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