diff options
| -rw-r--r-- | sound/soc/fsl/Kconfig | 8 | ||||
| -rw-r--r-- | sound/soc/fsl/fsl_ssi.c | 576 | ||||
| -rw-r--r-- | sound/soc/fsl/fsl_ssi.h | 50 |
3 files changed, 363 insertions, 271 deletions
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index d262ec0653d3..37933629cbed 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig | |||
| @@ -16,6 +16,7 @@ config SND_SOC_FSL_SSI | |||
| 16 | tristate "Synchronous Serial Interface module support" | 16 | tristate "Synchronous Serial Interface module support" |
| 17 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n | 17 | select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n |
| 18 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && ARCH_MXC | 18 | select SND_SOC_IMX_PCM_FIQ if SND_IMX_SOC != n && ARCH_MXC |
| 19 | select REGMAP_MMIO | ||
| 19 | help | 20 | help |
| 20 | Say Y if you want to add Synchronous Serial Interface (SSI) | 21 | Say Y if you want to add Synchronous Serial Interface (SSI) |
| 21 | support for the Freescale CPUs. | 22 | support for the Freescale CPUs. |
| @@ -207,12 +208,7 @@ config SND_SOC_PHYCORE_AC97 | |||
| 207 | 208 | ||
| 208 | config SND_SOC_EUKREA_TLV320 | 209 | config SND_SOC_EUKREA_TLV320 |
| 209 | tristate "Eukrea TLV320" | 210 | tristate "Eukrea TLV320" |
| 210 | depends on MACH_EUKREA_MBIMX27_BASEBOARD \ | 211 | depends on ARCH_MXC && I2C |
| 211 | || MACH_EUKREA_MBIMXSD25_BASEBOARD \ | ||
| 212 | || MACH_EUKREA_MBIMXSD35_BASEBOARD \ | ||
| 213 | || MACH_EUKREA_MBIMXSD51_BASEBOARD \ | ||
| 214 | || (OF && ARM) | ||
| 215 | depends on I2C | ||
| 216 | select SND_SOC_TLV320AIC23_I2C | 212 | select SND_SOC_TLV320AIC23_I2C |
| 217 | select SND_SOC_IMX_AUDMUX | 213 | select SND_SOC_IMX_AUDMUX |
| 218 | select SND_SOC_IMX_SSI | 214 | select SND_SOC_IMX_SSI |
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index f233d915b7e4..9bfef55d77d1 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c | |||
| @@ -54,25 +54,6 @@ | |||
| 54 | #include "fsl_ssi.h" | 54 | #include "fsl_ssi.h" |
| 55 | #include "imx-pcm.h" | 55 | #include "imx-pcm.h" |
| 56 | 56 | ||
| 57 | #ifdef PPC | ||
| 58 | #define read_ssi(addr) in_be32(addr) | ||
| 59 | #define write_ssi(val, addr) out_be32(addr, val) | ||
| 60 | #define write_ssi_mask(addr, clear, set) clrsetbits_be32(addr, clear, set) | ||
| 61 | #else | ||
| 62 | #define read_ssi(addr) readl(addr) | ||
| 63 | #define write_ssi(val, addr) writel(val, addr) | ||
| 64 | /* | ||
| 65 | * FIXME: Proper locking should be added at write_ssi_mask caller level | ||
| 66 | * to ensure this register read/modify/write sequence is race free. | ||
| 67 | */ | ||
| 68 | static inline void write_ssi_mask(u32 __iomem *addr, u32 clear, u32 set) | ||
| 69 | { | ||
| 70 | u32 val = readl(addr); | ||
| 71 | val = (val & ~clear) | set; | ||
| 72 | writel(val, addr); | ||
| 73 | } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | /** | 57 | /** |
| 77 | * FSLSSI_I2S_RATES: sample rates supported by the I2S | 58 | * FSLSSI_I2S_RATES: sample rates supported by the I2S |
| 78 | * | 59 | * |
| @@ -132,72 +113,86 @@ struct fsl_ssi_rxtx_reg_val { | |||
| 132 | struct fsl_ssi_reg_val rx; | 113 | struct fsl_ssi_reg_val rx; |
| 133 | struct fsl_ssi_reg_val tx; | 114 | struct fsl_ssi_reg_val tx; |
| 134 | }; | 115 | }; |
| 116 | static const struct regmap_config fsl_ssi_regconfig = { | ||
| 117 | .max_register = CCSR_SSI_SACCDIS, | ||
| 118 | .reg_bits = 32, | ||
| 119 | .val_bits = 32, | ||
| 120 | .reg_stride = 4, | ||
| 121 | .val_format_endian = REGMAP_ENDIAN_NATIVE, | ||
| 122 | }; | ||
| 123 | |||
| 124 | struct fsl_ssi_soc_data { | ||
| 125 | bool imx; | ||
| 126 | bool offline_config; | ||
| 127 | u32 sisr_write_mask; | ||
| 128 | }; | ||
| 135 | 129 | ||
| 136 | /** | 130 | /** |
| 137 | * fsl_ssi_private: per-SSI private data | 131 | * fsl_ssi_private: per-SSI private data |
| 138 | * | 132 | * |
| 139 | * @ssi: pointer to the SSI's registers | 133 | * @reg: Pointer to the regmap registers |
| 140 | * @ssi_phys: physical address of the SSI registers | ||
| 141 | * @irq: IRQ of this SSI | 134 | * @irq: IRQ of this SSI |
| 142 | * @playback: the number of playback streams opened | 135 | * @cpu_dai_drv: CPU DAI driver for this device |
| 143 | * @capture: the number of capture streams opened | 136 | * |
| 144 | * @cpu_dai: the CPU DAI for this device | 137 | * @dai_fmt: DAI configuration this device is currently used with |
| 145 | * @dev_attr: the sysfs device attribute structure | 138 | * @i2s_mode: i2s and network mode configuration of the device. Is used to |
| 146 | * @stats: SSI statistics | 139 | * switch between normal and i2s/network mode |
| 140 | * mode depending on the number of channels | ||
| 141 | * @use_dma: DMA is used or FIQ with stream filter | ||
| 142 | * @use_dual_fifo: DMA with support for both FIFOs used | ||
| 143 | * @fifo_deph: Depth of the SSI FIFOs | ||
| 144 | * @rxtx_reg_val: Specific register settings for receive/transmit configuration | ||
| 145 | * | ||
| 146 | * @clk: SSI clock | ||
| 147 | * @baudclk: SSI baud clock for master mode | ||
| 148 | * @baudclk_streams: Active streams that are using baudclk | ||
| 149 | * @bitclk_freq: bitclock frequency set by .set_dai_sysclk | ||
| 150 | * | ||
| 151 | * @dma_params_tx: DMA transmit parameters | ||
| 152 | * @dma_params_rx: DMA receive parameters | ||
| 153 | * @ssi_phys: physical address of the SSI registers | ||
| 154 | * | ||
| 155 | * @fiq_params: FIQ stream filtering parameters | ||
| 156 | * | ||
| 157 | * @pdev: Pointer to pdev used for deprecated fsl-ssi sound card | ||
| 158 | * | ||
| 159 | * @dbg_stats: Debugging statistics | ||
| 160 | * | ||
| 161 | * @soc: SoC specifc data | ||
| 147 | */ | 162 | */ |
| 148 | struct fsl_ssi_private { | 163 | struct fsl_ssi_private { |
| 149 | struct ccsr_ssi __iomem *ssi; | 164 | struct regmap *regs; |
| 150 | dma_addr_t ssi_phys; | ||
| 151 | unsigned int irq; | 165 | unsigned int irq; |
| 152 | unsigned int fifo_depth; | ||
| 153 | struct snd_soc_dai_driver cpu_dai_drv; | 166 | struct snd_soc_dai_driver cpu_dai_drv; |
| 154 | struct platform_device *pdev; | ||
| 155 | unsigned int dai_fmt; | ||
| 156 | 167 | ||
| 157 | enum fsl_ssi_type hw_type; | 168 | unsigned int dai_fmt; |
| 169 | u8 i2s_mode; | ||
| 158 | bool use_dma; | 170 | bool use_dma; |
| 159 | bool baudclk_locked; | ||
| 160 | bool use_dual_fifo; | 171 | bool use_dual_fifo; |
| 161 | u8 i2s_mode; | 172 | unsigned int fifo_depth; |
| 162 | spinlock_t baudclk_lock; | 173 | struct fsl_ssi_rxtx_reg_val rxtx_reg_val; |
| 163 | struct clk *baudclk; | 174 | |
| 164 | struct clk *clk; | 175 | struct clk *clk; |
| 176 | struct clk *baudclk; | ||
| 177 | unsigned int baudclk_streams; | ||
| 178 | unsigned int bitclk_freq; | ||
| 179 | |||
| 180 | /* DMA params */ | ||
| 165 | struct snd_dmaengine_dai_dma_data dma_params_tx; | 181 | struct snd_dmaengine_dai_dma_data dma_params_tx; |
| 166 | struct snd_dmaengine_dai_dma_data dma_params_rx; | 182 | struct snd_dmaengine_dai_dma_data dma_params_rx; |
| 183 | dma_addr_t ssi_phys; | ||
| 184 | |||
| 185 | /* params for non-dma FIQ stream filtered mode */ | ||
| 167 | struct imx_pcm_fiq_params fiq_params; | 186 | struct imx_pcm_fiq_params fiq_params; |
| 168 | /* Register values for rx/tx configuration */ | 187 | |
| 169 | struct fsl_ssi_rxtx_reg_val rxtx_reg_val; | 188 | /* Used when using fsl-ssi as sound-card. This is only used by ppc and |
| 189 | * should be replaced with simple-sound-card. */ | ||
| 190 | struct platform_device *pdev; | ||
| 170 | 191 | ||
| 171 | struct fsl_ssi_dbg dbg_stats; | 192 | struct fsl_ssi_dbg dbg_stats; |
| 172 | }; | ||
| 173 | 193 | ||
| 174 | static const struct of_device_id fsl_ssi_ids[] = { | 194 | const struct fsl_ssi_soc_data *soc; |
| 175 | { .compatible = "fsl,mpc8610-ssi", .data = (void *) FSL_SSI_MCP8610}, | ||
| 176 | { .compatible = "fsl,imx51-ssi", .data = (void *) FSL_SSI_MX51}, | ||
| 177 | { .compatible = "fsl,imx35-ssi", .data = (void *) FSL_SSI_MX35}, | ||
| 178 | { .compatible = "fsl,imx21-ssi", .data = (void *) FSL_SSI_MX21}, | ||
| 179 | {} | ||
| 180 | }; | 195 | }; |
| 181 | MODULE_DEVICE_TABLE(of, fsl_ssi_ids); | ||
| 182 | |||
| 183 | static bool fsl_ssi_is_ac97(struct fsl_ssi_private *ssi_private) | ||
| 184 | { | ||
| 185 | return !!(ssi_private->dai_fmt & SND_SOC_DAIFMT_AC97); | ||
| 186 | } | ||
| 187 | |||
| 188 | static bool fsl_ssi_on_imx(struct fsl_ssi_private *ssi_private) | ||
| 189 | { | ||
| 190 | switch (ssi_private->hw_type) { | ||
| 191 | case FSL_SSI_MX21: | ||
| 192 | case FSL_SSI_MX35: | ||
| 193 | case FSL_SSI_MX51: | ||
| 194 | return true; | ||
| 195 | case FSL_SSI_MCP8610: | ||
| 196 | return false; | ||
| 197 | } | ||
| 198 | |||
| 199 | return false; | ||
| 200 | } | ||
| 201 | 196 | ||
| 202 | /* | 197 | /* |
| 203 | * imx51 and later SoCs have a slightly different IP that allows the | 198 | * imx51 and later SoCs have a slightly different IP that allows the |
| @@ -214,18 +209,54 @@ static bool fsl_ssi_on_imx(struct fsl_ssi_private *ssi_private) | |||
| 214 | * while the SSI unit is running (SSIEN). So we support the necessary | 209 | * while the SSI unit is running (SSIEN). So we support the necessary |
| 215 | * online configuration of fsl-ssi starting at imx51. | 210 | * online configuration of fsl-ssi starting at imx51. |
| 216 | */ | 211 | */ |
| 217 | static bool fsl_ssi_offline_config(struct fsl_ssi_private *ssi_private) | 212 | |
| 213 | static struct fsl_ssi_soc_data fsl_ssi_mpc8610 = { | ||
| 214 | .imx = false, | ||
| 215 | .offline_config = true, | ||
| 216 | .sisr_write_mask = CCSR_SSI_SISR_RFRC | CCSR_SSI_SISR_TFRC | | ||
| 217 | CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 | | ||
| 218 | CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1, | ||
| 219 | }; | ||
| 220 | |||
| 221 | static struct fsl_ssi_soc_data fsl_ssi_imx21 = { | ||
| 222 | .imx = true, | ||
| 223 | .offline_config = true, | ||
| 224 | .sisr_write_mask = 0, | ||
| 225 | }; | ||
| 226 | |||
| 227 | static struct fsl_ssi_soc_data fsl_ssi_imx35 = { | ||
| 228 | .imx = true, | ||
| 229 | .offline_config = true, | ||
| 230 | .sisr_write_mask = CCSR_SSI_SISR_RFRC | CCSR_SSI_SISR_TFRC | | ||
| 231 | CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 | | ||
| 232 | CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1, | ||
| 233 | }; | ||
| 234 | |||
| 235 | static struct fsl_ssi_soc_data fsl_ssi_imx51 = { | ||
| 236 | .imx = true, | ||
| 237 | .offline_config = false, | ||
| 238 | .sisr_write_mask = CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 | | ||
| 239 | CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1, | ||
| 240 | }; | ||
| 241 | |||
| 242 | static const struct of_device_id fsl_ssi_ids[] = { | ||
| 243 | { .compatible = "fsl,mpc8610-ssi", .data = &fsl_ssi_mpc8610 }, | ||
| 244 | { .compatible = "fsl,imx51-ssi", .data = &fsl_ssi_imx51 }, | ||
| 245 | { .compatible = "fsl,imx35-ssi", .data = &fsl_ssi_imx35 }, | ||
| 246 | { .compatible = "fsl,imx21-ssi", .data = &fsl_ssi_imx21 }, | ||
| 247 | {} | ||
| 248 | }; | ||
| 249 | MODULE_DEVICE_TABLE(of, fsl_ssi_ids); | ||
| 250 | |||
| 251 | static bool fsl_ssi_is_ac97(struct fsl_ssi_private *ssi_private) | ||
| 218 | { | 252 | { |
| 219 | switch (ssi_private->hw_type) { | 253 | return !!(ssi_private->dai_fmt & SND_SOC_DAIFMT_AC97); |
| 220 | case FSL_SSI_MCP8610: | 254 | } |
| 221 | case FSL_SSI_MX21: | ||
| 222 | case FSL_SSI_MX35: | ||
| 223 | return true; | ||
| 224 | case FSL_SSI_MX51: | ||
| 225 | return false; | ||
| 226 | } | ||
| 227 | 255 | ||
| 228 | return true; | 256 | static bool fsl_ssi_is_i2s_master(struct fsl_ssi_private *ssi_private) |
| 257 | { | ||
| 258 | return (ssi_private->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) == | ||
| 259 | SND_SOC_DAIFMT_CBS_CFS; | ||
| 229 | } | 260 | } |
| 230 | 261 | ||
| 231 | /** | 262 | /** |
| @@ -243,39 +274,20 @@ static bool fsl_ssi_offline_config(struct fsl_ssi_private *ssi_private) | |||
| 243 | static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) | 274 | static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) |
| 244 | { | 275 | { |
| 245 | struct fsl_ssi_private *ssi_private = dev_id; | 276 | struct fsl_ssi_private *ssi_private = dev_id; |
| 246 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 277 | struct regmap *regs = ssi_private->regs; |
| 247 | __be32 sisr; | 278 | __be32 sisr; |
| 248 | __be32 sisr2; | 279 | __be32 sisr2; |
| 249 | __be32 sisr_write_mask = 0; | ||
| 250 | |||
| 251 | switch (ssi_private->hw_type) { | ||
| 252 | case FSL_SSI_MX21: | ||
| 253 | sisr_write_mask = 0; | ||
| 254 | break; | ||
| 255 | |||
| 256 | case FSL_SSI_MCP8610: | ||
| 257 | case FSL_SSI_MX35: | ||
| 258 | sisr_write_mask = CCSR_SSI_SISR_RFRC | CCSR_SSI_SISR_TFRC | | ||
| 259 | CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 | | ||
| 260 | CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1; | ||
| 261 | break; | ||
| 262 | |||
| 263 | case FSL_SSI_MX51: | ||
| 264 | sisr_write_mask = CCSR_SSI_SISR_ROE0 | CCSR_SSI_SISR_ROE1 | | ||
| 265 | CCSR_SSI_SISR_TUE0 | CCSR_SSI_SISR_TUE1; | ||
| 266 | break; | ||
| 267 | } | ||
| 268 | 280 | ||
| 269 | /* We got an interrupt, so read the status register to see what we | 281 | /* We got an interrupt, so read the status register to see what we |
| 270 | were interrupted for. We mask it with the Interrupt Enable register | 282 | were interrupted for. We mask it with the Interrupt Enable register |
| 271 | so that we only check for events that we're interested in. | 283 | so that we only check for events that we're interested in. |
| 272 | */ | 284 | */ |
| 273 | sisr = read_ssi(&ssi->sisr); | 285 | regmap_read(regs, CCSR_SSI_SISR, &sisr); |
| 274 | 286 | ||
| 275 | sisr2 = sisr & sisr_write_mask; | 287 | sisr2 = sisr & ssi_private->soc->sisr_write_mask; |
| 276 | /* Clear the bits that we set */ | 288 | /* Clear the bits that we set */ |
| 277 | if (sisr2) | 289 | if (sisr2) |
| 278 | write_ssi(sisr2, &ssi->sisr); | 290 | regmap_write(regs, CCSR_SSI_SISR, sisr2); |
| 279 | 291 | ||
| 280 | fsl_ssi_dbg_isr(&ssi_private->dbg_stats, sisr); | 292 | fsl_ssi_dbg_isr(&ssi_private->dbg_stats, sisr); |
| 281 | 293 | ||
| @@ -288,17 +300,26 @@ static irqreturn_t fsl_ssi_isr(int irq, void *dev_id) | |||
| 288 | static void fsl_ssi_rxtx_config(struct fsl_ssi_private *ssi_private, | 300 | static void fsl_ssi_rxtx_config(struct fsl_ssi_private *ssi_private, |
| 289 | bool enable) | 301 | bool enable) |
| 290 | { | 302 | { |
| 291 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 303 | struct regmap *regs = ssi_private->regs; |
| 292 | struct fsl_ssi_rxtx_reg_val *vals = &ssi_private->rxtx_reg_val; | 304 | struct fsl_ssi_rxtx_reg_val *vals = &ssi_private->rxtx_reg_val; |
| 293 | 305 | ||
| 294 | if (enable) { | 306 | if (enable) { |
| 295 | write_ssi_mask(&ssi->sier, 0, vals->rx.sier | vals->tx.sier); | 307 | regmap_update_bits(regs, CCSR_SSI_SIER, |
| 296 | write_ssi_mask(&ssi->srcr, 0, vals->rx.srcr | vals->tx.srcr); | 308 | vals->rx.sier | vals->tx.sier, |
| 297 | write_ssi_mask(&ssi->stcr, 0, vals->rx.stcr | vals->tx.stcr); | 309 | vals->rx.sier | vals->tx.sier); |
| 310 | regmap_update_bits(regs, CCSR_SSI_SRCR, | ||
| 311 | vals->rx.srcr | vals->tx.srcr, | ||
| 312 | vals->rx.srcr | vals->tx.srcr); | ||
| 313 | regmap_update_bits(regs, CCSR_SSI_STCR, | ||
| 314 | vals->rx.stcr | vals->tx.stcr, | ||
| 315 | vals->rx.stcr | vals->tx.stcr); | ||
| 298 | } else { | 316 | } else { |
| 299 | write_ssi_mask(&ssi->srcr, vals->rx.srcr | vals->tx.srcr, 0); | 317 | regmap_update_bits(regs, CCSR_SSI_SRCR, |
| 300 | write_ssi_mask(&ssi->stcr, vals->rx.stcr | vals->tx.stcr, 0); | 318 | vals->rx.srcr | vals->tx.srcr, 0); |
| 301 | write_ssi_mask(&ssi->sier, vals->rx.sier | vals->tx.sier, 0); | 319 | regmap_update_bits(regs, CCSR_SSI_STCR, |
| 320 | vals->rx.stcr | vals->tx.stcr, 0); | ||
| 321 | regmap_update_bits(regs, CCSR_SSI_SIER, | ||
| 322 | vals->rx.sier | vals->tx.sier, 0); | ||
| 302 | } | 323 | } |
| 303 | } | 324 | } |
| 304 | 325 | ||
| @@ -329,13 +350,17 @@ static void fsl_ssi_rxtx_config(struct fsl_ssi_private *ssi_private, | |||
| 329 | static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, | 350 | static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, |
| 330 | struct fsl_ssi_reg_val *vals) | 351 | struct fsl_ssi_reg_val *vals) |
| 331 | { | 352 | { |
| 332 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 353 | struct regmap *regs = ssi_private->regs; |
| 333 | struct fsl_ssi_reg_val *avals; | 354 | struct fsl_ssi_reg_val *avals; |
| 334 | u32 scr_val = read_ssi(&ssi->scr); | 355 | int nr_active_streams; |
| 335 | int nr_active_streams = !!(scr_val & CCSR_SSI_SCR_TE) + | 356 | u32 scr_val; |
| 336 | !!(scr_val & CCSR_SSI_SCR_RE); | ||
| 337 | int keep_active; | 357 | int keep_active; |
| 338 | 358 | ||
| 359 | regmap_read(regs, CCSR_SSI_SCR, &scr_val); | ||
| 360 | |||
| 361 | nr_active_streams = !!(scr_val & CCSR_SSI_SCR_TE) + | ||
| 362 | !!(scr_val & CCSR_SSI_SCR_RE); | ||
| 363 | |||
| 339 | if (nr_active_streams - 1 > 0) | 364 | if (nr_active_streams - 1 > 0) |
| 340 | keep_active = 1; | 365 | keep_active = 1; |
| 341 | else | 366 | else |
| @@ -352,7 +377,7 @@ static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, | |||
| 352 | if (!enable) { | 377 | if (!enable) { |
| 353 | u32 scr = fsl_ssi_disable_val(vals->scr, avals->scr, | 378 | u32 scr = fsl_ssi_disable_val(vals->scr, avals->scr, |
| 354 | keep_active); | 379 | keep_active); |
| 355 | write_ssi_mask(&ssi->scr, scr, 0); | 380 | regmap_update_bits(regs, CCSR_SSI_SCR, scr, 0); |
| 356 | } | 381 | } |
| 357 | 382 | ||
| 358 | /* | 383 | /* |
| @@ -360,7 +385,7 @@ static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, | |||
| 360 | * reconfiguration, so we have to enable all necessary flags at once | 385 | * reconfiguration, so we have to enable all necessary flags at once |
| 361 | * even if we do not use them later (capture and playback configuration) | 386 | * even if we do not use them later (capture and playback configuration) |
| 362 | */ | 387 | */ |
| 363 | if (fsl_ssi_offline_config(ssi_private)) { | 388 | if (ssi_private->soc->offline_config) { |
| 364 | if ((enable && !nr_active_streams) || | 389 | if ((enable && !nr_active_streams) || |
| 365 | (!enable && !keep_active)) | 390 | (!enable && !keep_active)) |
| 366 | fsl_ssi_rxtx_config(ssi_private, enable); | 391 | fsl_ssi_rxtx_config(ssi_private, enable); |
| @@ -373,9 +398,9 @@ static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, | |||
| 373 | * (online configuration) | 398 | * (online configuration) |
| 374 | */ | 399 | */ |
| 375 | if (enable) { | 400 | if (enable) { |
| 376 | write_ssi_mask(&ssi->sier, 0, vals->sier); | 401 | regmap_update_bits(regs, CCSR_SSI_SIER, vals->sier, vals->sier); |
| 377 | write_ssi_mask(&ssi->srcr, 0, vals->srcr); | 402 | regmap_update_bits(regs, CCSR_SSI_SRCR, vals->srcr, vals->srcr); |
| 378 | write_ssi_mask(&ssi->stcr, 0, vals->stcr); | 403 | regmap_update_bits(regs, CCSR_SSI_STCR, vals->stcr, vals->stcr); |
| 379 | } else { | 404 | } else { |
| 380 | u32 sier; | 405 | u32 sier; |
| 381 | u32 srcr; | 406 | u32 srcr; |
| @@ -398,15 +423,15 @@ static void fsl_ssi_config(struct fsl_ssi_private *ssi_private, bool enable, | |||
| 398 | stcr = fsl_ssi_disable_val(vals->stcr, avals->stcr, | 423 | stcr = fsl_ssi_disable_val(vals->stcr, avals->stcr, |
| 399 | keep_active); | 424 | keep_active); |
| 400 | 425 | ||
| 401 | write_ssi_mask(&ssi->srcr, srcr, 0); | 426 | regmap_update_bits(regs, CCSR_SSI_SRCR, srcr, 0); |
| 402 | write_ssi_mask(&ssi->stcr, stcr, 0); | 427 | regmap_update_bits(regs, CCSR_SSI_STCR, stcr, 0); |
| 403 | write_ssi_mask(&ssi->sier, sier, 0); | 428 | regmap_update_bits(regs, CCSR_SSI_SIER, sier, 0); |
| 404 | } | 429 | } |
| 405 | 430 | ||
| 406 | config_done: | 431 | config_done: |
| 407 | /* Enabling of subunits is done after configuration */ | 432 | /* Enabling of subunits is done after configuration */ |
| 408 | if (enable) | 433 | if (enable) |
| 409 | write_ssi_mask(&ssi->scr, 0, vals->scr); | 434 | regmap_update_bits(regs, CCSR_SSI_SCR, vals->scr, vals->scr); |
| 410 | } | 435 | } |
| 411 | 436 | ||
| 412 | 437 | ||
| @@ -457,32 +482,33 @@ static void fsl_ssi_setup_reg_vals(struct fsl_ssi_private *ssi_private) | |||
| 457 | 482 | ||
| 458 | static void fsl_ssi_setup_ac97(struct fsl_ssi_private *ssi_private) | 483 | static void fsl_ssi_setup_ac97(struct fsl_ssi_private *ssi_private) |
| 459 | { | 484 | { |
| 460 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 485 | struct regmap *regs = ssi_private->regs; |
| 461 | 486 | ||
| 462 | /* | 487 | /* |
| 463 | * Setup the clock control register | 488 | * Setup the clock control register |
| 464 | */ | 489 | */ |
| 465 | write_ssi(CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13), | 490 | regmap_write(regs, CCSR_SSI_STCCR, |
| 466 | &ssi->stccr); | 491 | CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13)); |
| 467 | write_ssi(CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13), | 492 | regmap_write(regs, CCSR_SSI_SRCCR, |
| 468 | &ssi->srccr); | 493 | CCSR_SSI_SxCCR_WL(17) | CCSR_SSI_SxCCR_DC(13)); |
| 469 | 494 | ||
| 470 | /* | 495 | /* |
| 471 | * Enable AC97 mode and startup the SSI | 496 | * Enable AC97 mode and startup the SSI |
| 472 | */ | 497 | */ |
| 473 | write_ssi(CCSR_SSI_SACNT_AC97EN | CCSR_SSI_SACNT_FV, | 498 | regmap_write(regs, CCSR_SSI_SACNT, |
| 474 | &ssi->sacnt); | 499 | CCSR_SSI_SACNT_AC97EN | CCSR_SSI_SACNT_FV); |
| 475 | write_ssi(0xff, &ssi->saccdis); | 500 | regmap_write(regs, CCSR_SSI_SACCDIS, 0xff); |
| 476 | write_ssi(0x300, &ssi->saccen); | 501 | regmap_write(regs, CCSR_SSI_SACCEN, 0x300); |
| 477 | 502 | ||
| 478 | /* | 503 | /* |
| 479 | * Enable SSI, Transmit and Receive. AC97 has to communicate with the | 504 | * Enable SSI, Transmit and Receive. AC97 has to communicate with the |
| 480 | * codec before a stream is started. | 505 | * codec before a stream is started. |
| 481 | */ | 506 | */ |
| 482 | write_ssi_mask(&ssi->scr, 0, CCSR_SSI_SCR_SSIEN | | 507 | regmap_update_bits(regs, CCSR_SSI_SCR, |
| 483 | CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE); | 508 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE, |
| 509 | CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE); | ||
| 484 | 510 | ||
| 485 | write_ssi(CCSR_SSI_SOR_WAIT(3), &ssi->sor); | 511 | regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_WAIT(3)); |
| 486 | } | 512 | } |
| 487 | 513 | ||
| 488 | /** | 514 | /** |
| @@ -499,13 +525,6 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
| 499 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 525 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 500 | struct fsl_ssi_private *ssi_private = | 526 | struct fsl_ssi_private *ssi_private = |
| 501 | snd_soc_dai_get_drvdata(rtd->cpu_dai); | 527 | snd_soc_dai_get_drvdata(rtd->cpu_dai); |
| 502 | unsigned long flags; | ||
| 503 | |||
| 504 | if (!dai->active && !fsl_ssi_is_ac97(ssi_private)) { | ||
| 505 | spin_lock_irqsave(&ssi_private->baudclk_lock, flags); | ||
| 506 | ssi_private->baudclk_locked = false; | ||
| 507 | spin_unlock_irqrestore(&ssi_private->baudclk_lock, flags); | ||
| 508 | } | ||
| 509 | 528 | ||
| 510 | /* When using dual fifo mode, it is safer to ensure an even period | 529 | /* When using dual fifo mode, it is safer to ensure an even period |
| 511 | * size. If appearing to an odd number while DMA always starts its | 530 | * size. If appearing to an odd number while DMA always starts its |
| @@ -520,7 +539,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
| 520 | } | 539 | } |
| 521 | 540 | ||
| 522 | /** | 541 | /** |
| 523 | * fsl_ssi_set_dai_sysclk - configure Digital Audio Interface bit clock | 542 | * fsl_ssi_set_bclk - configure Digital Audio Interface bit clock |
| 524 | * | 543 | * |
| 525 | * Note: This function can be only called when using SSI as DAI master | 544 | * Note: This function can be only called when using SSI as DAI master |
| 526 | * | 545 | * |
| @@ -528,20 +547,31 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream, | |||
| 528 | * freq: Output BCLK frequency = samplerate * 32 (fixed) * channels | 547 | * freq: Output BCLK frequency = samplerate * 32 (fixed) * channels |
| 529 | * dir: SND_SOC_CLOCK_OUT -> TxBCLK, SND_SOC_CLOCK_IN -> RxBCLK. | 548 | * dir: SND_SOC_CLOCK_OUT -> TxBCLK, SND_SOC_CLOCK_IN -> RxBCLK. |
| 530 | */ | 549 | */ |
| 531 | static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | 550 | static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, |
| 532 | int clk_id, unsigned int freq, int dir) | 551 | struct snd_soc_dai *cpu_dai, |
| 552 | struct snd_pcm_hw_params *hw_params) | ||
| 533 | { | 553 | { |
| 534 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | 554 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); |
| 535 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 555 | struct regmap *regs = ssi_private->regs; |
| 536 | int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret; | 556 | int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret; |
| 537 | u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i; | 557 | u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i; |
| 538 | unsigned long flags, clkrate, baudrate, tmprate; | 558 | unsigned long clkrate, baudrate, tmprate; |
| 539 | u64 sub, savesub = 100000; | 559 | u64 sub, savesub = 100000; |
| 560 | unsigned int freq; | ||
| 561 | bool baudclk_is_used; | ||
| 562 | |||
| 563 | /* Prefer the explicitly set bitclock frequency */ | ||
| 564 | if (ssi_private->bitclk_freq) | ||
| 565 | freq = ssi_private->bitclk_freq; | ||
| 566 | else | ||
| 567 | freq = params_channels(hw_params) * 32 * params_rate(hw_params); | ||
| 540 | 568 | ||
| 541 | /* Don't apply it to any non-baudclk circumstance */ | 569 | /* Don't apply it to any non-baudclk circumstance */ |
| 542 | if (IS_ERR(ssi_private->baudclk)) | 570 | if (IS_ERR(ssi_private->baudclk)) |
| 543 | return -EINVAL; | 571 | return -EINVAL; |
| 544 | 572 | ||
| 573 | baudclk_is_used = ssi_private->baudclk_streams & ~(BIT(substream->stream)); | ||
| 574 | |||
| 545 | /* It should be already enough to divide clock by setting pm alone */ | 575 | /* It should be already enough to divide clock by setting pm alone */ |
| 546 | psr = 0; | 576 | psr = 0; |
| 547 | div2 = 0; | 577 | div2 = 0; |
| @@ -554,7 +584,11 @@ static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | |||
| 554 | continue; | 584 | continue; |
| 555 | 585 | ||
| 556 | tmprate = freq * factor * (i + 2); | 586 | tmprate = freq * factor * (i + 2); |
| 557 | clkrate = clk_round_rate(ssi_private->baudclk, tmprate); | 587 | |
| 588 | if (baudclk_is_used) | ||
| 589 | clkrate = clk_get_rate(ssi_private->baudclk); | ||
| 590 | else | ||
| 591 | clkrate = clk_round_rate(ssi_private->baudclk, tmprate); | ||
| 558 | 592 | ||
| 559 | do_div(clkrate, factor); | 593 | do_div(clkrate, factor); |
| 560 | afreq = (u32)clkrate / (i + 1); | 594 | afreq = (u32)clkrate / (i + 1); |
| @@ -594,23 +628,28 @@ static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | |||
| 594 | mask = CCSR_SSI_SxCCR_PM_MASK | CCSR_SSI_SxCCR_DIV2 | | 628 | mask = CCSR_SSI_SxCCR_PM_MASK | CCSR_SSI_SxCCR_DIV2 | |
| 595 | CCSR_SSI_SxCCR_PSR; | 629 | CCSR_SSI_SxCCR_PSR; |
| 596 | 630 | ||
| 597 | if (dir == SND_SOC_CLOCK_OUT || synchronous) | 631 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || synchronous) |
| 598 | write_ssi_mask(&ssi->stccr, mask, stccr); | 632 | regmap_update_bits(regs, CCSR_SSI_STCCR, mask, stccr); |
| 599 | else | 633 | else |
| 600 | write_ssi_mask(&ssi->srccr, mask, stccr); | 634 | regmap_update_bits(regs, CCSR_SSI_SRCCR, mask, stccr); |
| 601 | 635 | ||
| 602 | spin_lock_irqsave(&ssi_private->baudclk_lock, flags); | 636 | if (!baudclk_is_used) { |
| 603 | if (!ssi_private->baudclk_locked) { | ||
| 604 | ret = clk_set_rate(ssi_private->baudclk, baudrate); | 637 | ret = clk_set_rate(ssi_private->baudclk, baudrate); |
| 605 | if (ret) { | 638 | if (ret) { |
| 606 | spin_unlock_irqrestore(&ssi_private->baudclk_lock, | ||
| 607 | flags); | ||
| 608 | dev_err(cpu_dai->dev, "failed to set baudclk rate\n"); | 639 | dev_err(cpu_dai->dev, "failed to set baudclk rate\n"); |
| 609 | return -EINVAL; | 640 | return -EINVAL; |
| 610 | } | 641 | } |
| 611 | ssi_private->baudclk_locked = true; | ||
| 612 | } | 642 | } |
| 613 | spin_unlock_irqrestore(&ssi_private->baudclk_lock, flags); | 643 | |
| 644 | return 0; | ||
| 645 | } | ||
| 646 | |||
| 647 | static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | ||
| 648 | int clk_id, unsigned int freq, int dir) | ||
| 649 | { | ||
| 650 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | ||
| 651 | |||
| 652 | ssi_private->bitclk_freq = freq; | ||
| 614 | 653 | ||
| 615 | return 0; | 654 | return 0; |
| 616 | } | 655 | } |
| @@ -632,12 +671,17 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream, | |||
| 632 | struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai) | 671 | struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai) |
| 633 | { | 672 | { |
| 634 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | 673 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); |
| 635 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 674 | struct regmap *regs = ssi_private->regs; |
| 636 | unsigned int channels = params_channels(hw_params); | 675 | unsigned int channels = params_channels(hw_params); |
| 637 | unsigned int sample_size = | 676 | unsigned int sample_size = |
| 638 | snd_pcm_format_width(params_format(hw_params)); | 677 | snd_pcm_format_width(params_format(hw_params)); |
| 639 | u32 wl = CCSR_SSI_SxCCR_WL(sample_size); | 678 | u32 wl = CCSR_SSI_SxCCR_WL(sample_size); |
| 640 | int enabled = read_ssi(&ssi->scr) & CCSR_SSI_SCR_SSIEN; | 679 | int ret; |
| 680 | u32 scr_val; | ||
| 681 | int enabled; | ||
| 682 | |||
| 683 | regmap_read(regs, CCSR_SSI_SCR, &scr_val); | ||
| 684 | enabled = scr_val & CCSR_SSI_SCR_SSIEN; | ||
| 641 | 685 | ||
| 642 | /* | 686 | /* |
| 643 | * If we're in synchronous mode, and the SSI is already enabled, | 687 | * If we're in synchronous mode, and the SSI is already enabled, |
| @@ -646,6 +690,21 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream, | |||
| 646 | if (enabled && ssi_private->cpu_dai_drv.symmetric_rates) | 690 | if (enabled && ssi_private->cpu_dai_drv.symmetric_rates) |
| 647 | return 0; | 691 | return 0; |
| 648 | 692 | ||
| 693 | if (fsl_ssi_is_i2s_master(ssi_private)) { | ||
| 694 | ret = fsl_ssi_set_bclk(substream, cpu_dai, hw_params); | ||
| 695 | if (ret) | ||
| 696 | return ret; | ||
| 697 | |||
| 698 | /* Do not enable the clock if it is already enabled */ | ||
| 699 | if (!(ssi_private->baudclk_streams & BIT(substream->stream))) { | ||
| 700 | ret = clk_prepare_enable(ssi_private->baudclk); | ||
| 701 | if (ret) | ||
| 702 | return ret; | ||
| 703 | |||
| 704 | ssi_private->baudclk_streams |= BIT(substream->stream); | ||
| 705 | } | ||
| 706 | } | ||
| 707 | |||
| 649 | /* | 708 | /* |
| 650 | * FIXME: The documentation says that SxCCR[WL] should not be | 709 | * FIXME: The documentation says that SxCCR[WL] should not be |
| 651 | * modified while the SSI is enabled. The only time this can | 710 | * modified while the SSI is enabled. The only time this can |
| @@ -659,40 +718,63 @@ static int fsl_ssi_hw_params(struct snd_pcm_substream *substream, | |||
| 659 | /* In synchronous mode, the SSI uses STCCR for capture */ | 718 | /* In synchronous mode, the SSI uses STCCR for capture */ |
| 660 | if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) || | 719 | if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) || |
| 661 | ssi_private->cpu_dai_drv.symmetric_rates) | 720 | ssi_private->cpu_dai_drv.symmetric_rates) |
| 662 | write_ssi_mask(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); | 721 | regmap_update_bits(regs, CCSR_SSI_STCCR, CCSR_SSI_SxCCR_WL_MASK, |
| 722 | wl); | ||
| 663 | else | 723 | else |
| 664 | write_ssi_mask(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl); | 724 | regmap_update_bits(regs, CCSR_SSI_SRCCR, CCSR_SSI_SxCCR_WL_MASK, |
| 725 | wl); | ||
| 665 | 726 | ||
| 666 | if (!fsl_ssi_is_ac97(ssi_private)) | 727 | if (!fsl_ssi_is_ac97(ssi_private)) |
| 667 | write_ssi_mask(&ssi->scr, | 728 | regmap_update_bits(regs, CCSR_SSI_SCR, |
| 668 | CCSR_SSI_SCR_NET | CCSR_SSI_SCR_I2S_MODE_MASK, | 729 | CCSR_SSI_SCR_NET | CCSR_SSI_SCR_I2S_MODE_MASK, |
| 669 | channels == 1 ? 0 : ssi_private->i2s_mode); | 730 | channels == 1 ? 0 : ssi_private->i2s_mode); |
| 670 | 731 | ||
| 671 | return 0; | 732 | return 0; |
| 672 | } | 733 | } |
| 673 | 734 | ||
| 674 | /** | 735 | static int fsl_ssi_hw_free(struct snd_pcm_substream *substream, |
| 675 | * fsl_ssi_set_dai_fmt - configure Digital Audio Interface Format. | 736 | struct snd_soc_dai *cpu_dai) |
| 676 | */ | ||
| 677 | static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | ||
| 678 | { | 737 | { |
| 679 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | 738 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 680 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 739 | struct fsl_ssi_private *ssi_private = |
| 740 | snd_soc_dai_get_drvdata(rtd->cpu_dai); | ||
| 741 | |||
| 742 | if (fsl_ssi_is_i2s_master(ssi_private) && | ||
| 743 | ssi_private->baudclk_streams & BIT(substream->stream)) { | ||
| 744 | clk_disable_unprepare(ssi_private->baudclk); | ||
| 745 | ssi_private->baudclk_streams &= ~BIT(substream->stream); | ||
| 746 | } | ||
| 747 | |||
| 748 | return 0; | ||
| 749 | } | ||
| 750 | |||
| 751 | static int _fsl_ssi_set_dai_fmt(struct fsl_ssi_private *ssi_private, | ||
| 752 | unsigned int fmt) | ||
| 753 | { | ||
| 754 | struct regmap *regs = ssi_private->regs; | ||
| 681 | u32 strcr = 0, stcr, srcr, scr, mask; | 755 | u32 strcr = 0, stcr, srcr, scr, mask; |
| 682 | u8 wm; | 756 | u8 wm; |
| 683 | 757 | ||
| 684 | ssi_private->dai_fmt = fmt; | 758 | ssi_private->dai_fmt = fmt; |
| 685 | 759 | ||
| 760 | if (fsl_ssi_is_i2s_master(ssi_private) && IS_ERR(ssi_private->baudclk)) { | ||
| 761 | dev_err(&ssi_private->pdev->dev, "baudclk is missing which is necessary for master mode\n"); | ||
| 762 | return -EINVAL; | ||
| 763 | } | ||
| 764 | |||
| 686 | fsl_ssi_setup_reg_vals(ssi_private); | 765 | fsl_ssi_setup_reg_vals(ssi_private); |
| 687 | 766 | ||
| 688 | scr = read_ssi(&ssi->scr) & ~(CCSR_SSI_SCR_SYN | CCSR_SSI_SCR_I2S_MODE_MASK); | 767 | regmap_read(regs, CCSR_SSI_SCR, &scr); |
| 768 | scr &= ~(CCSR_SSI_SCR_SYN | CCSR_SSI_SCR_I2S_MODE_MASK); | ||
| 689 | scr |= CCSR_SSI_SCR_SYNC_TX_FS; | 769 | scr |= CCSR_SSI_SCR_SYNC_TX_FS; |
| 690 | 770 | ||
| 691 | mask = CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFDIR | CCSR_SSI_STCR_TXDIR | | 771 | mask = CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFDIR | CCSR_SSI_STCR_TXDIR | |
| 692 | CCSR_SSI_STCR_TSCKP | CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TFSL | | 772 | CCSR_SSI_STCR_TSCKP | CCSR_SSI_STCR_TFSI | CCSR_SSI_STCR_TFSL | |
| 693 | CCSR_SSI_STCR_TEFS; | 773 | CCSR_SSI_STCR_TEFS; |
| 694 | stcr = read_ssi(&ssi->stcr) & ~mask; | 774 | regmap_read(regs, CCSR_SSI_STCR, &stcr); |
| 695 | srcr = read_ssi(&ssi->srcr) & ~mask; | 775 | regmap_read(regs, CCSR_SSI_SRCR, &srcr); |
| 776 | stcr &= ~mask; | ||
| 777 | srcr &= ~mask; | ||
| 696 | 778 | ||
| 697 | ssi_private->i2s_mode = CCSR_SSI_SCR_NET; | 779 | ssi_private->i2s_mode = CCSR_SSI_SCR_NET; |
| 698 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | 780 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| @@ -700,6 +782,12 @@ static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | |||
| 700 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 782 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 701 | case SND_SOC_DAIFMT_CBS_CFS: | 783 | case SND_SOC_DAIFMT_CBS_CFS: |
| 702 | ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_MASTER; | 784 | ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_MASTER; |
| 785 | regmap_update_bits(regs, CCSR_SSI_STCCR, | ||
| 786 | CCSR_SSI_SxCCR_DC_MASK, | ||
| 787 | CCSR_SSI_SxCCR_DC(2)); | ||
| 788 | regmap_update_bits(regs, CCSR_SSI_SRCCR, | ||
| 789 | CCSR_SSI_SxCCR_DC_MASK, | ||
| 790 | CCSR_SSI_SxCCR_DC(2)); | ||
| 703 | break; | 791 | break; |
| 704 | case SND_SOC_DAIFMT_CBM_CFM: | 792 | case SND_SOC_DAIFMT_CBM_CFM: |
| 705 | ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_SLAVE; | 793 | ssi_private->i2s_mode |= CCSR_SSI_SCR_I2S_MODE_SLAVE; |
| @@ -778,9 +866,9 @@ static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | |||
| 778 | scr |= CCSR_SSI_SCR_SYN; | 866 | scr |= CCSR_SSI_SCR_SYN; |
| 779 | } | 867 | } |
| 780 | 868 | ||
| 781 | write_ssi(stcr, &ssi->stcr); | 869 | regmap_write(regs, CCSR_SSI_STCR, stcr); |
| 782 | write_ssi(srcr, &ssi->srcr); | 870 | regmap_write(regs, CCSR_SSI_SRCR, srcr); |
| 783 | write_ssi(scr, &ssi->scr); | 871 | regmap_write(regs, CCSR_SSI_SCR, scr); |
| 784 | 872 | ||
| 785 | /* | 873 | /* |
| 786 | * Set the watermark for transmit FIFI 0 and receive FIFO 0. We don't | 874 | * Set the watermark for transmit FIFI 0 and receive FIFO 0. We don't |
| @@ -798,16 +886,16 @@ static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | |||
| 798 | else | 886 | else |
| 799 | wm = ssi_private->fifo_depth; | 887 | wm = ssi_private->fifo_depth; |
| 800 | 888 | ||
| 801 | write_ssi(CCSR_SSI_SFCSR_TFWM0(wm) | CCSR_SSI_SFCSR_RFWM0(wm) | | 889 | regmap_write(regs, CCSR_SSI_SFCSR, |
| 802 | CCSR_SSI_SFCSR_TFWM1(wm) | CCSR_SSI_SFCSR_RFWM1(wm), | 890 | CCSR_SSI_SFCSR_TFWM0(wm) | CCSR_SSI_SFCSR_RFWM0(wm) | |
| 803 | &ssi->sfcsr); | 891 | CCSR_SSI_SFCSR_TFWM1(wm) | CCSR_SSI_SFCSR_RFWM1(wm)); |
| 804 | 892 | ||
| 805 | if (ssi_private->use_dual_fifo) { | 893 | if (ssi_private->use_dual_fifo) { |
| 806 | write_ssi_mask(&ssi->srcr, CCSR_SSI_SRCR_RFEN1, | 894 | regmap_update_bits(regs, CCSR_SSI_SRCR, CCSR_SSI_SRCR_RFEN1, |
| 807 | CCSR_SSI_SRCR_RFEN1); | 895 | CCSR_SSI_SRCR_RFEN1); |
| 808 | write_ssi_mask(&ssi->stcr, CCSR_SSI_STCR_TFEN1, | 896 | regmap_update_bits(regs, CCSR_SSI_STCR, CCSR_SSI_STCR_TFEN1, |
| 809 | CCSR_SSI_STCR_TFEN1); | 897 | CCSR_SSI_STCR_TFEN1); |
| 810 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_TCH_EN, | 898 | regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_TCH_EN, |
| 811 | CCSR_SSI_SCR_TCH_EN); | 899 | CCSR_SSI_SCR_TCH_EN); |
| 812 | } | 900 | } |
| 813 | 901 | ||
| @@ -815,6 +903,17 @@ static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | |||
| 815 | fsl_ssi_setup_ac97(ssi_private); | 903 | fsl_ssi_setup_ac97(ssi_private); |
| 816 | 904 | ||
| 817 | return 0; | 905 | return 0; |
| 906 | |||
| 907 | } | ||
| 908 | |||
| 909 | /** | ||
| 910 | * fsl_ssi_set_dai_fmt - configure Digital Audio Interface Format. | ||
| 911 | */ | ||
| 912 | static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | ||
| 913 | { | ||
| 914 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | ||
| 915 | |||
| 916 | return _fsl_ssi_set_dai_fmt(ssi_private, fmt); | ||
| 818 | } | 917 | } |
| 819 | 918 | ||
| 820 | /** | 919 | /** |
| @@ -826,31 +925,34 @@ static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask, | |||
| 826 | u32 rx_mask, int slots, int slot_width) | 925 | u32 rx_mask, int slots, int slot_width) |
| 827 | { | 926 | { |
| 828 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); | 927 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); |
| 829 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 928 | struct regmap *regs = ssi_private->regs; |
| 830 | u32 val; | 929 | u32 val; |
| 831 | 930 | ||
| 832 | /* The slot number should be >= 2 if using Network mode or I2S mode */ | 931 | /* The slot number should be >= 2 if using Network mode or I2S mode */ |
| 833 | val = read_ssi(&ssi->scr) & (CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_NET); | 932 | regmap_read(regs, CCSR_SSI_SCR, &val); |
| 933 | val &= CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_NET; | ||
| 834 | if (val && slots < 2) { | 934 | if (val && slots < 2) { |
| 835 | dev_err(cpu_dai->dev, "slot number should be >= 2 in I2S or NET\n"); | 935 | dev_err(cpu_dai->dev, "slot number should be >= 2 in I2S or NET\n"); |
| 836 | return -EINVAL; | 936 | return -EINVAL; |
| 837 | } | 937 | } |
| 838 | 938 | ||
| 839 | write_ssi_mask(&ssi->stccr, CCSR_SSI_SxCCR_DC_MASK, | 939 | regmap_update_bits(regs, CCSR_SSI_STCCR, CCSR_SSI_SxCCR_DC_MASK, |
| 840 | CCSR_SSI_SxCCR_DC(slots)); | 940 | CCSR_SSI_SxCCR_DC(slots)); |
| 841 | write_ssi_mask(&ssi->srccr, CCSR_SSI_SxCCR_DC_MASK, | 941 | regmap_update_bits(regs, CCSR_SSI_SRCCR, CCSR_SSI_SxCCR_DC_MASK, |
| 842 | CCSR_SSI_SxCCR_DC(slots)); | 942 | CCSR_SSI_SxCCR_DC(slots)); |
| 843 | 943 | ||
| 844 | /* The register SxMSKs needs SSI to provide essential clock due to | 944 | /* The register SxMSKs needs SSI to provide essential clock due to |
| 845 | * hardware design. So we here temporarily enable SSI to set them. | 945 | * hardware design. So we here temporarily enable SSI to set them. |
| 846 | */ | 946 | */ |
| 847 | val = read_ssi(&ssi->scr) & CCSR_SSI_SCR_SSIEN; | 947 | regmap_read(regs, CCSR_SSI_SCR, &val); |
| 848 | write_ssi_mask(&ssi->scr, 0, CCSR_SSI_SCR_SSIEN); | 948 | val &= CCSR_SSI_SCR_SSIEN; |
| 949 | regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, | ||
| 950 | CCSR_SSI_SCR_SSIEN); | ||
| 849 | 951 | ||
| 850 | write_ssi(tx_mask, &ssi->stmsk); | 952 | regmap_write(regs, CCSR_SSI_STMSK, tx_mask); |
| 851 | write_ssi(rx_mask, &ssi->srmsk); | 953 | regmap_write(regs, CCSR_SSI_SRMSK, rx_mask); |
| 852 | 954 | ||
| 853 | write_ssi_mask(&ssi->scr, CCSR_SSI_SCR_SSIEN, val); | 955 | regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val); |
| 854 | 956 | ||
| 855 | return 0; | 957 | return 0; |
| 856 | } | 958 | } |
| @@ -869,11 +971,11 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd, | |||
| 869 | { | 971 | { |
| 870 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 972 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 871 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai); | 973 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(rtd->cpu_dai); |
| 872 | struct ccsr_ssi __iomem *ssi = ssi_private->ssi; | 974 | struct regmap *regs = ssi_private->regs; |
| 873 | unsigned long flags; | ||
| 874 | 975 | ||
| 875 | switch (cmd) { | 976 | switch (cmd) { |
| 876 | case SNDRV_PCM_TRIGGER_START: | 977 | case SNDRV_PCM_TRIGGER_START: |
| 978 | case SNDRV_PCM_TRIGGER_RESUME: | ||
| 877 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 979 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 878 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 980 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 879 | fsl_ssi_tx_config(ssi_private, true); | 981 | fsl_ssi_tx_config(ssi_private, true); |
| @@ -882,18 +984,12 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd, | |||
| 882 | break; | 984 | break; |
| 883 | 985 | ||
| 884 | case SNDRV_PCM_TRIGGER_STOP: | 986 | case SNDRV_PCM_TRIGGER_STOP: |
| 987 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
| 885 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | 988 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 886 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 989 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 887 | fsl_ssi_tx_config(ssi_private, false); | 990 | fsl_ssi_tx_config(ssi_private, false); |
| 888 | else | 991 | else |
| 889 | fsl_ssi_rx_config(ssi_private, false); | 992 | fsl_ssi_rx_config(ssi_private, false); |
| 890 | |||
| 891 | if (!fsl_ssi_is_ac97(ssi_private) && (read_ssi(&ssi->scr) & | ||
| 892 | (CCSR_SSI_SCR_TE | CCSR_SSI_SCR_RE)) == 0) { | ||
| 893 | spin_lock_irqsave(&ssi_private->baudclk_lock, flags); | ||
| 894 | ssi_private->baudclk_locked = false; | ||
| 895 | spin_unlock_irqrestore(&ssi_private->baudclk_lock, flags); | ||
| 896 | } | ||
| 897 | break; | 993 | break; |
| 898 | 994 | ||
| 899 | default: | 995 | default: |
| @@ -902,9 +998,9 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd, | |||
| 902 | 998 | ||
| 903 | if (fsl_ssi_is_ac97(ssi_private)) { | 999 | if (fsl_ssi_is_ac97(ssi_private)) { |
| 904 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 1000 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 905 | write_ssi(CCSR_SSI_SOR_TX_CLR, &ssi->sor); | 1001 | regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_TX_CLR); |
| 906 | else | 1002 | else |
| 907 | write_ssi(CCSR_SSI_SOR_RX_CLR, &ssi->sor); | 1003 | regmap_write(regs, CCSR_SSI_SOR, CCSR_SSI_SOR_RX_CLR); |
| 908 | } | 1004 | } |
| 909 | 1005 | ||
| 910 | return 0; | 1006 | return 0; |
| @@ -914,7 +1010,7 @@ static int fsl_ssi_dai_probe(struct snd_soc_dai *dai) | |||
| 914 | { | 1010 | { |
| 915 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(dai); | 1011 | struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(dai); |
| 916 | 1012 | ||
| 917 | if (fsl_ssi_on_imx(ssi_private) && ssi_private->use_dma) { | 1013 | if (ssi_private->soc->imx && ssi_private->use_dma) { |
| 918 | dai->playback_dma_data = &ssi_private->dma_params_tx; | 1014 | dai->playback_dma_data = &ssi_private->dma_params_tx; |
| 919 | dai->capture_dma_data = &ssi_private->dma_params_rx; | 1015 | dai->capture_dma_data = &ssi_private->dma_params_rx; |
| 920 | } | 1016 | } |
| @@ -925,6 +1021,7 @@ static int fsl_ssi_dai_probe(struct snd_soc_dai *dai) | |||
| 925 | static const struct snd_soc_dai_ops fsl_ssi_dai_ops = { | 1021 | static const struct snd_soc_dai_ops fsl_ssi_dai_ops = { |
| 926 | .startup = fsl_ssi_startup, | 1022 | .startup = fsl_ssi_startup, |
| 927 | .hw_params = fsl_ssi_hw_params, | 1023 | .hw_params = fsl_ssi_hw_params, |
| 1024 | .hw_free = fsl_ssi_hw_free, | ||
| 928 | .set_fmt = fsl_ssi_set_dai_fmt, | 1025 | .set_fmt = fsl_ssi_set_dai_fmt, |
| 929 | .set_sysclk = fsl_ssi_set_dai_sysclk, | 1026 | .set_sysclk = fsl_ssi_set_dai_sysclk, |
| 930 | .set_tdm_slot = fsl_ssi_set_dai_tdm_slot, | 1027 | .set_tdm_slot = fsl_ssi_set_dai_tdm_slot, |
| @@ -978,7 +1075,7 @@ static struct fsl_ssi_private *fsl_ac97_data; | |||
| 978 | static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, | 1075 | static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, |
| 979 | unsigned short val) | 1076 | unsigned short val) |
| 980 | { | 1077 | { |
| 981 | struct ccsr_ssi *ssi = fsl_ac97_data->ssi; | 1078 | struct regmap *regs = fsl_ac97_data->regs; |
| 982 | unsigned int lreg; | 1079 | unsigned int lreg; |
| 983 | unsigned int lval; | 1080 | unsigned int lval; |
| 984 | 1081 | ||
| @@ -987,12 +1084,12 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, | |||
| 987 | 1084 | ||
| 988 | 1085 | ||
| 989 | lreg = reg << 12; | 1086 | lreg = reg << 12; |
| 990 | write_ssi(lreg, &ssi->sacadd); | 1087 | regmap_write(regs, CCSR_SSI_SACADD, lreg); |
| 991 | 1088 | ||
| 992 | lval = val << 4; | 1089 | lval = val << 4; |
| 993 | write_ssi(lval , &ssi->sacdat); | 1090 | regmap_write(regs, CCSR_SSI_SACDAT, lval); |
| 994 | 1091 | ||
| 995 | write_ssi_mask(&ssi->sacnt, CCSR_SSI_SACNT_RDWR_MASK, | 1092 | regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK, |
| 996 | CCSR_SSI_SACNT_WR); | 1093 | CCSR_SSI_SACNT_WR); |
| 997 | udelay(100); | 1094 | udelay(100); |
| 998 | } | 1095 | } |
| @@ -1000,19 +1097,21 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg, | |||
| 1000 | static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97, | 1097 | static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97, |
| 1001 | unsigned short reg) | 1098 | unsigned short reg) |
| 1002 | { | 1099 | { |
| 1003 | struct ccsr_ssi *ssi = fsl_ac97_data->ssi; | 1100 | struct regmap *regs = fsl_ac97_data->regs; |
| 1004 | 1101 | ||
| 1005 | unsigned short val = -1; | 1102 | unsigned short val = -1; |
| 1103 | u32 reg_val; | ||
| 1006 | unsigned int lreg; | 1104 | unsigned int lreg; |
| 1007 | 1105 | ||
| 1008 | lreg = (reg & 0x7f) << 12; | 1106 | lreg = (reg & 0x7f) << 12; |
| 1009 | write_ssi(lreg, &ssi->sacadd); | 1107 | regmap_write(regs, CCSR_SSI_SACADD, lreg); |
| 1010 | write_ssi_mask(&ssi->sacnt, CCSR_SSI_SACNT_RDWR_MASK, | 1108 | regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK, |
| 1011 | CCSR_SSI_SACNT_RD); | 1109 | CCSR_SSI_SACNT_RD); |
| 1012 | 1110 | ||
| 1013 | udelay(100); | 1111 | udelay(100); |
| 1014 | 1112 | ||
| 1015 | val = (read_ssi(&ssi->sacdat) >> 4) & 0xffff; | 1113 | regmap_read(regs, CCSR_SSI_SACDAT, ®_val); |
| 1114 | val = (reg_val >> 4) & 0xffff; | ||
| 1016 | 1115 | ||
| 1017 | return val; | 1116 | return val; |
| 1018 | } | 1117 | } |
| @@ -1064,8 +1163,6 @@ static int fsl_ssi_imx_probe(struct platform_device *pdev, | |||
| 1064 | if (IS_ERR(ssi_private->baudclk)) | 1163 | if (IS_ERR(ssi_private->baudclk)) |
| 1065 | dev_dbg(&pdev->dev, "could not get baud clock: %ld\n", | 1164 | dev_dbg(&pdev->dev, "could not get baud clock: %ld\n", |
| 1066 | PTR_ERR(ssi_private->baudclk)); | 1165 | PTR_ERR(ssi_private->baudclk)); |
| 1067 | else | ||
| 1068 | clk_prepare_enable(ssi_private->baudclk); | ||
| 1069 | 1166 | ||
| 1070 | /* | 1167 | /* |
| 1071 | * We have burstsize be "fifo_depth - 2" to match the SSI | 1168 | * We have burstsize be "fifo_depth - 2" to match the SSI |
| @@ -1073,10 +1170,8 @@ static int fsl_ssi_imx_probe(struct platform_device *pdev, | |||
| 1073 | */ | 1170 | */ |
| 1074 | ssi_private->dma_params_tx.maxburst = ssi_private->fifo_depth - 2; | 1171 | ssi_private->dma_params_tx.maxburst = ssi_private->fifo_depth - 2; |
| 1075 | ssi_private->dma_params_rx.maxburst = ssi_private->fifo_depth - 2; | 1172 | ssi_private->dma_params_rx.maxburst = ssi_private->fifo_depth - 2; |
| 1076 | ssi_private->dma_params_tx.addr = ssi_private->ssi_phys + | 1173 | ssi_private->dma_params_tx.addr = ssi_private->ssi_phys + CCSR_SSI_STX0; |
| 1077 | offsetof(struct ccsr_ssi, stx0); | 1174 | ssi_private->dma_params_rx.addr = ssi_private->ssi_phys + CCSR_SSI_SRX0; |
| 1078 | ssi_private->dma_params_rx.addr = ssi_private->ssi_phys + | ||
| 1079 | offsetof(struct ccsr_ssi, srx0); | ||
| 1080 | 1175 | ||
| 1081 | ret = !of_property_read_u32_array(np, "dmas", dmas, 4); | 1176 | ret = !of_property_read_u32_array(np, "dmas", dmas, 4); |
| 1082 | if (ssi_private->use_dma && !ret && dmas[2] == IMX_DMATYPE_SSI_DUAL) { | 1177 | if (ssi_private->use_dma && !ret && dmas[2] == IMX_DMATYPE_SSI_DUAL) { |
| @@ -1116,9 +1211,6 @@ static int fsl_ssi_imx_probe(struct platform_device *pdev, | |||
| 1116 | return 0; | 1211 | return 0; |
| 1117 | 1212 | ||
| 1118 | error_pcm: | 1213 | error_pcm: |
| 1119 | if (!IS_ERR(ssi_private->baudclk)) | ||
| 1120 | clk_disable_unprepare(ssi_private->baudclk); | ||
| 1121 | |||
| 1122 | clk_disable_unprepare(ssi_private->clk); | 1214 | clk_disable_unprepare(ssi_private->clk); |
| 1123 | 1215 | ||
| 1124 | return ret; | 1216 | return ret; |
| @@ -1129,8 +1221,6 @@ static void fsl_ssi_imx_clean(struct platform_device *pdev, | |||
| 1129 | { | 1221 | { |
| 1130 | if (!ssi_private->use_dma) | 1222 | if (!ssi_private->use_dma) |
| 1131 | imx_pcm_fiq_exit(pdev); | 1223 | imx_pcm_fiq_exit(pdev); |
| 1132 | if (!IS_ERR(ssi_private->baudclk)) | ||
| 1133 | clk_disable_unprepare(ssi_private->baudclk); | ||
| 1134 | clk_disable_unprepare(ssi_private->clk); | 1224 | clk_disable_unprepare(ssi_private->clk); |
| 1135 | } | 1225 | } |
| 1136 | 1226 | ||
| @@ -1140,12 +1230,11 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1140 | int ret = 0; | 1230 | int ret = 0; |
| 1141 | struct device_node *np = pdev->dev.of_node; | 1231 | struct device_node *np = pdev->dev.of_node; |
| 1142 | const struct of_device_id *of_id; | 1232 | const struct of_device_id *of_id; |
| 1143 | enum fsl_ssi_type hw_type; | ||
| 1144 | const char *p, *sprop; | 1233 | const char *p, *sprop; |
| 1145 | const uint32_t *iprop; | 1234 | const uint32_t *iprop; |
| 1146 | struct resource res; | 1235 | struct resource res; |
| 1236 | void __iomem *iomem; | ||
| 1147 | char name[64]; | 1237 | char name[64]; |
| 1148 | bool ac97 = false; | ||
| 1149 | 1238 | ||
| 1150 | /* SSIs that are not connected on the board should have a | 1239 | /* SSIs that are not connected on the board should have a |
| 1151 | * status = "disabled" | 1240 | * status = "disabled" |
| @@ -1155,17 +1244,8 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1155 | return -ENODEV; | 1244 | return -ENODEV; |
| 1156 | 1245 | ||
| 1157 | of_id = of_match_device(fsl_ssi_ids, &pdev->dev); | 1246 | of_id = of_match_device(fsl_ssi_ids, &pdev->dev); |
| 1158 | if (!of_id) | 1247 | if (!of_id || !of_id->data) |
| 1159 | return -EINVAL; | ||
| 1160 | hw_type = (enum fsl_ssi_type) of_id->data; | ||
| 1161 | |||
| 1162 | sprop = of_get_property(np, "fsl,mode", NULL); | ||
| 1163 | if (!sprop) { | ||
| 1164 | dev_err(&pdev->dev, "fsl,mode property is necessary\n"); | ||
| 1165 | return -EINVAL; | 1248 | return -EINVAL; |
| 1166 | } | ||
| 1167 | if (!strcmp(sprop, "ac97-slave")) | ||
| 1168 | ac97 = true; | ||
| 1169 | 1249 | ||
| 1170 | ssi_private = devm_kzalloc(&pdev->dev, sizeof(*ssi_private), | 1250 | ssi_private = devm_kzalloc(&pdev->dev, sizeof(*ssi_private), |
| 1171 | GFP_KERNEL); | 1251 | GFP_KERNEL); |
| @@ -1174,11 +1254,21 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1174 | return -ENOMEM; | 1254 | return -ENOMEM; |
| 1175 | } | 1255 | } |
| 1176 | 1256 | ||
| 1257 | ssi_private->soc = of_id->data; | ||
| 1258 | |||
| 1259 | sprop = of_get_property(np, "fsl,mode", NULL); | ||
| 1260 | if (sprop) { | ||
| 1261 | if (!strcmp(sprop, "ac97-slave")) | ||
| 1262 | ssi_private->dai_fmt = SND_SOC_DAIFMT_AC97; | ||
| 1263 | else if (!strcmp(sprop, "i2s-slave")) | ||
| 1264 | ssi_private->dai_fmt = SND_SOC_DAIFMT_I2S | | ||
| 1265 | SND_SOC_DAIFMT_CBM_CFM; | ||
| 1266 | } | ||
| 1267 | |||
| 1177 | ssi_private->use_dma = !of_property_read_bool(np, | 1268 | ssi_private->use_dma = !of_property_read_bool(np, |
| 1178 | "fsl,fiq-stream-filter"); | 1269 | "fsl,fiq-stream-filter"); |
| 1179 | ssi_private->hw_type = hw_type; | ||
| 1180 | 1270 | ||
| 1181 | if (ac97) { | 1271 | if (fsl_ssi_is_ac97(ssi_private)) { |
| 1182 | memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_ac97_dai, | 1272 | memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_ac97_dai, |
| 1183 | sizeof(fsl_ssi_ac97_dai)); | 1273 | sizeof(fsl_ssi_ac97_dai)); |
| 1184 | 1274 | ||
| @@ -1198,12 +1288,20 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1198 | dev_err(&pdev->dev, "could not determine device resources\n"); | 1288 | dev_err(&pdev->dev, "could not determine device resources\n"); |
| 1199 | return ret; | 1289 | return ret; |
| 1200 | } | 1290 | } |
| 1201 | ssi_private->ssi = of_iomap(np, 0); | 1291 | ssi_private->ssi_phys = res.start; |
| 1202 | if (!ssi_private->ssi) { | 1292 | |
| 1293 | iomem = devm_ioremap(&pdev->dev, res.start, resource_size(&res)); | ||
| 1294 | if (!iomem) { | ||
| 1203 | dev_err(&pdev->dev, "could not map device resources\n"); | 1295 | dev_err(&pdev->dev, "could not map device resources\n"); |
| 1204 | return -ENOMEM; | 1296 | return -ENOMEM; |
| 1205 | } | 1297 | } |
| 1206 | ssi_private->ssi_phys = res.start; | 1298 | |
| 1299 | ssi_private->regs = devm_regmap_init_mmio(&pdev->dev, iomem, | ||
| 1300 | &fsl_ssi_regconfig); | ||
| 1301 | if (IS_ERR(ssi_private->regs)) { | ||
| 1302 | dev_err(&pdev->dev, "Failed to init register map\n"); | ||
| 1303 | return PTR_ERR(ssi_private->regs); | ||
| 1304 | } | ||
| 1207 | 1305 | ||
| 1208 | ssi_private->irq = irq_of_parse_and_map(np, 0); | 1306 | ssi_private->irq = irq_of_parse_and_map(np, 0); |
| 1209 | if (!ssi_private->irq) { | 1307 | if (!ssi_private->irq) { |
| @@ -1226,13 +1324,10 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1226 | /* Older 8610 DTs didn't have the fifo-depth property */ | 1324 | /* Older 8610 DTs didn't have the fifo-depth property */ |
| 1227 | ssi_private->fifo_depth = 8; | 1325 | ssi_private->fifo_depth = 8; |
| 1228 | 1326 | ||
| 1229 | ssi_private->baudclk_locked = false; | ||
| 1230 | spin_lock_init(&ssi_private->baudclk_lock); | ||
| 1231 | |||
| 1232 | dev_set_drvdata(&pdev->dev, ssi_private); | 1327 | dev_set_drvdata(&pdev->dev, ssi_private); |
| 1233 | 1328 | ||
| 1234 | if (fsl_ssi_on_imx(ssi_private)) { | 1329 | if (ssi_private->soc->imx) { |
| 1235 | ret = fsl_ssi_imx_probe(pdev, ssi_private, ssi_private->ssi); | 1330 | ret = fsl_ssi_imx_probe(pdev, ssi_private, iomem); |
| 1236 | if (ret) | 1331 | if (ret) |
| 1237 | goto error_irqmap; | 1332 | goto error_irqmap; |
| 1238 | } | 1333 | } |
| @@ -1289,6 +1384,9 @@ static int fsl_ssi_probe(struct platform_device *pdev) | |||
| 1289 | } | 1384 | } |
| 1290 | 1385 | ||
| 1291 | done: | 1386 | done: |
| 1387 | if (ssi_private->dai_fmt) | ||
| 1388 | _fsl_ssi_set_dai_fmt(ssi_private, ssi_private->dai_fmt); | ||
| 1389 | |||
| 1292 | return 0; | 1390 | return 0; |
| 1293 | 1391 | ||
| 1294 | error_sound_card: | 1392 | error_sound_card: |
| @@ -1298,7 +1396,7 @@ error_irq: | |||
| 1298 | snd_soc_unregister_component(&pdev->dev); | 1396 | snd_soc_unregister_component(&pdev->dev); |
| 1299 | 1397 | ||
| 1300 | error_asoc_register: | 1398 | error_asoc_register: |
| 1301 | if (fsl_ssi_on_imx(ssi_private)) | 1399 | if (ssi_private->soc->imx) |
| 1302 | fsl_ssi_imx_clean(pdev, ssi_private); | 1400 | fsl_ssi_imx_clean(pdev, ssi_private); |
| 1303 | 1401 | ||
| 1304 | error_irqmap: | 1402 | error_irqmap: |
| @@ -1318,7 +1416,7 @@ static int fsl_ssi_remove(struct platform_device *pdev) | |||
| 1318 | platform_device_unregister(ssi_private->pdev); | 1416 | platform_device_unregister(ssi_private->pdev); |
| 1319 | snd_soc_unregister_component(&pdev->dev); | 1417 | snd_soc_unregister_component(&pdev->dev); |
| 1320 | 1418 | ||
| 1321 | if (fsl_ssi_on_imx(ssi_private)) | 1419 | if (ssi_private->soc->imx) |
| 1322 | fsl_ssi_imx_clean(pdev, ssi_private); | 1420 | fsl_ssi_imx_clean(pdev, ssi_private); |
| 1323 | 1421 | ||
| 1324 | if (ssi_private->use_dma) | 1422 | if (ssi_private->use_dma) |
diff --git a/sound/soc/fsl/fsl_ssi.h b/sound/soc/fsl/fsl_ssi.h index 71c3e7e4340d..506510540d0a 100644 --- a/sound/soc/fsl/fsl_ssi.h +++ b/sound/soc/fsl/fsl_ssi.h | |||
| @@ -12,32 +12,30 @@ | |||
| 12 | #ifndef _MPC8610_I2S_H | 12 | #ifndef _MPC8610_I2S_H |
| 13 | #define _MPC8610_I2S_H | 13 | #define _MPC8610_I2S_H |
| 14 | 14 | ||
| 15 | /* SSI Register Map */ | 15 | /* SSI registers */ |
| 16 | struct ccsr_ssi { | 16 | #define CCSR_SSI_STX0 0x00 |
| 17 | __be32 stx0; /* 0x.0000 - SSI Transmit Data Register 0 */ | 17 | #define CCSR_SSI_STX1 0x04 |
| 18 | __be32 stx1; /* 0x.0004 - SSI Transmit Data Register 1 */ | 18 | #define CCSR_SSI_SRX0 0x08 |
| 19 | __be32 srx0; /* 0x.0008 - SSI Receive Data Register 0 */ | 19 | #define CCSR_SSI_SRX1 0x0c |
| 20 | __be32 srx1; /* 0x.000C - SSI Receive Data Register 1 */ | 20 | #define CCSR_SSI_SCR 0x10 |
| 21 | __be32 scr; /* 0x.0010 - SSI Control Register */ | 21 | #define CCSR_SSI_SISR 0x14 |
| 22 | __be32 sisr; /* 0x.0014 - SSI Interrupt Status Register Mixed */ | 22 | #define CCSR_SSI_SIER 0x18 |
| 23 | __be32 sier; /* 0x.0018 - SSI Interrupt Enable Register */ | 23 | #define CCSR_SSI_STCR 0x1c |
| 24 | __be32 stcr; /* 0x.001C - SSI Transmit Configuration Register */ | 24 | #define CCSR_SSI_SRCR 0x20 |
| 25 | __be32 srcr; /* 0x.0020 - SSI Receive Configuration Register */ | 25 | #define CCSR_SSI_STCCR 0x24 |
| 26 | __be32 stccr; /* 0x.0024 - SSI Transmit Clock Control Register */ | 26 | #define CCSR_SSI_SRCCR 0x28 |
| 27 | __be32 srccr; /* 0x.0028 - SSI Receive Clock Control Register */ | 27 | #define CCSR_SSI_SFCSR 0x2c |
| 28 | __be32 sfcsr; /* 0x.002C - SSI FIFO Control/Status Register */ | 28 | #define CCSR_SSI_STR 0x30 |
| 29 | __be32 str; /* 0x.0030 - SSI Test Register */ | 29 | #define CCSR_SSI_SOR 0x34 |
| 30 | __be32 sor; /* 0x.0034 - SSI Option Register */ | 30 | #define CCSR_SSI_SACNT 0x38 |
| 31 | __be32 sacnt; /* 0x.0038 - SSI AC97 Control Register */ | 31 | #define CCSR_SSI_SACADD 0x3c |
| 32 | __be32 sacadd; /* 0x.003C - SSI AC97 Command Address Register */ | 32 | #define CCSR_SSI_SACDAT 0x40 |
| 33 | __be32 sacdat; /* 0x.0040 - SSI AC97 Command Data Register */ | 33 | #define CCSR_SSI_SATAG 0x44 |
| 34 | __be32 satag; /* 0x.0044 - SSI AC97 Tag Register */ | 34 | #define CCSR_SSI_STMSK 0x48 |
| 35 | __be32 stmsk; /* 0x.0048 - SSI Transmit Time Slot Mask Register */ | 35 | #define CCSR_SSI_SRMSK 0x4c |
| 36 | __be32 srmsk; /* 0x.004C - SSI Receive Time Slot Mask Register */ | 36 | #define CCSR_SSI_SACCST 0x50 |
| 37 | __be32 saccst; /* 0x.0050 - SSI AC97 Channel Status Register */ | 37 | #define CCSR_SSI_SACCEN 0x54 |
| 38 | __be32 saccen; /* 0x.0054 - SSI AC97 Channel Enable Register */ | 38 | #define CCSR_SSI_SACCDIS 0x58 |
| 39 | __be32 saccdis; /* 0x.0058 - SSI AC97 Channel Disable Register */ | ||
| 40 | }; | ||
| 41 | 39 | ||
| 42 | #define CCSR_SSI_SCR_SYNC_TX_FS 0x00001000 | 40 | #define CCSR_SSI_SCR_SYNC_TX_FS 0x00001000 |
| 43 | #define CCSR_SSI_SCR_RFR_CLK_DIS 0x00000800 | 41 | #define CCSR_SSI_SCR_RFR_CLK_DIS 0x00000800 |
