blob: cb176826d1cbe4e0c77b2c955348d6a0adeebd53 [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>
Vivien Didelot25f73ed2013-09-27 15:06:28 -040025#include <linux/platform_data/at24.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070026#include <linux/i2c/pcf857x.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070027
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020028#include <media/i2c/tvp514x.h>
29#include <media/i2c/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>
Philip Avinash834acb22013-08-18 10:49:02 +053036#include <linux/platform_data/gpio-davinci.h>
37#include <linux/platform_data/i2c-davinci.h>
38#include <linux/platform_data/mtd-davinci.h>
39#include <linux/platform_data/mtd-davinci-aemif.h>
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053040
Kevin Hilmane38d92f2009-04-29 17:44:58 -070041#include <asm/mach-types.h>
42#include <asm/mach/arch.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070043
Kevin Hilmane38d92f2009-04-29 17:44:58 -070044#include <mach/common.h>
Philip Avinash834acb22013-08-18 10:49:02 +053045#include <mach/irqs.h>
Kevin Hilmane38d92f2009-04-29 17:44:58 -070046#include <mach/serial.h>
Nageswari Srinivasan77a92c72010-01-06 17:19:49 +053047#include <mach/clock.h>
Kevin Hilmanac7b75b2009-05-07 06:19:40 -070048
Manjunath Hadli39c6d2d2011-12-21 19:13:35 +053049#include "davinci.h"
Sekhar Noric1978e12009-11-24 18:25:15 +053050#include "clock.h"
51
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053052#define NAND_BLOCK_SIZE SZ_128K
53
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053054/* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
55 * and U-Boot environment this avoids dependency on any particular combination
56 * of UBL, U-Boot or flashing tools etc.
57 */
58static struct mtd_partition davinci_nand_partitions[] = {
59 {
60 /* UBL, U-Boot with environment */
61 .name = "bootloader",
62 .offset = MTDPART_OFS_APPEND,
63 .size = 16 * NAND_BLOCK_SIZE,
64 .mask_flags = MTD_WRITEABLE, /* force read-only */
65 }, {
66 .name = "kernel",
67 .offset = MTDPART_OFS_APPEND,
68 .size = SZ_4M,
69 .mask_flags = 0,
70 }, {
71 .name = "filesystem",
72 .offset = MTDPART_OFS_APPEND,
73 .size = MTDPART_SIZ_FULL,
74 .mask_flags = 0,
75 }
76};
77
Sekhar Nori0b3fc7b2010-08-09 15:46:40 +053078static struct davinci_aemif_timing dm6467tevm_nandflash_timing = {
79 .wsetup = 29,
80 .wstrobe = 24,
81 .whold = 14,
82 .rsetup = 19,
83 .rstrobe = 33,
84 .rhold = 0,
85 .ta = 29,
86};
87
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053088static struct davinci_nand_pdata davinci_nand_data = {
89 .mask_cle = 0x80000,
90 .mask_ale = 0x40000,
91 .parts = davinci_nand_partitions,
92 .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
93 .ecc_mode = NAND_ECC_HW,
Sekhar Noriacd36352013-08-16 14:43:48 +053094 .ecc_bits = 1,
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +053095 .options = 0,
96};
97
98static struct resource davinci_nand_resources[] = {
99 {
Sergei Shtylyov70342172010-04-16 21:29:11 +0400100 .start = DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
101 .end = DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530102 .flags = IORESOURCE_MEM,
103 }, {
Sergei Shtylyov70342172010-04-16 21:29:11 +0400104 .start = DM646X_ASYNC_EMIF_CONTROL_BASE,
105 .end = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530106 .flags = IORESOURCE_MEM,
107 },
108};
109
110static struct platform_device davinci_nand_device = {
111 .name = "davinci_nand",
112 .id = 0,
113
114 .num_resources = ARRAY_SIZE(davinci_nand_resources),
115 .resource = davinci_nand_resources,
116
117 .dev = {
118 .platform_data = &davinci_nand_data,
119 },
120};
121
Sekhar Nori28d4d1d2017-03-22 19:21:01 +0100122#define HAS_ATA (IS_ENABLED(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
123 IS_ENABLED(CONFIG_PATA_BK3710))
Sekhar Norib73b5262009-11-24 18:25:14 +0530124
Arnd Bergmann8e580412016-02-01 21:35:58 +0100125#ifdef CONFIG_I2C
Sekhar Norib73b5262009-11-24 18:25:14 +0530126/* CPLD Register 0 bits to control ATA */
127#define DM646X_EVM_ATA_RST BIT(0)
128#define DM646X_EVM_ATA_PWD BIT(1)
129
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530130/* CPLD Register 0 Client: used for I/O Control */
131static int cpld_reg0_probe(struct i2c_client *client,
132 const struct i2c_device_id *id)
133{
134 if (HAS_ATA) {
135 u8 data;
136 struct i2c_msg msg[2] = {
137 {
138 .addr = client->addr,
139 .flags = I2C_M_RD,
140 .len = 1,
141 .buf = &data,
142 },
143 {
144 .addr = client->addr,
145 .flags = 0,
146 .len = 1,
147 .buf = &data,
148 },
149 };
150
151 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
152 i2c_transfer(client->adapter, msg, 1);
153 data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
154 i2c_transfer(client->adapter, msg + 1, 1);
155 }
156
157 return 0;
158}
159
160static const struct i2c_device_id cpld_reg_ids[] = {
161 { "cpld_reg0", 0, },
162 { },
163};
164
165static struct i2c_driver dm6467evm_cpld_driver = {
166 .driver.name = "cpld_reg0",
167 .id_table = cpld_reg_ids,
168 .probe = cpld_reg0_probe,
169};
170
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700171/* LEDS */
172
173static struct gpio_led evm_leds[] = {
174 { .name = "DS1", .active_low = 1, },
175 { .name = "DS2", .active_low = 1, },
176 { .name = "DS3", .active_low = 1, },
177 { .name = "DS4", .active_low = 1, },
178};
179
Sekhar Nori445094f2009-11-04 17:08:42 +0530180static const struct gpio_led_platform_data evm_led_data = {
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700181 .num_leds = ARRAY_SIZE(evm_leds),
182 .leds = evm_leds,
183};
184
185static struct platform_device *evm_led_dev;
186
187static int evm_led_setup(struct i2c_client *client, int gpio,
188 unsigned int ngpio, void *c)
189{
190 struct gpio_led *leds = evm_leds;
191 int status;
192
193 while (ngpio--) {
194 leds->gpio = gpio++;
195 leds++;
Peter Senna Tschudinbaad1b32012-09-18 18:59:59 +0200196 }
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700197
198 evm_led_dev = platform_device_alloc("leds-gpio", 0);
199 platform_device_add_data(evm_led_dev, &evm_led_data,
200 sizeof(evm_led_data));
201
202 evm_led_dev->dev.parent = &client->dev;
203 status = platform_device_add(evm_led_dev);
204 if (status < 0) {
205 platform_device_put(evm_led_dev);
206 evm_led_dev = NULL;
207 }
208 return status;
209}
210
211static int evm_led_teardown(struct i2c_client *client, int gpio,
212 unsigned ngpio, void *c)
213{
214 if (evm_led_dev) {
215 platform_device_unregister(evm_led_dev);
216 evm_led_dev = NULL;
217 }
218 return 0;
219}
220
221static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
222
223static int evm_sw_setup(struct i2c_client *client, int gpio,
224 unsigned ngpio, void *c)
225{
226 int status;
227 int i;
228 char label[10];
229
230 for (i = 0; i < 4; ++i) {
231 snprintf(label, 10, "user_sw%d", i);
232 status = gpio_request(gpio, label);
233 if (status)
234 goto out_free;
235 evm_sw_gpio[i] = gpio++;
236
237 status = gpio_direction_input(evm_sw_gpio[i]);
238 if (status) {
239 gpio_free(evm_sw_gpio[i]);
240 evm_sw_gpio[i] = -EINVAL;
241 goto out_free;
242 }
243
244 status = gpio_export(evm_sw_gpio[i], 0);
245 if (status) {
246 gpio_free(evm_sw_gpio[i]);
247 evm_sw_gpio[i] = -EINVAL;
248 goto out_free;
249 }
250 }
251 return status;
252out_free:
253 for (i = 0; i < 4; ++i) {
254 if (evm_sw_gpio[i] != -EINVAL) {
255 gpio_free(evm_sw_gpio[i]);
256 evm_sw_gpio[i] = -EINVAL;
257 }
258 }
259 return status;
260}
261
262static int evm_sw_teardown(struct i2c_client *client, int gpio,
263 unsigned ngpio, void *c)
264{
265 int i;
266
267 for (i = 0; i < 4; ++i) {
268 if (evm_sw_gpio[i] != -EINVAL) {
269 gpio_unexport(evm_sw_gpio[i]);
270 gpio_free(evm_sw_gpio[i]);
271 evm_sw_gpio[i] = -EINVAL;
272 }
273 }
274 return 0;
275}
276
277static int evm_pcf_setup(struct i2c_client *client, int gpio,
278 unsigned int ngpio, void *c)
279{
280 int status;
281
282 if (ngpio < 8)
283 return -EINVAL;
284
285 status = evm_sw_setup(client, gpio, 4, c);
286 if (status)
287 return status;
288
289 return evm_led_setup(client, gpio+4, 4, c);
290}
291
292static int evm_pcf_teardown(struct i2c_client *client, int gpio,
293 unsigned int ngpio, void *c)
294{
295 BUG_ON(ngpio < 8);
296
297 evm_sw_teardown(client, gpio, 4, c);
298 evm_led_teardown(client, gpio+4, 4, c);
299
300 return 0;
301}
302
303static struct pcf857x_platform_data pcf_data = {
304 .gpio_base = DAVINCI_N_GPIO+1,
305 .setup = evm_pcf_setup,
306 .teardown = evm_pcf_teardown,
307};
308
309/* Most of this EEPROM is unused, but U-Boot uses some data:
310 * - 0x7f00, 6 bytes Ethernet Address
311 * - ... newer boards may have more
312 */
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700313
314static struct at24_platform_data eeprom_info = {
315 .byte_len = (256*1024) / 8,
316 .page_size = 64,
317 .flags = AT24_FLAG_ADDR16,
Mark A. Greerb14dc0f2009-04-15 12:41:27 -0700318 .setup = davinci_get_mac_addr,
319 .context = (void *)0x7f00,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700320};
Arnd Bergmann8e580412016-02-01 21:35:58 +0100321#endif
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700322
Chaithrika U S25acf552009-06-05 06:28:08 -0400323static u8 dm646x_iis_serializer_direction[] = {
324 TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
325};
326
327static u8 dm646x_dit_serializer_direction[] = {
328 TX_MODE,
329};
330
331static struct snd_platform_data dm646x_evm_snd_data[] = {
332 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400333 .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),
337 .tdm_slots = 2,
338 .serial_dir = dm646x_iis_serializer_direction,
Sekhar Nori48519f02010-07-19 12:31:16 +0530339 .asp_chan_q = EVENTQ_0,
Chaithrika U S25acf552009-06-05 06:28:08 -0400340 },
341 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400342 .tx_dma_offset = 0x400,
343 .rx_dma_offset = 0,
344 .op_mode = DAVINCI_MCASP_DIT_MODE,
345 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
346 .tdm_slots = 32,
347 .serial_dir = dm646x_dit_serializer_direction,
Sekhar Nori48519f02010-07-19 12:31:16 +0530348 .asp_chan_q = EVENTQ_0,
Chaithrika U S25acf552009-06-05 06:28:08 -0400349 },
350};
351
Arnd Bergmann8e580412016-02-01 21:35:58 +0100352#ifdef CONFIG_I2C
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400353static struct i2c_client *cpld_client;
354
355static int cpld_video_probe(struct i2c_client *client,
356 const struct i2c_device_id *id)
357{
358 cpld_client = client;
359 return 0;
360}
361
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800362static int cpld_video_remove(struct i2c_client *client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400363{
364 cpld_client = NULL;
365 return 0;
366}
367
368static const struct i2c_device_id cpld_video_id[] = {
369 { "cpld_video", 0 },
370 { }
371};
372
373static struct i2c_driver cpld_video_driver = {
374 .driver = {
375 .name = "cpld_video",
376 },
377 .probe = cpld_video_probe,
378 .remove = cpld_video_remove,
379 .id_table = cpld_video_id,
380};
381
382static void evm_init_cpld(void)
383{
384 i2c_add_driver(&cpld_video_driver);
385}
386
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700387static struct i2c_board_info __initdata i2c_info[] = {
388 {
389 I2C_BOARD_INFO("24c256", 0x50),
390 .platform_data = &eeprom_info,
391 },
392 {
393 I2C_BOARD_INFO("pcf8574a", 0x38),
394 .platform_data = &pcf_data,
395 },
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530396 {
397 I2C_BOARD_INFO("cpld_reg0", 0x3a),
398 },
Chaithrika U S1a7ff8f2009-08-25 15:20:05 +0300399 {
400 I2C_BOARD_INFO("tlv320aic33", 0x18),
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400401 },
402 {
403 I2C_BOARD_INFO("cpld_video", 0x3b),
404 },
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700405};
406
407static struct davinci_i2c_platform_data i2c_pdata = {
408 .bus_freq = 100 /* kHz */,
409 .bus_delay = 0 /* usec */,
410};
411
Sekhar Norib73b5262009-11-24 18:25:14 +0530412#define VCH2CLK_MASK (BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
413#define VCH2CLK_SYSCLK8 (BIT(9))
414#define VCH2CLK_AUXCLK (BIT(9) | BIT(8))
415#define VCH3CLK_MASK (BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
416#define VCH3CLK_SYSCLK8 (BIT(13))
417#define VCH3CLK_AUXCLK (BIT(14) | BIT(13))
418
419#define VIDCH2CLK (BIT(10))
420#define VIDCH3CLK (BIT(11))
421#define VIDCH1CLK (BIT(4))
422#define TVP7002_INPUT (BIT(4))
423#define TVP5147_INPUT (~BIT(4))
424#define VPIF_INPUT_ONE_CHANNEL (BIT(5))
425#define VPIF_INPUT_TWO_CHANNEL (~BIT(5))
426#define TVP5147_CH0 "tvp514x-0"
427#define TVP5147_CH1 "tvp514x-1"
428
Sekhar Norib73b5262009-11-24 18:25:14 +0530429/* spin lock for updating above registers */
430static spinlock_t vpif_reg_lock;
431
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400432static int set_vpif_clock(int mux_mode, int hd)
433{
434 unsigned long flags;
435 unsigned int value;
436 int val = 0;
437 int err = 0;
438
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530439 if (!cpld_client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400440 return -ENXIO;
441
442 /* disable the clock */
443 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530444 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400445 value |= (VIDCH3CLK | VIDCH2CLK);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530446 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400447 spin_unlock_irqrestore(&vpif_reg_lock, flags);
448
449 val = i2c_smbus_read_byte(cpld_client);
450 if (val < 0)
451 return val;
452
453 if (mux_mode == 1)
454 val &= ~0x40;
455 else
456 val |= 0x40;
457
458 err = i2c_smbus_write_byte(cpld_client, val);
459 if (err)
460 return err;
461
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530462 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400463 value &= ~(VCH2CLK_MASK);
464 value &= ~(VCH3CLK_MASK);
465
466 if (hd >= 1)
467 value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
468 else
469 value |= (VCH2CLK_AUXCLK | VCH3CLK_AUXCLK);
470
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530471 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400472
473 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530474 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400475 /* enable the clock */
476 value &= ~(VIDCH3CLK | VIDCH2CLK);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530477 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400478 spin_unlock_irqrestore(&vpif_reg_lock, flags);
479
480 return 0;
481}
482
483static struct vpif_subdev_info dm646x_vpif_subdev[] = {
484 {
485 .name = "adv7343",
486 .board_info = {
487 I2C_BOARD_INFO("adv7343", 0x2a),
488 },
489 },
490 {
491 .name = "ths7303",
492 .board_info = {
493 I2C_BOARD_INFO("ths7303", 0x2c),
494 },
495 },
496};
497
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300498static const struct vpif_output dm6467_ch0_outputs[] = {
499 {
500 .output = {
501 .index = 0,
502 .name = "Composite",
503 .type = V4L2_OUTPUT_TYPE_ANALOG,
504 .capabilities = V4L2_OUT_CAP_STD,
505 .std = V4L2_STD_ALL,
506 },
507 .subdev_name = "adv7343",
508 .output_route = ADV7343_COMPOSITE_ID,
509 },
510 {
511 .output = {
512 .index = 1,
513 .name = "Component",
514 .type = V4L2_OUTPUT_TYPE_ANALOG,
Hans Verkuil20a005a2013-02-15 15:10:45 -0300515 .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300516 },
517 .subdev_name = "adv7343",
518 .output_route = ADV7343_COMPONENT_ID,
519 },
520 {
521 .output = {
522 .index = 2,
523 .name = "S-Video",
524 .type = V4L2_OUTPUT_TYPE_ANALOG,
525 .capabilities = V4L2_OUT_CAP_STD,
526 .std = V4L2_STD_ALL,
527 },
528 .subdev_name = "adv7343",
529 .output_route = ADV7343_SVIDEO_ID,
530 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400531};
532
533static struct vpif_display_config dm646x_vpif_display_config = {
534 .set_clock = set_vpif_clock,
535 .subdevinfo = dm646x_vpif_subdev,
536 .subdev_count = ARRAY_SIZE(dm646x_vpif_subdev),
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300537 .chan_config[0] = {
538 .outputs = dm6467_ch0_outputs,
539 .output_count = ARRAY_SIZE(dm6467_ch0_outputs),
540 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400541 .card_name = "DM646x EVM",
542};
543
544/**
545 * setup_vpif_input_path()
546 * @channel: channel id (0 - CH0, 1 - CH1)
547 * @sub_dev_name: ptr sub device name
548 *
549 * This will set vpif input to capture data from tvp514x or
550 * tvp7002.
551 */
552static int setup_vpif_input_path(int channel, const char *sub_dev_name)
553{
554 int err = 0;
555 int val;
556
557 /* for channel 1, we don't do anything */
558 if (channel != 0)
559 return 0;
560
561 if (!cpld_client)
562 return -ENXIO;
563
564 val = i2c_smbus_read_byte(cpld_client);
565 if (val < 0)
566 return val;
567
568 if (!strcmp(sub_dev_name, TVP5147_CH0) ||
569 !strcmp(sub_dev_name, TVP5147_CH1))
570 val &= TVP5147_INPUT;
571 else
572 val |= TVP7002_INPUT;
573
574 err = i2c_smbus_write_byte(cpld_client, val);
575 if (err)
576 return err;
577 return 0;
578}
579
580/**
581 * setup_vpif_input_channel_mode()
582 * @mux_mode: mux mode. 0 - 1 channel or (1) - 2 channel
583 *
584 * This will setup input mode to one channel (TVP7002) or 2 channel (TVP5147)
585 */
586static int setup_vpif_input_channel_mode(int mux_mode)
587{
588 unsigned long flags;
589 int err = 0;
590 int val;
591 u32 value;
592
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530593 if (!cpld_client)
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400594 return -ENXIO;
595
596 val = i2c_smbus_read_byte(cpld_client);
597 if (val < 0)
598 return val;
599
600 spin_lock_irqsave(&vpif_reg_lock, flags);
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530601 value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400602 if (mux_mode) {
603 val &= VPIF_INPUT_TWO_CHANNEL;
604 value |= VIDCH1CLK;
605 } else {
606 val |= VPIF_INPUT_ONE_CHANNEL;
607 value &= ~VIDCH1CLK;
608 }
Manjunath Hadli5cfb19a2011-12-21 19:13:36 +0530609 __raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400610 spin_unlock_irqrestore(&vpif_reg_lock, flags);
611
612 err = i2c_smbus_write_byte(cpld_client, val);
613 if (err)
614 return err;
615
616 return 0;
617}
618
619static struct tvp514x_platform_data tvp5146_pdata = {
620 .clk_polarity = 0,
621 .hs_polarity = 1,
622 .vs_polarity = 1
623};
624
625#define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
626
627static struct vpif_subdev_info vpif_capture_sdev_info[] = {
628 {
629 .name = TVP5147_CH0,
630 .board_info = {
631 I2C_BOARD_INFO("tvp5146", 0x5d),
632 .platform_data = &tvp5146_pdata,
633 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400634 },
635 {
636 .name = TVP5147_CH1,
637 .board_info = {
638 I2C_BOARD_INFO("tvp5146", 0x5c),
639 .platform_data = &tvp5146_pdata,
640 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400641 },
642};
643
644static const struct vpif_input dm6467_ch0_inputs[] = {
645 {
646 .input = {
647 .index = 0,
648 .name = "Composite",
649 .type = V4L2_INPUT_TYPE_CAMERA,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300650 .capabilities = V4L2_IN_CAP_STD,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400651 .std = TVP514X_STD_ALL,
652 },
653 .subdev_name = TVP5147_CH0,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300654 .input_route = INPUT_CVBS_VI2B,
655 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400656 },
657};
658
659static const struct vpif_input dm6467_ch1_inputs[] = {
660 {
661 .input = {
662 .index = 0,
663 .name = "S-Video",
664 .type = V4L2_INPUT_TYPE_CAMERA,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300665 .capabilities = V4L2_IN_CAP_STD,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400666 .std = TVP514X_STD_ALL,
667 },
668 .subdev_name = TVP5147_CH1,
Hans Verkuil7aaad132012-09-20 09:06:25 -0300669 .input_route = INPUT_SVIDEO_VI2C_VI1C,
670 .output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC,
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400671 },
672};
673
674static struct vpif_capture_config dm646x_vpif_capture_cfg = {
675 .setup_input_path = setup_vpif_input_path,
676 .setup_input_channel_mode = setup_vpif_input_channel_mode,
677 .subdev_info = vpif_capture_sdev_info,
678 .subdev_count = ARRAY_SIZE(vpif_capture_sdev_info),
679 .chan_config[0] = {
680 .inputs = dm6467_ch0_inputs,
681 .input_count = ARRAY_SIZE(dm6467_ch0_inputs),
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300682 .vpif_if = {
683 .if_type = VPIF_IF_BT656,
684 .hd_pol = 1,
685 .vd_pol = 1,
686 .fid_pol = 0,
687 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400688 },
689 .chan_config[1] = {
690 .inputs = dm6467_ch1_inputs,
691 .input_count = ARRAY_SIZE(dm6467_ch1_inputs),
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300692 .vpif_if = {
693 .if_type = VPIF_IF_BT656,
694 .hd_pol = 1,
695 .vd_pol = 1,
696 .fid_pol = 0,
697 },
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400698 },
699};
700
701static void __init evm_init_video(void)
702{
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400703 spin_lock_init(&vpif_reg_lock);
704
705 dm646x_setup_vpif(&dm646x_vpif_display_config,
706 &dm646x_vpif_capture_cfg);
707}
708
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700709static void __init evm_init_i2c(void)
710{
711 davinci_init_i2c(&i2c_pdata);
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530712 i2c_add_driver(&dm6467evm_cpld_driver);
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700713 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
Muralidharan Karicheri85609c12009-09-16 13:15:30 -0400714 evm_init_cpld();
715 evm_init_video();
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700716}
Arnd Bergmann8e580412016-02-01 21:35:58 +0100717#endif
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700718
Sekhar Nori56e580d2011-06-14 15:33:20 +0000719#define DM6467T_EVM_REF_FREQ 33000000
720
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700721static void __init davinci_map_io(void)
722{
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700723 dm646x_init();
Sekhar Nori56e580d2011-06-14 15:33:20 +0000724
725 if (machine_is_davinci_dm6467tevm())
726 davinci_set_refclk_rate(DM6467T_EVM_REF_FREQ);
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700727}
728
Sekhar Norif6f97582012-01-21 02:48:17 +0530729#define DM646X_EVM_PHY_ID "davinci_mdio-0:01"
Rajashekhara, Sudhakarcce3ddd2010-06-29 11:35:15 +0530730/*
731 * The following EDMA channels/slots are not being used by drivers (for
732 * example: Timer, GPIO, UART events etc) on dm646x, hence they are being
733 * reserved for codecs on the DSP side.
734 */
735static const s16 dm646x_dma_rsv_chans[][2] = {
736 /* (offset, number) */
737 { 0, 4},
738 {13, 3},
739 {24, 4},
740 {30, 2},
741 {54, 3},
742 {-1, -1}
743};
744
745static const s16 dm646x_dma_rsv_slots[][2] = {
746 /* (offset, number) */
747 { 0, 4},
748 {13, 3},
749 {24, 4},
750 {30, 2},
751 {54, 3},
752 {128, 384},
753 {-1, -1}
754};
755
756static struct edma_rsv_info dm646x_edma_rsv[] = {
757 {
758 .rsv_chans = dm646x_dma_rsv_chans,
759 .rsv_slots = dm646x_dma_rsv_slots,
760 },
761};
762
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700763static __init void evm_init(void)
764{
Philip Avinash834acb22013-08-18 10:49:02 +0530765 int ret;
Mark A. Greer972412b2009-04-15 12:40:56 -0700766 struct davinci_soc_info *soc_info = &davinci_soc_info;
767
Philip Avinash834acb22013-08-18 10:49:02 +0530768 ret = dm646x_gpio_register();
769 if (ret)
770 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
771
Arnd Bergmann8e580412016-02-01 21:35:58 +0100772#ifdef CONFIG_I2C
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700773 evm_init_i2c();
Arnd Bergmann8e580412016-02-01 21:35:58 +0100774#endif
775
Manjunathappa, Prakashfcf71572013-06-19 14:45:42 +0530776 davinci_serial_init(dm646x_serial_device);
Chaithrika U S25acf552009-06-05 06:28:08 -0400777 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
778 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
Mark A. Greer972412b2009-04-15 12:40:56 -0700779
Sekhar Nori0b3fc7b2010-08-09 15:46:40 +0530780 if (machine_is_davinci_dm6467tevm())
781 davinci_nand_data.timing = &dm6467tevm_nandflash_timing;
782
Hemant Pedanekar50fbabf2009-09-18 23:09:29 +0530783 platform_device_register(&davinci_nand_device);
784
Ivan Khoronzhuk67f51852014-01-30 13:03:40 +0200785 if (davinci_aemif_setup(&davinci_nand_device))
786 pr_warn("%s: Cannot configure AEMIF.\n", __func__);
787
Rajashekhara, Sudhakarcce3ddd2010-06-29 11:35:15 +0530788 dm646x_init_edma(dm646x_edma_rsv);
789
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530790 if (HAS_ATA)
Sergei Shtylyov7a9978a2010-04-21 18:11:33 +0400791 davinci_init_ide();
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530792
Cyril Chemparathy782f2d72010-09-15 10:11:25 -0400793 soc_info->emac_pdata->phy_id = DM646X_EVM_PHY_ID;
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700794}
795
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700796MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
Nicolas Pitree7e56012011-07-05 22:38:11 -0400797 .atag_offset = 0x100,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700798 .map_io = davinci_map_io,
Cyril Chemparathybd808942010-05-07 17:06:37 -0400799 .init_irq = davinci_irq_init,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700800 .init_time = davinci_timer_init,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700801 .init_machine = evm_init,
Shawn Guo3aa3e842012-04-26 09:45:39 +0800802 .init_late = davinci_init_late,
Nicolas Pitref68deab2011-07-05 22:28:08 -0400803 .dma_zone_size = SZ_128M,
Sekhar Noric6121dd2011-12-05 11:29:46 +0100804 .restart = davinci_restart,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700805MACHINE_END
806
Sekhar Noric1978e12009-11-24 18:25:15 +0530807MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
Nicolas Pitree7e56012011-07-05 22:38:11 -0400808 .atag_offset = 0x100,
Sekhar Noric1978e12009-11-24 18:25:15 +0530809 .map_io = davinci_map_io,
Cyril Chemparathybd808942010-05-07 17:06:37 -0400810 .init_irq = davinci_irq_init,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700811 .init_time = davinci_timer_init,
Sekhar Noric1978e12009-11-24 18:25:15 +0530812 .init_machine = evm_init,
Shawn Guo3aa3e842012-04-26 09:45:39 +0800813 .init_late = davinci_init_late,
Nicolas Pitref68deab2011-07-05 22:28:08 -0400814 .dma_zone_size = SZ_128M,
Sekhar Noric6121dd2011-12-05 11:29:46 +0100815 .restart = davinci_restart,
Sekhar Noric1978e12009-11-24 18:25:15 +0530816MACHINE_END
817