| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sunxi_emac.c,v 1.10 2017/11/30 21:36:11 jmcneill Exp $ */ | | 1 | /* $NetBSD: sunxi_emac.c,v 1.11 2017/12/01 17:47:51 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -23,27 +23,27 @@ | | | @@ -23,27 +23,27 @@ |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | /* | | 29 | /* |
30 | * Allwinner Gigabit Ethernet MAC (EMAC) controller | | 30 | * Allwinner Gigabit Ethernet MAC (EMAC) controller |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include "opt_net_mpsafe.h" | | 33 | #include "opt_net_mpsafe.h" |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | __KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.10 2017/11/30 21:36:11 jmcneill Exp $"); | | 36 | __KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.11 2017/12/01 17:47:51 jmcneill Exp $"); |
37 | | | 37 | |
38 | #include <sys/param.h> | | 38 | #include <sys/param.h> |
39 | #include <sys/bus.h> | | 39 | #include <sys/bus.h> |
40 | #include <sys/device.h> | | 40 | #include <sys/device.h> |
41 | #include <sys/intr.h> | | 41 | #include <sys/intr.h> |
42 | #include <sys/systm.h> | | 42 | #include <sys/systm.h> |
43 | #include <sys/kernel.h> | | 43 | #include <sys/kernel.h> |
44 | #include <sys/mutex.h> | | 44 | #include <sys/mutex.h> |
45 | #include <sys/callout.h> | | 45 | #include <sys/callout.h> |
46 | #include <sys/gpio.h> | | 46 | #include <sys/gpio.h> |
47 | #include <sys/cprng.h> | | 47 | #include <sys/cprng.h> |
48 | | | 48 | |
49 | #include <net/if.h> | | 49 | #include <net/if.h> |
| @@ -1300,52 +1300,67 @@ sunxi_emac_get_resources(struct sunxi_em | | | @@ -1300,52 +1300,67 @@ sunxi_emac_get_resources(struct sunxi_em |
1300 | if (fdtbus_get_reg(syscon_phandle, 0, &addr, &size) != 0) | | 1300 | if (fdtbus_get_reg(syscon_phandle, 0, &addr, &size) != 0) |
1301 | return ENXIO; | | 1301 | return ENXIO; |
1302 | if (size < EMAC_CLK_REG + 4) | | 1302 | if (size < EMAC_CLK_REG + 4) |
1303 | return ENXIO; | | 1303 | return ENXIO; |
1304 | addr += EMAC_CLK_REG; | | 1304 | addr += EMAC_CLK_REG; |
1305 | size -= EMAC_CLK_REG; | | 1305 | size -= EMAC_CLK_REG; |
1306 | } else { | | 1306 | } else { |
1307 | if (fdtbus_get_reg(phandle, 1, &addr, &size) != 0) | | 1307 | if (fdtbus_get_reg(phandle, 1, &addr, &size) != 0) |
1308 | return ENXIO; | | 1308 | return ENXIO; |
1309 | } | | 1309 | } |
1310 | if (bus_space_map(sc->bst, addr, size, 0, &sc->bsh[_RES_SYSCON]) != 0) | | 1310 | if (bus_space_map(sc->bst, addr, size, 0, &sc->bsh[_RES_SYSCON]) != 0) |
1311 | return ENXIO; | | 1311 | return ENXIO; |
1312 | | | 1312 | |
1313 | /* Get clocks and resets. "ahb" is required, "ephy" is optional. */ | | 1313 | /* The "ahb"/"stmmaceth" clock and reset is required */ |
1314 | | | 1314 | if ((sc->clk_ahb = fdtbus_clock_get(phandle, "ahb")) == NULL && |
1315 | if ((sc->clk_ahb = fdtbus_clock_get(phandle, "ahb")) == NULL) | | 1315 | (sc->clk_ahb = fdtbus_clock_get(phandle, "stmmaceth")) == NULL) |
1316 | return ENXIO; | | 1316 | return ENXIO; |
1317 | sc->clk_ephy = fdtbus_clock_get(phandle, "ephy"); | | 1317 | if ((sc->rst_ahb = fdtbus_reset_get(phandle, "ahb")) == NULL && |
1318 | | | 1318 | (sc->rst_ahb = fdtbus_reset_get(phandle, "stmmaceth")) == NULL) |
1319 | if ((sc->rst_ahb = fdtbus_reset_get(phandle, "ahb")) == NULL) | | | |
1320 | return ENXIO; | | 1319 | return ENXIO; |
| | | 1320 | |
| | | 1321 | /* Internal PHY clock and reset are optional properties. */ |
| | | 1322 | sc->clk_ephy = fdtbus_clock_get(phandle, "ephy"); |
| | | 1323 | if (sc->clk_ephy == NULL) { |
| | | 1324 | int phy_phandle = fdtbus_get_phandle(phandle, "phy-handle"); |
| | | 1325 | if (phy_phandle != -1) |
| | | 1326 | sc->clk_ephy = fdtbus_clock_get_index(phy_phandle, 0); |
| | | 1327 | } |
1321 | sc->rst_ephy = fdtbus_reset_get(phandle, "ephy"); | | 1328 | sc->rst_ephy = fdtbus_reset_get(phandle, "ephy"); |
| | | 1329 | if (sc->rst_ephy == NULL) { |
| | | 1330 | int phy_phandle = fdtbus_get_phandle(phandle, "phy-phandle"); |
| | | 1331 | if (phy_phandle != -1) |
| | | 1332 | sc->rst_ephy = fdtbus_reset_get_index(phy_phandle, 0); |
| | | 1333 | } |
1322 | | | 1334 | |
1323 | /* Regulator is optional */ | | 1335 | /* Regulator is optional */ |
1324 | sc->reg_phy = fdtbus_regulator_acquire(phandle, "phy-supply"); | | 1336 | sc->reg_phy = fdtbus_regulator_acquire(phandle, "phy-supply"); |
1325 | | | 1337 | |
1326 | /* Reset GPIO is optional */ | | 1338 | /* Reset GPIO is optional */ |
1327 | sc->pin_reset = fdtbus_gpio_acquire(sc->phandle, | | 1339 | sc->pin_reset = fdtbus_gpio_acquire(sc->phandle, |
1328 | "allwinner,reset-gpio", GPIO_PIN_OUTPUT); | | 1340 | "allwinner,reset-gpio", GPIO_PIN_OUTPUT); |
1329 | | | 1341 | |
1330 | return 0; | | 1342 | return 0; |
1331 | } | | 1343 | } |
1332 | | | 1344 | |
1333 | static int | | 1345 | static int |
1334 | sunxi_emac_get_phyid(struct sunxi_emac_softc *sc) | | 1346 | sunxi_emac_get_phyid(struct sunxi_emac_softc *sc) |
1335 | { | | 1347 | { |
1336 | bus_addr_t addr; | | 1348 | bus_addr_t addr; |
| | | 1349 | int phy_phandle; |
1337 | | | 1350 | |
1338 | const int phy_phandle = fdtbus_get_phandle(sc->phandle, "phy"); | | 1351 | phy_phandle = fdtbus_get_phandle(sc->phandle, "phy"); |
| | | 1352 | if (phy_phandle == -1) |
| | | 1353 | phy_phandle = fdtbus_get_phandle(sc->phandle, "phy-handle"); |
1339 | if (phy_phandle == -1) | | 1354 | if (phy_phandle == -1) |
1340 | return MII_PHY_ANY; | | 1355 | return MII_PHY_ANY; |
1341 | | | 1356 | |
1342 | if (fdtbus_get_reg(phy_phandle, 0, &addr, NULL) != 0) | | 1357 | if (fdtbus_get_reg(phy_phandle, 0, &addr, NULL) != 0) |
1343 | return MII_PHY_ANY; | | 1358 | return MII_PHY_ANY; |
1344 | | | 1359 | |
1345 | return (int)addr; | | 1360 | return (int)addr; |
1346 | } | | 1361 | } |
1347 | | | 1362 | |
1348 | static int | | 1363 | static int |
1349 | sunxi_emac_match(device_t parent, cfdata_t cf, void *aux) | | 1364 | sunxi_emac_match(device_t parent, cfdata_t cf, void *aux) |
1350 | { | | 1365 | { |
1351 | struct fdt_attach_args * const faa = aux; | | 1366 | struct fdt_attach_args * const faa = aux; |