From a2f038fe0e13beaaf254881e37c3335e37d6ce26 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Fri, 5 May 2017 20:13:55 +0000 Subject: Move dwge(4) glue into dev/fdt. --- sys/arch/armv7/sunxi/files.sunxi | 5 +- sys/arch/armv7/sunxi/if_dwge_fdt.c | 147 ------------------------------------- sys/dev/fdt/files.fdt | 5 +- sys/dev/fdt/if_dwge_fdt.c | 147 +++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 152 deletions(-) delete mode 100644 sys/arch/armv7/sunxi/if_dwge_fdt.c create mode 100644 sys/dev/fdt/if_dwge_fdt.c (limited to 'sys') diff --git a/sys/arch/armv7/sunxi/files.sunxi b/sys/arch/armv7/sunxi/files.sunxi index 76caf06613d..2bb38520b62 100644 --- a/sys/arch/armv7/sunxi/files.sunxi +++ b/sys/arch/armv7/sunxi/files.sunxi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sunxi,v 1.18 2017/01/21 08:26:49 patrick Exp $ +# $OpenBSD: files.sunxi,v 1.19 2017/05/05 20:13:54 kettenis Exp $ device sxiintc attach sxiintc at fdt @@ -22,6 +22,3 @@ file arch/armv7/sunxi/sxiahci.c sxiahci device sxie: ether, ifnet, mii, ifmedia attach sxie at fdt file arch/armv7/sunxi/sxie.c sxie - -attach dwge at fdt with dwge_fdt -file arch/armv7/sunxi/if_dwge_fdt.c dwge_fdt diff --git a/sys/arch/armv7/sunxi/if_dwge_fdt.c b/sys/arch/armv7/sunxi/if_dwge_fdt.c deleted file mode 100644 index c22ae019ad8..00000000000 --- a/sys/arch/armv7/sunxi/if_dwge_fdt.c +++ /dev/null @@ -1,147 +0,0 @@ -/* $OpenBSD: if_dwge_fdt.c,v 1.3 2016/08/22 19:31:27 kettenis Exp $ */ -/* - * Copyright (c) 2016 Patrick Wildt - * Copyright (c) 2016 Mark Kettenis - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#if NBPFILTER > 0 -#include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -int dwge_fdt_match(struct device *, void *, void *); -void dwge_fdt_attach(struct device *, struct device *, void *); -int dwge_fdt_intr(void *); - -struct dwge_fdt_softc { - struct dwc_gmac_softc sc_core; - void *sc_ih; -}; - -struct cfattach dwge_fdt_ca = { - sizeof(struct dwge_fdt_softc), dwge_fdt_match, dwge_fdt_attach, -}; - -int -dwge_fdt_match(struct device *parent, void *match, void *aux) -{ - struct fdt_attach_args *faa = aux; - - return OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-gmac"); -} - -void -dwge_fdt_attach(struct device *parent, struct device *self, void *aux) -{ - struct dwge_fdt_softc *fsc = (struct dwge_fdt_softc *)self; - struct dwc_gmac_softc *sc = &fsc->sc_core; - struct fdt_attach_args *faa = aux; - char phy_mode[8]; - int phyloc = MII_PHY_ANY; - uint32_t phy_supply; - uint32_t phy; - uint32_t freq; - int node; - - if (faa->fa_nreg < 1) - return; - - pinctrl_byname(faa->fa_node, "default"); - - sc->sc_bst = faa->fa_iot; - sc->sc_dmat = faa->fa_dmat; - - printf("\n"); - - if (bus_space_map(sc->sc_bst, faa->fa_reg[0].addr, - faa->fa_reg[0].size, 0, &sc->sc_bsh)) - panic("%s: bus_space_map failed!", __func__); - - /* default to RGMII */ - OF_getprop(faa->fa_node, "phy-mode", phy_mode, sizeof(phy_mode)); - if (strcmp(phy_mode, "mii") == 0) - freq = 25000000; - else - freq = 125000000; - clock_set_frequency(faa->fa_node, "allwinner_gmac_tx", freq); - - /* lookup PHY */ - phy = OF_getpropint(faa->fa_node, "phy", 0); - node = OF_getnodebyphandle(phy); - if (node) - phyloc = OF_getpropint(node, "reg", phyloc); - - /* enable clock */ - clock_enable(faa->fa_node, "stmmaceth"); - delay(5000); - - /* power up phy */ - phy_supply = OF_getpropint(faa->fa_node, "phy-supply", 0); - if (phy_supply) - regulator_enable(phy_supply); - - fsc->sc_ih = arm_intr_establish_fdt(faa->fa_node, IPL_NET, - dwge_fdt_intr, sc, sc->sc_dev.dv_xname); - if (fsc->sc_ih == NULL) { - printf(": unable to establish interrupt\n"); - goto clrpwr; - } - - dwc_gmac_attach(sc, GMAC_MII_CLK_150_250M_DIV102, phyloc); - - return; -clrpwr: - if (phy_supply) - regulator_disable(phy_supply); - clock_disable(faa->fa_node, "stmmaceth"); - bus_space_unmap(sc->sc_bst, sc->sc_bsh, faa->fa_reg[0].size); -} - -int -dwge_fdt_intr(void *arg) -{ - struct dwge_fdt_softc *sc = arg; - - return dwc_gmac_intr(&sc->sc_core); -} diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index 238d1d1e8bb..92fc968d30e 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.14 2017/05/05 17:43:47 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.15 2017/05/05 20:13:54 kettenis Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -48,6 +48,9 @@ file dev/fdt/virtio_mmio.c virtio_mmio attach ahci at fdt with ahci_fdt file dev/fdt/ahci_fdt.c ahci_fdt +attach dwge at fdt with dwge_fdt +file dev/fdt/if_dwge_fdt.c dwge_fdt + attach ehci at fdt with ehci_fdt file dev/fdt/ehci_fdt.c ehci_fdt diff --git a/sys/dev/fdt/if_dwge_fdt.c b/sys/dev/fdt/if_dwge_fdt.c new file mode 100644 index 00000000000..fc6eda1c14e --- /dev/null +++ b/sys/dev/fdt/if_dwge_fdt.c @@ -0,0 +1,147 @@ +/* $OpenBSD: if_dwge_fdt.c,v 1.1 2017/05/05 20:13:54 kettenis Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * Copyright (c) 2016 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#if NBPFILTER > 0 +#include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +int dwge_fdt_match(struct device *, void *, void *); +void dwge_fdt_attach(struct device *, struct device *, void *); +int dwge_fdt_intr(void *); + +struct dwge_fdt_softc { + struct dwc_gmac_softc sc_core; + void *sc_ih; +}; + +struct cfattach dwge_fdt_ca = { + sizeof(struct dwge_fdt_softc), dwge_fdt_match, dwge_fdt_attach, +}; + +int +dwge_fdt_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-gmac"); +} + +void +dwge_fdt_attach(struct device *parent, struct device *self, void *aux) +{ + struct dwge_fdt_softc *fsc = (struct dwge_fdt_softc *)self; + struct dwc_gmac_softc *sc = &fsc->sc_core; + struct fdt_attach_args *faa = aux; + char phy_mode[8]; + int phyloc = MII_PHY_ANY; + uint32_t phy_supply; + uint32_t phy; + uint32_t freq; + int node; + + if (faa->fa_nreg < 1) + return; + + pinctrl_byname(faa->fa_node, "default"); + + sc->sc_bst = faa->fa_iot; + sc->sc_dmat = faa->fa_dmat; + + printf("\n"); + + if (bus_space_map(sc->sc_bst, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_bsh)) + panic("%s: bus_space_map failed!", __func__); + + /* default to RGMII */ + OF_getprop(faa->fa_node, "phy-mode", phy_mode, sizeof(phy_mode)); + if (strcmp(phy_mode, "mii") == 0) + freq = 25000000; + else + freq = 125000000; + clock_set_frequency(faa->fa_node, "allwinner_gmac_tx", freq); + + /* lookup PHY */ + phy = OF_getpropint(faa->fa_node, "phy", 0); + node = OF_getnodebyphandle(phy); + if (node) + phyloc = OF_getpropint(node, "reg", phyloc); + + /* enable clock */ + clock_enable(faa->fa_node, "stmmaceth"); + delay(5000); + + /* power up phy */ + phy_supply = OF_getpropint(faa->fa_node, "phy-supply", 0); + if (phy_supply) + regulator_enable(phy_supply); + + fsc->sc_ih = arm_intr_establish_fdt(faa->fa_node, IPL_NET, + dwge_fdt_intr, sc, sc->sc_dev.dv_xname); + if (fsc->sc_ih == NULL) { + printf(": unable to establish interrupt\n"); + goto clrpwr; + } + + dwc_gmac_attach(sc, GMAC_MII_CLK_150_250M_DIV102, phyloc); + + return; +clrpwr: + if (phy_supply) + regulator_disable(phy_supply); + clock_disable(faa->fa_node, "stmmaceth"); + bus_space_unmap(sc->sc_bst, sc->sc_bsh, faa->fa_reg[0].size); +} + +int +dwge_fdt_intr(void *arg) +{ + struct dwge_fdt_softc *sc = arg; + + return dwc_gmac_intr(&sc->sc_core); +} -- cgit v1.2.3