blob: 734cc02725194e339937a6ac03bb36beabd4b0e2 [file] [log] [blame]
Kevin Hilmane38d92f2009-04-29 17:44:58 -07001/*
2 * TI DaVinci DM646X EVM board
3 *
4 * Derived from: arch/arm/mach-davinci/board-evm.c
5 * Copyright (C) 2006 Texas Instruments.
6 *
7 * (C) 2007-2008, MontaVista Software, Inc.
8 *
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.
12 *
13 */
14
15/**************************************************************************
16 * Included Files
17 **************************************************************************/
18
19#include <linux/kernel.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070020#include <linux/init.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070021#include <linux/leds.h>
22#include <linux/gpio.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070023#include <linux/platform_device.h>
24#include <linux/i2c.h>
25#include <linux/i2c/at24.h>
26#include <linux/i2c/pcf857x.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070027
Muralidharan Karicheri85609c12009-09-16 13:15:30 -040028#include <media/tvp514x.h>
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -030029#include <media/adv7343.h>
Muralidharan Karicheri85609c12009-09-16 13:15:30 -040030
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053031#include <linux/mtd/mtd.h>
32#include <linux/mtd/nand.h>
33#include <linux/mtd/partitions.h>
Sekhar Noric1978e12009-11-24 18:25:15 +053034#include <linux/clk.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040035#include <linux/export.h>
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053036
Kevin Hilmane38d92f2009-04-29 17:44:58 -070037#include <asm/mach-types.h>
38#include <asm/mach/arch.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070039
Kevin Hilmane38d92f2009-04-29 17:44:58 -070040#include <mach/common.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070041#include <mach/serial.h>
Arnd Bergmannec2a0832012-08-24 15:11:34 +020042#include <linux/platform_data/i2c-davinci.h>
43#include <linux/platform_data/mtd-davinci.h>
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +053044#include <mach/clock.h>
45#include <mach/cdce949.h>
Arnd Bergmannec2a0832012-08-24 15:11:34 +020046#include <linux/platform_data/mtd-davinci-aemif.h>
Kevin Hilmanac7b75b2009-05-07 06:19:40 -070047
Manjunath Hadli39c6d2d2011-12-21 19:13:35 +053048#include "davinci.h"
Sekhar Noric1978e12009-11-24 18:25:15 +053049#include "clock.h"
50
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053051#define NAND_BLOCK_SIZE SZ_128K
52
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053053/* 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.
56 */
57static struct mtd_partition davinci_nand_partitions[] = {
58 {
59 /* UBL, U-Boot with environment */
60 .name = "bootloader",
61 .offset = MTDPART_OFS_APPEND,
62 .size = 16 * NAND_BLOCK_SIZE,
63 .mask_flags = MTD_WRITEABLE, /* force read-only */
64 }, {
65 .name = "kernel",
66 .offset = MTDPART_OFS_APPEND,
67 .size = SZ_4M,
68 .mask_flags = 0,
69 }, {
70 .name = "filesystem",
71 .offset = MTDPART_OFS_APPEND,
72 .size = MTDPART_SIZ_FULL,
73 .mask_flags = 0,
74 }
75};
76
Sekhar Nori0b3fc7b2010-08-09 15:46:40 +053077static struct davinci_aemif_timing dm6467tevm_nandflash_timing = {
78 .wsetup = 29,
79 .wstrobe = 24,
80 .whold = 14,
81 .rsetup = 19,
82 .rstrobe = 33,
83 .rhold = 0,
84 .ta = 29,
85};
86
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053087static struct davinci_nand_pdata davinci_nand_data = {
88 .mask_cle = 0x80000,
89 .mask_ale = 0x40000,
90 .parts = davinci_nand_partitions,
91 .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
92 .ecc_mode = NAND_ECC_HW,
93 .options = 0,
94};
95
96static struct resource davinci_nand_resources[] = {
97 {
Sergei Shtylyov70342172010-04-16 21:29:11 +040098 .start = DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
99 .end = DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530100 .flags = IORESOURCE_MEM,
101 }, {
Sergei Shtylyov70342172010-04-16 21:29:11 +0400102 .start = DM646X_ASYNC_EMIF_CONTROL_BASE,
103 .end = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530104 .flags = IORESOURCE_MEM,
105 },
106};
107
108static struct platform_device davinci_nand_device = {
109 .name = "davinci_nand",
110 .id = 0,
111
112 .num_resources = ARRAY_SIZE(davinci_nand_resources),
113 .resource = davinci_nand_resources,
114
115 .dev = {
116 .platform_data = &davinci_nand_data,
117 },
118};
119
Lad, Prabhakara0a56db2013-04-01 12:43:44 +0530120#define HAS_ATA IS_ENABLED(CONFIG_BLK_DEV_PALMCHIP_BK3710)
Sekhar Norib73b5262009-11-24 18:25:14 +0530121
122/* CPLD Register 0 bits to control ATA */
123#define DM646X_EVM_ATA_RST BIT(0)
124#define DM646X_EVM_ATA_PWD BIT(1)
125
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530126/* CPLD Register 0 Client: used for I/O Control */
127static int cpld_reg0_probe(struct i2c_client *client,
128 const struct i2c_device_id *id)
129{
130 if (HAS_ATA) {
131 u8 data;
132 struct i2c_msg msg[2] = {
133 {
134 .addr = client->addr,
135 .flags = I2C_M_RD,
136 .len = 1,
137 .buf = &data,
138 },
139 {
140 .addr = client->addr,
141 .flags = 0,
142 .len = 1,
143 .buf = &data,
144 },
145 };
146
147 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
148 i2c_transfer(client->adapter, msg, 1);
149 data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
150 i2c_transfer(client->adapter, msg + 1, 1);
151 }
152
153 return 0;
154}
155
156static const struct i2c_device_id cpld_reg_ids[] = {
157 { "cpld_reg0", 0, },
158 { },
159};
160
161static struct i2c_driver dm6467evm_cpld_driver = {
162 .driver.name = "cpld_reg0",
163 .id_table = cpld_reg_ids,
164 .probe = cpld_reg0_probe,
165};
166
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700167/* LEDS */
168
169static struct gpio_led evm_leds[] = {
170 { .name = "DS1", .active_low = 1, },
171 { .name = "DS2", .active_low = 1, },
172 { .name = "DS3", .active_low = 1, },
173 { .name = "DS4", .active_low = 1, },
174};
175
Sekhar Nori445094f2009-11-04 17:08:42 +0530176static const struct gpio_led_platform_data evm_led_data = {
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700177 .num_leds = ARRAY_SIZE(evm_leds),
178 .leds = evm_leds,
179};
180
181static struct platform_device *evm_led_dev;
182
183static int evm_led_setup(struct i2c_client *client, int gpio,
184 unsigned int ngpio, void *c)
185{
186 struct gpio_led *leds = evm_leds;
187 int status;
188
189 while (ngpio--) {
190 leds->gpio = gpio++;
191 leds++;
Peter Senna Tschudinbaad1b32012-09-18 18:59:59 +0200192 }
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700193
194 evm_led_dev = platform_device_alloc("leds-gpio", 0);
195 platform_device_add_data(evm_led_dev, &evm_led_data,
196 sizeof(evm_led_data));
197
198 evm_led_dev->dev.parent = &client->dev;
199 status = platform_device_add(evm_led_dev);
200 if (status < 0) {
201 platform_device_put(evm_led_dev);
202 evm_led_dev = NULL;
203 }
204 return status;
205}
206
207static int evm_led_teardown(struct i2c_client *client, int gpio,
208 unsigned ngpio, void *c)
209{
210 if (evm_led_dev) {
211 platform_device_unregister(evm_led_dev);
212 evm_led_dev = NULL;
213 }
214 return 0;
215}
216
217static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
218
219static int evm_sw_setup(struct i2c_client *client, int gpio,
220 unsigned ngpio, void *c)
221{
222 int status;
223 int i;
224 char label[10];
225
226 for (i = 0; i < 4; ++i) {
227 snprintf(label, 10, "user_sw%d", i);
228 status = gpio_request(gpio, label);
229 if (status)
230 goto out_free;
231 evm_sw_gpio[i] = gpio++;
232
233 status = gpio_direction_input(evm_sw_gpio[i]);
234 if (status) {
235 gpio_free(evm_sw_gpio[i]);
236 evm_sw_gpio[i] = -EINVAL;
237 goto out_free;
238 }
239
240 status = gpio_export(evm_sw_gpio[i], 0);
241 if (status) {
242 gpio_free(evm_sw_gpio[i]);
243 evm_sw_gpio[i] = -EINVAL;
244 goto out_free;
245 }
246 }
247 return status;
248out_free:
249 for (i = 0; i < 4; ++i) {
250 if (evm_sw_gpio[i] != -EINVAL) {
251 gpio_free(evm_sw_gpio[i]);
252 evm_sw_gpio[i] = -EINVAL;
253 }
254 }
255 return status;
256}
257
258static int evm_sw_teardown(struct i2c_client *client, int gpio,
259 unsigned ngpio, void *c)
260{
261 int i;
262
263 for (i = 0; i < 4; ++i) {
264 if (evm_sw_gpio[i] != -EINVAL) {
265 gpio_unexport(evm_sw_gpio[i]);
266 gpio_free(evm_sw_gpio[i]);
267 evm_sw_gpio[i] = -EINVAL;
268 }
269 }
270 return 0;
271}
272
273static int evm_pcf_setup(struct i2c_client *client, int gpio,
274 unsigned int ngpio, void *c)
275{
276 int status;
277
278 if (ngpio < 8)
279 return -EINVAL;
280
281 status = evm_sw_setup(client, gpio, 4, c);
282 if (status)
283 return status;
284
285 return evm_led_setup(client, gpio+4, 4, c);
286}
287
288static int evm_pcf_teardown(struct i2c_client *client, int gpio,
289 unsigned int ngpio, void *c)
290{
291 BUG_ON(ngpio < 8);
292
293 evm_sw_teardown(client, gpio, 4, c);
294 evm_led_teardown(client, gpio+4, 4, c);
295
296 return 0;
297}
298
299static struct pcf857x_platform_data pcf_data = {
300 .gpio_base = DAVINCI_N_GPIO+1,
301 .setup = evm_pcf_setup,
302 .teardown = evm_pcf_teardown,
303};
304
305/* Most of this EEPROM is unused, but U-Boot uses some data:
306 * - 0x7f00, 6 bytes Ethernet Address
307 * - ... newer boards may have more
308 */
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700309
310static struct at24_platform_data eeprom_info = {
311 .byte_len = (256*1024) / 8,
312 .page_size = 64,
313 .flags = AT24_FLAG_ADDR16,
Mark A. Greerb14dc0f2009-04-15 12:41:27 -0700314 .setup = davinci_get_mac_addr,
315 .context = (void *)0x7f00,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700316};
317
Chaithrika U S25acf552009-06-05 06:28:08 -0400318static u8 dm646x_iis_serializer_direction[] = {
319 TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
320};
321
322static u8 dm646x_dit_serializer_direction[] = {
323 TX_MODE,
324};
325
326static struct snd_platform_data dm646x_evm_snd_data[] = {
327 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400328 .tx_dma_offset = 0x400,
329 .rx_dma_offset = 0x400,
330 .op_mode = DAVINCI_MCASP_IIS_MODE,
331 .num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction),
332 .tdm_slots = 2,
333 .serial_dir = dm646x_iis_serializer_direction,
Sekhar Nori48519f02010-07-19 12:31:16 +0530334 .asp_chan_q = EVENTQ_0,
Chaithrika U S25acf552009-06-05 06:28:08 -0400335 },
336 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400337 .tx_dma_offset = 0x400,
338 .rx_dma_offset = 0,
339 .op_mode = DAVINCI_MCASP_DIT_MODE,
340 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
341 .tdm_slots = 32,
342 .serial_dir = dm646x_dit_serializer_direction,
Sekhar Nori48519f02010-07-19 12:31:16 +0530343 .asp_chan_q = EVENTQ_0,
Chaithrika U S25acf552009-06-05 06:28:08 -0400344 },
345};
346
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400347static struct i2c_client *cpld_client;
348
349static int cpld_video_probe(struct i2c_client *client,
350 const struct i2c_device_id *id)
351{
352 cpld_client = client;
353 return 0;
354}
355
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800356static int cpld_video_remove(struct i2c_client *client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400357{
358 cpld_client = NULL;
359 return 0;
360}
361
362static const struct i2c_device_id cpld_video_id[] = {
363 { "cpld_video", 0 },
364 { }
365};
366
367static struct i2c_driver cpld_video_driver = {
368 .driver = {
369 .name = "cpld_video",
370 },
371 .probe = cpld_video_probe,
372 .remove = cpld_video_remove,
373 .id_table = cpld_video_id,
374};
375
376static void evm_init_cpld(void)
377{
378 i2c_add_driver(&cpld_video_driver);
379}
380
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700381static struct i2c_board_info __initdata i2c_info[] = {
382 {
383 I2C_BOARD_INFO("24c256", 0x50),
384 .platform_data = &eeprom_info,
385 },
386 {
387 I2C_BOARD_INFO("pcf8574a", 0x38),
388 .platform_data = &pcf_data,
389 },
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530390 {
391 I2C_BOARD_INFO("cpld_reg0", 0x3a),
392 },
Chaithrika U S1a7ff8f2009-08-25 15:20:05 +0300393 {
394 I2C_BOARD_INFO("tlv320aic33", 0x18),
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400395 },
396 {
397 I2C_BOARD_INFO("cpld_video", 0x3b),
398 },
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530399 {
400 I2C_BOARD_INFO("cdce949", 0x6c),
401 },
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700402};
403
404static struct davinci_i2c_platform_data i2c_pdata = {
405 .bus_freq = 100 /* kHz */,
406 .bus_delay = 0 /* usec */,
407};
408
Sekhar Norib73b5262009-11-24 18:25:14 +0530409#define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
410#define VCH2CLK_SYSCLK8 (BIT(9))
411#define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
412#define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
413#define VCH3CLK_SYSCLK8 (BIT(13))
414#define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
415
416#define VIDCH2CLK (BIT(10))
417#define VIDCH3CLK (BIT(11))
418#define VIDCH1CLK (BIT(4))
419#define TVP7002_INPUT (BIT(4))
420#define TVP5147_INPUT (~BIT(4))
421#define VPIF_INPUT_ONE_CHANNEL (BIT(5))
422#define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
423#define TVP5147_CH0 "tvp514x-0"
424#define TVP5147_CH1 "tvp514x-1"
425
Sekhar Norib73b5262009-11-24 18:25:14 +0530426/* spin lock for updating above registers */
427static spinlock_t vpif_reg_lock;
428
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400429static int set_vpif_clock(int mux_mode, int hd)
430{
431 unsigned long flags;
432 unsigned int value;
433 int val = 0;
434 int err = 0;
435
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530436 if (!cpld_client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400437 return -ENXIO;
438
439 /* disable the clock */
440 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530441 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400442 value |= (VIDCH3CLK | VIDCH2CLK);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530443 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400444 spin_unlock_irqrestore(&vpif_reg_lock, flags);
445
446 val = i2c_smbus_read_byte(cpld_client);
447 if (val < 0)
448 return val;
449
450 if (mux_mode == 1)
451 val &= ~0x40;
452 else
453 val |= 0x40;
454
455 err = i2c_smbus_write_byte(cpld_client, val);
456 if (err)
457 return err;
458
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530459 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400460 value &= ~(VCH2CLK_MASK);
461 value &= ~(VCH3CLK_MASK);
462
463 if (hd >= 1)
464 value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
465 else
466 value |= (VCH2CLK_AUXCLK | VCH3CLK_AUXCLK);
467
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530468 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400469
470 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530471 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400472 /* enable the clock */
473 value &= ~(VIDCH3CLK | VIDCH2CLK);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530474 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400475 spin_unlock_irqrestore(&vpif_reg_lock, flags);
476
477 return 0;
478}
479
480static struct vpif_subdev_info dm646x_vpif_subdev[] = {
481 {
482 .name = "adv7343",
483 .board_info = {
484 I2C_BOARD_INFO("adv7343", 0x2a),
485 },
486 },
487 {
488 .name = "ths7303",
489 .board_info = {
490 I2C_BOARD_INFO("ths7303", 0x2c),
491 },
492 },
493};
494
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300495static const struct vpif_output dm6467_ch0_outputs[] = {
496 {
497 .output = {
498 .index = 0,
499 .name = "Composite",
500 .type = V4L2_OUTPUT_TYPE_ANALOG,
501 .capabilities = V4L2_OUT_CAP_STD,
502 .std = V4L2_STD_ALL,
503 },
504 .subdev_name = "adv7343",
505 .output_route = ADV7343_COMPOSITE_ID,
506 },
507 {
508 .output = {
509 .index = 1,
510 .name = "Component",
511 .type = V4L2_OUTPUT_TYPE_ANALOG,
Hans Verkuil20a005a2013-02-15 15:10:45 -0300512 .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300513 },
514 .subdev_name = "adv7343",
515 .output_route = ADV7343_COMPONENT_ID,
516 },
517 {
518 .output = {
519 .index = 2,
520 .name = "S-Video",
521 .type = V4L2_OUTPUT_TYPE_ANALOG,
522 .capabilities = V4L2_OUT_CAP_STD,
523 .std = V4L2_STD_ALL,
524 },
525 .subdev_name = "adv7343",
526 .output_route = ADV7343_SVIDEO_ID,
527 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400528};
529
530static struct vpif_display_config dm646x_vpif_display_config = {
531 .set_clock = set_vpif_clock,
532 .subdevinfo = dm646x_vpif_subdev,
533 .subdev_count = ARRAY_SIZE(dm646x_vpif_subdev),
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300534 .chan_config[0] = {
535 .outputs = dm6467_ch0_outputs,
536 .output_count = ARRAY_SIZE(dm6467_ch0_outputs),
537 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400538 .card_name = "DM646x EVM",
539};
540
541/**
542 * setup_vpif_input_path()
543 * @channel: channel id (0 - CH0, 1 - CH1)
544 * @sub_dev_name: ptr sub device name
545 *
546 * This will set vpif input to capture data from tvp514x or
547 * tvp7002.
548 */
549static int setup_vpif_input_path(int channel, const char *sub_dev_name)
550{
551 int err = 0;
552 int val;
553
554 /* for channel 1, we don't do anything */
555 if (channel != 0)
556 return 0;
557
558 if (!cpld_client)
559 return -ENXIO;
560
561 val = i2c_smbus_read_byte(cpld_client);
562 if (val < 0)
563 return val;
564
565 if (!strcmp(sub_dev_name, TVP5147_CH0) ||
566 !strcmp(sub_dev_name, TVP5147_CH1))
567 val &= TVP5147_INPUT;
568 else
569 val |= TVP7002_INPUT;
570
571 err = i2c_smbus_write_byte(cpld_client, val);
572 if (err)
573 return err;
574 return 0;
575}
576
577/**
578 * setup_vpif_input_channel_mode()
579 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
580 *
581 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
582 */
583static int setup_vpif_input_channel_mode(int mux_mode)
584{
585 unsigned long flags;
586 int err = 0;
587 int val;
588 u32 value;
589
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530590 if (!cpld_client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400591 return -ENXIO;
592
593 val = i2c_smbus_read_byte(cpld_client);
594 if (val < 0)
595 return val;
596
597 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530598 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400599 if (mux_mode) {
600 val &= VPIF_INPUT_TWO_CHANNEL;
601 value |= VIDCH1CLK;
602 } else {
603 val |= VPIF_INPUT_ONE_CHANNEL;
604 value &= ~VIDCH1CLK;
605 }
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530606 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400607 spin_unlock_irqrestore(&vpif_reg_lock, flags);
608
609 err = i2c_smbus_write_byte(cpld_client, val);
610 if (err)
611 return err;
612
613 return 0;
614}
615
616static struct tvp514x_platform_data tvp5146_pdata = {
617 .clk_polarity = 0,
618 .hs_polarity = 1,
619 .vs_polarity = 1
620};
621
622#define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
623
624static struct vpif_subdev_info vpif_capture_sdev_info[] = {
625 {
626 .name = TVP5147_CH0,
627 .board_info = {
628 I2C_BOARD_INFO("tvp5146", 0x5d),
629 .platform_data = &tvp5146_pdata,
630 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400631 },
632 {
633 .name = TVP5147_CH1,
634 .board_info = {
635 I2C_BOARD_INFO("tvp5146", 0x5c),
636 .platform_data = &tvp5146_pdata,
637 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400638 },
639};
640
641static const struct vpif_input dm6467_ch0_inputs[] = {
642 {
643 .input = {
644 .index = 0,
645 .name = "Composite",
646 .type = V4L2_INPUT_TYPE_CAMERA,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300647 .capabilities = V4L2_IN_CAP_STD,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400648 .std = TVP514X_STD_ALL,
649 },
650 .subdev_name = TVP5147_CH0,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300651 .input_route = INPUT_CVBS_VI2B,
652 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400653 },
654};
655
656static const struct vpif_input dm6467_ch1_inputs[] = {
657 {
658 .input = {
659 .index = 0,
660 .name = "S-Video",
661 .type = V4L2_INPUT_TYPE_CAMERA,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300662 .capabilities = V4L2_IN_CAP_STD,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400663 .std = TVP514X_STD_ALL,
664 },
665 .subdev_name = TVP5147_CH1,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300666 .input_route = INPUT_SVIDEO_VI2C_VI1C,
667 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400668 },
669};
670
671static struct vpif_capture_config dm646x_vpif_capture_cfg = {
672 .setup_input_path = setup_vpif_input_path,
673 .setup_input_channel_mode = setup_vpif_input_channel_mode,
674 .subdev_info = vpif_capture_sdev_info,
675 .subdev_count = ARRAY_SIZE(vpif_capture_sdev_info),
676 .chan_config[0] = {
677 .inputs = dm6467_ch0_inputs,
678 .input_count = ARRAY_SIZE(dm6467_ch0_inputs),
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300679 .vpif_if = {
680 .if_type = VPIF_IF_BT656,
681 .hd_pol = 1,
682 .vd_pol = 1,
683 .fid_pol = 0,
684 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400685 },
686 .chan_config[1] = {
687 .inputs = dm6467_ch1_inputs,
688 .input_count = ARRAY_SIZE(dm6467_ch1_inputs),
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300689 .vpif_if = {
690 .if_type = VPIF_IF_BT656,
691 .hd_pol = 1,
692 .vd_pol = 1,
693 .fid_pol = 0,
694 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400695 },
696};
697
698static void __init evm_init_video(void)
699{
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400700 spin_lock_init(&vpif_reg_lock);
701
702 dm646x_setup_vpif(&dm646x_vpif_display_config,
703 &dm646x_vpif_capture_cfg);
704}
705
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700706static void __init evm_init_i2c(void)
707{
708 davinci_init_i2c(&i2c_pdata);
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530709 i2c_add_driver(&dm6467evm_cpld_driver);
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700710 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400711 evm_init_cpld();
712 evm_init_video();
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700713}
714
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530715#define CDCE949_XIN_RATE 27000000
716
717/* CDCE949 support - "lpsc" field is overridden to work as clock number */
718static struct clk cdce_clk_in = {
719 .name = "cdce_xin",
720 .rate = CDCE949_XIN_RATE,
721};
722
Kevin Hilmanc5641912010-01-11 08:22:23 -0800723static struct clk_lookup cdce_clks[] = {
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530724 CLK(NULL, "xin", &cdce_clk_in),
725 CLK(NULL, NULL, NULL),
726};
727
728static void __init cdce_clk_init(void)
729{
Kevin Hilmanc5641912010-01-11 08:22:23 -0800730 struct clk_lookup *c;
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530731 struct clk *clk;
732
Kevin Hilmanc5641912010-01-11 08:22:23 -0800733 for (c = cdce_clks; c->clk; c++) {
734 clk = c->clk;
735 clkdev_add(c);
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530736 clk_register(clk);
737 }
738}
739
Sekhar Nori56e580d2011-06-14 15:33:20 +0000740#define DM6467T_EVM_REF_FREQ 33000000
741
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700742static void __init davinci_map_io(void)
743{
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700744 dm646x_init();
Sekhar Nori56e580d2011-06-14 15:33:20 +0000745
746 if (machine_is_davinci_dm6467tevm())
747 davinci_set_refclk_rate(DM6467T_EVM_REF_FREQ);
748
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +0530749 cdce_clk_init();
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700750}
751
Sekhar Norif6f97582012-01-21 02:48:17 +0530752#define DM646X_EVM_PHY_ID "davinci_mdio-0:01"
Rajashekhara, Sudhakarcce3ddd2010-06-29 11:35:15 +0530753/*
754 * The following EDMA channels/slots are not being used by drivers (for
755 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
756 * reserved for codecs on the DSP side.
757 */
758static const s16 dm646x_dma_rsv_chans[][2] = {
759 /* (offset, number) */
760 { 0, 4},
761 {13, 3},
762 {24, 4},
763 {30, 2},
764 {54, 3},
765 {-1, -1}
766};
767
768static const s16 dm646x_dma_rsv_slots[][2] = {
769 /* (offset, number) */
770 { 0, 4},
771 {13, 3},
772 {24, 4},
773 {30, 2},
774 {54, 3},
775 {128, 384},
776 {-1, -1}
777};
778
779static struct edma_rsv_info dm646x_edma_rsv[] = {
780 {
781 .rsv_chans = dm646x_dma_rsv_chans,
782 .rsv_slots = dm646x_dma_rsv_slots,
783 },
784};
785
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700786static __init void evm_init(void)
787{
Mark A. Greer972412b2009-04-15 12:40:56 -0700788 struct davinci_soc_info *soc_info = &davinci_soc_info;
789
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700790 evm_init_i2c();
Manjunathappa, Prakashfcf71572013-06-19 14:45:42 +0530791 davinci_serial_init(dm646x_serial_device);
Chaithrika U S25acf552009-06-05 06:28:08 -0400792 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
793 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
Mark A. Greer972412b2009-04-15 12:40:56 -0700794
Sekhar Nori0b3fc7b2010-08-09 15:46:40 +0530795 if (machine_is_davinci_dm6467tevm())
796 davinci_nand_data.timing = &dm6467tevm_nandflash_timing;
797
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530798 platform_device_register(&davinci_nand_device);
799
Rajashekhara, Sudhakarcce3ddd2010-06-29 11:35:15 +0530800 dm646x_init_edma(dm646x_edma_rsv);
801
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530802 if (HAS_ATA)
Sergei Shtylyov7a9978a2010-04-21 18:11:33 +0400803 davinci_init_ide();
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530804
Cyril Chemparathy782f2d72010-09-15 10:11:25 -0400805 soc_info->emac_pdata->phy_id = DM646X_EVM_PHY_ID;
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700806}
807
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700808MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
Nicolas Pitree7e56012011-07-05 22:38:11 -0400809 .atag_offset = 0x100,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700810 .map_io = davinci_map_io,
Cyril Chemparathybd808942010-05-07 17:06:37 -0400811 .init_irq = davinci_irq_init,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700812 .init_time = davinci_timer_init,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700813 .init_machine = evm_init,
Shawn Guo3aa3e842012-04-26 09:45:39 +0800814 .init_late = davinci_init_late,
Nicolas Pitref68deab2011-07-05 22:28:08 -0400815 .dma_zone_size = SZ_128M,
Sekhar Noric6121dd2011-12-05 11:29:46 +0100816 .restart = davinci_restart,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700817MACHINE_END
818
Sekhar Noric1978e12009-11-24 18:25:15 +0530819MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
Nicolas Pitree7e56012011-07-05 22:38:11 -0400820 .atag_offset = 0x100,
Sekhar Noric1978e12009-11-24 18:25:15 +0530821 .map_io = davinci_map_io,
Cyril Chemparathybd808942010-05-07 17:06:37 -0400822 .init_irq = davinci_irq_init,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700823 .init_time = davinci_timer_init,
Sekhar Noric1978e12009-11-24 18:25:15 +0530824 .init_machine = evm_init,
Shawn Guo3aa3e842012-04-26 09:45:39 +0800825 .init_late = davinci_init_late,
Nicolas Pitref68deab2011-07-05 22:28:08 -0400826 .dma_zone_size = SZ_128M,
Sekhar Noric6121dd2011-12-05 11:29:46 +0100827 .restart = davinci_restart,
Sekhar Noric1978e12009-11-24 18:25:15 +0530828MACHINE_END
829