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 .ecc_mode
= NAND_ECC_HW
,
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
,
164 const struct i2c_device_id
*id
)
168 struct i2c_msg msg
[2] = {
170 .addr
= client
->addr
,
176 .addr
= client
->addr
,
183 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
184 i2c_transfer(client
->adapter
, msg
, 1);
185 data
&= ~(DM646X_EVM_ATA_RST
| DM646X_EVM_ATA_PWD
);
186 i2c_transfer(client
->adapter
, msg
+ 1, 1);
192 static const struct i2c_device_id cpld_reg_ids
[] = {
197 static struct i2c_driver dm6467evm_cpld_driver
= {
198 .driver
.name
= "cpld_reg0",
199 .id_table
= cpld_reg_ids
,
200 .probe
= cpld_reg0_probe
,
205 static struct gpio_led evm_leds
[] = {
206 { .name
= "DS1", .active_low
= 1, },
207 { .name
= "DS2", .active_low
= 1, },
208 { .name
= "DS3", .active_low
= 1, },
209 { .name
= "DS4", .active_low
= 1, },
212 static const struct gpio_led_platform_data evm_led_data
= {
213 .num_leds
= ARRAY_SIZE(evm_leds
),
217 static struct platform_device
*evm_led_dev
;
219 static int evm_led_setup(struct i2c_client
*client
, int gpio
,
220 unsigned int ngpio
, void *c
)
222 struct gpio_led
*leds
= evm_leds
;
230 evm_led_dev
= platform_device_alloc("leds-gpio", 0);
231 platform_device_add_data(evm_led_dev
, &evm_led_data
,
232 sizeof(evm_led_data
));
234 evm_led_dev
->dev
.parent
= &client
->dev
;
235 status
= platform_device_add(evm_led_dev
);
237 platform_device_put(evm_led_dev
);
243 static int evm_led_teardown(struct i2c_client
*client
, int gpio
,
244 unsigned ngpio
, void *c
)
247 platform_device_unregister(evm_led_dev
);
253 static int evm_sw_gpio
[4] = { -EINVAL
, -EINVAL
, -EINVAL
, -EINVAL
};
255 static int evm_sw_setup(struct i2c_client
*client
, int gpio
,
256 unsigned ngpio
, void *c
)
262 for (i
= 0; i
< 4; ++i
) {
263 snprintf(label
, 10, "user_sw%d", i
);
264 status
= gpio_request(gpio
, label
);
267 evm_sw_gpio
[i
] = gpio
++;
269 status
= gpio_direction_input(evm_sw_gpio
[i
]);
271 gpio_free(evm_sw_gpio
[i
]);
272 evm_sw_gpio
[i
] = -EINVAL
;
276 status
= gpio_export(evm_sw_gpio
[i
], 0);
278 gpio_free(evm_sw_gpio
[i
]);
279 evm_sw_gpio
[i
] = -EINVAL
;
285 for (i
= 0; i
< 4; ++i
) {
286 if (evm_sw_gpio
[i
] != -EINVAL
) {
287 gpio_free(evm_sw_gpio
[i
]);
288 evm_sw_gpio
[i
] = -EINVAL
;
294 static int evm_sw_teardown(struct i2c_client
*client
, int gpio
,
295 unsigned ngpio
, void *c
)
299 for (i
= 0; i
< 4; ++i
) {
300 if (evm_sw_gpio
[i
] != -EINVAL
) {
301 gpio_unexport(evm_sw_gpio
[i
]);
302 gpio_free(evm_sw_gpio
[i
]);
303 evm_sw_gpio
[i
] = -EINVAL
;
309 static int evm_pcf_setup(struct i2c_client
*client
, int gpio
,
310 unsigned int ngpio
, void *c
)
317 status
= evm_sw_setup(client
, gpio
, 4, c
);
321 return evm_led_setup(client
, gpio
+4, 4, c
);
324 static int evm_pcf_teardown(struct i2c_client
*client
, int gpio
,
325 unsigned int ngpio
, void *c
)
329 evm_sw_teardown(client
, gpio
, 4, c
);
330 evm_led_teardown(client
, gpio
+4, 4, c
);
335 static struct pcf857x_platform_data pcf_data
= {
336 .gpio_base
= DAVINCI_N_GPIO
+1,
337 .setup
= evm_pcf_setup
,
338 .teardown
= evm_pcf_teardown
,
341 /* Most of this EEPROM is unused, but U-Boot uses some data:
342 * - 0x7f00, 6 bytes Ethernet Address
343 * - ... newer boards may have more
346 static struct nvmem_cell_info dm646x_evm_nvmem_cells
[] = {
354 static struct nvmem_cell_table dm646x_evm_nvmem_cell_table
= {
355 .nvmem_name
= "1-00500",
356 .cells
= dm646x_evm_nvmem_cells
,
357 .ncells
= ARRAY_SIZE(dm646x_evm_nvmem_cells
),
360 static struct nvmem_cell_lookup dm646x_evm_nvmem_cell_lookup
= {
361 .nvmem_name
= "1-00500",
362 .cell_name
= "macaddr",
363 .dev_id
= "davinci_emac.1",
364 .con_id
= "mac-address",
367 static const struct property_entry eeprom_properties
[] = {
368 PROPERTY_ENTRY_U32("pagesize", 64),
373 static u8 dm646x_iis_serializer_direction
[] = {
374 TX_MODE
, RX_MODE
, INACTIVE_MODE
, INACTIVE_MODE
,
377 static u8 dm646x_dit_serializer_direction
[] = {
381 static struct snd_platform_data dm646x_evm_snd_data
[] = {
383 .tx_dma_offset
= 0x400,
384 .rx_dma_offset
= 0x400,
385 .op_mode
= DAVINCI_MCASP_IIS_MODE
,
386 .num_serializer
= ARRAY_SIZE(dm646x_iis_serializer_direction
),
388 .serial_dir
= dm646x_iis_serializer_direction
,
389 .asp_chan_q
= EVENTQ_0
,
392 .tx_dma_offset
= 0x400,
394 .op_mode
= DAVINCI_MCASP_DIT_MODE
,
395 .num_serializer
= ARRAY_SIZE(dm646x_dit_serializer_direction
),
397 .serial_dir
= dm646x_dit_serializer_direction
,
398 .asp_chan_q
= EVENTQ_0
,
403 static struct i2c_client
*cpld_client
;
405 static int cpld_video_probe(struct i2c_client
*client
,
406 const struct i2c_device_id
*id
)
408 cpld_client
= client
;
412 static int cpld_video_remove(struct i2c_client
*client
)
418 static const struct i2c_device_id cpld_video_id
[] = {
423 static struct i2c_driver cpld_video_driver
= {
425 .name
= "cpld_video",
427 .probe
= cpld_video_probe
,
428 .remove
= cpld_video_remove
,
429 .id_table
= cpld_video_id
,
432 static void evm_init_cpld(void)
434 i2c_add_driver(&cpld_video_driver
);
437 static struct i2c_board_info __initdata i2c_info
[] = {
439 I2C_BOARD_INFO("24c256", 0x50),
440 .properties
= eeprom_properties
,
443 I2C_BOARD_INFO("pcf8574a", 0x38),
444 .platform_data
= &pcf_data
,
447 I2C_BOARD_INFO("cpld_reg0", 0x3a),
450 I2C_BOARD_INFO("tlv320aic33", 0x18),
453 I2C_BOARD_INFO("cpld_video", 0x3b),
457 static struct davinci_i2c_platform_data i2c_pdata
= {
458 .bus_freq
= 100 /* kHz */,
459 .bus_delay
= 0 /* usec */,
462 #define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
463 #define VCH2CLK_SYSCLK8 (BIT(9))
464 #define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
465 #define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
466 #define VCH3CLK_SYSCLK8 (BIT(13))
467 #define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
469 #define VIDCH2CLK (BIT(10))
470 #define VIDCH3CLK (BIT(11))
471 #define VIDCH1CLK (BIT(4))
472 #define TVP7002_INPUT (BIT(4))
473 #define TVP5147_INPUT (~BIT(4))
474 #define VPIF_INPUT_ONE_CHANNEL (BIT(5))
475 #define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
476 #define TVP5147_CH0 "tvp514x-0"
477 #define TVP5147_CH1 "tvp514x-1"
479 /* spin lock for updating above registers */
480 static spinlock_t vpif_reg_lock
;
482 static int set_vpif_clock(int mux_mode
, int hd
)
492 /* disable the clock */
493 spin_lock_irqsave(&vpif_reg_lock
, flags
);
494 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
495 value
|= (VIDCH3CLK
| VIDCH2CLK
);
496 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
497 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
499 val
= i2c_smbus_read_byte(cpld_client
);
508 err
= i2c_smbus_write_byte(cpld_client
, val
);
512 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
513 value
&= ~(VCH2CLK_MASK
);
514 value
&= ~(VCH3CLK_MASK
);
517 value
|= (VCH2CLK_SYSCLK8
| VCH3CLK_SYSCLK8
);
519 value
|= (VCH2CLK_AUXCLK
| VCH3CLK_AUXCLK
);
521 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
523 spin_lock_irqsave(&vpif_reg_lock
, flags
);
524 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
525 /* enable the clock */
526 value
&= ~(VIDCH3CLK
| VIDCH2CLK
);
527 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
528 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
533 static struct vpif_subdev_info dm646x_vpif_subdev
[] = {
537 I2C_BOARD_INFO("adv7343", 0x2a),
543 I2C_BOARD_INFO("ths7303", 0x2c),
548 static const struct vpif_output dm6467_ch0_outputs
[] = {
553 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
554 .capabilities
= V4L2_OUT_CAP_STD
,
557 .subdev_name
= "adv7343",
558 .output_route
= ADV7343_COMPOSITE_ID
,
564 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
565 .capabilities
= V4L2_OUT_CAP_DV_TIMINGS
,
567 .subdev_name
= "adv7343",
568 .output_route
= ADV7343_COMPONENT_ID
,
574 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
575 .capabilities
= V4L2_OUT_CAP_STD
,
578 .subdev_name
= "adv7343",
579 .output_route
= ADV7343_SVIDEO_ID
,
583 static struct vpif_display_config dm646x_vpif_display_config
= {
584 .set_clock
= set_vpif_clock
,
585 .subdevinfo
= dm646x_vpif_subdev
,
586 .subdev_count
= ARRAY_SIZE(dm646x_vpif_subdev
),
589 .outputs
= dm6467_ch0_outputs
,
590 .output_count
= ARRAY_SIZE(dm6467_ch0_outputs
),
592 .card_name
= "DM646x EVM Video Display",
596 * setup_vpif_input_path()
597 * @channel: channel id (0 - CH0, 1 - CH1)
598 * @sub_dev_name: ptr sub device name
600 * This will set vpif input to capture data from tvp514x or
603 static int setup_vpif_input_path(int channel
, const char *sub_dev_name
)
608 /* for channel 1, we don't do anything */
615 val
= i2c_smbus_read_byte(cpld_client
);
619 if (!strcmp(sub_dev_name
, TVP5147_CH0
) ||
620 !strcmp(sub_dev_name
, TVP5147_CH1
))
621 val
&= TVP5147_INPUT
;
623 val
|= TVP7002_INPUT
;
625 err
= i2c_smbus_write_byte(cpld_client
, val
);
632 * setup_vpif_input_channel_mode()
633 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
635 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
637 static int setup_vpif_input_channel_mode(int mux_mode
)
647 val
= i2c_smbus_read_byte(cpld_client
);
651 spin_lock_irqsave(&vpif_reg_lock
, flags
);
652 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
654 val
&= VPIF_INPUT_TWO_CHANNEL
;
657 val
|= VPIF_INPUT_ONE_CHANNEL
;
660 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
661 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
663 err
= i2c_smbus_write_byte(cpld_client
, val
);
670 static struct tvp514x_platform_data tvp5146_pdata
= {
676 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
678 static struct vpif_subdev_info vpif_capture_sdev_info
[] = {
682 I2C_BOARD_INFO("tvp5146", 0x5d),
683 .platform_data
= &tvp5146_pdata
,
689 I2C_BOARD_INFO("tvp5146", 0x5c),
690 .platform_data
= &tvp5146_pdata
,
695 static struct vpif_input dm6467_ch0_inputs
[] = {
700 .type
= V4L2_INPUT_TYPE_CAMERA
,
701 .capabilities
= V4L2_IN_CAP_STD
,
702 .std
= TVP514X_STD_ALL
,
704 .subdev_name
= TVP5147_CH0
,
705 .input_route
= INPUT_CVBS_VI2B
,
706 .output_route
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
710 static struct vpif_input dm6467_ch1_inputs
[] = {
715 .type
= V4L2_INPUT_TYPE_CAMERA
,
716 .capabilities
= V4L2_IN_CAP_STD
,
717 .std
= TVP514X_STD_ALL
,
719 .subdev_name
= TVP5147_CH1
,
720 .input_route
= INPUT_SVIDEO_VI2C_VI1C
,
721 .output_route
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
725 static struct vpif_capture_config dm646x_vpif_capture_cfg
= {
726 .setup_input_path
= setup_vpif_input_path
,
727 .setup_input_channel_mode
= setup_vpif_input_channel_mode
,
728 .subdev_info
= vpif_capture_sdev_info
,
729 .subdev_count
= ARRAY_SIZE(vpif_capture_sdev_info
),
732 .inputs
= dm6467_ch0_inputs
,
733 .input_count
= ARRAY_SIZE(dm6467_ch0_inputs
),
735 .if_type
= VPIF_IF_BT656
,
742 .inputs
= dm6467_ch1_inputs
,
743 .input_count
= ARRAY_SIZE(dm6467_ch1_inputs
),
745 .if_type
= VPIF_IF_BT656
,
751 .card_name
= "DM646x EVM Video Capture",
754 static void __init
evm_init_video(void)
756 spin_lock_init(&vpif_reg_lock
);
758 dm646x_setup_vpif(&dm646x_vpif_display_config
,
759 &dm646x_vpif_capture_cfg
);
762 static void __init
evm_init_i2c(void)
764 davinci_init_i2c(&i2c_pdata
);
765 i2c_add_driver(&dm6467evm_cpld_driver
);
766 i2c_register_board_info(1, i2c_info
, ARRAY_SIZE(i2c_info
));
772 #define DM646X_REF_FREQ 27000000
773 #define DM646X_AUX_FREQ 24000000
774 #define DM6467T_EVM_REF_FREQ 33000000
776 static void __init
davinci_map_io(void)
781 static void __init
dm646x_evm_init_time(void)
783 dm646x_init_time(DM646X_REF_FREQ
, DM646X_AUX_FREQ
);
786 static void __init
dm6467t_evm_init_time(void)
788 dm646x_init_time(DM6467T_EVM_REF_FREQ
, DM646X_AUX_FREQ
);
791 #define DM646X_EVM_PHY_ID "davinci_mdio-0:01"
793 * The following EDMA channels/slots are not being used by drivers (for
794 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
795 * reserved for codecs on the DSP side.
797 static const s16 dm646x_dma_rsv_chans
[][2] = {
798 /* (offset, number) */
807 static const s16 dm646x_dma_rsv_slots
[][2] = {
808 /* (offset, number) */
818 static struct edma_rsv_info dm646x_edma_rsv
[] = {
820 .rsv_chans
= dm646x_dma_rsv_chans
,
821 .rsv_slots
= dm646x_dma_rsv_slots
,
825 static __init
void evm_init(void)
828 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
830 dm646x_register_clocks();
832 ret
= dm646x_gpio_register();
834 pr_warn("%s: GPIO init failed: %d\n", __func__
, ret
);
837 nvmem_add_cell_table(&dm646x_evm_nvmem_cell_table
);
838 nvmem_add_cell_lookups(&dm646x_evm_nvmem_cell_lookup
, 1);
842 davinci_serial_init(dm646x_serial_device
);
843 dm646x_init_mcasp0(&dm646x_evm_snd_data
[0]);
844 dm646x_init_mcasp1(&dm646x_evm_snd_data
[1]);
846 if (machine_is_davinci_dm6467tevm())
847 davinci_nand_data
.timing
= &dm6467tevm_nandflash_timing
;
849 if (platform_device_register(&davinci_aemif_device
))
850 pr_warn("%s: Cannot register AEMIF device.\n", __func__
);
852 dm646x_init_edma(dm646x_edma_rsv
);
857 soc_info
->emac_pdata
->phy_id
= DM646X_EVM_PHY_ID
;
860 MACHINE_START(DAVINCI_DM6467_EVM
, "DaVinci DM646x EVM")
861 .atag_offset
= 0x100,
862 .map_io
= davinci_map_io
,
863 .init_irq
= dm646x_init_irq
,
864 .init_time
= dm646x_evm_init_time
,
865 .init_machine
= evm_init
,
866 .init_late
= davinci_init_late
,
867 .dma_zone_size
= SZ_128M
,
870 MACHINE_START(DAVINCI_DM6467TEVM
, "DaVinci DM6467T EVM")
871 .atag_offset
= 0x100,
872 .map_io
= davinci_map_io
,
873 .init_irq
= dm646x_init_irq
,
874 .init_time
= dm6467t_evm_init_time
,
875 .init_machine
= evm_init
,
876 .init_late
= davinci_init_late
,
877 .dma_zone_size
= SZ_128M
,