2 * TI DaVinci DM646X EVM board
4 * Derived from: arch/arm/mach-davinci/board-evm.c
5 * Copyright (C) 2006 Texas Instruments.
7 * (C) 2007-2008, MontaVista Software, Inc.
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
15 /**************************************************************************
17 **************************************************************************/
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/leds.h>
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/i2c.h>
25 #include <linux/property.h>
26 #include <linux/platform_data/pcf857x.h>
27 #include <linux/platform_data/ti-aemif.h>
29 #include <media/i2c/tvp514x.h>
30 #include <media/i2c/adv7343.h>
32 #include <linux/mtd/mtd.h>
33 #include <linux/mtd/rawnand.h>
34 #include <linux/mtd/partitions.h>
35 #include <linux/nvmem-provider.h>
36 #include <linux/clk.h>
37 #include <linux/export.h>
38 #include <linux/platform_data/gpio-davinci.h>
39 #include <linux/platform_data/i2c-davinci.h>
40 #include <linux/platform_data/mtd-davinci.h>
41 #include <linux/platform_data/mtd-davinci-aemif.h>
43 #include <asm/mach-types.h>
44 #include <asm/mach/arch.h>
46 #include <mach/common.h>
47 #include <mach/serial.h>
52 #define NAND_BLOCK_SIZE SZ_128K
54 /* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
55 * and U-Boot environment this avoids dependency on any particular combination
56 * of UBL, U-Boot or flashing tools etc.
58 static struct mtd_partition davinci_nand_partitions[] = {
60 /* UBL, U-Boot with environment */
62 .offset = MTDPART_OFS_APPEND,
63 .size = 16 * NAND_BLOCK_SIZE,
64 .mask_flags = MTD_WRITEABLE, /* force read-only */
67 .offset = MTDPART_OFS_APPEND,
72 .offset = MTDPART_OFS_APPEND,
73 .size = MTDPART_SIZ_FULL,
78 static struct davinci_aemif_timing dm6467tevm_nandflash_timing = {
88 static struct davinci_nand_pdata davinci_nand_data = {
92 .parts = davinci_nand_partitions,
93 .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
94 .engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST,
99 static struct resource davinci_nand_resources[] = {
101 .start = DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
102 .end = DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
103 .flags = IORESOURCE_MEM,
105 .start = DM646X_ASYNC_EMIF_CONTROL_BASE,
106 .end = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
107 .flags = IORESOURCE_MEM,
111 static struct platform_device davinci_aemif_devices[] = {
113 .name = "davinci_nand",
115 .num_resources = ARRAY_SIZE(davinci_nand_resources),
116 .resource = davinci_nand_resources,
118 .platform_data = &davinci_nand_data,
123 static struct resource davinci_aemif_resources[] = {
125 .start = DM646X_ASYNC_EMIF_CONTROL_BASE,
126 .end = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
127 .flags = IORESOURCE_MEM,
131 static struct aemif_abus_data davinci_aemif_abus_data[] = {
137 static struct aemif_platform_data davinci_aemif_pdata = {
138 .abus_data = davinci_aemif_abus_data,
139 .num_abus_data = ARRAY_SIZE(davinci_aemif_abus_data),
140 .sub_devices = davinci_aemif_devices,
141 .num_sub_devices = ARRAY_SIZE(davinci_aemif_devices),
144 static struct platform_device davinci_aemif_device = {
148 .platform_data = &davinci_aemif_pdata,
150 .resource = davinci_aemif_resources,
151 .num_resources = ARRAY_SIZE(davinci_aemif_resources),
154 #define HAS_ATA (IS_ENABLED(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
155 IS_ENABLED(CONFIG_PATA_BK3710))
158 /* CPLD Register 0 bits to control ATA */
159 #define DM646X_EVM_ATA_RST BIT(0)
160 #define DM646X_EVM_ATA_PWD BIT(1)
162 /* CPLD Register 0 Client: used for I/O Control */
163 static int cpld_reg0_probe(struct i2c_client *client)
167 struct i2c_msg msg[2] = {
169 .addr = client->addr,
175 .addr = client->addr,
182 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
183 i2c_transfer(client->adapter, msg, 1);
184 data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
185 i2c_transfer(client->adapter, msg + 1, 1);
191 static const struct i2c_device_id cpld_reg_ids[] = {
196 static struct i2c_driver dm6467evm_cpld_driver = {
197 .driver.name = "cpld_reg0",
198 .id_table = cpld_reg_ids,
199 .probe_new = cpld_reg0_probe,
204 static struct gpio_led evm_leds[] = {
205 { .name = "DS1", .active_low = 1, },
206 { .name = "DS2", .active_low = 1, },
207 { .name = "DS3", .active_low = 1, },
208 { .name = "DS4", .active_low = 1, },
211 static const struct gpio_led_platform_data evm_led_data = {
212 .num_leds = ARRAY_SIZE(evm_leds),
216 static struct platform_device *evm_led_dev;
218 static int evm_led_setup(struct i2c_client *client, int gpio,
219 unsigned int ngpio, void *c)
221 struct gpio_led *leds = evm_leds;
229 evm_led_dev = platform_device_alloc("leds-gpio", 0);
230 platform_device_add_data(evm_led_dev, &evm_led_data,
231 sizeof(evm_led_data));
233 evm_led_dev->dev.parent = &client->dev;
234 status = platform_device_add(evm_led_dev);
236 platform_device_put(evm_led_dev);
242 static int evm_led_teardown(struct i2c_client *client, int gpio,
243 unsigned ngpio, void *c)
246 platform_device_unregister(evm_led_dev);
252 static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
254 static int evm_sw_setup(struct i2c_client *client, int gpio,
255 unsigned ngpio, void *c)
261 for (i = 0; i < 4; ++i) {
262 snprintf(label, 10, "user_sw%d", i);
263 status = gpio_request(gpio, label);
266 evm_sw_gpio[i] = gpio++;
268 status = gpio_direction_input(evm_sw_gpio[i]);
272 status = gpio_export(evm_sw_gpio[i], 0);
279 for (i = 0; i < 4; ++i) {
280 if (evm_sw_gpio[i] != -EINVAL) {
281 gpio_free(evm_sw_gpio[i]);
282 evm_sw_gpio[i] = -EINVAL;
288 static int evm_sw_teardown(struct i2c_client *client, int gpio,
289 unsigned ngpio, void *c)
293 for (i = 0; i < 4; ++i) {
294 if (evm_sw_gpio[i] != -EINVAL) {
295 gpio_unexport(evm_sw_gpio[i]);
296 gpio_free(evm_sw_gpio[i]);
297 evm_sw_gpio[i] = -EINVAL;
303 static int evm_pcf_setup(struct i2c_client *client, int gpio,
304 unsigned int ngpio, void *c)
311 status = evm_sw_setup(client, gpio, 4, c);
315 return evm_led_setup(client, gpio+4, 4, c);
318 static int evm_pcf_teardown(struct i2c_client *client, int gpio,
319 unsigned int ngpio, void *c)
323 evm_sw_teardown(client, gpio, 4, c);
324 evm_led_teardown(client, gpio+4, 4, c);
329 static struct pcf857x_platform_data pcf_data = {
330 .gpio_base = DAVINCI_N_GPIO+1,
331 .setup = evm_pcf_setup,
332 .teardown = evm_pcf_teardown,
335 /* Most of this EEPROM is unused, but U-Boot uses some data:
336 * - 0x7f00, 6 bytes Ethernet Address
337 * - ... newer boards may have more
340 static struct nvmem_cell_info dm646x_evm_nvmem_cells[] = {
348 static struct nvmem_cell_table dm646x_evm_nvmem_cell_table = {
349 .nvmem_name = "1-00500",
350 .cells = dm646x_evm_nvmem_cells,
351 .ncells = ARRAY_SIZE(dm646x_evm_nvmem_cells),
354 static struct nvmem_cell_lookup dm646x_evm_nvmem_cell_lookup = {
355 .nvmem_name = "1-00500",
356 .cell_name = "macaddr",
357 .dev_id = "davinci_emac.1",
358 .con_id = "mac-address",
361 static const struct property_entry eeprom_properties[] = {
362 PROPERTY_ENTRY_U32("pagesize", 64),
366 static const struct software_node eeprom_node = {
367 .properties = eeprom_properties,
371 static u8 dm646x_iis_serializer_direction[] = {
372 TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
375 static u8 dm646x_dit_serializer_direction[] = {
379 static struct snd_platform_data dm646x_evm_snd_data[] = {
381 .tx_dma_offset = 0x400,
382 .rx_dma_offset = 0x400,
383 .op_mode = DAVINCI_MCASP_IIS_MODE,
384 .num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction),
386 .serial_dir = dm646x_iis_serializer_direction,
387 .asp_chan_q = EVENTQ_0,
390 .tx_dma_offset = 0x400,
392 .op_mode = DAVINCI_MCASP_DIT_MODE,
393 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
395 .serial_dir = dm646x_dit_serializer_direction,
396 .asp_chan_q = EVENTQ_0,
401 static struct i2c_client *cpld_client;
403 static int cpld_video_probe(struct i2c_client *client)
405 cpld_client = client;
409 static int cpld_video_remove(struct i2c_client *client)
415 static const struct i2c_device_id cpld_video_id[] = {
420 static struct i2c_driver cpld_video_driver = {
422 .name = "cpld_video",
424 .probe_new = cpld_video_probe,
425 .remove = cpld_video_remove,
426 .id_table = cpld_video_id,
429 static void evm_init_cpld(void)
431 i2c_add_driver(&cpld_video_driver);
434 static struct i2c_board_info __initdata i2c_info[] = {
436 I2C_BOARD_INFO("24c256", 0x50),
437 .swnode = &eeprom_node,
440 I2C_BOARD_INFO("pcf8574a", 0x38),
441 .platform_data = &pcf_data,
444 I2C_BOARD_INFO("cpld_reg0", 0x3a),
447 I2C_BOARD_INFO("tlv320aic33", 0x18),
450 I2C_BOARD_INFO("cpld_video", 0x3b),
454 static struct davinci_i2c_platform_data i2c_pdata = {
455 .bus_freq = 100 /* kHz */,
456 .bus_delay = 0 /* usec */,
459 #define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
460 #define VCH2CLK_SYSCLK8 (BIT(9))
461 #define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
462 #define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
463 #define VCH3CLK_SYSCLK8 (BIT(13))
464 #define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
466 #define VIDCH2CLK (BIT(10))
467 #define VIDCH3CLK (BIT(11))
468 #define VIDCH1CLK (BIT(4))
469 #define TVP7002_INPUT (BIT(4))
470 #define TVP5147_INPUT (~BIT(4))
471 #define VPIF_INPUT_ONE_CHANNEL (BIT(5))
472 #define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
473 #define TVP5147_CH0 "tvp514x-0"
474 #define TVP5147_CH1 "tvp514x-1"
476 /* spin lock for updating above registers */
477 static spinlock_t vpif_reg_lock;
479 static int set_vpif_clock(int mux_mode, int hd)
489 /* disable the clock */
490 spin_lock_irqsave(&vpif_reg_lock, flags);
491 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
492 value |= (VIDCH3CLK | VIDCH2CLK);
493 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
494 spin_unlock_irqrestore(&vpif_reg_lock, flags);
496 val = i2c_smbus_read_byte(cpld_client);
505 err = i2c_smbus_write_byte(cpld_client, val);
509 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
510 value &= ~(VCH2CLK_MASK);
511 value &= ~(VCH3CLK_MASK);
514 value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
516 value |= (VCH2CLK_AUXCLK | VCH3CLK_AUXCLK);
518 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
520 spin_lock_irqsave(&vpif_reg_lock, flags);
521 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
522 /* enable the clock */
523 value &= ~(VIDCH3CLK | VIDCH2CLK);
524 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
525 spin_unlock_irqrestore(&vpif_reg_lock, flags);
530 static struct vpif_subdev_info dm646x_vpif_subdev[] = {
534 I2C_BOARD_INFO("adv7343", 0x2a),
540 I2C_BOARD_INFO("ths7303", 0x2c),
545 static const struct vpif_output dm6467_ch0_outputs[] = {
550 .type = V4L2_OUTPUT_TYPE_ANALOG,
551 .capabilities = V4L2_OUT_CAP_STD,
554 .subdev_name = "adv7343",
555 .output_route = ADV7343_COMPOSITE_ID,
561 .type = V4L2_OUTPUT_TYPE_ANALOG,
562 .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
564 .subdev_name = "adv7343",
565 .output_route = ADV7343_COMPONENT_ID,
571 .type = V4L2_OUTPUT_TYPE_ANALOG,
572 .capabilities = V4L2_OUT_CAP_STD,
575 .subdev_name = "adv7343",
576 .output_route = ADV7343_SVIDEO_ID,
580 static struct vpif_display_config dm646x_vpif_display_config = {
581 .set_clock = set_vpif_clock,
582 .subdevinfo = dm646x_vpif_subdev,
583 .subdev_count = ARRAY_SIZE(dm646x_vpif_subdev),
586 .outputs = dm6467_ch0_outputs,
587 .output_count = ARRAY_SIZE(dm6467_ch0_outputs),
589 .card_name = "DM646x EVM Video Display",
593 * setup_vpif_input_path()
594 * @channel: channel id (0 - CH0, 1 - CH1)
595 * @sub_dev_name: ptr sub device name
597 * This will set vpif input to capture data from tvp514x or
600 static int setup_vpif_input_path(int channel, const char *sub_dev_name)
605 /* for channel 1, we don't do anything */
612 val = i2c_smbus_read_byte(cpld_client);
616 if (!strcmp(sub_dev_name, TVP5147_CH0) ||
617 !strcmp(sub_dev_name, TVP5147_CH1))
618 val &= TVP5147_INPUT;
620 val |= TVP7002_INPUT;
622 err = i2c_smbus_write_byte(cpld_client, val);
629 * setup_vpif_input_channel_mode()
630 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
632 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
634 static int setup_vpif_input_channel_mode(int mux_mode)
644 val = i2c_smbus_read_byte(cpld_client);
648 spin_lock_irqsave(&vpif_reg_lock, flags);
649 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
651 val &= VPIF_INPUT_TWO_CHANNEL;
654 val |= VPIF_INPUT_ONE_CHANNEL;
657 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
658 spin_unlock_irqrestore(&vpif_reg_lock, flags);
660 err = i2c_smbus_write_byte(cpld_client, val);
667 static struct tvp514x_platform_data tvp5146_pdata = {
673 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
675 static struct vpif_subdev_info vpif_capture_sdev_info[] = {
679 I2C_BOARD_INFO("tvp5146", 0x5d),
680 .platform_data = &tvp5146_pdata,
686 I2C_BOARD_INFO("tvp5146", 0x5c),
687 .platform_data = &tvp5146_pdata,
692 static struct vpif_input dm6467_ch0_inputs[] = {
697 .type = V4L2_INPUT_TYPE_CAMERA,
698 .capabilities = V4L2_IN_CAP_STD,
699 .std = TVP514X_STD_ALL,
701 .subdev_name = TVP5147_CH0,
702 .input_route = INPUT_CVBS_VI2B,
703 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
707 static struct vpif_input dm6467_ch1_inputs[] = {
712 .type = V4L2_INPUT_TYPE_CAMERA,
713 .capabilities = V4L2_IN_CAP_STD,
714 .std = TVP514X_STD_ALL,
716 .subdev_name = TVP5147_CH1,
717 .input_route = INPUT_SVIDEO_VI2C_VI1C,
718 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
722 static struct vpif_capture_config dm646x_vpif_capture_cfg = {
723 .setup_input_path = setup_vpif_input_path,
724 .setup_input_channel_mode = setup_vpif_input_channel_mode,
725 .subdev_info = vpif_capture_sdev_info,
726 .subdev_count = ARRAY_SIZE(vpif_capture_sdev_info),
729 .inputs = dm6467_ch0_inputs,
730 .input_count = ARRAY_SIZE(dm6467_ch0_inputs),
732 .if_type = VPIF_IF_BT656,
739 .inputs = dm6467_ch1_inputs,
740 .input_count = ARRAY_SIZE(dm6467_ch1_inputs),
742 .if_type = VPIF_IF_BT656,
748 .card_name = "DM646x EVM Video Capture",
751 static void __init evm_init_video(void)
753 spin_lock_init(&vpif_reg_lock);
755 dm646x_setup_vpif(&dm646x_vpif_display_config,
756 &dm646x_vpif_capture_cfg);
759 static void __init evm_init_i2c(void)
761 davinci_init_i2c(&i2c_pdata);
762 i2c_add_driver(&dm6467evm_cpld_driver);
763 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
769 #define DM646X_REF_FREQ 27000000
770 #define DM646X_AUX_FREQ 24000000
771 #define DM6467T_EVM_REF_FREQ 33000000
773 static void __init davinci_map_io(void)
778 static void __init dm646x_evm_init_time(void)
780 dm646x_init_time(DM646X_REF_FREQ, DM646X_AUX_FREQ);
783 static void __init dm6467t_evm_init_time(void)
785 dm646x_init_time(DM6467T_EVM_REF_FREQ, DM646X_AUX_FREQ);
788 #define DM646X_EVM_PHY_ID "davinci_mdio-0:01"
790 * The following EDMA channels/slots are not being used by drivers (for
791 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
792 * reserved for codecs on the DSP side.
794 static const s16 dm646x_dma_rsv_chans[][2] = {
795 /* (offset, number) */
804 static const s16 dm646x_dma_rsv_slots[][2] = {
805 /* (offset, number) */
815 static struct edma_rsv_info dm646x_edma_rsv[] = {
817 .rsv_chans = dm646x_dma_rsv_chans,
818 .rsv_slots = dm646x_dma_rsv_slots,
822 static __init void evm_init(void)
825 struct davinci_soc_info *soc_info = &davinci_soc_info;
827 dm646x_register_clocks();
829 ret = dm646x_gpio_register();
831 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
834 nvmem_add_cell_table(&dm646x_evm_nvmem_cell_table);
835 nvmem_add_cell_lookups(&dm646x_evm_nvmem_cell_lookup, 1);
839 davinci_serial_init(dm646x_serial_device);
840 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
841 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
843 if (machine_is_davinci_dm6467tevm())
844 davinci_nand_data.timing = &dm6467tevm_nandflash_timing;
846 if (platform_device_register(&davinci_aemif_device))
847 pr_warn("%s: Cannot register AEMIF device.\n", __func__);
849 dm646x_init_edma(dm646x_edma_rsv);
854 soc_info->emac_pdata->phy_id = DM646X_EVM_PHY_ID;
857 MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
858 .atag_offset = 0x100,
859 .map_io = davinci_map_io,
860 .init_irq = dm646x_init_irq,
861 .init_time = dm646x_evm_init_time,
862 .init_machine = evm_init,
863 .init_late = davinci_init_late,
864 .dma_zone_size = SZ_128M,
867 MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
868 .atag_offset = 0x100,
869 .map_io = davinci_map_io,
870 .init_irq = dm646x_init_irq,
871 .init_time = dm6467t_evm_init_time,
872 .init_machine = evm_init,
873 .init_late = davinci_init_late,
874 .dma_zone_size = SZ_128M,