1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2013 Imagination Technologies
15 #include <mach/jz4780.h>
16 #include <mach/jz4780_dram.h>
17 #include <mach/jz4780_gpio.h>
26 static void ci20_mux_mmc(void)
28 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
31 writel(0x30f00000, gpio_regs + GPIO_PXINTC(4));
32 writel(0x30f00000, gpio_regs + GPIO_PXMASKC(4));
33 writel(0x30f00000, gpio_regs + GPIO_PXPAT1C(4));
34 writel(0x30f00000, gpio_regs + GPIO_PXPAT0C(4));
35 writel(0x30f00000, gpio_regs + GPIO_PXPENC(4));
36 jz4780_clk_ungate_mmc();
39 #ifndef CONFIG_SPL_BUILD
41 static void ci20_mux_eth(void)
43 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
45 #ifdef CONFIG_MTD_RAW_NAND
46 /* setup pins (some already setup for NAND) */
47 writel(0x04030000, gpio_regs + GPIO_PXINTC(0));
48 writel(0x04030000, gpio_regs + GPIO_PXMASKC(0));
49 writel(0x04030000, gpio_regs + GPIO_PXPAT1C(0));
50 writel(0x04030000, gpio_regs + GPIO_PXPAT0C(0));
51 writel(0x04030000, gpio_regs + GPIO_PXPENS(0));
53 /* setup pins (as above +NAND CS +RD/WE +SDx +SAx) */
54 writel(0x0dff00ff, gpio_regs + GPIO_PXINTC(0));
55 writel(0x0dff00ff, gpio_regs + GPIO_PXMASKC(0));
56 writel(0x0dff00ff, gpio_regs + GPIO_PXPAT1C(0));
57 writel(0x0dff00ff, gpio_regs + GPIO_PXPAT0C(0));
58 writel(0x0dff00ff, gpio_regs + GPIO_PXPENS(0));
59 writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
60 writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
61 writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
62 writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
63 writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
67 static void ci20_mux_jtag(void)
70 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
73 writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
74 writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
75 writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
76 writel(3 << 30, gpio_regs + GPIO_PXPAT0C(0));
80 static void ci20_mux_nand(void)
82 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
85 writel(0x002c00ff, gpio_regs + GPIO_PXINTC(0));
86 writel(0x002c00ff, gpio_regs + GPIO_PXMASKC(0));
87 writel(0x002c00ff, gpio_regs + GPIO_PXPAT1C(0));
88 writel(0x002c00ff, gpio_regs + GPIO_PXPAT0C(0));
89 writel(0x002c00ff, gpio_regs + GPIO_PXPENS(0));
90 writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
91 writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
92 writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
93 writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
94 writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
97 jz47xx_gpio_direction_input(JZ_GPIO(0, 20));
98 writel(20, gpio_regs + GPIO_PXPENS(0));
100 /* disable write protect */
101 jz47xx_gpio_direction_output(JZ_GPIO(5, 22), 1);
104 static void ci20_mux_uart(void)
106 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
109 writel(0x9, gpio_regs + GPIO_PXINTC(5));
110 writel(0x9, gpio_regs + GPIO_PXMASKC(5));
111 writel(0x9, gpio_regs + GPIO_PXPAT1C(5));
112 writel(0x9, gpio_regs + GPIO_PXPAT0C(5));
113 writel(0x9, gpio_regs + GPIO_PXPENC(5));
114 jz4780_clk_ungate_uart(0);
117 jz4780_clk_ungate_uart(1);
118 jz4780_clk_ungate_uart(2);
122 writel(1 << 12, gpio_regs + GPIO_PXINTC(3));
123 writel(1 << 12, gpio_regs + GPIO_PXMASKS(3));
124 writel(1 << 12, gpio_regs + GPIO_PXPAT1S(3));
125 writel(1 << 12, gpio_regs + GPIO_PXPAT0C(3));
126 writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
127 writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
128 writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
129 writel(1 << 30, gpio_regs + GPIO_PXPAT0C(0));
130 writel(1 << 31, gpio_regs + GPIO_PXPAT0S(0));
131 jz4780_clk_ungate_uart(3);
135 writel(0x100400, gpio_regs + GPIO_PXINTC(2));
136 writel(0x100400, gpio_regs + GPIO_PXMASKC(2));
137 writel(0x100400, gpio_regs + GPIO_PXPAT1S(2));
138 writel(0x100400, gpio_regs + GPIO_PXPAT0C(2));
139 writel(0x100400, gpio_regs + GPIO_PXPENC(2));
140 jz4780_clk_ungate_uart(4);
143 int board_early_init_f(void)
152 /* SYS_POWER_IND high (LED blue, VBUS off) */
153 jz47xx_gpio_direction_output(JZ_GPIO(5, 15), 0);
156 jz47xx_gpio_direction_output(JZ_GPIO(2, 0), 0);
157 jz47xx_gpio_direction_output(JZ_GPIO(2, 1), 0);
158 jz47xx_gpio_direction_output(JZ_GPIO(2, 2), 0);
159 jz47xx_gpio_direction_output(JZ_GPIO(2, 3), 0);
164 int misc_init_r(void)
166 const u32 efuse_clk = jz4780_clk_get_efuse_clk();
168 char manufacturer[3];
170 /* Read the board OTP data */
171 jz4780_efuse_init(efuse_clk);
172 jz4780_efuse_read(0x18, 16, (u8 *)&otp);
174 /* Set MAC address */
175 if (!is_valid_ethaddr(otp.mac)) {
176 /* no MAC assigned, generate one from the unique chip ID */
177 jz4780_efuse_read(0x8, 4, &otp.mac[0]);
178 jz4780_efuse_read(0x12, 2, &otp.mac[4]);
179 otp.mac[0] = (otp.mac[0] | 0x02) & ~0x01;
181 eth_env_set_enetaddr("ethaddr", otp.mac);
183 /* Put other board information into the environment */
184 env_set_ulong("serial#", otp.serial_number);
185 env_set_ulong("board_date", otp.date);
186 manufacturer[0] = otp.manufacturer[0];
187 manufacturer[1] = otp.manufacturer[1];
189 env_set("board_mfr", manufacturer);
194 #ifdef CONFIG_DRIVER_DM9000
195 int board_eth_init(bd_t *bis)
198 jz4780_clk_ungate_ethernet();
200 /* Enable power (PB25) */
201 jz47xx_gpio_direction_output(JZ_GPIO(1, 25), 1);
205 jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 0);
207 jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 1);
210 return dm9000_initialize(bis);
212 #endif /* CONFIG_DRIVER_DM9000 */
215 static u8 ci20_revision(void)
217 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
220 jz47xx_gpio_direction_input(JZ_GPIO(2, 18));
221 jz47xx_gpio_direction_input(JZ_GPIO(2, 19));
224 writel(BIT(18) | BIT(19), gpio_regs + GPIO_PXPENC(2));
226 /* Read PC18/19 for version */
227 val = (!!jz47xx_gpio_get_value(JZ_GPIO(2, 18))) |
228 ((!!jz47xx_gpio_get_value(JZ_GPIO(2, 19))) << 1);
230 if (val == 3) /* Rev 1 boards had no pulldowns - giving 3 */
232 if (val == 1) /* Rev 2 boards pulldown port C bit 18 giving 1 */
240 gd->ram_size = sdram_size(0) + sdram_size(1);
244 /* U-Boot common routines */
247 printf("Board: Creator CI20 (rev.%d)\n", ci20_revision());
251 #ifdef CONFIG_SPL_BUILD
253 #if defined(CONFIG_SPL_MMC_SUPPORT)
254 int board_mmc_init(bd_t *bd)
257 return jz_mmc_init((void __iomem *)MSC0_BASE);
261 static const struct jz4780_ddr_config K4B2G0846Q_48_config = {
263 (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
264 (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
266 (4 << DDRC_TIMING2_TCCD_BIT) | (15 << DDRC_TIMING2_TRAS_BIT) |
267 (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
269 (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
270 (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
271 (21 << DDRC_TIMING3_TRC_BIT),
273 (31 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
274 (4 << DDRC_TIMING4_TCKE_BIT) | (9 << DDRC_TIMING4_TMINSR_BIT) |
275 (8 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
277 (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
278 (4 << DDRC_TIMING5_TWDLAT_BIT),
280 (25 << DDRC_TIMING6_TXSRD_BIT) | (12 << DDRC_TIMING6_TFAW_BIT) |
281 (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
285 /* Mode Register 0 */
287 #ifdef SDRAM_DISABLE_DLL
288 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
290 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
305 static const struct jz4780_ddr_config H5TQ2G83CFR_48_config = {
307 (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
308 (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
310 (4 << DDRC_TIMING2_TCCD_BIT) | (16 << DDRC_TIMING2_TRAS_BIT) |
311 (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
313 (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
314 (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
315 (22 << DDRC_TIMING3_TRC_BIT),
317 (42 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
318 (4 << DDRC_TIMING4_TCKE_BIT) | (7 << DDRC_TIMING4_TMINSR_BIT) |
319 (3 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
321 (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
322 (4 << DDRC_TIMING5_TWDLAT_BIT),
324 (25 << DDRC_TIMING6_TXSRD_BIT) | (20 << DDRC_TIMING6_TFAW_BIT) |
325 (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
329 /* Mode Register 0 */
331 #ifdef SDRAM_DISABLE_DLL
332 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
334 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
349 #if (CONFIG_SYS_MHZ != 1200)
350 #error No DDR configuration for CPU speed
353 const struct jz4780_ddr_config *jz4780_get_ddr_config(void)
355 const int board_revision = ci20_revision();
357 if (board_revision == 2)
358 return &K4B2G0846Q_48_config;
359 else /* Fall back to H5TQ2G83CFR RAM */
360 return &H5TQ2G83CFR_48_config;