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