hiddenDangerAnalysis.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  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>
  12. #include <linux/init.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/gpio.h>
  16. #include <linux/i2c.h>
  17. #include <linux/i2c/pcf857x.h>
  18. #include <linux/i2c/at24.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/mtd/nand.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <linux/mtd/physmap.h>
  23. #include <linux/phy.h>
  24. #include <linux/clk.h>
  25. #include <linux/videodev2.h>
  26. #include <linux/v4l2-dv-timings.h>
  27. #include <linux/export.h>
  28. #include <media/tvp514x.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <mach/common.h>
  32. #include <linux/platform_data/i2c-davinci.h>
  33. #include <mach/serial.h>
  34. #include <mach/mux.h>
  35. #include <linux/platform_data/mtd-davinci.h>
  36. #include <linux/platform_data/mmc-davinci.h>
  37. #include <linux/platform_data/usb-davinci.h>
  38. #include <linux/platform_data/mtd-davinci-aemif.h>
  39. #include "davinci.h"
  40. #define DM644X_EVM_PHY_ID "davinci_mdio-0:01"
  41. #define LXT971_PHY_ID (0x001378e2)
  42. #define LXT971_PHY_MASK (0xfffffff0)
  43. static struct mtd_partition davinci_evm_norflash_partitions[] = {
  44. /* bootloader (UBL, U-Boot, etc) in first 5 sectors */
  45. {
  46. .name = "bootloader",
  47. .offset = 0,
  48. .size = 5 * SZ_64K,
  49. .mask_flags = MTD_WRITEABLE, /* force read-only */
  50. },
  51. /* bootloader params in the next 1 sectors */
  52. {
  53. .name = "params",
  54. .offset = MTDPART_OFS_APPEND,
  55. .size = SZ_64K,
  56. .mask_flags = 0,
  57. },
  58. /* kernel */
  59. {
  60. .name = "kernel",
  61. .offset = MTDPART_OFS_APPEND,
  62. .size = SZ_2M,
  63. .mask_flags = 0
  64. },
  65. /* file system */
  66. {
  67. .name = "filesystem",
  68. .offset = MTDPART_OFS_APPEND,
  69. .size = MTDPART_SIZ_FULL,
  70. .mask_flags = 0
  71. }
  72. };
  73. static struct physmap_flash_data davinci_evm_norflash_data = {
  74. .width = 2,
  75. .parts = davinci_evm_norflash_partitions,
  76. .nr_parts = ARRAY_SIZE(davinci_evm_norflash_partitions),
  77. };
  78. /* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
  79. * limits addresses to 16M, so using addresses past 16M will wrap */
  80. static struct resource davinci_evm_norflash_resource = {
  81. .start = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
  82. .end = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
  83. .flags = IORESOURCE_MEM,
  84. };
  85. static struct platform_device davinci_evm_norflash_device = {
  86. .name = "physmap-flash",
  87. .id = 0,
  88. .dev = {
  89. .platform_data = &davinci_evm_norflash_data,
  90. },
  91. .num_resources = 1,
  92. .resource = &davinci_evm_norflash_resource,
  93. };
  94. /* DM644x EVM includes a 64 MByte small-page NAND flash (16K blocks).
  95. * It may used instead of the (default) NOR chip to boot, using TI's
  96. * tools to install the secondary boot loader (UBL) and U-Boot.
  97. */
  98. static struct mtd_partition davinci_evm_nandflash_partition[] = {
  99. /* Bootloader layout depends on whose u-boot is installed, but we
  100. * can hide all the details.
  101. * - block 0 for u-boot environment ... in mainline u-boot
  102. * - block 1 for UBL (plus up to four backup copies in blocks 2..5)
  103. * - blocks 6...? for u-boot
  104. * - blocks 16..23 for u-boot environment ... in TI's u-boot
  105. */
  106. {
  107. .name = "bootloader",
  108. .offset = 0,
  109. .size = SZ_256K + SZ_128K,
  110. .mask_flags = MTD_WRITEABLE, /* force read-only */
  111. },
  112. /* Kernel */
  113. {
  114. .name = "kernel",
  115. .offset = MTDPART_OFS_APPEND,
  116. .size = SZ_4M,
  117. .mask_flags = 0,
  118. },
  119. /* File system (older GIT kernels started this on the 5MB mark) */
  120. {
  121. .name = "filesystem",
  122. .offset = MTDPART_OFS_APPEND,
  123. .size = MTDPART_SIZ_FULL,
  124. .mask_flags = 0,
  125. }
  126. /* A few blocks at end hold a flash BBT ... created by TI's CCS
  127. * using flashwriter_nand.out, but ignored by TI's versions of
  128. * Linux and u-boot. We boot faster by using them.
  129. */
  130. };
  131. static struct davinci_aemif_timing davinci_evm_nandflash_timing = {
  132. .wsetup = 20,
  133. .wstrobe = 40,
  134. .whold = 20,
  135. .rsetup = 10,
  136. .rstrobe = 40,
  137. .rhold = 10,
  138. .ta = 40,
  139. };
  140. static struct davinci_nand_pdata davinci_evm_nandflash_data = {
  141. .parts = davinci_evm_nandflash_partition,
  142. .nr_parts = ARRAY_SIZE(davinci_evm_nandflash_partition),
  143. .ecc_mode = NAND_ECC_HW,
  144. .bbt_options = NAND_BBT_USE_FLASH,
  145. .timing = &davinci_evm_nandflash_timing,
  146. };
  147. static struct resource davinci_evm_nandflash_resource[] = {
  148. {
  149. .start = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
  150. .end = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
  151. .flags = IORESOURCE_MEM,
  152. }, {
  153. .start = DM644X_ASYNC_EMIF_CONTROL_BASE,
  154. .end = DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  155. .flags = IORESOURCE_MEM,
  156. },
  157. };
  158. static struct platform_device davinci_evm_nandflash_device = {
  159. .name = "davinci_nand",
  160. .id = 0,
  161. .dev = {
  162. .platform_data = &davinci_evm_nandflash_data,
  163. },
  164. .num_resources = ARRAY_SIZE(davinci_evm_nandflash_resource),
  165. .resource = davinci_evm_nandflash_resource,
  166. };
  167. static u64 davinci_fb_dma_mask = DMA_BIT_MASK(32);
  168. static struct platform_device davinci_fb_device = {
  169. .name = "davincifb",
  170. .id = -1,
  171. .dev = {
  172. .dma_mask = &davinci_fb_dma_mask,
  173. .coherent_dma_mask = DMA_BIT_MASK(32),
  174. },
  175. .num_resources = 0,
  176. };
  177. static struct tvp514x_platform_data dm644xevm_tvp5146_pdata = {
  178. .clk_polarity = 0,
  179. .hs_polarity = 1,
  180. .vs_polarity = 1
  181. };
  182. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  183. /* Inputs available at the TVP5146 */
  184. static struct v4l2_input dm644xevm_tvp5146_inputs[] = {
  185. {
  186. .index = 0,
  187. .name = "Composite",
  188. .type = V4L2_INPUT_TYPE_CAMERA,
  189. .std = TVP514X_STD_ALL,
  190. },
  191. {
  192. .index = 1,
  193. .name = "S-Video",
  194. .type = V4L2_INPUT_TYPE_CAMERA,
  195. .std = TVP514X_STD_ALL,
  196. },
  197. };
  198. /*
  199. * this is the route info for connecting each input to decoder
  200. * ouput that goes to vpfe. There is a one to one correspondence
  201. * with tvp5146_inputs
  202. */
  203. static struct vpfe_route dm644xevm_tvp5146_routes[] = {
  204. {
  205. .input = INPUT_CVBS_VI2B,
  206. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  207. },
  208. {
  209. .input = INPUT_SVIDEO_VI2C_VI1C,
  210. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  211. },
  212. };
  213. static struct vpfe_subdev_info dm644xevm_vpfe_sub_devs[] = {
  214. {
  215. .name = "tvp5146",
  216. .grp_id = 0,
  217. .num_inputs = ARRAY_SIZE(dm644xevm_tvp5146_inputs),
  218. .inputs = dm644xevm_tvp5146_inputs,
  219. .routes = dm644xevm_tvp5146_routes,
  220. .can_route = 1,
  221. .ccdc_if_params = {
  222. .if_type = VPFE_BT656,
  223. .hdpol = VPFE_PINPOL_POSITIVE,
  224. .vdpol = VPFE_PINPOL_POSITIVE,
  225. },
  226. .board_info = {
  227. I2C_BOARD_INFO("tvp5146", 0x5d),
  228. .platform_data = &dm644xevm_tvp5146_pdata,
  229. },
  230. },
  231. };
  232. static struct vpfe_config dm644xevm_capture_cfg = {
  233. .num_subdevs = ARRAY_SIZE(dm644xevm_vpfe_sub_devs),
  234. .i2c_adapter_id = 1,
  235. .sub_devs = dm644xevm_vpfe_sub_devs,
  236. .card_name = "DM6446 EVM",
  237. .ccdc = "DM6446 CCDC",
  238. };
  239. static struct platform_device rtc_dev = {
  240. .name = "rtc_davinci_evm",
  241. .id = -1,
  242. };
  243. static struct snd_platform_data dm644x_evm_snd_data;
  244. /*----------------------------------------------------------------------*/
  245. /*
  246. * I2C GPIO expanders
  247. */
  248. #define PCF_Uxx_BASE(x) (DAVINCI_N_GPIO + ((x) * 8))
  249. /* U2 -- LEDs */
  250. static struct gpio_led evm_leds[] = {
  251. { .name = "DS8", .active_low = 1,
  252. .default_trigger = "heartbeat", },
  253. { .name = "DS7", .active_low = 1, },
  254. { .name = "DS6", .active_low = 1, },
  255. { .name = "DS5", .active_low = 1, },
  256. { .name = "DS4", .active_low = 1, },
  257. { .name = "DS3", .active_low = 1, },
  258. { .name = "DS2", .active_low = 1,
  259. .default_trigger = "mmc0", },
  260. { .name = "DS1", .active_low = 1,
  261. .default_trigger = "ide-disk", },
  262. };
  263. static const struct gpio_led_platform_data evm_led_data = {
  264. .num_leds = ARRAY_SIZE(evm_leds),
  265. .leds = evm_leds,
  266. };
  267. static struct platform_device *evm_led_dev;
  268. static int
  269. evm_led_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  270. {
  271. struct gpio_led *leds = evm_leds;
  272. int status;
  273. while (ngpio--) {
  274. leds->gpio = gpio++;
  275. leds++;
  276. }
  277. /* what an extremely annoying way to be forced to handle
  278. * device unregistration ...
  279. */
  280. evm_led_dev = platform_device_alloc("leds-gpio", 0);
  281. platform_device_add_data(evm_led_dev,
  282. &evm_led_data, sizeof evm_led_data);
  283. evm_led_dev->dev.parent = &client->dev;
  284. status = platform_device_add(evm_led_dev);
  285. if (status < 0) {
  286. platform_device_put(evm_led_dev);
  287. evm_led_dev = NULL;
  288. }
  289. return status;
  290. }
  291. static int
  292. evm_led_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  293. {
  294. if (evm_led_dev) {
  295. platform_device_unregister(evm_led_dev);
  296. evm_led_dev = NULL;
  297. }
  298. return 0;
  299. }
  300. static struct pcf857x_platform_data pcf_data_u2 = {
  301. .gpio_base = PCF_Uxx_BASE(0),
  302. .setup = evm_led_setup,
  303. .teardown = evm_led_teardown,
  304. };
  305. /* U18 - A/V clock generator and user switch */
  306. static int sw_gpio;
  307. static ssize_t
  308. sw_show(struct device *d, struct device_attribute *a, char *buf)
  309. {
  310. char *s = gpio_get_value_cansleep(sw_gpio) ? "on\n" : "off\n";
  311. strcpy(buf, s);
  312. return strlen(s);
  313. }
  314. static DEVICE_ATTR(user_sw, S_IRUGO, sw_show, NULL);
  315. static int
  316. evm_u18_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  317. {
  318. int status;
  319. /* export dip switch option */
  320. sw_gpio = gpio + 7;
  321. status = gpio_request(sw_gpio, "user_sw");
  322. if (status == 0)
  323. status = gpio_direction_input(sw_gpio);
  324. if (status == 0)
  325. status = device_create_file(&client->dev, &dev_attr_user_sw);
  326. else
  327. gpio_free(sw_gpio);
  328. if (status != 0)
  329. sw_gpio = -EINVAL;
  330. /* audio PLL: 48 kHz (vs 44.1 or 32), single rate (vs double) */
  331. gpio_request(gpio + 3, "pll_fs2");
  332. gpio_direction_output(gpio + 3, 0);
  333. gpio_request(gpio + 2, "pll_fs1");
  334. gpio_direction_output(gpio + 2, 0);
  335. gpio_request(gpio + 1, "pll_sr");
  336. gpio_direction_output(gpio + 1, 0);
  337. return 0;
  338. }
  339. static int
  340. evm_u18_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  341. {
  342. gpio_free(gpio + 1);
  343. gpio_free(gpio + 2);
  344. gpio_free(gpio + 3);
  345. if (sw_gpio > 0) {
  346. device_remove_file(&client->dev, &dev_attr_user_sw);
  347. gpio_free(sw_gpio);
  348. }
  349. return 0;
  350. }
  351. static struct pcf857x_platform_data pcf_data_u18 = {
  352. .gpio_base = PCF_Uxx_BASE(1),
  353. .n_latch = (1 << 3) | (1 << 2) | (1 << 1),
  354. .setup = evm_u18_setup,
  355. .teardown = evm_u18_teardown,
  356. };
  357. /* U35 - various I/O signals used to manage USB, CF, ATA, etc */
  358. static int
  359. evm_u35_setup(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  360. {
  361. /* p0 = nDRV_VBUS (initial: don't supply it) */
  362. gpio_request(gpio + 0, "nDRV_VBUS");
  363. gpio_direction_output(gpio + 0, 1);
  364. /* p1 = VDDIMX_EN */
  365. gpio_request(gpio + 1, "VDDIMX_EN");
  366. gpio_direction_output(gpio + 1, 1);
  367. /* p2 = VLYNQ_EN */
  368. gpio_request(gpio + 2, "VLYNQ_EN");
  369. gpio_direction_output(gpio + 2, 1);
  370. /* p3 = n3V3_CF_RESET (initial: stay in reset) */
  371. gpio_request(gpio + 3, "nCF_RESET");
  372. gpio_direction_output(gpio + 3, 0);
  373. /* (p4 unused) */
  374. /* p5 = 1V8_WLAN_RESET (initial: stay in reset) */
  375. gpio_request(gpio + 5, "WLAN_RESET");
  376. gpio_direction_output(gpio + 5, 1);
  377. /* p6 = nATA_SEL (initial: select) */
  378. gpio_request(gpio + 6, "nATA_SEL");
  379. gpio_direction_output(gpio + 6, 0);
  380. /* p7 = nCF_SEL (initial: deselect) */
  381. gpio_request(gpio + 7, "nCF_SEL");
  382. gpio_direction_output(gpio + 7, 1);
  383. return 0;
  384. }
  385. static int
  386. evm_u35_teardown(struct i2c_client *client, int gpio, unsigned ngpio, void *c)
  387. {
  388. gpio_free(gpio + 7);
  389. gpio_free(gpio + 6);
  390. gpio_free(gpio + 5);
  391. gpio_free(gpio + 3);
  392. gpio_free(gpio + 2);
  393. gpio_free(gpio + 1);
  394. gpio_free(gpio + 0);
  395. return 0;
  396. }
  397. static struct pcf857x_platform_data pcf_data_u35 = {
  398. .gpio_base = PCF_Uxx_BASE(2),
  399. .setup = evm_u35_setup,
  400. .teardown = evm_u35_teardown,
  401. };
  402. /*----------------------------------------------------------------------*/
  403. /* Most of this EEPROM is unused, but U-Boot uses some data:
  404. * - 0x7f00, 6 bytes Ethernet Address
  405. * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
  406. * - ... newer boards may have more
  407. */
  408. static struct at24_platform_data eeprom_info = {
  409. .byte_len = (256*1024) / 8,
  410. .page_size = 64,
  411. .flags = AT24_FLAG_ADDR16,
  412. .setup = davinci_get_mac_addr,
  413. .context = (void *)0x7f00,
  414. };
  415. /*
  416. * MSP430 supports RTC, card detection, input from IR remote, and
  417. * a bit more. It triggers interrupts on GPIO(7) from pressing
  418. * buttons on the IR remote, and for card detect switches.
  419. */
  420. static struct i2c_client *dm6446evm_msp;
  421. static int dm6446evm_msp_probe(struct i2c_client *client,
  422. const struct i2c_device_id *id)
  423. {
  424. dm6446evm_msp = client;
  425. return 0;
  426. }
  427. static int dm6446evm_msp_remove(struct i2c_client *client)
  428. {
  429. dm6446evm_msp = NULL;
  430. return 0;
  431. }
  432. static const struct i2c_device_id dm6446evm_msp_ids[] = {
  433. { "dm6446evm_msp", 0, },
  434. { /* end of list */ },
  435. };
  436. static struct i2c_driver dm6446evm_msp_driver = {
  437. .driver.name = "dm6446evm_msp",
  438. .id_table = dm6446evm_msp_ids,
  439. .probe = dm6446evm_msp_probe,
  440. .remove = dm6446evm_msp_remove,
  441. };
  442. static int dm6444evm_msp430_get_pins(void)
  443. {
  444. static const char txbuf[2] = { 2, 4, };
  445. char buf[4];
  446. struct i2c_msg msg[2] = {
  447. {
  448. .flags = 0,
  449. .len = 2,
  450. .buf = (void __force *)txbuf,
  451. },
  452. {
  453. .flags = I2C_M_RD,
  454. .len = 4,
  455. .buf = buf,
  456. },
  457. };
  458. int status;
  459. if (!dm6446evm_msp)
  460. return -ENXIO;
  461. msg[0].addr = dm6446evm_msp->addr;
  462. msg[1].addr = dm6446evm_msp->addr;
  463. /* Command 4 == get input state, returns port 2 and port3 data
  464. * S Addr W [A] len=2 [A] cmd=4 [A]
  465. * RS Addr R [A] [len=4] A [cmd=4] A [port2] A [port3] N P
  466. */
  467. status = i2c_transfer(dm6446evm_msp->adapter, msg, 2);
  468. if (status < 0)
  469. return status;
  470. dev_dbg(&dm6446evm_msp->dev,
  471. "PINS: %02x %02x %02x %02x\n",
  472. buf[0], buf[1], buf[2], buf[3]);
  473. return (buf[3] << 8) | buf[2];