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

Merge tag 'asoc-v4.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-next

ASoC: Updates for v4.4

A first batch of updates targetted at v4.4. There are no substantial
core fixes here, the biggest block of changes is updates to the rcar
drivers and the addition of a CODEC driver for the AK4613.

+2480 -830
+17
Documentation/devicetree/bindings/sound/ak4613.txt
··· 1 + AK4613 I2C transmitter 2 + 3 + This device supports I2C mode only. 4 + 5 + Required properties: 6 + 7 + - compatible : "asahi-kasei,ak4613" 8 + - reg : The chip select number on the I2C bus 9 + 10 + Example: 11 + 12 + &i2c { 13 + ak4613: ak4613@0x10 { 14 + compatible = "asahi-kasei,ak4613"; 15 + reg = <0x10>; 16 + }; 17 + };
+21 -1
Documentation/devicetree/bindings/sound/ak4642.txt
··· 7 7 - compatible : "asahi-kasei,ak4642" or "asahi-kasei,ak4643" or "asahi-kasei,ak4648" 8 8 - reg : The chip select number on the I2C bus 9 9 10 - Example: 10 + Optional properties: 11 + 12 + - #clock-cells : common clock binding; shall be set to 0 13 + - clocks : common clock binding; MCKI clock 14 + - clock-frequency : common clock binding; frequency of MCKO 15 + - clock-output-names : common clock binding; MCKO clock name 16 + 17 + Example 1: 11 18 12 19 &i2c { 13 20 ak4648: ak4648@0x12 { 14 21 compatible = "asahi-kasei,ak4642"; 15 22 reg = <0x12>; 23 + }; 24 + }; 25 + 26 + Example 2: 27 + 28 + &i2c { 29 + ak4643: codec@12 { 30 + compatible = "asahi-kasei,ak4643"; 31 + reg = <0x12>; 32 + #clock-cells = <0>; 33 + clocks = <&audio_clock>; 34 + clock-frequency = <12288000>; 35 + clock-output-names = "ak4643_mcko"; 16 36 }; 17 37 };
+7
Documentation/devicetree/bindings/sound/renesas,rsnd.txt
··· 4 4 - compatible : "renesas,rcar_sound-<soctype>", fallbacks 5 5 "renesas,rcar_sound-gen1" if generation1, and 6 6 "renesas,rcar_sound-gen2" if generation2 7 + "renesas,rcar_sound-gen3" if generation3 7 8 Examples with soctypes are: 8 9 - "renesas,rcar_sound-r8a7778" (R-Car M1A) 9 10 - "renesas,rcar_sound-r8a7790" (R-Car H2) 10 11 - "renesas,rcar_sound-r8a7791" (R-Car M2-W) 12 + - "renesas,rcar_sound-r8a7795" (R-Car H3) 11 13 - reg : Should contain the register physical address. 12 14 required register is 13 15 SRU/ADG/SSI if generation1 ··· 32 30 - rcar_sound,dai : DAI contents. 33 31 The number of DAI subnode should be same as HW. 34 32 see below for detail. 33 + - #sound-dai-cells : it must be 0 if your system is using single DAI 34 + it must be 1 if your system is using multi DAI 35 + - #clock-cells : it must be 0 if your system has audio_clkout 36 + it must be 1 if your system has audio_clkout0/1/2/3 37 + - clock-frequency : for all audio_clkout0/1/2/3 35 38 36 39 SSI subnode properties: 37 40 - interrupts : Should contain SSI interrupt for PIO transfer
+33
Documentation/devicetree/bindings/sound/sun4i-codec.txt
··· 1 + * Allwinner A10 Codec 2 + 3 + Required properties: 4 + - compatible: must be either "allwinner,sun4i-a10-codec" or 5 + "allwinner,sun7i-a20-codec" 6 + - reg: must contain the registers location and length 7 + - interrupts: must contain the codec interrupt 8 + - dmas: DMA channels for tx and rx dma. See the DMA client binding, 9 + Documentation/devicetree/bindings/dma/dma.txt 10 + - dma-names: should include "tx" and "rx". 11 + - clocks: a list of phandle + clock-specifer pairs, one for each entry 12 + in clock-names. 13 + - clock-names: should contain followings: 14 + - "apb": the parent APB clock for this controller 15 + - "codec": the parent module clock 16 + - routing : A list of the connections between audio components. Each 17 + entry is a pair of strings, the first being the connection's sink, 18 + the second being the connection's source. 19 + 20 + 21 + Example: 22 + codec: codec@01c22c00 { 23 + #sound-dai-cells = <0>; 24 + compatible = "allwinner,sun7i-a20-codec"; 25 + reg = <0x01c22c00 0x40>; 26 + interrupts = <0 30 4>; 27 + clocks = <&apb0_gates 0>, <&codec_clk>; 28 + clock-names = "apb", "codec"; 29 + dmas = <&dma 0 19>, <&dma 0 19>; 30 + dma-names = "rx", "tx"; 31 + routing = "Headphone Jack", "HP Right", 32 + "Headphone Jack", "HP Left"; 33 + };
+10 -1
Documentation/devicetree/bindings/sound/tdm-slot.txt
··· 4 4 5 5 TDM slot properties: 6 6 dai-tdm-slot-num : Number of slots in use. 7 - dai-tdm-slot-width : Width in bits for each slot. 7 + dai-tdm-slot-width : Width in bits for each slot. 8 + dai-tdm-slot-tx-mask : Transmit direction slot mask, optional 9 + dai-tdm-slot-rx-mask : Receive direction slot mask, optional 8 10 9 11 For instance: 10 12 dai-tdm-slot-num = <2>; 11 13 dai-tdm-slot-width = <8>; 14 + dai-tdm-slot-tx-mask = <0 1>; 15 + dai-tdm-slot-rx-mask = <1 0>; 12 16 13 17 And for each spcified driver, there could be one .of_xlate_tdm_slot_mask() 14 18 to specify a explicit mapping of the channels and the slots. If it's absent ··· 22 18 For snd_soc_of_xlate_tdm_slot_mask(), the tx and rx masks will use a 1 bit 23 19 for an active slot as default, and the default active bits are at the LSB of 24 20 the masks. 21 + 22 + The explicit masks are given as array of integers, where the first 23 + number presents bit-0 (LSB), second presents bit-1, etc. Any non zero 24 + number is considered 1 and 0 is 0. snd_soc_of_xlate_tdm_slot_mask() 25 + does not do anything, if either mask is set non zero value.
+3 -6
MAINTAINERS
··· 11239 11239 M: Liam Girdwood <lgirdwood@gmail.com> 11240 11240 M: Mark Brown <broonie@kernel.org> 11241 11241 L: linux-kernel@vger.kernel.org 11242 - W: http://opensource.wolfsonmicro.com/node/15 11243 11242 W: http://www.slimlogic.co.uk/?p=48 11244 11243 T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 11245 11244 S: Supported ··· 11367 11368 M: Mark Brown <broonie@kernel.org> 11368 11369 M: Liam Girdwood <lrg@slimlogic.co.uk> 11369 11370 L: linux-input@vger.kernel.org 11370 - T: git git://opensource.wolfsonmicro.com/linux-2.6-touch 11371 - W: http://opensource.wolfsonmicro.com/node/7 11371 + W: https://github.com/CirrusLogic/linux-drivers/wiki 11372 11372 S: Supported 11373 11373 F: drivers/input/touchscreen/*wm97* 11374 11374 F: include/linux/wm97xx.h 11375 11375 11376 11376 WOLFSON MICROELECTRONICS DRIVERS 11377 11377 L: patches@opensource.wolfsonmicro.com 11378 - T: git git://opensource.wolfsonmicro.com/linux-2.6-asoc 11379 - T: git git://opensource.wolfsonmicro.com/linux-2.6-audioplus 11380 - W: http://opensource.wolfsonmicro.com/content/linux-drivers-wolfson-devices 11378 + T: git https://github.com/CirrusLogic/linux-drivers.git 11379 + W: https://github.com/CirrusLogic/linux-drivers/wiki 11381 11380 S: Supported 11382 11381 F: Documentation/hwmon/wm83?? 11383 11382 F: arch/arm/mach-s3c64xx/mach-crag6410*
+6 -15
drivers/spi/spi-atmel.c
··· 871 871 * Calculate the lowest divider that satisfies the 872 872 * constraint, assuming div32/fdiv/mbz == 0. 873 873 */ 874 - if (xfer->speed_hz) 875 - scbr = DIV_ROUND_UP(bus_hz, xfer->speed_hz); 876 - else 877 - /* 878 - * This can happend if max_speed is null. 879 - * In this case, we set the lowest possible speed 880 - */ 881 - scbr = 0xff; 874 + scbr = DIV_ROUND_UP(bus_hz, xfer->speed_hz); 882 875 883 876 /* 884 877 * If the resulting divider doesn't fit into the ··· 1293 1300 return -EINVAL; 1294 1301 } 1295 1302 1296 - if (xfer->bits_per_word) { 1297 - asd = spi->controller_state; 1298 - bits = (asd->csr >> 4) & 0xf; 1299 - if (bits != xfer->bits_per_word - 8) { 1300 - dev_dbg(&spi->dev, 1303 + asd = spi->controller_state; 1304 + bits = (asd->csr >> 4) & 0xf; 1305 + if (bits != xfer->bits_per_word - 8) { 1306 + dev_dbg(&spi->dev, 1301 1307 "you can't yet change bits_per_word in transfers\n"); 1302 - return -ENOPROTOOPT; 1303 - } 1308 + return -ENOPROTOOPT; 1304 1309 } 1305 1310 1306 1311 /*
-1
include/sound/rcar_snd.h
··· 12 12 #ifndef RCAR_SND_H 13 13 #define RCAR_SND_H 14 14 15 - #include <linux/sh_clk.h> 16 15 17 16 #define RSND_GEN1_SRU 0 18 17 #define RSND_GEN1_ADG 1
+2
include/sound/rt5645.h
··· 21 21 /* 0 = IN2P; 1 = GPIO6; 2 = GPIO10; 3 = GPIO12 */ 22 22 23 23 unsigned int jd_mode; 24 + /* Invert JD when jack insert */ 25 + bool jd_invert; 24 26 }; 25 27 26 28 #endif
+2
include/sound/simple_card.h
··· 19 19 unsigned int sysclk; 20 20 int slots; 21 21 int slot_width; 22 + unsigned int tx_slot_mask; 23 + unsigned int rx_slot_mask; 22 24 struct clk *clk; 23 25 }; 24 26
+14
include/sound/soc.h
··· 226 226 .info = snd_soc_info_volsw, \ 227 227 .get = xhandler_get, .put = xhandler_put, \ 228 228 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, 0) } 229 + #define SOC_SINGLE_RANGE_EXT_TLV(xname, xreg, xshift, xmin, xmax, xinvert, \ 230 + xhandler_get, xhandler_put, tlv_array) \ 231 + { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ 232 + .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 233 + SNDRV_CTL_ELEM_ACCESS_READWRITE,\ 234 + .tlv.p = (tlv_array), \ 235 + .info = snd_soc_info_volsw_range, \ 236 + .get = xhandler_get, .put = xhandler_put, \ 237 + .private_value = (unsigned long)&(struct soc_mixer_control) \ 238 + {.reg = xreg, .rreg = xreg, .shift = xshift, \ 239 + .rshift = xshift, .min = xmin, .max = xmax, \ 240 + .platform_max = xmax, .invert = xinvert} } 229 241 #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\ 230 242 xhandler_get, xhandler_put, tlv_array) \ 231 243 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ ··· 1613 1601 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, 1614 1602 const char *propname); 1615 1603 int snd_soc_of_parse_tdm_slot(struct device_node *np, 1604 + unsigned int *tx_mask, 1605 + unsigned int *rx_mask, 1616 1606 unsigned int *slots, 1617 1607 unsigned int *slot_width); 1618 1608 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
+8 -7
sound/arm/Kconfig
··· 9 9 Drivers that are implemented on ASoC can be found in 10 10 "ALSA for SoC audio support" section. 11 11 12 + config SND_PXA2XX_LIB 13 + tristate 14 + select SND_AC97_CODEC if SND_PXA2XX_LIB_AC97 15 + select SND_DMAENGINE_PCM 16 + 17 + config SND_PXA2XX_LIB_AC97 18 + bool 19 + 12 20 if SND_ARM 13 21 14 22 config SND_ARMAACI ··· 28 20 config SND_PXA2XX_PCM 29 21 tristate 30 22 select SND_PCM 31 - 32 - config SND_PXA2XX_LIB 33 - tristate 34 - select SND_AC97_CODEC if SND_PXA2XX_LIB_AC97 35 - 36 - config SND_PXA2XX_LIB_AC97 37 - bool 38 23 39 24 config SND_PXA2XX_AC97 40 25 tristate "AC97 driver for the Intel PXA2xx chip"
+1
sound/soc/Kconfig
··· 58 58 source "sound/soc/sirf/Kconfig" 59 59 source "sound/soc/spear/Kconfig" 60 60 source "sound/soc/sti/Kconfig" 61 + source "sound/soc/sunxi/Kconfig" 61 62 source "sound/soc/tegra/Kconfig" 62 63 source "sound/soc/txx9/Kconfig" 63 64 source "sound/soc/ux500/Kconfig"
+1
sound/soc/Makefile
··· 40 40 obj-$(CONFIG_SND_SOC) += sirf/ 41 41 obj-$(CONFIG_SND_SOC) += spear/ 42 42 obj-$(CONFIG_SND_SOC) += sti/ 43 + obj-$(CONFIG_SND_SOC) += sunxi/ 43 44 obj-$(CONFIG_SND_SOC) += tegra/ 44 45 obj-$(CONFIG_SND_SOC) += txx9/ 45 46 obj-$(CONFIG_SND_SOC) += ux500/
+1
sound/soc/atmel/atmel_wm8904.c
··· 176 176 { .compatible = "atmel,asoc-wm8904", }, 177 177 { } 178 178 }; 179 + MODULE_DEVICE_TABLE(of, atmel_asoc_wm8904_dt_ids); 179 180 #endif 180 181 181 182 static struct platform_driver atmel_asoc_wm8904_driver = {
+1 -9
sound/soc/au1x/db1000.c
··· 38 38 { 39 39 struct snd_soc_card *card = &db1000_ac97; 40 40 card->dev = &pdev->dev; 41 - return snd_soc_register_card(card); 42 - } 43 - 44 - static int db1000_audio_remove(struct platform_device *pdev) 45 - { 46 - struct snd_soc_card *card = platform_get_drvdata(pdev); 47 - snd_soc_unregister_card(card); 48 - return 0; 41 + return devm_snd_soc_register_card(&pdev->dev, card); 49 42 } 50 43 51 44 static struct platform_driver db1000_audio_driver = { ··· 47 54 .pm = &snd_soc_pm_ops, 48 55 }, 49 56 .probe = db1000_audio_probe, 50 - .remove = db1000_audio_remove, 51 57 }; 52 58 53 59 module_platform_driver(db1000_audio_driver);
+1 -9
sound/soc/au1x/db1200.c
··· 174 174 175 175 card = db1200_cards[pid->driver_data]; 176 176 card->dev = &pdev->dev; 177 - return snd_soc_register_card(card); 178 - } 179 - 180 - static int db1200_audio_remove(struct platform_device *pdev) 181 - { 182 - struct snd_soc_card *card = platform_get_drvdata(pdev); 183 - snd_soc_unregister_card(card); 184 - return 0; 177 + return devm_snd_soc_register_card(&pdev->dev, card); 185 178 } 186 179 187 180 static struct platform_driver db1200_audio_driver = { ··· 184 191 }, 185 192 .id_table = db1200_pids, 186 193 .probe = db1200_audio_probe, 187 - .remove = db1200_audio_remove, 188 194 }; 189 195 190 196 module_platform_driver(db1200_audio_driver);
-1
sound/soc/au1x/psc-i2s.c
··· 296 296 { 297 297 struct resource *iores, *dmares; 298 298 unsigned long sel; 299 - int ret; 300 299 struct au1xpsc_audio_data *wd; 301 300 302 301 wd = devm_kzalloc(&pdev->dev, sizeof(struct au1xpsc_audio_data),
+1 -10
sound/soc/blackfin/bf5xx-ad1836.c
··· 87 87 card->dev = &pdev->dev; 88 88 platform_set_drvdata(pdev, card); 89 89 90 - ret = snd_soc_register_card(card); 90 + ret = devm_snd_soc_register_card(&pdev->dev, card); 91 91 if (ret) 92 92 dev_err(&pdev->dev, "Failed to register card\n"); 93 93 return ret; 94 - } 95 - 96 - static int bf5xx_ad1836_driver_remove(struct platform_device *pdev) 97 - { 98 - struct snd_soc_card *card = platform_get_drvdata(pdev); 99 - 100 - snd_soc_unregister_card(card); 101 - return 0; 102 94 } 103 95 104 96 static struct platform_driver bf5xx_ad1836_driver = { ··· 99 107 .pm = &snd_soc_pm_ops, 100 108 }, 101 109 .probe = bf5xx_ad1836_driver_probe, 102 - .remove = bf5xx_ad1836_driver_remove, 103 110 }; 104 111 module_platform_driver(bf5xx_ad1836_driver); 105 112
+1 -11
sound/soc/blackfin/bfin-eval-adau1373.c
··· 154 154 155 155 card->dev = &pdev->dev; 156 156 157 - return snd_soc_register_card(&bfin_eval_adau1373); 158 - } 159 - 160 - static int bfin_eval_adau1373_remove(struct platform_device *pdev) 161 - { 162 - struct snd_soc_card *card = platform_get_drvdata(pdev); 163 - 164 - snd_soc_unregister_card(card); 165 - 166 - return 0; 157 + return devm_snd_soc_register_card(&pdev->dev, &bfin_eval_adau1373); 167 158 } 168 159 169 160 static struct platform_driver bfin_eval_adau1373_driver = { ··· 163 172 .pm = &snd_soc_pm_ops, 164 173 }, 165 174 .probe = bfin_eval_adau1373_probe, 166 - .remove = bfin_eval_adau1373_remove, 167 175 }; 168 176 169 177 module_platform_driver(bfin_eval_adau1373_driver);
+1 -11
sound/soc/blackfin/bfin-eval-adau1701.c
··· 94 94 95 95 card->dev = &pdev->dev; 96 96 97 - return snd_soc_register_card(&bfin_eval_adau1701); 98 - } 99 - 100 - static int bfin_eval_adau1701_remove(struct platform_device *pdev) 101 - { 102 - struct snd_soc_card *card = platform_get_drvdata(pdev); 103 - 104 - snd_soc_unregister_card(card); 105 - 106 - return 0; 97 + return devm_snd_soc_register_card(&pdev->dev, &bfin_eval_adau1701); 107 98 } 108 99 109 100 static struct platform_driver bfin_eval_adau1701_driver = { ··· 103 112 .pm = &snd_soc_pm_ops, 104 113 }, 105 114 .probe = bfin_eval_adau1701_probe, 106 - .remove = bfin_eval_adau1701_remove, 107 115 }; 108 116 109 117 module_platform_driver(bfin_eval_adau1701_driver);
+1 -11
sound/soc/blackfin/bfin-eval-adav80x.c
··· 119 119 120 120 card->dev = &pdev->dev; 121 121 122 - return snd_soc_register_card(&bfin_eval_adav80x); 123 - } 124 - 125 - static int bfin_eval_adav80x_remove(struct platform_device *pdev) 126 - { 127 - struct snd_soc_card *card = platform_get_drvdata(pdev); 128 - 129 - snd_soc_unregister_card(card); 130 - 131 - return 0; 122 + return devm_snd_soc_register_card(&pdev->dev, &bfin_eval_adav80x); 132 123 } 133 124 134 125 static const struct platform_device_id bfin_eval_adav80x_ids[] = { ··· 135 144 .pm = &snd_soc_pm_ops, 136 145 }, 137 146 .probe = bfin_eval_adav80x_probe, 138 - .remove = bfin_eval_adav80x_remove, 139 147 .id_table = bfin_eval_adav80x_ids, 140 148 }; 141 149
+5 -4
sound/soc/codecs/Kconfig
··· 36 36 select SND_SOC_AK4104 if SPI_MASTER 37 37 select SND_SOC_AK4535 if I2C 38 38 select SND_SOC_AK4554 39 + select SND_SOC_AK4613 if I2C 39 40 select SND_SOC_AK4641 if I2C 40 41 select SND_SOC_AK4642 if I2C 41 42 select SND_SOC_AK4671 if I2C ··· 80 79 select SND_SOC_MAX9877 if I2C 81 80 select SND_SOC_MC13783 if MFD_MC13XXX 82 81 select SND_SOC_ML26124 if I2C 83 - select SND_SOC_HDMI_CODEC 84 82 select SND_SOC_PCM1681 if I2C 85 83 select SND_SOC_PCM1792A if SPI_MASTER 86 84 select SND_SOC_PCM3008 ··· 319 319 config SND_SOC_AK4554 320 320 tristate "AKM AK4554 CODEC" 321 321 322 + config SND_SOC_AK4613 323 + tristate "AKM AK4613 CODEC" 324 + depends on I2C 325 + 322 326 config SND_SOC_AK4641 323 327 tristate 324 328 ··· 445 441 446 442 config SND_SOC_DMIC 447 443 tristate 448 - 449 - config SND_SOC_HDMI_CODEC 450 - tristate "HDMI stub CODEC" 451 444 452 445 config SND_SOC_ES8328 453 446 tristate "Everest Semi ES8328 CODEC"
+2 -2
sound/soc/codecs/Makefile
··· 26 26 snd-soc-ak4104-objs := ak4104.o 27 27 snd-soc-ak4535-objs := ak4535.o 28 28 snd-soc-ak4554-objs := ak4554.o 29 + snd-soc-ak4613-objs := ak4613.o 29 30 snd-soc-ak4641-objs := ak4641.o 30 31 snd-soc-ak4642-objs := ak4642.o 31 32 snd-soc-ak4671-objs := ak4671.o ··· 73 72 snd-soc-max9850-objs := max9850.o 74 73 snd-soc-mc13783-objs := mc13783.o 75 74 snd-soc-ml26124-objs := ml26124.o 76 - snd-soc-hdmi-codec-objs := hdmi.o 77 75 snd-soc-pcm1681-objs := pcm1681.o 78 76 snd-soc-pcm1792a-codec-objs := pcm1792a.o 79 77 snd-soc-pcm3008-objs := pcm3008.o ··· 216 216 obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o 217 217 obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 218 218 obj-$(CONFIG_SND_SOC_AK4554) += snd-soc-ak4554.o 219 + obj-$(CONFIG_SND_SOC_AK4613) += snd-soc-ak4613.o 219 220 obj-$(CONFIG_SND_SOC_AK4641) += snd-soc-ak4641.o 220 221 obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o 221 222 obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o ··· 265 264 obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o 266 265 obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o 267 266 obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o 268 - obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o 269 267 obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o 270 268 obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o 271 269 obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
+497
sound/soc/codecs/ak4613.c
··· 1 + /* 2 + * ak4613.c -- Asahi Kasei ALSA Soc Audio driver 3 + * 4 + * Copyright (C) 2015 Renesas Electronics Corporation 5 + * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 + * 7 + * Based on ak4642.c by Kuninori Morimoto 8 + * Based on wm8731.c by Richard Purdie 9 + * Based on ak4535.c by Richard Purdie 10 + * Based on wm8753.c by Liam Girdwood 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License version 2 as 14 + * published by the Free Software Foundation. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/i2c.h> 19 + #include <linux/slab.h> 20 + #include <linux/of_device.h> 21 + #include <linux/module.h> 22 + #include <linux/regmap.h> 23 + #include <sound/soc.h> 24 + #include <sound/pcm_params.h> 25 + #include <sound/tlv.h> 26 + 27 + #define PW_MGMT1 0x00 /* Power Management 1 */ 28 + #define PW_MGMT2 0x01 /* Power Management 2 */ 29 + #define PW_MGMT3 0x02 /* Power Management 3 */ 30 + #define CTRL1 0x03 /* Control 1 */ 31 + #define CTRL2 0x04 /* Control 2 */ 32 + #define DEMP1 0x05 /* De-emphasis1 */ 33 + #define DEMP2 0x06 /* De-emphasis2 */ 34 + #define OFD 0x07 /* Overflow Detect */ 35 + #define ZRD 0x08 /* Zero Detect */ 36 + #define ICTRL 0x09 /* Input Control */ 37 + #define OCTRL 0x0a /* Output Control */ 38 + #define LOUT1 0x0b /* LOUT1 Volume Control */ 39 + #define ROUT1 0x0c /* ROUT1 Volume Control */ 40 + #define LOUT2 0x0d /* LOUT2 Volume Control */ 41 + #define ROUT2 0x0e /* ROUT2 Volume Control */ 42 + #define LOUT3 0x0f /* LOUT3 Volume Control */ 43 + #define ROUT3 0x10 /* ROUT3 Volume Control */ 44 + #define LOUT4 0x11 /* LOUT4 Volume Control */ 45 + #define ROUT4 0x12 /* ROUT4 Volume Control */ 46 + #define LOUT5 0x13 /* LOUT5 Volume Control */ 47 + #define ROUT5 0x14 /* ROUT5 Volume Control */ 48 + #define LOUT6 0x15 /* LOUT6 Volume Control */ 49 + #define ROUT6 0x16 /* ROUT6 Volume Control */ 50 + 51 + /* PW_MGMT1 */ 52 + #define RSTN BIT(0) 53 + #define PMDAC BIT(1) 54 + #define PMADC BIT(2) 55 + #define PMVR BIT(3) 56 + 57 + /* PW_MGMT2 */ 58 + #define PMAD_ALL 0x7 59 + 60 + /* PW_MGMT3 */ 61 + #define PMDA_ALL 0x3f 62 + 63 + /* CTRL1 */ 64 + #define DIF0 BIT(3) 65 + #define DIF1 BIT(4) 66 + #define DIF2 BIT(5) 67 + #define TDM0 BIT(6) 68 + #define TDM1 BIT(7) 69 + #define NO_FMT (0xff) 70 + #define FMT_MASK (0xf8) 71 + 72 + /* CTRL2 */ 73 + #define DFS_NORMAL_SPEED (0 << 2) 74 + #define DFS_DOUBLE_SPEED (1 << 2) 75 + #define DFS_QUAD_SPEED (2 << 2) 76 + 77 + struct ak4613_priv { 78 + struct mutex lock; 79 + 80 + unsigned int fmt; 81 + u8 fmt_ctrl; 82 + int cnt; 83 + }; 84 + 85 + struct ak4613_formats { 86 + unsigned int width; 87 + unsigned int fmt; 88 + }; 89 + 90 + struct ak4613_interface { 91 + struct ak4613_formats capture; 92 + struct ak4613_formats playback; 93 + }; 94 + 95 + /* 96 + * Playback Volume 97 + * 98 + * max : 0x00 : 0 dB 99 + * ( 0.5 dB step ) 100 + * min : 0xFE : -127.0 dB 101 + * mute: 0xFF 102 + */ 103 + static const DECLARE_TLV_DB_SCALE(out_tlv, -12750, 50, 1); 104 + 105 + static const struct snd_kcontrol_new ak4613_snd_controls[] = { 106 + SOC_DOUBLE_R_TLV("Digital Playback Volume1", LOUT1, ROUT1, 107 + 0, 0xFF, 1, out_tlv), 108 + SOC_DOUBLE_R_TLV("Digital Playback Volume2", LOUT2, ROUT2, 109 + 0, 0xFF, 1, out_tlv), 110 + SOC_DOUBLE_R_TLV("Digital Playback Volume3", LOUT3, ROUT3, 111 + 0, 0xFF, 1, out_tlv), 112 + SOC_DOUBLE_R_TLV("Digital Playback Volume4", LOUT4, ROUT4, 113 + 0, 0xFF, 1, out_tlv), 114 + SOC_DOUBLE_R_TLV("Digital Playback Volume5", LOUT5, ROUT5, 115 + 0, 0xFF, 1, out_tlv), 116 + SOC_DOUBLE_R_TLV("Digital Playback Volume6", LOUT6, ROUT6, 117 + 0, 0xFF, 1, out_tlv), 118 + }; 119 + 120 + static const struct reg_default ak4613_reg[] = { 121 + { 0x0, 0x0f }, { 0x1, 0x07 }, { 0x2, 0x3f }, { 0x3, 0x20 }, 122 + { 0x4, 0x20 }, { 0x5, 0x55 }, { 0x6, 0x05 }, { 0x7, 0x07 }, 123 + { 0x8, 0x0f }, { 0x9, 0x07 }, { 0xa, 0x3f }, { 0xb, 0x00 }, 124 + { 0xc, 0x00 }, { 0xd, 0x00 }, { 0xe, 0x00 }, { 0xf, 0x00 }, 125 + { 0x10, 0x00 }, { 0x11, 0x00 }, { 0x12, 0x00 }, { 0x13, 0x00 }, 126 + { 0x14, 0x00 }, { 0x15, 0x00 }, { 0x16, 0x00 }, 127 + }; 128 + 129 + #define AUDIO_IFACE_IDX_TO_VAL(i) (i << 3) 130 + #define AUDIO_IFACE(b, fmt) { b, SND_SOC_DAIFMT_##fmt } 131 + static const struct ak4613_interface ak4613_iface[] = { 132 + /* capture */ /* playback */ 133 + [0] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(16, RIGHT_J) }, 134 + [1] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(20, RIGHT_J) }, 135 + [2] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(24, RIGHT_J) }, 136 + [3] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(24, LEFT_J) }, 137 + [4] = { AUDIO_IFACE(24, I2S), AUDIO_IFACE(24, I2S) }, 138 + }; 139 + 140 + static const struct regmap_config ak4613_regmap_cfg = { 141 + .reg_bits = 8, 142 + .val_bits = 8, 143 + .max_register = 0x16, 144 + .reg_defaults = ak4613_reg, 145 + .num_reg_defaults = ARRAY_SIZE(ak4613_reg), 146 + }; 147 + 148 + static const struct of_device_id ak4613_of_match[] = { 149 + { .compatible = "asahi-kasei,ak4613", .data = &ak4613_regmap_cfg }, 150 + {}, 151 + }; 152 + MODULE_DEVICE_TABLE(of, ak4613_of_match); 153 + 154 + static const struct i2c_device_id ak4613_i2c_id[] = { 155 + { "ak4613", (kernel_ulong_t)&ak4613_regmap_cfg }, 156 + { } 157 + }; 158 + MODULE_DEVICE_TABLE(i2c, ak4613_i2c_id); 159 + 160 + static const struct snd_soc_dapm_widget ak4613_dapm_widgets[] = { 161 + 162 + /* Outputs */ 163 + SND_SOC_DAPM_OUTPUT("LOUT1"), 164 + SND_SOC_DAPM_OUTPUT("LOUT2"), 165 + SND_SOC_DAPM_OUTPUT("LOUT3"), 166 + SND_SOC_DAPM_OUTPUT("LOUT4"), 167 + SND_SOC_DAPM_OUTPUT("LOUT5"), 168 + SND_SOC_DAPM_OUTPUT("LOUT6"), 169 + 170 + SND_SOC_DAPM_OUTPUT("ROUT1"), 171 + SND_SOC_DAPM_OUTPUT("ROUT2"), 172 + SND_SOC_DAPM_OUTPUT("ROUT3"), 173 + SND_SOC_DAPM_OUTPUT("ROUT4"), 174 + SND_SOC_DAPM_OUTPUT("ROUT5"), 175 + SND_SOC_DAPM_OUTPUT("ROUT6"), 176 + 177 + /* Inputs */ 178 + SND_SOC_DAPM_INPUT("LIN1"), 179 + SND_SOC_DAPM_INPUT("LIN2"), 180 + 181 + SND_SOC_DAPM_INPUT("RIN1"), 182 + SND_SOC_DAPM_INPUT("RIN2"), 183 + 184 + /* DAC */ 185 + SND_SOC_DAPM_DAC("DAC1", NULL, PW_MGMT3, 0, 0), 186 + SND_SOC_DAPM_DAC("DAC2", NULL, PW_MGMT3, 1, 0), 187 + SND_SOC_DAPM_DAC("DAC3", NULL, PW_MGMT3, 2, 0), 188 + SND_SOC_DAPM_DAC("DAC4", NULL, PW_MGMT3, 3, 0), 189 + SND_SOC_DAPM_DAC("DAC5", NULL, PW_MGMT3, 4, 0), 190 + SND_SOC_DAPM_DAC("DAC6", NULL, PW_MGMT3, 5, 0), 191 + 192 + /* ADC */ 193 + SND_SOC_DAPM_ADC("ADC1", NULL, PW_MGMT2, 0, 0), 194 + SND_SOC_DAPM_ADC("ADC2", NULL, PW_MGMT2, 1, 0), 195 + }; 196 + 197 + static const struct snd_soc_dapm_route ak4613_intercon[] = { 198 + {"LOUT1", NULL, "DAC1"}, 199 + {"LOUT2", NULL, "DAC2"}, 200 + {"LOUT3", NULL, "DAC3"}, 201 + {"LOUT4", NULL, "DAC4"}, 202 + {"LOUT5", NULL, "DAC5"}, 203 + {"LOUT6", NULL, "DAC6"}, 204 + 205 + {"ROUT1", NULL, "DAC1"}, 206 + {"ROUT2", NULL, "DAC2"}, 207 + {"ROUT3", NULL, "DAC3"}, 208 + {"ROUT4", NULL, "DAC4"}, 209 + {"ROUT5", NULL, "DAC5"}, 210 + {"ROUT6", NULL, "DAC6"}, 211 + 212 + {"DAC1", NULL, "Playback"}, 213 + {"DAC2", NULL, "Playback"}, 214 + {"DAC3", NULL, "Playback"}, 215 + {"DAC4", NULL, "Playback"}, 216 + {"DAC5", NULL, "Playback"}, 217 + {"DAC6", NULL, "Playback"}, 218 + 219 + {"Capture", NULL, "ADC1"}, 220 + {"Capture", NULL, "ADC2"}, 221 + 222 + {"ADC1", NULL, "LIN1"}, 223 + {"ADC2", NULL, "LIN2"}, 224 + 225 + {"ADC1", NULL, "RIN1"}, 226 + {"ADC2", NULL, "RIN2"}, 227 + }; 228 + 229 + static void ak4613_dai_shutdown(struct snd_pcm_substream *substream, 230 + struct snd_soc_dai *dai) 231 + { 232 + struct snd_soc_codec *codec = dai->codec; 233 + struct ak4613_priv *priv = snd_soc_codec_get_drvdata(codec); 234 + struct device *dev = codec->dev; 235 + 236 + mutex_lock(&priv->lock); 237 + priv->cnt--; 238 + if (priv->cnt < 0) { 239 + dev_err(dev, "unexpected counter error\n"); 240 + priv->cnt = 0; 241 + } 242 + if (!priv->cnt) 243 + priv->fmt_ctrl = NO_FMT; 244 + mutex_unlock(&priv->lock); 245 + } 246 + 247 + static int ak4613_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 248 + { 249 + struct snd_soc_codec *codec = dai->codec; 250 + struct ak4613_priv *priv = snd_soc_codec_get_drvdata(codec); 251 + 252 + fmt &= SND_SOC_DAIFMT_FORMAT_MASK; 253 + 254 + switch (fmt) { 255 + case SND_SOC_DAIFMT_RIGHT_J: 256 + case SND_SOC_DAIFMT_LEFT_J: 257 + case SND_SOC_DAIFMT_I2S: 258 + priv->fmt = fmt; 259 + 260 + break; 261 + default: 262 + return -EINVAL; 263 + } 264 + 265 + return 0; 266 + } 267 + 268 + static int ak4613_dai_hw_params(struct snd_pcm_substream *substream, 269 + struct snd_pcm_hw_params *params, 270 + struct snd_soc_dai *dai) 271 + { 272 + struct snd_soc_codec *codec = dai->codec; 273 + struct ak4613_priv *priv = snd_soc_codec_get_drvdata(codec); 274 + const struct ak4613_formats *fmts; 275 + struct device *dev = codec->dev; 276 + unsigned int width = params_width(params); 277 + unsigned int fmt = priv->fmt; 278 + unsigned int rate; 279 + int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 280 + int i, ret; 281 + u8 fmt_ctrl, ctrl2; 282 + 283 + rate = params_rate(params); 284 + switch (rate) { 285 + case 32000: 286 + case 44100: 287 + case 48000: 288 + ctrl2 = DFS_NORMAL_SPEED; 289 + break; 290 + case 88200: 291 + case 96000: 292 + ctrl2 = DFS_DOUBLE_SPEED; 293 + break; 294 + case 176400: 295 + case 192000: 296 + ctrl2 = DFS_QUAD_SPEED; 297 + break; 298 + default: 299 + return -EINVAL; 300 + } 301 + 302 + /* 303 + * FIXME 304 + * 305 + * It doesn't support TDM at this point 306 + */ 307 + fmt_ctrl = NO_FMT; 308 + for (i = 0; i < ARRAY_SIZE(ak4613_iface); i++) { 309 + fmts = (is_play) ? &ak4613_iface[i].playback : 310 + &ak4613_iface[i].capture; 311 + 312 + if (fmts->fmt != fmt) 313 + continue; 314 + 315 + if (fmt == SND_SOC_DAIFMT_RIGHT_J) { 316 + if (fmts->width != width) 317 + continue; 318 + } else { 319 + if (fmts->width < width) 320 + continue; 321 + } 322 + 323 + fmt_ctrl = AUDIO_IFACE_IDX_TO_VAL(i); 324 + break; 325 + } 326 + 327 + ret = -EINVAL; 328 + if (fmt_ctrl == NO_FMT) 329 + goto hw_params_end; 330 + 331 + mutex_lock(&priv->lock); 332 + if ((priv->fmt_ctrl == NO_FMT) || 333 + (priv->fmt_ctrl == fmt_ctrl)) { 334 + priv->fmt_ctrl = fmt_ctrl; 335 + priv->cnt++; 336 + ret = 0; 337 + } 338 + mutex_unlock(&priv->lock); 339 + 340 + if (ret < 0) 341 + goto hw_params_end; 342 + 343 + snd_soc_update_bits(codec, CTRL1, FMT_MASK, fmt_ctrl); 344 + snd_soc_write(codec, CTRL2, ctrl2); 345 + 346 + hw_params_end: 347 + if (ret < 0) 348 + dev_warn(dev, "unsupported data width/format combination\n"); 349 + 350 + return ret; 351 + } 352 + 353 + static int ak4613_set_bias_level(struct snd_soc_codec *codec, 354 + enum snd_soc_bias_level level) 355 + { 356 + u8 mgmt1 = 0; 357 + 358 + switch (level) { 359 + case SND_SOC_BIAS_ON: 360 + mgmt1 |= RSTN; 361 + /* fall through */ 362 + case SND_SOC_BIAS_PREPARE: 363 + mgmt1 |= PMADC | PMDAC; 364 + /* fall through */ 365 + case SND_SOC_BIAS_STANDBY: 366 + mgmt1 |= PMVR; 367 + /* fall through */ 368 + case SND_SOC_BIAS_OFF: 369 + default: 370 + break; 371 + } 372 + 373 + snd_soc_write(codec, PW_MGMT1, mgmt1); 374 + 375 + return 0; 376 + } 377 + 378 + static const struct snd_soc_dai_ops ak4613_dai_ops = { 379 + .shutdown = ak4613_dai_shutdown, 380 + .set_fmt = ak4613_dai_set_fmt, 381 + .hw_params = ak4613_dai_hw_params, 382 + }; 383 + 384 + #define AK4613_PCM_RATE (SNDRV_PCM_RATE_32000 |\ 385 + SNDRV_PCM_RATE_44100 |\ 386 + SNDRV_PCM_RATE_48000 |\ 387 + SNDRV_PCM_RATE_64000 |\ 388 + SNDRV_PCM_RATE_88200 |\ 389 + SNDRV_PCM_RATE_96000 |\ 390 + SNDRV_PCM_RATE_176400 |\ 391 + SNDRV_PCM_RATE_192000) 392 + #define AK4613_PCM_FMTBIT (SNDRV_PCM_FMTBIT_S16_LE |\ 393 + SNDRV_PCM_FMTBIT_S24_LE) 394 + 395 + static struct snd_soc_dai_driver ak4613_dai = { 396 + .name = "ak4613-hifi", 397 + .playback = { 398 + .stream_name = "Playback", 399 + .channels_min = 2, 400 + .channels_max = 2, 401 + .rates = AK4613_PCM_RATE, 402 + .formats = AK4613_PCM_FMTBIT, 403 + }, 404 + .capture = { 405 + .stream_name = "Capture", 406 + .channels_min = 2, 407 + .channels_max = 2, 408 + .rates = AK4613_PCM_RATE, 409 + .formats = AK4613_PCM_FMTBIT, 410 + }, 411 + .ops = &ak4613_dai_ops, 412 + .symmetric_rates = 1, 413 + }; 414 + 415 + static int ak4613_resume(struct snd_soc_codec *codec) 416 + { 417 + struct regmap *regmap = dev_get_regmap(codec->dev, NULL); 418 + 419 + regcache_mark_dirty(regmap); 420 + return regcache_sync(regmap); 421 + } 422 + 423 + static struct snd_soc_codec_driver soc_codec_dev_ak4613 = { 424 + .resume = ak4613_resume, 425 + .set_bias_level = ak4613_set_bias_level, 426 + .controls = ak4613_snd_controls, 427 + .num_controls = ARRAY_SIZE(ak4613_snd_controls), 428 + .dapm_widgets = ak4613_dapm_widgets, 429 + .num_dapm_widgets = ARRAY_SIZE(ak4613_dapm_widgets), 430 + .dapm_routes = ak4613_intercon, 431 + .num_dapm_routes = ARRAY_SIZE(ak4613_intercon), 432 + }; 433 + 434 + static int ak4613_i2c_probe(struct i2c_client *i2c, 435 + const struct i2c_device_id *id) 436 + { 437 + struct device *dev = &i2c->dev; 438 + struct device_node *np = dev->of_node; 439 + const struct regmap_config *regmap_cfg; 440 + struct regmap *regmap; 441 + struct ak4613_priv *priv; 442 + 443 + regmap_cfg = NULL; 444 + if (np) { 445 + const struct of_device_id *of_id; 446 + 447 + of_id = of_match_device(ak4613_of_match, dev); 448 + if (of_id) 449 + regmap_cfg = of_id->data; 450 + } else { 451 + regmap_cfg = (const struct regmap_config *)id->driver_data; 452 + } 453 + 454 + if (!regmap_cfg) 455 + return -EINVAL; 456 + 457 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 458 + if (!priv) 459 + return -ENOMEM; 460 + 461 + priv->fmt_ctrl = NO_FMT; 462 + priv->cnt = 0; 463 + 464 + mutex_init(&priv->lock); 465 + 466 + i2c_set_clientdata(i2c, priv); 467 + 468 + regmap = devm_regmap_init_i2c(i2c, regmap_cfg); 469 + if (IS_ERR(regmap)) 470 + return PTR_ERR(regmap); 471 + 472 + return snd_soc_register_codec(dev, &soc_codec_dev_ak4613, 473 + &ak4613_dai, 1); 474 + } 475 + 476 + static int ak4613_i2c_remove(struct i2c_client *client) 477 + { 478 + snd_soc_unregister_codec(&client->dev); 479 + return 0; 480 + } 481 + 482 + static struct i2c_driver ak4613_i2c_driver = { 483 + .driver = { 484 + .name = "ak4613-codec", 485 + .owner = THIS_MODULE, 486 + .of_match_table = ak4613_of_match, 487 + }, 488 + .probe = ak4613_i2c_probe, 489 + .remove = ak4613_i2c_remove, 490 + .id_table = ak4613_i2c_id, 491 + }; 492 + 493 + module_i2c_driver(ak4613_i2c_driver); 494 + 495 + MODULE_DESCRIPTION("Soc AK4613 driver"); 496 + MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); 497 + MODULE_LICENSE("GPL v2");
+100 -53
sound/soc/codecs/ak4642.c
··· 23 23 * AK4648 is tested. 24 24 */ 25 25 26 + #include <linux/clk.h> 27 + #include <linux/clk-provider.h> 26 28 #include <linux/delay.h> 27 29 #include <linux/i2c.h> 28 30 #include <linux/slab.h> ··· 130 128 #define I2S (3 << 0) 131 129 132 130 /* MD_CTL2 */ 133 - #define FS0 (1 << 0) 134 - #define FS1 (1 << 1) 135 - #define FS2 (1 << 2) 136 - #define FS3 (1 << 5) 137 - #define FS_MASK (FS0 | FS1 | FS2 | FS3) 131 + #define FSs(val) (((val & 0x7) << 0) | ((val & 0x8) << 2)) 132 + #define PSs(val) ((val & 0x3) << 6) 138 133 139 134 /* MD_CTL3 */ 140 135 #define BST1 (1 << 3) ··· 146 147 147 148 struct ak4642_priv { 148 149 const struct ak4642_drvdata *drvdata; 150 + struct clk *mcko; 149 151 }; 150 152 151 153 /* ··· 430 430 return 0; 431 431 } 432 432 433 + static int ak4642_set_mcko(struct snd_soc_codec *codec, 434 + u32 frequency) 435 + { 436 + u32 fs_list[] = { 437 + [0] = 8000, 438 + [1] = 12000, 439 + [2] = 16000, 440 + [3] = 24000, 441 + [4] = 7350, 442 + [5] = 11025, 443 + [6] = 14700, 444 + [7] = 22050, 445 + [10] = 32000, 446 + [11] = 48000, 447 + [14] = 29400, 448 + [15] = 44100, 449 + }; 450 + u32 ps_list[] = { 451 + [0] = 256, 452 + [1] = 128, 453 + [2] = 64, 454 + [3] = 32 455 + }; 456 + int ps, fs; 457 + 458 + for (ps = 0; ps < ARRAY_SIZE(ps_list); ps++) { 459 + for (fs = 0; fs < ARRAY_SIZE(fs_list); fs++) { 460 + if (frequency == ps_list[ps] * fs_list[fs]) { 461 + snd_soc_write(codec, MD_CTL2, 462 + PSs(ps) | FSs(fs)); 463 + return 0; 464 + } 465 + } 466 + } 467 + 468 + return 0; 469 + } 470 + 433 471 static int ak4642_dai_hw_params(struct snd_pcm_substream *substream, 434 472 struct snd_pcm_hw_params *params, 435 473 struct snd_soc_dai *dai) 436 474 { 437 475 struct snd_soc_codec *codec = dai->codec; 438 - u8 rate; 476 + struct ak4642_priv *priv = snd_soc_codec_get_drvdata(codec); 477 + u32 rate = clk_get_rate(priv->mcko); 439 478 440 - switch (params_rate(params)) { 441 - case 7350: 442 - rate = FS2; 443 - break; 444 - case 8000: 445 - rate = 0; 446 - break; 447 - case 11025: 448 - rate = FS2 | FS0; 449 - break; 450 - case 12000: 451 - rate = FS0; 452 - break; 453 - case 14700: 454 - rate = FS2 | FS1; 455 - break; 456 - case 16000: 457 - rate = FS1; 458 - break; 459 - case 22050: 460 - rate = FS2 | FS1 | FS0; 461 - break; 462 - case 24000: 463 - rate = FS1 | FS0; 464 - break; 465 - case 29400: 466 - rate = FS3 | FS2 | FS1; 467 - break; 468 - case 32000: 469 - rate = FS3 | FS1; 470 - break; 471 - case 44100: 472 - rate = FS3 | FS2 | FS1 | FS0; 473 - break; 474 - case 48000: 475 - rate = FS3 | FS1 | FS0; 476 - break; 477 - default: 478 - return -EINVAL; 479 - } 480 - snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate); 479 + if (!rate) 480 + rate = params_rate(params) * 256; 481 481 482 - return 0; 482 + return ak4642_set_mcko(codec, rate); 483 483 } 484 484 485 485 static int ak4642_set_bias_level(struct snd_soc_codec *codec, ··· 532 532 return 0; 533 533 } 534 534 535 + static int ak4642_probe(struct snd_soc_codec *codec) 536 + { 537 + struct ak4642_priv *priv = snd_soc_codec_get_drvdata(codec); 538 + 539 + if (priv->mcko) 540 + ak4642_set_mcko(codec, clk_get_rate(priv->mcko)); 541 + 542 + return 0; 543 + } 544 + 535 545 static struct snd_soc_codec_driver soc_codec_dev_ak4642 = { 546 + .probe = ak4642_probe, 536 547 .resume = ak4642_resume, 537 548 .set_bias_level = ak4642_set_bias_level, 538 549 .controls = ak4642_snd_controls, ··· 591 580 .extended_frequencies = 1, 592 581 }; 593 582 583 + #ifdef CONFIG_COMMON_CLK 584 + static struct clk *ak4642_of_parse_mcko(struct device *dev) 585 + { 586 + struct device_node *np = dev->of_node; 587 + struct clk *clk; 588 + const char *clk_name = np->name; 589 + const char *parent_clk_name = NULL; 590 + u32 rate; 591 + 592 + if (of_property_read_u32(np, "clock-frequency", &rate)) 593 + return NULL; 594 + 595 + if (of_property_read_bool(np, "clocks")) 596 + parent_clk_name = of_clk_get_parent_name(np, 0); 597 + 598 + of_property_read_string(np, "clock-output-names", &clk_name); 599 + 600 + clk = clk_register_fixed_rate(dev, clk_name, parent_clk_name, 601 + (parent_clk_name) ? 0 : CLK_IS_ROOT, 602 + rate); 603 + if (!IS_ERR(clk)) 604 + of_clk_add_provider(np, of_clk_src_simple_get, clk); 605 + 606 + return clk; 607 + } 608 + #else 609 + #define ak4642_of_parse_mcko(d) 0 610 + #endif 611 + 594 612 static const struct of_device_id ak4642_of_match[]; 595 613 static int ak4642_i2c_probe(struct i2c_client *i2c, 596 614 const struct i2c_device_id *id) 597 615 { 598 - struct device_node *np = i2c->dev.of_node; 616 + struct device *dev = &i2c->dev; 617 + struct device_node *np = dev->of_node; 599 618 const struct ak4642_drvdata *drvdata = NULL; 600 619 struct regmap *regmap; 601 620 struct ak4642_priv *priv; 621 + struct clk *mcko = NULL; 602 622 603 623 if (np) { 604 624 const struct of_device_id *of_id; 605 625 606 - of_id = of_match_device(ak4642_of_match, &i2c->dev); 626 + mcko = ak4642_of_parse_mcko(dev); 627 + if (IS_ERR(mcko)) 628 + mcko = NULL; 629 + 630 + of_id = of_match_device(ak4642_of_match, dev); 607 631 if (of_id) 608 632 drvdata = of_id->data; 609 633 } else { ··· 646 600 } 647 601 648 602 if (!drvdata) { 649 - dev_err(&i2c->dev, "Unknown device type\n"); 603 + dev_err(dev, "Unknown device type\n"); 650 604 return -EINVAL; 651 605 } 652 606 653 - priv = devm_kzalloc(&i2c->dev, sizeof(*priv), GFP_KERNEL); 607 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 654 608 if (!priv) 655 609 return -ENOMEM; 656 610 657 611 priv->drvdata = drvdata; 612 + priv->mcko = mcko; 658 613 659 614 i2c_set_clientdata(i2c, priv); 660 615 ··· 663 616 if (IS_ERR(regmap)) 664 617 return PTR_ERR(regmap); 665 618 666 - return snd_soc_register_codec(&i2c->dev, 619 + return snd_soc_register_codec(dev, 667 620 &soc_codec_dev_ak4642, &ak4642_dai, 1); 668 621 } 669 622
+16
sound/soc/codecs/arizona.c
··· 147 147 0x4f5, 0x0da); 148 148 } 149 149 break; 150 + default: 151 + break; 150 152 } 151 153 152 154 return 0; ··· 691 689 ARIZONA_IN_VU, val); 692 690 } 693 691 692 + bool arizona_input_analog(struct snd_soc_codec *codec, int shift) 693 + { 694 + unsigned int reg = ARIZONA_IN1L_CONTROL + ((shift / 2) * 8); 695 + unsigned int val = snd_soc_read(codec, reg); 696 + 697 + return !(val & ARIZONA_IN1_MODE_MASK); 698 + } 699 + EXPORT_SYMBOL_GPL(arizona_input_analog); 700 + 694 701 int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, 695 702 int event) 696 703 { ··· 736 725 reg = snd_soc_read(codec, ARIZONA_INPUT_ENABLES); 737 726 if (reg == 0) 738 727 arizona_in_set_vu(codec, 0); 728 + break; 729 + default: 730 + break; 739 731 } 740 732 741 733 return 0; ··· 819 805 default: 820 806 break; 821 807 } 808 + break; 809 + default: 822 810 break; 823 811 } 824 812
+2
sound/soc/codecs/arizona.h
··· 294 294 int arizona_set_output_mode(struct snd_soc_codec *codec, int output, 295 295 bool diff); 296 296 297 + extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift); 298 + 297 299 #endif
-109
sound/soc/codecs/hdmi.c
··· 1 - /* 2 - * ALSA SoC codec driver for HDMI audio codecs. 3 - * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ 4 - * Author: Ricardo Neri <ricardo.neri@ti.com> 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * version 2 as published by the Free Software Foundation. 9 - * 10 - * This program is distributed in the hope that it will be useful, but 11 - * WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 - * General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 - * 02110-1301 USA 19 - * 20 - */ 21 - #include <linux/module.h> 22 - #include <sound/soc.h> 23 - #include <linux/of.h> 24 - #include <linux/of_device.h> 25 - 26 - #define DRV_NAME "hdmi-audio-codec" 27 - 28 - static const struct snd_soc_dapm_widget hdmi_widgets[] = { 29 - SND_SOC_DAPM_INPUT("RX"), 30 - SND_SOC_DAPM_OUTPUT("TX"), 31 - }; 32 - 33 - static const struct snd_soc_dapm_route hdmi_routes[] = { 34 - { "Capture", NULL, "RX" }, 35 - { "TX", NULL, "Playback" }, 36 - }; 37 - 38 - static struct snd_soc_dai_driver hdmi_codec_dai = { 39 - .name = "hdmi-hifi", 40 - .playback = { 41 - .stream_name = "Playback", 42 - .channels_min = 2, 43 - .channels_max = 8, 44 - .rates = SNDRV_PCM_RATE_32000 | 45 - SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 46 - SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 47 - SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, 48 - .formats = SNDRV_PCM_FMTBIT_S16_LE | 49 - SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 50 - .sig_bits = 24, 51 - }, 52 - .capture = { 53 - .stream_name = "Capture", 54 - .channels_min = 2, 55 - .channels_max = 2, 56 - .rates = SNDRV_PCM_RATE_32000 | 57 - SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 58 - SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 59 - SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, 60 - .formats = SNDRV_PCM_FMTBIT_S16_LE | 61 - SNDRV_PCM_FMTBIT_S24_LE, 62 - }, 63 - 64 - }; 65 - 66 - #ifdef CONFIG_OF 67 - static const struct of_device_id hdmi_audio_codec_ids[] = { 68 - { .compatible = "linux,hdmi-audio", }, 69 - { } 70 - }; 71 - MODULE_DEVICE_TABLE(of, hdmi_audio_codec_ids); 72 - #endif 73 - 74 - static struct snd_soc_codec_driver hdmi_codec = { 75 - .dapm_widgets = hdmi_widgets, 76 - .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), 77 - .dapm_routes = hdmi_routes, 78 - .num_dapm_routes = ARRAY_SIZE(hdmi_routes), 79 - .ignore_pmdown_time = true, 80 - }; 81 - 82 - static int hdmi_codec_probe(struct platform_device *pdev) 83 - { 84 - return snd_soc_register_codec(&pdev->dev, &hdmi_codec, 85 - &hdmi_codec_dai, 1); 86 - } 87 - 88 - static int hdmi_codec_remove(struct platform_device *pdev) 89 - { 90 - snd_soc_unregister_codec(&pdev->dev); 91 - return 0; 92 - } 93 - 94 - static struct platform_driver hdmi_codec_driver = { 95 - .driver = { 96 - .name = DRV_NAME, 97 - .of_match_table = of_match_ptr(hdmi_audio_codec_ids), 98 - }, 99 - 100 - .probe = hdmi_codec_probe, 101 - .remove = hdmi_codec_remove, 102 - }; 103 - 104 - module_platform_driver(hdmi_codec_driver); 105 - 106 - MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>"); 107 - MODULE_DESCRIPTION("ASoC generic HDMI codec driver"); 108 - MODULE_LICENSE("GPL"); 109 - MODULE_ALIAS("platform:" DRV_NAME);
+47 -10
sound/soc/codecs/rt5645.c
··· 732 732 static const struct snd_kcontrol_new rt5645_dac_l_mix[] = { 733 733 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER, 734 734 RT5645_M_ADCMIX_L_SFT, 1, 1), 735 - SOC_DAPM_SINGLE("DAC1 Switch", RT5645_AD_DA_MIXER, 735 + SOC_DAPM_SINGLE_AUTODISABLE("DAC1 Switch", RT5645_AD_DA_MIXER, 736 736 RT5645_M_DAC1_L_SFT, 1, 1), 737 737 }; 738 738 739 739 static const struct snd_kcontrol_new rt5645_dac_r_mix[] = { 740 740 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER, 741 741 RT5645_M_ADCMIX_R_SFT, 1, 1), 742 - SOC_DAPM_SINGLE("DAC1 Switch", RT5645_AD_DA_MIXER, 742 + SOC_DAPM_SINGLE_AUTODISABLE("DAC1 Switch", RT5645_AD_DA_MIXER, 743 743 RT5645_M_DAC1_R_SFT, 1, 1), 744 744 }; 745 745 ··· 1381 1381 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1382 1382 RT5645_MAMP_INT_REG2, 0xfc00); 1383 1383 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1140); 1384 - mdelay(5); 1384 + msleep(40); 1385 1385 rt5645->hp_on = true; 1386 1386 } else { 1387 1387 /* depop parameters */ ··· 2829 2829 snd_soc_dapm_sync(dapm); 2830 2830 rt5645->jack_type = SND_JACK_HEADPHONE; 2831 2831 } 2832 - 2833 - snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200); 2834 - snd_soc_write(codec, RT5645_DEPOP_M1, 0x001d); 2835 - snd_soc_write(codec, RT5645_DEPOP_M1, 0x0001); 2832 + if (rt5645->pdata.jd_invert) 2833 + regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, 2834 + RT5645_JD_1_1_MASK, RT5645_JD_1_1_INV); 2836 2835 } else { /* jack out */ 2837 2836 rt5645->jack_type = 0; 2838 2837 2838 + regmap_update_bits(rt5645->regmap, RT5645_HP_VOL, 2839 + RT5645_L_MUTE | RT5645_R_MUTE, 2840 + RT5645_L_MUTE | RT5645_R_MUTE); 2839 2841 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, 2840 2842 RT5645_CBJ_MN_JD, RT5645_CBJ_MN_JD); 2841 2843 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, ··· 2850 2848 snd_soc_dapm_disable_pin(dapm, "LDO2"); 2851 2849 snd_soc_dapm_disable_pin(dapm, "Mic Det Power"); 2852 2850 snd_soc_dapm_sync(dapm); 2851 + if (rt5645->pdata.jd_invert) 2852 + regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, 2853 + RT5645_JD_1_1_MASK, RT5645_JD_1_1_NOR); 2853 2854 } 2854 2855 2855 2856 return rt5645->jack_type; ··· 2885 2880 rt5645->en_button_func = true; 2886 2881 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 2887 2882 RT5645_GP1_PIN_IRQ, RT5645_GP1_PIN_IRQ); 2888 - regmap_update_bits(rt5645->regmap, RT5645_DEPOP_M1, 2889 - RT5645_HP_CB_MASK, RT5645_HP_CB_PU); 2890 2883 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL1, 2891 2884 RT5645_DIG_GATE_CTRL, RT5645_DIG_GATE_CTRL); 2892 2885 } ··· 3208 3205 DMI_MATCH(DMI_PRODUCT_NAME, "Celes"), 3209 3206 }, 3210 3207 }, 3208 + { 3209 + .ident = "Google Ultima", 3210 + .callback = strago_quirk_cb, 3211 + .matches = { 3212 + DMI_MATCH(DMI_PRODUCT_NAME, "Ultima"), 3213 + }, 3214 + }, 3211 3215 { } 3212 3216 }; 3217 + 3218 + static struct rt5645_platform_data buddy_platform_data = { 3219 + .dmic1_data_pin = RT5645_DMIC_DATA_GPIO5, 3220 + .dmic2_data_pin = RT5645_DMIC_DATA_IN2P, 3221 + .jd_mode = 3, 3222 + .jd_invert = true, 3223 + }; 3224 + 3225 + static int buddy_quirk_cb(const struct dmi_system_id *id) 3226 + { 3227 + rt5645_pdata = &buddy_platform_data; 3228 + 3229 + return 1; 3230 + } 3231 + 3232 + static struct dmi_system_id dmi_platform_intel_broadwell[] __initdata = { 3233 + { 3234 + .ident = "Chrome Buddy", 3235 + .callback = buddy_quirk_cb, 3236 + .matches = { 3237 + DMI_MATCH(DMI_PRODUCT_NAME, "Buddy"), 3238 + }, 3239 + }, 3240 + { } 3241 + }; 3242 + 3213 3243 3214 3244 static int rt5645_parse_dt(struct rt5645_priv *rt5645, struct device *dev) 3215 3245 { ··· 3276 3240 3277 3241 if (pdata) 3278 3242 rt5645->pdata = *pdata; 3279 - else if (dmi_check_system(dmi_platform_intel_braswell)) 3243 + else if (dmi_check_system(dmi_platform_intel_braswell) || 3244 + dmi_check_system(dmi_platform_intel_broadwell)) 3280 3245 rt5645->pdata = *rt5645_pdata; 3281 3246 else 3282 3247 rt5645_parse_dt(rt5645, &i2c->dev);
+4 -2
sound/soc/codecs/rt5645.h
··· 777 777 #define RT5645_PWR_CLS_D_R_BIT 9 778 778 #define RT5645_PWR_CLS_D_L (0x1 << 8) 779 779 #define RT5645_PWR_CLS_D_L_BIT 8 780 - #define RT5645_PWR_ADC_R (0x1 << 1) 781 - #define RT5645_PWR_ADC_R_BIT 1 782 780 #define RT5645_PWR_DAC_L2 (0x1 << 7) 783 781 #define RT5645_PWR_DAC_L2_BIT 7 784 782 #define RT5645_PWR_DAC_R2 (0x1 << 6) ··· 1624 1626 #define RT5645_OT_P_NOR (0x0 << 10) 1625 1627 #define RT5645_OT_P_INV (0x1 << 10) 1626 1628 #define RT5645_IRQ_JD_1_1_EN (0x1 << 9) 1629 + #define RT5645_JD_1_1_MASK (0x1 << 7) 1630 + #define RT5645_JD_1_1_SFT 7 1631 + #define RT5645_JD_1_1_NOR (0x0 << 7) 1632 + #define RT5645_JD_1_1_INV (0x1 << 7) 1627 1633 1628 1634 /* IRQ Control 2 (0xbe) */ 1629 1635 #define RT5645_IRQ_MB1_OC_MASK (0x1 << 15)
+26 -4
sound/soc/codecs/tlv320aic3x.c
··· 80 80 unsigned int sysclk; 81 81 unsigned int dai_fmt; 82 82 unsigned int tdm_delay; 83 + unsigned int slot_width; 83 84 struct list_head list; 84 85 int master; 85 86 int gpio_reset; ··· 1026 1025 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; 1027 1026 u16 d, pll_d = 1; 1028 1027 int clk; 1028 + int width = aic3x->slot_width; 1029 + 1030 + if (!width) 1031 + width = params_width(params); 1029 1032 1030 1033 /* select data word length */ 1031 1034 data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4)); 1032 - switch (params_width(params)) { 1035 + switch (width) { 1033 1036 case 16: 1034 1037 break; 1035 1038 case 20: ··· 1175 1170 struct snd_soc_codec *codec = dai->codec; 1176 1171 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 1177 1172 int delay = 0; 1173 + int width = aic3x->slot_width; 1174 + 1175 + if (!width) 1176 + width = substream->runtime->sample_bits; 1178 1177 1179 1178 /* TDM slot selection only valid in DSP_A/_B mode */ 1180 1179 if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_A) 1181 - delay += (aic3x->tdm_delay + 1); 1180 + delay += (aic3x->tdm_delay*width + 1); 1182 1181 else if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_B) 1183 - delay += aic3x->tdm_delay; 1182 + delay += aic3x->tdm_delay*width; 1184 1183 1185 1184 /* Configure data delay */ 1186 1185 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay); ··· 1305 1296 return -EINVAL; 1306 1297 } 1307 1298 1308 - aic3x->tdm_delay = lsb * slot_width; 1299 + switch (slot_width) { 1300 + case 16: 1301 + case 20: 1302 + case 24: 1303 + case 32: 1304 + break; 1305 + default: 1306 + dev_err(codec->dev, "Unsupported slot width %d\n", slot_width); 1307 + return -EINVAL; 1308 + } 1309 + 1310 + 1311 + aic3x->tdm_delay = lsb; 1312 + aic3x->slot_width = slot_width; 1309 1313 1310 1314 /* DOUT in high-impedance on inactive bit clocks */ 1311 1315 snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
+9 -14
sound/soc/codecs/wm0010.c
··· 577 577 struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec); 578 578 unsigned long flags; 579 579 int ret; 580 - const struct firmware *fw; 581 580 struct spi_message m; 582 581 struct spi_transfer t; 583 582 struct dfw_pllrec pll_rec; ··· 622 623 wm0010->state = WM0010_OUT_OF_RESET; 623 624 spin_unlock_irqrestore(&wm0010->irq_lock, flags); 624 625 625 - /* First the bootloader */ 626 - ret = request_firmware(&fw, "wm0010_stage2.bin", codec->dev); 627 - if (ret != 0) { 628 - dev_err(codec->dev, "Failed to request stage2 loader: %d\n", 629 - ret); 630 - goto abort; 631 - } 632 - 633 626 if (!wait_for_completion_timeout(&wm0010->boot_completion, 634 627 msecs_to_jiffies(20))) 635 628 dev_err(codec->dev, "Failed to get interrupt from DSP\n"); ··· 664 673 665 674 img_swap = kzalloc(len, GFP_KERNEL | GFP_DMA); 666 675 if (!img_swap) 667 - goto abort; 676 + goto abort_out; 668 677 669 678 /* We need to re-order for 0010 */ 670 679 byte_swap_64((u64 *)&pll_rec, img_swap, len); ··· 679 688 spi_message_add_tail(&t, &m); 680 689 681 690 ret = spi_sync(spi, &m); 682 - if (ret != 0) { 691 + if (ret) { 683 692 dev_err(codec->dev, "First PLL write failed: %d\n", ret); 684 - goto abort; 693 + goto abort_swap; 685 694 } 686 695 687 696 /* Use a second send of the message to get the return status */ 688 697 ret = spi_sync(spi, &m); 689 - if (ret != 0) { 698 + if (ret) { 690 699 dev_err(codec->dev, "Second PLL write failed: %d\n", ret); 691 - goto abort; 700 + goto abort_swap; 692 701 } 693 702 694 703 p = (u32 *)out; ··· 721 730 722 731 return 0; 723 732 733 + abort_swap: 734 + kfree(img_swap); 735 + abort_out: 736 + kfree(out); 724 737 abort: 725 738 /* Put the chip back into reset */ 726 739 wm0010_halt(codec);
+163 -24
sound/soc/codecs/wm5110.c
··· 38 38 struct wm5110_priv { 39 39 struct arizona_priv core; 40 40 struct arizona_fll fll[2]; 41 + 42 + unsigned int in_value; 43 + int in_pre_pending; 44 + int in_post_pending; 45 + 46 + unsigned int in_pga_cache[6]; 41 47 }; 42 48 43 49 static const struct wm_adsp_region wm5110_dsp1_regions[] = { ··· 434 428 return ret; 435 429 } 436 430 431 + static int wm5110_in_pga_get(struct snd_kcontrol *kcontrol, 432 + struct snd_ctl_elem_value *ucontrol) 433 + { 434 + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 435 + struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 436 + struct snd_soc_card *card = dapm->card; 437 + int ret; 438 + 439 + /* 440 + * PGA Volume is also used as part of the enable sequence, so 441 + * usage of it should be avoided whilst that is running. 442 + */ 443 + mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 444 + 445 + ret = snd_soc_get_volsw_range(kcontrol, ucontrol); 446 + 447 + mutex_unlock(&card->dapm_mutex); 448 + 449 + return ret; 450 + } 451 + 452 + static int wm5110_in_pga_put(struct snd_kcontrol *kcontrol, 453 + struct snd_ctl_elem_value *ucontrol) 454 + { 455 + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 456 + struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 457 + struct snd_soc_card *card = dapm->card; 458 + int ret; 459 + 460 + /* 461 + * PGA Volume is also used as part of the enable sequence, so 462 + * usage of it should be avoided whilst that is running. 463 + */ 464 + mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 465 + 466 + ret = snd_soc_put_volsw_range(kcontrol, ucontrol); 467 + 468 + mutex_unlock(&card->dapm_mutex); 469 + 470 + return ret; 471 + } 472 + 473 + static int wm5110_in_analog_ev(struct snd_soc_dapm_widget *w, 474 + struct snd_kcontrol *kcontrol, int event) 475 + { 476 + struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 477 + struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 478 + struct wm5110_priv *wm5110 = snd_soc_codec_get_drvdata(codec); 479 + struct arizona *arizona = priv->arizona; 480 + unsigned int reg, mask; 481 + struct reg_sequence analog_seq[] = { 482 + { 0x80, 0x3 }, 483 + { 0x35d, 0 }, 484 + { 0x80, 0x0 }, 485 + }; 486 + 487 + reg = ARIZONA_IN1L_CONTROL + ((w->shift ^ 0x1) * 4); 488 + mask = ARIZONA_IN1L_PGA_VOL_MASK; 489 + 490 + switch (event) { 491 + case SND_SOC_DAPM_WILL_PMU: 492 + wm5110->in_value |= 0x3 << ((w->shift ^ 0x1) * 2); 493 + wm5110->in_pre_pending++; 494 + wm5110->in_post_pending++; 495 + return 0; 496 + case SND_SOC_DAPM_PRE_PMU: 497 + wm5110->in_pga_cache[w->shift] = snd_soc_read(codec, reg); 498 + 499 + snd_soc_update_bits(codec, reg, mask, 500 + 0x40 << ARIZONA_IN1L_PGA_VOL_SHIFT); 501 + 502 + wm5110->in_pre_pending--; 503 + if (wm5110->in_pre_pending == 0) { 504 + analog_seq[1].def = wm5110->in_value; 505 + regmap_multi_reg_write_bypassed(arizona->regmap, 506 + analog_seq, 507 + ARRAY_SIZE(analog_seq)); 508 + 509 + msleep(55); 510 + 511 + wm5110->in_value = 0; 512 + } 513 + 514 + break; 515 + case SND_SOC_DAPM_POST_PMU: 516 + snd_soc_update_bits(codec, reg, mask, 517 + wm5110->in_pga_cache[w->shift]); 518 + 519 + wm5110->in_post_pending--; 520 + if (wm5110->in_post_pending == 0) 521 + regmap_multi_reg_write_bypassed(arizona->regmap, 522 + analog_seq, 523 + ARRAY_SIZE(analog_seq)); 524 + break; 525 + default: 526 + break; 527 + } 528 + 529 + return 0; 530 + } 531 + 532 + static int wm5110_in_ev(struct snd_soc_dapm_widget *w, 533 + struct snd_kcontrol *kcontrol, int event) 534 + { 535 + struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 536 + struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 537 + struct arizona *arizona = priv->arizona; 538 + 539 + switch (arizona->rev) { 540 + case 0 ... 4: 541 + if (arizona_input_analog(codec, w->shift)) 542 + wm5110_in_analog_ev(w, kcontrol, event); 543 + 544 + break; 545 + default: 546 + break; 547 + } 548 + 549 + return arizona_in_ev(w, kcontrol, event); 550 + } 551 + 437 552 static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0); 438 553 static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 439 554 static DECLARE_TLV_DB_SCALE(digital_tlv, -6400, 50, 0); ··· 581 454 SOC_ENUM("IN3 OSR", arizona_in_dmic_osr[2]), 582 455 SOC_ENUM("IN4 OSR", arizona_in_dmic_osr[3]), 583 456 584 - SOC_SINGLE_RANGE_TLV("IN1L Volume", ARIZONA_IN1L_CONTROL, 585 - ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 586 - SOC_SINGLE_RANGE_TLV("IN1R Volume", ARIZONA_IN1R_CONTROL, 587 - ARIZONA_IN1R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 588 - SOC_SINGLE_RANGE_TLV("IN2L Volume", ARIZONA_IN2L_CONTROL, 589 - ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 590 - SOC_SINGLE_RANGE_TLV("IN2R Volume", ARIZONA_IN2R_CONTROL, 591 - ARIZONA_IN2R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 592 - SOC_SINGLE_RANGE_TLV("IN3L Volume", ARIZONA_IN3L_CONTROL, 593 - ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 594 - SOC_SINGLE_RANGE_TLV("IN3R Volume", ARIZONA_IN3R_CONTROL, 595 - ARIZONA_IN3R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, ana_tlv), 457 + SOC_SINGLE_RANGE_EXT_TLV("IN1L Volume", ARIZONA_IN1L_CONTROL, 458 + ARIZONA_IN1L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 459 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 460 + SOC_SINGLE_RANGE_EXT_TLV("IN1R Volume", ARIZONA_IN1R_CONTROL, 461 + ARIZONA_IN1R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 462 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 463 + SOC_SINGLE_RANGE_EXT_TLV("IN2L Volume", ARIZONA_IN2L_CONTROL, 464 + ARIZONA_IN2L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 465 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 466 + SOC_SINGLE_RANGE_EXT_TLV("IN2R Volume", ARIZONA_IN2R_CONTROL, 467 + ARIZONA_IN2R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 468 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 469 + SOC_SINGLE_RANGE_EXT_TLV("IN3L Volume", ARIZONA_IN3L_CONTROL, 470 + ARIZONA_IN3L_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 471 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 472 + SOC_SINGLE_RANGE_EXT_TLV("IN3R Volume", ARIZONA_IN3R_CONTROL, 473 + ARIZONA_IN3R_PGA_VOL_SHIFT, 0x40, 0x5f, 0, 474 + wm5110_in_pga_get, wm5110_in_pga_put, ana_tlv), 596 475 597 476 SOC_ENUM("IN HPF Cutoff Frequency", arizona_in_hpf_cut_enum), 598 477 ··· 1029 896 SND_SOC_DAPM_OUTPUT("DRC2 Signal Activity"), 1030 897 1031 898 SND_SOC_DAPM_PGA_E("IN1L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN1L_ENA_SHIFT, 1032 - 0, NULL, 0, arizona_in_ev, 899 + 0, NULL, 0, wm5110_in_ev, 1033 900 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1034 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 901 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 902 + SND_SOC_DAPM_WILL_PMU), 1035 903 SND_SOC_DAPM_PGA_E("IN1R PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN1R_ENA_SHIFT, 1036 - 0, NULL, 0, arizona_in_ev, 904 + 0, NULL, 0, wm5110_in_ev, 1037 905 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1038 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 906 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 907 + SND_SOC_DAPM_WILL_PMU), 1039 908 SND_SOC_DAPM_PGA_E("IN2L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN2L_ENA_SHIFT, 1040 - 0, NULL, 0, arizona_in_ev, 909 + 0, NULL, 0, wm5110_in_ev, 1041 910 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1042 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 911 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 912 + SND_SOC_DAPM_WILL_PMU), 1043 913 SND_SOC_DAPM_PGA_E("IN2R PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN2R_ENA_SHIFT, 1044 - 0, NULL, 0, arizona_in_ev, 914 + 0, NULL, 0, wm5110_in_ev, 1045 915 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1046 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 916 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 917 + SND_SOC_DAPM_WILL_PMU), 1047 918 SND_SOC_DAPM_PGA_E("IN3L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN3L_ENA_SHIFT, 1048 - 0, NULL, 0, arizona_in_ev, 919 + 0, NULL, 0, wm5110_in_ev, 1049 920 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1050 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 921 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 922 + SND_SOC_DAPM_WILL_PMU), 1051 923 SND_SOC_DAPM_PGA_E("IN3R PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN3R_ENA_SHIFT, 1052 - 0, NULL, 0, arizona_in_ev, 924 + 0, NULL, 0, wm5110_in_ev, 1053 925 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD | 1054 - SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 926 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 927 + SND_SOC_DAPM_WILL_PMU), 1055 928 SND_SOC_DAPM_PGA_E("IN4L PGA", ARIZONA_INPUT_ENABLES, ARIZONA_IN4L_ENA_SHIFT, 1056 929 0, NULL, 0, arizona_in_ev, 1057 930 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
+18 -8
sound/soc/codecs/wm8960.c
··· 211 211 return wm8960_set_deemph(codec); 212 212 } 213 213 214 - static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0); 215 - static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1); 214 + static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1); 215 + static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1725, 75, 0); 216 + static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1); 216 217 static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0); 217 218 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); 218 - static const DECLARE_TLV_DB_SCALE(boost_tlv, -1200, 300, 1); 219 + static const DECLARE_TLV_DB_SCALE(lineinboost_tlv, -1500, 300, 1); 220 + static const unsigned int micboost_tlv[] = { 221 + TLV_DB_RANGE_HEAD(2), 222 + 0, 1, TLV_DB_SCALE_ITEM(0, 1300, 0), 223 + 2, 3, TLV_DB_SCALE_ITEM(2000, 900, 0), 224 + }; 219 225 220 226 static const struct snd_kcontrol_new wm8960_snd_controls[] = { 221 227 SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL, 222 - 0, 63, 0, adc_tlv), 228 + 0, 63, 0, inpga_tlv), 223 229 SOC_DOUBLE_R("Capture Volume ZC Switch", WM8960_LINVOL, WM8960_RINVOL, 224 230 6, 1, 0), 225 231 SOC_DOUBLE_R("Capture Switch", WM8960_LINVOL, WM8960_RINVOL, 226 232 7, 1, 0), 227 233 228 234 SOC_SINGLE_TLV("Right Input Boost Mixer RINPUT3 Volume", 229 - WM8960_INBMIX1, 4, 7, 0, boost_tlv), 235 + WM8960_INBMIX1, 4, 7, 0, lineinboost_tlv), 230 236 SOC_SINGLE_TLV("Right Input Boost Mixer RINPUT2 Volume", 231 - WM8960_INBMIX1, 1, 7, 0, boost_tlv), 237 + WM8960_INBMIX1, 1, 7, 0, lineinboost_tlv), 232 238 SOC_SINGLE_TLV("Left Input Boost Mixer LINPUT3 Volume", 233 - WM8960_INBMIX2, 4, 7, 0, boost_tlv), 239 + WM8960_INBMIX2, 4, 7, 0, lineinboost_tlv), 234 240 SOC_SINGLE_TLV("Left Input Boost Mixer LINPUT2 Volume", 235 - WM8960_INBMIX2, 1, 7, 0, boost_tlv), 241 + WM8960_INBMIX2, 1, 7, 0, lineinboost_tlv), 242 + SOC_SINGLE_TLV("Right Input Boost Mixer RINPUT1 Volume", 243 + WM8960_RINPATH, 4, 3, 0, micboost_tlv), 244 + SOC_SINGLE_TLV("Left Input Boost Mixer LINPUT1 Volume", 245 + WM8960_LINPATH, 4, 3, 0, micboost_tlv), 236 246 237 247 SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC, 238 248 0, 255, 0, dac_tlv),
+2 -1
sound/soc/codecs/wm8962.c
··· 2944 2944 WM8962_DAC_MUTE, val); 2945 2945 } 2946 2946 2947 - #define WM8962_RATES SNDRV_PCM_RATE_8000_96000 2947 + #define WM8962_RATES (SNDRV_PCM_RATE_8000_48000 |\ 2948 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 2948 2949 2949 2950 #define WM8962_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 2950 2951 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+209 -110
sound/soc/davinci/davinci-mcasp.c
··· 80 80 81 81 /* McASP specific data */ 82 82 int tdm_slots; 83 + u32 tdm_mask[2]; 84 + int slot_width; 83 85 u8 op_mode; 84 86 u8 num_serializer; 85 87 u8 *serial_dir; 86 88 u8 version; 87 89 u8 bclk_div; 88 - u16 bclk_lrclk_ratio; 89 90 int streams; 90 91 u32 irq_request[2]; 91 92 int dma_request[2]; ··· 557 556 mcasp->bclk_div = div; 558 557 break; 559 558 560 - case 2: /* BCLK/LRCLK ratio */ 561 - mcasp->bclk_lrclk_ratio = div; 559 + case 2: /* 560 + * BCLK/LRCLK ratio descries how many bit-clock cycles 561 + * fit into one frame. The clock ratio is given for a 562 + * full period of data (for I2S format both left and 563 + * right channels), so it has to be divided by number 564 + * of tdm-slots (for I2S - divided by 2). 565 + * Instead of storing this ratio, we calculate a new 566 + * tdm_slot width by dividing the the ratio by the 567 + * number of configured tdm slots. 568 + */ 569 + mcasp->slot_width = div / mcasp->tdm_slots; 570 + if (div % mcasp->tdm_slots) 571 + dev_warn(mcasp->dev, 572 + "%s(): BCLK/LRCLK %d is not divisible by %d tdm slots", 573 + __func__, div, mcasp->tdm_slots); 562 574 break; 563 575 564 576 default: ··· 610 596 return 0; 611 597 } 612 598 599 + /* All serializers must have equal number of channels */ 600 + static int davinci_mcasp_ch_constraint(struct davinci_mcasp *mcasp, int stream, 601 + int serializers) 602 + { 603 + struct snd_pcm_hw_constraint_list *cl = &mcasp->chconstr[stream]; 604 + unsigned int *list = (unsigned int *) cl->list; 605 + int slots = mcasp->tdm_slots; 606 + int i, count = 0; 607 + 608 + if (mcasp->tdm_mask[stream]) 609 + slots = hweight32(mcasp->tdm_mask[stream]); 610 + 611 + for (i = 2; i <= slots; i++) 612 + list[count++] = i; 613 + 614 + for (i = 2; i <= serializers; i++) 615 + list[count++] = i*slots; 616 + 617 + cl->count = count; 618 + 619 + return 0; 620 + } 621 + 622 + static int davinci_mcasp_set_ch_constraints(struct davinci_mcasp *mcasp) 623 + { 624 + int rx_serializers = 0, tx_serializers = 0, ret, i; 625 + 626 + for (i = 0; i < mcasp->num_serializer; i++) 627 + if (mcasp->serial_dir[i] == TX_MODE) 628 + tx_serializers++; 629 + else if (mcasp->serial_dir[i] == RX_MODE) 630 + rx_serializers++; 631 + 632 + ret = davinci_mcasp_ch_constraint(mcasp, SNDRV_PCM_STREAM_PLAYBACK, 633 + tx_serializers); 634 + if (ret) 635 + return ret; 636 + 637 + ret = davinci_mcasp_ch_constraint(mcasp, SNDRV_PCM_STREAM_CAPTURE, 638 + rx_serializers); 639 + 640 + return ret; 641 + } 642 + 643 + 644 + static int davinci_mcasp_set_tdm_slot(struct snd_soc_dai *dai, 645 + unsigned int tx_mask, 646 + unsigned int rx_mask, 647 + int slots, int slot_width) 648 + { 649 + struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai); 650 + 651 + dev_dbg(mcasp->dev, 652 + "%s() tx_mask 0x%08x rx_mask 0x%08x slots %d width %d\n", 653 + __func__, tx_mask, rx_mask, slots, slot_width); 654 + 655 + if (tx_mask >= (1<<slots) || rx_mask >= (1<<slots)) { 656 + dev_err(mcasp->dev, 657 + "Bad tdm mask tx: 0x%08x rx: 0x%08x slots %d\n", 658 + tx_mask, rx_mask, slots); 659 + return -EINVAL; 660 + } 661 + 662 + if (slot_width && 663 + (slot_width < 8 || slot_width > 32 || slot_width % 4 != 0)) { 664 + dev_err(mcasp->dev, "%s: Unsupported slot_width %d\n", 665 + __func__, slot_width); 666 + return -EINVAL; 667 + } 668 + 669 + mcasp->tdm_slots = slots; 670 + mcasp->tdm_mask[SNDRV_PCM_STREAM_PLAYBACK] = rx_mask; 671 + mcasp->tdm_mask[SNDRV_PCM_STREAM_CAPTURE] = tx_mask; 672 + mcasp->slot_width = slot_width; 673 + 674 + return davinci_mcasp_set_ch_constraints(mcasp); 675 + } 676 + 613 677 static int davinci_config_channel_size(struct davinci_mcasp *mcasp, 614 - int word_length) 678 + int sample_width) 615 679 { 616 680 u32 fmt; 617 - u32 tx_rotate = (word_length / 4) & 0x7; 618 - u32 mask = (1ULL << word_length) - 1; 681 + u32 tx_rotate = (sample_width / 4) & 0x7; 682 + u32 mask = (1ULL << sample_width) - 1; 683 + u32 slot_width = sample_width; 684 + 619 685 /* 620 686 * For captured data we should not rotate, inversion and masking is 621 687 * enoguh to get the data to the right position: ··· 708 614 u32 rx_rotate = 0; 709 615 710 616 /* 711 - * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv() 712 - * callback, take it into account here. That allows us to for example 713 - * send 32 bits per channel to the codec, while only 16 of them carry 714 - * audio payload. 715 - * The clock ratio is given for a full period of data (for I2S format 716 - * both left and right channels), so it has to be divided by number of 717 - * tdm-slots (for I2S - divided by 2). 617 + * Setting the tdm slot width either with set_clkdiv() or 618 + * set_tdm_slot() allows us to for example send 32 bits per 619 + * channel to the codec, while only 16 of them carry audio 620 + * payload. 718 621 */ 719 - if (mcasp->bclk_lrclk_ratio) { 720 - u32 slot_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots; 721 - 622 + if (mcasp->slot_width) { 722 623 /* 723 - * When we have more bclk then it is needed for the data, we 724 - * need to use the rotation to move the received samples to have 725 - * correct alignment. 624 + * When we have more bclk then it is needed for the 625 + * data, we need to use the rotation to move the 626 + * received samples to have correct alignment. 726 627 */ 727 - rx_rotate = (slot_length - word_length) / 4; 728 - word_length = slot_length; 628 + slot_width = mcasp->slot_width; 629 + rx_rotate = (slot_width - sample_width) / 4; 729 630 } 730 631 731 632 /* mapping of the XSSZ bit-field as described in the datasheet */ 732 - fmt = (word_length >> 1) - 1; 633 + fmt = (slot_width >> 1) - 1; 733 634 734 635 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) { 735 636 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt), ··· 752 663 u8 rx_ser = 0; 753 664 u8 slots = mcasp->tdm_slots; 754 665 u8 max_active_serializers = (channels + slots - 1) / slots; 755 - int active_serializers, numevt, n; 666 + int active_serializers, numevt; 756 667 u32 reg; 757 668 /* Default configuration */ 758 669 if (mcasp->version < MCASP_VERSION_3) ··· 834 745 * The number of words for numevt need to be in steps of active 835 746 * serializers. 836 747 */ 837 - n = numevt % active_serializers; 838 - if (n) 839 - numevt += (active_serializers - n); 748 + numevt = (numevt / active_serializers) * active_serializers; 749 + 840 750 while (period_words % numevt && numevt > 0) 841 751 numevt -= active_serializers; 842 752 if (numevt <= 0) ··· 865 777 866 778 /* 867 779 * If more than one serializer is needed, then use them with 868 - * their specified tdm_slots count. Otherwise, one serializer 869 - * can cope with the transaction using as many slots as channels 870 - * in the stream, requires channels symmetry 780 + * all the specified tdm_slots. Otherwise, one serializer can 781 + * cope with the transaction using just as many slots as there 782 + * are channels in the stream. 871 783 */ 872 - active_serializers = (channels + total_slots - 1) / total_slots; 873 - if (active_serializers == 1) 874 - active_slots = channels; 875 - else 876 - active_slots = total_slots; 784 + if (mcasp->tdm_mask[stream]) { 785 + active_slots = hweight32(mcasp->tdm_mask[stream]); 786 + active_serializers = (channels + active_slots - 1) / 787 + active_slots; 788 + if (active_serializers == 1) { 789 + active_slots = channels; 790 + for (i = 0; i < total_slots; i++) { 791 + if ((1 << i) & mcasp->tdm_mask[stream]) { 792 + mask |= (1 << i); 793 + if (--active_slots <= 0) 794 + break; 795 + } 796 + } 797 + } 798 + } else { 799 + active_serializers = (channels + total_slots - 1) / total_slots; 800 + if (active_serializers == 1) 801 + active_slots = channels; 802 + else 803 + active_slots = total_slots; 877 804 878 - for (i = 0; i < active_slots; i++) 879 - mask |= (1 << i); 880 - 805 + for (i = 0; i < active_slots; i++) 806 + mask |= (1 << i); 807 + } 881 808 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); 882 809 883 810 if (!mcasp->dat_port) 884 811 busel = TXSEL; 885 812 886 - mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask); 887 - mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD); 888 - mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, 889 - FSXMOD(total_slots), FSXMOD(0x1FF)); 890 - 891 - mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask); 892 - mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD); 893 - mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, 894 - FSRMOD(total_slots), FSRMOD(0x1FF)); 813 + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 814 + mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask); 815 + mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD); 816 + mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, 817 + FSXMOD(total_slots), FSXMOD(0x1FF)); 818 + } else if (stream == SNDRV_PCM_STREAM_CAPTURE) { 819 + mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask); 820 + mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD); 821 + mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, 822 + FSRMOD(total_slots), FSRMOD(0x1FF)); 823 + } 895 824 896 825 return 0; 897 826 } ··· 1028 923 int sbits = params_width(params); 1029 924 int ppm, div; 1030 925 926 + if (mcasp->slot_width) 927 + sbits = mcasp->slot_width; 928 + 1031 929 div = davinci_mcasp_calc_clk_div(mcasp, rate*sbits*slots, 1032 930 &ppm); 1033 931 if (ppm) ··· 1136 1028 struct snd_interval range; 1137 1029 int i; 1138 1030 1031 + if (rd->mcasp->slot_width) 1032 + sbits = rd->mcasp->slot_width; 1033 + 1139 1034 snd_interval_any(&range); 1140 1035 range.empty = 1; 1141 1036 ··· 1181 1070 1182 1071 for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) { 1183 1072 if (snd_mask_test(fmt, i)) { 1184 - uint bclk_freq = snd_pcm_format_width(i)*slots*rate; 1073 + uint sbits = snd_pcm_format_width(i); 1185 1074 int ppm; 1186 1075 1187 - davinci_mcasp_calc_clk_div(rd->mcasp, bclk_freq, &ppm); 1076 + if (rd->mcasp->slot_width) 1077 + sbits = rd->mcasp->slot_width; 1078 + 1079 + davinci_mcasp_calc_clk_div(rd->mcasp, sbits*slots*rate, 1080 + &ppm); 1188 1081 if (abs(ppm) < DAVINCI_MAX_RATE_ERROR_PPM) { 1189 1082 snd_mask_set(&nfmt, i); 1190 1083 count++; ··· 1210 1095 &mcasp->ruledata[substream->stream]; 1211 1096 u32 max_channels = 0; 1212 1097 int i, dir; 1098 + int tdm_slots = mcasp->tdm_slots; 1099 + 1100 + if (mcasp->tdm_mask[substream->stream]) 1101 + tdm_slots = hweight32(mcasp->tdm_mask[substream->stream]); 1213 1102 1214 1103 mcasp->substreams[substream->stream] = substream; 1215 1104 ··· 1234 1115 max_channels++; 1235 1116 } 1236 1117 ruledata->serializers = max_channels; 1237 - max_channels *= mcasp->tdm_slots; 1118 + max_channels *= tdm_slots; 1238 1119 /* 1239 1120 * If the already active stream has less channels than the calculated 1240 1121 * limnit based on the seirializers * tdm_slots, we need to use that as ··· 1244 1125 */ 1245 1126 if (mcasp->channels && mcasp->channels < max_channels) 1246 1127 max_channels = mcasp->channels; 1128 + /* 1129 + * But we can always allow channels upto the amount of 1130 + * the available tdm_slots. 1131 + */ 1132 + if (max_channels < tdm_slots) 1133 + max_channels = tdm_slots; 1247 1134 1248 1135 snd_pcm_hw_constraint_minmax(substream->runtime, 1249 1136 SNDRV_PCM_HW_PARAM_CHANNELS, 1250 1137 2, max_channels); 1251 1138 1252 - if (mcasp->chconstr[substream->stream].count) 1253 - snd_pcm_hw_constraint_list(substream->runtime, 1254 - 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1255 - &mcasp->chconstr[substream->stream]); 1139 + snd_pcm_hw_constraint_list(substream->runtime, 1140 + 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1141 + &mcasp->chconstr[substream->stream]); 1142 + 1143 + if (mcasp->slot_width) 1144 + snd_pcm_hw_constraint_minmax(substream->runtime, 1145 + SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 1146 + 8, mcasp->slot_width); 1256 1147 1257 1148 /* 1258 1149 * If we rely on implicit BCLK divider setting we should ··· 1314 1185 .set_fmt = davinci_mcasp_set_dai_fmt, 1315 1186 .set_clkdiv = davinci_mcasp_set_clkdiv, 1316 1187 .set_sysclk = davinci_mcasp_set_sysclk, 1188 + .set_tdm_slot = davinci_mcasp_set_tdm_slot, 1317 1189 }; 1318 1190 1319 1191 static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai) ··· 1429 1299 .ops = &davinci_mcasp_dai_ops, 1430 1300 1431 1301 .symmetric_samplebits = 1, 1302 + .symmetric_rates = 1, 1432 1303 }, 1433 1304 { 1434 1305 .name = "davinci-mcasp.1", ··· 1645 1514 return pdata; 1646 1515 } 1647 1516 1648 - /* All serializers must have equal number of channels */ 1649 - static int davinci_mcasp_ch_constraint(struct davinci_mcasp *mcasp, 1650 - struct snd_pcm_hw_constraint_list *cl, 1651 - int serializers) 1652 - { 1653 - unsigned int *list; 1654 - int i, count = 0; 1655 - 1656 - if (serializers <= 1) 1657 - return 0; 1658 - 1659 - list = devm_kzalloc(mcasp->dev, sizeof(unsigned int) * 1660 - (mcasp->tdm_slots + serializers - 2), 1661 - GFP_KERNEL); 1662 - if (!list) 1663 - return -ENOMEM; 1664 - 1665 - for (i = 2; i <= mcasp->tdm_slots; i++) 1666 - list[count++] = i; 1667 - 1668 - for (i = 2; i <= serializers; i++) 1669 - list[count++] = i*mcasp->tdm_slots; 1670 - 1671 - cl->count = count; 1672 - cl->list = list; 1673 - 1674 - return 0; 1675 - } 1676 - 1677 - 1678 - static int davinci_mcasp_init_ch_constraints(struct davinci_mcasp *mcasp) 1679 - { 1680 - int rx_serializers = 0, tx_serializers = 0, ret, i; 1681 - 1682 - for (i = 0; i < mcasp->num_serializer; i++) 1683 - if (mcasp->serial_dir[i] == TX_MODE) 1684 - tx_serializers++; 1685 - else if (mcasp->serial_dir[i] == RX_MODE) 1686 - rx_serializers++; 1687 - 1688 - ret = davinci_mcasp_ch_constraint(mcasp, &mcasp->chconstr[ 1689 - SNDRV_PCM_STREAM_PLAYBACK], 1690 - tx_serializers); 1691 - if (ret) 1692 - return ret; 1693 - 1694 - ret = davinci_mcasp_ch_constraint(mcasp, &mcasp->chconstr[ 1695 - SNDRV_PCM_STREAM_CAPTURE], 1696 - rx_serializers); 1697 - 1698 - return ret; 1699 - } 1700 - 1701 1517 enum { 1702 1518 PCM_EDMA, 1703 1519 PCM_SDMA, ··· 1763 1685 1764 1686 irq = platform_get_irq_byname(pdev, "common"); 1765 1687 if (irq >= 0) { 1766 - irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common\n", 1688 + irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common", 1767 1689 dev_name(&pdev->dev)); 1768 1690 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1769 1691 davinci_mcasp_common_irq_handler, ··· 1780 1702 1781 1703 irq = platform_get_irq_byname(pdev, "rx"); 1782 1704 if (irq >= 0) { 1783 - irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx\n", 1705 + irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx", 1784 1706 dev_name(&pdev->dev)); 1785 1707 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1786 1708 davinci_mcasp_rx_irq_handler, ··· 1795 1717 1796 1718 irq = platform_get_irq_byname(pdev, "tx"); 1797 1719 if (irq >= 0) { 1798 - irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_tx\n", 1720 + irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_tx", 1799 1721 dev_name(&pdev->dev)); 1800 1722 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1801 1723 davinci_mcasp_tx_irq_handler, ··· 1861 1783 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE; 1862 1784 } 1863 1785 1864 - ret = davinci_mcasp_init_ch_constraints(mcasp); 1786 + /* Allocate memory for long enough list for all possible 1787 + * scenarios. Maximum number tdm slots is 32 and there cannot 1788 + * be more serializers than given in the configuration. The 1789 + * serializer directions could be taken into account, but it 1790 + * would make code much more complex and save only couple of 1791 + * bytes. 1792 + */ 1793 + mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list = 1794 + devm_kzalloc(mcasp->dev, sizeof(unsigned int) * 1795 + (32 + mcasp->num_serializer - 2), 1796 + GFP_KERNEL); 1797 + 1798 + mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list = 1799 + devm_kzalloc(mcasp->dev, sizeof(unsigned int) * 1800 + (32 + mcasp->num_serializer - 2), 1801 + GFP_KERNEL); 1802 + 1803 + if (!mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list || 1804 + !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list) 1805 + return -ENOMEM; 1806 + 1807 + ret = davinci_mcasp_set_ch_constraints(mcasp); 1865 1808 if (ret) 1866 1809 goto err; 1867 1810
+3 -1
sound/soc/fsl/fsl-asoc-card.c
··· 488 488 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 489 489 } else { 490 490 dev_err(&pdev->dev, "unknown Device Tree compatible\n"); 491 - return -EINVAL; 491 + ret = -EINVAL; 492 + goto asrc_fail; 492 493 } 493 494 494 495 /* Common settings for corresponding Freescale CPU DAI driver */ ··· 593 592 { .compatible = "fsl,imx-audio-wm8960", }, 594 593 {} 595 594 }; 595 + MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids); 596 596 597 597 static struct platform_driver fsl_asoc_card_driver = { 598 598 .probe = fsl_asoc_card_probe,
+1
sound/soc/fsl/fsl_sai.c
··· 801 801 { .compatible = "fsl,imx6sx-sai", }, 802 802 { /* sentinel */ } 803 803 }; 804 + MODULE_DEVICE_TABLE(of, fsl_sai_ids); 804 805 805 806 static struct platform_driver fsl_sai_driver = { 806 807 .probe = fsl_sai_probe,
+3 -2
sound/soc/fsl/fsl_ssi.c
··· 249 249 250 250 static bool fsl_ssi_is_ac97(struct fsl_ssi_private *ssi_private) 251 251 { 252 - return !!(ssi_private->dai_fmt & SND_SOC_DAIFMT_AC97); 252 + return (ssi_private->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) == 253 + SND_SOC_DAIFMT_AC97; 253 254 } 254 255 255 256 static bool fsl_ssi_is_i2s_master(struct fsl_ssi_private *ssi_private) ··· 948 947 CCSR_SSI_SCR_TCH_EN); 949 948 } 950 949 951 - if (fmt & SND_SOC_DAIFMT_AC97) 950 + if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_AC97) 952 951 fsl_ssi_setup_ac97(ssi_private); 953 952 954 953 return 0;
+6 -2
sound/soc/generic/simple-card.c
··· 151 151 } 152 152 153 153 if (set->slots) { 154 - ret = snd_soc_dai_set_tdm_slot(dai, 0, 0, 154 + ret = snd_soc_dai_set_tdm_slot(dai, 155 + set->tx_slot_mask, 156 + set->rx_slot_mask, 155 157 set->slots, 156 158 set->slot_width); 157 159 if (ret && ret != -ENOTSUPP) { ··· 245 243 return ret; 246 244 247 245 /* Parse TDM slot */ 248 - ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width); 246 + ret = snd_soc_of_parse_tdm_slot(np, &dai->tx_slot_mask, 247 + &dai->rx_slot_mask, 248 + &dai->slots, &dai->slot_width); 249 249 if (ret) 250 250 return ret; 251 251
-17
sound/soc/intel/atom/sst-mfld-platform-pcm.c
··· 368 368 kfree(stream); 369 369 } 370 370 371 - static inline unsigned int get_current_pipe_id(struct snd_soc_dai *dai, 372 - struct snd_pcm_substream *substream) 373 - { 374 - struct sst_data *sst = snd_soc_dai_get_drvdata(dai); 375 - struct sst_dev_stream_map *map = sst->pdata->pdev_strm_map; 376 - struct sst_runtime_stream *stream = 377 - substream->runtime->private_data; 378 - u32 str_id = stream->stream_info.str_id; 379 - unsigned int pipe_id; 380 - 381 - pipe_id = map[str_id].device_id; 382 - 383 - dev_dbg(dai->dev, "got pipe_id = %#x for str_id = %d\n", 384 - pipe_id, str_id); 385 - return pipe_id; 386 - } 387 - 388 371 static int sst_media_prepare(struct snd_pcm_substream *substream, 389 372 struct snd_soc_dai *dai) 390 373 {
+1 -8
sound/soc/intel/boards/broadwell.c
··· 266 266 { 267 267 broadwell_rt286.dev = &pdev->dev; 268 268 269 - return snd_soc_register_card(&broadwell_rt286); 270 - } 271 - 272 - static int broadwell_audio_remove(struct platform_device *pdev) 273 - { 274 - snd_soc_unregister_card(&broadwell_rt286); 275 - return 0; 269 + return devm_snd_soc_register_card(&pdev->dev, &broadwell_rt286); 276 270 } 277 271 278 272 static struct platform_driver broadwell_audio = { 279 273 .probe = broadwell_audio_probe, 280 - .remove = broadwell_audio_remove, 281 274 .driver = { 282 275 .name = "broadwell-audio", 283 276 },
+12 -8
sound/soc/intel/haswell/sst-haswell-ipc.c
··· 302 302 struct sst_hsw_ipc_dx_reply dx; 303 303 void *dx_context; 304 304 dma_addr_t dx_context_paddr; 305 + enum sst_hsw_device_id dx_dev; 306 + enum sst_hsw_device_mclk dx_mclk; 307 + enum sst_hsw_device_mode dx_mode; 308 + u32 dx_clock_divider; 305 309 306 310 /* boot */ 307 311 wait_queue_head_t boot_wait; ··· 1404 1400 1405 1401 trace_ipc_request("set device config", dev); 1406 1402 1407 - config.ssp_interface = dev; 1408 - config.clock_frequency = mclk; 1409 - config.mode = mode; 1410 - config.clock_divider = clock_divider; 1403 + hsw->dx_dev = config.ssp_interface = dev; 1404 + hsw->dx_mclk = config.clock_frequency = mclk; 1405 + hsw->dx_mode = config.mode = mode; 1406 + hsw->dx_clock_divider = config.clock_divider = clock_divider; 1411 1407 if (mode == SST_HSW_DEVICE_TDM_CLOCK_MASTER) 1412 1408 config.channels = 4; 1413 1409 else ··· 1708 1704 return -EIO; 1709 1705 } 1710 1706 1711 - /* Set ADSP SSP port settings */ 1712 - ret = sst_hsw_device_set_config(hsw, SST_HSW_DEVICE_SSP_0, 1713 - SST_HSW_DEVICE_MCLK_FREQ_24_MHZ, 1714 - SST_HSW_DEVICE_CLOCK_MASTER, 9); 1707 + /* Set ADSP SSP port settings - sadly the FW does not store SSP port 1708 + settings as part of the PM context. */ 1709 + ret = sst_hsw_device_set_config(hsw, hsw->dx_dev, hsw->dx_mclk, 1710 + hsw->dx_mode, hsw->dx_clock_divider); 1715 1711 if (ret < 0) 1716 1712 dev_err(dev, "error: SSP re-initialization failed\n"); 1717 1713
-33
sound/soc/intel/skylake/skl-pcm.c
··· 510 510 }, 511 511 }, 512 512 { 513 - .name = "DMIC23 Pin", 514 - .ops = &skl_dmic_dai_ops, 515 - .capture = { 516 - .stream_name = "DMIC23 Rx", 517 - .channels_min = HDA_STEREO, 518 - .channels_max = HDA_STEREO, 519 - .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000, 520 - .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, 521 - }, 522 - }, 523 - { 524 513 .name = "HD-Codec Pin", 525 514 .ops = &skl_link_dai_ops, 526 515 .playback = { ··· 521 532 }, 522 533 .capture = { 523 534 .stream_name = "HD-Codec Rx", 524 - .channels_min = HDA_STEREO, 525 - .channels_max = HDA_STEREO, 526 - .rates = SNDRV_PCM_RATE_48000, 527 - .formats = SNDRV_PCM_FMTBIT_S16_LE, 528 - }, 529 - }, 530 - { 531 - .name = "HD-Codec-SPK Pin", 532 - .ops = &skl_link_dai_ops, 533 - .playback = { 534 - .stream_name = "HD-Codec-SPK Tx", 535 - .channels_min = HDA_STEREO, 536 - .channels_max = HDA_STEREO, 537 - .rates = SNDRV_PCM_RATE_48000, 538 - .formats = SNDRV_PCM_FMTBIT_S16_LE, 539 - }, 540 - }, 541 - { 542 - .name = "HD-Codec-AMIC Pin", 543 - .ops = &skl_link_dai_ops, 544 - .capture = { 545 - .stream_name = "HD-Codec-AMIC Rx", 546 535 .channels_min = HDA_STEREO, 547 536 .channels_max = HDA_STEREO, 548 537 .rates = SNDRV_PCM_RATE_48000,
+1
sound/soc/jz4740/jz4740-i2s.c
··· 485 485 { .compatible = "ingenic,jz4780-i2s", .data = (void *)JZ_I2S_JZ4780 }, 486 486 { /* sentinel */ } 487 487 }; 488 + MODULE_DEVICE_TABLE(of, jz4740_of_matches); 488 489 #endif 489 490 490 491 static int jz4740_i2s_dev_probe(struct platform_device *pdev)
+1
sound/soc/kirkwood/armada-370-db.c
··· 130 130 { .compatible = "marvell,a370db-audio" }, 131 131 { }, 132 132 }; 133 + MODULE_DEVICE_TABLE(of, a370db_dt_ids); 133 134 134 135 static struct platform_driver a370db_driver = { 135 136 .driver = {
+1 -10
sound/soc/mediatek/mt8173-max98090.c
··· 179 179 } 180 180 card->dev = &pdev->dev; 181 181 182 - ret = snd_soc_register_card(card); 182 + ret = devm_snd_soc_register_card(&pdev->dev, card); 183 183 if (ret) 184 184 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", 185 185 __func__, ret); 186 186 return ret; 187 - } 188 - 189 - static int mt8173_max98090_dev_remove(struct platform_device *pdev) 190 - { 191 - struct snd_soc_card *card = platform_get_drvdata(pdev); 192 - 193 - snd_soc_unregister_card(card); 194 - return 0; 195 187 } 196 188 197 189 static const struct of_device_id mt8173_max98090_dt_match[] = { ··· 201 209 #endif 202 210 }, 203 211 .probe = mt8173_max98090_dev_probe, 204 - .remove = mt8173_max98090_dev_remove, 205 212 }; 206 213 207 214 module_platform_driver(mt8173_max98090_driver);
+1 -10
sound/soc/mediatek/mt8173-rt5650-rt5676.c
··· 246 246 card->dev = &pdev->dev; 247 247 platform_set_drvdata(pdev, card); 248 248 249 - ret = snd_soc_register_card(card); 249 + ret = devm_snd_soc_register_card(&pdev->dev, card); 250 250 if (ret) 251 251 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", 252 252 __func__, ret); 253 253 return ret; 254 - } 255 - 256 - static int mt8173_rt5650_rt5676_dev_remove(struct platform_device *pdev) 257 - { 258 - struct snd_soc_card *card = platform_get_drvdata(pdev); 259 - 260 - snd_soc_unregister_card(card); 261 - return 0; 262 254 } 263 255 264 256 static const struct of_device_id mt8173_rt5650_rt5676_dt_match[] = { ··· 268 276 #endif 269 277 }, 270 278 .probe = mt8173_rt5650_rt5676_dev_probe, 271 - .remove = mt8173_rt5650_rt5676_dev_remove, 272 279 }; 273 280 274 281 module_platform_driver(mt8173_rt5650_rt5676_driver);
+17
sound/soc/mediatek/mtk-afe-pcm.c
··· 549 549 memif->substream = substream; 550 550 551 551 snd_soc_set_runtime_hwparams(substream, &mtk_afe_hardware); 552 + 553 + /* 554 + * Capture cannot use ping-pong buffer since hw_ptr at IRQ may be 555 + * smaller than period_size due to AFE's internal buffer. 556 + * This easily leads to overrun when avail_min is period_size. 557 + * One more period can hold the possible unread buffer. 558 + */ 559 + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 560 + ret = snd_pcm_hw_constraint_minmax(runtime, 561 + SNDRV_PCM_HW_PARAM_PERIODS, 562 + 3, 563 + mtk_afe_hardware.periods_max); 564 + if (ret < 0) { 565 + dev_err(afe->dev, "hw_constraint_minmax failed\n"); 566 + return ret; 567 + } 568 + } 552 569 ret = snd_pcm_hw_constraint_integer(runtime, 553 570 SNDRV_PCM_HW_PARAM_PERIODS); 554 571 if (ret < 0)
+1 -5
sound/soc/mxs/mxs-sgtl5000.c
··· 142 142 card->dev = &pdev->dev; 143 143 platform_set_drvdata(pdev, card); 144 144 145 - ret = snd_soc_register_card(card); 145 + ret = devm_snd_soc_register_card(&pdev->dev, card); 146 146 if (ret) { 147 147 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", 148 148 ret); ··· 154 154 155 155 static int mxs_sgtl5000_remove(struct platform_device *pdev) 156 156 { 157 - struct snd_soc_card *card = platform_get_drvdata(pdev); 158 - 159 157 mxs_saif_put_mclk(0); 160 - 161 - snd_soc_unregister_card(card); 162 158 163 159 return 0; 164 160 }
-2
sound/soc/pxa/Kconfig
··· 1 1 config SND_PXA2XX_SOC 2 2 tristate "SoC Audio for the Intel PXA2xx chip" 3 3 depends on ARCH_PXA 4 - select SND_ARM 5 4 select SND_PXA2XX_LIB 6 5 help 7 6 Say Y or M if you want to add support for codecs attached to ··· 24 25 config SND_PXA2XX_SOC_AC97 25 26 tristate 26 27 select AC97_BUS 27 - select SND_ARM 28 28 select SND_PXA2XX_LIB_AC97 29 29 select SND_SOC_AC97_BUS 30 30
+1 -8
sound/soc/pxa/brownstone.c
··· 116 116 int ret; 117 117 118 118 brownstone.dev = &pdev->dev; 119 - ret = snd_soc_register_card(&brownstone); 119 + ret = devm_snd_soc_register_card(&pdev->dev, &brownstone); 120 120 if (ret) 121 121 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 122 122 ret); 123 123 return ret; 124 - } 125 - 126 - static int brownstone_remove(struct platform_device *pdev) 127 - { 128 - snd_soc_unregister_card(&brownstone); 129 - return 0; 130 124 } 131 125 132 126 static struct platform_driver mmp_driver = { ··· 129 135 .pm = &snd_soc_pm_ops, 130 136 }, 131 137 .probe = brownstone_probe, 132 - .remove = brownstone_remove, 133 138 }; 134 139 135 140 module_platform_driver(mmp_driver);
+1 -10
sound/soc/pxa/corgi.c
··· 295 295 296 296 card->dev = &pdev->dev; 297 297 298 - ret = snd_soc_register_card(card); 298 + ret = devm_snd_soc_register_card(&pdev->dev, card); 299 299 if (ret) 300 300 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 301 301 ret); 302 302 return ret; 303 - } 304 - 305 - static int corgi_remove(struct platform_device *pdev) 306 - { 307 - struct snd_soc_card *card = platform_get_drvdata(pdev); 308 - 309 - snd_soc_unregister_card(card); 310 - return 0; 311 303 } 312 304 313 305 static struct platform_driver corgi_driver = { ··· 308 316 .pm = &snd_soc_pm_ops, 309 317 }, 310 318 .probe = corgi_probe, 311 - .remove = corgi_remove, 312 319 }; 313 320 314 321 module_platform_driver(corgi_driver);
+1 -4
sound/soc/pxa/e740_wm9705.c
··· 138 138 139 139 card->dev = &pdev->dev; 140 140 141 - ret = snd_soc_register_card(card); 141 + ret = devm_snd_soc_register_card(&pdev->dev, card); 142 142 if (ret) { 143 143 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 144 144 ret); ··· 149 149 150 150 static int e740_remove(struct platform_device *pdev) 151 151 { 152 - struct snd_soc_card *card = platform_get_drvdata(pdev); 153 - 154 152 gpio_free_array(e740_audio_gpios, ARRAY_SIZE(e740_audio_gpios)); 155 - snd_soc_unregister_card(card); 156 153 return 0; 157 154 } 158 155
+1 -4
sound/soc/pxa/e750_wm9705.c
··· 120 120 121 121 card->dev = &pdev->dev; 122 122 123 - ret = snd_soc_register_card(card); 123 + ret = devm_snd_soc_register_card(&pdev->dev, card); 124 124 if (ret) { 125 125 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 126 126 ret); ··· 131 131 132 132 static int e750_remove(struct platform_device *pdev) 133 133 { 134 - struct snd_soc_card *card = platform_get_drvdata(pdev); 135 - 136 134 gpio_free_array(e750_audio_gpios, ARRAY_SIZE(e750_audio_gpios)); 137 - snd_soc_unregister_card(card); 138 135 return 0; 139 136 } 140 137
+1 -4
sound/soc/pxa/e800_wm9712.c
··· 119 119 120 120 card->dev = &pdev->dev; 121 121 122 - ret = snd_soc_register_card(card); 122 + ret = devm_snd_soc_register_card(&pdev->dev, card); 123 123 if (ret) { 124 124 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 125 125 ret); ··· 130 130 131 131 static int e800_remove(struct platform_device *pdev) 132 132 { 133 - struct snd_soc_card *card = platform_get_drvdata(pdev); 134 - 135 133 gpio_free_array(e800_audio_gpios, ARRAY_SIZE(e800_audio_gpios)); 136 - snd_soc_unregister_card(card); 137 134 return 0; 138 135 } 139 136
+1 -3
sound/soc/pxa/hx4700.c
··· 193 193 return ret; 194 194 195 195 snd_soc_card_hx4700.dev = &pdev->dev; 196 - ret = snd_soc_register_card(&snd_soc_card_hx4700); 196 + ret = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_hx4700); 197 197 if (ret) 198 198 gpio_free_array(hx4700_audio_gpios, 199 199 ARRAY_SIZE(hx4700_audio_gpios)); ··· 203 203 204 204 static int hx4700_audio_remove(struct platform_device *pdev) 205 205 { 206 - snd_soc_unregister_card(&snd_soc_card_hx4700); 207 - 208 206 gpio_set_value(GPIO92_HX4700_HP_DRIVER, 0); 209 207 gpio_set_value(GPIO107_HX4700_SPK_nSD, 0); 210 208
+1 -10
sound/soc/pxa/imote2.c
··· 72 72 73 73 card->dev = &pdev->dev; 74 74 75 - ret = snd_soc_register_card(card); 75 + ret = devm_snd_soc_register_card(&pdev->dev, card); 76 76 if (ret) 77 77 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 78 78 ret); 79 79 return ret; 80 - } 81 - 82 - static int imote2_remove(struct platform_device *pdev) 83 - { 84 - struct snd_soc_card *card = platform_get_drvdata(pdev); 85 - 86 - snd_soc_unregister_card(card); 87 - return 0; 88 80 } 89 81 90 82 static struct platform_driver imote2_driver = { ··· 85 93 .pm = &snd_soc_pm_ops, 86 94 }, 87 95 .probe = imote2_probe, 88 - .remove = imote2_remove, 89 96 }; 90 97 91 98 module_platform_driver(imote2_driver);
+1 -10
sound/soc/pxa/mioa701_wm9713.c
··· 181 181 return -ENODEV; 182 182 183 183 mioa701.dev = &pdev->dev; 184 - rc = snd_soc_register_card(&mioa701); 184 + rc = devm_snd_soc_register_card(&pdev->dev, &mioa701); 185 185 if (!rc) 186 186 dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will" 187 187 "lead to overheating and possible destruction of your device." ··· 189 189 return rc; 190 190 } 191 191 192 - static int mioa701_wm9713_remove(struct platform_device *pdev) 193 - { 194 - struct snd_soc_card *card = platform_get_drvdata(pdev); 195 - 196 - snd_soc_unregister_card(card); 197 - return 0; 198 - } 199 - 200 192 static struct platform_driver mioa701_wm9713_driver = { 201 193 .probe = mioa701_wm9713_probe, 202 - .remove = mioa701_wm9713_remove, 203 194 .driver = { 204 195 .name = "mioa701-wm9713", 205 196 .pm = &snd_soc_pm_ops,
+1 -8
sound/soc/pxa/palm27x.c
··· 140 140 141 141 palm27x_asoc.dev = &pdev->dev; 142 142 143 - ret = snd_soc_register_card(&palm27x_asoc); 143 + ret = devm_snd_soc_register_card(&pdev->dev, &palm27x_asoc); 144 144 if (ret) 145 145 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 146 146 ret); 147 147 return ret; 148 148 } 149 149 150 - static int palm27x_asoc_remove(struct platform_device *pdev) 151 - { 152 - snd_soc_unregister_card(&palm27x_asoc); 153 - return 0; 154 - } 155 - 156 150 static struct platform_driver palm27x_wm9712_driver = { 157 151 .probe = palm27x_asoc_probe, 158 - .remove = palm27x_asoc_remove, 159 152 .driver = { 160 153 .name = "palm27x-asoc", 161 154 .pm = &snd_soc_pm_ops,
+1 -10
sound/soc/pxa/poodle.c
··· 267 267 268 268 card->dev = &pdev->dev; 269 269 270 - ret = snd_soc_register_card(card); 270 + ret = devm_snd_soc_register_card(&pdev->dev, card); 271 271 if (ret) 272 272 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 273 273 ret); 274 274 return ret; 275 - } 276 - 277 - static int poodle_remove(struct platform_device *pdev) 278 - { 279 - struct snd_soc_card *card = platform_get_drvdata(pdev); 280 - 281 - snd_soc_unregister_card(card); 282 - return 0; 283 275 } 284 276 285 277 static struct platform_driver poodle_driver = { ··· 280 288 .pm = &snd_soc_pm_ops, 281 289 }, 282 290 .probe = poodle_probe, 283 - .remove = poodle_remove, 284 291 }; 285 292 286 293 module_platform_driver(poodle_driver);
+1
sound/soc/pxa/pxa-ssp.c
··· 809 809 { .compatible = "mrvl,pxa-ssp-dai" }, 810 810 {} 811 811 }; 812 + MODULE_DEVICE_TABLE(of, pxa_ssp_of_ids); 812 813 #endif 813 814 814 815 static int asoc_ssp_probe(struct platform_device *pdev)
+2 -2
sound/soc/pxa/pxa2xx-ac97.c
··· 49 49 .reset = pxa2xx_ac97_cold_reset, 50 50 }; 51 51 52 - static unsigned long pxa2xx_ac97_pcm_stereo_in_req = 12; 52 + static unsigned long pxa2xx_ac97_pcm_stereo_in_req = 11; 53 53 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = { 54 54 .addr = __PREG(PCDR), 55 55 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, ··· 57 57 .filter_data = &pxa2xx_ac97_pcm_stereo_in_req, 58 58 }; 59 59 60 - static unsigned long pxa2xx_ac97_pcm_stereo_out_req = 11; 60 + static unsigned long pxa2xx_ac97_pcm_stereo_out_req = 12; 61 61 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = { 62 62 .addr = __PREG(PCDR), 63 63 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
+1
sound/soc/pxa/pxa2xx-pcm.c
··· 132 132 { .compatible = "mrvl,pxa-pcm-audio" }, 133 133 { } 134 134 }; 135 + MODULE_DEVICE_TABLE(of, snd_soc_pxa_audio_match); 135 136 #endif 136 137 137 138 static struct platform_driver pxa_pcm_driver = {
+1 -4
sound/soc/pxa/spitz.c
··· 305 305 306 306 card->dev = &pdev->dev; 307 307 308 - ret = snd_soc_register_card(card); 308 + ret = devm_snd_soc_register_card(&pdev->dev, card); 309 309 if (ret) { 310 310 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 311 311 ret); ··· 322 322 323 323 static int spitz_remove(struct platform_device *pdev) 324 324 { 325 - struct snd_soc_card *card = platform_get_drvdata(pdev); 326 - 327 - snd_soc_unregister_card(card); 328 325 gpio_free(spitz_mic_gpio); 329 326 return 0; 330 327 }
+1 -4
sound/soc/pxa/tosa.c
··· 233 233 234 234 card->dev = &pdev->dev; 235 235 236 - ret = snd_soc_register_card(card); 236 + ret = devm_snd_soc_register_card(&pdev->dev, card); 237 237 if (ret) { 238 238 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 239 239 ret); ··· 244 244 245 245 static int tosa_remove(struct platform_device *pdev) 246 246 { 247 - struct snd_soc_card *card = platform_get_drvdata(pdev); 248 - 249 247 gpio_free(TOSA_GPIO_L_MUTE); 250 - snd_soc_unregister_card(card); 251 248 return 0; 252 249 } 253 250
+1 -11
sound/soc/pxa/ttc-dkb.c
··· 128 128 129 129 card->dev = &pdev->dev; 130 130 131 - ret = snd_soc_register_card(card); 131 + ret = devm_snd_soc_register_card(&pdev->dev, card); 132 132 if (ret) 133 133 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 134 134 ret); 135 135 136 136 return ret; 137 - } 138 - 139 - static int ttc_dkb_remove(struct platform_device *pdev) 140 - { 141 - struct snd_soc_card *card = platform_get_drvdata(pdev); 142 - 143 - snd_soc_unregister_card(card); 144 - 145 - return 0; 146 137 } 147 138 148 139 static struct platform_driver ttc_dkb_driver = { ··· 142 151 .pm = &snd_soc_pm_ops, 143 152 }, 144 153 .probe = ttc_dkb_probe, 145 - .remove = ttc_dkb_remove, 146 154 }; 147 155 148 156 module_platform_driver(ttc_dkb_driver);
+2 -1
sound/soc/qcom/lpass-cpu.c
··· 438 438 if (IS_ERR(drvdata->mi2s_bit_clk[dai_id])) { 439 439 dev_err(&pdev->dev, 440 440 "%s() error getting mi2s-bit-clk: %ld\n", 441 - __func__, PTR_ERR(drvdata->mi2s_bit_clk[i])); 441 + __func__, 442 + PTR_ERR(drvdata->mi2s_bit_clk[dai_id])); 442 443 return PTR_ERR(drvdata->mi2s_bit_clk[dai_id]); 443 444 } 444 445 }
+2 -2
sound/soc/rockchip/Kconfig
··· 17 17 18 18 config SND_SOC_ROCKCHIP_MAX98090 19 19 tristate "ASoC support for Rockchip boards using a MAX98090 codec" 20 - depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB 20 + depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 21 21 select SND_SOC_ROCKCHIP_I2S 22 22 select SND_SOC_MAX98090 23 23 select SND_SOC_TS3A227E ··· 27 27 28 28 config SND_SOC_ROCKCHIP_RT5645 29 29 tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec" 30 - depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB 30 + depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 31 31 select SND_SOC_ROCKCHIP_I2S 32 32 select SND_SOC_RT5645 33 33 help
+1
sound/soc/sh/Kconfig
··· 37 37 config SND_SOC_RCAR 38 38 tristate "R-Car series SRU/SCU/SSIU/SSI support" 39 39 depends on DMA_OF 40 + depends on COMMON_CLK 40 41 select SND_SIMPLE_CARD 41 42 select REGMAP_MMIO 42 43 help
+234 -69
sound/soc/sh/rcar/adg.c
··· 7 7 * License. See the file "COPYING" in the main directory of this archive 8 8 * for more details. 9 9 */ 10 - #include <linux/sh_clk.h> 10 + #include <linux/clk-provider.h> 11 11 #include "rsnd.h" 12 12 13 13 #define CLKA 0 ··· 16 16 #define CLKI 3 17 17 #define CLKMAX 4 18 18 19 + #define CLKOUT 0 20 + #define CLKOUT1 1 21 + #define CLKOUT2 2 22 + #define CLKOUT3 3 23 + #define CLKOUTMAX 4 24 + 25 + #define BRRx_MASK(x) (0x3FF & x) 26 + 27 + static struct rsnd_mod_ops adg_ops = { 28 + .name = "adg", 29 + }; 30 + 19 31 struct rsnd_adg { 20 32 struct clk *clk[CLKMAX]; 33 + struct clk *clkout[CLKOUTMAX]; 34 + struct clk_onecell_data onecell; 35 + struct rsnd_mod mod; 21 36 22 - int rbga_rate_for_441khz_div_6; /* RBGA */ 23 - int rbgb_rate_for_48khz_div_6; /* RBGB */ 24 - u32 ckr; 37 + int rbga_rate_for_441khz; /* RBGA */ 38 + int rbgb_rate_for_48khz; /* RBGB */ 25 39 }; 26 40 27 41 #define for_each_rsnd_clk(pos, adg, i) \ ··· 43 29 (i < CLKMAX) && \ 44 30 ((pos) = adg->clk[i]); \ 45 31 i++) 32 + #define for_each_rsnd_clkout(pos, adg, i) \ 33 + for (i = 0; \ 34 + (i < CLKOUTMAX) && \ 35 + ((pos) = adg->clkout[i]); \ 36 + i++) 46 37 #define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg) 47 38 39 + static u32 rsnd_adg_calculate_rbgx(unsigned long div) 40 + { 41 + int i, ratio; 42 + 43 + if (!div) 44 + return 0; 45 + 46 + for (i = 3; i >= 0; i--) { 47 + ratio = 2 << (i * 2); 48 + if (0 == (div % ratio)) 49 + return (u32)((i << 8) | ((div / ratio) - 1)); 50 + } 51 + 52 + return ~0; 53 + } 48 54 49 55 static u32 rsnd_adg_ssi_ws_timing_gen2(struct rsnd_dai_stream *io) 50 56 { ··· 94 60 int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *mod, 95 61 struct rsnd_dai_stream *io) 96 62 { 63 + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 64 + struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 65 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 97 66 int id = rsnd_mod_id(mod); 98 67 int shift = (id % 2) ? 16 : 0; 99 68 u32 mask, val; ··· 106 69 val = val << shift; 107 70 mask = 0xffff << shift; 108 71 109 - rsnd_mod_bset(mod, CMDOUT_TIMSEL, mask, val); 72 + rsnd_mod_bset(adg_mod, CMDOUT_TIMSEL, mask, val); 110 73 111 74 return 0; 112 75 } 113 76 114 - static int rsnd_adg_set_src_timsel_gen2(struct rsnd_mod *mod, 77 + static int rsnd_adg_set_src_timsel_gen2(struct rsnd_mod *src_mod, 115 78 struct rsnd_dai_stream *io, 116 79 u32 timsel) 117 80 { 81 + struct rsnd_priv *priv = rsnd_mod_to_priv(src_mod); 82 + struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 83 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 118 84 int is_play = rsnd_io_is_play(io); 119 - int id = rsnd_mod_id(mod); 85 + int id = rsnd_mod_id(src_mod); 120 86 int shift = (id % 2) ? 16 : 0; 121 87 u32 mask, ws; 122 88 u32 in, out; 89 + 90 + rsnd_mod_confirm_src(src_mod); 123 91 124 92 ws = rsnd_adg_ssi_ws_timing_gen2(io); 125 93 ··· 137 95 138 96 switch (id / 2) { 139 97 case 0: 140 - rsnd_mod_bset(mod, SRCIN_TIMSEL0, mask, in); 141 - rsnd_mod_bset(mod, SRCOUT_TIMSEL0, mask, out); 98 + rsnd_mod_bset(adg_mod, SRCIN_TIMSEL0, mask, in); 99 + rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL0, mask, out); 142 100 break; 143 101 case 1: 144 - rsnd_mod_bset(mod, SRCIN_TIMSEL1, mask, in); 145 - rsnd_mod_bset(mod, SRCOUT_TIMSEL1, mask, out); 102 + rsnd_mod_bset(adg_mod, SRCIN_TIMSEL1, mask, in); 103 + rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL1, mask, out); 146 104 break; 147 105 case 2: 148 - rsnd_mod_bset(mod, SRCIN_TIMSEL2, mask, in); 149 - rsnd_mod_bset(mod, SRCOUT_TIMSEL2, mask, out); 106 + rsnd_mod_bset(adg_mod, SRCIN_TIMSEL2, mask, in); 107 + rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL2, mask, out); 150 108 break; 151 109 case 3: 152 - rsnd_mod_bset(mod, SRCIN_TIMSEL3, mask, in); 153 - rsnd_mod_bset(mod, SRCOUT_TIMSEL3, mask, out); 110 + rsnd_mod_bset(adg_mod, SRCIN_TIMSEL3, mask, in); 111 + rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL3, mask, out); 154 112 break; 155 113 case 4: 156 - rsnd_mod_bset(mod, SRCIN_TIMSEL4, mask, in); 157 - rsnd_mod_bset(mod, SRCOUT_TIMSEL4, mask, out); 114 + rsnd_mod_bset(adg_mod, SRCIN_TIMSEL4, mask, in); 115 + rsnd_mod_bset(adg_mod, SRCOUT_TIMSEL4, mask, out); 158 116 break; 159 117 } 160 118 161 119 return 0; 162 120 } 163 121 164 - int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod, 122 + int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *src_mod, 165 123 struct rsnd_dai_stream *io, 166 124 unsigned int src_rate, 167 125 unsigned int dst_rate) 168 126 { 169 - struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 127 + struct rsnd_priv *priv = rsnd_mod_to_priv(src_mod); 170 128 struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 129 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 171 130 struct device *dev = rsnd_priv_to_dev(priv); 172 131 int idx, sel, div, step, ret; 173 132 u32 val, en; ··· 177 134 clk_get_rate(adg->clk[CLKA]), /* 0000: CLKA */ 178 135 clk_get_rate(adg->clk[CLKB]), /* 0001: CLKB */ 179 136 clk_get_rate(adg->clk[CLKC]), /* 0010: CLKC */ 180 - adg->rbga_rate_for_441khz_div_6,/* 0011: RBGA */ 181 - adg->rbgb_rate_for_48khz_div_6, /* 0100: RBGB */ 137 + adg->rbga_rate_for_441khz, /* 0011: RBGA */ 138 + adg->rbgb_rate_for_48khz, /* 0100: RBGB */ 182 139 }; 140 + 141 + rsnd_mod_confirm_src(src_mod); 183 142 184 143 min = ~0; 185 144 val = 0; ··· 220 175 return -EIO; 221 176 } 222 177 223 - ret = rsnd_adg_set_src_timsel_gen2(mod, io, val); 178 + ret = rsnd_adg_set_src_timsel_gen2(src_mod, io, val); 224 179 if (ret < 0) { 225 180 dev_err(dev, "timsel error\n"); 226 181 return ret; 227 182 } 228 183 229 - rsnd_mod_bset(mod, DIV_EN, en, en); 184 + rsnd_mod_bset(adg_mod, DIV_EN, en, en); 230 185 231 186 dev_dbg(dev, "convert rate %d <-> %d\n", src_rate, dst_rate); 232 187 233 188 return 0; 234 189 } 235 190 236 - int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod, 191 + int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *src_mod, 237 192 struct rsnd_dai_stream *io) 238 193 { 239 194 u32 val = rsnd_adg_ssi_ws_timing_gen2(io); 240 195 241 - return rsnd_adg_set_src_timsel_gen2(mod, io, val); 196 + rsnd_mod_confirm_src(src_mod); 197 + 198 + return rsnd_adg_set_src_timsel_gen2(src_mod, io, val); 242 199 } 243 200 244 201 int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv, ··· 249 202 unsigned int dst_rate) 250 203 { 251 204 struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 205 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 252 206 struct device *dev = rsnd_priv_to_dev(priv); 253 207 int idx, sel, div, shift; 254 208 u32 mask, val; ··· 259 211 clk_get_rate(adg->clk[CLKB]), /* 001: CLKB */ 260 212 clk_get_rate(adg->clk[CLKC]), /* 010: CLKC */ 261 213 0, /* 011: MLBCLK (not used) */ 262 - adg->rbga_rate_for_441khz_div_6,/* 100: RBGA */ 263 - adg->rbgb_rate_for_48khz_div_6, /* 101: RBGB */ 214 + adg->rbga_rate_for_441khz, /* 100: RBGA */ 215 + adg->rbgb_rate_for_48khz, /* 101: RBGB */ 264 216 }; 265 217 266 218 /* find div (= 1/128, 1/256, 1/512, 1/1024, 1/2048 */ ··· 286 238 287 239 switch (id / 4) { 288 240 case 0: 289 - rsnd_mod_bset(mod, AUDIO_CLK_SEL3, mask, val); 241 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL3, mask, val); 290 242 break; 291 243 case 1: 292 - rsnd_mod_bset(mod, AUDIO_CLK_SEL4, mask, val); 244 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL4, mask, val); 293 245 break; 294 246 case 2: 295 - rsnd_mod_bset(mod, AUDIO_CLK_SEL5, mask, val); 247 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL5, mask, val); 296 248 break; 297 249 } 298 250 ··· 305 257 return 0; 306 258 } 307 259 308 - static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val) 260 + static void rsnd_adg_set_ssi_clk(struct rsnd_mod *ssi_mod, u32 val) 309 261 { 310 - int id = rsnd_mod_id(mod); 262 + struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 263 + struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 264 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 265 + int id = rsnd_mod_id(ssi_mod); 311 266 int shift = (id % 4) * 8; 312 267 u32 mask = 0xFF << shift; 268 + 269 + rsnd_mod_confirm_ssi(ssi_mod); 313 270 314 271 val = val << shift; 315 272 ··· 327 274 328 275 switch (id / 4) { 329 276 case 0: 330 - rsnd_mod_bset(mod, AUDIO_CLK_SEL0, mask, val); 277 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL0, mask, val); 331 278 break; 332 279 case 1: 333 - rsnd_mod_bset(mod, AUDIO_CLK_SEL1, mask, val); 280 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL1, mask, val); 334 281 break; 335 282 case 2: 336 - rsnd_mod_bset(mod, AUDIO_CLK_SEL2, mask, val); 283 + rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL2, mask, val); 337 284 break; 338 285 } 339 286 } ··· 379 326 } 380 327 381 328 /* 382 - * find 1/6 clock from BRGA/BRGB 329 + * find divided clock from BRGA/BRGB 383 330 */ 384 - if (rate == adg->rbga_rate_for_441khz_div_6) { 331 + if (rate == adg->rbga_rate_for_441khz) { 385 332 data = 0x10; 386 333 goto found_clock; 387 334 } 388 335 389 - if (rate == adg->rbgb_rate_for_48khz_div_6) { 336 + if (rate == adg->rbgb_rate_for_48khz) { 390 337 data = 0x20; 391 338 goto found_clock; 392 339 } ··· 395 342 396 343 found_clock: 397 344 398 - /* see rsnd_adg_ssi_clk_init() */ 399 - rsnd_mod_bset(mod, SSICKR, 0x00FF0000, adg->ckr); 400 - rsnd_mod_write(mod, BRRA, 0x00000002); /* 1/6 */ 401 - rsnd_mod_write(mod, BRRB, 0x00000002); /* 1/6 */ 402 - 403 345 /* 404 346 * This "mod" = "ssi" here. 405 347 * we can get "ssi id" from mod 406 348 */ 407 349 rsnd_adg_set_ssi_clk(mod, data); 408 350 409 - dev_dbg(dev, "ADG: ssi%d selects clk%d = %d", 410 - rsnd_mod_id(mod), i, rate); 351 + dev_dbg(dev, "ADG: %s[%d] selects 0x%x for %d\n", 352 + rsnd_mod_name(mod), rsnd_mod_id(mod), 353 + data, rate); 411 354 412 355 return 0; 413 356 } 414 357 415 - static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg) 358 + static void rsnd_adg_get_clkin(struct rsnd_priv *priv, 359 + struct rsnd_adg *adg) 360 + { 361 + struct device *dev = rsnd_priv_to_dev(priv); 362 + struct clk *clk; 363 + static const char * const clk_name[] = { 364 + [CLKA] = "clk_a", 365 + [CLKB] = "clk_b", 366 + [CLKC] = "clk_c", 367 + [CLKI] = "clk_i", 368 + }; 369 + int i; 370 + 371 + for (i = 0; i < CLKMAX; i++) { 372 + clk = devm_clk_get(dev, clk_name[i]); 373 + adg->clk[i] = IS_ERR(clk) ? NULL : clk; 374 + } 375 + 376 + for_each_rsnd_clk(clk, adg, i) 377 + dev_dbg(dev, "clk %d : %p : %ld\n", i, clk, clk_get_rate(clk)); 378 + } 379 + 380 + static void rsnd_adg_get_clkout(struct rsnd_priv *priv, 381 + struct rsnd_adg *adg) 416 382 { 417 383 struct clk *clk; 418 - unsigned long rate; 419 - u32 ckr; 384 + struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 385 + struct device *dev = rsnd_priv_to_dev(priv); 386 + struct device_node *np = dev->of_node; 387 + u32 ckr, rbgx, rbga, rbgb; 388 + u32 rate, req_rate, div; 389 + uint32_t count = 0; 390 + unsigned long req_48kHz_rate, req_441kHz_rate; 420 391 int i; 392 + const char *parent_clk_name = NULL; 393 + static const char * const clkout_name[] = { 394 + [CLKOUT] = "audio_clkout", 395 + [CLKOUT1] = "audio_clkout1", 396 + [CLKOUT2] = "audio_clkout2", 397 + [CLKOUT3] = "audio_clkout3", 398 + }; 421 399 int brg_table[] = { 422 400 [CLKA] = 0x0, 423 401 [CLKB] = 0x1, ··· 456 372 [CLKI] = 0x2, 457 373 }; 458 374 375 + of_property_read_u32(np, "#clock-cells", &count); 376 + 377 + /* 378 + * ADG supports BRRA/BRRB output only 379 + * this means all clkout0/1/2/3 will be same rate 380 + */ 381 + of_property_read_u32(np, "clock-frequency", &req_rate); 382 + req_48kHz_rate = 0; 383 + req_441kHz_rate = 0; 384 + if (0 == (req_rate % 44100)) 385 + req_441kHz_rate = req_rate; 386 + if (0 == (req_rate % 48000)) 387 + req_48kHz_rate = req_rate; 388 + 459 389 /* 460 390 * This driver is assuming that AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC 461 391 * have 44.1kHz or 48kHz base clocks for now. 462 392 * 463 393 * SSI itself can divide parent clock by 1/1 - 1/16 464 - * So, BRGA outputs 44.1kHz base parent clock 1/32, 465 - * and, BRGB outputs 48.0kHz base parent clock 1/32 here. 466 394 * see 467 395 * rsnd_adg_ssi_clk_try_start() 396 + * rsnd_ssi_master_clk_start() 468 397 */ 469 398 ckr = 0; 470 - adg->rbga_rate_for_441khz_div_6 = 0; 471 - adg->rbgb_rate_for_48khz_div_6 = 0; 399 + rbga = 2; /* default 1/6 */ 400 + rbgb = 2; /* default 1/6 */ 401 + adg->rbga_rate_for_441khz = 0; 402 + adg->rbgb_rate_for_48khz = 0; 472 403 for_each_rsnd_clk(clk, adg, i) { 473 404 rate = clk_get_rate(clk); 474 405 ··· 491 392 continue; 492 393 493 394 /* RBGA */ 494 - if (!adg->rbga_rate_for_441khz_div_6 && (0 == rate % 44100)) { 495 - adg->rbga_rate_for_441khz_div_6 = rate / 6; 496 - ckr |= brg_table[i] << 20; 395 + if (!adg->rbga_rate_for_441khz && (0 == rate % 44100)) { 396 + div = 6; 397 + if (req_441kHz_rate) 398 + div = rate / req_441kHz_rate; 399 + rbgx = rsnd_adg_calculate_rbgx(div); 400 + if (BRRx_MASK(rbgx) == rbgx) { 401 + rbga = rbgx; 402 + adg->rbga_rate_for_441khz = rate / div; 403 + ckr |= brg_table[i] << 20; 404 + if (req_441kHz_rate) 405 + parent_clk_name = __clk_get_name(clk); 406 + } 497 407 } 498 408 499 409 /* RBGB */ 500 - if (!adg->rbgb_rate_for_48khz_div_6 && (0 == rate % 48000)) { 501 - adg->rbgb_rate_for_48khz_div_6 = rate / 6; 502 - ckr |= brg_table[i] << 16; 410 + if (!adg->rbgb_rate_for_48khz && (0 == rate % 48000)) { 411 + div = 6; 412 + if (req_48kHz_rate) 413 + div = rate / req_48kHz_rate; 414 + rbgx = rsnd_adg_calculate_rbgx(div); 415 + if (BRRx_MASK(rbgx) == rbgx) { 416 + rbgb = rbgx; 417 + adg->rbgb_rate_for_48khz = rate / div; 418 + ckr |= brg_table[i] << 16; 419 + if (req_48kHz_rate) { 420 + parent_clk_name = __clk_get_name(clk); 421 + ckr |= 0x80000000; 422 + } 423 + } 503 424 } 504 425 } 505 426 506 - adg->ckr = ckr; 427 + /* 428 + * ADG supports BRRA/BRRB output only. 429 + * this means all clkout0/1/2/3 will be * same rate 430 + */ 431 + 432 + /* 433 + * for clkout 434 + */ 435 + if (!count) { 436 + clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], 437 + parent_clk_name, 438 + (parent_clk_name) ? 439 + 0 : CLK_IS_ROOT, req_rate); 440 + if (!IS_ERR(clk)) { 441 + adg->clkout[CLKOUT] = clk; 442 + of_clk_add_provider(np, of_clk_src_simple_get, clk); 443 + } 444 + } 445 + /* 446 + * for clkout0/1/2/3 447 + */ 448 + else { 449 + for (i = 0; i < CLKOUTMAX; i++) { 450 + clk = clk_register_fixed_rate(dev, clkout_name[i], 451 + parent_clk_name, 452 + (parent_clk_name) ? 453 + 0 : CLK_IS_ROOT, 454 + req_rate); 455 + if (!IS_ERR(clk)) { 456 + adg->onecell.clks = adg->clkout; 457 + adg->onecell.clk_num = CLKOUTMAX; 458 + 459 + adg->clkout[i] = clk; 460 + 461 + of_clk_add_provider(np, of_clk_src_onecell_get, 462 + &adg->onecell); 463 + } 464 + } 465 + } 466 + 467 + rsnd_mod_bset(adg_mod, SSICKR, 0x00FF0000, ckr); 468 + rsnd_mod_write(adg_mod, BRRA, rbga); 469 + rsnd_mod_write(adg_mod, BRRB, rbgb); 470 + 471 + for_each_rsnd_clkout(clk, adg, i) 472 + dev_dbg(dev, "clkout %d : %p : %ld\n", i, clk, clk_get_rate(clk)); 473 + dev_dbg(dev, "SSICKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n", 474 + ckr, rbga, rbgb); 507 475 } 508 476 509 477 int rsnd_adg_probe(struct platform_device *pdev, ··· 579 413 { 580 414 struct rsnd_adg *adg; 581 415 struct device *dev = rsnd_priv_to_dev(priv); 582 - struct clk *clk; 583 - int i; 584 416 585 417 adg = devm_kzalloc(dev, sizeof(*adg), GFP_KERNEL); 586 418 if (!adg) { ··· 586 422 return -ENOMEM; 587 423 } 588 424 589 - adg->clk[CLKA] = devm_clk_get(dev, "clk_a"); 590 - adg->clk[CLKB] = devm_clk_get(dev, "clk_b"); 591 - adg->clk[CLKC] = devm_clk_get(dev, "clk_c"); 592 - adg->clk[CLKI] = devm_clk_get(dev, "clk_i"); 425 + /* 426 + * ADG is special module. 427 + * Use ADG mod without rsnd_mod_init() to make debug easy 428 + * for rsnd_write/rsnd_read 429 + */ 430 + adg->mod.ops = &adg_ops; 431 + adg->mod.priv = priv; 593 432 594 - for_each_rsnd_clk(clk, adg, i) 595 - dev_dbg(dev, "clk %d : %p : %ld\n", i, clk, clk_get_rate(clk)); 596 - 597 - rsnd_adg_ssi_clk_init(priv, adg); 433 + rsnd_adg_get_clkin(priv, adg); 434 + rsnd_adg_get_clkout(priv, adg); 598 435 599 436 priv->adg = adg; 600 437
+12
sound/soc/sh/rcar/core.c
··· 110 110 static const struct of_device_id rsnd_of_match[] = { 111 111 { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 }, 112 112 { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 }, 113 + { .compatible = "renesas,rcar_sound-gen3", .data = &rsnd_of_data_gen2 }, /* gen2 compatible */ 113 114 {}, 114 115 }; 115 116 MODULE_DEVICE_TABLE(of, rsnd_of_match); ··· 126 125 ((io)->info ? (io)->info->name : NULL) 127 126 #define rsnd_info_id(priv, io, name) \ 128 127 ((io)->info->name - priv->info->name##_info) 128 + 129 + void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type) 130 + { 131 + if (mod->type != type) { 132 + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 133 + struct device *dev = rsnd_priv_to_dev(priv); 134 + 135 + dev_warn(dev, "%s[%d] is not your expected module\n", 136 + rsnd_mod_name(mod), rsnd_mod_id(mod)); 137 + } 138 + } 129 139 130 140 /* 131 141 * rsnd_mod functions
+3 -3
sound/soc/sh/rcar/ctu.c
··· 66 66 if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv))) 67 67 id = 0; 68 68 69 - return &((struct rsnd_ctu *)(priv->ctu) + id)->mod; 69 + return rsnd_mod_get((struct rsnd_ctu *)(priv->ctu) + id); 70 70 } 71 71 72 72 static void rsnd_of_parse_ctu(struct platform_device *pdev, ··· 150 150 151 151 ctu->info = &info->ctu_info[i]; 152 152 153 - ret = rsnd_mod_init(priv, &ctu->mod, &rsnd_ctu_ops, 153 + ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops, 154 154 clk, RSND_MOD_CTU, i); 155 155 if (ret) 156 156 return ret; ··· 166 166 int i; 167 167 168 168 for_each_rsnd_ctu(ctu, priv, i) { 169 - rsnd_mod_quit(&ctu->mod); 169 + rsnd_mod_quit(rsnd_mod_get(ctu)); 170 170 } 171 171 }
+3 -3
sound/soc/sh/rcar/dvc.c
··· 282 282 if (WARN_ON(id < 0 || id >= rsnd_dvc_nr(priv))) 283 283 id = 0; 284 284 285 - return &((struct rsnd_dvc *)(priv->dvc) + id)->mod; 285 + return rsnd_mod_get((struct rsnd_dvc *)(priv->dvc) + id); 286 286 } 287 287 288 288 static void rsnd_of_parse_dvc(struct platform_device *pdev, ··· 361 361 362 362 dvc->info = &info->dvc_info[i]; 363 363 364 - ret = rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops, 364 + ret = rsnd_mod_init(priv, rsnd_mod_get(dvc), &rsnd_dvc_ops, 365 365 clk, RSND_MOD_DVC, i); 366 366 if (ret) 367 367 return ret; ··· 377 377 int i; 378 378 379 379 for_each_rsnd_dvc(dvc, priv, i) { 380 - rsnd_mod_quit(&dvc->mod); 380 + rsnd_mod_quit(rsnd_mod_get(dvc)); 381 381 } 382 382 }
+3 -3
sound/soc/sh/rcar/mix.c
··· 99 99 if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv))) 100 100 id = 0; 101 101 102 - return &((struct rsnd_mix *)(priv->mix) + id)->mod; 102 + return rsnd_mod_get((struct rsnd_mix *)(priv->mix) + id); 103 103 } 104 104 105 105 static void rsnd_of_parse_mix(struct platform_device *pdev, ··· 179 179 180 180 mix->info = &info->mix_info[i]; 181 181 182 - ret = rsnd_mod_init(priv, &mix->mod, &rsnd_mix_ops, 182 + ret = rsnd_mod_init(priv, rsnd_mod_get(mix), &rsnd_mix_ops, 183 183 clk, RSND_MOD_MIX, i); 184 184 if (ret) 185 185 return ret; ··· 195 195 int i; 196 196 197 197 for_each_rsnd_mix(mix, priv, i) { 198 - rsnd_mod_quit(&mix->mod); 198 + rsnd_mod_quit(rsnd_mod_get(mix)); 199 199 } 200 200 }
+13 -2
sound/soc/sh/rcar/rsnd.h
··· 214 214 }; 215 215 #define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en) 216 216 #define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp) 217 + #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) 217 218 218 219 void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma); 219 220 void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma); ··· 225 224 struct rsnd_priv *priv); 226 225 struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, 227 226 struct rsnd_mod *mod, char *name); 228 - 229 - #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) 230 227 231 228 /* 232 229 * R-Car sound mod ··· 331 332 #define rsnd_mod_id(mod) ((mod) ? (mod)->id : -1) 332 333 #define rsnd_mod_hw_start(mod) clk_enable((mod)->clk) 333 334 #define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk) 335 + #define rsnd_mod_get(ip) (&(ip)->mod) 334 336 335 337 int rsnd_mod_init(struct rsnd_priv *priv, 336 338 struct rsnd_mod *mod, ··· 626 626 void rsnd_dvc_remove(struct platform_device *pdev, 627 627 struct rsnd_priv *priv); 628 628 struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id); 629 + 630 + #ifdef DEBUG 631 + void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type); 632 + #define rsnd_mod_confirm_ssi(mssi) rsnd_mod_make_sure(mssi, RSND_MOD_SSI) 633 + #define rsnd_mod_confirm_src(msrc) rsnd_mod_make_sure(msrc, RSND_MOD_SRC) 634 + #define rsnd_mod_confirm_dvc(mdvc) rsnd_mod_make_sure(mdvc, RSND_MOD_DVC) 635 + #else 636 + #define rsnd_mod_confirm_ssi(mssi) 637 + #define rsnd_mod_confirm_src(msrc) 638 + #define rsnd_mod_confirm_dvc(mdvc) 639 + #endif 629 640 630 641 #endif
+5 -12
sound/soc/sh/rcar/src.c
··· 918 918 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 919 919 } 920 920 921 - static int rsnd_src_pcm_new(struct rsnd_mod *mod, 921 + static int rsnd_src_pcm_new_gen2(struct rsnd_mod *mod, 922 922 struct rsnd_dai_stream *io, 923 923 struct snd_soc_pcm_runtime *rtd) 924 924 { 925 - struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 926 925 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 927 926 struct rsnd_src *src = rsnd_mod_to_src(mod); 928 927 int ret; ··· 929 930 /* 930 931 * enable SRC sync convert if possible 931 932 */ 932 - 933 - /* 934 - * Gen1 is not supported 935 - */ 936 - if (rsnd_is_gen1(priv)) 937 - return 0; 938 933 939 934 /* 940 935 * SRC sync convert needs clock master ··· 968 975 .start = rsnd_src_start_gen2, 969 976 .stop = rsnd_src_stop_gen2, 970 977 .hw_params = rsnd_src_hw_params, 971 - .pcm_new = rsnd_src_pcm_new, 978 + .pcm_new = rsnd_src_pcm_new_gen2, 972 979 }; 973 980 974 981 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) ··· 976 983 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 977 984 id = 0; 978 985 979 - return &((struct rsnd_src *)(priv->src) + id)->mod; 986 + return rsnd_mod_get((struct rsnd_src *)(priv->src) + id); 980 987 } 981 988 982 989 static void rsnd_of_parse_src(struct platform_device *pdev, ··· 1071 1078 1072 1079 src->info = &info->src_info[i]; 1073 1080 1074 - ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i); 1081 + ret = rsnd_mod_init(priv, rsnd_mod_get(src), ops, clk, RSND_MOD_SRC, i); 1075 1082 if (ret) 1076 1083 return ret; 1077 1084 } ··· 1086 1093 int i; 1087 1094 1088 1095 for_each_rsnd_src(src, priv, i) { 1089 - rsnd_mod_quit(&src->mod); 1096 + rsnd_mod_quit(rsnd_mod_get(src)); 1090 1097 } 1091 1098 }
+47 -43
sound/soc/sh/rcar/ssi.c
··· 128 128 struct rsnd_priv *priv = rsnd_io_to_priv(io); 129 129 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 130 130 struct device *dev = rsnd_priv_to_dev(priv); 131 - int i, j, ret; 132 - int adg_clk_div_table[] = { 133 - 1, 6, /* see adg.c */ 134 - }; 131 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 132 + int j, ret; 135 133 int ssi_clk_mul_table[] = { 136 134 1, 2, 4, 8, 16, 6, 12, 137 135 }; ··· 139 141 /* 140 142 * Find best clock, and try to start ADG 141 143 */ 142 - for (i = 0; i < ARRAY_SIZE(adg_clk_div_table); i++) { 143 - for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) { 144 + for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) { 144 145 145 - /* 146 - * this driver is assuming that 147 - * system word is 64fs (= 2 x 32bit) 148 - * see rsnd_ssi_init() 149 - */ 150 - main_rate = rate / adg_clk_div_table[i] 151 - * 32 * 2 * ssi_clk_mul_table[j]; 146 + /* 147 + * this driver is assuming that 148 + * system word is 64fs (= 2 x 32bit) 149 + * see rsnd_ssi_init() 150 + */ 151 + main_rate = rate * 32 * 2 * ssi_clk_mul_table[j]; 152 152 153 - ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate); 154 - if (0 == ret) { 155 - ssi->cr_clk = FORCE | SWL_32 | 156 - SCKD | SWSD | CKDV(j); 153 + ret = rsnd_adg_ssi_clk_try_start(mod, main_rate); 154 + if (0 == ret) { 155 + ssi->cr_clk = FORCE | SWL_32 | 156 + SCKD | SWSD | CKDV(j); 157 157 158 - dev_dbg(dev, "%s[%d] outputs %u Hz\n", 159 - rsnd_mod_name(&ssi->mod), 160 - rsnd_mod_id(&ssi->mod), rate); 158 + dev_dbg(dev, "%s[%d] outputs %u Hz\n", 159 + rsnd_mod_name(mod), 160 + rsnd_mod_id(mod), rate); 161 161 162 - return 0; 163 - } 162 + return 0; 164 163 } 165 164 } 166 165 ··· 167 172 168 173 static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi) 169 174 { 175 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 176 + 170 177 ssi->cr_clk = 0; 171 - rsnd_adg_ssi_clk_stop(&ssi->mod); 178 + rsnd_adg_ssi_clk_stop(mod); 172 179 } 173 180 174 181 static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi, ··· 179 182 struct rsnd_priv *priv = rsnd_io_to_priv(io); 180 183 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 181 184 struct device *dev = rsnd_priv_to_dev(priv); 185 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 182 186 u32 cr_mode; 183 187 u32 cr; 184 188 185 189 if (0 == ssi->usrcnt) { 186 - rsnd_mod_hw_start(&ssi->mod); 190 + rsnd_mod_hw_start(mod); 187 191 188 192 if (rsnd_rdai_is_clk_master(rdai)) { 189 193 struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi); ··· 196 198 } 197 199 } 198 200 199 - if (rsnd_ssi_is_dma_mode(&ssi->mod)) { 201 + if (rsnd_ssi_is_dma_mode(mod)) { 200 202 cr_mode = UIEN | OIEN | /* over/under run */ 201 203 DMEN; /* DMA : enable DMA */ 202 204 } else { ··· 208 210 cr_mode | 209 211 EN; 210 212 211 - rsnd_mod_write(&ssi->mod, SSICR, cr); 213 + rsnd_mod_write(mod, SSICR, cr); 212 214 213 215 /* enable WS continue */ 214 216 if (rsnd_rdai_is_clk_master(rdai)) 215 - rsnd_mod_write(&ssi->mod, SSIWSR, CONT); 217 + rsnd_mod_write(mod, SSIWSR, CONT); 216 218 217 219 /* clear error status */ 218 - rsnd_mod_write(&ssi->mod, SSISR, 0); 220 + rsnd_mod_write(mod, SSISR, 0); 219 221 220 222 ssi->usrcnt++; 221 223 222 224 dev_dbg(dev, "%s[%d] hw started\n", 223 - rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); 225 + rsnd_mod_name(mod), rsnd_mod_id(mod)); 224 226 } 225 227 226 228 static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi) 227 229 { 228 - struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); 230 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 231 + struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 229 232 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 230 233 struct device *dev = rsnd_priv_to_dev(priv); 231 234 u32 cr; ··· 246 247 cr = ssi->cr_own | 247 248 ssi->cr_clk; 248 249 249 - rsnd_mod_write(&ssi->mod, SSICR, cr | EN); 250 - rsnd_ssi_status_check(&ssi->mod, DIRQ); 250 + rsnd_mod_write(mod, SSICR, cr | EN); 251 + rsnd_ssi_status_check(mod, DIRQ); 251 252 252 253 /* 253 254 * disable SSI, 254 255 * and, wait idle state 255 256 */ 256 - rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */ 257 - rsnd_ssi_status_check(&ssi->mod, IIRQ); 257 + rsnd_mod_write(mod, SSICR, cr); /* disabled all */ 258 + rsnd_ssi_status_check(mod, IIRQ); 258 259 259 260 if (rsnd_rdai_is_clk_master(rdai)) { 260 261 struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi); ··· 265 266 rsnd_ssi_master_clk_stop(ssi); 266 267 } 267 268 268 - rsnd_mod_hw_stop(&ssi->mod); 269 + rsnd_mod_hw_stop(mod); 269 270 270 271 ssi->chan = 0; 271 272 } 272 273 273 274 dev_dbg(dev, "%s[%d] hw stopped\n", 274 - rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); 275 + rsnd_mod_name(mod), rsnd_mod_id(mod)); 275 276 } 276 277 277 278 /* ··· 370 371 /* It will be removed on rsnd_ssi_hw_stop */ 371 372 ssi->chan = chan; 372 373 if (ssi_parent) 373 - return rsnd_ssi_hw_params(&ssi_parent->mod, io, 374 + return rsnd_ssi_hw_params(rsnd_mod_get(ssi_parent), io, 374 375 substream, params); 375 376 376 377 return 0; ··· 378 379 379 380 static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status) 380 381 { 382 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 383 + 381 384 /* under/over flow error */ 382 385 if (status & (UIRQ | OIRQ)) { 383 386 ssi->err++; 384 387 385 388 /* clear error status */ 386 - rsnd_mod_write(&ssi->mod, SSISR, 0); 389 + rsnd_mod_write(mod, SSISR, 0); 387 390 } 388 391 } 389 392 ··· 657 656 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv))) 658 657 id = 0; 659 658 660 - return &((struct rsnd_ssi *)(priv->ssi) + id)->mod; 659 + return rsnd_mod_get((struct rsnd_ssi *)(priv->ssi) + id); 661 660 } 662 661 663 662 int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod) ··· 669 668 670 669 static void rsnd_ssi_parent_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi) 671 670 { 672 - if (!rsnd_ssi_is_pin_sharing(&ssi->mod)) 671 + struct rsnd_mod *mod = rsnd_mod_get(ssi); 672 + 673 + if (!rsnd_ssi_is_pin_sharing(mod)) 673 674 return; 674 675 675 - switch (rsnd_mod_id(&ssi->mod)) { 676 + switch (rsnd_mod_id(mod)) { 676 677 case 1: 677 678 case 2: 678 679 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0)); ··· 797 794 else if (rsnd_ssi_pio_available(ssi)) 798 795 ops = &rsnd_ssi_pio_ops; 799 796 800 - ret = rsnd_mod_init(priv, &ssi->mod, ops, clk, RSND_MOD_SSI, i); 797 + ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk, 798 + RSND_MOD_SSI, i); 801 799 if (ret) 802 800 return ret; 803 801 ··· 815 811 int i; 816 812 817 813 for_each_rsnd_ssi(ssi, priv, i) { 818 - rsnd_mod_quit(&ssi->mod); 814 + rsnd_mod_quit(rsnd_mod_get(ssi)); 819 815 } 820 816 }
+24 -61
sound/soc/sh/siu_dai.c
··· 738 738 struct siu_info *info; 739 739 int ret; 740 740 741 - info = kmalloc(sizeof(*info), GFP_KERNEL); 741 + info = devm_kmalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 742 742 if (!info) 743 743 return -ENOMEM; 744 744 siu_i2s_data = info; ··· 746 746 747 747 ret = request_firmware(&fw_entry, "siu_spb.bin", &pdev->dev); 748 748 if (ret) 749 - goto ereqfw; 749 + return ret; 750 750 751 751 /* 752 752 * Loaded firmware is "const" - read only, but we have to modify it in ··· 757 757 release_firmware(fw_entry); 758 758 759 759 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 760 - if (!res) { 761 - ret = -ENODEV; 762 - goto egetres; 763 - } 760 + if (!res) 761 + return -ENODEV; 764 762 765 - region = request_mem_region(res->start, resource_size(res), 766 - pdev->name); 763 + region = devm_request_mem_region(&pdev->dev, res->start, 764 + resource_size(res), pdev->name); 767 765 if (!region) { 768 766 dev_err(&pdev->dev, "SIU region already claimed\n"); 769 - ret = -EBUSY; 770 - goto ereqmemreg; 767 + return -EBUSY; 771 768 } 772 769 773 - ret = -ENOMEM; 774 - info->pram = ioremap(res->start, PRAM_SIZE); 770 + info->pram = devm_ioremap(&pdev->dev, res->start, PRAM_SIZE); 775 771 if (!info->pram) 776 - goto emappram; 777 - info->xram = ioremap(res->start + XRAM_OFFSET, XRAM_SIZE); 772 + return -ENOMEM; 773 + info->xram = devm_ioremap(&pdev->dev, res->start + XRAM_OFFSET, 774 + XRAM_SIZE); 778 775 if (!info->xram) 779 - goto emapxram; 780 - info->yram = ioremap(res->start + YRAM_OFFSET, YRAM_SIZE); 776 + return -ENOMEM; 777 + info->yram = devm_ioremap(&pdev->dev, res->start + YRAM_OFFSET, 778 + YRAM_SIZE); 781 779 if (!info->yram) 782 - goto emapyram; 783 - info->reg = ioremap(res->start + REG_OFFSET, resource_size(res) - 784 - REG_OFFSET); 780 + return -ENOMEM; 781 + info->reg = devm_ioremap(&pdev->dev, res->start + REG_OFFSET, 782 + resource_size(res) - REG_OFFSET); 785 783 if (!info->reg) 786 - goto emapreg; 784 + return -ENOMEM; 787 785 788 786 dev_set_drvdata(&pdev->dev, info); 789 787 790 788 /* register using ARRAY version so we can keep dai name */ 791 - ret = snd_soc_register_component(&pdev->dev, &siu_i2s_component, 792 - &siu_i2s_dai, 1); 789 + ret = devm_snd_soc_register_component(&pdev->dev, &siu_i2s_component, 790 + &siu_i2s_dai, 1); 793 791 if (ret < 0) 794 - goto edaiinit; 792 + return ret; 795 793 796 - ret = snd_soc_register_platform(&pdev->dev, &siu_platform); 794 + ret = devm_snd_soc_register_platform(&pdev->dev, &siu_platform); 797 795 if (ret < 0) 798 - goto esocregp; 796 + return ret; 799 797 800 798 pm_runtime_enable(&pdev->dev); 801 799 802 - return ret; 803 - 804 - esocregp: 805 - snd_soc_unregister_component(&pdev->dev); 806 - edaiinit: 807 - iounmap(info->reg); 808 - emapreg: 809 - iounmap(info->yram); 810 - emapyram: 811 - iounmap(info->xram); 812 - emapxram: 813 - iounmap(info->pram); 814 - emappram: 815 - release_mem_region(res->start, resource_size(res)); 816 - ereqmemreg: 817 - egetres: 818 - ereqfw: 819 - kfree(info); 820 - 821 - return ret; 800 + return 0; 822 801 } 823 802 824 803 static int siu_remove(struct platform_device *pdev) 825 804 { 826 - struct siu_info *info = dev_get_drvdata(&pdev->dev); 827 - struct resource *res; 828 - 829 805 pm_runtime_disable(&pdev->dev); 830 - 831 - snd_soc_unregister_platform(&pdev->dev); 832 - snd_soc_unregister_component(&pdev->dev); 833 - 834 - iounmap(info->reg); 835 - iounmap(info->yram); 836 - iounmap(info->xram); 837 - iounmap(info->pram); 838 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 839 - if (res) 840 - release_mem_region(res->start, resource_size(res)); 841 - kfree(info); 842 - 843 806 return 0; 844 807 } 845 808
+25
sound/soc/soc-core.c
··· 3291 3291 } 3292 3292 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); 3293 3293 3294 + static int snd_soc_of_get_slot_mask(struct device_node *np, 3295 + const char *prop_name, 3296 + unsigned int *mask) 3297 + { 3298 + u32 val; 3299 + const __be32 *of_slot_mask = of_get_property(np, prop_name, &val); 3300 + int i; 3301 + 3302 + if (!of_slot_mask) 3303 + return 0; 3304 + val /= sizeof(u32); 3305 + for (i = 0; i < val; i++) 3306 + if (be32_to_cpup(&of_slot_mask[i])) 3307 + *mask |= (1 << i); 3308 + 3309 + return val; 3310 + } 3311 + 3294 3312 int snd_soc_of_parse_tdm_slot(struct device_node *np, 3313 + unsigned int *tx_mask, 3314 + unsigned int *rx_mask, 3295 3315 unsigned int *slots, 3296 3316 unsigned int *slot_width) 3297 3317 { 3298 3318 u32 val; 3299 3319 int ret; 3320 + 3321 + if (tx_mask) 3322 + snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask); 3323 + if (rx_mask) 3324 + snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask); 3300 3325 3301 3326 if (of_property_read_bool(np, "dai-tdm-slot-num")) { 3302 3327 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
+1 -1
sound/soc/soc-dapm.c
··· 3501 3501 3502 3502 default: 3503 3503 WARN(1, "Unknown event %d\n", event); 3504 - return -EINVAL; 3504 + ret = -EINVAL; 3505 3505 } 3506 3506 3507 3507 out:
+49
sound/soc/soc-pcm.c
··· 34 34 35 35 #define DPCM_MAX_BE_USERS 8 36 36 37 + /* 38 + * snd_soc_dai_stream_valid() - check if a DAI supports the given stream 39 + * 40 + * Returns true if the DAI supports the indicated stream type. 41 + */ 42 + static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream) 43 + { 44 + struct snd_soc_pcm_stream *codec_stream; 45 + 46 + if (stream == SNDRV_PCM_STREAM_PLAYBACK) 47 + codec_stream = &dai->driver->playback; 48 + else 49 + codec_stream = &dai->driver->capture; 50 + 51 + /* If the codec specifies any rate at all, it supports the stream. */ 52 + return codec_stream->rates; 53 + } 54 + 37 55 /** 38 56 * snd_soc_runtime_activate() - Increment active count for PCM runtime components 39 57 * @rtd: ASoC PCM runtime that is activated ··· 389 371 390 372 /* first calculate min/max only for CODECs in the DAI link */ 391 373 for (i = 0; i < rtd->num_codecs; i++) { 374 + 375 + /* 376 + * Skip CODECs which don't support the current stream type. 377 + * Otherwise, since the rate, channel, and format values will 378 + * zero in that case, we would have no usable settings left, 379 + * causing the resulting setup to fail. 380 + * At least one CODEC should match, otherwise we should have 381 + * bailed out on a higher level, since there would be no 382 + * CODEC to support the transfer direction in that case. 383 + */ 384 + if (!snd_soc_dai_stream_valid(rtd->codec_dais[i], 385 + substream->stream)) 386 + continue; 387 + 392 388 codec_dai_drv = rtd->codec_dais[i]->driver; 393 389 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 394 390 codec_stream = &codec_dai_drv->playback; ··· 858 826 for (i = 0; i < rtd->num_codecs; i++) { 859 827 struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; 860 828 struct snd_pcm_hw_params codec_params; 829 + 830 + /* 831 + * Skip CODECs which don't support the current stream type, 832 + * the idea being that if a CODEC is not used for the currently 833 + * set up transfer direction, it should not need to be 834 + * configured, especially since the configuration used might 835 + * not even be supported by that CODEC. There may be cases 836 + * however where a CODEC needs to be set up although it is 837 + * actually not being used for the transfer, e.g. if a 838 + * capture-only CODEC is acting as an LRCLK and/or BCLK master 839 + * for the DAI link including a playback-only CODEC. 840 + * If this becomes necessary, we will have to augment the 841 + * machine driver setup with information on how to act, so 842 + * we can do the right thing here. 843 + */ 844 + if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) 845 + continue; 861 846 862 847 /* copy params for each codec */ 863 848 codec_params = *params;
+9
sound/soc/soc-utils.c
··· 101 101 SNDRV_PCM_FMTBIT_S32_LE | \ 102 102 SNDRV_PCM_FMTBIT_U32_LE | \ 103 103 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE) 104 + /* 105 + * The dummy CODEC is only meant to be used in situations where there is no 106 + * actual hardware. 107 + * 108 + * If there is actual hardware even if it does not have a control bus 109 + * the hardware will still have constraints like supported samplerates, etc. 110 + * which should be modelled. And the data flow graph also should be modelled 111 + * using DAPM. 112 + */ 104 113 static struct snd_soc_dai_driver dummy_dai = { 105 114 .name = "snd-soc-dummy-dai", 106 115 .playback = {
+1 -1
sound/soc/spear/Kconfig
··· 1 1 config SND_SPEAR_SOC 2 2 tristate 3 - select SND_DMAENGINE_PCM 3 + select SND_SOC_GENERIC_DMAENGINE_PCM 4 4 5 5 config SND_SPEAR_SPDIF_OUT 6 6 tristate
+10 -4
sound/soc/sti/uniperif_player.c
··· 989 989 if (!info) 990 990 return -ENOMEM; 991 991 992 - of_property_read_u32(pnode, "version", &player->ver); 993 - if (player->ver == SND_ST_UNIPERIF_VERSION_UNKNOWN) { 992 + if (of_property_read_u32(pnode, "version", &player->ver) || 993 + player->ver == SND_ST_UNIPERIF_VERSION_UNKNOWN) { 994 994 dev_err(dev, "Unknown uniperipheral version "); 995 995 return -EINVAL; 996 996 } ··· 998 998 if (player->ver >= SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) 999 999 info->underflow_enabled = 1; 1000 1000 1001 - of_property_read_u32(pnode, "uniperiph-id", &info->id); 1001 + if (of_property_read_u32(pnode, "uniperiph-id", &info->id)) { 1002 + dev_err(dev, "uniperipheral id not defined"); 1003 + return -EINVAL; 1004 + } 1002 1005 1003 1006 /* Read the device mode property */ 1004 - of_property_read_string(pnode, "mode", &mode); 1007 + if (of_property_read_string(pnode, "mode", &mode)) { 1008 + dev_err(dev, "uniperipheral mode not defined"); 1009 + return -EINVAL; 1010 + } 1005 1011 1006 1012 if (strcasecmp(mode, "hdmi") == 0) 1007 1013 info->player_type = SND_ST_UNIPERIF_PLAYER_TYPE_HDMI;
+5 -1
sound/soc/sti/uniperif_reader.c
··· 316 316 if (!info) 317 317 return -ENOMEM; 318 318 319 - of_property_read_u32(node, "version", &reader->ver); 319 + if (of_property_read_u32(node, "version", &reader->ver) || 320 + reader->ver == SND_ST_UNIPERIF_VERSION_UNKNOWN) { 321 + dev_err(&pdev->dev, "Unknown uniperipheral version "); 322 + return -EINVAL; 323 + } 320 324 321 325 /* Save the info structure */ 322 326 reader->info = info;
+11
sound/soc/sunxi/Kconfig
··· 1 + menu "Allwinner SoC Audio support" 2 + 3 + config SND_SUN4I_CODEC 4 + tristate "Allwinner A10 Codec Support" 5 + select SND_SOC_GENERIC_DMAENGINE_PCM 6 + select REGMAP_MMIO 7 + help 8 + Select Y or M to add support for the Codec embedded in the Allwinner 9 + A10 and affiliated SoCs. 10 + 11 + endmenu
+2
sound/soc/sunxi/Makefile
··· 1 + obj-$(CONFIG_SND_SUN4I_CODEC) += sun4i-codec.o 2 +
+719
sound/soc/sunxi/sun4i-codec.c
··· 1 + /* 2 + * Copyright 2014 Emilio López <emilio@elopez.com.ar> 3 + * Copyright 2014 Jon Smirl <jonsmirl@gmail.com> 4 + * Copyright 2015 Maxime Ripard <maxime.ripard@free-electrons.com> 5 + * 6 + * Based on the Allwinner SDK driver, released under the GPL. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + */ 18 + 19 + #include <linux/init.h> 20 + #include <linux/kernel.h> 21 + #include <linux/module.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/delay.h> 24 + #include <linux/slab.h> 25 + #include <linux/of.h> 26 + #include <linux/of_platform.h> 27 + #include <linux/of_address.h> 28 + #include <linux/clk.h> 29 + #include <linux/regmap.h> 30 + 31 + #include <sound/core.h> 32 + #include <sound/pcm.h> 33 + #include <sound/pcm_params.h> 34 + #include <sound/soc.h> 35 + #include <sound/tlv.h> 36 + #include <sound/initval.h> 37 + #include <sound/dmaengine_pcm.h> 38 + 39 + /* Codec DAC register offsets and bit fields */ 40 + #define SUN4I_CODEC_DAC_DPC (0x00) 41 + #define SUN4I_CODEC_DAC_DPC_EN_DA (31) 42 + #define SUN4I_CODEC_DAC_DPC_DVOL (12) 43 + #define SUN4I_CODEC_DAC_FIFOC (0x04) 44 + #define SUN4I_CODEC_DAC_FIFOC_DAC_FS (29) 45 + #define SUN4I_CODEC_DAC_FIFOC_FIR_VERSION (28) 46 + #define SUN4I_CODEC_DAC_FIFOC_SEND_LASAT (26) 47 + #define SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE (24) 48 + #define SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT (21) 49 + #define SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL (8) 50 + #define SUN4I_CODEC_DAC_FIFOC_MONO_EN (6) 51 + #define SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS (5) 52 + #define SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN (4) 53 + #define SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH (0) 54 + #define SUN4I_CODEC_DAC_FIFOS (0x08) 55 + #define SUN4I_CODEC_DAC_TXDATA (0x0c) 56 + #define SUN4I_CODEC_DAC_ACTL (0x10) 57 + #define SUN4I_CODEC_DAC_ACTL_DACAENR (31) 58 + #define SUN4I_CODEC_DAC_ACTL_DACAENL (30) 59 + #define SUN4I_CODEC_DAC_ACTL_MIXEN (29) 60 + #define SUN4I_CODEC_DAC_ACTL_LDACLMIXS (15) 61 + #define SUN4I_CODEC_DAC_ACTL_RDACRMIXS (14) 62 + #define SUN4I_CODEC_DAC_ACTL_LDACRMIXS (13) 63 + #define SUN4I_CODEC_DAC_ACTL_DACPAS (8) 64 + #define SUN4I_CODEC_DAC_ACTL_MIXPAS (7) 65 + #define SUN4I_CODEC_DAC_ACTL_PA_MUTE (6) 66 + #define SUN4I_CODEC_DAC_ACTL_PA_VOL (0) 67 + #define SUN4I_CODEC_DAC_TUNE (0x14) 68 + #define SUN4I_CODEC_DAC_DEBUG (0x18) 69 + 70 + /* Codec ADC register offsets and bit fields */ 71 + #define SUN4I_CODEC_ADC_FIFOC (0x1c) 72 + #define SUN4I_CODEC_ADC_FIFOC_EN_AD (28) 73 + #define SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE (24) 74 + #define SUN4I_CODEC_ADC_FIFOC_RX_TRIG_LEVEL (8) 75 + #define SUN4I_CODEC_ADC_FIFOC_MONO_EN (7) 76 + #define SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS (6) 77 + #define SUN4I_CODEC_ADC_FIFOC_ADC_DRQ_EN (4) 78 + #define SUN4I_CODEC_ADC_FIFOC_FIFO_FLUSH (0) 79 + #define SUN4I_CODEC_ADC_FIFOS (0x20) 80 + #define SUN4I_CODEC_ADC_RXDATA (0x24) 81 + #define SUN4I_CODEC_ADC_ACTL (0x28) 82 + #define SUN4I_CODEC_ADC_ACTL_ADC_R_EN (31) 83 + #define SUN4I_CODEC_ADC_ACTL_ADC_L_EN (30) 84 + #define SUN4I_CODEC_ADC_ACTL_PREG1EN (29) 85 + #define SUN4I_CODEC_ADC_ACTL_PREG2EN (28) 86 + #define SUN4I_CODEC_ADC_ACTL_VMICEN (27) 87 + #define SUN4I_CODEC_ADC_ACTL_VADCG (20) 88 + #define SUN4I_CODEC_ADC_ACTL_ADCIS (17) 89 + #define SUN4I_CODEC_ADC_ACTL_PA_EN (4) 90 + #define SUN4I_CODEC_ADC_ACTL_DDE (3) 91 + #define SUN4I_CODEC_ADC_DEBUG (0x2c) 92 + 93 + /* Other various ADC registers */ 94 + #define SUN4I_CODEC_DAC_TXCNT (0x30) 95 + #define SUN4I_CODEC_ADC_RXCNT (0x34) 96 + #define SUN4I_CODEC_AC_SYS_VERI (0x38) 97 + #define SUN4I_CODEC_AC_MIC_PHONE_CAL (0x3c) 98 + 99 + struct sun4i_codec { 100 + struct device *dev; 101 + struct regmap *regmap; 102 + struct clk *clk_apb; 103 + struct clk *clk_module; 104 + 105 + struct snd_dmaengine_dai_dma_data playback_dma_data; 106 + }; 107 + 108 + static void sun4i_codec_start_playback(struct sun4i_codec *scodec) 109 + { 110 + /* 111 + * FIXME: according to the BSP, we might need to drive a PA 112 + * GPIO high here on some boards 113 + */ 114 + 115 + /* Flush TX FIFO */ 116 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 117 + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH), 118 + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); 119 + 120 + /* Enable DAC DRQ */ 121 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 122 + BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN), 123 + BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN)); 124 + } 125 + 126 + static void sun4i_codec_stop_playback(struct sun4i_codec *scodec) 127 + { 128 + /* 129 + * FIXME: according to the BSP, we might need to drive a PA 130 + * GPIO low here on some boards 131 + */ 132 + 133 + /* Disable DAC DRQ */ 134 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 135 + BIT(SUN4I_CODEC_DAC_FIFOC_DAC_DRQ_EN), 136 + 0); 137 + } 138 + 139 + static int sun4i_codec_trigger(struct snd_pcm_substream *substream, int cmd, 140 + struct snd_soc_dai *dai) 141 + { 142 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 143 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); 144 + 145 + if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) 146 + return -ENOTSUPP; 147 + 148 + switch (cmd) { 149 + case SNDRV_PCM_TRIGGER_START: 150 + case SNDRV_PCM_TRIGGER_RESUME: 151 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 152 + sun4i_codec_start_playback(scodec); 153 + break; 154 + 155 + case SNDRV_PCM_TRIGGER_STOP: 156 + case SNDRV_PCM_TRIGGER_SUSPEND: 157 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 158 + sun4i_codec_stop_playback(scodec); 159 + break; 160 + 161 + default: 162 + return -EINVAL; 163 + } 164 + 165 + return 0; 166 + } 167 + 168 + static int sun4i_codec_prepare(struct snd_pcm_substream *substream, 169 + struct snd_soc_dai *dai) 170 + { 171 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 172 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); 173 + u32 val; 174 + 175 + if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) 176 + return -ENOTSUPP; 177 + 178 + /* Flush the TX FIFO */ 179 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 180 + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH), 181 + BIT(SUN4I_CODEC_DAC_FIFOC_FIFO_FLUSH)); 182 + 183 + /* Set TX FIFO Empty Trigger Level */ 184 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 185 + 0x3f << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL, 186 + 0xf << SUN4I_CODEC_DAC_FIFOC_TX_TRIG_LEVEL); 187 + 188 + if (substream->runtime->rate > 32000) 189 + /* Use 64 bits FIR filter */ 190 + val = 0; 191 + else 192 + /* Use 32 bits FIR filter */ 193 + val = BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION); 194 + 195 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 196 + BIT(SUN4I_CODEC_DAC_FIFOC_FIR_VERSION), 197 + val); 198 + 199 + /* Send zeros when we have an underrun */ 200 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 201 + BIT(SUN4I_CODEC_DAC_FIFOC_SEND_LASAT), 202 + 0); 203 + 204 + return 0; 205 + } 206 + 207 + static unsigned long sun4i_codec_get_mod_freq(struct snd_pcm_hw_params *params) 208 + { 209 + unsigned int rate = params_rate(params); 210 + 211 + switch (rate) { 212 + case 176400: 213 + case 88200: 214 + case 44100: 215 + case 33075: 216 + case 22050: 217 + case 14700: 218 + case 11025: 219 + case 7350: 220 + return 22579200; 221 + 222 + case 192000: 223 + case 96000: 224 + case 48000: 225 + case 32000: 226 + case 24000: 227 + case 16000: 228 + case 12000: 229 + case 8000: 230 + return 24576000; 231 + 232 + default: 233 + return 0; 234 + } 235 + } 236 + 237 + static int sun4i_codec_get_hw_rate(struct snd_pcm_hw_params *params) 238 + { 239 + unsigned int rate = params_rate(params); 240 + 241 + switch (rate) { 242 + case 192000: 243 + case 176400: 244 + return 6; 245 + 246 + case 96000: 247 + case 88200: 248 + return 7; 249 + 250 + case 48000: 251 + case 44100: 252 + return 0; 253 + 254 + case 32000: 255 + case 33075: 256 + return 1; 257 + 258 + case 24000: 259 + case 22050: 260 + return 2; 261 + 262 + case 16000: 263 + case 14700: 264 + return 3; 265 + 266 + case 12000: 267 + case 11025: 268 + return 4; 269 + 270 + case 8000: 271 + case 7350: 272 + return 5; 273 + 274 + default: 275 + return -EINVAL; 276 + } 277 + } 278 + 279 + static int sun4i_codec_hw_params(struct snd_pcm_substream *substream, 280 + struct snd_pcm_hw_params *params, 281 + struct snd_soc_dai *dai) 282 + { 283 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 284 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); 285 + unsigned long clk_freq; 286 + int hwrate; 287 + u32 val; 288 + 289 + if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) 290 + return -ENOTSUPP; 291 + 292 + clk_freq = sun4i_codec_get_mod_freq(params); 293 + if (!clk_freq) 294 + return -EINVAL; 295 + 296 + if (clk_set_rate(scodec->clk_module, clk_freq)) 297 + return -EINVAL; 298 + 299 + hwrate = sun4i_codec_get_hw_rate(params); 300 + if (hwrate < 0) 301 + return hwrate; 302 + 303 + /* Set DAC sample rate */ 304 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 305 + 7 << SUN4I_CODEC_DAC_FIFOC_DAC_FS, 306 + hwrate << SUN4I_CODEC_DAC_FIFOC_DAC_FS); 307 + 308 + /* Set the number of channels we want to use */ 309 + if (params_channels(params) == 1) 310 + val = BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN); 311 + else 312 + val = 0; 313 + 314 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 315 + BIT(SUN4I_CODEC_DAC_FIFOC_MONO_EN), 316 + val); 317 + 318 + /* Set the number of sample bits to either 16 or 24 bits */ 319 + if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) { 320 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 321 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS), 322 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS)); 323 + 324 + /* Set TX FIFO mode to padding the LSBs with 0 */ 325 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 326 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE), 327 + 0); 328 + 329 + scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 330 + } else { 331 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 332 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_SAMPLE_BITS), 333 + 0); 334 + 335 + /* Set TX FIFO mode to repeat the MSB */ 336 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 337 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE), 338 + BIT(SUN4I_CODEC_DAC_FIFOC_TX_FIFO_MODE)); 339 + 340 + scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 341 + } 342 + 343 + return 0; 344 + } 345 + 346 + static int sun4i_codec_startup(struct snd_pcm_substream *substream, 347 + struct snd_soc_dai *dai) 348 + { 349 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 350 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); 351 + 352 + /* 353 + * Stop issuing DRQ when we have room for less than 16 samples 354 + * in our TX FIFO 355 + */ 356 + regmap_update_bits(scodec->regmap, SUN4I_CODEC_DAC_FIFOC, 357 + 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT, 358 + 3 << SUN4I_CODEC_DAC_FIFOC_DRQ_CLR_CNT); 359 + 360 + return clk_prepare_enable(scodec->clk_module); 361 + } 362 + 363 + static void sun4i_codec_shutdown(struct snd_pcm_substream *substream, 364 + struct snd_soc_dai *dai) 365 + { 366 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 367 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(rtd->card); 368 + 369 + clk_disable_unprepare(scodec->clk_module); 370 + } 371 + 372 + static const struct snd_soc_dai_ops sun4i_codec_dai_ops = { 373 + .startup = sun4i_codec_startup, 374 + .shutdown = sun4i_codec_shutdown, 375 + .trigger = sun4i_codec_trigger, 376 + .hw_params = sun4i_codec_hw_params, 377 + .prepare = sun4i_codec_prepare, 378 + }; 379 + 380 + static struct snd_soc_dai_driver sun4i_codec_dai = { 381 + .name = "Codec", 382 + .ops = &sun4i_codec_dai_ops, 383 + .playback = { 384 + .stream_name = "Codec Playback", 385 + .channels_min = 1, 386 + .channels_max = 2, 387 + .rate_min = 8000, 388 + .rate_max = 192000, 389 + .rates = SNDRV_PCM_RATE_8000_48000 | 390 + SNDRV_PCM_RATE_96000 | 391 + SNDRV_PCM_RATE_192000 | 392 + SNDRV_PCM_RATE_KNOT, 393 + .formats = SNDRV_PCM_FMTBIT_S16_LE | 394 + SNDRV_PCM_FMTBIT_S32_LE, 395 + .sig_bits = 24, 396 + }, 397 + }; 398 + 399 + /*** Codec ***/ 400 + static const struct snd_kcontrol_new sun4i_codec_pa_mute = 401 + SOC_DAPM_SINGLE("Switch", SUN4I_CODEC_DAC_ACTL, 402 + SUN4I_CODEC_DAC_ACTL_PA_MUTE, 1, 0); 403 + 404 + static DECLARE_TLV_DB_SCALE(sun4i_codec_pa_volume_scale, -6300, 100, 1); 405 + 406 + static const struct snd_kcontrol_new sun4i_codec_widgets[] = { 407 + SOC_SINGLE_TLV("PA Volume", SUN4I_CODEC_DAC_ACTL, 408 + SUN4I_CODEC_DAC_ACTL_PA_VOL, 0x3F, 0, 409 + sun4i_codec_pa_volume_scale), 410 + }; 411 + 412 + static const struct snd_kcontrol_new sun4i_codec_left_mixer_controls[] = { 413 + SOC_DAPM_SINGLE("Left DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, 414 + SUN4I_CODEC_DAC_ACTL_LDACLMIXS, 1, 0), 415 + }; 416 + 417 + static const struct snd_kcontrol_new sun4i_codec_right_mixer_controls[] = { 418 + SOC_DAPM_SINGLE("Right DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, 419 + SUN4I_CODEC_DAC_ACTL_RDACRMIXS, 1, 0), 420 + SOC_DAPM_SINGLE("Left DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, 421 + SUN4I_CODEC_DAC_ACTL_LDACRMIXS, 1, 0), 422 + }; 423 + 424 + static const struct snd_kcontrol_new sun4i_codec_pa_mixer_controls[] = { 425 + SOC_DAPM_SINGLE("DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, 426 + SUN4I_CODEC_DAC_ACTL_DACPAS, 1, 0), 427 + SOC_DAPM_SINGLE("Mixer Playback Switch", SUN4I_CODEC_DAC_ACTL, 428 + SUN4I_CODEC_DAC_ACTL_MIXPAS, 1, 0), 429 + }; 430 + 431 + static const struct snd_soc_dapm_widget sun4i_codec_dapm_widgets[] = { 432 + /* Digital parts of the DACs */ 433 + SND_SOC_DAPM_SUPPLY("DAC", SUN4I_CODEC_DAC_DPC, 434 + SUN4I_CODEC_DAC_DPC_EN_DA, 0, 435 + NULL, 0), 436 + 437 + /* Analog parts of the DACs */ 438 + SND_SOC_DAPM_DAC("Left DAC", "Codec Playback", SUN4I_CODEC_DAC_ACTL, 439 + SUN4I_CODEC_DAC_ACTL_DACAENL, 0), 440 + SND_SOC_DAPM_DAC("Right DAC", "Codec Playback", SUN4I_CODEC_DAC_ACTL, 441 + SUN4I_CODEC_DAC_ACTL_DACAENR, 0), 442 + 443 + /* Mixers */ 444 + SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0, 445 + sun4i_codec_left_mixer_controls, 446 + ARRAY_SIZE(sun4i_codec_left_mixer_controls)), 447 + SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0, 448 + sun4i_codec_right_mixer_controls, 449 + ARRAY_SIZE(sun4i_codec_right_mixer_controls)), 450 + 451 + /* Global Mixer Enable */ 452 + SND_SOC_DAPM_SUPPLY("Mixer Enable", SUN4I_CODEC_DAC_ACTL, 453 + SUN4I_CODEC_DAC_ACTL_MIXEN, 0, NULL, 0), 454 + 455 + /* Pre-Amplifier */ 456 + SND_SOC_DAPM_MIXER("Pre-Amplifier", SUN4I_CODEC_ADC_ACTL, 457 + SUN4I_CODEC_ADC_ACTL_PA_EN, 0, 458 + sun4i_codec_pa_mixer_controls, 459 + ARRAY_SIZE(sun4i_codec_pa_mixer_controls)), 460 + SND_SOC_DAPM_SWITCH("Pre-Amplifier Mute", SND_SOC_NOPM, 0, 0, 461 + &sun4i_codec_pa_mute), 462 + 463 + SND_SOC_DAPM_OUTPUT("HP Right"), 464 + SND_SOC_DAPM_OUTPUT("HP Left"), 465 + }; 466 + 467 + static const struct snd_soc_dapm_route sun4i_codec_dapm_routes[] = { 468 + /* Left DAC Routes */ 469 + { "Left DAC", NULL, "DAC" }, 470 + 471 + /* Right DAC Routes */ 472 + { "Right DAC", NULL, "DAC" }, 473 + 474 + /* Right Mixer Routes */ 475 + { "Right Mixer", NULL, "Mixer Enable" }, 476 + { "Right Mixer", "Left DAC Playback Switch", "Left DAC" }, 477 + { "Right Mixer", "Right DAC Playback Switch", "Right DAC" }, 478 + 479 + /* Left Mixer Routes */ 480 + { "Left Mixer", NULL, "Mixer Enable" }, 481 + { "Left Mixer", "Left DAC Playback Switch", "Left DAC" }, 482 + 483 + /* Pre-Amplifier Mixer Routes */ 484 + { "Pre-Amplifier", "Mixer Playback Switch", "Left Mixer" }, 485 + { "Pre-Amplifier", "Mixer Playback Switch", "Right Mixer" }, 486 + { "Pre-Amplifier", "DAC Playback Switch", "Left DAC" }, 487 + { "Pre-Amplifier", "DAC Playback Switch", "Right DAC" }, 488 + 489 + /* PA -> HP path */ 490 + { "Pre-Amplifier Mute", "Switch", "Pre-Amplifier" }, 491 + { "HP Right", NULL, "Pre-Amplifier Mute" }, 492 + { "HP Left", NULL, "Pre-Amplifier Mute" }, 493 + }; 494 + 495 + static struct snd_soc_codec_driver sun4i_codec_codec = { 496 + .controls = sun4i_codec_widgets, 497 + .num_controls = ARRAY_SIZE(sun4i_codec_widgets), 498 + .dapm_widgets = sun4i_codec_dapm_widgets, 499 + .num_dapm_widgets = ARRAY_SIZE(sun4i_codec_dapm_widgets), 500 + .dapm_routes = sun4i_codec_dapm_routes, 501 + .num_dapm_routes = ARRAY_SIZE(sun4i_codec_dapm_routes), 502 + }; 503 + 504 + static const struct snd_soc_component_driver sun4i_codec_component = { 505 + .name = "sun4i-codec", 506 + }; 507 + 508 + #define SUN4I_CODEC_RATES SNDRV_PCM_RATE_8000_192000 509 + #define SUN4I_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ 510 + SNDRV_PCM_FMTBIT_S32_LE) 511 + 512 + static int sun4i_codec_dai_probe(struct snd_soc_dai *dai) 513 + { 514 + struct snd_soc_card *card = snd_soc_dai_get_drvdata(dai); 515 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card); 516 + 517 + snd_soc_dai_init_dma_data(dai, &scodec->playback_dma_data, 518 + NULL); 519 + 520 + return 0; 521 + } 522 + 523 + static struct snd_soc_dai_driver dummy_cpu_dai = { 524 + .name = "sun4i-codec-cpu-dai", 525 + .probe = sun4i_codec_dai_probe, 526 + .playback = { 527 + .stream_name = "Playback", 528 + .channels_min = 1, 529 + .channels_max = 2, 530 + .rates = SUN4I_CODEC_RATES, 531 + .formats = SUN4I_CODEC_FORMATS, 532 + .sig_bits = 24, 533 + }, 534 + }; 535 + 536 + static const struct regmap_config sun4i_codec_regmap_config = { 537 + .reg_bits = 32, 538 + .reg_stride = 4, 539 + .val_bits = 32, 540 + .max_register = SUN4I_CODEC_AC_MIC_PHONE_CAL, 541 + }; 542 + 543 + static const struct of_device_id sun4i_codec_of_match[] = { 544 + { .compatible = "allwinner,sun4i-a10-codec" }, 545 + { .compatible = "allwinner,sun7i-a20-codec" }, 546 + {} 547 + }; 548 + MODULE_DEVICE_TABLE(of, sun4i_codec_of_match); 549 + 550 + static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev, 551 + int *num_links) 552 + { 553 + struct snd_soc_dai_link *link = devm_kzalloc(dev, sizeof(*link), 554 + GFP_KERNEL); 555 + if (!link) 556 + return NULL; 557 + 558 + link->name = "cdc"; 559 + link->stream_name = "CDC PCM"; 560 + link->codec_dai_name = "Codec"; 561 + link->cpu_dai_name = dev_name(dev); 562 + link->codec_name = dev_name(dev); 563 + link->platform_name = dev_name(dev); 564 + link->dai_fmt = SND_SOC_DAIFMT_I2S; 565 + 566 + *num_links = 1; 567 + 568 + return link; 569 + }; 570 + 571 + static struct snd_soc_card *sun4i_codec_create_card(struct device *dev) 572 + { 573 + struct snd_soc_card *card; 574 + int ret; 575 + 576 + card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 577 + if (!card) 578 + return NULL; 579 + 580 + card->dai_link = sun4i_codec_create_link(dev, &card->num_links); 581 + if (!card->dai_link) 582 + return NULL; 583 + 584 + card->dev = dev; 585 + card->name = "sun4i-codec"; 586 + 587 + ret = snd_soc_of_parse_audio_routing(card, "routing"); 588 + if (ret) { 589 + dev_err(dev, "Failed to create our audio routing\n"); 590 + return NULL; 591 + } 592 + 593 + return card; 594 + }; 595 + 596 + static int sun4i_codec_probe(struct platform_device *pdev) 597 + { 598 + struct snd_soc_card *card; 599 + struct sun4i_codec *scodec; 600 + struct resource *res; 601 + void __iomem *base; 602 + int ret; 603 + 604 + scodec = devm_kzalloc(&pdev->dev, sizeof(*scodec), GFP_KERNEL); 605 + if (!scodec) 606 + return -ENOMEM; 607 + 608 + scodec->dev = &pdev->dev; 609 + 610 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 611 + base = devm_ioremap_resource(&pdev->dev, res); 612 + if (IS_ERR(base)) { 613 + dev_err(&pdev->dev, "Failed to map the registers\n"); 614 + return PTR_ERR(base); 615 + } 616 + 617 + scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base, 618 + &sun4i_codec_regmap_config); 619 + if (IS_ERR(scodec->regmap)) { 620 + dev_err(&pdev->dev, "Failed to create our regmap\n"); 621 + return PTR_ERR(scodec->regmap); 622 + } 623 + 624 + /* Get the clocks from the DT */ 625 + scodec->clk_apb = devm_clk_get(&pdev->dev, "apb"); 626 + if (IS_ERR(scodec->clk_apb)) { 627 + dev_err(&pdev->dev, "Failed to get the APB clock\n"); 628 + return PTR_ERR(scodec->clk_apb); 629 + } 630 + 631 + scodec->clk_module = devm_clk_get(&pdev->dev, "codec"); 632 + if (IS_ERR(scodec->clk_module)) { 633 + dev_err(&pdev->dev, "Failed to get the module clock\n"); 634 + return PTR_ERR(scodec->clk_module); 635 + } 636 + 637 + /* Enable the bus clock */ 638 + if (clk_prepare_enable(scodec->clk_apb)) { 639 + dev_err(&pdev->dev, "Failed to enable the APB clock\n"); 640 + return -EINVAL; 641 + } 642 + 643 + /* DMA configuration for TX FIFO */ 644 + scodec->playback_dma_data.addr = res->start + SUN4I_CODEC_DAC_TXDATA; 645 + scodec->playback_dma_data.maxburst = 4; 646 + scodec->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 647 + 648 + ret = snd_soc_register_codec(&pdev->dev, &sun4i_codec_codec, 649 + &sun4i_codec_dai, 1); 650 + if (ret) { 651 + dev_err(&pdev->dev, "Failed to register our codec\n"); 652 + goto err_clk_disable; 653 + } 654 + 655 + ret = devm_snd_soc_register_component(&pdev->dev, 656 + &sun4i_codec_component, 657 + &dummy_cpu_dai, 1); 658 + if (ret) { 659 + dev_err(&pdev->dev, "Failed to register our DAI\n"); 660 + goto err_unregister_codec; 661 + } 662 + 663 + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 664 + if (ret) { 665 + dev_err(&pdev->dev, "Failed to register against DMAEngine\n"); 666 + goto err_unregister_codec; 667 + } 668 + 669 + card = sun4i_codec_create_card(&pdev->dev); 670 + if (!card) { 671 + dev_err(&pdev->dev, "Failed to create our card\n"); 672 + goto err_unregister_codec; 673 + } 674 + 675 + platform_set_drvdata(pdev, card); 676 + snd_soc_card_set_drvdata(card, scodec); 677 + 678 + ret = snd_soc_register_card(card); 679 + if (ret) { 680 + dev_err(&pdev->dev, "Failed to register our card\n"); 681 + goto err_unregister_codec; 682 + } 683 + 684 + return 0; 685 + 686 + err_unregister_codec: 687 + snd_soc_unregister_codec(&pdev->dev); 688 + err_clk_disable: 689 + clk_disable_unprepare(scodec->clk_apb); 690 + return ret; 691 + } 692 + 693 + static int sun4i_codec_remove(struct platform_device *pdev) 694 + { 695 + struct snd_soc_card *card = platform_get_drvdata(pdev); 696 + struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card); 697 + 698 + snd_soc_unregister_card(card); 699 + snd_soc_unregister_codec(&pdev->dev); 700 + clk_disable_unprepare(scodec->clk_apb); 701 + 702 + return 0; 703 + } 704 + 705 + static struct platform_driver sun4i_codec_driver = { 706 + .driver = { 707 + .name = "sun4i-codec", 708 + .of_match_table = sun4i_codec_of_match, 709 + }, 710 + .probe = sun4i_codec_probe, 711 + .remove = sun4i_codec_remove, 712 + }; 713 + module_platform_driver(sun4i_codec_driver); 714 + 715 + MODULE_DESCRIPTION("Allwinner A10 codec driver"); 716 + MODULE_AUTHOR("Emilio López <emilio@elopez.com.ar>"); 717 + MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>"); 718 + MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 719 + MODULE_LICENSE("GPL");
+1
sound/soc/ux500/mop500.c
··· 152 152 { .compatible = "stericsson,snd-soc-mop500", }, 153 153 {}, 154 154 }; 155 + MODULE_DEVICE_TABLE(of, snd_soc_mop500_match); 155 156 156 157 static struct platform_driver snd_soc_mop500_driver = { 157 158 .driver = {
+1
sound/soc/ux500/ux500_msp_dai.c
··· 843 843 { .compatible = "stericsson,ux500-msp-i2s", }, 844 844 {}, 845 845 }; 846 + MODULE_DEVICE_TABLE(of, ux500_msp_i2s_match); 846 847 847 848 static struct platform_driver msp_i2s_driver = { 848 849 .driver = {