blob: b7ca2e1315e5f11ac30103c81564a4e7d3f8c90d [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
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -03007#include <asm/arch/clock.h>
8#include <asm/arch/crm_regs.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/mx7-pins.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020013#include <asm/mach-imx/iomux-v3.h>
14#include <asm/mach-imx/mxc_i2c.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030015#include <asm/io.h>
16#include <common.h>
Vanessa Maegima27142c32017-05-08 13:17:28 -030017#include <i2c.h>
18#include <miiphy.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"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | \
26 PAD_CTL_PUS_PU100KOHM | PAD_CTL_HYS)
27
Vanessa Maegima27142c32017-05-08 13:17:28 -030028#define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
29 PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU100KOHM)
30
31#ifdef CONFIG_SYS_I2C_MXC
32#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
Fabio Estevamfb3532d2018-12-11 16:40:38 -020033
Vanessa Maegima27142c32017-05-08 13:17:28 -030034/* I2C4 for PMIC */
35static struct i2c_pads_info i2c_pad_info4 = {
36 .scl = {
37 .i2c_mode = MX7D_PAD_SAI1_RX_SYNC__I2C4_SCL | PC,
38 .gpio_mode = MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16 | PC,
39 .gp = IMX_GPIO_NR(6, 16),
40 },
41 .sda = {
42 .i2c_mode = MX7D_PAD_SAI1_RX_BCLK__I2C4_SDA | PC,
43 .gpio_mode = MX7D_PAD_SAI1_RX_BCLK__GPIO6_IO17 | PC,
44 .gp = IMX_GPIO_NR(6, 17),
45 },
46};
47#endif
48
49int dram_init(void)
50{
Fabio Estevam6ed39812018-06-29 15:19:11 -030051 gd->ram_size = imx_ddr_size();
Vanessa Maegima27142c32017-05-08 13:17:28 -030052
Jun Niefeb13442019-05-08 14:38:32 +080053 /* Subtract the defined OPTEE runtime firmware length */
54#ifdef CONFIG_OPTEE_TZDRAM_SIZE
55 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
56#endif
57
Vanessa Maegima27142c32017-05-08 13:17:28 -030058 return 0;
59}
60
61#ifdef CONFIG_POWER
62#define I2C_PMIC 3
63int power_init_board(void)
64{
65 struct pmic *p;
66 int ret;
67 unsigned int reg, rev_id;
68
69 ret = power_pfuze3000_init(I2C_PMIC);
70 if (ret)
71 return ret;
72
73 p = pmic_get("PFUZE3000");
74 ret = pmic_probe(p);
Jun Nie8600eef2019-05-08 14:38:36 +080075 if (ret) {
76 printf("Warning: Cannot find PMIC PFUZE3000\n");
77 printf("\tPower consumption is not optimized.\n");
78 return 0;
79 }
Vanessa Maegima27142c32017-05-08 13:17:28 -030080
81 pmic_reg_read(p, PFUZE3000_DEVICEID, &reg);
82 pmic_reg_read(p, PFUZE3000_REVID, &rev_id);
83 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
84
85 /* disable Low Power Mode during standby mode */
86 pmic_reg_read(p, PFUZE3000_LDOGCTL, &reg);
87 reg |= 0x1;
88 pmic_reg_write(p, PFUZE3000_LDOGCTL, reg);
89
90 /* SW1A/1B mode set to APS/APS */
91 reg = 0x8;
92 pmic_reg_write(p, PFUZE3000_SW1AMODE, reg);
93 pmic_reg_write(p, PFUZE3000_SW1BMODE, reg);
94
95 /* SW1A/1B standby voltage set to 1.025V */
96 reg = 0xd;
97 pmic_reg_write(p, PFUZE3000_SW1ASTBY, reg);
98 pmic_reg_write(p, PFUZE3000_SW1BSTBY, reg);
99
100 /* decrease SW1B normal voltage to 0.975V */
101 pmic_reg_read(p, PFUZE3000_SW1BVOLT, &reg);
102 reg &= ~0x1f;
103 reg |= PFUZE3000_SW1AB_SETP(975);
104 pmic_reg_write(p, PFUZE3000_SW1BVOLT, reg);
105
106 return 0;
107}
108#endif
109
110static iomux_v3_cfg_t const wdog_pads[] = {
111 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
112};
113
114static iomux_v3_cfg_t const uart5_pads[] = {
115 MX7D_PAD_I2C4_SCL__UART5_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
116 MX7D_PAD_I2C4_SDA__UART5_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
117};
118
Vanessa Maegima27142c32017-05-08 13:17:28 -0300119#ifdef CONFIG_FEC_MXC
Vanessa Maegima27142c32017-05-08 13:17:28 -0300120static int setup_fec(void)
121{
122 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs
123 = (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
124
125 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17] */
126 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
127 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
128 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
129
Eric Nelsoneadd7322017-08-31 08:34:23 -0700130 return set_clk_enet(ENET_125MHZ);
Vanessa Maegima27142c32017-05-08 13:17:28 -0300131}
132
133int board_phy_config(struct phy_device *phydev)
134{
135 unsigned short val;
136
137 /* To enable AR8035 ouput a 125MHz clk from CLK_25M */
138 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
139 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
140 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
141
142 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
143 val &= 0xffe7;
144 val |= 0x18;
145 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
146
147 /* introduce tx clock delay */
148 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
149 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
150 val |= 0x0100;
151 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
152
153 if (phydev->drv->config)
154 phydev->drv->config(phydev);
155
156 return 0;
157}
158#endif
159
160static void setup_iomux_uart(void)
161{
162 imx_iomux_v3_setup_multiple_pads(uart5_pads, ARRAY_SIZE(uart5_pads));
163}
164
Vanessa Maegima27142c32017-05-08 13:17:28 -0300165int board_early_init_f(void)
166{
167 setup_iomux_uart();
168
169#ifdef CONFIG_SYS_I2C_MXC
170 setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4);
171#endif
172
173 return 0;
174}
175
Joris Offougadaf2be12019-08-30 14:44:36 +0200176#ifdef CONFIG_DM_VIDEO
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200177void setup_lcd(void)
178{
Joris Offouga0dc6a40e2019-04-04 14:00:54 +0200179 gpio_request(IMX_GPIO_NR(1, 11), "lcd_brightness");
180 gpio_request(IMX_GPIO_NR(1, 6), "lcd_enable");
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200181 /* Set Brightness to high */
182 gpio_direction_output(IMX_GPIO_NR(1, 11) , 1);
183 /* Set LCD enable to high */
184 gpio_direction_output(IMX_GPIO_NR(1, 6) , 1);
185}
186#endif
187
Vanessa Maegima27142c32017-05-08 13:17:28 -0300188int board_init(void)
189{
190 /* address of boot parameters */
191 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
192
Joris Offougadaf2be12019-08-30 14:44:36 +0200193#ifdef CONFIG_DM_VIDEO
Fabio Estevamfb3532d2018-12-11 16:40:38 -0200194 setup_lcd();
195#endif
Vanessa Maegima27142c32017-05-08 13:17:28 -0300196#ifdef CONFIG_FEC_MXC
197 setup_fec();
198#endif
199
200 return 0;
201}
202
203int board_late_init(void)
204{
205 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
206
207 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
208
209 set_wdog_reset(wdog);
210
211 /*
212 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
213 * since we use PMIC_PWRON to reset the board.
214 */
215 clrsetbits_le16(&wdog->wcr, 0, 0x10);
216
217 return 0;
218}
219
220int checkboard(void)
221{
222 puts("Board: i.MX7D PICOSOM\n");
223
224 return 0;
225}
226
Fabio Estevam7d8a02a2018-09-28 11:22:39 -0300227static iomux_v3_cfg_t const usb_otg2_pads[] = {
228 MX7D_PAD_UART3_CTS_B__USB_OTG2_PWR | MUX_PAD_CTRL(NO_PAD_CTRL),
229};
230
231int board_ehci_hcd_init(int port)
232{
233 switch (port) {
234 case 0:
235 break;
236 case 1:
237 imx_iomux_v3_setup_multiple_pads(usb_otg2_pads,
238 ARRAY_SIZE(usb_otg2_pads));
239 break;
240 default:
241 return -EINVAL;
242 }
243 return 0;
244}
245