blob: f46b02e38e597d6d27a3fb6e9ec4586423111c68 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut2988ab22013-08-31 15:53:46 +02002/*
3 * SanDisk Sansa Fuze Plus board
4 *
5 * Copyright (C) 2013 Marek Vasut <marex@denx.de>
6 *
7 * Hardware investigation done by:
8 *
9 * Amaury Pouly <amaury.pouly@gmail.com>
Marek Vasut2988ab22013-08-31 15:53:46 +020010 */
11
12#include <common.h>
13#include <errno.h>
Simon Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Marek Vasut2988ab22013-08-31 15:53:46 +020017#include <asm/gpio.h>
18#include <asm/io.h>
19#include <asm/arch/iomux-mx23.h>
20#include <asm/arch/imx-regs.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/sys_proto.h>
Simon Glassdbd79542020-05-10 11:40:11 -060023#include <linux/delay.h>
Marek Vasut2988ab22013-08-31 15:53:46 +020024
25DECLARE_GLOBAL_DATA_PTR;
26
27/*
28 * Functions
29 */
30int board_early_init_f(void)
31{
32 /* IO0 clock at 480MHz */
33 mxs_set_ioclk(MXC_IOCLK0, 480000);
34
35 /* SSP0 clock at 96MHz */
36 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
37
38 return 0;
39}
40
41int dram_init(void)
42{
43 return mxs_dram_init();
44}
45
46#ifdef CONFIG_CMD_MMC
47static int xfi3_mmc_cd(int id)
48{
49 switch (id) {
50 case 0:
51 /* The SSP_DETECT is inverted on this board. */
52 return gpio_get_value(MX23_PAD_SSP1_DETECT__GPIO_2_1);
53 case 1:
54 /* Internal eMMC always present */
55 return 1;
56 default:
57 return 0;
58 }
59}
60
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090061int board_mmc_init(struct bd_info *bis)
Marek Vasut2988ab22013-08-31 15:53:46 +020062{
63 int ret;
64
65 /* MicroSD slot */
66 gpio_direction_input(MX23_PAD_SSP1_DETECT__GPIO_2_1);
67 gpio_direction_output(MX23_PAD_GPMI_D08__GPIO_0_8, 0);
68 ret = mxsmmc_initialize(bis, 0, NULL, xfi3_mmc_cd);
69 if (ret)
70 return ret;
71
72 /* Internal eMMC */
73 gpio_direction_output(MX23_PAD_PWM3__GPIO_1_29, 0);
74 ret = mxsmmc_initialize(bis, 1, NULL, xfi3_mmc_cd);
75
76 return ret;
77}
78#endif
79
80#ifdef CONFIG_VIDEO_MXS
81#define MUX_CONFIG_LCD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
82const iomux_cfg_t iomux_lcd_gpio[] = {
83 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_LCD,
84 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_LCD,
85 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_LCD,
86 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_LCD,
87 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_LCD,
88 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_LCD,
89 MX23_PAD_LCD_D06__GPIO_1_6 | MUX_CONFIG_LCD,
90 MX23_PAD_LCD_D07__GPIO_1_7 | MUX_CONFIG_LCD,
91 MX23_PAD_LCD_D08__GPIO_1_8 | MUX_CONFIG_LCD,
92 MX23_PAD_LCD_D09__GPIO_1_9 | MUX_CONFIG_LCD,
93 MX23_PAD_LCD_D10__GPIO_1_10 | MUX_CONFIG_LCD,
94 MX23_PAD_LCD_D11__GPIO_1_11 | MUX_CONFIG_LCD,
95 MX23_PAD_LCD_D12__GPIO_1_12 | MUX_CONFIG_LCD,
96 MX23_PAD_LCD_D13__GPIO_1_13 | MUX_CONFIG_LCD,
97 MX23_PAD_LCD_D14__GPIO_1_14 | MUX_CONFIG_LCD,
98 MX23_PAD_LCD_D15__GPIO_1_15 | MUX_CONFIG_LCD,
99 MX23_PAD_LCD_D16__GPIO_1_16 | MUX_CONFIG_LCD,
100 MX23_PAD_LCD_D17__GPIO_1_17 | MUX_CONFIG_LCD,
101 MX23_PAD_LCD_RESET__GPIO_1_18 | MUX_CONFIG_LCD,
102 MX23_PAD_LCD_RS__GPIO_1_19 | MUX_CONFIG_LCD,
103 MX23_PAD_LCD_WR__GPIO_1_20 | MUX_CONFIG_LCD,
104 MX23_PAD_LCD_CS__GPIO_1_21 | MUX_CONFIG_LCD,
105 MX23_PAD_LCD_ENABLE__GPIO_1_23 | MUX_CONFIG_LCD,
106};
107
108const iomux_cfg_t iomux_lcd_lcd[] = {
109 MX23_PAD_LCD_D00__LCD_D00 | MUX_CONFIG_LCD,
110 MX23_PAD_LCD_D01__LCD_D01 | MUX_CONFIG_LCD,
111 MX23_PAD_LCD_D02__LCD_D02 | MUX_CONFIG_LCD,
112 MX23_PAD_LCD_D03__LCD_D03 | MUX_CONFIG_LCD,
113 MX23_PAD_LCD_D04__LCD_D04 | MUX_CONFIG_LCD,
114 MX23_PAD_LCD_D05__LCD_D05 | MUX_CONFIG_LCD,
115 MX23_PAD_LCD_D06__LCD_D06 | MUX_CONFIG_LCD,
116 MX23_PAD_LCD_D07__LCD_D07 | MUX_CONFIG_LCD,
117 MX23_PAD_LCD_D08__LCD_D08 | MUX_CONFIG_LCD,
118 MX23_PAD_LCD_D09__LCD_D09 | MUX_CONFIG_LCD,
119 MX23_PAD_LCD_D10__LCD_D10 | MUX_CONFIG_LCD,
120 MX23_PAD_LCD_D11__LCD_D11 | MUX_CONFIG_LCD,
121 MX23_PAD_LCD_D12__LCD_D12 | MUX_CONFIG_LCD,
122 MX23_PAD_LCD_D13__LCD_D13 | MUX_CONFIG_LCD,
123 MX23_PAD_LCD_D14__LCD_D14 | MUX_CONFIG_LCD,
124 MX23_PAD_LCD_D15__LCD_D15 | MUX_CONFIG_LCD,
125 MX23_PAD_LCD_D16__LCD_D16 | MUX_CONFIG_LCD,
126 MX23_PAD_LCD_D17__LCD_D17 | MUX_CONFIG_LCD,
127 MX23_PAD_LCD_RESET__LCD_RESET | MUX_CONFIG_LCD,
128 MX23_PAD_LCD_RS__LCD_RS | MUX_CONFIG_LCD,
129 MX23_PAD_LCD_WR__LCD_WR | MUX_CONFIG_LCD,
130 MX23_PAD_LCD_CS__LCD_CS | MUX_CONFIG_LCD,
131 MX23_PAD_LCD_ENABLE__LCD_ENABLE | MUX_CONFIG_LCD,
132 MX23_PAD_LCD_VSYNC__LCD_VSYNC | MUX_CONFIG_LCD,
133};
134
135static int mxsfb_read_register(uint32_t reg, uint32_t *value)
136{
137 iomux_cfg_t mux;
138 uint32_t val = 0;
139 int i;
140
141 /* Mangle the register offset. */
142 reg = ((reg & 0xff) << 1) | (((reg >> 8) & 0xff) << 10);
143
144 /*
145 * The SmartLCD interface on MX233 can only do WRITE operation
146 * via the LCDIF controller. Implement the READ operation by
147 * fiddling with bits.
148 */
149 mxs_iomux_setup_multiple_pads(iomux_lcd_gpio,
150 ARRAY_SIZE(iomux_lcd_gpio));
151
152 gpio_direction_output(MX23_PAD_LCD_RS__GPIO_1_19, 1);
153 gpio_direction_output(MX23_PAD_LCD_CS__GPIO_1_21, 1);
154 gpio_direction_output(MX23_PAD_LCD_WR__GPIO_1_20, 1);
155 gpio_direction_output(MX23_PAD_LCD_ENABLE__GPIO_1_23, 1);
156
157 for (i = 0; i < 18; i++) {
158 mux = MXS_IOMUX_PAD_NAKED(1, i, PAD_MUXSEL_GPIO);
159 gpio_direction_output(mux, 0);
160 }
161
162 udelay(2);
163 gpio_direction_output(MX23_PAD_LCD_RS__GPIO_1_19, 0);
164 udelay(1);
165 gpio_direction_output(MX23_PAD_LCD_CS__GPIO_1_21, 0);
166 udelay(1);
167 gpio_direction_output(MX23_PAD_LCD_WR__GPIO_1_20, 0);
168 udelay(1);
169
170 for (i = 0; i < 18; i++) {
171 mux = MXS_IOMUX_PAD_NAKED(1, i, PAD_MUXSEL_GPIO);
172 gpio_direction_output(mux, (reg >> i) & 1);
173 }
174 udelay(1);
175
176 gpio_direction_output(MX23_PAD_LCD_WR__GPIO_1_20, 1);
177 udelay(3);
178
179 for (i = 0; i < 18; i++) {
180 mux = MXS_IOMUX_PAD_NAKED(1, i, PAD_MUXSEL_GPIO);
181 gpio_direction_input(mux);
182 }
183 udelay(2);
184
185 gpio_direction_output(MX23_PAD_LCD_ENABLE__GPIO_1_23, 0);
186 udelay(1);
187 gpio_direction_output(MX23_PAD_LCD_RS__GPIO_1_19, 1);
188 udelay(1);
189 gpio_direction_output(MX23_PAD_LCD_ENABLE__GPIO_1_23, 1);
190 udelay(3);
191 gpio_direction_output(MX23_PAD_LCD_ENABLE__GPIO_1_23, 0);
192 udelay(2);
193
194 for (i = 0; i < 18; i++) {
195 mux = MXS_IOMUX_PAD_NAKED(1, i, PAD_MUXSEL_GPIO);
196 val |= !!gpio_get_value(mux) << i;
197 }
198 udelay(1);
199
200 gpio_direction_output(MX23_PAD_LCD_ENABLE__GPIO_1_23, 1);
201 udelay(1);
202 gpio_direction_output(MX23_PAD_LCD_CS__GPIO_1_21, 1);
203 udelay(1);
204
205 mxs_iomux_setup_multiple_pads(iomux_lcd_lcd,
206 ARRAY_SIZE(iomux_lcd_lcd));
207
208 /* Demangle the register value. */
209 *value = ((val >> 1) & 0xff) | ((val >> 2) & 0xff00);
210
211 writel(val, 0x2000);
212 return 0;
213}
214
215static int mxsfb_write_byte(uint32_t payload, const unsigned int data)
216{
217 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
218 const unsigned int timeout = 0x10000;
219
220 /* What is going on here I do not know. FIXME */
221 payload = ((payload & 0xff) << 1) | (((payload >> 8) & 0xff) << 10);
222
223 if (mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
224 timeout))
225 return -ETIMEDOUT;
226
227 writel((1 << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) |
228 (1 << LCDIF_TRANSFER_COUNT_H_COUNT_OFFSET),
229 &regs->hw_lcdif_transfer_count);
230
231 writel(LCDIF_CTRL_DATA_SELECT | LCDIF_CTRL_RUN,
232 &regs->hw_lcdif_ctrl_clr);
233
234 if (data)
235 writel(LCDIF_CTRL_DATA_SELECT, &regs->hw_lcdif_ctrl_set);
236
237 writel(LCDIF_CTRL_RUN, &regs->hw_lcdif_ctrl_set);
238
239 if (mxs_wait_mask_clr(&regs->hw_lcdif_lcdif_stat_reg, 1 << 29,
240 timeout))
241 return -ETIMEDOUT;
242
243 writel(payload, &regs->hw_lcdif_data);
244 return mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
245 timeout);
246}
247
248static void mxsfb_write_register(uint32_t reg, uint32_t data)
249{
250 mxsfb_write_byte(reg, 0);
251 mxsfb_write_byte(data, 1);
252}
253
254static const struct {
255 uint8_t reg;
256 uint8_t delay;
257 uint16_t val;
258} lcd_regs[] = {
259 { 0xe5, 0 , 0x78f0 },
260 { 0xe3, 0 , 0x3008 },
261 { 0xe7, 0 , 0x0012 },
262 { 0xef, 0 , 0x1231 },
263 { 0x00, 0 , 0x0001 },
264 { 0x01, 0 , 0x0100 },
265 { 0x02, 0 , 0x0700 },
266 { 0x03, 0 , 0x1030 },
267 { 0x04, 0 , 0x0000 },
268 { 0x08, 0 , 0x0207 },
269 { 0x09, 0 , 0x0000 },
270 { 0x0a, 0 , 0x0000 },
271 { 0x0c, 0 , 0x0000 },
272 { 0x0d, 0 , 0x0000 },
273 { 0x0f, 0 , 0x0000 },
274 { 0x10, 0 , 0x0000 },
275 { 0x11, 0 , 0x0007 },
276 { 0x12, 0 , 0x0000 },
277 { 0x13, 20 , 0x0000 },
278 /* Wait 20 mS here. */
279 { 0x10, 0 , 0x1290 },
280 { 0x11, 50 , 0x0007 },
281 /* Wait 50 mS here. */
282 { 0x12, 50 , 0x0019 },
283 /* Wait 50 mS here. */
284 { 0x13, 0 , 0x1700 },
285 { 0x29, 50 , 0x0014 },
286 /* Wait 50 mS here. */
287 { 0x20, 0 , 0x0000 },
288 { 0x21, 0 , 0x0000 },
289 { 0x30, 0 , 0x0504 },
290 { 0x31, 0 , 0x0007 },
291 { 0x32, 0 , 0x0006 },
292 { 0x35, 0 , 0x0106 },
293 { 0x36, 0 , 0x0202 },
294 { 0x37, 0 , 0x0504 },
295 { 0x38, 0 , 0x0500 },
296 { 0x39, 0 , 0x0706 },
297 { 0x3c, 0 , 0x0204 },
298 { 0x3d, 0 , 0x0202 },
299 { 0x50, 0 , 0x0000 },
300 { 0x51, 0 , 0x00ef },
301 { 0x52, 0 , 0x0000 },
302 { 0x53, 0 , 0x013f },
303 { 0x60, 0 , 0xa700 },
304 { 0x61, 0 , 0x0001 },
305 { 0x6a, 0 , 0x0000 },
306 { 0x2b, 50 , 0x000d },
307 /* Wait 50 mS here. */
308 { 0x90, 0 , 0x0011 },
309 { 0x92, 0 , 0x0600 },
310 { 0x93, 0 , 0x0003 },
311 { 0x95, 0 , 0x0110 },
312 { 0x97, 0 , 0x0000 },
313 { 0x98, 0 , 0x0000 },
314 { 0x07, 0 , 0x0173 },
315};
316
317void board_mxsfb_system_setup(void)
318{
319 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
320 uint32_t id;
321 int i;
322
323 /* Switch the LCDIF into System-Mode */
324 writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DOTCLK_MODE |
325 LCDIF_CTRL_BYPASS_COUNT, &regs->hw_lcdif_ctrl_clr);
326
327 /* To program the LCD, switch to 18bit bus + 18bit data. */
328 clrsetbits_le32(&regs->hw_lcdif_ctrl,
329 LCDIF_CTRL_WORD_LENGTH_MASK | LCDIF_CTRL_LCD_DATABUS_WIDTH_MASK,
330 LCDIF_CTRL_WORD_LENGTH_18BIT |
331 LCDIF_CTRL_LCD_DATABUS_WIDTH_18BIT);
332
333 mxsfb_read_register(0, &id);
334 writel(id, 0x2004);
335
336 /* Restart the SmartLCD controller */
337 mdelay(50);
338 writel(1, &regs->hw_lcdif_ctrl1_set);
339 mdelay(50);
340 writel(1, &regs->hw_lcdif_ctrl1_clr);
341 mdelay(50);
342 writel(1, &regs->hw_lcdif_ctrl1_set);
343 mdelay(50);
344
345 /* Program the SmartLCD controller */
346 writel(LCDIF_CTRL1_RECOVER_ON_UNDERFLOW, &regs->hw_lcdif_ctrl1_set);
347
348 writel((0x02 << LCDIF_TIMING_CMD_HOLD_OFFSET) |
349 (0x02 << LCDIF_TIMING_CMD_SETUP_OFFSET) |
350 (0x02 << LCDIF_TIMING_DATA_HOLD_OFFSET) |
351 (0x01 << LCDIF_TIMING_DATA_SETUP_OFFSET),
352 &regs->hw_lcdif_timing);
353
354 /*
355 * ILI9325 init and configuration sequence.
356 */
357 for (i = 0; i < ARRAY_SIZE(lcd_regs); i++) {
358 mxsfb_write_register(lcd_regs[i].reg, lcd_regs[i].val);
359 if (lcd_regs[i].delay)
360 mdelay(lcd_regs[i].delay);
361 }
362 /* Turn on Framebuffer Upload Mode */
363 mxsfb_write_byte(0x22, 0);
364
365 writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DATA_SELECT,
366 &regs->hw_lcdif_ctrl_set);
367
368 /* Operate the framebuffer in 16bit mode. */
369 clrsetbits_le32(&regs->hw_lcdif_ctrl,
370 LCDIF_CTRL_WORD_LENGTH_MASK | LCDIF_CTRL_LCD_DATABUS_WIDTH_MASK,
371 LCDIF_CTRL_WORD_LENGTH_16BIT |
372 LCDIF_CTRL_LCD_DATABUS_WIDTH_18BIT);
373}
374#endif
375
376int board_init(void)
377{
378 /* Adress of boot parameters */
379 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
380
381 /* Turn on PWM backlight */
382 gpio_direction_output(MX23_PAD_PWM2__GPIO_1_28, 1);
383
384 return 0;
385}
386
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900387int board_eth_init(struct bd_info *bis)
Marek Vasut2988ab22013-08-31 15:53:46 +0200388{
389 usb_eth_initialize(bis);
390 return 0;
391}