board-dm355-evm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * TI DaVinci EVM board support
  3. *
  4. * Author: Kevin Hilman, Deep Root Systems, LLC
  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/err.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/mtd/rawnand.h>
  18. #include <linux/i2c.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio/machine.h>
  21. #include <linux/clk.h>
  22. #include <linux/dm9000.h>
  23. #include <linux/videodev2.h>
  24. #include <media/i2c/tvp514x.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/eeprom.h>
  27. #include <linux/platform_data/gpio-davinci.h>
  28. #include <linux/platform_data/i2c-davinci.h>
  29. #include <linux/platform_data/mtd-davinci.h>
  30. #include <linux/platform_data/mmc-davinci.h>
  31. #include <linux/platform_data/usb-davinci.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <mach/serial.h>
  35. #include <mach/common.h>
  36. #include "davinci.h"
  37. /* NOTE: this is geared for the standard config, with a socketed
  38. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  39. * swap chips, maybe with a different block size, partitioning may
  40. * need to be changed.
  41. */
  42. #define NAND_BLOCK_SIZE SZ_128K
  43. static struct mtd_partition davinci_nand_partitions[] = {
  44. {
  45. /* UBL (a few copies) plus U-Boot */
  46. .name = "bootloader",
  47. .offset = 0,
  48. .size = 15 * NAND_BLOCK_SIZE,
  49. .mask_flags = MTD_WRITEABLE, /* force read-only */
  50. }, {
  51. /* U-Boot environment */
  52. .name = "params",
  53. .offset = MTDPART_OFS_APPEND,
  54. .size = 1 * NAND_BLOCK_SIZE,
  55. .mask_flags = 0,
  56. }, {
  57. .name = "kernel",
  58. .offset = MTDPART_OFS_APPEND,
  59. .size = SZ_4M,
  60. .mask_flags = 0,
  61. }, {
  62. .name = "filesystem1",
  63. .offset = MTDPART_OFS_APPEND,
  64. .size = SZ_512M,
  65. .mask_flags = 0,
  66. }, {
  67. .name = "filesystem2",
  68. .offset = MTDPART_OFS_APPEND,
  69. .size = MTDPART_SIZ_FULL,
  70. .mask_flags = 0,
  71. }
  72. /* two blocks with bad block table (and mirror) at the end */
  73. };
  74. static struct davinci_nand_pdata davinci_nand_data = {
  75. .core_chipsel = 0,
  76. .mask_chipsel = BIT(14),
  77. .parts = davinci_nand_partitions,
  78. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  79. .ecc_mode = NAND_ECC_HW,
  80. .bbt_options = NAND_BBT_USE_FLASH,
  81. .ecc_bits = 4,
  82. };
  83. static struct resource davinci_nand_resources[] = {
  84. {
  85. .start = DM355_ASYNC_EMIF_DATA_CE0_BASE,
  86. .end = DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  87. .flags = IORESOURCE_MEM,
  88. }, {
  89. .start = DM355_ASYNC_EMIF_CONTROL_BASE,
  90. .end = DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  91. .flags = IORESOURCE_MEM,
  92. },
  93. };
  94. static struct platform_device davinci_nand_device = {
  95. .name = "davinci_nand",
  96. .id = 0,
  97. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  98. .resource = davinci_nand_resources,
  99. .dev = {
  100. .platform_data = &davinci_nand_data,
  101. },
  102. };
  103. #define DM355_I2C_SDA_PIN GPIO_TO_PIN(0, 15)
  104. #define DM355_I2C_SCL_PIN GPIO_TO_PIN(0, 14)
  105. static struct gpiod_lookup_table i2c_recovery_gpiod_table = {
  106. .dev_id = "i2c_davinci.1",
  107. .table = {
  108. GPIO_LOOKUP("davinci_gpio.0", DM355_I2C_SDA_PIN, "sda",
  109. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  110. GPIO_LOOKUP("davinci_gpio.0", DM355_I2C_SCL_PIN, "scl",
  111. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  112. },
  113. };
  114. static struct davinci_i2c_platform_data i2c_pdata = {
  115. .bus_freq = 400 /* kHz */,
  116. .bus_delay = 0 /* usec */,
  117. .gpio_recovery = true,
  118. };
  119. static int dm355evm_mmc_gpios = -EINVAL;
  120. static void dm355evm_mmcsd_gpios(unsigned gpio)
  121. {
  122. gpio_request(gpio + 0, "mmc0_ro");
  123. gpio_request(gpio + 1, "mmc0_cd");
  124. gpio_request(gpio + 2, "mmc1_ro");
  125. gpio_request(gpio + 3, "mmc1_cd");
  126. /* we "know" these are input-only so we don't
  127. * need to call gpio_direction_input()
  128. */
  129. dm355evm_mmc_gpios = gpio;
  130. }
  131. static struct i2c_board_info dm355evm_i2c_info[] = {
  132. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  133. .platform_data = dm355evm_mmcsd_gpios,
  134. },
  135. /* { plus irq }, */
  136. { I2C_BOARD_INFO("tlv320aic33", 0x1b), },
  137. };
  138. static void __init evm_init_i2c(void)
  139. {
  140. gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
  141. davinci_init_i2c(&i2c_pdata);
  142. gpio_request(5, "dm355evm_msp");
  143. gpio_direction_input(5);
  144. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  145. i2c_register_board_info(1, dm355evm_i2c_info,
  146. ARRAY_SIZE(dm355evm_i2c_info));
  147. }
  148. static struct resource dm355evm_dm9000_rsrc[] = {
  149. {
  150. /* addr */
  151. .start = 0x04014000,
  152. .end = 0x04014001,
  153. .flags = IORESOURCE_MEM,
  154. }, {
  155. /* data */
  156. .start = 0x04014002,
  157. .end = 0x04014003,
  158. .flags = IORESOURCE_MEM,
  159. }, {
  160. .flags = IORESOURCE_IRQ
  161. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  162. },
  163. };
  164. static struct dm9000_plat_data dm335evm_dm9000_platdata;
  165. static struct platform_device dm355evm_dm9000 = {
  166. .name = "dm9000",
  167. .id = -1,
  168. .resource = dm355evm_dm9000_rsrc,
  169. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  170. .dev = {
  171. .platform_data = &dm335evm_dm9000_platdata,
  172. },
  173. };
  174. static struct tvp514x_platform_data tvp5146_pdata = {
  175. .clk_polarity = 0,
  176. .hs_polarity = 1,
  177. .vs_polarity = 1
  178. };
  179. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  180. /* Inputs available at the TVP5146 */
  181. static struct v4l2_input tvp5146_inputs[] = {
  182. {
  183. .index = 0,
  184. .name = "Composite",
  185. .type = V4L2_INPUT_TYPE_CAMERA,
  186. .std = TVP514X_STD_ALL,
  187. },
  188. {
  189. .index = 1,
  190. .name = "S-Video",
  191. .type = V4L2_INPUT_TYPE_CAMERA,
  192. .std = TVP514X_STD_ALL,
  193. },
  194. };
  195. /*
  196. * this is the route info for connecting each input to decoder
  197. * ouput that goes to vpfe. There is a one to one correspondence
  198. * with tvp5146_inputs
  199. */
  200. static struct vpfe_route tvp5146_routes[] = {
  201. {
  202. .input = INPUT_CVBS_VI2B,
  203. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  204. },
  205. {
  206. .input = INPUT_SVIDEO_VI2C_VI1C,
  207. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  208. },
  209. };
  210. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  211. {
  212. .name = "tvp5146",
  213. .grp_id = 0,
  214. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  215. .inputs = tvp5146_inputs,
  216. .routes = tvp5146_routes,
  217. .can_route = 1,
  218. .ccdc_if_params = {
  219. .if_type = VPFE_BT656,
  220. .hdpol = VPFE_PINPOL_POSITIVE,
  221. .vdpol = VPFE_PINPOL_POSITIVE,
  222. },
  223. .board_info = {
  224. I2C_BOARD_INFO("tvp5146", 0x5d),
  225. .platform_data = &tvp5146_pdata,
  226. },
  227. }
  228. };
  229. static struct vpfe_config vpfe_cfg = {
  230. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  231. .i2c_adapter_id = 1,
  232. .sub_devs = vpfe_sub_devs,
  233. .card_name = "DM355 EVM",
  234. .ccdc = "DM355 CCDC",
  235. };
  236. /* venc standards timings */
  237. static struct vpbe_enc_mode_info dm355evm_enc_preset_timing[] = {
  238. {
  239. .name = "ntsc",
  240. .timings_type = VPBE_ENC_STD,
  241. .std_id = V4L2_STD_NTSC,
  242. .interlaced = 1,
  243. .xres = 720,
  244. .yres = 480,
  245. .aspect = {11, 10},
  246. .fps = {30000, 1001},
  247. .left_margin = 0x79,
  248. .upper_margin = 0x10,
  249. },
  250. {
  251. .name = "pal",
  252. .timings_type = VPBE_ENC_STD,
  253. .std_id = V4L2_STD_PAL,
  254. .interlaced = 1,
  255. .xres = 720,
  256. .yres = 576,
  257. .aspect = {54, 59},
  258. .fps = {25, 1},
  259. .left_margin = 0x7E,
  260. .upper_margin = 0x16
  261. },
  262. };
  263. #define VENC_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  264. /*
  265. * The outputs available from VPBE + ecnoders. Keep the
  266. * the order same as that of encoders. First those from venc followed by that
  267. * from encoders. Index in the output refers to index on a particular encoder.
  268. * Driver uses this index to pass it to encoder when it supports more than
  269. * one output. Application uses index of the array to set an output.
  270. */
  271. static struct vpbe_output dm355evm_vpbe_outputs[] = {
  272. {
  273. .output = {
  274. .index = 0,
  275. .name = "Composite",
  276. .type = V4L2_OUTPUT_TYPE_ANALOG,
  277. .std = VENC_STD_ALL,
  278. .capabilities = V4L2_OUT_CAP_STD,
  279. },
  280. .subdev_name = DM355_VPBE_VENC_SUBDEV_NAME,
  281. .default_mode = "ntsc",
  282. .num_modes = ARRAY_SIZE(dm355evm_enc_preset_timing),
  283. .modes = dm355evm_enc_preset_timing,
  284. .if_params = MEDIA_BUS_FMT_FIXED,
  285. },
  286. };
  287. static struct vpbe_config dm355evm_display_cfg = {
  288. .module_name = "dm355-vpbe-display",
  289. .i2c_adapter_id = 1,
  290. .osd = {
  291. .module_name = DM355_VPBE_OSD_SUBDEV_NAME,
  292. },
  293. .venc = {
  294. .module_name = DM355_VPBE_VENC_SUBDEV_NAME,
  295. },
  296. .num_outputs = ARRAY_SIZE(dm355evm_vpbe_outputs),
  297. .outputs = dm355evm_vpbe_outputs,
  298. };
  299. static struct platform_device *davinci_evm_devices[] __initdata = {
  300. &dm355evm_dm9000,
  301. &davinci_nand_device,
  302. };
  303. static void __init dm355_evm_map_io(void)
  304. {
  305. dm355_init();
  306. }
  307. static int dm355evm_mmc_get_cd(int module)
  308. {
  309. if (!gpio_is_valid(dm355evm_mmc_gpios))
  310. return -ENXIO;
  311. /* low == card present */
  312. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  313. }
  314. static int dm355evm_mmc_get_ro(int module)
  315. {
  316. if (!gpio_is_valid(dm355evm_mmc_gpios))
  317. return -ENXIO;
  318. /* high == card's write protect switch active */
  319. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  320. }
  321. static struct davinci_mmc_config dm355evm_mmc_config = {
  322. .get_cd = dm355evm_mmc_get_cd,
  323. .get_ro = dm355evm_mmc_get_ro,
  324. .wires = 4,
  325. .max_freq = 50000000,
  326. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  327. };
  328. /* Don't connect anything to J10 unless you're only using USB host
  329. * mode *and* have to do so with some kind of gender-bender. If
  330. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  331. * the ID pin won't need any help.
  332. */
  333. #define USB_ID_VALUE 1 /* ID pulled low */
  334. static struct spi_eeprom at25640a = {
  335. .byte_len = SZ_64K / 8,
  336. .name = "at25640a",
  337. .page_size = 32,
  338. .flags = EE_ADDR2,
  339. };
  340. static const struct spi_board_info dm355_evm_spi_info[] __initconst = {
  341. {
  342. .modalias = "at25",
  343. .platform_data = &at25640a,
  344. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  345. .bus_num = 0,
  346. .chip_select = 0,
  347. .mode = SPI_MODE_0,
  348. },
  349. };
  350. static __init void dm355_evm_init(void)
  351. {
  352. struct clk *aemif;
  353. int ret;
  354. dm355_register_clocks();
  355. ret = dm355_gpio_register();
  356. if (ret)
  357. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  358. gpio_request(1, "dm9000");
  359. gpio_direction_input(1);
  360. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  361. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  362. if (!WARN(IS_ERR(aemif), "unable to get AEMIF clock\n"))
  363. clk_prepare_enable(aemif);
  364. platform_add_devices(davinci_evm_devices,
  365. ARRAY_SIZE(davinci_evm_devices));
  366. evm_init_i2c();
  367. davinci_serial_init(dm355_serial_device);
  368. /* NOTE: NAND flash timings set by the UBL are slower than
  369. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  370. * but could be 0x0400008c for about 25% faster page reads.
  371. */
  372. gpio_request(2, "usb_id_toggle");
  373. gpio_direction_output(2, USB_ID_VALUE);
  374. /* irlml6401 switches over 1A in under 8 msec */
  375. davinci_setup_usb(1000, 8);
  376. davinci_setup_mmc(0, &dm355evm_mmc_config);
  377. davinci_setup_mmc(1, &dm355evm_mmc_config);
  378. dm355_init_video(&vpfe_cfg, &dm355evm_display_cfg);
  379. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  380. ARRAY_SIZE(dm355_evm_spi_info));
  381. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  382. dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN);
  383. }
  384. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  385. .atag_offset = 0x100,
  386. .map_io = dm355_evm_map_io,
  387. .init_irq = davinci_irq_init,
  388. .init_time = dm355_init_time,
  389. .init_machine = dm355_evm_init,
  390. .init_late = davinci_init_late,
  391. .dma_zone_size = SZ_128M,
  392. MACHINE_END