1diff --git a/sound/Makefile b/sound/Makefile 2index 797ecdcd3..b508dd4cf 100644 3--- a/sound/Makefile 4+++ b/sound/Makefile 5@@ -5,7 +5,8 @@ 6 obj-$(CONFIG_SOUND) += soundcore.o 7 obj-$(CONFIG_DMASOUND) += oss/dmasound/ 8 obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 9- firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ xen/ 10+ firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ xen/ \ 11+ ../../../../../$(PRODUCT_PATH)/kernel_core/sound/soc/ 12 obj-$(CONFIG_SND_AOA) += aoa/ 13 14 # This one must be compilable even if sound is configured out 15diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c 16index 2c5f7e905..51821334f 100644 17--- a/sound/drivers/aloop.c 18+++ b/sound/drivers/aloop.c 19@@ -37,6 +37,7 @@ MODULE_SUPPORTED_DEVICE("{{ALSA,Loopback soundcard}}"); 20 21 #define MAX_PCM_SUBSTREAMS 8 22 23+static bool use_raw_jiffies; 24 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 25 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 26 static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; 27@@ -44,6 +45,8 @@ static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; 28 static int pcm_notify[SNDRV_CARDS]; 29 static char *timer_source[SNDRV_CARDS]; 30 31+module_param(use_raw_jiffies, bool, 0444); 32+MODULE_PARM_DESC(use_raw_jiffies, "Use raw jiffies follows local clocks."); 33 module_param_array(index, int, NULL, 0444); 34 MODULE_PARM_DESC(index, "Index value for loopback soundcard."); 35 module_param_array(id, charp, NULL, 0444); 36@@ -163,6 +166,22 @@ struct loopback_pcm { 37 38 static struct platform_device *devices[SNDRV_CARDS]; 39 40+static inline unsigned long get_raw_jiffies(void) 41+{ 42+ struct timespec64 ts64; 43+ 44+ ktime_get_raw_ts64(&ts64); 45+ return timespec64_to_jiffies(&ts64); 46+} 47+ 48+static inline unsigned long cycles_to_jiffies(void) 49+{ 50+ if (likely(use_raw_jiffies)) 51+ return get_raw_jiffies(); 52+ 53+ return jiffies; 54+} 55+ 56 static inline unsigned int byte_pos(struct loopback_pcm *dpcm, unsigned int x) 57 { 58 if (dpcm->pcm_rate_shift == NO_PITCH) { 59@@ -387,7 +406,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) 60 err = loopback_check_format(cable, substream->stream); 61 if (err < 0) 62 return err; 63- dpcm->last_jiffies = jiffies; 64+ dpcm->last_jiffies = cycles_to_jiffies(); 65 dpcm->pcm_rate_shift = 0; 66 dpcm->last_drift = 0; 67 spin_lock(&cable->lock); 68@@ -419,7 +438,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) 69 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 70 case SNDRV_PCM_TRIGGER_RESUME: 71 spin_lock(&cable->lock); 72- dpcm->last_jiffies = jiffies; 73+ dpcm->last_jiffies = cycles_to_jiffies(); 74 cable->pause &= ~stream; 75 err = cable->ops->start(dpcm); 76 spin_unlock(&cable->lock); 77@@ -608,6 +627,7 @@ static unsigned int loopback_jiffies_timer_pos_update 78 cable->streams[SNDRV_PCM_STREAM_CAPTURE]; 79 unsigned long delta_play = 0, delta_capt = 0, cur_jiffies; 80 unsigned int running, count1, count2; 81+ unsigned long cur_jiffies = cycles_to_jiffies(); 82 83 cur_jiffies = jiffies; 84 running = cable->running ^ cable->pause; 85@@ -843,7 +863,7 @@ static void loopback_jiffies_timer_dpcm_info(struct loopback_pcm *dpcm, 86 snd_iprintf(buffer, " irq_pos:\t\t%u\n", dpcm->irq_pos); 87 snd_iprintf(buffer, " period_frac:\t%u\n", dpcm->period_size_frac); 88 snd_iprintf(buffer, " last_jiffies:\t%lu (%lu)\n", 89- dpcm->last_jiffies, jiffies); 90+ dpcm->last_jiffies, cycles_to_jiffies()); 91 snd_iprintf(buffer, " timer_expires:\t%lu\n", dpcm->timer.expires); 92 } 93 94diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig 95index 52c89a6f5..9aa44103e 100644 96--- a/sound/soc/codecs/Kconfig 97+++ b/sound/soc/codecs/Kconfig 98@@ -89,6 +89,7 @@ config SND_SOC_ALL_CODECS 99 imply SND_SOC_DA732X 100 imply SND_SOC_DA9055 101 imply SND_SOC_DMIC 102+ imply SND_SOC_DUMMY_CODEC 103 imply SND_SOC_ES8316 104 imply SND_SOC_ES8328_SPI 105 imply SND_SOC_ES8328_I2C 106@@ -766,6 +767,9 @@ config SND_SOC_DMIC 107 Enable support for the Generic Digital Microphone CODEC. 108 Select this if your sound card has DMICs. 109 110+config SND_SOC_DUMMY_CODEC 111+ tristate "Dummy CODEC" 112+ 113 config SND_SOC_HDMI_CODEC 114 tristate 115 select SND_PCM_ELD 116@@ -1029,6 +1033,9 @@ config SND_SOC_RK3328 117 tristate "Rockchip RK3328 audio CODEC" 118 select REGMAP_MMIO 119 120+config SND_SOC_RK_CODEC_DIGITAL 121+ tristate "Rockchip Codec Digital Interface" 122+ 123 config SND_SOC_RL6231 124 tristate 125 default y if SND_SOC_RT5514=y 126diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c 127index 4d286844e..2be7ba425 100644 128--- a/sound/soc/codecs/bt-sco.c 129+++ b/sound/soc/codecs/bt-sco.c 130@@ -26,14 +26,14 @@ static struct snd_soc_dai_driver bt_sco_dai[] = { 131 .playback = { 132 .stream_name = "Playback", 133 .channels_min = 1, 134- .channels_max = 1, 135+ .channels_max = 2, 136 .rates = SNDRV_PCM_RATE_8000, 137 .formats = SNDRV_PCM_FMTBIT_S16_LE, 138 }, 139 .capture = { 140 .stream_name = "Capture", 141 .channels_min = 1, 142- .channels_max = 1, 143+ .channels_max = 2, 144 .rates = SNDRV_PCM_RATE_8000, 145 .formats = SNDRV_PCM_FMTBIT_S16_LE, 146 }, 147@@ -43,14 +43,14 @@ static struct snd_soc_dai_driver bt_sco_dai[] = { 148 .playback = { 149 .stream_name = "Playback", 150 .channels_min = 1, 151- .channels_max = 1, 152+ .channels_max = 2, 153 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, 154 .formats = SNDRV_PCM_FMTBIT_S16_LE, 155 }, 156 .capture = { 157 .stream_name = "Capture", 158 .channels_min = 1, 159- .channels_max = 1, 160+ .channels_max = 2, 161 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, 162 .formats = SNDRV_PCM_FMTBIT_S16_LE, 163 }, 164diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig 165index d610b553e..fa31a0151 100644 166--- a/sound/soc/rockchip/Kconfig 167+++ b/sound/soc/rockchip/Kconfig 168@@ -7,6 +7,22 @@ config SND_SOC_ROCKCHIP 169 the Rockchip SoCs' Audio interfaces. You will also need to 170 select the audio interfaces to support below. 171 172+config SND_SOC_ROCKCHIP_PREALLOC_BUFFER_SIZE 173+ int "Default prealloc buffer size (kbytes)" 174+ depends on SND_SOC_ROCKCHIP 175+ default "512" 176+ help 177+ The default value is 512 kilobytes. Only change this if you know 178+ what you are doing. 179+ 180+config SND_SOC_ROCKCHIP_AUDIO_PWM 181+ tristate "Rockchip Audio PWM Driver" 182+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 183+ select SND_SOC_GENERIC_DMAENGINE_PCM 184+ help 185+ Say Y or M if you want to add support for Audio PWM driver for 186+ Rockchip Audio PWM Controller. 187+ 188 config SND_SOC_ROCKCHIP_I2S 189 tristate "Rockchip I2S Device Driver" 190 depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 191@@ -16,6 +32,15 @@ config SND_SOC_ROCKCHIP_I2S 192 Rockchip I2S device. The device supports upto maximum of 193 8 channels each for play and record. 194 195+config SND_SOC_ROCKCHIP_I2S_TDM 196+ tristate "Rockchip I2S/TDM Device Driver" 197+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 198+ select SND_SOC_GENERIC_DMAENGINE_PCM 199+ help 200+ Say Y or M if you want to add support for I2S/TDM driver for 201+ Rockchip I2S/TDM device. The device supports up to maximum of 202+ 8 channels each for play and record. 203+ 204 config SND_SOC_ROCKCHIP_PDM 205 tristate "Rockchip PDM Controller Driver" 206 depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 207@@ -34,6 +59,21 @@ config SND_SOC_ROCKCHIP_SPDIF 208 Say Y or M if you want to add support for SPDIF driver for 209 Rockchip SPDIF transceiver device. 210 211+config SND_SOC_ROCKCHIP_SPDIFRX 212+ tristate "Rockchip SPDIFRX Device Driver" 213+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 214+ select SND_SOC_GENERIC_DMAENGINE_PCM 215+ help 216+ Say Y or M if you want to add support for SPDIFRX driver for 217+ Rockchip SPDIF receiver device. 218+ 219+config SND_SOC_ROCKCHIP_VAD 220+ tristate "Rockchip Voice Activity Detection Driver" 221+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 222+ help 223+ Say Y or M if you want to add support for VAD driver for 224+ Rockchip VAD device. 225+ 226 config SND_SOC_ROCKCHIP_MAX98090 227 tristate "ASoC support for Rockchip boards using a MAX98090 codec" 228 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 229@@ -45,6 +85,13 @@ config SND_SOC_ROCKCHIP_MAX98090 230 Say Y or M here if you want to add support for SoC audio on Rockchip 231 boards using the MAX98090 codec and HDMI codec, such as Veyron. 232 233+config SND_SOC_ROCKCHIP_MULTICODECS 234+ tristate "ASoC support for Rockchip multicodecs" 235+ depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP 236+ help 237+ Say Y or M here if you want to add support for SoC audio on Rockchip 238+ boards using multicodecs, such as RK3308 boards. 239+ 240 config SND_SOC_ROCKCHIP_RT5645 241 tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec" 242 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 243@@ -54,6 +101,14 @@ config SND_SOC_ROCKCHIP_RT5645 244 Say Y or M here if you want to add support for SoC audio on Rockchip 245 boards using the RT5645/RT5650 codec, such as Veyron. 246 247+config SND_SOC_ROCKCHIP_HDMI 248+ tristate "ASoC support for Rockchip HDMI audio" 249+ depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP 250+ select SND_SOC_HDMI_CODEC 251+ help 252+ Say Y or M here if you want to add support for SoC audio on Rockchip 253+ boards using built-in HDMI or external HDMI. 254+ 255 config SND_SOC_RK3288_HDMI_ANALOG 256 tristate "ASoC support multiple codecs for Rockchip RK3288 boards" 257 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 258diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile 259index 65e814d46..83be7d21e 100644 260--- a/sound/soc/rockchip/Makefile 261+++ b/sound/soc/rockchip/Makefile 262@@ -5,7 +5,8 @@ snd-soc-rockchip-pcm-objs := rockchip_pcm.o 263 snd-soc-rockchip-pdm-objs := rockchip_pdm.o 264 snd-soc-rockchip-spdif-objs := rockchip_spdif.o 265 266-obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o snd-soc-rockchip-pcm.o 267+obj-$(CONFIG_SND_SOC_ROCKCHIP) += snd-soc-rockchip-pcm.o 268+obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o 269 obj-$(CONFIG_SND_SOC_ROCKCHIP_PDM) += snd-soc-rockchip-pdm.o 270 obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o 271 272diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c 273index 785baf98f..165d027b4 274--- a/sound/soc/rockchip/rockchip_i2s.c 275+++ b/sound/soc/rockchip/rockchip_i2s.c 276@@ -15,11 +15,11 @@ 277 #include <linux/clk.h> 278 #include <linux/pm_runtime.h> 279 #include <linux/regmap.h> 280+#include <linux/spinlock.h> 281 #include <sound/pcm_params.h> 282 #include <sound/dmaengine_pcm.h> 283 284 #include "rockchip_i2s.h" 285-#include "rockchip_pcm.h" 286 287 #define DRV_NAME "rockchip-i2s" 288 289@@ -40,6 +40,9 @@ struct rk_i2s_dev { 290 struct regmap *regmap; 291 struct regmap *grf; 292 293+ bool has_capture; 294+ bool has_playback; 295+ 296 /* 297 * Used to indicate the tx/rx status. 298 * I2S controller hopes to start the tx and rx together, 299@@ -49,6 +52,8 @@ struct rk_i2s_dev { 300 bool rx_start; 301 bool is_master_mode; 302 const struct rk_i2s_pins *pins; 303+ unsigned int bclk_ratio; 304+ spinlock_t lock; /* tx/rx lock */ 305 }; 306 307 static int i2s_runtime_suspend(struct device *dev) 308@@ -92,6 +97,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) 309 unsigned int val = 0; 310 int retry = 10; 311 312+ spin_lock(&i2s->lock); 313 if (on) { 314 regmap_update_bits(i2s->regmap, I2S_DMACR, 315 I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); 316@@ -132,6 +138,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) 317 } 318 } 319 } 320+ spin_unlock(&i2s->lock); 321 } 322 323 static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 324@@ -139,6 +146,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 325 unsigned int val = 0; 326 int retry = 10; 327 328+ spin_lock(&i2s->lock); 329 if (on) { 330 regmap_update_bits(i2s->regmap, I2S_DMACR, 331 I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); 332@@ -179,6 +187,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 333 } 334 } 335 } 336+ spin_unlock(&i2s->lock); 337 } 338 339 static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, 340@@ -207,13 +216,27 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, 341 342 regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); 343 344- mask = I2S_CKR_CKP_MASK; 345+ mask = I2S_CKR_CKP_MASK | I2S_CKR_TLP_MASK | I2S_CKR_RLP_MASK; 346 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 347 case SND_SOC_DAIFMT_NB_NF: 348- val = I2S_CKR_CKP_NEG; 349+ val = I2S_CKR_CKP_NORMAL | 350+ I2S_CKR_TLP_NORMAL | 351+ I2S_CKR_RLP_NORMAL; 352+ break; 353+ case SND_SOC_DAIFMT_NB_IF: 354+ val = I2S_CKR_CKP_NORMAL | 355+ I2S_CKR_TLP_INVERTED | 356+ I2S_CKR_RLP_INVERTED; 357 break; 358 case SND_SOC_DAIFMT_IB_NF: 359- val = I2S_CKR_CKP_POS; 360+ val = I2S_CKR_CKP_INVERTED | 361+ I2S_CKR_TLP_NORMAL | 362+ I2S_CKR_RLP_NORMAL; 363+ break; 364+ case SND_SOC_DAIFMT_IB_IF: 365+ val = I2S_CKR_CKP_INVERTED | 366+ I2S_CKR_TLP_INVERTED | 367+ I2S_CKR_RLP_INVERTED; 368 break; 369 default: 370 ret = -EINVAL; 371@@ -287,11 +310,11 @@ static int rockchip_i2s_hw_params(struct snd_pcm_substream *substream, 372 373 if (i2s->is_master_mode) { 374 mclk_rate = clk_get_rate(i2s->mclk); 375- bclk_rate = 2 * 32 * params_rate(params); 376- if (bclk_rate == 0 || mclk_rate % bclk_rate) 377+ bclk_rate = i2s->bclk_ratio * params_rate(params); 378+ if (!bclk_rate) 379 return -EINVAL; 380 381- div_bclk = mclk_rate / bclk_rate; 382+ div_bclk = DIV_ROUND_CLOSEST(mclk_rate, bclk_rate); 383 div_lrck = bclk_rate / params_rate(params); 384 regmap_update_bits(i2s->regmap, I2S_CKR, 385 I2S_CKR_MDIV_MASK, 386@@ -422,6 +445,16 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, 387 return ret; 388 } 389 390+static int rockchip_i2s_set_bclk_ratio(struct snd_soc_dai *dai, 391+ unsigned int ratio) 392+{ 393+ struct rk_i2s_dev *i2s = to_info(dai); 394+ 395+ i2s->bclk_ratio = ratio; 396+ 397+ return 0; 398+} 399+ 400 static int rockchip_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, 401 unsigned int freq, int dir) 402 { 403@@ -442,14 +475,16 @@ static int rockchip_i2s_dai_probe(struct snd_soc_dai *dai) 404 { 405 struct rk_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai); 406 407- dai->capture_dma_data = &i2s->capture_dma_data; 408- dai->playback_dma_data = &i2s->playback_dma_data; 409+ snd_soc_dai_init_dma_data(dai, 410+ i2s->has_playback ? &i2s->playback_dma_data : NULL, 411+ i2s->has_capture ? &i2s->capture_dma_data : NULL); 412 413 return 0; 414 } 415 416 static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = { 417 .hw_params = rockchip_i2s_hw_params, 418+ .set_bclk_ratio = rockchip_i2s_set_bclk_ratio, 419 .set_sysclk = rockchip_i2s_set_sysclk, 420 .set_fmt = rockchip_i2s_set_fmt, 421 .trigger = rockchip_i2s_trigger, 422@@ -457,28 +492,6 @@ static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = { 423 424 static struct snd_soc_dai_driver rockchip_i2s_dai = { 425 .probe = rockchip_i2s_dai_probe, 426- .playback = { 427- .stream_name = "Playback", 428- .channels_min = 2, 429- .channels_max = 8, 430- .rates = SNDRV_PCM_RATE_8000_192000, 431- .formats = (SNDRV_PCM_FMTBIT_S8 | 432- SNDRV_PCM_FMTBIT_S16_LE | 433- SNDRV_PCM_FMTBIT_S20_3LE | 434- SNDRV_PCM_FMTBIT_S24_LE | 435- SNDRV_PCM_FMTBIT_S32_LE), 436- }, 437- .capture = { 438- .stream_name = "Capture", 439- .channels_min = 2, 440- .channels_max = 2, 441- .rates = SNDRV_PCM_RATE_8000_192000, 442- .formats = (SNDRV_PCM_FMTBIT_S8 | 443- SNDRV_PCM_FMTBIT_S16_LE | 444- SNDRV_PCM_FMTBIT_S20_3LE | 445- SNDRV_PCM_FMTBIT_S24_LE | 446- SNDRV_PCM_FMTBIT_S32_LE), 447- }, 448 .ops = &rockchip_i2s_dai_ops, 449 .symmetric_rates = 1, 450 }; 451@@ -575,7 +588,7 @@ static const struct rk_i2s_pins rk3399_i2s_pins = { 452 .shift = 11, 453 }; 454 455-static const struct of_device_id rockchip_i2s_match[] = { 456+static const struct of_device_id rockchip_i2s_match[] __maybe_unused = { 457 { .compatible = "rockchip,rk3066-i2s", }, 458 { .compatible = "rockchip,rk3188-i2s", }, 459 { .compatible = "rockchip,rk3288-i2s", }, 460@@ -583,21 +596,90 @@ static const struct of_device_id rockchip_i2s_match[] = { 461 {}, 462 }; 463 464+static int rockchip_i2s_init_dai(struct rk_i2s_dev *i2s, struct resource *res, 465+ struct snd_soc_dai_driver **dp) 466+{ 467+ struct device_node *node = i2s->dev->of_node; 468+ struct snd_soc_dai_driver *dai; 469+ struct property *dma_names; 470+ const char *dma_name; 471+ unsigned int val; 472+ 473+ of_property_for_each_string(node, "dma-names", dma_names, dma_name) { 474+ if (!strcmp(dma_name, "tx")) 475+ i2s->has_playback = true; 476+ if (!strcmp(dma_name, "rx")) 477+ i2s->has_capture = true; 478+ } 479+ 480+ dai = devm_kmemdup(i2s->dev, &rockchip_i2s_dai, 481+ sizeof(*dai), GFP_KERNEL); 482+ if (!dai) 483+ return -ENOMEM; 484+ 485+ if (i2s->has_playback) { 486+ dai->playback.stream_name = "Playback"; 487+ dai->playback.channels_min = 2; 488+ dai->playback.channels_max = 8; 489+ dai->playback.rates = SNDRV_PCM_RATE_8000_192000; 490+ dai->playback.formats = SNDRV_PCM_FMTBIT_S8 | 491+ SNDRV_PCM_FMTBIT_S16_LE | 492+ SNDRV_PCM_FMTBIT_S20_3LE | 493+ SNDRV_PCM_FMTBIT_S24_LE | 494+ SNDRV_PCM_FMTBIT_S32_LE; 495+ 496+ i2s->playback_dma_data.addr = res->start + I2S_TXDR; 497+ i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 498+ i2s->playback_dma_data.maxburst = 8; 499+ 500+ if (!of_property_read_u32(node, "rockchip,playback-channels", &val)) { 501+ if (val >= 2 && val <= 8) 502+ dai->playback.channels_max = val; 503+ } 504+ } 505+ 506+ if (i2s->has_capture) { 507+ dai->capture.stream_name = "Capture"; 508+ dai->capture.channels_min = 2; 509+ dai->capture.channels_max = 8; 510+ dai->capture.rates = SNDRV_PCM_RATE_8000_192000; 511+ dai->capture.formats = SNDRV_PCM_FMTBIT_S8 | 512+ SNDRV_PCM_FMTBIT_S16_LE | 513+ SNDRV_PCM_FMTBIT_S20_3LE | 514+ SNDRV_PCM_FMTBIT_S24_LE | 515+ SNDRV_PCM_FMTBIT_S32_LE; 516+ 517+ i2s->capture_dma_data.addr = res->start + I2S_RXDR; 518+ i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 519+ i2s->capture_dma_data.maxburst = 8; 520+ 521+ if (!of_property_read_u32(node, "rockchip,capture-channels", &val)) { 522+ if (val >= 2 && val <= 8) 523+ dai->capture.channels_max = val; 524+ } 525+ } 526+ 527+ if (dp) 528+ *dp = dai; 529+ 530+ return 0; 531+} 532+ 533 static int rockchip_i2s_probe(struct platform_device *pdev) 534 { 535 struct device_node *node = pdev->dev.of_node; 536 const struct of_device_id *of_id; 537 struct rk_i2s_dev *i2s; 538- struct snd_soc_dai_driver *soc_dai; 539+ struct snd_soc_dai_driver *dai; 540 struct resource *res; 541 void __iomem *regs; 542 int ret; 543- int val; 544 545 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); 546 if (!i2s) 547 return -ENOMEM; 548 549+ spin_lock_init(&i2s->lock); 550 i2s->dev = &pdev->dev; 551 552 i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); 553@@ -609,50 +691,40 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 554 i2s->pins = of_id->data; 555 } 556 557- /* try to prepare related clocks */ 558- i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); 559- if (IS_ERR(i2s->hclk)) { 560- dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); 561- return PTR_ERR(i2s->hclk); 562- } 563- ret = clk_prepare_enable(i2s->hclk); 564- if (ret) { 565- dev_err(i2s->dev, "hclock enable failed %d\n", ret); 566- return ret; 567- } 568- 569- i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); 570- if (IS_ERR(i2s->mclk)) { 571- dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); 572- ret = PTR_ERR(i2s->mclk); 573- goto err_clk; 574- } 575- 576 regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 577- if (IS_ERR(regs)) { 578- ret = PTR_ERR(regs); 579- goto err_clk; 580- } 581+ if (IS_ERR(regs)) 582+ return PTR_ERR(regs); 583 584 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, 585 &rockchip_i2s_regmap_config); 586 if (IS_ERR(i2s->regmap)) { 587 dev_err(&pdev->dev, 588 "Failed to initialise managed register map\n"); 589- ret = PTR_ERR(i2s->regmap); 590- goto err_clk; 591+ return PTR_ERR(i2s->regmap); 592 } 593 594- i2s->playback_dma_data.addr = res->start + I2S_TXDR; 595- i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 596- i2s->playback_dma_data.maxburst = 4; 597- 598- i2s->capture_dma_data.addr = res->start + I2S_RXDR; 599- i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 600- i2s->capture_dma_data.maxburst = 4; 601+ i2s->bclk_ratio = 64; 602 603 dev_set_drvdata(&pdev->dev, i2s); 604 605+ i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); 606+ if (IS_ERR(i2s->mclk)) { 607+ dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); 608+ return PTR_ERR(i2s->mclk); 609+ } 610+ 611+ /* try to prepare related clocks */ 612+ i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); 613+ if (IS_ERR(i2s->hclk)) { 614+ dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); 615+ return PTR_ERR(i2s->hclk); 616+ } 617+ ret = clk_prepare_enable(i2s->hclk); 618+ if (ret) { 619+ dev_err(i2s->dev, "hclock enable failed %d\n", ret); 620+ return ret; 621+ } 622+ 623 pm_runtime_enable(&pdev->dev); 624 if (!pm_runtime_enabled(&pdev->dev)) { 625 ret = i2s_runtime_resume(&pdev->dev); 626@@ -660,33 +732,20 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 627 goto err_pm_disable; 628 } 629 630- soc_dai = devm_kmemdup(&pdev->dev, &rockchip_i2s_dai, 631- sizeof(*soc_dai), GFP_KERNEL); 632- if (!soc_dai) { 633- ret = -ENOMEM; 634+ ret = rockchip_i2s_init_dai(i2s, res, &dai); 635+ if (ret) 636 goto err_pm_disable; 637- } 638- 639- if (!of_property_read_u32(node, "rockchip,playback-channels", &val)) { 640- if (val >= 2 && val <= 8) 641- soc_dai->playback.channels_max = val; 642- } 643- 644- if (!of_property_read_u32(node, "rockchip,capture-channels", &val)) { 645- if (val >= 2 && val <= 8) 646- soc_dai->capture.channels_max = val; 647- } 648 649 ret = devm_snd_soc_register_component(&pdev->dev, 650 &rockchip_i2s_component, 651- soc_dai, 1); 652+ dai, 1); 653 654 if (ret) { 655 dev_err(&pdev->dev, "Could not register DAI\n"); 656 goto err_suspend; 657 } 658 659- ret = rockchip_pcm_platform_register(&pdev->dev); 660+ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 661 if (ret) { 662 dev_err(&pdev->dev, "Could not register PCM\n"); 663 goto err_suspend; 664@@ -699,8 +758,9 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 665 i2s_runtime_suspend(&pdev->dev); 666 err_pm_disable: 667 pm_runtime_disable(&pdev->dev); 668-err_clk: 669+ 670 clk_disable_unprepare(i2s->hclk); 671+ 672 return ret; 673 } 674 675diff --git a/sound/soc/rockchip/rockchip_i2s.h b/sound/soc/rockchip/rockchip_i2s.h 676index fcaae24e4..251851bf4 100644 677--- a/sound/soc/rockchip/rockchip_i2s.h 678+++ b/sound/soc/rockchip/rockchip_i2s.h 679@@ -88,15 +88,17 @@ 680 #define I2S_CKR_MSS_SLAVE (1 << I2S_CKR_MSS_SHIFT) 681 #define I2S_CKR_MSS_MASK (1 << I2S_CKR_MSS_SHIFT) 682 #define I2S_CKR_CKP_SHIFT 26 683-#define I2S_CKR_CKP_NEG (0 << I2S_CKR_CKP_SHIFT) 684-#define I2S_CKR_CKP_POS (1 << I2S_CKR_CKP_SHIFT) 685+#define I2S_CKR_CKP_NORMAL (0 << I2S_CKR_CKP_SHIFT) 686+#define I2S_CKR_CKP_INVERTED (1 << I2S_CKR_CKP_SHIFT) 687 #define I2S_CKR_CKP_MASK (1 << I2S_CKR_CKP_SHIFT) 688 #define I2S_CKR_RLP_SHIFT 25 689 #define I2S_CKR_RLP_NORMAL (0 << I2S_CKR_RLP_SHIFT) 690-#define I2S_CKR_RLP_OPPSITE (1 << I2S_CKR_RLP_SHIFT) 691+#define I2S_CKR_RLP_INVERTED (1 << I2S_CKR_RLP_SHIFT) 692+#define I2S_CKR_RLP_MASK (1 << I2S_CKR_RLP_SHIFT) 693 #define I2S_CKR_TLP_SHIFT 24 694 #define I2S_CKR_TLP_NORMAL (0 << I2S_CKR_TLP_SHIFT) 695-#define I2S_CKR_TLP_OPPSITE (1 << I2S_CKR_TLP_SHIFT) 696+#define I2S_CKR_TLP_INVERTED (1 << I2S_CKR_TLP_SHIFT) 697+#define I2S_CKR_TLP_MASK (1 << I2S_CKR_TLP_SHIFT) 698 #define I2S_CKR_MDIV_SHIFT 16 699 #define I2S_CKR_MDIV(x) ((x - 1) << I2S_CKR_MDIV_SHIFT) 700 #define I2S_CKR_MDIV_MASK (0xff << I2S_CKR_MDIV_SHIFT) 701diff --git a/sound/soc/rockchip/rockchip_pdm.c b/sound/soc/rockchip/rockchip_pdm.c 702index 5adb293d0..a5686fae4 100644 703--- a/sound/soc/rockchip/rockchip_pdm.c 704+++ b/sound/soc/rockchip/rockchip_pdm.c 705@@ -20,6 +20,7 @@ 706 707 #define PDM_DMA_BURST_SIZE (8) /* size * width: 8*4 = 32 bytes */ 708 #define PDM_SIGNOFF_CLK_RATE (100000000) 709+#define PDM_PATH_MAX (4) 710 711 enum rk_pdm_version { 712 RK_PDM_RK3229, 713@@ -149,7 +150,7 @@ static int rockchip_pdm_hw_params(struct snd_pcm_substream *substream, 714 struct rk_pdm_dev *pdm = to_info(dai); 715 unsigned int val = 0; 716 unsigned int clk_rate, clk_div, samplerate; 717- unsigned int clk_src, clk_out = 0; 718+ unsigned int clk_src = 0, clk_out = 0; 719 unsigned long m, n; 720 bool change; 721 int ret; 722@@ -441,9 +442,10 @@ static bool rockchip_pdm_precious_reg(struct device *dev, unsigned int reg) 723 } 724 725 static const struct reg_default rockchip_pdm_reg_defaults[] = { 726- {0x04, 0x78000017}, 727- {0x08, 0x0bb8ea60}, 728- {0x18, 0x0000001f}, 729+ { PDM_CTRL0, 0x78000017 }, 730+ { PDM_CTRL1, 0x0bb8ea60 }, 731+ { PDM_CLK_CTRL, 0x0000e401 }, 732+ { PDM_DMA_CTRL, 0x0000001f }, 733 }; 734 735 static const struct regmap_config rockchip_pdm_regmap_config = { 736@@ -460,7 +462,7 @@ static const struct regmap_config rockchip_pdm_regmap_config = { 737 .cache_type = REGCACHE_FLAT, 738 }; 739 740-static const struct of_device_id rockchip_pdm_match[] = { 741+static const struct of_device_id rockchip_pdm_match[] __maybe_unused = { 742 { .compatible = "rockchip,pdm", 743 .data = (void *)RK_PDM_RK3229 }, 744 { .compatible = "rockchip,px30-pdm", 745@@ -473,8 +475,36 @@ static const struct of_device_id rockchip_pdm_match[] = { 746 }; 747 MODULE_DEVICE_TABLE(of, rockchip_pdm_match); 748 749+static int rockchip_pdm_path_parse(struct rk_pdm_dev *pdm, struct device_node *node) 750+{ 751+ unsigned int path[PDM_PATH_MAX]; 752+ int cnt = 0, ret = 0, i = 0, val = 0, msk = 0; 753+ 754+ cnt = of_count_phandle_with_args(node, "rockchip,path-map", 755+ NULL); 756+ if (cnt != PDM_PATH_MAX) 757+ return cnt; 758+ 759+ ret = of_property_read_u32_array(node, "rockchip,path-map", 760+ path, cnt); 761+ if (ret) 762+ return ret; 763+ 764+ for (i = 0; i < cnt; i++) { 765+ if (path[i] >= PDM_PATH_MAX) 766+ return -EINVAL; 767+ msk |= PDM_PATH_MASK(i); 768+ val |= PDM_PATH(i, path[i]); 769+ } 770+ 771+ regmap_update_bits(pdm->regmap, PDM_CLK_CTRL, msk, val); 772+ 773+ return 0; 774+} 775+ 776 static int rockchip_pdm_probe(struct platform_device *pdev) 777 { 778+ struct device_node *node = pdev->dev.of_node; 779 const struct of_device_id *match; 780 struct rk_pdm_dev *pdm; 781 struct resource *res; 782@@ -495,8 +525,7 @@ static int rockchip_pdm_probe(struct platform_device *pdev) 783 return PTR_ERR(pdm->reset); 784 } 785 786- res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 787- regs = devm_ioremap_resource(&pdev->dev, res); 788+ regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 789 if (IS_ERR(regs)) 790 return PTR_ERR(regs); 791 792@@ -541,6 +570,11 @@ static int rockchip_pdm_probe(struct platform_device *pdev) 793 } 794 795 rockchip_pdm_rxctrl(pdm, 0); 796+ 797+ ret = rockchip_pdm_path_parse(pdm, node); 798+ if (ret != 0 && ret != -ENOENT) 799+ goto err_suspend; 800+ 801 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 802 if (ret) { 803 dev_err(&pdev->dev, "could not register pcm: %d\n", ret); 804diff --git a/sound/soc/rockchip/rockchip_pdm.h b/sound/soc/rockchip/rockchip_pdm.h 805index 8e5bbafef..cab977272 100644 806--- a/sound/soc/rockchip/rockchip_pdm.h 807+++ b/sound/soc/rockchip/rockchip_pdm.h 808@@ -41,6 +41,8 @@ 809 #define PDM_PATH1_EN BIT(28) 810 #define PDM_PATH0_EN BIT(27) 811 #define PDM_HWT_EN BIT(26) 812+#define PDM_SAMPLERATE_MSK GENMASK(7, 5) 813+#define PDM_SAMPLERATE(x) ((x) << 5) 814 #define PDM_VDW_MSK (0x1f << 0) 815 #define PDM_VDW(X) ((X - 1) << 0) 816 817@@ -51,6 +53,9 @@ 818 #define PDM_FD_DENOMINATOR_MSK GENMASK(15, 0) 819 820 /* PDM CLK CTRL */ 821+#define PDM_PATH_SHIFT(x) (8 + (x) * 2) 822+#define PDM_PATH_MASK(x) (0x3 << PDM_PATH_SHIFT(x)) 823+#define PDM_PATH(x, v) ((v) << PDM_PATH_SHIFT(x)) 824 #define PDM_CLK_FD_RATIO_MSK BIT(6) 825 #define PDM_CLK_FD_RATIO_40 (0X0 << 6) 826 #define PDM_CLK_FD_RATIO_35 BIT(6) 827@@ -66,6 +71,7 @@ 828 #define PDM_CLK_1280FS (0x2 << 0) 829 #define PDM_CLK_2560FS (0x3 << 0) 830 #define PDM_CLK_5120FS (0x4 << 0) 831+#define PDM_CIC_RATIO_MSK (0x3 << 0) 832 833 /* PDM HPF CTRL */ 834 #define PDM_HPF_LE BIT(3) 835diff --git a/sound/soc/rockchip/rockchip_spdif.c b/sound/soc/rockchip/rockchip_spdif.c 836index 674810851..7f00470ac 100644 837--- a/sound/soc/rockchip/rockchip_spdif.c 838+++ b/sound/soc/rockchip/rockchip_spdif.c 839@@ -41,7 +41,7 @@ struct rk_spdif_dev { 840 struct regmap *regmap; 841 }; 842 843-static const struct of_device_id rk_spdif_match[] = { 844+static const struct of_device_id rk_spdif_match[] __maybe_unused = { 845 { .compatible = "rockchip,rk3066-spdif", 846 .data = (void *)RK_SPDIF_RK3066 }, 847 { .compatible = "rockchip,rk3188-spdif", 848@@ -138,8 +138,7 @@ static int rk_spdif_hw_params(struct snd_pcm_substream *substream, 849 850 ret = regmap_update_bits(spdif->regmap, SPDIF_CFGR, 851 SPDIF_CFGR_CLK_DIV_MASK | SPDIF_CFGR_HALFWORD_ENABLE | 852- SDPIF_CFGR_VDW_MASK, 853- val); 854+ SDPIF_CFGR_VDW_MASK, val); 855 856 return ret; 857 } 858@@ -155,31 +154,26 @@ static int rk_spdif_trigger(struct snd_pcm_substream *substream, 859 case SNDRV_PCM_TRIGGER_RESUME: 860 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 861 ret = regmap_update_bits(spdif->regmap, SPDIF_DMACR, 862- SPDIF_DMACR_TDE_ENABLE | 863- SPDIF_DMACR_TDL_MASK, 864- SPDIF_DMACR_TDE_ENABLE | 865- SPDIF_DMACR_TDL(16)); 866+ SPDIF_DMACR_TDE_ENABLE | SPDIF_DMACR_TDL_MASK, 867+ SPDIF_DMACR_TDE_ENABLE | SPDIF_DMACR_TDL(16)); 868 869 if (ret != 0) 870 return ret; 871 872 ret = regmap_update_bits(spdif->regmap, SPDIF_XFER, 873- SPDIF_XFER_TXS_START, 874- SPDIF_XFER_TXS_START); 875+ SPDIF_XFER_TXS_START, SPDIF_XFER_TXS_START); 876 break; 877 case SNDRV_PCM_TRIGGER_SUSPEND: 878 case SNDRV_PCM_TRIGGER_STOP: 879 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 880 ret = regmap_update_bits(spdif->regmap, SPDIF_DMACR, 881- SPDIF_DMACR_TDE_ENABLE, 882- SPDIF_DMACR_TDE_DISABLE); 883+ SPDIF_DMACR_TDE_ENABLE, SPDIF_DMACR_TDE_DISABLE); 884 885 if (ret != 0) 886 return ret; 887 888 ret = regmap_update_bits(spdif->regmap, SPDIF_XFER, 889- SPDIF_XFER_TXS_START, 890- SPDIF_XFER_TXS_STOP); 891+ SPDIF_XFER_TXS_START, SPDIF_XFER_TXS_STOP); 892 break; 893 default: 894 ret = -EINVAL; 895@@ -247,6 +241,7 @@ static bool rk_spdif_rd_reg(struct device *dev, unsigned int reg) 896 case SPDIF_INTCR: 897 case SPDIF_INTSR: 898 case SPDIF_XFER: 899+ case SPDIF_SMPDR: 900 return true; 901 default: 902 return false; 903@@ -258,6 +253,7 @@ static bool rk_spdif_volatile_reg(struct device *dev, unsigned int reg) 904 switch (reg) { 905 case SPDIF_INTSR: 906 case SPDIF_SDBLR: 907+ case SPDIF_SMPDR: 908 return true; 909 default: 910 return false; 911@@ -291,7 +287,7 @@ static int rk_spdif_probe(struct platform_device *pdev) 912 grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf"); 913 if (IS_ERR(grf)) { 914 dev_err(&pdev->dev, 915- "rockchip_spdif missing 'rockchip,grf' \n"); 916+ "rockchip_spdif missing 'rockchip,grf'\n"); 917 return PTR_ERR(grf); 918 } 919 920@@ -313,8 +309,7 @@ static int rk_spdif_probe(struct platform_device *pdev) 921 if (IS_ERR(spdif->mclk)) 922 return PTR_ERR(spdif->mclk); 923 924- res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 925- regs = devm_ioremap_resource(&pdev->dev, res); 926+ regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 927 if (IS_ERR(regs)) 928 return PTR_ERR(regs); 929 930diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c 931index 6333a2ecb..03b1f7e35 100644 932--- a/sound/usb/quirks.c 933+++ b/sound/usb/quirks.c 934@@ -1523,6 +1523,9 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip) 935 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */ 936 case USB_ID(0x05a3, 0x9420): /* ELP HD USB Camera */ 937 case USB_ID(0x05a7, 0x1020): /* Bose Companion 5 */ 938+#ifdef CONFIG_HID_RKVR 939+ case USB_ID(0x071B, 0x3205): /* RockChip NanoC VR */ 940+#endif 941 case USB_ID(0x074d, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ 942 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */ 943 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */ 944@@ -1838,6 +1841,9 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip, 945 int stream) 946 { 947 switch (chip->usb_id) { 948+#ifdef CONFIG_HID_RKVR 949+ case USB_ID(0x071B, 0x3205): /* RockChip NanoC VR */ 950+#endif 951 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */ 952 /* Optoplay sets the sample rate attribute although 953 * it seems not supporting it in fact. 954