devices.c 9.4 KB

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