Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_device.h> |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/delay.h> |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 28 | #include <linux/time.h> |
Huang Shijie | 3946860 | 2012-02-16 14:17:32 +0800 | [diff] [blame] | 29 | #include <linux/fsl/mxs-dma.h> |
Shawn Guo | f755865 | 2012-05-06 23:00:50 +0800 | [diff] [blame] | 30 | #include <linux/pinctrl/consumer.h> |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 31 | #include <sound/core.h> |
| 32 | #include <sound/pcm.h> |
| 33 | #include <sound/pcm_params.h> |
| 34 | #include <sound/soc.h> |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 35 | #include <asm/mach-types.h> |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 36 | |
| 37 | #include "mxs-saif.h" |
| 38 | |
Shawn Guo | 114fe75 | 2013-03-28 23:21:16 +0800 | [diff] [blame^] | 39 | #define MXS_SET_ADDR 0x4 |
| 40 | #define MXS_CLR_ADDR 0x8 |
| 41 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 42 | static struct mxs_saif *mxs_saif[2]; |
| 43 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 44 | /* |
| 45 | * SAIF is a little different with other normal SOC DAIs on clock using. |
| 46 | * |
| 47 | * For MXS, two SAIF modules are instantiated on-chip. |
| 48 | * Each SAIF has a set of clock pins and can be operating in master |
| 49 | * mode simultaneously if they are connected to different off-chip codecs. |
| 50 | * Also, one of the two SAIFs can master or drive the clock pins while the |
| 51 | * other SAIF, in slave mode, receives clocking from the master SAIF. |
| 52 | * This also means that both SAIFs must operate at the same sample rate. |
| 53 | * |
| 54 | * We abstract this as each saif has a master, the master could be |
| 55 | * himself or other saifs. In the generic saif driver, saif does not need |
| 56 | * to know the different clkmux. Saif only needs to know who is his master |
| 57 | * and operating his master to generate the proper clock rate for him. |
| 58 | * The master id is provided in mach-specific layer according to different |
| 59 | * clkmux setting. |
| 60 | */ |
| 61 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 62 | static int mxs_saif_set_dai_sysclk(struct snd_soc_dai *cpu_dai, |
| 63 | int clk_id, unsigned int freq, int dir) |
| 64 | { |
| 65 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
| 66 | |
| 67 | switch (clk_id) { |
| 68 | case MXS_SAIF_MCLK: |
| 69 | saif->mclk = freq; |
| 70 | break; |
| 71 | default: |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | /* |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 78 | * Since SAIF may work on EXTMASTER mode, IOW, it's working BITCLK&LRCLK |
| 79 | * is provided by other SAIF, we provide a interface here to get its master |
| 80 | * from its master_id. |
| 81 | * Note that the master could be himself. |
| 82 | */ |
| 83 | static inline struct mxs_saif *mxs_saif_get_master(struct mxs_saif * saif) |
| 84 | { |
| 85 | return mxs_saif[saif->master_id]; |
| 86 | } |
| 87 | |
| 88 | /* |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 89 | * Set SAIF clock and MCLK |
| 90 | */ |
| 91 | static int mxs_saif_set_clk(struct mxs_saif *saif, |
| 92 | unsigned int mclk, |
| 93 | unsigned int rate) |
| 94 | { |
| 95 | u32 scr; |
| 96 | int ret; |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 97 | struct mxs_saif *master_saif; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 98 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 99 | dev_dbg(saif->dev, "mclk %d rate %d\n", mclk, rate); |
| 100 | |
| 101 | /* Set master saif to generate proper clock */ |
| 102 | master_saif = mxs_saif_get_master(saif); |
| 103 | if (!master_saif) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | dev_dbg(saif->dev, "master saif%d\n", master_saif->id); |
| 107 | |
| 108 | /* Checking if can playback and capture simutaneously */ |
| 109 | if (master_saif->ongoing && rate != master_saif->cur_rate) { |
| 110 | dev_err(saif->dev, |
| 111 | "can not change clock, master saif%d(rate %d) is ongoing\n", |
| 112 | master_saif->id, master_saif->cur_rate); |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | |
| 116 | scr = __raw_readl(master_saif->base + SAIF_CTRL); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 117 | scr &= ~BM_SAIF_CTRL_BITCLK_MULT_RATE; |
| 118 | scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE; |
| 119 | |
| 120 | /* |
| 121 | * Set SAIF clock |
| 122 | * |
| 123 | * The SAIF clock should be either 384*fs or 512*fs. |
| 124 | * If MCLK is used, the SAIF clk ratio need to match mclk ratio. |
| 125 | * For 32x mclk, set saif clk as 512*fs. |
| 126 | * For 48x mclk, set saif clk as 384*fs. |
| 127 | * |
| 128 | * If MCLK is not used, we just set saif clk to 512*fs. |
| 129 | */ |
Fabio Estevam | 6b35f92 | 2012-01-19 10:23:22 -0200 | [diff] [blame] | 130 | clk_prepare_enable(master_saif->clk); |
| 131 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 132 | if (master_saif->mclk_in_use) { |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 133 | if (mclk % 32 == 0) { |
| 134 | scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE; |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 135 | ret = clk_set_rate(master_saif->clk, 512 * rate); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 136 | } else if (mclk % 48 == 0) { |
| 137 | scr |= BM_SAIF_CTRL_BITCLK_BASE_RATE; |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 138 | ret = clk_set_rate(master_saif->clk, 384 * rate); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 139 | } else { |
| 140 | /* SAIF MCLK should be either 32x or 48x */ |
Fabio Estevam | 6b35f92 | 2012-01-19 10:23:22 -0200 | [diff] [blame] | 141 | clk_disable_unprepare(master_saif->clk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 142 | return -EINVAL; |
| 143 | } |
| 144 | } else { |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 145 | ret = clk_set_rate(master_saif->clk, 512 * rate); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 146 | scr &= ~BM_SAIF_CTRL_BITCLK_BASE_RATE; |
| 147 | } |
| 148 | |
Fabio Estevam | 6b35f92 | 2012-01-19 10:23:22 -0200 | [diff] [blame] | 149 | clk_disable_unprepare(master_saif->clk); |
| 150 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 151 | if (ret) |
| 152 | return ret; |
| 153 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 154 | master_saif->cur_rate = rate; |
| 155 | |
| 156 | if (!master_saif->mclk_in_use) { |
| 157 | __raw_writel(scr, master_saif->base + SAIF_CTRL); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Program the over-sample rate for MCLK output |
| 163 | * |
| 164 | * The available MCLK range is 32x, 48x... 512x. The rate |
| 165 | * could be from 8kHz to 192kH. |
| 166 | */ |
| 167 | switch (mclk / rate) { |
| 168 | case 32: |
| 169 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(4); |
| 170 | break; |
| 171 | case 64: |
| 172 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(3); |
| 173 | break; |
| 174 | case 128: |
| 175 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(2); |
| 176 | break; |
| 177 | case 256: |
| 178 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(1); |
| 179 | break; |
| 180 | case 512: |
| 181 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(0); |
| 182 | break; |
| 183 | case 48: |
| 184 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(3); |
| 185 | break; |
| 186 | case 96: |
| 187 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(2); |
| 188 | break; |
| 189 | case 192: |
| 190 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(1); |
| 191 | break; |
| 192 | case 384: |
| 193 | scr |= BF_SAIF_CTRL_BITCLK_MULT_RATE(0); |
| 194 | break; |
| 195 | default: |
| 196 | return -EINVAL; |
| 197 | } |
| 198 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 199 | __raw_writel(scr, master_saif->base + SAIF_CTRL); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Put and disable MCLK. |
| 206 | */ |
| 207 | int mxs_saif_put_mclk(unsigned int saif_id) |
| 208 | { |
| 209 | struct mxs_saif *saif = mxs_saif[saif_id]; |
| 210 | u32 stat; |
| 211 | |
| 212 | if (!saif) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | stat = __raw_readl(saif->base + SAIF_STAT); |
| 216 | if (stat & BM_SAIF_STAT_BUSY) { |
| 217 | dev_err(saif->dev, "error: busy\n"); |
| 218 | return -EBUSY; |
| 219 | } |
| 220 | |
Shawn Guo | 67939b2 | 2011-12-20 14:15:44 +0800 | [diff] [blame] | 221 | clk_disable_unprepare(saif->clk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 222 | |
| 223 | /* disable MCLK output */ |
| 224 | __raw_writel(BM_SAIF_CTRL_CLKGATE, |
| 225 | saif->base + SAIF_CTRL + MXS_SET_ADDR); |
| 226 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 227 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 228 | |
| 229 | saif->mclk_in_use = 0; |
| 230 | return 0; |
| 231 | } |
Lothar Waßmann | cf7d0f0 | 2012-11-22 13:31:09 +0100 | [diff] [blame] | 232 | EXPORT_SYMBOL_GPL(mxs_saif_put_mclk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * Get MCLK and set clock rate, then enable it |
| 236 | * |
| 237 | * This interface is used for codecs who are using MCLK provided |
| 238 | * by saif. |
| 239 | */ |
| 240 | int mxs_saif_get_mclk(unsigned int saif_id, unsigned int mclk, |
| 241 | unsigned int rate) |
| 242 | { |
| 243 | struct mxs_saif *saif = mxs_saif[saif_id]; |
| 244 | u32 stat; |
| 245 | int ret; |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 246 | struct mxs_saif *master_saif; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 247 | |
| 248 | if (!saif) |
| 249 | return -EINVAL; |
| 250 | |
Dong Aisheng | bbe8ff5 | 2011-08-21 23:45:40 +0800 | [diff] [blame] | 251 | /* Clear Reset */ |
| 252 | __raw_writel(BM_SAIF_CTRL_SFTRST, |
| 253 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 254 | |
| 255 | /* FIXME: need clear clk gate for register r/w */ |
| 256 | __raw_writel(BM_SAIF_CTRL_CLKGATE, |
| 257 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 258 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 259 | master_saif = mxs_saif_get_master(saif); |
| 260 | if (saif != master_saif) { |
| 261 | dev_err(saif->dev, "can not get mclk from a non-master saif\n"); |
| 262 | return -EINVAL; |
| 263 | } |
| 264 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 265 | stat = __raw_readl(saif->base + SAIF_STAT); |
| 266 | if (stat & BM_SAIF_STAT_BUSY) { |
| 267 | dev_err(saif->dev, "error: busy\n"); |
| 268 | return -EBUSY; |
| 269 | } |
| 270 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 271 | saif->mclk_in_use = 1; |
| 272 | ret = mxs_saif_set_clk(saif, mclk, rate); |
| 273 | if (ret) |
| 274 | return ret; |
| 275 | |
Shawn Guo | 67939b2 | 2011-12-20 14:15:44 +0800 | [diff] [blame] | 276 | ret = clk_prepare_enable(saif->clk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 277 | if (ret) |
| 278 | return ret; |
| 279 | |
| 280 | /* enable MCLK output */ |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 281 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 282 | saif->base + SAIF_CTRL + MXS_SET_ADDR); |
| 283 | |
| 284 | return 0; |
| 285 | } |
Lothar Waßmann | cf7d0f0 | 2012-11-22 13:31:09 +0100 | [diff] [blame] | 286 | EXPORT_SYMBOL_GPL(mxs_saif_get_mclk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * SAIF DAI format configuration. |
| 290 | * Should only be called when port is inactive. |
| 291 | */ |
| 292 | static int mxs_saif_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) |
| 293 | { |
| 294 | u32 scr, stat; |
| 295 | u32 scr0; |
| 296 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
| 297 | |
| 298 | stat = __raw_readl(saif->base + SAIF_STAT); |
| 299 | if (stat & BM_SAIF_STAT_BUSY) { |
| 300 | dev_err(cpu_dai->dev, "error: busy\n"); |
| 301 | return -EBUSY; |
| 302 | } |
| 303 | |
| 304 | scr0 = __raw_readl(saif->base + SAIF_CTRL); |
| 305 | scr0 = scr0 & ~BM_SAIF_CTRL_BITCLK_EDGE & ~BM_SAIF_CTRL_LRCLK_POLARITY \ |
| 306 | & ~BM_SAIF_CTRL_JUSTIFY & ~BM_SAIF_CTRL_DELAY; |
| 307 | scr = 0; |
| 308 | |
| 309 | /* DAI mode */ |
| 310 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 311 | case SND_SOC_DAIFMT_I2S: |
| 312 | /* data frame low 1clk before data */ |
| 313 | scr |= BM_SAIF_CTRL_DELAY; |
| 314 | scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY; |
| 315 | break; |
| 316 | case SND_SOC_DAIFMT_LEFT_J: |
| 317 | /* data frame high with data */ |
| 318 | scr &= ~BM_SAIF_CTRL_DELAY; |
| 319 | scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY; |
| 320 | scr &= ~BM_SAIF_CTRL_JUSTIFY; |
| 321 | break; |
| 322 | default: |
| 323 | return -EINVAL; |
| 324 | } |
| 325 | |
| 326 | /* DAI clock inversion */ |
| 327 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 328 | case SND_SOC_DAIFMT_IB_IF: |
| 329 | scr |= BM_SAIF_CTRL_BITCLK_EDGE; |
| 330 | scr |= BM_SAIF_CTRL_LRCLK_POLARITY; |
| 331 | break; |
| 332 | case SND_SOC_DAIFMT_IB_NF: |
| 333 | scr |= BM_SAIF_CTRL_BITCLK_EDGE; |
| 334 | scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY; |
| 335 | break; |
| 336 | case SND_SOC_DAIFMT_NB_IF: |
| 337 | scr &= ~BM_SAIF_CTRL_BITCLK_EDGE; |
| 338 | scr |= BM_SAIF_CTRL_LRCLK_POLARITY; |
| 339 | break; |
| 340 | case SND_SOC_DAIFMT_NB_NF: |
| 341 | scr &= ~BM_SAIF_CTRL_BITCLK_EDGE; |
| 342 | scr &= ~BM_SAIF_CTRL_LRCLK_POLARITY; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Note: We simply just support master mode since SAIF TX can only |
| 348 | * work as master. |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 349 | * Here the master is relative to codec side. |
| 350 | * Saif internally could be slave when working on EXTMASTER mode. |
| 351 | * We just hide this to machine driver. |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 352 | */ |
| 353 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 354 | case SND_SOC_DAIFMT_CBS_CFS: |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 355 | if (saif->id == saif->master_id) |
| 356 | scr &= ~BM_SAIF_CTRL_SLAVE_MODE; |
| 357 | else |
| 358 | scr |= BM_SAIF_CTRL_SLAVE_MODE; |
| 359 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 360 | __raw_writel(scr | scr0, saif->base + SAIF_CTRL); |
| 361 | break; |
| 362 | default: |
| 363 | return -EINVAL; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static int mxs_saif_startup(struct snd_pcm_substream *substream, |
| 370 | struct snd_soc_dai *cpu_dai) |
| 371 | { |
| 372 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
| 373 | snd_soc_dai_set_dma_data(cpu_dai, substream, &saif->dma_param); |
| 374 | |
| 375 | /* clear error status to 0 for each re-open */ |
| 376 | saif->fifo_underrun = 0; |
| 377 | saif->fifo_overrun = 0; |
| 378 | |
| 379 | /* Clear Reset for normal operations */ |
| 380 | __raw_writel(BM_SAIF_CTRL_SFTRST, |
| 381 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 382 | |
Dong Aisheng | bbe8ff5 | 2011-08-21 23:45:40 +0800 | [diff] [blame] | 383 | /* clear clock gate */ |
| 384 | __raw_writel(BM_SAIF_CTRL_CLKGATE, |
| 385 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 386 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Should only be called when port is inactive. |
| 392 | * although can be called multiple times by upper layers. |
| 393 | */ |
| 394 | static int mxs_saif_hw_params(struct snd_pcm_substream *substream, |
| 395 | struct snd_pcm_hw_params *params, |
| 396 | struct snd_soc_dai *cpu_dai) |
| 397 | { |
| 398 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
Dong Aisheng | c2e1d90 | 2012-07-20 17:20:24 +0800 | [diff] [blame] | 399 | struct mxs_saif *master_saif; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 400 | u32 scr, stat; |
| 401 | int ret; |
| 402 | |
Dong Aisheng | c2e1d90 | 2012-07-20 17:20:24 +0800 | [diff] [blame] | 403 | master_saif = mxs_saif_get_master(saif); |
| 404 | if (!master_saif) |
| 405 | return -EINVAL; |
| 406 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 407 | /* mclk should already be set */ |
| 408 | if (!saif->mclk && saif->mclk_in_use) { |
| 409 | dev_err(cpu_dai->dev, "set mclk first\n"); |
| 410 | return -EINVAL; |
| 411 | } |
| 412 | |
| 413 | stat = __raw_readl(saif->base + SAIF_STAT); |
| 414 | if (stat & BM_SAIF_STAT_BUSY) { |
| 415 | dev_err(cpu_dai->dev, "error: busy\n"); |
| 416 | return -EBUSY; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Set saif clk based on sample rate. |
| 421 | * If mclk is used, we also set mclk, if not, saif->mclk is |
| 422 | * default 0, means not used. |
| 423 | */ |
| 424 | ret = mxs_saif_set_clk(saif, saif->mclk, params_rate(params)); |
| 425 | if (ret) { |
| 426 | dev_err(cpu_dai->dev, "unable to get proper clk\n"); |
| 427 | return ret; |
| 428 | } |
| 429 | |
Dong Aisheng | c2e1d90 | 2012-07-20 17:20:24 +0800 | [diff] [blame] | 430 | /* prepare clk in hw_param, enable in trigger */ |
| 431 | clk_prepare(saif->clk); |
Dong Aisheng | d0ba4c0 | 2012-07-20 17:20:25 +0800 | [diff] [blame] | 432 | if (saif != master_saif) { |
| 433 | /* |
| 434 | * Set an initial clock rate for the saif internal logic to work |
| 435 | * properly. This is important when working in EXTMASTER mode |
| 436 | * that uses the other saif's BITCLK&LRCLK but it still needs a |
| 437 | * basic clock which should be fast enough for the internal |
| 438 | * logic. |
| 439 | */ |
| 440 | clk_enable(saif->clk); |
| 441 | ret = clk_set_rate(saif->clk, 24000000); |
| 442 | clk_disable(saif->clk); |
| 443 | if (ret) |
| 444 | return ret; |
| 445 | |
Dong Aisheng | c2e1d90 | 2012-07-20 17:20:24 +0800 | [diff] [blame] | 446 | clk_prepare(master_saif->clk); |
Dong Aisheng | d0ba4c0 | 2012-07-20 17:20:25 +0800 | [diff] [blame] | 447 | } |
Dong Aisheng | c2e1d90 | 2012-07-20 17:20:24 +0800 | [diff] [blame] | 448 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 449 | scr = __raw_readl(saif->base + SAIF_CTRL); |
| 450 | |
| 451 | scr &= ~BM_SAIF_CTRL_WORD_LENGTH; |
| 452 | scr &= ~BM_SAIF_CTRL_BITCLK_48XFS_ENABLE; |
| 453 | switch (params_format(params)) { |
| 454 | case SNDRV_PCM_FORMAT_S16_LE: |
| 455 | scr |= BF_SAIF_CTRL_WORD_LENGTH(0); |
| 456 | break; |
| 457 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 458 | scr |= BF_SAIF_CTRL_WORD_LENGTH(4); |
| 459 | scr |= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE; |
| 460 | break; |
| 461 | case SNDRV_PCM_FORMAT_S24_LE: |
| 462 | scr |= BF_SAIF_CTRL_WORD_LENGTH(8); |
| 463 | scr |= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE; |
| 464 | break; |
| 465 | default: |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
| 469 | /* Tx/Rx config */ |
| 470 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 471 | /* enable TX mode */ |
| 472 | scr &= ~BM_SAIF_CTRL_READ_MODE; |
| 473 | } else { |
| 474 | /* enable RX mode */ |
| 475 | scr |= BM_SAIF_CTRL_READ_MODE; |
| 476 | } |
| 477 | |
| 478 | __raw_writel(scr, saif->base + SAIF_CTRL); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int mxs_saif_prepare(struct snd_pcm_substream *substream, |
| 483 | struct snd_soc_dai *cpu_dai) |
| 484 | { |
| 485 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
| 486 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 487 | /* enable FIFO error irqs */ |
| 488 | __raw_writel(BM_SAIF_CTRL_FIFO_ERROR_IRQ_EN, |
| 489 | saif->base + SAIF_CTRL + MXS_SET_ADDR); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int mxs_saif_trigger(struct snd_pcm_substream *substream, int cmd, |
| 495 | struct snd_soc_dai *cpu_dai) |
| 496 | { |
| 497 | struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 498 | struct mxs_saif *master_saif; |
| 499 | u32 delay; |
| 500 | |
| 501 | master_saif = mxs_saif_get_master(saif); |
| 502 | if (!master_saif) |
| 503 | return -EINVAL; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 504 | |
| 505 | switch (cmd) { |
| 506 | case SNDRV_PCM_TRIGGER_START: |
| 507 | case SNDRV_PCM_TRIGGER_RESUME: |
| 508 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 509 | dev_dbg(cpu_dai->dev, "start\n"); |
| 510 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 511 | clk_enable(master_saif->clk); |
| 512 | if (!master_saif->mclk_in_use) |
| 513 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 514 | master_saif->base + SAIF_CTRL + MXS_SET_ADDR); |
| 515 | |
| 516 | /* |
| 517 | * If the saif's master is not himself, we also need to enable |
| 518 | * itself clk for its internal basic logic to work. |
| 519 | */ |
| 520 | if (saif != master_saif) { |
| 521 | clk_enable(saif->clk); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 522 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 523 | saif->base + SAIF_CTRL + MXS_SET_ADDR); |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 524 | } |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 525 | |
| 526 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 527 | /* |
Fabio Estevam | f55f147 | 2012-11-01 15:57:11 -0200 | [diff] [blame] | 528 | * write data to saif data register to trigger |
| 529 | * the transfer. |
| 530 | * For 24-bit format the 32-bit FIFO register stores |
| 531 | * only one channel, so we need to write twice. |
| 532 | * This is also safe for the other non 24-bit formats. |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 533 | */ |
| 534 | __raw_writel(0, saif->base + SAIF_DATA); |
Fabio Estevam | f55f147 | 2012-11-01 15:57:11 -0200 | [diff] [blame] | 535 | __raw_writel(0, saif->base + SAIF_DATA); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 536 | } else { |
| 537 | /* |
Fabio Estevam | f55f147 | 2012-11-01 15:57:11 -0200 | [diff] [blame] | 538 | * read data from saif data register to trigger |
| 539 | * the receive. |
| 540 | * For 24-bit format the 32-bit FIFO register stores |
| 541 | * only one channel, so we need to read twice. |
| 542 | * This is also safe for the other non 24-bit formats. |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 543 | */ |
| 544 | __raw_readl(saif->base + SAIF_DATA); |
Fabio Estevam | f55f147 | 2012-11-01 15:57:11 -0200 | [diff] [blame] | 545 | __raw_readl(saif->base + SAIF_DATA); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 546 | } |
| 547 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 548 | master_saif->ongoing = 1; |
| 549 | |
| 550 | dev_dbg(saif->dev, "CTRL 0x%x STAT 0x%x\n", |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 551 | __raw_readl(saif->base + SAIF_CTRL), |
| 552 | __raw_readl(saif->base + SAIF_STAT)); |
| 553 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 554 | dev_dbg(master_saif->dev, "CTRL 0x%x STAT 0x%x\n", |
| 555 | __raw_readl(master_saif->base + SAIF_CTRL), |
| 556 | __raw_readl(master_saif->base + SAIF_STAT)); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 557 | break; |
| 558 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 559 | case SNDRV_PCM_TRIGGER_STOP: |
| 560 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 561 | dev_dbg(cpu_dai->dev, "stop\n"); |
| 562 | |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 563 | /* wait a while for the current sample to complete */ |
| 564 | delay = USEC_PER_SEC / master_saif->cur_rate; |
| 565 | |
| 566 | if (!master_saif->mclk_in_use) { |
| 567 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 568 | master_saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
| 569 | udelay(delay); |
| 570 | } |
| 571 | clk_disable(master_saif->clk); |
| 572 | |
| 573 | if (saif != master_saif) { |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 574 | __raw_writel(BM_SAIF_CTRL_RUN, |
| 575 | saif->base + SAIF_CTRL + MXS_CLR_ADDR); |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 576 | udelay(delay); |
| 577 | clk_disable(saif->clk); |
| 578 | } |
| 579 | |
| 580 | master_saif->ongoing = 0; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 581 | |
| 582 | break; |
| 583 | default: |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | #define MXS_SAIF_RATES SNDRV_PCM_RATE_8000_192000 |
| 591 | #define MXS_SAIF_FORMATS \ |
| 592 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 593 | SNDRV_PCM_FMTBIT_S24_LE) |
| 594 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 595 | static const struct snd_soc_dai_ops mxs_saif_dai_ops = { |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 596 | .startup = mxs_saif_startup, |
| 597 | .trigger = mxs_saif_trigger, |
| 598 | .prepare = mxs_saif_prepare, |
| 599 | .hw_params = mxs_saif_hw_params, |
| 600 | .set_sysclk = mxs_saif_set_dai_sysclk, |
| 601 | .set_fmt = mxs_saif_set_dai_fmt, |
| 602 | }; |
| 603 | |
| 604 | static int mxs_saif_dai_probe(struct snd_soc_dai *dai) |
| 605 | { |
| 606 | struct mxs_saif *saif = dev_get_drvdata(dai->dev); |
| 607 | |
| 608 | snd_soc_dai_set_drvdata(dai, saif); |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static struct snd_soc_dai_driver mxs_saif_dai = { |
| 614 | .name = "mxs-saif", |
| 615 | .probe = mxs_saif_dai_probe, |
| 616 | .playback = { |
| 617 | .channels_min = 2, |
| 618 | .channels_max = 2, |
| 619 | .rates = MXS_SAIF_RATES, |
| 620 | .formats = MXS_SAIF_FORMATS, |
| 621 | }, |
| 622 | .capture = { |
| 623 | .channels_min = 2, |
| 624 | .channels_max = 2, |
| 625 | .rates = MXS_SAIF_RATES, |
| 626 | .formats = MXS_SAIF_FORMATS, |
| 627 | }, |
| 628 | .ops = &mxs_saif_dai_ops, |
| 629 | }; |
| 630 | |
| 631 | static irqreturn_t mxs_saif_irq(int irq, void *dev_id) |
| 632 | { |
| 633 | struct mxs_saif *saif = dev_id; |
| 634 | unsigned int stat; |
| 635 | |
| 636 | stat = __raw_readl(saif->base + SAIF_STAT); |
| 637 | if (!(stat & (BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ | |
| 638 | BM_SAIF_STAT_FIFO_OVERFLOW_IRQ))) |
| 639 | return IRQ_NONE; |
| 640 | |
| 641 | if (stat & BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ) { |
| 642 | dev_dbg(saif->dev, "underrun!!! %d\n", ++saif->fifo_underrun); |
| 643 | __raw_writel(BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ, |
| 644 | saif->base + SAIF_STAT + MXS_CLR_ADDR); |
| 645 | } |
| 646 | |
| 647 | if (stat & BM_SAIF_STAT_FIFO_OVERFLOW_IRQ) { |
| 648 | dev_dbg(saif->dev, "overrun!!! %d\n", ++saif->fifo_overrun); |
| 649 | __raw_writel(BM_SAIF_STAT_FIFO_OVERFLOW_IRQ, |
| 650 | saif->base + SAIF_STAT + MXS_CLR_ADDR); |
| 651 | } |
| 652 | |
| 653 | dev_dbg(saif->dev, "SAIF_CTRL %x SAIF_STAT %x\n", |
| 654 | __raw_readl(saif->base + SAIF_CTRL), |
| 655 | __raw_readl(saif->base + SAIF_STAT)); |
| 656 | |
| 657 | return IRQ_HANDLED; |
| 658 | } |
| 659 | |
Bill Pemberton | fd58273 | 2012-12-07 09:26:27 -0500 | [diff] [blame] | 660 | static int mxs_saif_probe(struct platform_device *pdev) |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 661 | { |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 662 | struct device_node *np = pdev->dev.of_node; |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 663 | struct resource *iores, *dmares; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 664 | struct mxs_saif *saif; |
Shawn Guo | f755865 | 2012-05-06 23:00:50 +0800 | [diff] [blame] | 665 | struct pinctrl *pinctrl; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 666 | int ret = 0; |
Fabio Estevam | 4498a3c | 2012-11-14 18:28:58 -0200 | [diff] [blame] | 667 | struct device_node *master; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 668 | |
Fabio Estevam | 4498a3c | 2012-11-14 18:28:58 -0200 | [diff] [blame] | 669 | if (!np) |
Julia Lawall | 0bb98ba | 2011-08-21 13:18:45 +0200 | [diff] [blame] | 670 | return -EINVAL; |
| 671 | |
Julia Lawall | 830eb87 | 2012-02-10 09:17:01 +0100 | [diff] [blame] | 672 | saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 673 | if (!saif) |
| 674 | return -ENOMEM; |
| 675 | |
Fabio Estevam | 324a7fb | 2013-01-08 10:45:04 -0200 | [diff] [blame] | 676 | ret = of_alias_get_id(np, "saif"); |
| 677 | if (ret < 0) |
| 678 | return ret; |
| 679 | else |
| 680 | saif->id = ret; |
| 681 | |
Fabio Estevam | 4498a3c | 2012-11-14 18:28:58 -0200 | [diff] [blame] | 682 | /* |
| 683 | * If there is no "fsl,saif-master" phandle, it's a saif |
| 684 | * master. Otherwise, it's a slave and its phandle points |
| 685 | * to the master. |
| 686 | */ |
| 687 | master = of_parse_phandle(np, "fsl,saif-master", 0); |
| 688 | if (!master) { |
| 689 | saif->master_id = saif->id; |
Dong Aisheng | 7788258 | 2011-11-22 23:52:21 +0800 | [diff] [blame] | 690 | } else { |
Fabio Estevam | 324a7fb | 2013-01-08 10:45:04 -0200 | [diff] [blame] | 691 | ret = of_alias_get_id(master, "saif"); |
| 692 | if (ret < 0) |
| 693 | return ret; |
| 694 | else |
| 695 | saif->master_id = ret; |
Dong Aisheng | 7606754 | 2011-09-07 20:51:50 +0800 | [diff] [blame] | 696 | } |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 697 | |
Fabio Estevam | 324a7fb | 2013-01-08 10:45:04 -0200 | [diff] [blame] | 698 | if (saif->master_id >= ARRAY_SIZE(mxs_saif)) { |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 699 | dev_err(&pdev->dev, "get wrong master id\n"); |
| 700 | return -EINVAL; |
| 701 | } |
| 702 | |
| 703 | mxs_saif[saif->id] = saif; |
| 704 | |
Shawn Guo | f755865 | 2012-05-06 23:00:50 +0800 | [diff] [blame] | 705 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
| 706 | if (IS_ERR(pinctrl)) { |
| 707 | ret = PTR_ERR(pinctrl); |
| 708 | return ret; |
| 709 | } |
| 710 | |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 711 | saif->clk = devm_clk_get(&pdev->dev, NULL); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 712 | if (IS_ERR(saif->clk)) { |
| 713 | ret = PTR_ERR(saif->clk); |
| 714 | dev_err(&pdev->dev, "Cannot get the clock: %d\n", |
| 715 | ret); |
Julia Lawall | 830eb87 | 2012-02-10 09:17:01 +0100 | [diff] [blame] | 716 | return ret; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 717 | } |
| 718 | |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 719 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 720 | |
Thierry Reding | b25b5aa | 2013-01-21 11:09:26 +0100 | [diff] [blame] | 721 | saif->base = devm_ioremap_resource(&pdev->dev, iores); |
| 722 | if (IS_ERR(saif->base)) |
| 723 | return PTR_ERR(saif->base); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 724 | |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 725 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 726 | if (!dmares) { |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 727 | /* |
| 728 | * TODO: This is a temporary solution and should be changed |
| 729 | * to use generic DMA binding later when the helplers get in. |
| 730 | */ |
| 731 | ret = of_property_read_u32(np, "fsl,saif-dma-channel", |
| 732 | &saif->dma_param.chan_num); |
| 733 | if (ret) { |
| 734 | dev_err(&pdev->dev, "failed to get dma channel\n"); |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 735 | return ret; |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 736 | } |
| 737 | } else { |
| 738 | saif->dma_param.chan_num = dmares->start; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 739 | } |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 740 | |
| 741 | saif->irq = platform_get_irq(pdev, 0); |
| 742 | if (saif->irq < 0) { |
| 743 | ret = saif->irq; |
| 744 | dev_err(&pdev->dev, "failed to get irq resource: %d\n", |
| 745 | ret); |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 746 | return ret; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | saif->dev = &pdev->dev; |
Julia Lawall | 830eb87 | 2012-02-10 09:17:01 +0100 | [diff] [blame] | 750 | ret = devm_request_irq(&pdev->dev, saif->irq, mxs_saif_irq, 0, |
| 751 | "mxs-saif", saif); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 752 | if (ret) { |
| 753 | dev_err(&pdev->dev, "failed to request irq\n"); |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 754 | return ret; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | saif->dma_param.chan_irq = platform_get_irq(pdev, 1); |
| 758 | if (saif->dma_param.chan_irq < 0) { |
| 759 | ret = saif->dma_param.chan_irq; |
| 760 | dev_err(&pdev->dev, "failed to get dma irq resource: %d\n", |
| 761 | ret); |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 762 | return ret; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | platform_set_drvdata(pdev, saif); |
| 766 | |
| 767 | ret = snd_soc_register_dai(&pdev->dev, &mxs_saif_dai); |
| 768 | if (ret) { |
| 769 | dev_err(&pdev->dev, "register DAI failed\n"); |
Fabio Estevam | 730963f | 2012-08-07 01:29:43 -0300 | [diff] [blame] | 770 | return ret; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Shawn Guo | 4da3fe7 | 2012-05-11 22:24:16 +0800 | [diff] [blame] | 773 | ret = mxs_pcm_platform_register(&pdev->dev); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 774 | if (ret) { |
Shawn Guo | 4da3fe7 | 2012-05-11 22:24:16 +0800 | [diff] [blame] | 775 | dev_err(&pdev->dev, "register PCM failed: %d\n", ret); |
| 776 | goto failed_pdev_alloc; |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | return 0; |
| 780 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 781 | failed_pdev_alloc: |
| 782 | snd_soc_unregister_dai(&pdev->dev); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 783 | |
| 784 | return ret; |
| 785 | } |
| 786 | |
Bill Pemberton | fd58273 | 2012-12-07 09:26:27 -0500 | [diff] [blame] | 787 | static int mxs_saif_remove(struct platform_device *pdev) |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 788 | { |
Shawn Guo | 4da3fe7 | 2012-05-11 22:24:16 +0800 | [diff] [blame] | 789 | mxs_pcm_platform_unregister(&pdev->dev); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 790 | snd_soc_unregister_dai(&pdev->dev); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 795 | static const struct of_device_id mxs_saif_dt_ids[] = { |
| 796 | { .compatible = "fsl,imx28-saif", }, |
| 797 | { /* sentinel */ } |
| 798 | }; |
| 799 | MODULE_DEVICE_TABLE(of, mxs_saif_dt_ids); |
| 800 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 801 | static struct platform_driver mxs_saif_driver = { |
| 802 | .probe = mxs_saif_probe, |
Bill Pemberton | fd58273 | 2012-12-07 09:26:27 -0500 | [diff] [blame] | 803 | .remove = mxs_saif_remove, |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 804 | |
| 805 | .driver = { |
| 806 | .name = "mxs-saif", |
| 807 | .owner = THIS_MODULE, |
Shawn Guo | 08641c7 | 2012-05-11 22:24:17 +0800 | [diff] [blame] | 808 | .of_match_table = mxs_saif_dt_ids, |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 809 | }, |
| 810 | }; |
| 811 | |
Axel Lin | 85aa096 | 2011-11-24 14:21:29 +0800 | [diff] [blame] | 812 | module_platform_driver(mxs_saif_driver); |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 813 | |
Dong Aisheng | 2a24f2c | 2011-07-21 12:36:56 +0800 | [diff] [blame] | 814 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); |
| 815 | MODULE_DESCRIPTION("MXS ASoC SAIF driver"); |
| 816 | MODULE_LICENSE("GPL"); |
Fabio Estevam | 9f4c3f1 | 2012-10-31 01:20:05 -0200 | [diff] [blame] | 817 | MODULE_ALIAS("platform:mxs-saif"); |