devices.c 11 KB

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