Davinci: generalized debug macros
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-davinci / board-dm646x-evm.c
blob6d8889342c9f8b978886bff64f5848b5f5fa7ce0
1 /*
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 /**************************************************************************
16 * Included Files
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>
41 #include <mach/i2c.h>
42 #include <mach/nand.h>
43 #include <mach/clock.h>
44 #include <mach/cdce949.h>
46 #include "clock.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 */
57 .name = "bootloader",
58 .offset = MTDPART_OFS_APPEND,
59 .size = 16 * NAND_BLOCK_SIZE,
60 .mask_flags = MTD_WRITEABLE, /* force read-only */
61 }, {
62 .name = "kernel",
63 .offset = MTDPART_OFS_APPEND,
64 .size = SZ_4M,
65 .mask_flags = 0,
66 }, {
67 .name = "filesystem",
68 .offset = MTDPART_OFS_APPEND,
69 .size = MTDPART_SIZ_FULL,
70 .mask_flags = 0,
74 static struct davinci_nand_pdata davinci_nand_data = {
75 .mask_cle = 0x80000,
76 .mask_ale = 0x40000,
77 .parts = davinci_nand_partitions,
78 .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
79 .ecc_mode = NAND_ECC_HW,
80 .options = 0,
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,
88 }, {
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",
97 .id = 0,
99 .num_resources = ARRAY_SIZE(davinci_nand_resources),
100 .resource = davinci_nand_resources,
102 .dev = {
103 .platform_data = &davinci_nand_data,
107 #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
108 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
109 #define HAS_ATA 1
110 #else
111 #define HAS_ATA 0
112 #endif
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)
122 if (HAS_ATA) {
123 u8 data;
124 struct i2c_msg msg[2] = {
126 .addr = client->addr,
127 .flags = I2C_M_RD,
128 .len = 1,
129 .buf = &data,
132 .addr = client->addr,
133 .flags = 0,
134 .len = 1,
135 .buf = &data,
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);
145 return 0;
148 static const struct i2c_device_id cpld_reg_ids[] = {
149 { "cpld_reg0", 0, },
150 { },
153 static struct i2c_driver dm6467evm_cpld_driver = {
154 .driver.name = "cpld_reg0",
155 .id_table = cpld_reg_ids,
156 .probe = cpld_reg0_probe,
159 /* LEDS */
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),
170 .leds = 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;
179 int status;
181 while (ngpio--) {
182 leds->gpio = gpio++;
183 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);
192 if (status < 0) {
193 platform_device_put(evm_led_dev);
194 evm_led_dev = NULL;
196 return status;
199 static int evm_led_teardown(struct i2c_client *client, int gpio,
200 unsigned ngpio, void *c)
202 if (evm_led_dev) {
203 platform_device_unregister(evm_led_dev);
204 evm_led_dev = NULL;
206 return 0;
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)
214 int status;
215 int i;
216 char label[10];
218 for (i = 0; i < 4; ++i) {
219 snprintf(label, 10, "user_sw%d", i);
220 status = gpio_request(gpio, label);
221 if (status)
222 goto out_free;
223 evm_sw_gpio[i] = gpio++;
225 status = gpio_direction_input(evm_sw_gpio[i]);
226 if (status) {
227 gpio_free(evm_sw_gpio[i]);
228 evm_sw_gpio[i] = -EINVAL;
229 goto out_free;
232 status = gpio_export(evm_sw_gpio[i], 0);
233 if (status) {
234 gpio_free(evm_sw_gpio[i]);
235 evm_sw_gpio[i] = -EINVAL;
236 goto out_free;
239 return status;
240 out_free:
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;
247 return status;
250 static int evm_sw_teardown(struct i2c_client *client, int gpio,
251 unsigned ngpio, void *c)
253 int i;
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;
262 return 0;
265 static int evm_pcf_setup(struct i2c_client *client, int gpio,
266 unsigned int ngpio, void *c)
268 int status;
270 if (ngpio < 8)
271 return -EINVAL;
273 status = evm_sw_setup(client, gpio, 4, c);
274 if (status)
275 return status;
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)
283 BUG_ON(ngpio < 8);
285 evm_sw_teardown(client, gpio, 4, c);
286 evm_led_teardown(client, gpio+4, 4, c);
288 return 0;
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,
304 .page_size = 64,
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[] = {
315 TX_MODE,
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),
324 .tdm_slots = 2,
325 .serial_dir = dm646x_iis_serializer_direction,
326 .eventq_no = EVENTQ_0,
329 .tx_dma_offset = 0x400,
330 .rx_dma_offset = 0,
331 .op_mode = DAVINCI_MCASP_DIT_MODE,
332 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
333 .tdm_slots = 32,
334 .serial_dir = dm646x_dit_serializer_direction,
335 .eventq_no = 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;
345 return 0;
348 static int __devexit cpld_video_remove(struct i2c_client *client)
350 cpld_client = NULL;
351 return 0;
354 static const struct i2c_device_id cpld_video_id[] = {
355 { "cpld_video", 0 },
359 static struct i2c_driver cpld_video_driver = {
360 .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)
427 unsigned long flags;
428 unsigned int value;
429 int val = 0;
430 int err = 0;
432 if (!vpif_vidclkctl_reg || !vpif_vsclkdis_reg || !cpld_client)
433 return -ENXIO;
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);
443 if (val < 0)
444 return val;
446 if (mux_mode == 1)
447 val &= ~0x40;
448 else
449 val |= 0x40;
451 err = i2c_smbus_write_byte(cpld_client, val);
452 if (err)
453 return err;
455 value = __raw_readl(vpif_vidclkctl_reg);
456 value &= ~(VCH2CLK_MASK);
457 value &= ~(VCH3CLK_MASK);
459 if (hd >= 1)
460 value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
461 else
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);
473 return 0;
476 static struct vpif_subdev_info dm646x_vpif_subdev[] = {
478 .name = "adv7343",
479 .board_info = {
480 I2C_BOARD_INFO("adv7343", 0x2a),
484 .name = "ths7303",
485 .board_info = {
486 I2C_BOARD_INFO("ths7303", 0x2c),
491 static const char *output[] = {
492 "Composite",
493 "Component",
494 "S-Video",
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),
501 .output = output,
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
512 * tvp7002.
514 static int setup_vpif_input_path(int channel, const char *sub_dev_name)
516 int err = 0;
517 int val;
519 /* for channel 1, we don't do anything */
520 if (channel != 0)
521 return 0;
523 if (!cpld_client)
524 return -ENXIO;
526 val = i2c_smbus_read_byte(cpld_client);
527 if (val < 0)
528 return val;
530 if (!strcmp(sub_dev_name, TVP5147_CH0) ||
531 !strcmp(sub_dev_name, TVP5147_CH1))
532 val &= TVP5147_INPUT;
533 else
534 val |= TVP7002_INPUT;
536 err = i2c_smbus_write_byte(cpld_client, val);
537 if (err)
538 return err;
539 return 0;
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)
550 unsigned long flags;
551 int err = 0;
552 int val;
553 u32 value;
555 if (!vpif_vsclkdis_reg || !cpld_client)
556 return -ENXIO;
558 val = i2c_smbus_read_byte(cpld_client);
559 if (val < 0)
560 return val;
562 spin_lock_irqsave(&vpif_reg_lock, flags);
563 value = __raw_readl(vpif_vsclkdis_reg);
564 if (mux_mode) {
565 val &= VPIF_INPUT_TWO_CHANNEL;
566 value |= VIDCH1CLK;
567 } else {
568 val |= VPIF_INPUT_ONE_CHANNEL;
569 value &= ~VIDCH1CLK;
571 __raw_writel(value, vpif_vsclkdis_reg);
572 spin_unlock_irqrestore(&vpif_reg_lock, flags);
574 err = i2c_smbus_write_byte(cpld_client, val);
575 if (err)
576 return err;
578 return 0;
581 static struct tvp514x_platform_data tvp5146_pdata = {
582 .clk_polarity = 0,
583 .hs_polarity = 1,
584 .vs_polarity = 1
587 #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
589 static struct vpif_subdev_info vpif_capture_sdev_info[] = {
591 .name = TVP5147_CH0,
592 .board_info = {
593 I2C_BOARD_INFO("tvp5146", 0x5d),
594 .platform_data = &tvp5146_pdata,
596 .input = INPUT_CVBS_VI2B,
597 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
598 .can_route = 1,
599 .vpif_if = {
600 .if_type = VPIF_IF_BT656,
601 .hd_pol = 1,
602 .vd_pol = 1,
603 .fid_pol = 0,
607 .name = TVP5147_CH1,
608 .board_info = {
609 I2C_BOARD_INFO("tvp5146", 0x5c),
610 .platform_data = &tvp5146_pdata,
612 .input = INPUT_SVIDEO_VI2C_VI1C,
613 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
614 .can_route = 1,
615 .vpif_if = {
616 .if_type = VPIF_IF_BT656,
617 .hd_pol = 1,
618 .vd_pol = 1,
619 .fid_pol = 0,
624 static const struct vpif_input dm6467_ch0_inputs[] = {
626 .input = {
627 .index = 0,
628 .name = "Composite",
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[] = {
638 .input = {
639 .index = 0,
640 .name = "S-Video",
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),
653 .chan_config[0] = {
654 .inputs = dm6467_ch0_inputs,
655 .input_count = ARRAY_SIZE(dm6467_ch0_inputs),
657 .chan_config[1] = {
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");
669 return;
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));
682 evm_init_cpld();
683 evm_init_video();
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 = {
690 .name = "cdce_xin",
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;
702 struct clk *clk;
704 for (c = cdce_clks; c->clk; c++) {
705 clk = c->clk;
706 clkdev_add(c);
707 clk_register(clk);
711 static void __init davinci_map_io(void)
713 dm646x_init();
714 cdce_clk_init();
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 */
724 static __init void evm_init(void)
726 struct davinci_soc_info *soc_info = &davinci_soc_info;
728 evm_init_i2c();
729 davinci_serial_init(&uart_config);
730 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
731 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
733 platform_device_register(&davinci_nand_device);
735 if (HAS_ATA)
736 davinci_init_ide();
738 soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
739 soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
742 #define DM646X_EVM_REF_FREQ 27000000
743 #define DM6467T_EVM_REF_FREQ 33000000
745 void __init dm646x_board_setup_refclk(struct clk *clk)
747 if (machine_is_davinci_dm6467tevm())
748 clk->rate = DM6467T_EVM_REF_FREQ;
749 else
750 clk->rate = DM646X_EVM_REF_FREQ;
753 MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
754 .phys_io = IO_PHYS,
755 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
756 .boot_params = (0x80000100),
757 .map_io = davinci_map_io,
758 .init_irq = davinci_irq_init,
759 .timer = &davinci_timer,
760 .init_machine = evm_init,
761 MACHINE_END
763 MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
764 .phys_io = IO_PHYS,
765 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
766 .boot_params = (0x80000100),
767 .map_io = davinci_map_io,
768 .init_irq = davinci_irq_init,
769 .timer = &davinci_timer,
770 .init_machine = evm_init,
771 MACHINE_END