blob: 5d2f815d2348f31b4aee41829d41fb0a7d0497fa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam26e9c972013-04-10 09:32:58 +00002/*
3 * Copyright (C) 2013 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
Fabio Estevam26e9c972013-04-10 09:32:58 +00006 */
7
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000010#include <asm/arch/clock.h>
11#include <asm/arch/iomux.h>
Peng Fane8c50ce2015-08-17 16:11:05 +080012#include <asm/arch/crm_regs.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000013#include <asm/arch/imx-regs.h>
Peng Fane8c50ce2015-08-17 16:11:05 +080014#include <asm/arch/mx6-ddr.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000015#include <asm/arch/mx6-pins.h>
16#include <asm/arch/sys_proto.h>
17#include <asm/gpio.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/mxc_i2c.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000020#include <asm/io.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040021#include <linux/sizes.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000022#include <common.h>
Yangbo Lu73340382019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Peng Fane7e8b2a2015-02-12 09:36:29 +080024#include <i2c.h>
Fabio Estevam26e9c972013-04-10 09:32:58 +000025#include <mmc.h>
Peng Fane7e8b2a2015-02-12 09:36:29 +080026#include <power/pmic.h>
27#include <power/pfuze100_pmic.h>
28#include "../common/pfuze.h"
Fabio Estevam26e9c972013-04-10 09:32:58 +000029
30DECLARE_GLOBAL_DATA_PTR;
31
Benoît Thébaudeau21670242013-04-26 01:34:47 +000032#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
33 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
34 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam26e9c972013-04-10 09:32:58 +000035
Benoît Thébaudeau21670242013-04-26 01:34:47 +000036#define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \
37 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
38 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam26e9c972013-04-10 09:32:58 +000039
Fabio Estevam67b8b9d2013-09-13 00:36:28 -030040#define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
41 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
42 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
43
Fabio Estevam4d83ec72015-02-28 14:25:46 -030044#define OTGID_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
45 PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW |\
46 PAD_CTL_DSE_80ohm | PAD_CTL_HYS | \
47 PAD_CTL_SRE_FAST)
48
Fabio Estevam25eb9612016-03-11 10:50:22 -030049#define ETH_PHY_POWER IMX_GPIO_NR(4, 21)
Fabio Estevam67b8b9d2013-09-13 00:36:28 -030050
Fabio Estevam26e9c972013-04-10 09:32:58 +000051int dram_init(void)
52{
Vanessa Maegimaa9e4f912016-06-09 15:28:31 -030053 gd->ram_size = imx_ddr_size();
Fabio Estevam26e9c972013-04-10 09:32:58 +000054
55 return 0;
56}
57
58static iomux_v3_cfg_t const uart1_pads[] = {
59 MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
60 MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
61};
62
Tom Rinid5deeeb2017-05-08 22:14:23 -040063#ifdef CONFIG_SPL_BUILD
Ye.Lia056ba52014-10-30 18:30:54 +080064static iomux_v3_cfg_t const usdhc1_pads[] = {
65 /* 8 bit SD */
66 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
67 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
68 MX6_PAD_SD1_DAT0__USDHC1_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
69 MX6_PAD_SD1_DAT1__USDHC1_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
70 MX6_PAD_SD1_DAT2__USDHC1_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
71 MX6_PAD_SD1_DAT3__USDHC1_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
72 MX6_PAD_SD1_DAT4__USDHC1_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
73 MX6_PAD_SD1_DAT5__USDHC1_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
74 MX6_PAD_SD1_DAT6__USDHC1_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
75 MX6_PAD_SD1_DAT7__USDHC1_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
76
77 /*CD pin*/
78 MX6_PAD_KEY_ROW7__GPIO_4_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
79};
80
Fabio Estevam26e9c972013-04-10 09:32:58 +000081static iomux_v3_cfg_t const usdhc2_pads[] = {
82 MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
83 MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
84 MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
85 MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
86 MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
87 MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Ye.Lia056ba52014-10-30 18:30:54 +080088
89 /*CD pin*/
90 MX6_PAD_SD2_DAT7__GPIO_5_0 | MUX_PAD_CTRL(NO_PAD_CTRL),
91};
92
93static iomux_v3_cfg_t const usdhc3_pads[] = {
94 MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97 MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
98 MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
99 MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
100
101 /*CD pin*/
102 MX6_PAD_REF_CLK_32K__GPIO_3_22 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevam26e9c972013-04-10 09:32:58 +0000103};
Tom Rinid5deeeb2017-05-08 22:14:23 -0400104#endif
Fabio Estevam26e9c972013-04-10 09:32:58 +0000105
106static void setup_iomux_uart(void)
107{
108 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
109}
110
Peng Fan03a43df2016-01-28 16:51:27 +0800111int board_mmc_get_env_dev(int devno)
112{
113 return devno;
114}
115
Peng Fanc477ae72017-03-04 10:45:44 +0800116#ifdef CONFIG_DM_PMIC_PFUZE100
117int power_init_board(void)
Fabio Estevam26e9c972013-04-10 09:32:58 +0000118{
Peng Fanc477ae72017-03-04 10:45:44 +0800119 struct udevice *dev;
120 int ret;
121 u32 dev_id, rev_id, i;
122 u32 switch_num = 6;
123 u32 offset = PFUZE100_SW1CMODE;
Ye.Lia056ba52014-10-30 18:30:54 +0800124
Fabio Estevamc35a1f42019-12-20 14:59:28 -0300125 ret = pmic_get("pfuze100@08", &dev);
Peng Fanc477ae72017-03-04 10:45:44 +0800126 if (ret == -ENODEV)
127 return 0;
Ye.Lia056ba52014-10-30 18:30:54 +0800128
Peng Fanc477ae72017-03-04 10:45:44 +0800129 if (ret != 0)
130 return ret;
Fabio Estevam26e9c972013-04-10 09:32:58 +0000131
Peng Fanc477ae72017-03-04 10:45:44 +0800132 dev_id = pmic_reg_read(dev, PFUZE100_DEVICEID);
133 rev_id = pmic_reg_read(dev, PFUZE100_REVID);
134 printf("PMIC: PFUZE100! DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
Ye.Lia056ba52014-10-30 18:30:54 +0800135
Peng Fanc477ae72017-03-04 10:45:44 +0800136 /* set SW1AB staby volatage 0.975V */
137 pmic_clrsetbits(dev, PFUZE100_SW1ABSTBY, 0x3f, 0x1b);
Ye.Lia056ba52014-10-30 18:30:54 +0800138
Peng Fanc477ae72017-03-04 10:45:44 +0800139 /* set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */
140 pmic_clrsetbits(dev, PFUZE100_SW1ABCONF, 0xc0, 0x40);
Fabio Estevam26e9c972013-04-10 09:32:58 +0000141
Peng Fanc477ae72017-03-04 10:45:44 +0800142 /* set SW1C staby volatage 0.975V */
143 pmic_clrsetbits(dev, PFUZE100_SW1CSTBY, 0x3f, 0x1b);
Peng Fane8c50ce2015-08-17 16:11:05 +0800144
Peng Fanc477ae72017-03-04 10:45:44 +0800145 /* set SW1C/VDDSOC step ramp up time to from 16us to 4us/25mV */
146 pmic_clrsetbits(dev, PFUZE100_SW1CCONF, 0xc0, 0x40);
Peng Fane8c50ce2015-08-17 16:11:05 +0800147
Peng Fanc477ae72017-03-04 10:45:44 +0800148 /* Init mode to APS_PFM */
149 pmic_reg_write(dev, PFUZE100_SW1ABMODE, APS_PFM);
Fabio Estevam26e9c972013-04-10 09:32:58 +0000150
Peng Fanc477ae72017-03-04 10:45:44 +0800151 for (i = 0; i < switch_num - 1; i++)
152 pmic_reg_write(dev, offset + i * SWITCH_SIZE, APS_PFM);
Peng Fane7e8b2a2015-02-12 09:36:29 +0800153
Peng Fanc477ae72017-03-04 10:45:44 +0800154 return 0;
Peng Fane7e8b2a2015-02-12 09:36:29 +0800155}
156#endif
157
Fabio Estevam67b8b9d2013-09-13 00:36:28 -0300158#ifdef CONFIG_FEC_MXC
Fabio Estevam67b8b9d2013-09-13 00:36:28 -0300159
160static int setup_fec(void)
161{
Fabio Estevamceb74c42014-07-09 17:59:54 -0300162 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam67b8b9d2013-09-13 00:36:28 -0300163
164 /* clear gpr1[14], gpr1[18:17] to select anatop clock */
165 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
166
Peng Fan967a83b2015-08-12 17:46:50 +0800167 return enable_fec_anatop_clock(0, ENET_50MHZ);
Fabio Estevam67b8b9d2013-09-13 00:36:28 -0300168}
169#endif
170
Fabio Estevam26e9c972013-04-10 09:32:58 +0000171int board_early_init_f(void)
172{
173 setup_iomux_uart();
Peng Fanc477ae72017-03-04 10:45:44 +0800174
Fabio Estevam26e9c972013-04-10 09:32:58 +0000175 return 0;
176}
177
178int board_init(void)
179{
180 /* address of boot parameters */
181 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
182
Fabio Estevam67b8b9d2013-09-13 00:36:28 -0300183#ifdef CONFIG_FEC_MXC
184 setup_fec();
185#endif
Peng Fandd6624a2014-11-10 08:50:41 +0800186
Fabio Estevam26e9c972013-04-10 09:32:58 +0000187 return 0;
188}
189
Fabio Estevam26e9c972013-04-10 09:32:58 +0000190int checkboard(void)
191{
192 puts("Board: MX6SLEVK\n");
193
194 return 0;
195}
Peng Fane8c50ce2015-08-17 16:11:05 +0800196
197#ifdef CONFIG_SPL_BUILD
198#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900199#include <linux/libfdt.h>
Peng Fane8c50ce2015-08-17 16:11:05 +0800200
Peng Fanc477ae72017-03-04 10:45:44 +0800201#define USDHC1_CD_GPIO IMX_GPIO_NR(4, 7)
202#define USDHC2_CD_GPIO IMX_GPIO_NR(5, 0)
203#define USDHC3_CD_GPIO IMX_GPIO_NR(3, 22)
204
205static struct fsl_esdhc_cfg usdhc_cfg[3] = {
206 {USDHC1_BASE_ADDR},
207 {USDHC2_BASE_ADDR, 0, 4},
208 {USDHC3_BASE_ADDR, 0, 4},
209};
210
211int board_mmc_getcd(struct mmc *mmc)
212{
213 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
214 int ret = 0;
215
216 switch (cfg->esdhc_base) {
217 case USDHC1_BASE_ADDR:
Fabio Estevam8dbdaa72017-10-10 13:43:42 -0300218 gpio_request(USDHC1_CD_GPIO, "cd1_gpio");
Peng Fanc477ae72017-03-04 10:45:44 +0800219 ret = !gpio_get_value(USDHC1_CD_GPIO);
220 break;
221 case USDHC2_BASE_ADDR:
Fabio Estevam8dbdaa72017-10-10 13:43:42 -0300222 gpio_request(USDHC2_CD_GPIO, "cd2_gpio");
Peng Fanc477ae72017-03-04 10:45:44 +0800223 ret = !gpio_get_value(USDHC2_CD_GPIO);
224 break;
225 case USDHC3_BASE_ADDR:
Fabio Estevam8dbdaa72017-10-10 13:43:42 -0300226 gpio_request(USDHC3_CD_GPIO, "cd3_gpio");
Peng Fanc477ae72017-03-04 10:45:44 +0800227 ret = !gpio_get_value(USDHC3_CD_GPIO);
228 break;
229 }
230
231 return ret;
232}
233
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900234int board_mmc_init(struct bd_info *bis)
Peng Fanc477ae72017-03-04 10:45:44 +0800235{
236 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
237 u32 val;
238 u32 port;
239
240 val = readl(&src_regs->sbmr1);
241
242 /* Boot from USDHC */
243 port = (val >> 11) & 0x3;
244 switch (port) {
245 case 0:
246 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
247 ARRAY_SIZE(usdhc1_pads));
248 gpio_direction_input(USDHC1_CD_GPIO);
249 usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
250 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
251 break;
252 case 1:
253 imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
254 ARRAY_SIZE(usdhc2_pads));
255 gpio_direction_input(USDHC2_CD_GPIO);
256 usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
257 usdhc_cfg[0].max_bus_width = 4;
258 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
259 break;
260 case 2:
261 imx_iomux_v3_setup_multiple_pads(usdhc3_pads,
262 ARRAY_SIZE(usdhc3_pads));
263 gpio_direction_input(USDHC3_CD_GPIO);
264 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
265 usdhc_cfg[0].max_bus_width = 4;
266 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
267 break;
268 }
269
270 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
271 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
272}
273
Peng Fane8c50ce2015-08-17 16:11:05 +0800274const struct mx6sl_iomux_ddr_regs mx6_ddr_ioregs = {
275 .dram_sdqs0 = 0x00003030,
276 .dram_sdqs1 = 0x00003030,
277 .dram_sdqs2 = 0x00003030,
278 .dram_sdqs3 = 0x00003030,
279 .dram_dqm0 = 0x00000030,
280 .dram_dqm1 = 0x00000030,
281 .dram_dqm2 = 0x00000030,
282 .dram_dqm3 = 0x00000030,
283 .dram_cas = 0x00000030,
284 .dram_ras = 0x00000030,
285 .dram_sdclk_0 = 0x00000028,
286 .dram_reset = 0x00000030,
287 .dram_sdba2 = 0x00000000,
288 .dram_odt0 = 0x00000008,
289 .dram_odt1 = 0x00000008,
290};
291
292const struct mx6sl_iomux_grp_regs mx6_grp_ioregs = {
293 .grp_b0ds = 0x00000030,
294 .grp_b1ds = 0x00000030,
295 .grp_b2ds = 0x00000030,
296 .grp_b3ds = 0x00000030,
297 .grp_addds = 0x00000030,
298 .grp_ctlds = 0x00000030,
299 .grp_ddrmode_ctl = 0x00020000,
300 .grp_ddrpke = 0x00000000,
301 .grp_ddrmode = 0x00020000,
302 .grp_ddr_type = 0x00080000,
303};
304
305const struct mx6_mmdc_calibration mx6_mmcd_calib = {
306 .p0_mpdgctrl0 = 0x20000000,
307 .p0_mpdgctrl1 = 0x00000000,
308 .p0_mprddlctl = 0x4241444a,
309 .p0_mpwrdlctl = 0x3030312b,
310 .mpzqlp2ctl = 0x1b4700c7,
311};
312
313static struct mx6_lpddr2_cfg mem_ddr = {
314 .mem_speed = 800,
315 .density = 4,
316 .width = 32,
317 .banks = 8,
318 .rowaddr = 14,
319 .coladdr = 10,
320 .trcd_lp = 2000,
321 .trppb_lp = 2000,
322 .trpab_lp = 2250,
323 .trasmin = 4200,
324};
325
326static void ccgr_init(void)
327{
328 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
329
330 writel(0xFFFFFFFF, &ccm->CCGR0);
331 writel(0xFFFFFFFF, &ccm->CCGR1);
332 writel(0xFFFFFFFF, &ccm->CCGR2);
333 writel(0xFFFFFFFF, &ccm->CCGR3);
334 writel(0xFFFFFFFF, &ccm->CCGR4);
335 writel(0xFFFFFFFF, &ccm->CCGR5);
336 writel(0xFFFFFFFF, &ccm->CCGR6);
337
338 writel(0x00260324, &ccm->cbcmr);
339}
340
341static void spl_dram_init(void)
342{
343 struct mx6_ddr_sysinfo sysinfo = {
344 .dsize = mem_ddr.width / 32,
345 .cs_density = 20,
346 .ncs = 2,
347 .cs1_mirror = 0,
348 .walat = 0,
349 .ralat = 2,
350 .mif3_mode = 3,
351 .bi_on = 1,
352 .rtt_wr = 0, /* LPDDR2 does not need rtt_wr rtt_nom */
353 .rtt_nom = 0,
354 .sde_to_rst = 0, /* LPDDR2 does not need this field */
355 .rst_to_cke = 0x10, /* JEDEC value for LPDDR2: 200us */
356 .ddr_type = DDR_TYPE_LPDDR2,
Fabio Estevamcb3c1212016-08-29 20:37:15 -0300357 .refsel = 0, /* Refresh cycles at 64KHz */
358 .refr = 3, /* 4 refresh commands per refresh cycle */
Peng Fane8c50ce2015-08-17 16:11:05 +0800359 };
360 mx6sl_dram_iocfg(32, &mx6_ddr_ioregs, &mx6_grp_ioregs);
361 mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr);
362}
363
364void board_init_f(ulong dummy)
365{
366 /* setup AIPS and disable watchdog */
367 arch_cpu_init();
368
369 ccgr_init();
370
371 /* iomux and setup of i2c */
372 board_early_init_f();
373
374 /* setup GP timer */
375 timer_init();
376
377 /* UART clocks enabled and gd valid - init serial console */
378 preloader_console_init();
379
380 /* DDR initialization */
381 spl_dram_init();
382
383 /* Clear the BSS. */
384 memset(__bss_start, 0, __bss_end - __bss_start);
385
386 /* load/boot image from boot device */
387 board_init_r(NULL, 0);
388}
Peng Fane8c50ce2015-08-17 16:11:05 +0800389#endif