board-dm355-evm.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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/module.h>
  13. #include <linux/init.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/mtd/nand.h>
  19. #include <linux/i2c.h>
  20. #include <linux/io.h>
  21. #include <linux/gpio.h>
  22. #include <linux/clk.h>
  23. #include <linux/videodev2.h>
  24. #include <media/tvp514x.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/eeprom.h>
  27. #include <asm/setup.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/map.h>
  31. #include <asm/mach/flash.h>
  32. #include <mach/hardware.h>
  33. #include <mach/dm355.h>
  34. #include <mach/psc.h>
  35. #include <mach/common.h>
  36. #include <mach/i2c.h>
  37. #include <mach/serial.h>
  38. #include <mach/nand.h>
  39. #include <mach/mmc.h>
  40. #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x01e10000
  41. #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
  42. /* NOTE: this is geared for the standard config, with a socketed
  43. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  44. * swap chips, maybe with a different block size, partitioning may
  45. * need to be changed.
  46. */
  47. #define NAND_BLOCK_SIZE SZ_128K
  48. static struct mtd_partition davinci_nand_partitions[] = {
  49. {
  50. /* UBL (a few copies) plus U-Boot */
  51. .name = "bootloader",
  52. .offset = 0,
  53. .size = 15 * NAND_BLOCK_SIZE,
  54. .mask_flags = MTD_WRITEABLE, /* force read-only */
  55. }, {
  56. /* U-Boot environment */
  57. .name = "params",
  58. .offset = MTDPART_OFS_APPEND,
  59. .size = 1 * NAND_BLOCK_SIZE,
  60. .mask_flags = 0,
  61. }, {
  62. .name = "kernel",
  63. .offset = MTDPART_OFS_APPEND,
  64. .size = SZ_4M,
  65. .mask_flags = 0,
  66. }, {
  67. .name = "filesystem1",
  68. .offset = MTDPART_OFS_APPEND,
  69. .size = SZ_512M,
  70. .mask_flags = 0,
  71. }, {
  72. .name = "filesystem2",
  73. .offset = MTDPART_OFS_APPEND,
  74. .size = MTDPART_SIZ_FULL,
  75. .mask_flags = 0,
  76. }
  77. /* two blocks with bad block table (and mirror) at the end */
  78. };
  79. static struct davinci_nand_pdata davinci_nand_data = {
  80. .mask_chipsel = BIT(14),
  81. .parts = davinci_nand_partitions,
  82. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  83. .ecc_mode = NAND_ECC_HW,
  84. .options = NAND_USE_FLASH_BBT,
  85. .ecc_bits = 4,
  86. };
  87. static struct resource davinci_nand_resources[] = {
  88. {
  89. .start = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
  90. .end = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  91. .flags = IORESOURCE_MEM,
  92. }, {
  93. .start = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
  94. .end = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  95. .flags = IORESOURCE_MEM,
  96. },
  97. };
  98. static struct platform_device davinci_nand_device = {
  99. .name = "davinci_nand",
  100. .id = 0,
  101. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  102. .resource = davinci_nand_resources,
  103. .dev = {
  104. .platform_data = &davinci_nand_data,
  105. },
  106. };
  107. static struct davinci_i2c_platform_data i2c_pdata = {
  108. .bus_freq = 400 /* kHz */,
  109. .bus_delay = 0 /* usec */,
  110. };
  111. static struct snd_platform_data dm355_evm_snd_data;
  112. static int dm355evm_mmc_gpios = -EINVAL;
  113. static void dm355evm_mmcsd_gpios(unsigned gpio)
  114. {
  115. gpio_request(gpio + 0, "mmc0_ro");
  116. gpio_request(gpio + 1, "mmc0_cd");
  117. gpio_request(gpio + 2, "mmc1_ro");
  118. gpio_request(gpio + 3, "mmc1_cd");
  119. /* we "know" these are input-only so we don't
  120. * need to call gpio_direction_input()
  121. */
  122. dm355evm_mmc_gpios = gpio;
  123. }
  124. static struct i2c_board_info dm355evm_i2c_info[] = {
  125. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  126. .platform_data = dm355evm_mmcsd_gpios,
  127. },
  128. /* { plus irq }, */
  129. { I2C_BOARD_INFO("tlv320aic33", 0x1b), },
  130. };
  131. static void __init evm_init_i2c(void)
  132. {
  133. davinci_init_i2c(&i2c_pdata);
  134. gpio_request(5, "dm355evm_msp");
  135. gpio_direction_input(5);
  136. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  137. i2c_register_board_info(1, dm355evm_i2c_info,
  138. ARRAY_SIZE(dm355evm_i2c_info));
  139. }
  140. static struct resource dm355evm_dm9000_rsrc[] = {
  141. {
  142. /* addr */
  143. .start = 0x04014000,
  144. .end = 0x04014001,
  145. .flags = IORESOURCE_MEM,
  146. }, {
  147. /* data */
  148. .start = 0x04014002,
  149. .end = 0x04014003,
  150. .flags = IORESOURCE_MEM,
  151. }, {
  152. .flags = IORESOURCE_IRQ
  153. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  154. },
  155. };
  156. static struct platform_device dm355evm_dm9000 = {
  157. .name = "dm9000",
  158. .id = -1,
  159. .resource = dm355evm_dm9000_rsrc,
  160. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  161. };
  162. static struct tvp514x_platform_data tvp5146_pdata = {
  163. .clk_polarity = 0,
  164. .hs_polarity = 1,
  165. .vs_polarity = 1
  166. };
  167. #define TVP514X_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)
  168. /* Inputs available at the TVP5146 */
  169. static struct v4l2_input tvp5146_inputs[] = {
  170. {
  171. .index = 0,
  172. .name = "Composite",
  173. .type = V4L2_INPUT_TYPE_CAMERA,
  174. .std = TVP514X_STD_ALL,
  175. },
  176. {
  177. .index = 1,
  178. .name = "S-Video",
  179. .type = V4L2_INPUT_TYPE_CAMERA,
  180. .std = TVP514X_STD_ALL,
  181. },
  182. };
  183. /*
  184. * this is the route info for connecting each input to decoder
  185. * ouput that goes to vpfe. There is a one to one correspondence
  186. * with tvp5146_inputs
  187. */
  188. static struct vpfe_route tvp5146_routes[] = {
  189. {
  190. .input = INPUT_CVBS_VI2B,
  191. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  192. },
  193. {
  194. .input = INPUT_SVIDEO_VI2C_VI1C,
  195. .output = OUTPUT_10BIT_422_EMBEDDED_SYNC,
  196. },
  197. };
  198. static struct vpfe_subdev_info vpfe_sub_devs[] = {
  199. {
  200. .name = "tvp5146",
  201. .grp_id = 0,
  202. .num_inputs = ARRAY_SIZE(tvp5146_inputs),
  203. .inputs = tvp5146_inputs,
  204. .routes = tvp5146_routes,
  205. .can_route = 1,
  206. .ccdc_if_params = {
  207. .if_type = VPFE_BT656,
  208. .hdpol = VPFE_PINPOL_POSITIVE,
  209. .vdpol = VPFE_PINPOL_POSITIVE,
  210. },
  211. .board_info = {
  212. I2C_BOARD_INFO("tvp5146", 0x5d),
  213. .platform_data = &tvp5146_pdata,
  214. },
  215. }
  216. };
  217. static struct vpfe_config vpfe_cfg = {
  218. .num_subdevs = ARRAY_SIZE(vpfe_sub_devs),
  219. .sub_devs = vpfe_sub_devs,
  220. .card_name = "DM355 EVM",
  221. .ccdc = "DM355 CCDC",
  222. };
  223. static struct platform_device *davinci_evm_devices[] __initdata = {
  224. &dm355evm_dm9000,
  225. &davinci_nand_device,
  226. };
  227. static struct davinci_uart_config uart_config __initdata = {
  228. .enabled_uarts = (1 << 0),
  229. };
  230. static void __init dm355_evm_map_io(void)
  231. {
  232. /* setup input configuration for VPFE input devices */
  233. dm355_set_vpfe_config(&vpfe_cfg);
  234. dm355_init();
  235. }
  236. static int dm355evm_mmc_get_cd(int module)
  237. {
  238. if (!gpio_is_valid(dm355evm_mmc_gpios))
  239. return -ENXIO;
  240. /* low == card present */
  241. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  242. }
  243. static int dm355evm_mmc_get_ro(int module)
  244. {
  245. if (!gpio_is_valid(dm355evm_mmc_gpios))
  246. return -ENXIO;
  247. /* high == card's write protect switch active */
  248. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  249. }
  250. static struct davinci_mmc_config dm355evm_mmc_config = {
  251. .get_cd = dm355evm_mmc_get_cd,
  252. .get_ro = dm355evm_mmc_get_ro,
  253. .wires = 4,
  254. .max_freq = 50000000,
  255. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  256. .version = MMC_CTLR_VERSION_1,
  257. };
  258. /* Don't connect anything to J10 unless you're only using USB host
  259. * mode *and* have to do so with some kind of gender-bender. If
  260. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  261. * the ID pin won't need any help.
  262. */
  263. #ifdef CONFIG_USB_MUSB_PERIPHERAL
  264. #define USB_ID_VALUE 0 /* ID pulled high; *should* float */
  265. #else
  266. #define USB_ID_VALUE 1 /* ID pulled low */
  267. #endif
  268. static struct spi_eeprom at25640a = {
  269. .byte_len = SZ_64K / 8,
  270. .name = "at25640a",
  271. .page_size = 32,
  272. .flags = EE_ADDR2,
  273. };
  274. static struct spi_board_info dm355_evm_spi_info[] __initconst = {
  275. {
  276. .modalias = "at25",
  277. .platform_data = &at25640a,
  278. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  279. .bus_num = 0,
  280. .chip_select = 0,
  281. .mode = SPI_MODE_0,
  282. },
  283. };
  284. static __init void dm355_evm_init(void)
  285. {
  286. struct clk *aemif;
  287. gpio_request(1, "dm9000");
  288. gpio_direction_input(1);
  289. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  290. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  291. if (IS_ERR(aemif))
  292. WARN("%s: unable to get AEMIF clock\n", __func__);
  293. else
  294. clk_enable(aemif);
  295. platform_add_devices(davinci_evm_devices,
  296. ARRAY_SIZE(davinci_evm_devices));
  297. evm_init_i2c();
  298. davinci_serial_init(&uart_config);
  299. /* NOTE: NAND flash timings set by the UBL are slower than
  300. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  301. * but could be 0x0400008c for about 25% faster page reads.
  302. */
  303. gpio_request(2, "usb_id_toggle");
  304. gpio_direction_output(2, USB_ID_VALUE);
  305. /* irlml6401 switches over 1A in under 8 msec */
  306. setup_usb(500, 8);
  307. davinci_setup_mmc(0, &dm355evm_mmc_config);
  308. davinci_setup_mmc(1, &dm355evm_mmc_config);
  309. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  310. ARRAY_SIZE(dm355_evm_spi_info));
  311. /* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
  312. dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN, &dm355_evm_snd_data);
  313. }
  314. static __init void dm355_evm_irq_init(void)
  315. {
  316. davinci_irq_init();
  317. }
  318. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  319. .phys_io = IO_PHYS,
  320. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  321. .boot_params = (0x80000100),
  322. .map_io = dm355_evm_map_io,
  323. .init_irq = dm355_evm_irq_init,
  324. .timer = &davinci_timer,
  325. .init_machine = dm355_evm_init,
  326. MACHINE_END