blob: 5b357f265a178d7da4f3d1337a5d84f7e6d6c668 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vanessa Maegima27142c32017-05-08 13:17:28 -03002/*
3 * Copyright (C) 2017 NXP Semiconductors
Vanessa Maegima27142c32017-05-08 13:17:28 -03004 */
5
6#include <asm/arch/clock.h>
7#include <asm/arch/crm_regs.h>
8#include <asm/arch/imx-regs.h>
9#include <asm/arch/mx7-pins.h>
10#include <asm/arch/sys_proto.h>
11#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020012#include <asm/mach-imx/iomux-v3.h>
13#include <asm/mach-imx/mxc_i2c.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030014#include <asm/io.h>
15#include <common.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030016#include <i2c.h>
17#include <miiphy.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030018#include <netdev.h>
19#include <usb.h>
20#include <power/pmic.h>
21#include <power/pfuze3000_pmic.h>
22#include "../../freescale/common/pfuze.h"
23
24DECLARE_GLOBAL_DATA_PTR;
25
26#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
27 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
28
Vanessa Maegima27142c32017-05-08 13:17:28 -030029#define ENET_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM)
30#define ENET_PAD_CTRL_MII (PAD_CTL_DSE_3P3V_32OHM)
31
32#define ENET_RX_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM)
33
34#define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
35 PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU100KOHM)
36
Fabio Estevamfb3532d2018-12-11 16:40:38 -020037
38#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
39 PAD_CTL_DSE_3P3V_49OHM)
40
41#define LCD_SYNC_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
42 PAD_CTL_DSE_3P3V_196OHM)
43
Vanessa Maegima27142c32017-05-08 13:17:28 -030044#ifdef CONFIG_SYS_I2C_MXC
45#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
Fabio Estevamfb3532d2018-12-11 16:40:38 -020046
Vanessa Maegima27142c32017-05-08 13:17:28 -030047/* I2C4 for PMIC */
48static struct i2c_pads_info i2c_pad_info4 = {
49 .scl = {
50 .i2c_mode = MX7D_PAD_SAI1_RX_SYNC__I2C4_SCL | PC,
51 .gpio_mode = MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16 | PC,
52 .gp = IMX_GPIO_NR(6, 16),
53 },
54 .sda = {
55 .i2c_mode = MX7D_PAD_SAI1_RX_BCLK__I2C4_SDA | PC,
56 .gpio_mode = MX7D_PAD_SAI1_RX_BCLK__GPIO6_IO17 | PC,
57 .gp = IMX_GPIO_NR(6, 17),
58 },
59};
60#endif
61
62int dram_init(void)
63{
Fabio Estevam6ed39812018-06-29 15:19:11 -030064 gd->ram_size = imx_ddr_size();
Vanessa Maegima27142c32017-05-08 13:17:28 -030065
Jun Niefeb13442019-05-08 14:38:32 +080066 /* Subtract the defined OPTEE runtime firmware length */
67#ifdef CONFIG_OPTEE_TZDRAM_SIZE
68 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
69#endif
70
Vanessa Maegima27142c32017-05-08 13:17:28 -030071 return 0;
72}
73
74#ifdef CONFIG_POWER
75#define I2C_PMIC 3
76int power_init_board(void)
77{
78 struct pmic *p;
79 int ret;
80 unsigned int reg, rev_id;
81
82 ret = power_pfuze3000_init(I2C_PMIC);
83 if (ret)
84 return ret;
85
86 p = pmic_get("PFUZE3000");
87 ret = pmic_probe(p);
88 if (ret)
89 return ret;
90
91 pmic_reg_read(p, PFUZE3000_DEVICEID, &reg);
92 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
93 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
94
95 /* disable Low Power Mode during standby mode */
96 pmic_reg_read(p, PFUZE3000_LDOGCTL, &reg);
97 reg |= 0x1;
98 pmic_reg_write(p, PFUZE3000_LDOGCTL, reg);
99
100 /* SW1A/1B mode set to APS/APS */
101 reg = 0x8;
102 pmic_reg_write(p, PFUZE3000_SW1AMODE, reg);
103 pmic_reg_write(p, PFUZE3000_SW1BMODE, reg);
104
105 /* SW1A/1B standby voltage set to 1.025V */
106 reg = 0xd;
107 pmic_reg_write(p, PFUZE3000_SW1ASTBY, reg);
108 pmic_reg_write(p, PFUZE3000_SW1BSTBY, reg);
109
110 /* decrease SW1B normal voltage to 0.975V */
111 pmic_reg_read(p, PFUZE3000_SW1BVOLT, &reg);
112 reg &= ~0x1f;
113 reg |= PFUZE3000_SW1AB_SETP(975);
114 pmic_reg_write(p, PFUZE3000_SW1BVOLT, reg);
115
116 return 0;
117}
118#endif
119
120static iomux_v3_cfg_t const wdog_pads[] = {
121 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
122};
123
124static iomux_v3_cfg_t const uart5_pads[] = {
125 MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
126 MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
127};
128
Vanessa Maegima27142c32017-05-08 13:17:28 -0300129#ifdef CONFIG_FEC_MXC
130static iomux_v3_cfg_t const fec1_pads[] = {
131 MX7D_PAD_SD2_CD_B__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
132 MX7D_PAD_SD2_WP__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
133 MX7D_PAD_ENET1_RGMII_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
134 MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
135 MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
136 MX7D_PAD_ENET1_RGMII_TD2__ENET1_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
137 MX7D_PAD_ENET1_RGMII_TD3__ENET1_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
138 MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
139 MX7D_PAD_ENET1_RGMII_RXC__ENET1_RGMII_RXC | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
140 MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
141 MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
142 MX7D_PAD_ENET1_RGMII_RD2__ENET1_RGMII_RD2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
143 MX7D_PAD_ENET1_RGMII_RD3__ENET1_RGMII_RD3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
144 MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
145 MX7D_PAD_SD3_STROBE__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
146 MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
147};
148
149#define FEC1_RST_GPIO IMX_GPIO_NR(6, 11)
150
151static void setup_iomux_fec(void)
152{
153 imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200154 gpio_request(FEC1_RST_GPIO, "phy_rst");
Vanessa Maegima27142c32017-05-08 13:17:28 -0300155 gpio_direction_output(FEC1_RST_GPIO, 0);
156 udelay(500);
157 gpio_set_value(FEC1_RST_GPIO, 1);
158}
159
160int board_eth_init(bd_t *bis)
161{
162 setup_iomux_fec();
163
164 return fecmxc_initialize_multi(bis, 0,
165 CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE);
166}
167
168static int setup_fec(void)
169{
170 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
171 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
172
173 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */
174 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
175 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
176 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
177
Eric Nelsoneadd7322017-08-31 08:34:23 -0700178 return set_clk_enet(ENET_125MHZ);
Vanessa Maegima27142c32017-05-08 13:17:28 -0300179}
180
181int board_phy_config(struct phy_device *phydev)
182{
183 unsigned short val;
184
185 /* To enable AR8035 ouput a 125MHz clk from CLK_25M */
186 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
187 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
188 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
189
190 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
191 val &= 0xffe7;
192 val |= 0x18;
193 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
194
195 /* introduce tx clock delay */
196 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
197 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
198 val |= 0x0100;
199 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
200
201 if (phydev->drv->config)
202 phydev->drv->config(phydev);
203
204 return 0;
205}
206#endif
207
208static void setup_iomux_uart(void)
209{
210 imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads));
211}
212
Vanessa Maegima27142c32017-05-08 13:17:28 -0300213int board_early_init_f(void)
214{
215 setup_iomux_uart();
216
217#ifdef CONFIG_SYS_I2C_MXC
218 setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4);
219#endif
220
221 return 0;
222}
223
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200224#ifdef CONFIG_VIDEO_MXS
225static iomux_v3_cfg_t const lcd_pads[] = {
226 MX7D_PAD_LCD_CLK__LCD_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
227 MX7D_PAD_LCD_ENABLE__LCD_ENABLE | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
228 MX7D_PAD_LCD_HSYNC__LCD_HSYNC | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
229 MX7D_PAD_LCD_VSYNC__LCD_VSYNC | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
230 MX7D_PAD_LCD_DATA00__LCD_DATA0 | MUX_PAD_CTRL(LCD_PAD_CTRL),
231 MX7D_PAD_LCD_DATA01__LCD_DATA1 | MUX_PAD_CTRL(LCD_PAD_CTRL),
232 MX7D_PAD_LCD_DATA02__LCD_DATA2 | MUX_PAD_CTRL(LCD_PAD_CTRL),
233 MX7D_PAD_LCD_DATA03__LCD_DATA3 | MUX_PAD_CTRL(LCD_PAD_CTRL),
234 MX7D_PAD_LCD_DATA04__LCD_DATA4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
235 MX7D_PAD_LCD_DATA05__LCD_DATA5 | MUX_PAD_CTRL(LCD_PAD_CTRL),
236 MX7D_PAD_LCD_DATA06__LCD_DATA6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
237 MX7D_PAD_LCD_DATA07__LCD_DATA7 | MUX_PAD_CTRL(LCD_PAD_CTRL),
238 MX7D_PAD_LCD_DATA08__LCD_DATA8 | MUX_PAD_CTRL(LCD_PAD_CTRL),
239 MX7D_PAD_LCD_DATA09__LCD_DATA9 | MUX_PAD_CTRL(LCD_PAD_CTRL),
240 MX7D_PAD_LCD_DATA10__LCD_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
241 MX7D_PAD_LCD_DATA11__LCD_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
242 MX7D_PAD_LCD_DATA12__LCD_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
243 MX7D_PAD_LCD_DATA13__LCD_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
244 MX7D_PAD_LCD_DATA14__LCD_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
245 MX7D_PAD_LCD_DATA15__LCD_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
246 MX7D_PAD_LCD_DATA16__LCD_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
247 MX7D_PAD_LCD_DATA17__LCD_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
248 MX7D_PAD_LCD_DATA18__LCD_DATA18 | MUX_PAD_CTRL(LCD_PAD_CTRL),
249 MX7D_PAD_LCD_DATA19__LCD_DATA19 | MUX_PAD_CTRL(LCD_PAD_CTRL),
250 MX7D_PAD_LCD_DATA20__LCD_DATA20 | MUX_PAD_CTRL(LCD_PAD_CTRL),
251 MX7D_PAD_LCD_DATA21__LCD_DATA21 | MUX_PAD_CTRL(LCD_PAD_CTRL),
252 MX7D_PAD_LCD_DATA22__LCD_DATA22 | MUX_PAD_CTRL(LCD_PAD_CTRL),
253 MX7D_PAD_LCD_DATA23__LCD_DATA23 | MUX_PAD_CTRL(LCD_PAD_CTRL),
254 MX7D_PAD_GPIO1_IO06__GPIO1_IO6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
255 MX7D_PAD_GPIO1_IO11__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
256};
257
258void setup_lcd(void)
259{
260 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200261 gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness");
262 gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable");
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200263 /* Set Brightness to high */
264 gpio_direction_output(IMX_GPIO_NR(1, 11) , 1);
265 /* Set LCD enable to high */
266 gpio_direction_output(IMX_GPIO_NR(1, 6) , 1);
267}
268#endif
269
Vanessa Maegima27142c32017-05-08 13:17:28 -0300270int board_init(void)
271{
272 /* address of boot parameters */
273 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
274
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200275#ifdef CONFIG_VIDEO_MXS
276 setup_lcd();
277#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -0300278#ifdef CONFIG_FEC_MXC
279 setup_fec();
280#endif
281
282 return 0;
283}
284
285int board_late_init(void)
286{
287 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
288
289 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
290
291 set_wdog_reset(wdog);
292
293 /*
294 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
295 * since we use PMIC_PWRON to reset the board.
296 */
297 clrsetbits_le16(&wdog->wcr, 0, 0x10);
298
299 return 0;
300}
301
302int checkboard(void)
303{
304 puts("Board: i.MX7D PICOSOM\n");
305
306 return 0;
307}
308
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300309static iomux_v3_cfg_t const usb_otg2_pads[] = {
310 MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL),
311};
312
313int board_ehci_hcd_init(int port)
314{
315 switch (port) {
316 case 0:
317 break;
318 case 1:
319 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
320 ARRAY_SIZE(usb_otg2_pads));
321 break;
322 default:
323 return -EINVAL;
324 }
325 return 0;
326}
327
Vanessa Maegima27142c32017-05-08 13:17:28 -0300328int board_usb_phy_mode(int port)
329{
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300330 switch (port) {
331 case 0:
332 return USB_INIT_DEVICE;
333 case 1:
334 return USB_INIT_HOST;
335 default:
336 return -EINVAL;
337 }
338 return 0;
Vanessa Maegima27142c32017-05-08 13:17:28 -0300339}