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,15 +627,16 @@ static unsigned int loopback_jiffies_timer_pos_update 78 cable->streams[SNDRV_PCM_STREAM_CAPTURE]; 79 unsigned long delta_play = 0, delta_capt = 0; 80 unsigned int running, count1, count2; 81+ unsigned long cur_jiffies = cycles_to_jiffies(); 82 83 running = cable->running ^ cable->pause; 84 if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) { 85- delta_play = jiffies - dpcm_play->last_jiffies; 86+ delta_play = cur_jiffies - dpcm_play->last_jiffies; 87 dpcm_play->last_jiffies += delta_play; 88 } 89 90 if (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) { 91- delta_capt = jiffies - dpcm_capt->last_jiffies; 92+ delta_capt = cur_jiffies - dpcm_capt->last_jiffies; 93 dpcm_capt->last_jiffies += delta_capt; 94 } 95 96@@ -842,7 +862,7 @@ static void loopback_jiffies_timer_dpcm_info(struct loopback_pcm *dpcm, 97 snd_iprintf(buffer, " irq_pos:\t\t%u\n", dpcm->irq_pos); 98 snd_iprintf(buffer, " period_frac:\t%u\n", dpcm->period_size_frac); 99 snd_iprintf(buffer, " last_jiffies:\t%lu (%lu)\n", 100- dpcm->last_jiffies, jiffies); 101+ dpcm->last_jiffies, cycles_to_jiffies()); 102 snd_iprintf(buffer, " timer_expires:\t%lu\n", dpcm->timer.expires); 103 } 104 105diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig 106index 34c6dd04b..78e46839a 100644 107--- a/sound/soc/codecs/Kconfig 108+++ b/sound/soc/codecs/Kconfig 109@@ -89,6 +89,7 @@ config SND_SOC_ALL_CODECS 110 imply SND_SOC_DA732X 111 imply SND_SOC_DA9055 112 imply SND_SOC_DMIC 113+ imply SND_SOC_DUMMY_CODEC 114 imply SND_SOC_ES8316 115 imply SND_SOC_ES8328_SPI 116 imply SND_SOC_ES8328_I2C 117@@ -761,6 +762,9 @@ config SND_SOC_DMIC 118 Enable support for the Generic Digital Microphone CODEC. 119 Select this if your sound card has DMICs. 120 121+config SND_SOC_DUMMY_CODEC 122+ tristate "Dummy CODEC" 123+ 124 config SND_SOC_HDMI_CODEC 125 tristate 126 select SND_PCM_ELD 127@@ -1024,6 +1028,9 @@ config SND_SOC_RK3328 128 tristate "Rockchip RK3328 audio CODEC" 129 select REGMAP_MMIO 130 131+config SND_SOC_RK_CODEC_DIGITAL 132+ tristate "Rockchip Codec Digital Interface" 133+ 134 config SND_SOC_RL6231 135 tristate 136 default y if SND_SOC_RT5514=y 137diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c 138index 4d286844e..2be7ba425 100644 139--- a/sound/soc/codecs/bt-sco.c 140+++ b/sound/soc/codecs/bt-sco.c 141@@ -26,14 +26,14 @@ static struct snd_soc_dai_driver bt_sco_dai[] = { 142 .playback = { 143 .stream_name = "Playback", 144 .channels_min = 1, 145- .channels_max = 1, 146+ .channels_max = 2, 147 .rates = SNDRV_PCM_RATE_8000, 148 .formats = SNDRV_PCM_FMTBIT_S16_LE, 149 }, 150 .capture = { 151 .stream_name = "Capture", 152 .channels_min = 1, 153- .channels_max = 1, 154+ .channels_max = 2, 155 .rates = SNDRV_PCM_RATE_8000, 156 .formats = SNDRV_PCM_FMTBIT_S16_LE, 157 }, 158@@ -43,14 +43,14 @@ static struct snd_soc_dai_driver bt_sco_dai[] = { 159 .playback = { 160 .stream_name = "Playback", 161 .channels_min = 1, 162- .channels_max = 1, 163+ .channels_max = 2, 164 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, 165 .formats = SNDRV_PCM_FMTBIT_S16_LE, 166 }, 167 .capture = { 168 .stream_name = "Capture", 169 .channels_min = 1, 170- .channels_max = 1, 171+ .channels_max = 2, 172 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, 173 .formats = SNDRV_PCM_FMTBIT_S16_LE, 174 }, 175diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig 176index d610b553e..fa31a0151 100644 177--- a/sound/soc/rockchip/Kconfig 178+++ b/sound/soc/rockchip/Kconfig 179@@ -7,6 +7,22 @@ config SND_SOC_ROCKCHIP 180 the Rockchip SoCs' Audio interfaces. You will also need to 181 select the audio interfaces to support below. 182 183+config SND_SOC_ROCKCHIP_PREALLOC_BUFFER_SIZE 184+ int "Default prealloc buffer size (kbytes)" 185+ depends on SND_SOC_ROCKCHIP 186+ default "512" 187+ help 188+ The default value is 512 kilobytes. Only change this if you know 189+ what you are doing. 190+ 191+config SND_SOC_ROCKCHIP_AUDIO_PWM 192+ tristate "Rockchip Audio PWM Driver" 193+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 194+ select SND_SOC_GENERIC_DMAENGINE_PCM 195+ help 196+ Say Y or M if you want to add support for Audio PWM driver for 197+ Rockchip Audio PWM Controller. 198+ 199 config SND_SOC_ROCKCHIP_I2S 200 tristate "Rockchip I2S Device Driver" 201 depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 202@@ -16,6 +32,15 @@ config SND_SOC_ROCKCHIP_I2S 203 Rockchip I2S device. The device supports upto maximum of 204 8 channels each for play and record. 205 206+config SND_SOC_ROCKCHIP_I2S_TDM 207+ tristate "Rockchip I2S/TDM Device Driver" 208+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 209+ select SND_SOC_GENERIC_DMAENGINE_PCM 210+ help 211+ Say Y or M if you want to add support for I2S/TDM driver for 212+ Rockchip I2S/TDM device. The device supports up to maximum of 213+ 8 channels each for play and record. 214+ 215 config SND_SOC_ROCKCHIP_PDM 216 tristate "Rockchip PDM Controller Driver" 217 depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 218@@ -34,6 +59,21 @@ config SND_SOC_ROCKCHIP_SPDIF 219 Say Y or M if you want to add support for SPDIF driver for 220 Rockchip SPDIF transceiver device. 221 222+config SND_SOC_ROCKCHIP_SPDIFRX 223+ tristate "Rockchip SPDIFRX Device Driver" 224+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 225+ select SND_SOC_GENERIC_DMAENGINE_PCM 226+ help 227+ Say Y or M if you want to add support for SPDIFRX driver for 228+ Rockchip SPDIF receiver device. 229+ 230+config SND_SOC_ROCKCHIP_VAD 231+ tristate "Rockchip Voice Activity Detection Driver" 232+ depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP 233+ help 234+ Say Y or M if you want to add support for VAD driver for 235+ Rockchip VAD device. 236+ 237 config SND_SOC_ROCKCHIP_MAX98090 238 tristate "ASoC support for Rockchip boards using a MAX98090 codec" 239 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 240@@ -45,6 +85,13 @@ config SND_SOC_ROCKCHIP_MAX98090 241 Say Y or M here if you want to add support for SoC audio on Rockchip 242 boards using the MAX98090 codec and HDMI codec, such as Veyron. 243 244+config SND_SOC_ROCKCHIP_MULTICODECS 245+ tristate "ASoC support for Rockchip multicodecs" 246+ depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP 247+ help 248+ Say Y or M here if you want to add support for SoC audio on Rockchip 249+ boards using multicodecs, such as RK3308 boards. 250+ 251 config SND_SOC_ROCKCHIP_RT5645 252 tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec" 253 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 254@@ -54,6 +101,14 @@ config SND_SOC_ROCKCHIP_RT5645 255 Say Y or M here if you want to add support for SoC audio on Rockchip 256 boards using the RT5645/RT5650 codec, such as Veyron. 257 258+config SND_SOC_ROCKCHIP_HDMI 259+ tristate "ASoC support for Rockchip HDMI audio" 260+ depends on SND_SOC_ROCKCHIP && CLKDEV_LOOKUP 261+ select SND_SOC_HDMI_CODEC 262+ help 263+ Say Y or M here if you want to add support for SoC audio on Rockchip 264+ boards using built-in HDMI or external HDMI. 265+ 266 config SND_SOC_RK3288_HDMI_ANALOG 267 tristate "ASoC support multiple codecs for Rockchip RK3288 boards" 268 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB && CLKDEV_LOOKUP 269diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile 270index 65e814d46..83be7d21e 100644 271--- a/sound/soc/rockchip/Makefile 272+++ b/sound/soc/rockchip/Makefile 273@@ -5,7 +5,8 @@ snd-soc-rockchip-pcm-objs := rockchip_pcm.o 274 snd-soc-rockchip-pdm-objs := rockchip_pdm.o 275 snd-soc-rockchip-spdif-objs := rockchip_spdif.o 276 277-obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o snd-soc-rockchip-pcm.o 278+obj-$(CONFIG_SND_SOC_ROCKCHIP) += snd-soc-rockchip-pcm.o 279+obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o 280 obj-$(CONFIG_SND_SOC_ROCKCHIP_PDM) += snd-soc-rockchip-pdm.o 281 obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o 282 283diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c 284index fa84ec695..165d027b4 100644 285--- a/sound/soc/rockchip/rockchip_i2s.c 286+++ b/sound/soc/rockchip/rockchip_i2s.c 287@@ -15,11 +15,11 @@ 288 #include <linux/clk.h> 289 #include <linux/pm_runtime.h> 290 #include <linux/regmap.h> 291+#include <linux/spinlock.h> 292 #include <sound/pcm_params.h> 293 #include <sound/dmaengine_pcm.h> 294 295 #include "rockchip_i2s.h" 296-#include "rockchip_pcm.h" 297 298 #define DRV_NAME "rockchip-i2s" 299 300@@ -40,6 +40,9 @@ struct rk_i2s_dev { 301 struct regmap *regmap; 302 struct regmap *grf; 303 304+ bool has_capture; 305+ bool has_playback; 306+ 307 /* 308 * Used to indicate the tx/rx status. 309 * I2S controller hopes to start the tx and rx together, 310@@ -49,6 +52,8 @@ struct rk_i2s_dev { 311 bool rx_start; 312 bool is_master_mode; 313 const struct rk_i2s_pins *pins; 314+ unsigned int bclk_ratio; 315+ spinlock_t lock; /* tx/rx lock */ 316 }; 317 318 static int i2s_runtime_suspend(struct device *dev) 319@@ -92,6 +97,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) 320 unsigned int val = 0; 321 int retry = 10; 322 323+ spin_lock(&i2s->lock); 324 if (on) { 325 regmap_update_bits(i2s->regmap, I2S_DMACR, 326 I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); 327@@ -132,6 +138,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) 328 } 329 } 330 } 331+ spin_unlock(&i2s->lock); 332 } 333 334 static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 335@@ -139,6 +146,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 336 unsigned int val = 0; 337 int retry = 10; 338 339+ spin_lock(&i2s->lock); 340 if (on) { 341 regmap_update_bits(i2s->regmap, I2S_DMACR, 342 I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); 343@@ -179,6 +187,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) 344 } 345 } 346 } 347+ spin_unlock(&i2s->lock); 348 } 349 350 static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, 351@@ -207,13 +216,27 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, 352 353 regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); 354 355- mask = I2S_CKR_CKP_MASK; 356+ mask = I2S_CKR_CKP_MASK | I2S_CKR_TLP_MASK | I2S_CKR_RLP_MASK; 357 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 358 case SND_SOC_DAIFMT_NB_NF: 359- val = I2S_CKR_CKP_NEG; 360+ val = I2S_CKR_CKP_NORMAL | 361+ I2S_CKR_TLP_NORMAL | 362+ I2S_CKR_RLP_NORMAL; 363+ break; 364+ case SND_SOC_DAIFMT_NB_IF: 365+ val = I2S_CKR_CKP_NORMAL | 366+ I2S_CKR_TLP_INVERTED | 367+ I2S_CKR_RLP_INVERTED; 368 break; 369 case SND_SOC_DAIFMT_IB_NF: 370- val = I2S_CKR_CKP_POS; 371+ val = I2S_CKR_CKP_INVERTED | 372+ I2S_CKR_TLP_NORMAL | 373+ I2S_CKR_RLP_NORMAL; 374+ break; 375+ case SND_SOC_DAIFMT_IB_IF: 376+ val = I2S_CKR_CKP_INVERTED | 377+ I2S_CKR_TLP_INVERTED | 378+ I2S_CKR_RLP_INVERTED; 379 break; 380 default: 381 ret = -EINVAL; 382@@ -287,11 +310,11 @@ static int rockchip_i2s_hw_params(struct snd_pcm_substream *substream, 383 384 if (i2s->is_master_mode) { 385 mclk_rate = clk_get_rate(i2s->mclk); 386- bclk_rate = 2 * 32 * params_rate(params); 387- if (bclk_rate == 0 || mclk_rate % bclk_rate) 388+ bclk_rate = i2s->bclk_ratio * params_rate(params); 389+ if (!bclk_rate) 390 return -EINVAL; 391 392- div_bclk = mclk_rate / bclk_rate; 393+ div_bclk = DIV_ROUND_CLOSEST(mclk_rate, bclk_rate); 394 div_lrck = bclk_rate / params_rate(params); 395 regmap_update_bits(i2s->regmap, I2S_CKR, 396 I2S_CKR_MDIV_MASK, 397@@ -422,6 +445,16 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, 398 return ret; 399 } 400 401+static int rockchip_i2s_set_bclk_ratio(struct snd_soc_dai *dai, 402+ unsigned int ratio) 403+{ 404+ struct rk_i2s_dev *i2s = to_info(dai); 405+ 406+ i2s->bclk_ratio = ratio; 407+ 408+ return 0; 409+} 410+ 411 static int rockchip_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, 412 unsigned int freq, int dir) 413 { 414@@ -442,14 +475,16 @@ static int rockchip_i2s_dai_probe(struct snd_soc_dai *dai) 415 { 416 struct rk_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai); 417 418- dai->capture_dma_data = &i2s->capture_dma_data; 419- dai->playback_dma_data = &i2s->playback_dma_data; 420+ snd_soc_dai_init_dma_data(dai, 421+ i2s->has_playback ? &i2s->playback_dma_data : NULL, 422+ i2s->has_capture ? &i2s->capture_dma_data : NULL); 423 424 return 0; 425 } 426 427 static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = { 428 .hw_params = rockchip_i2s_hw_params, 429+ .set_bclk_ratio = rockchip_i2s_set_bclk_ratio, 430 .set_sysclk = rockchip_i2s_set_sysclk, 431 .set_fmt = rockchip_i2s_set_fmt, 432 .trigger = rockchip_i2s_trigger, 433@@ -457,28 +492,6 @@ static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = { 434 435 static struct snd_soc_dai_driver rockchip_i2s_dai = { 436 .probe = rockchip_i2s_dai_probe, 437- .playback = { 438- .stream_name = "Playback", 439- .channels_min = 2, 440- .channels_max = 8, 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- .capture = { 449- .stream_name = "Capture", 450- .channels_min = 2, 451- .channels_max = 2, 452- .rates = SNDRV_PCM_RATE_8000_192000, 453- .formats = (SNDRV_PCM_FMTBIT_S8 | 454- SNDRV_PCM_FMTBIT_S16_LE | 455- SNDRV_PCM_FMTBIT_S20_3LE | 456- SNDRV_PCM_FMTBIT_S24_LE | 457- SNDRV_PCM_FMTBIT_S32_LE), 458- }, 459 .ops = &rockchip_i2s_dai_ops, 460 .symmetric_rates = 1, 461 }; 462@@ -575,7 +588,7 @@ static const struct rk_i2s_pins rk3399_i2s_pins = { 463 .shift = 11, 464 }; 465 466-static const struct of_device_id rockchip_i2s_match[] = { 467+static const struct of_device_id rockchip_i2s_match[] __maybe_unused = { 468 { .compatible = "rockchip,rk3066-i2s", }, 469 { .compatible = "rockchip,rk3188-i2s", }, 470 { .compatible = "rockchip,rk3288-i2s", }, 471@@ -583,21 +596,90 @@ static const struct of_device_id rockchip_i2s_match[] = { 472 {}, 473 }; 474 475+static int rockchip_i2s_init_dai(struct rk_i2s_dev *i2s, struct resource *res, 476+ struct snd_soc_dai_driver **dp) 477+{ 478+ struct device_node *node = i2s->dev->of_node; 479+ struct snd_soc_dai_driver *dai; 480+ struct property *dma_names; 481+ const char *dma_name; 482+ unsigned int val; 483+ 484+ of_property_for_each_string(node, "dma-names", dma_names, dma_name) { 485+ if (!strcmp(dma_name, "tx")) 486+ i2s->has_playback = true; 487+ if (!strcmp(dma_name, "rx")) 488+ i2s->has_capture = true; 489+ } 490+ 491+ dai = devm_kmemdup(i2s->dev, &rockchip_i2s_dai, 492+ sizeof(*dai), GFP_KERNEL); 493+ if (!dai) 494+ return -ENOMEM; 495+ 496+ if (i2s->has_playback) { 497+ dai->playback.stream_name = "Playback"; 498+ dai->playback.channels_min = 2; 499+ dai->playback.channels_max = 8; 500+ dai->playback.rates = SNDRV_PCM_RATE_8000_192000; 501+ dai->playback.formats = SNDRV_PCM_FMTBIT_S8 | 502+ SNDRV_PCM_FMTBIT_S16_LE | 503+ SNDRV_PCM_FMTBIT_S20_3LE | 504+ SNDRV_PCM_FMTBIT_S24_LE | 505+ SNDRV_PCM_FMTBIT_S32_LE; 506+ 507+ i2s->playback_dma_data.addr = res->start + I2S_TXDR; 508+ i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 509+ i2s->playback_dma_data.maxburst = 8; 510+ 511+ if (!of_property_read_u32(node, "rockchip,playback-channels", &val)) { 512+ if (val >= 2 && val <= 8) 513+ dai->playback.channels_max = val; 514+ } 515+ } 516+ 517+ if (i2s->has_capture) { 518+ dai->capture.stream_name = "Capture"; 519+ dai->capture.channels_min = 2; 520+ dai->capture.channels_max = 8; 521+ dai->capture.rates = SNDRV_PCM_RATE_8000_192000; 522+ dai->capture.formats = SNDRV_PCM_FMTBIT_S8 | 523+ SNDRV_PCM_FMTBIT_S16_LE | 524+ SNDRV_PCM_FMTBIT_S20_3LE | 525+ SNDRV_PCM_FMTBIT_S24_LE | 526+ SNDRV_PCM_FMTBIT_S32_LE; 527+ 528+ i2s->capture_dma_data.addr = res->start + I2S_RXDR; 529+ i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 530+ i2s->capture_dma_data.maxburst = 8; 531+ 532+ if (!of_property_read_u32(node, "rockchip,capture-channels", &val)) { 533+ if (val >= 2 && val <= 8) 534+ dai->capture.channels_max = val; 535+ } 536+ } 537+ 538+ if (dp) 539+ *dp = dai; 540+ 541+ return 0; 542+} 543+ 544 static int rockchip_i2s_probe(struct platform_device *pdev) 545 { 546 struct device_node *node = pdev->dev.of_node; 547 const struct of_device_id *of_id; 548 struct rk_i2s_dev *i2s; 549- struct snd_soc_dai_driver *soc_dai; 550+ struct snd_soc_dai_driver *dai; 551 struct resource *res; 552 void __iomem *regs; 553 int ret; 554- int val; 555 556 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); 557 if (!i2s) 558 return -ENOMEM; 559 560+ spin_lock_init(&i2s->lock); 561 i2s->dev = &pdev->dev; 562 563 i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); 564@@ -609,26 +691,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 565 i2s->pins = of_id->data; 566 } 567 568- /* try to prepare related clocks */ 569- i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); 570- if (IS_ERR(i2s->hclk)) { 571- dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); 572- return PTR_ERR(i2s->hclk); 573- } 574- ret = clk_prepare_enable(i2s->hclk); 575- if (ret) { 576- dev_err(i2s->dev, "hclock enable failed %d\n", ret); 577- return ret; 578- } 579- 580- i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); 581- if (IS_ERR(i2s->mclk)) { 582- dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); 583- return PTR_ERR(i2s->mclk); 584- } 585- 586- res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 587- regs = devm_ioremap_resource(&pdev->dev, res); 588+ regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 589 if (IS_ERR(regs)) 590 return PTR_ERR(regs); 591 592@@ -640,16 +703,28 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 593 return PTR_ERR(i2s->regmap); 594 } 595 596- i2s->playback_dma_data.addr = res->start + I2S_TXDR; 597- i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 598- i2s->playback_dma_data.maxburst = 4; 599- 600- i2s->capture_dma_data.addr = res->start + I2S_RXDR; 601- i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 602- i2s->capture_dma_data.maxburst = 4; 603+ i2s->bclk_ratio = 64; 604 605 dev_set_drvdata(&pdev->dev, i2s); 606 607+ i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); 608+ if (IS_ERR(i2s->mclk)) { 609+ dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); 610+ return PTR_ERR(i2s->mclk); 611+ } 612+ 613+ /* try to prepare related clocks */ 614+ i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); 615+ if (IS_ERR(i2s->hclk)) { 616+ dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); 617+ return PTR_ERR(i2s->hclk); 618+ } 619+ ret = clk_prepare_enable(i2s->hclk); 620+ if (ret) { 621+ dev_err(i2s->dev, "hclock enable failed %d\n", ret); 622+ return ret; 623+ } 624+ 625 pm_runtime_enable(&pdev->dev); 626 if (!pm_runtime_enabled(&pdev->dev)) { 627 ret = i2s_runtime_resume(&pdev->dev); 628@@ -657,33 +732,20 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 629 goto err_pm_disable; 630 } 631 632- soc_dai = devm_kmemdup(&pdev->dev, &rockchip_i2s_dai, 633- sizeof(*soc_dai), GFP_KERNEL); 634- if (!soc_dai) { 635- ret = -ENOMEM; 636+ ret = rockchip_i2s_init_dai(i2s, res, &dai); 637+ if (ret) 638 goto err_pm_disable; 639- } 640- 641- if (!of_property_read_u32(node, "rockchip,playback-channels", &val)) { 642- if (val >= 2 && val <= 8) 643- soc_dai->playback.channels_max = val; 644- } 645- 646- if (!of_property_read_u32(node, "rockchip,capture-channels", &val)) { 647- if (val >= 2 && val <= 8) 648- soc_dai->capture.channels_max = val; 649- } 650 651 ret = devm_snd_soc_register_component(&pdev->dev, 652 &rockchip_i2s_component, 653- soc_dai, 1); 654+ dai, 1); 655 656 if (ret) { 657 dev_err(&pdev->dev, "Could not register DAI\n"); 658 goto err_suspend; 659 } 660 661- ret = rockchip_pcm_platform_register(&pdev->dev); 662+ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 663 if (ret) { 664 dev_err(&pdev->dev, "Could not register PCM\n"); 665 goto err_suspend; 666@@ -697,6 +759,8 @@ static int rockchip_i2s_probe(struct platform_device *pdev) 667 err_pm_disable: 668 pm_runtime_disable(&pdev->dev); 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 75d4d317b..e60bf1f40 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