blob: e63b19df6ed253c53bc84a12ee9653a63d6c9e80 [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
66 return 0;
67}
68
69#ifdef CONFIG_POWER
70#define I2C_PMIC 3
71int power_init_board(void)
72{
73 struct pmic *p;
74 int ret;
75 unsigned int reg, rev_id;
76
77 ret = power_pfuze3000_init(I2C_PMIC);
78 if (ret)
79 return ret;
80
81 p = pmic_get("PFUZE3000");
82 ret = pmic_probe(p);
83 if (ret)
84 return ret;
85
86 pmic_reg_read(p, PFUZE3000_DEVICEID, &reg);
87 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
88 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
89
90 /* disable Low Power Mode during standby mode */
91 pmic_reg_read(p, PFUZE3000_LDOGCTL, &reg);
92 reg |= 0x1;
93 pmic_reg_write(p, PFUZE3000_LDOGCTL, reg);
94
95 /* SW1A/1B mode set to APS/APS */
96 reg = 0x8;
97 pmic_reg_write(p, PFUZE3000_SW1AMODE, reg);
98 pmic_reg_write(p, PFUZE3000_SW1BMODE, reg);
99
100 /* SW1A/1B standby voltage set to 1.025V */
101 reg = 0xd;
102 pmic_reg_write(p, PFUZE3000_SW1ASTBY, reg);
103 pmic_reg_write(p, PFUZE3000_SW1BSTBY, reg);
104
105 /* decrease SW1B normal voltage to 0.975V */
106 pmic_reg_read(p, PFUZE3000_SW1BVOLT, &reg);
107 reg &= ~0x1f;
108 reg |= PFUZE3000_SW1AB_SETP(975);
109 pmic_reg_write(p, PFUZE3000_SW1BVOLT, reg);
110
111 return 0;
112}
113#endif
114
115static iomux_v3_cfg_t const wdog_pads[] = {
116 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
117};
118
119static iomux_v3_cfg_t const uart5_pads[] = {
120 MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
121 MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
122};
123
Vanessa Maegima27142c32017-05-08 13:17:28 -0300124#ifdef CONFIG_FEC_MXC
125static iomux_v3_cfg_t const fec1_pads[] = {
126 MX7D_PAD_SD2_CD_B__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
127 MX7D_PAD_SD2_WP__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
128 MX7D_PAD_ENET1_RGMII_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
129 MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
130 MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
131 MX7D_PAD_ENET1_RGMII_TD2__ENET1_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
132 MX7D_PAD_ENET1_RGMII_TD3__ENET1_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
133 MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
134 MX7D_PAD_ENET1_RGMII_RXC__ENET1_RGMII_RXC | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
135 MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
136 MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
137 MX7D_PAD_ENET1_RGMII_RD2__ENET1_RGMII_RD2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
138 MX7D_PAD_ENET1_RGMII_RD3__ENET1_RGMII_RD3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
139 MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
140 MX7D_PAD_SD3_STROBE__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
141 MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
142};
143
144#define FEC1_RST_GPIO IMX_GPIO_NR(6, 11)
145
146static void setup_iomux_fec(void)
147{
148 imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200149 gpio_request(FEC1_RST_GPIO, "phy_rst");
Vanessa Maegima27142c32017-05-08 13:17:28 -0300150 gpio_direction_output(FEC1_RST_GPIO, 0);
151 udelay(500);
152 gpio_set_value(FEC1_RST_GPIO, 1);
153}
154
155int board_eth_init(bd_t *bis)
156{
157 setup_iomux_fec();
158
159 return fecmxc_initialize_multi(bis, 0,
160 CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE);
161}
162
163static int setup_fec(void)
164{
165 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
166 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
167
168 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */
169 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
170 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
171 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
172
Eric Nelsoneadd7322017-08-31 08:34:23 -0700173 return set_clk_enet(ENET_125MHZ);
Vanessa Maegima27142c32017-05-08 13:17:28 -0300174}
175
176int board_phy_config(struct phy_device *phydev)
177{
178 unsigned short val;
179
180 /* To enable AR8035 ouput a 125MHz clk from CLK_25M */
181 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
182 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
183 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
184
185 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
186 val &= 0xffe7;
187 val |= 0x18;
188 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
189
190 /* introduce tx clock delay */
191 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
192 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
193 val |= 0x0100;
194 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
195
196 if (phydev->drv->config)
197 phydev->drv->config(phydev);
198
199 return 0;
200}
201#endif
202
203static void setup_iomux_uart(void)
204{
205 imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads));
206}
207
Vanessa Maegima27142c32017-05-08 13:17:28 -0300208int board_early_init_f(void)
209{
210 setup_iomux_uart();
211
212#ifdef CONFIG_SYS_I2C_MXC
213 setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4);
214#endif
215
216 return 0;
217}
218
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200219#ifdef CONFIG_VIDEO_MXS
220static iomux_v3_cfg_t const lcd_pads[] = {
221 MX7D_PAD_LCD_CLK__LCD_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL),
222 MX7D_PAD_LCD_ENABLE__LCD_ENABLE | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
223 MX7D_PAD_LCD_HSYNC__LCD_HSYNC | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
224 MX7D_PAD_LCD_VSYNC__LCD_VSYNC | MUX_PAD_CTRL(LCD_SYNC_PAD_CTRL),
225 MX7D_PAD_LCD_DATA00__LCD_DATA0 | MUX_PAD_CTRL(LCD_PAD_CTRL),
226 MX7D_PAD_LCD_DATA01__LCD_DATA1 | MUX_PAD_CTRL(LCD_PAD_CTRL),
227 MX7D_PAD_LCD_DATA02__LCD_DATA2 | MUX_PAD_CTRL(LCD_PAD_CTRL),
228 MX7D_PAD_LCD_DATA03__LCD_DATA3 | MUX_PAD_CTRL(LCD_PAD_CTRL),
229 MX7D_PAD_LCD_DATA04__LCD_DATA4 | MUX_PAD_CTRL(LCD_PAD_CTRL),
230 MX7D_PAD_LCD_DATA05__LCD_DATA5 | MUX_PAD_CTRL(LCD_PAD_CTRL),
231 MX7D_PAD_LCD_DATA06__LCD_DATA6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
232 MX7D_PAD_LCD_DATA07__LCD_DATA7 | MUX_PAD_CTRL(LCD_PAD_CTRL),
233 MX7D_PAD_LCD_DATA08__LCD_DATA8 | MUX_PAD_CTRL(LCD_PAD_CTRL),
234 MX7D_PAD_LCD_DATA09__LCD_DATA9 | MUX_PAD_CTRL(LCD_PAD_CTRL),
235 MX7D_PAD_LCD_DATA10__LCD_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL),
236 MX7D_PAD_LCD_DATA11__LCD_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL),
237 MX7D_PAD_LCD_DATA12__LCD_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL),
238 MX7D_PAD_LCD_DATA13__LCD_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL),
239 MX7D_PAD_LCD_DATA14__LCD_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL),
240 MX7D_PAD_LCD_DATA15__LCD_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL),
241 MX7D_PAD_LCD_DATA16__LCD_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL),
242 MX7D_PAD_LCD_DATA17__LCD_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL),
243 MX7D_PAD_LCD_DATA18__LCD_DATA18 | MUX_PAD_CTRL(LCD_PAD_CTRL),
244 MX7D_PAD_LCD_DATA19__LCD_DATA19 | MUX_PAD_CTRL(LCD_PAD_CTRL),
245 MX7D_PAD_LCD_DATA20__LCD_DATA20 | MUX_PAD_CTRL(LCD_PAD_CTRL),
246 MX7D_PAD_LCD_DATA21__LCD_DATA21 | MUX_PAD_CTRL(LCD_PAD_CTRL),
247 MX7D_PAD_LCD_DATA22__LCD_DATA22 | MUX_PAD_CTRL(LCD_PAD_CTRL),
248 MX7D_PAD_LCD_DATA23__LCD_DATA23 | MUX_PAD_CTRL(LCD_PAD_CTRL),
249 MX7D_PAD_GPIO1_IO06__GPIO1_IO6 | MUX_PAD_CTRL(LCD_PAD_CTRL),
250 MX7D_PAD_GPIO1_IO11__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
251};
252
253void setup_lcd(void)
254{
255 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200256 gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness");
257 gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable");
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200258 /* Set Brightness to high */
259 gpio_direction_output(IMX_GPIO_NR(1, 11) , 1);
260 /* Set LCD enable to high */
261 gpio_direction_output(IMX_GPIO_NR(1, 6) , 1);
262}
263#endif
264
Vanessa Maegima27142c32017-05-08 13:17:28 -0300265int board_init(void)
266{
267 /* address of boot parameters */
268 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
269
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200270#ifdef CONFIG_VIDEO_MXS
271 setup_lcd();
272#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -0300273#ifdef CONFIG_FEC_MXC
274 setup_fec();
275#endif
276
277 return 0;
278}
279
280int board_late_init(void)
281{
282 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
283
284 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
285
286 set_wdog_reset(wdog);
287
288 /*
289 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
290 * since we use PMIC_PWRON to reset the board.
291 */
292 clrsetbits_le16(&wdog->wcr, 0, 0x10);
293
294 return 0;
295}
296
297int checkboard(void)
298{
299 puts("Board: i.MX7D PICOSOM\n");
300
301 return 0;
302}
303
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300304static iomux_v3_cfg_t const usb_otg2_pads[] = {
305 MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL),
306};
307
308int board_ehci_hcd_init(int port)
309{
310 switch (port) {
311 case 0:
312 break;
313 case 1:
314 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
315 ARRAY_SIZE(usb_otg2_pads));
316 break;
317 default:
318 return -EINVAL;
319 }
320 return 0;
321}
322
Vanessa Maegima27142c32017-05-08 13:17:28 -0300323int board_usb_phy_mode(int port)
324{
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300325 switch (port) {
326 case 0:
327 return USB_INIT_DEVICE;
328 case 1:
329 return USB_INIT_HOST;
330 default:
331 return -EINVAL;
332 }
333 return 0;
Vanessa Maegima27142c32017-05-08 13:17:28 -0300334}