Ian Campbell | ba8311f | 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 | |
| 9 | int sunxi_gmac_initialize(bd_t *bis) |
| 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 | 1a9a6fb | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 16 | #ifndef CONFIG_MACH_SUN6I |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 17 | setbits_le32(&ccm->ahb_gate1, 0x1 << AHB_GATE_OFFSET_GMAC); |
Hans de Goede | 1a9a6fb | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 18 | #else |
| 19 | setbits_le32(&ccm->ahb_reset0_cfg, 0x1 << AHB_RESET_OFFSET_GMAC); |
| 20 | setbits_le32(&ccm->ahb_gate0, 0x1 << AHB_GATE_OFFSET_GMAC); |
| 21 | #endif |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 22 | |
| 23 | /* Set MII clock */ |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 24 | #ifdef CONFIG_RGMII |
Ian Campbell | ba8311f | 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); |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 27 | #else |
| 28 | setbits_le32(&ccm->gmac_clk_cfg, CCM_GMAC_CTRL_TX_CLK_SRC_MII | |
| 29 | CCM_GMAC_CTRL_GPIT_MII); |
| 30 | #endif |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 31 | |
Hans de Goede | 5d62900 | 2014-09-30 18:45:32 +0200 | [diff] [blame] | 32 | /* |
| 33 | * In order for the gmac nic to work reliable on the Bananapi, we |
| 34 | * need to set bits 10-12 GTXDC "GMAC Transmit Clock Delay Chain" |
| 35 | * of the GMAC clk register to 3. |
| 36 | */ |
Hans de Goede | d8eb473 | 2014-12-31 11:30:26 +0100 | [diff] [blame] | 37 | #if defined CONFIG_TARGET_BANANAPI || defined CONFIG_TARGET_BANANAPRO |
Hans de Goede | 5d62900 | 2014-09-30 18:45:32 +0200 | [diff] [blame] | 38 | setbits_le32(&ccm->gmac_clk_cfg, 0x3 << 10); |
| 39 | #endif |
| 40 | |
Hans de Goede | 1a9a6fb | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 41 | #ifndef CONFIG_MACH_SUN6I |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 42 | /* Configure pin mux settings for GMAC */ |
| 43 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(16); pin++) { |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 44 | #ifdef CONFIG_RGMII |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 45 | /* skip unused pins in RGMII mode */ |
| 46 | if (pin == SUNXI_GPA(9) || pin == SUNXI_GPA(14)) |
| 47 | continue; |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 48 | #endif |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 49 | sunxi_gpio_set_cfgpin(pin, SUN7I_GPA0_GMAC); |
| 50 | sunxi_gpio_set_drv(pin, 3); |
| 51 | } |
Hans de Goede | 1a9a6fb | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 52 | #elif defined CONFIG_RGMII |
| 53 | /* Configure sun6i RGMII mode pin mux settings */ |
| 54 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++) { |
| 55 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 56 | sunxi_gpio_set_drv(pin, 3); |
| 57 | } |
| 58 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 59 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 60 | sunxi_gpio_set_drv(pin, 3); |
| 61 | } |
| 62 | for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(20); pin++) { |
| 63 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 64 | sunxi_gpio_set_drv(pin, 3); |
| 65 | } |
| 66 | for (pin = SUNXI_GPA(25); pin <= SUNXI_GPA(27); pin++) { |
| 67 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 68 | sunxi_gpio_set_drv(pin, 3); |
| 69 | } |
| 70 | #elif defined CONFIG_GMII |
| 71 | /* Configure sun6i GMII mode pin mux settings */ |
| 72 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(27); pin++) { |
| 73 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 74 | sunxi_gpio_set_drv(pin, 2); |
| 75 | } |
| 76 | #else |
| 77 | /* Configure sun6i MII mode pin mux settings */ |
| 78 | for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++) |
| 79 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 80 | for (pin = SUNXI_GPA(8); pin <= SUNXI_GPA(9); pin++) |
| 81 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 82 | for (pin = SUNXI_GPA(11); pin <= SUNXI_GPA(14); pin++) |
| 83 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 84 | for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(24); pin++) |
| 85 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 86 | for (pin = SUNXI_GPA(26); pin <= SUNXI_GPA(27); pin++) |
| 87 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA0_GMAC); |
| 88 | #endif |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 89 | |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_RGMII |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 91 | return designware_initialize(SUNXI_GMAC_BASE, PHY_INTERFACE_MODE_RGMII); |
Hans de Goede | 1a9a6fb | 2014-11-21 17:19:45 +0100 | [diff] [blame] | 92 | #elif defined CONFIG_GMII |
| 93 | return designware_initialize(SUNXI_GMAC_BASE, PHY_INTERFACE_MODE_GMII); |
Chen-Yu Tsai | c1f6aa3 | 2014-06-09 11:37:01 +0200 | [diff] [blame] | 94 | #else |
| 95 | return designware_initialize(SUNXI_GMAC_BASE, PHY_INTERFACE_MODE_MII); |
| 96 | #endif |
Ian Campbell | ba8311f | 2014-05-05 11:52:28 +0100 | [diff] [blame] | 97 | } |