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/i2c/at24.h>
26 #include <linux/i2c/pcf857x.h>
28 #include <media/tvp514x.h>
29 #include <media/adv7343.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/nand.h>
33 #include <linux/mtd/partitions.h>
34 #include <linux/clk.h>
35 #include <linux/export.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/arch.h>
40 #include <mach/common.h>
41 #include <mach/serial.h>
42 #include <linux/platform_data/i2c-davinci.h>
43 #include <linux/platform_data/mtd-davinci.h>
44 #include <mach/clock.h>
45 #include <mach/cdce949.h>
46 #include <linux/platform_data/mtd-davinci-aemif.h>
51 #define NAND_BLOCK_SIZE SZ_128K
53 /* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
54 * and U-Boot environment this avoids dependency on any particular combination
55 * of UBL, U-Boot or flashing tools etc.
57 static struct mtd_partition davinci_nand_partitions
[] = {
59 /* UBL, U-Boot with environment */
61 .offset
= MTDPART_OFS_APPEND
,
62 .size
= 16 * NAND_BLOCK_SIZE
,
63 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
66 .offset
= MTDPART_OFS_APPEND
,
71 .offset
= MTDPART_OFS_APPEND
,
72 .size
= MTDPART_SIZ_FULL
,
77 static struct davinci_aemif_timing dm6467tevm_nandflash_timing
= {
87 static struct davinci_nand_pdata davinci_nand_data
= {
90 .parts
= davinci_nand_partitions
,
91 .nr_parts
= ARRAY_SIZE(davinci_nand_partitions
),
92 .ecc_mode
= NAND_ECC_HW
,
96 static struct resource davinci_nand_resources
[] = {
98 .start
= DM646X_ASYNC_EMIF_CS2_SPACE_BASE
,
99 .end
= DM646X_ASYNC_EMIF_CS2_SPACE_BASE
+ SZ_32M
- 1,
100 .flags
= IORESOURCE_MEM
,
102 .start
= DM646X_ASYNC_EMIF_CONTROL_BASE
,
103 .end
= DM646X_ASYNC_EMIF_CONTROL_BASE
+ SZ_4K
- 1,
104 .flags
= IORESOURCE_MEM
,
108 static struct platform_device davinci_nand_device
= {
109 .name
= "davinci_nand",
112 .num_resources
= ARRAY_SIZE(davinci_nand_resources
),
113 .resource
= davinci_nand_resources
,
116 .platform_data
= &davinci_nand_data
,
120 #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
121 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
127 /* CPLD Register 0 bits to control ATA */
128 #define DM646X_EVM_ATA_RST BIT(0)
129 #define DM646X_EVM_ATA_PWD BIT(1)
131 /* CPLD Register 0 Client: used for I/O Control */
132 static int cpld_reg0_probe(struct i2c_client
*client
,
133 const struct i2c_device_id
*id
)
137 struct i2c_msg msg
[2] = {
139 .addr
= client
->addr
,
145 .addr
= client
->addr
,
152 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
153 i2c_transfer(client
->adapter
, msg
, 1);
154 data
&= ~(DM646X_EVM_ATA_RST
| DM646X_EVM_ATA_PWD
);
155 i2c_transfer(client
->adapter
, msg
+ 1, 1);
161 static const struct i2c_device_id cpld_reg_ids
[] = {
166 static struct i2c_driver dm6467evm_cpld_driver
= {
167 .driver
.name
= "cpld_reg0",
168 .id_table
= cpld_reg_ids
,
169 .probe
= cpld_reg0_probe
,
174 static struct gpio_led evm_leds
[] = {
175 { .name
= "DS1", .active_low
= 1, },
176 { .name
= "DS2", .active_low
= 1, },
177 { .name
= "DS3", .active_low
= 1, },
178 { .name
= "DS4", .active_low
= 1, },
181 static const struct gpio_led_platform_data evm_led_data
= {
182 .num_leds
= ARRAY_SIZE(evm_leds
),
186 static struct platform_device
*evm_led_dev
;
188 static int evm_led_setup(struct i2c_client
*client
, int gpio
,
189 unsigned int ngpio
, void *c
)
191 struct gpio_led
*leds
= evm_leds
;
199 evm_led_dev
= platform_device_alloc("leds-gpio", 0);
200 platform_device_add_data(evm_led_dev
, &evm_led_data
,
201 sizeof(evm_led_data
));
203 evm_led_dev
->dev
.parent
= &client
->dev
;
204 status
= platform_device_add(evm_led_dev
);
206 platform_device_put(evm_led_dev
);
212 static int evm_led_teardown(struct i2c_client
*client
, int gpio
,
213 unsigned ngpio
, void *c
)
216 platform_device_unregister(evm_led_dev
);
222 static int evm_sw_gpio
[4] = { -EINVAL
, -EINVAL
, -EINVAL
, -EINVAL
};
224 static int evm_sw_setup(struct i2c_client
*client
, int gpio
,
225 unsigned ngpio
, void *c
)
231 for (i
= 0; i
< 4; ++i
) {
232 snprintf(label
, 10, "user_sw%d", i
);
233 status
= gpio_request(gpio
, label
);
236 evm_sw_gpio
[i
] = gpio
++;
238 status
= gpio_direction_input(evm_sw_gpio
[i
]);
240 gpio_free(evm_sw_gpio
[i
]);
241 evm_sw_gpio
[i
] = -EINVAL
;
245 status
= gpio_export(evm_sw_gpio
[i
], 0);
247 gpio_free(evm_sw_gpio
[i
]);
248 evm_sw_gpio
[i
] = -EINVAL
;
254 for (i
= 0; i
< 4; ++i
) {
255 if (evm_sw_gpio
[i
] != -EINVAL
) {
256 gpio_free(evm_sw_gpio
[i
]);
257 evm_sw_gpio
[i
] = -EINVAL
;
263 static int evm_sw_teardown(struct i2c_client
*client
, int gpio
,
264 unsigned ngpio
, void *c
)
268 for (i
= 0; i
< 4; ++i
) {
269 if (evm_sw_gpio
[i
] != -EINVAL
) {
270 gpio_unexport(evm_sw_gpio
[i
]);
271 gpio_free(evm_sw_gpio
[i
]);
272 evm_sw_gpio
[i
] = -EINVAL
;
278 static int evm_pcf_setup(struct i2c_client
*client
, int gpio
,
279 unsigned int ngpio
, void *c
)
286 status
= evm_sw_setup(client
, gpio
, 4, c
);
290 return evm_led_setup(client
, gpio
+4, 4, c
);
293 static int evm_pcf_teardown(struct i2c_client
*client
, int gpio
,
294 unsigned int ngpio
, void *c
)
298 evm_sw_teardown(client
, gpio
, 4, c
);
299 evm_led_teardown(client
, gpio
+4, 4, c
);
304 static struct pcf857x_platform_data pcf_data
= {
305 .gpio_base
= DAVINCI_N_GPIO
+1,
306 .setup
= evm_pcf_setup
,
307 .teardown
= evm_pcf_teardown
,
310 /* Most of this EEPROM is unused, but U-Boot uses some data:
311 * - 0x7f00, 6 bytes Ethernet Address
312 * - ... newer boards may have more
315 static struct at24_platform_data eeprom_info
= {
316 .byte_len
= (256*1024) / 8,
318 .flags
= AT24_FLAG_ADDR16
,
319 .setup
= davinci_get_mac_addr
,
320 .context
= (void *)0x7f00,
323 static u8 dm646x_iis_serializer_direction
[] = {
324 TX_MODE
, RX_MODE
, INACTIVE_MODE
, INACTIVE_MODE
,
327 static u8 dm646x_dit_serializer_direction
[] = {
331 static struct snd_platform_data dm646x_evm_snd_data
[] = {
333 .tx_dma_offset
= 0x400,
334 .rx_dma_offset
= 0x400,
335 .op_mode
= DAVINCI_MCASP_IIS_MODE
,
336 .num_serializer
= ARRAY_SIZE(dm646x_iis_serializer_direction
),
338 .serial_dir
= dm646x_iis_serializer_direction
,
339 .asp_chan_q
= EVENTQ_0
,
342 .tx_dma_offset
= 0x400,
344 .op_mode
= DAVINCI_MCASP_DIT_MODE
,
345 .num_serializer
= ARRAY_SIZE(dm646x_dit_serializer_direction
),
347 .serial_dir
= dm646x_dit_serializer_direction
,
348 .asp_chan_q
= EVENTQ_0
,
352 static struct i2c_client
*cpld_client
;
354 static int cpld_video_probe(struct i2c_client
*client
,
355 const struct i2c_device_id
*id
)
357 cpld_client
= client
;
361 static int cpld_video_remove(struct i2c_client
*client
)
367 static const struct i2c_device_id cpld_video_id
[] = {
372 static struct i2c_driver cpld_video_driver
= {
374 .name
= "cpld_video",
376 .probe
= cpld_video_probe
,
377 .remove
= cpld_video_remove
,
378 .id_table
= cpld_video_id
,
381 static void evm_init_cpld(void)
383 i2c_add_driver(&cpld_video_driver
);
386 static struct i2c_board_info __initdata i2c_info
[] = {
388 I2C_BOARD_INFO("24c256", 0x50),
389 .platform_data
= &eeprom_info
,
392 I2C_BOARD_INFO("pcf8574a", 0x38),
393 .platform_data
= &pcf_data
,
396 I2C_BOARD_INFO("cpld_reg0", 0x3a),
399 I2C_BOARD_INFO("tlv320aic33", 0x18),
402 I2C_BOARD_INFO("cpld_video", 0x3b),
405 I2C_BOARD_INFO("cdce949", 0x6c),
409 static struct davinci_i2c_platform_data i2c_pdata
= {
410 .bus_freq
= 100 /* kHz */,
411 .bus_delay
= 0 /* usec */,
414 #define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
415 #define VCH2CLK_SYSCLK8 (BIT(9))
416 #define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
417 #define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
418 #define VCH3CLK_SYSCLK8 (BIT(13))
419 #define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
421 #define VIDCH2CLK (BIT(10))
422 #define VIDCH3CLK (BIT(11))
423 #define VIDCH1CLK (BIT(4))
424 #define TVP7002_INPUT (BIT(4))
425 #define TVP5147_INPUT (~BIT(4))
426 #define VPIF_INPUT_ONE_CHANNEL (BIT(5))
427 #define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
428 #define TVP5147_CH0 "tvp514x-0"
429 #define TVP5147_CH1 "tvp514x-1"
431 /* spin lock for updating above registers */
432 static spinlock_t vpif_reg_lock
;
434 static int set_vpif_clock(int mux_mode
, int hd
)
444 /* disable the clock */
445 spin_lock_irqsave(&vpif_reg_lock
, flags
);
446 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
447 value
|= (VIDCH3CLK
| VIDCH2CLK
);
448 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
449 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
451 val
= i2c_smbus_read_byte(cpld_client
);
460 err
= i2c_smbus_write_byte(cpld_client
, val
);
464 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
465 value
&= ~(VCH2CLK_MASK
);
466 value
&= ~(VCH3CLK_MASK
);
469 value
|= (VCH2CLK_SYSCLK8
| VCH3CLK_SYSCLK8
);
471 value
|= (VCH2CLK_AUXCLK
| VCH3CLK_AUXCLK
);
473 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
475 spin_lock_irqsave(&vpif_reg_lock
, flags
);
476 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
477 /* enable the clock */
478 value
&= ~(VIDCH3CLK
| VIDCH2CLK
);
479 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS
));
480 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
485 static struct vpif_subdev_info dm646x_vpif_subdev
[] = {
489 I2C_BOARD_INFO("adv7343", 0x2a),
495 I2C_BOARD_INFO("ths7303", 0x2c),
500 static const struct vpif_output dm6467_ch0_outputs
[] = {
505 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
506 .capabilities
= V4L2_OUT_CAP_STD
,
509 .subdev_name
= "adv7343",
510 .output_route
= ADV7343_COMPOSITE_ID
,
516 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
517 .capabilities
= V4L2_OUT_CAP_CUSTOM_TIMINGS
,
519 .subdev_name
= "adv7343",
520 .output_route
= ADV7343_COMPONENT_ID
,
526 .type
= V4L2_OUTPUT_TYPE_ANALOG
,
527 .capabilities
= V4L2_OUT_CAP_STD
,
530 .subdev_name
= "adv7343",
531 .output_route
= ADV7343_SVIDEO_ID
,
535 static struct vpif_display_config dm646x_vpif_display_config
= {
536 .set_clock
= set_vpif_clock
,
537 .subdevinfo
= dm646x_vpif_subdev
,
538 .subdev_count
= ARRAY_SIZE(dm646x_vpif_subdev
),
540 .outputs
= dm6467_ch0_outputs
,
541 .output_count
= ARRAY_SIZE(dm6467_ch0_outputs
),
543 .card_name
= "DM646x EVM",
547 * setup_vpif_input_path()
548 * @channel: channel id (0 - CH0, 1 - CH1)
549 * @sub_dev_name: ptr sub device name
551 * This will set vpif input to capture data from tvp514x or
554 static int setup_vpif_input_path(int channel
, const char *sub_dev_name
)
559 /* for channel 1, we don't do anything */
566 val
= i2c_smbus_read_byte(cpld_client
);
570 if (!strcmp(sub_dev_name
, TVP5147_CH0
) ||
571 !strcmp(sub_dev_name
, TVP5147_CH1
))
572 val
&= TVP5147_INPUT
;
574 val
|= TVP7002_INPUT
;
576 err
= i2c_smbus_write_byte(cpld_client
, val
);
583 * setup_vpif_input_channel_mode()
584 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
586 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
588 static int setup_vpif_input_channel_mode(int mux_mode
)
598 val
= i2c_smbus_read_byte(cpld_client
);
602 spin_lock_irqsave(&vpif_reg_lock
, flags
);
603 value
= __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
605 val
&= VPIF_INPUT_TWO_CHANNEL
;
608 val
|= VPIF_INPUT_ONE_CHANNEL
;
611 __raw_writel(value
, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL
));
612 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
614 err
= i2c_smbus_write_byte(cpld_client
, val
);
621 static struct tvp514x_platform_data tvp5146_pdata
= {
627 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
629 static struct vpif_subdev_info vpif_capture_sdev_info
[] = {
633 I2C_BOARD_INFO("tvp5146", 0x5d),
634 .platform_data
= &tvp5146_pdata
,
640 I2C_BOARD_INFO("tvp5146", 0x5c),
641 .platform_data
= &tvp5146_pdata
,
646 static const struct vpif_input dm6467_ch0_inputs
[] = {
651 .type
= V4L2_INPUT_TYPE_CAMERA
,
652 .capabilities
= V4L2_IN_CAP_STD
,
653 .std
= TVP514X_STD_ALL
,
655 .subdev_name
= TVP5147_CH0
,
656 .input_route
= INPUT_CVBS_VI2B
,
657 .output_route
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
661 static const struct vpif_input dm6467_ch1_inputs
[] = {
666 .type
= V4L2_INPUT_TYPE_CAMERA
,
667 .capabilities
= V4L2_IN_CAP_STD
,
668 .std
= TVP514X_STD_ALL
,
670 .subdev_name
= TVP5147_CH1
,
671 .input_route
= INPUT_SVIDEO_VI2C_VI1C
,
672 .output_route
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
676 static struct vpif_capture_config dm646x_vpif_capture_cfg
= {
677 .setup_input_path
= setup_vpif_input_path
,
678 .setup_input_channel_mode
= setup_vpif_input_channel_mode
,
679 .subdev_info
= vpif_capture_sdev_info
,
680 .subdev_count
= ARRAY_SIZE(vpif_capture_sdev_info
),
682 .inputs
= dm6467_ch0_inputs
,
683 .input_count
= ARRAY_SIZE(dm6467_ch0_inputs
),
685 .if_type
= VPIF_IF_BT656
,
692 .inputs
= dm6467_ch1_inputs
,
693 .input_count
= ARRAY_SIZE(dm6467_ch1_inputs
),
695 .if_type
= VPIF_IF_BT656
,
703 static void __init
evm_init_video(void)
705 spin_lock_init(&vpif_reg_lock
);
707 dm646x_setup_vpif(&dm646x_vpif_display_config
,
708 &dm646x_vpif_capture_cfg
);
711 static void __init
evm_init_i2c(void)
713 davinci_init_i2c(&i2c_pdata
);
714 i2c_add_driver(&dm6467evm_cpld_driver
);
715 i2c_register_board_info(1, i2c_info
, ARRAY_SIZE(i2c_info
));
720 #define CDCE949_XIN_RATE 27000000
722 /* CDCE949 support - "lpsc" field is overridden to work as clock number */
723 static struct clk cdce_clk_in
= {
725 .rate
= CDCE949_XIN_RATE
,
728 static struct clk_lookup cdce_clks
[] = {
729 CLK(NULL
, "xin", &cdce_clk_in
),
730 CLK(NULL
, NULL
, NULL
),
733 static void __init
cdce_clk_init(void)
735 struct clk_lookup
*c
;
738 for (c
= cdce_clks
; c
->clk
; c
++) {
745 #define DM6467T_EVM_REF_FREQ 33000000
747 static void __init
davinci_map_io(void)
751 if (machine_is_davinci_dm6467tevm())
752 davinci_set_refclk_rate(DM6467T_EVM_REF_FREQ
);
757 static struct davinci_uart_config uart_config __initdata
= {
758 .enabled_uarts
= (1 << 0),
761 #define DM646X_EVM_PHY_ID "davinci_mdio-0:01"
763 * The following EDMA channels/slots are not being used by drivers (for
764 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
765 * reserved for codecs on the DSP side.
767 static const s16 dm646x_dma_rsv_chans
[][2] = {
768 /* (offset, number) */
777 static const s16 dm646x_dma_rsv_slots
[][2] = {
778 /* (offset, number) */
788 static struct edma_rsv_info dm646x_edma_rsv
[] = {
790 .rsv_chans
= dm646x_dma_rsv_chans
,
791 .rsv_slots
= dm646x_dma_rsv_slots
,
795 static __init
void evm_init(void)
797 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
800 davinci_serial_init(&uart_config
);
801 dm646x_init_mcasp0(&dm646x_evm_snd_data
[0]);
802 dm646x_init_mcasp1(&dm646x_evm_snd_data
[1]);
804 if (machine_is_davinci_dm6467tevm())
805 davinci_nand_data
.timing
= &dm6467tevm_nandflash_timing
;
807 platform_device_register(&davinci_nand_device
);
809 dm646x_init_edma(dm646x_edma_rsv
);
814 soc_info
->emac_pdata
->phy_id
= DM646X_EVM_PHY_ID
;
817 MACHINE_START(DAVINCI_DM6467_EVM
, "DaVinci DM646x EVM")
818 .atag_offset
= 0x100,
819 .map_io
= davinci_map_io
,
820 .init_irq
= davinci_irq_init
,
821 .init_time
= davinci_timer_init
,
822 .init_machine
= evm_init
,
823 .init_late
= davinci_init_late
,
824 .dma_zone_size
= SZ_128M
,
825 .restart
= davinci_restart
,
828 MACHINE_START(DAVINCI_DM6467TEVM
, "DaVinci DM6467T EVM")
829 .atag_offset
= 0x100,
830 .map_io
= davinci_map_io
,
831 .init_irq
= davinci_irq_init
,
832 .init_time
= davinci_timer_init
,
833 .init_machine
= evm_init
,
834 .init_late
= davinci_init_late
,
835 .dma_zone_size
= SZ_128M
,
836 .restart
= davinci_restart
,