fsl_ssi.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. /*
  2. * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  3. *
  4. * Author: Timur Tabi <timur@freescale.com>
  5. *
  6. * Copyright 2007-2010 Freescale Semiconductor, Inc.
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. *
  12. *
  13. * Some notes why imx-pcm-fiq is used instead of DMA on some boards:
  14. *
  15. * The i.MX SSI core has some nasty limitations in AC97 mode. While most
  16. * sane processor vendors have a FIFO per AC97 slot, the i.MX has only
  17. * one FIFO which combines all valid receive slots. We cannot even select
  18. * which slots we want to receive. The WM9712 with which this driver
  19. * was developed with always sends GPIO status data in slot 12 which
  20. * we receive in our (PCM-) data stream. The only chance we have is to
  21. * manually skip this data in the FIQ handler. With sampling rates different
  22. * from 48000Hz not every frame has valid receive data, so the ratio
  23. * between pcm data and GPIO status data changes. Our FIQ handler is not
  24. * able to handle this, hence this driver only works with 48000Hz sampling
  25. * rate.
  26. * Reading and writing AC97 registers is another challenge. The core
  27. * provides us status bits when the read register is updated with *another*
  28. * value. When we read the same register two times (and the register still
  29. * contains the same value) these status bits are not set. We work
  30. * around this by not polling these bits but only wait a fixed delay.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/io.h>
  34. #include <linux/module.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/clk.h>
  37. #include <linux/device.h>
  38. #include <linux/delay.h>
  39. #include <linux/slab.h>
  40. #include <linux/spinlock.h>
  41. #include <linux/of.h>
  42. #include <linux/of_address.h>
  43. #include <linux/of_irq.h>
  44. #include <linux/of_platform.h>
  45. #include <sound/core.h>
  46. #include <sound/pcm.h>
  47. #include <sound/pcm_params.h>
  48. #include <sound/initval.h>
  49. #include <sound/soc.h>
  50. #include <sound/dmaengine_pcm.h>
  51. #include "fsl_ssi.h"
  52. #include "imx-pcm.h"
  53. /**
  54. * FSLSSI_I2S_RATES: sample rates supported by the I2S
  55. *
  56. * This driver currently only supports the SSI running in I2S slave mode,
  57. * which means the codec determines the sample rate. Therefore, we tell
  58. * ALSA that we support all rates and let the codec driver decide what rates
  59. * are really supported.
  60. */
  61. #define FSLSSI_I2S_RATES SNDRV_PCM_RATE_CONTINUOUS
  62. /**
  63. * FSLSSI_I2S_FORMATS: audio formats supported by the SSI
  64. *
  65. * The SSI has a limitation in that the samples must be in the same byte
  66. * order as the host CPU. This is because when multiple bytes are written
  67. * to the STX register, the bytes and bits must be written in the same
  68. * order. The STX is a shift register, so all the bits need to be aligned
  69. * (bit-endianness must match byte-endianness). Processors typically write
  70. * the bits within a byte in the same order that the bytes of a word are
  71. * written in. So if the host CPU is big-endian, then only big-endian
  72. * samples will be written to STX properly.
  73. */
  74. #ifdef __BIG_ENDIAN
  75. #define FSLSSI_I2S_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE | \
  76. SNDRV_PCM_FMTBIT_S18_3BE | SNDRV_PCM_FMTBIT_S20_3BE | \
  77. SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_S24_BE)
  78. #else
  79. #define FSLSSI_I2S_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \
  80. SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  81. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE)
  82. #endif
  83. #define FSLSSI_SIER_DBG_RX_FLAGS (CCSR_SSI_SIER_RFF0_EN | \
  84. CCSR_SSI_SIER_RLS_EN | CCSR_SSI_SIER_RFS_EN | \
  85. CCSR_SSI_SIER_ROE0_EN | CCSR_SSI_SIER_RFRC_EN)
  86. #define FSLSSI_SIER_DBG_TX_FLAGS (CCSR_SSI_SIER_TFE0_EN | \
  87. CCSR_SSI_SIER_TLS_EN | CCSR_SSI_SIER_TFS_EN | \
  88. CCSR_SSI_SIER_TUE0_EN | CCSR_SSI_SIER_TFRC_EN)
  89. enum fsl_ssi_type {
  90. FSL_SSI_MCP8610,
  91. FSL_SSI_MX21,
  92. FSL_SSI_MX35,
  93. FSL_SSI_MX51,
  94. };
  95. struct fsl_ssi_reg_val {
  96. u32 sier;
  97. u32 srcr;
  98. u32 stcr;
  99. u32 scr;
  100. };
  101. struct fsl_ssi_rxtx_reg_val {
  102. struct fsl_ssi_reg_val rx;
  103. struct fsl_ssi_reg_val tx;
  104. };
  105. static const struct reg_default fsl_ssi_reg_defaults[] = {
  106. {0x10, 0x00000000},
  107. {0x18, 0x00003003},
  108. {0x1c, 0x00000200},
  109. {0x20, 0x00000200},
  110. {0x24, 0x00040000},
  111. {0x28, 0x00040000},
  112. {0x38, 0x00000000},
  113. {0x48, 0x00000000},
  114. {0x4c, 0x00000000},
  115. {0x54, 0x00000000},
  116. {0x58, 0x00000000},
  117. };
  118. static bool fsl_ssi_readable_reg(struct device *dev, unsigned int reg)
  119. {
  120. switch (reg) {
  121. case CCSR_SSI_SACCEN:
  122. case CCSR_SSI_SACCDIS:
  123. return false;
  124. default:
  125. return true;
  126. }
  127. }
  128. static bool fsl_ssi_volatile_reg(struct device *dev, unsigned int reg)
  129. {
  130. switch (reg) {
  131. case CCSR_SSI_STX0:
  132. case CCSR_SSI_STX1:
  133. case CCSR_SSI_SRX0:
  134. case CCSR_SSI_SRX1:
  135. case CCSR_SSI_SISR:
  136. case CCSR_SSI_SFCSR:
  137. case CCSR_SSI_SACADD:
  138. case CCSR_SSI_SACDAT:
  139. case CCSR_SSI_SATAG:
  140. case CCSR_SSI_SACCST:
  141. return true;
  142. default:
  143. return false;
  144. }
  145. }
  146. static bool fsl_ssi_writeable_reg(struct device *dev, unsigned int reg)
  147. {
  148. switch (reg) {
  149. case CCSR_SSI_SRX0:
  150. case CCSR_SSI_SRX1:
  151. case CCSR_SSI_SACCST:
  152. return false;
  153. default:
  154. return true;
  155. }
  156. }
  157. static const struct regmap_config fsl_ssi_regconfig = {
  158. .max_register = CCSR_SSI_SACCDIS,
  159. .reg_bits = 32,
  160. .val_bits = 32,
  161. .reg_stride = 4,
  162. .val_format_endian = REGMAP_ENDIAN_NATIVE,
  163. .reg_defaults = fsl_ssi_reg_defaults,
  164. .num_reg_defaults = ARRAY_SIZE(fsl_ssi_reg_defaults),
  165. .readable_reg = fsl_ssi_readable_reg,
  166. .volatile_reg = fsl_ssi_volatile_reg,
  167. .writeable_reg = fsl_ssi_writeable_reg,
  168. .cache_type = REGCACHE_RBTREE,
  169. };
  170. struct fsl_ssi_soc_data {
  171. bool imx;
  172. bool offline_config;
  173. u32 sisr_write_mask;
  174. };
  175. /**
  176. * fsl_ssi_private: per-SSI private data
  177. *
  178. * @reg: Pointer to the regmap registers
  179. * @irq: IRQ of this SSI
  180. * @cpu_dai_drv: CPU DAI driver for this device
  181. *
  182. * @dai_fmt: DAI configuration this device is currently used with
  183. * @i2s_mode: i2s and network mode configuration of the device. Is used to
  184. * switch between normal and i2s/network mode
  185. * mode depending on the number of channels
  186. * @use_dma: DMA is used or FIQ with stream filter
  187. * @use_dual_fifo: DMA with support for both FIFOs used
  188. * @fifo_deph: Depth of the SSI FIFOs
  189. * @rxtx_reg_val: Specific register settings for receive/transmit configuration
  190. *
  191. * @clk: SSI clock
  192. * @baudclk: SSI baud clock for master mode
  193. * @baudclk_streams: Active streams that are using baudclk
  194. * @bitclk_freq: bitclock frequency set by .set_dai_sysclk
  195. *
  196. * @dma_params_tx: DMA transmit parameters
  197. * @dma_params_rx: DMA receive parameters
  198. * @ssi_phys: physical address of the SSI registers
  199. *
  200. * @fiq_params: FIQ stream filtering parameters
  201. *
  202. * @pdev: Pointer to pdev used for deprecated fsl-ssi sound card
  203. *
  204. * @dbg_stats: Debugging statistics
  205. *
  206. * @soc: SoC specific data
  207. */
  208. struct fsl_ssi_private {
  209. struct regmap *regs;
  210. int irq;
  211. struct snd_soc_dai_driver cpu_dai_drv;
  212. unsigned int dai_fmt;
  213. u8 i2s_mode;
  214. bool use_dma;
  215. bool use_dual_fifo;
  216. bool has_ipg_clk_name;
  217. unsigned int fifo_depth;
  218. struct fsl_ssi_rxtx_reg_val rxtx_reg_val;
  219. struct clk *clk;
  220. struct clk *baudclk;
  221. unsigned int baudclk_streams;
  222. unsigned int bitclk_freq;
  223. /*regcache for SFCSR*/
  224. u32 regcache_sfcsr;
  225. /* DMA params */
  226. struct snd_dmaengine_dai_dma_data dma_params_tx;
  227. struct snd_dmaengine_dai_dma_data dma_params_rx;
  228. dma_addr_t ssi_phys;
  229. /* params for non-dma FIQ stream filtered mode */
  230. struct imx_pcm_fiq_params fiq_params;
  231. /* Used when using fsl-ssi as sound-card. This is only used by ppc and
  232. * should be replaced with simple-sound-card. */
  233. struct platform_device *pdev;
  234. struct fsl_ssi_dbg dbg_stats;
  235. const struct fsl_ssi_soc_data *soc;
  236. };
  237. /*
  238. * imx51 and later SoCs have a slightly different IP that allows the
  239. * SSI configuration while the SSI unit is running.
  240. *
  241. * More important, it is necessary on those SoCs to configure the
  242. * sperate TX/RX DMA bits just before starting the stream
  243. * (fsl_ssi_trigger). The SDMA unit has to be configured before fsl_ssi
  244. * sends any DMA requests to the SDMA unit, otherwise it is not defined
  245. * how the SDMA unit handles the DMA request.
  246. *
  247. * SDMA units are present on devices starting at imx35 but the imx35
  248. * reference manual states that the DMA bits should not be changed
  249. * while the SSI unit is running (SSIEN). So we support the necessary
  250. * online configuration of fsl-ssi starting at imx51.
  251. */
  252. static struct fsl_ssi_soc_data fsl_ssi_mpc8610 = {
  253. .imx = false,
  254. .offline_config = true,
  255. .sisr_write_mask = CCSR_SSI_SISR_RFRC | CCSR_SSI_SISR_TFRC |
  256. CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 |
  257. CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1,
  258. };
  259. static struct fsl_ssi_soc_data fsl_ssi_imx21 = {
  260. .imx = true,
  261. .offline_config = true,
  262. .sisr_write_mask = 0,
  263. };
  264. static struct fsl_ssi_soc_data fsl_ssi_imx35 = {
  265. .imx = true,
  266. .offline_config = true,
  267. .sisr_write_mask = CCSR_SSI_SISR_RFRC | CCSR_SSI_SISR_TFRC |
  268. CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 |
  269. CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1,
  270. };
  271. static struct fsl_ssi_soc_data fsl_ssi_imx51 = {
  272. .imx = true,
  273. .offline_config = false,
  274. .sisr_write_mask = CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 |
  275. CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1,
  276. };
  277. static const struct of_device_id fsl_ssi_ids[] = {
  278. { .compatible = "fsl,mpc8610-ssi", .data = &fsl_ssi_mpc8610 },
  279. { .compatible = "fsl,imx51-ssi", .data = &fsl_ssi_imx51 },
  280. { .compatible = "fsl,imx35-ssi", .data = &fsl_ssi_imx35 },
  281. { .compatible = "fsl,imx21-ssi", .data = &fsl_ssi_imx21 },
  282. {}
  283. };
  284. MODULE_DEVICE_TABLE(of, fsl_ssi_ids);
  285. static bool fsl_ssi_is_ac97(struct fsl_ssi_private *ssi_private)
  286. {
  287. return (ssi_private->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) ==
  288. SND_SOC_DAIFMT_AC97;
  289. }
  290. static bool fsl_ssi_is_i2s_master(struct fsl_ssi_private *ssi_private)
  291. {
  292. return (ssi_private->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) ==
  293. SND_SOC_DAIFMT_CBS_CFS;
  294. }
  295. static bool fsl_ssi_is_i2s_cbm_cfs(struct fsl_ssi_private *ssi_private)
  296. {
  297. return (ssi_private->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) ==
  298. SND_SOC_DAIFMT_CBM_CFS;
  299. }
  300. /**
  301. * fsl_ssi_isr: SSI interrupt handler
  302. *
  303. * Although it's possible to use the interrupt handler to send and receive
  304. * data to/from the SSI, we use the DMA instead. Programming is more
  305. * complicated, but the performance is much better.
  306. *
  307. * This interrupt handler is used only to gather statistics.
  308. *
  309. * @irq: IRQ of the SSI device
  310. * @dev_id: pointer to the ssi_private structure for this SSI device
  311. */
  312. static irqreturn_t fsl_ssi_isr(int irq, void *dev_id)
  313. {
  314. struct fsl_ssi_private *ssi_private = dev_id;
  315. struct regmap *regs = ssi_private->regs;
  316. __be32 sisr;
  317. __be32 sisr2;
  318. /* We got an interrupt, so read the status register to see what we
  319. were interrupted for. We mask it with the Interrupt Enable register
  320. so that we only check for events that we're interested in.
  321. */
  322. regmap_read(regs, CCSR_SSI_SISR, &sisr);
  323. sisr2 = sisr & ssi_private->soc->sisr_write_mask;
  324. /* Clear the bits that we set */
  325. if (sisr2)
  326. regmap_write(regs, CCSR_SSI_SISR, sisr2);
  327. fsl_ssi_dbg_isr(&ssi_private->dbg_stats, sisr);
  328. return IRQ_HANDLED;
  329. }
  330. /*
  331. * Enable/Disable all rx/tx config flags at once.
  332. */
  333. static void fsl_ssi_rxtx_config(struct fsl_ssi_private *ssi_private,
  334. bool enable)
  335. {
  336. struct regmap *regs = ssi_private->regs;
  337. struct fsl_ssi_rxtx_reg_val *vals = &ssi_private->rxtx_reg_val;
  338. if (enable) {
  339. regmap_update_bits(regs, CCSR_SSI_SIER,
  340. vals->rx.sier | vals->tx.sier,
  341. vals->rx.sier | vals->tx.sier);
  342. regmap_update_bits(regs, CCSR_SSI_SRCR,
  343. vals->rx.srcr | vals->tx.srcr,
  344. vals->rx.srcr | vals->tx.srcr);
  345. regmap_update_bits(regs, CCSR_SSI_STCR,
  346. vals->rx.stcr | vals->tx.stcr,
  347. vals->rx.stcr | vals->tx.stcr);
  348. } else {
  349. regmap_update_bits(regs, CCSR_SSI_SRCR,
  350. vals->rx.srcr | vals->tx.srcr, 0);
  351. regmap_update_bits(regs, CCSR_SSI_STCR,
  352. vals->rx.stcr | vals->tx.stcr, 0);
  353. regmap_update_bits(regs, CCSR_SSI_SIER,
  354. vals->rx.sier | vals->tx.sier, 0);
  355. }
  356. }
  357. /*
  358. * Calculate the bits that have to be disabled for the current stream that is
  359. * getting disabled. This keeps the bits enabled that are necessary for the
  360. * second stream to work if 'stream_active' is true.
  361. *
  362. * Detailed calculation:
  363. * These are the values that need to be active after disabling. For non-active
  364. * second stream, this is 0:
  365. * vals_stream * !!stream_active
  366. *
  367. * The following computes the overall differences between the setup for the
  368. * to-disable stream and the active stream, a simple XOR:
  369. * vals_disable ^ (vals_stream * !!(stream_active))
  370. *
  371. * The full expression adds a mask on all values we care about
  372. */
  373. #define fsl_ssi_disable_val(vals_disable, vals_stream, stream_active) \
  374. ((vals_disable) & \
  375. ((vals_disable) ^ ((vals_stream) * (u32)!!(stream_active))))
  376. /*
  377. * Enable/Disable a ssi configuration. You have to pass either
  378. * ssi_private->rxtx_reg_val.rx or tx as vals parameter.
  379. */
  380. static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable,
  381. struct fsl_ssi_reg_val *vals)
  382. {
  383. struct regmap *regs = ssi_private->regs;
  384. struct fsl_ssi_reg_val *avals;
  385. int nr_active_streams;
  386. u32 scr_val;
  387. int keep_active;
  388. regmap_read(regs, CCSR_SSI_SCR, &scr_val);
  389. nr_active_streams = !!(scr_val & CCSR_SSI_SCR_TE) +
  390. !!(scr_val & CCSR_SSI_SCR_RE);
  391. if (nr_active_streams - 1 > 0)
  392. keep_active = 1;
  393. else
  394. keep_active = 0;
  395. /* Find the other direction values rx or tx which we do not want to
  396. * modify */
  397. if (&ssi_private->rxtx_reg_val.rx == vals)
  398. avals = &ssi_private->rxtx_reg_val.tx;
  399. else
  400. avals = &ssi_private->rxtx_reg_val.rx;
  401. /* If vals should be disabled, start with disabling the unit */
  402. if (!enable) {
  403. u32 scr = fsl_ssi_disable_val(vals->scr, avals->scr,
  404. keep_active);
  405. regmap_update_bits(regs, CCSR_SSI_SCR, scr, 0);
  406. }
  407. /*
  408. * We are running on a SoC which does not support online SSI
  409. * reconfiguration, so we have to enable all necessary flags at once
  410. * even if we do not use them later (capture and playback configuration)
  411. */
  412. if (ssi_private->soc->offline_config) {
  413. if ((enable && !nr_active_streams) ||
  414. (!enable && !keep_active))
  415. fsl_ssi_rxtx_config(ssi_private, enable);
  416. goto config_done;
  417. }
  418. /*
  419. * Configure single direction units while the SSI unit is running
  420. * (online configuration)
  421. */
  422. if (enable) {
  423. regmap_update_bits(regs, CCSR_SSI_SIER, vals->sier, vals->sier);
  424. regmap_update_bits(regs, CCSR_SSI_SRCR, vals->srcr, vals->srcr);
  425. regmap_update_bits(regs, CCSR_SSI_STCR, vals->stcr, vals->stcr);
  426. } else {
  427. u32 sier;
  428. u32 srcr;
  429. u32 stcr;
  430. /*
  431. * Disabling the necessary flags for one of rx/tx while the
  432. * other stream is active is a little bit more difficult. We
  433. * have to disable only those flags that differ between both
  434. * streams (rx XOR tx) and that are set in the stream that is
  435. * disabled now. Otherwise we could alter flags of the other
  436. * stream
  437. */
  438. /* These assignments are simply vals without bits set in avals*/
  439. sier = fsl_ssi_disable_val(vals->sier, avals->sier,
  440. keep_active);
  441. srcr = fsl_ssi_disable_val(vals->srcr, avals->srcr,
  442. keep_active);
  443. stcr = fsl_ssi_disable_val(vals->stcr, avals->stcr,
  444. keep_active);
  445. regmap_update_bits(regs, CCSR_SSI_SRCR, srcr, 0);
  446. regmap_update_bits(regs, CCSR_SSI_STCR, stcr, 0);
  447. regmap_update_bits(regs, CCSR_SSI_SIER, sier, 0);
  448. }
  449. config_done:
  450. /* Enabling of subunits is done after configuration */
  451. if (enable)
  452. regmap_update_bits(regs, CCSR_SSI_SCR, vals->scr, vals->scr);
  453. }
  454. static void fsl_ssi_rx_config(struct fsl_ssi_private *ssi_private, bool enable)
  455. {
  456. fsl_ssi_config(ssi_private, enable, &ssi_private->rxtx_reg_val.rx);
  457. }
  458. static void fsl_ssi_tx_config(struct fsl_ssi_private *ssi_private, bool enable)
  459. {
  460. fsl_ssi_config(ssi_private, enable, &ssi_private->rxtx_reg_val.tx);
  461. }
  462. /*
  463. * Setup rx/tx register values used to enable/disable the streams. These will
  464. * be used later in fsl_ssi_config to setup the streams without the need to
  465. * check for all different SSI modes.
  466. */
  467. static void fsl_ssi_setup_reg_vals(struct fsl_ssi_private *ssi_private)
  468. {
  469. struct fsl_ssi_rxtx_reg_val *reg = &ssi_private->rxtx_reg_val;
  470. reg->rx.sier = CCSR_SSI_SIER_RFF0_EN;
  471. reg->rx.srcr = CCSR_SSI_SRCR_RFEN0;
  472. reg->rx.scr = 0;
  473. reg->tx.sier = CCSR_SSI_SIER_TFE0_EN;
  474. reg->tx.stcr = CCSR_SSI_STCR_TFEN0;
  475. reg->tx.scr = 0;
  476. if (!fsl_ssi_is_ac97(ssi_private)) {
  477. reg->rx.scr = CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE;
  478. reg->rx.sier |= CCSR_SSI_SIER_RFF0_EN;
  479. reg->tx.scr = CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE;
  480. reg->tx.sier |= CCSR_SSI_SIER_TFE0_EN;
  481. }
  482. if (ssi_private->use_dma) {
  483. reg->rx.sier |= CCSR_SSI_SIER_RDMAE;
  484. reg->tx.sier |= CCSR_SSI_SIER_TDMAE;
  485. } else {
  486. reg->rx.sier |= CCSR_SSI_SIER_RIE;
  487. reg->tx.sier |= CCSR_SSI_SIER_TIE;
  488. }
  489. reg->rx.sier |= FSLSSI_SIER_DBG_RX_FLAGS;
  490. reg->tx.sier |= FSLSSI_SIER_DBG_TX_FLAGS;
  491. }
  492. static void fsl_ssi_setup_ac97(struct fsl_ssi_private *ssi_private)
  493. {
  494. struct regmap *regs = ssi_private->regs;
  495. /*
  496. * Setup the clock control register
  497. */
  498. regmap_write(regs, CCSR_SSI_STCCR,
  499. CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13));
  500. regmap_write(regs, CCSR_SSI_SRCCR,
  501. CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13));
  502. /*
  503. * Enable AC97 mode and startup the SSI
  504. */
  505. regmap_write(regs, CCSR_SSI_SACNT,
  506. CCSR_SSI_SACNT_AC97EN | CCSR_SSI_SACNT_FV);
  507. regmap_write(regs, CCSR_SSI_SACCDIS, 0xff);
  508. regmap_write(regs, CCSR_SSI_SACCEN, 0x300);
  509. /*
  510. * Enable SSI, Transmit and Receive. AC97 has to communicate with the
  511. * codec before a stream is started.
  512. */
  513. regmap_update_bits(regs, CCSR_SSI_SCR,
  514. CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE,
  515. CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE);
  516. regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_WAIT(3));
  517. }
  518. /**
  519. * fsl_ssi_startup: create a new substream
  520. *
  521. * This is the first function called when a stream is opened.
  522. *
  523. * If this is the first stream open, then grab the IRQ and program most of
  524. * the SSI registers.
  525. */
  526. static int fsl_ssi_startup(struct snd_pcm_substream *substream,
  527. struct snd_soc_dai *dai)
  528. {
  529. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  530. struct fsl_ssi_private *ssi_private =
  531. snd_soc_dai_get_drvdata(rtd->cpu_dai);
  532. int ret;
  533. ret = clk_prepare_enable(ssi_private->clk);
  534. if (ret)
  535. return ret;
  536. /* When using dual fifo mode, it is safer to ensure an even period
  537. * size. If appearing to an odd number while DMA always starts its
  538. * task from fifo0, fifo1 would be neglected at the end of each
  539. * period. But SSI would still access fifo1 with an invalid data.
  540. */
  541. if (ssi_private->use_dual_fifo)
  542. snd_pcm_hw_constraint_step(substream->runtime, 0,
  543. SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2);
  544. return 0;
  545. }
  546. /**
  547. * fsl_ssi_shutdown: shutdown the SSI
  548. *
  549. */
  550. static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
  551. struct snd_soc_dai *dai)
  552. {
  553. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  554. struct fsl_ssi_private *ssi_private =
  555. snd_soc_dai_get_drvdata(rtd->cpu_dai);
  556. clk_disable_unprepare(ssi_private->clk);
  557. }
  558. /**
  559. * fsl_ssi_set_bclk - configure Digital Audio Interface bit clock
  560. *
  561. * Note: This function can be only called when using SSI as DAI master
  562. *
  563. * Quick instruction for parameters:
  564. * freq: Output BCLK frequency = samplerate * 32 (fixed) * channels
  565. * dir: SND_SOC_CLOCK_OUT -> TxBCLK, SND_SOC_CLOCK_IN -> RxBCLK.
  566. */
  567. static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
  568. struct snd_soc_dai *cpu_dai,
  569. struct snd_pcm_hw_params *hw_params)
  570. {
  571. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
  572. struct regmap *regs = ssi_private->regs;
  573. int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret;
  574. u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i;
  575. unsigned long clkrate, baudrate, tmprate;
  576. u64 sub, savesub = 100000;
  577. unsigned int freq;
  578. bool baudclk_is_used;
  579. /* Prefer the explicitly set bitclock frequency */
  580. if (ssi_private->bitclk_freq)
  581. freq = ssi_private->bitclk_freq;
  582. else
  583. freq = params_channels(hw_params) * 32 * params_rate(hw_params);
  584. /* Don't apply it to any non-baudclk circumstance */
  585. if (IS_ERR(ssi_private->baudclk))
  586. return -EINVAL;
  587. baudclk_is_used = ssi_private->baudclk_streams & ~(BIT(substream->stream));
  588. /* It should be already enough to divide clock by setting pm alone */
  589. psr = 0;
  590. div2 = 0;
  591. factor = (div2 + 1) * (7 * psr + 1) * 2;
  592. for (i = 0; i < 255; i++) {
  593. tmprate = freq * factor * (i + 1);
  594. if (baudclk_is_used)
  595. clkrate = clk_get_rate(ssi_private->baudclk);
  596. else
  597. clkrate = clk_round_rate(ssi_private->baudclk, tmprate);
  598. /*
  599. * Hardware limitation: The bclk rate must be
  600. * never greater than 1/5 IPG clock rate
  601. */
  602. if (clkrate * 5 > clk_get_rate(ssi_private->clk))
  603. continue;
  604. clkrate /= factor;
  605. afreq = clkrate / (i + 1);
  606. if (freq == afreq)
  607. sub = 0;
  608. else if (freq / afreq == 1)
  609. sub = freq - afreq;
  610. else if (afreq / freq == 1)
  611. sub = afreq - freq;
  612. else
  613. continue;
  614. /* Calculate the fraction */
  615. sub *= 100000;
  616. do_div(sub, freq);
  617. if (sub < savesub && !(i == 0 && psr == 0 && div2 == 0)) {
  618. baudrate = tmprate;
  619. savesub = sub;
  620. pm = i;
  621. }
  622. /* We are lucky */
  623. if (savesub == 0)
  624. break;
  625. }
  626. /* No proper pm found if it is still remaining the initial value */
  627. if (pm == 999) {
  628. dev_err(cpu_dai->dev, "failed to handle the required sysclk\n");
  629. return -EINVAL;
  630. }
  631. stccr = CCSR_SSI_SxCCR_PM(pm + 1) | (div2 ? CCSR_SSI_SxCCR_DIV2 : 0) |
  632. (psr ? CCSR_SSI_SxCCR_PSR : 0);
  633. mask = CCSR_SSI_SxCCR_PM_MASK | CCSR_SSI_SxCCR_DIV2 |
  634. CCSR_SSI_SxCCR_PSR;
  635. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || synchronous)
  636. regmap_update_bits(regs, CCSR_SSI_STCCR, mask, stccr);
  637. else
  638. regmap_update_bits(regs, CCSR_SSI_SRCCR, mask, stccr);
  639. if (!baudclk_is_used) {
  640. ret = clk_set_rate(ssi_private->baudclk, baudrate);
  641. if (ret) {
  642. dev_err(cpu_dai->dev, "failed to set baudclk rate\n");
  643. return -EINVAL;
  644. }
  645. }
  646. return 0;
  647. }
  648. static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
  649. int clk_id, unsigned int freq, int dir)
  650. {
  651. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
  652. ssi_private->bitclk_freq = freq;
  653. return 0;
  654. }
  655. /**
  656. * fsl_ssi_hw_params - program the sample size
  657. *
  658. * Most of the SSI registers have been programmed in the startup function,
  659. * but the word length must be programmed here. Unfortunately, programming
  660. * the SxCCR.WL bits requires the SSI to be temporarily disabled. This can
  661. * cause a problem with supporting simultaneous playback and capture. If
  662. * the SSI is already playing a stream, then that stream may be temporarily
  663. * stopped when you start capture.
  664. *
  665. * Note: The SxCCR.DC and SxCCR.PM bits are only used if the SSI is the
  666. * clock master.
  667. */
  668. static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
  669. struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai)
  670. {
  671. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
  672. struct regmap *regs = ssi_private->regs;
  673. unsigned int channels = params_channels(hw_params);
  674. unsigned int sample_size =
  675. snd_pcm_format_width(params_format(hw_params));
  676. u32 wl = CCSR_SSI_SxCCR_WL(sample_size);
  677. int ret;
  678. u32 scr_val;
  679. int enabled;
  680. regmap_read(regs, CCSR_SSI_SCR, &scr_val);
  681. enabled = scr_val & CCSR_SSI_SCR_SSIEN;
  682. /*
  683. * If we're in synchronous mode, and the SSI is already enabled,
  684. * then STCCR is already set properly.
  685. */
  686. if (enabled && ssi_private->cpu_dai_drv.symmetric_rates)
  687. return 0;
  688. if (fsl_ssi_is_i2s_master(ssi_private)) {
  689. ret = fsl_ssi_set_bclk(substream, cpu_dai, hw_params);
  690. if (ret)
  691. return ret;
  692. /* Do not enable the clock if it is already enabled */
  693. if (!(ssi_private->baudclk_streams & BIT(substream->stream))) {
  694. ret = clk_prepare_enable(ssi_private->baudclk);
  695. if (ret)
  696. return ret;
  697. ssi_private->baudclk_streams |= BIT(substream->stream);
  698. }
  699. }
  700. if (!fsl_ssi_is_ac97(ssi_private)) {
  701. u8 i2smode;
  702. /*
  703. * Switch to normal net mode in order to have a frame sync
  704. * signal every 32 bits instead of 16 bits
  705. */
  706. if (fsl_ssi_is_i2s_cbm_cfs(ssi_private) && sample_size == 16)
  707. i2smode = CCSR_SSI_SCR_I2S_MODE_NORMAL |
  708. CCSR_SSI_SCR_NET;
  709. else
  710. i2smode = ssi_private->i2s_mode;
  711. regmap_update_bits(regs, CCSR_SSI_SCR,
  712. CCSR_SSI_SCR_NET | CCSR_SSI_SCR_I2S_MODE_MASK,
  713. channels == 1 ? 0 : i2smode);
  714. }
  715. /*
  716. * FIXME: The documentation says that SxCCR[WL] should not be
  717. * modified while the SSI is enabled. The only time this can
  718. * happen is if we're trying to do simultaneous playback and
  719. * capture in asynchronous mode. Unfortunately, I have been enable
  720. * to get that to work at all on the P1022DS. Therefore, we don't
  721. * bother to disable/enable the SSI when setting SxCCR[WL], because
  722. * the SSI will stop anyway. Maybe one day, this will get fixed.
  723. */
  724. /* In synchronous mode, the SSI uses STCCR for capture */
  725. if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ||
  726. ssi_private->cpu_dai_drv.symmetric_rates)
  727. regmap_update_bits(regs, CCSR_SSI_STCCR, CCSR_SSI_SxCCR_WL_MASK,
  728. wl);
  729. else
  730. regmap_update_bits(regs, CCSR_SSI_SRCCR, CCSR_SSI_SxCCR_WL_MASK,
  731. wl);
  732. return 0;
  733. }
  734. static int fsl_ssi_hw_free(struct snd_pcm_substream *substream,
  735. struct snd_soc_dai *cpu_dai)
  736. {
  737. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  738. struct fsl_ssi_private *ssi_private =
  739. snd_soc_dai_get_drvdata(rtd->cpu_dai);
  740. if (fsl_ssi_is_i2s_master(ssi_private) &&
  741. ssi_private->baudclk_streams & BIT(substream->stream)) {
  742. clk_disable_unprepare(ssi_private->baudclk);
  743. ssi_private->baudclk_streams &= ~BIT(substream->stream);
  744. }
  745. return 0;
  746. }
  747. static int _fsl_ssi_set_dai_fmt(struct device *dev,
  748. struct fsl_ssi_private *ssi_private,
  749. unsigned int fmt)
  750. {
  751. struct regmap *regs = ssi_private->regs;
  752. u32 strcr = 0, stcr, srcr, scr, mask;
  753. u8 wm;
  754. ssi_private->dai_fmt = fmt;
  755. if (fsl_ssi_is_i2s_master(ssi_private) && IS_ERR(ssi_private->baudclk)) {
  756. dev_err(dev, "baudclk is missing which is necessary for master mode\n");
  757. return -EINVAL;
  758. }
  759. fsl_ssi_setup_reg_vals(ssi_private);
  760. regmap_read(regs, CCSR_SSI_SCR, &scr);
  761. scr &= ~(CCSR_SSI_SCR_SYN | CCSR_SSI_SCR_I2S_MODE_MASK);
  762. scr |= CCSR_SSI_SCR_SYNC_TX_FS;
  763. mask = CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFDIR | CCSR_SSI_STCR_TXDIR |
  764. CCSR_SSI_STCR_TSCKP | CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TFSL |
  765. CCSR_SSI_STCR_TEFS;
  766. regmap_read(regs, CCSR_SSI_STCR, &stcr);
  767. regmap_read(regs, CCSR_SSI_SRCR, &srcr);
  768. stcr &= ~mask;
  769. srcr &= ~mask;
  770. ssi_private->i2s_mode = CCSR_SSI_SCR_NET;
  771. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  772. case SND_SOC_DAIFMT_I2S:
  773. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  774. case SND_SOC_DAIFMT_CBM_CFS:
  775. case SND_SOC_DAIFMT_CBS_CFS:
  776. ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_MASTER;
  777. regmap_update_bits(regs, CCSR_SSI_STCCR,
  778. CCSR_SSI_SxCCR_DC_MASK,
  779. CCSR_SSI_SxCCR_DC(2));
  780. regmap_update_bits(regs, CCSR_SSI_SRCCR,
  781. CCSR_SSI_SxCCR_DC_MASK,
  782. CCSR_SSI_SxCCR_DC(2));
  783. break;
  784. case SND_SOC_DAIFMT_CBM_CFM:
  785. ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_SLAVE;
  786. break;
  787. default:
  788. return -EINVAL;
  789. }
  790. /* Data on rising edge of bclk, frame low, 1clk before data */
  791. strcr |= CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TSCKP |
  792. CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TEFS;
  793. break;
  794. case SND_SOC_DAIFMT_LEFT_J:
  795. /* Data on rising edge of bclk, frame high */
  796. strcr |= CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TSCKP;
  797. break;
  798. case SND_SOC_DAIFMT_DSP_A:
  799. /* Data on rising edge of bclk, frame high, 1clk before data */
  800. strcr |= CCSR_SSI_STCR_TFSL | CCSR_SSI_STCR_TSCKP |
  801. CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TEFS;
  802. break;
  803. case SND_SOC_DAIFMT_DSP_B:
  804. /* Data on rising edge of bclk, frame high */
  805. strcr |= CCSR_SSI_STCR_TFSL | CCSR_SSI_STCR_TSCKP |
  806. CCSR_SSI_STCR_TXBIT0;
  807. break;
  808. case SND_SOC_DAIFMT_AC97:
  809. ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_NORMAL;
  810. break;
  811. default:
  812. return -EINVAL;
  813. }
  814. scr |= ssi_private->i2s_mode;
  815. /* DAI clock inversion */
  816. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  817. case SND_SOC_DAIFMT_NB_NF:
  818. /* Nothing to do for both normal cases */
  819. break;
  820. case SND_SOC_DAIFMT_IB_NF:
  821. /* Invert bit clock */
  822. strcr ^= CCSR_SSI_STCR_TSCKP;
  823. break;
  824. case SND_SOC_DAIFMT_NB_IF:
  825. /* Invert frame clock */
  826. strcr ^= CCSR_SSI_STCR_TFSI;
  827. break;
  828. case SND_SOC_DAIFMT_IB_IF:
  829. /* Invert both clocks */
  830. strcr ^= CCSR_SSI_STCR_TSCKP;
  831. strcr ^= CCSR_SSI_STCR_TFSI;
  832. break;
  833. default:
  834. return -EINVAL;
  835. }
  836. /* DAI clock master masks */
  837. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  838. case SND_SOC_DAIFMT_CBS_CFS:
  839. strcr |= CCSR_SSI_STCR_TFDIR | CCSR_SSI_STCR_TXDIR;
  840. scr |= CCSR_SSI_SCR_SYS_CLK_EN;
  841. break;
  842. case SND_SOC_DAIFMT_CBM_CFM:
  843. scr &= ~CCSR_SSI_SCR_SYS_CLK_EN;
  844. break;
  845. case SND_SOC_DAIFMT_CBM_CFS:
  846. strcr &= ~CCSR_SSI_STCR_TXDIR;
  847. strcr |= CCSR_SSI_STCR_TFDIR;
  848. scr &= ~CCSR_SSI_SCR_SYS_CLK_EN;
  849. break;
  850. default:
  851. if (!fsl_ssi_is_ac97(ssi_private))
  852. return -EINVAL;
  853. }
  854. stcr |= strcr;
  855. srcr |= strcr;
  856. if (ssi_private->cpu_dai_drv.symmetric_rates
  857. || fsl_ssi_is_ac97(ssi_private)) {
  858. /* Need to clear RXDIR when using SYNC or AC97 mode */
  859. srcr &= ~CCSR_SSI_SRCR_RXDIR;
  860. scr |= CCSR_SSI_SCR_SYN;
  861. }
  862. regmap_write(regs, CCSR_SSI_STCR, stcr);
  863. regmap_write(regs, CCSR_SSI_SRCR, srcr);
  864. regmap_write(regs, CCSR_SSI_SCR, scr);
  865. /*
  866. * Set the watermark for transmit FIFI 0 and receive FIFO 0. We don't
  867. * use FIFO 1. We program the transmit water to signal a DMA transfer
  868. * if there are only two (or fewer) elements left in the FIFO. Two
  869. * elements equals one frame (left channel, right channel). This value,
  870. * however, depends on the depth of the transmit buffer.
  871. *
  872. * We set the watermark on the same level as the DMA burstsize. For
  873. * fiq it is probably better to use the biggest possible watermark
  874. * size.
  875. */
  876. if (ssi_private->use_dma)
  877. wm = ssi_private->fifo_depth - 2;
  878. else
  879. wm = ssi_private->fifo_depth;
  880. regmap_write(regs, CCSR_SSI_SFCSR,
  881. CCSR_SSI_SFCSR_TFWM0(wm) | CCSR_SSI_SFCSR_RFWM0(wm) |
  882. CCSR_SSI_SFCSR_TFWM1(wm) | CCSR_SSI_SFCSR_RFWM1(wm));
  883. if (ssi_private->use_dual_fifo) {
  884. regmap_update_bits(regs, CCSR_SSI_SRCR, CCSR_SSI_SRCR_RFEN1,
  885. CCSR_SSI_SRCR_RFEN1);
  886. regmap_update_bits(regs, CCSR_SSI_STCR, CCSR_SSI_STCR_TFEN1,
  887. CCSR_SSI_STCR_TFEN1);
  888. regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_TCH_EN,
  889. CCSR_SSI_SCR_TCH_EN);
  890. }
  891. if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_AC97)
  892. fsl_ssi_setup_ac97(ssi_private);
  893. return 0;
  894. }
  895. /**
  896. * fsl_ssi_set_dai_fmt - configure Digital Audio Interface Format.
  897. */
  898. static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
  899. {
  900. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
  901. return _fsl_ssi_set_dai_fmt(cpu_dai->dev, ssi_private, fmt);
  902. }
  903. /**
  904. * fsl_ssi_set_dai_tdm_slot - set TDM slot number
  905. *
  906. * Note: This function can be only called when using SSI as DAI master
  907. */
  908. static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
  909. u32 rx_mask, int slots, int slot_width)
  910. {
  911. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
  912. struct regmap *regs = ssi_private->regs;
  913. u32 val;
  914. /* The slot number should be >= 2 if using Network mode or I2S mode */
  915. regmap_read(regs, CCSR_SSI_SCR, &val);
  916. val &= CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_NET;
  917. if (val && slots < 2) {
  918. dev_err(cpu_dai->dev, "slot number should be >= 2 in I2S or NET\n");
  919. return -EINVAL;
  920. }
  921. regmap_update_bits(regs, CCSR_SSI_STCCR, CCSR_SSI_SxCCR_DC_MASK,
  922. CCSR_SSI_SxCCR_DC(slots));
  923. regmap_update_bits(regs, CCSR_SSI_SRCCR, CCSR_SSI_SxCCR_DC_MASK,
  924. CCSR_SSI_SxCCR_DC(slots));
  925. /* The register SxMSKs needs SSI to provide essential clock due to
  926. * hardware design. So we here temporarily enable SSI to set them.
  927. */
  928. regmap_read(regs, CCSR_SSI_SCR, &val);
  929. val &= CCSR_SSI_SCR_SSIEN;
  930. regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN,
  931. CCSR_SSI_SCR_SSIEN);
  932. regmap_write(regs, CCSR_SSI_STMSK, ~tx_mask);
  933. regmap_write(regs, CCSR_SSI_SRMSK, ~rx_mask);
  934. regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val);
  935. return 0;
  936. }
  937. /**
  938. * fsl_ssi_trigger: start and stop the DMA transfer.
  939. *
  940. * This function is called by ALSA to start, stop, pause, and resume the DMA
  941. * transfer of data.
  942. *
  943. * The DMA channel is in external master start and pause mode, which
  944. * means the SSI completely controls the flow of data.
  945. */
  946. static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
  947. struct snd_soc_dai *dai)
  948. {
  949. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  950. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai);
  951. struct regmap *regs = ssi_private->regs;
  952. switch (cmd) {
  953. case SNDRV_PCM_TRIGGER_START:
  954. case SNDRV_PCM_TRIGGER_RESUME:
  955. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  956. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  957. fsl_ssi_tx_config(ssi_private, true);
  958. else
  959. fsl_ssi_rx_config(ssi_private, true);
  960. break;
  961. case SNDRV_PCM_TRIGGER_STOP:
  962. case SNDRV_PCM_TRIGGER_SUSPEND:
  963. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  964. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  965. fsl_ssi_tx_config(ssi_private, false);
  966. else
  967. fsl_ssi_rx_config(ssi_private, false);
  968. break;
  969. default:
  970. return -EINVAL;
  971. }
  972. if (fsl_ssi_is_ac97(ssi_private)) {
  973. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  974. regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_TX_CLR);
  975. else
  976. regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_RX_CLR);
  977. }
  978. return 0;
  979. }
  980. static int fsl_ssi_dai_probe(struct snd_soc_dai *dai)
  981. {
  982. struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(dai);
  983. if (ssi_private->soc->imx && ssi_private->use_dma) {
  984. dai->playback_dma_data = &ssi_private->dma_params_tx;
  985. dai->capture_dma_data = &ssi_private->dma_params_rx;
  986. }
  987. return 0;
  988. }
  989. static const struct snd_soc_dai_ops fsl_ssi_dai_ops = {
  990. .startup = fsl_ssi_startup,
  991. .shutdown = fsl_ssi_shutdown,
  992. .hw_params = fsl_ssi_hw_params,
  993. .hw_free = fsl_ssi_hw_free,
  994. .set_fmt = fsl_ssi_set_dai_fmt,
  995. .set_sysclk = fsl_ssi_set_dai_sysclk,
  996. .set_tdm_slot = fsl_ssi_set_dai_tdm_slot,
  997. .trigger = fsl_ssi_trigger,
  998. };
  999. /* Template for the CPU dai driver structure */
  1000. static struct snd_soc_dai_driver fsl_ssi_dai_template = {
  1001. .probe = fsl_ssi_dai_probe,
  1002. .playback = {
  1003. .stream_name = "CPU-Playback",
  1004. .channels_min = 1,
  1005. .channels_max = 2,
  1006. .rates = FSLSSI_I2S_RATES,
  1007. .formats = FSLSSI_I2S_FORMATS,
  1008. },
  1009. .capture = {
  1010. .stream_name = "CPU-Capture",
  1011. .channels_min = 1,
  1012. .channels_max = 2,
  1013. .rates = FSLSSI_I2S_RATES,
  1014. .formats = FSLSSI_I2S_FORMATS,
  1015. },
  1016. .ops = &fsl_ssi_dai_ops,
  1017. };
  1018. static const struct snd_soc_component_driver fsl_ssi_component = {
  1019. .name = "fsl-ssi",
  1020. };
  1021. static struct snd_soc_dai_driver fsl_ssi_ac97_dai = {
  1022. .bus_control = true,
  1023. .probe = fsl_ssi_dai_probe,
  1024. .playback = {
  1025. .stream_name = "AC97 Playback",
  1026. .channels_min = 2,
  1027. .channels_max = 2,
  1028. .rates = SNDRV_PCM_RATE_8000_48000,
  1029. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1030. },
  1031. .capture = {
  1032. .stream_name = "AC97 Capture",
  1033. .channels_min = 2,
  1034. .channels_max = 2,
  1035. .rates = SNDRV_PCM_RATE_48000,
  1036. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1037. },
  1038. .ops = &fsl_ssi_dai_ops,
  1039. };
  1040. static struct fsl_ssi_private *fsl_ac97_data;
  1041. static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
  1042. unsigned short val)
  1043. {
  1044. struct regmap *regs = fsl_ac97_data->regs;
  1045. unsigned int lreg;
  1046. unsigned int lval;
  1047. int ret;
  1048. if (reg > 0x7f)
  1049. return;
  1050. ret = clk_prepare_enable(fsl_ac97_data->clk);
  1051. if (ret) {
  1052. pr_err("ac97 write clk_prepare_enable failed: %d\n",
  1053. ret);
  1054. return;
  1055. }
  1056. lreg = reg << 12;
  1057. regmap_write(regs, CCSR_SSI_SACADD, lreg);
  1058. lval = val << 4;
  1059. regmap_write(regs, CCSR_SSI_SACDAT, lval);
  1060. regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK,
  1061. CCSR_SSI_SACNT_WR);
  1062. udelay(100);
  1063. clk_disable_unprepare(fsl_ac97_data->clk);
  1064. }
  1065. static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
  1066. unsigned short reg)
  1067. {
  1068. struct regmap *regs = fsl_ac97_data->regs;
  1069. unsigned short val = -1;
  1070. u32 reg_val;
  1071. unsigned int lreg;
  1072. int ret;
  1073. ret = clk_prepare_enable(fsl_ac97_data->clk);
  1074. if (ret) {
  1075. pr_err("ac97 read clk_prepare_enable failed: %d\n",
  1076. ret);
  1077. return -1;
  1078. }
  1079. lreg = (reg & 0x7f) << 12;
  1080. regmap_write(regs, CCSR_SSI_SACADD, lreg);
  1081. regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK,
  1082. CCSR_SSI_SACNT_RD);
  1083. udelay(100);
  1084. regmap_read(regs, CCSR_SSI_SACDAT, &reg_val);
  1085. val = (reg_val >> 4) & 0xffff;
  1086. clk_disable_unprepare(fsl_ac97_data->clk);
  1087. return val;
  1088. }
  1089. static struct snd_ac97_bus_ops fsl_ssi_ac97_ops = {
  1090. .read = fsl_ssi_ac97_read,
  1091. .write = fsl_ssi_ac97_write,
  1092. };
  1093. /**
  1094. * Make every character in a string lower-case
  1095. */
  1096. static void make_lowercase(char *s)
  1097. {
  1098. char *p = s;
  1099. char c;
  1100. while ((c = *p)) {
  1101. if ((c >= 'A') && (c <= 'Z'))
  1102. *p = c + ('a' - 'A');
  1103. p++;
  1104. }
  1105. }
  1106. static int fsl_ssi_imx_probe(struct platform_device *pdev,
  1107. struct fsl_ssi_private *ssi_private, void __iomem *iomem)
  1108. {
  1109. struct device_node *np = pdev->dev.of_node;
  1110. u32 dmas[4];
  1111. int ret;
  1112. if (ssi_private->has_ipg_clk_name)
  1113. ssi_private->clk = devm_clk_get(&pdev->dev, "ipg");
  1114. else
  1115. ssi_private->clk = devm_clk_get(&pdev->dev, NULL);
  1116. if (IS_ERR(ssi_private->clk)) {
  1117. ret = PTR_ERR(ssi_private->clk);
  1118. dev_err(&pdev->dev, "could not get clock: %d\n", ret);
  1119. return ret;
  1120. }
  1121. if (!ssi_private->has_ipg_clk_name) {
  1122. ret = clk_prepare_enable(ssi_private->clk);
  1123. if (ret) {
  1124. dev_err(&pdev->dev, "clk_prepare_enable failed: %d\n", ret);
  1125. return ret;
  1126. }
  1127. }
  1128. /* For those SLAVE implementations, we ignore non-baudclk cases
  1129. * and, instead, abandon MASTER mode that needs baud clock.
  1130. */
  1131. ssi_private->baudclk = devm_clk_get(&pdev->dev, "baud");
  1132. if (IS_ERR(ssi_private->baudclk))
  1133. dev_dbg(&pdev->dev, "could not get baud clock: %ld\n",
  1134. PTR_ERR(ssi_private->baudclk));
  1135. /*
  1136. * We have burstsize be "fifo_depth - 2" to match the SSI
  1137. * watermark setting in fsl_ssi_startup().
  1138. */
  1139. ssi_private->dma_params_tx.maxburst = ssi_private->fifo_depth - 2;
  1140. ssi_private->dma_params_rx.maxburst = ssi_private->fifo_depth - 2;
  1141. ssi_private->dma_params_tx.addr = ssi_private->ssi_phys + CCSR_SSI_STX0;
  1142. ssi_private->dma_params_rx.addr = ssi_private->ssi_phys + CCSR_SSI_SRX0;
  1143. ret = of_property_read_u32_array(np, "dmas", dmas, 4);
  1144. if (ssi_private->use_dma && !ret && dmas[2] == IMX_DMATYPE_SSI_DUAL) {
  1145. ssi_private->use_dual_fifo = true;
  1146. /* When using dual fifo mode, we need to keep watermark
  1147. * as even numbers due to dma script limitation.
  1148. */
  1149. ssi_private->dma_params_tx.maxburst &= ~0x1;
  1150. ssi_private->dma_params_rx.maxburst &= ~0x1;
  1151. }
  1152. if (!ssi_private->use_dma) {
  1153. /*
  1154. * Some boards use an incompatible codec. To get it
  1155. * working, we are using imx-fiq-pcm-audio, that
  1156. * can handle those codecs. DMA is not possible in this
  1157. * situation.
  1158. */
  1159. ssi_private->fiq_params.irq = ssi_private->irq;
  1160. ssi_private->fiq_params.base = iomem;
  1161. ssi_private->fiq_params.dma_params_rx =
  1162. &ssi_private->dma_params_rx;
  1163. ssi_private->fiq_params.dma_params_tx =
  1164. &ssi_private->dma_params_tx;
  1165. ret = imx_pcm_fiq_init(pdev, &ssi_private->fiq_params);
  1166. if (ret)
  1167. goto error_pcm;
  1168. } else {
  1169. ret = imx_pcm_dma_init(pdev, IMX_SSI_DMABUF_SIZE);
  1170. if (ret)
  1171. goto error_pcm;
  1172. }
  1173. return 0;
  1174. error_pcm:
  1175. if (!ssi_private->has_ipg_clk_name)
  1176. clk_disable_unprepare(ssi_private->clk);
  1177. return ret;
  1178. }
  1179. static void fsl_ssi_imx_clean(struct platform_device *pdev,
  1180. struct fsl_ssi_private *ssi_private)
  1181. {
  1182. if (!ssi_private->use_dma)
  1183. imx_pcm_fiq_exit(pdev);
  1184. if (!ssi_private->has_ipg_clk_name)
  1185. clk_disable_unprepare(ssi_private->clk);
  1186. }
  1187. static int fsl_ssi_probe(struct platform_device *pdev)
  1188. {
  1189. struct fsl_ssi_private *ssi_private;
  1190. int ret = 0;
  1191. struct device_node *np = pdev->dev.of_node;
  1192. const struct of_device_id *of_id;
  1193. const char *p, *sprop;
  1194. const uint32_t *iprop;
  1195. struct resource *res;
  1196. void __iomem *iomem;
  1197. char name[64];
  1198. of_id = of_match_device(fsl_ssi_ids, &pdev->dev);
  1199. if (!of_id || !of_id->data)
  1200. return -EINVAL;
  1201. ssi_private = devm_kzalloc(&pdev->dev, sizeof(*ssi_private),
  1202. GFP_KERNEL);
  1203. if (!ssi_private) {
  1204. dev_err(&pdev->dev, "could not allocate DAI object\n");
  1205. return -ENOMEM;
  1206. }
  1207. ssi_private->soc = of_id->data;
  1208. sprop = of_get_property(np, "fsl,mode", NULL);
  1209. if (sprop) {
  1210. if (!strcmp(sprop, "ac97-slave"))
  1211. ssi_private->dai_fmt = SND_SOC_DAIFMT_AC97;
  1212. }
  1213. ssi_private->use_dma = !of_property_read_bool(np,
  1214. "fsl,fiq-stream-filter");
  1215. if (fsl_ssi_is_ac97(ssi_private)) {
  1216. memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_ac97_dai,
  1217. sizeof(fsl_ssi_ac97_dai));
  1218. fsl_ac97_data = ssi_private;
  1219. } else {
  1220. /* Initialize this copy of the CPU DAI driver structure */
  1221. memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template,
  1222. sizeof(fsl_ssi_dai_template));
  1223. }
  1224. ssi_private->cpu_dai_drv.name = dev_name(&pdev->dev);
  1225. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1226. iomem = devm_ioremap_resource(&pdev->dev, res);
  1227. if (IS_ERR(iomem))
  1228. return PTR_ERR(iomem);
  1229. ssi_private->ssi_phys = res->start;
  1230. ret = of_property_match_string(np, "clock-names", "ipg");
  1231. if (ret < 0) {
  1232. ssi_private->has_ipg_clk_name = false;
  1233. ssi_private->regs = devm_regmap_init_mmio(&pdev->dev, iomem,
  1234. &fsl_ssi_regconfig);
  1235. } else {
  1236. ssi_private->has_ipg_clk_name = true;
  1237. ssi_private->regs = devm_regmap_init_mmio_clk(&pdev->dev,
  1238. "ipg", iomem, &fsl_ssi_regconfig);
  1239. }
  1240. if (IS_ERR(ssi_private->regs)) {
  1241. dev_err(&pdev->dev, "Failed to init register map\n");
  1242. return PTR_ERR(ssi_private->regs);
  1243. }
  1244. ssi_private->irq = platform_get_irq(pdev, 0);
  1245. if (ssi_private->irq < 0) {
  1246. dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
  1247. return ssi_private->irq;
  1248. }
  1249. /* Are the RX and the TX clocks locked? */
  1250. if (!of_find_property(np, "fsl,ssi-asynchronous", NULL)) {
  1251. if (!fsl_ssi_is_ac97(ssi_private))
  1252. ssi_private->cpu_dai_drv.symmetric_rates = 1;
  1253. ssi_private->cpu_dai_drv.symmetric_channels = 1;
  1254. ssi_private->cpu_dai_drv.symmetric_samplebits = 1;
  1255. }
  1256. /* Determine the FIFO depth. */
  1257. iprop = of_get_property(np, "fsl,fifo-depth", NULL);
  1258. if (iprop)
  1259. ssi_private->fifo_depth = be32_to_cpup(iprop);
  1260. else
  1261. /* Older 8610 DTs didn't have the fifo-depth property */
  1262. ssi_private->fifo_depth = 8;
  1263. dev_set_drvdata(&pdev->dev, ssi_private);
  1264. if (ssi_private->soc->imx) {
  1265. ret = fsl_ssi_imx_probe(pdev, ssi_private, iomem);
  1266. if (ret)
  1267. return ret;
  1268. }
  1269. if (fsl_ssi_is_ac97(ssi_private)) {
  1270. ret = snd_soc_set_ac97_ops_of_reset(&fsl_ssi_ac97_ops, pdev);
  1271. if (ret) {
  1272. dev_err(&pdev->dev, "could not set AC'97 ops\n");
  1273. goto error_ac97_ops;
  1274. }
  1275. }
  1276. ret = devm_snd_soc_register_component(&pdev->dev, &fsl_ssi_component,
  1277. &ssi_private->cpu_dai_drv, 1);
  1278. if (ret) {
  1279. dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
  1280. goto error_asoc_register;
  1281. }
  1282. if (ssi_private->use_dma) {
  1283. ret = devm_request_irq(&pdev->dev, ssi_private->irq,
  1284. fsl_ssi_isr, 0, dev_name(&pdev->dev),
  1285. ssi_private);
  1286. if (ret < 0) {
  1287. dev_err(&pdev->dev, "could not claim irq %u\n",
  1288. ssi_private->irq);
  1289. goto error_asoc_register;
  1290. }
  1291. }
  1292. ret = fsl_ssi_debugfs_create(&ssi_private->dbg_stats, &pdev->dev);
  1293. if (ret)
  1294. goto error_asoc_register;
  1295. /*
  1296. * If codec-handle property is missing from SSI node, we assume
  1297. * that the machine driver uses new binding which does not require
  1298. * SSI driver to trigger machine driver's probe.
  1299. */
  1300. if (!of_get_property(np, "codec-handle", NULL))
  1301. goto done;
  1302. /* Trigger the machine driver's probe function. The platform driver
  1303. * name of the machine driver is taken from /compatible property of the
  1304. * device tree. We also pass the address of the CPU DAI driver
  1305. * structure.
  1306. */
  1307. sprop = of_get_property(of_find_node_by_path("/"), "compatible", NULL);
  1308. /* Sometimes the compatible name has a "fsl," prefix, so we strip it. */
  1309. p = strrchr(sprop, ',');
  1310. if (p)
  1311. sprop = p + 1;
  1312. snprintf(name, sizeof(name), "snd-soc-%s", sprop);
  1313. make_lowercase(name);
  1314. ssi_private->pdev =
  1315. platform_device_register_data(&pdev->dev, name, 0, NULL, 0);
  1316. if (IS_ERR(ssi_private->pdev)) {
  1317. ret = PTR_ERR(ssi_private->pdev);
  1318. dev_err(&pdev->dev, "failed to register platform: %d\n", ret);
  1319. goto error_sound_card;
  1320. }
  1321. done:
  1322. if (ssi_private->dai_fmt)
  1323. _fsl_ssi_set_dai_fmt(&pdev->dev, ssi_private,
  1324. ssi_private->dai_fmt);
  1325. if (fsl_ssi_is_ac97(ssi_private)) {
  1326. u32 ssi_idx;
  1327. ret = of_property_read_u32(np, "cell-index", &ssi_idx);
  1328. if (ret) {
  1329. dev_err(&pdev->dev, "cannot get SSI index property\n");
  1330. goto error_sound_card;
  1331. }
  1332. ssi_private->pdev =
  1333. platform_device_register_data(NULL,
  1334. "ac97-codec", ssi_idx, NULL, 0);
  1335. if (IS_ERR(ssi_private->pdev)) {
  1336. ret = PTR_ERR(ssi_private->pdev);
  1337. dev_err(&pdev->dev,
  1338. "failed to register AC97 codec platform: %d\n",
  1339. ret);
  1340. goto error_sound_card;
  1341. }
  1342. }
  1343. return 0;
  1344. error_sound_card:
  1345. fsl_ssi_debugfs_remove(&ssi_private->dbg_stats);
  1346. error_asoc_register:
  1347. if (fsl_ssi_is_ac97(ssi_private))
  1348. snd_soc_set_ac97_ops(NULL);
  1349. error_ac97_ops:
  1350. if (ssi_private->soc->imx)
  1351. fsl_ssi_imx_clean(pdev, ssi_private);
  1352. return ret;
  1353. }
  1354. static int fsl_ssi_remove(struct platform_device *pdev)
  1355. {
  1356. struct fsl_ssi_private *ssi_private = dev_get_drvdata(&pdev->dev);
  1357. fsl_ssi_debugfs_remove(&ssi_private->dbg_stats);
  1358. if (ssi_private->pdev)
  1359. platform_device_unregister(ssi_private->pdev);
  1360. if (ssi_private->soc->imx)
  1361. fsl_ssi_imx_clean(pdev, ssi_private);
  1362. if (fsl_ssi_is_ac97(ssi_private))
  1363. snd_soc_set_ac97_ops(NULL);
  1364. return 0;
  1365. }
  1366. #ifdef CONFIG_PM_SLEEP
  1367. static int fsl_ssi_suspend(struct device *dev)
  1368. {
  1369. struct fsl_ssi_private *ssi_private = dev_get_drvdata(dev);
  1370. struct regmap *regs = ssi_private->regs;
  1371. regmap_read(regs, CCSR_SSI_SFCSR,
  1372. &ssi_private->regcache_sfcsr);
  1373. regcache_cache_only(regs, true);
  1374. regcache_mark_dirty(regs);
  1375. return 0;
  1376. }
  1377. static int fsl_ssi_resume(struct device *dev)
  1378. {
  1379. struct fsl_ssi_private *ssi_private = dev_get_drvdata(dev);
  1380. struct regmap *regs = ssi_private->regs;
  1381. regcache_cache_only(regs, false);
  1382. regmap_update_bits(regs, CCSR_SSI_SFCSR,
  1383. CCSR_SSI_SFCSR_RFWM1_MASK | CCSR_SSI_SFCSR_TFWM1_MASK |
  1384. CCSR_SSI_SFCSR_RFWM0_MASK | CCSR_SSI_SFCSR_TFWM0_MASK,
  1385. ssi_private->regcache_sfcsr);
  1386. return regcache_sync(regs);
  1387. }
  1388. #endif /* CONFIG_PM_SLEEP */
  1389. static const struct dev_pm_ops fsl_ssi_pm = {
  1390. SET_SYSTEM_SLEEP_PM_OPS(fsl_ssi_suspend, fsl_ssi_resume)
  1391. };
  1392. static struct platform_driver fsl_ssi_driver = {
  1393. .driver = {
  1394. .name = "fsl-ssi-dai",
  1395. .of_match_table = fsl_ssi_ids,
  1396. .pm = &fsl_ssi_pm,
  1397. },
  1398. .probe = fsl_ssi_probe,
  1399. .remove = fsl_ssi_remove,
  1400. };
  1401. module_platform_driver(fsl_ssi_driver);
  1402. MODULE_ALIAS("platform:fsl-ssi-dai");
  1403. MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
  1404. MODULE_DESCRIPTION("Freescale Synchronous Serial Interface (SSI) ASoC Driver");
  1405. MODULE_LICENSE("GPL v2");