ARM: davinci: da850 EVM: read mac address from SPI flash
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-davinci / board-da850-evm.c
blobd0cd9df233cdc13230de538737ed823b5e991ac0
1 /*
2 * TI DA850/OMAP-L138 EVM board
4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
6 * Derived from: arch/arm/mach-davinci/board-da830-evm.c
7 * Original Copyrights follow:
9 * 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
12 * or implied.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/console.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c/at24.h>
20 #include <linux/gpio.h>
21 #include <linux/platform_device.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/nand.h>
24 #include <linux/mtd/partitions.h>
25 #include <linux/mtd/physmap.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
30 #include <mach/common.h>
31 #include <mach/irqs.h>
32 #include <mach/cp_intc.h>
33 #include <mach/da8xx.h>
34 #include <mach/nand.h>
36 #define DA850_EVM_PHY_MASK 0x1
37 #define DA850_EVM_MDIO_FREQUENCY 2200000 /* PHY bus frequency */
39 #define DA850_LCD_BL_PIN GPIO_TO_PIN(2, 15)
40 #define DA850_LCD_PWR_PIN GPIO_TO_PIN(8, 10)
42 #define DA850_MMCSD_CD_PIN GPIO_TO_PIN(4, 0)
43 #define DA850_MMCSD_WP_PIN GPIO_TO_PIN(4, 1)
45 #ifdef CONFIG_MTD
46 static void da850_evm_m25p80_notify_add(struct mtd_info *mtd)
48 char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
49 size_t retlen;
51 if (!strcmp(mtd->name, "MAC-Address")) {
52 mtd->read(mtd, 0, ETH_ALEN, &retlen, mac_addr);
53 if (retlen == ETH_ALEN)
54 pr_info("Read MAC addr from SPI Flash: %pM\n",
55 mac_addr);
59 static struct mtd_notifier da850evm_spi_notifier = {
60 .add = da850_evm_m25p80_notify_add,
63 static void da850_evm_setup_mac_addr(void)
65 register_mtd_user(&da850evm_spi_notifier);
67 #else
68 static void da850_evm_setup_mac_addr(void) { }
69 #endif
71 static struct mtd_partition da850_evm_norflash_partition[] = {
73 .name = "NOR filesystem",
74 .offset = 0,
75 .size = MTDPART_SIZ_FULL,
76 .mask_flags = 0,
80 static struct physmap_flash_data da850_evm_norflash_data = {
81 .width = 2,
82 .parts = da850_evm_norflash_partition,
83 .nr_parts = ARRAY_SIZE(da850_evm_norflash_partition),
86 static struct resource da850_evm_norflash_resource[] = {
88 .start = DA8XX_AEMIF_CS2_BASE,
89 .end = DA8XX_AEMIF_CS2_BASE + SZ_32M - 1,
90 .flags = IORESOURCE_MEM,
94 static struct platform_device da850_evm_norflash_device = {
95 .name = "physmap-flash",
96 .id = 0,
97 .dev = {
98 .platform_data = &da850_evm_norflash_data,
100 .num_resources = 1,
101 .resource = da850_evm_norflash_resource,
104 /* DA850/OMAP-L138 EVM includes a 512 MByte large-page NAND flash
105 * (128K blocks). It may be used instead of the (default) SPI flash
106 * to boot, using TI's tools to install the secondary boot loader
107 * (UBL) and U-Boot.
109 struct mtd_partition da850_evm_nandflash_partition[] = {
111 .name = "u-boot env",
112 .offset = 0,
113 .size = SZ_128K,
114 .mask_flags = MTD_WRITEABLE,
117 .name = "UBL",
118 .offset = MTDPART_OFS_APPEND,
119 .size = SZ_128K,
120 .mask_flags = MTD_WRITEABLE,
123 .name = "u-boot",
124 .offset = MTDPART_OFS_APPEND,
125 .size = 4 * SZ_128K,
126 .mask_flags = MTD_WRITEABLE,
129 .name = "kernel",
130 .offset = 0x200000,
131 .size = SZ_2M,
132 .mask_flags = 0,
135 .name = "filesystem",
136 .offset = MTDPART_OFS_APPEND,
137 .size = MTDPART_SIZ_FULL,
138 .mask_flags = 0,
142 static struct davinci_nand_pdata da850_evm_nandflash_data = {
143 .parts = da850_evm_nandflash_partition,
144 .nr_parts = ARRAY_SIZE(da850_evm_nandflash_partition),
145 .ecc_mode = NAND_ECC_HW,
146 .options = NAND_USE_FLASH_BBT,
149 static struct resource da850_evm_nandflash_resource[] = {
151 .start = DA8XX_AEMIF_CS3_BASE,
152 .end = DA8XX_AEMIF_CS3_BASE + SZ_512K + 2 * SZ_1K - 1,
153 .flags = IORESOURCE_MEM,
156 .start = DA8XX_AEMIF_CTL_BASE,
157 .end = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,
158 .flags = IORESOURCE_MEM,
162 static struct platform_device da850_evm_nandflash_device = {
163 .name = "davinci_nand",
164 .id = 1,
165 .dev = {
166 .platform_data = &da850_evm_nandflash_data,
168 .num_resources = ARRAY_SIZE(da850_evm_nandflash_resource),
169 .resource = da850_evm_nandflash_resource,
172 static struct i2c_board_info __initdata da850_evm_i2c_devices[] = {
174 I2C_BOARD_INFO("tlv320aic3x", 0x18),
178 static struct davinci_i2c_platform_data da850_evm_i2c_0_pdata = {
179 .bus_freq = 100, /* kHz */
180 .bus_delay = 0, /* usec */
183 static struct davinci_uart_config da850_evm_uart_config __initdata = {
184 .enabled_uarts = 0x7,
187 static struct platform_device *da850_evm_devices[] __initdata = {
188 &da850_evm_nandflash_device,
189 &da850_evm_norflash_device,
192 /* davinci da850 evm audio machine driver */
193 static u8 da850_iis_serializer_direction[] = {
194 INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,
195 INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,
196 INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, TX_MODE,
197 RX_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,
200 static struct snd_platform_data da850_evm_snd_data = {
201 .tx_dma_offset = 0x2000,
202 .rx_dma_offset = 0x2000,
203 .op_mode = DAVINCI_MCASP_IIS_MODE,
204 .num_serializer = ARRAY_SIZE(da850_iis_serializer_direction),
205 .tdm_slots = 2,
206 .serial_dir = da850_iis_serializer_direction,
207 .eventq_no = EVENTQ_1,
208 .version = MCASP_VERSION_2,
209 .txnumevt = 1,
210 .rxnumevt = 1,
213 static int da850_evm_mmc_get_ro(int index)
215 return gpio_get_value(DA850_MMCSD_WP_PIN);
218 static int da850_evm_mmc_get_cd(int index)
220 return !gpio_get_value(DA850_MMCSD_CD_PIN);
223 static struct davinci_mmc_config da850_mmc_config = {
224 .get_ro = da850_evm_mmc_get_ro,
225 .get_cd = da850_evm_mmc_get_cd,
226 .wires = 4,
227 .version = MMC_CTLR_VERSION_2,
230 static int da850_lcd_hw_init(void)
232 int status;
234 status = gpio_request(DA850_LCD_BL_PIN, "lcd bl\n");
235 if (status < 0)
236 return status;
238 status = gpio_request(DA850_LCD_PWR_PIN, "lcd pwr\n");
239 if (status < 0) {
240 gpio_free(DA850_LCD_BL_PIN);
241 return status;
244 gpio_direction_output(DA850_LCD_BL_PIN, 0);
245 gpio_direction_output(DA850_LCD_PWR_PIN, 0);
247 /* disable lcd backlight */
248 gpio_set_value(DA850_LCD_BL_PIN, 0);
250 /* disable lcd power */
251 gpio_set_value(DA850_LCD_PWR_PIN, 0);
253 /* enable lcd power */
254 gpio_set_value(DA850_LCD_PWR_PIN, 1);
256 /* enable lcd backlight */
257 gpio_set_value(DA850_LCD_BL_PIN, 1);
259 return 0;
262 #define DA8XX_AEMIF_CE2CFG_OFFSET 0x10
263 #define DA8XX_AEMIF_ASIZE_16BIT 0x1
265 static void __init da850_evm_init_nor(void)
267 void __iomem *aemif_addr;
269 aemif_addr = ioremap(DA8XX_AEMIF_CTL_BASE, SZ_32K);
271 /* Configure data bus width of CS2 to 16 bit */
272 writel(readl(aemif_addr + DA8XX_AEMIF_CE2CFG_OFFSET) |
273 DA8XX_AEMIF_ASIZE_16BIT,
274 aemif_addr + DA8XX_AEMIF_CE2CFG_OFFSET);
276 iounmap(aemif_addr);
279 #if defined(CONFIG_MTD_PHYSMAP) || \
280 defined(CONFIG_MTD_PHYSMAP_MODULE)
281 #define HAS_NOR 1
282 #else
283 #define HAS_NOR 0
284 #endif
286 #if defined(CONFIG_MMC_DAVINCI) || \
287 defined(CONFIG_MMC_DAVINCI_MODULE)
288 #define HAS_MMC 1
289 #else
290 #define HAS_MMC 0
291 #endif
293 static __init void da850_evm_init(void)
295 struct davinci_soc_info *soc_info = &davinci_soc_info;
296 int ret;
298 ret = da8xx_pinmux_setup(da850_nand_pins);
299 if (ret)
300 pr_warning("da850_evm_init: nand mux setup failed: %d\n",
301 ret);
303 ret = da8xx_pinmux_setup(da850_nor_pins);
304 if (ret)
305 pr_warning("da850_evm_init: nor mux setup failed: %d\n",
306 ret);
308 da850_evm_init_nor();
310 platform_add_devices(da850_evm_devices,
311 ARRAY_SIZE(da850_evm_devices));
313 ret = da8xx_register_edma();
314 if (ret)
315 pr_warning("da850_evm_init: edma registration failed: %d\n",
316 ret);
318 ret = da8xx_pinmux_setup(da850_i2c0_pins);
319 if (ret)
320 pr_warning("da850_evm_init: i2c0 mux setup failed: %d\n",
321 ret);
323 ret = da8xx_register_i2c(0, &da850_evm_i2c_0_pdata);
324 if (ret)
325 pr_warning("da850_evm_init: i2c0 registration failed: %d\n",
326 ret);
328 soc_info->emac_pdata->phy_mask = DA850_EVM_PHY_MASK;
329 soc_info->emac_pdata->mdio_max_freq = DA850_EVM_MDIO_FREQUENCY;
330 soc_info->emac_pdata->rmii_en = 0;
332 ret = da8xx_pinmux_setup(da850_cpgmac_pins);
333 if (ret)
334 pr_warning("da850_evm_init: cpgmac mux setup failed: %d\n",
335 ret);
337 ret = da8xx_register_emac();
338 if (ret)
339 pr_warning("da850_evm_init: emac registration failed: %d\n",
340 ret);
342 ret = da8xx_register_watchdog();
343 if (ret)
344 pr_warning("da830_evm_init: watchdog registration failed: %d\n",
345 ret);
347 if (HAS_MMC) {
348 if (HAS_NOR)
349 pr_warning("WARNING: both NOR Flash and MMC/SD are "
350 "enabled, but they share AEMIF pins.\n"
351 "\tDisable one of them.\n");
353 ret = da8xx_pinmux_setup(da850_mmcsd0_pins);
354 if (ret)
355 pr_warning("da850_evm_init: mmcsd0 mux setup failed:"
356 " %d\n", ret);
358 ret = gpio_request(DA850_MMCSD_CD_PIN, "MMC CD\n");
359 if (ret)
360 pr_warning("da850_evm_init: can not open GPIO %d\n",
361 DA850_MMCSD_CD_PIN);
362 gpio_direction_input(DA850_MMCSD_CD_PIN);
364 ret = gpio_request(DA850_MMCSD_WP_PIN, "MMC WP\n");
365 if (ret)
366 pr_warning("da850_evm_init: can not open GPIO %d\n",
367 DA850_MMCSD_WP_PIN);
368 gpio_direction_input(DA850_MMCSD_WP_PIN);
370 ret = da8xx_register_mmcsd0(&da850_mmc_config);
371 if (ret)
372 pr_warning("da850_evm_init: mmcsd0 registration failed:"
373 " %d\n", ret);
376 davinci_serial_init(&da850_evm_uart_config);
378 i2c_register_board_info(1, da850_evm_i2c_devices,
379 ARRAY_SIZE(da850_evm_i2c_devices));
382 * shut down uart 0 and 1; they are not used on the board and
383 * accessing them causes endless "too much work in irq53" messages
384 * with arago fs
386 __raw_writel(0, IO_ADDRESS(DA8XX_UART1_BASE) + 0x30);
387 __raw_writel(0, IO_ADDRESS(DA8XX_UART0_BASE) + 0x30);
389 ret = da8xx_pinmux_setup(da850_mcasp_pins);
390 if (ret)
391 pr_warning("da850_evm_init: mcasp mux setup failed: %d\n",
392 ret);
394 da8xx_init_mcasp(0, &da850_evm_snd_data);
396 ret = da8xx_pinmux_setup(da850_lcdcntl_pins);
397 if (ret)
398 pr_warning("da850_evm_init: lcdcntl mux setup failed: %d\n",
399 ret);
401 ret = da850_lcd_hw_init();
402 if (ret)
403 pr_warning("da850_evm_init: lcd initialization failed: %d\n",
404 ret);
406 ret = da8xx_register_lcdc();
407 if (ret)
408 pr_warning("da850_evm_init: lcdc registration failed: %d\n",
409 ret);
411 da850_evm_setup_mac_addr();
414 #ifdef CONFIG_SERIAL_8250_CONSOLE
415 static int __init da850_evm_console_init(void)
417 return add_preferred_console("ttyS", 2, "115200");
419 console_initcall(da850_evm_console_init);
420 #endif
422 static __init void da850_evm_irq_init(void)
424 struct davinci_soc_info *soc_info = &davinci_soc_info;
426 cp_intc_init((void __iomem *)DA8XX_CP_INTC_VIRT, DA850_N_CP_INTC_IRQ,
427 soc_info->intc_irq_prios);
430 static void __init da850_evm_map_io(void)
432 da850_init();
435 MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138 EVM")
436 .phys_io = IO_PHYS,
437 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
438 .boot_params = (DA8XX_DDR_BASE + 0x100),
439 .map_io = da850_evm_map_io,
440 .init_irq = da850_evm_irq_init,
441 .timer = &davinci_timer,
442 .init_machine = da850_evm_init,
443 MACHINE_END