25 #include <linux/module.h>
30 #include <linux/bitops.h>
33 #include <linux/ctype.h>
34 #include <linux/slab.h>
45 #define CREATE_TRACE_POINTS
52 #ifdef CONFIG_DEBUG_FS
53 struct dentry *snd_soc_debugfs_root;
67 static int pmdown_time = 5000;
73 static int min_bytes_needed(
unsigned long val)
78 for (i = (
sizeof val * 8) - 1; i >= 0; --
i, ++
c)
81 c = (
sizeof val * 8) - c;
92 unsigned int reg,
char *
buf,
size_t len)
94 int wordsize = min_bytes_needed(codec->
driver->reg_cache_size) * 2;
95 int regsize = codec->
driver->reg_word_size * 2;
98 char regbuf[regsize + 1];
105 if (wordsize + regsize + 2 + 1 != len)
110 memset(regbuf,
'X', regsize);
111 regbuf[regsize] =
'\0';
113 snprintf(regbuf, regsize + 1,
"%.*x", regsize, ret);
117 snprintf(tmpbuf, len + 1,
"%.*x: %s\n", wordsize, reg, regbuf);
129 int wordsize, regsize;
134 wordsize = min_bytes_needed(codec->
driver->reg_cache_size) * 2;
135 regsize = codec->
driver->reg_word_size * 2;
137 len = wordsize + regsize + 2 + 1;
139 if (!codec->
driver->reg_cache_size)
142 if (codec->
driver->reg_cache_step)
143 step = codec->
driver->reg_cache_step;
145 for (i = 0; i < codec->
driver->reg_cache_size; i +=
step) {
148 if (codec->
driver->display_register) {
149 count += codec->
driver->display_register(codec, buf + count,
155 if (total + len >= count - 1)
157 format_register_str(codec, i, buf + total, len);
164 total =
min(total, count - 1);
189 const char *buf,
size_t count)
203 #ifdef CONFIG_DEBUG_FS
204 static ssize_t codec_reg_read_file(
struct file *
file,
char __user *user_buf,
205 size_t count, loff_t *ppos)
211 if (*ppos < 0 || !count)
218 ret = soc_codec_reg_show(codec, buf, count, *ppos);
231 static ssize_t codec_reg_write_file(
struct file *file,
232 const char __user *user_buf,
size_t count, loff_t *ppos)
240 buf_size =
min(count, (
sizeof(buf)-1));
245 while (*start ==
' ')
248 while (*start ==
' ')
262 .read = codec_reg_read_file,
263 .write = codec_reg_write_file,
267 static void soc_init_codec_debugfs(
struct snd_soc_codec *codec)
269 struct dentry *debugfs_card_root = codec->
card->debugfs_card_root;
273 if (!codec->debugfs_codec_root) {
274 dev_warn(codec->
dev,
"Failed to create codec debugfs directory\n");
284 codec->debugfs_codec_root,
285 codec, &codec_reg_fops);
286 if (!codec->debugfs_reg)
287 dev_warn(codec->
dev,
"Failed to create codec register debugfs file\n");
292 static void soc_cleanup_codec_debugfs(
struct snd_soc_codec *codec)
299 struct dentry *debugfs_card_root = platform->
card->debugfs_card_root;
303 if (!platform->debugfs_platform_root) {
305 "Failed to create platform debugfs directory\n");
310 platform->debugfs_platform_root);
318 static ssize_t codec_list_read_file(
struct file *file,
char __user *user_buf,
319 size_t count, loff_t *ppos)
348 .
read = codec_list_read_file,
352 static ssize_t dai_list_read_file(
struct file *file,
char __user *user_buf,
353 size_t count, loff_t *ppos)
380 .
read = dai_list_read_file,
384 static ssize_t platform_list_read_file(
struct file *file,
385 char __user *user_buf,
386 size_t count, loff_t *ppos)
414 .
read = platform_list_read_file,
421 snd_soc_debugfs_root);
422 if (!card->debugfs_card_root) {
424 "ASoC: Failed to create card debugfs directory\n");
429 card->debugfs_card_root,
431 if (!card->debugfs_pop_time)
433 "Failed to create pop time debugfs file\n");
436 static void soc_cleanup_card_debugfs(
struct snd_soc_card *card)
443 static inline void soc_init_codec_debugfs(
struct snd_soc_codec *codec)
447 static inline void soc_cleanup_codec_debugfs(
struct snd_soc_codec *codec)
451 static inline void soc_init_platform_debugfs(
struct snd_soc_platform *platform)
455 static inline void soc_cleanup_platform_debugfs(
struct snd_soc_platform *platform)
459 static inline void soc_init_card_debugfs(
struct snd_soc_card *card)
463 static inline void soc_cleanup_card_debugfs(
struct snd_soc_card *card)
469 const char *dai_link,
int stream)
474 if (card->
rtd[i].dai_link->no_pcm &&
475 !
strcmp(card->
rtd[i].dai_link->name, dai_link))
476 return card->
rtd[
i].pcm->streams[
stream].substream;
478 dev_dbg(card->
dev,
"failed to find dai link %s\n", dai_link);
489 if (!
strcmp(card->
rtd[i].dai_link->name, dai_link))
490 return &card->
rtd[
i];
492 dev_dbg(card->
dev,
"failed to find rtd %s\n", dai_link);
497 #ifdef CONFIG_SND_SOC_AC97_BUS
499 static int soc_ac97_dev_unregister(
struct snd_soc_codec *codec)
501 if (codec->
ac97->dev.bus)
507 static void soc_ac97_device_release(
struct device *dev){}
510 static int soc_ac97_dev_register(
struct snd_soc_codec *codec)
515 codec->
ac97->dev.parent = codec->
card->dev;
516 codec->
ac97->dev.release = soc_ac97_device_release;
519 codec->
card->snd_card->number, 0, codec->
name);
530 #ifdef CONFIG_PM_SLEEP
555 for (i = 0; i < card->
num_rtd; i++) {
559 if (card->
rtd[i].dai_link->ignore_suspend)
563 drv->
ops->digital_mute(dai, 1);
567 for (i = 0; i < card->
num_rtd; i++) {
568 if (card->
rtd[i].dai_link->ignore_suspend)
571 snd_pcm_suspend_all(card->
rtd[i].pcm);
577 for (i = 0; i < card->
num_rtd; i++) {
581 if (card->
rtd[i].dai_link->ignore_suspend)
584 if (cpu_dai->
driver->suspend && !cpu_dai->
driver->ac97_control)
585 cpu_dai->
driver->suspend(cpu_dai);
587 platform->
driver->suspend(cpu_dai);
593 for (i = 0; i < card->
num_rtd; i++) {
595 card->
rtd[
i].codec->dapm.suspend_bias_level = card->
rtd[
i].codec->dapm.bias_level;
598 for (i = 0; i < card->
num_rtd; i++) {
600 if (card->
rtd[i].dai_link->ignore_suspend)
621 switch (codec->
dapm.bias_level) {
629 if (codec->
dapm.idle_bias_off) {
631 "idle_bias_off CODEC on over suspend\n");
635 codec->
driver->suspend(codec);
642 dev_dbg(codec->
dev,
"CODEC is on over suspend\n");
648 for (i = 0; i < card->
num_rtd; i++) {
651 if (card->
rtd[i].dai_link->ignore_suspend)
654 if (cpu_dai->
driver->suspend && cpu_dai->
driver->ac97_control)
655 cpu_dai->
driver->suspend(cpu_dai);
688 for (i = 0; i < card->
num_rtd; i++) {
691 if (card->
rtd[i].dai_link->ignore_suspend)
694 if (cpu_dai->
driver->resume && cpu_dai->
driver->ac97_control)
695 cpu_dai->
driver->resume(cpu_dai);
704 switch (codec->
dapm.bias_level) {
707 codec->
driver->resume(codec);
711 dev_dbg(codec->
dev,
"CODEC was on over suspend\n");
717 for (i = 0; i < card->
num_rtd; i++) {
719 if (card->
rtd[i].dai_link->ignore_suspend)
732 for (i = 0; i < card->
num_rtd; i++) {
736 if (card->
rtd[i].dai_link->ignore_suspend)
740 drv->
ops->digital_mute(dai, 0);
743 for (i = 0; i < card->
num_rtd; i++) {
747 if (card->
rtd[i].dai_link->ignore_suspend)
750 if (cpu_dai->
driver->resume && !cpu_dai->
driver->ac97_control)
751 cpu_dai->
driver->resume(cpu_dai);
753 platform->
driver->resume(cpu_dai);
761 dev_dbg(card->
dev,
"resume work completed\n");
775 int i, ac97_control = 0;
788 for (i = 0; i < card->
num_rtd; i++) {
790 ac97_control |= cpu_dai->
driver->ac97_control;
793 dev_dbg(dev,
"Resuming AC97 immediately\n");
796 dev_dbg(dev,
"Scheduling resume work\n");
798 dev_err(dev,
"resume work item may be lost\n");
805 #define snd_soc_suspend NULL
806 #define snd_soc_resume NULL
812 static int soc_bind_dai_link(
struct snd_soc_card *card,
int num)
819 const char *platform_name;
821 dev_dbg(card->
dev,
"binding %s at idx %d\n", dai_link->
name, num);
839 dev_err(card->
dev,
"CPU DAI %s not registered\n",
861 if (codec->
dev == codec_dai->
dev &&
870 dev_err(card->
dev,
"CODEC DAI %s not registered\n",
877 dev_err(card->
dev,
"CODEC %s not registered\n",
885 platform_name =
"snd-soc-dummy";
890 if (platform->
dev->of_node !=
901 dev_err(card->
dev,
"platform %s not registered\n",
915 if (platform->
driver->remove) {
916 ret = platform->
driver->remove(platform);
918 pr_err(
"asoc: failed to remove %s: %d\n",
919 platform->
name, ret);
925 soc_cleanup_platform_debugfs(platform);
928 module_put(platform->
dev->driver->owner);
937 if (codec->
driver->remove) {
938 err = codec->
driver->remove(codec);
941 "asoc: failed to remove %s: %d\n",
948 soc_cleanup_codec_debugfs(codec);
951 module_put(codec->
dev->driver->owner);
969 if (codec_dai && codec_dai->
probed &&
970 codec_dai->
driver->remove_order == order) {
971 if (codec_dai->
driver->remove) {
972 err = codec_dai->
driver->remove(codec_dai);
974 pr_err(
"asoc: failed to remove %s: %d\n",
975 codec_dai->
name, err);
982 if (cpu_dai && cpu_dai->
probed &&
983 cpu_dai->
driver->remove_order == order) {
984 if (cpu_dai->
driver->remove) {
985 err = cpu_dai->
driver->remove(cpu_dai);
987 pr_err(
"asoc: failed to remove %s: %d\n",
993 if (!cpu_dai->
codec) {
995 module_put(cpu_dai->
dev->driver->owner);
1000 static void soc_remove_link_components(
struct snd_soc_card *card,
int num,
1010 if (platform && platform->
probed &&
1011 platform->
driver->remove_order == order) {
1012 soc_remove_platform(platform);
1017 codec = codec_dai->
codec;
1018 if (codec && codec->
probed &&
1019 codec->
driver->remove_order == order)
1020 soc_remove_codec(codec);
1025 codec = cpu_dai->
codec;
1026 if (codec && codec->
probed &&
1027 codec->
driver->remove_order == order)
1028 soc_remove_codec(codec);
1032 static void soc_remove_dai_links(
struct snd_soc_card *card)
1038 for (dai = 0; dai < card->
num_rtd; dai++)
1039 soc_remove_link_dais(card, dai, order);
1044 for (dai = 0; dai < card->
num_rtd; dai++)
1045 soc_remove_link_components(card, dai, order);
1051 static void soc_set_name_prefix(
struct snd_soc_card *card,
1077 soc_set_name_prefix(card, codec);
1079 if (!try_module_get(codec->
dev->driver->owner))
1082 soc_init_codec_debugfs(codec);
1090 if (dai->
dev != codec->
dev)
1098 if (driver->
probe) {
1099 ret = driver->
probe(codec);
1102 "asoc: failed to probe CODEC %s: %d\n",
1127 soc_cleanup_codec_debugfs(codec);
1128 module_put(codec->
dev->driver->owner);
1133 static int soc_probe_platform(
struct snd_soc_card *card,
1143 if (!try_module_get(platform->
dev->driver->owner))
1146 soc_init_platform_debugfs(platform);
1154 if (dai->
dev != platform->
dev)
1160 platform->
dapm.idle_bias_off = 1;
1162 if (driver->
probe) {
1163 ret = driver->
probe(platform);
1166 "asoc: failed to probe platform %s: %d\n",
1167 platform->
name, ret);
1187 soc_cleanup_platform_debugfs(platform);
1188 module_put(platform->
dev->driver->owner);
1193 static void rtd_release(
struct device *dev)
1198 static int soc_post_component_init(
struct snd_soc_card *card,
1200 int num,
int dailess)
1210 rtd = &card->
rtd[num];
1211 name = dai_link->
name;
1213 aux_dev = &card->
aux_dev[num];
1215 name = aux_dev->
name;
1227 if (!dailess && dai_link->
init)
1228 ret = dai_link->
init(rtd);
1229 else if (dailess && aux_dev->
init)
1232 dev_err(card->
dev,
"asoc: failed to init %s: %d\n", name, ret);
1244 rtd->
dev->parent = card->
dev;
1245 rtd->
dev->release = rtd_release;
1256 "asoc: failed to register runtime device: %d\n", ret);
1265 "asoc: failed to add codec dapm sysfs entries: %d\n",
1272 "asoc: failed to add codec sysfs files: %d\n", ret);
1274 #ifdef CONFIG_DEBUG_FS
1276 if (!dailess && !dai_link->
dynamic)
1281 dev_err(rtd->
dev,
"asoc: failed to add dpcm sysfs entries: %d\n", ret);
1288 static int soc_probe_link_components(
struct snd_soc_card *card,
int num,
1298 if (cpu_dai->
codec &&
1299 !cpu_dai->
codec->probed &&
1300 cpu_dai->
codec->driver->probe_order == order) {
1301 ret = soc_probe_codec(card, cpu_dai->
codec);
1307 if (!codec_dai->
codec->probed &&
1308 codec_dai->
codec->driver->probe_order == order) {
1309 ret = soc_probe_codec(card, codec_dai->
codec);
1316 platform->
driver->probe_order == order) {
1317 ret = soc_probe_platform(card, platform);
1325 static int soc_probe_link_dais(
struct snd_soc_card *card,
int num,
int order)
1336 dev_dbg(card->
dev,
"probe %s dai link %d late %d\n",
1337 card->
name, num, order);
1349 cpu_dai->
driver->probe_order == order) {
1350 if (!cpu_dai->
codec) {
1352 if (!try_module_get(cpu_dai->
dev->driver->owner))
1359 if (cpu_dai->
driver->probe) {
1360 ret = cpu_dai->
driver->probe(cpu_dai);
1362 pr_err(
"asoc: failed to probe CPU DAI %s: %d\n",
1363 cpu_dai->
name, ret);
1364 module_put(cpu_dai->
dev->driver->owner);
1374 if (!codec_dai->
probed && codec_dai->
driver->probe_order == order) {
1375 if (codec_dai->
driver->probe) {
1376 ret = codec_dai->
driver->probe(codec_dai);
1378 pr_err(
"asoc: failed to probe CODEC DAI %s: %d\n",
1379 codec_dai->
name, ret);
1393 ret = soc_post_component_init(card, codec, num, 0);
1399 pr_warn(
"asoc: failed to add pmdown_time sysfs:%d\n", ret);
1401 if (cpu_dai->
driver->compress_dai) {
1405 pr_err(
"asoc: can't create compress %s\n",
1415 pr_err(
"asoc: can't create pcm %s :%d\n",
1423 if (play_w && capture_w) {
1427 dev_err(card->
dev,
"Can't link %s to %s: %d\n",
1428 play_w->
name, capture_w->
name, ret);
1435 if (play_w && capture_w) {
1439 dev_err(card->
dev,
"Can't link %s to %s: %d\n",
1440 play_w->
name, capture_w->
name, ret);
1448 if (rtd->
codec_dai->driver->ac97_control)
1449 snd_ac97_dev_add_pdata(codec->
ac97, rtd->
cpu_dai->ac97_pdata);
1454 #ifdef CONFIG_SND_SOC_AC97_BUS
1462 if (rtd->
codec_dai->driver->ac97_control && !rtd->
codec->ac97_registered) {
1471 if (!rtd->
codec->ac97_created)
1474 ret = soc_ac97_dev_register(rtd->
codec);
1476 pr_err(
"asoc: AC97 device register failed:%d\n", ret);
1480 rtd->
codec->ac97_registered = 1;
1485 static void soc_unregister_ac97_dai_link(
struct snd_soc_codec *codec)
1488 soc_ac97_dev_unregister(codec);
1494 static int soc_check_aux_dev(
struct snd_soc_card *card,
int num)
1510 static int soc_probe_aux_dev(
struct snd_soc_card *card,
int num)
1521 "asoc: codec already probed");
1533 ret = soc_probe_codec(card, codec);
1537 ret = soc_post_component_init(card, codec, num, 1);
1543 static void soc_remove_aux_dev(
struct snd_soc_card *card,
int num)
1555 if (codec && codec->
probed)
1556 soc_remove_codec(codec);
1559 static int snd_soc_init_codec_cache(
struct snd_soc_codec *codec,
1572 dev_err(codec->
dev,
"Failed to set cache compression type: %d\n",
1580 static int snd_soc_instantiate_card(
struct snd_soc_card *card)
1592 ret = soc_bind_dai_link(card, i);
1599 ret = soc_check_aux_dev(card, i);
1615 if (compress_type && compress_type
1620 ret = snd_soc_init_codec_cache(codec, compress_type);
1629 pr_err(
"asoc: can't create sound card for card %s: %d\n",
1640 #ifdef CONFIG_DEBUG_FS
1644 #ifdef CONFIG_PM_SLEEP
1655 ret = card->
probe(card);
1657 goto card_probe_error;
1664 ret = soc_probe_link_components(card, i, order);
1666 pr_err(
"asoc: failed to instantiate card %s: %d\n",
1677 ret = soc_probe_link_dais(card, i, order);
1679 pr_err(
"asoc: failed to instantiate card %s: %d\n",
1687 ret = soc_probe_aux_dev(card, i);
1689 pr_err(
"asoc: failed to add auxiliary devices %s: %d\n",
1691 goto probe_aux_dev_err;
1715 "Failed to set DAI format: %d\n",
1726 "Failed to set DAI format: %d\n",
1728 }
else if (dai_fmt) {
1751 "Failed to set DAI format: %d\n",
1763 switch (card->
snd_card->driver[i]) {
1778 dev_err(card->
dev,
"%s late_probe() failed: %d\n",
1780 goto probe_aux_dev_err;
1792 pr_err(
"asoc: failed to register soundcard for %s: %d\n",
1794 goto probe_aux_dev_err;
1797 #ifdef CONFIG_SND_SOC_AC97_BUS
1799 for (i = 0; i < card->
num_rtd; i++) {
1800 ret = soc_register_ac97_dai_link(&card->
rtd[i]);
1802 pr_err(
"asoc: failed to register AC97 %s: %d\n",
1805 soc_unregister_ac97_dai_link(card->
rtd[i].codec);
1806 goto probe_aux_dev_err;
1819 soc_remove_aux_dev(card, i);
1822 soc_remove_dai_links(card);
1839 struct snd_soc_card *card = platform_get_drvdata(pdev);
1849 "ASoC machine %s should use snd_soc_register_card()\n",
1858 static int soc_cleanup_card_resources(
struct snd_soc_card *card)
1863 for (i = 0; i < card->
num_rtd; i++) {
1870 soc_remove_aux_dev(card, i);
1873 soc_remove_dai_links(card);
1875 soc_cleanup_card_debugfs(card);
1891 struct snd_soc_card *card = platform_get_drvdata(pdev);
1907 for (i = 0; i < card->
num_rtd; i++) {
1931 .name =
"soc-audio",
1936 .remove = soc_remove,
1998 if (!platform->
driver->read) {
1999 dev_err(platform->
dev,
"platform has no read back\n");
2003 ret = platform->
driver->read(platform, reg);
2004 dev_dbg(platform->
dev,
"read %x => %x\n", reg, ret);
2005 trace_snd_soc_preg_read(platform, reg, ret);
2012 unsigned int reg,
unsigned int val)
2014 if (!platform->
driver->write) {
2015 dev_err(platform->
dev,
"platform has no write back\n");
2019 dev_dbg(platform->
dev,
"write %x = %x\n", reg, val);
2020 trace_snd_soc_preg_write(platform, reg, val);
2021 return platform->
driver->write(platform, reg, val);
2052 codec->
ac97->bus->ops = ops;
2053 codec->
ac97->num = num;
2075 #ifdef CONFIG_SND_SOC_AC97_BUS
2076 soc_unregister_ac97_dai_link(codec);
2090 ret = codec->
read(codec, reg);
2091 dev_dbg(codec->
dev,
"read %x => %x\n", reg, ret);
2092 trace_snd_soc_reg_read(codec, reg, ret);
2099 unsigned int reg,
unsigned int val)
2101 dev_dbg(codec->
dev,
"write %x = %x\n", reg, val);
2102 trace_snd_soc_reg_write(codec, reg, val);
2103 return codec->
write(codec, reg, val);
2108 unsigned int reg,
const void *
data,
size_t len)
2126 unsigned int mask,
unsigned int value)
2129 unsigned int old,
new;
2134 mask, value, &change);
2141 new = (old & ~mask) | (value & mask);
2142 change = old !=
new;
2166 unsigned short reg,
unsigned int mask,
2192 unsigned int mask,
unsigned int value)
2195 unsigned int old,
new;
2198 new = (old & ~mask) | value;
2199 change = old !=
new;
2216 runtime->
hw.info = hw->
info;
2240 void *
data,
const char *long_name,
2248 memcpy(&
template, _template,
sizeof(
template));
2252 long_name =
template.name;
2260 snprintf(name, name_len,
"%s %s", prefix, long_name);
2262 template.name =
name;
2264 template.name = long_name;
2275 static int snd_soc_add_controls(
struct snd_card *card,
struct device *dev,
2281 for (i = 0; i < num_controls; i++) {
2284 control->
name, prefix));
2286 dev_err(dev,
"Failed to add %s: %d\n", control->
name, err);
2310 return snd_soc_add_controls(card, codec->
dev, controls, num_controls,
2330 return snd_soc_add_controls(card, platform->
dev, controls, num_controls,
2350 return snd_soc_add_controls(card, soc_card->
dev, controls, num_controls,
2370 return snd_soc_add_controls(card, dai->
dev, controls, num_controls,
2419 ucontrol->
value.enumerated.item[0]
2422 ucontrol->
value.enumerated.item[1] =
2446 if (ucontrol->
value.enumerated.item[0] > e->
max - 1)
2448 val = ucontrol->
value.enumerated.item[0] << e->
shift_l;
2451 if (ucontrol->
value.enumerated.item[1] > e->
max - 1)
2453 val |= ucontrol->
value.enumerated.item[1] << e->
shift_r;
2478 unsigned int reg_val, val, mux;
2482 for (mux = 0; mux < e->
max; mux++) {
2483 if (val == e->
values[mux])
2486 ucontrol->
value.enumerated.item[0] = mux;
2489 for (mux = 0; mux < e->
max; mux++) {
2490 if (val == e->
values[mux])
2493 ucontrol->
value.enumerated.item[1] = mux;
2520 if (ucontrol->
value.enumerated.item[0] > e->
max - 1)
2525 if (ucontrol->
value.enumerated.item[1] > e->
max - 1)
2576 if (max == 1 && !
strstr(kcontrol->
id.name,
" Volume"))
2614 uinfo->
count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2637 unsigned int reg = mc->
reg;
2642 unsigned int mask = (1 << fls(max)) - 1;
2645 ucontrol->
value.integer.value[0] =
2648 ucontrol->
value.integer.value[0] =
2649 max - ucontrol->
value.integer.value[0];
2651 if (snd_soc_volsw_is_stereo(mc)) {
2653 ucontrol->
value.integer.value[1] =
2656 ucontrol->
value.integer.value[1] =
2659 ucontrol->
value.integer.value[1] =
2660 max - ucontrol->
value.integer.value[1];
2683 unsigned int reg = mc->
reg;
2688 unsigned int mask = (1 << fls(max)) - 1;
2692 unsigned int val2 = 0;
2693 unsigned int val, val_mask;
2695 val = (ucontrol->
value.integer.value[0] &
mask);
2698 val_mask = mask <<
shift;
2700 if (snd_soc_volsw_is_stereo(mc)) {
2701 val2 = (ucontrol->
value.integer.value[1] &
mask);
2705 val_mask |= mask <<
rshift;
2708 val2 = val2 <<
shift;
2740 unsigned int reg = mc->
reg;
2748 ucontrol->
value.integer.value[0] =
2751 if (snd_soc_volsw_is_stereo(mc))
2752 ucontrol->
value.integer.value[1] =
2775 unsigned int reg = mc->
reg;
2783 unsigned short val, val_mask, val2 = 0;
2793 if (snd_soc_volsw_is_stereo(mc)) {
2795 val2 = (ucontrol->
value.integer.value[1] +
min) &
mask;
2849 unsigned int reg = mc->
reg;
2853 ucontrol->
value.integer.value[0] =
2854 ((
signed char)(val & 0xff))-min;
2855 ucontrol->
value.integer.value[1] =
2856 ((
signed char)((val >> 8) & 0xff))-
min;
2876 unsigned int reg = mc->
reg;
2880 val = (ucontrol->
value.integer.value[0]+
min) & 0xff;
2881 val |= ((ucontrol->
value.integer.value[1]+
min) & 0xff) << 8;
2933 unsigned int reg = mc->
reg;
2937 unsigned int mask = (1 << fls(max)) - 1;
2939 unsigned int val, val_mask;
2941 val = ((ucontrol->
value.integer.value[0] +
min) & mask);
2944 val_mask = mask <<
shift;
2966 unsigned int reg = mc->
reg;
2970 unsigned int mask = (1 << fls(max)) - 1;
2973 ucontrol->
value.integer.value[0] =
2976 ucontrol->
value.integer.value[0] =
2977 max - ucontrol->
value.integer.value[0];
2978 ucontrol->
value.integer.value[0] =
2979 ucontrol->
value.integer.value[0] -
min;
2995 const char *name,
int max)
3008 if (!
strncmp(kctl->
id.name, name,
sizeof(kctl->
id.name))) {
3015 if (max <= mc->max) {
3046 ucontrol->
value.bytes.data,
3052 if (ret == 0 && params->
mask) {
3055 ucontrol->
value.bytes.data[0] &= ~params->
mask;
3058 ((
u16 *)(&ucontrol->
value.bytes.data))[0]
3062 ((
u32 *)(&ucontrol->
value.bytes.data))[0]
3086 data = ucontrol->
value.bytes.data;
3099 val &= params->
mask;
3107 ((
u8 *)data)[0] &= ~params->
mask;
3108 ((
u8 *)data)[0] |=
val;
3180 unsigned int regwmask = (1<<regwshift)-1;
3191 val |= regval << (regwshift*(regcount-i-1));
3194 if (min < 0 && val > max)
3198 ucontrol->
value.integer.value[0] =
val;
3226 unsigned int regwmask = (1<<regwshift)-1;
3230 long val = ucontrol->
value.integer.value[0];
3238 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3239 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3265 unsigned int reg = mc->
reg;
3271 if (shift != 0 && val != 0)
3273 ucontrol->
value.enumerated.item[0] = val ^
invert;
3295 unsigned int reg = mc->
reg;
3299 unsigned int strobe = ucontrol->
value.enumerated.item[0] != 0;
3300 unsigned int val1 = (strobe ^
invert) ? mask : 0;
3301 unsigned int val2 = (strobe ^
invert) ? 0 : mask;
3323 unsigned int freq,
int dir)
3326 return dai->
driver->ops->set_sysclk(dai, clk_id, freq, dir);
3327 else if (dai->
codec && dai->
codec->driver->set_sysclk)
3328 return dai->
codec->driver->set_sysclk(dai->
codec, clk_id, 0,
3348 if (codec->
driver->set_sysclk)
3349 return codec->
driver->set_sysclk(codec, clk_id, source,
3367 int div_id,
int div)
3370 return dai->
driver->ops->set_clkdiv(dai, div_id, div);
3387 unsigned int freq_in,
unsigned int freq_out)
3390 return dai->
driver->ops->set_pll(dai, pll_id, source,
3392 else if (dai->
codec && dai->
codec->driver->set_pll)
3393 return dai->
codec->driver->set_pll(dai->
codec, pll_id, source,
3411 unsigned int freq_in,
unsigned int freq_out)
3413 if (codec->
driver->set_pll)
3414 return codec->
driver->set_pll(codec, pll_id, source,
3434 return dai->
driver->ops->set_fmt(dai, fmt);
3453 return dai->
driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
3473 unsigned int tx_num,
unsigned int *tx_slot,
3474 unsigned int rx_num,
unsigned int *rx_slot)
3477 return dai->
driver->ops->set_channel_map(dai, tx_num, tx_slot,
3494 return dai->
driver->ops->set_tristate(dai, tristate);
3510 return dai->
driver->ops->digital_mute(dai, mute);
3526 if (!card->
name || !card->
dev)
3538 "Neither/both codec name/of_node are set for %s\n",
3544 dev_err(card->
dev,
"codec_dai_name not set for %s\n",
3555 "Both platform name/of_node are set for %s\n", link->
name);
3566 "Neither/both cpu name/of_node are set for %s\n",
3577 "Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3585 snd_soc_initialize_card_lists(card);
3587 soc_init_card_debugfs(card);
3601 INIT_LIST_HEAD(&card->
list);
3607 ret = snd_soc_instantiate_card(card);
3609 soc_cleanup_card_debugfs(card);
3624 soc_cleanup_card_resources(card);
3635 static char *fmt_single_name(
struct device *dev,
int *
id)
3640 if (dev_name(dev) ==
NULL)
3658 if (
sscanf(name,
"%x-%x", &id1, &id2) == 2) {
3662 *
id = ((id1 & 0xffff) << 16) +
id2;
3678 static inline char *fmt_multiple_name(
struct device *dev,
3682 pr_err(
"asoc: error - multiple DAI %s registered with no name\n",
3701 dev_dbg(dev,
"dai register %s\n", dev_name(dev));
3708 dai->
name = fmt_single_name(dev, &dai->
id);
3718 dai->
driver->ops = &null_dai_ops;
3723 if (codec->
dev == dev) {
3724 dev_dbg(dev,
"Mapped DAI %s to CODEC %s\n",
3732 dai->
dapm.idle_bias_off = 1;
3734 list_add(&dai->
list, &dai_list);
3754 if (dev == dai->
dev)
3783 dev_dbg(dev,
"dai register %s #%Zu\n", dev_name(dev), count);
3785 for (i = 0; i <
count; i++) {
3794 dai->
name = fmt_multiple_name(dev, &dai_drv[i]);
3809 dai->
driver->ops = &null_dai_ops;
3814 if (codec->
dev == dev) {
3815 dev_dbg(dev,
"Mapped DAI %s to CODEC %s\n",
3823 dai->
dapm.idle_bias_off = 1;
3825 list_add(&dai->
list, &dai_list);
3835 for (i--; i >= 0; i--)
3852 for (i = 0; i <
count; i++)
3867 dev_dbg(dev,
"platform register %s\n", dev_name(dev));
3870 if (platform ==
NULL)
3874 platform->
name = fmt_single_name(dev, &platform->
id);
3881 platform->
driver = platform_drv;
3883 platform->
dapm.platform = platform;
3888 list_add(&platform->
list, &platform_list);
3891 pr_debug(
"Registered platform '%s'\n", platform->
name);
3907 if (dev == platform->
dev)
3917 pr_debug(
"Unregistered platform '%s'\n", platform->
name);
3923 static u64 codec_format_map[] = {
3951 for (i = 0; i <
ARRAY_SIZE(codec_format_map); i++)
3952 if (stream->
formats & codec_format_map[i])
3953 stream->
formats |= codec_format_map[
i];
3970 dev_dbg(dev,
"codec register %s\n", dev_name(dev));
3977 codec->
name = fmt_single_name(dev, &codec->
id);
4000 codec->
driver = codec_drv;
4033 for (i = 0; i <
num_dai; i++) {
4034 fixup_codec_formats(&dai_drv[i].playback);
4035 fixup_codec_formats(&dai_drv[i].capture);
4046 dev_err(codec->
dev,
"Failed to regster DAIs: %d\n",
4071 if (dev == codec->
dev)
4078 for (i = 0; i < codec->
num_dai; i++)
4096 const char *propname)
4107 if (ret < 0 && ret != -
EINVAL) {
4109 "Property '%s' could not be read: %d\n",
4119 const char *propname)
4127 if (num_routes < 0 || num_routes & 1) {
4129 "Property '%s' does not exist or its length is not even\n",
4136 "Property '%s's length is zero\n",
4145 "Could not allocate DAPM route table\n");
4149 for (i = 0; i < num_routes; i++) {
4151 2 * i, &routes[i].
sink);
4154 "Property '%s' index %d could not be read: %d\n",
4155 propname, 2 * i, ret);
4160 (2 * i) + 1, &routes[i].
source);
4163 "Property '%s' index %d could not be read: %d\n",
4164 propname, (2 * i) + 1, ret);
4177 static int __init snd_soc_init(
void)
4179 #ifdef CONFIG_DEBUG_FS
4181 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
4182 pr_warn(
"ASoC: Failed to create debugfs directory\n");
4183 snd_soc_debugfs_root =
NULL;
4188 pr_warn(
"ASoC: Failed to create CODEC list debugfs file\n");
4192 pr_warn(
"ASoC: Failed to create DAI list debugfs file\n");
4195 &platform_list_fops))
4196 pr_warn(
"ASoC: Failed to create platform list debugfs file\n");
4205 static void __exit snd_soc_exit(
void)
4209 #ifdef CONFIG_DEBUG_FS