board-dm355-evm.c 11 KB

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