| .. | .. |
|---|
| 23 | 23 | #define DAIS_DRV_NAME "rockchip-mdais" |
|---|
| 24 | 24 | #define RK3308_GRF_SOC_CON2 0x308 |
|---|
| 25 | 25 | |
|---|
| 26 | +#define SOUND_NAME_PREFIX "sound-name-prefix" |
|---|
| 27 | + |
|---|
| 26 | 28 | static inline struct rk_mdais_dev *to_info(struct snd_soc_dai *dai) |
|---|
| 27 | 29 | { |
|---|
| 28 | 30 | return snd_soc_dai_get_drvdata(dai); |
|---|
| 31 | +} |
|---|
| 32 | + |
|---|
| 33 | +static inline unsigned int *mdais_channel_maps(struct rk_mdais_dev *mdais, |
|---|
| 34 | + struct snd_pcm_substream *substream) |
|---|
| 35 | +{ |
|---|
| 36 | + return substream->stream ? mdais->capture_channel_maps : |
|---|
| 37 | + mdais->playback_channel_maps; |
|---|
| 29 | 38 | } |
|---|
| 30 | 39 | |
|---|
| 31 | 40 | static void hw_refine_channels(struct snd_pcm_hw_params *params, |
|---|
| .. | .. |
|---|
| 52 | 61 | if (IS_ERR(cparams)) |
|---|
| 53 | 62 | return PTR_ERR(cparams); |
|---|
| 54 | 63 | |
|---|
| 55 | | - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
|---|
| 56 | | - channel_maps = mdais->playback_channel_maps; |
|---|
| 57 | | - else |
|---|
| 58 | | - channel_maps = mdais->capture_channel_maps; |
|---|
| 64 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 59 | 65 | |
|---|
| 60 | 66 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 61 | 67 | child = mdais->dais[i].dai; |
|---|
| 62 | | - if (channel_maps[i]) |
|---|
| 63 | | - hw_refine_channels(cparams, channel_maps[i]); |
|---|
| 68 | + if (!channel_maps[i]) |
|---|
| 69 | + continue; |
|---|
| 70 | + |
|---|
| 71 | + hw_refine_channels(cparams, channel_maps[i]); |
|---|
| 64 | 72 | if (child->driver->ops && child->driver->ops->hw_params) { |
|---|
| 65 | 73 | ret = child->driver->ops->hw_params(substream, cparams, child); |
|---|
| 66 | 74 | if (ret < 0) { |
|---|
| 67 | | - dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n", |
|---|
| 75 | + dev_err(dai->dev, "Failed to set %s hw params: %d\n", |
|---|
| 68 | 76 | dai->name, ret); |
|---|
| 69 | | - return ret; |
|---|
| 77 | + break; |
|---|
| 70 | 78 | } |
|---|
| 71 | 79 | } |
|---|
| 72 | 80 | } |
|---|
| 73 | 81 | |
|---|
| 74 | 82 | kfree(cparams); |
|---|
| 83 | + |
|---|
| 84 | + return ret; |
|---|
| 85 | +} |
|---|
| 86 | + |
|---|
| 87 | +static int rockchip_mdais_hw_free(struct snd_pcm_substream *substream, |
|---|
| 88 | + struct snd_soc_dai *dai) |
|---|
| 89 | +{ |
|---|
| 90 | + struct rk_mdais_dev *mdais = to_info(dai); |
|---|
| 91 | + struct snd_soc_dai *child; |
|---|
| 92 | + unsigned int *channel_maps; |
|---|
| 93 | + int ret = 0, i = 0; |
|---|
| 94 | + |
|---|
| 95 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 96 | + |
|---|
| 97 | + for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 98 | + child = mdais->dais[i].dai; |
|---|
| 99 | + if (!channel_maps[i]) |
|---|
| 100 | + continue; |
|---|
| 101 | + |
|---|
| 102 | + if (child->driver->ops && child->driver->ops->hw_free) { |
|---|
| 103 | + ret = child->driver->ops->hw_free(substream, child); |
|---|
| 104 | + if (ret < 0) |
|---|
| 105 | + return ret; |
|---|
| 106 | + } |
|---|
| 107 | + } |
|---|
| 108 | + |
|---|
| 75 | 109 | return 0; |
|---|
| 76 | 110 | } |
|---|
| 77 | 111 | |
|---|
| .. | .. |
|---|
| 83 | 117 | unsigned int *channel_maps; |
|---|
| 84 | 118 | int ret = 0, i = 0; |
|---|
| 85 | 119 | |
|---|
| 86 | | - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
|---|
| 87 | | - channel_maps = mdais->playback_channel_maps; |
|---|
| 88 | | - else |
|---|
| 89 | | - channel_maps = mdais->capture_channel_maps; |
|---|
| 120 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 90 | 121 | |
|---|
| 91 | 122 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 92 | 123 | /* skip DAIs which have no channel mapping */ |
|---|
| .. | .. |
|---|
| 110 | 141 | { |
|---|
| 111 | 142 | struct rk_mdais_dev *mdais = to_info(dai); |
|---|
| 112 | 143 | struct snd_soc_dai *child; |
|---|
| 144 | + unsigned int *channel_maps; |
|---|
| 113 | 145 | int ret = 0, i = 0; |
|---|
| 114 | 146 | |
|---|
| 147 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 148 | + |
|---|
| 115 | 149 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 150 | + if (!channel_maps[i]) |
|---|
| 151 | + continue; |
|---|
| 152 | + |
|---|
| 116 | 153 | child = mdais->dais[i].dai; |
|---|
| 117 | 154 | if (child->driver->ops && child->driver->ops->startup) { |
|---|
| 118 | 155 | ret = child->driver->ops->startup(substream, child); |
|---|
| .. | .. |
|---|
| 129 | 166 | { |
|---|
| 130 | 167 | struct rk_mdais_dev *mdais = to_info(dai); |
|---|
| 131 | 168 | struct snd_soc_dai *child; |
|---|
| 169 | + unsigned int *channel_maps; |
|---|
| 132 | 170 | int i = 0; |
|---|
| 133 | 171 | |
|---|
| 172 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 173 | + |
|---|
| 134 | 174 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 175 | + if (!channel_maps[i]) |
|---|
| 176 | + continue; |
|---|
| 177 | + |
|---|
| 135 | 178 | child = mdais->dais[i].dai; |
|---|
| 136 | 179 | if (child->driver->ops && child->driver->ops->shutdown) { |
|---|
| 137 | 180 | child->driver->ops->shutdown(substream, child); |
|---|
| .. | .. |
|---|
| 144 | 187 | { |
|---|
| 145 | 188 | struct rk_mdais_dev *mdais = to_info(dai); |
|---|
| 146 | 189 | struct snd_soc_dai *child; |
|---|
| 190 | + unsigned int *channel_maps; |
|---|
| 147 | 191 | int ret = 0, i = 0; |
|---|
| 148 | 192 | |
|---|
| 193 | + channel_maps = mdais_channel_maps(mdais, substream); |
|---|
| 194 | + |
|---|
| 149 | 195 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 196 | + if (!channel_maps[i]) |
|---|
| 197 | + continue; |
|---|
| 198 | + |
|---|
| 150 | 199 | child = mdais->dais[i].dai; |
|---|
| 151 | 200 | if (child->driver->ops && child->driver->ops->prepare) { |
|---|
| 152 | 201 | ret = child->driver->ops->prepare(substream, child); |
|---|
| .. | .. |
|---|
| 220 | 269 | static int rockchip_mdais_dai_probe(struct snd_soc_dai *dai) |
|---|
| 221 | 270 | { |
|---|
| 222 | 271 | struct rk_mdais_dev *mdais = to_info(dai); |
|---|
| 272 | + struct snd_soc_component *comp; |
|---|
| 223 | 273 | struct snd_soc_dai *child; |
|---|
| 274 | + const char *str; |
|---|
| 224 | 275 | int ret, i = 0; |
|---|
| 225 | 276 | |
|---|
| 226 | 277 | for (i = 0; i < mdais->num_dais; i++) { |
|---|
| 227 | 278 | child = mdais->dais[i].dai; |
|---|
| 279 | + comp = child->component; |
|---|
| 228 | 280 | if (!child->probed && child->driver->probe) { |
|---|
| 229 | | - child->component->card = dai->component->card; |
|---|
| 281 | + if (!comp->name_prefix) { |
|---|
| 282 | + ret = device_property_read_string(child->dev, |
|---|
| 283 | + SOUND_NAME_PREFIX, &str); |
|---|
| 284 | + if (!ret) |
|---|
| 285 | + comp->name_prefix = str; |
|---|
| 286 | + } |
|---|
| 287 | + |
|---|
| 288 | + comp->card = dai->component->card; |
|---|
| 230 | 289 | ret = child->driver->probe(child); |
|---|
| 231 | 290 | if (ret < 0) { |
|---|
| 232 | 291 | dev_err(child->dev, |
|---|
| 233 | | - "ASoC: failed to probe DAI %s: %d\n", |
|---|
| 292 | + "Failed to probe DAI %s: %d\n", |
|---|
| 234 | 293 | child->name, ret); |
|---|
| 235 | 294 | return ret; |
|---|
| 236 | 295 | } |
|---|
| 296 | + |
|---|
| 297 | + ret = snd_soc_add_component_controls(comp, |
|---|
| 298 | + comp->driver->controls, |
|---|
| 299 | + comp->driver->num_controls); |
|---|
| 300 | + if (ret) |
|---|
| 301 | + dev_err(dai->dev, "%s: Failed to add controls, should add '%s' in DT\n", |
|---|
| 302 | + dev_name(child->dev), SOUND_NAME_PREFIX); |
|---|
| 303 | + |
|---|
| 237 | 304 | dai->probed = 1; |
|---|
| 238 | 305 | } |
|---|
| 239 | 306 | } |
|---|
| .. | .. |
|---|
| 243 | 310 | |
|---|
| 244 | 311 | static const struct snd_soc_dai_ops rockchip_mdais_dai_ops = { |
|---|
| 245 | 312 | .hw_params = rockchip_mdais_hw_params, |
|---|
| 313 | + .hw_free = rockchip_mdais_hw_free, |
|---|
| 246 | 314 | .set_sysclk = rockchip_mdais_set_sysclk, |
|---|
| 247 | 315 | .set_fmt = rockchip_mdais_set_fmt, |
|---|
| 248 | 316 | .set_tdm_slot = rockchip_mdais_tdm_slot, |
|---|
| .. | .. |
|---|
| 383 | 451 | .probe = rockchip_mdais_dai_probe, |
|---|
| 384 | 452 | .playback = { |
|---|
| 385 | 453 | .stream_name = "Playback", |
|---|
| 386 | | - .channels_min = 2, |
|---|
| 387 | | - .channels_max = 32, |
|---|
| 388 | | - .rates = SNDRV_PCM_RATE_8000_192000, |
|---|
| 454 | + .channels_min = 1, |
|---|
| 455 | + .channels_max = 512, |
|---|
| 456 | + .rates = SNDRV_PCM_RATE_8000_384000, |
|---|
| 389 | 457 | .formats = (SNDRV_PCM_FMTBIT_S8 | |
|---|
| 390 | 458 | SNDRV_PCM_FMTBIT_S16_LE | |
|---|
| 391 | 459 | SNDRV_PCM_FMTBIT_S20_3LE | |
|---|
| .. | .. |
|---|
| 394 | 462 | }, |
|---|
| 395 | 463 | .capture = { |
|---|
| 396 | 464 | .stream_name = "Capture", |
|---|
| 397 | | - .channels_min = 2, |
|---|
| 398 | | - .channels_max = 32, |
|---|
| 399 | | - .rates = SNDRV_PCM_RATE_8000_192000, |
|---|
| 465 | + .channels_min = 1, |
|---|
| 466 | + .channels_max = 512, |
|---|
| 467 | + .rates = SNDRV_PCM_RATE_8000_384000, |
|---|
| 400 | 468 | .formats = (SNDRV_PCM_FMTBIT_S8 | |
|---|
| 401 | 469 | SNDRV_PCM_FMTBIT_S16_LE | |
|---|
| 402 | 470 | SNDRV_PCM_FMTBIT_S20_3LE | |
|---|