blob: 916220516e4a09cd3a4befca3bedfcdc58d40370 [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>
Vanessa Maegima27142c32017-05-08 13:17:28 -030019#include <power/pmic.h>
20#include <power/pfuze3000_pmic.h>
21#include "../../freescale/common/pfuze.h"
Joris Offougadaf2be12019-08-30 14:44:36 +020022#ifdef CONFIG_DM_VIDEO
23#include <bmp_logo_data.h>
24#include <video.h>
25#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -030026
27DECLARE_GLOBAL_DATA_PTR;
28
29#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
30 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
31
Vanessa Maegima27142c32017-05-08 13:17:28 -030032#define ENET_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM)
33#define ENET_PAD_CTRL_MII (PAD_CTL_DSE_3P3V_32OHM)
34
35#define ENET_RX_PAD_CTRL (PAD_CTL_PUS_PU100KOHM | PAD_CTL_DSE_3P3V_49OHM)
36
37#define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
38 PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU100KOHM)
39
Fabio Estevamfb3532d2018-12-11 16:40:38 -020040
41#define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
42 PAD_CTL_DSE_3P3V_49OHM)
43
44#define LCD_SYNC_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_PU100KOHM | \
45 PAD_CTL_DSE_3P3V_196OHM)
46
Vanessa Maegima27142c32017-05-08 13:17:28 -030047#ifdef CONFIG_SYS_I2C_MXC
48#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
Fabio Estevamfb3532d2018-12-11 16:40:38 -020049
Vanessa Maegima27142c32017-05-08 13:17:28 -030050/* I2C4 for PMIC */
51static struct i2c_pads_info i2c_pad_info4 = {
52 .scl = {
53 .i2c_mode = MX7D_PAD_SAI1_RX_SYNC__I2C4_SCL | PC,
54 .gpio_mode = MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16 | PC,
55 .gp = IMX_GPIO_NR(6, 16),
56 },
57 .sda = {
58 .i2c_mode = MX7D_PAD_SAI1_RX_BCLK__I2C4_SDA | PC,
59 .gpio_mode = MX7D_PAD_SAI1_RX_BCLK__GPIO6_IO17 | PC,
60 .gp = IMX_GPIO_NR(6, 17),
61 },
62};
63#endif
64
65int dram_init(void)
66{
Fabio Estevam6ed39812018-06-29 15:19:11 -030067 gd->ram_size = imx_ddr_size();
Vanessa Maegima27142c32017-05-08 13:17:28 -030068
Jun Niefeb13442019-05-08 14:38:32 +080069 /* Subtract the defined OPTEE runtime firmware length */
70#ifdef CONFIG_OPTEE_TZDRAM_SIZE
71 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
72#endif
73
Vanessa Maegima27142c32017-05-08 13:17:28 -030074 return 0;
75}
76
77#ifdef CONFIG_POWER
78#define I2C_PMIC 3
79int power_init_board(void)
80{
81 struct pmic *p;
82 int ret;
83 unsigned int reg, rev_id;
84
85 ret = power_pfuze3000_init(I2C_PMIC);
86 if (ret)
87 return ret;
88
89 p = pmic_get("PFUZE3000");
90 ret = pmic_probe(p);
Jun Nie8600eef2019-05-08 14:38:36 +080091 if (ret) {
92 printf("Warning: Cannot find PMIC PFUZE3000\n");
93 printf("\tPower consumption is not optimized.\n");
94 return 0;
95 }
Vanessa Maegima27142c32017-05-08 13:17:28 -030096
97 pmic_reg_read(p, PFUZE3000_DEVICEID, &reg);
98 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
99 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
100
101 /* disable Low Power Mode during standby mode */
102 pmic_reg_read(p, PFUZE3000_LDOGCTL, &reg);
103 reg |= 0x1;
104 pmic_reg_write(p, PFUZE3000_LDOGCTL, reg);
105
106 /* SW1A/1B mode set to APS/APS */
107 reg = 0x8;
108 pmic_reg_write(p, PFUZE3000_SW1AMODE, reg);
109 pmic_reg_write(p, PFUZE3000_SW1BMODE, reg);
110
111 /* SW1A/1B standby voltage set to 1.025V */
112 reg = 0xd;
113 pmic_reg_write(p, PFUZE3000_SW1ASTBY, reg);
114 pmic_reg_write(p, PFUZE3000_SW1BSTBY, reg);
115
116 /* decrease SW1B normal voltage to 0.975V */
117 pmic_reg_read(p, PFUZE3000_SW1BVOLT, &reg);
118 reg &= ~0x1f;
119 reg |= PFUZE3000_SW1AB_SETP(975);
120 pmic_reg_write(p, PFUZE3000_SW1BVOLT, reg);
121
122 return 0;
123}
124#endif
125
126static iomux_v3_cfg_t const wdog_pads[] = {
127 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
128};
129
130static iomux_v3_cfg_t const uart5_pads[] = {
131 MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
132 MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
133};
134
Vanessa Maegima27142c32017-05-08 13:17:28 -0300135#ifdef CONFIG_FEC_MXC
136static iomux_v3_cfg_t const fec1_pads[] = {
137 MX7D_PAD_SD2_CD_B__ENET1_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
138 MX7D_PAD_SD2_WP__ENET1_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL_MII),
139 MX7D_PAD_ENET1_RGMII_TXC__ENET1_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
140 MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
141 MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
142 MX7D_PAD_ENET1_RGMII_TD2__ENET1_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
143 MX7D_PAD_ENET1_RGMII_TD3__ENET1_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
144 MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
145 MX7D_PAD_ENET1_RGMII_RXC__ENET1_RGMII_RXC | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
146 MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
147 MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
148 MX7D_PAD_ENET1_RGMII_RD2__ENET1_RGMII_RD2 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
149 MX7D_PAD_ENET1_RGMII_RD3__ENET1_RGMII_RD3 | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
150 MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL | MUX_PAD_CTRL(ENET_RX_PAD_CTRL),
151 MX7D_PAD_SD3_STROBE__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
152 MX7D_PAD_SD3_RESET_B__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
153};
154
155#define FEC1_RST_GPIO IMX_GPIO_NR(6, 11)
156
157static void setup_iomux_fec(void)
158{
159 imx_iomux_v3_setup_multiple_pads(fec1_pads, ARRAY_SIZE(fec1_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200160 gpio_request(FEC1_RST_GPIO, "phy_rst");
Vanessa Maegima27142c32017-05-08 13:17:28 -0300161 gpio_direction_output(FEC1_RST_GPIO, 0);
162 udelay(500);
163 gpio_set_value(FEC1_RST_GPIO, 1);
164}
165
166int board_eth_init(bd_t *bis)
167{
168 setup_iomux_fec();
169
170 return fecmxc_initialize_multi(bis, 0,
171 CONFIG_FEC_MXC_PHYADDR, IMX_FEC_BASE);
172}
173
174static int setup_fec(void)
175{
176 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
177 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
178
179 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */
180 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
181 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
182 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
183
Eric Nelsoneadd7322017-08-31 08:34:23 -0700184 return set_clk_enet(ENET_125MHZ);
Vanessa Maegima27142c32017-05-08 13:17:28 -0300185}
186
187int board_phy_config(struct phy_device *phydev)
188{
189 unsigned short val;
190
191 /* To enable AR8035 ouput a 125MHz clk from CLK_25M */
192 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
193 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
194 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
195
196 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
197 val &= 0xffe7;
198 val |= 0x18;
199 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
200
201 /* introduce tx clock delay */
202 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
203 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
204 val |= 0x0100;
205 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
206
207 if (phydev->drv->config)
208 phydev->drv->config(phydev);
209
210 return 0;
211}
212#endif
213
214static void setup_iomux_uart(void)
215{
216 imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads));
217}
218
Vanessa Maegima27142c32017-05-08 13:17:28 -0300219int board_early_init_f(void)
220{
221 setup_iomux_uart();
222
223#ifdef CONFIG_SYS_I2C_MXC
224 setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4);
225#endif
226
227 return 0;
228}
229
Joris Offougadaf2be12019-08-30 14:44:36 +0200230#ifdef CONFIG_DM_VIDEO
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200231static iomux_v3_cfg_t const lcd_pads[] = {
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200232 MX7D_PAD_GPIO1_IO11__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
233};
234
235void setup_lcd(void)
236{
237 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200238 gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness");
239 gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable");
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200240 /* Set Brightness to high */
241 gpio_direction_output(IMX_GPIO_NR(1, 11) , 1);
242 /* Set LCD enable to high */
243 gpio_direction_output(IMX_GPIO_NR(1, 6) , 1);
244}
245#endif
246
Vanessa Maegima27142c32017-05-08 13:17:28 -0300247int board_init(void)
248{
249 /* address of boot parameters */
250 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
251
Joris Offougadaf2be12019-08-30 14:44:36 +0200252#ifdef CONFIG_DM_VIDEO
253 struct udevice *dev;
254 int ret;
255
256 ret = uclass_get_device(UCLASS_VIDEO, 0, &dev);
257 if (ret)
258 return ret;
259
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200260 setup_lcd();
Joris Offougadaf2be12019-08-30 14:44:36 +0200261
262 ret = video_bmp_display(dev, (ulong)bmp_logo_bitmap, 0, 0, true);
263 if (ret)
264 return ret;
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200265#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -0300266#ifdef CONFIG_FEC_MXC
267 setup_fec();
268#endif
269
270 return 0;
271}
272
273int board_late_init(void)
274{
275 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
276
277 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
278
279 set_wdog_reset(wdog);
280
281 /*
282 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
283 * since we use PMIC_PWRON to reset the board.
284 */
285 clrsetbits_le16(&wdog->wcr, 0, 0x10);
286
287 return 0;
288}
289
290int checkboard(void)
291{
292 puts("Board: i.MX7D PICOSOM\n");
293
294 return 0;
295}
296
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300297static iomux_v3_cfg_t const usb_otg2_pads[] = {
298 MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL),
299};
300
301int board_ehci_hcd_init(int port)
302{
303 switch (port) {
304 case 0:
305 break;
306 case 1:
307 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
308 ARRAY_SIZE(usb_otg2_pads));
309 break;
310 default:
311 return -EINVAL;
312 }
313 return 0;
314}
315