1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Creative ZEN X-Fi3 board
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2013 Marek Vasut <marex@denx.de>
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Hardware investigation done by:
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Amaury Pouly <amaury.pouly@gmail.com>
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <common.h>
14*4882a593Smuzhiyun #include <errno.h>
15*4882a593Smuzhiyun #include <asm/gpio.h>
16*4882a593Smuzhiyun #include <asm/io.h>
17*4882a593Smuzhiyun #include <asm/arch/iomux-mx23.h>
18*4882a593Smuzhiyun #include <asm/arch/imx-regs.h>
19*4882a593Smuzhiyun #include <asm/arch/clock.h>
20*4882a593Smuzhiyun #include <asm/arch/sys_proto.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun * Functions
26*4882a593Smuzhiyun */
board_early_init_f(void)27*4882a593Smuzhiyun int board_early_init_f(void)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun /* IO0 clock at 480MHz */
30*4882a593Smuzhiyun mxs_set_ioclk(MXC_IOCLK0, 480000);
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* SSP0 clock at 96MHz */
33*4882a593Smuzhiyun mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun return 0;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun
dram_init(void)38*4882a593Smuzhiyun int dram_init(void)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun return mxs_dram_init();
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #ifdef CONFIG_CMD_MMC
xfi3_mmc_cd(int id)44*4882a593Smuzhiyun static int xfi3_mmc_cd(int id)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun switch (id) {
47*4882a593Smuzhiyun case 0:
48*4882a593Smuzhiyun /* The SSP_DETECT is inverted on this board. */
49*4882a593Smuzhiyun return gpio_get_value(MX23_PAD_SSP1_DETECT__GPIO_2_1);
50*4882a593Smuzhiyun case 1:
51*4882a593Smuzhiyun /* Phison bridge always present */
52*4882a593Smuzhiyun return 1;
53*4882a593Smuzhiyun default:
54*4882a593Smuzhiyun return 0;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
board_mmc_init(bd_t * bis)58*4882a593Smuzhiyun int board_mmc_init(bd_t *bis)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun int ret;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /* MicroSD slot */
63*4882a593Smuzhiyun gpio_direction_input(MX23_PAD_SSP1_DETECT__GPIO_2_1);
64*4882a593Smuzhiyun gpio_direction_output(MX23_PAD_GPMI_D07__GPIO_0_7, 0);
65*4882a593Smuzhiyun ret = mxsmmc_initialize(bis, 0, NULL, xfi3_mmc_cd);
66*4882a593Smuzhiyun if (ret)
67*4882a593Smuzhiyun return ret;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /* Phison SD-NAND bridge */
70*4882a593Smuzhiyun ret = mxsmmc_initialize(bis, 1, NULL, xfi3_mmc_cd);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun return ret;
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #ifdef CONFIG_VIDEO_MXS
mxsfb_write_byte(uint32_t payload,const unsigned int data)77*4882a593Smuzhiyun static int mxsfb_write_byte(uint32_t payload, const unsigned int data)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
80*4882a593Smuzhiyun const unsigned int timeout = 0x10000;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if (mxs_wait_mask_clr(®s->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
83*4882a593Smuzhiyun timeout))
84*4882a593Smuzhiyun return -ETIMEDOUT;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun writel((1 << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) |
87*4882a593Smuzhiyun (1 << LCDIF_TRANSFER_COUNT_H_COUNT_OFFSET),
88*4882a593Smuzhiyun ®s->hw_lcdif_transfer_count);
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun writel(LCDIF_CTRL_DATA_SELECT | LCDIF_CTRL_RUN,
91*4882a593Smuzhiyun ®s->hw_lcdif_ctrl_clr);
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun if (data)
94*4882a593Smuzhiyun writel(LCDIF_CTRL_DATA_SELECT, ®s->hw_lcdif_ctrl_set);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun writel(LCDIF_CTRL_RUN, ®s->hw_lcdif_ctrl_set);
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun if (mxs_wait_mask_clr(®s->hw_lcdif_lcdif_stat_reg, 1 << 29,
99*4882a593Smuzhiyun timeout))
100*4882a593Smuzhiyun return -ETIMEDOUT;
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun writel(payload, ®s->hw_lcdif_data);
103*4882a593Smuzhiyun return mxs_wait_mask_clr(®s->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
104*4882a593Smuzhiyun timeout);
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun
mxsfb_write_register(uint32_t reg,uint32_t data)107*4882a593Smuzhiyun static void mxsfb_write_register(uint32_t reg, uint32_t data)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun mxsfb_write_byte(reg, 0);
110*4882a593Smuzhiyun mxsfb_write_byte(data, 1);
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun static const struct {
114*4882a593Smuzhiyun uint8_t reg;
115*4882a593Smuzhiyun uint8_t delay;
116*4882a593Smuzhiyun uint16_t val;
117*4882a593Smuzhiyun } lcd_regs[] = {
118*4882a593Smuzhiyun { 0x01, 0, 0x001c },
119*4882a593Smuzhiyun { 0x02, 0, 0x0100 },
120*4882a593Smuzhiyun /* Writing 0x30 to reg. 0x03 flips the LCD */
121*4882a593Smuzhiyun { 0x03, 0, 0x1038 },
122*4882a593Smuzhiyun { 0x08, 0, 0x0808 },
123*4882a593Smuzhiyun /* This can contain 0x111 to rotate the LCD. */
124*4882a593Smuzhiyun { 0x0c, 0, 0x0000 },
125*4882a593Smuzhiyun { 0x0f, 0, 0x0c01 },
126*4882a593Smuzhiyun { 0x20, 0, 0x0000 },
127*4882a593Smuzhiyun { 0x21, 30, 0x0000 },
128*4882a593Smuzhiyun /* Wait 30 mS here */
129*4882a593Smuzhiyun { 0x10, 0, 0x0a00 },
130*4882a593Smuzhiyun { 0x11, 30, 0x1038 },
131*4882a593Smuzhiyun /* Wait 30 mS here */
132*4882a593Smuzhiyun { 0x12, 0, 0x1010 },
133*4882a593Smuzhiyun { 0x13, 0, 0x0050 },
134*4882a593Smuzhiyun { 0x14, 0, 0x4f58 },
135*4882a593Smuzhiyun { 0x30, 0, 0x0000 },
136*4882a593Smuzhiyun { 0x31, 0, 0x00db },
137*4882a593Smuzhiyun { 0x32, 0, 0x0000 },
138*4882a593Smuzhiyun { 0x33, 0, 0x0000 },
139*4882a593Smuzhiyun { 0x34, 0, 0x00db },
140*4882a593Smuzhiyun { 0x35, 0, 0x0000 },
141*4882a593Smuzhiyun { 0x36, 0, 0x00af },
142*4882a593Smuzhiyun { 0x37, 0, 0x0000 },
143*4882a593Smuzhiyun { 0x38, 0, 0x00db },
144*4882a593Smuzhiyun { 0x39, 0, 0x0000 },
145*4882a593Smuzhiyun { 0x50, 0, 0x0000 },
146*4882a593Smuzhiyun { 0x51, 0, 0x0705 },
147*4882a593Smuzhiyun { 0x52, 0, 0x0e0a },
148*4882a593Smuzhiyun { 0x53, 0, 0x0300 },
149*4882a593Smuzhiyun { 0x54, 0, 0x0a0e },
150*4882a593Smuzhiyun { 0x55, 0, 0x0507 },
151*4882a593Smuzhiyun { 0x56, 0, 0x0000 },
152*4882a593Smuzhiyun { 0x57, 0, 0x0003 },
153*4882a593Smuzhiyun { 0x58, 0, 0x090a },
154*4882a593Smuzhiyun { 0x59, 30, 0x0a09 },
155*4882a593Smuzhiyun /* Wait 30 mS here */
156*4882a593Smuzhiyun { 0x07, 30, 0x1017 },
157*4882a593Smuzhiyun /* Wait 40 mS here */
158*4882a593Smuzhiyun { 0x36, 0, 0x00af },
159*4882a593Smuzhiyun { 0x37, 0, 0x0000 },
160*4882a593Smuzhiyun { 0x38, 0, 0x00db },
161*4882a593Smuzhiyun { 0x39, 0, 0x0000 },
162*4882a593Smuzhiyun { 0x20, 0, 0x0000 },
163*4882a593Smuzhiyun { 0x21, 0, 0x0000 },
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun
mxsfb_system_setup(void)166*4882a593Smuzhiyun void mxsfb_system_setup(void)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
169*4882a593Smuzhiyun int i;
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun /* Switch the LCDIF into System-Mode */
172*4882a593Smuzhiyun writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DOTCLK_MODE |
173*4882a593Smuzhiyun LCDIF_CTRL_BYPASS_COUNT, ®s->hw_lcdif_ctrl_clr);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /* Restart the SmartLCD controller */
176*4882a593Smuzhiyun mdelay(50);
177*4882a593Smuzhiyun writel(1, ®s->hw_lcdif_ctrl1_set);
178*4882a593Smuzhiyun mdelay(50);
179*4882a593Smuzhiyun writel(1, ®s->hw_lcdif_ctrl1_clr);
180*4882a593Smuzhiyun mdelay(50);
181*4882a593Smuzhiyun writel(1, ®s->hw_lcdif_ctrl1_set);
182*4882a593Smuzhiyun mdelay(50);
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun /* Program the SmartLCD controller */
185*4882a593Smuzhiyun writel(LCDIF_CTRL1_RECOVER_ON_UNDERFLOW, ®s->hw_lcdif_ctrl1_set);
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun writel((0x03 << LCDIF_TIMING_CMD_HOLD_OFFSET) |
188*4882a593Smuzhiyun (0x03 << LCDIF_TIMING_CMD_SETUP_OFFSET) |
189*4882a593Smuzhiyun (0x03 << LCDIF_TIMING_DATA_HOLD_OFFSET) |
190*4882a593Smuzhiyun (0x02 << LCDIF_TIMING_DATA_SETUP_OFFSET),
191*4882a593Smuzhiyun ®s->hw_lcdif_timing);
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /*
194*4882a593Smuzhiyun * OTM2201A init and configuration sequence.
195*4882a593Smuzhiyun */
196*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(lcd_regs); i++) {
197*4882a593Smuzhiyun mxsfb_write_register(lcd_regs[i].reg, lcd_regs[i].val);
198*4882a593Smuzhiyun if (lcd_regs[i].delay)
199*4882a593Smuzhiyun mdelay(lcd_regs[i].delay);
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun /* Turn on Framebuffer Upload Mode */
202*4882a593Smuzhiyun mxsfb_write_byte(0x22, 0);
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DATA_SELECT,
205*4882a593Smuzhiyun ®s->hw_lcdif_ctrl_set);
206*4882a593Smuzhiyun }
207*4882a593Smuzhiyun #endif
208*4882a593Smuzhiyun
board_init(void)209*4882a593Smuzhiyun int board_init(void)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun /* Adress of boot parameters */
212*4882a593Smuzhiyun gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun /* Turn on PWM backlight */
215*4882a593Smuzhiyun gpio_direction_output(MX23_PAD_PWM2__GPIO_1_28, 1);
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun return 0;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
board_eth_init(bd_t * bis)220*4882a593Smuzhiyun int board_eth_init(bd_t *bis)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun usb_eth_initialize(bis);
223*4882a593Smuzhiyun return 0;
224*4882a593Smuzhiyun }
225