mcbsp.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-omap1/mcbsp.c
  4. *
  5. * Copyright (C) 2008 Instituto Nokia de Tecnologia
  6. * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
  7. *
  8. * Multichannel mode not supported.
  9. */
  10. #include <linux/ioport.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/clk.h>
  14. #include <linux/err.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <linux/omap-dma.h>
  19. #include <linux/soc/ti/omap1-io.h>
  20. #include <linux/platform_data/asoc-ti-mcbsp.h>
  21. #include "mux.h"
  22. #include "soc.h"
  23. #include "irqs.h"
  24. #include "iomap.h"
  25. #define DPS_RSTCT2_PER_EN (1 << 0)
  26. #define DSP_RSTCT2_WD_PER_EN (1 << 1)
  27. static int dsp_use;
  28. static struct clk *api_clk;
  29. static struct clk *dsp_clk;
  30. static struct platform_device **omap_mcbsp_devices;
  31. static void omap1_mcbsp_request(unsigned int id)
  32. {
  33. /*
  34. * On 1510, 1610 and 1710, McBSP1 and McBSP3
  35. * are DSP public peripherals.
  36. */
  37. if (id == 0 || id == 2) {
  38. if (dsp_use++ == 0) {
  39. api_clk = clk_get(NULL, "api_ck");
  40. dsp_clk = clk_get(NULL, "dsp_ck");
  41. if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
  42. clk_prepare_enable(api_clk);
  43. clk_prepare_enable(dsp_clk);
  44. /*
  45. * DSP external peripheral reset
  46. * FIXME: This should be moved to dsp code
  47. */
  48. __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
  49. DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
  50. }
  51. }
  52. }
  53. }
  54. static void omap1_mcbsp_free(unsigned int id)
  55. {
  56. if (id == 0 || id == 2) {
  57. if (--dsp_use == 0) {
  58. if (!IS_ERR(api_clk)) {
  59. clk_disable_unprepare(api_clk);
  60. clk_put(api_clk);
  61. }
  62. if (!IS_ERR(dsp_clk)) {
  63. clk_disable_unprepare(dsp_clk);
  64. clk_put(dsp_clk);
  65. }
  66. }
  67. }
  68. }
  69. static struct omap_mcbsp_ops omap1_mcbsp_ops = {
  70. .request = omap1_mcbsp_request,
  71. .free = omap1_mcbsp_free,
  72. };
  73. #define OMAP7XX_MCBSP1_BASE 0xfffb1000
  74. #define OMAP7XX_MCBSP2_BASE 0xfffb1800
  75. #define OMAP1510_MCBSP1_BASE 0xe1011800
  76. #define OMAP1510_MCBSP2_BASE 0xfffb1000
  77. #define OMAP1510_MCBSP3_BASE 0xe1017000
  78. #define OMAP1610_MCBSP1_BASE 0xe1011800
  79. #define OMAP1610_MCBSP2_BASE 0xfffb1000
  80. #define OMAP1610_MCBSP3_BASE 0xe1017000
  81. struct resource omap15xx_mcbsp_res[][6] = {
  82. {
  83. {
  84. .start = OMAP1510_MCBSP1_BASE,
  85. .end = OMAP1510_MCBSP1_BASE + SZ_256,
  86. .flags = IORESOURCE_MEM,
  87. },
  88. {
  89. .name = "rx",
  90. .start = INT_McBSP1RX,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. {
  94. .name = "tx",
  95. .start = INT_McBSP1TX,
  96. .flags = IORESOURCE_IRQ,
  97. },
  98. {
  99. .name = "rx",
  100. .start = 9,
  101. .flags = IORESOURCE_DMA,
  102. },
  103. {
  104. .name = "tx",
  105. .start = 8,
  106. .flags = IORESOURCE_DMA,
  107. },
  108. },
  109. {
  110. {
  111. .start = OMAP1510_MCBSP2_BASE,
  112. .end = OMAP1510_MCBSP2_BASE + SZ_256,
  113. .flags = IORESOURCE_MEM,
  114. },
  115. {
  116. .name = "rx",
  117. .start = INT_1510_SPI_RX,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. {
  121. .name = "tx",
  122. .start = INT_1510_SPI_TX,
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. {
  126. .name = "rx",
  127. .start = 17,
  128. .flags = IORESOURCE_DMA,
  129. },
  130. {
  131. .name = "tx",
  132. .start = 16,
  133. .flags = IORESOURCE_DMA,
  134. },
  135. },
  136. {
  137. {
  138. .start = OMAP1510_MCBSP3_BASE,
  139. .end = OMAP1510_MCBSP3_BASE + SZ_256,
  140. .flags = IORESOURCE_MEM,
  141. },
  142. {
  143. .name = "rx",
  144. .start = INT_McBSP3RX,
  145. .flags = IORESOURCE_IRQ,
  146. },
  147. {
  148. .name = "tx",
  149. .start = INT_McBSP3TX,
  150. .flags = IORESOURCE_IRQ,
  151. },
  152. {
  153. .name = "rx",
  154. .start = 11,
  155. .flags = IORESOURCE_DMA,
  156. },
  157. {
  158. .name = "tx",
  159. .start = 10,
  160. .flags = IORESOURCE_DMA,
  161. },
  162. },
  163. };
  164. #define omap15xx_mcbsp_res_0 omap15xx_mcbsp_res[0]
  165. static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
  166. {
  167. .ops = &omap1_mcbsp_ops,
  168. },
  169. {
  170. .ops = &omap1_mcbsp_ops,
  171. },
  172. {
  173. .ops = &omap1_mcbsp_ops,
  174. },
  175. };
  176. #define OMAP15XX_MCBSP_RES_SZ ARRAY_SIZE(omap15xx_mcbsp_res[1])
  177. #define OMAP15XX_MCBSP_COUNT ARRAY_SIZE(omap15xx_mcbsp_res)
  178. struct resource omap16xx_mcbsp_res[][6] = {
  179. {
  180. {
  181. .start = OMAP1610_MCBSP1_BASE,
  182. .end = OMAP1610_MCBSP1_BASE + SZ_256,
  183. .flags = IORESOURCE_MEM,
  184. },
  185. {
  186. .name = "rx",
  187. .start = INT_McBSP1RX,
  188. .flags = IORESOURCE_IRQ,
  189. },
  190. {
  191. .name = "tx",
  192. .start = INT_McBSP1TX,
  193. .flags = IORESOURCE_IRQ,
  194. },
  195. {
  196. .name = "rx",
  197. .start = 9,
  198. .flags = IORESOURCE_DMA,
  199. },
  200. {
  201. .name = "tx",
  202. .start = 8,
  203. .flags = IORESOURCE_DMA,
  204. },
  205. },
  206. {
  207. {
  208. .start = OMAP1610_MCBSP2_BASE,
  209. .end = OMAP1610_MCBSP2_BASE + SZ_256,
  210. .flags = IORESOURCE_MEM,
  211. },
  212. {
  213. .name = "rx",
  214. .start = INT_1610_McBSP2_RX,
  215. .flags = IORESOURCE_IRQ,
  216. },
  217. {
  218. .name = "tx",
  219. .start = INT_1610_McBSP2_TX,
  220. .flags = IORESOURCE_IRQ,
  221. },
  222. {
  223. .name = "rx",
  224. .start = 17,
  225. .flags = IORESOURCE_DMA,
  226. },
  227. {
  228. .name = "tx",
  229. .start = 16,
  230. .flags = IORESOURCE_DMA,
  231. },
  232. },
  233. {
  234. {
  235. .start = OMAP1610_MCBSP3_BASE,
  236. .end = OMAP1610_MCBSP3_BASE + SZ_256,
  237. .flags = IORESOURCE_MEM,
  238. },
  239. {
  240. .name = "rx",
  241. .start = INT_McBSP3RX,
  242. .flags = IORESOURCE_IRQ,
  243. },
  244. {
  245. .name = "tx",
  246. .start = INT_McBSP3TX,
  247. .flags = IORESOURCE_IRQ,
  248. },
  249. {
  250. .name = "rx",
  251. .start = 11,
  252. .flags = IORESOURCE_DMA,
  253. },
  254. {
  255. .name = "tx",
  256. .start = 10,
  257. .flags = IORESOURCE_DMA,
  258. },
  259. },
  260. };
  261. #define omap16xx_mcbsp_res_0 omap16xx_mcbsp_res[0]
  262. static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
  263. {
  264. .ops = &omap1_mcbsp_ops,
  265. },
  266. {
  267. .ops = &omap1_mcbsp_ops,
  268. },
  269. {
  270. .ops = &omap1_mcbsp_ops,
  271. },
  272. };
  273. #define OMAP16XX_MCBSP_RES_SZ ARRAY_SIZE(omap16xx_mcbsp_res[1])
  274. #define OMAP16XX_MCBSP_COUNT ARRAY_SIZE(omap16xx_mcbsp_res)
  275. static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
  276. struct omap_mcbsp_platform_data *config, int size)
  277. {
  278. int i;
  279. omap_mcbsp_devices = kcalloc(size, sizeof(struct platform_device *),
  280. GFP_KERNEL);
  281. if (!omap_mcbsp_devices) {
  282. printk(KERN_ERR "Could not register McBSP devices\n");
  283. return;
  284. }
  285. for (i = 0; i < size; i++) {
  286. struct platform_device *new_mcbsp;
  287. int ret;
  288. new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
  289. if (!new_mcbsp)
  290. continue;
  291. platform_device_add_resources(new_mcbsp, &res[i * res_count],
  292. res_count);
  293. config[i].reg_size = 2;
  294. config[i].reg_step = 2;
  295. new_mcbsp->dev.platform_data = &config[i];
  296. ret = platform_device_add(new_mcbsp);
  297. if (ret) {
  298. platform_device_put(new_mcbsp);
  299. continue;
  300. }
  301. omap_mcbsp_devices[i] = new_mcbsp;
  302. }
  303. }
  304. static int __init omap1_mcbsp_init(void)
  305. {
  306. if (!cpu_class_is_omap1())
  307. return -ENODEV;
  308. if (cpu_is_omap15xx())
  309. omap_mcbsp_register_board_cfg(omap15xx_mcbsp_res_0,
  310. OMAP15XX_MCBSP_RES_SZ,
  311. omap15xx_mcbsp_pdata,
  312. OMAP15XX_MCBSP_COUNT);
  313. if (cpu_is_omap16xx())
  314. omap_mcbsp_register_board_cfg(omap16xx_mcbsp_res_0,
  315. OMAP16XX_MCBSP_RES_SZ,
  316. omap16xx_mcbsp_pdata,
  317. OMAP16XX_MCBSP_COUNT);
  318. return 0;
  319. }
  320. arch_initcall(omap1_mcbsp_init);