board-dm355-evm.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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/spi/spi.h>
  24. #include <linux/spi/eeprom.h>
  25. #include <asm/setup.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/mach/arch.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/mach/flash.h>
  30. #include <mach/hardware.h>
  31. #include <mach/dm355.h>
  32. #include <mach/psc.h>
  33. #include <mach/common.h>
  34. #include <mach/i2c.h>
  35. #include <mach/serial.h>
  36. #include <mach/nand.h>
  37. #include <mach/mmc.h>
  38. #include <mach/common.h>
  39. #define DAVINCI_ASYNC_EMIF_CONTROL_BASE 0x01e10000
  40. #define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
  41. /* NOTE: this is geared for the standard config, with a socketed
  42. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  43. * swap chips, maybe with a different block size, partitioning may
  44. * need to be changed.
  45. */
  46. #define NAND_BLOCK_SIZE SZ_128K
  47. static struct mtd_partition davinci_nand_partitions[] = {
  48. {
  49. /* UBL (a few copies) plus U-Boot */
  50. .name = "bootloader",
  51. .offset = 0,
  52. .size = 15 * NAND_BLOCK_SIZE,
  53. .mask_flags = MTD_WRITEABLE, /* force read-only */
  54. }, {
  55. /* U-Boot environment */
  56. .name = "params",
  57. .offset = MTDPART_OFS_APPEND,
  58. .size = 1 * NAND_BLOCK_SIZE,
  59. .mask_flags = 0,
  60. }, {
  61. .name = "kernel",
  62. .offset = MTDPART_OFS_APPEND,
  63. .size = SZ_4M,
  64. .mask_flags = 0,
  65. }, {
  66. .name = "filesystem1",
  67. .offset = MTDPART_OFS_APPEND,
  68. .size = SZ_512M,
  69. .mask_flags = 0,
  70. }, {
  71. .name = "filesystem2",
  72. .offset = MTDPART_OFS_APPEND,
  73. .size = MTDPART_SIZ_FULL,
  74. .mask_flags = 0,
  75. }
  76. /* two blocks with bad block table (and mirror) at the end */
  77. };
  78. static struct davinci_nand_pdata davinci_nand_data = {
  79. .mask_chipsel = BIT(14),
  80. .parts = davinci_nand_partitions,
  81. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  82. .ecc_mode = NAND_ECC_HW_SYNDROME,
  83. .options = NAND_USE_FLASH_BBT,
  84. };
  85. static struct resource davinci_nand_resources[] = {
  86. {
  87. .start = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
  88. .end = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  89. .flags = IORESOURCE_MEM,
  90. }, {
  91. .start = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
  92. .end = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  93. .flags = IORESOURCE_MEM,
  94. },
  95. };
  96. static struct platform_device davinci_nand_device = {
  97. .name = "davinci_nand",
  98. .id = 0,
  99. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  100. .resource = davinci_nand_resources,
  101. .dev = {
  102. .platform_data = &davinci_nand_data,
  103. },
  104. };
  105. static struct davinci_i2c_platform_data i2c_pdata = {
  106. .bus_freq = 400 /* kHz */,
  107. .bus_delay = 0 /* usec */,
  108. };
  109. static int dm355evm_mmc_gpios = -EINVAL;
  110. static void dm355evm_mmcsd_gpios(unsigned gpio)
  111. {
  112. gpio_request(gpio + 0, "mmc0_ro");
  113. gpio_request(gpio + 1, "mmc0_cd");
  114. gpio_request(gpio + 2, "mmc1_ro");
  115. gpio_request(gpio + 3, "mmc1_cd");
  116. /* we "know" these are input-only so we don't
  117. * need to call gpio_direction_input()
  118. */
  119. dm355evm_mmc_gpios = gpio;
  120. }
  121. static struct i2c_board_info dm355evm_i2c_info[] = {
  122. { I2C_BOARD_INFO("dm355evm_msp", 0x25),
  123. .platform_data = dm355evm_mmcsd_gpios,
  124. /* plus irq */ },
  125. /* { I2C_BOARD_INFO("tlv320aic3x", 0x1b), }, */
  126. /* { I2C_BOARD_INFO("tvp5146", 0x5d), }, */
  127. };
  128. static void __init evm_init_i2c(void)
  129. {
  130. davinci_init_i2c(&i2c_pdata);
  131. gpio_request(5, "dm355evm_msp");
  132. gpio_direction_input(5);
  133. dm355evm_i2c_info[0].irq = gpio_to_irq(5);
  134. i2c_register_board_info(1, dm355evm_i2c_info,
  135. ARRAY_SIZE(dm355evm_i2c_info));
  136. }
  137. static struct resource dm355evm_dm9000_rsrc[] = {
  138. {
  139. /* addr */
  140. .start = 0x04014000,
  141. .end = 0x04014001,
  142. .flags = IORESOURCE_MEM,
  143. }, {
  144. /* data */
  145. .start = 0x04014002,
  146. .end = 0x04014003,
  147. .flags = IORESOURCE_MEM,
  148. }, {
  149. .flags = IORESOURCE_IRQ
  150. | IORESOURCE_IRQ_HIGHEDGE /* rising (active high) */,
  151. },
  152. };
  153. static struct platform_device dm355evm_dm9000 = {
  154. .name = "dm9000",
  155. .id = -1,
  156. .resource = dm355evm_dm9000_rsrc,
  157. .num_resources = ARRAY_SIZE(dm355evm_dm9000_rsrc),
  158. };
  159. static struct platform_device *davinci_evm_devices[] __initdata = {
  160. &dm355evm_dm9000,
  161. &davinci_nand_device,
  162. };
  163. static struct davinci_uart_config uart_config __initdata = {
  164. .enabled_uarts = (1 << 0),
  165. };
  166. static void __init dm355_evm_map_io(void)
  167. {
  168. dm355_init();
  169. }
  170. static int dm355evm_mmc_get_cd(int module)
  171. {
  172. if (!gpio_is_valid(dm355evm_mmc_gpios))
  173. return -ENXIO;
  174. /* low == card present */
  175. return !gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 1);
  176. }
  177. static int dm355evm_mmc_get_ro(int module)
  178. {
  179. if (!gpio_is_valid(dm355evm_mmc_gpios))
  180. return -ENXIO;
  181. /* high == card's write protect switch active */
  182. return gpio_get_value_cansleep(dm355evm_mmc_gpios + 2 * module + 0);
  183. }
  184. static struct davinci_mmc_config dm355evm_mmc_config = {
  185. .get_cd = dm355evm_mmc_get_cd,
  186. .get_ro = dm355evm_mmc_get_ro,
  187. .wires = 4,
  188. .max_freq = 50000000,
  189. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  190. .version = MMC_CTLR_VERSION_1,
  191. };
  192. /* Don't connect anything to J10 unless you're only using USB host
  193. * mode *and* have to do so with some kind of gender-bender. If
  194. * you have proper Mini-B or Mini-A cables (or Mini-A adapters)
  195. * the ID pin won't need any help.
  196. */
  197. #ifdef CONFIG_USB_MUSB_PERIPHERAL
  198. #define USB_ID_VALUE 0 /* ID pulled high; *should* float */
  199. #else
  200. #define USB_ID_VALUE 1 /* ID pulled low */
  201. #endif
  202. static struct spi_eeprom at25640a = {
  203. .byte_len = SZ_64K / 8,
  204. .name = "at25640a",
  205. .page_size = 32,
  206. .flags = EE_ADDR2,
  207. };
  208. static struct spi_board_info dm355_evm_spi_info[] __initconst = {
  209. {
  210. .modalias = "at25",
  211. .platform_data = &at25640a,
  212. .max_speed_hz = 10 * 1000 * 1000, /* at 3v3 */
  213. .bus_num = 0,
  214. .chip_select = 0,
  215. .mode = SPI_MODE_0,
  216. },
  217. };
  218. static __init void dm355_evm_init(void)
  219. {
  220. struct clk *aemif;
  221. gpio_request(1, "dm9000");
  222. gpio_direction_input(1);
  223. dm355evm_dm9000_rsrc[2].start = gpio_to_irq(1);
  224. aemif = clk_get(&dm355evm_dm9000.dev, "aemif");
  225. if (IS_ERR(aemif))
  226. WARN("%s: unable to get AEMIF clock\n", __func__);
  227. else
  228. clk_enable(aemif);
  229. platform_add_devices(davinci_evm_devices,
  230. ARRAY_SIZE(davinci_evm_devices));
  231. evm_init_i2c();
  232. davinci_serial_init(&uart_config);
  233. /* NOTE: NAND flash timings set by the UBL are slower than
  234. * needed by MT29F16G08FAA chips ... EMIF.A1CR is 0x40400204
  235. * but could be 0x0400008c for about 25% faster page reads.
  236. */
  237. gpio_request(2, "usb_id_toggle");
  238. gpio_direction_output(2, USB_ID_VALUE);
  239. /* irlml6401 switches over 1A in under 8 msec */
  240. setup_usb(500, 8);
  241. davinci_setup_mmc(0, &dm355evm_mmc_config);
  242. davinci_setup_mmc(1, &dm355evm_mmc_config);
  243. dm355_init_spi0(BIT(0), dm355_evm_spi_info,
  244. ARRAY_SIZE(dm355_evm_spi_info));
  245. }
  246. static __init void dm355_evm_irq_init(void)
  247. {
  248. davinci_irq_init();
  249. }
  250. MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
  251. .phys_io = IO_PHYS,
  252. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  253. .boot_params = (0x80000100),
  254. .map_io = dm355_evm_map_io,
  255. .init_irq = dm355_evm_irq_init,
  256. .timer = &davinci_timer,
  257. .init_machine = dm355_evm_init,
  258. MACHINE_END