Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/sunxi Use syscon API instead of mapping syscon ...



details:   https://anonhg.NetBSD.org/src/rev/8c1d1a6f3cda
branches:  trunk
changeset: 362877:8c1d1a6f3cda
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Jun 30 12:36:13 2018 +0000

description:
Use syscon API instead of mapping syscon registers ourselves.

diffstat:

 sys/arch/arm/sunxi/sunxi_emac.c |  52 ++++++++++++----------------------------
 1 files changed, 16 insertions(+), 36 deletions(-)

diffs (125 lines):

diff -r 13ff123f0e04 -r 8c1d1a6f3cda sys/arch/arm/sunxi/sunxi_emac.c
--- a/sys/arch/arm/sunxi/sunxi_emac.c   Sat Jun 30 12:35:18 2018 +0000
+++ b/sys/arch/arm/sunxi/sunxi_emac.c   Sat Jun 30 12:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.15 2018/06/26 06:47:58 msaitoh Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.16 2018/06/30 12:36:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.15 2018/06/26 06:47:58 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.16 2018/06/30 12:36:13 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -55,6 +55,7 @@
 #include <dev/mii/miivar.h>
 
 #include <dev/fdt/fdtvar.h>
+#include <dev/fdt/syscon.h>
 
 #include <arm/sunxi/sunxi_emac.h>
 
@@ -167,12 +168,6 @@
        u_int                   cur;
 };
 
-enum {
-       _RES_EMAC,
-       _RES_SYSCON,
-       _RES_NITEMS
-};
-
 struct sunxi_emac_softc {
        device_t                dev;
        int                     phandle;
@@ -180,7 +175,7 @@
        bus_space_tag_t         bst;
        bus_dma_tag_t           dmat;
 
-       bus_space_handle_t      bsh[_RES_NITEMS];
+       bus_space_handle_t      bsh;
        struct clk              *clk_ahb;
        struct clk              *clk_ephy;
        struct fdtbus_reset     *rst_ahb;
@@ -188,6 +183,8 @@
        struct fdtbus_regulator *reg_phy;
        struct fdtbus_gpio_pin  *pin_reset;
 
+       struct syscon           *syscon;
+
        int                     phy_id;
 
        kmutex_t                mtx;
@@ -202,14 +199,9 @@
 };
 
 #define        RD4(sc, reg)                    \
-       bus_space_read_4((sc)->bst, (sc)->bsh[_RES_EMAC], (reg))
+       bus_space_read_4((sc)->bst, (sc)->bsh, (reg))
 #define        WR4(sc, reg, val)               \
-       bus_space_write_4((sc)->bst, (sc)->bsh[_RES_EMAC], (reg), (val))
-
-#define        SYSCONRD4(sc, reg)              \
-       bus_space_read_4((sc)->bst, (sc)->bsh[_RES_SYSCON], (reg))
-#define        SYSCONWR4(sc, reg, val)         \
-       bus_space_write_4((sc)->bst, (sc)->bsh[_RES_SYSCON], (reg), (val))
+       bus_space_write_4((sc)->bst, (sc)->bsh, (reg), (val))
 
 static int
 sunxi_emac_mii_readreg(device_t dev, int phy, int reg)
@@ -925,7 +917,8 @@
 
        aprint_debug_dev(sc->dev, "PHY type: %s\n", phy_type);
 
-       reg = SYSCONRD4(sc, 0);
+       syscon_lock(sc->syscon);
+       reg = syscon_read_4(sc->syscon, EMAC_CLK_REG);
 
        reg &= ~(EMAC_CLK_PIT | EMAC_CLK_SRC | EMAC_CLK_RMII_EN);
        if (strcmp(phy_type, "rgmii") == 0)
@@ -972,7 +965,8 @@
 
        aprint_debug_dev(sc->dev, "EMAC clock: 0x%08x\n", reg);
 
-       SYSCONWR4(sc, 0, reg);
+       syscon_write_4(sc->syscon, EMAC_CLK_REG, reg);
+       syscon_unlock(sc->syscon);
 
        return 0;
 }
@@ -1298,26 +1292,12 @@
        /* Map EMAC registers */
        if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0)
                return ENXIO;
-       if (bus_space_map(sc->bst, addr, size, 0, &sc->bsh[_RES_EMAC]) != 0)
+       if (bus_space_map(sc->bst, addr, size, 0, &sc->bsh) != 0)
                return ENXIO;
 
-       /* Map SYSCON registers */
-       if (of_hasprop(phandle, "syscon")) {
-               const int syscon_phandle = fdtbus_get_phandle(phandle,
-                   "syscon");
-               if (syscon_phandle == -1)
-                       return ENXIO;
-               if (fdtbus_get_reg(syscon_phandle, 0, &addr, &size) != 0)
-                       return ENXIO;
-               if (size < EMAC_CLK_REG + 4)
-                       return ENXIO;
-               addr += EMAC_CLK_REG;
-               size -= EMAC_CLK_REG;
-       } else {
-               if (fdtbus_get_reg(phandle, 1, &addr, &size) != 0)
-                       return ENXIO;
-       }
-       if (bus_space_map(sc->bst, addr, size, 0, &sc->bsh[_RES_SYSCON]) != 0)
+       /* Get SYSCON registers */
+       sc->syscon = fdtbus_syscon_acquire(phandle, "syscon");
+       if (sc->syscon == NULL)
                return ENXIO;
 
        /* The "ahb"/"stmmaceth" clock and reset is required */



Home | Main Index | Thread Index | Old Index