devices.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /*
  2. * linux/arch/arm/plat-omap/devices.c
  3. *
  4. * Common platform device setup/initialization for OMAP1 and OMAP2
  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/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <mach/hardware.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/mach/map.h>
  19. #include <mach/tc.h>
  20. #include <mach/control.h>
  21. #include <mach/board.h>
  22. #include <mach/mmc.h>
  23. #include <mach/mux.h>
  24. #include <mach/gpio.h>
  25. #include <mach/menelaus.h>
  26. #include <mach/mcbsp.h>
  27. #include <mach/dsp_common.h>
  28. #if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
  29. static struct dsp_platform_data dsp_pdata = {
  30. .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list),
  31. };
  32. static struct resource omap_dsp_resources[] = {
  33. {
  34. .name = "dsp_mmu",
  35. .start = -1,
  36. .flags = IORESOURCE_IRQ,
  37. },
  38. };
  39. static struct platform_device omap_dsp_device = {
  40. .name = "dsp",
  41. .id = -1,
  42. .num_resources = ARRAY_SIZE(omap_dsp_resources),
  43. .resource = omap_dsp_resources,
  44. .dev = {
  45. .platform_data = &dsp_pdata,
  46. },
  47. };
  48. static inline void omap_init_dsp(void)
  49. {
  50. struct resource *res;
  51. int irq;
  52. if (cpu_is_omap15xx())
  53. irq = INT_1510_DSP_MMU;
  54. else if (cpu_is_omap16xx())
  55. irq = INT_1610_DSP_MMU;
  56. else if (cpu_is_omap24xx())
  57. irq = INT_24XX_DSP_MMU;
  58. res = platform_get_resource_byname(&omap_dsp_device,
  59. IORESOURCE_IRQ, "dsp_mmu");
  60. res->start = irq;
  61. platform_device_register(&omap_dsp_device);
  62. }
  63. int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev)
  64. {
  65. static DEFINE_MUTEX(dsp_pdata_lock);
  66. spin_lock_init(&kdev->lock);
  67. mutex_lock(&dsp_pdata_lock);
  68. list_add_tail(&kdev->entry, &dsp_pdata.kdev_list);
  69. mutex_unlock(&dsp_pdata_lock);
  70. return 0;
  71. }
  72. EXPORT_SYMBOL(dsp_kfunc_device_register);
  73. #else
  74. static inline void omap_init_dsp(void) { }
  75. #endif /* CONFIG_OMAP_DSP */
  76. /*-------------------------------------------------------------------------*/
  77. #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE)
  78. static void omap_init_kp(void)
  79. {
  80. /* 2430 and 34xx keypad is on TWL4030 */
  81. if (cpu_is_omap2430() || cpu_is_omap34xx())
  82. return;
  83. if (machine_is_omap_h2() || machine_is_omap_h3()) {
  84. omap_cfg_reg(F18_1610_KBC0);
  85. omap_cfg_reg(D20_1610_KBC1);
  86. omap_cfg_reg(D19_1610_KBC2);
  87. omap_cfg_reg(E18_1610_KBC3);
  88. omap_cfg_reg(C21_1610_KBC4);
  89. omap_cfg_reg(G18_1610_KBR0);
  90. omap_cfg_reg(F19_1610_KBR1);
  91. omap_cfg_reg(H14_1610_KBR2);
  92. omap_cfg_reg(E20_1610_KBR3);
  93. omap_cfg_reg(E19_1610_KBR4);
  94. omap_cfg_reg(N19_1610_KBR5);
  95. } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) {
  96. omap_cfg_reg(E2_730_KBR0);
  97. omap_cfg_reg(J7_730_KBR1);
  98. omap_cfg_reg(E1_730_KBR2);
  99. omap_cfg_reg(F3_730_KBR3);
  100. omap_cfg_reg(D2_730_KBR4);
  101. omap_cfg_reg(C2_730_KBC0);
  102. omap_cfg_reg(D3_730_KBC1);
  103. omap_cfg_reg(E4_730_KBC2);
  104. omap_cfg_reg(F4_730_KBC3);
  105. omap_cfg_reg(E3_730_KBC4);
  106. } else if (machine_is_omap_h4()) {
  107. omap_cfg_reg(T19_24XX_KBR0);
  108. omap_cfg_reg(R19_24XX_KBR1);
  109. omap_cfg_reg(V18_24XX_KBR2);
  110. omap_cfg_reg(M21_24XX_KBR3);
  111. omap_cfg_reg(E5__24XX_KBR4);
  112. if (omap_has_menelaus()) {
  113. omap_cfg_reg(B3__24XX_KBR5);
  114. omap_cfg_reg(AA4_24XX_KBC2);
  115. omap_cfg_reg(B13_24XX_KBC6);
  116. } else {
  117. omap_cfg_reg(M18_24XX_KBR5);
  118. omap_cfg_reg(H19_24XX_KBC2);
  119. omap_cfg_reg(N19_24XX_KBC6);
  120. }
  121. omap_cfg_reg(R20_24XX_KBC0);
  122. omap_cfg_reg(M14_24XX_KBC1);
  123. omap_cfg_reg(V17_24XX_KBC3);
  124. omap_cfg_reg(P21_24XX_KBC4);
  125. omap_cfg_reg(L14_24XX_KBC5);
  126. }
  127. }
  128. #else
  129. static inline void omap_init_kp(void) {}
  130. #endif
  131. /*-------------------------------------------------------------------------*/
  132. #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
  133. static struct platform_device **omap_mcbsp_devices;
  134. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  135. int size)
  136. {
  137. int i;
  138. omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
  139. GFP_KERNEL);
  140. if (!omap_mcbsp_devices) {
  141. printk(KERN_ERR "Could not register McBSP devices\n");
  142. return;
  143. }
  144. for (i = 0; i < size; i++) {
  145. struct platform_device *new_mcbsp;
  146. int ret;
  147. new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
  148. if (!new_mcbsp)
  149. continue;
  150. new_mcbsp->dev.platform_data = &config[i];
  151. ret = platform_device_add(new_mcbsp);
  152. if (ret) {
  153. platform_device_put(new_mcbsp);
  154. continue;
  155. }
  156. omap_mcbsp_devices[i] = new_mcbsp;
  157. }
  158. }
  159. #else
  160. void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
  161. int size)
  162. { }
  163. #endif
  164. /*-------------------------------------------------------------------------*/
  165. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \
  166. defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  167. #define OMAP_MMC_NR_RES 2
  168. /*
  169. * Register MMC devices. Called from mach-omap1 and mach-omap2 device init.
  170. */
  171. int __init omap_mmc_add(const char *name, int id, unsigned long base,
  172. unsigned long size, unsigned int irq,
  173. struct omap_mmc_platform_data *data)
  174. {
  175. struct platform_device *pdev;
  176. struct resource res[OMAP_MMC_NR_RES];
  177. int ret;
  178. pdev = platform_device_alloc(name, id);
  179. if (!pdev)
  180. return -ENOMEM;
  181. memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
  182. res[0].start = base;
  183. res[0].end = base + size - 1;
  184. res[0].flags = IORESOURCE_MEM;
  185. res[1].start = res[1].end = irq;
  186. res[1].flags = IORESOURCE_IRQ;
  187. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  188. if (ret == 0)
  189. ret = platform_device_add_data(pdev, data, sizeof(*data));
  190. if (ret)
  191. goto fail;
  192. ret = platform_device_add(pdev);
  193. if (ret)
  194. goto fail;
  195. return 0;
  196. fail:
  197. platform_device_put(pdev);
  198. return ret;
  199. }
  200. #endif
  201. /*-------------------------------------------------------------------------*/
  202. /* Numbering for the SPI-capable controllers when used for SPI:
  203. * spi = 1
  204. * uwire = 2
  205. * mmc1..2 = 3..4
  206. * mcbsp1..3 = 5..7
  207. */
  208. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  209. #define OMAP_UWIRE_BASE 0xfffb3000
  210. static struct resource uwire_resources[] = {
  211. {
  212. .start = OMAP_UWIRE_BASE,
  213. .end = OMAP_UWIRE_BASE + 0x20,
  214. .flags = IORESOURCE_MEM,
  215. },
  216. };
  217. static struct platform_device omap_uwire_device = {
  218. .name = "omap_uwire",
  219. .id = -1,
  220. .num_resources = ARRAY_SIZE(uwire_resources),
  221. .resource = uwire_resources,
  222. };
  223. static void omap_init_uwire(void)
  224. {
  225. /* FIXME define and use a boot tag; not all boards will be hooking
  226. * up devices to the microwire controller, and multi-board configs
  227. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  228. */
  229. /* board-specific code must configure chipselects (only a few
  230. * are normally used) and SCLK/SDI/SDO (each has two choices).
  231. */
  232. (void) platform_device_register(&omap_uwire_device);
  233. }
  234. #else
  235. static inline void omap_init_uwire(void) {}
  236. #endif
  237. /*-------------------------------------------------------------------------*/
  238. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  239. static struct resource wdt_resources[] = {
  240. {
  241. .flags = IORESOURCE_MEM,
  242. },
  243. };
  244. static struct platform_device omap_wdt_device = {
  245. .name = "omap_wdt",
  246. .id = -1,
  247. .num_resources = ARRAY_SIZE(wdt_resources),
  248. .resource = wdt_resources,
  249. };
  250. static void omap_init_wdt(void)
  251. {
  252. if (cpu_is_omap16xx())
  253. wdt_resources[0].start = 0xfffeb000;
  254. else if (cpu_is_omap2420())
  255. wdt_resources[0].start = 0x48022000; /* WDT2 */
  256. else if (cpu_is_omap2430())
  257. wdt_resources[0].start = 0x49016000; /* WDT2 */
  258. else if (cpu_is_omap343x())
  259. wdt_resources[0].start = 0x48314000; /* WDT2 */
  260. else
  261. return;
  262. wdt_resources[0].end = wdt_resources[0].start + 0x4f;
  263. (void) platform_device_register(&omap_wdt_device);
  264. }
  265. #else
  266. static inline void omap_init_wdt(void) {}
  267. #endif
  268. /*-------------------------------------------------------------------------*/
  269. #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE)
  270. #ifdef CONFIG_ARCH_OMAP24XX
  271. #define OMAP_RNG_BASE 0x480A0000
  272. #else
  273. #define OMAP_RNG_BASE 0xfffe5000
  274. #endif
  275. static struct resource rng_resources[] = {
  276. {
  277. .start = OMAP_RNG_BASE,
  278. .end = OMAP_RNG_BASE + 0x4f,
  279. .flags = IORESOURCE_MEM,
  280. },
  281. };
  282. static struct platform_device omap_rng_device = {
  283. .name = "omap_rng",
  284. .id = -1,
  285. .num_resources = ARRAY_SIZE(rng_resources),
  286. .resource = rng_resources,
  287. };
  288. static void omap_init_rng(void)
  289. {
  290. (void) platform_device_register(&omap_rng_device);
  291. }
  292. #else
  293. static inline void omap_init_rng(void) {}
  294. #endif
  295. /*
  296. * This gets called after board-specific INIT_MACHINE, and initializes most
  297. * on-chip peripherals accessible on this board (except for few like USB):
  298. *
  299. * (a) Does any "standard config" pin muxing needed. Board-specific
  300. * code will have muxed GPIO pins and done "nonstandard" setup;
  301. * that code could live in the boot loader.
  302. * (b) Populating board-specific platform_data with the data drivers
  303. * rely on to handle wiring variations.
  304. * (c) Creating platform devices as meaningful on this board and
  305. * with this kernel configuration.
  306. *
  307. * Claiming GPIOs, and setting their direction and initial values, is the
  308. * responsibility of the device drivers. So is responding to probe().
  309. *
  310. * Board-specific knowlege like creating devices or pin setup is to be
  311. * kept out of drivers as much as possible. In particular, pin setup
  312. * may be handled by the boot loader, and drivers should expect it will
  313. * normally have been done by the time they're probed.
  314. */
  315. static int __init omap_init_devices(void)
  316. {
  317. /* please keep these calls, and their implementations above,
  318. * in alphabetical order so they're easier to sort through.
  319. */
  320. omap_init_dsp();
  321. omap_init_kp();
  322. omap_init_uwire();
  323. omap_init_wdt();
  324. omap_init_rng();
  325. return 0;
  326. }
  327. arch_initcall(omap_init_devices);