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