1 /* $OpenBSD: imxpciephy.c,v 1.1 2020/04/26 15:03:04 patrick Exp $ */ 2 /* 3 * Copyright (c) 2020 Patrick Wildt <patrick@blueri.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/systm.h> 20 #include <sys/device.h> 21 22 #include <machine/bus.h> 23 #include <machine/fdt.h> 24 25 #include <dev/ofw/openfirm.h> 26 #include <dev/ofw/ofw_misc.h> 27 #include <dev/ofw/fdt.h> 28 29 struct imxpciephy_softc { 30 struct device sc_dev; 31 bus_space_tag_t sc_iot; 32 bus_space_handle_t sc_ioh; 33 }; 34 35 int imxpciephy_match(struct device *, void *, void *); 36 void imxpciephy_attach(struct device *, struct device *, void *); 37 38 struct cfattach imxpciephy_ca = { 39 sizeof(struct imxpciephy_softc), imxpciephy_match, imxpciephy_attach 40 }; 41 42 struct cfdriver imxpciephy_cd = { 43 NULL, "imxpciephy", DV_DULL 44 }; 45 46 int 47 imxpciephy_match(struct device *parent, void *match, void *aux) 48 { 49 struct fdt_attach_args *faa = aux; 50 int node = faa->fa_node; 51 52 if (OF_is_compatible(node, "fsl,imx7d-pcie-phy")) 53 return 10; /* Must beat syscon(4). */ 54 55 return 0; 56 } 57 58 void 59 imxpciephy_attach(struct device *parent, struct device *self, void *aux) 60 { 61 struct imxpciephy_softc *sc = (struct imxpciephy_softc *)self; 62 struct fdt_attach_args *faa = aux; 63 64 if (faa->fa_nreg < 1) { 65 printf(": no registers\n"); 66 return; 67 } 68 69 sc->sc_iot = faa->fa_iot; 70 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 71 faa->fa_reg[0].size, 0, &sc->sc_ioh)) { 72 printf(": can't map registers\n"); 73 return; 74 } 75 76 regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, 77 faa->fa_reg[0].size); 78 79 printf("\n"); 80 } 81