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. .engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST,
  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", DM355_I2C_SDA_PIN, "sda",
  109. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  110. GPIO_LOOKUP("davinci_gpio", DM355_I2C_SCL_PIN, "scl",
  111. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  112. { }
  113. },
  114. };
  115. static struct davinci_i2c_platform_data i2c_pdata = {
  116. .bus_freq = 400 /* kHz */,
  117. .bus_delay = 0 /* usec */,
  118. .gpio_recovery = true,
  119. };
  120. static int dm355evm_mmc_gpios = -EINVAL;
  121. static void dm355evm_mmcsd_gpios(unsigned gpio)
  122. {
  123. gpio_request(gpio + 0, "mmc0_ro");
  124. gpio_request(gpio + 1, "mmc0_cd");
  125. gpio_request(gpio + 2, "mmc1_ro");
  126. gpio_request(gpio + 3, "mmc1_cd");
  127. /* we "know" these are input-only so we don't
  128. * need to call gpio_direction_input()
  129. */
  130. dm355evm_mmc_gpios = gpio;
  131. }
  132. static struct i2c_board_info dm355evm_i2c_info[] = {
  133. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  134. .platform_data = dm355evm_mmcsd_gpios,
  135. },
  136. /* { plus irq }, */
  137. { I2C_BOARD_INFO("tlv320aic33", 0x1b), },
  138. };
  139. static void __init evm_init_i2c(void)
  140. {
  141. gpiod_add_lookup_table(&i2c_recovery_gpiod_table);
  142. davinci_init_i2c(&i2c_pdata);
  143. gpio_request(5, "dm355evm_msp");
  144. gpio_direction_input(5);
  145. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  146. i2c_register_board_info(1, dm355evm_i2c_info,
  147. ARRAY_SIZE(dm355evm_i2c_info));
  148. }
  149. static struct resource dm355evm_dm9000_rsrc[] = {
  150. {
  151. /* addr */
  152. .start = 0x04014000,
  153. .end = 0x04014001,
  154. .flags = IORESOURCE_MEM,
  155. }, {
  156. /* data */
  157. .start = 0x04014002,
  158. .end = 0x04014003,
  159. .flags = IORESOURCE_MEM,
  160. }, {
  161. .flags = IORESOURCE_IRQ
  162. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  163. },
  164. };
  165. static struct dm9000_plat_data dm335evm_dm9000_platdata;
  166. static struct platform_device dm355evm_dm9000 = {
  167. .name = "dm9000",
  168. .id = -1,
  169. .resource = dm355evm_dm9000_rsrc,
  170. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  171. .dev = {
  172. .platform_data = &dm335evm_dm9000_platdata,
  173. },
  174. };
  175. static struct tvp514x_platform_data tvp5146_pdata = {
  176. .clk_polarity = 0,
  177. .hs_polarity = 1,
  178. .vs_polarity = 1
  179. };
  180. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  181. /* Inputs available at the TVP5146 */
  182. static struct v4l2_input tvp5146_inputs[] = {
  183. {
  184. .index = 0,
  185. .name = "Composite",
  186. .type = V4L2_INPUT_TYPE_CAMERA,
  187. .std = TVP514X_STD_ALL,
  188. },
  189. {
  190. .index = 1,
  191. .name = "S-Video",
  192. .type = V4L2_INPUT_TYPE_CAMERA,
  193. .std = TVP514X_STD_ALL,
  194. },
  195. };
  196. /*
  197. * this is the route info for connecting each input to decoder
  198. * ouput that goes to vpfe. There is a one to one correspondence
  199. * with tvp5146_inputs
  200. */
  201. static struct vpfe_route tvp5146_routes[] = {
  202. {
  203. .input = INPUT_CVBS_VI2B,
  204. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  205. },
  206. {
  207. .input = INPUT_SVIDEO_VI2C_VI1C,
  208. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  209. },
  210. };
  211. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  212. {
  213. .name = "tvp5146",
  214. .grp_id = 0,
  215. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  216. .inputs = tvp5146_inputs,
  217. .routes = tvp5146_routes,
  218. .can_route = 1,
  219. .ccdc_if_params = {
  220. .if_type = VPFE_BT656,
  221. .hdpol = VPFE_PINPOL_POSITIVE,
  222. .vdpol = VPFE_PINPOL_POSITIVE,
  223. },
  224. .board_info = {
  225. I2C_BOARD_INFO("tvp5146", 0x5d),
  226. .platform_data = &tvp5146_pdata,
  227. },
  228. }
  229. };
  230. static struct vpfe_config vpfe_cfg = {
  231. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  232. .i2c_adapter_id = 1,
  233. .sub_devs = vpfe_sub_devs,
  234. .card_name = "DM355 EVM",
  235. .ccdc = "DM355 CCDC",
  236. };
  237. /* venc standards timings */
  238. static struct vpbe_enc_mode_info dm355evm_enc_preset_timing[] = {
  239. {
  240. .name = "ntsc",
  241. .timings_type = VPBE_ENC_STD,
  242. .std_id = V4L2_STD_NTSC,
  243. .interlaced = 1,
  244. .xres = 720,
  245. .yres = 480,
  246. .aspect = {11, 10},
  247. .fps = {30000, 1001},
  248. .left_margin = 0x79,
  249. .upper_margin = 0x10,
  250. },
  251. {
  252. .name = "pal",
  253. .timings_type = VPBE_ENC_STD,
  254. .std_id = V4L2_STD_PAL,
  255. .interlaced = 1,
  256. .xres = 720,
  257. .yres = 576,
  258. .aspect = {54, 59},
  259. .fps = {25, 1},
  260. .left_margin = 0x7E,
  261. .upper_margin = 0x16
  262. },
  263. };
  264. #define VENC_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  265. /*
  266. * The outputs available from VPBE + ecnoders. Keep the
  267. * the order same as that of encoders. First those from venc followed by that
  268. * from encoders. Index in the output refers to index on a particular encoder.
  269. * Driver uses this index to pass it to encoder when it supports more than
  270. * one output. Application uses index of the array to set an output.
  271. */
  272. static struct vpbe_output dm355evm_vpbe_outputs[] = {
  273. {
  274. .output = {
  275. .index = 0,
  276. .name = "Composite",
  277. .type = V4L2_OUTPUT_TYPE_ANALOG,
  278. .std = VENC_STD_ALL,
  279. .capabilities = V4L2_OUT_CAP_STD,
  280. },
  281. .subdev_name = DM355_VPBE_VENC_SUBDEV_NAME,
  282. .default_mode = "ntsc",
  283. .num_modes = ARRAY_SIZE(dm355evm_enc_preset_timing),
  284. .modes = dm355evm_enc_preset_timing,
  285. .if_params = MEDIA_BUS_FMT_FIXED,
  286. },
  287. };
  288. static struct vpbe_config dm355evm_display_cfg = {
  289. .module_name = "dm355-vpbe-display",
  290. .i2c_adapter_id = 1,
  291. .osd = {
  292. .module_name = DM355_VPBE_OSD_SUBDEV_NAME,
  293. },
  294. .venc = {
  295. .module_name = DM355_VPBE_VENC_SUBDEV_NAME,
  296. },
  297. .num_outputs = ARRAY_SIZE(dm355evm_vpbe_outputs),
  298. .outputs = dm355evm_vpbe_outputs,
  299. };
  300. static struct platform_device *davinci_evm_devices[] __initdata = {
  301. &dm355evm_dm9000,
  302. &davinci_nand_device,
  303. };
  304. static void __init dm355_evm_map_io(void)
  305. {
  306. dm355_init();
  307. }
  308. static int dm355evm_mmc_get_cd(int module)
  309. {
  310. if (!gpio_is_valid(dm355evm_mmc_gpios))
  311. return -ENXIO;
  312. /* low == card present */
  313. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  314. }
  315. static int dm355evm_mmc_get_ro(int module)
  316. {
  317. if (!gpio_is_valid(dm355evm_mmc_gpios))
  318. return -ENXIO;
  319. /* high == card's write protect switch active */
  320. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  321. }
  322. static struct davinci_mmc_config dm355evm_mmc_config = {
  323. .get_cd = dm355evm_mmc_get_cd,
  324. .get_ro = dm355evm_mmc_get_ro,
  325. .wires = 4,
  326. .max_freq = 50000000,
  327. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  328. };
  329. /* Don't connect anything to J10 unless you're only using USB host
  330. * mode *and* have to do so with some kind of gender-bender. If
  331. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  332. * the ID pin won't need any help.
  333. */
  334. #define USB_ID_VALUE 1 /* ID pulled low */
  335. static struct spi_eeprom at25640a = {
  336. .byte_len = SZ_64K / 8,
  337. .name = "at25640a",
  338. .page_size = 32,
  339. .flags = EE_ADDR2,
  340. };
  341. static const struct spi_board_info dm355_evm_spi_info[] __initconst = {
  342. {
  343. .modalias = "at25",
  344. .platform_data = &at25640a,
  345. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  346. .bus_num = 0,
  347. .chip_select = 0,
  348. .mode = SPI_MODE_0,
  349. },
  350. };
  351. static __init void dm355_evm_init(void)
  352. {
  353. struct clk *aemif;
  354. int ret;
  355. dm355_register_clocks();
  356. ret = dm355_gpio_register();
  357. if (ret)
  358. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  359. gpio_request(1, "dm9000");
  360. gpio_direction_input(1);
  361. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  362. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  363. if (!WARN(IS_ERR(aemif), "unable to get AEMIF clock\n"))
  364. clk_prepare_enable(aemif);
  365. platform_add_devices(davinci_evm_devices,
  366. ARRAY_SIZE(davinci_evm_devices));
  367. evm_init_i2c();
  368. davinci_serial_init(dm355_serial_device);
  369. /* NOTE: NAND flash timings set by the UBL are slower than
  370. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  371. * but could be 0x0400008c for about 25% faster page reads.
  372. */
  373. gpio_request(2, "usb_id_toggle");
  374. gpio_direction_output(2, USB_ID_VALUE);
  375. /* irlml6401 switches over 1A in under 8 msec */
  376. davinci_setup_usb(1000, 8);
  377. davinci_setup_mmc(0, &dm355evm_mmc_config);
  378. davinci_setup_mmc(1, &dm355evm_mmc_config);
  379. dm355_init_video(&vpfe_cfg, &dm355evm_display_cfg);
  380. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  381. ARRAY_SIZE(dm355_evm_spi_info));
  382. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  383. dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN);
  384. }
  385. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  386. .atag_offset = 0x100,
  387. .map_io = dm355_evm_map_io,
  388. .init_irq = dm355_init_irq,
  389. .init_time = dm355_init_time,
  390. .init_machine = dm355_evm_init,
  391. .init_late = davinci_init_late,
  392. .dma_zone_size = SZ_128M,
  393. MACHINE_END