2 * (C) Copyright 2008-2009
3 * BuS Elektronik GmbH & Co. KG <www.bus-elektronik.de>
4 * Jens Scharsig <esw@bus-elektronik.de>
6 * SPDX-License-Identifier: GPL-2.0+
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/at91_pio.h>
18 #include <asm/arch/at91_pmc.h>
19 #include <asm/arch/at91_mc.h>
20 #include <asm/arch/at91_common.h>
22 #ifdef CONFIG_STATUS_LED
23 #include <status_led.h>
29 extern unsigned long display_width
;
30 extern unsigned long display_height
;
33 #ifdef CONFIG_CMD_NAND
34 void cpux9k2_nand_hw_init(void);
37 DECLARE_GLOBAL_DATA_PTR
;
40 * Miscelaneous platform dependent initialisations
45 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
47 /* Correct IRDA resistor problem / Set PA23_TXD in Output */
48 writel(ATMEL_PMX_AA_TXD2
, &pio
->pioa
.oer
);
50 gd
->bd
->bi_arch_number
= MACH_TYPE_EB_CPUX9K2
;
51 /* adress of boot parameters */
52 gd
->bd
->bi_boot_params
= CONFIG_SYS_SDRAM_BASE
+ 0x100;
54 #ifdef CONFIG_STATUS_LED
55 status_led_set(STATUS_LED_BOOT
, STATUS_LED_ON
);
57 #ifdef CONFIG_CMD_NAND
58 cpux9k2_nand_hw_init();
63 int board_early_init_f(void)
65 at91_seriald_hw_init();
69 #ifdef CONFIG_MISC_INIT_R
78 if (getenv("ethaddr") == NULL
) {
79 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR
, 0x00,
80 CONFIG_SYS_I2C_EEPROM_ADDR_LEN
,
81 (uchar
*) &mac
, sizeof(mac
)) != 0) {
82 puts("Error reading MAC from EEPROM\n");
87 for (midx
= 0; midx
< 6; midx
++) {
88 if ((mac
[midx
] != 0) && (mac
[midx
] != 0xFF))
93 if ((macn6
!= mac
[6]) || (macn7
!= mac
[7]))
96 eth_setenv_enetaddr("ethaddr", mac
);
98 puts("Error: invalid MAC at EEPROM\n");
101 gd
->jt
[XF_do_reset
] = (void *) do_reset
;
103 #ifdef CONFIG_STATUS_LED
104 status_led_set(STATUS_LED_BOOT
, STATUS_LED_BLINKING
);
110 #ifdef CONFIG_RESET_PHY_R
119 * DRAM initialisations
124 gd
->ram_size
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
,
125 CONFIG_SYS_SDRAM_SIZE
);
130 * Ethernet initialisations
133 #ifdef CONFIG_DRIVER_AT91EMAC
134 int board_eth_init(bd_t
*bis
)
137 rc
= at91emac_register(bis
, (u32
) ATMEL_BASE_EMAC
);
143 * Disk On Chip (NAND) Millenium initialization.
144 * The NAND lives in the CS2* space
146 #if defined(CONFIG_CMD_NAND)
148 #define MASK_ALE (1 << 22) /* our ALE is AD22 */
149 #define MASK_CLE (1 << 21) /* our CLE is AD21 */
151 void cpux9k2_nand_hw_init(void)
154 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
155 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
156 at91_mc_t
*mc
= (at91_mc_t
*) ATMEL_BASE_MC
;
158 /* Setup Smart Media, fitst enable the address range of CS3 */
159 writel(readl(&mc
->ebi
.csa
) | AT91_EBI_CSA_CS3A
, &mc
->ebi
.csa
);
161 /* RWH = 1 | RWS = 0 | TDF = 1 | NWS = 3 */
162 csr
= AT91_SMC_CSR_RWHOLD(1) | AT91_SMC_CSR_TDF(1) |
163 AT91_SMC_CSR_NWS(3) |
164 AT91_SMC_CSR_ACSS_STANDARD
| AT91_SMC_CSR_DBW_8
|
166 writel(csr
, &mc
->smc
.csr
[3]);
168 writel(ATMEL_PMX_CA_SMOE
| ATMEL_PMX_CA_SMWE
, &pio
->pioc
.asr
);
169 writel(ATMEL_PMX_CA_BFCK
| ATMEL_PMX_CA_SMOE
| ATMEL_PMX_CA_SMWE
,
172 /* Configure PC2 as input (signal Nand READY ) */
173 writel(ATMEL_PMX_CA_BFAVD
, &pio
->pioc
.per
);
174 writel(ATMEL_PMX_CA_BFAVD
, &pio
->pioc
.odr
); /* disable output */
175 writel(ATMEL_PMX_CA_BFCK
, &pio
->pioc
.codr
);
177 /* PIOC clock enabling */
178 writel(1 << ATMEL_ID_PIOC
, &pmc
->pcer
);
181 static void board_nand_hwcontrol(struct mtd_info
*mtd
,
182 int cmd
, unsigned int ctrl
)
184 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
185 struct nand_chip
*this = mtd
->priv
;
186 ulong IO_ADDR_W
= (ulong
) this->IO_ADDR_W
;
188 if (ctrl
& NAND_CTRL_CHANGE
) {
189 IO_ADDR_W
&= ~(MASK_ALE
| MASK_CLE
);
192 IO_ADDR_W
|= MASK_CLE
;
194 IO_ADDR_W
|= MASK_ALE
;
196 if ((ctrl
& NAND_NCE
))
197 writel(1, &pio
->pioc
.codr
);
199 writel(1, &pio
->pioc
.sodr
);
201 this->IO_ADDR_W
= (void *) IO_ADDR_W
;
203 if (cmd
!= NAND_CMD_NONE
)
204 writeb(cmd
, this->IO_ADDR_W
);
207 static int board_nand_dev_ready(struct mtd_info
*mtd
)
209 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
210 return ((readl(&pio
->pioc
.pdsr
) & (1 << 2)) != 0);
213 int board_nand_init(struct nand_chip
*nand
)
215 cpux9k2_nand_hw_init();
216 nand
->ecc
.mode
= NAND_ECC_SOFT
;
217 nand
->cmd_ctrl
= board_nand_hwcontrol
;
218 nand
->dev_ready
= board_nand_dev_ready
;
219 nand
->chip_delay
= 20;
225 #if defined(CONFIG_VIDEO)
228 * FUNCTION: initialize VCxK device
231 int drv_video_init(void)
233 #ifdef CONFIG_SPLASH_SCREEN
234 unsigned long splash
;
238 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
239 at91_mc_t
*mc
= (at91_mc_t
*) ATMEL_BASE_MC
;
241 printf("Init Video as ");
242 s
= getenv("displaywidth");
244 display_width
= simple_strtoul(s
, NULL
, 10);
247 s
= getenv("displayheight");
249 display_height
= simple_strtoul(s
, NULL
, 10);
251 display_height
= 256;
252 printf("%ld x %ld pixel matrix\n", display_width
, display_height
);
254 /* RWH = 2 | RWS =2 | TDF = 4 | NWS = 0x6 */
255 csr
= AT91_SMC_CSR_RWHOLD(2) | AT91_SMC_CSR_RWSETUP(2) |
256 AT91_SMC_CSR_TDF(4) | AT91_SMC_CSR_NWS(6) |
257 AT91_SMC_CSR_ACSS_STANDARD
| AT91_SMC_CSR_DBW_16
|
258 AT91_SMC_CSR_BAT_16
| AT91_SMC_CSR_WSEN
;
259 writel(csr
, &mc
->smc
.csr
[2]);
260 writel(1 << ATMEL_ID_PIOB
, &pmc
->pcer
);
262 vcxk_init(display_width
, display_height
);
263 #ifdef CONFIG_SPLASH_SCREEN
264 s
= getenv("splashimage");
266 splash
= simple_strtoul(s
, NULL
, 16);
267 printf("use splashimage: %lx\n", splash
);
268 video_display_bitmap(splash
, 0, 0);
275 #ifdef CONFIG_SOFT_I2C
277 void i2c_init_board(void)
280 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
281 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
283 writel(1 << ATMEL_ID_PIOA
, &pmc
->pcer
);
284 pin
= ATMEL_PMX_AA_TWD
| ATMEL_PMX_AA_TWCK
;
285 writel(pin
, &pio
->pioa
.idr
);
286 writel(pin
, &pio
->pioa
.pudr
);
287 writel(pin
, &pio
->pioa
.per
);
288 writel(pin
, &pio
->pioa
.oer
);
289 writel(pin
, &pio
->pioa
.sodr
);
294 /*--------------------------------------------------------------------------*/
296 #ifdef CONFIG_STATUS_LED
298 void __led_toggle(led_id_t mask
)
300 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
302 if (readl(&pio
->piod
.odsr
) & mask
)
303 writel(mask
, &pio
->piod
.codr
);
305 writel(mask
, &pio
->piod
.codr
);
308 void __led_init(led_id_t mask
, int state
)
310 at91_pmc_t
*pmc
= (at91_pmc_t
*) ATMEL_BASE_PMC
;
311 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
313 writel(1 << ATMEL_ID_PIOD
, &pmc
->pcer
); /* Enable PIOB clock */
314 /* Disable peripherals on LEDs */
315 writel(STATUS_LED_BIT
| STATUS_LED_BIT1
, &pio
->piod
.per
);
316 /* Enable pins as outputs */
317 writel(STATUS_LED_BIT
| STATUS_LED_BIT1
, &pio
->piod
.oer
);
318 /* Turn all LEDs OFF */
319 writel(STATUS_LED_BIT
| STATUS_LED_BIT1
, &pio
->piod
.sodr
);
321 __led_set(mask
, state
);
324 void __led_set(led_id_t mask
, int state
)
326 at91_pio_t
*pio
= (at91_pio_t
*) ATMEL_BASE_PIO
;
327 if (state
== STATUS_LED_ON
)
328 writel(mask
, &pio
->piod
.codr
);
330 writel(mask
, &pio
->piod
.sodr
);
335 /*---------------------------------------------------------------------------*/
337 int do_brightness(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
345 side
= simple_strtoul(argv
[1], NULL
, 10);
346 bright
= simple_strtoul(argv
[2], NULL
, 10);
347 if ((side
>= 0) && (side
<= 3) &&
348 (bright
>= 0) && (bright
<= 1000)) {
349 vcxk_setbrightness(side
, bright
);
352 printf("parameters out of range\n");
353 printf("Usage:\n%s\n", cmdtp
->usage
);
358 printf("Usage:\n%s\n", cmdtp
->usage
);
365 /*---------------------------------------------------------------------------*/
368 bright
, 3, 0, do_brightness
,
369 "bright - sets the display brightness\n",
370 " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n"