2 * (C) Copyright 2008-2009
3 * BuS Elektronik GmbH & Co. KG <www.bus-elektronik.de>
4 * Jens Scharsig <esw@bus-elektronik.de>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <asm/arch/hardware.h>
33 #include <asm/arch/at91_pio.h>
34 #include <asm/arch/at91_pmc.h>
35 #include <asm/arch/at91_mc.h>
36 #include <asm/arch/at91_common.h>
38 #ifdef CONFIG_STATUS_LED
39 #include <status_led.h>
45 extern unsigned long display_width;
46 extern unsigned long display_height;
49 #ifdef CONFIG_CMD_NAND
50 void cpux9k2_nand_hw_init(void);
53 DECLARE_GLOBAL_DATA_PTR;
56 * Miscelaneous platform dependent initialisations
61 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
65 /* Correct IRDA resistor problem / Set PA23_TXD in Output */
66 writel(ATMEL_PMX_AA_TXD2, &pio->pioa.oer);
68 gd->bd->bi_arch_number = MACH_TYPE_EB_CPUX9K2;
69 /* adress of boot parameters */
70 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
72 #ifdef CONFIG_STATUS_LED
73 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
75 #ifdef CONFIG_CMD_NAND
76 cpux9k2_nand_hw_init();
81 int board_early_init_f(void)
83 at91_seriald_hw_init();
87 #ifdef CONFIG_MISC_INIT_R
96 if (getenv("ethaddr") == NULL) {
97 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x00,
98 CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
99 (uchar *) &mac, sizeof(mac)) != 0) {
100 puts("Error reading MAC from EEPROM\n");
105 for (midx = 0; midx < 6; midx++) {
106 if ((mac[midx] != 0) && (mac[midx] != 0xFF))
111 if ((macn6 != mac[6]) || (macn7 != mac[7]))
114 eth_setenv_enetaddr("ethaddr", mac);
116 puts("Error: invalid MAC at EEPROM\n");
119 gd->jt[XF_do_reset] = (void *) do_reset;
121 #ifdef CONFIG_STATUS_LED
122 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
128 #ifdef CONFIG_RESET_PHY_R
137 * DRAM initialisations
142 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
143 CONFIG_SYS_SDRAM_SIZE);
148 * Ethernet initialisations
151 #ifdef CONFIG_DRIVER_AT91EMAC
152 int board_eth_init(bd_t *bis)
155 rc = at91emac_register(bis, (u32) ATMEL_BASE_EMAC);
161 * Disk On Chip (NAND) Millenium initialization.
162 * The NAND lives in the CS2* space
164 #if defined(CONFIG_CMD_NAND)
166 #define MASK_ALE (1 << 22) /* our ALE is AD22 */
167 #define MASK_CLE (1 << 21) /* our CLE is AD21 */
169 void cpux9k2_nand_hw_init(void)
172 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
173 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
174 at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
176 /* Setup Smart Media, fitst enable the address range of CS3 */
177 writel(readl(&mc->ebi.csa) | AT91_EBI_CSA_CS3A, &mc->ebi.csa);
179 /* RWH = 1 | RWS = 0 | TDF = 1 | NWS = 3 */
180 csr = AT91_SMC_CSR_RWHOLD(1) | AT91_SMC_CSR_TDF(1) |
181 AT91_SMC_CSR_NWS(3) |
182 AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_8 |
184 writel(csr, &mc->smc.csr[3]);
186 writel(ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE, &pio->pioc.asr);
187 writel(ATMEL_PMX_CA_BFCK | ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE,
190 /* Configure PC2 as input (signal Nand READY ) */
191 writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.per);
192 writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.odr); /* disable output */
193 writel(ATMEL_PMX_CA_BFCK, &pio->pioc.codr);
195 /* PIOC clock enabling */
196 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
199 static void board_nand_hwcontrol(struct mtd_info *mtd,
200 int cmd, unsigned int ctrl)
202 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
203 struct nand_chip *this = mtd->priv;
204 ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
206 if (ctrl & NAND_CTRL_CHANGE) {
207 IO_ADDR_W &= ~(MASK_ALE | MASK_CLE);
210 IO_ADDR_W |= MASK_CLE;
212 IO_ADDR_W |= MASK_ALE;
214 if ((ctrl & NAND_NCE))
215 writel(1, &pio->pioc.codr);
217 writel(1, &pio->pioc.sodr);
219 this->IO_ADDR_W = (void *) IO_ADDR_W;
221 if (cmd != NAND_CMD_NONE)
222 writeb(cmd, this->IO_ADDR_W);
225 static int board_nand_dev_ready(struct mtd_info *mtd)
227 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
228 return ((readl(&pio->pioc.pdsr) & (1 << 2)) != 0);
231 int board_nand_init(struct nand_chip *nand)
233 cpux9k2_nand_hw_init();
234 nand->ecc.mode = NAND_ECC_SOFT;
235 nand->cmd_ctrl = board_nand_hwcontrol;
236 nand->dev_ready = board_nand_dev_ready;
237 nand->chip_delay = 20;
243 #if defined(CONFIG_VIDEO)
246 * FUNCTION: initialize VCxK device
249 int drv_video_init(void)
251 #ifdef CONFIG_SPLASH_SCREEN
252 unsigned long splash;
256 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
257 at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
259 printf("Init Video as ");
260 s = getenv("displaywidth");
262 display_width = simple_strtoul(s, NULL, 10);
265 s = getenv("displayheight");
267 display_height = simple_strtoul(s, NULL, 10);
269 display_height = 256;
270 printf("%ld x %ld pixel matrix\n", display_width, display_height);
272 /* RWH = 7 | RWS =7 | TDF = 15 | NWS = 0x7F */
273 csr = AT91_SMC_CSR_RWHOLD(7) | AT91_SMC_CSR_RWSETUP(7) |
274 AT91_SMC_CSR_TDF(15) | AT91_SMC_CSR_NWS(127) |
275 AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_16 |
276 AT91_SMC_CSR_BAT_16 | AT91_SMC_CSR_WSEN;
277 writel(csr, &mc->smc.csr[2]);
278 writel(1 << ATMEL_ID_PIOB, &pmc->pcer);
280 vcxk_init(display_width, display_height);
281 #ifdef CONFIG_SPLASH_SCREEN
282 s = getenv("splashimage");
284 splash = simple_strtoul(s, NULL, 16);
285 printf("use splashimage: %lx\n", splash);
286 video_display_bitmap(splash, 0, 0);
293 #ifdef CONFIG_SOFT_I2C
295 void i2c_init_board(void)
298 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
299 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
301 writel(1 << ATMEL_ID_PIOA, &pmc->pcer);
302 pin = ATMEL_PMX_AA_TWD | ATMEL_PMX_AA_TWCK;
303 writel(pin, &pio->pioa.idr);
304 writel(pin, &pio->pioa.pudr);
305 writel(pin, &pio->pioa.per);
306 writel(pin, &pio->pioa.oer);
307 writel(pin, &pio->pioa.sodr);
312 /*--------------------------------------------------------------------------*/
314 #ifdef CONFIG_STATUS_LED
316 void __led_toggle(led_id_t mask)
318 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
320 if (readl(&pio->piod.odsr) & mask)
321 writel(mask, &pio->piod.codr);
323 writel(mask, &pio->piod.codr);
326 void __led_init(led_id_t mask, int state)
328 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
329 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
331 writel(1 << ATMEL_ID_PIOD, &pmc->pcer); /* Enable PIOB clock */
332 /* Disable peripherals on LEDs */
333 writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.per);
334 /* Enable pins as outputs */
335 writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.oer);
336 /* Turn all LEDs OFF */
337 writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.sodr);
339 __led_set(mask, state);
342 void __led_set(led_id_t mask, int state)
344 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
345 if (state == STATUS_LED_ON)
346 writel(mask, &pio->piod.codr);
348 writel(mask, &pio->piod.sodr);
353 /*---------------------------------------------------------------------------*/
355 int do_brightness(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
363 side = simple_strtoul(argv[1], NULL, 10);
364 bright = simple_strtoul(argv[2], NULL, 10);
365 if ((side >= 0) && (side <= 3) &&
366 (bright >= 0) && (bright <= 1000)) {
367 vcxk_setbrightness(side, bright);
370 printf("parameters out of range\n");
371 printf("Usage:\n%s\n", cmdtp->usage);
376 printf("Usage:\n%s\n", cmdtp->usage);
383 /*---------------------------------------------------------------------------*/
386 bright, 3, 0, do_brightness,
387 "bright - sets the display brightness\n",
388 " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n"