blob: d8fdf7728e04537f27e4a301bbc1ba12f25eb79b [file] [log] [blame]
Ian Campbellba8311f2014-05-05 11:52:28 +01001#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 Goede42cbbe32016-03-17 13:53:03 +01009void eth_init_board(void)
Ian Campbellba8311f2014-05-05 11:52:28 +010010{
11 int pin;
12 struct sunxi_ccm_reg *const ccm =
13 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
14
Ian Campbellba8311f2014-05-05 11:52:28 +010015 /* Set MII clock */
Chen-Yu Tsaic1f6aa32014-06-09 11:37:01 +020016#ifdef CONFIG_RGMII
Ian Campbellba8311f2014-05-05 11:52:28 +010017 setbits_le32(&ccm->gmac_clk_cfg, CCM_GMAC_CTRL_TX_CLK_SRC_INT_RGMII |
18 CCM_GMAC_CTRL_GPIT_RGMII);
Hans de Goedebf880fe2015-01-25 12:10:48 +010019 setbits_le32(&ccm->gmac_clk_cfg,
20 CCM_GMAC_CTRL_TX_CLK_DELAY(CONFIG_GMAC_TX_DELAY));
Chen-Yu Tsaic1f6aa32014-06-09 11:37:01 +020021#else
22 setbits_le32(&ccm->gmac_clk_cfg, CCM_GMAC_CTRL_TX_CLK_SRC_MII |
23 CCM_GMAC_CTRL_GPIT_MII);
24#endif
Ian Campbellba8311f2014-05-05 11:52:28 +010025
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010026#ifndef CONFIG_MACH_SUN6I
Ian Campbellba8311f2014-05-05 11:52:28 +010027 /* Configure pin mux settings for GMAC */
Stefan Mavrodieveaee8582017-11-03 08:56:51 +020028#ifdef CONFIG_SUN7I_GMAC_FORCE_TXERR
29 for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(17); pin++) {
30#else
Ian Campbellba8311f2014-05-05 11:52:28 +010031 for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(16); pin++) {
Stefan Mavrodieveaee8582017-11-03 08:56:51 +020032#endif
Chen-Yu Tsaic1f6aa32014-06-09 11:37:01 +020033#ifdef CONFIG_RGMII
Ian Campbellba8311f2014-05-05 11:52:28 +010034 /* skip unused pins in RGMII mode */
35 if (pin == SUNXI_GPA(9) || pin == SUNXI_GPA(14))
36 continue;
Chen-Yu Tsaic1f6aa32014-06-09 11:37:01 +020037#endif
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010038 sunxi_gpio_set_cfgpin(pin, SUN7I_GPA_GMAC);
Ian Campbellba8311f2014-05-05 11:52:28 +010039 sunxi_gpio_set_drv(pin, 3);
40 }
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010041#elif defined CONFIG_RGMII
42 /* Configure sun6i RGMII mode pin mux settings */
43 for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010044 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010045 sunxi_gpio_set_drv(pin, 3);
46 }
47 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010048 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010049 sunxi_gpio_set_drv(pin, 3);
50 }
51 for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(20); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010052 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010053 sunxi_gpio_set_drv(pin, 3);
54 }
55 for (pin = SUNXI_GPA(25); pin <= SUNXI_GPA(27); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010056 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010057 sunxi_gpio_set_drv(pin, 3);
58 }
59#elif defined CONFIG_GMII
60 /* Configure sun6i GMII mode pin mux settings */
61 for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(27); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010062 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010063 sunxi_gpio_set_drv(pin, 2);
64 }
65#else
66 /* Configure sun6i MII mode pin mux settings */
67 for (pin = SUNXI_GPA(0); pin <= SUNXI_GPA(3); pin++)
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010068 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010069 for (pin = SUNXI_GPA(8); pin <= SUNXI_GPA(9); pin++)
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010070 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010071 for (pin = SUNXI_GPA(11); pin <= SUNXI_GPA(14); pin++)
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010072 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010073 for (pin = SUNXI_GPA(19); pin <= SUNXI_GPA(24); pin++)
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010074 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010075 for (pin = SUNXI_GPA(26); pin <= SUNXI_GPA(27); pin++)
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010076 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
Hans de Goede1a9a6fb2014-11-21 17:19:45 +010077#endif
Ian Campbellba8311f2014-05-05 11:52:28 +010078}