2 * TI DaVinci EVM board support
4 * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
6 * 2007 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/platform_device.h>
16 #include <linux/gpio.h>
17 #include <linux/leds.h>
18 #include <linux/memory.h>
19 #include <linux/etherdevice.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c/pcf857x.h>
23 #include <linux/i2c/at24.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/physmap.h>
30 #include <linux/phy.h>
31 #include <linux/clk.h>
33 #include <asm/setup.h>
34 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38 #include <asm/mach/flash.h>
40 #include <mach/dm644x.h>
41 #include <mach/common.h>
43 #include <mach/serial.h>
46 #include <mach/nand.h>
48 #define DM644X_EVM_PHY_MASK (0x2)
49 #define DM644X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
51 #define DAVINCI_CFC_ATA_BASE 0x01C66000
53 #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x01e00000
54 #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
55 #define DAVINCI_ASYNC_EMIF_DATA_CE1_BASE 0x04000000
56 #define DAVINCI_ASYNC_EMIF_DATA_CE2_BASE 0x06000000
57 #define DAVINCI_ASYNC_EMIF_DATA_CE3_BASE 0x08000000
59 #define LXT971_PHY_ID (0x001378e2)
60 #define LXT971_PHY_MASK (0xfffffff0)
62 static struct mtd_partition davinci_evm_norflash_partitions[] = {
63 /* bootloader (UBL, U-Boot, etc) in first 5 sectors */
68 .mask_flags = MTD_WRITEABLE, /* force read-only */
70 /* bootloader params in the next 1 sectors */
73 .offset = MTDPART_OFS_APPEND,
80 .offset = MTDPART_OFS_APPEND,
87 .offset = MTDPART_OFS_APPEND,
88 .size = MTDPART_SIZ_FULL,
93 static struct physmap_flash_data davinci_evm_norflash_data = {
95 .parts = davinci_evm_norflash_partitions,
96 .nr_parts = ARRAY_SIZE(davinci_evm_norflash_partitions),
99 /* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
100 * limits addresses to 16M, so using addresses past 16M will wrap */
101 static struct resource davinci_evm_norflash_resource = {
102 .start = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
103 .end = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
104 .flags = IORESOURCE_MEM,
107 static struct platform_device davinci_evm_norflash_device = {
108 .name = "physmap-flash",
111 .platform_data = &davinci_evm_norflash_data,
114 .resource = &davinci_evm_norflash_resource,
117 /* DM644x EVM includes a 64 MByte small-page NAND flash (16K blocks).
118 * It may used instead of the (default) NOR chip to boot, using TI's
119 * tools to install the secondary boot loader (UBL) and U-Boot.
121 struct mtd_partition davinci_evm_nandflash_partition[] = {
122 /* Bootloader layout depends on whose u-boot is installed, but we
123 * can hide all the details.
124 * - block 0 for u-boot environment ... in mainline u-boot
125 * - block 1 for UBL (plus up to four backup copies in blocks 2..5)
126 * - blocks 6...? for u-boot
127 * - blocks 16..23 for u-boot environment ... in TI's u-boot
130 .name = "bootloader",
132 .size = SZ_256K + SZ_128K,
133 .mask_flags = MTD_WRITEABLE, /* force read-only */
138 .offset = MTDPART_OFS_APPEND,
142 /* File system (older GIT kernels started this on the 5MB mark) */
144 .name = "filesystem",
145 .offset = MTDPART_OFS_APPEND,
146 .size = MTDPART_SIZ_FULL,
149 /* A few blocks at end hold a flash BBT ... created by TI's CCS
150 * using flashwriter_nand.out, but ignored by TI's versions of
151 * Linux and u-boot. We boot faster by using them.
155 static struct davinci_nand_pdata davinci_evm_nandflash_data = {
156 .parts = davinci_evm_nandflash_partition,
157 .nr_parts = ARRAY_SIZE(davinci_evm_nandflash_partition),
158 .ecc_mode = NAND_ECC_HW,
159 .options = NAND_USE_FLASH_BBT,
162 static struct resource davinci_evm_nandflash_resource[] = {
164 .start = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
165 .end = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
166 .flags = IORESOURCE_MEM,
168 .start = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
169 .end = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
170 .flags = IORESOURCE_MEM,
174 static struct platform_device davinci_evm_nandflash_device = {
175 .name = "davinci_nand",
178 .platform_data = &davinci_evm_nandflash_data,
180 .num_resources = ARRAY_SIZE(davinci_evm_nandflash_resource),
181 .resource = davinci_evm_nandflash_resource,
184 static u64 davinci_fb_dma_mask = DMA_BIT_MASK(32);
186 static struct platform_device davinci_fb_device = {
190 .dma_mask = &davinci_fb_dma_mask,
191 .coherent_dma_mask = DMA_BIT_MASK(32),
196 static struct platform_device rtc_dev = {
197 .name = "rtc_davinci_evm",
201 static struct resource ide_resources[] = {
203 .start = DAVINCI_CFC_ATA_BASE,
204 .end = DAVINCI_CFC_ATA_BASE + 0x7ff,
205 .flags = IORESOURCE_MEM,
210 .flags = IORESOURCE_IRQ,
214 static u64 ide_dma_mask = DMA_BIT_MASK(32);
216 static struct platform_device ide_dev = {
217 .name = "palm_bk3710",
219 .resource = ide_resources,
220 .num_resources = ARRAY_SIZE(ide_resources),
222 .dma_mask = &ide_dma_mask,
223 .coherent_dma_mask = DMA_BIT_MASK(32),
227 /*----------------------------------------------------------------------*/
233 #define PCF_Uxx_BASE(x) (DAVINCI_N_GPIO + ((x) * 8))
238 static struct gpio_led evm_leds[] = {
239 { .name = "DS8", .active_low = 1,
240 .default_trigger = "heartbeat", },
241 { .name = "DS7", .active_low = 1, },
242 { .name = "DS6", .active_low = 1, },
243 { .name = "DS5", .active_low = 1, },
244 { .name = "DS4", .active_low = 1, },
245 { .name = "DS3", .active_low = 1, },
246 { .name = "DS2", .active_low = 1,
247 .default_trigger = "mmc0", },
248 { .name = "DS1", .active_low = 1,
249 .default_trigger = "ide-disk", },
252 static const struct gpio_led_platform_data evm_led_data = {
253 .num_leds = ARRAY_SIZE(evm_leds),
257 static struct platform_device *evm_led_dev;
260 evm_led_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
262 struct gpio_led *leds = evm_leds;
270 /* what an extremely annoying way to be forced to handle
271 * device unregistration ...
273 evm_led_dev = platform_device_alloc("leds-gpio", 0);
274 platform_device_add_data(evm_led_dev,
275 &evm_led_data, sizeof evm_led_data);
277 evm_led_dev->dev.parent = &client->dev;
278 status = platform_device_add(evm_led_dev);
280 platform_device_put(evm_led_dev);
287 evm_led_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
290 platform_device_unregister(evm_led_dev);
296 static struct pcf857x_platform_data pcf_data_u2 = {
297 .gpio_base = PCF_Uxx_BASE(0),
298 .setup = evm_led_setup,
299 .teardown = evm_led_teardown,
303 /* U18 - A/V clock generator and user switch */
308 sw_show(struct device *d, struct device_attribute *a, char *buf)
310 char *s = gpio_get_value_cansleep(sw_gpio) ? "on\n" : "off\n";
316 static DEVICE_ATTR(user_sw, S_IRUGO, sw_show, NULL);
319 evm_u18_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
323 /* export dip switch option */
325 status = gpio_request(sw_gpio, "user_sw");
327 status = gpio_direction_input(sw_gpio);
329 status = device_create_file(&client->dev, &dev_attr_user_sw);
335 /* audio PLL: 48 kHz (vs 44.1 or 32), single rate (vs double) */
336 gpio_request(gpio + 3, "pll_fs2");
337 gpio_direction_output(gpio + 3, 0);
339 gpio_request(gpio + 2, "pll_fs1");
340 gpio_direction_output(gpio + 2, 0);
342 gpio_request(gpio + 1, "pll_sr");
343 gpio_direction_output(gpio + 1, 0);
349 evm_u18_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
356 device_remove_file(&client->dev, &dev_attr_user_sw);
362 static struct pcf857x_platform_data pcf_data_u18 = {
363 .gpio_base = PCF_Uxx_BASE(1),
364 .n_latch = (1 << 3) | (1 << 2) | (1 << 1),
365 .setup = evm_u18_setup,
366 .teardown = evm_u18_teardown,
370 /* U35 - various I/O signals used to manage USB, CF, ATA, etc */
373 evm_u35_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
375 /* p0 = nDRV_VBUS (initial: don't supply it) */
376 gpio_request(gpio + 0, "nDRV_VBUS");
377 gpio_direction_output(gpio + 0, 1);
380 gpio_request(gpio + 1, "VDDIMX_EN");
381 gpio_direction_output(gpio + 1, 1);
384 gpio_request(gpio + 2, "VLYNQ_EN");
385 gpio_direction_output(gpio + 2, 1);
387 /* p3 = n3V3_CF_RESET (initial: stay in reset) */
388 gpio_request(gpio + 3, "nCF_RESET");
389 gpio_direction_output(gpio + 3, 0);
393 /* p5 = 1V8_WLAN_RESET (initial: stay in reset) */
394 gpio_request(gpio + 5, "WLAN_RESET");
395 gpio_direction_output(gpio + 5, 1);
397 /* p6 = nATA_SEL (initial: select) */
398 gpio_request(gpio + 6, "nATA_SEL");
399 gpio_direction_output(gpio + 6, 0);
401 /* p7 = nCF_SEL (initial: deselect) */
402 gpio_request(gpio + 7, "nCF_SEL");
403 gpio_direction_output(gpio + 7, 1);
405 /* irlml6401 switches over 1A, in under 8 msec;
406 * now it can be managed by nDRV_VBUS ...
414 evm_u35_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
426 static struct pcf857x_platform_data pcf_data_u35 = {
427 .gpio_base = PCF_Uxx_BASE(2),
428 .setup = evm_u35_setup,
429 .teardown = evm_u35_teardown,
432 /*----------------------------------------------------------------------*/
434 /* Most of this EEPROM is unused, but U-Boot uses some data:
435 * - 0x7f00, 6 bytes Ethernet Address
436 * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
437 * - ... newer boards may have more
439 static struct memory_accessor *at24_mem_acc;
441 static void at24_setup(struct memory_accessor *mem_acc, void *context)
443 DECLARE_MAC_BUF(mac_str);
446 at24_mem_acc = mem_acc;
448 /* Read MAC addr from EEPROM */
449 if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, 6) == 6) {
450 printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
451 print_mac(mac_str, mac_addr));
455 static struct at24_platform_data eeprom_info = {
456 .byte_len = (256*1024) / 8,
458 .flags = AT24_FLAG_ADDR16,
462 int dm6446evm_eeprom_read(void *buf, off_t off, size_t count)
465 return at24_mem_acc->read(at24_mem_acc, buf, off, count);
468 EXPORT_SYMBOL(dm6446evm_eeprom_read);
470 int dm6446evm_eeprom_write(void *buf, off_t off, size_t count)
473 return at24_mem_acc->write(at24_mem_acc, buf, off, count);
476 EXPORT_SYMBOL(dm6446evm_eeprom_write);
479 * MSP430 supports RTC, card detection, input from IR remote, and
480 * a bit more. It triggers interrupts on GPIO(7) from pressing
481 * buttons on the IR remote, and for card detect switches.
483 static struct i2c_client *dm6446evm_msp;
485 static int dm6446evm_msp_probe(struct i2c_client *client,
486 const struct i2c_device_id *id)
488 dm6446evm_msp = client;
492 static int dm6446evm_msp_remove(struct i2c_client *client)
494 dm6446evm_msp = NULL;
498 static const struct i2c_device_id dm6446evm_msp_ids[] = {
499 { "dm6446evm_msp", 0, },
500 { /* end of list */ },
503 static struct i2c_driver dm6446evm_msp_driver = {
504 .driver.name = "dm6446evm_msp",
505 .id_table = dm6446evm_msp_ids,
506 .probe = dm6446evm_msp_probe,
507 .remove = dm6446evm_msp_remove,
510 static int dm6444evm_msp430_get_pins(void)
512 static const char txbuf[2] = { 2, 4, };
514 struct i2c_msg msg[2] = {
516 .addr = dm6446evm_msp->addr,
519 .buf = (void __force *)txbuf,
522 .addr = dm6446evm_msp->addr,
533 /* Command 4 == get input state, returns port 2 and port3 data
534 * S Addr W [A] len=2 [A] cmd=4 [A]
535 * RS Addr R [A] [len=4] A [cmd=4] A [port2] A [port3] N P
537 status = i2c_transfer(dm6446evm_msp->adapter, msg, 2);
541 dev_dbg(&dm6446evm_msp->dev,
542 "PINS: %02x %02x %02x %02x\n",
543 buf[0], buf[1], buf[2], buf[3]);
545 return (buf[3] << 8) | buf[2];
548 static struct i2c_board_info __initdata i2c_info[] = {
550 I2C_BOARD_INFO("dm6446evm_msp", 0x23),
553 I2C_BOARD_INFO("pcf8574", 0x38),
554 .platform_data = &pcf_data_u2,
557 I2C_BOARD_INFO("pcf8574", 0x39),
558 .platform_data = &pcf_data_u18,
561 I2C_BOARD_INFO("pcf8574", 0x3a),
562 .platform_data = &pcf_data_u35,
565 I2C_BOARD_INFO("24c256", 0x50),
566 .platform_data = &eeprom_info,
569 * - tvl320aic33 audio codec (0x1b)
570 * - tvp5146 video decoder (0x5d)
574 /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz),
575 * which requires 100 usec of idle bus after i2c writes sent to it.
577 static struct davinci_i2c_platform_data i2c_pdata = {
578 .bus_freq = 20 /* kHz */,
579 .bus_delay = 100 /* usec */,
582 static void __init evm_init_i2c(void)
584 davinci_init_i2c(&i2c_pdata);
585 i2c_add_driver(&dm6446evm_msp_driver);
586 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
589 static struct platform_device *davinci_evm_devices[] __initdata = {
594 static struct davinci_uart_config uart_config __initdata = {
595 .enabled_uarts = (1 << 0),
599 davinci_evm_map_io(void)
601 davinci_map_common_io();
605 static int davinci_phy_fixup(struct phy_device *phydev)
607 unsigned int control;
608 /* CRITICAL: Fix for increasing PHY signal drive strength for
609 * TX lockup issue. On DaVinci EVM, the Intel LXT971 PHY
610 * signal strength was low causing TX to fail randomly. The
611 * fix is to Set bit 11 (Increased MII drive strength) of PHY
612 * register 26 (Digital Config register) on this phy. */
613 control = phy_read(phydev, 26);
614 phy_write(phydev, 26, (control | 0x800));
618 #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
619 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
625 #if defined(CONFIG_MTD_PHYSMAP) || \
626 defined(CONFIG_MTD_PHYSMAP_MODULE)
632 #if defined(CONFIG_MTD_NAND_DAVINCI) || \
633 defined(CONFIG_MTD_NAND_DAVINCI_MODULE)
639 static __init void davinci_evm_init(void)
641 struct clk *aemif_clk;
643 aemif_clk = clk_get(NULL, "aemif");
644 clk_enable(aemif_clk);
647 if (HAS_NAND || HAS_NOR)
648 pr_warning("WARNING: both IDE and Flash are "
649 "enabled, but they share AEMIF pins.\n"
650 "\tDisable IDE for NAND/NOR support.\n");
651 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
652 davinci_cfg_reg(DM644X_ATAEN);
653 davinci_cfg_reg(DM644X_HDIREN);
654 platform_device_register(&ide_dev);
655 } else if (HAS_NAND || HAS_NOR) {
656 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
657 davinci_cfg_reg(DM644X_ATAEN_DISABLE);
659 /* only one device will be jumpered and detected */
661 platform_device_register(&davinci_evm_nandflash_device);
662 evm_leds[7].default_trigger = "nand-disk";
664 pr_warning("WARNING: both NAND and NOR flash "
665 "are enabled; disable one of them.\n");
667 platform_device_register(&davinci_evm_norflash_device);
670 platform_add_devices(davinci_evm_devices,
671 ARRAY_SIZE(davinci_evm_devices));
674 davinci_serial_init(&uart_config);
676 /* Register the fixup for PHY on DaVinci */
677 phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK,
682 static __init void davinci_evm_irq_init(void)
687 MACHINE_START(DAVINCI_EVM, "DaVinci DM644x EVM")
688 /* Maintainer: MontaVista Software <source@mvista.com> */
690 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
691 .boot_params = (DAVINCI_DDR_BASE + 0x100),
692 .map_io = davinci_evm_map_io,
693 .init_irq = davinci_evm_irq_init,
694 .timer = &davinci_timer,
695 .init_machine = davinci_evm_init,