devices.c 7.8 KB

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