blob: 79ea456028372f48415dd7946ac7030f73db4f12 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrick Bruennba81b042016-11-04 11:57:02 +01002/*
3 * Copyright (C) 2015 Beckhoff Automation GmbH & Co. KG
4 * Patrick Bruenn <p.bruenn@beckhoff.com>
5 *
6 * Based on <u-boot>/board/freescale/mx53loco/mx53loco.c
7 * Copyright (C) 2011 Freescale Semiconductor, Inc.
Patrick Bruennba81b042016-11-04 11:57:02 +01008 */
9
10#include <common.h>
Simon Glass11c89f32017-05-17 17:18:03 -060011#include <dm.h>
Patrick Bruennba81b042016-11-04 11:57:02 +010012#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/arch/crm_regs.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/iomux-mx53.h>
18#include <asm/arch/clock.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020019#include <asm/mach-imx/mx5_video.h>
Patrick Bruennba81b042016-11-04 11:57:02 +010020#include <ACEX1K.h>
21#include <netdev.h>
22#include <i2c.h>
23#include <mmc.h>
24#include <fsl_esdhc.h>
25#include <asm/gpio.h>
26#include <linux/fb.h>
27#include <ipu_pixfmt.h>
Diego Dorta2661c9c2017-09-22 12:12:18 -030028#include <input.h>
Patrick Bruennba81b042016-11-04 11:57:02 +010029#include <fs.h>
Patrick Bruennba81b042016-11-04 11:57:02 +010030#include <dm/platform_data/serial_mxc.h>
31
32enum LED_GPIOS {
33 GPIO_SD1_CD = IMX_GPIO_NR(1, 1),
34 GPIO_SD2_CD = IMX_GPIO_NR(1, 4),
35 GPIO_LED_SD2_R = IMX_GPIO_NR(3, 16),
36 GPIO_LED_SD2_B = IMX_GPIO_NR(3, 17),
37 GPIO_LED_SD2_G = IMX_GPIO_NR(3, 18),
38 GPIO_LED_SD1_R = IMX_GPIO_NR(3, 19),
39 GPIO_LED_SD1_B = IMX_GPIO_NR(3, 20),
40 GPIO_LED_SD1_G = IMX_GPIO_NR(3, 21),
41 GPIO_LED_PWR_R = IMX_GPIO_NR(3, 22),
42 GPIO_LED_PWR_B = IMX_GPIO_NR(3, 23),
43 GPIO_LED_PWR_G = IMX_GPIO_NR(3, 24),
44 GPIO_SUPS_INT = IMX_GPIO_NR(3, 31),
45 GPIO_C3_CONFIG = IMX_GPIO_NR(6, 8),
46 GPIO_C3_STATUS = IMX_GPIO_NR(6, 7),
47 GPIO_C3_DONE = IMX_GPIO_NR(6, 9),
48};
49
50#define CCAT_BASE_ADDR ((void *)0xf0000000)
51#define CCAT_END_ADDR (CCAT_BASE_ADDR + (1024 * 1024 * 32))
52#define CCAT_SIZE 1191788
53#define CCAT_SIGN_ADDR (CCAT_BASE_ADDR + 12)
54static const char CCAT_SIGNATURE[] = "CCAT";
55
56static const u32 CCAT_MODE_CONFIG = 0x0024DC81;
57static const u32 CCAT_MODE_RUN = 0x0033DC8F;
58
59DECLARE_GLOBAL_DATA_PTR;
60
Patrick Bruennba81b042016-11-04 11:57:02 +010061u32 get_board_rev(void)
62{
63 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
64 struct fuse_bank *bank = &iim->bank[0];
65 struct fuse_bank0_regs *fuse =
66 (struct fuse_bank0_regs *)bank->fuse_regs;
67
68 int rev = readl(&fuse->gp[6]);
69
70 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
71}
72
73/*
74 * Set CCAT mode
75 * @mode: use CCAT_MODE_CONFIG or CCAT_MODE_RUN
76 */
77void weim_cs0_settings(u32 mode)
78{
79 struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
80
81 writel(0x0, &weim_regs->cs0gcr1);
82 writel(mode, &weim_regs->cs0gcr1);
83 writel(0x00001002, &weim_regs->cs0gcr2);
84
85 writel(0x04000000, &weim_regs->cs0rcr1);
86 writel(0x00000000, &weim_regs->cs0rcr2);
87
88 writel(0x04000000, &weim_regs->cs0wcr1);
89 writel(0x00000000, &weim_regs->cs0wcr2);
90}
91
92static void setup_gpio_eim(void)
93{
Steffen Dirkwinkel098e9ef2019-04-17 13:57:14 +020094 gpio_request(GPIO_C3_STATUS, "GPIO_C3_STATUS");
95 gpio_request(GPIO_C3_DONE, "GPIO_C3_DONE");
96 gpio_request(GPIO_C3_CONFIG, "GPIO_C3_CONFIG");
Patrick Bruennba81b042016-11-04 11:57:02 +010097 gpio_direction_input(GPIO_C3_STATUS);
98 gpio_direction_input(GPIO_C3_DONE);
99 gpio_direction_output(GPIO_C3_CONFIG, 1);
100
101 weim_cs0_settings(CCAT_MODE_RUN);
102}
103
104static void setup_gpio_sups(void)
105{
Steffen Dirkwinkel098e9ef2019-04-17 13:57:14 +0200106 gpio_request(GPIO_SUPS_INT, "GPIO_SUPS_INT");
Patrick Bruennba81b042016-11-04 11:57:02 +0100107 gpio_direction_input(GPIO_SUPS_INT);
108
109 static const int BLINK_INTERVALL = 50000;
110 int status = 1;
111 while (gpio_get_value(GPIO_SUPS_INT)) {
112 /* signal "CX SUPS power fail" */
113 gpio_set_value(GPIO_LED_PWR_R,
114 (++status / BLINK_INTERVALL) % 2);
115 }
116
117 /* signal "CX power up" */
118 gpio_set_value(GPIO_LED_PWR_R, 1);
119}
120
121static void setup_gpio_leds(void)
122{
Steffen Dirkwinkel098e9ef2019-04-17 13:57:14 +0200123 gpio_request(GPIO_LED_SD2_R, "GPIO_LED_SD2_R");
124 gpio_request(GPIO_LED_SD2_B, "GPIO_LED_SD2_B");
125 gpio_request(GPIO_LED_SD2_G, "GPIO_LED_SD2_G");
126 gpio_request(GPIO_LED_SD1_R, "GPIO_LED_SD1_R");
127 gpio_request(GPIO_LED_SD1_B, "GPIO_LED_SD1_B");
128 gpio_request(GPIO_LED_SD1_G, "GPIO_LED_SD1_G");
129 gpio_request(GPIO_LED_PWR_R, "GPIO_LED_PWR_R");
130 gpio_request(GPIO_LED_PWR_B, "GPIO_LED_PWR_B");
131 gpio_request(GPIO_LED_PWR_G, "GPIO_LED_PWR_G");
132
Patrick Bruennba81b042016-11-04 11:57:02 +0100133 gpio_direction_output(GPIO_LED_SD2_R, 0);
134 gpio_direction_output(GPIO_LED_SD2_B, 0);
135 gpio_direction_output(GPIO_LED_SD2_G, 0);
136 gpio_direction_output(GPIO_LED_SD1_R, 0);
137 gpio_direction_output(GPIO_LED_SD1_B, 0);
138 gpio_direction_output(GPIO_LED_SD1_G, 0);
139 gpio_direction_output(GPIO_LED_PWR_R, 0);
140 gpio_direction_output(GPIO_LED_PWR_B, 0);
141 gpio_direction_output(GPIO_LED_PWR_G, 0);
142}
143
144#ifdef CONFIG_USB_EHCI_MX5
145int board_ehci_hcd_init(int port)
146{
147 /* request VBUS power enable pin, GPIO7_8 */
148 gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
149 return 0;
150}
151#endif
152
153#ifdef CONFIG_FSL_ESDHC
154struct fsl_esdhc_cfg esdhc_cfg[2] = {
155 {MMC_SDHC1_BASE_ADDR},
156 {MMC_SDHC2_BASE_ADDR},
157};
158
159int board_mmc_getcd(struct mmc *mmc)
160{
161 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
162 int ret;
163
Steffen Dirkwinkel098e9ef2019-04-17 13:57:14 +0200164 gpio_request(GPIO_SD1_CD, "GPIO_SD1_CD");
165 gpio_request(GPIO_SD2_CD, "GPIO_SD2_CD");
Patrick Bruennba81b042016-11-04 11:57:02 +0100166 gpio_direction_input(GPIO_SD1_CD);
167 gpio_direction_input(GPIO_SD2_CD);
168
169 if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
170 ret = !gpio_get_value(GPIO_SD1_CD);
171 else
172 ret = !gpio_get_value(GPIO_SD2_CD);
173
174 return ret;
175}
176
177int board_mmc_init(bd_t *bis)
178{
179 u32 index;
180 int ret;
181
182 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
183 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
184
185 for (index = 0; index < CONFIG_SYS_FSL_ESDHC_NUM; index++) {
186 switch (index) {
187 case 0:
188 break;
189 case 1:
190 break;
191 default:
192 printf("Warning: you configured more ESDHC controller(%d) as supported by the board(2)\n",
193 CONFIG_SYS_FSL_ESDHC_NUM);
194 return -EINVAL;
195 }
196 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[index]);
197 if (ret)
198 return ret;
199 }
200
201 return 0;
202}
203#endif
204
205static int power_init(void)
206{
207 /* nothing to do on CX9020 */
208 return 0;
209}
210
211static void clock_1GHz(void)
212{
213 int ret;
214 u32 ref_clk = MXC_HCLK;
215 /*
216 * After increasing voltage to 1.25V, we can switch
217 * CPU clock to 1GHz and DDR to 400MHz safely
218 */
219 ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
220 if (ret)
221 printf("CPU: Switch CPU clock to 1GHZ failed\n");
222
223 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
224 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
225 if (ret)
226 printf("CPU: Switch DDR clock to 400MHz failed\n");
227}
228
229int board_early_init_f(void)
230{
Patrick Bruennba81b042016-11-04 11:57:02 +0100231
232 return 0;
233}
234
235/*
236 * Do not overwrite the console
237 * Use always serial for U-Boot console
238 */
239int overwrite_console(void)
240{
241 return 1;
242}
243
244int board_init(void)
245{
246 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
247
248 mxc_set_sata_internal_clock();
249
Steffen Dirkwinkel098e9ef2019-04-17 13:57:14 +0200250 setup_gpio_leds();
251 setup_gpio_sups();
252 setup_gpio_eim();
253 setup_iomux_lcd();
254
Patrick Bruennba81b042016-11-04 11:57:02 +0100255 return 0;
256}
257
258int checkboard(void)
259{
260 puts("Board: Beckhoff CX9020\n");
261
262 return 0;
263}
264
265static int ccat_config_fn(int assert_config, int flush, int cookie)
266{
267 /* prepare FPGA for programming */
268 weim_cs0_settings(CCAT_MODE_CONFIG);
269 gpio_set_value(GPIO_C3_CONFIG, 0);
270 udelay(1);
271 gpio_set_value(GPIO_C3_CONFIG, 1);
272 udelay(230);
273
274 return FPGA_SUCCESS;
275}
276
277static int ccat_status_fn(int cookie)
278{
279 return FPGA_FAIL;
280}
281
282static int ccat_write_fn(const void *buf, size_t buf_len, int flush, int cookie)
283{
284 const uint8_t *const buffer = buf;
285
286 /* program CCAT */
287 int i;
288 for (i = 0; i < buf_len; ++i)
289 writeb(buffer[i], CCAT_BASE_ADDR);
290
291 writeb(0xff, CCAT_BASE_ADDR);
292 writeb(0xff, CCAT_BASE_ADDR);
293
294 return FPGA_SUCCESS;
295}
296
297static int ccat_done_fn(int cookie)
298{
299 /* programming complete? */
300 return gpio_get_value(GPIO_C3_DONE);
301}
302
303static int ccat_post_fn(int cookie)
304{
305 /* switch to FPGA run mode */
306 weim_cs0_settings(CCAT_MODE_RUN);
307 invalidate_dcache_range((ulong) CCAT_BASE_ADDR, (ulong) CCAT_END_ADDR);
308
309 if (memcmp(CCAT_SIGN_ADDR, CCAT_SIGNATURE, sizeof(CCAT_SIGNATURE))) {
310 printf("Verifing CCAT firmware failed, signature not found\n");
311 return FPGA_FAIL;
312 }
313
314 /* signal "CX booting OS" */
315 gpio_set_value(GPIO_LED_PWR_R, 1);
316 gpio_set_value(GPIO_LED_PWR_G, 1);
317 gpio_set_value(GPIO_LED_PWR_B, 0);
318 return FPGA_SUCCESS;
319}
320
321static Altera_CYC2_Passive_Serial_fns ccat_fns = {
322 .config = ccat_config_fn,
323 .status = ccat_status_fn,
324 .done = ccat_done_fn,
325 .write = ccat_write_fn,
326 .abort = ccat_post_fn,
327 .post = ccat_post_fn,
328};
329
330static Altera_desc ccat_fpga = {
331 .family = Altera_CYC2,
332 .iface = passive_serial,
333 .size = CCAT_SIZE,
334 .iface_fns = &ccat_fns,
335 .base = CCAT_BASE_ADDR,
336};
337
338int board_late_init(void)
339{
340 if (!power_init())
341 clock_1GHz();
342
343 fpga_init();
344 fpga_add(fpga_altera, &ccat_fpga);
345
346 return 0;
347}