Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: sirf: Move the tx rx enable from port to codec, that will not need register sharing

The port driver only used to register component and dmaengine pcm.

Signed-off-by: Rongjun Ying <rongjun.ying@csr.com>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Rongjun Ying and committed by
Mark Brown
b87704ce c9eaa447

+116 -177
+66 -8
sound/soc/codecs/sirf-audio-codec.c
··· 279 279 {"Mic input mode mux", "Differential", "MICIN1"}, 280 280 }; 281 281 282 + static void sirf_audio_codec_tx_enable(struct sirf_audio_codec *sirf_audio_codec) 283 + { 284 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_OP, 285 + AUDIO_FIFO_RESET, AUDIO_FIFO_RESET); 286 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_OP, 287 + AUDIO_FIFO_RESET, ~AUDIO_FIFO_RESET); 288 + regmap_write(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_INT_MSK, 0); 289 + regmap_write(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0); 290 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_OP, 291 + AUDIO_FIFO_START, AUDIO_FIFO_START); 292 + regmap_update_bits(sirf_audio_codec->regmap, 293 + AUDIO_PORT_IC_CODEC_TX_CTRL, IC_TX_ENABLE, IC_TX_ENABLE); 294 + } 295 + 296 + static void sirf_audio_codec_tx_disable(struct sirf_audio_codec *sirf_audio_codec) 297 + { 298 + regmap_write(sirf_audio_codec->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0); 299 + regmap_update_bits(sirf_audio_codec->regmap, 300 + AUDIO_PORT_IC_CODEC_TX_CTRL, IC_TX_ENABLE, ~IC_TX_ENABLE); 301 + } 302 + 303 + static void sirf_audio_codec_rx_enable(struct sirf_audio_codec *sirf_audio_codec, 304 + int channels) 305 + { 306 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_RXFIFO_OP, 307 + AUDIO_FIFO_RESET, AUDIO_FIFO_RESET); 308 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_RXFIFO_OP, 309 + AUDIO_FIFO_RESET, ~AUDIO_FIFO_RESET); 310 + regmap_write(sirf_audio_codec->regmap, 311 + AUDIO_PORT_IC_RXFIFO_INT_MSK, 0); 312 + regmap_write(sirf_audio_codec->regmap, AUDIO_PORT_IC_RXFIFO_OP, 0); 313 + regmap_update_bits(sirf_audio_codec->regmap, AUDIO_PORT_IC_RXFIFO_OP, 314 + AUDIO_FIFO_START, AUDIO_FIFO_START); 315 + if (channels == 1) 316 + regmap_update_bits(sirf_audio_codec->regmap, 317 + AUDIO_PORT_IC_CODEC_RX_CTRL, 318 + IC_RX_ENABLE_MONO, IC_RX_ENABLE_MONO); 319 + else 320 + regmap_update_bits(sirf_audio_codec->regmap, 321 + AUDIO_PORT_IC_CODEC_RX_CTRL, 322 + IC_RX_ENABLE_STEREO, IC_RX_ENABLE_STEREO); 323 + } 324 + 325 + static void sirf_audio_codec_rx_disable(struct sirf_audio_codec *sirf_audio_codec) 326 + { 327 + regmap_update_bits(sirf_audio_codec->regmap, 328 + AUDIO_PORT_IC_CODEC_RX_CTRL, 329 + IC_RX_ENABLE_STEREO, ~IC_RX_ENABLE_STEREO); 330 + } 331 + 282 332 static int sirf_audio_codec_trigger(struct snd_pcm_substream *substream, 283 333 int cmd, 284 334 struct snd_soc_dai *dai) 285 335 { 286 - int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 287 336 struct snd_soc_codec *codec = dai->codec; 288 - u32 val = 0; 337 + struct sirf_audio_codec *sirf_audio_codec = snd_soc_codec_get_drvdata(codec); 338 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 289 339 290 340 /* 291 341 * This is a workaround, When stop playback, ··· 345 295 case SNDRV_PCM_TRIGGER_STOP: 346 296 case SNDRV_PCM_TRIGGER_SUSPEND: 347 297 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 298 + if (playback) { 299 + snd_soc_update_bits(codec, AUDIO_IC_CODEC_CTRL0, 300 + IC_HSLEN | IC_HSREN, 0); 301 + sirf_audio_codec_tx_disable(sirf_audio_codec); 302 + } else 303 + sirf_audio_codec_rx_disable(sirf_audio_codec); 348 304 break; 349 305 case SNDRV_PCM_TRIGGER_START: 350 306 case SNDRV_PCM_TRIGGER_RESUME: 351 307 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 352 - if (playback) 353 - val = IC_HSLEN | IC_HSREN; 308 + if (playback) { 309 + sirf_audio_codec_tx_enable(sirf_audio_codec); 310 + snd_soc_update_bits(codec, AUDIO_IC_CODEC_CTRL0, 311 + IC_HSLEN | IC_HSREN, IC_HSLEN | IC_HSREN); 312 + } else 313 + sirf_audio_codec_rx_enable(sirf_audio_codec, 314 + substream->runtime->channels); 354 315 break; 355 316 default: 356 317 return -EINVAL; 357 318 } 358 319 359 - if (playback) 360 - snd_soc_update_bits(codec, AUDIO_IC_CODEC_CTRL0, 361 - IC_HSLEN | IC_HSREN, val); 362 320 return 0; 363 321 } 364 322 ··· 450 392 .reg_bits = 32, 451 393 .reg_stride = 4, 452 394 .val_bits = 32, 453 - .max_register = AUDIO_IC_CODEC_CTRL3, 395 + .max_register = AUDIO_PORT_IC_RXFIFO_INT_MSK, 454 396 .cache_type = REGCACHE_NONE, 455 397 }; 456 398
+50
sound/soc/codecs/sirf-audio-codec.h
··· 72 72 #define IC_RXPGAR 0x7B 73 73 #define IC_RXPGAL 0x7B 74 74 75 + #define AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK 0x3F 76 + #define AUDIO_PORT_TX_FIFO_SC_OFFSET 0 77 + #define AUDIO_PORT_TX_FIFO_LC_OFFSET 10 78 + #define AUDIO_PORT_TX_FIFO_HC_OFFSET 20 79 + 80 + #define TX_FIFO_SC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 81 + << AUDIO_PORT_TX_FIFO_SC_OFFSET) 82 + #define TX_FIFO_LC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 83 + << AUDIO_PORT_TX_FIFO_LC_OFFSET) 84 + #define TX_FIFO_HC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 85 + << AUDIO_PORT_TX_FIFO_HC_OFFSET) 86 + 87 + #define AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK 0x0F 88 + #define AUDIO_PORT_RX_FIFO_SC_OFFSET 0 89 + #define AUDIO_PORT_RX_FIFO_LC_OFFSET 10 90 + #define AUDIO_PORT_RX_FIFO_HC_OFFSET 20 91 + 92 + #define RX_FIFO_SC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 93 + << AUDIO_PORT_RX_FIFO_SC_OFFSET) 94 + #define RX_FIFO_LC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 95 + << AUDIO_PORT_RX_FIFO_LC_OFFSET) 96 + #define RX_FIFO_HC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 97 + << AUDIO_PORT_RX_FIFO_HC_OFFSET) 98 + #define AUDIO_PORT_IC_CODEC_TX_CTRL (0x00F4) 99 + #define AUDIO_PORT_IC_CODEC_RX_CTRL (0x00F8) 100 + 101 + #define AUDIO_PORT_IC_TXFIFO_OP (0x00FC) 102 + #define AUDIO_PORT_IC_TXFIFO_LEV_CHK (0x0100) 103 + #define AUDIO_PORT_IC_TXFIFO_STS (0x0104) 104 + #define AUDIO_PORT_IC_TXFIFO_INT (0x0108) 105 + #define AUDIO_PORT_IC_TXFIFO_INT_MSK (0x010C) 106 + 107 + #define AUDIO_PORT_IC_RXFIFO_OP (0x0110) 108 + #define AUDIO_PORT_IC_RXFIFO_LEV_CHK (0x0114) 109 + #define AUDIO_PORT_IC_RXFIFO_STS (0x0118) 110 + #define AUDIO_PORT_IC_RXFIFO_INT (0x011C) 111 + #define AUDIO_PORT_IC_RXFIFO_INT_MSK (0x0120) 112 + 113 + #define AUDIO_FIFO_START (1 << 0) 114 + #define AUDIO_FIFO_RESET (1 << 1) 115 + 116 + #define AUDIO_FIFO_FULL (1 << 0) 117 + #define AUDIO_FIFO_EMPTY (1 << 1) 118 + #define AUDIO_FIFO_OFLOW (1 << 2) 119 + #define AUDIO_FIFO_UFLOW (1 << 3) 120 + 121 + #define IC_TX_ENABLE (0x03) 122 + #define IC_RX_ENABLE_MONO (0x01) 123 + #define IC_RX_ENABLE_STEREO (0x03) 124 + 75 125 #endif /*__SIRF_AUDIO_CODEC_H*/
-107
sound/soc/sirf/sirf-audio-port.c
··· 6 6 * Licensed under GPLv2 or later. 7 7 */ 8 8 #include <linux/module.h> 9 - #include <linux/io.h> 10 - #include <linux/regmap.h> 11 9 #include <sound/soc.h> 12 10 #include <sound/dmaengine_pcm.h> 13 - 14 - #include "sirf-audio-port.h" 15 11 16 12 struct sirf_audio_port { 17 13 struct regmap *regmap; ··· 15 19 struct snd_dmaengine_dai_dma_data capture_dma_data; 16 20 }; 17 21 18 - static void sirf_audio_port_tx_enable(struct sirf_audio_port *port) 19 - { 20 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 21 - AUDIO_FIFO_RESET, AUDIO_FIFO_RESET); 22 - regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_INT_MSK, 0); 23 - regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0); 24 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 25 - AUDIO_FIFO_START, AUDIO_FIFO_START); 26 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_TX_CTRL, 27 - IC_TX_ENABLE, IC_TX_ENABLE); 28 - } 29 - 30 - static void sirf_audio_port_tx_disable(struct sirf_audio_port *port) 31 - { 32 - regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0); 33 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_TX_CTRL, 34 - IC_TX_ENABLE, ~IC_TX_ENABLE); 35 - } 36 - 37 - static void sirf_audio_port_rx_enable(struct sirf_audio_port *port, 38 - int channels) 39 - { 40 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_RXFIFO_OP, 41 - AUDIO_FIFO_RESET, AUDIO_FIFO_RESET); 42 - regmap_write(port->regmap, AUDIO_PORT_IC_RXFIFO_INT_MSK, 0); 43 - regmap_write(port->regmap, AUDIO_PORT_IC_RXFIFO_OP, 0); 44 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_RXFIFO_OP, 45 - AUDIO_FIFO_START, AUDIO_FIFO_START); 46 - if (channels == 1) 47 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL, 48 - IC_RX_ENABLE_MONO, IC_RX_ENABLE_MONO); 49 - else 50 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL, 51 - IC_RX_ENABLE_STEREO, IC_RX_ENABLE_STEREO); 52 - } 53 - 54 - static void sirf_audio_port_rx_disable(struct sirf_audio_port *port) 55 - { 56 - regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL, 57 - IC_RX_ENABLE_STEREO, ~IC_RX_ENABLE_STEREO); 58 - } 59 22 60 23 static int sirf_audio_port_dai_probe(struct snd_soc_dai *dai) 61 24 { ··· 23 68 &port->capture_dma_data); 24 69 return 0; 25 70 } 26 - 27 - static int sirf_audio_port_trigger(struct snd_pcm_substream *substream, int cmd, 28 - struct snd_soc_dai *dai) 29 - { 30 - struct sirf_audio_port *port = snd_soc_dai_get_drvdata(dai); 31 - int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 32 - 33 - switch (cmd) { 34 - case SNDRV_PCM_TRIGGER_STOP: 35 - case SNDRV_PCM_TRIGGER_SUSPEND: 36 - case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 37 - if (playback) 38 - sirf_audio_port_tx_disable(port); 39 - else 40 - sirf_audio_port_rx_disable(port); 41 - break; 42 - case SNDRV_PCM_TRIGGER_START: 43 - case SNDRV_PCM_TRIGGER_RESUME: 44 - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 45 - if (playback) 46 - sirf_audio_port_tx_enable(port); 47 - else 48 - sirf_audio_port_rx_enable(port, 49 - substream->runtime->channels); 50 - break; 51 - default: 52 - return -EINVAL; 53 - } 54 - 55 - return 0; 56 - } 57 - 58 - static const struct snd_soc_dai_ops sirf_audio_port_dai_ops = { 59 - .trigger = sirf_audio_port_trigger, 60 - }; 61 71 62 72 static struct snd_soc_dai_driver sirf_audio_port_dai = { 63 73 .probe = sirf_audio_port_dai_probe, ··· 40 120 .rates = SNDRV_PCM_RATE_48000, 41 121 .formats = SNDRV_PCM_FMTBIT_S16_LE, 42 122 }, 43 - .ops = &sirf_audio_port_dai_ops, 44 123 }; 45 124 46 125 static const struct snd_soc_component_driver sirf_audio_port_component = { 47 126 .name = "sirf-audio-port", 48 127 }; 49 128 50 - static const struct regmap_config sirf_audio_port_regmap_config = { 51 - .reg_bits = 32, 52 - .reg_stride = 4, 53 - .val_bits = 32, 54 - .max_register = AUDIO_PORT_IC_RXFIFO_INT_MSK, 55 - .cache_type = REGCACHE_NONE, 56 - }; 57 - 58 129 static int sirf_audio_port_probe(struct platform_device *pdev) 59 130 { 60 131 int ret; 61 132 struct sirf_audio_port *port; 62 - void __iomem *base; 63 - struct resource *mem_res; 64 133 65 134 port = devm_kzalloc(&pdev->dev, 66 135 sizeof(struct sirf_audio_port), GFP_KERNEL); 67 136 if (!port) 68 137 return -ENOMEM; 69 - 70 - mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 71 - if (!mem_res) { 72 - dev_err(&pdev->dev, "no mem resource?\n"); 73 - return -ENODEV; 74 - } 75 - 76 - base = devm_ioremap(&pdev->dev, mem_res->start, 77 - resource_size(mem_res)); 78 - if (base == NULL) 79 - return -ENOMEM; 80 - 81 - port->regmap = devm_regmap_init_mmio(&pdev->dev, base, 82 - &sirf_audio_port_regmap_config); 83 - if (IS_ERR(port->regmap)) 84 - return PTR_ERR(port->regmap); 85 138 86 139 ret = devm_snd_soc_register_component(&pdev->dev, 87 140 &sirf_audio_port_component, &sirf_audio_port_dai, 1);
-62
sound/soc/sirf/sirf-audio-port.h
··· 1 - /* 2 - * SiRF Audio port controllers define 3 - * 4 - * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company. 5 - * 6 - * Licensed under GPLv2 or later. 7 - */ 8 - 9 - #ifndef _SIRF_AUDIO_PORT_H 10 - #define _SIRF_AUDIO_PORT_H 11 - 12 - #define AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK 0x3F 13 - #define AUDIO_PORT_TX_FIFO_SC_OFFSET 0 14 - #define AUDIO_PORT_TX_FIFO_LC_OFFSET 10 15 - #define AUDIO_PORT_TX_FIFO_HC_OFFSET 20 16 - 17 - #define TX_FIFO_SC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 18 - << AUDIO_PORT_TX_FIFO_SC_OFFSET) 19 - #define TX_FIFO_LC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 20 - << AUDIO_PORT_TX_FIFO_LC_OFFSET) 21 - #define TX_FIFO_HC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \ 22 - << AUDIO_PORT_TX_FIFO_HC_OFFSET) 23 - 24 - #define AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK 0x0F 25 - #define AUDIO_PORT_RX_FIFO_SC_OFFSET 0 26 - #define AUDIO_PORT_RX_FIFO_LC_OFFSET 10 27 - #define AUDIO_PORT_RX_FIFO_HC_OFFSET 20 28 - 29 - #define RX_FIFO_SC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 30 - << AUDIO_PORT_RX_FIFO_SC_OFFSET) 31 - #define RX_FIFO_LC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 32 - << AUDIO_PORT_RX_FIFO_LC_OFFSET) 33 - #define RX_FIFO_HC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \ 34 - << AUDIO_PORT_RX_FIFO_HC_OFFSET) 35 - #define AUDIO_PORT_IC_CODEC_TX_CTRL (0x00F4) 36 - #define AUDIO_PORT_IC_CODEC_RX_CTRL (0x00F8) 37 - 38 - #define AUDIO_PORT_IC_TXFIFO_OP (0x00FC) 39 - #define AUDIO_PORT_IC_TXFIFO_LEV_CHK (0x0100) 40 - #define AUDIO_PORT_IC_TXFIFO_STS (0x0104) 41 - #define AUDIO_PORT_IC_TXFIFO_INT (0x0108) 42 - #define AUDIO_PORT_IC_TXFIFO_INT_MSK (0x010C) 43 - 44 - #define AUDIO_PORT_IC_RXFIFO_OP (0x0110) 45 - #define AUDIO_PORT_IC_RXFIFO_LEV_CHK (0x0114) 46 - #define AUDIO_PORT_IC_RXFIFO_STS (0x0118) 47 - #define AUDIO_PORT_IC_RXFIFO_INT (0x011C) 48 - #define AUDIO_PORT_IC_RXFIFO_INT_MSK (0x0120) 49 - 50 - #define AUDIO_FIFO_START (1 << 0) 51 - #define AUDIO_FIFO_RESET (1 << 1) 52 - 53 - #define AUDIO_FIFO_FULL (1 << 0) 54 - #define AUDIO_FIFO_EMPTY (1 << 1) 55 - #define AUDIO_FIFO_OFLOW (1 << 2) 56 - #define AUDIO_FIFO_UFLOW (1 << 3) 57 - 58 - #define IC_TX_ENABLE (0x03) 59 - #define IC_RX_ENABLE_MONO (0x01) 60 - #define IC_RX_ENABLE_STEREO (0x03) 61 - 62 - #endif /*__SIRF_AUDIO_PORT_H*/