mcbsp.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * linux/arch/arm/mach-omap1/mcbsp.c
  3. *
  4. * Copyright (C) 2008 Instituto Nokia de Tecnologia
  5. * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Multichannel mode not supported.
  12. */
  13. #include <linux/ioport.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/clk.h>
  17. #include <linux/err.h>
  18. #include <linux/io.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/slab.h>
  21. #include <linux/omap-dma.h>
  22. #include <mach/mux.h>
  23. #include "soc.h"
  24. #include <linux/platform_data/asoc-ti-mcbsp.h>
  25. #include <mach/irqs.h>
  26. #include "iomap.h"
  27. #define DPS_RSTCT2_PER_EN (1 << 0)
  28. #define DSP_RSTCT2_WD_PER_EN (1 << 1)
  29. static int dsp_use;
  30. static struct clk *api_clk;
  31. static struct clk *dsp_clk;
  32. static struct platform_device **omap_mcbsp_devices;
  33. static void omap1_mcbsp_request(unsigned int id)
  34. {
  35. /*
  36. * On 1510, 1610 and 1710, McBSP1 and McBSP3
  37. * are DSP public peripherals.
  38. */
  39. if (id == 0 || id == 2) {
  40. if (dsp_use++ == 0) {
  41. api_clk = clk_get(NULL, "api_ck");
  42. dsp_clk = clk_get(NULL, "dsp_ck");
  43. if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
  44. clk_enable(api_clk);
  45. clk_enable(dsp_clk);
  46. /*
  47. * DSP external peripheral reset
  48. * FIXME: This should be moved to dsp code
  49. */
  50. __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
  51. DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
  52. }
  53. }
  54. }
  55. }
  56. static void omap1_mcbsp_free(unsigned int id)
  57. {
  58. if (id == 0 || id == 2) {
  59. if (--dsp_use == 0) {
  60. if (!IS_ERR(api_clk)) {
  61. clk_disable(api_clk);
  62. clk_put(api_clk);
  63. }
  64. if (!IS_ERR(dsp_clk)) {
  65. clk_disable(dsp_clk);
  66. clk_put(dsp_clk);
  67. }
  68. }
  69. }
  70. }
  71. static struct omap_mcbsp_ops omap1_mcbsp_ops = {
  72. .request = omap1_mcbsp_request,
  73. .free = omap1_mcbsp_free,
  74. };
  75. #define OMAP7XX_MCBSP1_BASE 0xfffb1000
  76. #define OMAP7XX_MCBSP2_BASE 0xfffb1800
  77. #define OMAP1510_MCBSP1_BASE 0xe1011800
  78. #define OMAP1510_MCBSP2_BASE 0xfffb1000
  79. #define OMAP1510_MCBSP3_BASE 0xe1017000
  80. #define OMAP1610_MCBSP1_BASE 0xe1011800
  81. #define OMAP1610_MCBSP2_BASE 0xfffb1000
  82. #define OMAP1610_MCBSP3_BASE 0xe1017000
  83. #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
  84. struct resource omap7xx_mcbsp_res[][6] = {
  85. {
  86. {
  87. .start = OMAP7XX_MCBSP1_BASE,
  88. .end = OMAP7XX_MCBSP1_BASE + SZ_256,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. {
  92. .name = "rx",
  93. .start = INT_7XX_McBSP1RX,
  94. .flags = IORESOURCE_IRQ,
  95. },
  96. {
  97. .name = "tx",
  98. .start = INT_7XX_McBSP1TX,
  99. .flags = IORESOURCE_IRQ,
  100. },
  101. {
  102. .name = "rx",
  103. .start = 9,
  104. .flags = IORESOURCE_DMA,
  105. },
  106. {
  107. .name = "tx",
  108. .start = 8,
  109. .flags = IORESOURCE_DMA,
  110. },
  111. },
  112. {
  113. {
  114. .start = OMAP7XX_MCBSP2_BASE,
  115. .end = OMAP7XX_MCBSP2_BASE + SZ_256,
  116. .flags = IORESOURCE_MEM,
  117. },
  118. {
  119. .name = "rx",
  120. .start = INT_7XX_McBSP2RX,
  121. .flags = IORESOURCE_IRQ,
  122. },
  123. {
  124. .name = "tx",
  125. .start = INT_7XX_McBSP2TX,
  126. .flags = IORESOURCE_IRQ,
  127. },
  128. {
  129. .name = "rx",
  130. .start = 11,
  131. .flags = IORESOURCE_DMA,
  132. },
  133. {
  134. .name = "tx",
  135. .start = 10,
  136. .flags = IORESOURCE_DMA,
  137. },
  138. },
  139. };
  140. #define omap7xx_mcbsp_res_0 omap7xx_mcbsp_res[0]
  141. static struct omap_mcbsp_platform_data omap7xx_mcbsp_pdata[] = {
  142. {
  143. .ops = &omap1_mcbsp_ops,
  144. },
  145. {
  146. .ops = &omap1_mcbsp_ops,
  147. },
  148. };
  149. #define OMAP7XX_MCBSP_RES_SZ ARRAY_SIZE(omap7xx_mcbsp_res[1])
  150. #define OMAP7XX_MCBSP_COUNT ARRAY_SIZE(omap7xx_mcbsp_res)
  151. #else
  152. #define omap7xx_mcbsp_res_0 NULL
  153. #define omap7xx_mcbsp_pdata NULL
  154. #define OMAP7XX_MCBSP_RES_SZ 0
  155. #define OMAP7XX_MCBSP_COUNT 0
  156. #endif
  157. #ifdef CONFIG_ARCH_OMAP15XX
  158. struct resource omap15xx_mcbsp_res[][6] = {
  159. {
  160. {
  161. .start = OMAP1510_MCBSP1_BASE,
  162. .end = OMAP1510_MCBSP1_BASE + SZ_256,
  163. .flags = IORESOURCE_MEM,
  164. },
  165. {
  166. .name = "rx",
  167. .start = INT_McBSP1RX,
  168. .flags = IORESOURCE_IRQ,
  169. },
  170. {
  171. .name = "tx",
  172. .start = INT_McBSP1TX,
  173. .flags = IORESOURCE_IRQ,
  174. },
  175. {
  176. .name = "rx",
  177. .start = 9,
  178. .flags = IORESOURCE_DMA,
  179. },
  180. {
  181. .name = "tx",
  182. .start = 8,
  183. .flags = IORESOURCE_DMA,
  184. },
  185. },
  186. {
  187. {
  188. .start = OMAP1510_MCBSP2_BASE,
  189. .end = OMAP1510_MCBSP2_BASE + SZ_256,
  190. .flags = IORESOURCE_MEM,
  191. },
  192. {
  193. .name = "rx",
  194. .start = INT_1510_SPI_RX,
  195. .flags = IORESOURCE_IRQ,
  196. },
  197. {
  198. .name = "tx",
  199. .start = INT_1510_SPI_TX,
  200. .flags = IORESOURCE_IRQ,
  201. },
  202. {
  203. .name = "rx",
  204. .start = 17,
  205. .flags = IORESOURCE_DMA,
  206. },
  207. {
  208. .name = "tx",
  209. .start = 16,
  210. .flags = IORESOURCE_DMA,
  211. },
  212. },
  213. {
  214. {
  215. .start = OMAP1510_MCBSP3_BASE,
  216. .end = OMAP1510_MCBSP3_BASE + SZ_256,
  217. .flags = IORESOURCE_MEM,
  218. },
  219. {
  220. .name = "rx",
  221. .start = INT_McBSP3RX,
  222. .flags = IORESOURCE_IRQ,
  223. },
  224. {
  225. .name = "tx",
  226. .start = INT_McBSP3TX,
  227. .flags = IORESOURCE_IRQ,
  228. },
  229. {
  230. .name = "rx",
  231. .start = 11,
  232. .flags = IORESOURCE_DMA,
  233. },
  234. {
  235. .name = "tx",
  236. .start = 10,
  237. .flags = IORESOURCE_DMA,
  238. },
  239. },
  240. };
  241. #define omap15xx_mcbsp_res_0 omap15xx_mcbsp_res[0]
  242. static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
  243. {
  244. .ops = &omap1_mcbsp_ops,
  245. },
  246. {
  247. .ops = &omap1_mcbsp_ops,
  248. },
  249. {
  250. .ops = &omap1_mcbsp_ops,
  251. },
  252. };
  253. #define OMAP15XX_MCBSP_RES_SZ ARRAY_SIZE(omap15xx_mcbsp_res[1])
  254. #define OMAP15XX_MCBSP_COUNT ARRAY_SIZE(omap15xx_mcbsp_res)
  255. #else
  256. #define omap15xx_mcbsp_res_0 NULL
  257. #define omap15xx_mcbsp_pdata NULL
  258. #define OMAP15XX_MCBSP_RES_SZ 0
  259. #define OMAP15XX_MCBSP_COUNT 0
  260. #endif
  261. #ifdef CONFIG_ARCH_OMAP16XX
  262. struct resource omap16xx_mcbsp_res[][6] = {
  263. {
  264. {
  265. .start = OMAP1610_MCBSP1_BASE,
  266. .end = OMAP1610_MCBSP1_BASE + SZ_256,
  267. .flags = IORESOURCE_MEM,
  268. },
  269. {
  270. .name = "rx",
  271. .start = INT_McBSP1RX,
  272. .flags = IORESOURCE_IRQ,
  273. },
  274. {
  275. .name = "tx",
  276. .start = INT_McBSP1TX,
  277. .flags = IORESOURCE_IRQ,
  278. },
  279. {
  280. .name = "rx",
  281. .start = 9,
  282. .flags = IORESOURCE_DMA,
  283. },
  284. {
  285. .name = "tx",
  286. .start = 8,
  287. .flags = IORESOURCE_DMA,
  288. },
  289. },
  290. {
  291. {
  292. .start = OMAP1610_MCBSP2_BASE,
  293. .end = OMAP1610_MCBSP2_BASE + SZ_256,
  294. .flags = IORESOURCE_MEM,
  295. },
  296. {
  297. .name = "rx",
  298. .start = INT_1610_McBSP2_RX,
  299. .flags = IORESOURCE_IRQ,
  300. },
  301. {
  302. .name = "tx",
  303. .start = INT_1610_McBSP2_TX,
  304. .flags = IORESOURCE_IRQ,
  305. },
  306. {
  307. .name = "rx",
  308. .start = 17,
  309. .flags = IORESOURCE_DMA,
  310. },
  311. {
  312. .name = "tx",
  313. .start = 16,
  314. .flags = IORESOURCE_DMA,
  315. },
  316. },
  317. {
  318. {
  319. .start = OMAP1610_MCBSP3_BASE,
  320. .end = OMAP1610_MCBSP3_BASE + SZ_256,
  321. .flags = IORESOURCE_MEM,
  322. },
  323. {
  324. .name = "rx",
  325. .start = INT_McBSP3RX,
  326. .flags = IORESOURCE_IRQ,
  327. },
  328. {
  329. .name = "tx",
  330. .start = INT_McBSP3TX,
  331. .flags = IORESOURCE_IRQ,
  332. },
  333. {
  334. .name = "rx",
  335. .start = 11,
  336. .flags = IORESOURCE_DMA,
  337. },
  338. {
  339. .name = "tx",
  340. .start = 10,
  341. .flags = IORESOURCE_DMA,
  342. },
  343. },
  344. };
  345. #define omap16xx_mcbsp_res_0 omap16xx_mcbsp_res[0]
  346. static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
  347. {
  348. .ops = &omap1_mcbsp_ops,
  349. },
  350. {
  351. .ops = &omap1_mcbsp_ops,
  352. },
  353. {
  354. .ops = &omap1_mcbsp_ops,
  355. },
  356. };
  357. #define OMAP16XX_MCBSP_RES_SZ ARRAY_SIZE(omap16xx_mcbsp_res[1])
  358. #define OMAP16XX_MCBSP_COUNT ARRAY_SIZE(omap16xx_mcbsp_res)
  359. #else
  360. #define omap16xx_mcbsp_res_0 NULL
  361. #define omap16xx_mcbsp_pdata NULL
  362. #define OMAP16XX_MCBSP_RES_SZ 0
  363. #define OMAP16XX_MCBSP_COUNT 0
  364. #endif
  365. static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
  366. struct omap_mcbsp_platform_data *config, int size)
  367. {
  368. int i;
  369. omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
  370. GFP_KERNEL);
  371. if (!omap_mcbsp_devices) {
  372. printk(KERN_ERR "Could not register McBSP devices\n");
  373. return;
  374. }
  375. for (i = 0; i < size; i++) {
  376. struct platform_device *new_mcbsp;
  377. int ret;
  378. new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
  379. if (!new_mcbsp)
  380. continue;
  381. platform_device_add_resources(new_mcbsp, &res[i * res_count],
  382. res_count);
  383. config[i].reg_size = 2;
  384. config[i].reg_step = 2;
  385. new_mcbsp->dev.platform_data = &config[i];
  386. ret = platform_device_add(new_mcbsp);
  387. if (ret) {
  388. platform_device_put(new_mcbsp);
  389. continue;
  390. }
  391. omap_mcbsp_devices[i] = new_mcbsp;
  392. }
  393. }
  394. static int __init omap1_mcbsp_init(void)
  395. {
  396. if (!cpu_class_is_omap1())
  397. return -ENODEV;
  398. if (cpu_is_omap7xx())
  399. omap_mcbsp_register_board_cfg(omap7xx_mcbsp_res_0,
  400. OMAP7XX_MCBSP_RES_SZ,
  401. omap7xx_mcbsp_pdata,
  402. OMAP7XX_MCBSP_COUNT);
  403. if (cpu_is_omap15xx())
  404. omap_mcbsp_register_board_cfg(omap15xx_mcbsp_res_0,
  405. OMAP15XX_MCBSP_RES_SZ,
  406. omap15xx_mcbsp_pdata,
  407. OMAP15XX_MCBSP_COUNT);
  408. if (cpu_is_omap16xx())
  409. omap_mcbsp_register_board_cfg(omap16xx_mcbsp_res_0,
  410. OMAP16XX_MCBSP_RES_SZ,
  411. omap16xx_mcbsp_pdata,
  412. OMAP16XX_MCBSP_COUNT);
  413. return 0;
  414. }
  415. arch_initcall(omap1_mcbsp_init);