Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Freescale ALSA SoC Digital Audio Interface (SAI) driver. |
| 3 | * |
| 4 | * Copyright 2012-2013 Freescale Semiconductor, Inc. |
| 5 | * |
| 6 | * This program is free software, you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation, either version 2 of the License, or(at your |
| 9 | * option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/dmaengine.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/of_address.h> |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 18 | #include <linux/regmap.h> |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <sound/core.h> |
| 21 | #include <sound/dmaengine_pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | |
| 24 | #include "fsl_sai.h" |
Nicolin Chen | c754064 | 2014-04-01 19:34:09 +0800 | [diff] [blame^] | 25 | #include "imx-pcm.h" |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 26 | |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 27 | #define FSL_SAI_FLAGS (FSL_SAI_CSR_SEIE |\ |
| 28 | FSL_SAI_CSR_FEIE) |
| 29 | |
| 30 | static irqreturn_t fsl_sai_isr(int irq, void *devid) |
| 31 | { |
| 32 | struct fsl_sai *sai = (struct fsl_sai *)devid; |
| 33 | struct device *dev = &sai->pdev->dev; |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 34 | u32 flags, xcsr, mask; |
| 35 | bool irq_none = true; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 36 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 37 | /* |
| 38 | * Both IRQ status bits and IRQ mask bits are in the xCSR but |
| 39 | * different shifts. And we here create a mask only for those |
| 40 | * IRQs that we activated. |
| 41 | */ |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 42 | mask = (FSL_SAI_FLAGS >> FSL_SAI_CSR_xIE_SHIFT) << FSL_SAI_CSR_xF_SHIFT; |
| 43 | |
| 44 | /* Tx IRQ */ |
| 45 | regmap_read(sai->regmap, FSL_SAI_TCSR, &xcsr); |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 46 | flags = xcsr & mask; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 47 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 48 | if (flags) |
| 49 | irq_none = false; |
| 50 | else |
| 51 | goto irq_rx; |
| 52 | |
| 53 | if (flags & FSL_SAI_CSR_WSF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 54 | dev_dbg(dev, "isr: Start of Tx word detected\n"); |
| 55 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 56 | if (flags & FSL_SAI_CSR_SEF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 57 | dev_warn(dev, "isr: Tx Frame sync error detected\n"); |
| 58 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 59 | if (flags & FSL_SAI_CSR_FEF) { |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 60 | dev_warn(dev, "isr: Transmit underrun detected\n"); |
| 61 | /* FIFO reset for safety */ |
| 62 | xcsr |= FSL_SAI_CSR_FR; |
| 63 | } |
| 64 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 65 | if (flags & FSL_SAI_CSR_FWF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 66 | dev_dbg(dev, "isr: Enabled transmit FIFO is empty\n"); |
| 67 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 68 | if (flags & FSL_SAI_CSR_FRF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 69 | dev_dbg(dev, "isr: Transmit FIFO watermark has been reached\n"); |
| 70 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 71 | flags &= FSL_SAI_CSR_xF_W_MASK; |
| 72 | xcsr &= ~FSL_SAI_CSR_xF_MASK; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 73 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 74 | if (flags) |
| 75 | regmap_write(sai->regmap, FSL_SAI_TCSR, flags | xcsr); |
| 76 | |
| 77 | irq_rx: |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 78 | /* Rx IRQ */ |
| 79 | regmap_read(sai->regmap, FSL_SAI_RCSR, &xcsr); |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 80 | flags = xcsr & mask; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 81 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 82 | if (flags) |
| 83 | irq_none = false; |
| 84 | else |
| 85 | goto out; |
| 86 | |
| 87 | if (flags & FSL_SAI_CSR_WSF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 88 | dev_dbg(dev, "isr: Start of Rx word detected\n"); |
| 89 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 90 | if (flags & FSL_SAI_CSR_SEF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 91 | dev_warn(dev, "isr: Rx Frame sync error detected\n"); |
| 92 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 93 | if (flags & FSL_SAI_CSR_FEF) { |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 94 | dev_warn(dev, "isr: Receive overflow detected\n"); |
| 95 | /* FIFO reset for safety */ |
| 96 | xcsr |= FSL_SAI_CSR_FR; |
| 97 | } |
| 98 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 99 | if (flags & FSL_SAI_CSR_FWF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 100 | dev_dbg(dev, "isr: Enabled receive FIFO is full\n"); |
| 101 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 102 | if (flags & FSL_SAI_CSR_FRF) |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 103 | dev_dbg(dev, "isr: Receive FIFO watermark has been reached\n"); |
| 104 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 105 | flags &= FSL_SAI_CSR_xF_W_MASK; |
| 106 | xcsr &= ~FSL_SAI_CSR_xF_MASK; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 107 | |
Nicolin Chen | 413312a | 2014-03-28 19:39:25 +0800 | [diff] [blame] | 108 | if (flags) |
| 109 | regmap_write(sai->regmap, FSL_SAI_TCSR, flags | xcsr); |
| 110 | |
| 111 | out: |
| 112 | if (irq_none) |
| 113 | return IRQ_NONE; |
| 114 | else |
| 115 | return IRQ_HANDLED; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 118 | static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai, |
| 119 | int clk_id, unsigned int freq, int fsl_dir) |
| 120 | { |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 121 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Nicolin Chen | 4e3a99f | 2013-12-20 16:41:05 +0800 | [diff] [blame] | 122 | u32 val_cr2, reg_cr2; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 123 | |
| 124 | if (fsl_dir == FSL_FMT_TRANSMITTER) |
| 125 | reg_cr2 = FSL_SAI_TCR2; |
| 126 | else |
| 127 | reg_cr2 = FSL_SAI_RCR2; |
| 128 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 129 | regmap_read(sai->regmap, reg_cr2, &val_cr2); |
| 130 | |
Xiubo Li | 633ff8f | 2014-01-08 16:13:05 +0800 | [diff] [blame] | 131 | val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; |
| 132 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 133 | switch (clk_id) { |
| 134 | case FSL_SAI_CLK_BUS: |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 135 | val_cr2 |= FSL_SAI_CR2_MSEL_BUS; |
| 136 | break; |
| 137 | case FSL_SAI_CLK_MAST1: |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 138 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK1; |
| 139 | break; |
| 140 | case FSL_SAI_CLK_MAST2: |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 141 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK2; |
| 142 | break; |
| 143 | case FSL_SAI_CLK_MAST3: |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 144 | val_cr2 |= FSL_SAI_CR2_MSEL_MCLK3; |
| 145 | break; |
| 146 | default: |
| 147 | return -EINVAL; |
| 148 | } |
Xiubo Li | 633ff8f | 2014-01-08 16:13:05 +0800 | [diff] [blame] | 149 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 150 | regmap_write(sai->regmap, reg_cr2, val_cr2); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai, |
| 156 | int clk_id, unsigned int freq, int dir) |
| 157 | { |
Nicolin Chen | 4e3a99f | 2013-12-20 16:41:05 +0800 | [diff] [blame] | 158 | int ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 159 | |
| 160 | if (dir == SND_SOC_CLOCK_IN) |
| 161 | return 0; |
| 162 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 163 | ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, |
| 164 | FSL_FMT_TRANSMITTER); |
| 165 | if (ret) { |
Nicolin Chen | 190af12 | 2013-12-20 16:41:04 +0800 | [diff] [blame] | 166 | dev_err(cpu_dai->dev, "Cannot set tx sysclk: %d\n", ret); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 167 | return ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, |
| 171 | FSL_FMT_RECEIVER); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 172 | if (ret) |
Nicolin Chen | 190af12 | 2013-12-20 16:41:04 +0800 | [diff] [blame] | 173 | dev_err(cpu_dai->dev, "Cannot set rx sysclk: %d\n", ret); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 174 | |
Nicolin Chen | 1fb2d9d | 2013-12-20 16:41:00 +0800 | [diff] [blame] | 175 | return ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai, |
| 179 | unsigned int fmt, int fsl_dir) |
| 180 | { |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 181 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Xiubo Li | e5d0fa9 | 2013-12-25 12:40:04 +0800 | [diff] [blame] | 182 | u32 val_cr2, val_cr4, reg_cr2, reg_cr4; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 183 | |
| 184 | if (fsl_dir == FSL_FMT_TRANSMITTER) { |
| 185 | reg_cr2 = FSL_SAI_TCR2; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 186 | reg_cr4 = FSL_SAI_TCR4; |
| 187 | } else { |
| 188 | reg_cr2 = FSL_SAI_RCR2; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 189 | reg_cr4 = FSL_SAI_RCR4; |
| 190 | } |
| 191 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 192 | regmap_read(sai->regmap, reg_cr2, &val_cr2); |
| 193 | regmap_read(sai->regmap, reg_cr4, &val_cr4); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 194 | |
| 195 | if (sai->big_endian_data) |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 196 | val_cr4 &= ~FSL_SAI_CR4_MF; |
Xiubo Li | 72aa62b | 2013-12-31 15:33:22 +0800 | [diff] [blame] | 197 | else |
| 198 | val_cr4 |= FSL_SAI_CR4_MF; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 199 | |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 200 | /* DAI mode */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 201 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 202 | case SND_SOC_DAIFMT_I2S: |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 203 | /* |
| 204 | * Frame low, 1clk before data, one word length for frame sync, |
| 205 | * frame sync starts one serial clock cycle earlier, |
| 206 | * that is, together with the last bit of the previous |
| 207 | * data word. |
| 208 | */ |
Nicolin Chen | ef33bc3 | 2014-04-04 15:09:47 +0800 | [diff] [blame] | 209 | val_cr2 |= FSL_SAI_CR2_BCP; |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 210 | val_cr4 |= FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 211 | break; |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 212 | case SND_SOC_DAIFMT_LEFT_J: |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 213 | /* |
| 214 | * Frame high, one word length for frame sync, |
| 215 | * frame sync asserts with the first bit of the frame. |
| 216 | */ |
Nicolin Chen | ef33bc3 | 2014-04-04 15:09:47 +0800 | [diff] [blame] | 217 | val_cr2 |= FSL_SAI_CR2_BCP; |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 218 | val_cr4 &= ~(FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP); |
| 219 | break; |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 220 | case SND_SOC_DAIFMT_DSP_A: |
| 221 | /* |
| 222 | * Frame high, 1clk before data, one bit for frame sync, |
| 223 | * frame sync starts one serial clock cycle earlier, |
| 224 | * that is, together with the last bit of the previous |
| 225 | * data word. |
| 226 | */ |
Nicolin Chen | ef33bc3 | 2014-04-04 15:09:47 +0800 | [diff] [blame] | 227 | val_cr2 |= FSL_SAI_CR2_BCP; |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 228 | val_cr4 &= ~FSL_SAI_CR4_FSP; |
| 229 | val_cr4 |= FSL_SAI_CR4_FSE; |
| 230 | sai->is_dsp_mode = true; |
| 231 | break; |
| 232 | case SND_SOC_DAIFMT_DSP_B: |
| 233 | /* |
| 234 | * Frame high, one bit for frame sync, |
| 235 | * frame sync asserts with the first bit of the frame. |
| 236 | */ |
Nicolin Chen | ef33bc3 | 2014-04-04 15:09:47 +0800 | [diff] [blame] | 237 | val_cr2 |= FSL_SAI_CR2_BCP; |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 238 | val_cr4 &= ~(FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP); |
| 239 | sai->is_dsp_mode = true; |
| 240 | break; |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 241 | case SND_SOC_DAIFMT_RIGHT_J: |
| 242 | /* To be done */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 243 | default: |
| 244 | return -EINVAL; |
| 245 | } |
| 246 | |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 247 | /* DAI clock inversion */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 248 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 249 | case SND_SOC_DAIFMT_IB_IF: |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 250 | /* Invert both clocks */ |
| 251 | val_cr2 ^= FSL_SAI_CR2_BCP; |
| 252 | val_cr4 ^= FSL_SAI_CR4_FSP; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 253 | break; |
| 254 | case SND_SOC_DAIFMT_IB_NF: |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 255 | /* Invert bit clock */ |
| 256 | val_cr2 ^= FSL_SAI_CR2_BCP; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 257 | break; |
| 258 | case SND_SOC_DAIFMT_NB_IF: |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 259 | /* Invert frame clock */ |
| 260 | val_cr4 ^= FSL_SAI_CR4_FSP; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 261 | break; |
| 262 | case SND_SOC_DAIFMT_NB_NF: |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 263 | /* Nothing to do for both normal cases */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 264 | break; |
| 265 | default: |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 269 | /* DAI clock master masks */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 270 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 271 | case SND_SOC_DAIFMT_CBS_CFS: |
| 272 | val_cr2 |= FSL_SAI_CR2_BCD_MSTR; |
| 273 | val_cr4 |= FSL_SAI_CR4_FSD_MSTR; |
| 274 | break; |
| 275 | case SND_SOC_DAIFMT_CBM_CFM: |
| 276 | val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR; |
| 277 | val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR; |
| 278 | break; |
Xiubo Li | 13cde09 | 2014-02-25 17:54:51 +0800 | [diff] [blame] | 279 | case SND_SOC_DAIFMT_CBS_CFM: |
| 280 | val_cr2 |= FSL_SAI_CR2_BCD_MSTR; |
| 281 | val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR; |
| 282 | break; |
| 283 | case SND_SOC_DAIFMT_CBM_CFS: |
| 284 | val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR; |
| 285 | val_cr4 |= FSL_SAI_CR4_FSD_MSTR; |
| 286 | break; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 287 | default: |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 291 | regmap_write(sai->regmap, reg_cr2, val_cr2); |
| 292 | regmap_write(sai->regmap, reg_cr4, val_cr4); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int fsl_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) |
| 298 | { |
Nicolin Chen | 4e3a99f | 2013-12-20 16:41:05 +0800 | [diff] [blame] | 299 | int ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 300 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 301 | ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_TRANSMITTER); |
| 302 | if (ret) { |
Nicolin Chen | 190af12 | 2013-12-20 16:41:04 +0800 | [diff] [blame] | 303 | dev_err(cpu_dai->dev, "Cannot set tx format: %d\n", ret); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 304 | return ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_RECEIVER); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 308 | if (ret) |
Nicolin Chen | 190af12 | 2013-12-20 16:41:04 +0800 | [diff] [blame] | 309 | dev_err(cpu_dai->dev, "Cannot set rx format: %d\n", ret); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 310 | |
Nicolin Chen | 1fb2d9d | 2013-12-20 16:41:00 +0800 | [diff] [blame] | 311 | return ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static int fsl_sai_hw_params(struct snd_pcm_substream *substream, |
| 315 | struct snd_pcm_hw_params *params, |
| 316 | struct snd_soc_dai *cpu_dai) |
| 317 | { |
Nicolin Chen | 4e3a99f | 2013-12-20 16:41:05 +0800 | [diff] [blame] | 318 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Nicolin Chen | 1d70030 | 2013-12-20 16:41:01 +0800 | [diff] [blame] | 319 | u32 val_cr4, val_cr5, val_mr, reg_cr4, reg_cr5, reg_mr; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 320 | unsigned int channels = params_channels(params); |
Nicolin Chen | 1d70030 | 2013-12-20 16:41:01 +0800 | [diff] [blame] | 321 | u32 word_width = snd_pcm_format_width(params_format(params)); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 322 | |
| 323 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 324 | reg_cr4 = FSL_SAI_TCR4; |
| 325 | reg_cr5 = FSL_SAI_TCR5; |
| 326 | reg_mr = FSL_SAI_TMR; |
| 327 | } else { |
| 328 | reg_cr4 = FSL_SAI_RCR4; |
| 329 | reg_cr5 = FSL_SAI_RCR5; |
| 330 | reg_mr = FSL_SAI_RMR; |
| 331 | } |
| 332 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 333 | regmap_read(sai->regmap, reg_cr4, &val_cr4); |
| 334 | regmap_read(sai->regmap, reg_cr4, &val_cr5); |
| 335 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 336 | val_cr4 &= ~FSL_SAI_CR4_SYWD_MASK; |
| 337 | val_cr4 &= ~FSL_SAI_CR4_FRSZ_MASK; |
| 338 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 339 | val_cr5 &= ~FSL_SAI_CR5_WNW_MASK; |
| 340 | val_cr5 &= ~FSL_SAI_CR5_W0W_MASK; |
| 341 | val_cr5 &= ~FSL_SAI_CR5_FBT_MASK; |
| 342 | |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 343 | if (!sai->is_dsp_mode) |
| 344 | val_cr4 |= FSL_SAI_CR4_SYWD(word_width); |
| 345 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 346 | val_cr5 |= FSL_SAI_CR5_WNW(word_width); |
| 347 | val_cr5 |= FSL_SAI_CR5_W0W(word_width); |
| 348 | |
Xiubo Li | 496a39d | 2013-12-31 15:33:21 +0800 | [diff] [blame] | 349 | val_cr5 &= ~FSL_SAI_CR5_FBT_MASK; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 350 | if (sai->big_endian_data) |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 351 | val_cr5 |= FSL_SAI_CR5_FBT(0); |
Xiubo Li | 72aa62b | 2013-12-31 15:33:22 +0800 | [diff] [blame] | 352 | else |
| 353 | val_cr5 |= FSL_SAI_CR5_FBT(word_width - 1); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 354 | |
| 355 | val_cr4 |= FSL_SAI_CR4_FRSZ(channels); |
Nicolin Chen | d22e28c | 2013-12-20 16:41:02 +0800 | [diff] [blame] | 356 | val_mr = ~0UL - ((1 << channels) - 1); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 357 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 358 | regmap_write(sai->regmap, reg_cr4, val_cr4); |
| 359 | regmap_write(sai->regmap, reg_cr5, val_cr5); |
| 360 | regmap_write(sai->regmap, reg_mr, val_mr); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd, |
| 366 | struct snd_soc_dai *cpu_dai) |
| 367 | { |
| 368 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 369 | bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 370 | u32 tcsr, rcsr; |
Xiubo Li | 496a39d | 2013-12-31 15:33:21 +0800 | [diff] [blame] | 371 | |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 372 | /* |
| 373 | * The transmitter bit clock and frame sync are to be |
| 374 | * used by both the transmitter and receiver. |
| 375 | */ |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 376 | regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC, |
| 377 | ~FSL_SAI_CR2_SYNC); |
| 378 | regmap_update_bits(sai->regmap, FSL_SAI_RCR2, FSL_SAI_CR2_SYNC, |
| 379 | FSL_SAI_CR2_SYNC); |
Xiubo Li | 496a39d | 2013-12-31 15:33:21 +0800 | [diff] [blame] | 380 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 381 | regmap_read(sai->regmap, FSL_SAI_TCSR, &tcsr); |
| 382 | regmap_read(sai->regmap, FSL_SAI_RCSR, &rcsr); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 383 | |
Xiubo Li | a3f7dcc | 2014-02-27 08:45:01 +0800 | [diff] [blame] | 384 | /* |
| 385 | * It is recommended that the transmitter is the last enabled |
| 386 | * and the first disabled. |
| 387 | */ |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 388 | switch (cmd) { |
| 389 | case SNDRV_PCM_TRIGGER_START: |
| 390 | case SNDRV_PCM_TRIGGER_RESUME: |
| 391 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 392 | if (!(tcsr & FSL_SAI_CSR_FRDE || rcsr & FSL_SAI_CSR_FRDE)) { |
| 393 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, |
| 394 | FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE); |
| 395 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, |
| 396 | FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE); |
| 397 | } |
Xiubo Li | e5d0fa9 | 2013-12-25 12:40:04 +0800 | [diff] [blame] | 398 | |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 399 | regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx), |
Nicolin Chen | 8abba5d | 2014-04-01 11:17:07 +0800 | [diff] [blame] | 400 | FSL_SAI_CSR_xIE_MASK, FSL_SAI_FLAGS); |
| 401 | regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx), |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 402 | FSL_SAI_CSR_FRDE, FSL_SAI_CSR_FRDE); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 403 | break; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 404 | case SNDRV_PCM_TRIGGER_STOP: |
| 405 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 406 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 407 | regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx), |
| 408 | FSL_SAI_CSR_FRDE, 0); |
Nicolin Chen | 8abba5d | 2014-04-01 11:17:07 +0800 | [diff] [blame] | 409 | regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx), |
| 410 | FSL_SAI_CSR_xIE_MASK, 0); |
Xiubo Li | e5d0fa9 | 2013-12-25 12:40:04 +0800 | [diff] [blame] | 411 | |
Nicolin Chen | e6b3984 | 2014-04-01 11:17:06 +0800 | [diff] [blame] | 412 | if (!(tcsr & FSL_SAI_CSR_FRDE || rcsr & FSL_SAI_CSR_FRDE)) { |
| 413 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, |
| 414 | FSL_SAI_CSR_TERE, 0); |
| 415 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, |
| 416 | FSL_SAI_CSR_TERE, 0); |
| 417 | } |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 418 | break; |
| 419 | default: |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int fsl_sai_startup(struct snd_pcm_substream *substream, |
| 427 | struct snd_soc_dai *cpu_dai) |
| 428 | { |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 429 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 430 | u32 reg; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 431 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 432 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 433 | reg = FSL_SAI_TCR3; |
| 434 | else |
| 435 | reg = FSL_SAI_RCR3; |
| 436 | |
| 437 | regmap_update_bits(sai->regmap, reg, FSL_SAI_CR3_TRCE, |
| 438 | FSL_SAI_CR3_TRCE); |
| 439 | |
| 440 | return 0; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static void fsl_sai_shutdown(struct snd_pcm_substream *substream, |
| 444 | struct snd_soc_dai *cpu_dai) |
| 445 | { |
| 446 | struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 447 | u32 reg; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 448 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 449 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 450 | reg = FSL_SAI_TCR3; |
| 451 | else |
| 452 | reg = FSL_SAI_RCR3; |
| 453 | |
| 454 | regmap_update_bits(sai->regmap, reg, FSL_SAI_CR3_TRCE, |
| 455 | ~FSL_SAI_CR3_TRCE); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = { |
| 459 | .set_sysclk = fsl_sai_set_dai_sysclk, |
| 460 | .set_fmt = fsl_sai_set_dai_fmt, |
| 461 | .hw_params = fsl_sai_hw_params, |
| 462 | .trigger = fsl_sai_trigger, |
| 463 | .startup = fsl_sai_startup, |
| 464 | .shutdown = fsl_sai_shutdown, |
| 465 | }; |
| 466 | |
| 467 | static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai) |
| 468 | { |
| 469 | struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); |
Xiubo Li | e6dc12d | 2013-12-25 11:20:14 +0800 | [diff] [blame] | 470 | |
Nicolin Chen | 8abba5d | 2014-04-01 11:17:07 +0800 | [diff] [blame] | 471 | regmap_update_bits(sai->regmap, FSL_SAI_TCSR, 0xffffffff, 0x0); |
| 472 | regmap_update_bits(sai->regmap, FSL_SAI_RCSR, 0xffffffff, 0x0); |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 473 | regmap_update_bits(sai->regmap, FSL_SAI_TCR1, FSL_SAI_CR1_RFW_MASK, |
| 474 | FSL_SAI_MAXBURST_TX * 2); |
| 475 | regmap_update_bits(sai->regmap, FSL_SAI_RCR1, FSL_SAI_CR1_RFW_MASK, |
| 476 | FSL_SAI_MAXBURST_RX - 1); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 477 | |
Xiubo Li | dd9f406 | 2013-12-20 12:35:33 +0800 | [diff] [blame] | 478 | snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params_tx, |
| 479 | &sai->dma_params_rx); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 480 | |
| 481 | snd_soc_dai_set_drvdata(cpu_dai, sai); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 486 | static struct snd_soc_dai_driver fsl_sai_dai = { |
| 487 | .probe = fsl_sai_dai_probe, |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 488 | .playback = { |
| 489 | .channels_min = 1, |
| 490 | .channels_max = 2, |
| 491 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 492 | .formats = FSL_SAI_FORMATS, |
| 493 | }, |
| 494 | .capture = { |
| 495 | .channels_min = 1, |
| 496 | .channels_max = 2, |
| 497 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 498 | .formats = FSL_SAI_FORMATS, |
| 499 | }, |
| 500 | .ops = &fsl_sai_pcm_dai_ops, |
| 501 | }; |
| 502 | |
| 503 | static const struct snd_soc_component_driver fsl_component = { |
| 504 | .name = "fsl-sai", |
| 505 | }; |
| 506 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 507 | static bool fsl_sai_readable_reg(struct device *dev, unsigned int reg) |
| 508 | { |
| 509 | switch (reg) { |
| 510 | case FSL_SAI_TCSR: |
| 511 | case FSL_SAI_TCR1: |
| 512 | case FSL_SAI_TCR2: |
| 513 | case FSL_SAI_TCR3: |
| 514 | case FSL_SAI_TCR4: |
| 515 | case FSL_SAI_TCR5: |
| 516 | case FSL_SAI_TFR: |
| 517 | case FSL_SAI_TMR: |
| 518 | case FSL_SAI_RCSR: |
| 519 | case FSL_SAI_RCR1: |
| 520 | case FSL_SAI_RCR2: |
| 521 | case FSL_SAI_RCR3: |
| 522 | case FSL_SAI_RCR4: |
| 523 | case FSL_SAI_RCR5: |
| 524 | case FSL_SAI_RDR: |
| 525 | case FSL_SAI_RFR: |
| 526 | case FSL_SAI_RMR: |
| 527 | return true; |
| 528 | default: |
| 529 | return false; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg) |
| 534 | { |
| 535 | switch (reg) { |
| 536 | case FSL_SAI_TFR: |
| 537 | case FSL_SAI_RFR: |
| 538 | case FSL_SAI_TDR: |
| 539 | case FSL_SAI_RDR: |
| 540 | return true; |
| 541 | default: |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | } |
| 546 | |
| 547 | static bool fsl_sai_writeable_reg(struct device *dev, unsigned int reg) |
| 548 | { |
| 549 | switch (reg) { |
| 550 | case FSL_SAI_TCSR: |
| 551 | case FSL_SAI_TCR1: |
| 552 | case FSL_SAI_TCR2: |
| 553 | case FSL_SAI_TCR3: |
| 554 | case FSL_SAI_TCR4: |
| 555 | case FSL_SAI_TCR5: |
| 556 | case FSL_SAI_TDR: |
| 557 | case FSL_SAI_TMR: |
| 558 | case FSL_SAI_RCSR: |
| 559 | case FSL_SAI_RCR1: |
| 560 | case FSL_SAI_RCR2: |
| 561 | case FSL_SAI_RCR3: |
| 562 | case FSL_SAI_RCR4: |
| 563 | case FSL_SAI_RCR5: |
| 564 | case FSL_SAI_RMR: |
| 565 | return true; |
| 566 | default: |
| 567 | return false; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | static struct regmap_config fsl_sai_regmap_config = { |
| 572 | .reg_bits = 32, |
| 573 | .reg_stride = 4, |
| 574 | .val_bits = 32, |
| 575 | |
| 576 | .max_register = FSL_SAI_RMR, |
| 577 | .readable_reg = fsl_sai_readable_reg, |
| 578 | .volatile_reg = fsl_sai_volatile_reg, |
| 579 | .writeable_reg = fsl_sai_writeable_reg, |
| 580 | }; |
| 581 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 582 | static int fsl_sai_probe(struct platform_device *pdev) |
| 583 | { |
Nicolin Chen | 4e3a99f | 2013-12-20 16:41:05 +0800 | [diff] [blame] | 584 | struct device_node *np = pdev->dev.of_node; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 585 | struct fsl_sai *sai; |
| 586 | struct resource *res; |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 587 | void __iomem *base; |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 588 | int irq, ret; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 589 | |
| 590 | sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); |
| 591 | if (!sai) |
| 592 | return -ENOMEM; |
| 593 | |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 594 | sai->pdev = pdev; |
| 595 | |
Nicolin Chen | c754064 | 2014-04-01 19:34:09 +0800 | [diff] [blame^] | 596 | if (of_device_is_compatible(pdev->dev.of_node, "fsl,imx6sx-sai")) |
| 597 | sai->sai_on_imx = true; |
| 598 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 599 | sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs"); |
| 600 | if (sai->big_endian_regs) |
| 601 | fsl_sai_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG; |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 602 | |
Xiubo Li | 78957fc | 2014-02-08 14:38:28 +0800 | [diff] [blame] | 603 | sai->big_endian_data = of_property_read_bool(np, "big-endian-data"); |
| 604 | |
| 605 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 606 | base = devm_ioremap_resource(&pdev->dev, res); |
| 607 | if (IS_ERR(base)) |
| 608 | return PTR_ERR(base); |
| 609 | |
| 610 | sai->regmap = devm_regmap_init_mmio_clk(&pdev->dev, |
| 611 | "sai", base, &fsl_sai_regmap_config); |
| 612 | if (IS_ERR(sai->regmap)) { |
| 613 | dev_err(&pdev->dev, "regmap init failed\n"); |
| 614 | return PTR_ERR(sai->regmap); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 615 | } |
| 616 | |
Nicolin Chen | e2681a1 | 2014-03-27 19:06:59 +0800 | [diff] [blame] | 617 | irq = platform_get_irq(pdev, 0); |
| 618 | if (irq < 0) { |
| 619 | dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); |
| 620 | return irq; |
| 621 | } |
| 622 | |
| 623 | ret = devm_request_irq(&pdev->dev, irq, fsl_sai_isr, 0, np->name, sai); |
| 624 | if (ret) { |
| 625 | dev_err(&pdev->dev, "failed to claim irq %u\n", irq); |
| 626 | return ret; |
| 627 | } |
| 628 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 629 | sai->dma_params_rx.addr = res->start + FSL_SAI_RDR; |
| 630 | sai->dma_params_tx.addr = res->start + FSL_SAI_TDR; |
| 631 | sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; |
| 632 | sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; |
| 633 | |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 634 | platform_set_drvdata(pdev, sai); |
| 635 | |
| 636 | ret = devm_snd_soc_register_component(&pdev->dev, &fsl_component, |
| 637 | &fsl_sai_dai, 1); |
| 638 | if (ret) |
| 639 | return ret; |
| 640 | |
Nicolin Chen | c754064 | 2014-04-01 19:34:09 +0800 | [diff] [blame^] | 641 | if (sai->sai_on_imx) |
| 642 | return imx_pcm_dma_init(pdev); |
| 643 | else |
| 644 | return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, |
| 645 | SND_DMAENGINE_PCM_FLAG_NO_RESIDUE); |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static const struct of_device_id fsl_sai_ids[] = { |
| 649 | { .compatible = "fsl,vf610-sai", }, |
Nicolin Chen | c754064 | 2014-04-01 19:34:09 +0800 | [diff] [blame^] | 650 | { .compatible = "fsl,imx6sx-sai", }, |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 651 | { /* sentinel */ } |
| 652 | }; |
| 653 | |
| 654 | static struct platform_driver fsl_sai_driver = { |
| 655 | .probe = fsl_sai_probe, |
Xiubo Li | 4355082 | 2013-12-17 11:24:38 +0800 | [diff] [blame] | 656 | .driver = { |
| 657 | .name = "fsl-sai", |
| 658 | .owner = THIS_MODULE, |
| 659 | .of_match_table = fsl_sai_ids, |
| 660 | }, |
| 661 | }; |
| 662 | module_platform_driver(fsl_sai_driver); |
| 663 | |
| 664 | MODULE_DESCRIPTION("Freescale Soc SAI Interface"); |
| 665 | MODULE_AUTHOR("Xiubo Li, <Li.Xiubo@freescale.com>"); |
| 666 | MODULE_ALIAS("platform:fsl-sai"); |
| 667 | MODULE_LICENSE("GPL"); |