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) { 6571547aba9SMark Brown /* If there are paths active then the CODEC will be held with 6581547aba9SMark Brown * bias _ON and should not be suspended. */ 659a8093297SLars-Peter Clausen if (!codec->suspended) { 660ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 6611547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 662125a25daSMark Brown /* 663125a25daSMark Brown * If the CODEC is capable of idle 664125a25daSMark Brown * bias off then being in STANDBY 665125a25daSMark Brown * means it's doing something, 666125a25daSMark Brown * otherwise fall through. 667125a25daSMark Brown */ 668125a25daSMark Brown if (codec->dapm.idle_bias_off) { 669125a25daSMark Brown dev_dbg(codec->dev, 67010e8aa9aSMichał Mirosław "ASoC: idle_bias_off CODEC on over suspend\n"); 671125a25daSMark Brown break; 672125a25daSMark Brown } 673a8093297SLars-Peter Clausen 6741547aba9SMark Brown case SND_SOC_BIAS_OFF: 675a8093297SLars-Peter Clausen if (codec->driver->suspend) 67684b315eeSLars-Peter Clausen codec->driver->suspend(codec); 677f0fba2adSLiam Girdwood codec->suspended = 1; 678e2c330b9SLars-Peter Clausen if (codec->component.regmap) 679e2c330b9SLars-Peter Clausen regcache_mark_dirty(codec->component.regmap); 680988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 681988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(codec->dev); 6821547aba9SMark Brown break; 6831547aba9SMark Brown default: 68410e8aa9aSMichał Mirosław dev_dbg(codec->dev, 68510e8aa9aSMichał Mirosław "ASoC: CODEC is on over suspend\n"); 6861547aba9SMark Brown break; 6871547aba9SMark Brown } 6881547aba9SMark Brown } 689f0fba2adSLiam Girdwood } 690db2a4165SFrank Mandarino 691f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 692f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6933efab7dcSMark Brown 694f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6953efab7dcSMark Brown continue; 6963efab7dcSMark Brown 697bc263214SLars-Peter Clausen if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control) 698f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 699988e8cc4SNicolin Chen 700988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 701988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 702db2a4165SFrank Mandarino } 703db2a4165SFrank Mandarino 70487506549SMark Brown if (card->suspend_post) 70570b2ac12SMark Brown card->suspend_post(card); 706db2a4165SFrank Mandarino 707db2a4165SFrank Mandarino return 0; 708db2a4165SFrank Mandarino } 7096f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 710db2a4165SFrank Mandarino 7116ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 7126ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 7136ed25978SAndy Green */ 7146ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 715db2a4165SFrank Mandarino { 716f0fba2adSLiam Girdwood struct snd_soc_card *card = 717f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 7182eea392dSJarkko Nikula struct snd_soc_codec *codec; 71988bd870fSBenoit Cousson int i, j; 720db2a4165SFrank Mandarino 7216ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 7226ed25978SAndy Green * so userspace apps are blocked from touching us 7236ed25978SAndy Green */ 7246ed25978SAndy Green 725f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: starting resume work\n"); 7266ed25978SAndy Green 7279949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 728f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 7299949788bSMark Brown 73087506549SMark Brown if (card->resume_pre) 73170b2ac12SMark Brown card->resume_pre(card); 732db2a4165SFrank Mandarino 733bc263214SLars-Peter Clausen /* resume control bus DAIs */ 734f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 735f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 7363efab7dcSMark Brown 737f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7383efab7dcSMark Brown continue; 7393efab7dcSMark Brown 740bc263214SLars-Peter Clausen if (cpu_dai->driver->resume && cpu_dai->driver->bus_control) 741f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 742db2a4165SFrank Mandarino } 743db2a4165SFrank Mandarino 7442eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 745a8093297SLars-Peter Clausen if (codec->suspended) { 746a8093297SLars-Peter Clausen if (codec->driver->resume) 747f0fba2adSLiam Girdwood codec->driver->resume(codec); 748f0fba2adSLiam Girdwood codec->suspended = 0; 7491547aba9SMark Brown } 750f0fba2adSLiam Girdwood } 751db2a4165SFrank Mandarino 752f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 7533efab7dcSMark Brown 754f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7553efab7dcSMark Brown continue; 7563efab7dcSMark Brown 7577bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 758d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_PLAYBACK, 759db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 760f0fba2adSLiam Girdwood 7617bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 762d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_CAPTURE, 763db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 764db2a4165SFrank Mandarino } 765db2a4165SFrank Mandarino 7663ff3f64bSMark Brown /* unmute any active DACs */ 767f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 7683efab7dcSMark Brown 769f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7703efab7dcSMark Brown continue; 7713efab7dcSMark Brown 77288bd870fSBenoit Cousson for (j = 0; j < card->rtd[i].num_codecs; j++) { 77388bd870fSBenoit Cousson struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; 77488bd870fSBenoit Cousson struct snd_soc_dai_driver *drv = dai->driver; 77588bd870fSBenoit Cousson 776f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 777f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 778db2a4165SFrank Mandarino } 77988bd870fSBenoit Cousson } 780db2a4165SFrank Mandarino 781f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 782f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 7833efab7dcSMark Brown 784f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7853efab7dcSMark Brown continue; 7863efab7dcSMark Brown 787bc263214SLars-Peter Clausen if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control) 788f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 789db2a4165SFrank Mandarino } 790db2a4165SFrank Mandarino 79187506549SMark Brown if (card->resume_post) 79270b2ac12SMark Brown card->resume_post(card); 793db2a4165SFrank Mandarino 794f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: resume work completed\n"); 7956ed25978SAndy Green 7966ed25978SAndy Green /* userspace can access us now we are back as we were before */ 797f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 798e2d32ff6SMark Brown 7998be4da29SLars-Peter Clausen /* Recheck all endpoints too, their state is affected by suspend */ 8008be4da29SLars-Peter Clausen dapm_mark_endpoints_dirty(card); 801e2d32ff6SMark Brown snd_soc_dapm_sync(&card->dapm); 8026ed25978SAndy Green } 8036ed25978SAndy Green 8046ed25978SAndy Green /* powers up audio subsystem after a suspend */ 8056f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 8066ed25978SAndy Green { 8076f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 808bc263214SLars-Peter Clausen bool bus_control = false; 809bc263214SLars-Peter Clausen int i; 810b9dd94a8SPeter Ujfalusi 811c5599b87SLars-Peter Clausen /* If the card is not initialized yet there is nothing to do */ 812c5599b87SLars-Peter Clausen if (!card->instantiated) 8135ff1ddf2SEric Miao return 0; 8145ff1ddf2SEric Miao 815988e8cc4SNicolin Chen /* activate pins from sleep state */ 816988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 81788bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 81888bd870fSBenoit Cousson struct snd_soc_dai **codec_dais = rtd->codec_dais; 81988bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 82088bd870fSBenoit Cousson int j; 82188bd870fSBenoit Cousson 822988e8cc4SNicolin Chen if (cpu_dai->active) 823988e8cc4SNicolin Chen pinctrl_pm_select_default_state(cpu_dai->dev); 82488bd870fSBenoit Cousson 82588bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 82688bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = codec_dais[j]; 827988e8cc4SNicolin Chen if (codec_dai->active) 828988e8cc4SNicolin Chen pinctrl_pm_select_default_state(codec_dai->dev); 829988e8cc4SNicolin Chen } 83088bd870fSBenoit Cousson } 831988e8cc4SNicolin Chen 832bc263214SLars-Peter Clausen /* 833bc263214SLars-Peter Clausen * DAIs that also act as the control bus master might have other drivers 834bc263214SLars-Peter Clausen * hanging off them so need to resume immediately. Other drivers don't 835bc263214SLars-Peter Clausen * have that problem and may take a substantial amount of time to resume 83664ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 83764ab9baaSMark Brown */ 838f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 839f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 840bc263214SLars-Peter Clausen bus_control |= cpu_dai->driver->bus_control; 84182e14e8bSStephen Warren } 842bc263214SLars-Peter Clausen if (bus_control) { 843bc263214SLars-Peter Clausen dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); 84464ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 84564ab9baaSMark Brown } else { 846f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Scheduling resume work\n"); 8476308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 848f110bfc7SLiam Girdwood dev_err(dev, "ASoC: resume work item may be lost\n"); 849f0fba2adSLiam Girdwood } 8506ed25978SAndy Green 851db2a4165SFrank Mandarino return 0; 852db2a4165SFrank Mandarino } 8536f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 854db2a4165SFrank Mandarino #else 8556f8ab4acSMark Brown #define snd_soc_suspend NULL 8566f8ab4acSMark Brown #define snd_soc_resume NULL 857db2a4165SFrank Mandarino #endif 858db2a4165SFrank Mandarino 85985e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops null_dai_ops = { 86002a06d30SBarry Song }; 86102a06d30SBarry Song 86265d9361fSLars-Peter Clausen static struct snd_soc_component *soc_find_component( 86365d9361fSLars-Peter Clausen const struct device_node *of_node, const char *name) 86412023a9aSMisael Lopez Cruz { 86565d9361fSLars-Peter Clausen struct snd_soc_component *component; 86612023a9aSMisael Lopez Cruz 86734e81ab4SLars-Peter Clausen lockdep_assert_held(&client_mutex); 86834e81ab4SLars-Peter Clausen 86965d9361fSLars-Peter Clausen list_for_each_entry(component, &component_list, list) { 87065d9361fSLars-Peter Clausen if (of_node) { 87165d9361fSLars-Peter Clausen if (component->dev->of_node == of_node) 87265d9361fSLars-Peter Clausen return component; 87365d9361fSLars-Peter Clausen } else if (strcmp(component->name, name) == 0) { 87465d9361fSLars-Peter Clausen return component; 87512023a9aSMisael Lopez Cruz } 87612023a9aSMisael Lopez Cruz } 87712023a9aSMisael Lopez Cruz 87812023a9aSMisael Lopez Cruz return NULL; 87912023a9aSMisael Lopez Cruz } 88012023a9aSMisael Lopez Cruz 88114621c7eSLars-Peter Clausen static struct snd_soc_dai *snd_soc_find_dai( 88214621c7eSLars-Peter Clausen const struct snd_soc_dai_link_component *dlc) 88312023a9aSMisael Lopez Cruz { 88414621c7eSLars-Peter Clausen struct snd_soc_component *component; 88514621c7eSLars-Peter Clausen struct snd_soc_dai *dai; 8863e0aa8d8SJyri Sarha struct device_node *component_of_node; 88712023a9aSMisael Lopez Cruz 88834e81ab4SLars-Peter Clausen lockdep_assert_held(&client_mutex); 88934e81ab4SLars-Peter Clausen 89014621c7eSLars-Peter Clausen /* Find CPU DAI from registered DAIs*/ 89114621c7eSLars-Peter Clausen list_for_each_entry(component, &component_list, list) { 8923e0aa8d8SJyri Sarha component_of_node = component->dev->of_node; 8933e0aa8d8SJyri Sarha if (!component_of_node && component->dev->parent) 8943e0aa8d8SJyri Sarha component_of_node = component->dev->parent->of_node; 8953e0aa8d8SJyri Sarha 8963e0aa8d8SJyri Sarha if (dlc->of_node && component_of_node != dlc->of_node) 89712023a9aSMisael Lopez Cruz continue; 8981ffae361SLars-Peter Clausen if (dlc->name && strcmp(component->name, dlc->name)) 89912023a9aSMisael Lopez Cruz continue; 90014621c7eSLars-Peter Clausen list_for_each_entry(dai, &component->dai_list, list) { 90114621c7eSLars-Peter Clausen if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) 90214621c7eSLars-Peter Clausen continue; 90312023a9aSMisael Lopez Cruz 90414621c7eSLars-Peter Clausen return dai; 90512023a9aSMisael Lopez Cruz } 90612023a9aSMisael Lopez Cruz } 90712023a9aSMisael Lopez Cruz 90812023a9aSMisael Lopez Cruz return NULL; 90912023a9aSMisael Lopez Cruz } 91012023a9aSMisael Lopez Cruz 911f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 912db2a4165SFrank Mandarino { 913f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 914f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 91588bd870fSBenoit Cousson struct snd_soc_dai_link_component *codecs = dai_link->codecs; 91614621c7eSLars-Peter Clausen struct snd_soc_dai_link_component cpu_dai_component; 91788bd870fSBenoit Cousson struct snd_soc_dai **codec_dais = rtd->codec_dais; 918435c5e25SMark Brown struct snd_soc_platform *platform; 919848dd8beSMark Brown const char *platform_name; 92088bd870fSBenoit Cousson int i; 921db2a4165SFrank Mandarino 922f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 9236308419aSMark Brown 92414621c7eSLars-Peter Clausen cpu_dai_component.name = dai_link->cpu_name; 92514621c7eSLars-Peter Clausen cpu_dai_component.of_node = dai_link->cpu_of_node; 92614621c7eSLars-Peter Clausen cpu_dai_component.dai_name = dai_link->cpu_dai_name; 92714621c7eSLars-Peter Clausen rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component); 928b19e6e7bSMark Brown if (!rtd->cpu_dai) { 929f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", 930f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 931b19e6e7bSMark Brown return -EPROBE_DEFER; 932c5af3a2eSMark Brown } 933c5af3a2eSMark Brown 93488bd870fSBenoit Cousson rtd->num_codecs = dai_link->num_codecs; 93588bd870fSBenoit Cousson 93688bd870fSBenoit Cousson /* Find CODEC from registered CODECs */ 93788bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 93814621c7eSLars-Peter Clausen codec_dais[i] = snd_soc_find_dai(&codecs[i]); 93988bd870fSBenoit Cousson if (!codec_dais[i]) { 94012023a9aSMisael Lopez Cruz dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", 94188bd870fSBenoit Cousson codecs[i].dai_name); 94212023a9aSMisael Lopez Cruz return -EPROBE_DEFER; 94312023a9aSMisael Lopez Cruz } 94488bd870fSBenoit Cousson } 94588bd870fSBenoit Cousson 94688bd870fSBenoit Cousson /* Single codec links expect codec and codec_dai in runtime data */ 94788bd870fSBenoit Cousson rtd->codec_dai = codec_dais[0]; 94888bd870fSBenoit Cousson rtd->codec = rtd->codec_dai->codec; 94912023a9aSMisael Lopez Cruz 950848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 951848dd8beSMark Brown platform_name = dai_link->platform_name; 9525a504963SStephen Warren if (!platform_name && !dai_link->platform_of_node) 953848dd8beSMark Brown platform_name = "snd-soc-dummy"; 954848dd8beSMark Brown 955b19e6e7bSMark Brown /* find one from the set of registered platforms */ 956f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 9575a504963SStephen Warren if (dai_link->platform_of_node) { 9585a504963SStephen Warren if (platform->dev->of_node != 9595a504963SStephen Warren dai_link->platform_of_node) 9605a504963SStephen Warren continue; 9615a504963SStephen Warren } else { 962f4333203SLars-Peter Clausen if (strcmp(platform->component.name, platform_name)) 9632610ab77SStephen Warren continue; 9645a504963SStephen Warren } 9652610ab77SStephen Warren 966f0fba2adSLiam Girdwood rtd->platform = platform; 967f0fba2adSLiam Girdwood } 968b19e6e7bSMark Brown if (!rtd->platform) { 969f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: platform %s not registered\n", 970f0fba2adSLiam Girdwood dai_link->platform_name); 971b19e6e7bSMark Brown return -EPROBE_DEFER; 972f0fba2adSLiam Girdwood } 973b19e6e7bSMark Brown 974b19e6e7bSMark Brown card->num_rtd++; 975b19e6e7bSMark Brown 976b19e6e7bSMark Brown return 0; 9776b05eda6SMark Brown } 9786b05eda6SMark Brown 979f1d45cc3SLars-Peter Clausen static void soc_remove_component(struct snd_soc_component *component) 980d12cd198SStephen Warren { 98170090bbbSLars-Peter Clausen if (!component->probed) 98270090bbbSLars-Peter Clausen return; 983d12cd198SStephen Warren 984f1d45cc3SLars-Peter Clausen /* This is a HACK and will be removed soon */ 985f1d45cc3SLars-Peter Clausen if (component->codec) 986f1d45cc3SLars-Peter Clausen list_del(&component->codec->card_list); 987d12cd198SStephen Warren 988f1d45cc3SLars-Peter Clausen if (component->remove) 989f1d45cc3SLars-Peter Clausen component->remove(component); 990d12cd198SStephen Warren 991f1d45cc3SLars-Peter Clausen snd_soc_dapm_free(snd_soc_component_get_dapm(component)); 992d12cd198SStephen Warren 993f1d45cc3SLars-Peter Clausen soc_cleanup_component_debugfs(component); 994f1d45cc3SLars-Peter Clausen component->probed = 0; 995f1d45cc3SLars-Peter Clausen module_put(component->dev->driver->owner); 996d12cd198SStephen Warren } 997d12cd198SStephen Warren 998e60cd14fSLars-Peter Clausen static void soc_remove_dai(struct snd_soc_dai *dai, int order) 999589c3563SJarkko Nikula { 1000589c3563SJarkko Nikula int err; 1001589c3563SJarkko Nikula 1002e60cd14fSLars-Peter Clausen if (dai && dai->probed && 1003e60cd14fSLars-Peter Clausen dai->driver->remove_order == order) { 1004e60cd14fSLars-Peter Clausen if (dai->driver->remove) { 1005e60cd14fSLars-Peter Clausen err = dai->driver->remove(dai); 1006589c3563SJarkko Nikula if (err < 0) 1007e60cd14fSLars-Peter Clausen dev_err(dai->dev, 1008b0aa88afSMisael Lopez Cruz "ASoC: failed to remove %s: %d\n", 1009e60cd14fSLars-Peter Clausen dai->name, err); 1010b0aa88afSMisael Lopez Cruz } 1011e60cd14fSLars-Peter Clausen dai->probed = 0; 1012b0aa88afSMisael Lopez Cruz } 1013b0aa88afSMisael Lopez Cruz } 1014b0aa88afSMisael Lopez Cruz 101562ae68faSStephen Warren static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) 1016f0fba2adSLiam Girdwood { 1017f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1018e60cd14fSLars-Peter Clausen int i; 1019f0fba2adSLiam Girdwood 1020f0fba2adSLiam Girdwood /* unregister the rtd device */ 1021f0fba2adSLiam Girdwood if (rtd->dev_registered) { 102236ae1a96SMark Brown device_unregister(rtd->dev); 1023f0fba2adSLiam Girdwood rtd->dev_registered = 0; 102402a06d30SBarry Song } 102502a06d30SBarry Song 1026f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 102788bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) 1028e60cd14fSLars-Peter Clausen soc_remove_dai(rtd->codec_dais[i], order); 1029f0fba2adSLiam Girdwood 1030e60cd14fSLars-Peter Clausen soc_remove_dai(rtd->cpu_dai, order); 1031f0fba2adSLiam Girdwood } 1032f0fba2adSLiam Girdwood 103362ae68faSStephen Warren static void soc_remove_link_components(struct snd_soc_card *card, int num, 103462ae68faSStephen Warren int order) 103562ae68faSStephen Warren { 103662ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 103762ae68faSStephen Warren struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 103862ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 103961aca564SLars-Peter Clausen struct snd_soc_component *component; 104088bd870fSBenoit Cousson int i; 104162ae68faSStephen Warren 104262ae68faSStephen Warren /* remove the platform */ 104370090bbbSLars-Peter Clausen if (platform && platform->component.driver->remove_order == order) 1044f1d45cc3SLars-Peter Clausen soc_remove_component(&platform->component); 104562ae68faSStephen Warren 104662ae68faSStephen Warren /* remove the CODEC-side CODEC */ 104788bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 104861aca564SLars-Peter Clausen component = rtd->codec_dais[i]->component; 104970090bbbSLars-Peter Clausen if (component->driver->remove_order == order) 105061aca564SLars-Peter Clausen soc_remove_component(component); 105162ae68faSStephen Warren } 105262ae68faSStephen Warren 105362ae68faSStephen Warren /* remove any CPU-side CODEC */ 105462ae68faSStephen Warren if (cpu_dai) { 105570090bbbSLars-Peter Clausen if (cpu_dai->component->driver->remove_order == order) 105661aca564SLars-Peter Clausen soc_remove_component(cpu_dai->component); 105762ae68faSStephen Warren } 105862ae68faSStephen Warren } 105962ae68faSStephen Warren 10600671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 10610671fd8eSKuninori Morimoto { 10620168bf0dSLiam Girdwood int dai, order; 10630671fd8eSKuninori Morimoto 10640168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 10650168bf0dSLiam Girdwood order++) { 10660168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 106762ae68faSStephen Warren soc_remove_link_dais(card, dai, order); 10680168bf0dSLiam Girdwood } 106962ae68faSStephen Warren 107062ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 107162ae68faSStephen Warren order++) { 107262ae68faSStephen Warren for (dai = 0; dai < card->num_rtd; dai++) 107362ae68faSStephen Warren soc_remove_link_components(card, dai, order); 107462ae68faSStephen Warren } 107562ae68faSStephen Warren 10760671fd8eSKuninori Morimoto card->num_rtd = 0; 10770671fd8eSKuninori Morimoto } 10780671fd8eSKuninori Morimoto 1079ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 108094f99c87SLars-Peter Clausen struct snd_soc_component *component) 1081ead9b919SJarkko Nikula { 1082ead9b919SJarkko Nikula int i; 1083ead9b919SJarkko Nikula 1084ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 1085ead9b919SJarkko Nikula return; 1086ead9b919SJarkko Nikula 1087ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 1088ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 108994f99c87SLars-Peter Clausen if (map->of_node && component->dev->of_node != map->of_node) 10903ca041edSSebastian Reichel continue; 109194f99c87SLars-Peter Clausen if (map->dev_name && strcmp(component->name, map->dev_name)) 10923ca041edSSebastian Reichel continue; 109394f99c87SLars-Peter Clausen component->name_prefix = map->name_prefix; 1094ead9b919SJarkko Nikula break; 1095ead9b919SJarkko Nikula } 1096ead9b919SJarkko Nikula } 1097ead9b919SJarkko Nikula 1098f1d45cc3SLars-Peter Clausen static int soc_probe_component(struct snd_soc_card *card, 1099f1d45cc3SLars-Peter Clausen struct snd_soc_component *component) 1100589c3563SJarkko Nikula { 1101f1d45cc3SLars-Peter Clausen struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 1102888df395SMark Brown struct snd_soc_dai *dai; 1103f1d45cc3SLars-Peter Clausen int ret; 1104589c3563SJarkko Nikula 110570090bbbSLars-Peter Clausen if (component->probed) 110670090bbbSLars-Peter Clausen return 0; 1107589c3563SJarkko Nikula 1108f1d45cc3SLars-Peter Clausen component->card = card; 1109f1d45cc3SLars-Peter Clausen dapm->card = card; 1110f1d45cc3SLars-Peter Clausen soc_set_name_prefix(card, component); 1111589c3563SJarkko Nikula 1112f1d45cc3SLars-Peter Clausen if (!try_module_get(component->dev->driver->owner)) 111370d29331SJarkko Nikula return -ENODEV; 111470d29331SJarkko Nikula 1115f1d45cc3SLars-Peter Clausen soc_init_component_debugfs(component); 1116d5d1e0beSLars-Peter Clausen 1117f1d45cc3SLars-Peter Clausen if (component->dapm_widgets) { 1118f1d45cc3SLars-Peter Clausen ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets, 1119f1d45cc3SLars-Peter Clausen component->num_dapm_widgets); 112077530150SLars-Peter Clausen 1121b318ad50SNariman Poushin if (ret != 0) { 1122f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1123b318ad50SNariman Poushin "Failed to create new controls %d\n", ret); 1124b318ad50SNariman Poushin goto err_probe; 1125b318ad50SNariman Poushin } 1126b318ad50SNariman Poushin } 1127b318ad50SNariman Poushin 11280634814fSLars-Peter Clausen list_for_each_entry(dai, &component->dai_list, list) { 11290634814fSLars-Peter Clausen ret = snd_soc_dapm_new_dai_widgets(dapm, dai); 1130261edc70SNariman Poushin if (ret != 0) { 1131f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1132261edc70SNariman Poushin "Failed to create DAI widgets %d\n", ret); 1133261edc70SNariman Poushin goto err_probe; 1134261edc70SNariman Poushin } 1135261edc70SNariman Poushin } 1136888df395SMark Brown 1137f1d45cc3SLars-Peter Clausen if (component->probe) { 1138f1d45cc3SLars-Peter Clausen ret = component->probe(component); 1139589c3563SJarkko Nikula if (ret < 0) { 1140f1d45cc3SLars-Peter Clausen dev_err(component->dev, 1141f1d45cc3SLars-Peter Clausen "ASoC: failed to probe component %d\n", ret); 114270d29331SJarkko Nikula goto err_probe; 1143589c3563SJarkko Nikula } 1144cb2cf612SLiam Girdwood 1145f1d45cc3SLars-Peter Clausen WARN(dapm->idle_bias_off && 1146f1d45cc3SLars-Peter Clausen dapm->bias_level != SND_SOC_BIAS_OFF, 1147956245e9SLiam Girdwood "codec %s can not start from non-off bias with idle_bias_off==1\n", 1148f1d45cc3SLars-Peter Clausen component->name); 1149956245e9SLiam Girdwood } 1150956245e9SLiam Girdwood 1151f1d45cc3SLars-Peter Clausen if (component->controls) 1152f1d45cc3SLars-Peter Clausen snd_soc_add_component_controls(component, component->controls, 1153f1d45cc3SLars-Peter Clausen component->num_controls); 1154f1d45cc3SLars-Peter Clausen if (component->dapm_routes) 1155f1d45cc3SLars-Peter Clausen snd_soc_dapm_add_routes(dapm, component->dapm_routes, 1156f1d45cc3SLars-Peter Clausen component->num_dapm_routes); 1157956245e9SLiam Girdwood 1158f1d45cc3SLars-Peter Clausen component->probed = 1; 1159f1d45cc3SLars-Peter Clausen list_add(&dapm->list, &card->dapm_list); 1160f1d45cc3SLars-Peter Clausen 1161f1d45cc3SLars-Peter Clausen /* This is a HACK and will be removed soon */ 1162f1d45cc3SLars-Peter Clausen if (component->codec) 1163f1d45cc3SLars-Peter Clausen list_add(&component->codec->card_list, &card->codec_dev_list); 1164956245e9SLiam Girdwood 1165956245e9SLiam Girdwood return 0; 1166956245e9SLiam Girdwood 1167956245e9SLiam Girdwood err_probe: 1168f1d45cc3SLars-Peter Clausen soc_cleanup_component_debugfs(component); 1169f1d45cc3SLars-Peter Clausen module_put(component->dev->driver->owner); 1170956245e9SLiam Girdwood 1171956245e9SLiam Girdwood return ret; 1172956245e9SLiam Girdwood } 1173956245e9SLiam Girdwood 117436ae1a96SMark Brown static void rtd_release(struct device *dev) 117536ae1a96SMark Brown { 117636ae1a96SMark Brown kfree(dev); 117736ae1a96SMark Brown } 1178f0fba2adSLiam Girdwood 11795f3484acSLars-Peter Clausen static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, 11805f3484acSLars-Peter Clausen const char *name) 1181503ae5e0SMisael Lopez Cruz { 1182589c3563SJarkko Nikula int ret = 0; 1183589c3563SJarkko Nikula 1184589c3563SJarkko Nikula /* register the rtd device */ 118536ae1a96SMark Brown rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 118636ae1a96SMark Brown if (!rtd->dev) 118736ae1a96SMark Brown return -ENOMEM; 118836ae1a96SMark Brown device_initialize(rtd->dev); 11895f3484acSLars-Peter Clausen rtd->dev->parent = rtd->card->dev; 119036ae1a96SMark Brown rtd->dev->release = rtd_release; 1191d29697dcSTakashi Iwai rtd->dev->groups = soc_dev_attr_groups; 1192f294afedSLars-Peter Clausen dev_set_name(rtd->dev, "%s", name); 119336ae1a96SMark Brown dev_set_drvdata(rtd->dev, rtd); 1194b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 119501d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); 119601d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); 119701d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); 119801d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); 119936ae1a96SMark Brown ret = device_add(rtd->dev); 1200589c3563SJarkko Nikula if (ret < 0) { 1201865df9cbSChuansheng Liu /* calling put_device() here to free the rtd->dev */ 1202865df9cbSChuansheng Liu put_device(rtd->dev); 12035f3484acSLars-Peter Clausen dev_err(rtd->card->dev, 1204f110bfc7SLiam Girdwood "ASoC: failed to register runtime device: %d\n", ret); 1205589c3563SJarkko Nikula return ret; 1206589c3563SJarkko Nikula } 1207589c3563SJarkko Nikula rtd->dev_registered = 1; 1208589c3563SJarkko Nikula return 0; 1209589c3563SJarkko Nikula } 1210589c3563SJarkko Nikula 121162ae68faSStephen Warren static int soc_probe_link_components(struct snd_soc_card *card, int num, 121262ae68faSStephen Warren int order) 121362ae68faSStephen Warren { 121462ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 121562ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 1216f1d45cc3SLars-Peter Clausen struct snd_soc_component *component; 121788bd870fSBenoit Cousson int i, ret; 121862ae68faSStephen Warren 121962ae68faSStephen Warren /* probe the CPU-side component, if it is a CODEC */ 122061aca564SLars-Peter Clausen component = rtd->cpu_dai->component; 122170090bbbSLars-Peter Clausen if (component->driver->probe_order == order) { 1222f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, component); 122362ae68faSStephen Warren if (ret < 0) 122462ae68faSStephen Warren return ret; 122562ae68faSStephen Warren } 122662ae68faSStephen Warren 122788bd870fSBenoit Cousson /* probe the CODEC-side components */ 122888bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 122961aca564SLars-Peter Clausen component = rtd->codec_dais[i]->component; 123070090bbbSLars-Peter Clausen if (component->driver->probe_order == order) { 1231f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, component); 123262ae68faSStephen Warren if (ret < 0) 123362ae68faSStephen Warren return ret; 123462ae68faSStephen Warren } 123588bd870fSBenoit Cousson } 123662ae68faSStephen Warren 123762ae68faSStephen Warren /* probe the platform */ 123870090bbbSLars-Peter Clausen if (platform->component.driver->probe_order == order) { 1239f1d45cc3SLars-Peter Clausen ret = soc_probe_component(card, &platform->component); 124062ae68faSStephen Warren if (ret < 0) 124162ae68faSStephen Warren return ret; 124262ae68faSStephen Warren } 124362ae68faSStephen Warren 124462ae68faSStephen Warren return 0; 124562ae68faSStephen Warren } 124662ae68faSStephen Warren 12478e2be562SLars-Peter Clausen static int soc_probe_dai(struct snd_soc_dai *dai, int order) 1248b0aa88afSMisael Lopez Cruz { 1249b0aa88afSMisael Lopez Cruz int ret; 1250b0aa88afSMisael Lopez Cruz 12518e2be562SLars-Peter Clausen if (!dai->probed && dai->driver->probe_order == order) { 12528e2be562SLars-Peter Clausen if (dai->driver->probe) { 12538e2be562SLars-Peter Clausen ret = dai->driver->probe(dai); 1254b0aa88afSMisael Lopez Cruz if (ret < 0) { 12558e2be562SLars-Peter Clausen dev_err(dai->dev, 12568e2be562SLars-Peter Clausen "ASoC: failed to probe DAI %s: %d\n", 12578e2be562SLars-Peter Clausen dai->name, ret); 1258b0aa88afSMisael Lopez Cruz return ret; 1259b0aa88afSMisael Lopez Cruz } 1260b0aa88afSMisael Lopez Cruz } 1261b0aa88afSMisael Lopez Cruz 12628e2be562SLars-Peter Clausen dai->probed = 1; 1263b0aa88afSMisael Lopez Cruz } 1264b0aa88afSMisael Lopez Cruz 1265b0aa88afSMisael Lopez Cruz return 0; 1266b0aa88afSMisael Lopez Cruz } 1267b0aa88afSMisael Lopez Cruz 12682436a723SMisael Lopez Cruz static int soc_link_dai_widgets(struct snd_soc_card *card, 12692436a723SMisael Lopez Cruz struct snd_soc_dai_link *dai_link, 12703f901a02SBenoit Cousson struct snd_soc_pcm_runtime *rtd) 12712436a723SMisael Lopez Cruz { 12723f901a02SBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 12733f901a02SBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dai; 12742436a723SMisael Lopez Cruz struct snd_soc_dapm_widget *play_w, *capture_w; 12752436a723SMisael Lopez Cruz int ret; 12762436a723SMisael Lopez Cruz 127788bd870fSBenoit Cousson if (rtd->num_codecs > 1) 127888bd870fSBenoit Cousson dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n"); 127988bd870fSBenoit Cousson 12802436a723SMisael Lopez Cruz /* link the DAI widgets */ 12812436a723SMisael Lopez Cruz play_w = codec_dai->playback_widget; 12822436a723SMisael Lopez Cruz capture_w = cpu_dai->capture_widget; 12832436a723SMisael Lopez Cruz if (play_w && capture_w) { 12842436a723SMisael Lopez Cruz ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1285c6615082SNikesh Oswal dai_link->num_params, capture_w, 1286c6615082SNikesh Oswal play_w); 12872436a723SMisael Lopez Cruz if (ret != 0) { 12882436a723SMisael Lopez Cruz dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 12892436a723SMisael Lopez Cruz play_w->name, capture_w->name, ret); 12902436a723SMisael Lopez Cruz return ret; 12912436a723SMisael Lopez Cruz } 12922436a723SMisael Lopez Cruz } 12932436a723SMisael Lopez Cruz 12942436a723SMisael Lopez Cruz play_w = cpu_dai->playback_widget; 12952436a723SMisael Lopez Cruz capture_w = codec_dai->capture_widget; 12962436a723SMisael Lopez Cruz if (play_w && capture_w) { 12972436a723SMisael Lopez Cruz ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1298c6615082SNikesh Oswal dai_link->num_params, capture_w, 1299c6615082SNikesh Oswal play_w); 13002436a723SMisael Lopez Cruz if (ret != 0) { 13012436a723SMisael Lopez Cruz dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 13022436a723SMisael Lopez Cruz play_w->name, capture_w->name, ret); 13032436a723SMisael Lopez Cruz return ret; 13042436a723SMisael Lopez Cruz } 13052436a723SMisael Lopez Cruz } 13062436a723SMisael Lopez Cruz 13072436a723SMisael Lopez Cruz return 0; 13082436a723SMisael Lopez Cruz } 13092436a723SMisael Lopez Cruz 131062ae68faSStephen Warren static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) 1311f0fba2adSLiam Girdwood { 1312f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1313f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1314c74184edSMark Brown struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 131588bd870fSBenoit Cousson int i, ret; 1316f0fba2adSLiam Girdwood 1317f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", 13180168bf0dSLiam Girdwood card->name, num, order); 1319f0fba2adSLiam Girdwood 1320f0fba2adSLiam Girdwood /* set default power off timeout */ 1321f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1322f0fba2adSLiam Girdwood 13238e2be562SLars-Peter Clausen ret = soc_probe_dai(cpu_dai, order); 13248e2be562SLars-Peter Clausen if (ret) 1325f0fba2adSLiam Girdwood return ret; 1326f0fba2adSLiam Girdwood 1327f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 132888bd870fSBenoit Cousson for (i = 0; i < rtd->num_codecs; i++) { 13298e2be562SLars-Peter Clausen ret = soc_probe_dai(rtd->codec_dais[i], order); 1330b0aa88afSMisael Lopez Cruz if (ret) 1331f0fba2adSLiam Girdwood return ret; 133288bd870fSBenoit Cousson } 1333f0fba2adSLiam Girdwood 13340168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 13350168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 13360168bf0dSLiam Girdwood return 0; 13370168bf0dSLiam Girdwood 13385f3484acSLars-Peter Clausen /* do machine specific initialization */ 13395f3484acSLars-Peter Clausen if (dai_link->init) { 13405f3484acSLars-Peter Clausen ret = dai_link->init(rtd); 13415f3484acSLars-Peter Clausen if (ret < 0) { 13425f3484acSLars-Peter Clausen dev_err(card->dev, "ASoC: failed to init %s: %d\n", 13435f3484acSLars-Peter Clausen dai_link->name, ret); 13445f3484acSLars-Peter Clausen return ret; 13455f3484acSLars-Peter Clausen } 13465f3484acSLars-Peter Clausen } 13475f3484acSLars-Peter Clausen 1348a5053a8eSKuninori Morimoto if (dai_link->dai_fmt) 1349a5053a8eSKuninori Morimoto snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); 1350a5053a8eSKuninori Morimoto 13515f3484acSLars-Peter Clausen ret = soc_post_component_init(rtd, dai_link->name); 1352589c3563SJarkko Nikula if (ret) 1353f0fba2adSLiam Girdwood return ret; 1354f0fba2adSLiam Girdwood 13555f3484acSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 13565f3484acSLars-Peter Clausen /* add DPCM sysfs entries */ 13572e55b90aSLars-Peter Clausen if (dai_link->dynamic) 13582e55b90aSLars-Peter Clausen soc_dpcm_debugfs_add(rtd); 13595f3484acSLars-Peter Clausen #endif 13605f3484acSLars-Peter Clausen 13611245b700SNamarta Kohli if (cpu_dai->driver->compress_dai) { 13621245b700SNamarta Kohli /*create compress_device"*/ 13631245b700SNamarta Kohli ret = soc_new_compress(rtd, num); 13641245b700SNamarta Kohli if (ret < 0) { 1365f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create compress %s\n", 13661245b700SNamarta Kohli dai_link->stream_name); 13671245b700SNamarta Kohli return ret; 13681245b700SNamarta Kohli } 13691245b700SNamarta Kohli } else { 13701245b700SNamarta Kohli 1371c74184edSMark Brown if (!dai_link->params) { 1372f0fba2adSLiam Girdwood /* create the pcm */ 1373f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1374f0fba2adSLiam Girdwood if (ret < 0) { 1375f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", 13760837fc62SFabio Estevam dai_link->stream_name, ret); 1377f0fba2adSLiam Girdwood return ret; 1378f0fba2adSLiam Girdwood } 1379c74184edSMark Brown } else { 13809d58a077SRichard Fitzgerald INIT_DELAYED_WORK(&rtd->delayed_work, 13819d58a077SRichard Fitzgerald codec2codec_close_delayed_work); 13829d58a077SRichard Fitzgerald 1383c74184edSMark Brown /* link the DAI widgets */ 13843f901a02SBenoit Cousson ret = soc_link_dai_widgets(card, dai_link, rtd); 13852436a723SMisael Lopez Cruz if (ret) 1386c74184edSMark Brown return ret; 1387c74184edSMark Brown } 1388c74184edSMark Brown } 1389c74184edSMark Brown 1390f0fba2adSLiam Girdwood return 0; 1391f0fba2adSLiam Girdwood } 1392f0fba2adSLiam Girdwood 139344c69bb1SLars-Peter Clausen static int soc_bind_aux_dev(struct snd_soc_card *card, int num) 1394b19e6e7bSMark Brown { 139544c69bb1SLars-Peter Clausen struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 13963ca041edSSebastian Reichel struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 139765d9361fSLars-Peter Clausen const char *name = aux_dev->codec_name; 13983ca041edSSebastian Reichel 139965d9361fSLars-Peter Clausen rtd->component = soc_find_component(aux_dev->codec_of_node, name); 140065d9361fSLars-Peter Clausen if (!rtd->component) { 14013ca041edSSebastian Reichel if (aux_dev->codec_of_node) 140265d9361fSLars-Peter Clausen name = of_node_full_name(aux_dev->codec_of_node); 14033ca041edSSebastian Reichel 140465d9361fSLars-Peter Clausen dev_err(card->dev, "ASoC: %s not registered\n", name); 1405b19e6e7bSMark Brown return -EPROBE_DEFER; 1406b19e6e7bSMark Brown } 1407b19e6e7bSMark Brown 140865d9361fSLars-Peter Clausen /* 140965d9361fSLars-Peter Clausen * Some places still reference rtd->codec, so we have to keep that 141065d9361fSLars-Peter Clausen * initialized if the component is a CODEC. Once all those references 141165d9361fSLars-Peter Clausen * have been removed, this code can be removed as well. 141265d9361fSLars-Peter Clausen */ 141365d9361fSLars-Peter Clausen rtd->codec = rtd->component->codec; 141465d9361fSLars-Peter Clausen 141544c69bb1SLars-Peter Clausen return 0; 14163ca041edSSebastian Reichel } 14172eea392dSJarkko Nikula 141844c69bb1SLars-Peter Clausen static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 141944c69bb1SLars-Peter Clausen { 142044c69bb1SLars-Peter Clausen struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 14215f3484acSLars-Peter Clausen struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 142244c69bb1SLars-Peter Clausen int ret; 142344c69bb1SLars-Peter Clausen 142465d9361fSLars-Peter Clausen ret = soc_probe_component(card, rtd->component); 14252eea392dSJarkko Nikula if (ret < 0) 1426589c3563SJarkko Nikula return ret; 14272eea392dSJarkko Nikula 14285f3484acSLars-Peter Clausen /* do machine specific initialization */ 14295f3484acSLars-Peter Clausen if (aux_dev->init) { 143057bf7726SLars-Peter Clausen ret = aux_dev->init(rtd->component); 14315f3484acSLars-Peter Clausen if (ret < 0) { 14325f3484acSLars-Peter Clausen dev_err(card->dev, "ASoC: failed to init %s: %d\n", 14335f3484acSLars-Peter Clausen aux_dev->name, ret); 14342eea392dSJarkko Nikula return ret; 14352eea392dSJarkko Nikula } 14365f3484acSLars-Peter Clausen } 14375f3484acSLars-Peter Clausen 14385f3484acSLars-Peter Clausen return soc_post_component_init(rtd, aux_dev->name); 14392eea392dSJarkko Nikula } 14402eea392dSJarkko Nikula 14412eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 14422eea392dSJarkko Nikula { 14432eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 144465d9361fSLars-Peter Clausen struct snd_soc_component *component = rtd->component; 14452eea392dSJarkko Nikula 14462eea392dSJarkko Nikula /* unregister the rtd device */ 14472eea392dSJarkko Nikula if (rtd->dev_registered) { 1448d3bf1561SChuansheng Liu device_unregister(rtd->dev); 14492eea392dSJarkko Nikula rtd->dev_registered = 0; 14502eea392dSJarkko Nikula } 14512eea392dSJarkko Nikula 145265d9361fSLars-Peter Clausen if (component && component->probed) 145365d9361fSLars-Peter Clausen soc_remove_component(component); 14542eea392dSJarkko Nikula } 14552eea392dSJarkko Nikula 1456f90fb3f7SLars-Peter Clausen static int snd_soc_init_codec_cache(struct snd_soc_codec *codec) 1457fdf0f54dSDimitris Papastamos { 1458fdf0f54dSDimitris Papastamos int ret; 1459fdf0f54dSDimitris Papastamos 1460fdf0f54dSDimitris Papastamos if (codec->cache_init) 1461fdf0f54dSDimitris Papastamos return 0; 1462fdf0f54dSDimitris Papastamos 1463fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1464fdf0f54dSDimitris Papastamos if (ret < 0) { 146510e8aa9aSMichał Mirosław dev_err(codec->dev, 146610e8aa9aSMichał Mirosław "ASoC: Failed to set cache compression type: %d\n", 146710e8aa9aSMichał Mirosław ret); 1468fdf0f54dSDimitris Papastamos return ret; 1469fdf0f54dSDimitris Papastamos } 1470fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1471fdf0f54dSDimitris Papastamos return 0; 1472fdf0f54dSDimitris Papastamos } 1473fdf0f54dSDimitris Papastamos 1474ce64c8b9SLars-Peter Clausen /** 1475ce64c8b9SLars-Peter Clausen * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime 1476ce64c8b9SLars-Peter Clausen * @rtd: The runtime for which the DAI link format should be changed 1477ce64c8b9SLars-Peter Clausen * @dai_fmt: The new DAI link format 1478ce64c8b9SLars-Peter Clausen * 1479ce64c8b9SLars-Peter Clausen * This function updates the DAI link format for all DAIs connected to the DAI 1480ce64c8b9SLars-Peter Clausen * link for the specified runtime. 1481ce64c8b9SLars-Peter Clausen * 1482ce64c8b9SLars-Peter Clausen * Note: For setups with a static format set the dai_fmt field in the 1483ce64c8b9SLars-Peter Clausen * corresponding snd_dai_link struct instead of using this function. 1484ce64c8b9SLars-Peter Clausen * 1485ce64c8b9SLars-Peter Clausen * Returns 0 on success, otherwise a negative error code. 1486ce64c8b9SLars-Peter Clausen */ 1487ce64c8b9SLars-Peter Clausen int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, 1488ce64c8b9SLars-Peter Clausen unsigned int dai_fmt) 1489ce64c8b9SLars-Peter Clausen { 1490ce64c8b9SLars-Peter Clausen struct snd_soc_dai **codec_dais = rtd->codec_dais; 1491ce64c8b9SLars-Peter Clausen struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1492ce64c8b9SLars-Peter Clausen unsigned int i; 1493ce64c8b9SLars-Peter Clausen int ret; 1494ce64c8b9SLars-Peter Clausen 1495ce64c8b9SLars-Peter Clausen for (i = 0; i < rtd->num_codecs; i++) { 1496ce64c8b9SLars-Peter Clausen struct snd_soc_dai *codec_dai = codec_dais[i]; 1497ce64c8b9SLars-Peter Clausen 1498ce64c8b9SLars-Peter Clausen ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); 1499ce64c8b9SLars-Peter Clausen if (ret != 0 && ret != -ENOTSUPP) { 1500ce64c8b9SLars-Peter Clausen dev_warn(codec_dai->dev, 1501ce64c8b9SLars-Peter Clausen "ASoC: Failed to set DAI format: %d\n", ret); 1502ce64c8b9SLars-Peter Clausen return ret; 1503ce64c8b9SLars-Peter Clausen } 1504ce64c8b9SLars-Peter Clausen } 1505ce64c8b9SLars-Peter Clausen 1506ce64c8b9SLars-Peter Clausen /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */ 1507ce64c8b9SLars-Peter Clausen if (cpu_dai->codec) { 1508ce64c8b9SLars-Peter Clausen unsigned int inv_dai_fmt; 1509ce64c8b9SLars-Peter Clausen 1510ce64c8b9SLars-Peter Clausen inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK; 1511ce64c8b9SLars-Peter Clausen switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1512ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBM_CFM: 1513ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; 1514ce64c8b9SLars-Peter Clausen break; 1515ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBM_CFS: 1516ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; 1517ce64c8b9SLars-Peter Clausen break; 1518ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBS_CFM: 1519ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; 1520ce64c8b9SLars-Peter Clausen break; 1521ce64c8b9SLars-Peter Clausen case SND_SOC_DAIFMT_CBS_CFS: 1522ce64c8b9SLars-Peter Clausen inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 1523ce64c8b9SLars-Peter Clausen break; 1524ce64c8b9SLars-Peter Clausen } 1525ce64c8b9SLars-Peter Clausen 1526ce64c8b9SLars-Peter Clausen dai_fmt = inv_dai_fmt; 1527ce64c8b9SLars-Peter Clausen } 1528ce64c8b9SLars-Peter Clausen 1529ce64c8b9SLars-Peter Clausen ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); 1530ce64c8b9SLars-Peter Clausen if (ret != 0 && ret != -ENOTSUPP) { 1531ce64c8b9SLars-Peter Clausen dev_warn(cpu_dai->dev, 1532ce64c8b9SLars-Peter Clausen "ASoC: Failed to set DAI format: %d\n", ret); 1533ce64c8b9SLars-Peter Clausen return ret; 1534ce64c8b9SLars-Peter Clausen } 1535ce64c8b9SLars-Peter Clausen 1536ce64c8b9SLars-Peter Clausen return 0; 1537ce64c8b9SLars-Peter Clausen } 1538ddaca25aSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt); 1539ce64c8b9SLars-Peter Clausen 1540b19e6e7bSMark Brown static int snd_soc_instantiate_card(struct snd_soc_card *card) 1541f0fba2adSLiam Girdwood { 1542fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1543ce64c8b9SLars-Peter Clausen int ret, i, order; 154496dd3622SMark Brown 154534e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 154601b9d99aSLiam Girdwood mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); 1547f0fba2adSLiam Girdwood 1548b19e6e7bSMark Brown /* bind DAIs */ 1549b19e6e7bSMark Brown for (i = 0; i < card->num_links; i++) { 1550b19e6e7bSMark Brown ret = soc_bind_dai_link(card, i); 1551b19e6e7bSMark Brown if (ret != 0) 1552b19e6e7bSMark Brown goto base_error; 1553db2a4165SFrank Mandarino } 1554db2a4165SFrank Mandarino 155544c69bb1SLars-Peter Clausen /* bind aux_devs too */ 1556b19e6e7bSMark Brown for (i = 0; i < card->num_aux_devs; i++) { 155744c69bb1SLars-Peter Clausen ret = soc_bind_aux_dev(card, i); 1558b19e6e7bSMark Brown if (ret != 0) 1559b19e6e7bSMark Brown goto base_error; 1560db2a4165SFrank Mandarino } 1561db2a4165SFrank Mandarino 1562fdf0f54dSDimitris Papastamos /* initialize the register cache for each available codec */ 1563fdf0f54dSDimitris Papastamos list_for_each_entry(codec, &codec_list, list) { 1564fdf0f54dSDimitris Papastamos if (codec->cache_init) 1565fdf0f54dSDimitris Papastamos continue; 1566f90fb3f7SLars-Peter Clausen ret = snd_soc_init_codec_cache(codec); 1567b19e6e7bSMark Brown if (ret < 0) 1568b19e6e7bSMark Brown goto base_error; 1569fdf0f54dSDimitris Papastamos } 1570fdf0f54dSDimitris Papastamos 1571f0fba2adSLiam Girdwood /* card bind complete so register a sound card */ 1572102b5a8dSTakashi Iwai ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1573f0fba2adSLiam Girdwood card->owner, 0, &card->snd_card); 1574f0fba2adSLiam Girdwood if (ret < 0) { 157510e8aa9aSMichał Mirosław dev_err(card->dev, 157610e8aa9aSMichał Mirosław "ASoC: can't create sound card for card %s: %d\n", 157710e8aa9aSMichał Mirosław card->name, ret); 1578b19e6e7bSMark Brown goto base_error; 1579db2a4165SFrank Mandarino } 1580db2a4165SFrank Mandarino 15810757d834SLars-Peter Clausen soc_init_card_debugfs(card); 15820757d834SLars-Peter Clausen 1583e37a4970SMark Brown card->dapm.bias_level = SND_SOC_BIAS_OFF; 1584e37a4970SMark Brown card->dapm.dev = card->dev; 1585e37a4970SMark Brown card->dapm.card = card; 1586e37a4970SMark Brown list_add(&card->dapm.list, &card->dapm_list); 1587e37a4970SMark Brown 1588d5d1e0beSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 1589d5d1e0beSLars-Peter Clausen snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); 1590d5d1e0beSLars-Peter Clausen #endif 1591d5d1e0beSLars-Peter Clausen 159288ee1c61SMark Brown #ifdef CONFIG_PM_SLEEP 15936ed25978SAndy Green /* deferred resume work */ 15946308419aSMark Brown INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 15951301a964SRandy Dunlap #endif 15966ed25978SAndy Green 15979a841ebbSMark Brown if (card->dapm_widgets) 15989a841ebbSMark Brown snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 15999a841ebbSMark Brown card->num_dapm_widgets); 16009a841ebbSMark Brown 1601f23e860eSNicolin Chen if (card->of_dapm_widgets) 1602f23e860eSNicolin Chen snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, 1603f23e860eSNicolin Chen card->num_of_dapm_widgets); 1604f23e860eSNicolin Chen 1605f0fba2adSLiam Girdwood /* initialise the sound card only once */ 1606f0fba2adSLiam Girdwood if (card->probe) { 1607e7361ec4SMark Brown ret = card->probe(card); 1608f0fba2adSLiam Girdwood if (ret < 0) 1609f0fba2adSLiam Girdwood goto card_probe_error; 1610f0fba2adSLiam Girdwood } 1611f0fba2adSLiam Girdwood 161262ae68faSStephen Warren /* probe all components used by DAI links on this card */ 16130168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 16140168bf0dSLiam Girdwood order++) { 1615fe3e78e0SMark Brown for (i = 0; i < card->num_links; i++) { 161662ae68faSStephen Warren ret = soc_probe_link_components(card, i, order); 161762ae68faSStephen Warren if (ret < 0) { 1618f110bfc7SLiam Girdwood dev_err(card->dev, 1619f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1620f110bfc7SLiam Girdwood ret); 162162ae68faSStephen Warren goto probe_dai_err; 162262ae68faSStephen Warren } 162362ae68faSStephen Warren } 162462ae68faSStephen Warren } 162562ae68faSStephen Warren 162662ae68faSStephen Warren /* probe all DAI links on this card */ 162762ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 162862ae68faSStephen Warren order++) { 162962ae68faSStephen Warren for (i = 0; i < card->num_links; i++) { 163062ae68faSStephen Warren ret = soc_probe_link_dais(card, i, order); 1631fe3e78e0SMark Brown if (ret < 0) { 1632f110bfc7SLiam Girdwood dev_err(card->dev, 1633f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1634f110bfc7SLiam Girdwood ret); 1635f0fba2adSLiam Girdwood goto probe_dai_err; 1636fe3e78e0SMark Brown } 1637fe3e78e0SMark Brown } 16380168bf0dSLiam Girdwood } 1639fe3e78e0SMark Brown 16402eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) { 16412eea392dSJarkko Nikula ret = soc_probe_aux_dev(card, i); 16422eea392dSJarkko Nikula if (ret < 0) { 1643f110bfc7SLiam Girdwood dev_err(card->dev, 1644f110bfc7SLiam Girdwood "ASoC: failed to add auxiliary devices %d\n", 1645f110bfc7SLiam Girdwood ret); 16462eea392dSJarkko Nikula goto probe_aux_dev_err; 16472eea392dSJarkko Nikula } 16482eea392dSJarkko Nikula } 16492eea392dSJarkko Nikula 1650888df395SMark Brown snd_soc_dapm_link_dai_widgets(card); 1651b893ea5fSLiam Girdwood snd_soc_dapm_connect_dai_link_widgets(card); 1652888df395SMark Brown 1653b7af1dafSMark Brown if (card->controls) 1654022658beSLiam Girdwood snd_soc_add_card_controls(card, card->controls, card->num_controls); 1655b7af1dafSMark Brown 1656b8ad29deSMark Brown if (card->dapm_routes) 1657b8ad29deSMark Brown snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1658b8ad29deSMark Brown card->num_dapm_routes); 1659b8ad29deSMark Brown 1660f23e860eSNicolin Chen if (card->of_dapm_routes) 1661f23e860eSNicolin Chen snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, 1662f23e860eSNicolin Chen card->num_of_dapm_routes); 166375d9ac46SMark Brown 1664f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1665fe3e78e0SMark Brown "%s", card->name); 1666f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 166722de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1668f0e8ed85SMark Brown snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), 1669f0e8ed85SMark Brown "%s", card->driver_name ? card->driver_name : card->name); 1670f0e8ed85SMark Brown for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { 1671f0e8ed85SMark Brown switch (card->snd_card->driver[i]) { 1672f0e8ed85SMark Brown case '_': 1673f0e8ed85SMark Brown case '-': 1674f0e8ed85SMark Brown case '\0': 1675f0e8ed85SMark Brown break; 1676f0e8ed85SMark Brown default: 1677f0e8ed85SMark Brown if (!isalnum(card->snd_card->driver[i])) 1678f0e8ed85SMark Brown card->snd_card->driver[i] = '_'; 1679f0e8ed85SMark Brown break; 1680f0e8ed85SMark Brown } 1681f0e8ed85SMark Brown } 1682fe3e78e0SMark Brown 168328e9ad92SMark Brown if (card->late_probe) { 168428e9ad92SMark Brown ret = card->late_probe(card); 168528e9ad92SMark Brown if (ret < 0) { 1686f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", 168728e9ad92SMark Brown card->name, ret); 168828e9ad92SMark Brown goto probe_aux_dev_err; 168928e9ad92SMark Brown } 169028e9ad92SMark Brown } 169128e9ad92SMark Brown 1692824ef826SLars-Peter Clausen snd_soc_dapm_new_widgets(card); 16938c193b8dSLars-Peter Clausen 1694f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1695fe3e78e0SMark Brown if (ret < 0) { 1696f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: failed to register soundcard %d\n", 1697f110bfc7SLiam Girdwood ret); 16986b3ed785SAxel Lin goto probe_aux_dev_err; 1699fe3e78e0SMark Brown } 1700fe3e78e0SMark Brown 1701435c5e25SMark Brown card->instantiated = 1; 17024f4c0072SMark Brown snd_soc_dapm_sync(&card->dapm); 1703f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 170434e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 1705b19e6e7bSMark Brown 1706b19e6e7bSMark Brown return 0; 1707db2a4165SFrank Mandarino 17082eea392dSJarkko Nikula probe_aux_dev_err: 17092eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 17102eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 17112eea392dSJarkko Nikula 1712f0fba2adSLiam Girdwood probe_dai_err: 17130671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1714fe3e78e0SMark Brown 1715f0fba2adSLiam Girdwood card_probe_error: 171687506549SMark Brown if (card->remove) 1717e7361ec4SMark Brown card->remove(card); 1718f0fba2adSLiam Girdwood 17190757d834SLars-Peter Clausen soc_cleanup_card_debugfs(card); 1720f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1721f0fba2adSLiam Girdwood 1722b19e6e7bSMark Brown base_error: 1723f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 172434e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 1725db2a4165SFrank Mandarino 1726b19e6e7bSMark Brown return ret; 1727435c5e25SMark Brown } 1728435c5e25SMark Brown 1729435c5e25SMark Brown /* probes a new socdev */ 1730435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1731435c5e25SMark Brown { 1732f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1733435c5e25SMark Brown 173470a7ca34SVinod Koul /* 173570a7ca34SVinod Koul * no card, so machine driver should be registering card 173670a7ca34SVinod Koul * we should not be here in that case so ret error 173770a7ca34SVinod Koul */ 173870a7ca34SVinod Koul if (!card) 173970a7ca34SVinod Koul return -EINVAL; 174070a7ca34SVinod Koul 1741fe4085e8SMark Brown dev_warn(&pdev->dev, 1742f110bfc7SLiam Girdwood "ASoC: machine %s should use snd_soc_register_card()\n", 1743fe4085e8SMark Brown card->name); 1744fe4085e8SMark Brown 1745435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1746435c5e25SMark Brown card->dev = &pdev->dev; 1747f0fba2adSLiam Girdwood 174828d528c8SMark Brown return snd_soc_register_card(card); 1749435c5e25SMark Brown } 1750435c5e25SMark Brown 1751b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1752db2a4165SFrank Mandarino { 1753db2a4165SFrank Mandarino int i; 1754db2a4165SFrank Mandarino 1755f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1756f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1757f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 175843829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1759db2a4165SFrank Mandarino } 1760db2a4165SFrank Mandarino 17612eea392dSJarkko Nikula /* remove auxiliary devices */ 17622eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 17632eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 17642eea392dSJarkko Nikula 1765f0fba2adSLiam Girdwood /* remove and free each DAI */ 17660671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1767f0fba2adSLiam Girdwood 1768a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1769a6052154SJarkko Nikula 1770f0fba2adSLiam Girdwood /* remove the card */ 177187506549SMark Brown if (card->remove) 1772e7361ec4SMark Brown card->remove(card); 1773f0fba2adSLiam Girdwood 17740aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 17750aaae527SLars-Peter Clausen 1776f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1777b0e26485SVinod Koul return 0; 1778b0e26485SVinod Koul 1779b2dfa62cSGuennadi Liakhovetski } 1780b0e26485SVinod Koul 1781b0e26485SVinod Koul /* removes a socdev */ 1782b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1783b0e26485SVinod Koul { 1784b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1785b0e26485SVinod Koul 1786c5af3a2eSMark Brown snd_soc_unregister_card(card); 1787db2a4165SFrank Mandarino return 0; 1788db2a4165SFrank Mandarino } 1789db2a4165SFrank Mandarino 17906f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 179151737470SMark Brown { 17926f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1793f0fba2adSLiam Girdwood int i; 179451737470SMark Brown 179551737470SMark Brown if (!card->instantiated) 1796416356fcSMark Brown return 0; 179751737470SMark Brown 179851737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 179951737470SMark Brown * now, we're shutting down so no imminent restart. */ 1800f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1801f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 180243829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1803f0fba2adSLiam Girdwood } 180451737470SMark Brown 1805f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1806416356fcSMark Brown 1807988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 1808988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 180988bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 181088bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 181188bd870fSBenoit Cousson int j; 181288bd870fSBenoit Cousson 1813988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 181488bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 181588bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 181688bd870fSBenoit Cousson pinctrl_pm_select_sleep_state(codec_dai->dev); 181788bd870fSBenoit Cousson } 1818988e8cc4SNicolin Chen } 1819988e8cc4SNicolin Chen 1820416356fcSMark Brown return 0; 182151737470SMark Brown } 18226f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 182351737470SMark Brown 18246f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 1825b1dd5897SViresh Kumar .suspend = snd_soc_suspend, 1826b1dd5897SViresh Kumar .resume = snd_soc_resume, 1827b1dd5897SViresh Kumar .freeze = snd_soc_suspend, 1828b1dd5897SViresh Kumar .thaw = snd_soc_resume, 18296f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1830b1dd5897SViresh Kumar .restore = snd_soc_resume, 1831416356fcSMark Brown }; 1832deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1833416356fcSMark Brown 1834db2a4165SFrank Mandarino /* ASoC platform driver */ 1835db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1836db2a4165SFrank Mandarino .driver = { 1837db2a4165SFrank Mandarino .name = "soc-audio", 18386f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1839db2a4165SFrank Mandarino }, 1840db2a4165SFrank Mandarino .probe = soc_probe, 1841db2a4165SFrank Mandarino .remove = soc_remove, 1842db2a4165SFrank Mandarino }; 1843db2a4165SFrank Mandarino 1844096e49d5SMark Brown /** 1845db2a4165SFrank Mandarino * snd_soc_cnew - create new control 1846db2a4165SFrank Mandarino * @_template: control template 1847db2a4165SFrank Mandarino * @data: control private data 1848ac11a2b3SMark Brown * @long_name: control long name 1849efb7ac3fSMark Brown * @prefix: control name prefix 1850db2a4165SFrank Mandarino * 1851db2a4165SFrank Mandarino * Create a new mixer control from a template control. 1852db2a4165SFrank Mandarino * 1853db2a4165SFrank Mandarino * Returns 0 for success, else error. 1854db2a4165SFrank Mandarino */ 1855db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 18563056557fSMark Brown void *data, const char *long_name, 1857efb7ac3fSMark Brown const char *prefix) 1858db2a4165SFrank Mandarino { 1859db2a4165SFrank Mandarino struct snd_kcontrol_new template; 1860efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 1861efb7ac3fSMark Brown char *name = NULL; 1862db2a4165SFrank Mandarino 1863db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 1864db2a4165SFrank Mandarino template.index = 0; 1865db2a4165SFrank Mandarino 1866efb7ac3fSMark Brown if (!long_name) 1867efb7ac3fSMark Brown long_name = template.name; 1868efb7ac3fSMark Brown 1869efb7ac3fSMark Brown if (prefix) { 18702b581074SLars-Peter Clausen name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); 1871efb7ac3fSMark Brown if (!name) 1872efb7ac3fSMark Brown return NULL; 1873efb7ac3fSMark Brown 1874efb7ac3fSMark Brown template.name = name; 1875efb7ac3fSMark Brown } else { 1876efb7ac3fSMark Brown template.name = long_name; 1877efb7ac3fSMark Brown } 1878efb7ac3fSMark Brown 1879efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 1880efb7ac3fSMark Brown 1881efb7ac3fSMark Brown kfree(name); 1882efb7ac3fSMark Brown 1883efb7ac3fSMark Brown return kcontrol; 1884db2a4165SFrank Mandarino } 1885db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 1886db2a4165SFrank Mandarino 1887022658beSLiam Girdwood static int snd_soc_add_controls(struct snd_card *card, struct device *dev, 1888022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls, 1889022658beSLiam Girdwood const char *prefix, void *data) 1890022658beSLiam Girdwood { 1891022658beSLiam Girdwood int err, i; 1892022658beSLiam Girdwood 1893022658beSLiam Girdwood for (i = 0; i < num_controls; i++) { 1894022658beSLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 1895022658beSLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, data, 1896022658beSLiam Girdwood control->name, prefix)); 1897022658beSLiam Girdwood if (err < 0) { 1898f110bfc7SLiam Girdwood dev_err(dev, "ASoC: Failed to add %s: %d\n", 1899f110bfc7SLiam Girdwood control->name, err); 1900022658beSLiam Girdwood return err; 1901022658beSLiam Girdwood } 1902022658beSLiam Girdwood } 1903022658beSLiam Girdwood 1904022658beSLiam Girdwood return 0; 1905022658beSLiam Girdwood } 1906022658beSLiam Girdwood 19074fefd698SDimitris Papastamos struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, 19084fefd698SDimitris Papastamos const char *name) 19094fefd698SDimitris Papastamos { 19104fefd698SDimitris Papastamos struct snd_card *card = soc_card->snd_card; 19114fefd698SDimitris Papastamos struct snd_kcontrol *kctl; 19124fefd698SDimitris Papastamos 19134fefd698SDimitris Papastamos if (unlikely(!name)) 19144fefd698SDimitris Papastamos return NULL; 19154fefd698SDimitris Papastamos 19164fefd698SDimitris Papastamos list_for_each_entry(kctl, &card->controls, list) 19174fefd698SDimitris Papastamos if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) 19184fefd698SDimitris Papastamos return kctl; 19194fefd698SDimitris Papastamos return NULL; 19204fefd698SDimitris Papastamos } 19214fefd698SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); 19224fefd698SDimitris Papastamos 1923db2a4165SFrank Mandarino /** 19240f2780adSLars-Peter Clausen * snd_soc_add_component_controls - Add an array of controls to a component. 19250f2780adSLars-Peter Clausen * 19260f2780adSLars-Peter Clausen * @component: Component to add controls to 19270f2780adSLars-Peter Clausen * @controls: Array of controls to add 19280f2780adSLars-Peter Clausen * @num_controls: Number of elements in the array 19290f2780adSLars-Peter Clausen * 19300f2780adSLars-Peter Clausen * Return: 0 for success, else error. 19310f2780adSLars-Peter Clausen */ 19320f2780adSLars-Peter Clausen int snd_soc_add_component_controls(struct snd_soc_component *component, 19330f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 19340f2780adSLars-Peter Clausen { 19350f2780adSLars-Peter Clausen struct snd_card *card = component->card->snd_card; 19360f2780adSLars-Peter Clausen 19370f2780adSLars-Peter Clausen return snd_soc_add_controls(card, component->dev, controls, 19380f2780adSLars-Peter Clausen num_controls, component->name_prefix, component); 19390f2780adSLars-Peter Clausen } 19400f2780adSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); 19410f2780adSLars-Peter Clausen 19420f2780adSLars-Peter Clausen /** 1943022658beSLiam Girdwood * snd_soc_add_codec_controls - add an array of controls to a codec. 1944022658beSLiam Girdwood * Convenience function to add a list of controls. Many codecs were 19453e8e1952SIan Molton * duplicating this code. 19463e8e1952SIan Molton * 19473e8e1952SIan Molton * @codec: codec to add controls to 19483e8e1952SIan Molton * @controls: array of controls to add 19493e8e1952SIan Molton * @num_controls: number of elements in the array 19503e8e1952SIan Molton * 19513e8e1952SIan Molton * Return 0 for success, else error. 19523e8e1952SIan Molton */ 1953022658beSLiam Girdwood int snd_soc_add_codec_controls(struct snd_soc_codec *codec, 19540f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 19553e8e1952SIan Molton { 19560f2780adSLars-Peter Clausen return snd_soc_add_component_controls(&codec->component, controls, 19570f2780adSLars-Peter Clausen num_controls); 19583e8e1952SIan Molton } 1959022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); 19603e8e1952SIan Molton 19613e8e1952SIan Molton /** 1962a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 1963022658beSLiam Girdwood * Convenience function to add a list of controls. 1964a491a5c8SLiam Girdwood * 1965a491a5c8SLiam Girdwood * @platform: platform to add controls to 1966a491a5c8SLiam Girdwood * @controls: array of controls to add 1967a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 1968a491a5c8SLiam Girdwood * 1969a491a5c8SLiam Girdwood * Return 0 for success, else error. 1970a491a5c8SLiam Girdwood */ 1971a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 19720f2780adSLars-Peter Clausen const struct snd_kcontrol_new *controls, unsigned int num_controls) 1973a491a5c8SLiam Girdwood { 19740f2780adSLars-Peter Clausen return snd_soc_add_component_controls(&platform->component, controls, 19750f2780adSLars-Peter Clausen num_controls); 1976a491a5c8SLiam Girdwood } 1977a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 1978a491a5c8SLiam Girdwood 1979a491a5c8SLiam Girdwood /** 1980022658beSLiam Girdwood * snd_soc_add_card_controls - add an array of controls to a SoC card. 1981022658beSLiam Girdwood * Convenience function to add a list of controls. 1982022658beSLiam Girdwood * 1983022658beSLiam Girdwood * @soc_card: SoC card to add controls to 1984022658beSLiam Girdwood * @controls: array of controls to add 1985022658beSLiam Girdwood * @num_controls: number of elements in the array 1986022658beSLiam Girdwood * 1987022658beSLiam Girdwood * Return 0 for success, else error. 1988022658beSLiam Girdwood */ 1989022658beSLiam Girdwood int snd_soc_add_card_controls(struct snd_soc_card *soc_card, 1990022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 1991022658beSLiam Girdwood { 1992022658beSLiam Girdwood struct snd_card *card = soc_card->snd_card; 1993022658beSLiam Girdwood 1994022658beSLiam Girdwood return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, 1995022658beSLiam Girdwood NULL, soc_card); 1996022658beSLiam Girdwood } 1997022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); 1998022658beSLiam Girdwood 1999022658beSLiam Girdwood /** 2000022658beSLiam Girdwood * snd_soc_add_dai_controls - add an array of controls to a DAI. 2001022658beSLiam Girdwood * Convienience function to add a list of controls. 2002022658beSLiam Girdwood * 2003022658beSLiam Girdwood * @dai: DAI to add controls to 2004022658beSLiam Girdwood * @controls: array of controls to add 2005022658beSLiam Girdwood * @num_controls: number of elements in the array 2006022658beSLiam Girdwood * 2007022658beSLiam Girdwood * Return 0 for success, else error. 2008022658beSLiam Girdwood */ 2009022658beSLiam Girdwood int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 2010022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2011022658beSLiam Girdwood { 2012313665b9SLars-Peter Clausen struct snd_card *card = dai->component->card->snd_card; 2013022658beSLiam Girdwood 2014022658beSLiam Girdwood return snd_soc_add_controls(card, dai->dev, controls, num_controls, 2015022658beSLiam Girdwood NULL, dai); 2016022658beSLiam Girdwood } 2017022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); 2018022658beSLiam Girdwood 2019022658beSLiam Girdwood /** 20208c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 20218c6529dbSLiam Girdwood * @dai: DAI 20228c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 20238c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 20248c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 20258c6529dbSLiam Girdwood * 20268c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 20278c6529dbSLiam Girdwood */ 20288c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 20298c6529dbSLiam Girdwood unsigned int freq, int dir) 20308c6529dbSLiam Girdwood { 2031f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 2032f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2033ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 2034da1c6ea6SMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, 2035ec4ee52aSMark Brown freq, dir); 20368c6529dbSLiam Girdwood else 20371104a9c8SMark Brown return -ENOTSUPP; 20388c6529dbSLiam Girdwood } 20398c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 20408c6529dbSLiam Girdwood 20418c6529dbSLiam Girdwood /** 2042ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 2043ec4ee52aSMark Brown * @codec: CODEC 2044ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 2045da1c6ea6SMark Brown * @source: Source for the clock 2046ec4ee52aSMark Brown * @freq: new clock frequency in Hz 2047ec4ee52aSMark Brown * @dir: new clock direction - input/output. 2048ec4ee52aSMark Brown * 2049ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 2050ec4ee52aSMark Brown */ 2051ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 2052da1c6ea6SMark Brown int source, unsigned int freq, int dir) 2053ec4ee52aSMark Brown { 2054ec4ee52aSMark Brown if (codec->driver->set_sysclk) 2055da1c6ea6SMark Brown return codec->driver->set_sysclk(codec, clk_id, source, 2056da1c6ea6SMark Brown freq, dir); 2057ec4ee52aSMark Brown else 20581104a9c8SMark Brown return -ENOTSUPP; 2059ec4ee52aSMark Brown } 2060ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 2061ec4ee52aSMark Brown 2062ec4ee52aSMark Brown /** 20638c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 20648c6529dbSLiam Girdwood * @dai: DAI 2065ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 20668c6529dbSLiam Girdwood * @div: new clock divisor. 20678c6529dbSLiam Girdwood * 20688c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 20698c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 20708c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 20718c6529dbSLiam Girdwood */ 20728c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 20738c6529dbSLiam Girdwood int div_id, int div) 20748c6529dbSLiam Girdwood { 2075f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 2076f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 20778c6529dbSLiam Girdwood else 20788c6529dbSLiam Girdwood return -EINVAL; 20798c6529dbSLiam Girdwood } 20808c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 20818c6529dbSLiam Girdwood 20828c6529dbSLiam Girdwood /** 20838c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 20848c6529dbSLiam Girdwood * @dai: DAI 20858c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 208685488037SMark Brown * @source: DAI specific source for the PLL 20878c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 20888c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 20898c6529dbSLiam Girdwood * 20908c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 20918c6529dbSLiam Girdwood */ 209285488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 209385488037SMark Brown unsigned int freq_in, unsigned int freq_out) 20948c6529dbSLiam Girdwood { 2095f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 2096f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 209785488037SMark Brown freq_in, freq_out); 2098ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 2099ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 2100ec4ee52aSMark Brown freq_in, freq_out); 21018c6529dbSLiam Girdwood else 21028c6529dbSLiam Girdwood return -EINVAL; 21038c6529dbSLiam Girdwood } 21048c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 21058c6529dbSLiam Girdwood 2106ec4ee52aSMark Brown /* 2107ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 2108ec4ee52aSMark Brown * @codec: CODEC 2109ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 2110ec4ee52aSMark Brown * @source: DAI specific source for the PLL 2111ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 2112ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 2113ec4ee52aSMark Brown * 2114ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 2115ec4ee52aSMark Brown */ 2116ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 2117ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 2118ec4ee52aSMark Brown { 2119ec4ee52aSMark Brown if (codec->driver->set_pll) 2120ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 2121ec4ee52aSMark Brown freq_in, freq_out); 2122ec4ee52aSMark Brown else 2123ec4ee52aSMark Brown return -EINVAL; 2124ec4ee52aSMark Brown } 2125ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 2126ec4ee52aSMark Brown 21278c6529dbSLiam Girdwood /** 2128e54cf76bSLiam Girdwood * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. 2129e54cf76bSLiam Girdwood * @dai: DAI 2130231b86b1SMasanari Iida * @ratio: Ratio of BCLK to Sample rate. 2131e54cf76bSLiam Girdwood * 2132e54cf76bSLiam Girdwood * Configures the DAI for a preset BCLK to sample rate ratio. 2133e54cf76bSLiam Girdwood */ 2134e54cf76bSLiam Girdwood int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) 2135e54cf76bSLiam Girdwood { 2136e54cf76bSLiam Girdwood if (dai->driver && dai->driver->ops->set_bclk_ratio) 2137e54cf76bSLiam Girdwood return dai->driver->ops->set_bclk_ratio(dai, ratio); 2138e54cf76bSLiam Girdwood else 2139e54cf76bSLiam Girdwood return -EINVAL; 2140e54cf76bSLiam Girdwood } 2141e54cf76bSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); 2142e54cf76bSLiam Girdwood 2143e54cf76bSLiam Girdwood /** 21448c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 21458c6529dbSLiam Girdwood * @dai: DAI 21468c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 21478c6529dbSLiam Girdwood * 21488c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 21498c6529dbSLiam Girdwood */ 21508c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 21518c6529dbSLiam Girdwood { 21525e4ba569SShawn Guo if (dai->driver == NULL) 21538c6529dbSLiam Girdwood return -EINVAL; 21545e4ba569SShawn Guo if (dai->driver->ops->set_fmt == NULL) 21555e4ba569SShawn Guo return -ENOTSUPP; 21565e4ba569SShawn Guo return dai->driver->ops->set_fmt(dai, fmt); 21578c6529dbSLiam Girdwood } 21588c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 21598c6529dbSLiam Girdwood 21608c6529dbSLiam Girdwood /** 2161e5c21514SXiubo Li * snd_soc_xlate_tdm_slot - generate tx/rx slot mask. 216289c67857SXiubo Li * @slots: Number of slots in use. 216389c67857SXiubo Li * @tx_mask: bitmask representing active TX slots. 216489c67857SXiubo Li * @rx_mask: bitmask representing active RX slots. 216589c67857SXiubo Li * 216689c67857SXiubo Li * Generates the TDM tx and rx slot default masks for DAI. 216789c67857SXiubo Li */ 2168e5c21514SXiubo Li static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, 216989c67857SXiubo Li unsigned int *tx_mask, 217089c67857SXiubo Li unsigned int *rx_mask) 217189c67857SXiubo Li { 217289c67857SXiubo Li if (*tx_mask || *rx_mask) 217389c67857SXiubo Li return 0; 217489c67857SXiubo Li 217589c67857SXiubo Li if (!slots) 217689c67857SXiubo Li return -EINVAL; 217789c67857SXiubo Li 217889c67857SXiubo Li *tx_mask = (1 << slots) - 1; 217989c67857SXiubo Li *rx_mask = (1 << slots) - 1; 218089c67857SXiubo Li 218189c67857SXiubo Li return 0; 218289c67857SXiubo Li } 218389c67857SXiubo Li 218489c67857SXiubo Li /** 2185e46c9366SLars-Peter Clausen * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation 2186e46c9366SLars-Peter Clausen * @dai: The DAI to configure 2187a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 2188a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 21898c6529dbSLiam Girdwood * @slots: Number of slots in use. 2190a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 21918c6529dbSLiam Girdwood * 2192e46c9366SLars-Peter Clausen * This function configures the specified DAI for TDM operation. @slot contains 2193e46c9366SLars-Peter Clausen * the total number of slots of the TDM stream and @slot_with the width of each 2194e46c9366SLars-Peter Clausen * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the 2195e46c9366SLars-Peter Clausen * active slots of the TDM stream for the specified DAI, i.e. which slots the 2196e46c9366SLars-Peter Clausen * DAI should write to or read from. If a bit is set the corresponding slot is 2197e46c9366SLars-Peter Clausen * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to 2198e46c9366SLars-Peter Clausen * the first slot, bit 1 to the second slot and so on. The first active slot 2199e46c9366SLars-Peter Clausen * maps to the first channel of the DAI, the second active slot to the second 2200e46c9366SLars-Peter Clausen * channel and so on. 2201e46c9366SLars-Peter Clausen * 2202e46c9366SLars-Peter Clausen * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask, 2203e46c9366SLars-Peter Clausen * @rx_mask and @slot_width will be ignored. 2204e46c9366SLars-Peter Clausen * 2205e46c9366SLars-Peter Clausen * Returns 0 on success, a negative error code otherwise. 22068c6529dbSLiam Girdwood */ 22078c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2208a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 22098c6529dbSLiam Girdwood { 2210e5c21514SXiubo Li if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) 2211e5c21514SXiubo Li dai->driver->ops->xlate_tdm_slot_mask(slots, 221289c67857SXiubo Li &tx_mask, &rx_mask); 221389c67857SXiubo Li else 2214e5c21514SXiubo Li snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); 221589c67857SXiubo Li 221688bd870fSBenoit Cousson dai->tx_mask = tx_mask; 221788bd870fSBenoit Cousson dai->rx_mask = rx_mask; 221888bd870fSBenoit Cousson 2219f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 2220f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2221a5479e38SDaniel Ribeiro slots, slot_width); 22228c6529dbSLiam Girdwood else 2223b2cbb6e1SXiubo Li return -ENOTSUPP; 22248c6529dbSLiam Girdwood } 22258c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 22268c6529dbSLiam Girdwood 22278c6529dbSLiam Girdwood /** 2228472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 2229472df3cbSBarry Song * @dai: DAI 2230472df3cbSBarry Song * @tx_num: how many TX channels 2231472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 2232472df3cbSBarry Song * 0~num-1 uses 2233472df3cbSBarry Song * @rx_num: how many RX channels 2234472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 2235472df3cbSBarry Song * 0~num-1 uses 2236472df3cbSBarry Song * 2237472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 2238472df3cbSBarry Song */ 2239472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 2240472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 2241472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 2242472df3cbSBarry Song { 2243f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 2244f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 2245472df3cbSBarry Song rx_num, rx_slot); 2246472df3cbSBarry Song else 2247472df3cbSBarry Song return -EINVAL; 2248472df3cbSBarry Song } 2249472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 2250472df3cbSBarry Song 2251472df3cbSBarry Song /** 22528c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 22538c6529dbSLiam Girdwood * @dai: DAI 22548c6529dbSLiam Girdwood * @tristate: tristate enable 22558c6529dbSLiam Girdwood * 22568c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 22578c6529dbSLiam Girdwood */ 22588c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 22598c6529dbSLiam Girdwood { 2260f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 2261f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 22628c6529dbSLiam Girdwood else 22638c6529dbSLiam Girdwood return -EINVAL; 22648c6529dbSLiam Girdwood } 22658c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 22668c6529dbSLiam Girdwood 22678c6529dbSLiam Girdwood /** 22688c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 22698c6529dbSLiam Girdwood * @dai: DAI 22708c6529dbSLiam Girdwood * @mute: mute enable 2271da18396fSMark Brown * @direction: stream to mute 22728c6529dbSLiam Girdwood * 22738c6529dbSLiam Girdwood * Mutes the DAI DAC. 22748c6529dbSLiam Girdwood */ 2275da18396fSMark Brown int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, 2276da18396fSMark Brown int direction) 22778c6529dbSLiam Girdwood { 2278da18396fSMark Brown if (!dai->driver) 2279da18396fSMark Brown return -ENOTSUPP; 2280da18396fSMark Brown 2281da18396fSMark Brown if (dai->driver->ops->mute_stream) 2282da18396fSMark Brown return dai->driver->ops->mute_stream(dai, mute, direction); 2283da18396fSMark Brown else if (direction == SNDRV_PCM_STREAM_PLAYBACK && 2284da18396fSMark Brown dai->driver->ops->digital_mute) 2285f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 22868c6529dbSLiam Girdwood else 228704570c62SMark Brown return -ENOTSUPP; 22888c6529dbSLiam Girdwood } 22898c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 22908c6529dbSLiam Girdwood 229188bd870fSBenoit Cousson static int snd_soc_init_multicodec(struct snd_soc_card *card, 229288bd870fSBenoit Cousson struct snd_soc_dai_link *dai_link) 229388bd870fSBenoit Cousson { 229488bd870fSBenoit Cousson /* Legacy codec/codec_dai link is a single entry in multicodec */ 229588bd870fSBenoit Cousson if (dai_link->codec_name || dai_link->codec_of_node || 229688bd870fSBenoit Cousson dai_link->codec_dai_name) { 229788bd870fSBenoit Cousson dai_link->num_codecs = 1; 229888bd870fSBenoit Cousson 229988bd870fSBenoit Cousson dai_link->codecs = devm_kzalloc(card->dev, 230088bd870fSBenoit Cousson sizeof(struct snd_soc_dai_link_component), 230188bd870fSBenoit Cousson GFP_KERNEL); 230288bd870fSBenoit Cousson if (!dai_link->codecs) 230388bd870fSBenoit Cousson return -ENOMEM; 230488bd870fSBenoit Cousson 230588bd870fSBenoit Cousson dai_link->codecs[0].name = dai_link->codec_name; 230688bd870fSBenoit Cousson dai_link->codecs[0].of_node = dai_link->codec_of_node; 230788bd870fSBenoit Cousson dai_link->codecs[0].dai_name = dai_link->codec_dai_name; 230888bd870fSBenoit Cousson } 230988bd870fSBenoit Cousson 231088bd870fSBenoit Cousson if (!dai_link->codecs) { 231188bd870fSBenoit Cousson dev_err(card->dev, "ASoC: DAI link has no CODECs\n"); 231288bd870fSBenoit Cousson return -EINVAL; 231388bd870fSBenoit Cousson } 231488bd870fSBenoit Cousson 231588bd870fSBenoit Cousson return 0; 231688bd870fSBenoit Cousson } 231788bd870fSBenoit Cousson 2318c5af3a2eSMark Brown /** 2319c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 2320c5af3a2eSMark Brown * 2321ac11a2b3SMark Brown * @card: Card to register 2322c5af3a2eSMark Brown * 2323c5af3a2eSMark Brown */ 232470a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 2325c5af3a2eSMark Brown { 232688bd870fSBenoit Cousson int i, j, ret; 2327f0fba2adSLiam Girdwood 2328c5af3a2eSMark Brown if (!card->name || !card->dev) 2329c5af3a2eSMark Brown return -EINVAL; 2330c5af3a2eSMark Brown 23315a504963SStephen Warren for (i = 0; i < card->num_links; i++) { 23325a504963SStephen Warren struct snd_soc_dai_link *link = &card->dai_link[i]; 23335a504963SStephen Warren 233488bd870fSBenoit Cousson ret = snd_soc_init_multicodec(card, link); 233588bd870fSBenoit Cousson if (ret) { 233688bd870fSBenoit Cousson dev_err(card->dev, "ASoC: failed to init multicodec\n"); 233788bd870fSBenoit Cousson return ret; 233888bd870fSBenoit Cousson } 233988bd870fSBenoit Cousson 234088bd870fSBenoit Cousson for (j = 0; j < link->num_codecs; j++) { 23415a504963SStephen Warren /* 23425a504963SStephen Warren * Codec must be specified by 1 of name or OF node, 23435a504963SStephen Warren * not both or neither. 23445a504963SStephen Warren */ 234588bd870fSBenoit Cousson if (!!link->codecs[j].name == 234688bd870fSBenoit Cousson !!link->codecs[j].of_node) { 234788bd870fSBenoit Cousson dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", 234810e8aa9aSMichał Mirosław link->name); 23495a504963SStephen Warren return -EINVAL; 23505a504963SStephen Warren } 2351bc92657aSStephen Warren /* Codec DAI name must be specified */ 235288bd870fSBenoit Cousson if (!link->codecs[j].dai_name) { 235388bd870fSBenoit Cousson dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", 235410e8aa9aSMichał Mirosław link->name); 2355bc92657aSStephen Warren return -EINVAL; 2356bc92657aSStephen Warren } 235788bd870fSBenoit Cousson } 23585a504963SStephen Warren 23595a504963SStephen Warren /* 23605a504963SStephen Warren * Platform may be specified by either name or OF node, but 23615a504963SStephen Warren * can be left unspecified, and a dummy platform will be used. 23625a504963SStephen Warren */ 23635a504963SStephen Warren if (link->platform_name && link->platform_of_node) { 236410e8aa9aSMichał Mirosław dev_err(card->dev, 236510e8aa9aSMichał Mirosław "ASoC: Both platform name/of_node are set for %s\n", 236610e8aa9aSMichał Mirosław link->name); 23675a504963SStephen Warren return -EINVAL; 23685a504963SStephen Warren } 23695a504963SStephen Warren 23705a504963SStephen Warren /* 2371bc92657aSStephen Warren * CPU device may be specified by either name or OF node, but 2372bc92657aSStephen Warren * can be left unspecified, and will be matched based on DAI 2373bc92657aSStephen Warren * name alone.. 23745a504963SStephen Warren */ 2375bc92657aSStephen Warren if (link->cpu_name && link->cpu_of_node) { 237610e8aa9aSMichał Mirosław dev_err(card->dev, 237710e8aa9aSMichał Mirosław "ASoC: Neither/both cpu name/of_node are set for %s\n", 237810e8aa9aSMichał Mirosław link->name); 2379bc92657aSStephen Warren return -EINVAL; 2380bc92657aSStephen Warren } 2381bc92657aSStephen Warren /* 2382bc92657aSStephen Warren * At least one of CPU DAI name or CPU device name/node must be 2383bc92657aSStephen Warren * specified 2384bc92657aSStephen Warren */ 2385bc92657aSStephen Warren if (!link->cpu_dai_name && 2386bc92657aSStephen Warren !(link->cpu_name || link->cpu_of_node)) { 238710e8aa9aSMichał Mirosław dev_err(card->dev, 238810e8aa9aSMichał Mirosław "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", 238910e8aa9aSMichał Mirosław link->name); 23905a504963SStephen Warren return -EINVAL; 23915a504963SStephen Warren } 23925a504963SStephen Warren } 23935a504963SStephen Warren 2394ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 2395ed77cc12SMark Brown 2396111c6419SStephen Warren snd_soc_initialize_card_lists(card); 2397111c6419SStephen Warren 2398181a6892SMark Brown card->rtd = devm_kzalloc(card->dev, 2399181a6892SMark Brown sizeof(struct snd_soc_pcm_runtime) * 24002eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 2401f0fba2adSLiam Girdwood GFP_KERNEL); 2402f0fba2adSLiam Girdwood if (card->rtd == NULL) 2403f0fba2adSLiam Girdwood return -ENOMEM; 2404a7dbb603SLiam Girdwood card->num_rtd = 0; 24052eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 2406f0fba2adSLiam Girdwood 24075f3484acSLars-Peter Clausen for (i = 0; i < card->num_links; i++) { 24085f3484acSLars-Peter Clausen card->rtd[i].card = card; 2409f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 241088bd870fSBenoit Cousson card->rtd[i].codec_dais = devm_kzalloc(card->dev, 241188bd870fSBenoit Cousson sizeof(struct snd_soc_dai *) * 241288bd870fSBenoit Cousson (card->rtd[i].dai_link->num_codecs), 241388bd870fSBenoit Cousson GFP_KERNEL); 241488bd870fSBenoit Cousson if (card->rtd[i].codec_dais == NULL) 241588bd870fSBenoit Cousson return -ENOMEM; 24165f3484acSLars-Peter Clausen } 24175f3484acSLars-Peter Clausen 24185f3484acSLars-Peter Clausen for (i = 0; i < card->num_aux_devs; i++) 24195f3484acSLars-Peter Clausen card->rtd_aux[i].card = card; 2420f0fba2adSLiam Girdwood 2421db432b41SMark Brown INIT_LIST_HEAD(&card->dapm_dirty); 24228a978234SLiam Girdwood INIT_LIST_HEAD(&card->dobj_list); 2423c5af3a2eSMark Brown card->instantiated = 0; 2424f0fba2adSLiam Girdwood mutex_init(&card->mutex); 2425a73fb2dfSLiam Girdwood mutex_init(&card->dapm_mutex); 2426c5af3a2eSMark Brown 2427b19e6e7bSMark Brown ret = snd_soc_instantiate_card(card); 2428b19e6e7bSMark Brown if (ret != 0) 24294e2576bdSKuninori Morimoto return ret; 2430c5af3a2eSMark Brown 2431988e8cc4SNicolin Chen /* deactivate pins to sleep state */ 2432988e8cc4SNicolin Chen for (i = 0; i < card->num_rtd; i++) { 243388bd870fSBenoit Cousson struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 243488bd870fSBenoit Cousson struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 243588bd870fSBenoit Cousson int j; 243688bd870fSBenoit Cousson 243788bd870fSBenoit Cousson for (j = 0; j < rtd->num_codecs; j++) { 243888bd870fSBenoit Cousson struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 2439988e8cc4SNicolin Chen if (!codec_dai->active) 2440988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(codec_dai->dev); 244188bd870fSBenoit Cousson } 244288bd870fSBenoit Cousson 2443988e8cc4SNicolin Chen if (!cpu_dai->active) 2444988e8cc4SNicolin Chen pinctrl_pm_select_sleep_state(cpu_dai->dev); 2445988e8cc4SNicolin Chen } 2446988e8cc4SNicolin Chen 2447b19e6e7bSMark Brown return ret; 2448c5af3a2eSMark Brown } 244970a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 2450c5af3a2eSMark Brown 2451c5af3a2eSMark Brown /** 2452c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 2453c5af3a2eSMark Brown * 2454ac11a2b3SMark Brown * @card: Card to unregister 2455c5af3a2eSMark Brown * 2456c5af3a2eSMark Brown */ 245770a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 2458c5af3a2eSMark Brown { 245901e0df66SLars-Peter Clausen if (card->instantiated) { 246001e0df66SLars-Peter Clausen card->instantiated = false; 24611c325f77SLars-Peter Clausen snd_soc_dapm_shutdown(card); 2462b0e26485SVinod Koul soc_cleanup_card_resources(card); 2463f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); 24648f6f9b29SKuninori Morimoto } 2465c5af3a2eSMark Brown 2466c5af3a2eSMark Brown return 0; 2467c5af3a2eSMark Brown } 246870a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 2469c5af3a2eSMark Brown 2470f0fba2adSLiam Girdwood /* 2471f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 2472f0fba2adSLiam Girdwood * and sanitizing names. 2473f0fba2adSLiam Girdwood */ 24740b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 2475f0fba2adSLiam Girdwood { 2476f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 2477f0fba2adSLiam Girdwood int id1, id2; 2478f0fba2adSLiam Girdwood 2479f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 2480f0fba2adSLiam Girdwood return NULL; 2481f0fba2adSLiam Girdwood 248258818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 2483f0fba2adSLiam Girdwood 2484f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 2485f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 2486f0fba2adSLiam Girdwood if (found) { 2487f0fba2adSLiam Girdwood /* get ID */ 2488f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 2489f0fba2adSLiam Girdwood 2490f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 2491f0fba2adSLiam Girdwood if (*id == -1) 2492f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 2493f0fba2adSLiam Girdwood } 2494f0fba2adSLiam Girdwood 2495f0fba2adSLiam Girdwood } else { 2496f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 2497f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 2498f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 2499f0fba2adSLiam Girdwood 2500f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 250105899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 2502f0fba2adSLiam Girdwood 2503f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 2504f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 250558818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 2506f0fba2adSLiam Girdwood } else 2507f0fba2adSLiam Girdwood *id = 0; 2508f0fba2adSLiam Girdwood } 2509f0fba2adSLiam Girdwood 2510f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 2511f0fba2adSLiam Girdwood } 2512f0fba2adSLiam Girdwood 2513f0fba2adSLiam Girdwood /* 2514f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 2515f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 2516f0fba2adSLiam Girdwood */ 2517f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 2518f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 2519f0fba2adSLiam Girdwood { 2520f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 252110e8aa9aSMichał Mirosław dev_err(dev, 252210e8aa9aSMichał Mirosław "ASoC: error - multiple DAI %s registered with no name\n", 252310e8aa9aSMichał Mirosław dev_name(dev)); 2524f0fba2adSLiam Girdwood return NULL; 2525f0fba2adSLiam Girdwood } 2526f0fba2adSLiam Girdwood 2527f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 2528f0fba2adSLiam Girdwood } 2529f0fba2adSLiam Girdwood 25309115171aSMark Brown /** 253132c9ba54SLars-Peter Clausen * snd_soc_unregister_dai - Unregister DAIs from the ASoC core 25329115171aSMark Brown * 253332c9ba54SLars-Peter Clausen * @component: The component for which the DAIs should be unregistered 25349115171aSMark Brown */ 253532c9ba54SLars-Peter Clausen static void snd_soc_unregister_dais(struct snd_soc_component *component) 25369115171aSMark Brown { 25375c1d5f09SLars-Peter Clausen struct snd_soc_dai *dai, *_dai; 25389115171aSMark Brown 25395c1d5f09SLars-Peter Clausen list_for_each_entry_safe(dai, _dai, &component->dai_list, list) { 254032c9ba54SLars-Peter Clausen dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n", 254132c9ba54SLars-Peter Clausen dai->name); 25429115171aSMark Brown list_del(&dai->list); 2543f0fba2adSLiam Girdwood kfree(dai->name); 2544f0fba2adSLiam Girdwood kfree(dai); 25459115171aSMark Brown } 254632c9ba54SLars-Peter Clausen } 25479115171aSMark Brown 25489115171aSMark Brown /** 254932c9ba54SLars-Peter Clausen * snd_soc_register_dais - Register a DAI with the ASoC core 25509115171aSMark Brown * 25516106d129SLars-Peter Clausen * @component: The component the DAIs are registered for 25526106d129SLars-Peter Clausen * @dai_drv: DAI driver to use for the DAIs 2553ac11a2b3SMark Brown * @count: Number of DAIs 255432c9ba54SLars-Peter Clausen * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the 255532c9ba54SLars-Peter Clausen * parent's name. 25569115171aSMark Brown */ 255732c9ba54SLars-Peter Clausen static int snd_soc_register_dais(struct snd_soc_component *component, 2558bb13109dSLars-Peter Clausen struct snd_soc_dai_driver *dai_drv, size_t count, 2559bb13109dSLars-Peter Clausen bool legacy_dai_naming) 25609115171aSMark Brown { 25616106d129SLars-Peter Clausen struct device *dev = component->dev; 2562f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 256332c9ba54SLars-Peter Clausen unsigned int i; 256432c9ba54SLars-Peter Clausen int ret; 2565f0fba2adSLiam Girdwood 2566f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); 25679115171aSMark Brown 2568bb13109dSLars-Peter Clausen component->dai_drv = dai_drv; 2569bb13109dSLars-Peter Clausen component->num_dai = count; 2570bb13109dSLars-Peter Clausen 25719115171aSMark Brown for (i = 0; i < count; i++) { 2572f0fba2adSLiam Girdwood 2573f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 2574c46e0079SAxel Lin if (dai == NULL) { 2575c46e0079SAxel Lin ret = -ENOMEM; 2576c46e0079SAxel Lin goto err; 2577c46e0079SAxel Lin } 2578f0fba2adSLiam Girdwood 257932c9ba54SLars-Peter Clausen /* 258032c9ba54SLars-Peter Clausen * Back in the old days when we still had component-less DAIs, 258132c9ba54SLars-Peter Clausen * instead of having a static name, component-less DAIs would 258232c9ba54SLars-Peter Clausen * inherit the name of the parent device so it is possible to 258332c9ba54SLars-Peter Clausen * register multiple instances of the DAI. We still need to keep 258432c9ba54SLars-Peter Clausen * the same naming style even though those DAIs are not 258532c9ba54SLars-Peter Clausen * component-less anymore. 258632c9ba54SLars-Peter Clausen */ 25879e498089SSrinivas Kandagatla if (count == 1 && legacy_dai_naming && 25889e498089SSrinivas Kandagatla (dai_drv[i].id == 0 || dai_drv[i].name == NULL)) { 2589db2a4165SFrank Mandarino dai->name = fmt_single_name(dev, &dai->id); 259032c9ba54SLars-Peter Clausen } else { 2591f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 259232c9ba54SLars-Peter Clausen if (dai_drv[i].id) 259332c9ba54SLars-Peter Clausen dai->id = dai_drv[i].id; 259432c9ba54SLars-Peter Clausen else 259532c9ba54SLars-Peter Clausen dai->id = i; 259632c9ba54SLars-Peter Clausen } 2597f0fba2adSLiam Girdwood if (dai->name == NULL) { 2598f0fba2adSLiam Girdwood kfree(dai); 259932c9ba54SLars-Peter Clausen ret = -ENOMEM; 26009115171aSMark Brown goto err; 26019115171aSMark Brown } 26029115171aSMark Brown 26036106d129SLars-Peter Clausen dai->component = component; 2604f0fba2adSLiam Girdwood dai->dev = dev; 2605f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 2606f0fba2adSLiam Girdwood if (!dai->driver->ops) 2607f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 2608f0fba2adSLiam Girdwood 26091438c2f6SLars-Peter Clausen list_add(&dai->list, &component->dai_list); 2610054880feSMark Brown 26119115171aSMark Brown dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); 2612f0fba2adSLiam Girdwood } 2613f0fba2adSLiam Girdwood 26149115171aSMark Brown return 0; 26159115171aSMark Brown 26169115171aSMark Brown err: 261732c9ba54SLars-Peter Clausen snd_soc_unregister_dais(component); 26189115171aSMark Brown 26199115171aSMark Brown return ret; 26209115171aSMark Brown } 26219115171aSMark Brown 262214e8bdebSLars-Peter Clausen static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm, 262314e8bdebSLars-Peter Clausen enum snd_soc_dapm_type type, int subseq) 2624d191bd8dSKuninori Morimoto { 262514e8bdebSLars-Peter Clausen struct snd_soc_component *component = dapm->component; 2626d191bd8dSKuninori Morimoto 262714e8bdebSLars-Peter Clausen component->driver->seq_notifier(component, type, subseq); 262814e8bdebSLars-Peter Clausen } 2629d191bd8dSKuninori Morimoto 263014e8bdebSLars-Peter Clausen static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, 263114e8bdebSLars-Peter Clausen int event) 263214e8bdebSLars-Peter Clausen { 263314e8bdebSLars-Peter Clausen struct snd_soc_component *component = dapm->component; 263414e8bdebSLars-Peter Clausen 263514e8bdebSLars-Peter Clausen return component->driver->stream_event(component, event); 263614e8bdebSLars-Peter Clausen } 263714e8bdebSLars-Peter Clausen 2638bb13109dSLars-Peter Clausen static int snd_soc_component_initialize(struct snd_soc_component *component, 2639bb13109dSLars-Peter Clausen const struct snd_soc_component_driver *driver, struct device *dev) 2640d191bd8dSKuninori Morimoto { 2641ce0fc93aSLars-Peter Clausen struct snd_soc_dapm_context *dapm; 2642ce0fc93aSLars-Peter Clausen 2643bb13109dSLars-Peter Clausen component->name = fmt_single_name(dev, &component->id); 2644bb13109dSLars-Peter Clausen if (!component->name) { 2645bb13109dSLars-Peter Clausen dev_err(dev, "ASoC: Failed to allocate name\n"); 2646d191bd8dSKuninori Morimoto return -ENOMEM; 2647d191bd8dSKuninori Morimoto } 2648d191bd8dSKuninori Morimoto 2649bb13109dSLars-Peter Clausen component->dev = dev; 2650bb13109dSLars-Peter Clausen component->driver = driver; 265161aca564SLars-Peter Clausen component->probe = component->driver->probe; 265261aca564SLars-Peter Clausen component->remove = component->driver->remove; 2653e2c330b9SLars-Peter Clausen 2654ce0fc93aSLars-Peter Clausen if (!component->dapm_ptr) 2655ce0fc93aSLars-Peter Clausen component->dapm_ptr = &component->dapm; 2656ce0fc93aSLars-Peter Clausen 2657ce0fc93aSLars-Peter Clausen dapm = component->dapm_ptr; 2658ce0fc93aSLars-Peter Clausen dapm->dev = dev; 2659ce0fc93aSLars-Peter Clausen dapm->component = component; 2660ce0fc93aSLars-Peter Clausen dapm->bias_level = SND_SOC_BIAS_OFF; 26615819c2faSLars-Peter Clausen dapm->idle_bias_off = true; 266214e8bdebSLars-Peter Clausen if (driver->seq_notifier) 266314e8bdebSLars-Peter Clausen dapm->seq_notifier = snd_soc_component_seq_notifier; 266414e8bdebSLars-Peter Clausen if (driver->stream_event) 266514e8bdebSLars-Peter Clausen dapm->stream_event = snd_soc_component_stream_event; 2666ce0fc93aSLars-Peter Clausen 266761aca564SLars-Peter Clausen component->controls = driver->controls; 266861aca564SLars-Peter Clausen component->num_controls = driver->num_controls; 266961aca564SLars-Peter Clausen component->dapm_widgets = driver->dapm_widgets; 267061aca564SLars-Peter Clausen component->num_dapm_widgets = driver->num_dapm_widgets; 267161aca564SLars-Peter Clausen component->dapm_routes = driver->dapm_routes; 267261aca564SLars-Peter Clausen component->num_dapm_routes = driver->num_dapm_routes; 267361aca564SLars-Peter Clausen 2674bb13109dSLars-Peter Clausen INIT_LIST_HEAD(&component->dai_list); 2675bb13109dSLars-Peter Clausen mutex_init(&component->io_mutex); 2676bb13109dSLars-Peter Clausen 2677bb13109dSLars-Peter Clausen return 0; 2678d191bd8dSKuninori Morimoto } 2679d191bd8dSKuninori Morimoto 268020feb881SLars-Peter Clausen static void snd_soc_component_setup_regmap(struct snd_soc_component *component) 2681886f5692SLars-Peter Clausen { 2682886f5692SLars-Peter Clausen int val_bytes = regmap_get_val_bytes(component->regmap); 268320feb881SLars-Peter Clausen 2684886f5692SLars-Peter Clausen /* Errors are legitimate for non-integer byte multiples */ 2685886f5692SLars-Peter Clausen if (val_bytes > 0) 2686886f5692SLars-Peter Clausen component->val_bytes = val_bytes; 2687886f5692SLars-Peter Clausen } 268820feb881SLars-Peter Clausen 2689e874bf5fSLars-Peter Clausen #ifdef CONFIG_REGMAP 2690e874bf5fSLars-Peter Clausen 269120feb881SLars-Peter Clausen /** 269220feb881SLars-Peter Clausen * snd_soc_component_init_regmap() - Initialize regmap instance for the component 269320feb881SLars-Peter Clausen * @component: The component for which to initialize the regmap instance 269420feb881SLars-Peter Clausen * @regmap: The regmap instance that should be used by the component 269520feb881SLars-Peter Clausen * 269620feb881SLars-Peter Clausen * This function allows deferred assignment of the regmap instance that is 269720feb881SLars-Peter Clausen * associated with the component. Only use this if the regmap instance is not 269820feb881SLars-Peter Clausen * yet ready when the component is registered. The function must also be called 269920feb881SLars-Peter Clausen * before the first IO attempt of the component. 270020feb881SLars-Peter Clausen */ 270120feb881SLars-Peter Clausen void snd_soc_component_init_regmap(struct snd_soc_component *component, 270220feb881SLars-Peter Clausen struct regmap *regmap) 270320feb881SLars-Peter Clausen { 270420feb881SLars-Peter Clausen component->regmap = regmap; 270520feb881SLars-Peter Clausen snd_soc_component_setup_regmap(component); 2706886f5692SLars-Peter Clausen } 270720feb881SLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); 270820feb881SLars-Peter Clausen 270920feb881SLars-Peter Clausen /** 271020feb881SLars-Peter Clausen * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component 271120feb881SLars-Peter Clausen * @component: The component for which to de-initialize the regmap instance 271220feb881SLars-Peter Clausen * 271320feb881SLars-Peter Clausen * Calls regmap_exit() on the regmap instance associated to the component and 271420feb881SLars-Peter Clausen * removes the regmap instance from the component. 271520feb881SLars-Peter Clausen * 271620feb881SLars-Peter Clausen * This function should only be used if snd_soc_component_init_regmap() was used 271720feb881SLars-Peter Clausen * to initialize the regmap instance. 271820feb881SLars-Peter Clausen */ 271920feb881SLars-Peter Clausen void snd_soc_component_exit_regmap(struct snd_soc_component *component) 272020feb881SLars-Peter Clausen { 272120feb881SLars-Peter Clausen regmap_exit(component->regmap); 272220feb881SLars-Peter Clausen component->regmap = NULL; 272320feb881SLars-Peter Clausen } 272420feb881SLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); 2725886f5692SLars-Peter Clausen 2726e874bf5fSLars-Peter Clausen #endif 2727d191bd8dSKuninori Morimoto 2728bb13109dSLars-Peter Clausen static void snd_soc_component_add_unlocked(struct snd_soc_component *component) 2729bb13109dSLars-Peter Clausen { 273020feb881SLars-Peter Clausen if (!component->write && !component->read) { 273120feb881SLars-Peter Clausen if (!component->regmap) 273220feb881SLars-Peter Clausen component->regmap = dev_get_regmap(component->dev, NULL); 273320feb881SLars-Peter Clausen if (component->regmap) 273420feb881SLars-Peter Clausen snd_soc_component_setup_regmap(component); 273520feb881SLars-Peter Clausen } 2736886f5692SLars-Peter Clausen 2737bb13109dSLars-Peter Clausen list_add(&component->list, &component_list); 27388a978234SLiam Girdwood INIT_LIST_HEAD(&component->dobj_list); 2739d191bd8dSKuninori Morimoto } 2740d191bd8dSKuninori Morimoto 2741bb13109dSLars-Peter Clausen static void snd_soc_component_add(struct snd_soc_component *component) 2742bb13109dSLars-Peter Clausen { 2743d191bd8dSKuninori Morimoto mutex_lock(&client_mutex); 2744bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(component); 2745d191bd8dSKuninori Morimoto mutex_unlock(&client_mutex); 2746bb13109dSLars-Peter Clausen } 2747d191bd8dSKuninori Morimoto 2748bb13109dSLars-Peter Clausen static void snd_soc_component_cleanup(struct snd_soc_component *component) 2749bb13109dSLars-Peter Clausen { 2750bb13109dSLars-Peter Clausen snd_soc_unregister_dais(component); 2751bb13109dSLars-Peter Clausen kfree(component->name); 2752bb13109dSLars-Peter Clausen } 2753d191bd8dSKuninori Morimoto 2754bb13109dSLars-Peter Clausen static void snd_soc_component_del_unlocked(struct snd_soc_component *component) 2755bb13109dSLars-Peter Clausen { 2756bb13109dSLars-Peter Clausen list_del(&component->list); 2757bb13109dSLars-Peter Clausen } 2758d191bd8dSKuninori Morimoto 2759d191bd8dSKuninori Morimoto int snd_soc_register_component(struct device *dev, 2760d191bd8dSKuninori Morimoto const struct snd_soc_component_driver *cmpnt_drv, 2761d191bd8dSKuninori Morimoto struct snd_soc_dai_driver *dai_drv, 2762d191bd8dSKuninori Morimoto int num_dai) 2763d191bd8dSKuninori Morimoto { 2764d191bd8dSKuninori Morimoto struct snd_soc_component *cmpnt; 2765bb13109dSLars-Peter Clausen int ret; 2766d191bd8dSKuninori Morimoto 2767bb13109dSLars-Peter Clausen cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL); 2768d191bd8dSKuninori Morimoto if (!cmpnt) { 2769d191bd8dSKuninori Morimoto dev_err(dev, "ASoC: Failed to allocate memory\n"); 2770d191bd8dSKuninori Morimoto return -ENOMEM; 2771d191bd8dSKuninori Morimoto } 2772d191bd8dSKuninori Morimoto 2773bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev); 2774bb13109dSLars-Peter Clausen if (ret) 2775bb13109dSLars-Peter Clausen goto err_free; 2776bb13109dSLars-Peter Clausen 27773d59400fSLars-Peter Clausen cmpnt->ignore_pmdown_time = true; 277898e639fbSLars-Peter Clausen cmpnt->registered_as_component = true; 27793d59400fSLars-Peter Clausen 2780bb13109dSLars-Peter Clausen ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); 2781bb13109dSLars-Peter Clausen if (ret < 0) { 2782f42cf8d6SMasanari Iida dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); 2783bb13109dSLars-Peter Clausen goto err_cleanup; 2784bb13109dSLars-Peter Clausen } 2785bb13109dSLars-Peter Clausen 2786bb13109dSLars-Peter Clausen snd_soc_component_add(cmpnt); 2787bb13109dSLars-Peter Clausen 2788bb13109dSLars-Peter Clausen return 0; 2789bb13109dSLars-Peter Clausen 2790bb13109dSLars-Peter Clausen err_cleanup: 2791bb13109dSLars-Peter Clausen snd_soc_component_cleanup(cmpnt); 2792bb13109dSLars-Peter Clausen err_free: 2793bb13109dSLars-Peter Clausen kfree(cmpnt); 2794bb13109dSLars-Peter Clausen return ret; 2795d191bd8dSKuninori Morimoto } 2796d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_register_component); 2797d191bd8dSKuninori Morimoto 2798d191bd8dSKuninori Morimoto /** 2799d191bd8dSKuninori Morimoto * snd_soc_unregister_component - Unregister a component from the ASoC core 2800d191bd8dSKuninori Morimoto * 2801*628536eaSJonathan Corbet * @dev: The device to unregister 2802d191bd8dSKuninori Morimoto */ 2803d191bd8dSKuninori Morimoto void snd_soc_unregister_component(struct device *dev) 2804d191bd8dSKuninori Morimoto { 2805d191bd8dSKuninori Morimoto struct snd_soc_component *cmpnt; 2806d191bd8dSKuninori Morimoto 280734e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 2808d191bd8dSKuninori Morimoto list_for_each_entry(cmpnt, &component_list, list) { 280998e639fbSLars-Peter Clausen if (dev == cmpnt->dev && cmpnt->registered_as_component) 2810d191bd8dSKuninori Morimoto goto found; 2811d191bd8dSKuninori Morimoto } 281234e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 2813d191bd8dSKuninori Morimoto return; 2814d191bd8dSKuninori Morimoto 2815d191bd8dSKuninori Morimoto found: 28168a978234SLiam Girdwood snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL); 281734e81ab4SLars-Peter Clausen snd_soc_component_del_unlocked(cmpnt); 281834e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 2819bb13109dSLars-Peter Clausen snd_soc_component_cleanup(cmpnt); 2820bb13109dSLars-Peter Clausen kfree(cmpnt); 2821d191bd8dSKuninori Morimoto } 2822d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_unregister_component); 2823d191bd8dSKuninori Morimoto 2824f1d45cc3SLars-Peter Clausen static int snd_soc_platform_drv_probe(struct snd_soc_component *component) 2825e2c330b9SLars-Peter Clausen { 2826e2c330b9SLars-Peter Clausen struct snd_soc_platform *platform = snd_soc_component_to_platform(component); 2827e2c330b9SLars-Peter Clausen 2828f1d45cc3SLars-Peter Clausen return platform->driver->probe(platform); 2829e2c330b9SLars-Peter Clausen } 2830e2c330b9SLars-Peter Clausen 2831f1d45cc3SLars-Peter Clausen static void snd_soc_platform_drv_remove(struct snd_soc_component *component) 2832e2c330b9SLars-Peter Clausen { 2833e2c330b9SLars-Peter Clausen struct snd_soc_platform *platform = snd_soc_component_to_platform(component); 2834e2c330b9SLars-Peter Clausen 2835f1d45cc3SLars-Peter Clausen platform->driver->remove(platform); 2836e2c330b9SLars-Peter Clausen } 2837e2c330b9SLars-Peter Clausen 2838d191bd8dSKuninori Morimoto /** 283971a45cdaSLars-Peter Clausen * snd_soc_add_platform - Add a platform to the ASoC core 284071a45cdaSLars-Peter Clausen * @dev: The parent device for the platform 284171a45cdaSLars-Peter Clausen * @platform: The platform to add 28427d1442b4SMasanari Iida * @platform_drv: The driver for the platform 284312a48a8cSMark Brown */ 284471a45cdaSLars-Peter Clausen int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, 2845d79e57dbSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 284612a48a8cSMark Brown { 2847b37f1d12SLars-Peter Clausen int ret; 2848b37f1d12SLars-Peter Clausen 2849bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(&platform->component, 2850bb13109dSLars-Peter Clausen &platform_drv->component_driver, dev); 2851bb13109dSLars-Peter Clausen if (ret) 2852bb13109dSLars-Peter Clausen return ret; 2853f0fba2adSLiam Girdwood 2854f0fba2adSLiam Girdwood platform->dev = dev; 2855f0fba2adSLiam Girdwood platform->driver = platform_drv; 2856f1d45cc3SLars-Peter Clausen 2857f1d45cc3SLars-Peter Clausen if (platform_drv->probe) 2858f1d45cc3SLars-Peter Clausen platform->component.probe = snd_soc_platform_drv_probe; 2859f1d45cc3SLars-Peter Clausen if (platform_drv->remove) 2860f1d45cc3SLars-Peter Clausen platform->component.remove = snd_soc_platform_drv_remove; 286112a48a8cSMark Brown 286281c7cfd1SLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 286381c7cfd1SLars-Peter Clausen platform->component.debugfs_prefix = "platform"; 286481c7cfd1SLars-Peter Clausen #endif 286512a48a8cSMark Brown 286612a48a8cSMark Brown mutex_lock(&client_mutex); 2867bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(&platform->component); 286812a48a8cSMark Brown list_add(&platform->list, &platform_list); 286912a48a8cSMark Brown mutex_unlock(&client_mutex); 287012a48a8cSMark Brown 2871f4333203SLars-Peter Clausen dev_dbg(dev, "ASoC: Registered platform '%s'\n", 2872f4333203SLars-Peter Clausen platform->component.name); 287312a48a8cSMark Brown 287412a48a8cSMark Brown return 0; 287512a48a8cSMark Brown } 287671a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_platform); 287771a45cdaSLars-Peter Clausen 287871a45cdaSLars-Peter Clausen /** 287971a45cdaSLars-Peter Clausen * snd_soc_register_platform - Register a platform with the ASoC core 288071a45cdaSLars-Peter Clausen * 2881*628536eaSJonathan Corbet * @dev: The device for the platform 2882*628536eaSJonathan Corbet * @platform_drv: The driver for the platform 288371a45cdaSLars-Peter Clausen */ 288471a45cdaSLars-Peter Clausen int snd_soc_register_platform(struct device *dev, 288571a45cdaSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 288671a45cdaSLars-Peter Clausen { 288771a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 288871a45cdaSLars-Peter Clausen int ret; 288971a45cdaSLars-Peter Clausen 289071a45cdaSLars-Peter Clausen dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); 289171a45cdaSLars-Peter Clausen 289271a45cdaSLars-Peter Clausen platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 289371a45cdaSLars-Peter Clausen if (platform == NULL) 289471a45cdaSLars-Peter Clausen return -ENOMEM; 289571a45cdaSLars-Peter Clausen 289671a45cdaSLars-Peter Clausen ret = snd_soc_add_platform(dev, platform, platform_drv); 289771a45cdaSLars-Peter Clausen if (ret) 289871a45cdaSLars-Peter Clausen kfree(platform); 289971a45cdaSLars-Peter Clausen 290071a45cdaSLars-Peter Clausen return ret; 290171a45cdaSLars-Peter Clausen } 290212a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 290312a48a8cSMark Brown 290412a48a8cSMark Brown /** 290571a45cdaSLars-Peter Clausen * snd_soc_remove_platform - Remove a platform from the ASoC core 290671a45cdaSLars-Peter Clausen * @platform: the platform to remove 290771a45cdaSLars-Peter Clausen */ 290871a45cdaSLars-Peter Clausen void snd_soc_remove_platform(struct snd_soc_platform *platform) 290971a45cdaSLars-Peter Clausen { 2910b37f1d12SLars-Peter Clausen 291171a45cdaSLars-Peter Clausen mutex_lock(&client_mutex); 291271a45cdaSLars-Peter Clausen list_del(&platform->list); 2913bb13109dSLars-Peter Clausen snd_soc_component_del_unlocked(&platform->component); 291471a45cdaSLars-Peter Clausen mutex_unlock(&client_mutex); 291571a45cdaSLars-Peter Clausen 291671a45cdaSLars-Peter Clausen dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", 2917f4333203SLars-Peter Clausen platform->component.name); 2918decc27b0SDaniel Mack 2919decc27b0SDaniel Mack snd_soc_component_cleanup(&platform->component); 292071a45cdaSLars-Peter Clausen } 292171a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_remove_platform); 292271a45cdaSLars-Peter Clausen 292371a45cdaSLars-Peter Clausen struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) 292471a45cdaSLars-Peter Clausen { 292571a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 292671a45cdaSLars-Peter Clausen 292734e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 292871a45cdaSLars-Peter Clausen list_for_each_entry(platform, &platform_list, list) { 292934e81ab4SLars-Peter Clausen if (dev == platform->dev) { 293034e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 293171a45cdaSLars-Peter Clausen return platform; 293271a45cdaSLars-Peter Clausen } 293334e81ab4SLars-Peter Clausen } 293434e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 293571a45cdaSLars-Peter Clausen 293671a45cdaSLars-Peter Clausen return NULL; 293771a45cdaSLars-Peter Clausen } 293871a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); 293971a45cdaSLars-Peter Clausen 294071a45cdaSLars-Peter Clausen /** 294112a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 294212a48a8cSMark Brown * 2943*628536eaSJonathan Corbet * @dev: platform to unregister 294412a48a8cSMark Brown */ 2945f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 294612a48a8cSMark Brown { 2947f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 2948f0fba2adSLiam Girdwood 294971a45cdaSLars-Peter Clausen platform = snd_soc_lookup_platform(dev); 295071a45cdaSLars-Peter Clausen if (!platform) 2951f0fba2adSLiam Girdwood return; 2952f0fba2adSLiam Girdwood 295371a45cdaSLars-Peter Clausen snd_soc_remove_platform(platform); 2954f0fba2adSLiam Girdwood kfree(platform); 295512a48a8cSMark Brown } 295612a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 295712a48a8cSMark Brown 2958151ab22cSMark Brown static u64 codec_format_map[] = { 2959151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 2960151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 2961151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 2962151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 2963151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 2964151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 2965151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 2966151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 2967151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 2968151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 2969151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 2970151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 2971151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 2972151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 2973151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 2974151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 2975151ab22cSMark Brown }; 2976151ab22cSMark Brown 2977151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 2978151ab22cSMark Brown * the endianness of the data but we're using the CPU format 2979151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 2980151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 2981151ab22cSMark Brown */ 2982151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 2983151ab22cSMark Brown { 2984151ab22cSMark Brown int i; 2985151ab22cSMark Brown 2986151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 2987151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 2988151ab22cSMark Brown stream->formats |= codec_format_map[i]; 2989151ab22cSMark Brown } 2990151ab22cSMark Brown 2991f1d45cc3SLars-Peter Clausen static int snd_soc_codec_drv_probe(struct snd_soc_component *component) 2992f1d45cc3SLars-Peter Clausen { 2993f1d45cc3SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 2994f1d45cc3SLars-Peter Clausen 2995f1d45cc3SLars-Peter Clausen return codec->driver->probe(codec); 2996f1d45cc3SLars-Peter Clausen } 2997f1d45cc3SLars-Peter Clausen 2998f1d45cc3SLars-Peter Clausen static void snd_soc_codec_drv_remove(struct snd_soc_component *component) 2999f1d45cc3SLars-Peter Clausen { 3000f1d45cc3SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3001f1d45cc3SLars-Peter Clausen 3002f1d45cc3SLars-Peter Clausen codec->driver->remove(codec); 3003f1d45cc3SLars-Peter Clausen } 3004f1d45cc3SLars-Peter Clausen 3005e2c330b9SLars-Peter Clausen static int snd_soc_codec_drv_write(struct snd_soc_component *component, 3006e2c330b9SLars-Peter Clausen unsigned int reg, unsigned int val) 3007e2c330b9SLars-Peter Clausen { 3008e2c330b9SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3009e2c330b9SLars-Peter Clausen 3010e2c330b9SLars-Peter Clausen return codec->driver->write(codec, reg, val); 3011e2c330b9SLars-Peter Clausen } 3012e2c330b9SLars-Peter Clausen 3013e2c330b9SLars-Peter Clausen static int snd_soc_codec_drv_read(struct snd_soc_component *component, 3014e2c330b9SLars-Peter Clausen unsigned int reg, unsigned int *val) 3015e2c330b9SLars-Peter Clausen { 3016e2c330b9SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3017e2c330b9SLars-Peter Clausen 3018e2c330b9SLars-Peter Clausen *val = codec->driver->read(codec, reg); 3019e2c330b9SLars-Peter Clausen 3020e2c330b9SLars-Peter Clausen return 0; 3021e2c330b9SLars-Peter Clausen } 3022e2c330b9SLars-Peter Clausen 302368f831c2SLars-Peter Clausen static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, 302468f831c2SLars-Peter Clausen enum snd_soc_bias_level level) 302568f831c2SLars-Peter Clausen { 302668f831c2SLars-Peter Clausen struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); 302768f831c2SLars-Peter Clausen 302868f831c2SLars-Peter Clausen return codec->driver->set_bias_level(codec, level); 302968f831c2SLars-Peter Clausen } 303068f831c2SLars-Peter Clausen 30310d0cf00aSMark Brown /** 30320d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 30330d0cf00aSMark Brown * 3034*628536eaSJonathan Corbet * @dev: The parent device for this codec 3035*628536eaSJonathan Corbet * @codec_drv: Codec driver 3036*628536eaSJonathan Corbet * @dai_drv: The associated DAI driver 3037*628536eaSJonathan Corbet * @num_dai: Number of DAIs 30380d0cf00aSMark Brown */ 3039f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 3040001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 3041001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 3042001ae4c0SMark Brown int num_dai) 30430d0cf00aSMark Brown { 3044f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3045bb13109dSLars-Peter Clausen struct snd_soc_dai *dai; 3046f0fba2adSLiam Girdwood int ret, i; 3047151ab22cSMark Brown 3048f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 30490d0cf00aSMark Brown 3050f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 3051f0fba2adSLiam Girdwood if (codec == NULL) 3052f0fba2adSLiam Girdwood return -ENOMEM; 30530d0cf00aSMark Brown 3054ce0fc93aSLars-Peter Clausen codec->component.dapm_ptr = &codec->dapm; 3055f1d45cc3SLars-Peter Clausen codec->component.codec = codec; 3056ce0fc93aSLars-Peter Clausen 3057bb13109dSLars-Peter Clausen ret = snd_soc_component_initialize(&codec->component, 3058bb13109dSLars-Peter Clausen &codec_drv->component_driver, dev); 3059bb13109dSLars-Peter Clausen if (ret) 3060bb13109dSLars-Peter Clausen goto err_free; 3061151ab22cSMark Brown 3062f1d45cc3SLars-Peter Clausen if (codec_drv->controls) { 3063f1d45cc3SLars-Peter Clausen codec->component.controls = codec_drv->controls; 3064f1d45cc3SLars-Peter Clausen codec->component.num_controls = codec_drv->num_controls; 3065f1d45cc3SLars-Peter Clausen } 3066f1d45cc3SLars-Peter Clausen if (codec_drv->dapm_widgets) { 3067f1d45cc3SLars-Peter Clausen codec->component.dapm_widgets = codec_drv->dapm_widgets; 3068f1d45cc3SLars-Peter Clausen codec->component.num_dapm_widgets = codec_drv->num_dapm_widgets; 3069f1d45cc3SLars-Peter Clausen } 3070f1d45cc3SLars-Peter Clausen if (codec_drv->dapm_routes) { 3071f1d45cc3SLars-Peter Clausen codec->component.dapm_routes = codec_drv->dapm_routes; 3072f1d45cc3SLars-Peter Clausen codec->component.num_dapm_routes = codec_drv->num_dapm_routes; 3073f1d45cc3SLars-Peter Clausen } 3074f1d45cc3SLars-Peter Clausen 3075f1d45cc3SLars-Peter Clausen if (codec_drv->probe) 3076f1d45cc3SLars-Peter Clausen codec->component.probe = snd_soc_codec_drv_probe; 3077f1d45cc3SLars-Peter Clausen if (codec_drv->remove) 3078f1d45cc3SLars-Peter Clausen codec->component.remove = snd_soc_codec_drv_remove; 3079e2c330b9SLars-Peter Clausen if (codec_drv->write) 3080e2c330b9SLars-Peter Clausen codec->component.write = snd_soc_codec_drv_write; 3081e2c330b9SLars-Peter Clausen if (codec_drv->read) 3082e2c330b9SLars-Peter Clausen codec->component.read = snd_soc_codec_drv_read; 30833d59400fSLars-Peter Clausen codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; 30845819c2faSLars-Peter Clausen codec->dapm.idle_bias_off = codec_drv->idle_bias_off; 308586dbf2acSLars-Peter Clausen codec->dapm.suspend_bias_off = codec_drv->suspend_bias_off; 308614e8bdebSLars-Peter Clausen if (codec_drv->seq_notifier) 3087474b62d6SMark Brown codec->dapm.seq_notifier = codec_drv->seq_notifier; 308868f831c2SLars-Peter Clausen if (codec_drv->set_bias_level) 308968f831c2SLars-Peter Clausen codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; 3090f0fba2adSLiam Girdwood codec->dev = dev; 3091f0fba2adSLiam Girdwood codec->driver = codec_drv; 3092e2c330b9SLars-Peter Clausen codec->component.val_bytes = codec_drv->reg_word_size; 3093f0fba2adSLiam Girdwood 309481c7cfd1SLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 309581c7cfd1SLars-Peter Clausen codec->component.init_debugfs = soc_init_codec_debugfs; 309681c7cfd1SLars-Peter Clausen codec->component.debugfs_prefix = "codec"; 309781c7cfd1SLars-Peter Clausen #endif 3098a39f75f7SXiubo Li 3099a39f75f7SXiubo Li if (codec_drv->get_regmap) 3100886f5692SLars-Peter Clausen codec->component.regmap = codec_drv->get_regmap(dev); 3101a39f75f7SXiubo Li 3102f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 3103f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 3104f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 3105f0fba2adSLiam Girdwood } 3106f0fba2adSLiam Girdwood 3107bb13109dSLars-Peter Clausen ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); 3108bb13109dSLars-Peter Clausen if (ret < 0) { 3109f42cf8d6SMasanari Iida dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); 3110bb13109dSLars-Peter Clausen goto err_cleanup; 3111bb13109dSLars-Peter Clausen } 3112bb13109dSLars-Peter Clausen 3113bb13109dSLars-Peter Clausen list_for_each_entry(dai, &codec->component.dai_list, list) 3114bb13109dSLars-Peter Clausen dai->codec = codec; 3115bb13109dSLars-Peter Clausen 3116054880feSMark Brown mutex_lock(&client_mutex); 3117bb13109dSLars-Peter Clausen snd_soc_component_add_unlocked(&codec->component); 3118054880feSMark Brown list_add(&codec->list, &codec_list); 3119054880feSMark Brown mutex_unlock(&client_mutex); 3120054880feSMark Brown 3121f4333203SLars-Peter Clausen dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", 3122f4333203SLars-Peter Clausen codec->component.name); 31230d0cf00aSMark Brown return 0; 3124f0fba2adSLiam Girdwood 3125bb13109dSLars-Peter Clausen err_cleanup: 3126bb13109dSLars-Peter Clausen snd_soc_component_cleanup(&codec->component); 3127bb13109dSLars-Peter Clausen err_free: 3128f0fba2adSLiam Girdwood kfree(codec); 3129f0fba2adSLiam Girdwood return ret; 31300d0cf00aSMark Brown } 31310d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 31320d0cf00aSMark Brown 31330d0cf00aSMark Brown /** 31340d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 31350d0cf00aSMark Brown * 3136*628536eaSJonathan Corbet * @dev: codec to unregister 31370d0cf00aSMark Brown */ 3138f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 31390d0cf00aSMark Brown { 3140f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3141f0fba2adSLiam Girdwood 314234e81ab4SLars-Peter Clausen mutex_lock(&client_mutex); 3143f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 3144f0fba2adSLiam Girdwood if (dev == codec->dev) 3145f0fba2adSLiam Girdwood goto found; 3146f0fba2adSLiam Girdwood } 314734e81ab4SLars-Peter Clausen mutex_unlock(&client_mutex); 3148f0fba2adSLiam Girdwood return; 3149f0fba2adSLiam Girdwood 3150f0fba2adSLiam Girdwood found: 31510d0cf00aSMark Brown list_del(&codec->list); 3152bb13109dSLars-Peter Clausen snd_soc_component_del_unlocked(&codec->component); 31530d0cf00aSMark Brown mutex_unlock(&client_mutex); 31540d0cf00aSMark Brown 3155f4333203SLars-Peter Clausen dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", 3156f4333203SLars-Peter Clausen codec->component.name); 3157f0fba2adSLiam Girdwood 3158bb13109dSLars-Peter Clausen snd_soc_component_cleanup(&codec->component); 31597a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 3160f0fba2adSLiam Girdwood kfree(codec); 31610d0cf00aSMark Brown } 31620d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 31630d0cf00aSMark Brown 3164bec4fa05SStephen Warren /* Retrieve a card's name from device tree */ 3165bec4fa05SStephen Warren int snd_soc_of_parse_card_name(struct snd_soc_card *card, 3166bec4fa05SStephen Warren const char *propname) 3167bec4fa05SStephen Warren { 31687e07e7c0STushar Behera struct device_node *np; 3169bec4fa05SStephen Warren int ret; 3170bec4fa05SStephen Warren 31717e07e7c0STushar Behera if (!card->dev) { 31727e07e7c0STushar Behera pr_err("card->dev is not set before calling %s\n", __func__); 31737e07e7c0STushar Behera return -EINVAL; 31747e07e7c0STushar Behera } 31757e07e7c0STushar Behera 31767e07e7c0STushar Behera np = card->dev->of_node; 31777e07e7c0STushar Behera 3178bec4fa05SStephen Warren ret = of_property_read_string_index(np, propname, 0, &card->name); 3179bec4fa05SStephen Warren /* 3180bec4fa05SStephen Warren * EINVAL means the property does not exist. This is fine providing 3181bec4fa05SStephen Warren * card->name was previously set, which is checked later in 3182bec4fa05SStephen Warren * snd_soc_register_card. 3183bec4fa05SStephen Warren */ 3184bec4fa05SStephen Warren if (ret < 0 && ret != -EINVAL) { 3185bec4fa05SStephen Warren dev_err(card->dev, 3186f110bfc7SLiam Girdwood "ASoC: Property '%s' could not be read: %d\n", 3187bec4fa05SStephen Warren propname, ret); 3188bec4fa05SStephen Warren return ret; 3189bec4fa05SStephen Warren } 3190bec4fa05SStephen Warren 3191bec4fa05SStephen Warren return 0; 3192bec4fa05SStephen Warren } 3193bec4fa05SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 3194bec4fa05SStephen Warren 31959a6d4860SXiubo Li static const struct snd_soc_dapm_widget simple_widgets[] = { 31969a6d4860SXiubo Li SND_SOC_DAPM_MIC("Microphone", NULL), 31979a6d4860SXiubo Li SND_SOC_DAPM_LINE("Line", NULL), 31989a6d4860SXiubo Li SND_SOC_DAPM_HP("Headphone", NULL), 31999a6d4860SXiubo Li SND_SOC_DAPM_SPK("Speaker", NULL), 32009a6d4860SXiubo Li }; 32019a6d4860SXiubo Li 32029a6d4860SXiubo Li int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, 32039a6d4860SXiubo Li const char *propname) 32049a6d4860SXiubo Li { 32059a6d4860SXiubo Li struct device_node *np = card->dev->of_node; 32069a6d4860SXiubo Li struct snd_soc_dapm_widget *widgets; 32079a6d4860SXiubo Li const char *template, *wname; 32089a6d4860SXiubo Li int i, j, num_widgets, ret; 32099a6d4860SXiubo Li 32109a6d4860SXiubo Li num_widgets = of_property_count_strings(np, propname); 32119a6d4860SXiubo Li if (num_widgets < 0) { 32129a6d4860SXiubo Li dev_err(card->dev, 32139a6d4860SXiubo Li "ASoC: Property '%s' does not exist\n", propname); 32149a6d4860SXiubo Li return -EINVAL; 32159a6d4860SXiubo Li } 32169a6d4860SXiubo Li if (num_widgets & 1) { 32179a6d4860SXiubo Li dev_err(card->dev, 32189a6d4860SXiubo Li "ASoC: Property '%s' length is not even\n", propname); 32199a6d4860SXiubo Li return -EINVAL; 32209a6d4860SXiubo Li } 32219a6d4860SXiubo Li 32229a6d4860SXiubo Li num_widgets /= 2; 32239a6d4860SXiubo Li if (!num_widgets) { 32249a6d4860SXiubo Li dev_err(card->dev, "ASoC: Property '%s's length is zero\n", 32259a6d4860SXiubo Li propname); 32269a6d4860SXiubo Li return -EINVAL; 32279a6d4860SXiubo Li } 32289a6d4860SXiubo Li 32299a6d4860SXiubo Li widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), 32309a6d4860SXiubo Li GFP_KERNEL); 32319a6d4860SXiubo Li if (!widgets) { 32329a6d4860SXiubo Li dev_err(card->dev, 32339a6d4860SXiubo Li "ASoC: Could not allocate memory for widgets\n"); 32349a6d4860SXiubo Li return -ENOMEM; 32359a6d4860SXiubo Li } 32369a6d4860SXiubo Li 32379a6d4860SXiubo Li for (i = 0; i < num_widgets; i++) { 32389a6d4860SXiubo Li ret = of_property_read_string_index(np, propname, 32399a6d4860SXiubo Li 2 * i, &template); 32409a6d4860SXiubo Li if (ret) { 32419a6d4860SXiubo Li dev_err(card->dev, 32429a6d4860SXiubo Li "ASoC: Property '%s' index %d read error:%d\n", 32439a6d4860SXiubo Li propname, 2 * i, ret); 32449a6d4860SXiubo Li return -EINVAL; 32459a6d4860SXiubo Li } 32469a6d4860SXiubo Li 32479a6d4860SXiubo Li for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) { 32489a6d4860SXiubo Li if (!strncmp(template, simple_widgets[j].name, 32499a6d4860SXiubo Li strlen(simple_widgets[j].name))) { 32509a6d4860SXiubo Li widgets[i] = simple_widgets[j]; 32519a6d4860SXiubo Li break; 32529a6d4860SXiubo Li } 32539a6d4860SXiubo Li } 32549a6d4860SXiubo Li 32559a6d4860SXiubo Li if (j >= ARRAY_SIZE(simple_widgets)) { 32569a6d4860SXiubo Li dev_err(card->dev, 32579a6d4860SXiubo Li "ASoC: DAPM widget '%s' is not supported\n", 32589a6d4860SXiubo Li template); 32599a6d4860SXiubo Li return -EINVAL; 32609a6d4860SXiubo Li } 32619a6d4860SXiubo Li 32629a6d4860SXiubo Li ret = of_property_read_string_index(np, propname, 32639a6d4860SXiubo Li (2 * i) + 1, 32649a6d4860SXiubo Li &wname); 32659a6d4860SXiubo Li if (ret) { 32669a6d4860SXiubo Li dev_err(card->dev, 32679a6d4860SXiubo Li "ASoC: Property '%s' index %d read error:%d\n", 32689a6d4860SXiubo Li propname, (2 * i) + 1, ret); 32699a6d4860SXiubo Li return -EINVAL; 32709a6d4860SXiubo Li } 32719a6d4860SXiubo Li 32729a6d4860SXiubo Li widgets[i].name = wname; 32739a6d4860SXiubo Li } 32749a6d4860SXiubo Li 3275f23e860eSNicolin Chen card->of_dapm_widgets = widgets; 3276f23e860eSNicolin Chen card->num_of_dapm_widgets = num_widgets; 32779a6d4860SXiubo Li 32789a6d4860SXiubo Li return 0; 32799a6d4860SXiubo Li } 32809a6d4860SXiubo Li EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); 32819a6d4860SXiubo Li 328289c67857SXiubo Li int snd_soc_of_parse_tdm_slot(struct device_node *np, 328389c67857SXiubo Li unsigned int *slots, 328489c67857SXiubo Li unsigned int *slot_width) 328589c67857SXiubo Li { 328689c67857SXiubo Li u32 val; 328789c67857SXiubo Li int ret; 328889c67857SXiubo Li 328989c67857SXiubo Li if (of_property_read_bool(np, "dai-tdm-slot-num")) { 329089c67857SXiubo Li ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); 329189c67857SXiubo Li if (ret) 329289c67857SXiubo Li return ret; 329389c67857SXiubo Li 329489c67857SXiubo Li if (slots) 329589c67857SXiubo Li *slots = val; 329689c67857SXiubo Li } 329789c67857SXiubo Li 329889c67857SXiubo Li if (of_property_read_bool(np, "dai-tdm-slot-width")) { 329989c67857SXiubo Li ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); 330089c67857SXiubo Li if (ret) 330189c67857SXiubo Li return ret; 330289c67857SXiubo Li 330389c67857SXiubo Li if (slot_width) 330489c67857SXiubo Li *slot_width = val; 330589c67857SXiubo Li } 330689c67857SXiubo Li 330789c67857SXiubo Li return 0; 330889c67857SXiubo Li } 330989c67857SXiubo Li EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); 331089c67857SXiubo Li 3311a4a54dd5SStephen Warren int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 3312a4a54dd5SStephen Warren const char *propname) 3313a4a54dd5SStephen Warren { 3314a4a54dd5SStephen Warren struct device_node *np = card->dev->of_node; 3315e3b1e6a1SMark Brown int num_routes; 3316a4a54dd5SStephen Warren struct snd_soc_dapm_route *routes; 3317a4a54dd5SStephen Warren int i, ret; 3318a4a54dd5SStephen Warren 3319a4a54dd5SStephen Warren num_routes = of_property_count_strings(np, propname); 3320c34ce320SRichard Zhao if (num_routes < 0 || num_routes & 1) { 332110e8aa9aSMichał Mirosław dev_err(card->dev, 332210e8aa9aSMichał Mirosław "ASoC: Property '%s' does not exist or its length is not even\n", 332310e8aa9aSMichał Mirosław propname); 3324a4a54dd5SStephen Warren return -EINVAL; 3325a4a54dd5SStephen Warren } 3326a4a54dd5SStephen Warren num_routes /= 2; 3327a4a54dd5SStephen Warren if (!num_routes) { 3328f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Property '%s's length is zero\n", 3329a4a54dd5SStephen Warren propname); 3330a4a54dd5SStephen Warren return -EINVAL; 3331a4a54dd5SStephen Warren } 3332a4a54dd5SStephen Warren 3333e3b1e6a1SMark Brown routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), 3334a4a54dd5SStephen Warren GFP_KERNEL); 3335a4a54dd5SStephen Warren if (!routes) { 3336a4a54dd5SStephen Warren dev_err(card->dev, 3337f110bfc7SLiam Girdwood "ASoC: Could not allocate DAPM route table\n"); 3338a4a54dd5SStephen Warren return -EINVAL; 3339a4a54dd5SStephen Warren } 3340a4a54dd5SStephen Warren 3341a4a54dd5SStephen Warren for (i = 0; i < num_routes; i++) { 3342a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3343e3b1e6a1SMark Brown 2 * i, &routes[i].sink); 3344a4a54dd5SStephen Warren if (ret) { 3345c871bd0bSMark Brown dev_err(card->dev, 3346c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 3347c871bd0bSMark Brown propname, 2 * i, ret); 3348a4a54dd5SStephen Warren return -EINVAL; 3349a4a54dd5SStephen Warren } 3350a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3351e3b1e6a1SMark Brown (2 * i) + 1, &routes[i].source); 3352a4a54dd5SStephen Warren if (ret) { 3353a4a54dd5SStephen Warren dev_err(card->dev, 3354c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 3355c871bd0bSMark Brown propname, (2 * i) + 1, ret); 3356a4a54dd5SStephen Warren return -EINVAL; 3357a4a54dd5SStephen Warren } 3358a4a54dd5SStephen Warren } 3359a4a54dd5SStephen Warren 3360f23e860eSNicolin Chen card->num_of_dapm_routes = num_routes; 3361f23e860eSNicolin Chen card->of_dapm_routes = routes; 3362a4a54dd5SStephen Warren 3363a4a54dd5SStephen Warren return 0; 3364a4a54dd5SStephen Warren } 3365a4a54dd5SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); 3366a4a54dd5SStephen Warren 3367a7930ed4SKuninori Morimoto unsigned int snd_soc_of_parse_daifmt(struct device_node *np, 3368389cb834SJyri Sarha const char *prefix, 3369389cb834SJyri Sarha struct device_node **bitclkmaster, 3370389cb834SJyri Sarha struct device_node **framemaster) 3371a7930ed4SKuninori Morimoto { 3372a7930ed4SKuninori Morimoto int ret, i; 3373a7930ed4SKuninori Morimoto char prop[128]; 3374a7930ed4SKuninori Morimoto unsigned int format = 0; 3375a7930ed4SKuninori Morimoto int bit, frame; 3376a7930ed4SKuninori Morimoto const char *str; 3377a7930ed4SKuninori Morimoto struct { 3378a7930ed4SKuninori Morimoto char *name; 3379a7930ed4SKuninori Morimoto unsigned int val; 3380a7930ed4SKuninori Morimoto } of_fmt_table[] = { 3381a7930ed4SKuninori Morimoto { "i2s", SND_SOC_DAIFMT_I2S }, 3382a7930ed4SKuninori Morimoto { "right_j", SND_SOC_DAIFMT_RIGHT_J }, 3383a7930ed4SKuninori Morimoto { "left_j", SND_SOC_DAIFMT_LEFT_J }, 3384a7930ed4SKuninori Morimoto { "dsp_a", SND_SOC_DAIFMT_DSP_A }, 3385a7930ed4SKuninori Morimoto { "dsp_b", SND_SOC_DAIFMT_DSP_B }, 3386a7930ed4SKuninori Morimoto { "ac97", SND_SOC_DAIFMT_AC97 }, 3387a7930ed4SKuninori Morimoto { "pdm", SND_SOC_DAIFMT_PDM}, 3388a7930ed4SKuninori Morimoto { "msb", SND_SOC_DAIFMT_MSB }, 3389a7930ed4SKuninori Morimoto { "lsb", SND_SOC_DAIFMT_LSB }, 3390a7930ed4SKuninori Morimoto }; 3391a7930ed4SKuninori Morimoto 3392a7930ed4SKuninori Morimoto if (!prefix) 3393a7930ed4SKuninori Morimoto prefix = ""; 3394a7930ed4SKuninori Morimoto 3395a7930ed4SKuninori Morimoto /* 3396a7930ed4SKuninori Morimoto * check "[prefix]format = xxx" 3397a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_FORMAT_MASK area 3398a7930ed4SKuninori Morimoto */ 3399a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sformat", prefix); 3400a7930ed4SKuninori Morimoto ret = of_property_read_string(np, prop, &str); 3401a7930ed4SKuninori Morimoto if (ret == 0) { 3402a7930ed4SKuninori Morimoto for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { 3403a7930ed4SKuninori Morimoto if (strcmp(str, of_fmt_table[i].name) == 0) { 3404a7930ed4SKuninori Morimoto format |= of_fmt_table[i].val; 3405a7930ed4SKuninori Morimoto break; 3406a7930ed4SKuninori Morimoto } 3407a7930ed4SKuninori Morimoto } 3408a7930ed4SKuninori Morimoto } 3409a7930ed4SKuninori Morimoto 3410a7930ed4SKuninori Morimoto /* 34118c2d6a9fSKuninori Morimoto * check "[prefix]continuous-clock" 3412a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_CLOCK_MASK area 3413a7930ed4SKuninori Morimoto */ 34148c2d6a9fSKuninori Morimoto snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); 34158c2d6a9fSKuninori Morimoto if (of_get_property(np, prop, NULL)) 34168c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_CONT; 34178c2d6a9fSKuninori Morimoto else 34188c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_GATED; 3419a7930ed4SKuninori Morimoto 3420a7930ed4SKuninori Morimoto /* 3421a7930ed4SKuninori Morimoto * check "[prefix]bitclock-inversion" 3422a7930ed4SKuninori Morimoto * check "[prefix]frame-inversion" 3423a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_INV_MASK area 3424a7930ed4SKuninori Morimoto */ 3425a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); 3426a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 3427a7930ed4SKuninori Morimoto 3428a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); 3429a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 3430a7930ed4SKuninori Morimoto 3431a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 3432a7930ed4SKuninori Morimoto case 0x11: 3433a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_IF; 3434a7930ed4SKuninori Morimoto break; 3435a7930ed4SKuninori Morimoto case 0x10: 3436a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_NF; 3437a7930ed4SKuninori Morimoto break; 3438a7930ed4SKuninori Morimoto case 0x01: 3439a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_NB_IF; 3440a7930ed4SKuninori Morimoto break; 3441a7930ed4SKuninori Morimoto default: 3442a7930ed4SKuninori Morimoto /* SND_SOC_DAIFMT_NB_NF is default */ 3443a7930ed4SKuninori Morimoto break; 3444a7930ed4SKuninori Morimoto } 3445a7930ed4SKuninori Morimoto 3446a7930ed4SKuninori Morimoto /* 3447a7930ed4SKuninori Morimoto * check "[prefix]bitclock-master" 3448a7930ed4SKuninori Morimoto * check "[prefix]frame-master" 3449a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_MASTER_MASK area 3450a7930ed4SKuninori Morimoto */ 3451a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); 3452a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 3453389cb834SJyri Sarha if (bit && bitclkmaster) 3454389cb834SJyri Sarha *bitclkmaster = of_parse_phandle(np, prop, 0); 3455a7930ed4SKuninori Morimoto 3456a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-master", prefix); 3457a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 3458389cb834SJyri Sarha if (frame && framemaster) 3459389cb834SJyri Sarha *framemaster = of_parse_phandle(np, prop, 0); 3460a7930ed4SKuninori Morimoto 3461a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 3462a7930ed4SKuninori Morimoto case 0x11: 3463a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFM; 3464a7930ed4SKuninori Morimoto break; 3465a7930ed4SKuninori Morimoto case 0x10: 3466a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFS; 3467a7930ed4SKuninori Morimoto break; 3468a7930ed4SKuninori Morimoto case 0x01: 3469a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFM; 3470a7930ed4SKuninori Morimoto break; 3471a7930ed4SKuninori Morimoto default: 3472a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFS; 3473a7930ed4SKuninori Morimoto break; 3474a7930ed4SKuninori Morimoto } 3475a7930ed4SKuninori Morimoto 3476a7930ed4SKuninori Morimoto return format; 3477a7930ed4SKuninori Morimoto } 3478a7930ed4SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); 3479a7930ed4SKuninori Morimoto 348093b0f3eeSJean-Francois Moine static int snd_soc_get_dai_name(struct of_phandle_args *args, 3481cb470087SKuninori Morimoto const char **dai_name) 3482cb470087SKuninori Morimoto { 3483cb470087SKuninori Morimoto struct snd_soc_component *pos; 34843e0aa8d8SJyri Sarha struct device_node *component_of_node; 348593b0f3eeSJean-Francois Moine int ret = -EPROBE_DEFER; 3486cb470087SKuninori Morimoto 3487cb470087SKuninori Morimoto mutex_lock(&client_mutex); 3488cb470087SKuninori Morimoto list_for_each_entry(pos, &component_list, list) { 34893e0aa8d8SJyri Sarha component_of_node = pos->dev->of_node; 34903e0aa8d8SJyri Sarha if (!component_of_node && pos->dev->parent) 34913e0aa8d8SJyri Sarha component_of_node = pos->dev->parent->of_node; 34923e0aa8d8SJyri Sarha 34933e0aa8d8SJyri Sarha if (component_of_node != args->np) 3494cb470087SKuninori Morimoto continue; 3495cb470087SKuninori Morimoto 34966833c452SKuninori Morimoto if (pos->driver->of_xlate_dai_name) { 349793b0f3eeSJean-Francois Moine ret = pos->driver->of_xlate_dai_name(pos, 349893b0f3eeSJean-Francois Moine args, 349993b0f3eeSJean-Francois Moine dai_name); 35006833c452SKuninori Morimoto } else { 35016833c452SKuninori Morimoto int id = -1; 35026833c452SKuninori Morimoto 350393b0f3eeSJean-Francois Moine switch (args->args_count) { 35046833c452SKuninori Morimoto case 0: 35056833c452SKuninori Morimoto id = 0; /* same as dai_drv[0] */ 35066833c452SKuninori Morimoto break; 35076833c452SKuninori Morimoto case 1: 350893b0f3eeSJean-Francois Moine id = args->args[0]; 35096833c452SKuninori Morimoto break; 35106833c452SKuninori Morimoto default: 35116833c452SKuninori Morimoto /* not supported */ 3512cb470087SKuninori Morimoto break; 3513cb470087SKuninori Morimoto } 3514cb470087SKuninori Morimoto 35156833c452SKuninori Morimoto if (id < 0 || id >= pos->num_dai) { 35166833c452SKuninori Morimoto ret = -EINVAL; 35173dcba280SNicolin Chen continue; 35186833c452SKuninori Morimoto } 3519e41975edSXiubo Li 3520e41975edSXiubo Li ret = 0; 3521e41975edSXiubo Li 3522e41975edSXiubo Li *dai_name = pos->dai_drv[id].name; 3523e41975edSXiubo Li if (!*dai_name) 3524e41975edSXiubo Li *dai_name = pos->name; 35256833c452SKuninori Morimoto } 35266833c452SKuninori Morimoto 3527cb470087SKuninori Morimoto break; 3528cb470087SKuninori Morimoto } 3529cb470087SKuninori Morimoto mutex_unlock(&client_mutex); 353093b0f3eeSJean-Francois Moine return ret; 353193b0f3eeSJean-Francois Moine } 353293b0f3eeSJean-Francois Moine 353393b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_name(struct device_node *of_node, 353493b0f3eeSJean-Francois Moine const char **dai_name) 353593b0f3eeSJean-Francois Moine { 353693b0f3eeSJean-Francois Moine struct of_phandle_args args; 353793b0f3eeSJean-Francois Moine int ret; 353893b0f3eeSJean-Francois Moine 353993b0f3eeSJean-Francois Moine ret = of_parse_phandle_with_args(of_node, "sound-dai", 354093b0f3eeSJean-Francois Moine "#sound-dai-cells", 0, &args); 354193b0f3eeSJean-Francois Moine if (ret) 354293b0f3eeSJean-Francois Moine return ret; 354393b0f3eeSJean-Francois Moine 354493b0f3eeSJean-Francois Moine ret = snd_soc_get_dai_name(&args, dai_name); 3545cb470087SKuninori Morimoto 3546cb470087SKuninori Morimoto of_node_put(args.np); 3547cb470087SKuninori Morimoto 3548cb470087SKuninori Morimoto return ret; 3549cb470087SKuninori Morimoto } 3550cb470087SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); 3551cb470087SKuninori Morimoto 355293b0f3eeSJean-Francois Moine /* 355393b0f3eeSJean-Francois Moine * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree 355493b0f3eeSJean-Francois Moine * @dev: Card device 355593b0f3eeSJean-Francois Moine * @of_node: Device node 355693b0f3eeSJean-Francois Moine * @dai_link: DAI link 355793b0f3eeSJean-Francois Moine * 355893b0f3eeSJean-Francois Moine * Builds an array of CODEC DAI components from the DAI link property 355993b0f3eeSJean-Francois Moine * 'sound-dai'. 356093b0f3eeSJean-Francois Moine * The array is set in the DAI link and the number of DAIs is set accordingly. 356193b0f3eeSJean-Francois Moine * The device nodes in the array (of_node) must be dereferenced by the caller. 356293b0f3eeSJean-Francois Moine * 356393b0f3eeSJean-Francois Moine * Returns 0 for success 356493b0f3eeSJean-Francois Moine */ 356593b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_link_codecs(struct device *dev, 356693b0f3eeSJean-Francois Moine struct device_node *of_node, 356793b0f3eeSJean-Francois Moine struct snd_soc_dai_link *dai_link) 356893b0f3eeSJean-Francois Moine { 356993b0f3eeSJean-Francois Moine struct of_phandle_args args; 357093b0f3eeSJean-Francois Moine struct snd_soc_dai_link_component *component; 357193b0f3eeSJean-Francois Moine char *name; 357293b0f3eeSJean-Francois Moine int index, num_codecs, ret; 357393b0f3eeSJean-Francois Moine 357493b0f3eeSJean-Francois Moine /* Count the number of CODECs */ 357593b0f3eeSJean-Francois Moine name = "sound-dai"; 357693b0f3eeSJean-Francois Moine num_codecs = of_count_phandle_with_args(of_node, name, 357793b0f3eeSJean-Francois Moine "#sound-dai-cells"); 357893b0f3eeSJean-Francois Moine if (num_codecs <= 0) { 357993b0f3eeSJean-Francois Moine if (num_codecs == -ENOENT) 358093b0f3eeSJean-Francois Moine dev_err(dev, "No 'sound-dai' property\n"); 358193b0f3eeSJean-Francois Moine else 358293b0f3eeSJean-Francois Moine dev_err(dev, "Bad phandle in 'sound-dai'\n"); 358393b0f3eeSJean-Francois Moine return num_codecs; 358493b0f3eeSJean-Francois Moine } 358593b0f3eeSJean-Francois Moine component = devm_kzalloc(dev, 358693b0f3eeSJean-Francois Moine sizeof *component * num_codecs, 358793b0f3eeSJean-Francois Moine GFP_KERNEL); 358893b0f3eeSJean-Francois Moine if (!component) 358993b0f3eeSJean-Francois Moine return -ENOMEM; 359093b0f3eeSJean-Francois Moine dai_link->codecs = component; 359193b0f3eeSJean-Francois Moine dai_link->num_codecs = num_codecs; 359293b0f3eeSJean-Francois Moine 359393b0f3eeSJean-Francois Moine /* Parse the list */ 359493b0f3eeSJean-Francois Moine for (index = 0, component = dai_link->codecs; 359593b0f3eeSJean-Francois Moine index < dai_link->num_codecs; 359693b0f3eeSJean-Francois Moine index++, component++) { 359793b0f3eeSJean-Francois Moine ret = of_parse_phandle_with_args(of_node, name, 359893b0f3eeSJean-Francois Moine "#sound-dai-cells", 359993b0f3eeSJean-Francois Moine index, &args); 360093b0f3eeSJean-Francois Moine if (ret) 360193b0f3eeSJean-Francois Moine goto err; 360293b0f3eeSJean-Francois Moine component->of_node = args.np; 360393b0f3eeSJean-Francois Moine ret = snd_soc_get_dai_name(&args, &component->dai_name); 360493b0f3eeSJean-Francois Moine if (ret < 0) 360593b0f3eeSJean-Francois Moine goto err; 360693b0f3eeSJean-Francois Moine } 360793b0f3eeSJean-Francois Moine return 0; 360893b0f3eeSJean-Francois Moine err: 360993b0f3eeSJean-Francois Moine for (index = 0, component = dai_link->codecs; 361093b0f3eeSJean-Francois Moine index < dai_link->num_codecs; 361193b0f3eeSJean-Francois Moine index++, component++) { 361293b0f3eeSJean-Francois Moine if (!component->of_node) 361393b0f3eeSJean-Francois Moine break; 361493b0f3eeSJean-Francois Moine of_node_put(component->of_node); 361593b0f3eeSJean-Francois Moine component->of_node = NULL; 361693b0f3eeSJean-Francois Moine } 361793b0f3eeSJean-Francois Moine dai_link->codecs = NULL; 361893b0f3eeSJean-Francois Moine dai_link->num_codecs = 0; 361993b0f3eeSJean-Francois Moine return ret; 362093b0f3eeSJean-Francois Moine } 362193b0f3eeSJean-Francois Moine EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); 362293b0f3eeSJean-Francois Moine 3623c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 3624db2a4165SFrank Mandarino { 36256553bf06SLars-Peter Clausen snd_soc_debugfs_init(); 3626fb257897SMark Brown snd_soc_util_init(); 3627fb257897SMark Brown 3628db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 3629db2a4165SFrank Mandarino } 36304abe8e16SMark Brown module_init(snd_soc_init); 3631db2a4165SFrank Mandarino 3632db2a4165SFrank Mandarino static void __exit snd_soc_exit(void) 3633db2a4165SFrank Mandarino { 3634fb257897SMark Brown snd_soc_util_exit(); 36356553bf06SLars-Peter Clausen snd_soc_debugfs_exit(); 3636fb257897SMark Brown 3637db2a4165SFrank Mandarino #ifdef CONFIG_DEBUG_FS 3638db2a4165SFrank Mandarino #endif 3639db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 3640db2a4165SFrank Mandarino } 3641db2a4165SFrank Mandarino module_exit(snd_soc_exit); 3642db2a4165SFrank Mandarino 3643db2a4165SFrank Mandarino /* Module information */ 3644db2a4165SFrank Mandarino MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 3645db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 3646db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 3647db2a4165SFrank Mandarino MODULE_ALIAS("platform:soc-audio"); 3648