devices.c 11 KB

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