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