Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 1 | #include <common.h> |
| 2 | #include <netdev.h> |
| 3 | #include <miiphy.h> |
| 4 | #include <asm/gpio.h> |
| 5 | #include <asm/io.h> |
| 6 | #include <asm/arch/clock.h> |
| 7 | #include <asm/arch/gpio.h> |
| 8 | |
Hans de Goede | fc8991c | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 9 | void eth_init_board(void) |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 10 | { |
| 11 | int pin; |
| 12 | struct sunxi_ccm_reg *const ccm = |
| 13 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 14 | |
| 15 | /* Set up clock gating */ |
Hans de Goede | 44d8ae5 | 2015-04-06 20:33:34 +0200 | [diff] [blame] | 16 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 17 | setbits_le32(&ccm->ahb_reset0_cfg, 0x1 << AHB_RESET_OFFSET_GMAC); |
| 18 | setbits_le32(&ccm->ahb_gate0, 0x1 << AHB_GATE_OFFSET_GMAC); |
Hans de Goede | 44d8ae5 | 2015-04-06 20:33:34 +0200 | [diff] [blame] | 19 | #else |
| 20 | setbits_le32(&ccm->ahb_gate1, 0x1 << AHB_GATE_OFFSET_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 21 | #endif |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 22 | |
| 23 | /* Set MII clock */ |
Chen-Yu Tsai | ef7e723 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 24 | #ifdef CONFIG_RGMII |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 25 | setbits_le32(&ccm->gmac_clk_cfg, CCM_GMAC_CTRL_TX_CLK_SRC_INT_RGMII | |
| 26 | CCM_GMAC_CTRL_GPIT_RGMII); |
Hans de Goede | c13f60d | 2015-01-25 12:10:48 +0100 | [diff] [blame] | 27 | setbits_le32(&ccm->gmac_clk_cfg, |
| 28 | CCM_GMAC_CTRL_TX_CLK_DELAY(CONFIG_GMAC_TX_DELAY)); |
Chen-Yu Tsai | ef7e723 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 29 | #else |
| 30 | setbits_le32(&ccm->gmac_clk_cfg, CCM_GMAC_CTRL_TX_CLK_SRC_MII | |
| 31 | CCM_GMAC_CTRL_GPIT_MII); |
| 32 | #endif |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 33 | |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 34 | #ifndef CONFIG_MACH_SUN6I |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 35 | /* Configure pin mux settings for GMAC */ |
Stefan Mavrodiev | aba3924 | 2017-11-03 08:56:51 +0200 | [diff] [blame] | 36 | #ifdef CONFIG_SUN7I_GMAC_FORCE_TXERR |
| 37 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(17); pin++) { |
| 38 | #else |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 39 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(16); pin++) { |
Stefan Mavrodiev | aba3924 | 2017-11-03 08:56:51 +0200 | [diff] [blame] | 40 | #endif |
Chen-Yu Tsai | ef7e723 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 41 | #ifdef CONFIG_RGMII |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 42 | /* skip unused pins in RGMII mode */ |
| 43 | if (pin == SUNXI_GPA(9) || pin == SUNXI_GPA(14)) |
| 44 | continue; |
Chen-Yu Tsai | ef7e723 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 45 | #endif |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 46 | sunxi_gpio_set_cfgpin(pin, SUN7I_GPA_GMAC); |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 47 | sunxi_gpio_set_drv(pin, 3); |
| 48 | } |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 49 | #elif defined CONFIG_RGMII |
| 50 | /* Configure sun6i RGMII mode pin mux settings */ |
| 51 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 52 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 53 | sunxi_gpio_set_drv(pin, 3); |
| 54 | } |
| 55 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 56 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 57 | sunxi_gpio_set_drv(pin, 3); |
| 58 | } |
| 59 | for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(20); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 60 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 61 | sunxi_gpio_set_drv(pin, 3); |
| 62 | } |
| 63 | for (pin = SUNXI_GPA(25); pin <= SUNXI_GPA(27); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 64 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 65 | sunxi_gpio_set_drv(pin, 3); |
| 66 | } |
| 67 | #elif defined CONFIG_GMII |
| 68 | /* Configure sun6i GMII mode pin mux settings */ |
| 69 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(27); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 70 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 71 | sunxi_gpio_set_drv(pin, 2); |
| 72 | } |
| 73 | #else |
| 74 | /* Configure sun6i MII mode pin mux settings */ |
| 75 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++) |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 76 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 77 | for (pin = SUNXI_GPA(8); pin <= SUNXI_GPA(9); pin++) |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 78 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 79 | for (pin = SUNXI_GPA(11); pin <= SUNXI_GPA(14); pin++) |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 80 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 81 | for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(24); pin++) |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 82 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 83 | for (pin = SUNXI_GPA(26); pin <= SUNXI_GPA(27); pin++) |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 84 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); |
Hans de Goede | eafec32 | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 85 | #endif |
Ian Campbell | 5835823 | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 86 | } |