devices.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 <linux/platform_data/omap-wd-timer.h>
  19. #include <asm/mach/map.h>
  20. #include <mach/tc.h>
  21. #include <mach/mux.h>
  22. #include <mach/omap7xx.h>
  23. #include <mach/camera.h>
  24. #include <mach/hardware.h>
  25. #include "common.h"
  26. #include "clock.h"
  27. #include "mmc.h"
  28. #include "sram.h"
  29. #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
  30. static struct platform_device omap_pcm = {
  31. .name = "omap-pcm-audio",
  32. .id = -1,
  33. };
  34. static void omap_init_audio(void)
  35. {
  36. platform_device_register(&omap_pcm);
  37. }
  38. #else
  39. static inline void omap_init_audio(void) {}
  40. #endif
  41. /*-------------------------------------------------------------------------*/
  42. #if defined(CONFIG_RTC_DRV_OMAP) || defined(CONFIG_RTC_DRV_OMAP_MODULE)
  43. #define OMAP_RTC_BASE 0xfffb4800
  44. static struct resource rtc_resources[] = {
  45. {
  46. .start = OMAP_RTC_BASE,
  47. .end = OMAP_RTC_BASE + 0x5f,
  48. .flags = IORESOURCE_MEM,
  49. },
  50. {
  51. .start = INT_RTC_TIMER,
  52. .flags = IORESOURCE_IRQ,
  53. },
  54. {
  55. .start = INT_RTC_ALARM,
  56. .flags = IORESOURCE_IRQ,
  57. },
  58. };
  59. static struct platform_device omap_rtc_device = {
  60. .name = "omap_rtc",
  61. .id = -1,
  62. .num_resources = ARRAY_SIZE(rtc_resources),
  63. .resource = rtc_resources,
  64. };
  65. static void omap_init_rtc(void)
  66. {
  67. (void) platform_device_register(&omap_rtc_device);
  68. }
  69. #else
  70. static inline void omap_init_rtc(void) {}
  71. #endif
  72. static inline void omap_init_mbox(void) { }
  73. /*-------------------------------------------------------------------------*/
  74. #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
  75. static inline void omap1_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
  76. int controller_nr)
  77. {
  78. if (controller_nr == 0) {
  79. if (cpu_is_omap7xx()) {
  80. omap_cfg_reg(MMC_7XX_CMD);
  81. omap_cfg_reg(MMC_7XX_CLK);
  82. omap_cfg_reg(MMC_7XX_DAT0);
  83. } else {
  84. omap_cfg_reg(MMC_CMD);
  85. omap_cfg_reg(MMC_CLK);
  86. omap_cfg_reg(MMC_DAT0);
  87. }
  88. if (cpu_is_omap1710()) {
  89. omap_cfg_reg(M15_1710_MMC_CLKI);
  90. omap_cfg_reg(P19_1710_MMC_CMDDIR);
  91. omap_cfg_reg(P20_1710_MMC_DATDIR0);
  92. }
  93. if (mmc_controller->slots[0].wires == 4 && !cpu_is_omap7xx()) {
  94. omap_cfg_reg(MMC_DAT1);
  95. /* NOTE: DAT2 can be on W10 (here) or M15 */
  96. if (!mmc_controller->slots[0].nomux)
  97. omap_cfg_reg(MMC_DAT2);
  98. omap_cfg_reg(MMC_DAT3);
  99. }
  100. }
  101. /* Block 2 is on newer chips, and has many pinout options */
  102. if (cpu_is_omap16xx() && controller_nr == 1) {
  103. if (!mmc_controller->slots[1].nomux) {
  104. omap_cfg_reg(Y8_1610_MMC2_CMD);
  105. omap_cfg_reg(Y10_1610_MMC2_CLK);
  106. omap_cfg_reg(R18_1610_MMC2_CLKIN);
  107. omap_cfg_reg(W8_1610_MMC2_DAT0);
  108. if (mmc_controller->slots[1].wires == 4) {
  109. omap_cfg_reg(V8_1610_MMC2_DAT1);
  110. omap_cfg_reg(W15_1610_MMC2_DAT2);
  111. omap_cfg_reg(R10_1610_MMC2_DAT3);
  112. }
  113. /* These are needed for the level shifter */
  114. omap_cfg_reg(V9_1610_MMC2_CMDDIR);
  115. omap_cfg_reg(V5_1610_MMC2_DATDIR0);
  116. omap_cfg_reg(W19_1610_MMC2_DATDIR1);
  117. }
  118. /* Feedback clock must be set on OMAP-1710 MMC2 */
  119. if (cpu_is_omap1710())
  120. omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
  121. MOD_CONF_CTRL_1);
  122. }
  123. }
  124. #define OMAP_MMC_NR_RES 4
  125. /*
  126. * Register MMC devices.
  127. */
  128. static int __init omap_mmc_add(const char *name, int id, unsigned long base,
  129. unsigned long size, unsigned int irq,
  130. unsigned rx_req, unsigned tx_req,
  131. struct omap_mmc_platform_data *data)
  132. {
  133. struct platform_device *pdev;
  134. struct resource res[OMAP_MMC_NR_RES];
  135. int ret;
  136. pdev = platform_device_alloc(name, id);
  137. if (!pdev)
  138. return -ENOMEM;
  139. memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
  140. res[0].start = base;
  141. res[0].end = base + size - 1;
  142. res[0].flags = IORESOURCE_MEM;
  143. res[1].start = res[1].end = irq;
  144. res[1].flags = IORESOURCE_IRQ;
  145. res[2].start = rx_req;
  146. res[2].name = "rx";
  147. res[2].flags = IORESOURCE_DMA;
  148. res[3].start = tx_req;
  149. res[3].name = "tx";
  150. res[3].flags = IORESOURCE_DMA;
  151. if (cpu_is_omap7xx())
  152. data->slots[0].features = MMC_OMAP7XX;
  153. if (cpu_is_omap15xx())
  154. data->slots[0].features = MMC_OMAP15XX;
  155. if (cpu_is_omap16xx())
  156. data->slots[0].features = MMC_OMAP16XX;
  157. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  158. if (ret == 0)
  159. ret = platform_device_add_data(pdev, data, sizeof(*data));
  160. if (ret)
  161. goto fail;
  162. ret = platform_device_add(pdev);
  163. if (ret)
  164. goto fail;
  165. /* return device handle to board setup code */
  166. data->dev = &pdev->dev;
  167. return 0;
  168. fail:
  169. platform_device_put(pdev);
  170. return ret;
  171. }
  172. void __init omap1_init_mmc(struct omap_mmc_platform_data **mmc_data,
  173. int nr_controllers)
  174. {
  175. int i;
  176. for (i = 0; i < nr_controllers; i++) {
  177. unsigned long base, size;
  178. unsigned rx_req, tx_req;
  179. unsigned int irq = 0;
  180. if (!mmc_data[i])
  181. continue;
  182. omap1_mmc_mux(mmc_data[i], i);
  183. switch (i) {
  184. case 0:
  185. base = OMAP1_MMC1_BASE;
  186. irq = INT_MMC;
  187. rx_req = 22;
  188. tx_req = 21;
  189. break;
  190. case 1:
  191. if (!cpu_is_omap16xx())
  192. return;
  193. base = OMAP1_MMC2_BASE;
  194. irq = INT_1610_MMC2;
  195. rx_req = 55;
  196. tx_req = 54;
  197. break;
  198. default:
  199. continue;
  200. }
  201. size = OMAP1_MMC_SIZE;
  202. omap_mmc_add("mmci-omap", i, base, size, irq,
  203. rx_req, tx_req, mmc_data[i]);
  204. }
  205. }
  206. #endif
  207. /*-------------------------------------------------------------------------*/
  208. /* OMAP7xx SPI support */
  209. #if defined(CONFIG_SPI_OMAP_100K) || defined(CONFIG_SPI_OMAP_100K_MODULE)
  210. struct platform_device omap_spi1 = {
  211. .name = "omap1_spi100k",
  212. .id = 1,
  213. };
  214. struct platform_device omap_spi2 = {
  215. .name = "omap1_spi100k",
  216. .id = 2,
  217. };
  218. static void omap_init_spi100k(void)
  219. {
  220. omap_spi1.dev.platform_data = ioremap(OMAP7XX_SPI1_BASE, 0x7ff);
  221. if (omap_spi1.dev.platform_data)
  222. platform_device_register(&omap_spi1);
  223. omap_spi2.dev.platform_data = ioremap(OMAP7XX_SPI2_BASE, 0x7ff);
  224. if (omap_spi2.dev.platform_data)
  225. platform_device_register(&omap_spi2);
  226. }
  227. #else
  228. static inline void omap_init_spi100k(void)
  229. {
  230. }
  231. #endif
  232. #define OMAP1_CAMERA_BASE 0xfffb6800
  233. #define OMAP1_CAMERA_IOSIZE 0x1c
  234. static struct resource omap1_camera_resources[] = {
  235. [0] = {
  236. .start = OMAP1_CAMERA_BASE,
  237. .end = OMAP1_CAMERA_BASE + OMAP1_CAMERA_IOSIZE - 1,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. [1] = {
  241. .start = INT_CAMERA,
  242. .flags = IORESOURCE_IRQ,
  243. },
  244. };
  245. static u64 omap1_camera_dma_mask = DMA_BIT_MASK(32);
  246. static struct platform_device omap1_camera_device = {
  247. .name = "omap1-camera",
  248. .id = 0, /* This is used to put cameras on this interface */
  249. .dev = {
  250. .dma_mask = &omap1_camera_dma_mask,
  251. .coherent_dma_mask = DMA_BIT_MASK(32),
  252. },
  253. .num_resources = ARRAY_SIZE(omap1_camera_resources),
  254. .resource = omap1_camera_resources,
  255. };
  256. void __init omap1_camera_init(void *info)
  257. {
  258. struct platform_device *dev = &omap1_camera_device;
  259. int ret;
  260. dev->dev.platform_data = info;
  261. ret = platform_device_register(dev);
  262. if (ret)
  263. dev_err(&dev->dev, "unable to register device: %d\n", ret);
  264. }
  265. /*-------------------------------------------------------------------------*/
  266. static inline void omap_init_sti(void) {}
  267. /* Numbering for the SPI-capable controllers when used for SPI:
  268. * spi = 1
  269. * uwire = 2
  270. * mmc1..2 = 3..4
  271. * mcbsp1..3 = 5..7
  272. */
  273. #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
  274. #define OMAP_UWIRE_BASE 0xfffb3000
  275. static struct resource uwire_resources[] = {
  276. {
  277. .start = OMAP_UWIRE_BASE,
  278. .end = OMAP_UWIRE_BASE + 0x20,
  279. .flags = IORESOURCE_MEM,
  280. },
  281. };
  282. static struct platform_device omap_uwire_device = {
  283. .name = "omap_uwire",
  284. .id = -1,
  285. .num_resources = ARRAY_SIZE(uwire_resources),
  286. .resource = uwire_resources,
  287. };
  288. static void omap_init_uwire(void)
  289. {
  290. /* FIXME define and use a boot tag; not all boards will be hooking
  291. * up devices to the microwire controller, and multi-board configs
  292. * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
  293. */
  294. /* board-specific code must configure chipselects (only a few
  295. * are normally used) and SCLK/SDI/SDO (each has two choices).
  296. */
  297. (void) platform_device_register(&omap_uwire_device);
  298. }
  299. #else
  300. static inline void omap_init_uwire(void) {}
  301. #endif
  302. #define OMAP1_RNG_BASE 0xfffe5000
  303. static struct resource omap1_rng_resources[] = {
  304. {
  305. .start = OMAP1_RNG_BASE,
  306. .end = OMAP1_RNG_BASE + 0x4f,
  307. .flags = IORESOURCE_MEM,
  308. },
  309. };
  310. static struct platform_device omap1_rng_device = {
  311. .name = "omap_rng",
  312. .id = -1,
  313. .num_resources = ARRAY_SIZE(omap1_rng_resources),
  314. .resource = omap1_rng_resources,
  315. };
  316. static void omap1_init_rng(void)
  317. {
  318. if (!cpu_is_omap16xx())
  319. return;
  320. (void) platform_device_register(&omap1_rng_device);
  321. }
  322. /*-------------------------------------------------------------------------*/
  323. /*
  324. * This gets called after board-specific INIT_MACHINE, and initializes most
  325. * on-chip peripherals accessible on this board (except for few like USB):
  326. *
  327. * (a) Does any "standard config" pin muxing needed. Board-specific
  328. * code will have muxed GPIO pins and done "nonstandard" setup;
  329. * that code could live in the boot loader.
  330. * (b) Populating board-specific platform_data with the data drivers
  331. * rely on to handle wiring variations.
  332. * (c) Creating platform devices as meaningful on this board and
  333. * with this kernel configuration.
  334. *
  335. * Claiming GPIOs, and setting their direction and initial values, is the
  336. * responsibility of the device drivers. So is responding to probe().
  337. *
  338. * Board-specific knowledge like creating devices or pin setup is to be
  339. * kept out of drivers as much as possible. In particular, pin setup
  340. * may be handled by the boot loader, and drivers should expect it will
  341. * normally have been done by the time they're probed.
  342. */
  343. static int __init omap1_init_devices(void)
  344. {
  345. if (!cpu_class_is_omap1())
  346. return -ENODEV;
  347. omap_sram_init();
  348. omap1_clk_late_init();
  349. /* please keep these calls, and their implementations above,
  350. * in alphabetical order so they're easier to sort through.
  351. */
  352. omap_init_audio();
  353. omap_init_mbox();
  354. omap_init_rtc();
  355. omap_init_spi100k();
  356. omap_init_sti();
  357. omap_init_uwire();
  358. omap1_init_rng();
  359. return 0;
  360. }
  361. arch_initcall(omap1_init_devices);
  362. #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
  363. static struct resource wdt_resources[] = {
  364. {
  365. .start = 0xfffeb000,
  366. .end = 0xfffeb07F,
  367. .flags = IORESOURCE_MEM,
  368. },
  369. };
  370. static struct platform_device omap_wdt_device = {
  371. .name = "omap_wdt",
  372. .id = -1,
  373. .num_resources = ARRAY_SIZE(wdt_resources),
  374. .resource = wdt_resources,
  375. };
  376. static int __init omap_init_wdt(void)
  377. {
  378. struct omap_wd_timer_platform_data pdata;
  379. int ret;
  380. if (!cpu_is_omap16xx())
  381. return -ENODEV;
  382. pdata.read_reset_sources = omap1_get_reset_sources;
  383. ret = platform_device_register(&omap_wdt_device);
  384. if (!ret) {
  385. ret = platform_device_add_data(&omap_wdt_device, &pdata,
  386. sizeof(pdata));
  387. if (ret)
  388. platform_device_del(&omap_wdt_device);
  389. }
  390. return ret;
  391. }
  392. subsys_initcall(omap_init_wdt);
  393. #endif