devices.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * linux/arch/arm/mach-omap1/devices.c
  3. *
  4. * OMAP1 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/dma-mapping.h>
  12. #include <linux/gpio.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/spi/spi.h>
  18. #include <asm/mach/map.h>
  19. #include <plat/tc.h>
  20. #include <plat/mux.h>
  21. #include <plat/dma.h>
  22. #include <plat/mmc.h>
  23. #include <plat/omap7xx.h>
  24. #include <mach/camera.h>
  25. #include <mach/hardware.h>
  26. #include "common.h"
  27. #include "clock.h"
  28. #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
  29. static struct platform_device omap_pcm = {
  30. .name = "omap-pcm-audio",
  31. .id = -1,
  32. };
  33. static void omap_init_audio(void)
  34. {
  35. platform_device_register(&omap_pcm);
  36. }
  37. #else
  38. static inline void omap_init_audio(void) {}
  39. #endif
  40. /*-------------------------------------------------------------------------*/
  41. #if defined(CONFIG_RTC_DRV_OMAP) || defined(CONFIG_RTC_DRV_OMAP_MODULE)
  42. #define OMAP_RTC_BASE 0xfffb4800
  43. static struct resource rtc_resources[] = {
  44. {
  45. .start = OMAP_RTC_BASE,
  46. .end = OMAP_RTC_BASE + 0x5f,
  47. .flags = IORESOURCE_MEM,
  48. },
  49. {
  50. .start = INT_RTC_TIMER,
  51. .flags = IORESOURCE_IRQ,
  52. },
  53. {
  54. .start = INT_RTC_ALARM,
  55. .flags = IORESOURCE_IRQ,
  56. },
  57. };
  58. static struct platform_device omap_rtc_device = {
  59. .name = "omap_rtc",
  60. .id = -1,
  61. .num_resources = ARRAY_SIZE(rtc_resources),
  62. .resource = rtc_resources,
  63. };
  64. static void omap_init_rtc(void)
  65. {
  66. (void) platform_device_register(&omap_rtc_device);
  67. }
  68. #else
  69. static inline void omap_init_rtc(void) {}
  70. #endif
  71. static inline void omap_init_mbox(void) { }
  72. /*-------------------------------------------------------------------------*/
  73. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
  74. static inline void omap1_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
  75. int controller_nr)
  76. {
  77. if (controller_nr == 0) {
  78. if (cpu_is_omap7xx()) {
  79. omap_cfg_reg(MMC_7XX_CMD);
  80. omap_cfg_reg(MMC_7XX_CLK);
  81. omap_cfg_reg(MMC_7XX_DAT0);
  82. } else {
  83. omap_cfg_reg(MMC_CMD);
  84. omap_cfg_reg(MMC_CLK);
  85. omap_cfg_reg(MMC_DAT0);
  86. }
  87. if (cpu_is_omap1710()) {
  88. omap_cfg_reg(M15_1710_MMC_CLKI);
  89. omap_cfg_reg(P19_1710_MMC_CMDDIR);
  90. omap_cfg_reg(P20_1710_MMC_DATDIR0);
  91. }
  92. if (mmc_controller->slots[0].wires == 4 && !cpu_is_omap7xx()) {
  93. omap_cfg_reg(MMC_DAT1);
  94. /* NOTE: DAT2 can be on W10 (here) or M15 */
  95. if (!mmc_controller->slots[0].nomux)
  96. omap_cfg_reg(MMC_DAT2);
  97. omap_cfg_reg(MMC_DAT3);
  98. }
  99. }
  100. /* Block 2 is on newer chips, and has many pinout options */
  101. if (cpu_is_omap16xx() && controller_nr == 1) {
  102. if (!mmc_controller->slots[1].nomux) {
  103. omap_cfg_reg(Y8_1610_MMC2_CMD);
  104. omap_cfg_reg(Y10_1610_MMC2_CLK);
  105. omap_cfg_reg(R18_1610_MMC2_CLKIN);
  106. omap_cfg_reg(W8_1610_MMC2_DAT0);
  107. if (mmc_controller->slots[1].wires == 4) {
  108. omap_cfg_reg(V8_1610_MMC2_DAT1);
  109. omap_cfg_reg(W15_1610_MMC2_DAT2);
  110. omap_cfg_reg(R10_1610_MMC2_DAT3);
  111. }
  112. /* These are needed for the level shifter */
  113. omap_cfg_reg(V9_1610_MMC2_CMDDIR);
  114. omap_cfg_reg(V5_1610_MMC2_DATDIR0);
  115. omap_cfg_reg(W19_1610_MMC2_DATDIR1);
  116. }
  117. /* Feedback clock must be set on OMAP-1710 MMC2 */
  118. if (cpu_is_omap1710())
  119. omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
  120. MOD_CONF_CTRL_1);
  121. }
  122. }
  123. #define OMAP_MMC_NR_RES 4
  124. /*
  125. * Register MMC devices.
  126. */
  127. static int __init omap_mmc_add(const char *name, int id, unsigned long base,
  128. unsigned long size, unsigned int irq,
  129. unsigned rx_req, unsigned tx_req,
  130. struct omap_mmc_platform_data *data)
  131. {
  132. struct platform_device *pdev;
  133. struct resource res[OMAP_MMC_NR_RES];
  134. int ret;
  135. pdev = platform_device_alloc(name, id);
  136. if (!pdev)
  137. return -ENOMEM;
  138. memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
  139. res[0].start = base;
  140. res[0].end = base + size - 1;
  141. res[0].flags = IORESOURCE_MEM;
  142. res[1].start = res[1].end = irq;
  143. res[1].flags = IORESOURCE_IRQ;
  144. res[2].start = rx_req;
  145. res[2].name = "rx";
  146. res[2].flags = IORESOURCE_DMA;
  147. res[3].start = tx_req;
  148. res[3].name = "tx";
  149. res[3].flags = IORESOURCE_DMA;
  150. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  151. if (ret == 0)
  152. ret = platform_device_add_data(pdev, data, sizeof(*data));
  153. if (ret)
  154. goto fail;
  155. ret = platform_device_add(pdev);
  156. if (ret)
  157. goto fail;
  158. /* return device handle to board setup code */
  159. data->dev = &pdev->dev;
  160. return 0;
  161. fail:
  162. platform_device_put(pdev);
  163. return ret;
  164. }
  165. void __init omap1_init_mmc(struct omap_mmc_platform_data **mmc_data,
  166. int nr_controllers)
  167. {
  168. int i;
  169. for (i = 0; i < nr_controllers; i++) {
  170. unsigned long base, size;
  171. unsigned rx_req, tx_req;
  172. unsigned int irq = 0;
  173. if (!mmc_data[i])
  174. continue;
  175. omap1_mmc_mux(mmc_data[i], i);
  176. switch (i) {
  177. case 0:
  178. base = OMAP1_MMC1_BASE;
  179. irq = INT_MMC;
  180. rx_req = OMAP_DMA_MMC_RX;
  181. tx_req = OMAP_DMA_MMC_TX;
  182. break;
  183. case 1:
  184. if (!cpu_is_omap16xx())
  185. return;
  186. base = OMAP1_MMC2_BASE;
  187. irq = INT_1610_MMC2;
  188. rx_req = OMAP_DMA_MMC2_RX;
  189. tx_req = OMAP_DMA_MMC2_TX;
  190. break;
  191. default:
  192. continue;
  193. }
  194. size = OMAP1_MMC_SIZE;
  195. omap_mmc_add("mmci-omap", i, base, size, irq,
  196. rx_req, tx_req, mmc_data[i]);
  197. };
  198. }
  199. #endif
  200. /*-------------------------------------------------------------------------*/
  201. /* OMAP7xx SPI support */
  202. #if defined(CONFIG_SPI_OMAP_100K) || defined(CONFIG_SPI_OMAP_100K_MODULE)
  203. struct platform_device omap_spi1 = {
  204. .name = "omap1_spi100k",
  205. .id = 1,
  206. };
  207. struct platform_device omap_spi2 = {
  208. .name = "omap1_spi100k",
  209. .id = 2,
  210. };
  211. static void omap_init_spi100k(void)
  212. {
  213. omap_spi1.dev.platform_data = ioremap(OMAP7XX_SPI1_BASE, 0x7ff);
  214. if (omap_spi1.dev.platform_data)
  215. platform_device_register(&omap_spi1);
  216. omap_spi2.dev.platform_data = ioremap(OMAP7XX_SPI2_BASE, 0x7ff);
  217. if (omap_spi2.dev.platform_data)
  218. platform_device_register(&omap_spi2);
  219. }
  220. #else
  221. static inline void omap_init_spi100k(void)
  222. {
  223. }
  224. #endif
  225. #define OMAP1_CAMERA_BASE 0xfffb6800
  226. #define OMAP1_CAMERA_IOSIZE 0x1c
  227. static struct resource omap1_camera_resources[] = {
  228. [0] = {
  229. .start = OMAP1_CAMERA_BASE,
  230. .end = OMAP1_CAMERA_BASE + OMAP1_CAMERA_IOSIZE - 1,
  231. .flags = IORESOURCE_MEM,
  232. },
  233. [1] = {
  234. .start = INT_CAMERA,
  235. .flags = IORESOURCE_IRQ,
  236. },
  237. };
  238. static u64 omap1_camera_dma_mask = DMA_BIT_MASK(32);
  239. static struct platform_device omap1_camera_device = {
  240. .name = "omap1-camera",
  241. .id = 0, /* This is used to put cameras on this interface */
  242. .dev = {
  243. .dma_mask = &omap1_camera_dma_mask,
  244. .coherent_dma_mask = DMA_BIT_MASK(32),
  245. },
  246. .num_resources = ARRAY_SIZE(omap1_camera_resources),
  247. .resource = omap1_camera_resources,
  248. };
  249. void __init omap1_camera_init(void *info)
  250. {
  251. struct platform_device *dev = &omap1_camera_device;
  252. int ret;
  253. dev->dev.platform_data = info;
  254. ret = platform_device_register(dev);
  255. if (ret)
  256. dev_err(&dev->dev, "unable to register device: %d\n", ret);
  257. }
  258. /*-------------------------------------------------------------------------*/
  259. static inline void omap_init_sti(void) {}
  260. /* Numbering for the SPI-capable controllers when used for SPI:
  261. * spi = 1
  262. * uwire = 2
  263. * mmc1..2 = 3..4
  264. * mcbsp1..3 = 5..7
  265. */
  266. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  267. #define OMAP_UWIRE_BASE 0xfffb3000
  268. static struct resource uwire_resources[] = {
  269. {
  270. .start = OMAP_UWIRE_BASE,
  271. .end = OMAP_UWIRE_BASE + 0x20,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. };
  275. static struct platform_device omap_uwire_device = {
  276. .name = "omap_uwire",
  277. .id = -1,
  278. .num_resources = ARRAY_SIZE(uwire_resources),
  279. .resource = uwire_resources,
  280. };
  281. static void omap_init_uwire(void)
  282. {
  283. /* FIXME define and use a boot tag; not all boards will be hooking
  284. * up devices to the microwire controller, and multi-board configs
  285. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  286. */
  287. /* board-specific code must configure chipselects (only a few
  288. * are normally used) and SCLK/SDI/SDO (each has two choices).
  289. */
  290. (void) platform_device_register(&omap_uwire_device);
  291. }
  292. #else
  293. static inline void omap_init_uwire(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 knowledge 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 omap1_init_devices(void)
  316. {
  317. if (!cpu_class_is_omap1())
  318. return -ENODEV;
  319. omap_sram_init();
  320. omap1_clk_late_init();
  321. /* please keep these calls, and their implementations above,
  322. * in alphabetical order so they're easier to sort through.
  323. */
  324. omap_init_audio();
  325. omap_init_mbox();
  326. omap_init_rtc();
  327. omap_init_spi100k();
  328. omap_init_sti();
  329. omap_init_uwire();
  330. return 0;
  331. }
  332. arch_initcall(omap1_init_devices);
  333. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  334. static struct resource wdt_resources[] = {
  335. {
  336. .start = 0xfffeb000,
  337. .end = 0xfffeb07F,
  338. .flags = IORESOURCE_MEM,
  339. },
  340. };
  341. static struct platform_device omap_wdt_device = {
  342. .name = "omap_wdt",
  343. .id = -1,
  344. .num_resources = ARRAY_SIZE(wdt_resources),
  345. .resource = wdt_resources,
  346. };
  347. static int __init omap_init_wdt(void)
  348. {
  349. if (!cpu_is_omap16xx())
  350. return -ENODEV;
  351. return platform_device_register(&omap_wdt_device);
  352. }
  353. subsys_initcall(omap_init_wdt);
  354. #endif