1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2013 Imagination Technologies
11 #include <environment.h>
16 #include <mach/jz4780.h>
17 #include <mach/jz4780_dram.h>
18 #include <mach/jz4780_gpio.h>
27 static void ci20_mux_mmc(void)
29 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
32 writel(0x30f00000, gpio_regs + GPIO_PXINTC(4));
33 writel(0x30f00000, gpio_regs + GPIO_PXMASKC(4));
34 writel(0x30f00000, gpio_regs + GPIO_PXPAT1C(4));
35 writel(0x30f00000, gpio_regs + GPIO_PXPAT0C(4));
36 writel(0x30f00000, gpio_regs + GPIO_PXPENC(4));
37 jz4780_clk_ungate_mmc();
40 #ifndef CONFIG_SPL_BUILD
42 static void ci20_mux_eth(void)
44 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
47 /* setup pins (some already setup for NAND) */
48 writel(0x04030000, gpio_regs + GPIO_PXINTC(0));
49 writel(0x04030000, gpio_regs + GPIO_PXMASKC(0));
50 writel(0x04030000, gpio_regs + GPIO_PXPAT1C(0));
51 writel(0x04030000, gpio_regs + GPIO_PXPAT0C(0));
52 writel(0x04030000, gpio_regs + GPIO_PXPENS(0));
54 /* setup pins (as above +NAND CS +RD/WE +SDx +SAx) */
55 writel(0x0dff00ff, gpio_regs + GPIO_PXINTC(0));
56 writel(0x0dff00ff, gpio_regs + GPIO_PXMASKC(0));
57 writel(0x0dff00ff, gpio_regs + GPIO_PXPAT1C(0));
58 writel(0x0dff00ff, gpio_regs + GPIO_PXPAT0C(0));
59 writel(0x0dff00ff, gpio_regs + GPIO_PXPENS(0));
60 writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
61 writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
62 writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
63 writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
64 writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
68 static void ci20_mux_jtag(void)
71 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
74 writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
75 writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
76 writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
77 writel(3 << 30, gpio_regs + GPIO_PXPAT0C(0));
81 static void ci20_mux_nand(void)
83 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
86 writel(0x002c00ff, gpio_regs + GPIO_PXINTC(0));
87 writel(0x002c00ff, gpio_regs + GPIO_PXMASKC(0));
88 writel(0x002c00ff, gpio_regs + GPIO_PXPAT1C(0));
89 writel(0x002c00ff, gpio_regs + GPIO_PXPAT0C(0));
90 writel(0x002c00ff, gpio_regs + GPIO_PXPENS(0));
91 writel(0x00000003, gpio_regs + GPIO_PXINTC(1));
92 writel(0x00000003, gpio_regs + GPIO_PXMASKC(1));
93 writel(0x00000003, gpio_regs + GPIO_PXPAT1C(1));
94 writel(0x00000003, gpio_regs + GPIO_PXPAT0C(1));
95 writel(0x00000003, gpio_regs + GPIO_PXPENS(1));
98 jz47xx_gpio_direction_input(JZ_GPIO(0, 20));
99 writel(20, gpio_regs + GPIO_PXPENS(0));
101 /* disable write protect */
102 jz47xx_gpio_direction_output(JZ_GPIO(5, 22), 1);
105 static void ci20_mux_uart(void)
107 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
110 writel(0x9, gpio_regs + GPIO_PXINTC(5));
111 writel(0x9, gpio_regs + GPIO_PXMASKC(5));
112 writel(0x9, gpio_regs + GPIO_PXPAT1C(5));
113 writel(0x9, gpio_regs + GPIO_PXPAT0C(5));
114 writel(0x9, gpio_regs + GPIO_PXPENC(5));
115 jz4780_clk_ungate_uart(0);
118 jz4780_clk_ungate_uart(1);
119 jz4780_clk_ungate_uart(2);
123 writel(1 << 12, gpio_regs + GPIO_PXINTC(3));
124 writel(1 << 12, gpio_regs + GPIO_PXMASKS(3));
125 writel(1 << 12, gpio_regs + GPIO_PXPAT1S(3));
126 writel(1 << 12, gpio_regs + GPIO_PXPAT0C(3));
127 writel(3 << 30, gpio_regs + GPIO_PXINTC(0));
128 writel(3 << 30, gpio_regs + GPIO_PXMASKC(0));
129 writel(3 << 30, gpio_regs + GPIO_PXPAT1C(0));
130 writel(1 << 30, gpio_regs + GPIO_PXPAT0C(0));
131 writel(1 << 31, gpio_regs + GPIO_PXPAT0S(0));
132 jz4780_clk_ungate_uart(3);
136 writel(0x100400, gpio_regs + GPIO_PXINTC(2));
137 writel(0x100400, gpio_regs + GPIO_PXMASKC(2));
138 writel(0x100400, gpio_regs + GPIO_PXPAT1S(2));
139 writel(0x100400, gpio_regs + GPIO_PXPAT0C(2));
140 writel(0x100400, gpio_regs + GPIO_PXPENC(2));
141 jz4780_clk_ungate_uart(4);
144 int board_early_init_f(void)
153 /* SYS_POWER_IND high (LED blue, VBUS off) */
154 jz47xx_gpio_direction_output(JZ_GPIO(5, 15), 0);
157 jz47xx_gpio_direction_output(JZ_GPIO(2, 0), 0);
158 jz47xx_gpio_direction_output(JZ_GPIO(2, 1), 0);
159 jz47xx_gpio_direction_output(JZ_GPIO(2, 2), 0);
160 jz47xx_gpio_direction_output(JZ_GPIO(2, 3), 0);
165 int misc_init_r(void)
167 const u32 efuse_clk = jz4780_clk_get_efuse_clk();
169 char manufacturer[3];
171 /* Read the board OTP data */
172 jz4780_efuse_init(efuse_clk);
173 jz4780_efuse_read(0x18, 16, (u8 *)&otp);
175 /* Set MAC address */
176 if (!is_valid_ethaddr(otp.mac)) {
177 /* no MAC assigned, generate one from the unique chip ID */
178 jz4780_efuse_read(0x8, 4, &otp.mac[0]);
179 jz4780_efuse_read(0x12, 2, &otp.mac[4]);
180 otp.mac[0] = (otp.mac[0] | 0x02) & ~0x01;
182 eth_env_set_enetaddr("ethaddr", otp.mac);
184 /* Put other board information into the environment */
185 env_set_ulong("serial#", otp.serial_number);
186 env_set_ulong("board_date", otp.date);
187 manufacturer[0] = otp.manufacturer[0];
188 manufacturer[1] = otp.manufacturer[1];
190 env_set("board_mfr", manufacturer);
195 #ifdef CONFIG_DRIVER_DM9000
196 int board_eth_init(bd_t *bis)
199 jz4780_clk_ungate_ethernet();
201 /* Enable power (PB25) */
202 jz47xx_gpio_direction_output(JZ_GPIO(1, 25), 1);
206 jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 0);
208 jz47xx_gpio_direction_output(JZ_GPIO(5, 12), 1);
211 return dm9000_initialize(bis);
213 #endif /* CONFIG_DRIVER_DM9000 */
216 static u8 ci20_revision(void)
218 void __iomem *gpio_regs = (void __iomem *)GPIO_BASE;
221 jz47xx_gpio_direction_input(JZ_GPIO(2, 18));
222 jz47xx_gpio_direction_input(JZ_GPIO(2, 19));
225 writel(BIT(18) | BIT(19), gpio_regs + GPIO_PXPENC(2));
227 /* Read PC18/19 for version */
228 val = (!!jz47xx_gpio_get_value(JZ_GPIO(2, 18))) |
229 ((!!jz47xx_gpio_get_value(JZ_GPIO(2, 19))) << 1);
231 if (val == 3) /* Rev 1 boards had no pulldowns - giving 3 */
233 if (val == 1) /* Rev 2 boards pulldown port C bit 18 giving 1 */
241 gd->ram_size = sdram_size(0) + sdram_size(1);
245 /* U-Boot common routines */
248 printf("Board: Creator CI20 (rev.%d)\n", ci20_revision());
252 #ifdef CONFIG_SPL_BUILD
254 #if defined(CONFIG_SPL_MMC_SUPPORT)
255 int board_mmc_init(bd_t *bd)
258 return jz_mmc_init((void __iomem *)MSC0_BASE);
262 static const struct jz4780_ddr_config K4B2G0846Q_48_config = {
264 (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
265 (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
267 (4 << DDRC_TIMING2_TCCD_BIT) | (15 << DDRC_TIMING2_TRAS_BIT) |
268 (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
270 (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
271 (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
272 (21 << DDRC_TIMING3_TRC_BIT),
274 (31 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
275 (4 << DDRC_TIMING4_TCKE_BIT) | (9 << DDRC_TIMING4_TMINSR_BIT) |
276 (8 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
278 (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
279 (4 << DDRC_TIMING5_TWDLAT_BIT),
281 (25 << DDRC_TIMING6_TXSRD_BIT) | (12 << DDRC_TIMING6_TFAW_BIT) |
282 (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
286 /* Mode Register 0 */
288 #ifdef SDRAM_DISABLE_DLL
289 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
291 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
306 static const struct jz4780_ddr_config H5TQ2G83CFR_48_config = {
308 (4 << DDRC_TIMING1_TRTP_BIT) | (13 << DDRC_TIMING1_TWTR_BIT) |
309 (6 << DDRC_TIMING1_TWR_BIT) | (5 << DDRC_TIMING1_TWL_BIT),
311 (4 << DDRC_TIMING2_TCCD_BIT) | (16 << DDRC_TIMING2_TRAS_BIT) |
312 (6 << DDRC_TIMING2_TRCD_BIT) | (6 << DDRC_TIMING2_TRL_BIT),
314 (4 << DDRC_TIMING3_ONUM) | (7 << DDRC_TIMING3_TCKSRE_BIT) |
315 (6 << DDRC_TIMING3_TRP_BIT) | (4 << DDRC_TIMING3_TRRD_BIT) |
316 (22 << DDRC_TIMING3_TRC_BIT),
318 (42 << DDRC_TIMING4_TRFC_BIT) | (1 << DDRC_TIMING4_TRWCOV_BIT) |
319 (4 << DDRC_TIMING4_TCKE_BIT) | (7 << DDRC_TIMING4_TMINSR_BIT) |
320 (3 << DDRC_TIMING4_TXP_BIT) | (3 << DDRC_TIMING4_TMRD_BIT),
322 (8 << DDRC_TIMING5_TRTW_BIT) | (4 << DDRC_TIMING5_TRDLAT_BIT) |
323 (4 << DDRC_TIMING5_TWDLAT_BIT),
325 (25 << DDRC_TIMING6_TXSRD_BIT) | (20 << DDRC_TIMING6_TFAW_BIT) |
326 (2 << DDRC_TIMING6_TCFGW_BIT) | (2 << DDRC_TIMING6_TCFGR_BIT),
330 /* Mode Register 0 */
332 #ifdef SDRAM_DISABLE_DLL
333 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS | DDR3_MR1_DLL_DISABLE),
335 .mr1 = (DDR3_MR1_DIC_7 | DDR3_MR1_RTT_DIS),
350 #if (CONFIG_SYS_MHZ != 1200)
351 #error No DDR configuration for CPU speed
354 const struct jz4780_ddr_config *jz4780_get_ddr_config(void)
356 const int board_revision = ci20_revision();
358 if (board_revision == 2)
359 return &K4B2G0846Q_48_config;
360 else /* Fall back to H5TQ2G83CFR RAM */
361 return &H5TQ2G83CFR_48_config;