blob: b5f0d31307456cf9e1f0a44e19a8b3ff51acd276 [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>
Simon Glassc05ed002020-05-10 11:40:11 -060022#include <linux/delay.h>
Marek Vasutaa04fef2013-08-31 15:53:45 +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 /* Phison bridge always present */
54 return 1;
55 default:
56 return 0;
57 }
58}
59
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090060int board_mmc_init(struct bd_info *bis)
Marek Vasutaa04fef2013-08-31 15:53:45 +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_D07__GPIO_0_7, 0);
67 ret = mxsmmc_initialize(bis, 0, NULL, xfi3_mmc_cd);
68 if (ret)
69 return ret;
70
71 /* Phison SD-NAND bridge */
72 ret = mxsmmc_initialize(bis, 1, NULL, xfi3_mmc_cd);
73
74 return ret;
75}
76#endif
77
78#ifdef CONFIG_VIDEO_MXS
79static int mxsfb_write_byte(uint32_t payload, const unsigned int data)
80{
81 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
82 const unsigned int timeout = 0x10000;
83
84 if (mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
85 timeout))
86 return -ETIMEDOUT;
87
88 writel((1 << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) |
89 (1 << LCDIF_TRANSFER_COUNT_H_COUNT_OFFSET),
90 &regs->hw_lcdif_transfer_count);
91
92 writel(LCDIF_CTRL_DATA_SELECT | LCDIF_CTRL_RUN,
93 &regs->hw_lcdif_ctrl_clr);
94
95 if (data)
96 writel(LCDIF_CTRL_DATA_SELECT, &regs->hw_lcdif_ctrl_set);
97
98 writel(LCDIF_CTRL_RUN, &regs->hw_lcdif_ctrl_set);
99
100 if (mxs_wait_mask_clr(&regs->hw_lcdif_lcdif_stat_reg, 1 << 29,
101 timeout))
102 return -ETIMEDOUT;
103
104 writel(payload, &regs->hw_lcdif_data);
105 return mxs_wait_mask_clr(&regs->hw_lcdif_ctrl_reg, LCDIF_CTRL_RUN,
106 timeout);
107}
108
109static void mxsfb_write_register(uint32_t reg, uint32_t data)
110{
111 mxsfb_write_byte(reg, 0);
112 mxsfb_write_byte(data, 1);
113}
114
115static const struct {
116 uint8_t reg;
117 uint8_t delay;
118 uint16_t val;
119} lcd_regs[] = {
120 { 0x01, 0, 0x001c },
121 { 0x02, 0, 0x0100 },
122 /* Writing 0x30 to reg. 0x03 flips the LCD */
123 { 0x03, 0, 0x1038 },
124 { 0x08, 0, 0x0808 },
125 /* This can contain 0x111 to rotate the LCD. */
126 { 0x0c, 0, 0x0000 },
127 { 0x0f, 0, 0x0c01 },
128 { 0x20, 0, 0x0000 },
129 { 0x21, 30, 0x0000 },
130 /* Wait 30 mS here */
131 { 0x10, 0, 0x0a00 },
132 { 0x11, 30, 0x1038 },
133 /* Wait 30 mS here */
134 { 0x12, 0, 0x1010 },
135 { 0x13, 0, 0x0050 },
136 { 0x14, 0, 0x4f58 },
137 { 0x30, 0, 0x0000 },
138 { 0x31, 0, 0x00db },
139 { 0x32, 0, 0x0000 },
140 { 0x33, 0, 0x0000 },
141 { 0x34, 0, 0x00db },
142 { 0x35, 0, 0x0000 },
143 { 0x36, 0, 0x00af },
144 { 0x37, 0, 0x0000 },
145 { 0x38, 0, 0x00db },
146 { 0x39, 0, 0x0000 },
147 { 0x50, 0, 0x0000 },
148 { 0x51, 0, 0x0705 },
149 { 0x52, 0, 0x0e0a },
150 { 0x53, 0, 0x0300 },
151 { 0x54, 0, 0x0a0e },
152 { 0x55, 0, 0x0507 },
153 { 0x56, 0, 0x0000 },
154 { 0x57, 0, 0x0003 },
155 { 0x58, 0, 0x090a },
156 { 0x59, 30, 0x0a09 },
157 /* Wait 30 mS here */
158 { 0x07, 30, 0x1017 },
159 /* Wait 40 mS here */
160 { 0x36, 0, 0x00af },
161 { 0x37, 0, 0x0000 },
162 { 0x38, 0, 0x00db },
163 { 0x39, 0, 0x0000 },
164 { 0x20, 0, 0x0000 },
165 { 0x21, 0, 0x0000 },
166};
167
Peng Fand39c3462015-10-29 15:54:40 +0800168void mxsfb_system_setup(void)
Marek Vasutaa04fef2013-08-31 15:53:45 +0200169{
170 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
171 int i;
172
173 /* Switch the LCDIF into System-Mode */
174 writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DOTCLK_MODE |
175 LCDIF_CTRL_BYPASS_COUNT, &regs->hw_lcdif_ctrl_clr);
176
177 /* Restart the SmartLCD controller */
178 mdelay(50);
179 writel(1, &regs->hw_lcdif_ctrl1_set);
180 mdelay(50);
181 writel(1, &regs->hw_lcdif_ctrl1_clr);
182 mdelay(50);
183 writel(1, &regs->hw_lcdif_ctrl1_set);
184 mdelay(50);
185
186 /* Program the SmartLCD controller */
187 writel(LCDIF_CTRL1_RECOVER_ON_UNDERFLOW, &regs->hw_lcdif_ctrl1_set);
188
189 writel((0x03 << LCDIF_TIMING_CMD_HOLD_OFFSET) |
190 (0x03 << LCDIF_TIMING_CMD_SETUP_OFFSET) |
191 (0x03 << LCDIF_TIMING_DATA_HOLD_OFFSET) |
192 (0x02 << LCDIF_TIMING_DATA_SETUP_OFFSET),
193 &regs->hw_lcdif_timing);
194
195 /*
196 * OTM2201A init and configuration sequence.
197 */
198 for (i = 0; i < ARRAY_SIZE(lcd_regs); i++) {
199 mxsfb_write_register(lcd_regs[i].reg, lcd_regs[i].val);
200 if (lcd_regs[i].delay)
201 mdelay(lcd_regs[i].delay);
202 }
203 /* Turn on Framebuffer Upload Mode */
204 mxsfb_write_byte(0x22, 0);
205
206 writel(LCDIF_CTRL_LCDIF_MASTER | LCDIF_CTRL_DATA_SELECT,
207 &regs->hw_lcdif_ctrl_set);
208}
209#endif
210
211int board_init(void)
212{
213 /* Adress of boot parameters */
214 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
215
216 /* Turn on PWM backlight */
217 gpio_direction_output(MX23_PAD_PWM2__GPIO_1_28, 1);
218
219 return 0;
220}
221
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900222int board_eth_init(struct bd_info *bis)
Marek Vasutaa04fef2013-08-31 15:53:45 +0200223{
224 usb_eth_initialize(bis);
225 return 0;
226}