mcbsp.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * linux/arch/arm/plat-omap/mcbsp.c
  3. *
  4. * Copyright (C) 2004 Nokia Corporation
  5. * Author: Samuel Ortiz <samuel.ortiz@nokia.com>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Multichannel mode not supported.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/wait.h>
  19. #include <linux/completion.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/err.h>
  22. #include <linux/clk.h>
  23. #include <linux/delay.h>
  24. #include <linux/io.h>
  25. #include <linux/slab.h>
  26. #include <plat/dma.h>
  27. #include <plat/mcbsp.h>
  28. #include <plat/omap_device.h>
  29. #include <linux/pm_runtime.h>
  30. /* XXX These "sideways" includes are a sign that something is wrong */
  31. #include "../mach-omap2/cm2xxx_3xxx.h"
  32. #include "../mach-omap2/cm-regbits-34xx.h"
  33. struct omap_mcbsp **mcbsp_ptr;
  34. int omap_mcbsp_count, omap_mcbsp_cache_size;
  35. static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
  36. {
  37. if (cpu_class_is_omap1()) {
  38. ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)] = (u16)val;
  39. __raw_writew((u16)val, mcbsp->io_base + reg);
  40. } else if (cpu_is_omap2420()) {
  41. ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)] = (u16)val;
  42. __raw_writew((u16)val, mcbsp->io_base + reg);
  43. } else {
  44. ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)] = val;
  45. __raw_writel(val, mcbsp->io_base + reg);
  46. }
  47. }
  48. static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache)
  49. {
  50. if (cpu_class_is_omap1()) {
  51. return !from_cache ? __raw_readw(mcbsp->io_base + reg) :
  52. ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)];
  53. } else if (cpu_is_omap2420()) {
  54. return !from_cache ? __raw_readw(mcbsp->io_base + reg) :
  55. ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)];
  56. } else {
  57. return !from_cache ? __raw_readl(mcbsp->io_base + reg) :
  58. ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)];
  59. }
  60. }
  61. #ifdef CONFIG_ARCH_OMAP3
  62. static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
  63. {
  64. __raw_writel(val, mcbsp->st_data->io_base_st + reg);
  65. }
  66. static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg)
  67. {
  68. return __raw_readl(mcbsp->st_data->io_base_st + reg);
  69. }
  70. #endif
  71. #define MCBSP_READ(mcbsp, reg) \
  72. omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
  73. #define MCBSP_WRITE(mcbsp, reg, val) \
  74. omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
  75. #define MCBSP_READ_CACHE(mcbsp, reg) \
  76. omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
  77. #define MCBSP_ST_READ(mcbsp, reg) \
  78. omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
  79. #define MCBSP_ST_WRITE(mcbsp, reg, val) \
  80. omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
  81. static void omap_mcbsp_dump_reg(u8 id)
  82. {
  83. struct omap_mcbsp *mcbsp = id_to_mcbsp_ptr(id);
  84. dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id);
  85. dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n",
  86. MCBSP_READ(mcbsp, DRR2));
  87. dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n",
  88. MCBSP_READ(mcbsp, DRR1));
  89. dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n",
  90. MCBSP_READ(mcbsp, DXR2));
  91. dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n",
  92. MCBSP_READ(mcbsp, DXR1));
  93. dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n",
  94. MCBSP_READ(mcbsp, SPCR2));
  95. dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n",
  96. MCBSP_READ(mcbsp, SPCR1));
  97. dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n",
  98. MCBSP_READ(mcbsp, RCR2));
  99. dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n",
  100. MCBSP_READ(mcbsp, RCR1));
  101. dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n",
  102. MCBSP_READ(mcbsp, XCR2));
  103. dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n",
  104. MCBSP_READ(mcbsp, XCR1));
  105. dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n",
  106. MCBSP_READ(mcbsp, SRGR2));
  107. dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n",
  108. MCBSP_READ(mcbsp, SRGR1));
  109. dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n",
  110. MCBSP_READ(mcbsp, PCR0));
  111. dev_dbg(mcbsp->dev, "***********************\n");
  112. }
  113. static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
  114. {
  115. struct omap_mcbsp *mcbsp_tx = dev_id;
  116. u16 irqst_spcr2;
  117. irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2);
  118. dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2);
  119. if (irqst_spcr2 & XSYNC_ERR) {
  120. dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n",
  121. irqst_spcr2);
  122. /* Writing zero to XSYNC_ERR clears the IRQ */
  123. MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2));
  124. } else {
  125. complete(&mcbsp_tx->tx_irq_completion);
  126. }
  127. return IRQ_HANDLED;
  128. }
  129. static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
  130. {
  131. struct omap_mcbsp *mcbsp_rx = dev_id;
  132. u16 irqst_spcr1;
  133. irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1);
  134. dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1);
  135. if (irqst_spcr1 & RSYNC_ERR) {
  136. dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n",
  137. irqst_spcr1);
  138. /* Writing zero to RSYNC_ERR clears the IRQ */
  139. MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1));
  140. } else {
  141. complete(&mcbsp_rx->rx_irq_completion);
  142. }
  143. return IRQ_HANDLED;
  144. }
  145. static void omap_mcbsp_tx_dma_callback(int lch, u16 ch_status, void *data)
  146. {
  147. struct omap_mcbsp *mcbsp_dma_tx = data;
  148. dev_dbg(mcbsp_dma_tx->dev, "TX DMA callback : 0x%x\n",
  149. MCBSP_READ(mcbsp_dma_tx, SPCR2));
  150. /* We can free the channels */
  151. omap_free_dma(mcbsp_dma_tx->dma_tx_lch);
  152. mcbsp_dma_tx->dma_tx_lch = -1;
  153. complete(&mcbsp_dma_tx->tx_dma_completion);
  154. }
  155. static void omap_mcbsp_rx_dma_callback(int lch, u16 ch_status, void *data)
  156. {
  157. struct omap_mcbsp *mcbsp_dma_rx = data;
  158. dev_dbg(mcbsp_dma_rx->dev, "RX DMA callback : 0x%x\n",
  159. MCBSP_READ(mcbsp_dma_rx, SPCR2));
  160. /* We can free the channels */
  161. omap_free_dma(mcbsp_dma_rx->dma_rx_lch);
  162. mcbsp_dma_rx->dma_rx_lch = -1;
  163. complete(&mcbsp_dma_rx->rx_dma_completion);
  164. }
  165. /*
  166. * omap_mcbsp_config simply write a config to the
  167. * appropriate McBSP.
  168. * You either call this function or set the McBSP registers
  169. * by yourself before calling omap_mcbsp_start().
  170. */
  171. void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config)
  172. {
  173. struct omap_mcbsp *mcbsp;
  174. if (!omap_mcbsp_check_valid_id(id)) {
  175. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  176. return;
  177. }
  178. mcbsp = id_to_mcbsp_ptr(id);
  179. dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n",
  180. mcbsp->id, mcbsp->phys_base);
  181. /* We write the given config */
  182. MCBSP_WRITE(mcbsp, SPCR2, config->spcr2);
  183. MCBSP_WRITE(mcbsp, SPCR1, config->spcr1);
  184. MCBSP_WRITE(mcbsp, RCR2, config->rcr2);
  185. MCBSP_WRITE(mcbsp, RCR1, config->rcr1);
  186. MCBSP_WRITE(mcbsp, XCR2, config->xcr2);
  187. MCBSP_WRITE(mcbsp, XCR1, config->xcr1);
  188. MCBSP_WRITE(mcbsp, SRGR2, config->srgr2);
  189. MCBSP_WRITE(mcbsp, SRGR1, config->srgr1);
  190. MCBSP_WRITE(mcbsp, MCR2, config->mcr2);
  191. MCBSP_WRITE(mcbsp, MCR1, config->mcr1);
  192. MCBSP_WRITE(mcbsp, PCR0, config->pcr0);
  193. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
  194. MCBSP_WRITE(mcbsp, XCCR, config->xccr);
  195. MCBSP_WRITE(mcbsp, RCCR, config->rccr);
  196. }
  197. }
  198. EXPORT_SYMBOL(omap_mcbsp_config);
  199. /**
  200. * omap_mcbsp_dma_params - returns the dma channel number
  201. * @id - mcbsp id
  202. * @stream - indicates the direction of data flow (rx or tx)
  203. *
  204. * Returns the dma channel number for the rx channel or tx channel
  205. * based on the value of @stream for the requested mcbsp given by @id
  206. */
  207. int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream)
  208. {
  209. struct omap_mcbsp *mcbsp;
  210. if (!omap_mcbsp_check_valid_id(id)) {
  211. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  212. return -ENODEV;
  213. }
  214. mcbsp = id_to_mcbsp_ptr(id);
  215. if (stream)
  216. return mcbsp->dma_rx_sync;
  217. else
  218. return mcbsp->dma_tx_sync;
  219. }
  220. EXPORT_SYMBOL(omap_mcbsp_dma_ch_params);
  221. /**
  222. * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
  223. * @id - mcbsp id
  224. * @stream - indicates the direction of data flow (rx or tx)
  225. *
  226. * Returns the address of mcbsp data transmit register or data receive register
  227. * to be used by DMA for transferring/receiving data based on the value of
  228. * @stream for the requested mcbsp given by @id
  229. */
  230. int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream)
  231. {
  232. struct omap_mcbsp *mcbsp;
  233. int data_reg;
  234. if (!omap_mcbsp_check_valid_id(id)) {
  235. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  236. return -ENODEV;
  237. }
  238. mcbsp = id_to_mcbsp_ptr(id);
  239. data_reg = mcbsp->phys_dma_base;
  240. if (mcbsp->mcbsp_config_type < MCBSP_CONFIG_TYPE2) {
  241. if (stream)
  242. data_reg += OMAP_MCBSP_REG_DRR1;
  243. else
  244. data_reg += OMAP_MCBSP_REG_DXR1;
  245. } else {
  246. if (stream)
  247. data_reg += OMAP_MCBSP_REG_DRR;
  248. else
  249. data_reg += OMAP_MCBSP_REG_DXR;
  250. }
  251. return data_reg;
  252. }
  253. EXPORT_SYMBOL(omap_mcbsp_dma_reg_params);
  254. #ifdef CONFIG_ARCH_OMAP3
  255. static struct omap_device *find_omap_device_by_dev(struct device *dev)
  256. {
  257. struct platform_device *pdev = container_of(dev,
  258. struct platform_device, dev);
  259. return container_of(pdev, struct omap_device, pdev);
  260. }
  261. static void omap_st_on(struct omap_mcbsp *mcbsp)
  262. {
  263. unsigned int w;
  264. struct omap_device *od;
  265. od = find_omap_device_by_dev(mcbsp->dev);
  266. /*
  267. * Sidetone uses McBSP ICLK - which must not idle when sidetones
  268. * are enabled or sidetones start sounding ugly.
  269. */
  270. w = omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE);
  271. w &= ~(1 << (mcbsp->id - 2));
  272. omap2_cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE);
  273. /* Enable McBSP Sidetone */
  274. w = MCBSP_READ(mcbsp, SSELCR);
  275. MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
  276. /* Enable Sidetone from Sidetone Core */
  277. w = MCBSP_ST_READ(mcbsp, SSELCR);
  278. MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN);
  279. }
  280. static void omap_st_off(struct omap_mcbsp *mcbsp)
  281. {
  282. unsigned int w;
  283. struct omap_device *od;
  284. od = find_omap_device_by_dev(mcbsp->dev);
  285. w = MCBSP_ST_READ(mcbsp, SSELCR);
  286. MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
  287. w = MCBSP_READ(mcbsp, SSELCR);
  288. MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
  289. w = omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE);
  290. w |= 1 << (mcbsp->id - 2);
  291. omap2_cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE);
  292. }
  293. static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
  294. {
  295. u16 val, i;
  296. struct omap_device *od;
  297. od = find_omap_device_by_dev(mcbsp->dev);
  298. val = MCBSP_ST_READ(mcbsp, SSELCR);
  299. if (val & ST_COEFFWREN)
  300. MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
  301. MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN);
  302. for (i = 0; i < 128; i++)
  303. MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]);
  304. i = 0;
  305. val = MCBSP_ST_READ(mcbsp, SSELCR);
  306. while (!(val & ST_COEFFWRDONE) && (++i < 1000))
  307. val = MCBSP_ST_READ(mcbsp, SSELCR);
  308. MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
  309. if (i == 1000)
  310. dev_err(mcbsp->dev, "McBSP FIR load error!\n");
  311. }
  312. static void omap_st_chgain(struct omap_mcbsp *mcbsp)
  313. {
  314. u16 w;
  315. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  316. struct omap_device *od;
  317. od = find_omap_device_by_dev(mcbsp->dev);
  318. w = MCBSP_ST_READ(mcbsp, SSELCR);
  319. MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \
  320. ST_CH1GAIN(st_data->ch1gain));
  321. }
  322. int omap_st_set_chgain(unsigned int id, int channel, s16 chgain)
  323. {
  324. struct omap_mcbsp *mcbsp;
  325. struct omap_mcbsp_st_data *st_data;
  326. int ret = 0;
  327. if (!omap_mcbsp_check_valid_id(id)) {
  328. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  329. return -ENODEV;
  330. }
  331. mcbsp = id_to_mcbsp_ptr(id);
  332. st_data = mcbsp->st_data;
  333. if (!st_data)
  334. return -ENOENT;
  335. spin_lock_irq(&mcbsp->lock);
  336. if (channel == 0)
  337. st_data->ch0gain = chgain;
  338. else if (channel == 1)
  339. st_data->ch1gain = chgain;
  340. else
  341. ret = -EINVAL;
  342. if (st_data->enabled)
  343. omap_st_chgain(mcbsp);
  344. spin_unlock_irq(&mcbsp->lock);
  345. return ret;
  346. }
  347. EXPORT_SYMBOL(omap_st_set_chgain);
  348. int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain)
  349. {
  350. struct omap_mcbsp *mcbsp;
  351. struct omap_mcbsp_st_data *st_data;
  352. int ret = 0;
  353. if (!omap_mcbsp_check_valid_id(id)) {
  354. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  355. return -ENODEV;
  356. }
  357. mcbsp = id_to_mcbsp_ptr(id);
  358. st_data = mcbsp->st_data;
  359. if (!st_data)
  360. return -ENOENT;
  361. spin_lock_irq(&mcbsp->lock);
  362. if (channel == 0)
  363. *chgain = st_data->ch0gain;
  364. else if (channel == 1)
  365. *chgain = st_data->ch1gain;
  366. else
  367. ret = -EINVAL;
  368. spin_unlock_irq(&mcbsp->lock);
  369. return ret;
  370. }
  371. EXPORT_SYMBOL(omap_st_get_chgain);
  372. static int omap_st_start(struct omap_mcbsp *mcbsp)
  373. {
  374. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  375. if (st_data && st_data->enabled && !st_data->running) {
  376. omap_st_fir_write(mcbsp, st_data->taps);
  377. omap_st_chgain(mcbsp);
  378. if (!mcbsp->free) {
  379. omap_st_on(mcbsp);
  380. st_data->running = 1;
  381. }
  382. }
  383. return 0;
  384. }
  385. int omap_st_enable(unsigned int id)
  386. {
  387. struct omap_mcbsp *mcbsp;
  388. struct omap_mcbsp_st_data *st_data;
  389. if (!omap_mcbsp_check_valid_id(id)) {
  390. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  391. return -ENODEV;
  392. }
  393. mcbsp = id_to_mcbsp_ptr(id);
  394. st_data = mcbsp->st_data;
  395. if (!st_data)
  396. return -ENODEV;
  397. spin_lock_irq(&mcbsp->lock);
  398. st_data->enabled = 1;
  399. omap_st_start(mcbsp);
  400. spin_unlock_irq(&mcbsp->lock);
  401. return 0;
  402. }
  403. EXPORT_SYMBOL(omap_st_enable);
  404. static int omap_st_stop(struct omap_mcbsp *mcbsp)
  405. {
  406. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  407. if (st_data && st_data->running) {
  408. if (!mcbsp->free) {
  409. omap_st_off(mcbsp);
  410. st_data->running = 0;
  411. }
  412. }
  413. return 0;
  414. }
  415. int omap_st_disable(unsigned int id)
  416. {
  417. struct omap_mcbsp *mcbsp;
  418. struct omap_mcbsp_st_data *st_data;
  419. int ret = 0;
  420. if (!omap_mcbsp_check_valid_id(id)) {
  421. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  422. return -ENODEV;
  423. }
  424. mcbsp = id_to_mcbsp_ptr(id);
  425. st_data = mcbsp->st_data;
  426. if (!st_data)
  427. return -ENODEV;
  428. spin_lock_irq(&mcbsp->lock);
  429. omap_st_stop(mcbsp);
  430. st_data->enabled = 0;
  431. spin_unlock_irq(&mcbsp->lock);
  432. return ret;
  433. }
  434. EXPORT_SYMBOL(omap_st_disable);
  435. int omap_st_is_enabled(unsigned int id)
  436. {
  437. struct omap_mcbsp *mcbsp;
  438. struct omap_mcbsp_st_data *st_data;
  439. if (!omap_mcbsp_check_valid_id(id)) {
  440. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  441. return -ENODEV;
  442. }
  443. mcbsp = id_to_mcbsp_ptr(id);
  444. st_data = mcbsp->st_data;
  445. if (!st_data)
  446. return -ENODEV;
  447. return st_data->enabled;
  448. }
  449. EXPORT_SYMBOL(omap_st_is_enabled);
  450. /*
  451. * omap_mcbsp_set_rx_threshold configures the transmit threshold in words.
  452. * The threshold parameter is 1 based, and it is converted (threshold - 1)
  453. * for the THRSH2 register.
  454. */
  455. void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
  456. {
  457. struct omap_mcbsp *mcbsp;
  458. if (!cpu_is_omap34xx() && !cpu_is_omap44xx())
  459. return;
  460. if (!omap_mcbsp_check_valid_id(id)) {
  461. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  462. return;
  463. }
  464. mcbsp = id_to_mcbsp_ptr(id);
  465. if (threshold && threshold <= mcbsp->max_tx_thres)
  466. MCBSP_WRITE(mcbsp, THRSH2, threshold - 1);
  467. }
  468. EXPORT_SYMBOL(omap_mcbsp_set_tx_threshold);
  469. /*
  470. * omap_mcbsp_set_rx_threshold configures the receive threshold in words.
  471. * The threshold parameter is 1 based, and it is converted (threshold - 1)
  472. * for the THRSH1 register.
  473. */
  474. void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
  475. {
  476. struct omap_mcbsp *mcbsp;
  477. if (!cpu_is_omap34xx() && !cpu_is_omap44xx())
  478. return;
  479. if (!omap_mcbsp_check_valid_id(id)) {
  480. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  481. return;
  482. }
  483. mcbsp = id_to_mcbsp_ptr(id);
  484. if (threshold && threshold <= mcbsp->max_rx_thres)
  485. MCBSP_WRITE(mcbsp, THRSH1, threshold - 1);
  486. }
  487. EXPORT_SYMBOL(omap_mcbsp_set_rx_threshold);
  488. /*
  489. * omap_mcbsp_get_max_tx_thres just return the current configured
  490. * maximum threshold for transmission
  491. */
  492. u16 omap_mcbsp_get_max_tx_threshold(unsigned int id)
  493. {
  494. struct omap_mcbsp *mcbsp;
  495. if (!omap_mcbsp_check_valid_id(id)) {
  496. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  497. return -ENODEV;
  498. }
  499. mcbsp = id_to_mcbsp_ptr(id);
  500. return mcbsp->max_tx_thres;
  501. }
  502. EXPORT_SYMBOL(omap_mcbsp_get_max_tx_threshold);
  503. /*
  504. * omap_mcbsp_get_max_rx_thres just return the current configured
  505. * maximum threshold for reception
  506. */
  507. u16 omap_mcbsp_get_max_rx_threshold(unsigned int id)
  508. {
  509. struct omap_mcbsp *mcbsp;
  510. if (!omap_mcbsp_check_valid_id(id)) {
  511. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  512. return -ENODEV;
  513. }
  514. mcbsp = id_to_mcbsp_ptr(id);
  515. return mcbsp->max_rx_thres;
  516. }
  517. EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold);
  518. u16 omap_mcbsp_get_fifo_size(unsigned int id)
  519. {
  520. struct omap_mcbsp *mcbsp;
  521. if (!omap_mcbsp_check_valid_id(id)) {
  522. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  523. return -ENODEV;
  524. }
  525. mcbsp = id_to_mcbsp_ptr(id);
  526. return mcbsp->pdata->buffer_size;
  527. }
  528. EXPORT_SYMBOL(omap_mcbsp_get_fifo_size);
  529. /*
  530. * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
  531. */
  532. u16 omap_mcbsp_get_tx_delay(unsigned int id)
  533. {
  534. struct omap_mcbsp *mcbsp;
  535. u16 buffstat;
  536. if (!omap_mcbsp_check_valid_id(id)) {
  537. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  538. return -ENODEV;
  539. }
  540. mcbsp = id_to_mcbsp_ptr(id);
  541. /* Returns the number of free locations in the buffer */
  542. buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
  543. /* Number of slots are different in McBSP ports */
  544. return mcbsp->pdata->buffer_size - buffstat;
  545. }
  546. EXPORT_SYMBOL(omap_mcbsp_get_tx_delay);
  547. /*
  548. * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
  549. * to reach the threshold value (when the DMA will be triggered to read it)
  550. */
  551. u16 omap_mcbsp_get_rx_delay(unsigned int id)
  552. {
  553. struct omap_mcbsp *mcbsp;
  554. u16 buffstat, threshold;
  555. if (!omap_mcbsp_check_valid_id(id)) {
  556. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  557. return -ENODEV;
  558. }
  559. mcbsp = id_to_mcbsp_ptr(id);
  560. /* Returns the number of used locations in the buffer */
  561. buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
  562. /* RX threshold */
  563. threshold = MCBSP_READ(mcbsp, THRSH1);
  564. /* Return the number of location till we reach the threshold limit */
  565. if (threshold <= buffstat)
  566. return 0;
  567. else
  568. return threshold - buffstat;
  569. }
  570. EXPORT_SYMBOL(omap_mcbsp_get_rx_delay);
  571. /*
  572. * omap_mcbsp_get_dma_op_mode just return the current configured
  573. * operating mode for the mcbsp channel
  574. */
  575. int omap_mcbsp_get_dma_op_mode(unsigned int id)
  576. {
  577. struct omap_mcbsp *mcbsp;
  578. int dma_op_mode;
  579. if (!omap_mcbsp_check_valid_id(id)) {
  580. printk(KERN_ERR "%s: Invalid id (%u)\n", __func__, id + 1);
  581. return -ENODEV;
  582. }
  583. mcbsp = id_to_mcbsp_ptr(id);
  584. dma_op_mode = mcbsp->dma_op_mode;
  585. return dma_op_mode;
  586. }
  587. EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode);
  588. static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
  589. {
  590. struct omap_device *od;
  591. od = find_omap_device_by_dev(mcbsp->dev);
  592. /*
  593. * Enable wakup behavior, smart idle and all wakeups
  594. * REVISIT: some wakeups may be unnecessary
  595. */
  596. if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
  597. MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
  598. }
  599. }
  600. static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
  601. {
  602. struct omap_device *od;
  603. od = find_omap_device_by_dev(mcbsp->dev);
  604. /*
  605. * Disable wakup behavior, smart idle and all wakeups
  606. */
  607. if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
  608. /*
  609. * HW bug workaround - If no_idle mode is taken, we need to
  610. * go to smart_idle before going to always_idle, or the
  611. * device will not hit retention anymore.
  612. */
  613. MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
  614. }
  615. }
  616. #else
  617. static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp) {}
  618. static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp) {}
  619. static inline void omap_st_start(struct omap_mcbsp *mcbsp) {}
  620. static inline void omap_st_stop(struct omap_mcbsp *mcbsp) {}
  621. #endif
  622. /*
  623. * We can choose between IRQ based or polled IO.
  624. * This needs to be called before omap_mcbsp_request().
  625. */
  626. int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type)
  627. {
  628. struct omap_mcbsp *mcbsp;
  629. if (!omap_mcbsp_check_valid_id(id)) {
  630. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  631. return -ENODEV;
  632. }
  633. mcbsp = id_to_mcbsp_ptr(id);
  634. spin_lock(&mcbsp->lock);
  635. if (!mcbsp->free) {
  636. dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
  637. mcbsp->id);
  638. spin_unlock(&mcbsp->lock);
  639. return -EINVAL;
  640. }
  641. mcbsp->io_type = io_type;
  642. spin_unlock(&mcbsp->lock);
  643. return 0;
  644. }
  645. EXPORT_SYMBOL(omap_mcbsp_set_io_type);
  646. int omap_mcbsp_request(unsigned int id)
  647. {
  648. struct omap_mcbsp *mcbsp;
  649. void *reg_cache;
  650. int err;
  651. if (!omap_mcbsp_check_valid_id(id)) {
  652. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  653. return -ENODEV;
  654. }
  655. mcbsp = id_to_mcbsp_ptr(id);
  656. reg_cache = kzalloc(omap_mcbsp_cache_size, GFP_KERNEL);
  657. if (!reg_cache) {
  658. return -ENOMEM;
  659. }
  660. spin_lock(&mcbsp->lock);
  661. if (!mcbsp->free) {
  662. dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
  663. mcbsp->id);
  664. err = -EBUSY;
  665. goto err_kfree;
  666. }
  667. mcbsp->free = false;
  668. mcbsp->reg_cache = reg_cache;
  669. spin_unlock(&mcbsp->lock);
  670. if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request)
  671. mcbsp->pdata->ops->request(id);
  672. pm_runtime_get_sync(mcbsp->dev);
  673. /* Do procedure specific to omap34xx arch, if applicable */
  674. omap34xx_mcbsp_request(mcbsp);
  675. /*
  676. * Make sure that transmitter, receiver and sample-rate generator are
  677. * not running before activating IRQs.
  678. */
  679. MCBSP_WRITE(mcbsp, SPCR1, 0);
  680. MCBSP_WRITE(mcbsp, SPCR2, 0);
  681. if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) {
  682. /* We need to get IRQs here */
  683. init_completion(&mcbsp->tx_irq_completion);
  684. err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler,
  685. 0, "McBSP", (void *)mcbsp);
  686. if (err != 0) {
  687. dev_err(mcbsp->dev, "Unable to request TX IRQ %d "
  688. "for McBSP%d\n", mcbsp->tx_irq,
  689. mcbsp->id);
  690. goto err_clk_disable;
  691. }
  692. if (mcbsp->rx_irq) {
  693. init_completion(&mcbsp->rx_irq_completion);
  694. err = request_irq(mcbsp->rx_irq,
  695. omap_mcbsp_rx_irq_handler,
  696. 0, "McBSP", (void *)mcbsp);
  697. if (err != 0) {
  698. dev_err(mcbsp->dev, "Unable to request RX IRQ %d "
  699. "for McBSP%d\n", mcbsp->rx_irq,
  700. mcbsp->id);
  701. goto err_free_irq;
  702. }
  703. }
  704. }
  705. return 0;
  706. err_free_irq:
  707. free_irq(mcbsp->tx_irq, (void *)mcbsp);
  708. err_clk_disable:
  709. if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
  710. mcbsp->pdata->ops->free(id);
  711. /* Do procedure specific to omap34xx arch, if applicable */
  712. omap34xx_mcbsp_free(mcbsp);
  713. pm_runtime_put_sync(mcbsp->dev);
  714. spin_lock(&mcbsp->lock);
  715. mcbsp->free = true;
  716. mcbsp->reg_cache = NULL;
  717. err_kfree:
  718. spin_unlock(&mcbsp->lock);
  719. kfree(reg_cache);
  720. return err;
  721. }
  722. EXPORT_SYMBOL(omap_mcbsp_request);
  723. void omap_mcbsp_free(unsigned int id)
  724. {
  725. struct omap_mcbsp *mcbsp;
  726. void *reg_cache;
  727. if (!omap_mcbsp_check_valid_id(id)) {
  728. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  729. return;
  730. }
  731. mcbsp = id_to_mcbsp_ptr(id);
  732. if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
  733. mcbsp->pdata->ops->free(id);
  734. /* Do procedure specific to omap34xx arch, if applicable */
  735. omap34xx_mcbsp_free(mcbsp);
  736. pm_runtime_put_sync(mcbsp->dev);
  737. if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) {
  738. /* Free IRQs */
  739. if (mcbsp->rx_irq)
  740. free_irq(mcbsp->rx_irq, (void *)mcbsp);
  741. free_irq(mcbsp->tx_irq, (void *)mcbsp);
  742. }
  743. reg_cache = mcbsp->reg_cache;
  744. spin_lock(&mcbsp->lock);
  745. if (mcbsp->free)
  746. dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
  747. else
  748. mcbsp->free = true;
  749. mcbsp->reg_cache = NULL;
  750. spin_unlock(&mcbsp->lock);
  751. if (reg_cache)
  752. kfree(reg_cache);
  753. }
  754. EXPORT_SYMBOL(omap_mcbsp_free);
  755. /*
  756. * Here we start the McBSP, by enabling transmitter, receiver or both.
  757. * If no transmitter or receiver is active prior calling, then sample-rate
  758. * generator and frame sync are started.
  759. */
  760. void omap_mcbsp_start(unsigned int id, int tx, int rx)
  761. {
  762. struct omap_mcbsp *mcbsp;
  763. int enable_srg = 0;
  764. u16 w;
  765. if (!omap_mcbsp_check_valid_id(id)) {
  766. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  767. return;
  768. }
  769. mcbsp = id_to_mcbsp_ptr(id);
  770. if (cpu_is_omap34xx())
  771. omap_st_start(mcbsp);
  772. mcbsp->rx_word_length = (MCBSP_READ_CACHE(mcbsp, RCR1) >> 5) & 0x7;
  773. mcbsp->tx_word_length = (MCBSP_READ_CACHE(mcbsp, XCR1) >> 5) & 0x7;
  774. /* Only enable SRG, if McBSP is master */
  775. w = MCBSP_READ_CACHE(mcbsp, PCR0);
  776. if (w & (FSXM | FSRM | CLKXM | CLKRM))
  777. enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
  778. MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
  779. if (enable_srg) {
  780. /* Start the sample generator */
  781. w = MCBSP_READ_CACHE(mcbsp, SPCR2);
  782. MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6));
  783. }
  784. /* Enable transmitter and receiver */
  785. tx &= 1;
  786. w = MCBSP_READ_CACHE(mcbsp, SPCR2);
  787. MCBSP_WRITE(mcbsp, SPCR2, w | tx);
  788. rx &= 1;
  789. w = MCBSP_READ_CACHE(mcbsp, SPCR1);
  790. MCBSP_WRITE(mcbsp, SPCR1, w | rx);
  791. /*
  792. * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
  793. * REVISIT: 100us may give enough time for two CLKSRG, however
  794. * due to some unknown PM related, clock gating etc. reason it
  795. * is now at 500us.
  796. */
  797. udelay(500);
  798. if (enable_srg) {
  799. /* Start frame sync */
  800. w = MCBSP_READ_CACHE(mcbsp, SPCR2);
  801. MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
  802. }
  803. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
  804. /* Release the transmitter and receiver */
  805. w = MCBSP_READ_CACHE(mcbsp, XCCR);
  806. w &= ~(tx ? XDISABLE : 0);
  807. MCBSP_WRITE(mcbsp, XCCR, w);
  808. w = MCBSP_READ_CACHE(mcbsp, RCCR);
  809. w &= ~(rx ? RDISABLE : 0);
  810. MCBSP_WRITE(mcbsp, RCCR, w);
  811. }
  812. /* Dump McBSP Regs */
  813. omap_mcbsp_dump_reg(id);
  814. }
  815. EXPORT_SYMBOL(omap_mcbsp_start);
  816. void omap_mcbsp_stop(unsigned int id, int tx, int rx)
  817. {
  818. struct omap_mcbsp *mcbsp;
  819. int idle;
  820. u16 w;
  821. if (!omap_mcbsp_check_valid_id(id)) {
  822. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  823. return;
  824. }
  825. mcbsp = id_to_mcbsp_ptr(id);
  826. /* Reset transmitter */
  827. tx &= 1;
  828. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
  829. w = MCBSP_READ_CACHE(mcbsp, XCCR);
  830. w |= (tx ? XDISABLE : 0);
  831. MCBSP_WRITE(mcbsp, XCCR, w);
  832. }
  833. w = MCBSP_READ_CACHE(mcbsp, SPCR2);
  834. MCBSP_WRITE(mcbsp, SPCR2, w & ~tx);
  835. /* Reset receiver */
  836. rx &= 1;
  837. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
  838. w = MCBSP_READ_CACHE(mcbsp, RCCR);
  839. w |= (rx ? RDISABLE : 0);
  840. MCBSP_WRITE(mcbsp, RCCR, w);
  841. }
  842. w = MCBSP_READ_CACHE(mcbsp, SPCR1);
  843. MCBSP_WRITE(mcbsp, SPCR1, w & ~rx);
  844. idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
  845. MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
  846. if (idle) {
  847. /* Reset the sample rate generator */
  848. w = MCBSP_READ_CACHE(mcbsp, SPCR2);
  849. MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6));
  850. }
  851. if (cpu_is_omap34xx())
  852. omap_st_stop(mcbsp);
  853. }
  854. EXPORT_SYMBOL(omap_mcbsp_stop);
  855. /* polled mcbsp i/o operations */
  856. int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
  857. {
  858. struct omap_mcbsp *mcbsp;
  859. if (!omap_mcbsp_check_valid_id(id)) {
  860. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  861. return -ENODEV;
  862. }
  863. mcbsp = id_to_mcbsp_ptr(id);
  864. MCBSP_WRITE(mcbsp, DXR1, buf);
  865. /* if frame sync error - clear the error */
  866. if (MCBSP_READ(mcbsp, SPCR2) & XSYNC_ERR) {
  867. /* clear error */
  868. MCBSP_WRITE(mcbsp, SPCR2, MCBSP_READ_CACHE(mcbsp, SPCR2));
  869. /* resend */
  870. return -1;
  871. } else {
  872. /* wait for transmit confirmation */
  873. int attemps = 0;
  874. while (!(MCBSP_READ(mcbsp, SPCR2) & XRDY)) {
  875. if (attemps++ > 1000) {
  876. MCBSP_WRITE(mcbsp, SPCR2,
  877. MCBSP_READ_CACHE(mcbsp, SPCR2) &
  878. (~XRST));
  879. udelay(10);
  880. MCBSP_WRITE(mcbsp, SPCR2,
  881. MCBSP_READ_CACHE(mcbsp, SPCR2) |
  882. (XRST));
  883. udelay(10);
  884. dev_err(mcbsp->dev, "Could not write to"
  885. " McBSP%d Register\n", mcbsp->id);
  886. return -2;
  887. }
  888. }
  889. }
  890. return 0;
  891. }
  892. EXPORT_SYMBOL(omap_mcbsp_pollwrite);
  893. int omap_mcbsp_pollread(unsigned int id, u16 *buf)
  894. {
  895. struct omap_mcbsp *mcbsp;
  896. if (!omap_mcbsp_check_valid_id(id)) {
  897. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  898. return -ENODEV;
  899. }
  900. mcbsp = id_to_mcbsp_ptr(id);
  901. /* if frame sync error - clear the error */
  902. if (MCBSP_READ(mcbsp, SPCR1) & RSYNC_ERR) {
  903. /* clear error */
  904. MCBSP_WRITE(mcbsp, SPCR1, MCBSP_READ_CACHE(mcbsp, SPCR1));
  905. /* resend */
  906. return -1;
  907. } else {
  908. /* wait for receive confirmation */
  909. int attemps = 0;
  910. while (!(MCBSP_READ(mcbsp, SPCR1) & RRDY)) {
  911. if (attemps++ > 1000) {
  912. MCBSP_WRITE(mcbsp, SPCR1,
  913. MCBSP_READ_CACHE(mcbsp, SPCR1) &
  914. (~RRST));
  915. udelay(10);
  916. MCBSP_WRITE(mcbsp, SPCR1,
  917. MCBSP_READ_CACHE(mcbsp, SPCR1) |
  918. (RRST));
  919. udelay(10);
  920. dev_err(mcbsp->dev, "Could not read from"
  921. " McBSP%d Register\n", mcbsp->id);
  922. return -2;
  923. }
  924. }
  925. }
  926. *buf = MCBSP_READ(mcbsp, DRR1);
  927. return 0;
  928. }
  929. EXPORT_SYMBOL(omap_mcbsp_pollread);
  930. /*
  931. * IRQ based word transmission.
  932. */
  933. void omap_mcbsp_xmit_word(unsigned int id, u32 word)
  934. {
  935. struct omap_mcbsp *mcbsp;
  936. omap_mcbsp_word_length word_length;
  937. if (!omap_mcbsp_check_valid_id(id)) {
  938. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  939. return;
  940. }
  941. mcbsp = id_to_mcbsp_ptr(id);
  942. word_length = mcbsp->tx_word_length;
  943. wait_for_completion(&mcbsp->tx_irq_completion);
  944. if (word_length > OMAP_MCBSP_WORD_16)
  945. MCBSP_WRITE(mcbsp, DXR2, word >> 16);
  946. MCBSP_WRITE(mcbsp, DXR1, word & 0xffff);
  947. }
  948. EXPORT_SYMBOL(omap_mcbsp_xmit_word);
  949. u32 omap_mcbsp_recv_word(unsigned int id)
  950. {
  951. struct omap_mcbsp *mcbsp;
  952. u16 word_lsb, word_msb = 0;
  953. omap_mcbsp_word_length word_length;
  954. if (!omap_mcbsp_check_valid_id(id)) {
  955. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  956. return -ENODEV;
  957. }
  958. mcbsp = id_to_mcbsp_ptr(id);
  959. word_length = mcbsp->rx_word_length;
  960. wait_for_completion(&mcbsp->rx_irq_completion);
  961. if (word_length > OMAP_MCBSP_WORD_16)
  962. word_msb = MCBSP_READ(mcbsp, DRR2);
  963. word_lsb = MCBSP_READ(mcbsp, DRR1);
  964. return (word_lsb | (word_msb << 16));
  965. }
  966. EXPORT_SYMBOL(omap_mcbsp_recv_word);
  967. /*
  968. * Simple DMA based buffer rx/tx routines.
  969. * Nothing fancy, just a single buffer tx/rx through DMA.
  970. * The DMA resources are released once the transfer is done.
  971. * For anything fancier, you should use your own customized DMA
  972. * routines and callbacks.
  973. */
  974. int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer,
  975. unsigned int length)
  976. {
  977. struct omap_mcbsp *mcbsp;
  978. int dma_tx_ch;
  979. int src_port = 0;
  980. int dest_port = 0;
  981. int sync_dev = 0;
  982. if (!omap_mcbsp_check_valid_id(id)) {
  983. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  984. return -ENODEV;
  985. }
  986. mcbsp = id_to_mcbsp_ptr(id);
  987. if (omap_request_dma(mcbsp->dma_tx_sync, "McBSP TX",
  988. omap_mcbsp_tx_dma_callback,
  989. mcbsp,
  990. &dma_tx_ch)) {
  991. dev_err(mcbsp->dev, " Unable to request DMA channel for "
  992. "McBSP%d TX. Trying IRQ based TX\n",
  993. mcbsp->id);
  994. return -EAGAIN;
  995. }
  996. mcbsp->dma_tx_lch = dma_tx_ch;
  997. dev_err(mcbsp->dev, "McBSP%d TX DMA on channel %d\n", mcbsp->id,
  998. dma_tx_ch);
  999. init_completion(&mcbsp->tx_dma_completion);
  1000. if (cpu_class_is_omap1()) {
  1001. src_port = OMAP_DMA_PORT_TIPB;
  1002. dest_port = OMAP_DMA_PORT_EMIFF;
  1003. }
  1004. if (cpu_class_is_omap2())
  1005. sync_dev = mcbsp->dma_tx_sync;
  1006. omap_set_dma_transfer_params(mcbsp->dma_tx_lch,
  1007. OMAP_DMA_DATA_TYPE_S16,
  1008. length >> 1, 1,
  1009. OMAP_DMA_SYNC_ELEMENT,
  1010. sync_dev, 0);
  1011. omap_set_dma_dest_params(mcbsp->dma_tx_lch,
  1012. src_port,
  1013. OMAP_DMA_AMODE_CONSTANT,
  1014. mcbsp->phys_base + OMAP_MCBSP_REG_DXR1,
  1015. 0, 0);
  1016. omap_set_dma_src_params(mcbsp->dma_tx_lch,
  1017. dest_port,
  1018. OMAP_DMA_AMODE_POST_INC,
  1019. buffer,
  1020. 0, 0);
  1021. omap_start_dma(mcbsp->dma_tx_lch);
  1022. wait_for_completion(&mcbsp->tx_dma_completion);
  1023. return 0;
  1024. }
  1025. EXPORT_SYMBOL(omap_mcbsp_xmit_buffer);
  1026. int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer,
  1027. unsigned int length)
  1028. {
  1029. struct omap_mcbsp *mcbsp;
  1030. int dma_rx_ch;
  1031. int src_port = 0;
  1032. int dest_port = 0;
  1033. int sync_dev = 0;
  1034. if (!omap_mcbsp_check_valid_id(id)) {
  1035. printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
  1036. return -ENODEV;
  1037. }
  1038. mcbsp = id_to_mcbsp_ptr(id);
  1039. if (omap_request_dma(mcbsp->dma_rx_sync, "McBSP RX",
  1040. omap_mcbsp_rx_dma_callback,
  1041. mcbsp,
  1042. &dma_rx_ch)) {
  1043. dev_err(mcbsp->dev, "Unable to request DMA channel for "
  1044. "McBSP%d RX. Trying IRQ based RX\n",
  1045. mcbsp->id);
  1046. return -EAGAIN;
  1047. }
  1048. mcbsp->dma_rx_lch = dma_rx_ch;
  1049. dev_err(mcbsp->dev, "McBSP%d RX DMA on channel %d\n", mcbsp->id,
  1050. dma_rx_ch);
  1051. init_completion(&mcbsp->rx_dma_completion);
  1052. if (cpu_class_is_omap1()) {
  1053. src_port = OMAP_DMA_PORT_TIPB;
  1054. dest_port = OMAP_DMA_PORT_EMIFF;
  1055. }
  1056. if (cpu_class_is_omap2())
  1057. sync_dev = mcbsp->dma_rx_sync;
  1058. omap_set_dma_transfer_params(mcbsp->dma_rx_lch,
  1059. OMAP_DMA_DATA_TYPE_S16,
  1060. length >> 1, 1,
  1061. OMAP_DMA_SYNC_ELEMENT,
  1062. sync_dev, 0);
  1063. omap_set_dma_src_params(mcbsp->dma_rx_lch,
  1064. src_port,
  1065. OMAP_DMA_AMODE_CONSTANT,
  1066. mcbsp->phys_base + OMAP_MCBSP_REG_DRR1,
  1067. 0, 0);
  1068. omap_set_dma_dest_params(mcbsp->dma_rx_lch,
  1069. dest_port,
  1070. OMAP_DMA_AMODE_POST_INC,
  1071. buffer,
  1072. 0, 0);
  1073. omap_start_dma(mcbsp->dma_rx_lch);
  1074. wait_for_completion(&mcbsp->rx_dma_completion);
  1075. return 0;
  1076. }
  1077. EXPORT_SYMBOL(omap_mcbsp_recv_buffer);
  1078. #ifdef CONFIG_ARCH_OMAP3
  1079. #define max_thres(m) (mcbsp->pdata->buffer_size)
  1080. #define valid_threshold(m, val) ((val) <= max_thres(m))
  1081. #define THRESHOLD_PROP_BUILDER(prop) \
  1082. static ssize_t prop##_show(struct device *dev, \
  1083. struct device_attribute *attr, char *buf) \
  1084. { \
  1085. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
  1086. \
  1087. return sprintf(buf, "%u\n", mcbsp->prop); \
  1088. } \
  1089. \
  1090. static ssize_t prop##_store(struct device *dev, \
  1091. struct device_attribute *attr, \
  1092. const char *buf, size_t size) \
  1093. { \
  1094. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
  1095. unsigned long val; \
  1096. int status; \
  1097. \
  1098. status = strict_strtoul(buf, 0, &val); \
  1099. if (status) \
  1100. return status; \
  1101. \
  1102. if (!valid_threshold(mcbsp, val)) \
  1103. return -EDOM; \
  1104. \
  1105. mcbsp->prop = val; \
  1106. return size; \
  1107. } \
  1108. \
  1109. static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
  1110. THRESHOLD_PROP_BUILDER(max_tx_thres);
  1111. THRESHOLD_PROP_BUILDER(max_rx_thres);
  1112. static const char *dma_op_modes[] = {
  1113. "element", "threshold", "frame",
  1114. };
  1115. static ssize_t dma_op_mode_show(struct device *dev,
  1116. struct device_attribute *attr, char *buf)
  1117. {
  1118. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
  1119. int dma_op_mode, i = 0;
  1120. ssize_t len = 0;
  1121. const char * const *s;
  1122. dma_op_mode = mcbsp->dma_op_mode;
  1123. for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
  1124. if (dma_op_mode == i)
  1125. len += sprintf(buf + len, "[%s] ", *s);
  1126. else
  1127. len += sprintf(buf + len, "%s ", *s);
  1128. }
  1129. len += sprintf(buf + len, "\n");
  1130. return len;
  1131. }
  1132. static ssize_t dma_op_mode_store(struct device *dev,
  1133. struct device_attribute *attr,
  1134. const char *buf, size_t size)
  1135. {
  1136. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
  1137. const char * const *s;
  1138. int i = 0;
  1139. for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++)
  1140. if (sysfs_streq(buf, *s))
  1141. break;
  1142. if (i == ARRAY_SIZE(dma_op_modes))
  1143. return -EINVAL;
  1144. spin_lock_irq(&mcbsp->lock);
  1145. if (!mcbsp->free) {
  1146. size = -EBUSY;
  1147. goto unlock;
  1148. }
  1149. mcbsp->dma_op_mode = i;
  1150. unlock:
  1151. spin_unlock_irq(&mcbsp->lock);
  1152. return size;
  1153. }
  1154. static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
  1155. static ssize_t st_taps_show(struct device *dev,
  1156. struct device_attribute *attr, char *buf)
  1157. {
  1158. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
  1159. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  1160. ssize_t status = 0;
  1161. int i;
  1162. spin_lock_irq(&mcbsp->lock);
  1163. for (i = 0; i < st_data->nr_taps; i++)
  1164. status += sprintf(&buf[status], (i ? ", %d" : "%d"),
  1165. st_data->taps[i]);
  1166. if (i)
  1167. status += sprintf(&buf[status], "\n");
  1168. spin_unlock_irq(&mcbsp->lock);
  1169. return status;
  1170. }
  1171. static ssize_t st_taps_store(struct device *dev,
  1172. struct device_attribute *attr,
  1173. const char *buf, size_t size)
  1174. {
  1175. struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
  1176. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  1177. int val, tmp, status, i = 0;
  1178. spin_lock_irq(&mcbsp->lock);
  1179. memset(st_data->taps, 0, sizeof(st_data->taps));
  1180. st_data->nr_taps = 0;
  1181. do {
  1182. status = sscanf(buf, "%d%n", &val, &tmp);
  1183. if (status < 0 || status == 0) {
  1184. size = -EINVAL;
  1185. goto out;
  1186. }
  1187. if (val < -32768 || val > 32767) {
  1188. size = -EINVAL;
  1189. goto out;
  1190. }
  1191. st_data->taps[i++] = val;
  1192. buf += tmp;
  1193. if (*buf != ',')
  1194. break;
  1195. buf++;
  1196. } while (1);
  1197. st_data->nr_taps = i;
  1198. out:
  1199. spin_unlock_irq(&mcbsp->lock);
  1200. return size;
  1201. }
  1202. static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
  1203. static const struct attribute *additional_attrs[] = {
  1204. &dev_attr_max_tx_thres.attr,
  1205. &dev_attr_max_rx_thres.attr,
  1206. &dev_attr_dma_op_mode.attr,
  1207. NULL,
  1208. };
  1209. static const struct attribute_group additional_attr_group = {
  1210. .attrs = (struct attribute **)additional_attrs,
  1211. };
  1212. static inline int __devinit omap_additional_add(struct device *dev)
  1213. {
  1214. return sysfs_create_group(&dev->kobj, &additional_attr_group);
  1215. }
  1216. static inline void __devexit omap_additional_remove(struct device *dev)
  1217. {
  1218. sysfs_remove_group(&dev->kobj, &additional_attr_group);
  1219. }
  1220. static const struct attribute *sidetone_attrs[] = {
  1221. &dev_attr_st_taps.attr,
  1222. NULL,
  1223. };
  1224. static const struct attribute_group sidetone_attr_group = {
  1225. .attrs = (struct attribute **)sidetone_attrs,
  1226. };
  1227. static int __devinit omap_st_add(struct omap_mcbsp *mcbsp)
  1228. {
  1229. struct platform_device *pdev;
  1230. struct resource *res;
  1231. struct omap_mcbsp_st_data *st_data;
  1232. int err;
  1233. st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL);
  1234. if (!st_data) {
  1235. err = -ENOMEM;
  1236. goto err1;
  1237. }
  1238. pdev = container_of(mcbsp->dev, struct platform_device, dev);
  1239. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone");
  1240. st_data->io_base_st = ioremap(res->start, resource_size(res));
  1241. if (!st_data->io_base_st) {
  1242. err = -ENOMEM;
  1243. goto err2;
  1244. }
  1245. err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
  1246. if (err)
  1247. goto err3;
  1248. mcbsp->st_data = st_data;
  1249. return 0;
  1250. err3:
  1251. iounmap(st_data->io_base_st);
  1252. err2:
  1253. kfree(st_data);
  1254. err1:
  1255. return err;
  1256. }
  1257. static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp)
  1258. {
  1259. struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
  1260. if (st_data) {
  1261. sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
  1262. iounmap(st_data->io_base_st);
  1263. kfree(st_data);
  1264. }
  1265. }
  1266. static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp)
  1267. {
  1268. mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
  1269. if (cpu_is_omap34xx()) {
  1270. /*
  1271. * Initially configure the maximum thresholds to a safe value.
  1272. * The McBSP FIFO usage with these values should not go under
  1273. * 16 locations.
  1274. * If the whole FIFO without safety buffer is used, than there
  1275. * is a possibility that the DMA will be not able to push the
  1276. * new data on time, causing channel shifts in runtime.
  1277. */
  1278. mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10;
  1279. mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10;
  1280. /*
  1281. * REVISIT: Set dmap_op_mode to THRESHOLD as default
  1282. * for mcbsp2 instances.
  1283. */
  1284. if (omap_additional_add(mcbsp->dev))
  1285. dev_warn(mcbsp->dev,
  1286. "Unable to create additional controls\n");
  1287. if (mcbsp->id == 2 || mcbsp->id == 3)
  1288. if (omap_st_add(mcbsp))
  1289. dev_warn(mcbsp->dev,
  1290. "Unable to create sidetone controls\n");
  1291. } else {
  1292. mcbsp->max_tx_thres = -EINVAL;
  1293. mcbsp->max_rx_thres = -EINVAL;
  1294. }
  1295. }
  1296. static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp)
  1297. {
  1298. if (cpu_is_omap34xx()) {
  1299. omap_additional_remove(mcbsp->dev);
  1300. if (mcbsp->id == 2 || mcbsp->id == 3)
  1301. omap_st_remove(mcbsp);
  1302. }
  1303. }
  1304. #else
  1305. static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) {}
  1306. static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) {}
  1307. #endif /* CONFIG_ARCH_OMAP3 */
  1308. /*
  1309. * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
  1310. * 730 has only 2 McBSP, and both of them are MPU peripherals.
  1311. */
  1312. static int __devinit omap_mcbsp_probe(struct platform_device *pdev)
  1313. {
  1314. struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data;
  1315. struct omap_mcbsp *mcbsp;
  1316. int id = pdev->id - 1;
  1317. struct resource *res;
  1318. int ret = 0;
  1319. if (!pdata) {
  1320. dev_err(&pdev->dev, "McBSP device initialized without"
  1321. "platform data\n");
  1322. ret = -EINVAL;
  1323. goto exit;
  1324. }
  1325. dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id);
  1326. if (id >= omap_mcbsp_count) {
  1327. dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id);
  1328. ret = -EINVAL;
  1329. goto exit;
  1330. }
  1331. mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL);
  1332. if (!mcbsp) {
  1333. ret = -ENOMEM;
  1334. goto exit;
  1335. }
  1336. spin_lock_init(&mcbsp->lock);
  1337. mcbsp->id = id + 1;
  1338. mcbsp->free = true;
  1339. mcbsp->dma_tx_lch = -1;
  1340. mcbsp->dma_rx_lch = -1;
  1341. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
  1342. if (!res) {
  1343. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1344. if (!res) {
  1345. dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory"
  1346. "resource\n", __func__, pdev->id);
  1347. ret = -ENOMEM;
  1348. goto exit;
  1349. }
  1350. }
  1351. mcbsp->phys_base = res->start;
  1352. omap_mcbsp_cache_size = resource_size(res);
  1353. mcbsp->io_base = ioremap(res->start, resource_size(res));
  1354. if (!mcbsp->io_base) {
  1355. ret = -ENOMEM;
  1356. goto err_ioremap;
  1357. }
  1358. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
  1359. if (!res)
  1360. mcbsp->phys_dma_base = mcbsp->phys_base;
  1361. else
  1362. mcbsp->phys_dma_base = res->start;
  1363. /* Default I/O is IRQ based */
  1364. mcbsp->io_type = OMAP_MCBSP_IRQ_IO;
  1365. mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx");
  1366. mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx");
  1367. /* From OMAP4 there will be a single irq line */
  1368. if (mcbsp->tx_irq == -ENXIO)
  1369. mcbsp->tx_irq = platform_get_irq(pdev, 0);
  1370. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
  1371. if (!res) {
  1372. dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n",
  1373. __func__, pdev->id);
  1374. ret = -ENODEV;
  1375. goto err_res;
  1376. }
  1377. mcbsp->dma_rx_sync = res->start;
  1378. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
  1379. if (!res) {
  1380. dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n",
  1381. __func__, pdev->id);
  1382. ret = -ENODEV;
  1383. goto err_res;
  1384. }
  1385. mcbsp->dma_tx_sync = res->start;
  1386. mcbsp->fclk = clk_get(&pdev->dev, "fck");
  1387. if (IS_ERR(mcbsp->fclk)) {
  1388. ret = PTR_ERR(mcbsp->fclk);
  1389. dev_err(&pdev->dev, "unable to get fck: %d\n", ret);
  1390. goto err_res;
  1391. }
  1392. mcbsp->pdata = pdata;
  1393. mcbsp->dev = &pdev->dev;
  1394. mcbsp_ptr[id] = mcbsp;
  1395. mcbsp->mcbsp_config_type = pdata->mcbsp_config_type;
  1396. platform_set_drvdata(pdev, mcbsp);
  1397. pm_runtime_enable(mcbsp->dev);
  1398. /* Initialize mcbsp properties for OMAP34XX if needed / applicable */
  1399. omap34xx_device_init(mcbsp);
  1400. return 0;
  1401. err_res:
  1402. iounmap(mcbsp->io_base);
  1403. err_ioremap:
  1404. kfree(mcbsp);
  1405. exit:
  1406. return ret;
  1407. }
  1408. static int __devexit omap_mcbsp_remove(struct platform_device *pdev)
  1409. {
  1410. struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
  1411. platform_set_drvdata(pdev, NULL);
  1412. if (mcbsp) {
  1413. if (mcbsp->pdata && mcbsp->pdata->ops &&
  1414. mcbsp->pdata->ops->free)
  1415. mcbsp->pdata->ops->free(mcbsp->id);
  1416. omap34xx_device_exit(mcbsp);
  1417. clk_put(mcbsp->fclk);
  1418. iounmap(mcbsp->io_base);
  1419. kfree(mcbsp);
  1420. }
  1421. return 0;
  1422. }
  1423. static struct platform_driver omap_mcbsp_driver = {
  1424. .probe = omap_mcbsp_probe,
  1425. .remove = __devexit_p(omap_mcbsp_remove),
  1426. .driver = {
  1427. .name = "omap-mcbsp",
  1428. },
  1429. };
  1430. int __init omap_mcbsp_init(void)
  1431. {
  1432. /* Register the McBSP driver */
  1433. return platform_driver_register(&omap_mcbsp_driver);
  1434. }