1db2a4165SFrank Mandarino /* 2db2a4165SFrank Mandarino * soc-core.c -- ALSA SoC Audio Layer 3db2a4165SFrank Mandarino * 4db2a4165SFrank Mandarino * Copyright 2005 Wolfson Microelectronics PLC. 50664d888SLiam Girdwood * Copyright 2005 Openedhand Ltd. 6f0fba2adSLiam Girdwood * Copyright (C) 2010 Slimlogic Ltd. 7f0fba2adSLiam Girdwood * Copyright (C) 2010 Texas Instruments Inc. 80664d888SLiam Girdwood * 9d331124dSLiam Girdwood * Author: Liam Girdwood <lrg@slimlogic.co.uk> 100664d888SLiam Girdwood * with code, comments and ideas from :- 110664d888SLiam Girdwood * Richard Purdie <richard@openedhand.com> 12db2a4165SFrank Mandarino * 13db2a4165SFrank Mandarino * This program is free software; you can redistribute it and/or modify it 14db2a4165SFrank Mandarino * under the terms of the GNU General Public License as published by the 15db2a4165SFrank Mandarino * Free Software Foundation; either version 2 of the License, or (at your 16db2a4165SFrank Mandarino * option) any later version. 17db2a4165SFrank Mandarino * 18db2a4165SFrank Mandarino * TODO: 19db2a4165SFrank Mandarino * o Add hw rules to enforce rates, etc. 20db2a4165SFrank Mandarino * o More testing with other codecs/machines. 21db2a4165SFrank Mandarino * o Add more codecs and platforms to ensure good API coverage. 22db2a4165SFrank Mandarino * o Support TDM on PCM and I2S 23db2a4165SFrank Mandarino */ 24db2a4165SFrank Mandarino 25db2a4165SFrank Mandarino #include <linux/module.h> 26db2a4165SFrank Mandarino #include <linux/moduleparam.h> 27db2a4165SFrank Mandarino #include <linux/init.h> 28db2a4165SFrank Mandarino #include <linux/delay.h> 29db2a4165SFrank Mandarino #include <linux/pm.h> 30db2a4165SFrank Mandarino #include <linux/bitops.h> 3112ef193dSTroy Kisky #include <linux/debugfs.h> 32db2a4165SFrank Mandarino #include <linux/platform_device.h> 33741a509fSMarkus Pargmann #include <linux/pinctrl/consumer.h> 34f0e8ed85SMark Brown #include <linux/ctype.h> 355a0e3ad6STejun Heo #include <linux/slab.h> 36bec4fa05SStephen Warren #include <linux/of.h> 37db2a4165SFrank Mandarino #include <sound/core.h> 383028eb8cSMark Brown #include <sound/jack.h> 39db2a4165SFrank Mandarino #include <sound/pcm.h> 40db2a4165SFrank Mandarino #include <sound/pcm_params.h> 41db2a4165SFrank Mandarino #include <sound/soc.h> 4201d7584cSLiam Girdwood #include <sound/soc-dpcm.h> 438a978234SLiam Girdwood #include <sound/soc-topology.h> 44db2a4165SFrank Mandarino #include <sound/initval.h> 45db2a4165SFrank Mandarino 46a8b1d34fSMark Brown #define CREATE_TRACE_POINTS 47a8b1d34fSMark Brown #include <trace/events/asoc.h> 48a8b1d34fSMark Brown 49f0fba2adSLiam Girdwood #define NAME_SIZE 32 50f0fba2adSLiam Girdwood 51384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 528a9dab1aSMark Brown struct dentry *snd_soc_debugfs_root; 538a9dab1aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); 54384c89e2SMark Brown #endif 55384c89e2SMark Brown 56c5af3a2eSMark Brown static DEFINE_MUTEX(client_mutex); 5712a48a8cSMark Brown static LIST_HEAD(platform_list); 580d0cf00aSMark Brown static LIST_HEAD(codec_list); 59030e79f6SKuninori Morimoto static LIST_HEAD(component_list); 60c5af3a2eSMark Brown 61db2a4165SFrank Mandarino /* 62db2a4165SFrank Mandarino * This is a timeout to do a DAPM powerdown after a stream is closed(). 63db2a4165SFrank Mandarino * It can be used to eliminate pops between different playback streams, e.g. 64db2a4165SFrank Mandarino * between two audio tracks. 65db2a4165SFrank Mandarino */ 66db2a4165SFrank Mandarino static int pmdown_time = 5000; 67db2a4165SFrank Mandarino module_param(pmdown_time, int, 0); 68db2a4165SFrank Mandarino MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 69db2a4165SFrank Mandarino 702bc9a81eSDimitris Papastamos /* returns the minimum number of bytes needed to represent 712bc9a81eSDimitris Papastamos * a particular given value */ 722bc9a81eSDimitris Papastamos static int min_bytes_needed(unsigned long val) 732bc9a81eSDimitris Papastamos { 742bc9a81eSDimitris Papastamos int c = 0; 752bc9a81eSDimitris Papastamos int i; 762bc9a81eSDimitris Papastamos 772bc9a81eSDimitris Papastamos for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) 782bc9a81eSDimitris Papastamos if (val & (1UL << i)) 792bc9a81eSDimitris Papastamos break; 802bc9a81eSDimitris Papastamos c = (sizeof val * 8) - c; 812bc9a81eSDimitris Papastamos if (!c || (c % 8)) 822bc9a81eSDimitris Papastamos c = (c + 8) / 8; 832bc9a81eSDimitris Papastamos else 842bc9a81eSDimitris Papastamos c /= 8; 852bc9a81eSDimitris Papastamos return c; 862bc9a81eSDimitris Papastamos } 872bc9a81eSDimitris Papastamos 8813fd179fSDimitris Papastamos /* fill buf which is 'len' bytes with a formatted 8913fd179fSDimitris Papastamos * string of the form 'reg: value\n' */ 9013fd179fSDimitris Papastamos static int format_register_str(struct snd_soc_codec *codec, 9113fd179fSDimitris Papastamos unsigned int reg, char *buf, size_t len) 922624d5faSMark Brown { 9300b317a4SStephen Warren int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 9400b317a4SStephen Warren int regsize = codec->driver->reg_word_size * 2; 9513fd179fSDimitris Papastamos int ret; 9613fd179fSDimitris Papastamos 9713fd179fSDimitris Papastamos /* +2 for ': ' and + 1 for '\n' */ 9813fd179fSDimitris Papastamos if (wordsize + regsize + 2 + 1 != len) 9913fd179fSDimitris Papastamos return -EINVAL; 10013fd179fSDimitris Papastamos 101d6b6c2caSTakashi Iwai sprintf(buf, "%.*x: ", wordsize, reg); 102d6b6c2caSTakashi Iwai buf += wordsize + 2; 103d6b6c2caSTakashi Iwai 10413fd179fSDimitris Papastamos ret = snd_soc_read(codec, reg); 105d6b6c2caSTakashi Iwai if (ret < 0) 106d6b6c2caSTakashi Iwai memset(buf, 'X', regsize); 107d6b6c2caSTakashi Iwai else 108d6b6c2caSTakashi Iwai sprintf(buf, "%.*x", regsize, ret); 109d6b6c2caSTakashi Iwai buf[regsize] = '\n'; 110d6b6c2caSTakashi Iwai /* no NUL-termination needed */ 11113fd179fSDimitris Papastamos return 0; 11213fd179fSDimitris Papastamos } 11313fd179fSDimitris Papastamos 11413fd179fSDimitris Papastamos /* codec register dump */ 11513fd179fSDimitris Papastamos static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, 11613fd179fSDimitris Papastamos size_t count, loff_t pos) 11713fd179fSDimitris Papastamos { 11813fd179fSDimitris Papastamos int i, step = 1; 1192bc9a81eSDimitris Papastamos int wordsize, regsize; 12013fd179fSDimitris Papastamos int len; 12113fd179fSDimitris Papastamos size_t total = 0; 12213fd179fSDimitris Papastamos loff_t p = 0; 1232bc9a81eSDimitris Papastamos 12400b317a4SStephen Warren wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 12500b317a4SStephen Warren regsize = codec->driver->reg_word_size * 2; 1262624d5faSMark Brown 12713fd179fSDimitris Papastamos len = wordsize + regsize + 2 + 1; 12813fd179fSDimitris Papastamos 129f0fba2adSLiam Girdwood if (!codec->driver->reg_cache_size) 1302624d5faSMark Brown return 0; 1312624d5faSMark Brown 132f0fba2adSLiam Girdwood if (codec->driver->reg_cache_step) 133f0fba2adSLiam Girdwood step = codec->driver->reg_cache_step; 1342624d5faSMark Brown 135f0fba2adSLiam Girdwood for (i = 0; i < codec->driver->reg_cache_size; i += step) { 13613fd179fSDimitris Papastamos /* only support larger than PAGE_SIZE bytes debugfs 13713fd179fSDimitris Papastamos * entries for the default case */ 13813fd179fSDimitris Papastamos if (p >= pos) { 13913fd179fSDimitris Papastamos if (total + len >= count - 1) 1402624d5faSMark Brown break; 14113fd179fSDimitris Papastamos format_register_str(codec, i, buf + total, len); 14213fd179fSDimitris Papastamos total += len; 14313fd179fSDimitris Papastamos } 14413fd179fSDimitris Papastamos p += len; 14513fd179fSDimitris Papastamos } 1462624d5faSMark Brown 14713fd179fSDimitris Papastamos total = min(total, count - 1); 1482624d5faSMark Brown 14913fd179fSDimitris Papastamos return total; 1502624d5faSMark Brown } 15113fd179fSDimitris Papastamos 1522624d5faSMark Brown static ssize_t codec_reg_show(struct device *dev, 1532624d5faSMark Brown struct device_attribute *attr, char *buf) 1542624d5faSMark Brown { 15536ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 156f0fba2adSLiam Girdwood 15713fd179fSDimitris Papastamos return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 1582624d5faSMark Brown } 1592624d5faSMark Brown 1602624d5faSMark Brown static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1612624d5faSMark Brown 162dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev, 163dbe21408SMark Brown struct device_attribute *attr, char *buf) 164dbe21408SMark Brown { 16536ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 166dbe21408SMark Brown 167f0fba2adSLiam Girdwood return sprintf(buf, "%ld\n", rtd->pmdown_time); 168dbe21408SMark Brown } 169dbe21408SMark Brown 170dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev, 171dbe21408SMark Brown struct device_attribute *attr, 172dbe21408SMark Brown const char *buf, size_t count) 173dbe21408SMark Brown { 17436ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 175c593b520SMark Brown int ret; 176dbe21408SMark Brown 177b785a492SJingoo Han ret = kstrtol(buf, 10, &rtd->pmdown_time); 178c593b520SMark Brown if (ret) 179c593b520SMark Brown return ret; 180dbe21408SMark Brown 181dbe21408SMark Brown return count; 182dbe21408SMark Brown } 183dbe21408SMark Brown 184dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 185dbe21408SMark Brown 186d29697dcSTakashi Iwai static struct attribute *soc_dev_attrs[] = { 187d29697dcSTakashi Iwai &dev_attr_codec_reg.attr, 188d29697dcSTakashi Iwai &dev_attr_pmdown_time.attr, 189d29697dcSTakashi Iwai NULL 190d29697dcSTakashi Iwai }; 191d29697dcSTakashi Iwai 192d29697dcSTakashi Iwai static umode_t soc_dev_attr_is_visible(struct kobject *kobj, 193d29697dcSTakashi Iwai struct attribute *attr, int idx) 194d29697dcSTakashi Iwai { 195d29697dcSTakashi Iwai struct device *dev = kobj_to_dev(kobj); 196d29697dcSTakashi Iwai struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 197d29697dcSTakashi Iwai 198d29697dcSTakashi Iwai if (attr == &dev_attr_pmdown_time.attr) 199d29697dcSTakashi Iwai return attr->mode; /* always visible */ 200d29697dcSTakashi Iwai return rtd->codec ? attr->mode : 0; /* enabled only with codec */ 201d29697dcSTakashi Iwai } 202d29697dcSTakashi Iwai 203d29697dcSTakashi Iwai static const struct attribute_group soc_dapm_dev_group = { 204d29697dcSTakashi Iwai .attrs = soc_dapm_dev_attrs, 205d29697dcSTakashi Iwai .is_visible = soc_dev_attr_is_visible, 206d29697dcSTakashi Iwai }; 207d29697dcSTakashi Iwai 208d29697dcSTakashi Iwai static const struct attribute_group soc_dev_roup = { 209d29697dcSTakashi Iwai .attrs = soc_dev_attrs, 210d29697dcSTakashi Iwai .is_visible = soc_dev_attr_is_visible, 211d29697dcSTakashi Iwai }; 212d29697dcSTakashi Iwai 213d29697dcSTakashi Iwai static const struct attribute_group *soc_dev_attr_groups[] = { 214d29697dcSTakashi Iwai &soc_dapm_dev_group, 215d29697dcSTakashi Iwai &soc_dev_roup, 216d29697dcSTakashi Iwai NULL 217d29697dcSTakashi Iwai }; 218d29697dcSTakashi Iwai 2192624d5faSMark Brown #ifdef CONFIG_DEBUG_FS 2202624d5faSMark Brown static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 2212624d5faSMark Brown size_t count, loff_t *ppos) 2222624d5faSMark Brown { 2232624d5faSMark Brown ssize_t ret; 2242624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 22513fd179fSDimitris Papastamos char *buf; 22613fd179fSDimitris Papastamos 22713fd179fSDimitris Papastamos if (*ppos < 0 || !count) 22813fd179fSDimitris Papastamos return -EINVAL; 22913fd179fSDimitris Papastamos 23013fd179fSDimitris Papastamos buf = kmalloc(count, GFP_KERNEL); 2312624d5faSMark Brown if (!buf) 2322624d5faSMark Brown return -ENOMEM; 23313fd179fSDimitris Papastamos 23413fd179fSDimitris Papastamos ret = soc_codec_reg_show(codec, buf, count, *ppos); 23513fd179fSDimitris Papastamos if (ret >= 0) { 23613fd179fSDimitris Papastamos if (copy_to_user(user_buf, buf, ret)) { 23713fd179fSDimitris Papastamos kfree(buf); 23813fd179fSDimitris Papastamos return -EFAULT; 23913fd179fSDimitris Papastamos } 24013fd179fSDimitris Papastamos *ppos += ret; 24113fd179fSDimitris Papastamos } 24213fd179fSDimitris Papastamos 2432624d5faSMark Brown kfree(buf); 2442624d5faSMark Brown return ret; 2452624d5faSMark Brown } 2462624d5faSMark Brown 2472624d5faSMark Brown static ssize_t codec_reg_write_file(struct file *file, 2482624d5faSMark Brown const char __user *user_buf, size_t count, loff_t *ppos) 2492624d5faSMark Brown { 2502624d5faSMark Brown char buf[32]; 25134e268d8SStephen Boyd size_t buf_size; 2522624d5faSMark Brown char *start = buf; 2532624d5faSMark Brown unsigned long reg, value; 2542624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 255b785a492SJingoo Han int ret; 2562624d5faSMark Brown 2572624d5faSMark Brown buf_size = min(count, (sizeof(buf)-1)); 2582624d5faSMark Brown if (copy_from_user(buf, user_buf, buf_size)) 2592624d5faSMark Brown return -EFAULT; 2602624d5faSMark Brown buf[buf_size] = 0; 2612624d5faSMark Brown 2622624d5faSMark Brown while (*start == ' ') 2632624d5faSMark Brown start++; 2642624d5faSMark Brown reg = simple_strtoul(start, &start, 16); 2652624d5faSMark Brown while (*start == ' ') 2662624d5faSMark Brown start++; 267b785a492SJingoo Han ret = kstrtoul(start, 16, &value); 268b785a492SJingoo Han if (ret) 269b785a492SJingoo Han return ret; 2700d51a9cbSMark Brown 2710d51a9cbSMark Brown /* Userspace has been fiddling around behind the kernel's back */ 272373d4d09SRusty Russell add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); 2730d51a9cbSMark Brown 274e4f078d8SDimitris Papastamos snd_soc_write(codec, reg, value); 2752624d5faSMark Brown return buf_size; 2762624d5faSMark Brown } 2772624d5faSMark Brown 2782624d5faSMark Brown static const struct file_operations codec_reg_fops = { 279234e3405SStephen Boyd .open = simple_open, 2802624d5faSMark Brown .read = codec_reg_read_file, 2812624d5faSMark Brown .write = codec_reg_write_file, 2826038f373SArnd Bergmann .llseek = default_llseek, 2832624d5faSMark Brown }; 2842624d5faSMark Brown 28581c7cfd1SLars-Peter Clausen static void soc_init_component_debugfs(struct snd_soc_component *component) 286e73f3de5SRussell King { 2876553bf06SLars-Peter Clausen if (!component->card->debugfs_card_root) 2886553bf06SLars-Peter Clausen return; 2896553bf06SLars-Peter Clausen 29081c7cfd1SLars-Peter Clausen if (component->debugfs_prefix) { 29181c7cfd1SLars-Peter Clausen char *name; 292e73f3de5SRussell King 29381c7cfd1SLars-Peter Clausen name = kasprintf(GFP_KERNEL, "%s:%s", 29481c7cfd1SLars-Peter Clausen component->debugfs_prefix, component->name); 29581c7cfd1SLars-Peter Clausen if (name) { 29681c7cfd1SLars-Peter Clausen component->debugfs_root = debugfs_create_dir(name, 29781c7cfd1SLars-Peter Clausen component->card->debugfs_card_root); 29881c7cfd1SLars-Peter Clausen kfree(name); 29981c7cfd1SLars-Peter Clausen } 30081c7cfd1SLars-Peter Clausen } else { 30181c7cfd1SLars-Peter Clausen component->debugfs_root = debugfs_create_dir(component->name, 30281c7cfd1SLars-Peter Clausen component->card->debugfs_card_root); 303e73f3de5SRussell King } 304e73f3de5SRussell King 30581c7cfd1SLars-Peter Clausen if (!component->debugfs_root) { 30681c7cfd1SLars-Peter Clausen dev_warn(component->dev, 30781c7cfd1SLars-Peter Clausen "ASoC: Failed to create component debugfs directory\n"); 3082624d5faSMark Brown return; 3092624d5faSMark Brown } 3102624d5faSMark Brown 31181c7cfd1SLars-Peter Clausen snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), 31281c7cfd1SLars-Peter Clausen component->debugfs_root); 31381c7cfd1SLars-Peter Clausen 31481c7cfd1SLars-Peter Clausen if (component->init_debugfs) 31581c7cfd1SLars-Peter Clausen component->init_debugfs(component); 31681c7cfd1SLars-Peter Clausen } 31781c7cfd1SLars-Peter Clausen 31881c7cfd1SLars-Peter Clausen static void soc_cleanup_component_debugfs(struct snd_soc_component *component) 31981c7cfd1SLars-Peter Clausen { 32081c7cfd1SLars-Peter Clausen debugfs_remove_recursive(component->debugfs_root); 32181c7cfd1SLars-Peter Clausen } 32281c7cfd1SLars-Peter Clausen 32381c7cfd1SLars-Peter Clausen static void soc_init_codec_debugfs(struct snd_soc_component *component) 32481c7cfd1SLars-Peter Clausen { 32581c7cfd1SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 32681c7cfd1SLars-Peter Clausen 3272624d5faSMark Brown codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 32881c7cfd1SLars-Peter Clausen codec->component.debugfs_root, 3292624d5faSMark Brown codec, &codec_reg_fops); 3302624d5faSMark Brown if (!codec->debugfs_reg) 33110e8aa9aSMichał Mirosław dev_warn(codec->dev, 33210e8aa9aSMichał Mirosław "ASoC: Failed to create codec register debugfs file\n"); 333731f1ab2SSebastien Guiriec } 334731f1ab2SSebastien Guiriec 335c3c5a19aSMark Brown static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, 336c3c5a19aSMark Brown size_t count, loff_t *ppos) 337c3c5a19aSMark Brown { 338c3c5a19aSMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3392b194f9dSMark Brown ssize_t len, ret = 0; 340c3c5a19aSMark Brown struct snd_soc_codec *codec; 341c3c5a19aSMark Brown 342c3c5a19aSMark Brown if (!buf) 343c3c5a19aSMark Brown return -ENOMEM; 344c3c5a19aSMark Brown 34534e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 34634e81ab4SLars-Peter Clausen 3472b194f9dSMark Brown list_for_each_entry(codec, &codec_list, list) { 3482b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 349f4333203SLars-Peter Clausen codec->component.name); 3502b194f9dSMark Brown if (len >= 0) 3512b194f9dSMark Brown ret += len; 3522b194f9dSMark Brown if (ret > PAGE_SIZE) { 3532b194f9dSMark Brown ret = PAGE_SIZE; 3542b194f9dSMark Brown break; 3552b194f9dSMark Brown } 3562b194f9dSMark Brown } 357c3c5a19aSMark Brown 35834e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 35934e81ab4SLars-Peter Clausen 360c3c5a19aSMark Brown if (ret >= 0) 361c3c5a19aSMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 362c3c5a19aSMark Brown 363c3c5a19aSMark Brown kfree(buf); 364c3c5a19aSMark Brown 365c3c5a19aSMark Brown return ret; 366c3c5a19aSMark Brown } 367c3c5a19aSMark Brown 368c3c5a19aSMark Brown static const struct file_operations codec_list_fops = { 369c3c5a19aSMark Brown .read = codec_list_read_file, 370c3c5a19aSMark Brown .llseek = default_llseek,/* read accesses f_pos */ 371c3c5a19aSMark Brown }; 372c3c5a19aSMark Brown 373f3208780SMark Brown static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, 374f3208780SMark Brown size_t count, loff_t *ppos) 375f3208780SMark Brown { 376f3208780SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3772b194f9dSMark Brown ssize_t len, ret = 0; 3781438c2f6SLars-Peter Clausen struct snd_soc_component *component; 379f3208780SMark Brown struct snd_soc_dai *dai; 380f3208780SMark Brown 381f3208780SMark Brown if (!buf) 382f3208780SMark Brown return -ENOMEM; 383f3208780SMark Brown 38434e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 38534e81ab4SLars-Peter Clausen 3861438c2f6SLars-Peter Clausen list_for_each_entry(component, &component_list, list) { 3871438c2f6SLars-Peter Clausen list_for_each_entry(dai, &component->dai_list, list) { 3881438c2f6SLars-Peter Clausen len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 3891438c2f6SLars-Peter Clausen dai->name); 3902b194f9dSMark Brown if (len >= 0) 3912b194f9dSMark Brown ret += len; 3922b194f9dSMark Brown if (ret > PAGE_SIZE) { 3932b194f9dSMark Brown ret = PAGE_SIZE; 3942b194f9dSMark Brown break; 3952b194f9dSMark Brown } 3962b194f9dSMark Brown } 3971438c2f6SLars-Peter Clausen } 398f3208780SMark Brown 39934e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 40034e81ab4SLars-Peter Clausen 401f3208780SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 402f3208780SMark Brown 403f3208780SMark Brown kfree(buf); 404f3208780SMark Brown 405f3208780SMark Brown return ret; 406f3208780SMark Brown } 407f3208780SMark Brown 408f3208780SMark Brown static const struct file_operations dai_list_fops = { 409f3208780SMark Brown .read = dai_list_read_file, 410f3208780SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 411f3208780SMark Brown }; 412f3208780SMark Brown 41319c7ac27SMark Brown static ssize_t platform_list_read_file(struct file *file, 41419c7ac27SMark Brown char __user *user_buf, 41519c7ac27SMark Brown size_t count, loff_t *ppos) 41619c7ac27SMark Brown { 41719c7ac27SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 4182b194f9dSMark Brown ssize_t len, ret = 0; 41919c7ac27SMark Brown struct snd_soc_platform *platform; 42019c7ac27SMark Brown 42119c7ac27SMark Brown if (!buf) 42219c7ac27SMark Brown return -ENOMEM; 42319c7ac27SMark Brown 42434e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 42534e81ab4SLars-Peter Clausen 4262b194f9dSMark Brown list_for_each_entry(platform, &platform_list, list) { 4272b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 428f4333203SLars-Peter Clausen platform->component.name); 4292b194f9dSMark Brown if (len >= 0) 4302b194f9dSMark Brown ret += len; 4312b194f9dSMark Brown if (ret > PAGE_SIZE) { 4322b194f9dSMark Brown ret = PAGE_SIZE; 4332b194f9dSMark Brown break; 4342b194f9dSMark Brown } 4352b194f9dSMark Brown } 43619c7ac27SMark Brown 43734e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 43834e81ab4SLars-Peter Clausen 43919c7ac27SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 44019c7ac27SMark Brown 44119c7ac27SMark Brown kfree(buf); 44219c7ac27SMark Brown 44319c7ac27SMark Brown return ret; 44419c7ac27SMark Brown } 44519c7ac27SMark Brown 44619c7ac27SMark Brown static const struct file_operations platform_list_fops = { 44719c7ac27SMark Brown .read = platform_list_read_file, 44819c7ac27SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 44919c7ac27SMark Brown }; 45019c7ac27SMark Brown 451a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card) 452a6052154SJarkko Nikula { 4536553bf06SLars-Peter Clausen if (!snd_soc_debugfs_root) 4546553bf06SLars-Peter Clausen return; 4556553bf06SLars-Peter Clausen 456a6052154SJarkko Nikula card->debugfs_card_root = debugfs_create_dir(card->name, 4578a9dab1aSMark Brown snd_soc_debugfs_root); 4583a45b867SJarkko Nikula if (!card->debugfs_card_root) { 459a6052154SJarkko Nikula dev_warn(card->dev, 4607c08be84SLothar Waßmann "ASoC: Failed to create card debugfs directory\n"); 4613a45b867SJarkko Nikula return; 4623a45b867SJarkko Nikula } 4633a45b867SJarkko Nikula 4643a45b867SJarkko Nikula card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 4653a45b867SJarkko Nikula card->debugfs_card_root, 4663a45b867SJarkko Nikula &card->pop_time); 4673a45b867SJarkko Nikula if (!card->debugfs_pop_time) 4683a45b867SJarkko Nikula dev_warn(card->dev, 469f110bfc7SLiam Girdwood "ASoC: Failed to create pop time debugfs file\n"); 470a6052154SJarkko Nikula } 471a6052154SJarkko Nikula 472a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card) 473a6052154SJarkko Nikula { 474a6052154SJarkko Nikula debugfs_remove_recursive(card->debugfs_card_root); 475a6052154SJarkko Nikula } 476a6052154SJarkko Nikula 4776553bf06SLars-Peter Clausen 4786553bf06SLars-Peter Clausen static void snd_soc_debugfs_init(void) 4796553bf06SLars-Peter Clausen { 4806553bf06SLars-Peter Clausen snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); 4816553bf06SLars-Peter Clausen if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { 4826553bf06SLars-Peter Clausen pr_warn("ASoC: Failed to create debugfs directory\n"); 4836553bf06SLars-Peter Clausen snd_soc_debugfs_root = NULL; 4846553bf06SLars-Peter Clausen return; 4856553bf06SLars-Peter Clausen } 4866553bf06SLars-Peter Clausen 4876553bf06SLars-Peter Clausen if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, 4886553bf06SLars-Peter Clausen &codec_list_fops)) 4896553bf06SLars-Peter Clausen pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); 4906553bf06SLars-Peter Clausen 4916553bf06SLars-Peter Clausen if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, 4926553bf06SLars-Peter Clausen &dai_list_fops)) 4936553bf06SLars-Peter Clausen pr_warn("ASoC: Failed to create DAI list debugfs file\n"); 4946553bf06SLars-Peter Clausen 4956553bf06SLars-Peter Clausen if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, 4966553bf06SLars-Peter Clausen &platform_list_fops)) 4976553bf06SLars-Peter Clausen pr_warn("ASoC: Failed to create platform list debugfs file\n"); 4986553bf06SLars-Peter Clausen } 4996553bf06SLars-Peter Clausen 5006553bf06SLars-Peter Clausen static void snd_soc_debugfs_exit(void) 5016553bf06SLars-Peter Clausen { 5026553bf06SLars-Peter Clausen debugfs_remove_recursive(snd_soc_debugfs_root); 5036553bf06SLars-Peter Clausen } 5046553bf06SLars-Peter Clausen 5052624d5faSMark Brown #else 5062624d5faSMark Brown 50781c7cfd1SLars-Peter Clausen #define soc_init_codec_debugfs NULL 50881c7cfd1SLars-Peter Clausen 50981c7cfd1SLars-Peter Clausen static inline void soc_init_component_debugfs( 51081c7cfd1SLars-Peter Clausen struct snd_soc_component *component) 5112624d5faSMark Brown { 5122624d5faSMark Brown } 5132624d5faSMark Brown 51481c7cfd1SLars-Peter Clausen static inline void soc_cleanup_component_debugfs( 51581c7cfd1SLars-Peter Clausen struct snd_soc_component *component) 516731f1ab2SSebastien Guiriec { 517731f1ab2SSebastien Guiriec } 518731f1ab2SSebastien Guiriec 519b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card) 520b95fccbcSAxel Lin { 521b95fccbcSAxel Lin } 522b95fccbcSAxel Lin 523b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) 524b95fccbcSAxel Lin { 525b95fccbcSAxel Lin } 5266553bf06SLars-Peter Clausen 5276553bf06SLars-Peter Clausen static inline void snd_soc_debugfs_init(void) 5286553bf06SLars-Peter Clausen { 5296553bf06SLars-Peter Clausen } 5306553bf06SLars-Peter Clausen 5316553bf06SLars-Peter Clausen static inline void snd_soc_debugfs_exit(void) 5326553bf06SLars-Peter Clausen { 5336553bf06SLars-Peter Clausen } 5346553bf06SLars-Peter Clausen 5352624d5faSMark Brown #endif 5362624d5faSMark Brown 53747c88fffSLiam Girdwood struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, 53847c88fffSLiam Girdwood const char *dai_link, int stream) 53947c88fffSLiam Girdwood { 54047c88fffSLiam Girdwood int i; 54147c88fffSLiam Girdwood 54247c88fffSLiam Girdwood for (i = 0; i < card->num_links; i++) { 54347c88fffSLiam Girdwood if (card->rtd[i].dai_link->no_pcm && 54447c88fffSLiam Girdwood !strcmp(card->rtd[i].dai_link->name, dai_link)) 54547c88fffSLiam Girdwood return card->rtd[i].pcm->streams[stream].substream; 54647c88fffSLiam Girdwood } 547f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link); 54847c88fffSLiam Girdwood return NULL; 54947c88fffSLiam Girdwood } 55047c88fffSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); 55147c88fffSLiam Girdwood 55247c88fffSLiam Girdwood struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, 55347c88fffSLiam Girdwood const char *dai_link) 55447c88fffSLiam Girdwood { 55547c88fffSLiam Girdwood int i; 55647c88fffSLiam Girdwood 55747c88fffSLiam Girdwood for (i = 0; i < card->num_links; i++) { 55847c88fffSLiam Girdwood if (!strcmp(card->rtd[i].dai_link->name, dai_link)) 55947c88fffSLiam Girdwood return &card->rtd[i]; 56047c88fffSLiam Girdwood } 561f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link); 56247c88fffSLiam Girdwood return NULL; 56347c88fffSLiam Girdwood } 56447c88fffSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); 56547c88fffSLiam Girdwood 5669d58a077SRichard Fitzgerald static void codec2codec_close_delayed_work(struct work_struct *work) 5679d58a077SRichard Fitzgerald { 5689d58a077SRichard Fitzgerald /* Currently nothing to do for c2c links 5699d58a077SRichard Fitzgerald * Since c2c links are internal nodes in the DAPM graph and 5709d58a077SRichard Fitzgerald * don't interface with the outside world or application layer 5719d58a077SRichard Fitzgerald * we don't have to do any special handling on close. 5729d58a077SRichard Fitzgerald */ 5739d58a077SRichard Fitzgerald } 5749d58a077SRichard Fitzgerald 5756f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP 576db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */ 5776f8ab4acSMark Brown int snd_soc_suspend(struct device *dev) 578db2a4165SFrank Mandarino { 5796f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 5802eea392dSJarkko Nikula struct snd_soc_codec *codec; 58188bd870fSBenoit Cousson int i, j; 582db2a4165SFrank Mandarino 583c5599b87SLars-Peter Clausen /* If the card is not initialized yet there is nothing to do */ 584c5599b87SLars-Peter Clausen if (!card->instantiated) 585e3509ff0SDaniel Mack return 0; 586e3509ff0SDaniel Mack 5876ed25978SAndy Green /* Due to the resume being scheduled into a workqueue we could 5886ed25978SAndy Green * suspend before that's finished - wait for it to complete. 5896ed25978SAndy Green */ 590f0fba2adSLiam Girdwood snd_power_lock(card->snd_card); 591f0fba2adSLiam Girdwood snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); 592f0fba2adSLiam Girdwood snd_power_unlock(card->snd_card); 5936ed25978SAndy Green 5946ed25978SAndy Green /* we're going to block userspace touching us until resume completes */ 595f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 5966ed25978SAndy Green 597a00f90f9SMark Brown /* mute any active DACs */ 598f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 5993efab7dcSMark Brown 600f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6013efab7dcSMark Brown continue; 6023efab7dcSMark Brown 60388bd870fSBenoit Cousson for (j = 0; j < card->rtd[i].num_codecs; j++) { 60488bd870fSBenoit Cousson struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; 60588bd870fSBenoit Cousson struct snd_soc_dai_driver *drv = dai->driver; 60688bd870fSBenoit Cousson 607f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 608f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 1); 609db2a4165SFrank Mandarino } 61088bd870fSBenoit Cousson } 611db2a4165SFrank Mandarino 6124ccab3e7SLiam Girdwood /* suspend all pcms */ 613f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 614f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6153efab7dcSMark Brown continue; 6163efab7dcSMark Brown 617f0fba2adSLiam Girdwood snd_pcm_suspend_all(card->rtd[i].pcm); 6183efab7dcSMark Brown } 6194ccab3e7SLiam Girdwood 62087506549SMark Brown if (card->suspend_pre) 62170b2ac12SMark Brown card->suspend_pre(card); 622db2a4165SFrank Mandarino 623f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 624f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6253efab7dcSMark Brown 626f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6273efab7dcSMark Brown continue; 6283efab7dcSMark Brown 629bc263214SLars-Peter Clausen if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control) 630f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 631db2a4165SFrank Mandarino } 632db2a4165SFrank Mandarino 63337660b6dSLars-Peter Clausen /* close any waiting streams */ 63437660b6dSLars-Peter Clausen for (i = 0; i < card->num_rtd; i++) 63543829731STejun Heo flush_delayed_work(&card->rtd[i].delayed_work); 636db2a4165SFrank Mandarino 637f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 6383efab7dcSMark Brown 639f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6403efab7dcSMark Brown continue; 6413efab7dcSMark Brown 6427bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 6437bd3a6f3SMark Brown SNDRV_PCM_STREAM_PLAYBACK, 644db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 645f0fba2adSLiam Girdwood 6467bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 6477bd3a6f3SMark Brown SNDRV_PCM_STREAM_CAPTURE, 648db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 649db2a4165SFrank Mandarino } 650db2a4165SFrank Mandarino 6518be4da29SLars-Peter Clausen /* Recheck all endpoints too, their state is affected by suspend */ 6528be4da29SLars-Peter Clausen dapm_mark_endpoints_dirty(card); 653e2d32ff6SMark Brown snd_soc_dapm_sync(&card->dapm); 654e2d32ff6SMark Brown 655f0fba2adSLiam Girdwood /* suspend all CODECs */ 6562eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 657*4890140fSLars-Peter Clausen struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 658*4890140fSLars-Peter Clausen 6591547aba9SMark Brown /* If there are paths active then the CODEC will be held with 6601547aba9SMark Brown * bias _ON and should not be suspended. */ 661a8093297SLars-Peter Clausen if (!codec->suspended) { 662*4890140fSLars-Peter Clausen switch (snd_soc_dapm_get_bias_level(dapm)) { 6631547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 664125a25daSMark Brown /* 665125a25daSMark Brown * If the CODEC is capable of idle 666125a25daSMark Brown * bias off then being in STANDBY 667125a25daSMark Brown * means it's doing something, 668125a25daSMark Brown * otherwise fall through. 669125a25daSMark Brown */ 670*4890140fSLars-Peter Clausen if (dapm->idle_bias_off) { 671125a25daSMark Brown dev_dbg(codec->dev, 67210e8aa9aSMichał Mirosław "ASoC: idle_bias_off CODEC on over suspend\n"); 673125a25daSMark Brown break; 674125a25daSMark Brown } 675a8093297SLars-Peter Clausen 6761547aba9SMark Brown case SND_SOC_BIAS_OFF: 677a8093297SLars-Peter Clausen if (codec->driver->suspend) 67884b315eeSLars-Peter Clausen codec->driver->suspend(codec); 679f0fba2adSLiam Girdwood codec->suspended = 1; 680e2c330b9SLars-Peter Clausen if (codec->component.regmap) 681e2c330b9SLars-Peter Clausen regcache_mark_dirty(codec->component.regmap); 682988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 683988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(codec->dev); 6841547aba9SMark Brown break; 6851547aba9SMark Brown default: 68610e8aa9aSMichał Mirosław dev_dbg(codec->dev, 68710e8aa9aSMichał Mirosław "ASoC: CODEC is on over suspend\n"); 6881547aba9SMark Brown break; 6891547aba9SMark Brown } 6901547aba9SMark Brown } 691f0fba2adSLiam Girdwood } 692db2a4165SFrank Mandarino 693f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 694f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6953efab7dcSMark Brown 696f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6973efab7dcSMark Brown continue; 6983efab7dcSMark Brown 699bc263214SLars-Peter Clausen if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control) 700f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 701988e8cc4SNicolin Chen 702988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 703988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 704db2a4165SFrank Mandarino } 705db2a4165SFrank Mandarino 70687506549SMark Brown if (card->suspend_post) 70770b2ac12SMark Brown card->suspend_post(card); 708db2a4165SFrank Mandarino 709db2a4165SFrank Mandarino return 0; 710db2a4165SFrank Mandarino } 7116f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 712db2a4165SFrank Mandarino 7136ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 7146ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 7156ed25978SAndy Green */ 7166ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 717db2a4165SFrank Mandarino { 718f0fba2adSLiam Girdwood struct snd_soc_card *card = 719f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 7202eea392dSJarkko Nikula struct snd_soc_codec *codec; 72188bd870fSBenoit Cousson int i, j; 722db2a4165SFrank Mandarino 7236ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 7246ed25978SAndy Green * so userspace apps are blocked from touching us 7256ed25978SAndy Green */ 7266ed25978SAndy Green 727f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: starting resume work\n"); 7286ed25978SAndy Green 7299949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 730f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 7319949788bSMark Brown 73287506549SMark Brown if (card->resume_pre) 73370b2ac12SMark Brown card->resume_pre(card); 734db2a4165SFrank Mandarino 735bc263214SLars-Peter Clausen /* resume control bus DAIs */ 736f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 737f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 7383efab7dcSMark Brown 739f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7403efab7dcSMark Brown continue; 7413efab7dcSMark Brown 742bc263214SLars-Peter Clausen if (cpu_dai->driver->resume && cpu_dai->driver->bus_control) 743f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 744db2a4165SFrank Mandarino } 745db2a4165SFrank Mandarino 7462eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 747a8093297SLars-Peter Clausen if (codec->suspended) { 748a8093297SLars-Peter Clausen if (codec->driver->resume) 749f0fba2adSLiam Girdwood codec->driver->resume(codec); 750f0fba2adSLiam Girdwood codec->suspended = 0; 7511547aba9SMark Brown } 752f0fba2adSLiam Girdwood } 753db2a4165SFrank Mandarino 754f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 7553efab7dcSMark Brown 756f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7573efab7dcSMark Brown continue; 7583efab7dcSMark Brown 7597bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 760d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_PLAYBACK, 761db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 762f0fba2adSLiam Girdwood 7637bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 764d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_CAPTURE, 765db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 766db2a4165SFrank Mandarino } 767db2a4165SFrank Mandarino 7683ff3f64bSMark Brown /* unmute any active DACs */ 769f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 7703efab7dcSMark Brown 771f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7723efab7dcSMark Brown continue; 7733efab7dcSMark Brown 77488bd870fSBenoit Cousson for (j = 0; j < card->rtd[i].num_codecs; j++) { 77588bd870fSBenoit Cousson struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; 77688bd870fSBenoit Cousson struct snd_soc_dai_driver *drv = dai->driver; 77788bd870fSBenoit Cousson 778f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 779f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 780db2a4165SFrank Mandarino } 78188bd870fSBenoit Cousson } 782db2a4165SFrank Mandarino 783f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 784f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 7853efab7dcSMark Brown 786f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7873efab7dcSMark Brown continue; 7883efab7dcSMark Brown 789bc263214SLars-Peter Clausen if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control) 790f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 791db2a4165SFrank Mandarino } 792db2a4165SFrank Mandarino 79387506549SMark Brown if (card->resume_post) 79470b2ac12SMark Brown card->resume_post(card); 795db2a4165SFrank Mandarino 796f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: resume work completed\n"); 7976ed25978SAndy Green 7986ed25978SAndy Green /* userspace can access us now we are back as we were before */ 799f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 800e2d32ff6SMark Brown 8018be4da29SLars-Peter Clausen /* Recheck all endpoints too, their state is affected by suspend */ 8028be4da29SLars-Peter Clausen dapm_mark_endpoints_dirty(card); 803e2d32ff6SMark Brown snd_soc_dapm_sync(&card->dapm); 8046ed25978SAndy Green } 8056ed25978SAndy Green 8066ed25978SAndy Green /* powers up audio subsystem after a suspend */ 8076f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 8086ed25978SAndy Green { 8096f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 810bc263214SLars-Peter Clausen bool bus_control = false; 811bc263214SLars-Peter Clausen int i; 812b9dd94a8SPeter Ujfalusi 813c5599b87SLars-Peter Clausen /* If the card is not initialized yet there is nothing to do */ 814c5599b87SLars-Peter Clausen if (!card->instantiated) 8155ff1ddf2SEric Miao return 0; 8165ff1ddf2SEric Miao 817988e8cc4SNicolin Chen /* activate pins from sleep state */ 818988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 81988bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 82088bd870fSBenoit Cousson struct snd_soc_dai **codec_dais = rtd->codec_dais; 82188bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 82288bd870fSBenoit Cousson int j; 82388bd870fSBenoit Cousson 824988e8cc4SNicolin Chen if (cpu_dai->active) 825988e8cc4SNicolin Chen pinctrl_pm_select_default_state(cpu_dai->dev); 82688bd870fSBenoit Cousson 82788bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 82888bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = codec_dais[j]; 829988e8cc4SNicolin Chen if (codec_dai->active) 830988e8cc4SNicolin Chen pinctrl_pm_select_default_state(codec_dai->dev); 831988e8cc4SNicolin Chen } 83288bd870fSBenoit Cousson } 833988e8cc4SNicolin Chen 834bc263214SLars-Peter Clausen /* 835bc263214SLars-Peter Clausen * DAIs that also act as the control bus master might have other drivers 836bc263214SLars-Peter Clausen * hanging off them so need to resume immediately. Other drivers don't 837bc263214SLars-Peter Clausen * have that problem and may take a substantial amount of time to resume 83864ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 83964ab9baaSMark Brown */ 840f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 841f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 842bc263214SLars-Peter Clausen bus_control |= cpu_dai->driver->bus_control; 84382e14e8bSStephen Warren } 844bc263214SLars-Peter Clausen if (bus_control) { 845bc263214SLars-Peter Clausen dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); 84664ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 84764ab9baaSMark Brown } else { 848f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Scheduling resume work\n"); 8496308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 850f110bfc7SLiam Girdwood dev_err(dev, "ASoC: resume work item may be lost\n"); 851f0fba2adSLiam Girdwood } 8526ed25978SAndy Green 853db2a4165SFrank Mandarino return 0; 854db2a4165SFrank Mandarino } 8556f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 856db2a4165SFrank Mandarino #else 8576f8ab4acSMark Brown #define snd_soc_suspend NULL 8586f8ab4acSMark Brown #define snd_soc_resume NULL 859db2a4165SFrank Mandarino #endif 860db2a4165SFrank Mandarino 86185e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops null_dai_ops = { 86202a06d30SBarry Song }; 86302a06d30SBarry Song 86465d9361fSLars-Peter Clausen static struct snd_soc_component *soc_find_component( 86565d9361fSLars-Peter Clausen const struct device_node *of_node, const char *name) 86612023a9aSMisael Lopez Cruz { 86765d9361fSLars-Peter Clausen struct snd_soc_component *component; 86812023a9aSMisael Lopez Cruz 86934e81ab4SLars-Peter Clausen lockdep_assert_held(&client_mutex); 87034e81ab4SLars-Peter Clausen 87165d9361fSLars-Peter Clausen list_for_each_entry(component, &component_list, list) { 87265d9361fSLars-Peter Clausen if (of_node) { 87365d9361fSLars-Peter Clausen if (component->dev->of_node == of_node) 87465d9361fSLars-Peter Clausen return component; 87565d9361fSLars-Peter Clausen } else if (strcmp(component->name, name) == 0) { 87665d9361fSLars-Peter Clausen return component; 87712023a9aSMisael Lopez Cruz } 87812023a9aSMisael Lopez Cruz } 87912023a9aSMisael Lopez Cruz 88012023a9aSMisael Lopez Cruz return NULL; 88112023a9aSMisael Lopez Cruz } 88212023a9aSMisael Lopez Cruz 88314621c7eSLars-Peter Clausen static struct snd_soc_dai *snd_soc_find_dai( 88414621c7eSLars-Peter Clausen const struct snd_soc_dai_link_component *dlc) 88512023a9aSMisael Lopez Cruz { 88614621c7eSLars-Peter Clausen struct snd_soc_component *component; 88714621c7eSLars-Peter Clausen struct snd_soc_dai *dai; 8883e0aa8d8SJyri Sarha struct device_node *component_of_node; 88912023a9aSMisael Lopez Cruz 89034e81ab4SLars-Peter Clausen lockdep_assert_held(&client_mutex); 89134e81ab4SLars-Peter Clausen 89214621c7eSLars-Peter Clausen /* Find CPU DAI from registered DAIs*/ 89314621c7eSLars-Peter Clausen list_for_each_entry(component, &component_list, list) { 8943e0aa8d8SJyri Sarha component_of_node = component->dev->of_node; 8953e0aa8d8SJyri Sarha if (!component_of_node && component->dev->parent) 8963e0aa8d8SJyri Sarha component_of_node = component->dev->parent->of_node; 8973e0aa8d8SJyri Sarha 8983e0aa8d8SJyri Sarha if (dlc->of_node && component_of_node != dlc->of_node) 89912023a9aSMisael Lopez Cruz continue; 9001ffae361SLars-Peter Clausen if (dlc->name && strcmp(component->name, dlc->name)) 90112023a9aSMisael Lopez Cruz continue; 90214621c7eSLars-Peter Clausen list_for_each_entry(dai, &component->dai_list, list) { 90314621c7eSLars-Peter Clausen if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) 90414621c7eSLars-Peter Clausen continue; 90512023a9aSMisael Lopez Cruz 90614621c7eSLars-Peter Clausen return dai; 90712023a9aSMisael Lopez Cruz } 90812023a9aSMisael Lopez Cruz } 90912023a9aSMisael Lopez Cruz 91012023a9aSMisael Lopez Cruz return NULL; 91112023a9aSMisael Lopez Cruz } 91212023a9aSMisael Lopez Cruz 913f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 914db2a4165SFrank Mandarino { 915f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 916f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 91788bd870fSBenoit Cousson struct snd_soc_dai_link_component *codecs = dai_link->codecs; 91814621c7eSLars-Peter Clausen struct snd_soc_dai_link_component cpu_dai_component; 91988bd870fSBenoit Cousson struct snd_soc_dai **codec_dais = rtd->codec_dais; 920435c5e25SMark Brown struct snd_soc_platform *platform; 921848dd8beSMark Brown const char *platform_name; 92288bd870fSBenoit Cousson int i; 923db2a4165SFrank Mandarino 924f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 9256308419aSMark Brown 92614621c7eSLars-Peter Clausen cpu_dai_component.name = dai_link->cpu_name; 92714621c7eSLars-Peter Clausen cpu_dai_component.of_node = dai_link->cpu_of_node; 92814621c7eSLars-Peter Clausen cpu_dai_component.dai_name = dai_link->cpu_dai_name; 92914621c7eSLars-Peter Clausen rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component); 930b19e6e7bSMark Brown if (!rtd->cpu_dai) { 931f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", 932f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 933b19e6e7bSMark Brown return -EPROBE_DEFER; 934c5af3a2eSMark Brown } 935c5af3a2eSMark Brown 93688bd870fSBenoit Cousson rtd->num_codecs = dai_link->num_codecs; 93788bd870fSBenoit Cousson 93888bd870fSBenoit Cousson /* Find CODEC from registered CODECs */ 93988bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 94014621c7eSLars-Peter Clausen codec_dais[i] = snd_soc_find_dai(&codecs[i]); 94188bd870fSBenoit Cousson if (!codec_dais[i]) { 94212023a9aSMisael Lopez Cruz dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", 94388bd870fSBenoit Cousson codecs[i].dai_name); 94412023a9aSMisael Lopez Cruz return -EPROBE_DEFER; 94512023a9aSMisael Lopez Cruz } 94688bd870fSBenoit Cousson } 94788bd870fSBenoit Cousson 94888bd870fSBenoit Cousson /* Single codec links expect codec and codec_dai in runtime data */ 94988bd870fSBenoit Cousson rtd->codec_dai = codec_dais[0]; 95088bd870fSBenoit Cousson rtd->codec = rtd->codec_dai->codec; 95112023a9aSMisael Lopez Cruz 952848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 953848dd8beSMark Brown platform_name = dai_link->platform_name; 9545a504963SStephen Warren if (!platform_name && !dai_link->platform_of_node) 955848dd8beSMark Brown platform_name = "snd-soc-dummy"; 956848dd8beSMark Brown 957b19e6e7bSMark Brown /* find one from the set of registered platforms */ 958f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 9595a504963SStephen Warren if (dai_link->platform_of_node) { 9605a504963SStephen Warren if (platform->dev->of_node != 9615a504963SStephen Warren dai_link->platform_of_node) 9625a504963SStephen Warren continue; 9635a504963SStephen Warren } else { 964f4333203SLars-Peter Clausen if (strcmp(platform->component.name, platform_name)) 9652610ab77SStephen Warren continue; 9665a504963SStephen Warren } 9672610ab77SStephen Warren 968f0fba2adSLiam Girdwood rtd->platform = platform; 969f0fba2adSLiam Girdwood } 970b19e6e7bSMark Brown if (!rtd->platform) { 971f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: platform %s not registered\n", 972f0fba2adSLiam Girdwood dai_link->platform_name); 973b19e6e7bSMark Brown return -EPROBE_DEFER; 974f0fba2adSLiam Girdwood } 975b19e6e7bSMark Brown 976b19e6e7bSMark Brown card->num_rtd++; 977b19e6e7bSMark Brown 978b19e6e7bSMark Brown return 0; 9796b05eda6SMark Brown } 9806b05eda6SMark Brown 981f1d45cc3SLars-Peter Clausen static void soc_remove_component(struct snd_soc_component *component) 982d12cd198SStephen Warren { 98370090bbbSLars-Peter Clausen if (!component->probed) 98470090bbbSLars-Peter Clausen return; 985d12cd198SStephen Warren 986f1d45cc3SLars-Peter Clausen /* This is a HACK and will be removed soon */ 987f1d45cc3SLars-Peter Clausen if (component->codec) 988f1d45cc3SLars-Peter Clausen list_del(&component->codec->card_list); 989d12cd198SStephen Warren 990f1d45cc3SLars-Peter Clausen if (component->remove) 991f1d45cc3SLars-Peter Clausen component->remove(component); 992d12cd198SStephen Warren 993f1d45cc3SLars-Peter Clausen snd_soc_dapm_free(snd_soc_component_get_dapm(component)); 994d12cd198SStephen Warren 995f1d45cc3SLars-Peter Clausen soc_cleanup_component_debugfs(component); 996f1d45cc3SLars-Peter Clausen component->probed = 0; 997f1d45cc3SLars-Peter Clausen module_put(component->dev->driver->owner); 998d12cd198SStephen Warren } 999d12cd198SStephen Warren 1000e60cd14fSLars-Peter Clausen static void soc_remove_dai(struct snd_soc_dai *dai, int order) 1001589c3563SJarkko Nikula { 1002589c3563SJarkko Nikula int err; 1003589c3563SJarkko Nikula 1004e60cd14fSLars-Peter Clausen if (dai && dai->probed && 1005e60cd14fSLars-Peter Clausen dai->driver->remove_order == order) { 1006e60cd14fSLars-Peter Clausen if (dai->driver->remove) { 1007e60cd14fSLars-Peter Clausen err = dai->driver->remove(dai); 1008589c3563SJarkko Nikula if (err < 0) 1009e60cd14fSLars-Peter Clausen dev_err(dai->dev, 1010b0aa88afSMisael Lopez Cruz "ASoC: failed to remove %s: %d\n", 1011e60cd14fSLars-Peter Clausen dai->name, err); 1012b0aa88afSMisael Lopez Cruz } 1013e60cd14fSLars-Peter Clausen dai->probed = 0; 1014b0aa88afSMisael Lopez Cruz } 1015b0aa88afSMisael Lopez Cruz } 1016b0aa88afSMisael Lopez Cruz 101762ae68faSStephen Warren static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) 1018f0fba2adSLiam Girdwood { 1019f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1020e60cd14fSLars-Peter Clausen int i; 1021f0fba2adSLiam Girdwood 1022f0fba2adSLiam Girdwood /* unregister the rtd device */ 1023f0fba2adSLiam Girdwood if (rtd->dev_registered) { 102436ae1a96SMark Brown device_unregister(rtd->dev); 1025f0fba2adSLiam Girdwood rtd->dev_registered = 0; 102602a06d30SBarry Song } 102702a06d30SBarry Song 1028f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 102988bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) 1030e60cd14fSLars-Peter Clausen soc_remove_dai(rtd->codec_dais[i], order); 1031f0fba2adSLiam Girdwood 1032e60cd14fSLars-Peter Clausen soc_remove_dai(rtd->cpu_dai, order); 1033f0fba2adSLiam Girdwood } 1034f0fba2adSLiam Girdwood 103562ae68faSStephen Warren static void soc_remove_link_components(struct snd_soc_card *card, int num, 103662ae68faSStephen Warren int order) 103762ae68faSStephen Warren { 103862ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 103962ae68faSStephen Warren struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 104062ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 104161aca564SLars-Peter Clausen struct snd_soc_component *component; 104288bd870fSBenoit Cousson int i; 104362ae68faSStephen Warren 104462ae68faSStephen Warren /* remove the platform */ 104570090bbbSLars-Peter Clausen if (platform && platform->component.driver->remove_order == order) 1046f1d45cc3SLars-Peter Clausen soc_remove_component(&platform->component); 104762ae68faSStephen Warren 104862ae68faSStephen Warren /* remove the CODEC-side CODEC */ 104988bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 105061aca564SLars-Peter Clausen component = rtd->codec_dais[i]->component; 105170090bbbSLars-Peter Clausen if (component->driver->remove_order == order) 105261aca564SLars-Peter Clausen soc_remove_component(component); 105362ae68faSStephen Warren } 105462ae68faSStephen Warren 105562ae68faSStephen Warren /* remove any CPU-side CODEC */ 105662ae68faSStephen Warren if (cpu_dai) { 105770090bbbSLars-Peter Clausen if (cpu_dai->component->driver->remove_order == order) 105861aca564SLars-Peter Clausen soc_remove_component(cpu_dai->component); 105962ae68faSStephen Warren } 106062ae68faSStephen Warren } 106162ae68faSStephen Warren 10620671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 10630671fd8eSKuninori Morimoto { 10640168bf0dSLiam Girdwood int dai, order; 10650671fd8eSKuninori Morimoto 10660168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 10670168bf0dSLiam Girdwood order++) { 10680168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 106962ae68faSStephen Warren soc_remove_link_dais(card, dai, order); 10700168bf0dSLiam Girdwood } 107162ae68faSStephen Warren 107262ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 107362ae68faSStephen Warren order++) { 107462ae68faSStephen Warren for (dai = 0; dai < card->num_rtd; dai++) 107562ae68faSStephen Warren soc_remove_link_components(card, dai, order); 107662ae68faSStephen Warren } 107762ae68faSStephen Warren 10780671fd8eSKuninori Morimoto card->num_rtd = 0; 10790671fd8eSKuninori Morimoto } 10800671fd8eSKuninori Morimoto 1081ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 108294f99c87SLars-Peter Clausen struct snd_soc_component *component) 1083ead9b919SJarkko Nikula { 1084ead9b919SJarkko Nikula int i; 1085ead9b919SJarkko Nikula 1086ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 1087ead9b919SJarkko Nikula return; 1088ead9b919SJarkko Nikula 1089ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 1090ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 109194f99c87SLars-Peter Clausen if (map->of_node && component->dev->of_node != map->of_node) 10923ca041edSSebastian Reichel continue; 109394f99c87SLars-Peter Clausen if (map->dev_name && strcmp(component->name, map->dev_name)) 10943ca041edSSebastian Reichel continue; 109594f99c87SLars-Peter Clausen component->name_prefix = map->name_prefix; 1096ead9b919SJarkko Nikula break; 1097ead9b919SJarkko Nikula } 1098ead9b919SJarkko Nikula } 1099ead9b919SJarkko Nikula 1100f1d45cc3SLars-Peter Clausen static int soc_probe_component(struct snd_soc_card *card, 1101f1d45cc3SLars-Peter Clausen struct snd_soc_component *component) 1102589c3563SJarkko Nikula { 1103f1d45cc3SLars-Peter Clausen struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 1104888df395SMark Brown struct snd_soc_dai *dai; 1105f1d45cc3SLars-Peter Clausen int ret; 1106589c3563SJarkko Nikula 110770090bbbSLars-Peter Clausen if (component->probed) 110870090bbbSLars-Peter Clausen return 0; 1109589c3563SJarkko Nikula 1110f1d45cc3SLars-Peter Clausen component->card = card; 1111f1d45cc3SLars-Peter Clausen dapm->card = card; 1112f1d45cc3SLars-Peter Clausen soc_set_name_prefix(card, component); 1113589c3563SJarkko Nikula 1114f1d45cc3SLars-Peter Clausen if (!try_module_get(component->dev->driver->owner)) 111570d29331SJarkko Nikula return -ENODEV; 111670d29331SJarkko Nikula 1117f1d45cc3SLars-Peter Clausen soc_init_component_debugfs(component); 1118d5d1e0beSLars-Peter Clausen 1119f1d45cc3SLars-Peter Clausen if (component->dapm_widgets) { 1120f1d45cc3SLars-Peter Clausen ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets, 1121f1d45cc3SLars-Peter Clausen component->num_dapm_widgets); 112277530150SLars-Peter Clausen 1123b318ad50SNariman Poushin if (ret != 0) { 1124f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1125b318ad50SNariman Poushin "Failed to create new controls %d\n", ret); 1126b318ad50SNariman Poushin goto err_probe; 1127b318ad50SNariman Poushin } 1128b318ad50SNariman Poushin } 1129b318ad50SNariman Poushin 11300634814fSLars-Peter Clausen list_for_each_entry(dai, &component->dai_list, list) { 11310634814fSLars-Peter Clausen ret = snd_soc_dapm_new_dai_widgets(dapm, dai); 1132261edc70SNariman Poushin if (ret != 0) { 1133f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1134261edc70SNariman Poushin "Failed to create DAI widgets %d\n", ret); 1135261edc70SNariman Poushin goto err_probe; 1136261edc70SNariman Poushin } 1137261edc70SNariman Poushin } 1138888df395SMark Brown 1139f1d45cc3SLars-Peter Clausen if (component->probe) { 1140f1d45cc3SLars-Peter Clausen ret = component->probe(component); 1141589c3563SJarkko Nikula if (ret < 0) { 1142f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1143f1d45cc3SLars-Peter Clausen "ASoC: failed to probe component %d\n", ret); 114470d29331SJarkko Nikula goto err_probe; 1145589c3563SJarkko Nikula } 1146cb2cf612SLiam Girdwood 1147f1d45cc3SLars-Peter Clausen WARN(dapm->idle_bias_off && 1148f1d45cc3SLars-Peter Clausen dapm->bias_level != SND_SOC_BIAS_OFF, 1149956245e9SLiam Girdwood "codec %s can not start from non-off bias with idle_bias_off==1\n", 1150f1d45cc3SLars-Peter Clausen component->name); 1151956245e9SLiam Girdwood } 1152956245e9SLiam Girdwood 1153f1d45cc3SLars-Peter Clausen if (component->controls) 1154f1d45cc3SLars-Peter Clausen snd_soc_add_component_controls(component, component->controls, 1155f1d45cc3SLars-Peter Clausen component->num_controls); 1156f1d45cc3SLars-Peter Clausen if (component->dapm_routes) 1157f1d45cc3SLars-Peter Clausen snd_soc_dapm_add_routes(dapm, component->dapm_routes, 1158f1d45cc3SLars-Peter Clausen component->num_dapm_routes); 1159956245e9SLiam Girdwood 1160f1d45cc3SLars-Peter Clausen component->probed = 1; 1161f1d45cc3SLars-Peter Clausen list_add(&dapm->list, &card->dapm_list); 1162f1d45cc3SLars-Peter Clausen 1163f1d45cc3SLars-Peter Clausen /* This is a HACK and will be removed soon */ 1164f1d45cc3SLars-Peter Clausen if (component->codec) 1165f1d45cc3SLars-Peter Clausen list_add(&component->codec->card_list, &card->codec_dev_list); 1166956245e9SLiam Girdwood 1167956245e9SLiam Girdwood return 0; 1168956245e9SLiam Girdwood 1169956245e9SLiam Girdwood err_probe: 1170f1d45cc3SLars-Peter Clausen soc_cleanup_component_debugfs(component); 1171f1d45cc3SLars-Peter Clausen module_put(component->dev->driver->owner); 1172956245e9SLiam Girdwood 1173956245e9SLiam Girdwood return ret; 1174956245e9SLiam Girdwood } 1175956245e9SLiam Girdwood 117636ae1a96SMark Brown static void rtd_release(struct device *dev) 117736ae1a96SMark Brown { 117836ae1a96SMark Brown kfree(dev); 117936ae1a96SMark Brown } 1180f0fba2adSLiam Girdwood 11815f3484acSLars-Peter Clausen static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, 11825f3484acSLars-Peter Clausen const char *name) 1183503ae5e0SMisael Lopez Cruz { 1184589c3563SJarkko Nikula int ret = 0; 1185589c3563SJarkko Nikula 1186589c3563SJarkko Nikula /* register the rtd device */ 118736ae1a96SMark Brown rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 118836ae1a96SMark Brown if (!rtd->dev) 118936ae1a96SMark Brown return -ENOMEM; 119036ae1a96SMark Brown device_initialize(rtd->dev); 11915f3484acSLars-Peter Clausen rtd->dev->parent = rtd->card->dev; 119236ae1a96SMark Brown rtd->dev->release = rtd_release; 1193d29697dcSTakashi Iwai rtd->dev->groups = soc_dev_attr_groups; 1194f294afedSLars-Peter Clausen dev_set_name(rtd->dev, "%s", name); 119536ae1a96SMark Brown dev_set_drvdata(rtd->dev, rtd); 1196b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 119701d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); 119801d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); 119901d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); 120001d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); 120136ae1a96SMark Brown ret = device_add(rtd->dev); 1202589c3563SJarkko Nikula if (ret < 0) { 1203865df9cbSChuansheng Liu /* calling put_device() here to free the rtd->dev */ 1204865df9cbSChuansheng Liu put_device(rtd->dev); 12055f3484acSLars-Peter Clausen dev_err(rtd->card->dev, 1206f110bfc7SLiam Girdwood "ASoC: failed to register runtime device: %d\n", ret); 1207589c3563SJarkko Nikula return ret; 1208589c3563SJarkko Nikula } 1209589c3563SJarkko Nikula rtd->dev_registered = 1; 1210589c3563SJarkko Nikula return 0; 1211589c3563SJarkko Nikula } 1212589c3563SJarkko Nikula 121362ae68faSStephen Warren static int soc_probe_link_components(struct snd_soc_card *card, int num, 121462ae68faSStephen Warren int order) 121562ae68faSStephen Warren { 121662ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 121762ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 1218f1d45cc3SLars-Peter Clausen struct snd_soc_component *component; 121988bd870fSBenoit Cousson int i, ret; 122062ae68faSStephen Warren 122162ae68faSStephen Warren /* probe the CPU-side component, if it is a CODEC */ 122261aca564SLars-Peter Clausen component = rtd->cpu_dai->component; 122370090bbbSLars-Peter Clausen if (component->driver->probe_order == order) { 1224f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, component); 122562ae68faSStephen Warren if (ret < 0) 122662ae68faSStephen Warren return ret; 122762ae68faSStephen Warren } 122862ae68faSStephen Warren 122988bd870fSBenoit Cousson /* probe the CODEC-side components */ 123088bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 123161aca564SLars-Peter Clausen component = rtd->codec_dais[i]->component; 123270090bbbSLars-Peter Clausen if (component->driver->probe_order == order) { 1233f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, component); 123462ae68faSStephen Warren if (ret < 0) 123562ae68faSStephen Warren return ret; 123662ae68faSStephen Warren } 123788bd870fSBenoit Cousson } 123862ae68faSStephen Warren 123962ae68faSStephen Warren /* probe the platform */ 124070090bbbSLars-Peter Clausen if (platform->component.driver->probe_order == order) { 1241f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, &platform->component); 124262ae68faSStephen Warren if (ret < 0) 124362ae68faSStephen Warren return ret; 124462ae68faSStephen Warren } 124562ae68faSStephen Warren 124662ae68faSStephen Warren return 0; 124762ae68faSStephen Warren } 124862ae68faSStephen Warren 12498e2be562SLars-Peter Clausen static int soc_probe_dai(struct snd_soc_dai *dai, int order) 1250b0aa88afSMisael Lopez Cruz { 1251b0aa88afSMisael Lopez Cruz int ret; 1252b0aa88afSMisael Lopez Cruz 12538e2be562SLars-Peter Clausen if (!dai->probed && dai->driver->probe_order == order) { 12548e2be562SLars-Peter Clausen if (dai->driver->probe) { 12558e2be562SLars-Peter Clausen ret = dai->driver->probe(dai); 1256b0aa88afSMisael Lopez Cruz if (ret < 0) { 12578e2be562SLars-Peter Clausen dev_err(dai->dev, 12588e2be562SLars-Peter Clausen "ASoC: failed to probe DAI %s: %d\n", 12598e2be562SLars-Peter Clausen dai->name, ret); 1260b0aa88afSMisael Lopez Cruz return ret; 1261b0aa88afSMisael Lopez Cruz } 1262b0aa88afSMisael Lopez Cruz } 1263b0aa88afSMisael Lopez Cruz 12648e2be562SLars-Peter Clausen dai->probed = 1; 1265b0aa88afSMisael Lopez Cruz } 1266b0aa88afSMisael Lopez Cruz 1267b0aa88afSMisael Lopez Cruz return 0; 1268b0aa88afSMisael Lopez Cruz } 1269b0aa88afSMisael Lopez Cruz 12702436a723SMisael Lopez Cruz static int soc_link_dai_widgets(struct snd_soc_card *card, 12712436a723SMisael Lopez Cruz struct snd_soc_dai_link *dai_link, 12723f901a02SBenoit Cousson struct snd_soc_pcm_runtime *rtd) 12732436a723SMisael Lopez Cruz { 12743f901a02SBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 12753f901a02SBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dai; 12762436a723SMisael Lopez Cruz struct snd_soc_dapm_widget *play_w, *capture_w; 12772436a723SMisael Lopez Cruz int ret; 12782436a723SMisael Lopez Cruz 127988bd870fSBenoit Cousson if (rtd->num_codecs > 1) 128088bd870fSBenoit Cousson dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n"); 128188bd870fSBenoit Cousson 12822436a723SMisael Lopez Cruz /* link the DAI widgets */ 12832436a723SMisael Lopez Cruz play_w = codec_dai->playback_widget; 12842436a723SMisael Lopez Cruz capture_w = cpu_dai->capture_widget; 12852436a723SMisael Lopez Cruz if (play_w && capture_w) { 12862436a723SMisael Lopez Cruz ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1287c6615082SNikesh Oswal dai_link->num_params, capture_w, 1288c6615082SNikesh Oswal play_w); 12892436a723SMisael Lopez Cruz if (ret != 0) { 12902436a723SMisael Lopez Cruz dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 12912436a723SMisael Lopez Cruz play_w->name, capture_w->name, ret); 12922436a723SMisael Lopez Cruz return ret; 12932436a723SMisael Lopez Cruz } 12942436a723SMisael Lopez Cruz } 12952436a723SMisael Lopez Cruz 12962436a723SMisael Lopez Cruz play_w = cpu_dai->playback_widget; 12972436a723SMisael Lopez Cruz capture_w = codec_dai->capture_widget; 12982436a723SMisael Lopez Cruz if (play_w && capture_w) { 12992436a723SMisael Lopez Cruz ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1300c6615082SNikesh Oswal dai_link->num_params, capture_w, 1301c6615082SNikesh Oswal play_w); 13022436a723SMisael Lopez Cruz if (ret != 0) { 13032436a723SMisael Lopez Cruz dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 13042436a723SMisael Lopez Cruz play_w->name, capture_w->name, ret); 13052436a723SMisael Lopez Cruz return ret; 13062436a723SMisael Lopez Cruz } 13072436a723SMisael Lopez Cruz } 13082436a723SMisael Lopez Cruz 13092436a723SMisael Lopez Cruz return 0; 13102436a723SMisael Lopez Cruz } 13112436a723SMisael Lopez Cruz 131262ae68faSStephen Warren static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) 1313f0fba2adSLiam Girdwood { 1314f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1315f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1316c74184edSMark Brown struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 131788bd870fSBenoit Cousson int i, ret; 1318f0fba2adSLiam Girdwood 1319f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", 13200168bf0dSLiam Girdwood card->name, num, order); 1321f0fba2adSLiam Girdwood 1322f0fba2adSLiam Girdwood /* set default power off timeout */ 1323f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1324f0fba2adSLiam Girdwood 13258e2be562SLars-Peter Clausen ret = soc_probe_dai(cpu_dai, order); 13268e2be562SLars-Peter Clausen if (ret) 1327f0fba2adSLiam Girdwood return ret; 1328f0fba2adSLiam Girdwood 1329f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 133088bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 13318e2be562SLars-Peter Clausen ret = soc_probe_dai(rtd->codec_dais[i], order); 1332b0aa88afSMisael Lopez Cruz if (ret) 1333f0fba2adSLiam Girdwood return ret; 133488bd870fSBenoit Cousson } 1335f0fba2adSLiam Girdwood 13360168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 13370168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 13380168bf0dSLiam Girdwood return 0; 13390168bf0dSLiam Girdwood 13405f3484acSLars-Peter Clausen /* do machine specific initialization */ 13415f3484acSLars-Peter Clausen if (dai_link->init) { 13425f3484acSLars-Peter Clausen ret = dai_link->init(rtd); 13435f3484acSLars-Peter Clausen if (ret < 0) { 13445f3484acSLars-Peter Clausen dev_err(card->dev, "ASoC: failed to init %s: %d\n", 13455f3484acSLars-Peter Clausen dai_link->name, ret); 13465f3484acSLars-Peter Clausen return ret; 13475f3484acSLars-Peter Clausen } 13485f3484acSLars-Peter Clausen } 13495f3484acSLars-Peter Clausen 1350a5053a8eSKuninori Morimoto if (dai_link->dai_fmt) 1351a5053a8eSKuninori Morimoto snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); 1352a5053a8eSKuninori Morimoto 13535f3484acSLars-Peter Clausen ret = soc_post_component_init(rtd, dai_link->name); 1354589c3563SJarkko Nikula if (ret) 1355f0fba2adSLiam Girdwood return ret; 1356f0fba2adSLiam Girdwood 13575f3484acSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 13585f3484acSLars-Peter Clausen /* add DPCM sysfs entries */ 13592e55b90aSLars-Peter Clausen if (dai_link->dynamic) 13602e55b90aSLars-Peter Clausen soc_dpcm_debugfs_add(rtd); 13615f3484acSLars-Peter Clausen #endif 13625f3484acSLars-Peter Clausen 13631245b700SNamarta Kohli if (cpu_dai->driver->compress_dai) { 13641245b700SNamarta Kohli /*create compress_device"*/ 13651245b700SNamarta Kohli ret = soc_new_compress(rtd, num); 13661245b700SNamarta Kohli if (ret < 0) { 1367f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create compress %s\n", 13681245b700SNamarta Kohli dai_link->stream_name); 13691245b700SNamarta Kohli return ret; 13701245b700SNamarta Kohli } 13711245b700SNamarta Kohli } else { 13721245b700SNamarta Kohli 1373c74184edSMark Brown if (!dai_link->params) { 1374f0fba2adSLiam Girdwood /* create the pcm */ 1375f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1376f0fba2adSLiam Girdwood if (ret < 0) { 1377f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", 13780837fc62SFabio Estevam dai_link->stream_name, ret); 1379f0fba2adSLiam Girdwood return ret; 1380f0fba2adSLiam Girdwood } 1381c74184edSMark Brown } else { 13829d58a077SRichard Fitzgerald INIT_DELAYED_WORK(&rtd->delayed_work, 13839d58a077SRichard Fitzgerald codec2codec_close_delayed_work); 13849d58a077SRichard Fitzgerald 1385c74184edSMark Brown /* link the DAI widgets */ 13863f901a02SBenoit Cousson ret = soc_link_dai_widgets(card, dai_link, rtd); 13872436a723SMisael Lopez Cruz if (ret) 1388c74184edSMark Brown return ret; 1389c74184edSMark Brown } 1390c74184edSMark Brown } 1391c74184edSMark Brown 1392f0fba2adSLiam Girdwood return 0; 1393f0fba2adSLiam Girdwood } 1394f0fba2adSLiam Girdwood 139544c69bb1SLars-Peter Clausen static int soc_bind_aux_dev(struct snd_soc_card *card, int num) 1396b19e6e7bSMark Brown { 139744c69bb1SLars-Peter Clausen struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 13983ca041edSSebastian Reichel struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 139965d9361fSLars-Peter Clausen const char *name = aux_dev->codec_name; 14003ca041edSSebastian Reichel 140165d9361fSLars-Peter Clausen rtd->component = soc_find_component(aux_dev->codec_of_node, name); 140265d9361fSLars-Peter Clausen if (!rtd->component) { 14033ca041edSSebastian Reichel if (aux_dev->codec_of_node) 140465d9361fSLars-Peter Clausen name = of_node_full_name(aux_dev->codec_of_node); 14053ca041edSSebastian Reichel 140665d9361fSLars-Peter Clausen dev_err(card->dev, "ASoC: %s not registered\n", name); 1407b19e6e7bSMark Brown return -EPROBE_DEFER; 1408b19e6e7bSMark Brown } 1409b19e6e7bSMark Brown 141065d9361fSLars-Peter Clausen /* 141165d9361fSLars-Peter Clausen * Some places still reference rtd->codec, so we have to keep that 141265d9361fSLars-Peter Clausen * initialized if the component is a CODEC. Once all those references 141365d9361fSLars-Peter Clausen * have been removed, this code can be removed as well. 141465d9361fSLars-Peter Clausen */ 141565d9361fSLars-Peter Clausen rtd->codec = rtd->component->codec; 141665d9361fSLars-Peter Clausen 141744c69bb1SLars-Peter Clausen return 0; 14183ca041edSSebastian Reichel } 14192eea392dSJarkko Nikula 142044c69bb1SLars-Peter Clausen static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 142144c69bb1SLars-Peter Clausen { 142244c69bb1SLars-Peter Clausen struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 14235f3484acSLars-Peter Clausen struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 142444c69bb1SLars-Peter Clausen int ret; 142544c69bb1SLars-Peter Clausen 142665d9361fSLars-Peter Clausen ret = soc_probe_component(card, rtd->component); 14272eea392dSJarkko Nikula if (ret < 0) 1428589c3563SJarkko Nikula return ret; 14292eea392dSJarkko Nikula 14305f3484acSLars-Peter Clausen /* do machine specific initialization */ 14315f3484acSLars-Peter Clausen if (aux_dev->init) { 143257bf7726SLars-Peter Clausen ret = aux_dev->init(rtd->component); 14335f3484acSLars-Peter Clausen if (ret < 0) { 14345f3484acSLars-Peter Clausen dev_err(card->dev, "ASoC: failed to init %s: %d\n", 14355f3484acSLars-Peter Clausen aux_dev->name, ret); 14362eea392dSJarkko Nikula return ret; 14372eea392dSJarkko Nikula } 14385f3484acSLars-Peter Clausen } 14395f3484acSLars-Peter Clausen 14405f3484acSLars-Peter Clausen return soc_post_component_init(rtd, aux_dev->name); 14412eea392dSJarkko Nikula } 14422eea392dSJarkko Nikula 14432eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 14442eea392dSJarkko Nikula { 14452eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 144665d9361fSLars-Peter Clausen struct snd_soc_component *component = rtd->component; 14472eea392dSJarkko Nikula 14482eea392dSJarkko Nikula /* unregister the rtd device */ 14492eea392dSJarkko Nikula if (rtd->dev_registered) { 1450d3bf1561SChuansheng Liu device_unregister(rtd->dev); 14512eea392dSJarkko Nikula rtd->dev_registered = 0; 14522eea392dSJarkko Nikula } 14532eea392dSJarkko Nikula 145465d9361fSLars-Peter Clausen if (component && component->probed) 145565d9361fSLars-Peter Clausen soc_remove_component(component); 14562eea392dSJarkko Nikula } 14572eea392dSJarkko Nikula 1458f90fb3f7SLars-Peter Clausen static int snd_soc_init_codec_cache(struct snd_soc_codec *codec) 1459fdf0f54dSDimitris Papastamos { 1460fdf0f54dSDimitris Papastamos int ret; 1461fdf0f54dSDimitris Papastamos 1462fdf0f54dSDimitris Papastamos if (codec->cache_init) 1463fdf0f54dSDimitris Papastamos return 0; 1464fdf0f54dSDimitris Papastamos 1465fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1466fdf0f54dSDimitris Papastamos if (ret < 0) { 146710e8aa9aSMichał Mirosław dev_err(codec->dev, 146810e8aa9aSMichał Mirosław "ASoC: Failed to set cache compression type: %d\n", 146910e8aa9aSMichał Mirosław ret); 1470fdf0f54dSDimitris Papastamos return ret; 1471fdf0f54dSDimitris Papastamos } 1472fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1473fdf0f54dSDimitris Papastamos return 0; 1474fdf0f54dSDimitris Papastamos } 1475fdf0f54dSDimitris Papastamos 1476ce64c8b9SLars-Peter Clausen /** 1477ce64c8b9SLars-Peter Clausen * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime 1478ce64c8b9SLars-Peter Clausen * @rtd: The runtime for which the DAI link format should be changed 1479ce64c8b9SLars-Peter Clausen * @dai_fmt: The new DAI link format 1480ce64c8b9SLars-Peter Clausen * 1481ce64c8b9SLars-Peter Clausen * This function updates the DAI link format for all DAIs connected to the DAI 1482ce64c8b9SLars-Peter Clausen * link for the specified runtime. 1483ce64c8b9SLars-Peter Clausen * 1484ce64c8b9SLars-Peter Clausen * Note: For setups with a static format set the dai_fmt field in the 1485ce64c8b9SLars-Peter Clausen * corresponding snd_dai_link struct instead of using this function. 1486ce64c8b9SLars-Peter Clausen * 1487ce64c8b9SLars-Peter Clausen * Returns 0 on success, otherwise a negative error code. 1488ce64c8b9SLars-Peter Clausen */ 1489ce64c8b9SLars-Peter Clausen int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, 1490ce64c8b9SLars-Peter Clausen unsigned int dai_fmt) 1491ce64c8b9SLars-Peter Clausen { 1492ce64c8b9SLars-Peter Clausen struct snd_soc_dai **codec_dais = rtd->codec_dais; 1493ce64c8b9SLars-Peter Clausen struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1494ce64c8b9SLars-Peter Clausen unsigned int i; 1495ce64c8b9SLars-Peter Clausen int ret; 1496ce64c8b9SLars-Peter Clausen 1497ce64c8b9SLars-Peter Clausen for (i = 0; i < rtd->num_codecs; i++) { 1498ce64c8b9SLars-Peter Clausen struct snd_soc_dai *codec_dai = codec_dais[i]; 1499ce64c8b9SLars-Peter Clausen 1500ce64c8b9SLars-Peter Clausen ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); 1501ce64c8b9SLars-Peter Clausen if (ret != 0 && ret != -ENOTSUPP) { 1502ce64c8b9SLars-Peter Clausen dev_warn(codec_dai->dev, 1503ce64c8b9SLars-Peter Clausen "ASoC: Failed to set DAI format: %d\n", ret); 1504ce64c8b9SLars-Peter Clausen return ret; 1505ce64c8b9SLars-Peter Clausen } 1506ce64c8b9SLars-Peter Clausen } 1507ce64c8b9SLars-Peter Clausen 1508ce64c8b9SLars-Peter Clausen /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */ 1509ce64c8b9SLars-Peter Clausen if (cpu_dai->codec) { 1510ce64c8b9SLars-Peter Clausen unsigned int inv_dai_fmt; 1511ce64c8b9SLars-Peter Clausen 1512ce64c8b9SLars-Peter Clausen inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK; 1513ce64c8b9SLars-Peter Clausen switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1514ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBM_CFM: 1515ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; 1516ce64c8b9SLars-Peter Clausen break; 1517ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBM_CFS: 1518ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; 1519ce64c8b9SLars-Peter Clausen break; 1520ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBS_CFM: 1521ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; 1522ce64c8b9SLars-Peter Clausen break; 1523ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBS_CFS: 1524ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 1525ce64c8b9SLars-Peter Clausen break; 1526ce64c8b9SLars-Peter Clausen } 1527ce64c8b9SLars-Peter Clausen 1528ce64c8b9SLars-Peter Clausen dai_fmt = inv_dai_fmt; 1529ce64c8b9SLars-Peter Clausen } 1530ce64c8b9SLars-Peter Clausen 1531ce64c8b9SLars-Peter Clausen ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); 1532ce64c8b9SLars-Peter Clausen if (ret != 0 && ret != -ENOTSUPP) { 1533ce64c8b9SLars-Peter Clausen dev_warn(cpu_dai->dev, 1534ce64c8b9SLars-Peter Clausen "ASoC: Failed to set DAI format: %d\n", ret); 1535ce64c8b9SLars-Peter Clausen return ret; 1536ce64c8b9SLars-Peter Clausen } 1537ce64c8b9SLars-Peter Clausen 1538ce64c8b9SLars-Peter Clausen return 0; 1539ce64c8b9SLars-Peter Clausen } 1540ddaca25aSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt); 1541ce64c8b9SLars-Peter Clausen 1542b19e6e7bSMark Brown static int snd_soc_instantiate_card(struct snd_soc_card *card) 1543f0fba2adSLiam Girdwood { 1544fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1545ce64c8b9SLars-Peter Clausen int ret, i, order; 154696dd3622SMark Brown 154734e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 154801b9d99aSLiam Girdwood mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); 1549f0fba2adSLiam Girdwood 1550b19e6e7bSMark Brown /* bind DAIs */ 1551b19e6e7bSMark Brown for (i = 0; i < card->num_links; i++) { 1552b19e6e7bSMark Brown ret = soc_bind_dai_link(card, i); 1553b19e6e7bSMark Brown if (ret != 0) 1554b19e6e7bSMark Brown goto base_error; 1555db2a4165SFrank Mandarino } 1556db2a4165SFrank Mandarino 155744c69bb1SLars-Peter Clausen /* bind aux_devs too */ 1558b19e6e7bSMark Brown for (i = 0; i < card->num_aux_devs; i++) { 155944c69bb1SLars-Peter Clausen ret = soc_bind_aux_dev(card, i); 1560b19e6e7bSMark Brown if (ret != 0) 1561b19e6e7bSMark Brown goto base_error; 1562db2a4165SFrank Mandarino } 1563db2a4165SFrank Mandarino 1564fdf0f54dSDimitris Papastamos /* initialize the register cache for each available codec */ 1565fdf0f54dSDimitris Papastamos list_for_each_entry(codec, &codec_list, list) { 1566fdf0f54dSDimitris Papastamos if (codec->cache_init) 1567fdf0f54dSDimitris Papastamos continue; 1568f90fb3f7SLars-Peter Clausen ret = snd_soc_init_codec_cache(codec); 1569b19e6e7bSMark Brown if (ret < 0) 1570b19e6e7bSMark Brown goto base_error; 1571fdf0f54dSDimitris Papastamos } 1572fdf0f54dSDimitris Papastamos 1573f0fba2adSLiam Girdwood /* card bind complete so register a sound card */ 1574102b5a8dSTakashi Iwai ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1575f0fba2adSLiam Girdwood card->owner, 0, &card->snd_card); 1576f0fba2adSLiam Girdwood if (ret < 0) { 157710e8aa9aSMichał Mirosław dev_err(card->dev, 157810e8aa9aSMichał Mirosław "ASoC: can't create sound card for card %s: %d\n", 157910e8aa9aSMichał Mirosław card->name, ret); 1580b19e6e7bSMark Brown goto base_error; 1581db2a4165SFrank Mandarino } 1582db2a4165SFrank Mandarino 15830757d834SLars-Peter Clausen soc_init_card_debugfs(card); 15840757d834SLars-Peter Clausen 1585e37a4970SMark Brown card->dapm.bias_level = SND_SOC_BIAS_OFF; 1586e37a4970SMark Brown card->dapm.dev = card->dev; 1587e37a4970SMark Brown card->dapm.card = card; 1588e37a4970SMark Brown list_add(&card->dapm.list, &card->dapm_list); 1589e37a4970SMark Brown 1590d5d1e0beSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 1591d5d1e0beSLars-Peter Clausen snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); 1592d5d1e0beSLars-Peter Clausen #endif 1593d5d1e0beSLars-Peter Clausen 159488ee1c61SMark Brown #ifdef CONFIG_PM_SLEEP 15956ed25978SAndy Green /* deferred resume work */ 15966308419aSMark Brown INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 15971301a964SRandy Dunlap #endif 15986ed25978SAndy Green 15999a841ebbSMark Brown if (card->dapm_widgets) 16009a841ebbSMark Brown snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 16019a841ebbSMark Brown card->num_dapm_widgets); 16029a841ebbSMark Brown 1603f23e860eSNicolin Chen if (card->of_dapm_widgets) 1604f23e860eSNicolin Chen snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, 1605f23e860eSNicolin Chen card->num_of_dapm_widgets); 1606f23e860eSNicolin Chen 1607f0fba2adSLiam Girdwood /* initialise the sound card only once */ 1608f0fba2adSLiam Girdwood if (card->probe) { 1609e7361ec4SMark Brown ret = card->probe(card); 1610f0fba2adSLiam Girdwood if (ret < 0) 1611f0fba2adSLiam Girdwood goto card_probe_error; 1612f0fba2adSLiam Girdwood } 1613f0fba2adSLiam Girdwood 161462ae68faSStephen Warren /* probe all components used by DAI links on this card */ 16150168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 16160168bf0dSLiam Girdwood order++) { 1617fe3e78e0SMark Brown for (i = 0; i < card->num_links; i++) { 161862ae68faSStephen Warren ret = soc_probe_link_components(card, i, order); 161962ae68faSStephen Warren if (ret < 0) { 1620f110bfc7SLiam Girdwood dev_err(card->dev, 1621f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1622f110bfc7SLiam Girdwood ret); 162362ae68faSStephen Warren goto probe_dai_err; 162462ae68faSStephen Warren } 162562ae68faSStephen Warren } 162662ae68faSStephen Warren } 162762ae68faSStephen Warren 162862ae68faSStephen Warren /* probe all DAI links on this card */ 162962ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 163062ae68faSStephen Warren order++) { 163162ae68faSStephen Warren for (i = 0; i < card->num_links; i++) { 163262ae68faSStephen Warren ret = soc_probe_link_dais(card, i, order); 1633fe3e78e0SMark Brown if (ret < 0) { 1634f110bfc7SLiam Girdwood dev_err(card->dev, 1635f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1636f110bfc7SLiam Girdwood ret); 1637f0fba2adSLiam Girdwood goto probe_dai_err; 1638fe3e78e0SMark Brown } 1639fe3e78e0SMark Brown } 16400168bf0dSLiam Girdwood } 1641fe3e78e0SMark Brown 16422eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) { 16432eea392dSJarkko Nikula ret = soc_probe_aux_dev(card, i); 16442eea392dSJarkko Nikula if (ret < 0) { 1645f110bfc7SLiam Girdwood dev_err(card->dev, 1646f110bfc7SLiam Girdwood "ASoC: failed to add auxiliary devices %d\n", 1647f110bfc7SLiam Girdwood ret); 16482eea392dSJarkko Nikula goto probe_aux_dev_err; 16492eea392dSJarkko Nikula } 16502eea392dSJarkko Nikula } 16512eea392dSJarkko Nikula 1652888df395SMark Brown snd_soc_dapm_link_dai_widgets(card); 1653b893ea5fSLiam Girdwood snd_soc_dapm_connect_dai_link_widgets(card); 1654888df395SMark Brown 1655b7af1dafSMark Brown if (card->controls) 1656022658beSLiam Girdwood snd_soc_add_card_controls(card, card->controls, card->num_controls); 1657b7af1dafSMark Brown 1658b8ad29deSMark Brown if (card->dapm_routes) 1659b8ad29deSMark Brown snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1660b8ad29deSMark Brown card->num_dapm_routes); 1661b8ad29deSMark Brown 1662f23e860eSNicolin Chen if (card->of_dapm_routes) 1663f23e860eSNicolin Chen snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, 1664f23e860eSNicolin Chen card->num_of_dapm_routes); 166575d9ac46SMark Brown 1666f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1667fe3e78e0SMark Brown "%s", card->name); 1668f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 166922de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1670f0e8ed85SMark Brown snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), 1671f0e8ed85SMark Brown "%s", card->driver_name ? card->driver_name : card->name); 1672f0e8ed85SMark Brown for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { 1673f0e8ed85SMark Brown switch (card->snd_card->driver[i]) { 1674f0e8ed85SMark Brown case '_': 1675f0e8ed85SMark Brown case '-': 1676f0e8ed85SMark Brown case '\0': 1677f0e8ed85SMark Brown break; 1678f0e8ed85SMark Brown default: 1679f0e8ed85SMark Brown if (!isalnum(card->snd_card->driver[i])) 1680f0e8ed85SMark Brown card->snd_card->driver[i] = '_'; 1681f0e8ed85SMark Brown break; 1682f0e8ed85SMark Brown } 1683f0e8ed85SMark Brown } 1684fe3e78e0SMark Brown 168528e9ad92SMark Brown if (card->late_probe) { 168628e9ad92SMark Brown ret = card->late_probe(card); 168728e9ad92SMark Brown if (ret < 0) { 1688f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", 168928e9ad92SMark Brown card->name, ret); 169028e9ad92SMark Brown goto probe_aux_dev_err; 169128e9ad92SMark Brown } 169228e9ad92SMark Brown } 169328e9ad92SMark Brown 1694824ef826SLars-Peter Clausen snd_soc_dapm_new_widgets(card); 16958c193b8dSLars-Peter Clausen 1696f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1697fe3e78e0SMark Brown if (ret < 0) { 1698f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: failed to register soundcard %d\n", 1699f110bfc7SLiam Girdwood ret); 17006b3ed785SAxel Lin goto probe_aux_dev_err; 1701fe3e78e0SMark Brown } 1702fe3e78e0SMark Brown 1703435c5e25SMark Brown card->instantiated = 1; 17044f4c0072SMark Brown snd_soc_dapm_sync(&card->dapm); 1705f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 170634e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 1707b19e6e7bSMark Brown 1708b19e6e7bSMark Brown return 0; 1709db2a4165SFrank Mandarino 17102eea392dSJarkko Nikula probe_aux_dev_err: 17112eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 17122eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 17132eea392dSJarkko Nikula 1714f0fba2adSLiam Girdwood probe_dai_err: 17150671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1716fe3e78e0SMark Brown 1717f0fba2adSLiam Girdwood card_probe_error: 171887506549SMark Brown if (card->remove) 1719e7361ec4SMark Brown card->remove(card); 1720f0fba2adSLiam Girdwood 17210757d834SLars-Peter Clausen soc_cleanup_card_debugfs(card); 1722f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1723f0fba2adSLiam Girdwood 1724b19e6e7bSMark Brown base_error: 1725f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 172634e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 1727db2a4165SFrank Mandarino 1728b19e6e7bSMark Brown return ret; 1729435c5e25SMark Brown } 1730435c5e25SMark Brown 1731435c5e25SMark Brown /* probes a new socdev */ 1732435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1733435c5e25SMark Brown { 1734f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1735435c5e25SMark Brown 173670a7ca34SVinod Koul /* 173770a7ca34SVinod Koul * no card, so machine driver should be registering card 173870a7ca34SVinod Koul * we should not be here in that case so ret error 173970a7ca34SVinod Koul */ 174070a7ca34SVinod Koul if (!card) 174170a7ca34SVinod Koul return -EINVAL; 174270a7ca34SVinod Koul 1743fe4085e8SMark Brown dev_warn(&pdev->dev, 1744f110bfc7SLiam Girdwood "ASoC: machine %s should use snd_soc_register_card()\n", 1745fe4085e8SMark Brown card->name); 1746fe4085e8SMark Brown 1747435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1748435c5e25SMark Brown card->dev = &pdev->dev; 1749f0fba2adSLiam Girdwood 175028d528c8SMark Brown return snd_soc_register_card(card); 1751435c5e25SMark Brown } 1752435c5e25SMark Brown 1753b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1754db2a4165SFrank Mandarino { 1755db2a4165SFrank Mandarino int i; 1756db2a4165SFrank Mandarino 1757f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1758f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1759f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 176043829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1761db2a4165SFrank Mandarino } 1762db2a4165SFrank Mandarino 17632eea392dSJarkko Nikula /* remove auxiliary devices */ 17642eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 17652eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 17662eea392dSJarkko Nikula 1767f0fba2adSLiam Girdwood /* remove and free each DAI */ 17680671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1769f0fba2adSLiam Girdwood 1770a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1771a6052154SJarkko Nikula 1772f0fba2adSLiam Girdwood /* remove the card */ 177387506549SMark Brown if (card->remove) 1774e7361ec4SMark Brown card->remove(card); 1775f0fba2adSLiam Girdwood 17760aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 17770aaae527SLars-Peter Clausen 1778f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1779b0e26485SVinod Koul return 0; 1780b0e26485SVinod Koul 1781b2dfa62cSGuennadi Liakhovetski } 1782b0e26485SVinod Koul 1783b0e26485SVinod Koul /* removes a socdev */ 1784b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1785b0e26485SVinod Koul { 1786b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1787b0e26485SVinod Koul 1788c5af3a2eSMark Brown snd_soc_unregister_card(card); 1789db2a4165SFrank Mandarino return 0; 1790db2a4165SFrank Mandarino } 1791db2a4165SFrank Mandarino 17926f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 179351737470SMark Brown { 17946f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1795f0fba2adSLiam Girdwood int i; 179651737470SMark Brown 179751737470SMark Brown if (!card->instantiated) 1798416356fcSMark Brown return 0; 179951737470SMark Brown 180051737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 180151737470SMark Brown * now, we're shutting down so no imminent restart. */ 1802f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1803f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 180443829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1805f0fba2adSLiam Girdwood } 180651737470SMark Brown 1807f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1808416356fcSMark Brown 1809988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 1810988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 181188bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 181288bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 181388bd870fSBenoit Cousson int j; 181488bd870fSBenoit Cousson 1815988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 181688bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 181788bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 181888bd870fSBenoit Cousson pinctrl_pm_select_sleep_state(codec_dai->dev); 181988bd870fSBenoit Cousson } 1820988e8cc4SNicolin Chen } 1821988e8cc4SNicolin Chen 1822416356fcSMark Brown return 0; 182351737470SMark Brown } 18246f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 182551737470SMark Brown 18266f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 1827b1dd5897SViresh Kumar .suspend = snd_soc_suspend, 1828b1dd5897SViresh Kumar .resume = snd_soc_resume, 1829b1dd5897SViresh Kumar .freeze = snd_soc_suspend, 1830b1dd5897SViresh Kumar .thaw = snd_soc_resume, 18316f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1832b1dd5897SViresh Kumar .restore = snd_soc_resume, 1833416356fcSMark Brown }; 1834deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1835416356fcSMark Brown 1836db2a4165SFrank Mandarino /* ASoC platform driver */ 1837db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1838db2a4165SFrank Mandarino .driver = { 1839db2a4165SFrank Mandarino .name = "soc-audio", 18406f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1841db2a4165SFrank Mandarino }, 1842db2a4165SFrank Mandarino .probe = soc_probe, 1843db2a4165SFrank Mandarino .remove = soc_remove, 1844db2a4165SFrank Mandarino }; 1845db2a4165SFrank Mandarino 1846096e49d5SMark Brown /** 1847db2a4165SFrank Mandarino * snd_soc_cnew - create new control 1848db2a4165SFrank Mandarino * @_template: control template 1849db2a4165SFrank Mandarino * @data: control private data 1850ac11a2b3SMark Brown * @long_name: control long name 1851efb7ac3fSMark Brown * @prefix: control name prefix 1852db2a4165SFrank Mandarino * 1853db2a4165SFrank Mandarino * Create a new mixer control from a template control. 1854db2a4165SFrank Mandarino * 1855db2a4165SFrank Mandarino * Returns 0 for success, else error. 1856db2a4165SFrank Mandarino */ 1857db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 18583056557fSMark Brown void *data, const char *long_name, 1859efb7ac3fSMark Brown const char *prefix) 1860db2a4165SFrank Mandarino { 1861db2a4165SFrank Mandarino struct snd_kcontrol_new template; 1862efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 1863efb7ac3fSMark Brown char *name = NULL; 1864db2a4165SFrank Mandarino 1865db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 1866db2a4165SFrank Mandarino template.index = 0; 1867db2a4165SFrank Mandarino 1868efb7ac3fSMark Brown if (!long_name) 1869efb7ac3fSMark Brown long_name = template.name; 1870efb7ac3fSMark Brown 1871efb7ac3fSMark Brown if (prefix) { 18722b581074SLars-Peter Clausen name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); 1873efb7ac3fSMark Brown if (!name) 1874efb7ac3fSMark Brown return NULL; 1875efb7ac3fSMark Brown 1876efb7ac3fSMark Brown template.name = name; 1877efb7ac3fSMark Brown } else { 1878efb7ac3fSMark Brown template.name = long_name; 1879efb7ac3fSMark Brown } 1880efb7ac3fSMark Brown 1881efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 1882efb7ac3fSMark Brown 1883efb7ac3fSMark Brown kfree(name); 1884efb7ac3fSMark Brown 1885efb7ac3fSMark Brown return kcontrol; 1886db2a4165SFrank Mandarino } 1887db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 1888db2a4165SFrank Mandarino 1889022658beSLiam Girdwood static int snd_soc_add_controls(struct snd_card *card, struct device *dev, 1890022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls, 1891022658beSLiam Girdwood const char *prefix, void *data) 1892022658beSLiam Girdwood { 1893022658beSLiam Girdwood int err, i; 1894022658beSLiam Girdwood 1895022658beSLiam Girdwood for (i = 0; i < num_controls; i++) { 1896022658beSLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 1897022658beSLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, data, 1898022658beSLiam Girdwood control->name, prefix)); 1899022658beSLiam Girdwood if (err < 0) { 1900f110bfc7SLiam Girdwood dev_err(dev, "ASoC: Failed to add %s: %d\n", 1901f110bfc7SLiam Girdwood control->name, err); 1902022658beSLiam Girdwood return err; 1903022658beSLiam Girdwood } 1904022658beSLiam Girdwood } 1905022658beSLiam Girdwood 1906022658beSLiam Girdwood return 0; 1907022658beSLiam Girdwood } 1908022658beSLiam Girdwood 19094fefd698SDimitris Papastamos struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, 19104fefd698SDimitris Papastamos const char *name) 19114fefd698SDimitris Papastamos { 19124fefd698SDimitris Papastamos struct snd_card *card = soc_card->snd_card; 19134fefd698SDimitris Papastamos struct snd_kcontrol *kctl; 19144fefd698SDimitris Papastamos 19154fefd698SDimitris Papastamos if (unlikely(!name)) 19164fefd698SDimitris Papastamos return NULL; 19174fefd698SDimitris Papastamos 19184fefd698SDimitris Papastamos list_for_each_entry(kctl, &card->controls, list) 19194fefd698SDimitris Papastamos if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) 19204fefd698SDimitris Papastamos return kctl; 19214fefd698SDimitris Papastamos return NULL; 19224fefd698SDimitris Papastamos } 19234fefd698SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); 19244fefd698SDimitris Papastamos 1925db2a4165SFrank Mandarino /** 19260f2780adSLars-Peter Clausen * snd_soc_add_component_controls - Add an array of controls to a component. 19270f2780adSLars-Peter Clausen * 19280f2780adSLars-Peter Clausen * @component: Component to add controls to 19290f2780adSLars-Peter Clausen * @controls: Array of controls to add 19300f2780adSLars-Peter Clausen * @num_controls: Number of elements in the array 19310f2780adSLars-Peter Clausen * 19320f2780adSLars-Peter Clausen * Return: 0 for success, else error. 19330f2780adSLars-Peter Clausen */ 19340f2780adSLars-Peter Clausen int snd_soc_add_component_controls(struct snd_soc_component *component, 19350f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 19360f2780adSLars-Peter Clausen { 19370f2780adSLars-Peter Clausen struct snd_card *card = component->card->snd_card; 19380f2780adSLars-Peter Clausen 19390f2780adSLars-Peter Clausen return snd_soc_add_controls(card, component->dev, controls, 19400f2780adSLars-Peter Clausen num_controls, component->name_prefix, component); 19410f2780adSLars-Peter Clausen } 19420f2780adSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); 19430f2780adSLars-Peter Clausen 19440f2780adSLars-Peter Clausen /** 1945022658beSLiam Girdwood * snd_soc_add_codec_controls - add an array of controls to a codec. 1946022658beSLiam Girdwood * Convenience function to add a list of controls. Many codecs were 19473e8e1952SIan Molton * duplicating this code. 19483e8e1952SIan Molton * 19493e8e1952SIan Molton * @codec: codec to add controls to 19503e8e1952SIan Molton * @controls: array of controls to add 19513e8e1952SIan Molton * @num_controls: number of elements in the array 19523e8e1952SIan Molton * 19533e8e1952SIan Molton * Return 0 for success, else error. 19543e8e1952SIan Molton */ 1955022658beSLiam Girdwood int snd_soc_add_codec_controls(struct snd_soc_codec *codec, 19560f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 19573e8e1952SIan Molton { 19580f2780adSLars-Peter Clausen return snd_soc_add_component_controls(&codec->component, controls, 19590f2780adSLars-Peter Clausen num_controls); 19603e8e1952SIan Molton } 1961022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); 19623e8e1952SIan Molton 19633e8e1952SIan Molton /** 1964a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 1965022658beSLiam Girdwood * Convenience function to add a list of controls. 1966a491a5c8SLiam Girdwood * 1967a491a5c8SLiam Girdwood * @platform: platform to add controls to 1968a491a5c8SLiam Girdwood * @controls: array of controls to add 1969a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 1970a491a5c8SLiam Girdwood * 1971a491a5c8SLiam Girdwood * Return 0 for success, else error. 1972a491a5c8SLiam Girdwood */ 1973a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 19740f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 1975a491a5c8SLiam Girdwood { 19760f2780adSLars-Peter Clausen return snd_soc_add_component_controls(&platform->component, controls, 19770f2780adSLars-Peter Clausen num_controls); 1978a491a5c8SLiam Girdwood } 1979a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 1980a491a5c8SLiam Girdwood 1981a491a5c8SLiam Girdwood /** 1982022658beSLiam Girdwood * snd_soc_add_card_controls - add an array of controls to a SoC card. 1983022658beSLiam Girdwood * Convenience function to add a list of controls. 1984022658beSLiam Girdwood * 1985022658beSLiam Girdwood * @soc_card: SoC card to add controls to 1986022658beSLiam Girdwood * @controls: array of controls to add 1987022658beSLiam Girdwood * @num_controls: number of elements in the array 1988022658beSLiam Girdwood * 1989022658beSLiam Girdwood * Return 0 for success, else error. 1990022658beSLiam Girdwood */ 1991022658beSLiam Girdwood int snd_soc_add_card_controls(struct snd_soc_card *soc_card, 1992022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 1993022658beSLiam Girdwood { 1994022658beSLiam Girdwood struct snd_card *card = soc_card->snd_card; 1995022658beSLiam Girdwood 1996022658beSLiam Girdwood return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, 1997022658beSLiam Girdwood NULL, soc_card); 1998022658beSLiam Girdwood } 1999022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); 2000022658beSLiam Girdwood 2001022658beSLiam Girdwood /** 2002022658beSLiam Girdwood * snd_soc_add_dai_controls - add an array of controls to a DAI. 2003022658beSLiam Girdwood * Convienience function to add a list of controls. 2004022658beSLiam Girdwood * 2005022658beSLiam Girdwood * @dai: DAI to add controls to 2006022658beSLiam Girdwood * @controls: array of controls to add 2007022658beSLiam Girdwood * @num_controls: number of elements in the array 2008022658beSLiam Girdwood * 2009022658beSLiam Girdwood * Return 0 for success, else error. 2010022658beSLiam Girdwood */ 2011022658beSLiam Girdwood int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 2012022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2013022658beSLiam Girdwood { 2014313665b9SLars-Peter Clausen struct snd_card *card = dai->component->card->snd_card; 2015022658beSLiam Girdwood 2016022658beSLiam Girdwood return snd_soc_add_controls(card, dai->dev, controls, num_controls, 2017022658beSLiam Girdwood NULL, dai); 2018022658beSLiam Girdwood } 2019022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); 2020022658beSLiam Girdwood 2021022658beSLiam Girdwood /** 20228c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 20238c6529dbSLiam Girdwood * @dai: DAI 20248c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 20258c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 20268c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 20278c6529dbSLiam Girdwood * 20288c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 20298c6529dbSLiam Girdwood */ 20308c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 20318c6529dbSLiam Girdwood unsigned int freq, int dir) 20328c6529dbSLiam Girdwood { 2033f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 2034f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2035ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 2036da1c6ea6SMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, 2037ec4ee52aSMark Brown freq, dir); 20388c6529dbSLiam Girdwood else 20391104a9c8SMark Brown return -ENOTSUPP; 20408c6529dbSLiam Girdwood } 20418c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 20428c6529dbSLiam Girdwood 20438c6529dbSLiam Girdwood /** 2044ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 2045ec4ee52aSMark Brown * @codec: CODEC 2046ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 2047da1c6ea6SMark Brown * @source: Source for the clock 2048ec4ee52aSMark Brown * @freq: new clock frequency in Hz 2049ec4ee52aSMark Brown * @dir: new clock direction - input/output. 2050ec4ee52aSMark Brown * 2051ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 2052ec4ee52aSMark Brown */ 2053ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 2054da1c6ea6SMark Brown int source, unsigned int freq, int dir) 2055ec4ee52aSMark Brown { 2056ec4ee52aSMark Brown if (codec->driver->set_sysclk) 2057da1c6ea6SMark Brown return codec->driver->set_sysclk(codec, clk_id, source, 2058da1c6ea6SMark Brown freq, dir); 2059ec4ee52aSMark Brown else 20601104a9c8SMark Brown return -ENOTSUPP; 2061ec4ee52aSMark Brown } 2062ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 2063ec4ee52aSMark Brown 2064ec4ee52aSMark Brown /** 20658c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 20668c6529dbSLiam Girdwood * @dai: DAI 2067ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 20688c6529dbSLiam Girdwood * @div: new clock divisor. 20698c6529dbSLiam Girdwood * 20708c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 20718c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 20728c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 20738c6529dbSLiam Girdwood */ 20748c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 20758c6529dbSLiam Girdwood int div_id, int div) 20768c6529dbSLiam Girdwood { 2077f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 2078f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 20798c6529dbSLiam Girdwood else 20808c6529dbSLiam Girdwood return -EINVAL; 20818c6529dbSLiam Girdwood } 20828c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 20838c6529dbSLiam Girdwood 20848c6529dbSLiam Girdwood /** 20858c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 20868c6529dbSLiam Girdwood * @dai: DAI 20878c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 208885488037SMark Brown * @source: DAI specific source for the PLL 20898c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 20908c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 20918c6529dbSLiam Girdwood * 20928c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 20938c6529dbSLiam Girdwood */ 209485488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 209585488037SMark Brown unsigned int freq_in, unsigned int freq_out) 20968c6529dbSLiam Girdwood { 2097f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 2098f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 209985488037SMark Brown freq_in, freq_out); 2100ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 2101ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 2102ec4ee52aSMark Brown freq_in, freq_out); 21038c6529dbSLiam Girdwood else 21048c6529dbSLiam Girdwood return -EINVAL; 21058c6529dbSLiam Girdwood } 21068c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 21078c6529dbSLiam Girdwood 2108ec4ee52aSMark Brown /* 2109ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 2110ec4ee52aSMark Brown * @codec: CODEC 2111ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 2112ec4ee52aSMark Brown * @source: DAI specific source for the PLL 2113ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 2114ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 2115ec4ee52aSMark Brown * 2116ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 2117ec4ee52aSMark Brown */ 2118ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 2119ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 2120ec4ee52aSMark Brown { 2121ec4ee52aSMark Brown if (codec->driver->set_pll) 2122ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 2123ec4ee52aSMark Brown freq_in, freq_out); 2124ec4ee52aSMark Brown else 2125ec4ee52aSMark Brown return -EINVAL; 2126ec4ee52aSMark Brown } 2127ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 2128ec4ee52aSMark Brown 21298c6529dbSLiam Girdwood /** 2130e54cf76bSLiam Girdwood * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. 2131e54cf76bSLiam Girdwood * @dai: DAI 2132e54cf76bSLiam Girdwood * @ratio Ratio of BCLK to Sample rate. 2133e54cf76bSLiam Girdwood * 2134e54cf76bSLiam Girdwood * Configures the DAI for a preset BCLK to sample rate ratio. 2135e54cf76bSLiam Girdwood */ 2136e54cf76bSLiam Girdwood int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) 2137e54cf76bSLiam Girdwood { 2138e54cf76bSLiam Girdwood if (dai->driver && dai->driver->ops->set_bclk_ratio) 2139e54cf76bSLiam Girdwood return dai->driver->ops->set_bclk_ratio(dai, ratio); 2140e54cf76bSLiam Girdwood else 2141e54cf76bSLiam Girdwood return -EINVAL; 2142e54cf76bSLiam Girdwood } 2143e54cf76bSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); 2144e54cf76bSLiam Girdwood 2145e54cf76bSLiam Girdwood /** 21468c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 21478c6529dbSLiam Girdwood * @dai: DAI 21488c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 21498c6529dbSLiam Girdwood * 21508c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 21518c6529dbSLiam Girdwood */ 21528c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 21538c6529dbSLiam Girdwood { 21545e4ba569SShawn Guo if (dai->driver == NULL) 21558c6529dbSLiam Girdwood return -EINVAL; 21565e4ba569SShawn Guo if (dai->driver->ops->set_fmt == NULL) 21575e4ba569SShawn Guo return -ENOTSUPP; 21585e4ba569SShawn Guo return dai->driver->ops->set_fmt(dai, fmt); 21598c6529dbSLiam Girdwood } 21608c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 21618c6529dbSLiam Girdwood 21628c6529dbSLiam Girdwood /** 2163e5c21514SXiubo Li * snd_soc_xlate_tdm_slot - generate tx/rx slot mask. 216489c67857SXiubo Li * @slots: Number of slots in use. 216589c67857SXiubo Li * @tx_mask: bitmask representing active TX slots. 216689c67857SXiubo Li * @rx_mask: bitmask representing active RX slots. 216789c67857SXiubo Li * 216889c67857SXiubo Li * Generates the TDM tx and rx slot default masks for DAI. 216989c67857SXiubo Li */ 2170e5c21514SXiubo Li static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, 217189c67857SXiubo Li unsigned int *tx_mask, 217289c67857SXiubo Li unsigned int *rx_mask) 217389c67857SXiubo Li { 217489c67857SXiubo Li if (*tx_mask || *rx_mask) 217589c67857SXiubo Li return 0; 217689c67857SXiubo Li 217789c67857SXiubo Li if (!slots) 217889c67857SXiubo Li return -EINVAL; 217989c67857SXiubo Li 218089c67857SXiubo Li *tx_mask = (1 << slots) - 1; 218189c67857SXiubo Li *rx_mask = (1 << slots) - 1; 218289c67857SXiubo Li 218389c67857SXiubo Li return 0; 218489c67857SXiubo Li } 218589c67857SXiubo Li 218689c67857SXiubo Li /** 2187e46c9366SLars-Peter Clausen * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation 2188e46c9366SLars-Peter Clausen * @dai: The DAI to configure 2189a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 2190a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 21918c6529dbSLiam Girdwood * @slots: Number of slots in use. 2192a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 21938c6529dbSLiam Girdwood * 2194e46c9366SLars-Peter Clausen * This function configures the specified DAI for TDM operation. @slot contains 2195e46c9366SLars-Peter Clausen * the total number of slots of the TDM stream and @slot_with the width of each 2196e46c9366SLars-Peter Clausen * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the 2197e46c9366SLars-Peter Clausen * active slots of the TDM stream for the specified DAI, i.e. which slots the 2198e46c9366SLars-Peter Clausen * DAI should write to or read from. If a bit is set the corresponding slot is 2199e46c9366SLars-Peter Clausen * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to 2200e46c9366SLars-Peter Clausen * the first slot, bit 1 to the second slot and so on. The first active slot 2201e46c9366SLars-Peter Clausen * maps to the first channel of the DAI, the second active slot to the second 2202e46c9366SLars-Peter Clausen * channel and so on. 2203e46c9366SLars-Peter Clausen * 2204e46c9366SLars-Peter Clausen * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask, 2205e46c9366SLars-Peter Clausen * @rx_mask and @slot_width will be ignored. 2206e46c9366SLars-Peter Clausen * 2207e46c9366SLars-Peter Clausen * Returns 0 on success, a negative error code otherwise. 22088c6529dbSLiam Girdwood */ 22098c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2210a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 22118c6529dbSLiam Girdwood { 2212e5c21514SXiubo Li if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) 2213e5c21514SXiubo Li dai->driver->ops->xlate_tdm_slot_mask(slots, 221489c67857SXiubo Li &tx_mask, &rx_mask); 221589c67857SXiubo Li else 2216e5c21514SXiubo Li snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); 221789c67857SXiubo Li 221888bd870fSBenoit Cousson dai->tx_mask = tx_mask; 221988bd870fSBenoit Cousson dai->rx_mask = rx_mask; 222088bd870fSBenoit Cousson 2221f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 2222f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2223a5479e38SDaniel Ribeiro slots, slot_width); 22248c6529dbSLiam Girdwood else 2225b2cbb6e1SXiubo Li return -ENOTSUPP; 22268c6529dbSLiam Girdwood } 22278c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 22288c6529dbSLiam Girdwood 22298c6529dbSLiam Girdwood /** 2230472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 2231472df3cbSBarry Song * @dai: DAI 2232472df3cbSBarry Song * @tx_num: how many TX channels 2233472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 2234472df3cbSBarry Song * 0~num-1 uses 2235472df3cbSBarry Song * @rx_num: how many RX channels 2236472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 2237472df3cbSBarry Song * 0~num-1 uses 2238472df3cbSBarry Song * 2239472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 2240472df3cbSBarry Song */ 2241472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 2242472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 2243472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 2244472df3cbSBarry Song { 2245f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 2246f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 2247472df3cbSBarry Song rx_num, rx_slot); 2248472df3cbSBarry Song else 2249472df3cbSBarry Song return -EINVAL; 2250472df3cbSBarry Song } 2251472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 2252472df3cbSBarry Song 2253472df3cbSBarry Song /** 22548c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 22558c6529dbSLiam Girdwood * @dai: DAI 22568c6529dbSLiam Girdwood * @tristate: tristate enable 22578c6529dbSLiam Girdwood * 22588c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 22598c6529dbSLiam Girdwood */ 22608c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 22618c6529dbSLiam Girdwood { 2262f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 2263f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 22648c6529dbSLiam Girdwood else 22658c6529dbSLiam Girdwood return -EINVAL; 22668c6529dbSLiam Girdwood } 22678c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 22688c6529dbSLiam Girdwood 22698c6529dbSLiam Girdwood /** 22708c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 22718c6529dbSLiam Girdwood * @dai: DAI 22728c6529dbSLiam Girdwood * @mute: mute enable 2273da18396fSMark Brown * @direction: stream to mute 22748c6529dbSLiam Girdwood * 22758c6529dbSLiam Girdwood * Mutes the DAI DAC. 22768c6529dbSLiam Girdwood */ 2277da18396fSMark Brown int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, 2278da18396fSMark Brown int direction) 22798c6529dbSLiam Girdwood { 2280da18396fSMark Brown if (!dai->driver) 2281da18396fSMark Brown return -ENOTSUPP; 2282da18396fSMark Brown 2283da18396fSMark Brown if (dai->driver->ops->mute_stream) 2284da18396fSMark Brown return dai->driver->ops->mute_stream(dai, mute, direction); 2285da18396fSMark Brown else if (direction == SNDRV_PCM_STREAM_PLAYBACK && 2286da18396fSMark Brown dai->driver->ops->digital_mute) 2287f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 22888c6529dbSLiam Girdwood else 228904570c62SMark Brown return -ENOTSUPP; 22908c6529dbSLiam Girdwood } 22918c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 22928c6529dbSLiam Girdwood 229388bd870fSBenoit Cousson static int snd_soc_init_multicodec(struct snd_soc_card *card, 229488bd870fSBenoit Cousson struct snd_soc_dai_link *dai_link) 229588bd870fSBenoit Cousson { 229688bd870fSBenoit Cousson /* Legacy codec/codec_dai link is a single entry in multicodec */ 229788bd870fSBenoit Cousson if (dai_link->codec_name || dai_link->codec_of_node || 229888bd870fSBenoit Cousson dai_link->codec_dai_name) { 229988bd870fSBenoit Cousson dai_link->num_codecs = 1; 230088bd870fSBenoit Cousson 230188bd870fSBenoit Cousson dai_link->codecs = devm_kzalloc(card->dev, 230288bd870fSBenoit Cousson sizeof(struct snd_soc_dai_link_component), 230388bd870fSBenoit Cousson GFP_KERNEL); 230488bd870fSBenoit Cousson if (!dai_link->codecs) 230588bd870fSBenoit Cousson return -ENOMEM; 230688bd870fSBenoit Cousson 230788bd870fSBenoit Cousson dai_link->codecs[0].name = dai_link->codec_name; 230888bd870fSBenoit Cousson dai_link->codecs[0].of_node = dai_link->codec_of_node; 230988bd870fSBenoit Cousson dai_link->codecs[0].dai_name = dai_link->codec_dai_name; 231088bd870fSBenoit Cousson } 231188bd870fSBenoit Cousson 231288bd870fSBenoit Cousson if (!dai_link->codecs) { 231388bd870fSBenoit Cousson dev_err(card->dev, "ASoC: DAI link has no CODECs\n"); 231488bd870fSBenoit Cousson return -EINVAL; 231588bd870fSBenoit Cousson } 231688bd870fSBenoit Cousson 231788bd870fSBenoit Cousson return 0; 231888bd870fSBenoit Cousson } 231988bd870fSBenoit Cousson 2320c5af3a2eSMark Brown /** 2321c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 2322c5af3a2eSMark Brown * 2323ac11a2b3SMark Brown * @card: Card to register 2324c5af3a2eSMark Brown * 2325c5af3a2eSMark Brown */ 232670a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 2327c5af3a2eSMark Brown { 232888bd870fSBenoit Cousson int i, j, ret; 2329f0fba2adSLiam Girdwood 2330c5af3a2eSMark Brown if (!card->name || !card->dev) 2331c5af3a2eSMark Brown return -EINVAL; 2332c5af3a2eSMark Brown 23335a504963SStephen Warren for (i = 0; i < card->num_links; i++) { 23345a504963SStephen Warren struct snd_soc_dai_link *link = &card->dai_link[i]; 23355a504963SStephen Warren 233688bd870fSBenoit Cousson ret = snd_soc_init_multicodec(card, link); 233788bd870fSBenoit Cousson if (ret) { 233888bd870fSBenoit Cousson dev_err(card->dev, "ASoC: failed to init multicodec\n"); 233988bd870fSBenoit Cousson return ret; 234088bd870fSBenoit Cousson } 234188bd870fSBenoit Cousson 234288bd870fSBenoit Cousson for (j = 0; j < link->num_codecs; j++) { 23435a504963SStephen Warren /* 23445a504963SStephen Warren * Codec must be specified by 1 of name or OF node, 23455a504963SStephen Warren * not both or neither. 23465a504963SStephen Warren */ 234788bd870fSBenoit Cousson if (!!link->codecs[j].name == 234888bd870fSBenoit Cousson !!link->codecs[j].of_node) { 234988bd870fSBenoit Cousson dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", 235010e8aa9aSMichał Mirosław link->name); 23515a504963SStephen Warren return -EINVAL; 23525a504963SStephen Warren } 2353bc92657aSStephen Warren /* Codec DAI name must be specified */ 235488bd870fSBenoit Cousson if (!link->codecs[j].dai_name) { 235588bd870fSBenoit Cousson dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", 235610e8aa9aSMichał Mirosław link->name); 2357bc92657aSStephen Warren return -EINVAL; 2358bc92657aSStephen Warren } 235988bd870fSBenoit Cousson } 23605a504963SStephen Warren 23615a504963SStephen Warren /* 23625a504963SStephen Warren * Platform may be specified by either name or OF node, but 23635a504963SStephen Warren * can be left unspecified, and a dummy platform will be used. 23645a504963SStephen Warren */ 23655a504963SStephen Warren if (link->platform_name && link->platform_of_node) { 236610e8aa9aSMichał Mirosław dev_err(card->dev, 236710e8aa9aSMichał Mirosław "ASoC: Both platform name/of_node are set for %s\n", 236810e8aa9aSMichał Mirosław link->name); 23695a504963SStephen Warren return -EINVAL; 23705a504963SStephen Warren } 23715a504963SStephen Warren 23725a504963SStephen Warren /* 2373bc92657aSStephen Warren * CPU device may be specified by either name or OF node, but 2374bc92657aSStephen Warren * can be left unspecified, and will be matched based on DAI 2375bc92657aSStephen Warren * name alone.. 23765a504963SStephen Warren */ 2377bc92657aSStephen Warren if (link->cpu_name && link->cpu_of_node) { 237810e8aa9aSMichał Mirosław dev_err(card->dev, 237910e8aa9aSMichał Mirosław "ASoC: Neither/both cpu name/of_node are set for %s\n", 238010e8aa9aSMichał Mirosław link->name); 2381bc92657aSStephen Warren return -EINVAL; 2382bc92657aSStephen Warren } 2383bc92657aSStephen Warren /* 2384bc92657aSStephen Warren * At least one of CPU DAI name or CPU device name/node must be 2385bc92657aSStephen Warren * specified 2386bc92657aSStephen Warren */ 2387bc92657aSStephen Warren if (!link->cpu_dai_name && 2388bc92657aSStephen Warren !(link->cpu_name || link->cpu_of_node)) { 238910e8aa9aSMichał Mirosław dev_err(card->dev, 239010e8aa9aSMichał Mirosław "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", 239110e8aa9aSMichał Mirosław link->name); 23925a504963SStephen Warren return -EINVAL; 23935a504963SStephen Warren } 23945a504963SStephen Warren } 23955a504963SStephen Warren 2396ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 2397ed77cc12SMark Brown 2398111c6419SStephen Warren snd_soc_initialize_card_lists(card); 2399111c6419SStephen Warren 2400181a6892SMark Brown card->rtd = devm_kzalloc(card->dev, 2401181a6892SMark Brown sizeof(struct snd_soc_pcm_runtime) * 24022eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 2403f0fba2adSLiam Girdwood GFP_KERNEL); 2404f0fba2adSLiam Girdwood if (card->rtd == NULL) 2405f0fba2adSLiam Girdwood return -ENOMEM; 2406a7dbb603SLiam Girdwood card->num_rtd = 0; 24072eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 2408f0fba2adSLiam Girdwood 24095f3484acSLars-Peter Clausen for (i = 0; i < card->num_links; i++) { 24105f3484acSLars-Peter Clausen card->rtd[i].card = card; 2411f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 241288bd870fSBenoit Cousson card->rtd[i].codec_dais = devm_kzalloc(card->dev, 241388bd870fSBenoit Cousson sizeof(struct snd_soc_dai *) * 241488bd870fSBenoit Cousson (card->rtd[i].dai_link->num_codecs), 241588bd870fSBenoit Cousson GFP_KERNEL); 241688bd870fSBenoit Cousson if (card->rtd[i].codec_dais == NULL) 241788bd870fSBenoit Cousson return -ENOMEM; 24185f3484acSLars-Peter Clausen } 24195f3484acSLars-Peter Clausen 24205f3484acSLars-Peter Clausen for (i = 0; i < card->num_aux_devs; i++) 24215f3484acSLars-Peter Clausen card->rtd_aux[i].card = card; 2422f0fba2adSLiam Girdwood 2423db432b41SMark Brown INIT_LIST_HEAD(&card->dapm_dirty); 24248a978234SLiam Girdwood INIT_LIST_HEAD(&card->dobj_list); 2425c5af3a2eSMark Brown card->instantiated = 0; 2426f0fba2adSLiam Girdwood mutex_init(&card->mutex); 2427a73fb2dfSLiam Girdwood mutex_init(&card->dapm_mutex); 2428c5af3a2eSMark Brown 2429b19e6e7bSMark Brown ret = snd_soc_instantiate_card(card); 2430b19e6e7bSMark Brown if (ret != 0) 24314e2576bdSKuninori Morimoto return ret; 2432c5af3a2eSMark Brown 2433988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 2434988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 243588bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 243688bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 243788bd870fSBenoit Cousson int j; 243888bd870fSBenoit Cousson 243988bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 244088bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 2441988e8cc4SNicolin Chen if (!codec_dai->active) 2442988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(codec_dai->dev); 244388bd870fSBenoit Cousson } 244488bd870fSBenoit Cousson 2445988e8cc4SNicolin Chen if (!cpu_dai->active) 2446988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 2447988e8cc4SNicolin Chen } 2448988e8cc4SNicolin Chen 2449b19e6e7bSMark Brown return ret; 2450c5af3a2eSMark Brown } 245170a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 2452c5af3a2eSMark Brown 2453c5af3a2eSMark Brown /** 2454c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 2455c5af3a2eSMark Brown * 2456ac11a2b3SMark Brown * @card: Card to unregister 2457c5af3a2eSMark Brown * 2458c5af3a2eSMark Brown */ 245970a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 2460c5af3a2eSMark Brown { 246101e0df66SLars-Peter Clausen if (card->instantiated) { 246201e0df66SLars-Peter Clausen card->instantiated = false; 24631c325f77SLars-Peter Clausen snd_soc_dapm_shutdown(card); 2464b0e26485SVinod Koul soc_cleanup_card_resources(card); 2465f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); 24668f6f9b29SKuninori Morimoto } 2467c5af3a2eSMark Brown 2468c5af3a2eSMark Brown return 0; 2469c5af3a2eSMark Brown } 247070a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 2471c5af3a2eSMark Brown 2472f0fba2adSLiam Girdwood /* 2473f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 2474f0fba2adSLiam Girdwood * and sanitizing names. 2475f0fba2adSLiam Girdwood */ 24760b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 2477f0fba2adSLiam Girdwood { 2478f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 2479f0fba2adSLiam Girdwood int id1, id2; 2480f0fba2adSLiam Girdwood 2481f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 2482f0fba2adSLiam Girdwood return NULL; 2483f0fba2adSLiam Girdwood 248458818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 2485f0fba2adSLiam Girdwood 2486f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 2487f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 2488f0fba2adSLiam Girdwood if (found) { 2489f0fba2adSLiam Girdwood /* get ID */ 2490f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 2491f0fba2adSLiam Girdwood 2492f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 2493f0fba2adSLiam Girdwood if (*id == -1) 2494f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 2495f0fba2adSLiam Girdwood } 2496f0fba2adSLiam Girdwood 2497f0fba2adSLiam Girdwood } else { 2498f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 2499f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 2500f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 2501f0fba2adSLiam Girdwood 2502f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 250305899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 2504f0fba2adSLiam Girdwood 2505f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 2506f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 250758818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 2508f0fba2adSLiam Girdwood } else 2509f0fba2adSLiam Girdwood *id = 0; 2510f0fba2adSLiam Girdwood } 2511f0fba2adSLiam Girdwood 2512f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 2513f0fba2adSLiam Girdwood } 2514f0fba2adSLiam Girdwood 2515f0fba2adSLiam Girdwood /* 2516f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 2517f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 2518f0fba2adSLiam Girdwood */ 2519f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 2520f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 2521f0fba2adSLiam Girdwood { 2522f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 252310e8aa9aSMichał Mirosław dev_err(dev, 252410e8aa9aSMichał Mirosław "ASoC: error - multiple DAI %s registered with no name\n", 252510e8aa9aSMichał Mirosław dev_name(dev)); 2526f0fba2adSLiam Girdwood return NULL; 2527f0fba2adSLiam Girdwood } 2528f0fba2adSLiam Girdwood 2529f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 2530f0fba2adSLiam Girdwood } 2531f0fba2adSLiam Girdwood 25329115171aSMark Brown /** 253332c9ba54SLars-Peter Clausen * snd_soc_unregister_dai - Unregister DAIs from the ASoC core 25349115171aSMark Brown * 253532c9ba54SLars-Peter Clausen * @component: The component for which the DAIs should be unregistered 25369115171aSMark Brown */ 253732c9ba54SLars-Peter Clausen static void snd_soc_unregister_dais(struct snd_soc_component *component) 25389115171aSMark Brown { 25395c1d5f09SLars-Peter Clausen struct snd_soc_dai *dai, *_dai; 25409115171aSMark Brown 25415c1d5f09SLars-Peter Clausen list_for_each_entry_safe(dai, _dai, &component->dai_list, list) { 254232c9ba54SLars-Peter Clausen dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n", 254332c9ba54SLars-Peter Clausen dai->name); 25449115171aSMark Brown list_del(&dai->list); 2545f0fba2adSLiam Girdwood kfree(dai->name); 2546f0fba2adSLiam Girdwood kfree(dai); 25479115171aSMark Brown } 254832c9ba54SLars-Peter Clausen } 25499115171aSMark Brown 25509115171aSMark Brown /** 255132c9ba54SLars-Peter Clausen * snd_soc_register_dais - Register a DAI with the ASoC core 25529115171aSMark Brown * 25536106d129SLars-Peter Clausen * @component: The component the DAIs are registered for 25546106d129SLars-Peter Clausen * @dai_drv: DAI driver to use for the DAIs 2555ac11a2b3SMark Brown * @count: Number of DAIs 255632c9ba54SLars-Peter Clausen * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the 255732c9ba54SLars-Peter Clausen * parent's name. 25589115171aSMark Brown */ 255932c9ba54SLars-Peter Clausen static int snd_soc_register_dais(struct snd_soc_component *component, 2560bb13109dSLars-Peter Clausen struct snd_soc_dai_driver *dai_drv, size_t count, 2561bb13109dSLars-Peter Clausen bool legacy_dai_naming) 25629115171aSMark Brown { 25636106d129SLars-Peter Clausen struct device *dev = component->dev; 2564f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 256532c9ba54SLars-Peter Clausen unsigned int i; 256632c9ba54SLars-Peter Clausen int ret; 2567f0fba2adSLiam Girdwood 2568f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); 25699115171aSMark Brown 2570bb13109dSLars-Peter Clausen component->dai_drv = dai_drv; 2571bb13109dSLars-Peter Clausen component->num_dai = count; 2572bb13109dSLars-Peter Clausen 25739115171aSMark Brown for (i = 0; i < count; i++) { 2574f0fba2adSLiam Girdwood 2575f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 2576c46e0079SAxel Lin if (dai == NULL) { 2577c46e0079SAxel Lin ret = -ENOMEM; 2578c46e0079SAxel Lin goto err; 2579c46e0079SAxel Lin } 2580f0fba2adSLiam Girdwood 258132c9ba54SLars-Peter Clausen /* 258232c9ba54SLars-Peter Clausen * Back in the old days when we still had component-less DAIs, 258332c9ba54SLars-Peter Clausen * instead of having a static name, component-less DAIs would 258432c9ba54SLars-Peter Clausen * inherit the name of the parent device so it is possible to 258532c9ba54SLars-Peter Clausen * register multiple instances of the DAI. We still need to keep 258632c9ba54SLars-Peter Clausen * the same naming style even though those DAIs are not 258732c9ba54SLars-Peter Clausen * component-less anymore. 258832c9ba54SLars-Peter Clausen */ 25899e498089SSrinivas Kandagatla if (count == 1 && legacy_dai_naming && 25909e498089SSrinivas Kandagatla (dai_drv[i].id == 0 || dai_drv[i].name == NULL)) { 2591db2a4165SFrank Mandarino dai->name = fmt_single_name(dev, &dai->id); 259232c9ba54SLars-Peter Clausen } else { 2593f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 259432c9ba54SLars-Peter Clausen if (dai_drv[i].id) 259532c9ba54SLars-Peter Clausen dai->id = dai_drv[i].id; 259632c9ba54SLars-Peter Clausen else 259732c9ba54SLars-Peter Clausen dai->id = i; 259832c9ba54SLars-Peter Clausen } 2599f0fba2adSLiam Girdwood if (dai->name == NULL) { 2600f0fba2adSLiam Girdwood kfree(dai); 260132c9ba54SLars-Peter Clausen ret = -ENOMEM; 26029115171aSMark Brown goto err; 26039115171aSMark Brown } 26049115171aSMark Brown 26056106d129SLars-Peter Clausen dai->component = component; 2606f0fba2adSLiam Girdwood dai->dev = dev; 2607f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 2608f0fba2adSLiam Girdwood if (!dai->driver->ops) 2609f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 2610f0fba2adSLiam Girdwood 26111438c2f6SLars-Peter Clausen list_add(&dai->list, &component->dai_list); 2612054880feSMark Brown 26139115171aSMark Brown dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); 2614f0fba2adSLiam Girdwood } 2615f0fba2adSLiam Girdwood 26169115171aSMark Brown return 0; 26179115171aSMark Brown 26189115171aSMark Brown err: 261932c9ba54SLars-Peter Clausen snd_soc_unregister_dais(component); 26209115171aSMark Brown 26219115171aSMark Brown return ret; 26229115171aSMark Brown } 26239115171aSMark Brown 262414e8bdebSLars-Peter Clausen static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm, 262514e8bdebSLars-Peter Clausen enum snd_soc_dapm_type type, int subseq) 2626d191bd8dSKuninori Morimoto { 262714e8bdebSLars-Peter Clausen struct snd_soc_component *component = dapm->component; 2628d191bd8dSKuninori Morimoto 262914e8bdebSLars-Peter Clausen component->driver->seq_notifier(component, type, subseq); 263014e8bdebSLars-Peter Clausen } 2631d191bd8dSKuninori Morimoto 263214e8bdebSLars-Peter Clausen static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, 263314e8bdebSLars-Peter Clausen int event) 263414e8bdebSLars-Peter Clausen { 263514e8bdebSLars-Peter Clausen struct snd_soc_component *component = dapm->component; 263614e8bdebSLars-Peter Clausen 263714e8bdebSLars-Peter Clausen return component->driver->stream_event(component, event); 263814e8bdebSLars-Peter Clausen } 263914e8bdebSLars-Peter Clausen 2640bb13109dSLars-Peter Clausen static int snd_soc_component_initialize(struct snd_soc_component *component, 2641bb13109dSLars-Peter Clausen const struct snd_soc_component_driver *driver, struct device *dev) 2642d191bd8dSKuninori Morimoto { 2643ce0fc93aSLars-Peter Clausen struct snd_soc_dapm_context *dapm; 2644ce0fc93aSLars-Peter Clausen 2645bb13109dSLars-Peter Clausen component->name = fmt_single_name(dev, &component->id); 2646bb13109dSLars-Peter Clausen if (!component->name) { 2647bb13109dSLars-Peter Clausen dev_err(dev, "ASoC: Failed to allocate name\n"); 2648d191bd8dSKuninori Morimoto return -ENOMEM; 2649d191bd8dSKuninori Morimoto } 2650d191bd8dSKuninori Morimoto 2651bb13109dSLars-Peter Clausen component->dev = dev; 2652bb13109dSLars-Peter Clausen component->driver = driver; 265361aca564SLars-Peter Clausen component->probe = component->driver->probe; 265461aca564SLars-Peter Clausen component->remove = component->driver->remove; 2655e2c330b9SLars-Peter Clausen 2656*4890140fSLars-Peter Clausen dapm = &component->dapm; 2657ce0fc93aSLars-Peter Clausen dapm->dev = dev; 2658ce0fc93aSLars-Peter Clausen dapm->component = component; 2659ce0fc93aSLars-Peter Clausen dapm->bias_level = SND_SOC_BIAS_OFF; 26605819c2faSLars-Peter Clausen dapm->idle_bias_off = true; 266114e8bdebSLars-Peter Clausen if (driver->seq_notifier) 266214e8bdebSLars-Peter Clausen dapm->seq_notifier = snd_soc_component_seq_notifier; 266314e8bdebSLars-Peter Clausen if (driver->stream_event) 266414e8bdebSLars-Peter Clausen dapm->stream_event = snd_soc_component_stream_event; 2665ce0fc93aSLars-Peter Clausen 266661aca564SLars-Peter Clausen component->controls = driver->controls; 266761aca564SLars-Peter Clausen component->num_controls = driver->num_controls; 266861aca564SLars-Peter Clausen component->dapm_widgets = driver->dapm_widgets; 266961aca564SLars-Peter Clausen component->num_dapm_widgets = driver->num_dapm_widgets; 267061aca564SLars-Peter Clausen component->dapm_routes = driver->dapm_routes; 267161aca564SLars-Peter Clausen component->num_dapm_routes = driver->num_dapm_routes; 267261aca564SLars-Peter Clausen 2673bb13109dSLars-Peter Clausen INIT_LIST_HEAD(&component->dai_list); 2674bb13109dSLars-Peter Clausen mutex_init(&component->io_mutex); 2675bb13109dSLars-Peter Clausen 2676bb13109dSLars-Peter Clausen return 0; 2677d191bd8dSKuninori Morimoto } 2678d191bd8dSKuninori Morimoto 267920feb881SLars-Peter Clausen static void snd_soc_component_setup_regmap(struct snd_soc_component *component) 2680886f5692SLars-Peter Clausen { 2681886f5692SLars-Peter Clausen int val_bytes = regmap_get_val_bytes(component->regmap); 268220feb881SLars-Peter Clausen 2683886f5692SLars-Peter Clausen /* Errors are legitimate for non-integer byte multiples */ 2684886f5692SLars-Peter Clausen if (val_bytes > 0) 2685886f5692SLars-Peter Clausen component->val_bytes = val_bytes; 2686886f5692SLars-Peter Clausen } 268720feb881SLars-Peter Clausen 2688e874bf5fSLars-Peter Clausen #ifdef CONFIG_REGMAP 2689e874bf5fSLars-Peter Clausen 269020feb881SLars-Peter Clausen /** 269120feb881SLars-Peter Clausen * snd_soc_component_init_regmap() - Initialize regmap instance for the component 269220feb881SLars-Peter Clausen * @component: The component for which to initialize the regmap instance 269320feb881SLars-Peter Clausen * @regmap: The regmap instance that should be used by the component 269420feb881SLars-Peter Clausen * 269520feb881SLars-Peter Clausen * This function allows deferred assignment of the regmap instance that is 269620feb881SLars-Peter Clausen * associated with the component. Only use this if the regmap instance is not 269720feb881SLars-Peter Clausen * yet ready when the component is registered. The function must also be called 269820feb881SLars-Peter Clausen * before the first IO attempt of the component. 269920feb881SLars-Peter Clausen */ 270020feb881SLars-Peter Clausen void snd_soc_component_init_regmap(struct snd_soc_component *component, 270120feb881SLars-Peter Clausen struct regmap *regmap) 270220feb881SLars-Peter Clausen { 270320feb881SLars-Peter Clausen component->regmap = regmap; 270420feb881SLars-Peter Clausen snd_soc_component_setup_regmap(component); 2705886f5692SLars-Peter Clausen } 270620feb881SLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); 270720feb881SLars-Peter Clausen 270820feb881SLars-Peter Clausen /** 270920feb881SLars-Peter Clausen * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component 271020feb881SLars-Peter Clausen * @component: The component for which to de-initialize the regmap instance 271120feb881SLars-Peter Clausen * 271220feb881SLars-Peter Clausen * Calls regmap_exit() on the regmap instance associated to the component and 271320feb881SLars-Peter Clausen * removes the regmap instance from the component. 271420feb881SLars-Peter Clausen * 271520feb881SLars-Peter Clausen * This function should only be used if snd_soc_component_init_regmap() was used 271620feb881SLars-Peter Clausen * to initialize the regmap instance. 271720feb881SLars-Peter Clausen */ 271820feb881SLars-Peter Clausen void snd_soc_component_exit_regmap(struct snd_soc_component *component) 271920feb881SLars-Peter Clausen { 272020feb881SLars-Peter Clausen regmap_exit(component->regmap); 272120feb881SLars-Peter Clausen component->regmap = NULL; 272220feb881SLars-Peter Clausen } 272320feb881SLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); 2724886f5692SLars-Peter Clausen 2725e874bf5fSLars-Peter Clausen #endif 2726d191bd8dSKuninori Morimoto 2727bb13109dSLars-Peter Clausen static void snd_soc_component_add_unlocked(struct snd_soc_component *component) 2728bb13109dSLars-Peter Clausen { 272920feb881SLars-Peter Clausen if (!component->write && !component->read) { 273020feb881SLars-Peter Clausen if (!component->regmap) 273120feb881SLars-Peter Clausen component->regmap = dev_get_regmap(component->dev, NULL); 273220feb881SLars-Peter Clausen if (component->regmap) 273320feb881SLars-Peter Clausen snd_soc_component_setup_regmap(component); 273420feb881SLars-Peter Clausen } 2735886f5692SLars-Peter Clausen 2736bb13109dSLars-Peter Clausen list_add(&component->list, &component_list); 27378a978234SLiam Girdwood INIT_LIST_HEAD(&component->dobj_list); 2738d191bd8dSKuninori Morimoto } 2739d191bd8dSKuninori Morimoto 2740bb13109dSLars-Peter Clausen static void snd_soc_component_add(struct snd_soc_component *component) 2741bb13109dSLars-Peter Clausen { 2742d191bd8dSKuninori Morimoto mutex_lock(&client_mutex); 2743bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(component); 2744d191bd8dSKuninori Morimoto mutex_unlock(&client_mutex); 2745bb13109dSLars-Peter Clausen } 2746d191bd8dSKuninori Morimoto 2747bb13109dSLars-Peter Clausen static void snd_soc_component_cleanup(struct snd_soc_component *component) 2748bb13109dSLars-Peter Clausen { 2749bb13109dSLars-Peter Clausen snd_soc_unregister_dais(component); 2750bb13109dSLars-Peter Clausen kfree(component->name); 2751bb13109dSLars-Peter Clausen } 2752d191bd8dSKuninori Morimoto 2753bb13109dSLars-Peter Clausen static void snd_soc_component_del_unlocked(struct snd_soc_component *component) 2754bb13109dSLars-Peter Clausen { 2755bb13109dSLars-Peter Clausen list_del(&component->list); 2756bb13109dSLars-Peter Clausen } 2757d191bd8dSKuninori Morimoto 2758d191bd8dSKuninori Morimoto int snd_soc_register_component(struct device *dev, 2759d191bd8dSKuninori Morimoto const struct snd_soc_component_driver *cmpnt_drv, 2760d191bd8dSKuninori Morimoto struct snd_soc_dai_driver *dai_drv, 2761d191bd8dSKuninori Morimoto int num_dai) 2762d191bd8dSKuninori Morimoto { 2763d191bd8dSKuninori Morimoto struct snd_soc_component *cmpnt; 2764bb13109dSLars-Peter Clausen int ret; 2765d191bd8dSKuninori Morimoto 2766bb13109dSLars-Peter Clausen cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL); 2767d191bd8dSKuninori Morimoto if (!cmpnt) { 2768d191bd8dSKuninori Morimoto dev_err(dev, "ASoC: Failed to allocate memory\n"); 2769d191bd8dSKuninori Morimoto return -ENOMEM; 2770d191bd8dSKuninori Morimoto } 2771d191bd8dSKuninori Morimoto 2772bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev); 2773bb13109dSLars-Peter Clausen if (ret) 2774bb13109dSLars-Peter Clausen goto err_free; 2775bb13109dSLars-Peter Clausen 27763d59400fSLars-Peter Clausen cmpnt->ignore_pmdown_time = true; 277798e639fbSLars-Peter Clausen cmpnt->registered_as_component = true; 27783d59400fSLars-Peter Clausen 2779bb13109dSLars-Peter Clausen ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); 2780bb13109dSLars-Peter Clausen if (ret < 0) { 2781f42cf8d6SMasanari Iida dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); 2782bb13109dSLars-Peter Clausen goto err_cleanup; 2783bb13109dSLars-Peter Clausen } 2784bb13109dSLars-Peter Clausen 2785bb13109dSLars-Peter Clausen snd_soc_component_add(cmpnt); 2786bb13109dSLars-Peter Clausen 2787bb13109dSLars-Peter Clausen return 0; 2788bb13109dSLars-Peter Clausen 2789bb13109dSLars-Peter Clausen err_cleanup: 2790bb13109dSLars-Peter Clausen snd_soc_component_cleanup(cmpnt); 2791bb13109dSLars-Peter Clausen err_free: 2792bb13109dSLars-Peter Clausen kfree(cmpnt); 2793bb13109dSLars-Peter Clausen return ret; 2794d191bd8dSKuninori Morimoto } 2795d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_register_component); 2796d191bd8dSKuninori Morimoto 2797d191bd8dSKuninori Morimoto /** 2798d191bd8dSKuninori Morimoto * snd_soc_unregister_component - Unregister a component from the ASoC core 2799d191bd8dSKuninori Morimoto * 2800d191bd8dSKuninori Morimoto */ 2801d191bd8dSKuninori Morimoto void snd_soc_unregister_component(struct device *dev) 2802d191bd8dSKuninori Morimoto { 2803d191bd8dSKuninori Morimoto struct snd_soc_component *cmpnt; 2804d191bd8dSKuninori Morimoto 280534e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 2806d191bd8dSKuninori Morimoto list_for_each_entry(cmpnt, &component_list, list) { 280798e639fbSLars-Peter Clausen if (dev == cmpnt->dev && cmpnt->registered_as_component) 2808d191bd8dSKuninori Morimoto goto found; 2809d191bd8dSKuninori Morimoto } 281034e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 2811d191bd8dSKuninori Morimoto return; 2812d191bd8dSKuninori Morimoto 2813d191bd8dSKuninori Morimoto found: 28148a978234SLiam Girdwood snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL); 281534e81ab4SLars-Peter Clausen snd_soc_component_del_unlocked(cmpnt); 281634e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 2817bb13109dSLars-Peter Clausen snd_soc_component_cleanup(cmpnt); 2818bb13109dSLars-Peter Clausen kfree(cmpnt); 2819d191bd8dSKuninori Morimoto } 2820d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_unregister_component); 2821d191bd8dSKuninori Morimoto 2822f1d45cc3SLars-Peter Clausen static int snd_soc_platform_drv_probe(struct snd_soc_component *component) 2823e2c330b9SLars-Peter Clausen { 2824e2c330b9SLars-Peter Clausen struct snd_soc_platform *platform = snd_soc_component_to_platform(component); 2825e2c330b9SLars-Peter Clausen 2826f1d45cc3SLars-Peter Clausen return platform->driver->probe(platform); 2827e2c330b9SLars-Peter Clausen } 2828e2c330b9SLars-Peter Clausen 2829f1d45cc3SLars-Peter Clausen static void snd_soc_platform_drv_remove(struct snd_soc_component *component) 2830e2c330b9SLars-Peter Clausen { 2831e2c330b9SLars-Peter Clausen struct snd_soc_platform *platform = snd_soc_component_to_platform(component); 2832e2c330b9SLars-Peter Clausen 2833f1d45cc3SLars-Peter Clausen platform->driver->remove(platform); 2834e2c330b9SLars-Peter Clausen } 2835e2c330b9SLars-Peter Clausen 2836d191bd8dSKuninori Morimoto /** 283771a45cdaSLars-Peter Clausen * snd_soc_add_platform - Add a platform to the ASoC core 283871a45cdaSLars-Peter Clausen * @dev: The parent device for the platform 283971a45cdaSLars-Peter Clausen * @platform: The platform to add 284071a45cdaSLars-Peter Clausen * @platform_driver: The driver for the platform 284112a48a8cSMark Brown */ 284271a45cdaSLars-Peter Clausen int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, 2843d79e57dbSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 284412a48a8cSMark Brown { 2845b37f1d12SLars-Peter Clausen int ret; 2846b37f1d12SLars-Peter Clausen 2847bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(&platform->component, 2848bb13109dSLars-Peter Clausen &platform_drv->component_driver, dev); 2849bb13109dSLars-Peter Clausen if (ret) 2850bb13109dSLars-Peter Clausen return ret; 2851f0fba2adSLiam Girdwood 2852f0fba2adSLiam Girdwood platform->dev = dev; 2853f0fba2adSLiam Girdwood platform->driver = platform_drv; 2854f1d45cc3SLars-Peter Clausen 2855f1d45cc3SLars-Peter Clausen if (platform_drv->probe) 2856f1d45cc3SLars-Peter Clausen platform->component.probe = snd_soc_platform_drv_probe; 2857f1d45cc3SLars-Peter Clausen if (platform_drv->remove) 2858f1d45cc3SLars-Peter Clausen platform->component.remove = snd_soc_platform_drv_remove; 285912a48a8cSMark Brown 286081c7cfd1SLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 286181c7cfd1SLars-Peter Clausen platform->component.debugfs_prefix = "platform"; 286281c7cfd1SLars-Peter Clausen #endif 286312a48a8cSMark Brown 286412a48a8cSMark Brown mutex_lock(&client_mutex); 2865bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(&platform->component); 286612a48a8cSMark Brown list_add(&platform->list, &platform_list); 286712a48a8cSMark Brown mutex_unlock(&client_mutex); 286812a48a8cSMark Brown 2869f4333203SLars-Peter Clausen dev_dbg(dev, "ASoC: Registered platform '%s'\n", 2870f4333203SLars-Peter Clausen platform->component.name); 287112a48a8cSMark Brown 287212a48a8cSMark Brown return 0; 287312a48a8cSMark Brown } 287471a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_platform); 287571a45cdaSLars-Peter Clausen 287671a45cdaSLars-Peter Clausen /** 287771a45cdaSLars-Peter Clausen * snd_soc_register_platform - Register a platform with the ASoC core 287871a45cdaSLars-Peter Clausen * 287971a45cdaSLars-Peter Clausen * @platform: platform to register 288071a45cdaSLars-Peter Clausen */ 288171a45cdaSLars-Peter Clausen int snd_soc_register_platform(struct device *dev, 288271a45cdaSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 288371a45cdaSLars-Peter Clausen { 288471a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 288571a45cdaSLars-Peter Clausen int ret; 288671a45cdaSLars-Peter Clausen 288771a45cdaSLars-Peter Clausen dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); 288871a45cdaSLars-Peter Clausen 288971a45cdaSLars-Peter Clausen platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 289071a45cdaSLars-Peter Clausen if (platform == NULL) 289171a45cdaSLars-Peter Clausen return -ENOMEM; 289271a45cdaSLars-Peter Clausen 289371a45cdaSLars-Peter Clausen ret = snd_soc_add_platform(dev, platform, platform_drv); 289471a45cdaSLars-Peter Clausen if (ret) 289571a45cdaSLars-Peter Clausen kfree(platform); 289671a45cdaSLars-Peter Clausen 289771a45cdaSLars-Peter Clausen return ret; 289871a45cdaSLars-Peter Clausen } 289912a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 290012a48a8cSMark Brown 290112a48a8cSMark Brown /** 290271a45cdaSLars-Peter Clausen * snd_soc_remove_platform - Remove a platform from the ASoC core 290371a45cdaSLars-Peter Clausen * @platform: the platform to remove 290471a45cdaSLars-Peter Clausen */ 290571a45cdaSLars-Peter Clausen void snd_soc_remove_platform(struct snd_soc_platform *platform) 290671a45cdaSLars-Peter Clausen { 2907b37f1d12SLars-Peter Clausen 290871a45cdaSLars-Peter Clausen mutex_lock(&client_mutex); 290971a45cdaSLars-Peter Clausen list_del(&platform->list); 2910bb13109dSLars-Peter Clausen snd_soc_component_del_unlocked(&platform->component); 291171a45cdaSLars-Peter Clausen mutex_unlock(&client_mutex); 291271a45cdaSLars-Peter Clausen 291371a45cdaSLars-Peter Clausen dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", 2914f4333203SLars-Peter Clausen platform->component.name); 2915decc27b0SDaniel Mack 2916decc27b0SDaniel Mack snd_soc_component_cleanup(&platform->component); 291771a45cdaSLars-Peter Clausen } 291871a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_remove_platform); 291971a45cdaSLars-Peter Clausen 292071a45cdaSLars-Peter Clausen struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) 292171a45cdaSLars-Peter Clausen { 292271a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 292371a45cdaSLars-Peter Clausen 292434e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 292571a45cdaSLars-Peter Clausen list_for_each_entry(platform, &platform_list, list) { 292634e81ab4SLars-Peter Clausen if (dev == platform->dev) { 292734e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 292871a45cdaSLars-Peter Clausen return platform; 292971a45cdaSLars-Peter Clausen } 293034e81ab4SLars-Peter Clausen } 293134e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 293271a45cdaSLars-Peter Clausen 293371a45cdaSLars-Peter Clausen return NULL; 293471a45cdaSLars-Peter Clausen } 293571a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); 293671a45cdaSLars-Peter Clausen 293771a45cdaSLars-Peter Clausen /** 293812a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 293912a48a8cSMark Brown * 2940ac11a2b3SMark Brown * @platform: platform to unregister 294112a48a8cSMark Brown */ 2942f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 294312a48a8cSMark Brown { 2944f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 2945f0fba2adSLiam Girdwood 294671a45cdaSLars-Peter Clausen platform = snd_soc_lookup_platform(dev); 294771a45cdaSLars-Peter Clausen if (!platform) 2948f0fba2adSLiam Girdwood return; 2949f0fba2adSLiam Girdwood 295071a45cdaSLars-Peter Clausen snd_soc_remove_platform(platform); 2951f0fba2adSLiam Girdwood kfree(platform); 295212a48a8cSMark Brown } 295312a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 295412a48a8cSMark Brown 2955151ab22cSMark Brown static u64 codec_format_map[] = { 2956151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 2957151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 2958151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 2959151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 2960151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 2961151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 2962151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 2963151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 2964151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 2965151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 2966151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 2967151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 2968151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 2969151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 2970151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 2971151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 2972151ab22cSMark Brown }; 2973151ab22cSMark Brown 2974151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 2975151ab22cSMark Brown * the endianness of the data but we're using the CPU format 2976151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 2977151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 2978151ab22cSMark Brown */ 2979151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 2980151ab22cSMark Brown { 2981151ab22cSMark Brown int i; 2982151ab22cSMark Brown 2983151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 2984151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 2985151ab22cSMark Brown stream->formats |= codec_format_map[i]; 2986151ab22cSMark Brown } 2987151ab22cSMark Brown 2988f1d45cc3SLars-Peter Clausen static int snd_soc_codec_drv_probe(struct snd_soc_component *component) 2989f1d45cc3SLars-Peter Clausen { 2990f1d45cc3SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 2991f1d45cc3SLars-Peter Clausen 2992f1d45cc3SLars-Peter Clausen return codec->driver->probe(codec); 2993f1d45cc3SLars-Peter Clausen } 2994f1d45cc3SLars-Peter Clausen 2995f1d45cc3SLars-Peter Clausen static void snd_soc_codec_drv_remove(struct snd_soc_component *component) 2996f1d45cc3SLars-Peter Clausen { 2997f1d45cc3SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 2998f1d45cc3SLars-Peter Clausen 2999f1d45cc3SLars-Peter Clausen codec->driver->remove(codec); 3000f1d45cc3SLars-Peter Clausen } 3001f1d45cc3SLars-Peter Clausen 3002e2c330b9SLars-Peter Clausen static int snd_soc_codec_drv_write(struct snd_soc_component *component, 3003e2c330b9SLars-Peter Clausen unsigned int reg, unsigned int val) 3004e2c330b9SLars-Peter Clausen { 3005e2c330b9SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3006e2c330b9SLars-Peter Clausen 3007e2c330b9SLars-Peter Clausen return codec->driver->write(codec, reg, val); 3008e2c330b9SLars-Peter Clausen } 3009e2c330b9SLars-Peter Clausen 3010e2c330b9SLars-Peter Clausen static int snd_soc_codec_drv_read(struct snd_soc_component *component, 3011e2c330b9SLars-Peter Clausen unsigned int reg, unsigned int *val) 3012e2c330b9SLars-Peter Clausen { 3013e2c330b9SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3014e2c330b9SLars-Peter Clausen 3015e2c330b9SLars-Peter Clausen *val = codec->driver->read(codec, reg); 3016e2c330b9SLars-Peter Clausen 3017e2c330b9SLars-Peter Clausen return 0; 3018e2c330b9SLars-Peter Clausen } 3019e2c330b9SLars-Peter Clausen 302068f831c2SLars-Peter Clausen static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, 302168f831c2SLars-Peter Clausen enum snd_soc_bias_level level) 302268f831c2SLars-Peter Clausen { 302368f831c2SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); 302468f831c2SLars-Peter Clausen 302568f831c2SLars-Peter Clausen return codec->driver->set_bias_level(codec, level); 302668f831c2SLars-Peter Clausen } 302768f831c2SLars-Peter Clausen 30280d0cf00aSMark Brown /** 30290d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 30300d0cf00aSMark Brown * 3031ac11a2b3SMark Brown * @codec: codec to register 30320d0cf00aSMark Brown */ 3033f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 3034001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 3035001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 3036001ae4c0SMark Brown int num_dai) 30370d0cf00aSMark Brown { 3038*4890140fSLars-Peter Clausen struct snd_soc_dapm_context *dapm; 3039f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3040bb13109dSLars-Peter Clausen struct snd_soc_dai *dai; 3041f0fba2adSLiam Girdwood int ret, i; 3042151ab22cSMark Brown 3043f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 30440d0cf00aSMark Brown 3045f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 3046f0fba2adSLiam Girdwood if (codec == NULL) 3047f0fba2adSLiam Girdwood return -ENOMEM; 30480d0cf00aSMark Brown 3049f1d45cc3SLars-Peter Clausen codec->component.codec = codec; 3050ce0fc93aSLars-Peter Clausen 3051bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(&codec->component, 3052bb13109dSLars-Peter Clausen &codec_drv->component_driver, dev); 3053bb13109dSLars-Peter Clausen if (ret) 3054bb13109dSLars-Peter Clausen goto err_free; 3055151ab22cSMark Brown 3056f1d45cc3SLars-Peter Clausen if (codec_drv->controls) { 3057f1d45cc3SLars-Peter Clausen codec->component.controls = codec_drv->controls; 3058f1d45cc3SLars-Peter Clausen codec->component.num_controls = codec_drv->num_controls; 3059f1d45cc3SLars-Peter Clausen } 3060f1d45cc3SLars-Peter Clausen if (codec_drv->dapm_widgets) { 3061f1d45cc3SLars-Peter Clausen codec->component.dapm_widgets = codec_drv->dapm_widgets; 3062f1d45cc3SLars-Peter Clausen codec->component.num_dapm_widgets = codec_drv->num_dapm_widgets; 3063f1d45cc3SLars-Peter Clausen } 3064f1d45cc3SLars-Peter Clausen if (codec_drv->dapm_routes) { 3065f1d45cc3SLars-Peter Clausen codec->component.dapm_routes = codec_drv->dapm_routes; 3066f1d45cc3SLars-Peter Clausen codec->component.num_dapm_routes = codec_drv->num_dapm_routes; 3067f1d45cc3SLars-Peter Clausen } 3068f1d45cc3SLars-Peter Clausen 3069f1d45cc3SLars-Peter Clausen if (codec_drv->probe) 3070f1d45cc3SLars-Peter Clausen codec->component.probe = snd_soc_codec_drv_probe; 3071f1d45cc3SLars-Peter Clausen if (codec_drv->remove) 3072f1d45cc3SLars-Peter Clausen codec->component.remove = snd_soc_codec_drv_remove; 3073e2c330b9SLars-Peter Clausen if (codec_drv->write) 3074e2c330b9SLars-Peter Clausen codec->component.write = snd_soc_codec_drv_write; 3075e2c330b9SLars-Peter Clausen if (codec_drv->read) 3076e2c330b9SLars-Peter Clausen codec->component.read = snd_soc_codec_drv_read; 30773d59400fSLars-Peter Clausen codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; 3078*4890140fSLars-Peter Clausen 3079*4890140fSLars-Peter Clausen dapm = snd_soc_codec_get_dapm(codec); 3080*4890140fSLars-Peter Clausen dapm->idle_bias_off = codec_drv->idle_bias_off; 3081*4890140fSLars-Peter Clausen dapm->suspend_bias_off = codec_drv->suspend_bias_off; 308214e8bdebSLars-Peter Clausen if (codec_drv->seq_notifier) 3083*4890140fSLars-Peter Clausen dapm->seq_notifier = codec_drv->seq_notifier; 308468f831c2SLars-Peter Clausen if (codec_drv->set_bias_level) 3085*4890140fSLars-Peter Clausen dapm->set_bias_level = snd_soc_codec_set_bias_level; 3086f0fba2adSLiam Girdwood codec->dev = dev; 3087f0fba2adSLiam Girdwood codec->driver = codec_drv; 3088e2c330b9SLars-Peter Clausen codec->component.val_bytes = codec_drv->reg_word_size; 3089f0fba2adSLiam Girdwood 309081c7cfd1SLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 309181c7cfd1SLars-Peter Clausen codec->component.init_debugfs = soc_init_codec_debugfs; 309281c7cfd1SLars-Peter Clausen codec->component.debugfs_prefix = "codec"; 309381c7cfd1SLars-Peter Clausen #endif 3094a39f75f7SXiubo Li 3095a39f75f7SXiubo Li if (codec_drv->get_regmap) 3096886f5692SLars-Peter Clausen codec->component.regmap = codec_drv->get_regmap(dev); 3097a39f75f7SXiubo Li 3098f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 3099f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 3100f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 3101f0fba2adSLiam Girdwood } 3102f0fba2adSLiam Girdwood 3103bb13109dSLars-Peter Clausen ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); 3104bb13109dSLars-Peter Clausen if (ret < 0) { 3105f42cf8d6SMasanari Iida dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); 3106bb13109dSLars-Peter Clausen goto err_cleanup; 3107bb13109dSLars-Peter Clausen } 3108bb13109dSLars-Peter Clausen 3109bb13109dSLars-Peter Clausen list_for_each_entry(dai, &codec->component.dai_list, list) 3110bb13109dSLars-Peter Clausen dai->codec = codec; 3111bb13109dSLars-Peter Clausen 3112054880feSMark Brown mutex_lock(&client_mutex); 3113bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(&codec->component); 3114054880feSMark Brown list_add(&codec->list, &codec_list); 3115054880feSMark Brown mutex_unlock(&client_mutex); 3116054880feSMark Brown 3117f4333203SLars-Peter Clausen dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", 3118f4333203SLars-Peter Clausen codec->component.name); 31190d0cf00aSMark Brown return 0; 3120f0fba2adSLiam Girdwood 3121bb13109dSLars-Peter Clausen err_cleanup: 3122bb13109dSLars-Peter Clausen snd_soc_component_cleanup(&codec->component); 3123bb13109dSLars-Peter Clausen err_free: 3124f0fba2adSLiam Girdwood kfree(codec); 3125f0fba2adSLiam Girdwood return ret; 31260d0cf00aSMark Brown } 31270d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 31280d0cf00aSMark Brown 31290d0cf00aSMark Brown /** 31300d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 31310d0cf00aSMark Brown * 3132ac11a2b3SMark Brown * @codec: codec to unregister 31330d0cf00aSMark Brown */ 3134f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 31350d0cf00aSMark Brown { 3136f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3137f0fba2adSLiam Girdwood 313834e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 3139f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 3140f0fba2adSLiam Girdwood if (dev == codec->dev) 3141f0fba2adSLiam Girdwood goto found; 3142f0fba2adSLiam Girdwood } 314334e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 3144f0fba2adSLiam Girdwood return; 3145f0fba2adSLiam Girdwood 3146f0fba2adSLiam Girdwood found: 31470d0cf00aSMark Brown list_del(&codec->list); 3148bb13109dSLars-Peter Clausen snd_soc_component_del_unlocked(&codec->component); 31490d0cf00aSMark Brown mutex_unlock(&client_mutex); 31500d0cf00aSMark Brown 3151f4333203SLars-Peter Clausen dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", 3152f4333203SLars-Peter Clausen codec->component.name); 3153f0fba2adSLiam Girdwood 3154bb13109dSLars-Peter Clausen snd_soc_component_cleanup(&codec->component); 31557a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 3156f0fba2adSLiam Girdwood kfree(codec); 31570d0cf00aSMark Brown } 31580d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 31590d0cf00aSMark Brown 3160bec4fa05SStephen Warren /* Retrieve a card's name from device tree */ 3161bec4fa05SStephen Warren int snd_soc_of_parse_card_name(struct snd_soc_card *card, 3162bec4fa05SStephen Warren const char *propname) 3163bec4fa05SStephen Warren { 31647e07e7c0STushar Behera struct device_node *np; 3165bec4fa05SStephen Warren int ret; 3166bec4fa05SStephen Warren 31677e07e7c0STushar Behera if (!card->dev) { 31687e07e7c0STushar Behera pr_err("card->dev is not set before calling %s\n", __func__); 31697e07e7c0STushar Behera return -EINVAL; 31707e07e7c0STushar Behera } 31717e07e7c0STushar Behera 31727e07e7c0STushar Behera np = card->dev->of_node; 31737e07e7c0STushar Behera 3174bec4fa05SStephen Warren ret = of_property_read_string_index(np, propname, 0, &card->name); 3175bec4fa05SStephen Warren /* 3176bec4fa05SStephen Warren * EINVAL means the property does not exist. This is fine providing 3177bec4fa05SStephen Warren * card->name was previously set, which is checked later in 3178bec4fa05SStephen Warren * snd_soc_register_card. 3179bec4fa05SStephen Warren */ 3180bec4fa05SStephen Warren if (ret < 0 && ret != -EINVAL) { 3181bec4fa05SStephen Warren dev_err(card->dev, 3182f110bfc7SLiam Girdwood "ASoC: Property '%s' could not be read: %d\n", 3183bec4fa05SStephen Warren propname, ret); 3184bec4fa05SStephen Warren return ret; 3185bec4fa05SStephen Warren } 3186bec4fa05SStephen Warren 3187bec4fa05SStephen Warren return 0; 3188bec4fa05SStephen Warren } 3189bec4fa05SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 3190bec4fa05SStephen Warren 31919a6d4860SXiubo Li static const struct snd_soc_dapm_widget simple_widgets[] = { 31929a6d4860SXiubo Li SND_SOC_DAPM_MIC("Microphone", NULL), 31939a6d4860SXiubo Li SND_SOC_DAPM_LINE("Line", NULL), 31949a6d4860SXiubo Li SND_SOC_DAPM_HP("Headphone", NULL), 31959a6d4860SXiubo Li SND_SOC_DAPM_SPK("Speaker", NULL), 31969a6d4860SXiubo Li }; 31979a6d4860SXiubo Li 31989a6d4860SXiubo Li int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, 31999a6d4860SXiubo Li const char *propname) 32009a6d4860SXiubo Li { 32019a6d4860SXiubo Li struct device_node *np = card->dev->of_node; 32029a6d4860SXiubo Li struct snd_soc_dapm_widget *widgets; 32039a6d4860SXiubo Li const char *template, *wname; 32049a6d4860SXiubo Li int i, j, num_widgets, ret; 32059a6d4860SXiubo Li 32069a6d4860SXiubo Li num_widgets = of_property_count_strings(np, propname); 32079a6d4860SXiubo Li if (num_widgets < 0) { 32089a6d4860SXiubo Li dev_err(card->dev, 32099a6d4860SXiubo Li "ASoC: Property '%s' does not exist\n", propname); 32109a6d4860SXiubo Li return -EINVAL; 32119a6d4860SXiubo Li } 32129a6d4860SXiubo Li if (num_widgets & 1) { 32139a6d4860SXiubo Li dev_err(card->dev, 32149a6d4860SXiubo Li "ASoC: Property '%s' length is not even\n", propname); 32159a6d4860SXiubo Li return -EINVAL; 32169a6d4860SXiubo Li } 32179a6d4860SXiubo Li 32189a6d4860SXiubo Li num_widgets /= 2; 32199a6d4860SXiubo Li if (!num_widgets) { 32209a6d4860SXiubo Li dev_err(card->dev, "ASoC: Property '%s's length is zero\n", 32219a6d4860SXiubo Li propname); 32229a6d4860SXiubo Li return -EINVAL; 32239a6d4860SXiubo Li } 32249a6d4860SXiubo Li 32259a6d4860SXiubo Li widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), 32269a6d4860SXiubo Li GFP_KERNEL); 32279a6d4860SXiubo Li if (!widgets) { 32289a6d4860SXiubo Li dev_err(card->dev, 32299a6d4860SXiubo Li "ASoC: Could not allocate memory for widgets\n"); 32309a6d4860SXiubo Li return -ENOMEM; 32319a6d4860SXiubo Li } 32329a6d4860SXiubo Li 32339a6d4860SXiubo Li for (i = 0; i < num_widgets; i++) { 32349a6d4860SXiubo Li ret = of_property_read_string_index(np, propname, 32359a6d4860SXiubo Li 2 * i, &template); 32369a6d4860SXiubo Li if (ret) { 32379a6d4860SXiubo Li dev_err(card->dev, 32389a6d4860SXiubo Li "ASoC: Property '%s' index %d read error:%d\n", 32399a6d4860SXiubo Li propname, 2 * i, ret); 32409a6d4860SXiubo Li return -EINVAL; 32419a6d4860SXiubo Li } 32429a6d4860SXiubo Li 32439a6d4860SXiubo Li for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) { 32449a6d4860SXiubo Li if (!strncmp(template, simple_widgets[j].name, 32459a6d4860SXiubo Li strlen(simple_widgets[j].name))) { 32469a6d4860SXiubo Li widgets[i] = simple_widgets[j]; 32479a6d4860SXiubo Li break; 32489a6d4860SXiubo Li } 32499a6d4860SXiubo Li } 32509a6d4860SXiubo Li 32519a6d4860SXiubo Li if (j >= ARRAY_SIZE(simple_widgets)) { 32529a6d4860SXiubo Li dev_err(card->dev, 32539a6d4860SXiubo Li "ASoC: DAPM widget '%s' is not supported\n", 32549a6d4860SXiubo Li template); 32559a6d4860SXiubo Li return -EINVAL; 32569a6d4860SXiubo Li } 32579a6d4860SXiubo Li 32589a6d4860SXiubo Li ret = of_property_read_string_index(np, propname, 32599a6d4860SXiubo Li (2 * i) + 1, 32609a6d4860SXiubo Li &wname); 32619a6d4860SXiubo Li if (ret) { 32629a6d4860SXiubo Li dev_err(card->dev, 32639a6d4860SXiubo Li "ASoC: Property '%s' index %d read error:%d\n", 32649a6d4860SXiubo Li propname, (2 * i) + 1, ret); 32659a6d4860SXiubo Li return -EINVAL; 32669a6d4860SXiubo Li } 32679a6d4860SXiubo Li 32689a6d4860SXiubo Li widgets[i].name = wname; 32699a6d4860SXiubo Li } 32709a6d4860SXiubo Li 3271f23e860eSNicolin Chen card->of_dapm_widgets = widgets; 3272f23e860eSNicolin Chen card->num_of_dapm_widgets = num_widgets; 32739a6d4860SXiubo Li 32749a6d4860SXiubo Li return 0; 32759a6d4860SXiubo Li } 32769a6d4860SXiubo Li EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); 32779a6d4860SXiubo Li 327889c67857SXiubo Li int snd_soc_of_parse_tdm_slot(struct device_node *np, 327989c67857SXiubo Li unsigned int *slots, 328089c67857SXiubo Li unsigned int *slot_width) 328189c67857SXiubo Li { 328289c67857SXiubo Li u32 val; 328389c67857SXiubo Li int ret; 328489c67857SXiubo Li 328589c67857SXiubo Li if (of_property_read_bool(np, "dai-tdm-slot-num")) { 328689c67857SXiubo Li ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); 328789c67857SXiubo Li if (ret) 328889c67857SXiubo Li return ret; 328989c67857SXiubo Li 329089c67857SXiubo Li if (slots) 329189c67857SXiubo Li *slots = val; 329289c67857SXiubo Li } 329389c67857SXiubo Li 329489c67857SXiubo Li if (of_property_read_bool(np, "dai-tdm-slot-width")) { 329589c67857SXiubo Li ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); 329689c67857SXiubo Li if (ret) 329789c67857SXiubo Li return ret; 329889c67857SXiubo Li 329989c67857SXiubo Li if (slot_width) 330089c67857SXiubo Li *slot_width = val; 330189c67857SXiubo Li } 330289c67857SXiubo Li 330389c67857SXiubo Li return 0; 330489c67857SXiubo Li } 330589c67857SXiubo Li EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); 330689c67857SXiubo Li 3307a4a54dd5SStephen Warren int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 3308a4a54dd5SStephen Warren const char *propname) 3309a4a54dd5SStephen Warren { 3310a4a54dd5SStephen Warren struct device_node *np = card->dev->of_node; 3311e3b1e6a1SMark Brown int num_routes; 3312a4a54dd5SStephen Warren struct snd_soc_dapm_route *routes; 3313a4a54dd5SStephen Warren int i, ret; 3314a4a54dd5SStephen Warren 3315a4a54dd5SStephen Warren num_routes = of_property_count_strings(np, propname); 3316c34ce320SRichard Zhao if (num_routes < 0 || num_routes & 1) { 331710e8aa9aSMichał Mirosław dev_err(card->dev, 331810e8aa9aSMichał Mirosław "ASoC: Property '%s' does not exist or its length is not even\n", 331910e8aa9aSMichał Mirosław propname); 3320a4a54dd5SStephen Warren return -EINVAL; 3321a4a54dd5SStephen Warren } 3322a4a54dd5SStephen Warren num_routes /= 2; 3323a4a54dd5SStephen Warren if (!num_routes) { 3324f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Property '%s's length is zero\n", 3325a4a54dd5SStephen Warren propname); 3326a4a54dd5SStephen Warren return -EINVAL; 3327a4a54dd5SStephen Warren } 3328a4a54dd5SStephen Warren 3329e3b1e6a1SMark Brown routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), 3330a4a54dd5SStephen Warren GFP_KERNEL); 3331a4a54dd5SStephen Warren if (!routes) { 3332a4a54dd5SStephen Warren dev_err(card->dev, 3333f110bfc7SLiam Girdwood "ASoC: Could not allocate DAPM route table\n"); 3334a4a54dd5SStephen Warren return -EINVAL; 3335a4a54dd5SStephen Warren } 3336a4a54dd5SStephen Warren 3337a4a54dd5SStephen Warren for (i = 0; i < num_routes; i++) { 3338a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3339e3b1e6a1SMark Brown 2 * i, &routes[i].sink); 3340a4a54dd5SStephen Warren if (ret) { 3341c871bd0bSMark Brown dev_err(card->dev, 3342c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 3343c871bd0bSMark Brown propname, 2 * i, ret); 3344a4a54dd5SStephen Warren return -EINVAL; 3345a4a54dd5SStephen Warren } 3346a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3347e3b1e6a1SMark Brown (2 * i) + 1, &routes[i].source); 3348a4a54dd5SStephen Warren if (ret) { 3349a4a54dd5SStephen Warren dev_err(card->dev, 3350c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 3351c871bd0bSMark Brown propname, (2 * i) + 1, ret); 3352a4a54dd5SStephen Warren return -EINVAL; 3353a4a54dd5SStephen Warren } 3354a4a54dd5SStephen Warren } 3355a4a54dd5SStephen Warren 3356f23e860eSNicolin Chen card->num_of_dapm_routes = num_routes; 3357f23e860eSNicolin Chen card->of_dapm_routes = routes; 3358a4a54dd5SStephen Warren 3359a4a54dd5SStephen Warren return 0; 3360a4a54dd5SStephen Warren } 3361a4a54dd5SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); 3362a4a54dd5SStephen Warren 3363a7930ed4SKuninori Morimoto unsigned int snd_soc_of_parse_daifmt(struct device_node *np, 3364389cb834SJyri Sarha const char *prefix, 3365389cb834SJyri Sarha struct device_node **bitclkmaster, 3366389cb834SJyri Sarha struct device_node **framemaster) 3367a7930ed4SKuninori Morimoto { 3368a7930ed4SKuninori Morimoto int ret, i; 3369a7930ed4SKuninori Morimoto char prop[128]; 3370a7930ed4SKuninori Morimoto unsigned int format = 0; 3371a7930ed4SKuninori Morimoto int bit, frame; 3372a7930ed4SKuninori Morimoto const char *str; 3373a7930ed4SKuninori Morimoto struct { 3374a7930ed4SKuninori Morimoto char *name; 3375a7930ed4SKuninori Morimoto unsigned int val; 3376a7930ed4SKuninori Morimoto } of_fmt_table[] = { 3377a7930ed4SKuninori Morimoto { "i2s", SND_SOC_DAIFMT_I2S }, 3378a7930ed4SKuninori Morimoto { "right_j", SND_SOC_DAIFMT_RIGHT_J }, 3379a7930ed4SKuninori Morimoto { "left_j", SND_SOC_DAIFMT_LEFT_J }, 3380a7930ed4SKuninori Morimoto { "dsp_a", SND_SOC_DAIFMT_DSP_A }, 3381a7930ed4SKuninori Morimoto { "dsp_b", SND_SOC_DAIFMT_DSP_B }, 3382a7930ed4SKuninori Morimoto { "ac97", SND_SOC_DAIFMT_AC97 }, 3383a7930ed4SKuninori Morimoto { "pdm", SND_SOC_DAIFMT_PDM}, 3384a7930ed4SKuninori Morimoto { "msb", SND_SOC_DAIFMT_MSB }, 3385a7930ed4SKuninori Morimoto { "lsb", SND_SOC_DAIFMT_LSB }, 3386a7930ed4SKuninori Morimoto }; 3387a7930ed4SKuninori Morimoto 3388a7930ed4SKuninori Morimoto if (!prefix) 3389a7930ed4SKuninori Morimoto prefix = ""; 3390a7930ed4SKuninori Morimoto 3391a7930ed4SKuninori Morimoto /* 3392a7930ed4SKuninori Morimoto * check "[prefix]format = xxx" 3393a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_FORMAT_MASK area 3394a7930ed4SKuninori Morimoto */ 3395a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sformat", prefix); 3396a7930ed4SKuninori Morimoto ret = of_property_read_string(np, prop, &str); 3397a7930ed4SKuninori Morimoto if (ret == 0) { 3398a7930ed4SKuninori Morimoto for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { 3399a7930ed4SKuninori Morimoto if (strcmp(str, of_fmt_table[i].name) == 0) { 3400a7930ed4SKuninori Morimoto format |= of_fmt_table[i].val; 3401a7930ed4SKuninori Morimoto break; 3402a7930ed4SKuninori Morimoto } 3403a7930ed4SKuninori Morimoto } 3404a7930ed4SKuninori Morimoto } 3405a7930ed4SKuninori Morimoto 3406a7930ed4SKuninori Morimoto /* 34078c2d6a9fSKuninori Morimoto * check "[prefix]continuous-clock" 3408a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_CLOCK_MASK area 3409a7930ed4SKuninori Morimoto */ 34108c2d6a9fSKuninori Morimoto snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); 34118c2d6a9fSKuninori Morimoto if (of_get_property(np, prop, NULL)) 34128c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_CONT; 34138c2d6a9fSKuninori Morimoto else 34148c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_GATED; 3415a7930ed4SKuninori Morimoto 3416a7930ed4SKuninori Morimoto /* 3417a7930ed4SKuninori Morimoto * check "[prefix]bitclock-inversion" 3418a7930ed4SKuninori Morimoto * check "[prefix]frame-inversion" 3419a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_INV_MASK area 3420a7930ed4SKuninori Morimoto */ 3421a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); 3422a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 3423a7930ed4SKuninori Morimoto 3424a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); 3425a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 3426a7930ed4SKuninori Morimoto 3427a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 3428a7930ed4SKuninori Morimoto case 0x11: 3429a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_IF; 3430a7930ed4SKuninori Morimoto break; 3431a7930ed4SKuninori Morimoto case 0x10: 3432a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_NF; 3433a7930ed4SKuninori Morimoto break; 3434a7930ed4SKuninori Morimoto case 0x01: 3435a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_NB_IF; 3436a7930ed4SKuninori Morimoto break; 3437a7930ed4SKuninori Morimoto default: 3438a7930ed4SKuninori Morimoto /* SND_SOC_DAIFMT_NB_NF is default */ 3439a7930ed4SKuninori Morimoto break; 3440a7930ed4SKuninori Morimoto } 3441a7930ed4SKuninori Morimoto 3442a7930ed4SKuninori Morimoto /* 3443a7930ed4SKuninori Morimoto * check "[prefix]bitclock-master" 3444a7930ed4SKuninori Morimoto * check "[prefix]frame-master" 3445a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_MASTER_MASK area 3446a7930ed4SKuninori Morimoto */ 3447a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); 3448a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 3449389cb834SJyri Sarha if (bit && bitclkmaster) 3450389cb834SJyri Sarha *bitclkmaster = of_parse_phandle(np, prop, 0); 3451a7930ed4SKuninori Morimoto 3452a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-master", prefix); 3453a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 3454389cb834SJyri Sarha if (frame && framemaster) 3455389cb834SJyri Sarha *framemaster = of_parse_phandle(np, prop, 0); 3456a7930ed4SKuninori Morimoto 3457a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 3458a7930ed4SKuninori Morimoto case 0x11: 3459a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFM; 3460a7930ed4SKuninori Morimoto break; 3461a7930ed4SKuninori Morimoto case 0x10: 3462a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFS; 3463a7930ed4SKuninori Morimoto break; 3464a7930ed4SKuninori Morimoto case 0x01: 3465a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFM; 3466a7930ed4SKuninori Morimoto break; 3467a7930ed4SKuninori Morimoto default: 3468a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFS; 3469a7930ed4SKuninori Morimoto break; 3470a7930ed4SKuninori Morimoto } 3471a7930ed4SKuninori Morimoto 3472a7930ed4SKuninori Morimoto return format; 3473a7930ed4SKuninori Morimoto } 3474a7930ed4SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); 3475a7930ed4SKuninori Morimoto 347693b0f3eeSJean-Francois Moine static int snd_soc_get_dai_name(struct of_phandle_args *args, 3477cb470087SKuninori Morimoto const char **dai_name) 3478cb470087SKuninori Morimoto { 3479cb470087SKuninori Morimoto struct snd_soc_component *pos; 34803e0aa8d8SJyri Sarha struct device_node *component_of_node; 348193b0f3eeSJean-Francois Moine int ret = -EPROBE_DEFER; 3482cb470087SKuninori Morimoto 3483cb470087SKuninori Morimoto mutex_lock(&client_mutex); 3484cb470087SKuninori Morimoto list_for_each_entry(pos, &component_list, list) { 34853e0aa8d8SJyri Sarha component_of_node = pos->dev->of_node; 34863e0aa8d8SJyri Sarha if (!component_of_node && pos->dev->parent) 34873e0aa8d8SJyri Sarha component_of_node = pos->dev->parent->of_node; 34883e0aa8d8SJyri Sarha 34893e0aa8d8SJyri Sarha if (component_of_node != args->np) 3490cb470087SKuninori Morimoto continue; 3491cb470087SKuninori Morimoto 34926833c452SKuninori Morimoto if (pos->driver->of_xlate_dai_name) { 349393b0f3eeSJean-Francois Moine ret = pos->driver->of_xlate_dai_name(pos, 349493b0f3eeSJean-Francois Moine args, 349593b0f3eeSJean-Francois Moine dai_name); 34966833c452SKuninori Morimoto } else { 34976833c452SKuninori Morimoto int id = -1; 34986833c452SKuninori Morimoto 349993b0f3eeSJean-Francois Moine switch (args->args_count) { 35006833c452SKuninori Morimoto case 0: 35016833c452SKuninori Morimoto id = 0; /* same as dai_drv[0] */ 35026833c452SKuninori Morimoto break; 35036833c452SKuninori Morimoto case 1: 350493b0f3eeSJean-Francois Moine id = args->args[0]; 35056833c452SKuninori Morimoto break; 35066833c452SKuninori Morimoto default: 35076833c452SKuninori Morimoto /* not supported */ 3508cb470087SKuninori Morimoto break; 3509cb470087SKuninori Morimoto } 3510cb470087SKuninori Morimoto 35116833c452SKuninori Morimoto if (id < 0 || id >= pos->num_dai) { 35126833c452SKuninori Morimoto ret = -EINVAL; 35133dcba280SNicolin Chen continue; 35146833c452SKuninori Morimoto } 3515e41975edSXiubo Li 3516e41975edSXiubo Li ret = 0; 3517e41975edSXiubo Li 3518e41975edSXiubo Li *dai_name = pos->dai_drv[id].name; 3519e41975edSXiubo Li if (!*dai_name) 3520e41975edSXiubo Li *dai_name = pos->name; 35216833c452SKuninori Morimoto } 35226833c452SKuninori Morimoto 3523cb470087SKuninori Morimoto break; 3524cb470087SKuninori Morimoto } 3525cb470087SKuninori Morimoto mutex_unlock(&client_mutex); 352693b0f3eeSJean-Francois Moine return ret; 352793b0f3eeSJean-Francois Moine } 352893b0f3eeSJean-Francois Moine 352993b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_name(struct device_node *of_node, 353093b0f3eeSJean-Francois Moine const char **dai_name) 353193b0f3eeSJean-Francois Moine { 353293b0f3eeSJean-Francois Moine struct of_phandle_args args; 353393b0f3eeSJean-Francois Moine int ret; 353493b0f3eeSJean-Francois Moine 353593b0f3eeSJean-Francois Moine ret = of_parse_phandle_with_args(of_node, "sound-dai", 353693b0f3eeSJean-Francois Moine "#sound-dai-cells", 0, &args); 353793b0f3eeSJean-Francois Moine if (ret) 353893b0f3eeSJean-Francois Moine return ret; 353993b0f3eeSJean-Francois Moine 354093b0f3eeSJean-Francois Moine ret = snd_soc_get_dai_name(&args, dai_name); 3541cb470087SKuninori Morimoto 3542cb470087SKuninori Morimoto of_node_put(args.np); 3543cb470087SKuninori Morimoto 3544cb470087SKuninori Morimoto return ret; 3545cb470087SKuninori Morimoto } 3546cb470087SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); 3547cb470087SKuninori Morimoto 354893b0f3eeSJean-Francois Moine /* 354993b0f3eeSJean-Francois Moine * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree 355093b0f3eeSJean-Francois Moine * @dev: Card device 355193b0f3eeSJean-Francois Moine * @of_node: Device node 355293b0f3eeSJean-Francois Moine * @dai_link: DAI link 355393b0f3eeSJean-Francois Moine * 355493b0f3eeSJean-Francois Moine * Builds an array of CODEC DAI components from the DAI link property 355593b0f3eeSJean-Francois Moine * 'sound-dai'. 355693b0f3eeSJean-Francois Moine * The array is set in the DAI link and the number of DAIs is set accordingly. 355793b0f3eeSJean-Francois Moine * The device nodes in the array (of_node) must be dereferenced by the caller. 355893b0f3eeSJean-Francois Moine * 355993b0f3eeSJean-Francois Moine * Returns 0 for success 356093b0f3eeSJean-Francois Moine */ 356193b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_link_codecs(struct device *dev, 356293b0f3eeSJean-Francois Moine struct device_node *of_node, 356393b0f3eeSJean-Francois Moine struct snd_soc_dai_link *dai_link) 356493b0f3eeSJean-Francois Moine { 356593b0f3eeSJean-Francois Moine struct of_phandle_args args; 356693b0f3eeSJean-Francois Moine struct snd_soc_dai_link_component *component; 356793b0f3eeSJean-Francois Moine char *name; 356893b0f3eeSJean-Francois Moine int index, num_codecs, ret; 356993b0f3eeSJean-Francois Moine 357093b0f3eeSJean-Francois Moine /* Count the number of CODECs */ 357193b0f3eeSJean-Francois Moine name = "sound-dai"; 357293b0f3eeSJean-Francois Moine num_codecs = of_count_phandle_with_args(of_node, name, 357393b0f3eeSJean-Francois Moine "#sound-dai-cells"); 357493b0f3eeSJean-Francois Moine if (num_codecs <= 0) { 357593b0f3eeSJean-Francois Moine if (num_codecs == -ENOENT) 357693b0f3eeSJean-Francois Moine dev_err(dev, "No 'sound-dai' property\n"); 357793b0f3eeSJean-Francois Moine else 357893b0f3eeSJean-Francois Moine dev_err(dev, "Bad phandle in 'sound-dai'\n"); 357993b0f3eeSJean-Francois Moine return num_codecs; 358093b0f3eeSJean-Francois Moine } 358193b0f3eeSJean-Francois Moine component = devm_kzalloc(dev, 358293b0f3eeSJean-Francois Moine sizeof *component * num_codecs, 358393b0f3eeSJean-Francois Moine GFP_KERNEL); 358493b0f3eeSJean-Francois Moine if (!component) 358593b0f3eeSJean-Francois Moine return -ENOMEM; 358693b0f3eeSJean-Francois Moine dai_link->codecs = component; 358793b0f3eeSJean-Francois Moine dai_link->num_codecs = num_codecs; 358893b0f3eeSJean-Francois Moine 358993b0f3eeSJean-Francois Moine /* Parse the list */ 359093b0f3eeSJean-Francois Moine for (index = 0, component = dai_link->codecs; 359193b0f3eeSJean-Francois Moine index < dai_link->num_codecs; 359293b0f3eeSJean-Francois Moine index++, component++) { 359393b0f3eeSJean-Francois Moine ret = of_parse_phandle_with_args(of_node, name, 359493b0f3eeSJean-Francois Moine "#sound-dai-cells", 359593b0f3eeSJean-Francois Moine index, &args); 359693b0f3eeSJean-Francois Moine if (ret) 359793b0f3eeSJean-Francois Moine goto err; 359893b0f3eeSJean-Francois Moine component->of_node = args.np; 359993b0f3eeSJean-Francois Moine ret = snd_soc_get_dai_name(&args, &component->dai_name); 360093b0f3eeSJean-Francois Moine if (ret < 0) 360193b0f3eeSJean-Francois Moine goto err; 360293b0f3eeSJean-Francois Moine } 360393b0f3eeSJean-Francois Moine return 0; 360493b0f3eeSJean-Francois Moine err: 360593b0f3eeSJean-Francois Moine for (index = 0, component = dai_link->codecs; 360693b0f3eeSJean-Francois Moine index < dai_link->num_codecs; 360793b0f3eeSJean-Francois Moine index++, component++) { 360893b0f3eeSJean-Francois Moine if (!component->of_node) 360993b0f3eeSJean-Francois Moine break; 361093b0f3eeSJean-Francois Moine of_node_put(component->of_node); 361193b0f3eeSJean-Francois Moine component->of_node = NULL; 361293b0f3eeSJean-Francois Moine } 361393b0f3eeSJean-Francois Moine dai_link->codecs = NULL; 361493b0f3eeSJean-Francois Moine dai_link->num_codecs = 0; 361593b0f3eeSJean-Francois Moine return ret; 361693b0f3eeSJean-Francois Moine } 361793b0f3eeSJean-Francois Moine EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); 361893b0f3eeSJean-Francois Moine 3619c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 3620db2a4165SFrank Mandarino { 36216553bf06SLars-Peter Clausen snd_soc_debugfs_init(); 3622fb257897SMark Brown snd_soc_util_init(); 3623fb257897SMark Brown 3624db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 3625db2a4165SFrank Mandarino } 36264abe8e16SMark Brown module_init(snd_soc_init); 3627db2a4165SFrank Mandarino 3628db2a4165SFrank Mandarino static void __exit snd_soc_exit(void) 3629db2a4165SFrank Mandarino { 3630fb257897SMark Brown snd_soc_util_exit(); 36316553bf06SLars-Peter Clausen snd_soc_debugfs_exit(); 3632fb257897SMark Brown 3633db2a4165SFrank Mandarino #ifdef CONFIG_DEBUG_FS 3634db2a4165SFrank Mandarino #endif 3635db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 3636db2a4165SFrank Mandarino } 3637db2a4165SFrank Mandarino module_exit(snd_soc_exit); 3638db2a4165SFrank Mandarino 3639db2a4165SFrank Mandarino /* Module information */ 3640db2a4165SFrank Mandarino MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 3641db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 3642db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 3643db2a4165SFrank Mandarino MODULE_ALIAS("platform:soc-audio"); 3644