blob: 48436f74fd7108bdc984a0c5af7c9be14e808369 [file] [log] [blame]
Kevin Hilman7c6337e2007-04-30 19:37:19 +01001/*
2 * TI DaVinci EVM board support
3 *
4 * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
5 *
6 * 2007 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11#include <linux/kernel.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010012#include <linux/init.h>
13#include <linux/dma-mapping.h>
14#include <linux/platform_device.h>
David Brownell7bff3c42008-09-07 23:43:02 -070015#include <linux/gpio.h>
Linus Walleije5353762017-12-20 13:17:49 +010016#include <linux/gpio/machine.h>
David Brownell7bff3c42008-09-07 23:43:02 -070017#include <linux/i2c.h>
Wolfram Sangb6480fa2017-05-21 23:57:26 +020018#include <linux/platform_data/pcf857x.h>
Vivien Didelot25f73ed2013-09-27 15:06:28 -040019#include <linux/platform_data/at24.h>
Sekhar Nori9411ac02018-04-18 15:02:46 +053020#include <linux/platform_data/gpio-davinci.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010021#include <linux/mtd/mtd.h>
Boris Brezillond4092d72017-08-04 17:29:10 +020022#include <linux/mtd/rawnand.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010023#include <linux/mtd/partitions.h>
24#include <linux/mtd/physmap.h>
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050025#include <linux/phy.h>
26#include <linux/clk.h>
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -040027#include <linux/videodev2.h>
Hans Verkuil36864082012-10-01 11:39:46 -030028#include <linux/v4l2-dv-timings.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040029#include <linux/export.h>
Ulf Hanssonf46f3352017-01-13 14:14:03 +010030#include <linux/leds.h>
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -040031
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020032#include <media/i2c/tvp514x.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010033
Kevin Hilman7c6337e2007-04-30 19:37:19 +010034#include <asm/mach-types.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010035#include <asm/mach/arch.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010036
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/common.h>
Arnd Bergmannec2a0832012-08-24 15:11:34 +020038#include <linux/platform_data/i2c-davinci.h>
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050039#include <mach/serial.h>
40#include <mach/mux.h>
Arnd Bergmannec2a0832012-08-24 15:11:34 +020041#include <linux/platform_data/mtd-davinci.h>
42#include <linux/platform_data/mmc-davinci.h>
43#include <linux/platform_data/usb-davinci.h>
44#include <linux/platform_data/mtd-davinci-aemif.h>
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050045
Manjunath Hadli39c6d2d2011-12-21 19:13:35 +053046#include "davinci.h"
47
Sekhar Norif6f97582012-01-21 02:48:17 +053048#define DM644X_EVM_PHY_ID "davinci_mdio-0:01"
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050049#define LXT971_PHY_ID (0x001378e2)
50#define LXT971_PHY_MASK (0xfffffff0)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010051
David Brownell7bff3c42008-09-07 23:43:02 -070052static struct mtd_partition davinci_evm_norflash_partitions[] = {
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050053 /* bootloader (UBL, U-Boot, etc) in first 5 sectors */
Kevin Hilman7c6337e2007-04-30 19:37:19 +010054 {
55 .name = "bootloader",
56 .offset = 0,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -050057 .size = 5 * SZ_64K,
Kevin Hilman7c6337e2007-04-30 19:37:19 +010058 .mask_flags = MTD_WRITEABLE, /* force read-only */
59 },
60 /* bootloader params in the next 1 sectors */
61 {
62 .name = "params",
63 .offset = MTDPART_OFS_APPEND,
64 .size = SZ_64K,
65 .mask_flags = 0,
66 },
67 /* kernel */
68 {
69 .name = "kernel",
70 .offset = MTDPART_OFS_APPEND,
71 .size = SZ_2M,
72 .mask_flags = 0
73 },
74 /* file system */
75 {
76 .name = "filesystem",
77 .offset = MTDPART_OFS_APPEND,
78 .size = MTDPART_SIZ_FULL,
79 .mask_flags = 0
80 }
81};
82
David Brownell7bff3c42008-09-07 23:43:02 -070083static struct physmap_flash_data davinci_evm_norflash_data = {
Kevin Hilman7c6337e2007-04-30 19:37:19 +010084 .width = 2,
David Brownell7bff3c42008-09-07 23:43:02 -070085 .parts = davinci_evm_norflash_partitions,
86 .nr_parts = ARRAY_SIZE(davinci_evm_norflash_partitions),
Kevin Hilman7c6337e2007-04-30 19:37:19 +010087};
88
89/* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
90 * limits addresses to 16M, so using addresses past 16M will wrap */
David Brownell7bff3c42008-09-07 23:43:02 -070091static struct resource davinci_evm_norflash_resource = {
Sergei Shtylyov70342172010-04-16 21:29:11 +040092 .start = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
93 .end = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
Kevin Hilman7c6337e2007-04-30 19:37:19 +010094 .flags = IORESOURCE_MEM,
95};
96
David Brownell7bff3c42008-09-07 23:43:02 -070097static struct platform_device davinci_evm_norflash_device = {
Kevin Hilman7c6337e2007-04-30 19:37:19 +010098 .name = "physmap-flash",
99 .id = 0,
100 .dev = {
David Brownell7bff3c42008-09-07 23:43:02 -0700101 .platform_data = &davinci_evm_norflash_data,
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100102 },
103 .num_resources = 1,
David Brownell7bff3c42008-09-07 23:43:02 -0700104 .resource = &davinci_evm_norflash_resource,
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100105};
106
David Brownell3e9c18e2009-04-15 14:19:21 -0500107/* DM644x EVM includes a 64 MByte small-page NAND flash (16K blocks).
108 * It may used instead of the (default) NOR chip to boot, using TI's
109 * tools to install the secondary boot loader (UBL) and U-Boot.
110 */
Kevin Hilman28552c22010-02-25 15:36:38 -0800111static struct mtd_partition davinci_evm_nandflash_partition[] = {
David Brownell3e9c18e2009-04-15 14:19:21 -0500112 /* Bootloader layout depends on whose u-boot is installed, but we
113 * can hide all the details.
114 * - block 0 for u-boot environment ... in mainline u-boot
115 * - block 1 for UBL (plus up to four backup copies in blocks 2..5)
116 * - blocks 6...? for u-boot
117 * - blocks 16..23 for u-boot environment ... in TI's u-boot
118 */
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500119 {
David Brownell3e9c18e2009-04-15 14:19:21 -0500120 .name = "bootloader",
121 .offset = 0,
122 .size = SZ_256K + SZ_128K,
123 .mask_flags = MTD_WRITEABLE, /* force read-only */
124 },
125 /* Kernel */
126 {
127 .name = "kernel",
128 .offset = MTDPART_OFS_APPEND,
129 .size = SZ_4M,
130 .mask_flags = 0,
131 },
132 /* File system (older GIT kernels started this on the 5MB mark) */
133 {
134 .name = "filesystem",
135 .offset = MTDPART_OFS_APPEND,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500136 .size = MTDPART_SIZ_FULL,
137 .mask_flags = 0,
138 }
David Brownell3e9c18e2009-04-15 14:19:21 -0500139 /* A few blocks at end hold a flash BBT ... created by TI's CCS
140 * using flashwriter_nand.out, but ignored by TI's versions of
141 * Linux and u-boot. We boot faster by using them.
142 */
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500143};
David Brownell7bff3c42008-09-07 23:43:02 -0700144
Sekhar Norife69c822010-08-09 15:46:37 +0530145static struct davinci_aemif_timing davinci_evm_nandflash_timing = {
146 .wsetup = 20,
147 .wstrobe = 40,
148 .whold = 20,
149 .rsetup = 10,
150 .rstrobe = 40,
151 .rhold = 10,
152 .ta = 40,
153};
154
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500155static struct davinci_nand_pdata davinci_evm_nandflash_data = {
Bartosz Golaszewski040c6a02018-04-30 10:24:48 +0200156 .core_chipsel = 0,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500157 .parts = davinci_evm_nandflash_partition,
158 .nr_parts = ARRAY_SIZE(davinci_evm_nandflash_partition),
159 .ecc_mode = NAND_ECC_HW,
Sekhar Noriacd36352013-08-16 14:43:48 +0530160 .ecc_bits = 1,
Brian Norrisbb9ebd4e2011-05-31 16:31:23 -0700161 .bbt_options = NAND_BBT_USE_FLASH,
Sekhar Norife69c822010-08-09 15:46:37 +0530162 .timing = &davinci_evm_nandflash_timing,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500163};
164
165static struct resource davinci_evm_nandflash_resource[] = {
166 {
Sergei Shtylyov70342172010-04-16 21:29:11 +0400167 .start = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
168 .end = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500169 .flags = IORESOURCE_MEM,
170 }, {
Sergei Shtylyov70342172010-04-16 21:29:11 +0400171 .start = DM644X_ASYNC_EMIF_CONTROL_BASE,
172 .end = DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500173 .flags = IORESOURCE_MEM,
174 },
175};
176
177static struct platform_device davinci_evm_nandflash_device = {
178 .name = "davinci_nand",
179 .id = 0,
180 .dev = {
181 .platform_data = &davinci_evm_nandflash_data,
182 },
183 .num_resources = ARRAY_SIZE(davinci_evm_nandflash_resource),
184 .resource = davinci_evm_nandflash_resource,
185};
186
David Brownell3e9c18e2009-04-15 14:19:21 -0500187static u64 davinci_fb_dma_mask = DMA_BIT_MASK(32);
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500188
189static struct platform_device davinci_fb_device = {
190 .name = "davincifb",
191 .id = -1,
192 .dev = {
193 .dma_mask = &davinci_fb_dma_mask,
David Brownell3e9c18e2009-04-15 14:19:21 -0500194 .coherent_dma_mask = DMA_BIT_MASK(32),
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500195 },
196 .num_resources = 0,
197};
198
Manjunath Hadli314d7382011-12-21 19:13:38 +0530199static struct tvp514x_platform_data dm644xevm_tvp5146_pdata = {
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400200 .clk_polarity = 0,
201 .hs_polarity = 1,
202 .vs_polarity = 1
203};
204
205#define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
206/* Inputs available at the TVP5146 */
Manjunath Hadli314d7382011-12-21 19:13:38 +0530207static struct v4l2_input dm644xevm_tvp5146_inputs[] = {
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400208 {
209 .index = 0,
210 .name = "Composite",
211 .type = V4L2_INPUT_TYPE_CAMERA,
212 .std = TVP514X_STD_ALL,
213 },
214 {
215 .index = 1,
216 .name = "S-Video",
217 .type = V4L2_INPUT_TYPE_CAMERA,
218 .std = TVP514X_STD_ALL,
219 },
220};
221
222/*
223 * this is the route info for connecting each input to decoder
224 * ouput that goes to vpfe. There is a one to one correspondence
225 * with tvp5146_inputs
226 */
Manjunath Hadli314d7382011-12-21 19:13:38 +0530227static struct vpfe_route dm644xevm_tvp5146_routes[] = {
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400228 {
229 .input = INPUT_CVBS_VI2B,
230 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
231 },
232 {
233 .input = INPUT_SVIDEO_VI2C_VI1C,
234 .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
235 },
236};
237
Manjunath Hadli314d7382011-12-21 19:13:38 +0530238static struct vpfe_subdev_info dm644xevm_vpfe_sub_devs[] = {
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400239 {
240 .name = "tvp5146",
241 .grp_id = 0,
Manjunath Hadli314d7382011-12-21 19:13:38 +0530242 .num_inputs = ARRAY_SIZE(dm644xevm_tvp5146_inputs),
243 .inputs = dm644xevm_tvp5146_inputs,
244 .routes = dm644xevm_tvp5146_routes,
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400245 .can_route = 1,
246 .ccdc_if_params = {
247 .if_type = VPFE_BT656,
248 .hdpol = VPFE_PINPOL_POSITIVE,
249 .vdpol = VPFE_PINPOL_POSITIVE,
250 },
251 .board_info = {
252 I2C_BOARD_INFO("tvp5146", 0x5d),
Manjunath Hadli314d7382011-12-21 19:13:38 +0530253 .platform_data = &dm644xevm_tvp5146_pdata,
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400254 },
255 },
256};
257
Manjunath Hadli314d7382011-12-21 19:13:38 +0530258static struct vpfe_config dm644xevm_capture_cfg = {
259 .num_subdevs = ARRAY_SIZE(dm644xevm_vpfe_sub_devs),
Vaibhav Hiremath077639f2009-10-13 15:08:54 +0000260 .i2c_adapter_id = 1,
Manjunath Hadli314d7382011-12-21 19:13:38 +0530261 .sub_devs = dm644xevm_vpfe_sub_devs,
Muralidharan Karicheriab8e8df2009-09-16 11:53:18 -0400262 .card_name = "DM6446 EVM",
263 .ccdc = "DM6446 CCDC",
264};
265
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500266static struct platform_device rtc_dev = {
267 .name = "rtc_davinci_evm",
268 .id = -1,
269};
David Brownell7bff3c42008-09-07 23:43:02 -0700270
David Brownell7bff3c42008-09-07 23:43:02 -0700271/*----------------------------------------------------------------------*/
Arnd Bergmann8e580412016-02-01 21:35:58 +0100272#ifdef CONFIG_I2C
David Brownell7bff3c42008-09-07 23:43:02 -0700273/*
274 * I2C GPIO expanders
275 */
276
277#define PCF_Uxx_BASE(x) (DAVINCI_N_GPIO + ((x) * 8))
278
279
280/* U2 -- LEDs */
281
282static struct gpio_led evm_leds[] = {
283 { .name = "DS8", .active_low = 1,
284 .default_trigger = "heartbeat", },
285 { .name = "DS7", .active_low = 1, },
286 { .name = "DS6", .active_low = 1, },
287 { .name = "DS5", .active_low = 1, },
288 { .name = "DS4", .active_low = 1, },
289 { .name = "DS3", .active_low = 1, },
290 { .name = "DS2", .active_low = 1,
291 .default_trigger = "mmc0", },
292 { .name = "DS1", .active_low = 1,
Stephan Linze5808222016-06-10 07:59:59 +0200293 .default_trigger = "disk-activity", },
David Brownell7bff3c42008-09-07 23:43:02 -0700294};
295
296static const struct gpio_led_platform_data evm_led_data = {
297 .num_leds = ARRAY_SIZE(evm_leds),
298 .leds = evm_leds,
299};
300
301static struct platform_device *evm_led_dev;
302
303static int
304evm_led_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
305{
306 struct gpio_led *leds = evm_leds;
307 int status;
308
309 while (ngpio--) {
310 leds->gpio = gpio++;
311 leds++;
312 }
313
314 /* what an extremely annoying way to be forced to handle
315 * device unregistration ...
316 */
317 evm_led_dev = platform_device_alloc("leds-gpio", 0);
318 platform_device_add_data(evm_led_dev,
319 &evm_led_data, sizeof evm_led_data);
320
321 evm_led_dev->dev.parent = &client->dev;
322 status = platform_device_add(evm_led_dev);
323 if (status < 0) {
324 platform_device_put(evm_led_dev);
325 evm_led_dev = NULL;
326 }
327 return status;
328}
329
330static int
331evm_led_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
332{
333 if (evm_led_dev) {
334 platform_device_unregister(evm_led_dev);
335 evm_led_dev = NULL;
336 }
337 return 0;
338}
339
340static struct pcf857x_platform_data pcf_data_u2 = {
341 .gpio_base = PCF_Uxx_BASE(0),
342 .setup = evm_led_setup,
343 .teardown = evm_led_teardown,
344};
345
346
347/* U18 - A/V clock generator and user switch */
348
349static int sw_gpio;
350
351static ssize_t
352sw_show(struct device *d, struct device_attribute *a, char *buf)
353{
354 char *s = gpio_get_value_cansleep(sw_gpio) ? "on\n" : "off\n";
355
356 strcpy(buf, s);
357 return strlen(s);
358}
359
360static DEVICE_ATTR(user_sw, S_IRUGO, sw_show, NULL);
361
362static int
363evm_u18_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
364{
365 int status;
366
367 /* export dip switch option */
368 sw_gpio = gpio + 7;
369 status = gpio_request(sw_gpio, "user_sw");
370 if (status == 0)
371 status = gpio_direction_input(sw_gpio);
372 if (status == 0)
373 status = device_create_file(&client->dev, &dev_attr_user_sw);
374 else
375 gpio_free(sw_gpio);
376 if (status != 0)
377 sw_gpio = -EINVAL;
378
379 /* audio PLL: 48 kHz (vs 44.1 or 32), single rate (vs double) */
380 gpio_request(gpio + 3, "pll_fs2");
381 gpio_direction_output(gpio + 3, 0);
382
383 gpio_request(gpio + 2, "pll_fs1");
384 gpio_direction_output(gpio + 2, 0);
385
386 gpio_request(gpio + 1, "pll_sr");
387 gpio_direction_output(gpio + 1, 0);
388
389 return 0;
390}
391
392static int
393evm_u18_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
394{
395 gpio_free(gpio + 1);
396 gpio_free(gpio + 2);
397 gpio_free(gpio + 3);
398
399 if (sw_gpio > 0) {
400 device_remove_file(&client->dev, &dev_attr_user_sw);
401 gpio_free(sw_gpio);
402 }
403 return 0;
404}
405
406static struct pcf857x_platform_data pcf_data_u18 = {
407 .gpio_base = PCF_Uxx_BASE(1),
408 .n_latch = (1 << 3) | (1 << 2) | (1 << 1),
409 .setup = evm_u18_setup,
410 .teardown = evm_u18_teardown,
411};
412
413
414/* U35 - various I/O signals used to manage USB, CF, ATA, etc */
415
416static int
417evm_u35_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
418{
419 /* p0 = nDRV_VBUS (initial: don't supply it) */
420 gpio_request(gpio + 0, "nDRV_VBUS");
421 gpio_direction_output(gpio + 0, 1);
422
423 /* p1 = VDDIMX_EN */
424 gpio_request(gpio + 1, "VDDIMX_EN");
425 gpio_direction_output(gpio + 1, 1);
426
427 /* p2 = VLYNQ_EN */
428 gpio_request(gpio + 2, "VLYNQ_EN");
429 gpio_direction_output(gpio + 2, 1);
430
431 /* p3 = n3V3_CF_RESET (initial: stay in reset) */
432 gpio_request(gpio + 3, "nCF_RESET");
433 gpio_direction_output(gpio + 3, 0);
434
435 /* (p4 unused) */
436
437 /* p5 = 1V8_WLAN_RESET (initial: stay in reset) */
438 gpio_request(gpio + 5, "WLAN_RESET");
439 gpio_direction_output(gpio + 5, 1);
440
441 /* p6 = nATA_SEL (initial: select) */
442 gpio_request(gpio + 6, "nATA_SEL");
443 gpio_direction_output(gpio + 6, 0);
444
445 /* p7 = nCF_SEL (initial: deselect) */
446 gpio_request(gpio + 7, "nCF_SEL");
447 gpio_direction_output(gpio + 7, 1);
448
449 return 0;
450}
451
452static int
453evm_u35_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
454{
455 gpio_free(gpio + 7);
456 gpio_free(gpio + 6);
457 gpio_free(gpio + 5);
458 gpio_free(gpio + 3);
459 gpio_free(gpio + 2);
460 gpio_free(gpio + 1);
461 gpio_free(gpio + 0);
462 return 0;
463}
464
465static struct pcf857x_platform_data pcf_data_u35 = {
466 .gpio_base = PCF_Uxx_BASE(2),
467 .setup = evm_u35_setup,
468 .teardown = evm_u35_teardown,
469};
470
471/*----------------------------------------------------------------------*/
472
473/* Most of this EEPROM is unused, but U-Boot uses some data:
474 * - 0x7f00, 6 bytes Ethernet Address
475 * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
476 * - ... newer boards may have more
477 */
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500478
David Brownell7bff3c42008-09-07 23:43:02 -0700479static struct at24_platform_data eeprom_info = {
480 .byte_len = (256*1024) / 8,
481 .page_size = 64,
482 .flags = AT24_FLAG_ADDR16,
Mark A. Greerb14dc0f2009-04-15 12:41:27 -0700483 .setup = davinci_get_mac_addr,
484 .context = (void *)0x7f00,
David Brownell7bff3c42008-09-07 23:43:02 -0700485};
486
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500487/*
488 * MSP430 supports RTC, card detection, input from IR remote, and
489 * a bit more. It triggers interrupts on GPIO(7) from pressing
490 * buttons on the IR remote, and for card detect switches.
491 */
492static struct i2c_client *dm6446evm_msp;
493
494static int dm6446evm_msp_probe(struct i2c_client *client,
495 const struct i2c_device_id *id)
496{
497 dm6446evm_msp = client;
498 return 0;
499}
500
501static int dm6446evm_msp_remove(struct i2c_client *client)
502{
503 dm6446evm_msp = NULL;
504 return 0;
505}
506
507static const struct i2c_device_id dm6446evm_msp_ids[] = {
508 { "dm6446evm_msp", 0, },
509 { /* end of list */ },
510};
511
512static struct i2c_driver dm6446evm_msp_driver = {
513 .driver.name = "dm6446evm_msp",
514 .id_table = dm6446evm_msp_ids,
515 .probe = dm6446evm_msp_probe,
516 .remove = dm6446evm_msp_remove,
517};
518
519static int dm6444evm_msp430_get_pins(void)
520{
521 static const char txbuf[2] = { 2, 4, };
522 char buf[4];
523 struct i2c_msg msg[2] = {
524 {
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500525 .flags = 0,
526 .len = 2,
527 .buf = (void __force *)txbuf,
528 },
529 {
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500530 .flags = I2C_M_RD,
531 .len = 4,
532 .buf = buf,
533 },
534 };
535 int status;
536
537 if (!dm6446evm_msp)
538 return -ENXIO;
539
Wei Yongjun9ad90232012-09-10 04:49:23 +0000540 msg[0].addr = dm6446evm_msp->addr;
541 msg[1].addr = dm6446evm_msp->addr;
542
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500543 /* Command 4 == get input state, returns port 2 and port3 data
544 * S Addr W [A] len=2 [A] cmd=4 [A]
545 * RS Addr R [A] [len=4] A [cmd=4] A [port2] A [port3] N P
546 */
547 status = i2c_transfer(dm6446evm_msp->adapter, msg, 2);
548 if (status < 0)
549 return status;
550
Andy Shevchenkod1a31e92015-10-01 16:13:05 +0300551 dev_dbg(&dm6446evm_msp->dev, "PINS: %4ph\n", buf);
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500552
553 return (buf[3] << 8) | buf[2];
554}
555
Kevin Hilman2dbf56ae2009-05-11 15:55:03 -0700556static int dm6444evm_mmc_get_cd(int module)
557{
558 int status = dm6444evm_msp430_get_pins();
559
560 return (status < 0) ? status : !(status & BIT(1));
561}
562
563static int dm6444evm_mmc_get_ro(int module)
564{
565 int status = dm6444evm_msp430_get_pins();
566
567 return (status < 0) ? status : status & BIT(6 + 8);
568}
569
570static struct davinci_mmc_config dm6446evm_mmc_config = {
571 .get_cd = dm6444evm_mmc_get_cd,
572 .get_ro = dm6444evm_mmc_get_ro,
573 .wires = 4,
Kevin Hilman2dbf56ae2009-05-11 15:55:03 -0700574};
575
David Brownell7bff3c42008-09-07 23:43:02 -0700576static struct i2c_board_info __initdata i2c_info[] = {
577 {
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500578 I2C_BOARD_INFO("dm6446evm_msp", 0x23),
579 },
580 {
David Brownell7bff3c42008-09-07 23:43:02 -0700581 I2C_BOARD_INFO("pcf8574", 0x38),
582 .platform_data = &pcf_data_u2,
583 },
584 {
585 I2C_BOARD_INFO("pcf8574", 0x39),
586 .platform_data = &pcf_data_u18,
587 },
588 {
589 I2C_BOARD_INFO("pcf8574", 0x3a),
590 .platform_data = &pcf_data_u35,
591 },
592 {
593 I2C_BOARD_INFO("24c256", 0x50),
594 .platform_data = &eeprom_info,
595 },
Chaithrika U S1a7ff8f2009-08-25 15:20:05 +0300596 {
597 I2C_BOARD_INFO("tlv320aic33", 0x1b),
598 },
David Brownell7bff3c42008-09-07 23:43:02 -0700599};
600
Sekhar Nori9411ac02018-04-18 15:02:46 +0530601#define DM644X_I2C_SDA_PIN GPIO_TO_PIN(2, 12)
602#define DM644X_I2C_SCL_PIN GPIO_TO_PIN(2, 11)
603
Linus Walleije5353762017-12-20 13:17:49 +0100604static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
Sekhar Nori9411ac02018-04-18 15:02:46 +0530605 .dev_id = "i2c_davinci.1",
Linus Walleije5353762017-12-20 13:17:49 +0100606 .table = {
Sekhar Nori9411ac02018-04-18 15:02:46 +0530607 GPIO_LOOKUP("davinci_gpio.0", DM644X_I2C_SDA_PIN, "sda",
Linus Walleije5353762017-12-20 13:17:49 +0100608 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
Sekhar Nori9411ac02018-04-18 15:02:46 +0530609 GPIO_LOOKUP("davinci_gpio.0", DM644X_I2C_SCL_PIN, "scl",
Linus Walleije5353762017-12-20 13:17:49 +0100610 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
611 },
612};
613
David Brownell7bff3c42008-09-07 23:43:02 -0700614/* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz),
615 * which requires 100 usec of idle bus after i2c writes sent to it.
616 */
617static struct davinci_i2c_platform_data i2c_pdata = {
618 .bus_freq = 20 /* kHz */,
619 .bus_delay = 100 /* usec */,
Linus Walleije5353762017-12-20 13:17:49 +0100620 .gpio_recovery = true,
David Brownell7bff3c42008-09-07 23:43:02 -0700621};
622
623static void __init evm_init_i2c(void)
624{
Linus Walleije5353762017-12-20 13:17:49 +0100625 gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
David Brownell7bff3c42008-09-07 23:43:02 -0700626 davinci_init_i2c(&i2c_pdata);
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500627 i2c_add_driver(&dm6446evm_msp_driver);
David Brownell7bff3c42008-09-07 23:43:02 -0700628 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
629}
Arnd Bergmann8e580412016-02-01 21:35:58 +0100630#endif
David Brownell7bff3c42008-09-07 23:43:02 -0700631
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530632#define VENC_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
633
634/* venc standard timings */
635static struct vpbe_enc_mode_info dm644xevm_enc_std_timing[] = {
636 {
637 .name = "ntsc",
638 .timings_type = VPBE_ENC_STD,
Lad, Prabhakar89cdbba2013-04-12 07:46:19 -0300639 .std_id = V4L2_STD_NTSC,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530640 .interlaced = 1,
641 .xres = 720,
642 .yres = 480,
643 .aspect = {11, 10},
644 .fps = {30000, 1001},
645 .left_margin = 0x79,
646 .upper_margin = 0x10,
647 },
648 {
649 .name = "pal",
650 .timings_type = VPBE_ENC_STD,
Lad, Prabhakar89cdbba2013-04-12 07:46:19 -0300651 .std_id = V4L2_STD_PAL,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530652 .interlaced = 1,
653 .xres = 720,
654 .yres = 576,
655 .aspect = {54, 59},
656 .fps = {25, 1},
657 .left_margin = 0x7e,
658 .upper_margin = 0x16,
659 },
660};
661
662/* venc dv preset timings */
663static struct vpbe_enc_mode_info dm644xevm_enc_preset_timing[] = {
664 {
665 .name = "480p59_94",
Hans Verkuilef2d41b2013-02-15 15:06:28 -0300666 .timings_type = VPBE_ENC_DV_TIMINGS,
Hans Verkuil36864082012-10-01 11:39:46 -0300667 .dv_timings = V4L2_DV_BT_CEA_720X480P59_94,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530668 .interlaced = 0,
669 .xres = 720,
670 .yres = 480,
671 .aspect = {1, 1},
672 .fps = {5994, 100},
673 .left_margin = 0x80,
674 .upper_margin = 0x20,
675 },
676 {
677 .name = "576p50",
Hans Verkuilef2d41b2013-02-15 15:06:28 -0300678 .timings_type = VPBE_ENC_DV_TIMINGS,
Hans Verkuil36864082012-10-01 11:39:46 -0300679 .dv_timings = V4L2_DV_BT_CEA_720X576P50,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530680 .interlaced = 0,
681 .xres = 720,
682 .yres = 576,
683 .aspect = {1, 1},
684 .fps = {50, 1},
685 .left_margin = 0x7e,
686 .upper_margin = 0x30,
687 },
688};
689
690/*
691 * The outputs available from VPBE + encoders. Keep the order same
692 * as that of encoders. First those from venc followed by that from
693 * encoders. Index in the output refers to index on a particular encoder.
694 * Driver uses this index to pass it to encoder when it supports more
695 * than one output. Userspace applications use index of the array to
696 * set an output.
697 */
698static struct vpbe_output dm644xevm_vpbe_outputs[] = {
699 {
700 .output = {
701 .index = 0,
702 .name = "Composite",
703 .type = V4L2_OUTPUT_TYPE_ANALOG,
704 .std = VENC_STD_ALL,
705 .capabilities = V4L2_OUT_CAP_STD,
706 },
Lad, Prabhakarcaff80c2012-11-20 07:30:36 -0300707 .subdev_name = DM644X_VPBE_VENC_SUBDEV_NAME,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530708 .default_mode = "ntsc",
709 .num_modes = ARRAY_SIZE(dm644xevm_enc_std_timing),
710 .modes = dm644xevm_enc_std_timing,
711 },
712 {
713 .output = {
714 .index = 1,
715 .name = "Component",
716 .type = V4L2_OUTPUT_TYPE_ANALOG,
Lad, Prabhakare32087b2012-10-03 02:25:42 -0300717 .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530718 },
Lad, Prabhakarcaff80c2012-11-20 07:30:36 -0300719 .subdev_name = DM644X_VPBE_VENC_SUBDEV_NAME,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530720 .default_mode = "480p59_94",
721 .num_modes = ARRAY_SIZE(dm644xevm_enc_preset_timing),
722 .modes = dm644xevm_enc_preset_timing,
723 },
724};
725
726static struct vpbe_config dm644xevm_display_cfg = {
727 .module_name = "dm644x-vpbe-display",
728 .i2c_adapter_id = 1,
729 .osd = {
Lad, Prabhakarcaff80c2012-11-20 07:30:36 -0300730 .module_name = DM644X_VPBE_OSD_SUBDEV_NAME,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530731 },
732 .venc = {
Lad, Prabhakarcaff80c2012-11-20 07:30:36 -0300733 .module_name = DM644X_VPBE_VENC_SUBDEV_NAME,
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530734 },
735 .num_outputs = ARRAY_SIZE(dm644xevm_vpbe_outputs),
736 .outputs = dm644xevm_vpbe_outputs,
737};
738
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100739static struct platform_device *davinci_evm_devices[] __initdata = {
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500740 &davinci_fb_device,
741 &rtc_dev,
742};
743
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100744static void __init
745davinci_evm_map_io(void)
746{
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500747 dm644x_init();
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100748}
749
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500750static int davinci_phy_fixup(struct phy_device *phydev)
751{
752 unsigned int control;
753 /* CRITICAL: Fix for increasing PHY signal drive strength for
754 * TX lockup issue. On DaVinci EVM, the Intel LXT971 PHY
755 * signal strength was low causing TX to fail randomly. The
756 * fix is to Set bit 11 (Increased MII drive strength) of PHY
757 * register 26 (Digital Config register) on this phy. */
758 control = phy_read(phydev, 26);
759 phy_write(phydev, 26, (control | 0x800));
760 return 0;
761}
762
Sekhar Nori28d4d1d2017-03-22 19:21:01 +0100763#define HAS_ATA (IS_ENABLED(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
764 IS_ENABLED(CONFIG_PATA_BK3710))
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500765
Lad, Prabhakara0a56db2013-04-01 12:43:44 +0530766#define HAS_NOR IS_ENABLED(CONFIG_MTD_PHYSMAP)
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500767
Lad, Prabhakara0a56db2013-04-01 12:43:44 +0530768#define HAS_NAND IS_ENABLED(CONFIG_MTD_NAND_DAVINCI)
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500769
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100770static __init void davinci_evm_init(void)
771{
Philip Avinash834acb22013-08-18 10:49:02 +0530772 int ret;
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500773 struct clk *aemif_clk;
Mark A. Greer972412b2009-04-15 12:40:56 -0700774 struct davinci_soc_info *soc_info = &davinci_soc_info;
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500775
Sekhar Nori8e730c72018-04-06 18:08:20 +0530776 dm644x_init_devices();
777
Philip Avinash834acb22013-08-18 10:49:02 +0530778 ret = dm644x_gpio_register();
779 if (ret)
780 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
781
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500782 aemif_clk = clk_get(NULL, "aemif");
m-karicheri2@ti.comb6f1ffe2012-08-02 16:53:48 +0000783 clk_prepare_enable(aemif_clk);
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500784
785 if (HAS_ATA) {
786 if (HAS_NAND || HAS_NOR)
Joe Perchesa7ca2bc2014-10-31 17:51:51 -0700787 pr_warn("WARNING: both IDE and Flash are enabled, but they share AEMIF pins\n"
788 "\tDisable IDE for NAND/NOR support\n");
Sergei Shtylyov7a9978a2010-04-21 18:11:33 +0400789 davinci_init_ide();
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500790 } else if (HAS_NAND || HAS_NOR) {
791 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
792 davinci_cfg_reg(DM644X_ATAEN_DISABLE);
793
794 /* only one device will be jumpered and detected */
795 if (HAS_NAND) {
796 platform_device_register(&davinci_evm_nandflash_device);
Ivan Khoronzhuk67f51852014-01-30 13:03:40 +0200797
798 if (davinci_aemif_setup(&davinci_evm_nandflash_device))
Joe Perchesa7ca2bc2014-10-31 17:51:51 -0700799 pr_warn("%s: Cannot configure AEMIF\n",
Ivan Khoronzhuk67f51852014-01-30 13:03:40 +0200800 __func__);
801
Arnd Bergmann8e580412016-02-01 21:35:58 +0100802#ifdef CONFIG_I2C
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500803 evm_leds[7].default_trigger = "nand-disk";
Arnd Bergmann8e580412016-02-01 21:35:58 +0100804#endif
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500805 if (HAS_NOR)
Joe Perchesa7ca2bc2014-10-31 17:51:51 -0700806 pr_warn("WARNING: both NAND and NOR flash are enabled; disable one of them.\n");
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500807 } else if (HAS_NOR)
808 platform_device_register(&davinci_evm_norflash_device);
809 }
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100810
811 platform_add_devices(davinci_evm_devices,
812 ARRAY_SIZE(davinci_evm_devices));
Arnd Bergmann8e580412016-02-01 21:35:58 +0100813#ifdef CONFIG_I2C
David Brownell7bff3c42008-09-07 23:43:02 -0700814 evm_init_i2c();
Kevin Hilman2dbf56ae2009-05-11 15:55:03 -0700815 davinci_setup_mmc(0, &dm6446evm_mmc_config);
Arnd Bergmann8e580412016-02-01 21:35:58 +0100816#endif
Manjunath Hadlid5be5f52012-02-23 15:17:46 +0530817 dm644x_init_video(&dm644xevm_capture_cfg, &dm644xevm_display_cfg);
Kevin Hilman2dbf56ae2009-05-11 15:55:03 -0700818
Manjunathappa, Prakashfcf71572013-06-19 14:45:42 +0530819 davinci_serial_init(dm644x_serial_device);
Petr Kulhavy6bce5ef2016-05-09 15:59:48 +0200820 dm644x_init_asp();
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500821
Sergei Shtylyov60d97a82011-03-13 20:06:59 +0000822 /* irlml6401 switches over 1A, in under 8 msec */
823 davinci_setup_usb(1000, 8);
824
Arnd Bergmann4bbef1d2014-03-13 17:50:35 +0100825 if (IS_BUILTIN(CONFIG_PHYLIB)) {
826 soc_info->emac_pdata->phy_id = DM644X_EVM_PHY_ID;
827 /* Register the fixup for PHY on DaVinci */
828 phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK,
829 davinci_phy_fixup);
830 }
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100831}
832
Kevin Hilmand0e47fb2009-04-14 11:30:11 -0500833MACHINE_START(DAVINCI_EVM, "DaVinci DM644x EVM")
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100834 /* Maintainer: MontaVista Software <source@mvista.com> */
Nicolas Pitree7e56012011-07-05 22:38:11 -0400835 .atag_offset = 0x100,
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100836 .map_io = davinci_evm_map_io,
Cyril Chemparathybd808942010-05-07 17:06:37 -0400837 .init_irq = davinci_irq_init,
David Lechner96c08172018-01-19 21:20:22 -0600838 .init_time = dm644x_init_time,
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100839 .init_machine = davinci_evm_init,
Shawn Guo3aa3e842012-04-26 09:45:39 +0800840 .init_late = davinci_init_late,
Nicolas Pitref68deab2011-07-05 22:28:08 -0400841 .dma_zone_size = SZ_128M,
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100842MACHINE_END