board-dm644x-evm.c 22.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * TI DaVinci EVM board support
 *
 * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
 *
 * 2007 (c) MontaVista Software, Inc. This file is licensed under
 * the terms of the GNU General Public License version 2. This program
 * is licensed "as is" without any warranty of any kind, whether express
 * or implied.
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/platform_device.h>
15
#include <linux/gpio.h>
16
#include <linux/gpio/machine.h>
17
#include <linux/i2c.h>
18
#include <linux/platform_data/pcf857x.h>
19
#include <linux/platform_data/gpio-davinci.h>
20
#include <linux/property.h>
21
#include <linux/mtd/mtd.h>
22
#include <linux/mtd/rawnand.h>
23
24
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
25
#include <linux/nvmem-provider.h>
26
27
#include <linux/phy.h>
#include <linux/clk.h>
28
#include <linux/videodev2.h>
29
#include <linux/v4l2-dv-timings.h>
30
#include <linux/export.h>
31
#include <linux/leds.h>
32
33
#include <linux/regulator/fixed.h>
#include <linux/regulator/machine.h>
34

35
#include <media/i2c/tvp514x.h>
36
37
38
39

#include <asm/mach-types.h>
#include <asm/mach/arch.h>

40
#include <mach/common.h>
41
#include <mach/mux.h>
42
43
44
#include <mach/serial.h>

#include <linux/platform_data/i2c-davinci.h>
45
46
47
48
#include <linux/platform_data/mtd-davinci.h>
#include <linux/platform_data/mmc-davinci.h>
#include <linux/platform_data/usb-davinci.h>
#include <linux/platform_data/mtd-davinci-aemif.h>
49
#include <linux/platform_data/ti-aemif.h>
50

51
#include "davinci.h"
52
#include "irqs.h"
53

54
#define DM644X_EVM_PHY_ID		"davinci_mdio-0:01"
55
56
#define LXT971_PHY_ID	(0x001378e2)
#define LXT971_PHY_MASK	(0xfffffff0)
57

58
static struct mtd_partition davinci_evm_norflash_partitions[] = {
59
	/* bootloader (UBL, U-Boot, etc) in first 5 sectors */
60
61
62
	{
		.name		= "bootloader",
		.offset		= 0,
63
		.size		= 5 * SZ_64K,
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
		.mask_flags	= MTD_WRITEABLE, /* force read-only */
	},
	/* bootloader params in the next 1 sectors */
	{
		.name		= "params",
		.offset		= MTDPART_OFS_APPEND,
		.size		= SZ_64K,
		.mask_flags	= 0,
	},
	/* kernel */
	{
		.name		= "kernel",
		.offset		= MTDPART_OFS_APPEND,
		.size		= SZ_2M,
		.mask_flags	= 0
	},
	/* file system */
	{
		.name		= "filesystem",
		.offset		= MTDPART_OFS_APPEND,
		.size		= MTDPART_SIZ_FULL,
		.mask_flags	= 0
	}
};

89
static struct physmap_flash_data davinci_evm_norflash_data = {
90
	.width		= 2,
91
92
	.parts		= davinci_evm_norflash_partitions,
	.nr_parts	= ARRAY_SIZE(davinci_evm_norflash_partitions),
93
94
95
96
};

/* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
 * limits addresses to 16M, so using addresses past 16M will wrap */
97
static struct resource davinci_evm_norflash_resource = {
98
99
	.start		= DM644X_ASYNC_EMIF_DATA_CE0_BASE,
	.end		= DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
100
101
102
	.flags		= IORESOURCE_MEM,
};

103
static struct platform_device davinci_evm_norflash_device = {
104
105
106
	.name		= "physmap-flash",
	.id		= 0,
	.dev		= {
107
		.platform_data	= &davinci_evm_norflash_data,
108
109
	},
	.num_resources	= 1,
110
111
112
	.resource	= &davinci_evm_norflash_resource,
};

113
114
115
116
/* DM644x EVM includes a 64 MByte small-page NAND flash (16K blocks).
 * It may used instead of the (default) NOR chip to boot, using TI's
 * tools to install the secondary boot loader (UBL) and U-Boot.
 */
117
static struct mtd_partition davinci_evm_nandflash_partition[] = {
118
119
120
121
122
123
124
125
126
127
128
129
130
131
	/* Bootloader layout depends on whose u-boot is installed, but we
	 * can hide all the details.
	 *  - block 0 for u-boot environment ... in mainline u-boot
	 *  - block 1 for UBL (plus up to four backup copies in blocks 2..5)
	 *  - blocks 6...? for u-boot
	 *  - blocks 16..23 for u-boot environment ... in TI's u-boot
	 */
	{
		.name		= "bootloader",
		.offset		= 0,
		.size		= SZ_256K + SZ_128K,
		.mask_flags	= MTD_WRITEABLE,	/* force read-only */
	},
	/* Kernel */
132
	{
133
134
135
136
137
138
139
140
141
		.name		= "kernel",
		.offset		= MTDPART_OFS_APPEND,
		.size		= SZ_4M,
		.mask_flags	= 0,
	},
	/* File system (older GIT kernels started this on the 5MB mark) */
	{
		.name		= "filesystem",
		.offset		= MTDPART_OFS_APPEND,
142
143
144
		.size		= MTDPART_SIZ_FULL,
		.mask_flags	= 0,
	}
145
146
147
148
	/* A few blocks at end hold a flash BBT ... created by TI's CCS
	 * using flashwriter_nand.out, but ignored by TI's versions of
	 * Linux and u-boot.  We boot faster by using them.
	 */
149
};
150

151
152
153
154
155
156
157
158
159
160
static struct davinci_aemif_timing davinci_evm_nandflash_timing = {
	.wsetup		= 20,
	.wstrobe	= 40,
	.whold		= 20,
	.rsetup		= 10,
	.rstrobe	= 40,
	.rhold		= 10,
	.ta		= 40,
};

161
static struct davinci_nand_pdata davinci_evm_nandflash_data = {
162
	.core_chipsel	= 0,
163
164
165
	.parts		= davinci_evm_nandflash_partition,
	.nr_parts	= ARRAY_SIZE(davinci_evm_nandflash_partition),
	.ecc_mode	= NAND_ECC_HW,
166
	.ecc_bits	= 1,
167
	.bbt_options	= NAND_BBT_USE_FLASH,
168
	.timing		= &davinci_evm_nandflash_timing,
169
170
171
172
};

static struct resource davinci_evm_nandflash_resource[] = {
	{
173
174
		.start		= DM644X_ASYNC_EMIF_DATA_CE0_BASE,
		.end		= DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
175
176
		.flags		= IORESOURCE_MEM,
	}, {
177
178
		.start		= DM644X_ASYNC_EMIF_CONTROL_BASE,
		.end		= DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
179
180
181
182
		.flags		= IORESOURCE_MEM,
	},
};

183
184
185
186
187
static struct resource davinci_evm_aemif_resource[] = {
	{
		.start		= DM644X_ASYNC_EMIF_CONTROL_BASE,
		.end		= DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
		.flags		= IORESOURCE_MEM,
188
	},
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
};

static struct aemif_abus_data davinci_evm_aemif_abus_data[] = {
	{
		.cs		= 1,
	},
};

static struct platform_device davinci_evm_nandflash_devices[] = {
	{
		.name		= "davinci_nand",
		.id		= 0,
		.dev		= {
			.platform_data	= &davinci_evm_nandflash_data,
		},
		.num_resources	= ARRAY_SIZE(davinci_evm_nandflash_resource),
		.resource	= davinci_evm_nandflash_resource,
	},
};

static struct aemif_platform_data davinci_evm_aemif_pdata = {
	.abus_data = davinci_evm_aemif_abus_data,
	.num_abus_data = ARRAY_SIZE(davinci_evm_aemif_abus_data),
	.sub_devices = davinci_evm_nandflash_devices,
	.num_sub_devices = ARRAY_SIZE(davinci_evm_nandflash_devices),
};

static struct platform_device davinci_evm_aemif_device = {
	.name			= "ti-aemif",
	.id			= -1,
	.dev = {
		.platform_data	= &davinci_evm_aemif_pdata,
	},
	.resource		= davinci_evm_aemif_resource,
	.num_resources		= ARRAY_SIZE(davinci_evm_aemif_resource),
224
225
};

226
static u64 davinci_fb_dma_mask = DMA_BIT_MASK(32);
227
228
229
230
231
232

static struct platform_device davinci_fb_device = {
	.name		= "davincifb",
	.id		= -1,
	.dev = {
		.dma_mask		= &davinci_fb_dma_mask,
233
		.coherent_dma_mask      = DMA_BIT_MASK(32),
234
235
236
237
	},
	.num_resources = 0,
};

238
static struct tvp514x_platform_data dm644xevm_tvp5146_pdata = {
239
240
241
242
243
244
245
	.clk_polarity = 0,
	.hs_polarity = 1,
	.vs_polarity = 1
};

#define TVP514X_STD_ALL	(V4L2_STD_NTSC | V4L2_STD_PAL)
/* Inputs available at the TVP5146 */
246
static struct v4l2_input dm644xevm_tvp5146_inputs[] = {
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
	{
		.index = 0,
		.name = "Composite",
		.type = V4L2_INPUT_TYPE_CAMERA,
		.std = TVP514X_STD_ALL,
	},
	{
		.index = 1,
		.name = "S-Video",
		.type = V4L2_INPUT_TYPE_CAMERA,
		.std = TVP514X_STD_ALL,
	},
};

/*
 * this is the route info for connecting each input to decoder
 * ouput that goes to vpfe. There is a one to one correspondence
 * with tvp5146_inputs
 */
266
static struct vpfe_route dm644xevm_tvp5146_routes[] = {
267
268
269
270
271
272
273
274
275
276
	{
		.input = INPUT_CVBS_VI2B,
		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
	},
	{
		.input = INPUT_SVIDEO_VI2C_VI1C,
		.output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
	},
};

277
static struct vpfe_subdev_info dm644xevm_vpfe_sub_devs[] = {
278
279
280
	{
		.name = "tvp5146",
		.grp_id = 0,
281
282
283
		.num_inputs = ARRAY_SIZE(dm644xevm_tvp5146_inputs),
		.inputs = dm644xevm_tvp5146_inputs,
		.routes = dm644xevm_tvp5146_routes,
284
285
286
287
288
289
290
291
		.can_route = 1,
		.ccdc_if_params = {
			.if_type = VPFE_BT656,
			.hdpol = VPFE_PINPOL_POSITIVE,
			.vdpol = VPFE_PINPOL_POSITIVE,
		},
		.board_info = {
			I2C_BOARD_INFO("tvp5146", 0x5d),
292
			.platform_data = &dm644xevm_tvp5146_pdata,
293
294
295
296
		},
	},
};

297
298
static struct vpfe_config dm644xevm_capture_cfg = {
	.num_subdevs = ARRAY_SIZE(dm644xevm_vpfe_sub_devs),
299
	.i2c_adapter_id = 1,
300
	.sub_devs = dm644xevm_vpfe_sub_devs,
301
302
303
304
	.card_name = "DM6446 EVM",
	.ccdc = "DM6446 CCDC",
};

305
306
307
308
static struct platform_device rtc_dev = {
	.name           = "rtc_davinci_evm",
	.id             = -1,
};
309
310

/*----------------------------------------------------------------------*/
311
#ifdef CONFIG_I2C
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
 * I2C GPIO expanders
 */

#define PCF_Uxx_BASE(x)	(DAVINCI_N_GPIO + ((x) * 8))


/* U2 -- LEDs */

static struct gpio_led evm_leds[] = {
	{ .name = "DS8", .active_low = 1,
		.default_trigger = "heartbeat", },
	{ .name = "DS7", .active_low = 1, },
	{ .name = "DS6", .active_low = 1, },
	{ .name = "DS5", .active_low = 1, },
	{ .name = "DS4", .active_low = 1, },
	{ .name = "DS3", .active_low = 1, },
	{ .name = "DS2", .active_low = 1,
		.default_trigger = "mmc0", },
	{ .name = "DS1", .active_low = 1,
332
		.default_trigger = "disk-activity", },
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
};

static const struct gpio_led_platform_data evm_led_data = {
	.num_leds	= ARRAY_SIZE(evm_leds),
	.leds		= evm_leds,
};

static struct platform_device *evm_led_dev;

static int
evm_led_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	struct gpio_led *leds = evm_leds;
	int status;

	while (ngpio--) {
		leds->gpio = gpio++;
		leds++;
	}

	/* what an extremely annoying way to be forced to handle
	 * device unregistration ...
	 */
	evm_led_dev = platform_device_alloc("leds-gpio", 0);
	platform_device_add_data(evm_led_dev,
			&evm_led_data, sizeof evm_led_data);

	evm_led_dev->dev.parent = &client->dev;
	status = platform_device_add(evm_led_dev);
	if (status < 0) {
		platform_device_put(evm_led_dev);
		evm_led_dev = NULL;
	}
	return status;
}

static int
evm_led_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	if (evm_led_dev) {
		platform_device_unregister(evm_led_dev);
		evm_led_dev = NULL;
	}
	return 0;
}

static struct pcf857x_platform_data pcf_data_u2 = {
	.gpio_base	= PCF_Uxx_BASE(0),
	.setup		= evm_led_setup,
	.teardown	= evm_led_teardown,
};


/* U18 - A/V clock generator and user switch */

static int sw_gpio;

static ssize_t
sw_show(struct device *d, struct device_attribute *a, char *buf)
{
	char *s = gpio_get_value_cansleep(sw_gpio) ? "on\n" : "off\n";

	strcpy(buf, s);
	return strlen(s);
}

static DEVICE_ATTR(user_sw, S_IRUGO, sw_show, NULL);

static int
evm_u18_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	int	status;

	/* export dip switch option */
	sw_gpio = gpio + 7;
	status = gpio_request(sw_gpio, "user_sw");
	if (status == 0)
		status = gpio_direction_input(sw_gpio);
	if (status == 0)
		status = device_create_file(&client->dev, &dev_attr_user_sw);
	else
		gpio_free(sw_gpio);
	if (status != 0)
		sw_gpio = -EINVAL;

	/* audio PLL:  48 kHz (vs 44.1 or 32), single rate (vs double) */
	gpio_request(gpio + 3, "pll_fs2");
	gpio_direction_output(gpio + 3, 0);

	gpio_request(gpio + 2, "pll_fs1");
	gpio_direction_output(gpio + 2, 0);

	gpio_request(gpio + 1, "pll_sr");
	gpio_direction_output(gpio + 1, 0);

	return 0;
}

static int
evm_u18_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	gpio_free(gpio + 1);
	gpio_free(gpio + 2);
	gpio_free(gpio + 3);

	if (sw_gpio > 0) {
		device_remove_file(&client->dev, &dev_attr_user_sw);
		gpio_free(sw_gpio);
	}
	return 0;
}

static struct pcf857x_platform_data pcf_data_u18 = {
	.gpio_base	= PCF_Uxx_BASE(1),
	.n_latch	= (1 << 3) | (1 << 2) | (1 << 1),
	.setup		= evm_u18_setup,
	.teardown	= evm_u18_teardown,
450
451
};

452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

/* U35 - various I/O signals used to manage USB, CF, ATA, etc */

static int
evm_u35_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	/* p0 = nDRV_VBUS (initial:  don't supply it) */
	gpio_request(gpio + 0, "nDRV_VBUS");
	gpio_direction_output(gpio + 0, 1);

	/* p1 = VDDIMX_EN */
	gpio_request(gpio + 1, "VDDIMX_EN");
	gpio_direction_output(gpio + 1, 1);

	/* p2 = VLYNQ_EN */
	gpio_request(gpio + 2, "VLYNQ_EN");
	gpio_direction_output(gpio + 2, 1);

	/* p3 = n3V3_CF_RESET (initial: stay in reset) */
	gpio_request(gpio + 3, "nCF_RESET");
	gpio_direction_output(gpio + 3, 0);

	/* (p4 unused) */

	/* p5 = 1V8_WLAN_RESET (initial: stay in reset) */
	gpio_request(gpio + 5, "WLAN_RESET");
	gpio_direction_output(gpio + 5, 1);

	/* p6 = nATA_SEL (initial: select) */
	gpio_request(gpio + 6, "nATA_SEL");
	gpio_direction_output(gpio + 6, 0);

	/* p7 = nCF_SEL (initial: deselect) */
	gpio_request(gpio + 7, "nCF_SEL");
	gpio_direction_output(gpio + 7, 1);

	return 0;
}

static int
evm_u35_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
{
	gpio_free(gpio + 7);
	gpio_free(gpio + 6);
	gpio_free(gpio + 5);
	gpio_free(gpio + 3);
	gpio_free(gpio + 2);
	gpio_free(gpio + 1);
	gpio_free(gpio + 0);
	return 0;
}

static struct pcf857x_platform_data pcf_data_u35 = {
	.gpio_base	= PCF_Uxx_BASE(2),
	.setup		= evm_u35_setup,
	.teardown	= evm_u35_teardown,
};

/*----------------------------------------------------------------------*/

/* Most of this EEPROM is unused, but U-Boot uses some data:
 *  - 0x7f00, 6 bytes Ethernet Address
 *  - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
 *  - ... newer boards may have more
 */
517

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
static struct nvmem_cell_info dm644evm_nvmem_cells[] = {
	{
		.name		= "macaddr",
		.offset		= 0x7f00,
		.bytes		= ETH_ALEN,
	}
};

static struct nvmem_cell_table dm644evm_nvmem_cell_table = {
	.nvmem_name	= "1-00500",
	.cells		= dm644evm_nvmem_cells,
	.ncells		= ARRAY_SIZE(dm644evm_nvmem_cells),
};

static struct nvmem_cell_lookup dm644evm_nvmem_cell_lookup = {
	.nvmem_name	= "1-00500",
	.cell_name	= "macaddr",
	.dev_id		= "davinci_emac.1",
	.con_id		= "mac-address",
};

539
540
541
static const struct property_entry eeprom_properties[] = {
	PROPERTY_ENTRY_U32("pagesize", 64),
	{ }
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
};

/*
 * MSP430 supports RTC, card detection, input from IR remote, and
 * a bit more.  It triggers interrupts on GPIO(7) from pressing
 * buttons on the IR remote, and for card detect switches.
 */
static struct i2c_client *dm6446evm_msp;

static int dm6446evm_msp_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	dm6446evm_msp = client;
	return 0;
}

static int dm6446evm_msp_remove(struct i2c_client *client)
{
	dm6446evm_msp = NULL;
	return 0;
}

static const struct i2c_device_id dm6446evm_msp_ids[] = {
	{ "dm6446evm_msp", 0, },
	{ /* end of list */ },
};

static struct i2c_driver dm6446evm_msp_driver = {
	.driver.name	= "dm6446evm_msp",
	.id_table	= dm6446evm_msp_ids,
	.probe		= dm6446evm_msp_probe,
	.remove		= dm6446evm_msp_remove,
574
575
};

576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
static int dm6444evm_msp430_get_pins(void)
{
	static const char txbuf[2] = { 2, 4, };
	char buf[4];
	struct i2c_msg msg[2] = {
		{
			.flags = 0,
			.len = 2,
			.buf = (void __force *)txbuf,
		},
		{
			.flags = I2C_M_RD,
			.len = 4,
			.buf = buf,
		},
	};
	int status;

	if (!dm6446evm_msp)
		return -ENXIO;

597
598
599
	msg[0].addr = dm6446evm_msp->addr;
	msg[1].addr = dm6446evm_msp->addr;

600
601
602
603
604
605
606
607
	/* Command 4 == get input state, returns port 2 and port3 data
	 *   S Addr W [A] len=2 [A] cmd=4 [A]
	 *   RS Addr R [A] [len=4] A [cmd=4] A [port2] A [port3] N P
	 */
	status = i2c_transfer(dm6446evm_msp->adapter, msg, 2);
	if (status < 0)
		return status;

608
	dev_dbg(&dm6446evm_msp->dev, "PINS: %4ph\n", buf);
609
610
611
612

	return (buf[3] << 8) | buf[2];
}

Kevin Hilman's avatar
Kevin Hilman committed
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
static int dm6444evm_mmc_get_cd(int module)
{
	int status = dm6444evm_msp430_get_pins();

	return (status < 0) ? status : !(status & BIT(1));
}

static int dm6444evm_mmc_get_ro(int module)
{
	int status = dm6444evm_msp430_get_pins();

	return (status < 0) ? status : status & BIT(6 + 8);
}

static struct davinci_mmc_config dm6446evm_mmc_config = {
	.get_cd		= dm6444evm_mmc_get_cd,
	.get_ro		= dm6444evm_mmc_get_ro,
	.wires		= 4,
};

633
static struct i2c_board_info __initdata i2c_info[] =  {
634
635
636
	{
		I2C_BOARD_INFO("dm6446evm_msp", 0x23),
	},
637
638
639
640
641
642
643
644
645
646
647
648
649
650
	{
		I2C_BOARD_INFO("pcf8574", 0x38),
		.platform_data	= &pcf_data_u2,
	},
	{
		I2C_BOARD_INFO("pcf8574", 0x39),
		.platform_data	= &pcf_data_u18,
	},
	{
		I2C_BOARD_INFO("pcf8574", 0x3a),
		.platform_data	= &pcf_data_u35,
	},
	{
		I2C_BOARD_INFO("24c256", 0x50),
651
		.properties = eeprom_properties,
652
	},
653
654
655
	{
		I2C_BOARD_INFO("tlv320aic33", 0x1b),
	},
656
657
};

658
659
660
661
662
663
664
665
666
667
668
669
670
/* Fixed regulator support */
static struct regulator_consumer_supply fixed_supplies_3_3v[] = {
	/* Baseboard 3.3V: 5V -> TPS54310PWP -> 3.3V */
	REGULATOR_SUPPLY("AVDD", "1-001b"),
	REGULATOR_SUPPLY("DRVDD", "1-001b"),
};

static struct regulator_consumer_supply fixed_supplies_1_8v[] = {
	/* Baseboard 1.8V: 5V -> TPS54310PWP -> 1.8V */
	REGULATOR_SUPPLY("IOVDD", "1-001b"),
	REGULATOR_SUPPLY("DVDD", "1-001b"),
};

671
672
673
#define DM644X_I2C_SDA_PIN	GPIO_TO_PIN(2, 12)
#define DM644X_I2C_SCL_PIN	GPIO_TO_PIN(2, 11)

674
static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
675
	.dev_id = "i2c_davinci.1",
676
	.table = {
677
		GPIO_LOOKUP("davinci_gpio", DM644X_I2C_SDA_PIN, "sda",
678
			    GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
679
		GPIO_LOOKUP("davinci_gpio", DM644X_I2C_SCL_PIN, "scl",
680
			    GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
681
		{ }
682
683
684
	},
};

685
686
687
688
689
690
/* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz),
 * which requires 100 usec of idle bus after i2c writes sent to it.
 */
static struct davinci_i2c_platform_data i2c_pdata = {
	.bus_freq	= 20 /* kHz */,
	.bus_delay	= 100 /* usec */,
691
	.gpio_recovery	= true,
692
693
694
695
};

static void __init evm_init_i2c(void)
{
696
	gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
697
	davinci_init_i2c(&i2c_pdata);
698
	i2c_add_driver(&dm6446evm_msp_driver);
699
700
	i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
}
701
#endif
702

703
704
705
706
707
708
709
#define VENC_STD_ALL	(V4L2_STD_NTSC | V4L2_STD_PAL)

/* venc standard timings */
static struct vpbe_enc_mode_info dm644xevm_enc_std_timing[] = {
	{
		.name		= "ntsc",
		.timings_type	= VPBE_ENC_STD,
710
		.std_id		= V4L2_STD_NTSC,
711
712
713
714
715
716
717
718
719
720
721
		.interlaced	= 1,
		.xres		= 720,
		.yres		= 480,
		.aspect		= {11, 10},
		.fps		= {30000, 1001},
		.left_margin	= 0x79,
		.upper_margin	= 0x10,
	},
	{
		.name		= "pal",
		.timings_type	= VPBE_ENC_STD,
722
		.std_id		= V4L2_STD_PAL,
723
724
725
726
727
728
729
730
731
732
733
734
735
736
		.interlaced	= 1,
		.xres		= 720,
		.yres		= 576,
		.aspect		= {54, 59},
		.fps		= {25, 1},
		.left_margin	= 0x7e,
		.upper_margin	= 0x16,
	},
};

/* venc dv preset timings */
static struct vpbe_enc_mode_info dm644xevm_enc_preset_timing[] = {
	{
		.name		= "480p59_94",
737
		.timings_type	= VPBE_ENC_DV_TIMINGS,
738
		.dv_timings	= V4L2_DV_BT_CEA_720X480P59_94,
739
740
741
742
743
744
745
746
747
748
		.interlaced	= 0,
		.xres		= 720,
		.yres		= 480,
		.aspect		= {1, 1},
		.fps		= {5994, 100},
		.left_margin	= 0x80,
		.upper_margin	= 0x20,
	},
	{
		.name		= "576p50",
749
		.timings_type	= VPBE_ENC_DV_TIMINGS,
750
		.dv_timings	= V4L2_DV_BT_CEA_720X576P50,
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
		.interlaced	= 0,
		.xres		= 720,
		.yres		= 576,
		.aspect		= {1, 1},
		.fps		= {50, 1},
		.left_margin	= 0x7e,
		.upper_margin	= 0x30,
	},
};

/*
 * The outputs available from VPBE + encoders. Keep the order same
 * as that of encoders. First those from venc followed by that from
 * encoders. Index in the output refers to index on a particular encoder.
 * Driver uses this index to pass it to encoder when it supports more
 * than one output. Userspace applications use index of the array to
 * set an output.
 */
static struct vpbe_output dm644xevm_vpbe_outputs[] = {
	{
		.output		= {
			.index		= 0,
			.name		= "Composite",
			.type		= V4L2_OUTPUT_TYPE_ANALOG,
			.std		= VENC_STD_ALL,
			.capabilities	= V4L2_OUT_CAP_STD,
		},
778
		.subdev_name	= DM644X_VPBE_VENC_SUBDEV_NAME,
779
780
781
782
783
784
785
786
787
		.default_mode	= "ntsc",
		.num_modes	= ARRAY_SIZE(dm644xevm_enc_std_timing),
		.modes		= dm644xevm_enc_std_timing,
	},
	{
		.output		= {
			.index		= 1,
			.name		= "Component",
			.type		= V4L2_OUTPUT_TYPE_ANALOG,
788
			.capabilities	= V4L2_OUT_CAP_DV_TIMINGS,
789
		},
790
		.subdev_name	= DM644X_VPBE_VENC_SUBDEV_NAME,
791
792
793
794
795
796
797
798
799
800
		.default_mode	= "480p59_94",
		.num_modes	= ARRAY_SIZE(dm644xevm_enc_preset_timing),
		.modes		= dm644xevm_enc_preset_timing,
	},
};

static struct vpbe_config dm644xevm_display_cfg = {
	.module_name	= "dm644x-vpbe-display",
	.i2c_adapter_id	= 1,
	.osd		= {
801
		.module_name	= DM644X_VPBE_OSD_SUBDEV_NAME,
802
803
	},
	.venc		= {
804
		.module_name	= DM644X_VPBE_VENC_SUBDEV_NAME,
805
806
807
808
809
	},
	.num_outputs	= ARRAY_SIZE(dm644xevm_vpbe_outputs),
	.outputs	= dm644xevm_vpbe_outputs,
};

810
static struct platform_device *davinci_evm_devices[] __initdata = {
811
812
813
814
	&davinci_fb_device,
	&rtc_dev,
};

815
816
817
static void __init
davinci_evm_map_io(void)
{
818
	dm644x_init();
819
820
}

821
static int davinci_phy_fixup(struct phy_device *phydev)
822
{
823
824
825
826
827
828
829
830
831
832
833
	unsigned int control;
	/* CRITICAL: Fix for increasing PHY signal drive strength for
	 * TX lockup issue. On DaVinci EVM, the Intel LXT971 PHY
	 * signal strength was low causing  TX to fail randomly. The
	 * fix is to Set bit 11 (Increased MII drive strength) of PHY
	 * register 26 (Digital Config register) on this phy. */
	control = phy_read(phydev, 26);
	phy_write(phydev, 26, (control | 0x800));
	return 0;
}

834
835
#define HAS_ATA		(IS_ENABLED(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
			 IS_ENABLED(CONFIG_PATA_BK3710))
836
837
838
839

#define HAS_NOR		IS_ENABLED(CONFIG_MTD_PHYSMAP)

#define HAS_NAND	IS_ENABLED(CONFIG_MTD_NAND_DAVINCI)
840

841
842
static __init void davinci_evm_init(void)
{
843
	int ret;
844
	struct clk *aemif_clk;
845
	struct davinci_soc_info *soc_info = &davinci_soc_info;
846

847
848
	dm644x_register_clocks();

849
850
851
852
853
	regulator_register_always_on(0, "fixed-dummy", fixed_supplies_1_8v,
				     ARRAY_SIZE(fixed_supplies_1_8v), 1800000);
	regulator_register_always_on(1, "fixed-dummy", fixed_supplies_3_3v,
				     ARRAY_SIZE(fixed_supplies_3_3v), 3300000);

854
855
	dm644x_init_devices();

856
857
858
859
	ret = dm644x_gpio_register();
	if (ret)
		pr_warn("%s: GPIO init failed: %d\n", __func__, ret);

860
	aemif_clk = clk_get(NULL, "aemif");
861
	clk_prepare_enable(aemif_clk);
862
863
864

	if (HAS_ATA) {
		if (HAS_NAND || HAS_NOR)
865
866
			pr_warn("WARNING: both IDE and Flash are enabled, but they share AEMIF pins\n"
				"\tDisable IDE for NAND/NOR support\n");
867
		davinci_init_ide();
868
869
870
871
872
873
	} else if (HAS_NAND || HAS_NOR) {
		davinci_cfg_reg(DM644X_HPIEN_DISABLE);
		davinci_cfg_reg(DM644X_ATAEN_DISABLE);

		/* only one device will be jumpered and detected */
		if (HAS_NAND) {
874
			platform_device_register(&davinci_evm_aemif_device);
875
#ifdef CONFIG_I2C
876
			evm_leds[7].default_trigger = "nand-disk";
877
#endif
878
			if (HAS_NOR)
879
				pr_warn("WARNING: both NAND and NOR flash are enabled; disable one of them.\n");
880
881
882
883
		} else if (HAS_NOR)
			platform_device_register(&davinci_evm_norflash_device);
	}

884
885
	platform_add_devices(davinci_evm_devices,
			     ARRAY_SIZE(davinci_evm_devices));
886
#ifdef CONFIG_I2C
887
888
	nvmem_add_cell_table(&dm644evm_nvmem_cell_table);
	nvmem_add_cell_lookups(&dm644evm_nvmem_cell_lookup, 1);
889
	evm_init_i2c();
Kevin Hilman's avatar
Kevin Hilman committed
890
	davinci_setup_mmc(0, &dm6446evm_mmc_config);
891
#endif
892
	dm644x_init_video(&dm644xevm_capture_cfg, &dm644xevm_display_cfg);
Kevin Hilman's avatar
Kevin Hilman committed
893

894
	davinci_serial_init(dm644x_serial_device);
895
	dm644x_init_asp();
896

897
898
899
	/* irlml6401 switches over 1A, in under 8 msec */
	davinci_setup_usb(1000, 8);

900
901
902
903
904
905
	if (IS_BUILTIN(CONFIG_PHYLIB)) {
		soc_info->emac_pdata->phy_id = DM644X_EVM_PHY_ID;
		/* Register the fixup for PHY on DaVinci */
		phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK,
						davinci_phy_fixup);
	}
906
907
}

908
MACHINE_START(DAVINCI_EVM, "DaVinci DM644x EVM")
909
	/* Maintainer: MontaVista Software <source@mvista.com> */
910
	.atag_offset  = 0x100,
911
	.map_io	      = davinci_evm_map_io,
912
	.init_irq     = dm644x_init_irq,
913
	.init_time	= dm644x_init_time,
914
	.init_machine = davinci_evm_init,
915
	.init_late	= davinci_init_late,
916
	.dma_zone_size	= SZ_128M,
917
MACHINE_END