Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Compulab, Ltd. |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 7 | #include <i2c.h> |
| 8 | #include <miiphy.h> |
| 9 | #include <cpsw.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 12 | #include <asm/gpio.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/emif.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 16 | #include <power/pmic.h> |
| 17 | #include <power/tps65218.h> |
| 18 | #include "board.h" |
Faiz Abbas | 29836a9 | 2018-02-15 17:12:11 +0530 | [diff] [blame] | 19 | #include <usb.h> |
| 20 | #include <asm/omap_common.h> |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 25 | |
| 26 | /* setup board specific PMIC */ |
| 27 | int power_init_board(void) |
| 28 | { |
| 29 | struct pmic *p; |
Nikita Kiryanov | 648ac63 | 2016-02-19 19:19:47 +0200 | [diff] [blame] | 30 | uchar tps_status = 0; |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 31 | |
| 32 | power_tps65218_init(I2C_PMIC); |
| 33 | p = pmic_get("TPS65218_PMIC"); |
Nikita Kiryanov | 648ac63 | 2016-02-19 19:19:47 +0200 | [diff] [blame] | 34 | if (p && !pmic_probe(p)) { |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 35 | puts("PMIC: TPS65218\n"); |
Nikita Kiryanov | 648ac63 | 2016-02-19 19:19:47 +0200 | [diff] [blame] | 36 | /* We don't care if fseal is locked, but we do need it set */ |
| 37 | tps65218_lock_fseal(); |
| 38 | tps65218_reg_read(TPS65218_STATUS, &tps_status); |
| 39 | if (!(tps_status & TPS65218_FSEAL)) |
| 40 | printf("WARNING: RTC not backed by battery!\n"); |
| 41 | } |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int board_init(void) |
| 47 | { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 48 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 49 | gpmc_init(); |
| 50 | set_i2c_pin_mux(); |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
Faiz Abbas | 29836a9 | 2018-02-15 17:12:11 +0530 | [diff] [blame] | 55 | int board_usb_init(int index, enum usb_init_type init) |
| 56 | { |
| 57 | enable_usb_clocks(index); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 62 | { |
| 63 | disable_usb_clocks(index); |
| 64 | return 0; |
| 65 | } |
| 66 | |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 67 | #ifdef CONFIG_DRIVER_TI_CPSW |
| 68 | |
| 69 | static void cpsw_control(int enabled) |
| 70 | { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 75 | { |
| 76 | .slave_reg_ofs = 0x208, |
| 77 | .sliver_reg_ofs = 0xd80, |
| 78 | .phy_addr = 0, |
| 79 | .phy_if = PHY_INTERFACE_MODE_RGMII, |
| 80 | }, |
| 81 | { |
| 82 | .slave_reg_ofs = 0x308, |
| 83 | .sliver_reg_ofs = 0xdc0, |
| 84 | .phy_addr = 1, |
| 85 | .phy_if = PHY_INTERFACE_MODE_RGMII, |
| 86 | }, |
| 87 | }; |
| 88 | |
| 89 | static struct cpsw_platform_data cpsw_data = { |
| 90 | .mdio_base = CPSW_MDIO_BASE, |
| 91 | .cpsw_base = CPSW_BASE, |
| 92 | .mdio_div = 0xff, |
| 93 | .channels = 8, |
| 94 | .cpdma_reg_ofs = 0x800, |
| 95 | .slaves = 2, |
| 96 | .slave_data = cpsw_slaves, |
| 97 | .ale_reg_ofs = 0xd00, |
| 98 | .ale_entries = 1024, |
| 99 | .host_port_reg_ofs = 0x108, |
| 100 | .hw_stats_reg_ofs = 0x900, |
| 101 | .bd_ram_ofs = 0x2000, |
| 102 | .mac_control = (1 << 5), |
| 103 | .control = cpsw_control, |
| 104 | .host_port_num = 0, |
| 105 | .version = CPSW_CTRL_VERSION_2, |
| 106 | }; |
| 107 | |
| 108 | #define GPIO_PHY1_RST 170 |
| 109 | #define GPIO_PHY2_RST 168 |
| 110 | |
| 111 | int board_phy_config(struct phy_device *phydev) |
| 112 | { |
| 113 | unsigned short val; |
| 114 | |
| 115 | /* introduce tx clock delay */ |
| 116 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5); |
| 117 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e); |
| 118 | val |= 0x0100; |
| 119 | phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val); |
| 120 | |
| 121 | if (phydev->drv->config) |
| 122 | return phydev->drv->config(phydev); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static void board_phy_init(void) |
| 128 | { |
| 129 | set_mdio_pin_mux(); |
| 130 | writel(0x40003, 0x44e10a74); /* Mux pin as clkout2 */ |
| 131 | writel(0x10006, 0x44df4108); /* Select EXTDEV as clock source */ |
| 132 | writel(0x4, 0x44df2e60); /* Set EXTDEV as MNbypass */ |
| 133 | |
| 134 | /* For revision A */ |
| 135 | writel(0x2000009, 0x44df2e6c); |
| 136 | writel(0x38a, 0x44df2e70); |
| 137 | |
| 138 | mdelay(10); |
| 139 | |
| 140 | gpio_request(GPIO_PHY1_RST, "phy1_rst"); |
| 141 | gpio_request(GPIO_PHY2_RST, "phy2_rst"); |
| 142 | gpio_direction_output(GPIO_PHY1_RST, 0); |
| 143 | gpio_direction_output(GPIO_PHY2_RST, 0); |
| 144 | mdelay(2); |
| 145 | |
| 146 | gpio_set_value(GPIO_PHY1_RST, 1); |
| 147 | gpio_set_value(GPIO_PHY2_RST, 1); |
| 148 | mdelay(2); |
| 149 | } |
| 150 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 151 | int board_eth_init(struct bd_info *bis) |
Nikita Kiryanov | 0da2219 | 2016-02-19 19:19:45 +0200 | [diff] [blame] | 152 | { |
| 153 | int rv; |
| 154 | |
| 155 | set_rgmii_pin_mux(); |
| 156 | writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel); |
| 157 | board_phy_init(); |
| 158 | |
| 159 | rv = cpsw_register(&cpsw_data); |
| 160 | if (rv < 0) |
| 161 | printf("Error %d registering CPSW switch\n", rv); |
| 162 | |
| 163 | return rv; |
| 164 | } |
| 165 | #endif |