arm: juno: Use PSCI based reset
[oweals/u-boot.git] / board / freescale / mx6slevk / mx6slevk.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2013 Freescale Semiconductor, Inc.
4  *
5  * Author: Fabio Estevam <fabio.estevam@freescale.com>
6  */
7
8 #include <asm/arch/clock.h>
9 #include <asm/arch/iomux.h>
10 #include <asm/arch/crm_regs.h>
11 #include <asm/arch/imx-regs.h>
12 #include <asm/arch/mx6-ddr.h>
13 #include <asm/arch/mx6-pins.h>
14 #include <asm/arch/sys_proto.h>
15 #include <asm/gpio.h>
16 #include <asm/mach-imx/iomux-v3.h>
17 #include <asm/mach-imx/mxc_i2c.h>
18 #include <asm/io.h>
19 #include <linux/sizes.h>
20 #include <common.h>
21 #include <fsl_esdhc_imx.h>
22 #include <i2c.h>
23 #include <mmc.h>
24 #include <power/pmic.h>
25 #include <power/pfuze100_pmic.h>
26 #include "../common/pfuze.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define UART_PAD_CTRL  (PAD_CTL_PUS_100K_UP |                   \
31         PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm |                 \
32         PAD_CTL_SRE_FAST  | PAD_CTL_HYS)
33
34 #define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP |                    \
35         PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm |                 \
36         PAD_CTL_SRE_FAST  | PAD_CTL_HYS)
37
38 #define ENET_PAD_CTRL  (PAD_CTL_PKE | PAD_CTL_PUE |             \
39         PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED   |             \
40         PAD_CTL_DSE_40ohm   | PAD_CTL_HYS)
41
42 #define OTGID_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE |             \
43                         PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW |\
44                         PAD_CTL_DSE_80ohm | PAD_CTL_HYS |       \
45                         PAD_CTL_SRE_FAST)
46
47 #define ETH_PHY_POWER   IMX_GPIO_NR(4, 21)
48
49 int dram_init(void)
50 {
51         gd->ram_size = imx_ddr_size();
52
53         return 0;
54 }
55
56 static iomux_v3_cfg_t const uart1_pads[] = {
57         MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
58         MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
59 };
60
61 #ifdef CONFIG_SPL_BUILD
62 static iomux_v3_cfg_t const usdhc1_pads[] = {
63         /* 8 bit SD */
64         MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
65         MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
66         MX6_PAD_SD1_DAT0__USDHC1_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
67         MX6_PAD_SD1_DAT1__USDHC1_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
68         MX6_PAD_SD1_DAT2__USDHC1_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
69         MX6_PAD_SD1_DAT3__USDHC1_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
70         MX6_PAD_SD1_DAT4__USDHC1_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
71         MX6_PAD_SD1_DAT5__USDHC1_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
72         MX6_PAD_SD1_DAT6__USDHC1_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
73         MX6_PAD_SD1_DAT7__USDHC1_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
74
75         /*CD pin*/
76         MX6_PAD_KEY_ROW7__GPIO_4_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
77 };
78
79 static iomux_v3_cfg_t const usdhc2_pads[] = {
80         MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
81         MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
82         MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
83         MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
84         MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
85         MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
86
87         /*CD pin*/
88         MX6_PAD_SD2_DAT7__GPIO_5_0 | MUX_PAD_CTRL(NO_PAD_CTRL),
89 };
90
91 static iomux_v3_cfg_t const usdhc3_pads[] = {
92         MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93         MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94         MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95         MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96         MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97         MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
98
99         /*CD pin*/
100         MX6_PAD_REF_CLK_32K__GPIO_3_22 | MUX_PAD_CTRL(NO_PAD_CTRL),
101 };
102 #endif
103
104 static void setup_iomux_uart(void)
105 {
106         imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
107 }
108
109 int board_mmc_get_env_dev(int devno)
110 {
111         return devno;
112 }
113
114 #ifdef CONFIG_DM_PMIC_PFUZE100
115 int power_init_board(void)
116 {
117         struct udevice *dev;
118         int ret;
119         u32 dev_id, rev_id, i;
120         u32 switch_num = 6;
121         u32 offset = PFUZE100_SW1CMODE;
122
123         ret = pmic_get("pfuze100@08", &dev);
124         if (ret == -ENODEV)
125                 return 0;
126
127         if (ret != 0)
128                 return ret;
129
130         dev_id = pmic_reg_read(dev, PFUZE100_DEVICEID);
131         rev_id = pmic_reg_read(dev, PFUZE100_REVID);
132         printf("PMIC: PFUZE100! DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
133
134         /* set SW1AB staby volatage 0.975V */
135         pmic_clrsetbits(dev, PFUZE100_SW1ABSTBY, 0x3f, 0x1b);
136
137         /* set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */
138         pmic_clrsetbits(dev, PFUZE100_SW1ABCONF, 0xc0, 0x40);
139
140         /* set SW1C staby volatage 0.975V */
141         pmic_clrsetbits(dev, PFUZE100_SW1CSTBY, 0x3f, 0x1b);
142
143         /* set SW1C/VDDSOC step ramp up time to from 16us to 4us/25mV */
144         pmic_clrsetbits(dev, PFUZE100_SW1CCONF, 0xc0, 0x40);
145
146         /* Init mode to APS_PFM */
147         pmic_reg_write(dev, PFUZE100_SW1ABMODE, APS_PFM);
148
149         for (i = 0; i < switch_num - 1; i++)
150                 pmic_reg_write(dev, offset + i * SWITCH_SIZE, APS_PFM);
151
152         return 0;
153 }
154 #endif
155
156 #ifdef CONFIG_FEC_MXC
157
158 static int setup_fec(void)
159 {
160         struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
161
162         /* clear gpr1[14], gpr1[18:17] to select anatop clock */
163         clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
164
165         return enable_fec_anatop_clock(0, ENET_50MHZ);
166 }
167 #endif
168
169 int board_early_init_f(void)
170 {
171         setup_iomux_uart();
172
173         return 0;
174 }
175
176 int board_init(void)
177 {
178         /* address of boot parameters */
179         gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
180
181 #ifdef  CONFIG_FEC_MXC
182         setup_fec();
183 #endif
184
185         return 0;
186 }
187
188 int checkboard(void)
189 {
190         puts("Board: MX6SLEVK\n");
191
192         return 0;
193 }
194
195 #ifdef CONFIG_SPL_BUILD
196 #include <spl.h>
197 #include <linux/libfdt.h>
198
199 #define USDHC1_CD_GPIO  IMX_GPIO_NR(4, 7)
200 #define USDHC2_CD_GPIO  IMX_GPIO_NR(5, 0)
201 #define USDHC3_CD_GPIO  IMX_GPIO_NR(3, 22)
202
203 static struct fsl_esdhc_cfg usdhc_cfg[3] = {
204         {USDHC1_BASE_ADDR},
205         {USDHC2_BASE_ADDR, 0, 4},
206         {USDHC3_BASE_ADDR, 0, 4},
207 };
208
209 int board_mmc_getcd(struct mmc *mmc)
210 {
211         struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
212         int ret = 0;
213
214         switch (cfg->esdhc_base) {
215         case USDHC1_BASE_ADDR:
216                 gpio_request(USDHC1_CD_GPIO, "cd1_gpio");
217                 ret = !gpio_get_value(USDHC1_CD_GPIO);
218                 break;
219         case USDHC2_BASE_ADDR:
220                 gpio_request(USDHC2_CD_GPIO, "cd2_gpio");
221                 ret = !gpio_get_value(USDHC2_CD_GPIO);
222                 break;
223         case USDHC3_BASE_ADDR:
224                 gpio_request(USDHC3_CD_GPIO, "cd3_gpio");
225                 ret = !gpio_get_value(USDHC3_CD_GPIO);
226                 break;
227         }
228
229         return ret;
230 }
231
232 int board_mmc_init(bd_t *bis)
233 {
234         struct src *src_regs = (struct src *)SRC_BASE_ADDR;
235         u32 val;
236         u32 port;
237
238         val = readl(&src_regs->sbmr1);
239
240         /* Boot from USDHC */
241         port = (val >> 11) & 0x3;
242         switch (port) {
243         case 0:
244                 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
245                                                  ARRAY_SIZE(usdhc1_pads));
246                 gpio_direction_input(USDHC1_CD_GPIO);
247                 usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
248                 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
249                 break;
250         case 1:
251                 imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
252                                                  ARRAY_SIZE(usdhc2_pads));
253                 gpio_direction_input(USDHC2_CD_GPIO);
254                 usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
255                 usdhc_cfg[0].max_bus_width = 4;
256                 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
257                 break;
258         case 2:
259                 imx_iomux_v3_setup_multiple_pads(usdhc3_pads,
260                                                  ARRAY_SIZE(usdhc3_pads));
261                 gpio_direction_input(USDHC3_CD_GPIO);
262                 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
263                 usdhc_cfg[0].max_bus_width = 4;
264                 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
265                 break;
266         }
267
268         gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
269         return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
270 }
271
272 const struct mx6sl_iomux_ddr_regs mx6_ddr_ioregs = {
273         .dram_sdqs0 = 0x00003030,
274         .dram_sdqs1 = 0x00003030,
275         .dram_sdqs2 = 0x00003030,
276         .dram_sdqs3 = 0x00003030,
277         .dram_dqm0 = 0x00000030,
278         .dram_dqm1 = 0x00000030,
279         .dram_dqm2 = 0x00000030,
280         .dram_dqm3 = 0x00000030,
281         .dram_cas  = 0x00000030,
282         .dram_ras  = 0x00000030,
283         .dram_sdclk_0 = 0x00000028,
284         .dram_reset = 0x00000030,
285         .dram_sdba2 = 0x00000000,
286         .dram_odt0 = 0x00000008,
287         .dram_odt1 = 0x00000008,
288 };
289
290 const struct mx6sl_iomux_grp_regs mx6_grp_ioregs = {
291         .grp_b0ds = 0x00000030,
292         .grp_b1ds = 0x00000030,
293         .grp_b2ds = 0x00000030,
294         .grp_b3ds = 0x00000030,
295         .grp_addds = 0x00000030,
296         .grp_ctlds = 0x00000030,
297         .grp_ddrmode_ctl = 0x00020000,
298         .grp_ddrpke = 0x00000000,
299         .grp_ddrmode = 0x00020000,
300         .grp_ddr_type = 0x00080000,
301 };
302
303 const struct mx6_mmdc_calibration mx6_mmcd_calib = {
304         .p0_mpdgctrl0 =  0x20000000,
305         .p0_mpdgctrl1 =  0x00000000,
306         .p0_mprddlctl =  0x4241444a,
307         .p0_mpwrdlctl =  0x3030312b,
308         .mpzqlp2ctl = 0x1b4700c7,
309 };
310
311 static struct mx6_lpddr2_cfg mem_ddr = {
312         .mem_speed = 800,
313         .density = 4,
314         .width = 32,
315         .banks = 8,
316         .rowaddr = 14,
317         .coladdr = 10,
318         .trcd_lp = 2000,
319         .trppb_lp = 2000,
320         .trpab_lp = 2250,
321         .trasmin = 4200,
322 };
323
324 static void ccgr_init(void)
325 {
326         struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
327
328         writel(0xFFFFFFFF, &ccm->CCGR0);
329         writel(0xFFFFFFFF, &ccm->CCGR1);
330         writel(0xFFFFFFFF, &ccm->CCGR2);
331         writel(0xFFFFFFFF, &ccm->CCGR3);
332         writel(0xFFFFFFFF, &ccm->CCGR4);
333         writel(0xFFFFFFFF, &ccm->CCGR5);
334         writel(0xFFFFFFFF, &ccm->CCGR6);
335
336         writel(0x00260324, &ccm->cbcmr);
337 }
338
339 static void spl_dram_init(void)
340 {
341         struct mx6_ddr_sysinfo sysinfo = {
342                 .dsize = mem_ddr.width / 32,
343                 .cs_density = 20,
344                 .ncs = 2,
345                 .cs1_mirror = 0,
346                 .walat = 0,
347                 .ralat = 2,
348                 .mif3_mode = 3,
349                 .bi_on = 1,
350                 .rtt_wr = 0,        /* LPDDR2 does not need rtt_wr rtt_nom */
351                 .rtt_nom = 0,
352                 .sde_to_rst = 0,    /* LPDDR2 does not need this field */
353                 .rst_to_cke = 0x10, /* JEDEC value for LPDDR2: 200us */
354                 .ddr_type = DDR_TYPE_LPDDR2,
355                 .refsel = 0,    /* Refresh cycles at 64KHz */
356                 .refr = 3,      /* 4 refresh commands per refresh cycle */
357         };
358         mx6sl_dram_iocfg(32, &mx6_ddr_ioregs, &mx6_grp_ioregs);
359         mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr);
360 }
361
362 void board_init_f(ulong dummy)
363 {
364         /* setup AIPS and disable watchdog */
365         arch_cpu_init();
366
367         ccgr_init();
368
369         /* iomux and setup of i2c */
370         board_early_init_f();
371
372         /* setup GP timer */
373         timer_init();
374
375         /* UART clocks enabled and gd valid - init serial console */
376         preloader_console_init();
377
378         /* DDR initialization */
379         spl_dram_init();
380
381         /* Clear the BSS. */
382         memset(__bss_start, 0, __bss_end - __bss_start);
383
384         /* load/boot image from boot device */
385         board_init_r(NULL, 0);
386 }
387 #endif