devices.c 11 KB

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