devices.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * mach-davinci/devices.c
  3. *
  4. * DaVinci platform device setup/initialization
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/io.h>
  15. #include <linux/reboot.h>
  16. #include <mach/hardware.h>
  17. #include <linux/platform_data/i2c-davinci.h>
  18. #include <mach/irqs.h>
  19. #include <mach/cputype.h>
  20. #include <mach/mux.h>
  21. #include <linux/platform_data/mmc-davinci.h>
  22. #include <mach/time.h>
  23. #include <linux/platform_data/edma.h>
  24. #include "davinci.h"
  25. #include "clock.h"
  26. #define DAVINCI_I2C_BASE 0x01C21000
  27. #define DAVINCI_ATA_BASE 0x01C66000
  28. #define DAVINCI_MMCSD0_BASE 0x01E10000
  29. #define DM355_MMCSD0_BASE 0x01E11000
  30. #define DM355_MMCSD1_BASE 0x01E00000
  31. #define DM365_MMCSD0_BASE 0x01D11000
  32. #define DM365_MMCSD1_BASE 0x01D00000
  33. void __iomem *davinci_sysmod_base;
  34. void davinci_map_sysmod(void)
  35. {
  36. davinci_sysmod_base = ioremap_nocache(DAVINCI_SYSTEM_MODULE_BASE,
  37. 0x800);
  38. /*
  39. * Throw a bug since a lot of board initialization code depends
  40. * on system module availability. ioremap() failing this early
  41. * need careful looking into anyway.
  42. */
  43. BUG_ON(!davinci_sysmod_base);
  44. }
  45. static struct resource i2c_resources[] = {
  46. {
  47. .start = DAVINCI_I2C_BASE,
  48. .end = DAVINCI_I2C_BASE + 0x40,
  49. .flags = IORESOURCE_MEM,
  50. },
  51. {
  52. .start = IRQ_I2C,
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. };
  56. static struct platform_device davinci_i2c_device = {
  57. .name = "i2c_davinci",
  58. .id = 1,
  59. .num_resources = ARRAY_SIZE(i2c_resources),
  60. .resource = i2c_resources,
  61. };
  62. void __init davinci_init_i2c(struct davinci_i2c_platform_data *pdata)
  63. {
  64. if (cpu_is_davinci_dm644x())
  65. davinci_cfg_reg(DM644X_I2C);
  66. davinci_i2c_device.dev.platform_data = pdata;
  67. (void) platform_device_register(&davinci_i2c_device);
  68. }
  69. static struct resource ide_resources[] = {
  70. {
  71. .start = DAVINCI_ATA_BASE,
  72. .end = DAVINCI_ATA_BASE + 0x7ff,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. {
  76. .start = IRQ_IDE,
  77. .end = IRQ_IDE,
  78. .flags = IORESOURCE_IRQ,
  79. },
  80. };
  81. static u64 ide_dma_mask = DMA_BIT_MASK(32);
  82. static struct platform_device ide_device = {
  83. .name = "palm_bk3710",
  84. .id = -1,
  85. .resource = ide_resources,
  86. .num_resources = ARRAY_SIZE(ide_resources),
  87. .dev = {
  88. .dma_mask = &ide_dma_mask,
  89. .coherent_dma_mask = DMA_BIT_MASK(32),
  90. },
  91. };
  92. void __init davinci_init_ide(void)
  93. {
  94. if (cpu_is_davinci_dm644x()) {
  95. davinci_cfg_reg(DM644X_HPIEN_DISABLE);
  96. davinci_cfg_reg(DM644X_ATAEN);
  97. davinci_cfg_reg(DM644X_HDIREN);
  98. } else if (cpu_is_davinci_dm646x()) {
  99. /* IRQ_DM646X_IDE is the same as IRQ_IDE */
  100. davinci_cfg_reg(DM646X_ATAEN);
  101. } else {
  102. WARN_ON(1);
  103. return;
  104. }
  105. platform_device_register(&ide_device);
  106. }
  107. #if IS_ENABLED(CONFIG_MMC_DAVINCI)
  108. static u64 mmcsd0_dma_mask = DMA_BIT_MASK(32);
  109. static struct resource mmcsd0_resources[] = {
  110. {
  111. /* different on dm355 */
  112. .start = DAVINCI_MMCSD0_BASE,
  113. .end = DAVINCI_MMCSD0_BASE + SZ_4K - 1,
  114. .flags = IORESOURCE_MEM,
  115. },
  116. /* IRQs: MMC/SD, then SDIO */
  117. {
  118. .start = IRQ_MMCINT,
  119. .flags = IORESOURCE_IRQ,
  120. }, {
  121. /* different on dm355 */
  122. .start = IRQ_SDIOINT,
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. };
  126. static struct platform_device davinci_mmcsd0_device = {
  127. .name = "dm6441-mmc",
  128. .id = 0,
  129. .dev = {
  130. .dma_mask = &mmcsd0_dma_mask,
  131. .coherent_dma_mask = DMA_BIT_MASK(32),
  132. },
  133. .num_resources = ARRAY_SIZE(mmcsd0_resources),
  134. .resource = mmcsd0_resources,
  135. };
  136. static u64 mmcsd1_dma_mask = DMA_BIT_MASK(32);
  137. static struct resource mmcsd1_resources[] = {
  138. {
  139. .start = DM355_MMCSD1_BASE,
  140. .end = DM355_MMCSD1_BASE + SZ_4K - 1,
  141. .flags = IORESOURCE_MEM,
  142. },
  143. /* IRQs: MMC/SD, then SDIO */
  144. {
  145. .start = IRQ_DM355_MMCINT1,
  146. .flags = IORESOURCE_IRQ,
  147. }, {
  148. .start = IRQ_DM355_SDIOINT1,
  149. .flags = IORESOURCE_IRQ,
  150. },
  151. };
  152. static struct platform_device davinci_mmcsd1_device = {
  153. .name = "dm6441-mmc",
  154. .id = 1,
  155. .dev = {
  156. .dma_mask = &mmcsd1_dma_mask,
  157. .coherent_dma_mask = DMA_BIT_MASK(32),
  158. },
  159. .num_resources = ARRAY_SIZE(mmcsd1_resources),
  160. .resource = mmcsd1_resources,
  161. };
  162. void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
  163. {
  164. struct platform_device *pdev = NULL;
  165. if (WARN_ON(cpu_is_davinci_dm646x()))
  166. return;
  167. /* REVISIT: update PINMUX, ARM_IRQMUX, and EDMA_EVTMUX here too;
  168. * for example if MMCSD1 is used for SDIO, maybe DAT2 is unused.
  169. *
  170. * FIXME dm6441 (no MMC/SD), dm357 (one), and dm335 (two) are
  171. * not handled right here ...
  172. */
  173. switch (module) {
  174. case 1:
  175. if (cpu_is_davinci_dm355()) {
  176. /* REVISIT we may not need all these pins if e.g. this
  177. * is a hard-wired SDIO device...
  178. */
  179. davinci_cfg_reg(DM355_SD1_CMD);
  180. davinci_cfg_reg(DM355_SD1_CLK);
  181. davinci_cfg_reg(DM355_SD1_DATA0);
  182. davinci_cfg_reg(DM355_SD1_DATA1);
  183. davinci_cfg_reg(DM355_SD1_DATA2);
  184. davinci_cfg_reg(DM355_SD1_DATA3);
  185. } else if (cpu_is_davinci_dm365()) {
  186. /* Configure pull down control */
  187. unsigned v;
  188. v = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_PUPDCTL1));
  189. __raw_writel(v & ~0xfc0,
  190. DAVINCI_SYSMOD_VIRT(SYSMOD_PUPDCTL1));
  191. mmcsd1_resources[0].start = DM365_MMCSD1_BASE;
  192. mmcsd1_resources[0].end = DM365_MMCSD1_BASE +
  193. SZ_4K - 1;
  194. mmcsd1_resources[2].start = IRQ_DM365_SDIOINT1;
  195. davinci_mmcsd1_device.name = "da830-mmc";
  196. } else
  197. break;
  198. pdev = &davinci_mmcsd1_device;
  199. break;
  200. case 0:
  201. if (cpu_is_davinci_dm355()) {
  202. mmcsd0_resources[0].start = DM355_MMCSD0_BASE;
  203. mmcsd0_resources[0].end = DM355_MMCSD0_BASE + SZ_4K - 1;
  204. mmcsd0_resources[2].start = IRQ_DM355_SDIOINT0;
  205. /* expose all 6 MMC0 signals: CLK, CMD, DATA[0..3] */
  206. davinci_cfg_reg(DM355_MMCSD0);
  207. /* enable RX EDMA */
  208. davinci_cfg_reg(DM355_EVT26_MMC0_RX);
  209. } else if (cpu_is_davinci_dm365()) {
  210. mmcsd0_resources[0].start = DM365_MMCSD0_BASE;
  211. mmcsd0_resources[0].end = DM365_MMCSD0_BASE +
  212. SZ_4K - 1;
  213. mmcsd0_resources[2].start = IRQ_DM365_SDIOINT0;
  214. davinci_mmcsd0_device.name = "da830-mmc";
  215. } else if (cpu_is_davinci_dm644x()) {
  216. /* REVISIT: should this be in board-init code? */
  217. /* Power-on 3.3V IO cells */
  218. __raw_writel(0,
  219. DAVINCI_SYSMOD_VIRT(SYSMOD_VDD3P3VPWDN));
  220. /*Set up the pull regiter for MMC */
  221. davinci_cfg_reg(DM644X_MSTK);
  222. }
  223. pdev = &davinci_mmcsd0_device;
  224. break;
  225. }
  226. if (WARN_ON(!pdev))
  227. return;
  228. pdev->dev.platform_data = config;
  229. platform_device_register(pdev);
  230. }
  231. #else
  232. void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
  233. {
  234. }
  235. #endif
  236. /*-------------------------------------------------------------------------*/
  237. static struct resource wdt_resources[] = {
  238. {
  239. .start = DAVINCI_WDOG_BASE,
  240. .end = DAVINCI_WDOG_BASE + SZ_1K - 1,
  241. .flags = IORESOURCE_MEM,
  242. },
  243. };
  244. struct platform_device davinci_wdt_device = {
  245. .name = "davinci-wdt",
  246. .id = -1,
  247. .num_resources = ARRAY_SIZE(wdt_resources),
  248. .resource = wdt_resources,
  249. };
  250. void davinci_restart(enum reboot_mode mode, const char *cmd)
  251. {
  252. davinci_watchdog_reset(&davinci_wdt_device);
  253. }
  254. int davinci_init_wdt(void)
  255. {
  256. return platform_device_register(&davinci_wdt_device);
  257. }
  258. static struct platform_device davinci_gpio_device = {
  259. .name = "davinci_gpio",
  260. .id = -1,
  261. };
  262. int davinci_gpio_register(struct resource *res, int size, void *pdata)
  263. {
  264. davinci_gpio_device.resource = res;
  265. davinci_gpio_device.num_resources = size;
  266. davinci_gpio_device.dev.platform_data = pdata;
  267. return platform_device_register(&davinci_gpio_device);
  268. }
  269. /*-------------------------------------------------------------------------*/
  270. /*-------------------------------------------------------------------------*/
  271. struct davinci_timer_instance davinci_timer_instance[2] = {
  272. {
  273. .base = DAVINCI_TIMER0_BASE,
  274. .bottom_irq = IRQ_TINT0_TINT12,
  275. .top_irq = IRQ_TINT0_TINT34,
  276. },
  277. {
  278. .base = DAVINCI_TIMER1_BASE,
  279. .bottom_irq = IRQ_TINT1_TINT12,
  280. .top_irq = IRQ_TINT1_TINT34,
  281. },
  282. };