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>
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/nand.h>
32 #include <linux/mtd/partitions.h>
33 #include <linux/clk.h>
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
38 #include <mach/dm646x.h>
39 #include <mach/common.h>
40 #include <mach/serial.h>
42 #include <mach/nand.h>
46 #define NAND_BLOCK_SIZE SZ_128K
48 /* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
49 * and U-Boot environment this avoids dependency on any particular combination
50 * of UBL, U-Boot or flashing tools etc.
52 static struct mtd_partition davinci_nand_partitions
[] = {
54 /* UBL, U-Boot with environment */
56 .offset
= MTDPART_OFS_APPEND
,
57 .size
= 16 * NAND_BLOCK_SIZE
,
58 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
61 .offset
= MTDPART_OFS_APPEND
,
66 .offset
= MTDPART_OFS_APPEND
,
67 .size
= MTDPART_SIZ_FULL
,
72 static struct davinci_nand_pdata davinci_nand_data
= {
75 .parts
= davinci_nand_partitions
,
76 .nr_parts
= ARRAY_SIZE(davinci_nand_partitions
),
77 .ecc_mode
= NAND_ECC_HW
,
81 #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x20008000
82 #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x42000000
84 static struct resource davinci_nand_resources
[] = {
86 .start
= DAVINCI_ASYNC_EMIF_DATA_CE0_BASE
,
87 .end
= DAVINCI_ASYNC_EMIF_DATA_CE0_BASE
+ SZ_32M
- 1,
88 .flags
= IORESOURCE_MEM
,
90 .start
= DAVINCI_ASYNC_EMIF_CONTROL_BASE
,
91 .end
= DAVINCI_ASYNC_EMIF_CONTROL_BASE
+ SZ_4K
- 1,
92 .flags
= IORESOURCE_MEM
,
96 static struct platform_device davinci_nand_device
= {
97 .name
= "davinci_nand",
100 .num_resources
= ARRAY_SIZE(davinci_nand_resources
),
101 .resource
= davinci_nand_resources
,
104 .platform_data
= &davinci_nand_data
,
108 #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
109 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
115 /* CPLD Register 0 bits to control ATA */
116 #define DM646X_EVM_ATA_RST BIT(0)
117 #define DM646X_EVM_ATA_PWD BIT(1)
119 /* CPLD Register 0 Client: used for I/O Control */
120 static int cpld_reg0_probe(struct i2c_client
*client
,
121 const struct i2c_device_id
*id
)
125 struct i2c_msg msg
[2] = {
127 .addr
= client
->addr
,
133 .addr
= client
->addr
,
140 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
141 i2c_transfer(client
->adapter
, msg
, 1);
142 data
&= ~(DM646X_EVM_ATA_RST
| DM646X_EVM_ATA_PWD
);
143 i2c_transfer(client
->adapter
, msg
+ 1, 1);
149 static const struct i2c_device_id cpld_reg_ids
[] = {
154 static struct i2c_driver dm6467evm_cpld_driver
= {
155 .driver
.name
= "cpld_reg0",
156 .id_table
= cpld_reg_ids
,
157 .probe
= cpld_reg0_probe
,
162 static struct gpio_led evm_leds
[] = {
163 { .name
= "DS1", .active_low
= 1, },
164 { .name
= "DS2", .active_low
= 1, },
165 { .name
= "DS3", .active_low
= 1, },
166 { .name
= "DS4", .active_low
= 1, },
169 static const struct gpio_led_platform_data evm_led_data
= {
170 .num_leds
= ARRAY_SIZE(evm_leds
),
174 static struct platform_device
*evm_led_dev
;
176 static int evm_led_setup(struct i2c_client
*client
, int gpio
,
177 unsigned int ngpio
, void *c
)
179 struct gpio_led
*leds
= evm_leds
;
187 evm_led_dev
= platform_device_alloc("leds-gpio", 0);
188 platform_device_add_data(evm_led_dev
, &evm_led_data
,
189 sizeof(evm_led_data
));
191 evm_led_dev
->dev
.parent
= &client
->dev
;
192 status
= platform_device_add(evm_led_dev
);
194 platform_device_put(evm_led_dev
);
200 static int evm_led_teardown(struct i2c_client
*client
, int gpio
,
201 unsigned ngpio
, void *c
)
204 platform_device_unregister(evm_led_dev
);
210 static int evm_sw_gpio
[4] = { -EINVAL
, -EINVAL
, -EINVAL
, -EINVAL
};
212 static int evm_sw_setup(struct i2c_client
*client
, int gpio
,
213 unsigned ngpio
, void *c
)
219 for (i
= 0; i
< 4; ++i
) {
220 snprintf(label
, 10, "user_sw%d", i
);
221 status
= gpio_request(gpio
, label
);
224 evm_sw_gpio
[i
] = gpio
++;
226 status
= gpio_direction_input(evm_sw_gpio
[i
]);
228 gpio_free(evm_sw_gpio
[i
]);
229 evm_sw_gpio
[i
] = -EINVAL
;
233 status
= gpio_export(evm_sw_gpio
[i
], 0);
235 gpio_free(evm_sw_gpio
[i
]);
236 evm_sw_gpio
[i
] = -EINVAL
;
242 for (i
= 0; i
< 4; ++i
) {
243 if (evm_sw_gpio
[i
] != -EINVAL
) {
244 gpio_free(evm_sw_gpio
[i
]);
245 evm_sw_gpio
[i
] = -EINVAL
;
251 static int evm_sw_teardown(struct i2c_client
*client
, int gpio
,
252 unsigned ngpio
, void *c
)
256 for (i
= 0; i
< 4; ++i
) {
257 if (evm_sw_gpio
[i
] != -EINVAL
) {
258 gpio_unexport(evm_sw_gpio
[i
]);
259 gpio_free(evm_sw_gpio
[i
]);
260 evm_sw_gpio
[i
] = -EINVAL
;
266 static int evm_pcf_setup(struct i2c_client
*client
, int gpio
,
267 unsigned int ngpio
, void *c
)
274 status
= evm_sw_setup(client
, gpio
, 4, c
);
278 return evm_led_setup(client
, gpio
+4, 4, c
);
281 static int evm_pcf_teardown(struct i2c_client
*client
, int gpio
,
282 unsigned int ngpio
, void *c
)
286 evm_sw_teardown(client
, gpio
, 4, c
);
287 evm_led_teardown(client
, gpio
+4, 4, c
);
292 static struct pcf857x_platform_data pcf_data
= {
293 .gpio_base
= DAVINCI_N_GPIO
+1,
294 .setup
= evm_pcf_setup
,
295 .teardown
= evm_pcf_teardown
,
298 /* Most of this EEPROM is unused, but U-Boot uses some data:
299 * - 0x7f00, 6 bytes Ethernet Address
300 * - ... newer boards may have more
303 static struct at24_platform_data eeprom_info
= {
304 .byte_len
= (256*1024) / 8,
306 .flags
= AT24_FLAG_ADDR16
,
307 .setup
= davinci_get_mac_addr
,
308 .context
= (void *)0x7f00,
311 static u8 dm646x_iis_serializer_direction
[] = {
312 TX_MODE
, RX_MODE
, INACTIVE_MODE
, INACTIVE_MODE
,
315 static u8 dm646x_dit_serializer_direction
[] = {
319 static struct snd_platform_data dm646x_evm_snd_data
[] = {
321 .tx_dma_offset
= 0x400,
322 .rx_dma_offset
= 0x400,
323 .op_mode
= DAVINCI_MCASP_IIS_MODE
,
324 .num_serializer
= ARRAY_SIZE(dm646x_iis_serializer_direction
),
326 .serial_dir
= dm646x_iis_serializer_direction
,
327 .eventq_no
= EVENTQ_0
,
330 .tx_dma_offset
= 0x400,
332 .op_mode
= DAVINCI_MCASP_DIT_MODE
,
333 .num_serializer
= ARRAY_SIZE(dm646x_dit_serializer_direction
),
335 .serial_dir
= dm646x_dit_serializer_direction
,
336 .eventq_no
= EVENTQ_0
,
340 static struct i2c_client
*cpld_client
;
342 static int cpld_video_probe(struct i2c_client
*client
,
343 const struct i2c_device_id
*id
)
345 cpld_client
= client
;
349 static int __devexit
cpld_video_remove(struct i2c_client
*client
)
355 static const struct i2c_device_id cpld_video_id
[] = {
360 static struct i2c_driver cpld_video_driver
= {
362 .name
= "cpld_video",
364 .probe
= cpld_video_probe
,
365 .remove
= cpld_video_remove
,
366 .id_table
= cpld_video_id
,
369 static void evm_init_cpld(void)
371 i2c_add_driver(&cpld_video_driver
);
374 static struct i2c_board_info __initdata i2c_info
[] = {
376 I2C_BOARD_INFO("24c256", 0x50),
377 .platform_data
= &eeprom_info
,
380 I2C_BOARD_INFO("pcf8574a", 0x38),
381 .platform_data
= &pcf_data
,
384 I2C_BOARD_INFO("cpld_reg0", 0x3a),
387 I2C_BOARD_INFO("tlv320aic33", 0x18),
390 I2C_BOARD_INFO("cpld_video", 0x3b),
394 static struct davinci_i2c_platform_data i2c_pdata
= {
395 .bus_freq
= 100 /* kHz */,
396 .bus_delay
= 0 /* usec */,
399 #define VIDCLKCTL_OFFSET (DAVINCI_SYSTEM_MODULE_BASE + 0x38)
400 #define VSCLKDIS_OFFSET (DAVINCI_SYSTEM_MODULE_BASE + 0x6c)
401 #define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
402 #define VCH2CLK_SYSCLK8 (BIT(9))
403 #define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
404 #define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
405 #define VCH3CLK_SYSCLK8 (BIT(13))
406 #define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
408 #define VIDCH2CLK (BIT(10))
409 #define VIDCH3CLK (BIT(11))
410 #define VIDCH1CLK (BIT(4))
411 #define TVP7002_INPUT (BIT(4))
412 #define TVP5147_INPUT (~BIT(4))
413 #define VPIF_INPUT_ONE_CHANNEL (BIT(5))
414 #define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
415 #define TVP5147_CH0 "tvp514x-0"
416 #define TVP5147_CH1 "tvp514x-1"
418 static void __iomem
*vpif_vidclkctl_reg
;
419 static void __iomem
*vpif_vsclkdis_reg
;
420 /* spin lock for updating above registers */
421 static spinlock_t vpif_reg_lock
;
423 static int set_vpif_clock(int mux_mode
, int hd
)
430 if (!vpif_vidclkctl_reg
|| !vpif_vsclkdis_reg
|| !cpld_client
)
433 /* disable the clock */
434 spin_lock_irqsave(&vpif_reg_lock
, flags
);
435 value
= __raw_readl(vpif_vsclkdis_reg
);
436 value
|= (VIDCH3CLK
| VIDCH2CLK
);
437 __raw_writel(value
, vpif_vsclkdis_reg
);
438 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
440 val
= i2c_smbus_read_byte(cpld_client
);
449 err
= i2c_smbus_write_byte(cpld_client
, val
);
453 value
= __raw_readl(vpif_vidclkctl_reg
);
454 value
&= ~(VCH2CLK_MASK
);
455 value
&= ~(VCH3CLK_MASK
);
458 value
|= (VCH2CLK_SYSCLK8
| VCH3CLK_SYSCLK8
);
460 value
|= (VCH2CLK_AUXCLK
| VCH3CLK_AUXCLK
);
462 __raw_writel(value
, vpif_vidclkctl_reg
);
464 spin_lock_irqsave(&vpif_reg_lock
, flags
);
465 value
= __raw_readl(vpif_vsclkdis_reg
);
466 /* enable the clock */
467 value
&= ~(VIDCH3CLK
| VIDCH2CLK
);
468 __raw_writel(value
, vpif_vsclkdis_reg
);
469 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
474 static struct vpif_subdev_info dm646x_vpif_subdev
[] = {
478 I2C_BOARD_INFO("adv7343", 0x2a),
484 I2C_BOARD_INFO("ths7303", 0x2c),
489 static const char *output
[] = {
495 static struct vpif_display_config dm646x_vpif_display_config
= {
496 .set_clock
= set_vpif_clock
,
497 .subdevinfo
= dm646x_vpif_subdev
,
498 .subdev_count
= ARRAY_SIZE(dm646x_vpif_subdev
),
500 .output_count
= ARRAY_SIZE(output
),
501 .card_name
= "DM646x EVM",
505 * setup_vpif_input_path()
506 * @channel: channel id (0 - CH0, 1 - CH1)
507 * @sub_dev_name: ptr sub device name
509 * This will set vpif input to capture data from tvp514x or
512 static int setup_vpif_input_path(int channel
, const char *sub_dev_name
)
517 /* for channel 1, we don't do anything */
524 val
= i2c_smbus_read_byte(cpld_client
);
528 if (!strcmp(sub_dev_name
, TVP5147_CH0
) ||
529 !strcmp(sub_dev_name
, TVP5147_CH1
))
530 val
&= TVP5147_INPUT
;
532 val
|= TVP7002_INPUT
;
534 err
= i2c_smbus_write_byte(cpld_client
, val
);
541 * setup_vpif_input_channel_mode()
542 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
544 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
546 static int setup_vpif_input_channel_mode(int mux_mode
)
553 if (!vpif_vsclkdis_reg
|| !cpld_client
)
556 val
= i2c_smbus_read_byte(cpld_client
);
560 spin_lock_irqsave(&vpif_reg_lock
, flags
);
561 value
= __raw_readl(vpif_vsclkdis_reg
);
563 val
&= VPIF_INPUT_TWO_CHANNEL
;
566 val
|= VPIF_INPUT_ONE_CHANNEL
;
569 __raw_writel(value
, vpif_vsclkdis_reg
);
570 spin_unlock_irqrestore(&vpif_reg_lock
, flags
);
572 err
= i2c_smbus_write_byte(cpld_client
, val
);
579 static struct tvp514x_platform_data tvp5146_pdata
= {
585 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
587 static struct vpif_subdev_info vpif_capture_sdev_info
[] = {
591 I2C_BOARD_INFO("tvp5146", 0x5d),
592 .platform_data
= &tvp5146_pdata
,
594 .input
= INPUT_CVBS_VI2B
,
595 .output
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
598 .if_type
= VPIF_IF_BT656
,
607 I2C_BOARD_INFO("tvp5146", 0x5c),
608 .platform_data
= &tvp5146_pdata
,
610 .input
= INPUT_SVIDEO_VI2C_VI1C
,
611 .output
= OUTPUT_10BIT_422_EMBEDDED_SYNC
,
614 .if_type
= VPIF_IF_BT656
,
622 static const struct vpif_input dm6467_ch0_inputs
[] = {
627 .type
= V4L2_INPUT_TYPE_CAMERA
,
628 .std
= TVP514X_STD_ALL
,
630 .subdev_name
= TVP5147_CH0
,
634 static const struct vpif_input dm6467_ch1_inputs
[] = {
639 .type
= V4L2_INPUT_TYPE_CAMERA
,
640 .std
= TVP514X_STD_ALL
,
642 .subdev_name
= TVP5147_CH1
,
646 static struct vpif_capture_config dm646x_vpif_capture_cfg
= {
647 .setup_input_path
= setup_vpif_input_path
,
648 .setup_input_channel_mode
= setup_vpif_input_channel_mode
,
649 .subdev_info
= vpif_capture_sdev_info
,
650 .subdev_count
= ARRAY_SIZE(vpif_capture_sdev_info
),
652 .inputs
= dm6467_ch0_inputs
,
653 .input_count
= ARRAY_SIZE(dm6467_ch0_inputs
),
656 .inputs
= dm6467_ch1_inputs
,
657 .input_count
= ARRAY_SIZE(dm6467_ch1_inputs
),
661 static void __init
evm_init_video(void)
663 vpif_vidclkctl_reg
= ioremap(VIDCLKCTL_OFFSET
, 4);
664 vpif_vsclkdis_reg
= ioremap(VSCLKDIS_OFFSET
, 4);
665 if (!vpif_vidclkctl_reg
|| !vpif_vsclkdis_reg
) {
666 pr_err("Can't map VPIF VIDCLKCTL or VSCLKDIS registers\n");
669 spin_lock_init(&vpif_reg_lock
);
671 dm646x_setup_vpif(&dm646x_vpif_display_config
,
672 &dm646x_vpif_capture_cfg
);
675 static void __init
evm_init_i2c(void)
677 davinci_init_i2c(&i2c_pdata
);
678 i2c_add_driver(&dm6467evm_cpld_driver
);
679 i2c_register_board_info(1, i2c_info
, ARRAY_SIZE(i2c_info
));
684 static void __init
davinci_map_io(void)
689 static struct davinci_uart_config uart_config __initdata
= {
690 .enabled_uarts
= (1 << 0),
693 #define DM646X_EVM_PHY_MASK (0x2)
694 #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
696 static __init
void evm_init(void)
698 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
701 davinci_serial_init(&uart_config
);
702 dm646x_init_mcasp0(&dm646x_evm_snd_data
[0]);
703 dm646x_init_mcasp1(&dm646x_evm_snd_data
[1]);
705 platform_device_register(&davinci_nand_device
);
710 soc_info
->emac_pdata
->phy_mask
= DM646X_EVM_PHY_MASK
;
711 soc_info
->emac_pdata
->mdio_max_freq
= DM646X_EVM_MDIO_FREQUENCY
;
714 static __init
void davinci_dm646x_evm_irq_init(void)
719 #define DM646X_EVM_REF_FREQ 27000000
720 #define DM6467T_EVM_REF_FREQ 33000000
722 void __init
dm646x_board_setup_refclk(struct clk
*clk
)
724 if (machine_is_davinci_dm6467tevm())
725 clk
->rate
= DM6467T_EVM_REF_FREQ
;
727 clk
->rate
= DM646X_EVM_REF_FREQ
;
730 MACHINE_START(DAVINCI_DM6467_EVM
, "DaVinci DM646x EVM")
732 .io_pg_offst
= (__IO_ADDRESS(IO_PHYS
) >> 18) & 0xfffc,
733 .boot_params
= (0x80000100),
734 .map_io
= davinci_map_io
,
735 .init_irq
= davinci_dm646x_evm_irq_init
,
736 .timer
= &davinci_timer
,
737 .init_machine
= evm_init
,
740 MACHINE_START(DAVINCI_DM6467TEVM
, "DaVinci DM6467T EVM")
742 .io_pg_offst
= (__IO_ADDRESS(IO_PHYS
) >> 18) & 0xfffc,
743 .boot_params
= (0x80000100),
744 .map_io
= davinci_map_io
,
745 .init_irq
= davinci_dm646x_evm_irq_init
,
746 .timer
= &davinci_timer
,
747 .init_machine
= evm_init
,