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>
43 #include <mach/clock.h>
44 #include <mach/cdce949.h>
48 #define NAND_BLOCK_SIZE SZ_128K
50 /* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
51 * and U-Boot environment this avoids dependency on any particular combination
52 * of UBL, U-Boot or flashing tools etc.
54 static struct mtd_partition davinci_nand_partitions[] = {
56 /* UBL, U-Boot with environment */
58 .offset = MTDPART_OFS_APPEND,
59 .size = 16 * NAND_BLOCK_SIZE,
60 .mask_flags = MTD_WRITEABLE, /* force read-only */
63 .offset = MTDPART_OFS_APPEND,
68 .offset = MTDPART_OFS_APPEND,
69 .size = MTDPART_SIZ_FULL,
74 static struct davinci_nand_pdata davinci_nand_data = {
77 .parts = davinci_nand_partitions,
78 .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
79 .ecc_mode = NAND_ECC_HW,
83 static struct resource davinci_nand_resources[] = {
85 .start = DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
86 .end = DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
87 .flags = IORESOURCE_MEM,
89 .start = DM646X_ASYNC_EMIF_CONTROL_BASE,
90 .end = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
91 .flags = IORESOURCE_MEM,
95 static struct platform_device davinci_nand_device = {
96 .name = "davinci_nand",
99 .num_resources = ARRAY_SIZE(davinci_nand_resources),
100 .resource = davinci_nand_resources,
103 .platform_data = &davinci_nand_data,
107 #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
108 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
114 /* CPLD Register 0 bits to control ATA */
115 #define DM646X_EVM_ATA_RST BIT(0)
116 #define DM646X_EVM_ATA_PWD BIT(1)
118 /* CPLD Register 0 Client: used for I/O Control */
119 static int cpld_reg0_probe(struct i2c_client *client,
120 const struct i2c_device_id *id)
124 struct i2c_msg msg[2] = {
126 .addr = client->addr,
132 .addr = client->addr,
139 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
140 i2c_transfer(client->adapter, msg, 1);
141 data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
142 i2c_transfer(client->adapter, msg + 1, 1);
148 static const struct i2c_device_id cpld_reg_ids[] = {
153 static struct i2c_driver dm6467evm_cpld_driver = {
154 .driver.name = "cpld_reg0",
155 .id_table = cpld_reg_ids,
156 .probe = cpld_reg0_probe,
161 static struct gpio_led evm_leds[] = {
162 { .name = "DS1", .active_low = 1, },
163 { .name = "DS2", .active_low = 1, },
164 { .name = "DS3", .active_low = 1, },
165 { .name = "DS4", .active_low = 1, },
168 static const struct gpio_led_platform_data evm_led_data = {
169 .num_leds = ARRAY_SIZE(evm_leds),
173 static struct platform_device *evm_led_dev;
175 static int evm_led_setup(struct i2c_client *client, int gpio,
176 unsigned int ngpio, void *c)
178 struct gpio_led *leds = evm_leds;
186 evm_led_dev = platform_device_alloc("leds-gpio", 0);
187 platform_device_add_data(evm_led_dev, &evm_led_data,
188 sizeof(evm_led_data));
190 evm_led_dev->dev.parent = &client->dev;
191 status = platform_device_add(evm_led_dev);
193 platform_device_put(evm_led_dev);
199 static int evm_led_teardown(struct i2c_client *client, int gpio,
200 unsigned ngpio, void *c)
203 platform_device_unregister(evm_led_dev);
209 static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
211 static int evm_sw_setup(struct i2c_client *client, int gpio,
212 unsigned ngpio, void *c)
218 for (i = 0; i < 4; ++i) {
219 snprintf(label, 10, "user_sw%d", i);
220 status = gpio_request(gpio, label);
223 evm_sw_gpio[i] = gpio++;
225 status = gpio_direction_input(evm_sw_gpio[i]);
227 gpio_free(evm_sw_gpio[i]);
228 evm_sw_gpio[i] = -EINVAL;
232 status = gpio_export(evm_sw_gpio[i], 0);
234 gpio_free(evm_sw_gpio[i]);
235 evm_sw_gpio[i] = -EINVAL;
241 for (i = 0; i < 4; ++i) {
242 if (evm_sw_gpio[i] != -EINVAL) {
243 gpio_free(evm_sw_gpio[i]);
244 evm_sw_gpio[i] = -EINVAL;
250 static int evm_sw_teardown(struct i2c_client *client, int gpio,
251 unsigned ngpio, void *c)
255 for (i = 0; i < 4; ++i) {
256 if (evm_sw_gpio[i] != -EINVAL) {
257 gpio_unexport(evm_sw_gpio[i]);
258 gpio_free(evm_sw_gpio[i]);
259 evm_sw_gpio[i] = -EINVAL;
265 static int evm_pcf_setup(struct i2c_client *client, int gpio,
266 unsigned int ngpio, void *c)
273 status = evm_sw_setup(client, gpio, 4, c);
277 return evm_led_setup(client, gpio+4, 4, c);
280 static int evm_pcf_teardown(struct i2c_client *client, int gpio,
281 unsigned int ngpio, void *c)
285 evm_sw_teardown(client, gpio, 4, c);
286 evm_led_teardown(client, gpio+4, 4, c);
291 static struct pcf857x_platform_data pcf_data = {
292 .gpio_base = DAVINCI_N_GPIO+1,
293 .setup = evm_pcf_setup,
294 .teardown = evm_pcf_teardown,
297 /* Most of this EEPROM is unused, but U-Boot uses some data:
298 * - 0x7f00, 6 bytes Ethernet Address
299 * - ... newer boards may have more
302 static struct at24_platform_data eeprom_info = {
303 .byte_len = (256*1024) / 8,
305 .flags = AT24_FLAG_ADDR16,
306 .setup = davinci_get_mac_addr,
307 .context = (void *)0x7f00,
310 static u8 dm646x_iis_serializer_direction[] = {
311 TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
314 static u8 dm646x_dit_serializer_direction[] = {
318 static struct snd_platform_data dm646x_evm_snd_data[] = {
320 .tx_dma_offset = 0x400,
321 .rx_dma_offset = 0x400,
322 .op_mode = DAVINCI_MCASP_IIS_MODE,
323 .num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction),
325 .serial_dir = dm646x_iis_serializer_direction,
326 .asp_chan_q = EVENTQ_0,
329 .tx_dma_offset = 0x400,
331 .op_mode = DAVINCI_MCASP_DIT_MODE,
332 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
334 .serial_dir = dm646x_dit_serializer_direction,
335 .asp_chan_q = EVENTQ_0,
339 static struct i2c_client *cpld_client;
341 static int cpld_video_probe(struct i2c_client *client,
342 const struct i2c_device_id *id)
344 cpld_client = client;
348 static int __devexit cpld_video_remove(struct i2c_client *client)
354 static const struct i2c_device_id cpld_video_id[] = {
359 static struct i2c_driver cpld_video_driver = {
361 .name = "cpld_video",
363 .probe = cpld_video_probe,
364 .remove = cpld_video_remove,
365 .id_table = cpld_video_id,
368 static void evm_init_cpld(void)
370 i2c_add_driver(&cpld_video_driver);
373 static struct i2c_board_info __initdata i2c_info[] = {
375 I2C_BOARD_INFO("24c256", 0x50),
376 .platform_data = &eeprom_info,
379 I2C_BOARD_INFO("pcf8574a", 0x38),
380 .platform_data = &pcf_data,
383 I2C_BOARD_INFO("cpld_reg0", 0x3a),
386 I2C_BOARD_INFO("tlv320aic33", 0x18),
389 I2C_BOARD_INFO("cpld_video", 0x3b),
392 I2C_BOARD_INFO("cdce949", 0x6c),
396 static struct davinci_i2c_platform_data i2c_pdata = {
397 .bus_freq = 100 /* kHz */,
398 .bus_delay = 0 /* usec */,
401 #define VIDCLKCTL_OFFSET (DAVINCI_SYSTEM_MODULE_BASE + 0x38)
402 #define VSCLKDIS_OFFSET (DAVINCI_SYSTEM_MODULE_BASE + 0x6c)
403 #define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
404 #define VCH2CLK_SYSCLK8 (BIT(9))
405 #define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
406 #define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
407 #define VCH3CLK_SYSCLK8 (BIT(13))
408 #define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
410 #define VIDCH2CLK (BIT(10))
411 #define VIDCH3CLK (BIT(11))
412 #define VIDCH1CLK (BIT(4))
413 #define TVP7002_INPUT (BIT(4))
414 #define TVP5147_INPUT (~BIT(4))
415 #define VPIF_INPUT_ONE_CHANNEL (BIT(5))
416 #define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
417 #define TVP5147_CH0 "tvp514x-0"
418 #define TVP5147_CH1 "tvp514x-1"
420 static void __iomem *vpif_vidclkctl_reg;
421 static void __iomem *vpif_vsclkdis_reg;
422 /* spin lock for updating above registers */
423 static spinlock_t vpif_reg_lock;
425 static int set_vpif_clock(int mux_mode, int hd)
432 if (!vpif_vidclkctl_reg || !vpif_vsclkdis_reg || !cpld_client)
435 /* disable the clock */
436 spin_lock_irqsave(&vpif_reg_lock, flags);
437 value = __raw_readl(vpif_vsclkdis_reg);
438 value |= (VIDCH3CLK | VIDCH2CLK);
439 __raw_writel(value, vpif_vsclkdis_reg);
440 spin_unlock_irqrestore(&vpif_reg_lock, flags);
442 val = i2c_smbus_read_byte(cpld_client);
451 err = i2c_smbus_write_byte(cpld_client, val);
455 value = __raw_readl(vpif_vidclkctl_reg);
456 value &= ~(VCH2CLK_MASK);
457 value &= ~(VCH3CLK_MASK);
460 value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
462 value |= (VCH2CLK_AUXCLK | VCH3CLK_AUXCLK);
464 __raw_writel(value, vpif_vidclkctl_reg);
466 spin_lock_irqsave(&vpif_reg_lock, flags);
467 value = __raw_readl(vpif_vsclkdis_reg);
468 /* enable the clock */
469 value &= ~(VIDCH3CLK | VIDCH2CLK);
470 __raw_writel(value, vpif_vsclkdis_reg);
471 spin_unlock_irqrestore(&vpif_reg_lock, flags);
476 static struct vpif_subdev_info dm646x_vpif_subdev[] = {
480 I2C_BOARD_INFO("adv7343", 0x2a),
486 I2C_BOARD_INFO("ths7303", 0x2c),
491 static const char *output[] = {
497 static struct vpif_display_config dm646x_vpif_display_config = {
498 .set_clock = set_vpif_clock,
499 .subdevinfo = dm646x_vpif_subdev,
500 .subdev_count = ARRAY_SIZE(dm646x_vpif_subdev),
502 .output_count = ARRAY_SIZE(output),
503 .card_name = "DM646x EVM",
507 * setup_vpif_input_path()
508 * @channel: channel id (0 - CH0, 1 - CH1)
509 * @sub_dev_name: ptr sub device name
511 * This will set vpif input to capture data from tvp514x or
514 static int setup_vpif_input_path(int channel, const char *sub_dev_name)
519 /* for channel 1, we don't do anything */
526 val = i2c_smbus_read_byte(cpld_client);
530 if (!strcmp(sub_dev_name, TVP5147_CH0) ||
531 !strcmp(sub_dev_name, TVP5147_CH1))
532 val &= TVP5147_INPUT;
534 val |= TVP7002_INPUT;
536 err = i2c_smbus_write_byte(cpld_client, val);
543 * setup_vpif_input_channel_mode()
544 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
546 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
548 static int setup_vpif_input_channel_mode(int mux_mode)
555 if (!vpif_vsclkdis_reg || !cpld_client)
558 val = i2c_smbus_read_byte(cpld_client);
562 spin_lock_irqsave(&vpif_reg_lock, flags);
563 value = __raw_readl(vpif_vsclkdis_reg);
565 val &= VPIF_INPUT_TWO_CHANNEL;
568 val |= VPIF_INPUT_ONE_CHANNEL;
571 __raw_writel(value, vpif_vsclkdis_reg);
572 spin_unlock_irqrestore(&vpif_reg_lock, flags);
574 err = i2c_smbus_write_byte(cpld_client, val);
581 static struct tvp514x_platform_data tvp5146_pdata = {
587 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
589 static struct vpif_subdev_info vpif_capture_sdev_info[] = {
593 I2C_BOARD_INFO("tvp5146", 0x5d),
594 .platform_data = &tvp5146_pdata,
596 .input = INPUT_CVBS_VI2B,
597 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
600 .if_type = VPIF_IF_BT656,
609 I2C_BOARD_INFO("tvp5146", 0x5c),
610 .platform_data = &tvp5146_pdata,
612 .input = INPUT_SVIDEO_VI2C_VI1C,
613 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
616 .if_type = VPIF_IF_BT656,
624 static const struct vpif_input dm6467_ch0_inputs[] = {
629 .type = V4L2_INPUT_TYPE_CAMERA,
630 .std = TVP514X_STD_ALL,
632 .subdev_name = TVP5147_CH0,
636 static const struct vpif_input dm6467_ch1_inputs[] = {
641 .type = V4L2_INPUT_TYPE_CAMERA,
642 .std = TVP514X_STD_ALL,
644 .subdev_name = TVP5147_CH1,
648 static struct vpif_capture_config dm646x_vpif_capture_cfg = {
649 .setup_input_path = setup_vpif_input_path,
650 .setup_input_channel_mode = setup_vpif_input_channel_mode,
651 .subdev_info = vpif_capture_sdev_info,
652 .subdev_count = ARRAY_SIZE(vpif_capture_sdev_info),
654 .inputs = dm6467_ch0_inputs,
655 .input_count = ARRAY_SIZE(dm6467_ch0_inputs),
658 .inputs = dm6467_ch1_inputs,
659 .input_count = ARRAY_SIZE(dm6467_ch1_inputs),
663 static void __init evm_init_video(void)
665 vpif_vidclkctl_reg = ioremap(VIDCLKCTL_OFFSET, 4);
666 vpif_vsclkdis_reg = ioremap(VSCLKDIS_OFFSET, 4);
667 if (!vpif_vidclkctl_reg || !vpif_vsclkdis_reg) {
668 pr_err("Can't map VPIF VIDCLKCTL or VSCLKDIS registers\n");
671 spin_lock_init(&vpif_reg_lock);
673 dm646x_setup_vpif(&dm646x_vpif_display_config,
674 &dm646x_vpif_capture_cfg);
677 static void __init evm_init_i2c(void)
679 davinci_init_i2c(&i2c_pdata);
680 i2c_add_driver(&dm6467evm_cpld_driver);
681 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
686 #define CDCE949_XIN_RATE 27000000
688 /* CDCE949 support - "lpsc" field is overridden to work as clock number */
689 static struct clk cdce_clk_in = {
691 .rate = CDCE949_XIN_RATE,
694 static struct clk_lookup cdce_clks[] = {
695 CLK(NULL, "xin", &cdce_clk_in),
696 CLK(NULL, NULL, NULL),
699 static void __init cdce_clk_init(void)
701 struct clk_lookup *c;
704 for (c = cdce_clks; c->clk; c++) {
711 static void __init davinci_map_io(void)
717 static struct davinci_uart_config uart_config __initdata = {
718 .enabled_uarts = (1 << 0),
721 #define DM646X_EVM_PHY_MASK (0x2)
722 #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
725 * The following EDMA channels/slots are not being used by drivers (for
726 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
727 * reserved for codecs on the DSP side.
729 static const s16 dm646x_dma_rsv_chans[][2] = {
730 /* (offset, number) */
739 static const s16 dm646x_dma_rsv_slots[][2] = {
740 /* (offset, number) */
750 static struct edma_rsv_info dm646x_edma_rsv[] = {
752 .rsv_chans = dm646x_dma_rsv_chans,
753 .rsv_slots = dm646x_dma_rsv_slots,
757 static __init void evm_init(void)
759 struct davinci_soc_info *soc_info = &davinci_soc_info;
762 davinci_serial_init(&uart_config);
763 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
764 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
766 platform_device_register(&davinci_nand_device);
768 dm646x_init_edma(dm646x_edma_rsv);
773 soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
774 soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
777 #define DM646X_EVM_REF_FREQ 27000000
778 #define DM6467T_EVM_REF_FREQ 33000000
780 void __init dm646x_board_setup_refclk(struct clk *clk)
782 if (machine_is_davinci_dm6467tevm())
783 clk->rate = DM6467T_EVM_REF_FREQ;
785 clk->rate = DM646X_EVM_REF_FREQ;
788 MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
789 .boot_params = (0x80000100),
790 .map_io = davinci_map_io,
791 .init_irq = davinci_irq_init,
792 .timer = &davinci_timer,
793 .init_machine = evm_init,
796 MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
797 .boot_params = (0x80000100),
798 .map_io = davinci_map_io,
799 .init_irq = davinci_irq_init,
800 .timer = &davinci_timer,
801 .init_machine = evm_init,