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> 33f0e8ed85SMark Brown #include <linux/ctype.h> 345a0e3ad6STejun Heo #include <linux/slab.h> 35bec4fa05SStephen Warren #include <linux/of.h> 36474828a4SMarek Vasut #include <sound/ac97_codec.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> 42db2a4165SFrank Mandarino #include <sound/initval.h> 43db2a4165SFrank Mandarino 44a8b1d34fSMark Brown #define CREATE_TRACE_POINTS 45a8b1d34fSMark Brown #include <trace/events/asoc.h> 46a8b1d34fSMark Brown 47f0fba2adSLiam Girdwood #define NAME_SIZE 32 48f0fba2adSLiam Girdwood 49db2a4165SFrank Mandarino static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 50db2a4165SFrank Mandarino 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); 57c5af3a2eSMark Brown static LIST_HEAD(card_list); 589115171aSMark Brown static LIST_HEAD(dai_list); 5912a48a8cSMark Brown static LIST_HEAD(platform_list); 600d0cf00aSMark Brown static LIST_HEAD(codec_list); 61c5af3a2eSMark Brown 62db2a4165SFrank Mandarino /* 63db2a4165SFrank Mandarino * This is a timeout to do a DAPM powerdown after a stream is closed(). 64db2a4165SFrank Mandarino * It can be used to eliminate pops between different playback streams, e.g. 65db2a4165SFrank Mandarino * between two audio tracks. 66db2a4165SFrank Mandarino */ 67db2a4165SFrank Mandarino static int pmdown_time = 5000; 68db2a4165SFrank Mandarino module_param(pmdown_time, int, 0); 69db2a4165SFrank Mandarino MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 70db2a4165SFrank Mandarino 712bc9a81eSDimitris Papastamos /* returns the minimum number of bytes needed to represent 722bc9a81eSDimitris Papastamos * a particular given value */ 732bc9a81eSDimitris Papastamos static int min_bytes_needed(unsigned long val) 742bc9a81eSDimitris Papastamos { 752bc9a81eSDimitris Papastamos int c = 0; 762bc9a81eSDimitris Papastamos int i; 772bc9a81eSDimitris Papastamos 782bc9a81eSDimitris Papastamos for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) 792bc9a81eSDimitris Papastamos if (val & (1UL << i)) 802bc9a81eSDimitris Papastamos break; 812bc9a81eSDimitris Papastamos c = (sizeof val * 8) - c; 822bc9a81eSDimitris Papastamos if (!c || (c % 8)) 832bc9a81eSDimitris Papastamos c = (c + 8) / 8; 842bc9a81eSDimitris Papastamos else 852bc9a81eSDimitris Papastamos c /= 8; 862bc9a81eSDimitris Papastamos return c; 872bc9a81eSDimitris Papastamos } 882bc9a81eSDimitris Papastamos 8913fd179fSDimitris Papastamos /* fill buf which is 'len' bytes with a formatted 9013fd179fSDimitris Papastamos * string of the form 'reg: value\n' */ 9113fd179fSDimitris Papastamos static int format_register_str(struct snd_soc_codec *codec, 9213fd179fSDimitris Papastamos unsigned int reg, char *buf, size_t len) 932624d5faSMark Brown { 9400b317a4SStephen Warren int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 9500b317a4SStephen Warren int regsize = codec->driver->reg_word_size * 2; 9613fd179fSDimitris Papastamos int ret; 9713fd179fSDimitris Papastamos char tmpbuf[len + 1]; 9813fd179fSDimitris Papastamos char regbuf[regsize + 1]; 9913fd179fSDimitris Papastamos 10013fd179fSDimitris Papastamos /* since tmpbuf is allocated on the stack, warn the callers if they 10113fd179fSDimitris Papastamos * try to abuse this function */ 10213fd179fSDimitris Papastamos WARN_ON(len > 63); 10313fd179fSDimitris Papastamos 10413fd179fSDimitris Papastamos /* +2 for ': ' and + 1 for '\n' */ 10513fd179fSDimitris Papastamos if (wordsize + regsize + 2 + 1 != len) 10613fd179fSDimitris Papastamos return -EINVAL; 10713fd179fSDimitris Papastamos 10813fd179fSDimitris Papastamos ret = snd_soc_read(codec, reg); 10913fd179fSDimitris Papastamos if (ret < 0) { 11013fd179fSDimitris Papastamos memset(regbuf, 'X', regsize); 11113fd179fSDimitris Papastamos regbuf[regsize] = '\0'; 11213fd179fSDimitris Papastamos } else { 11313fd179fSDimitris Papastamos snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); 11413fd179fSDimitris Papastamos } 11513fd179fSDimitris Papastamos 11613fd179fSDimitris Papastamos /* prepare the buffer */ 11713fd179fSDimitris Papastamos snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); 11813fd179fSDimitris Papastamos /* copy it back to the caller without the '\0' */ 11913fd179fSDimitris Papastamos memcpy(buf, tmpbuf, len); 12013fd179fSDimitris Papastamos 12113fd179fSDimitris Papastamos return 0; 12213fd179fSDimitris Papastamos } 12313fd179fSDimitris Papastamos 12413fd179fSDimitris Papastamos /* codec register dump */ 12513fd179fSDimitris Papastamos static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, 12613fd179fSDimitris Papastamos size_t count, loff_t pos) 12713fd179fSDimitris Papastamos { 12813fd179fSDimitris Papastamos int i, step = 1; 1292bc9a81eSDimitris Papastamos int wordsize, regsize; 13013fd179fSDimitris Papastamos int len; 13113fd179fSDimitris Papastamos size_t total = 0; 13213fd179fSDimitris Papastamos loff_t p = 0; 1332bc9a81eSDimitris Papastamos 13400b317a4SStephen Warren wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 13500b317a4SStephen Warren regsize = codec->driver->reg_word_size * 2; 1362624d5faSMark Brown 13713fd179fSDimitris Papastamos len = wordsize + regsize + 2 + 1; 13813fd179fSDimitris Papastamos 139f0fba2adSLiam Girdwood if (!codec->driver->reg_cache_size) 1402624d5faSMark Brown return 0; 1412624d5faSMark Brown 142f0fba2adSLiam Girdwood if (codec->driver->reg_cache_step) 143f0fba2adSLiam Girdwood step = codec->driver->reg_cache_step; 1442624d5faSMark Brown 145f0fba2adSLiam Girdwood for (i = 0; i < codec->driver->reg_cache_size; i += step) { 146b92d150bSLars-Peter Clausen if (!snd_soc_codec_readable_register(codec, i)) 1472624d5faSMark Brown continue; 148f0fba2adSLiam Girdwood if (codec->driver->display_register) { 149f0fba2adSLiam Girdwood count += codec->driver->display_register(codec, buf + count, 1502624d5faSMark Brown PAGE_SIZE - count, i); 1515164d74dSMark Brown } else { 15213fd179fSDimitris Papastamos /* only support larger than PAGE_SIZE bytes debugfs 15313fd179fSDimitris Papastamos * entries for the default case */ 15413fd179fSDimitris Papastamos if (p >= pos) { 15513fd179fSDimitris Papastamos if (total + len >= count - 1) 1562624d5faSMark Brown break; 15713fd179fSDimitris Papastamos format_register_str(codec, i, buf + total, len); 15813fd179fSDimitris Papastamos total += len; 15913fd179fSDimitris Papastamos } 16013fd179fSDimitris Papastamos p += len; 16113fd179fSDimitris Papastamos } 1622624d5faSMark Brown } 1632624d5faSMark Brown 16413fd179fSDimitris Papastamos total = min(total, count - 1); 1652624d5faSMark Brown 16613fd179fSDimitris Papastamos return total; 1672624d5faSMark Brown } 16813fd179fSDimitris Papastamos 1692624d5faSMark Brown static ssize_t codec_reg_show(struct device *dev, 1702624d5faSMark Brown struct device_attribute *attr, char *buf) 1712624d5faSMark Brown { 17236ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 173f0fba2adSLiam Girdwood 17413fd179fSDimitris Papastamos return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 1752624d5faSMark Brown } 1762624d5faSMark Brown 1772624d5faSMark Brown static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1782624d5faSMark Brown 179dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev, 180dbe21408SMark Brown struct device_attribute *attr, char *buf) 181dbe21408SMark Brown { 18236ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 183dbe21408SMark Brown 184f0fba2adSLiam Girdwood return sprintf(buf, "%ld\n", rtd->pmdown_time); 185dbe21408SMark Brown } 186dbe21408SMark Brown 187dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev, 188dbe21408SMark Brown struct device_attribute *attr, 189dbe21408SMark Brown const char *buf, size_t count) 190dbe21408SMark Brown { 19136ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 192c593b520SMark Brown int ret; 193dbe21408SMark Brown 194c593b520SMark Brown ret = strict_strtol(buf, 10, &rtd->pmdown_time); 195c593b520SMark Brown if (ret) 196c593b520SMark Brown return ret; 197dbe21408SMark Brown 198dbe21408SMark Brown return count; 199dbe21408SMark Brown } 200dbe21408SMark Brown 201dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 202dbe21408SMark Brown 2032624d5faSMark Brown #ifdef CONFIG_DEBUG_FS 2042624d5faSMark Brown static int codec_reg_open_file(struct inode *inode, struct file *file) 2052624d5faSMark Brown { 2062624d5faSMark Brown file->private_data = inode->i_private; 2072624d5faSMark Brown return 0; 2082624d5faSMark Brown } 2092624d5faSMark Brown 2102624d5faSMark Brown static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 2112624d5faSMark Brown size_t count, loff_t *ppos) 2122624d5faSMark Brown { 2132624d5faSMark Brown ssize_t ret; 2142624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 21513fd179fSDimitris Papastamos char *buf; 21613fd179fSDimitris Papastamos 21713fd179fSDimitris Papastamos if (*ppos < 0 || !count) 21813fd179fSDimitris Papastamos return -EINVAL; 21913fd179fSDimitris Papastamos 22013fd179fSDimitris Papastamos buf = kmalloc(count, GFP_KERNEL); 2212624d5faSMark Brown if (!buf) 2222624d5faSMark Brown return -ENOMEM; 22313fd179fSDimitris Papastamos 22413fd179fSDimitris Papastamos ret = soc_codec_reg_show(codec, buf, count, *ppos); 22513fd179fSDimitris Papastamos if (ret >= 0) { 22613fd179fSDimitris Papastamos if (copy_to_user(user_buf, buf, ret)) { 22713fd179fSDimitris Papastamos kfree(buf); 22813fd179fSDimitris Papastamos return -EFAULT; 22913fd179fSDimitris Papastamos } 23013fd179fSDimitris Papastamos *ppos += ret; 23113fd179fSDimitris Papastamos } 23213fd179fSDimitris Papastamos 2332624d5faSMark Brown kfree(buf); 2342624d5faSMark Brown return ret; 2352624d5faSMark Brown } 2362624d5faSMark Brown 2372624d5faSMark Brown static ssize_t codec_reg_write_file(struct file *file, 2382624d5faSMark Brown const char __user *user_buf, size_t count, loff_t *ppos) 2392624d5faSMark Brown { 2402624d5faSMark Brown char buf[32]; 24134e268d8SStephen Boyd size_t buf_size; 2422624d5faSMark Brown char *start = buf; 2432624d5faSMark Brown unsigned long reg, value; 2442624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 2452624d5faSMark Brown 2462624d5faSMark Brown buf_size = min(count, (sizeof(buf)-1)); 2472624d5faSMark Brown if (copy_from_user(buf, user_buf, buf_size)) 2482624d5faSMark Brown return -EFAULT; 2492624d5faSMark Brown buf[buf_size] = 0; 2502624d5faSMark Brown 2512624d5faSMark Brown while (*start == ' ') 2522624d5faSMark Brown start++; 2532624d5faSMark Brown reg = simple_strtoul(start, &start, 16); 2542624d5faSMark Brown while (*start == ' ') 2552624d5faSMark Brown start++; 2562624d5faSMark Brown if (strict_strtoul(start, 16, &value)) 2572624d5faSMark Brown return -EINVAL; 2580d51a9cbSMark Brown 2590d51a9cbSMark Brown /* Userspace has been fiddling around behind the kernel's back */ 2600d51a9cbSMark Brown add_taint(TAINT_USER); 2610d51a9cbSMark Brown 262e4f078d8SDimitris Papastamos snd_soc_write(codec, reg, value); 2632624d5faSMark Brown return buf_size; 2642624d5faSMark Brown } 2652624d5faSMark Brown 2662624d5faSMark Brown static const struct file_operations codec_reg_fops = { 2672624d5faSMark Brown .open = codec_reg_open_file, 2682624d5faSMark Brown .read = codec_reg_read_file, 2692624d5faSMark Brown .write = codec_reg_write_file, 2706038f373SArnd Bergmann .llseek = default_llseek, 2712624d5faSMark Brown }; 2722624d5faSMark Brown 2732624d5faSMark Brown static void soc_init_codec_debugfs(struct snd_soc_codec *codec) 2742624d5faSMark Brown { 275d6ce4cf3SJarkko Nikula struct dentry *debugfs_card_root = codec->card->debugfs_card_root; 276d6ce4cf3SJarkko Nikula 2776ba6c9c3SMark Brown codec->debugfs_codec_root = debugfs_create_dir(codec->name, 278d6ce4cf3SJarkko Nikula debugfs_card_root); 2792624d5faSMark Brown if (!codec->debugfs_codec_root) { 28064e60f9fSLiam Girdwood dev_warn(codec->dev, "Failed to create codec debugfs directory\n"); 2812624d5faSMark Brown return; 2822624d5faSMark Brown } 2832624d5faSMark Brown 284aaee8ef1SMark Brown debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, 285aaee8ef1SMark Brown &codec->cache_sync); 286aaee8ef1SMark Brown debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, 287aaee8ef1SMark Brown &codec->cache_only); 288aaee8ef1SMark Brown 2892624d5faSMark Brown codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 2902624d5faSMark Brown codec->debugfs_codec_root, 2912624d5faSMark Brown codec, &codec_reg_fops); 2922624d5faSMark Brown if (!codec->debugfs_reg) 29364e60f9fSLiam Girdwood dev_warn(codec->dev, "Failed to create codec register debugfs file\n"); 2942624d5faSMark Brown 2958eecaf62SLars-Peter Clausen snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); 2962624d5faSMark Brown } 2972624d5faSMark Brown 2982624d5faSMark Brown static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 2992624d5faSMark Brown { 3002624d5faSMark Brown debugfs_remove_recursive(codec->debugfs_codec_root); 3012624d5faSMark Brown } 3022624d5faSMark Brown 303731f1ab2SSebastien Guiriec static void soc_init_platform_debugfs(struct snd_soc_platform *platform) 304731f1ab2SSebastien Guiriec { 305731f1ab2SSebastien Guiriec struct dentry *debugfs_card_root = platform->card->debugfs_card_root; 306731f1ab2SSebastien Guiriec 307731f1ab2SSebastien Guiriec platform->debugfs_platform_root = debugfs_create_dir(platform->name, 308731f1ab2SSebastien Guiriec debugfs_card_root); 309731f1ab2SSebastien Guiriec if (!platform->debugfs_platform_root) { 310731f1ab2SSebastien Guiriec dev_warn(platform->dev, 311731f1ab2SSebastien Guiriec "Failed to create platform debugfs directory\n"); 312731f1ab2SSebastien Guiriec return; 313731f1ab2SSebastien Guiriec } 314731f1ab2SSebastien Guiriec 315731f1ab2SSebastien Guiriec snd_soc_dapm_debugfs_init(&platform->dapm, 316731f1ab2SSebastien Guiriec platform->debugfs_platform_root); 317731f1ab2SSebastien Guiriec } 318731f1ab2SSebastien Guiriec 319731f1ab2SSebastien Guiriec static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) 320731f1ab2SSebastien Guiriec { 321731f1ab2SSebastien Guiriec debugfs_remove_recursive(platform->debugfs_platform_root); 322731f1ab2SSebastien Guiriec } 323731f1ab2SSebastien Guiriec 324c3c5a19aSMark Brown static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, 325c3c5a19aSMark Brown size_t count, loff_t *ppos) 326c3c5a19aSMark Brown { 327c3c5a19aSMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3282b194f9dSMark Brown ssize_t len, ret = 0; 329c3c5a19aSMark Brown struct snd_soc_codec *codec; 330c3c5a19aSMark Brown 331c3c5a19aSMark Brown if (!buf) 332c3c5a19aSMark Brown return -ENOMEM; 333c3c5a19aSMark Brown 3342b194f9dSMark Brown list_for_each_entry(codec, &codec_list, list) { 3352b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 336c3c5a19aSMark Brown codec->name); 3372b194f9dSMark Brown if (len >= 0) 3382b194f9dSMark Brown ret += len; 3392b194f9dSMark Brown if (ret > PAGE_SIZE) { 3402b194f9dSMark Brown ret = PAGE_SIZE; 3412b194f9dSMark Brown break; 3422b194f9dSMark Brown } 3432b194f9dSMark Brown } 344c3c5a19aSMark Brown 345c3c5a19aSMark Brown if (ret >= 0) 346c3c5a19aSMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 347c3c5a19aSMark Brown 348c3c5a19aSMark Brown kfree(buf); 349c3c5a19aSMark Brown 350c3c5a19aSMark Brown return ret; 351c3c5a19aSMark Brown } 352c3c5a19aSMark Brown 353c3c5a19aSMark Brown static const struct file_operations codec_list_fops = { 354c3c5a19aSMark Brown .read = codec_list_read_file, 355c3c5a19aSMark Brown .llseek = default_llseek,/* read accesses f_pos */ 356c3c5a19aSMark Brown }; 357c3c5a19aSMark Brown 358f3208780SMark Brown static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, 359f3208780SMark Brown size_t count, loff_t *ppos) 360f3208780SMark Brown { 361f3208780SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3622b194f9dSMark Brown ssize_t len, ret = 0; 363f3208780SMark Brown struct snd_soc_dai *dai; 364f3208780SMark Brown 365f3208780SMark Brown if (!buf) 366f3208780SMark Brown return -ENOMEM; 367f3208780SMark Brown 3682b194f9dSMark Brown list_for_each_entry(dai, &dai_list, list) { 3692b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); 3702b194f9dSMark Brown if (len >= 0) 3712b194f9dSMark Brown ret += len; 3722b194f9dSMark Brown if (ret > PAGE_SIZE) { 3732b194f9dSMark Brown ret = PAGE_SIZE; 3742b194f9dSMark Brown break; 3752b194f9dSMark Brown } 3762b194f9dSMark Brown } 377f3208780SMark Brown 378f3208780SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 379f3208780SMark Brown 380f3208780SMark Brown kfree(buf); 381f3208780SMark Brown 382f3208780SMark Brown return ret; 383f3208780SMark Brown } 384f3208780SMark Brown 385f3208780SMark Brown static const struct file_operations dai_list_fops = { 386f3208780SMark Brown .read = dai_list_read_file, 387f3208780SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 388f3208780SMark Brown }; 389f3208780SMark Brown 39019c7ac27SMark Brown static ssize_t platform_list_read_file(struct file *file, 39119c7ac27SMark Brown char __user *user_buf, 39219c7ac27SMark Brown size_t count, loff_t *ppos) 39319c7ac27SMark Brown { 39419c7ac27SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3952b194f9dSMark Brown ssize_t len, ret = 0; 39619c7ac27SMark Brown struct snd_soc_platform *platform; 39719c7ac27SMark Brown 39819c7ac27SMark Brown if (!buf) 39919c7ac27SMark Brown return -ENOMEM; 40019c7ac27SMark Brown 4012b194f9dSMark Brown list_for_each_entry(platform, &platform_list, list) { 4022b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 40319c7ac27SMark Brown platform->name); 4042b194f9dSMark Brown if (len >= 0) 4052b194f9dSMark Brown ret += len; 4062b194f9dSMark Brown if (ret > PAGE_SIZE) { 4072b194f9dSMark Brown ret = PAGE_SIZE; 4082b194f9dSMark Brown break; 4092b194f9dSMark Brown } 4102b194f9dSMark Brown } 41119c7ac27SMark Brown 41219c7ac27SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 41319c7ac27SMark Brown 41419c7ac27SMark Brown kfree(buf); 41519c7ac27SMark Brown 41619c7ac27SMark Brown return ret; 41719c7ac27SMark Brown } 41819c7ac27SMark Brown 41919c7ac27SMark Brown static const struct file_operations platform_list_fops = { 42019c7ac27SMark Brown .read = platform_list_read_file, 42119c7ac27SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 42219c7ac27SMark Brown }; 42319c7ac27SMark Brown 424a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card) 425a6052154SJarkko Nikula { 426a6052154SJarkko Nikula card->debugfs_card_root = debugfs_create_dir(card->name, 4278a9dab1aSMark Brown snd_soc_debugfs_root); 4283a45b867SJarkko Nikula if (!card->debugfs_card_root) { 429a6052154SJarkko Nikula dev_warn(card->dev, 4307c08be84SLothar Waßmann "ASoC: Failed to create card debugfs directory\n"); 4313a45b867SJarkko Nikula return; 4323a45b867SJarkko Nikula } 4333a45b867SJarkko Nikula 4343a45b867SJarkko Nikula card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 4353a45b867SJarkko Nikula card->debugfs_card_root, 4363a45b867SJarkko Nikula &card->pop_time); 4373a45b867SJarkko Nikula if (!card->debugfs_pop_time) 4383a45b867SJarkko Nikula dev_warn(card->dev, 4393a45b867SJarkko Nikula "Failed to create pop time debugfs file\n"); 440a6052154SJarkko Nikula } 441a6052154SJarkko Nikula 442a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card) 443a6052154SJarkko Nikula { 444a6052154SJarkko Nikula debugfs_remove_recursive(card->debugfs_card_root); 445a6052154SJarkko Nikula } 446a6052154SJarkko Nikula 4472624d5faSMark Brown #else 4482624d5faSMark Brown 4492624d5faSMark Brown static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) 4502624d5faSMark Brown { 4512624d5faSMark Brown } 4522624d5faSMark Brown 4532624d5faSMark Brown static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 4542624d5faSMark Brown { 4552624d5faSMark Brown } 456b95fccbcSAxel Lin 457731f1ab2SSebastien Guiriec static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform) 458731f1ab2SSebastien Guiriec { 459731f1ab2SSebastien Guiriec } 460731f1ab2SSebastien Guiriec 461731f1ab2SSebastien Guiriec static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) 462731f1ab2SSebastien Guiriec { 463731f1ab2SSebastien Guiriec } 464731f1ab2SSebastien Guiriec 465b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card) 466b95fccbcSAxel Lin { 467b95fccbcSAxel Lin } 468b95fccbcSAxel Lin 469b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) 470b95fccbcSAxel Lin { 471b95fccbcSAxel Lin } 4722624d5faSMark Brown #endif 4732624d5faSMark Brown 474db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS 475db2a4165SFrank Mandarino /* unregister ac97 codec */ 476db2a4165SFrank Mandarino static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 477db2a4165SFrank Mandarino { 478db2a4165SFrank Mandarino if (codec->ac97->dev.bus) 479db2a4165SFrank Mandarino device_unregister(&codec->ac97->dev); 480db2a4165SFrank Mandarino return 0; 481db2a4165SFrank Mandarino } 482db2a4165SFrank Mandarino 483db2a4165SFrank Mandarino /* stop no dev release warning */ 484db2a4165SFrank Mandarino static void soc_ac97_device_release(struct device *dev){} 485db2a4165SFrank Mandarino 486db2a4165SFrank Mandarino /* register ac97 codec to bus */ 487db2a4165SFrank Mandarino static int soc_ac97_dev_register(struct snd_soc_codec *codec) 488db2a4165SFrank Mandarino { 489db2a4165SFrank Mandarino int err; 490db2a4165SFrank Mandarino 491db2a4165SFrank Mandarino codec->ac97->dev.bus = &ac97_bus_type; 4924ac5c61fSMark Brown codec->ac97->dev.parent = codec->card->dev; 493db2a4165SFrank Mandarino codec->ac97->dev.release = soc_ac97_device_release; 494db2a4165SFrank Mandarino 495bb072bf0SKay Sievers dev_set_name(&codec->ac97->dev, "%d-%d:%s", 496f0fba2adSLiam Girdwood codec->card->snd_card->number, 0, codec->name); 497db2a4165SFrank Mandarino err = device_register(&codec->ac97->dev); 498db2a4165SFrank Mandarino if (err < 0) { 499db2a4165SFrank Mandarino snd_printk(KERN_ERR "Can't register ac97 bus\n"); 500db2a4165SFrank Mandarino codec->ac97->dev.bus = NULL; 501db2a4165SFrank Mandarino return err; 502db2a4165SFrank Mandarino } 503db2a4165SFrank Mandarino return 0; 504db2a4165SFrank Mandarino } 505db2a4165SFrank Mandarino #endif 506db2a4165SFrank Mandarino 5076f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP 508db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */ 5096f8ab4acSMark Brown int snd_soc_suspend(struct device *dev) 510db2a4165SFrank Mandarino { 5116f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 5122eea392dSJarkko Nikula struct snd_soc_codec *codec; 513db2a4165SFrank Mandarino int i; 514db2a4165SFrank Mandarino 515e3509ff0SDaniel Mack /* If the initialization of this soc device failed, there is no codec 516e3509ff0SDaniel Mack * associated with it. Just bail out in this case. 517e3509ff0SDaniel Mack */ 518f0fba2adSLiam Girdwood if (list_empty(&card->codec_dev_list)) 519e3509ff0SDaniel Mack return 0; 520e3509ff0SDaniel Mack 5216ed25978SAndy Green /* Due to the resume being scheduled into a workqueue we could 5226ed25978SAndy Green * suspend before that's finished - wait for it to complete. 5236ed25978SAndy Green */ 524f0fba2adSLiam Girdwood snd_power_lock(card->snd_card); 525f0fba2adSLiam Girdwood snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); 526f0fba2adSLiam Girdwood snd_power_unlock(card->snd_card); 5276ed25978SAndy Green 5286ed25978SAndy Green /* we're going to block userspace touching us until resume completes */ 529f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 5306ed25978SAndy Green 531a00f90f9SMark Brown /* mute any active DACs */ 532f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 533f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 534f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 5353efab7dcSMark Brown 536f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5373efab7dcSMark Brown continue; 5383efab7dcSMark Brown 539f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 540f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 1); 541db2a4165SFrank Mandarino } 542db2a4165SFrank Mandarino 5434ccab3e7SLiam Girdwood /* suspend all pcms */ 544f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 545f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5463efab7dcSMark Brown continue; 5473efab7dcSMark Brown 548f0fba2adSLiam Girdwood snd_pcm_suspend_all(card->rtd[i].pcm); 5493efab7dcSMark Brown } 5504ccab3e7SLiam Girdwood 55187506549SMark Brown if (card->suspend_pre) 55270b2ac12SMark Brown card->suspend_pre(card); 553db2a4165SFrank Mandarino 554f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 555f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 556f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 5573efab7dcSMark Brown 558f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5593efab7dcSMark Brown continue; 5603efab7dcSMark Brown 561f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) 562f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 563f0fba2adSLiam Girdwood if (platform->driver->suspend && !platform->suspended) { 564f0fba2adSLiam Girdwood platform->driver->suspend(cpu_dai); 565f0fba2adSLiam Girdwood platform->suspended = 1; 566f0fba2adSLiam Girdwood } 567db2a4165SFrank Mandarino } 568db2a4165SFrank Mandarino 569db2a4165SFrank Mandarino /* close any waiting streams and save state */ 570f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 5715b84ba26STejun Heo flush_delayed_work_sync(&card->rtd[i].delayed_work); 572ce6120ccSLiam Girdwood card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; 573f0fba2adSLiam Girdwood } 574db2a4165SFrank Mandarino 575f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 5767bd3a6f3SMark Brown struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; 5773efab7dcSMark Brown 578f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5793efab7dcSMark Brown continue; 5803efab7dcSMark Brown 5817bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 5827bd3a6f3SMark Brown SNDRV_PCM_STREAM_PLAYBACK, 5837bd3a6f3SMark Brown codec_dai, 584db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 585f0fba2adSLiam Girdwood 5867bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 5877bd3a6f3SMark Brown SNDRV_PCM_STREAM_CAPTURE, 5887bd3a6f3SMark Brown codec_dai, 589db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 590db2a4165SFrank Mandarino } 591db2a4165SFrank Mandarino 592f0fba2adSLiam Girdwood /* suspend all CODECs */ 5932eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 5941547aba9SMark Brown /* If there are paths active then the CODEC will be held with 5951547aba9SMark Brown * bias _ON and should not be suspended. */ 596f0fba2adSLiam Girdwood if (!codec->suspended && codec->driver->suspend) { 597ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 5981547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 599125a25daSMark Brown /* 600125a25daSMark Brown * If the CODEC is capable of idle 601125a25daSMark Brown * bias off then being in STANDBY 602125a25daSMark Brown * means it's doing something, 603125a25daSMark Brown * otherwise fall through. 604125a25daSMark Brown */ 605125a25daSMark Brown if (codec->dapm.idle_bias_off) { 606125a25daSMark Brown dev_dbg(codec->dev, 607125a25daSMark Brown "idle_bias_off CODEC on over suspend\n"); 608125a25daSMark Brown break; 609125a25daSMark Brown } 6101547aba9SMark Brown case SND_SOC_BIAS_OFF: 61184b315eeSLars-Peter Clausen codec->driver->suspend(codec); 612f0fba2adSLiam Girdwood codec->suspended = 1; 6137be4ba24SMark Brown codec->cache_sync = 1; 6141547aba9SMark Brown break; 6151547aba9SMark Brown default: 616f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC is on over suspend\n"); 6171547aba9SMark Brown break; 6181547aba9SMark Brown } 6191547aba9SMark Brown } 620f0fba2adSLiam Girdwood } 621db2a4165SFrank Mandarino 622f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 623f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6243efab7dcSMark Brown 625f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6263efab7dcSMark Brown continue; 6273efab7dcSMark Brown 628f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 629f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 630db2a4165SFrank Mandarino } 631db2a4165SFrank Mandarino 63287506549SMark Brown if (card->suspend_post) 63370b2ac12SMark Brown card->suspend_post(card); 634db2a4165SFrank Mandarino 635db2a4165SFrank Mandarino return 0; 636db2a4165SFrank Mandarino } 6376f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 638db2a4165SFrank Mandarino 6396ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 6406ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 6416ed25978SAndy Green */ 6426ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 643db2a4165SFrank Mandarino { 644f0fba2adSLiam Girdwood struct snd_soc_card *card = 645f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 6462eea392dSJarkko Nikula struct snd_soc_codec *codec; 647db2a4165SFrank Mandarino int i; 648db2a4165SFrank Mandarino 6496ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 6506ed25978SAndy Green * so userspace apps are blocked from touching us 6516ed25978SAndy Green */ 6526ed25978SAndy Green 653f0fba2adSLiam Girdwood dev_dbg(card->dev, "starting resume work\n"); 6546ed25978SAndy Green 6559949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 656f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 6579949788bSMark Brown 65887506549SMark Brown if (card->resume_pre) 65970b2ac12SMark Brown card->resume_pre(card); 660db2a4165SFrank Mandarino 661f0fba2adSLiam Girdwood /* resume AC97 DAIs */ 662f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 663f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6643efab7dcSMark Brown 665f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6663efab7dcSMark Brown continue; 6673efab7dcSMark Brown 668f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) 669f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 670db2a4165SFrank Mandarino } 671db2a4165SFrank Mandarino 6722eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 6731547aba9SMark Brown /* If the CODEC was idle over suspend then it will have been 6741547aba9SMark Brown * left with bias OFF or STANDBY and suspended so we must now 6751547aba9SMark Brown * resume. Otherwise the suspend was suppressed. 6761547aba9SMark Brown */ 677f0fba2adSLiam Girdwood if (codec->driver->resume && codec->suspended) { 678ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 6791547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 6801547aba9SMark Brown case SND_SOC_BIAS_OFF: 681f0fba2adSLiam Girdwood codec->driver->resume(codec); 682f0fba2adSLiam Girdwood codec->suspended = 0; 6831547aba9SMark Brown break; 6841547aba9SMark Brown default: 685f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC was 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++) { 6927bd3a6f3SMark Brown struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; 6933efab7dcSMark Brown 694f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6953efab7dcSMark Brown continue; 6963efab7dcSMark Brown 6977bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 6987bd3a6f3SMark Brown SNDRV_PCM_STREAM_PLAYBACK, codec_dai, 699db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 700f0fba2adSLiam Girdwood 7017bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 7027bd3a6f3SMark Brown SNDRV_PCM_STREAM_CAPTURE, codec_dai, 703db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 704db2a4165SFrank Mandarino } 705db2a4165SFrank Mandarino 7063ff3f64bSMark Brown /* unmute any active DACs */ 707f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 708f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 709f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 7103efab7dcSMark Brown 711f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7123efab7dcSMark Brown continue; 7133efab7dcSMark Brown 714f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 715f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 716db2a4165SFrank Mandarino } 717db2a4165SFrank Mandarino 718f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 719f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 720f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 7213efab7dcSMark Brown 722f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7233efab7dcSMark Brown continue; 7243efab7dcSMark Brown 725f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) 726f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 727f0fba2adSLiam Girdwood if (platform->driver->resume && platform->suspended) { 728f0fba2adSLiam Girdwood platform->driver->resume(cpu_dai); 729f0fba2adSLiam Girdwood platform->suspended = 0; 730f0fba2adSLiam Girdwood } 731db2a4165SFrank Mandarino } 732db2a4165SFrank Mandarino 73387506549SMark Brown if (card->resume_post) 73470b2ac12SMark Brown card->resume_post(card); 735db2a4165SFrank Mandarino 736f0fba2adSLiam Girdwood dev_dbg(card->dev, "resume work completed\n"); 7376ed25978SAndy Green 7386ed25978SAndy Green /* userspace can access us now we are back as we were before */ 739f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 7406ed25978SAndy Green } 7416ed25978SAndy Green 7426ed25978SAndy Green /* powers up audio subsystem after a suspend */ 7436f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 7446ed25978SAndy Green { 7456f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 74682e14e8bSStephen Warren int i, ac97_control = 0; 747b9dd94a8SPeter Ujfalusi 7485ff1ddf2SEric Miao /* If the initialization of this soc device failed, there is no codec 7495ff1ddf2SEric Miao * associated with it. Just bail out in this case. 7505ff1ddf2SEric Miao */ 7515ff1ddf2SEric Miao if (list_empty(&card->codec_dev_list)) 7525ff1ddf2SEric Miao return 0; 7535ff1ddf2SEric Miao 75464ab9baaSMark Brown /* AC97 devices might have other drivers hanging off them so 75564ab9baaSMark Brown * need to resume immediately. Other drivers don't have that 75664ab9baaSMark Brown * problem and may take a substantial amount of time to resume 75764ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 75864ab9baaSMark Brown */ 759f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 760f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 76182e14e8bSStephen Warren ac97_control |= cpu_dai->driver->ac97_control; 76282e14e8bSStephen Warren } 76382e14e8bSStephen Warren if (ac97_control) { 764f0fba2adSLiam Girdwood dev_dbg(dev, "Resuming AC97 immediately\n"); 76564ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 76664ab9baaSMark Brown } else { 767f0fba2adSLiam Girdwood dev_dbg(dev, "Scheduling resume work\n"); 7686308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 769f0fba2adSLiam Girdwood dev_err(dev, "resume work item may be lost\n"); 770f0fba2adSLiam Girdwood } 7716ed25978SAndy Green 772db2a4165SFrank Mandarino return 0; 773db2a4165SFrank Mandarino } 7746f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 775db2a4165SFrank Mandarino #else 7766f8ab4acSMark Brown #define snd_soc_suspend NULL 7776f8ab4acSMark Brown #define snd_soc_resume NULL 778db2a4165SFrank Mandarino #endif 779db2a4165SFrank Mandarino 78085e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops null_dai_ops = { 78102a06d30SBarry Song }; 78202a06d30SBarry Song 783f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 784db2a4165SFrank Mandarino { 785f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 786f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 787fe3e78e0SMark Brown struct snd_soc_codec *codec; 788435c5e25SMark Brown struct snd_soc_platform *platform; 789f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai, *cpu_dai; 790848dd8beSMark Brown const char *platform_name; 791db2a4165SFrank Mandarino 792f0fba2adSLiam Girdwood if (rtd->complete) 793f0fba2adSLiam Girdwood return 1; 794f0fba2adSLiam Girdwood dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); 7956308419aSMark Brown 796f0fba2adSLiam Girdwood /* do we already have the CPU DAI for this link ? */ 797f0fba2adSLiam Girdwood if (rtd->cpu_dai) { 798f0fba2adSLiam Girdwood goto find_codec; 799435c5e25SMark Brown } 800f0fba2adSLiam Girdwood /* no, then find CPU DAI from registered DAIs*/ 801f0fba2adSLiam Girdwood list_for_each_entry(cpu_dai, &dai_list, list) { 8025a504963SStephen Warren if (dai_link->cpu_dai_of_node) { 8035a504963SStephen Warren if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node) 8045a504963SStephen Warren continue; 8055a504963SStephen Warren } else { 8062610ab77SStephen Warren if (strcmp(cpu_dai->name, dai_link->cpu_dai_name)) 8072610ab77SStephen Warren continue; 8085a504963SStephen Warren } 8092610ab77SStephen Warren 810f0fba2adSLiam Girdwood rtd->cpu_dai = cpu_dai; 811f0fba2adSLiam Girdwood goto find_codec; 812f0fba2adSLiam Girdwood } 813f0fba2adSLiam Girdwood dev_dbg(card->dev, "CPU DAI %s not registered\n", 814f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 815f0fba2adSLiam Girdwood 816f0fba2adSLiam Girdwood find_codec: 817f0fba2adSLiam Girdwood /* do we already have the CODEC for this link ? */ 818f0fba2adSLiam Girdwood if (rtd->codec) { 819f0fba2adSLiam Girdwood goto find_platform; 820c5af3a2eSMark Brown } 821c5af3a2eSMark Brown 822f0fba2adSLiam Girdwood /* no, then find CODEC from registered CODECs*/ 823f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 8245a504963SStephen Warren if (dai_link->codec_of_node) { 8255a504963SStephen Warren if (codec->dev->of_node != dai_link->codec_of_node) 8265a504963SStephen Warren continue; 8275a504963SStephen Warren } else { 8282610ab77SStephen Warren if (strcmp(codec->name, dai_link->codec_name)) 8292610ab77SStephen Warren continue; 8305a504963SStephen Warren } 8312610ab77SStephen Warren 832f0fba2adSLiam Girdwood rtd->codec = codec; 833f0fba2adSLiam Girdwood 8342610ab77SStephen Warren /* 8352610ab77SStephen Warren * CODEC found, so find CODEC DAI from registered DAIs from 8362610ab77SStephen Warren * this CODEC 8372610ab77SStephen Warren */ 838f0fba2adSLiam Girdwood list_for_each_entry(codec_dai, &dai_list, list) { 839f0fba2adSLiam Girdwood if (codec->dev == codec_dai->dev && 8402610ab77SStephen Warren !strcmp(codec_dai->name, 8412610ab77SStephen Warren dai_link->codec_dai_name)) { 8422610ab77SStephen Warren 843f0fba2adSLiam Girdwood rtd->codec_dai = codec_dai; 844f0fba2adSLiam Girdwood goto find_platform; 845435c5e25SMark Brown } 846f0fba2adSLiam Girdwood } 847f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC DAI %s not registered\n", 848f0fba2adSLiam Girdwood dai_link->codec_dai_name); 849f0fba2adSLiam Girdwood 850f0fba2adSLiam Girdwood goto find_platform; 851f0fba2adSLiam Girdwood } 852f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC %s not registered\n", 853f0fba2adSLiam Girdwood dai_link->codec_name); 854f0fba2adSLiam Girdwood 855f0fba2adSLiam Girdwood find_platform: 856848dd8beSMark Brown /* do we need a platform? */ 857848dd8beSMark Brown if (rtd->platform) 858f0fba2adSLiam Girdwood goto out; 859848dd8beSMark Brown 860848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 861848dd8beSMark Brown platform_name = dai_link->platform_name; 8625a504963SStephen Warren if (!platform_name && !dai_link->platform_of_node) 863848dd8beSMark Brown platform_name = "snd-soc-dummy"; 864848dd8beSMark Brown 865848dd8beSMark Brown /* no, then find one from the set of registered platforms */ 866f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 8675a504963SStephen Warren if (dai_link->platform_of_node) { 8685a504963SStephen Warren if (platform->dev->of_node != 8695a504963SStephen Warren dai_link->platform_of_node) 8705a504963SStephen Warren continue; 8715a504963SStephen Warren } else { 8722610ab77SStephen Warren if (strcmp(platform->name, platform_name)) 8732610ab77SStephen Warren continue; 8745a504963SStephen Warren } 8752610ab77SStephen Warren 876f0fba2adSLiam Girdwood rtd->platform = platform; 877f0fba2adSLiam Girdwood goto out; 878f0fba2adSLiam Girdwood } 8796b05eda6SMark Brown 880f0fba2adSLiam Girdwood dev_dbg(card->dev, "platform %s not registered\n", 881f0fba2adSLiam Girdwood dai_link->platform_name); 882f0fba2adSLiam Girdwood return 0; 883f0fba2adSLiam Girdwood 884f0fba2adSLiam Girdwood out: 885f0fba2adSLiam Girdwood /* mark rtd as complete if we found all 4 of our client devices */ 886f0fba2adSLiam Girdwood if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) { 887f0fba2adSLiam Girdwood rtd->complete = 1; 888f0fba2adSLiam Girdwood card->num_rtd++; 889f0fba2adSLiam Girdwood } 890f0fba2adSLiam Girdwood return 1; 8916b05eda6SMark Brown } 8926b05eda6SMark Brown 893589c3563SJarkko Nikula static void soc_remove_codec(struct snd_soc_codec *codec) 894589c3563SJarkko Nikula { 895589c3563SJarkko Nikula int err; 896589c3563SJarkko Nikula 897589c3563SJarkko Nikula if (codec->driver->remove) { 898589c3563SJarkko Nikula err = codec->driver->remove(codec); 899589c3563SJarkko Nikula if (err < 0) 900589c3563SJarkko Nikula dev_err(codec->dev, 901589c3563SJarkko Nikula "asoc: failed to remove %s: %d\n", 902589c3563SJarkko Nikula codec->name, err); 903589c3563SJarkko Nikula } 904589c3563SJarkko Nikula 905589c3563SJarkko Nikula /* Make sure all DAPM widgets are freed */ 906589c3563SJarkko Nikula snd_soc_dapm_free(&codec->dapm); 907589c3563SJarkko Nikula 908589c3563SJarkko Nikula soc_cleanup_codec_debugfs(codec); 909589c3563SJarkko Nikula codec->probed = 0; 910589c3563SJarkko Nikula list_del(&codec->card_list); 911589c3563SJarkko Nikula module_put(codec->dev->driver->owner); 912589c3563SJarkko Nikula } 913589c3563SJarkko Nikula 9140168bf0dSLiam Girdwood static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) 915f0fba2adSLiam Girdwood { 916f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 917f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 918f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 919f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 920f0fba2adSLiam Girdwood int err; 921f0fba2adSLiam Girdwood 922f0fba2adSLiam Girdwood /* unregister the rtd device */ 923f0fba2adSLiam Girdwood if (rtd->dev_registered) { 92436ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_pmdown_time); 92536ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_codec_reg); 92636ae1a96SMark Brown device_unregister(rtd->dev); 927f0fba2adSLiam Girdwood rtd->dev_registered = 0; 92802a06d30SBarry Song } 92902a06d30SBarry Song 930f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 9310168bf0dSLiam Girdwood if (codec_dai && codec_dai->probed && 9320168bf0dSLiam Girdwood codec_dai->driver->remove_order == order) { 933f0fba2adSLiam Girdwood if (codec_dai->driver->remove) { 934f0fba2adSLiam Girdwood err = codec_dai->driver->remove(codec_dai); 935f0fba2adSLiam Girdwood if (err < 0) 9360837fc62SFabio Estevam pr_err("asoc: failed to remove %s: %d\n", 9370837fc62SFabio Estevam codec_dai->name, err); 938f0fba2adSLiam Girdwood } 939f0fba2adSLiam Girdwood codec_dai->probed = 0; 940f0fba2adSLiam Girdwood list_del(&codec_dai->card_list); 941f0fba2adSLiam Girdwood } 942f0fba2adSLiam Girdwood 943f0fba2adSLiam Girdwood /* remove the platform */ 9440168bf0dSLiam Girdwood if (platform && platform->probed && 9450168bf0dSLiam Girdwood platform->driver->remove_order == order) { 946f0fba2adSLiam Girdwood if (platform->driver->remove) { 947f0fba2adSLiam Girdwood err = platform->driver->remove(platform); 948f0fba2adSLiam Girdwood if (err < 0) 9490837fc62SFabio Estevam pr_err("asoc: failed to remove %s: %d\n", 9500837fc62SFabio Estevam platform->name, err); 951f0fba2adSLiam Girdwood } 952675c496bSLiam Girdwood 953675c496bSLiam Girdwood /* Make sure all DAPM widgets are freed */ 954675c496bSLiam Girdwood snd_soc_dapm_free(&platform->dapm); 955675c496bSLiam Girdwood 956731f1ab2SSebastien Guiriec soc_cleanup_platform_debugfs(platform); 957f0fba2adSLiam Girdwood platform->probed = 0; 958f0fba2adSLiam Girdwood list_del(&platform->card_list); 959f0fba2adSLiam Girdwood module_put(platform->dev->driver->owner); 960f0fba2adSLiam Girdwood } 961f0fba2adSLiam Girdwood 962f0fba2adSLiam Girdwood /* remove the CODEC */ 9630168bf0dSLiam Girdwood if (codec && codec->probed && 9640168bf0dSLiam Girdwood codec->driver->remove_order == order) 965589c3563SJarkko Nikula soc_remove_codec(codec); 966f0fba2adSLiam Girdwood 967f0fba2adSLiam Girdwood /* remove the cpu_dai */ 9680168bf0dSLiam Girdwood if (cpu_dai && cpu_dai->probed && 9690168bf0dSLiam Girdwood cpu_dai->driver->remove_order == order) { 970f0fba2adSLiam Girdwood if (cpu_dai->driver->remove) { 971f0fba2adSLiam Girdwood err = cpu_dai->driver->remove(cpu_dai); 972f0fba2adSLiam Girdwood if (err < 0) 9730837fc62SFabio Estevam pr_err("asoc: failed to remove %s: %d\n", 9740837fc62SFabio Estevam cpu_dai->name, err); 975f0fba2adSLiam Girdwood } 976f0fba2adSLiam Girdwood cpu_dai->probed = 0; 977f0fba2adSLiam Girdwood list_del(&cpu_dai->card_list); 978f0fba2adSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 979f0fba2adSLiam Girdwood } 980f0fba2adSLiam Girdwood } 981f0fba2adSLiam Girdwood 9820671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 9830671fd8eSKuninori Morimoto { 9840168bf0dSLiam Girdwood int dai, order; 9850671fd8eSKuninori Morimoto 9860168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 9870168bf0dSLiam Girdwood order++) { 9880168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 9890168bf0dSLiam Girdwood soc_remove_dai_link(card, dai, order); 9900168bf0dSLiam Girdwood } 9910671fd8eSKuninori Morimoto card->num_rtd = 0; 9920671fd8eSKuninori Morimoto } 9930671fd8eSKuninori Morimoto 994ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 995ead9b919SJarkko Nikula struct snd_soc_codec *codec) 996ead9b919SJarkko Nikula { 997ead9b919SJarkko Nikula int i; 998ead9b919SJarkko Nikula 999ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 1000ead9b919SJarkko Nikula return; 1001ead9b919SJarkko Nikula 1002ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 1003ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 1004ead9b919SJarkko Nikula if (map->dev_name && !strcmp(codec->name, map->dev_name)) { 1005ead9b919SJarkko Nikula codec->name_prefix = map->name_prefix; 1006ead9b919SJarkko Nikula break; 1007ead9b919SJarkko Nikula } 1008ead9b919SJarkko Nikula } 1009ead9b919SJarkko Nikula } 1010ead9b919SJarkko Nikula 1011589c3563SJarkko Nikula static int soc_probe_codec(struct snd_soc_card *card, 1012589c3563SJarkko Nikula struct snd_soc_codec *codec) 1013589c3563SJarkko Nikula { 1014589c3563SJarkko Nikula int ret = 0; 101589b95ac0SMark Brown const struct snd_soc_codec_driver *driver = codec->driver; 1016888df395SMark Brown struct snd_soc_dai *dai; 1017589c3563SJarkko Nikula 1018589c3563SJarkko Nikula codec->card = card; 1019589c3563SJarkko Nikula codec->dapm.card = card; 1020589c3563SJarkko Nikula soc_set_name_prefix(card, codec); 1021589c3563SJarkko Nikula 102270d29331SJarkko Nikula if (!try_module_get(codec->dev->driver->owner)) 102370d29331SJarkko Nikula return -ENODEV; 102470d29331SJarkko Nikula 1025d5d1e0beSLars-Peter Clausen soc_init_codec_debugfs(codec); 1026d5d1e0beSLars-Peter Clausen 102777530150SLars-Peter Clausen if (driver->dapm_widgets) 102877530150SLars-Peter Clausen snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, 102977530150SLars-Peter Clausen driver->num_dapm_widgets); 103077530150SLars-Peter Clausen 1031888df395SMark Brown /* Create DAPM widgets for each DAI stream */ 1032888df395SMark Brown list_for_each_entry(dai, &dai_list, list) { 1033888df395SMark Brown if (dai->dev != codec->dev) 1034888df395SMark Brown continue; 1035888df395SMark Brown 1036888df395SMark Brown snd_soc_dapm_new_dai_widgets(&codec->dapm, dai); 1037888df395SMark Brown } 1038888df395SMark Brown 103933c5f969SMark Brown codec->dapm.idle_bias_off = driver->idle_bias_off; 104033c5f969SMark Brown 104189b95ac0SMark Brown if (driver->probe) { 104289b95ac0SMark Brown ret = driver->probe(codec); 1043589c3563SJarkko Nikula if (ret < 0) { 1044589c3563SJarkko Nikula dev_err(codec->dev, 1045589c3563SJarkko Nikula "asoc: failed to probe CODEC %s: %d\n", 1046589c3563SJarkko Nikula codec->name, ret); 104770d29331SJarkko Nikula goto err_probe; 1048589c3563SJarkko Nikula } 1049589c3563SJarkko Nikula } 1050589c3563SJarkko Nikula 1051b7af1dafSMark Brown if (driver->controls) 1052022658beSLiam Girdwood snd_soc_add_codec_controls(codec, driver->controls, 1053b7af1dafSMark Brown driver->num_controls); 105489b95ac0SMark Brown if (driver->dapm_routes) 105589b95ac0SMark Brown snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, 105689b95ac0SMark Brown driver->num_dapm_routes); 105789b95ac0SMark Brown 1058589c3563SJarkko Nikula /* mark codec as probed and add to card codec list */ 1059589c3563SJarkko Nikula codec->probed = 1; 1060589c3563SJarkko Nikula list_add(&codec->card_list, &card->codec_dev_list); 10617be31be8SJarkko Nikula list_add(&codec->dapm.list, &card->dapm_list); 1062589c3563SJarkko Nikula 106370d29331SJarkko Nikula return 0; 106470d29331SJarkko Nikula 106570d29331SJarkko Nikula err_probe: 1066d5d1e0beSLars-Peter Clausen soc_cleanup_codec_debugfs(codec); 106770d29331SJarkko Nikula module_put(codec->dev->driver->owner); 106870d29331SJarkko Nikula 1069589c3563SJarkko Nikula return ret; 1070589c3563SJarkko Nikula } 1071589c3563SJarkko Nikula 1072956245e9SLiam Girdwood static int soc_probe_platform(struct snd_soc_card *card, 1073956245e9SLiam Girdwood struct snd_soc_platform *platform) 1074956245e9SLiam Girdwood { 1075956245e9SLiam Girdwood int ret = 0; 1076956245e9SLiam Girdwood const struct snd_soc_platform_driver *driver = platform->driver; 1077956245e9SLiam Girdwood 1078956245e9SLiam Girdwood platform->card = card; 1079b7950641SLiam Girdwood platform->dapm.card = card; 1080956245e9SLiam Girdwood 1081956245e9SLiam Girdwood if (!try_module_get(platform->dev->driver->owner)) 1082956245e9SLiam Girdwood return -ENODEV; 1083956245e9SLiam Girdwood 1084731f1ab2SSebastien Guiriec soc_init_platform_debugfs(platform); 1085731f1ab2SSebastien Guiriec 1086cb2cf612SLiam Girdwood if (driver->dapm_widgets) 1087cb2cf612SLiam Girdwood snd_soc_dapm_new_controls(&platform->dapm, 1088cb2cf612SLiam Girdwood driver->dapm_widgets, driver->num_dapm_widgets); 1089cb2cf612SLiam Girdwood 1090956245e9SLiam Girdwood if (driver->probe) { 1091956245e9SLiam Girdwood ret = driver->probe(platform); 1092956245e9SLiam Girdwood if (ret < 0) { 1093956245e9SLiam Girdwood dev_err(platform->dev, 1094956245e9SLiam Girdwood "asoc: failed to probe platform %s: %d\n", 1095956245e9SLiam Girdwood platform->name, ret); 1096956245e9SLiam Girdwood goto err_probe; 1097956245e9SLiam Girdwood } 1098956245e9SLiam Girdwood } 1099956245e9SLiam Girdwood 1100cb2cf612SLiam Girdwood if (driver->controls) 1101cb2cf612SLiam Girdwood snd_soc_add_platform_controls(platform, driver->controls, 1102cb2cf612SLiam Girdwood driver->num_controls); 1103cb2cf612SLiam Girdwood if (driver->dapm_routes) 1104cb2cf612SLiam Girdwood snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, 1105cb2cf612SLiam Girdwood driver->num_dapm_routes); 1106cb2cf612SLiam Girdwood 1107956245e9SLiam Girdwood /* mark platform as probed and add to card platform list */ 1108956245e9SLiam Girdwood platform->probed = 1; 1109956245e9SLiam Girdwood list_add(&platform->card_list, &card->platform_dev_list); 1110b7950641SLiam Girdwood list_add(&platform->dapm.list, &card->dapm_list); 1111956245e9SLiam Girdwood 1112956245e9SLiam Girdwood return 0; 1113956245e9SLiam Girdwood 1114956245e9SLiam Girdwood err_probe: 1115956245e9SLiam Girdwood module_put(platform->dev->driver->owner); 1116956245e9SLiam Girdwood 1117956245e9SLiam Girdwood return ret; 1118956245e9SLiam Girdwood } 1119956245e9SLiam Girdwood 112036ae1a96SMark Brown static void rtd_release(struct device *dev) 112136ae1a96SMark Brown { 112236ae1a96SMark Brown kfree(dev); 112336ae1a96SMark Brown } 1124f0fba2adSLiam Girdwood 1125589c3563SJarkko Nikula static int soc_post_component_init(struct snd_soc_card *card, 1126589c3563SJarkko Nikula struct snd_soc_codec *codec, 1127589c3563SJarkko Nikula int num, int dailess) 1128589c3563SJarkko Nikula { 1129589c3563SJarkko Nikula struct snd_soc_dai_link *dai_link = NULL; 1130589c3563SJarkko Nikula struct snd_soc_aux_dev *aux_dev = NULL; 1131589c3563SJarkko Nikula struct snd_soc_pcm_runtime *rtd; 1132589c3563SJarkko Nikula const char *temp, *name; 1133589c3563SJarkko Nikula int ret = 0; 1134589c3563SJarkko Nikula 1135589c3563SJarkko Nikula if (!dailess) { 1136589c3563SJarkko Nikula dai_link = &card->dai_link[num]; 1137589c3563SJarkko Nikula rtd = &card->rtd[num]; 1138589c3563SJarkko Nikula name = dai_link->name; 1139589c3563SJarkko Nikula } else { 1140589c3563SJarkko Nikula aux_dev = &card->aux_dev[num]; 1141589c3563SJarkko Nikula rtd = &card->rtd_aux[num]; 1142589c3563SJarkko Nikula name = aux_dev->name; 1143589c3563SJarkko Nikula } 11440962bb21SJanusz Krzysztofik rtd->card = card; 1145589c3563SJarkko Nikula 11464b1cfcb4SMark Brown /* Make sure all DAPM widgets are instantiated */ 11474b1cfcb4SMark Brown snd_soc_dapm_new_widgets(&codec->dapm); 11484b1cfcb4SMark Brown 1149589c3563SJarkko Nikula /* machine controls, routes and widgets are not prefixed */ 1150589c3563SJarkko Nikula temp = codec->name_prefix; 1151589c3563SJarkko Nikula codec->name_prefix = NULL; 1152589c3563SJarkko Nikula 1153589c3563SJarkko Nikula /* do machine specific initialization */ 1154589c3563SJarkko Nikula if (!dailess && dai_link->init) 1155589c3563SJarkko Nikula ret = dai_link->init(rtd); 1156589c3563SJarkko Nikula else if (dailess && aux_dev->init) 1157589c3563SJarkko Nikula ret = aux_dev->init(&codec->dapm); 1158589c3563SJarkko Nikula if (ret < 0) { 1159589c3563SJarkko Nikula dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret); 1160589c3563SJarkko Nikula return ret; 1161589c3563SJarkko Nikula } 1162589c3563SJarkko Nikula codec->name_prefix = temp; 1163589c3563SJarkko Nikula 1164589c3563SJarkko Nikula /* register the rtd device */ 1165589c3563SJarkko Nikula rtd->codec = codec; 116636ae1a96SMark Brown 116736ae1a96SMark Brown rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 116836ae1a96SMark Brown if (!rtd->dev) 116936ae1a96SMark Brown return -ENOMEM; 117036ae1a96SMark Brown device_initialize(rtd->dev); 117136ae1a96SMark Brown rtd->dev->parent = card->dev; 117236ae1a96SMark Brown rtd->dev->release = rtd_release; 117336ae1a96SMark Brown rtd->dev->init_name = name; 117436ae1a96SMark Brown dev_set_drvdata(rtd->dev, rtd); 1175b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 117636ae1a96SMark Brown ret = device_add(rtd->dev); 1177589c3563SJarkko Nikula if (ret < 0) { 1178589c3563SJarkko Nikula dev_err(card->dev, 1179589c3563SJarkko Nikula "asoc: failed to register runtime device: %d\n", ret); 1180589c3563SJarkko Nikula return ret; 1181589c3563SJarkko Nikula } 1182589c3563SJarkko Nikula rtd->dev_registered = 1; 1183589c3563SJarkko Nikula 1184589c3563SJarkko Nikula /* add DAPM sysfs entries for this codec */ 118536ae1a96SMark Brown ret = snd_soc_dapm_sys_add(rtd->dev); 1186589c3563SJarkko Nikula if (ret < 0) 1187589c3563SJarkko Nikula dev_err(codec->dev, 1188589c3563SJarkko Nikula "asoc: failed to add codec dapm sysfs entries: %d\n", 1189589c3563SJarkko Nikula ret); 1190589c3563SJarkko Nikula 1191589c3563SJarkko Nikula /* add codec sysfs entries */ 119236ae1a96SMark Brown ret = device_create_file(rtd->dev, &dev_attr_codec_reg); 1193589c3563SJarkko Nikula if (ret < 0) 1194589c3563SJarkko Nikula dev_err(codec->dev, 1195589c3563SJarkko Nikula "asoc: failed to add codec sysfs files: %d\n", ret); 1196589c3563SJarkko Nikula 1197589c3563SJarkko Nikula return 0; 1198589c3563SJarkko Nikula } 1199589c3563SJarkko Nikula 12000168bf0dSLiam Girdwood static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) 1201f0fba2adSLiam Girdwood { 1202f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1203f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1204f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 1205f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 1206f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1207f0fba2adSLiam Girdwood int ret; 1208f0fba2adSLiam Girdwood 12090168bf0dSLiam Girdwood dev_dbg(card->dev, "probe %s dai link %d late %d\n", 12100168bf0dSLiam Girdwood card->name, num, order); 1211f0fba2adSLiam Girdwood 1212f0fba2adSLiam Girdwood /* config components */ 1213f0fba2adSLiam Girdwood codec_dai->codec = codec; 1214f0fba2adSLiam Girdwood cpu_dai->platform = platform; 1215f0fba2adSLiam Girdwood codec_dai->card = card; 1216f0fba2adSLiam Girdwood cpu_dai->card = card; 1217f0fba2adSLiam Girdwood 1218f0fba2adSLiam Girdwood /* set default power off timeout */ 1219f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1220f0fba2adSLiam Girdwood 1221f0fba2adSLiam Girdwood /* probe the cpu_dai */ 12220168bf0dSLiam Girdwood if (!cpu_dai->probed && 12230168bf0dSLiam Girdwood cpu_dai->driver->probe_order == order) { 122461b61e3cSLiam Girdwood if (!try_module_get(cpu_dai->dev->driver->owner)) 122561b61e3cSLiam Girdwood return -ENODEV; 122661b61e3cSLiam Girdwood 1227f0fba2adSLiam Girdwood if (cpu_dai->driver->probe) { 1228f0fba2adSLiam Girdwood ret = cpu_dai->driver->probe(cpu_dai); 1229f0fba2adSLiam Girdwood if (ret < 0) { 12300837fc62SFabio Estevam pr_err("asoc: failed to probe CPU DAI %s: %d\n", 12310837fc62SFabio Estevam cpu_dai->name, ret); 123261b61e3cSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 1233f0fba2adSLiam Girdwood return ret; 1234f0fba2adSLiam Girdwood } 1235f0fba2adSLiam Girdwood } 1236f0fba2adSLiam Girdwood cpu_dai->probed = 1; 12371c8371d6SWolfram Sang /* mark cpu_dai as probed and add to card dai list */ 1238f0fba2adSLiam Girdwood list_add(&cpu_dai->card_list, &card->dai_dev_list); 1239f0fba2adSLiam Girdwood } 1240f0fba2adSLiam Girdwood 1241f0fba2adSLiam Girdwood /* probe the CODEC */ 12420168bf0dSLiam Girdwood if (!codec->probed && 12430168bf0dSLiam Girdwood codec->driver->probe_order == order) { 1244589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 1245589c3563SJarkko Nikula if (ret < 0) 1246f0fba2adSLiam Girdwood return ret; 1247f0fba2adSLiam Girdwood } 1248f0fba2adSLiam Girdwood 1249f0fba2adSLiam Girdwood /* probe the platform */ 12500168bf0dSLiam Girdwood if (!platform->probed && 12510168bf0dSLiam Girdwood platform->driver->probe_order == order) { 1252956245e9SLiam Girdwood ret = soc_probe_platform(card, platform); 1253956245e9SLiam Girdwood if (ret < 0) 1254f0fba2adSLiam Girdwood return ret; 1255f0fba2adSLiam Girdwood } 1256f0fba2adSLiam Girdwood 1257f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 12580168bf0dSLiam Girdwood if (!codec_dai->probed && codec_dai->driver->probe_order == order) { 1259f0fba2adSLiam Girdwood if (codec_dai->driver->probe) { 1260f0fba2adSLiam Girdwood ret = codec_dai->driver->probe(codec_dai); 1261f0fba2adSLiam Girdwood if (ret < 0) { 12620837fc62SFabio Estevam pr_err("asoc: failed to probe CODEC DAI %s: %d\n", 12630837fc62SFabio Estevam codec_dai->name, ret); 1264f0fba2adSLiam Girdwood return ret; 1265f0fba2adSLiam Girdwood } 1266f0fba2adSLiam Girdwood } 1267f0fba2adSLiam Girdwood 12681c8371d6SWolfram Sang /* mark codec_dai as probed and add to card dai list */ 1269f0fba2adSLiam Girdwood codec_dai->probed = 1; 1270f0fba2adSLiam Girdwood list_add(&codec_dai->card_list, &card->dai_dev_list); 1271f0fba2adSLiam Girdwood } 1272f0fba2adSLiam Girdwood 12730168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 12740168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 12750168bf0dSLiam Girdwood return 0; 12760168bf0dSLiam Girdwood 1277589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 0); 1278589c3563SJarkko Nikula if (ret) 1279f0fba2adSLiam Girdwood return ret; 1280f0fba2adSLiam Girdwood 128136ae1a96SMark Brown ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); 1282f0fba2adSLiam Girdwood if (ret < 0) 12830837fc62SFabio Estevam pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret); 1284f0fba2adSLiam Girdwood 1285f0fba2adSLiam Girdwood /* create the pcm */ 1286f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1287f0fba2adSLiam Girdwood if (ret < 0) { 12880837fc62SFabio Estevam pr_err("asoc: can't create pcm %s :%d\n", 12890837fc62SFabio Estevam dai_link->stream_name, ret); 1290f0fba2adSLiam Girdwood return ret; 1291f0fba2adSLiam Girdwood } 1292f0fba2adSLiam Girdwood 1293f0fba2adSLiam Girdwood /* add platform data for AC97 devices */ 1294f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control) 1295f0fba2adSLiam Girdwood snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); 1296f0fba2adSLiam Girdwood 1297f0fba2adSLiam Girdwood return 0; 1298f0fba2adSLiam Girdwood } 1299f0fba2adSLiam Girdwood 1300f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1301f0fba2adSLiam Girdwood static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) 1302f0fba2adSLiam Girdwood { 1303f0fba2adSLiam Girdwood int ret; 1304f0fba2adSLiam Girdwood 1305f0fba2adSLiam Girdwood /* Only instantiate AC97 if not already done by the adaptor 1306f0fba2adSLiam Girdwood * for the generic AC97 subsystem. 13076b05eda6SMark Brown */ 1308f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { 13090562f788SMika Westerberg /* 13100562f788SMika Westerberg * It is possible that the AC97 device is already registered to 13110562f788SMika Westerberg * the device subsystem. This happens when the device is created 13120562f788SMika Westerberg * via snd_ac97_mixer(). Currently only SoC codec that does so 13130562f788SMika Westerberg * is the generic AC97 glue but others migh emerge. 13140562f788SMika Westerberg * 13150562f788SMika Westerberg * In those cases we don't try to register the device again. 13160562f788SMika Westerberg */ 13170562f788SMika Westerberg if (!rtd->codec->ac97_created) 13180562f788SMika Westerberg return 0; 1319f0fba2adSLiam Girdwood 1320f0fba2adSLiam Girdwood ret = soc_ac97_dev_register(rtd->codec); 1321f0fba2adSLiam Girdwood if (ret < 0) { 13220837fc62SFabio Estevam pr_err("asoc: AC97 device register failed:%d\n", ret); 1323f0fba2adSLiam Girdwood return ret; 1324435c5e25SMark Brown } 1325435c5e25SMark Brown 1326f0fba2adSLiam Girdwood rtd->codec->ac97_registered = 1; 1327f0fba2adSLiam Girdwood } 1328f0fba2adSLiam Girdwood return 0; 1329f0fba2adSLiam Girdwood } 1330435c5e25SMark Brown 1331f0fba2adSLiam Girdwood static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) 1332f0fba2adSLiam Girdwood { 1333f0fba2adSLiam Girdwood if (codec->ac97_registered) { 1334f0fba2adSLiam Girdwood soc_ac97_dev_unregister(codec); 1335f0fba2adSLiam Girdwood codec->ac97_registered = 0; 1336f0fba2adSLiam Girdwood } 1337f0fba2adSLiam Girdwood } 1338f0fba2adSLiam Girdwood #endif 1339435c5e25SMark Brown 13402eea392dSJarkko Nikula static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 13412eea392dSJarkko Nikula { 13422eea392dSJarkko Nikula struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 13432eea392dSJarkko Nikula struct snd_soc_codec *codec; 1344676ad98aSJarkko Nikula int ret = -ENODEV; 13452eea392dSJarkko Nikula 13462eea392dSJarkko Nikula /* find CODEC from registered CODECs*/ 13472eea392dSJarkko Nikula list_for_each_entry(codec, &codec_list, list) { 13482eea392dSJarkko Nikula if (!strcmp(codec->name, aux_dev->codec_name)) { 13492eea392dSJarkko Nikula if (codec->probed) { 13502eea392dSJarkko Nikula dev_err(codec->dev, 13512eea392dSJarkko Nikula "asoc: codec already probed"); 13522eea392dSJarkko Nikula ret = -EBUSY; 13532eea392dSJarkko Nikula goto out; 13542eea392dSJarkko Nikula } 1355676ad98aSJarkko Nikula goto found; 13562eea392dSJarkko Nikula } 13572eea392dSJarkko Nikula } 1358676ad98aSJarkko Nikula /* codec not found */ 1359676ad98aSJarkko Nikula dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); 1360676ad98aSJarkko Nikula goto out; 13612eea392dSJarkko Nikula 1362676ad98aSJarkko Nikula found: 1363589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 13642eea392dSJarkko Nikula if (ret < 0) 1365589c3563SJarkko Nikula return ret; 13662eea392dSJarkko Nikula 1367589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 1); 13682eea392dSJarkko Nikula 13692eea392dSJarkko Nikula out: 13702eea392dSJarkko Nikula return ret; 13712eea392dSJarkko Nikula } 13722eea392dSJarkko Nikula 13732eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 13742eea392dSJarkko Nikula { 13752eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 13762eea392dSJarkko Nikula struct snd_soc_codec *codec = rtd->codec; 13772eea392dSJarkko Nikula 13782eea392dSJarkko Nikula /* unregister the rtd device */ 13792eea392dSJarkko Nikula if (rtd->dev_registered) { 138036ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_codec_reg); 138136ae1a96SMark Brown device_del(rtd->dev); 13822eea392dSJarkko Nikula rtd->dev_registered = 0; 13832eea392dSJarkko Nikula } 13842eea392dSJarkko Nikula 1385589c3563SJarkko Nikula if (codec && codec->probed) 1386589c3563SJarkko Nikula soc_remove_codec(codec); 13872eea392dSJarkko Nikula } 13882eea392dSJarkko Nikula 1389fdf0f54dSDimitris Papastamos static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, 1390fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type) 1391fdf0f54dSDimitris Papastamos { 1392fdf0f54dSDimitris Papastamos int ret; 1393fdf0f54dSDimitris Papastamos 1394fdf0f54dSDimitris Papastamos if (codec->cache_init) 1395fdf0f54dSDimitris Papastamos return 0; 1396fdf0f54dSDimitris Papastamos 1397fdf0f54dSDimitris Papastamos /* override the compress_type if necessary */ 1398fdf0f54dSDimitris Papastamos if (compress_type && codec->compress_type != compress_type) 1399fdf0f54dSDimitris Papastamos codec->compress_type = compress_type; 1400fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1401fdf0f54dSDimitris Papastamos if (ret < 0) { 1402fdf0f54dSDimitris Papastamos dev_err(codec->dev, "Failed to set cache compression type: %d\n", 1403fdf0f54dSDimitris Papastamos ret); 1404fdf0f54dSDimitris Papastamos return ret; 1405fdf0f54dSDimitris Papastamos } 1406fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1407fdf0f54dSDimitris Papastamos return 0; 1408fdf0f54dSDimitris Papastamos } 1409fdf0f54dSDimitris Papastamos 1410f0fba2adSLiam Girdwood static void snd_soc_instantiate_card(struct snd_soc_card *card) 1411f0fba2adSLiam Girdwood { 1412fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1413fdf0f54dSDimitris Papastamos struct snd_soc_codec_conf *codec_conf; 1414fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type; 141575d9ac46SMark Brown struct snd_soc_dai_link *dai_link; 14160168bf0dSLiam Girdwood int ret, i, order; 141796dd3622SMark Brown 1418f0fba2adSLiam Girdwood mutex_lock(&card->mutex); 1419f0fba2adSLiam Girdwood 1420f0fba2adSLiam Girdwood if (card->instantiated) { 1421f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1422435c5e25SMark Brown return; 1423db2a4165SFrank Mandarino } 1424db2a4165SFrank Mandarino 1425f0fba2adSLiam Girdwood /* bind DAIs */ 1426f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 1427f0fba2adSLiam Girdwood soc_bind_dai_link(card, i); 1428f0fba2adSLiam Girdwood 1429f0fba2adSLiam Girdwood /* bind completed ? */ 1430f0fba2adSLiam Girdwood if (card->num_rtd != card->num_links) { 1431f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1432f0fba2adSLiam Girdwood return; 1433db2a4165SFrank Mandarino } 1434db2a4165SFrank Mandarino 1435fdf0f54dSDimitris Papastamos /* initialize the register cache for each available codec */ 1436fdf0f54dSDimitris Papastamos list_for_each_entry(codec, &codec_list, list) { 1437fdf0f54dSDimitris Papastamos if (codec->cache_init) 1438fdf0f54dSDimitris Papastamos continue; 1439861f2fafSDimitris Papastamos /* by default we don't override the compress_type */ 1440861f2fafSDimitris Papastamos compress_type = 0; 1441fdf0f54dSDimitris Papastamos /* check to see if we need to override the compress_type */ 1442fdf0f54dSDimitris Papastamos for (i = 0; i < card->num_configs; ++i) { 1443fdf0f54dSDimitris Papastamos codec_conf = &card->codec_conf[i]; 1444fdf0f54dSDimitris Papastamos if (!strcmp(codec->name, codec_conf->dev_name)) { 1445fdf0f54dSDimitris Papastamos compress_type = codec_conf->compress_type; 1446fdf0f54dSDimitris Papastamos if (compress_type && compress_type 1447fdf0f54dSDimitris Papastamos != codec->compress_type) 1448fdf0f54dSDimitris Papastamos break; 1449fdf0f54dSDimitris Papastamos } 1450fdf0f54dSDimitris Papastamos } 1451fdf0f54dSDimitris Papastamos ret = snd_soc_init_codec_cache(codec, compress_type); 1452fdf0f54dSDimitris Papastamos if (ret < 0) { 1453fdf0f54dSDimitris Papastamos mutex_unlock(&card->mutex); 1454fdf0f54dSDimitris Papastamos return; 1455fdf0f54dSDimitris Papastamos } 1456fdf0f54dSDimitris Papastamos } 1457fdf0f54dSDimitris Papastamos 1458f0fba2adSLiam Girdwood /* card bind complete so register a sound card */ 1459f0fba2adSLiam Girdwood ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1460f0fba2adSLiam Girdwood card->owner, 0, &card->snd_card); 1461f0fba2adSLiam Girdwood if (ret < 0) { 14620837fc62SFabio Estevam pr_err("asoc: can't create sound card for card %s: %d\n", 14630837fc62SFabio Estevam card->name, ret); 1464f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1465f0fba2adSLiam Girdwood return; 1466db2a4165SFrank Mandarino } 1467f0fba2adSLiam Girdwood card->snd_card->dev = card->dev; 1468db2a4165SFrank Mandarino 1469e37a4970SMark Brown card->dapm.bias_level = SND_SOC_BIAS_OFF; 1470e37a4970SMark Brown card->dapm.dev = card->dev; 1471e37a4970SMark Brown card->dapm.card = card; 1472e37a4970SMark Brown list_add(&card->dapm.list, &card->dapm_list); 1473e37a4970SMark Brown 1474d5d1e0beSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 1475d5d1e0beSLars-Peter Clausen snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); 1476d5d1e0beSLars-Peter Clausen #endif 1477d5d1e0beSLars-Peter Clausen 147888ee1c61SMark Brown #ifdef CONFIG_PM_SLEEP 14796ed25978SAndy Green /* deferred resume work */ 14806308419aSMark Brown INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 14811301a964SRandy Dunlap #endif 14826ed25978SAndy Green 14839a841ebbSMark Brown if (card->dapm_widgets) 14849a841ebbSMark Brown snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 14859a841ebbSMark Brown card->num_dapm_widgets); 14869a841ebbSMark Brown 1487f0fba2adSLiam Girdwood /* initialise the sound card only once */ 1488f0fba2adSLiam Girdwood if (card->probe) { 1489e7361ec4SMark Brown ret = card->probe(card); 1490f0fba2adSLiam Girdwood if (ret < 0) 1491f0fba2adSLiam Girdwood goto card_probe_error; 1492f0fba2adSLiam Girdwood } 1493f0fba2adSLiam Girdwood 14940168bf0dSLiam Girdwood /* early DAI link probe */ 14950168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 14960168bf0dSLiam Girdwood order++) { 1497fe3e78e0SMark Brown for (i = 0; i < card->num_links; i++) { 14980168bf0dSLiam Girdwood ret = soc_probe_dai_link(card, i, order); 1499fe3e78e0SMark Brown if (ret < 0) { 1500321de0d0SMark Brown pr_err("asoc: failed to instantiate card %s: %d\n", 1501321de0d0SMark Brown card->name, ret); 1502f0fba2adSLiam Girdwood goto probe_dai_err; 1503fe3e78e0SMark Brown } 1504fe3e78e0SMark Brown } 15050168bf0dSLiam Girdwood } 1506fe3e78e0SMark Brown 15072eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) { 15082eea392dSJarkko Nikula ret = soc_probe_aux_dev(card, i); 15092eea392dSJarkko Nikula if (ret < 0) { 15102eea392dSJarkko Nikula pr_err("asoc: failed to add auxiliary devices %s: %d\n", 15112eea392dSJarkko Nikula card->name, ret); 15122eea392dSJarkko Nikula goto probe_aux_dev_err; 15132eea392dSJarkko Nikula } 15142eea392dSJarkko Nikula } 15152eea392dSJarkko Nikula 1516888df395SMark Brown snd_soc_dapm_link_dai_widgets(card); 1517888df395SMark Brown 1518b7af1dafSMark Brown if (card->controls) 1519022658beSLiam Girdwood snd_soc_add_card_controls(card, card->controls, card->num_controls); 1520b7af1dafSMark Brown 1521b8ad29deSMark Brown if (card->dapm_routes) 1522b8ad29deSMark Brown snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1523b8ad29deSMark Brown card->num_dapm_routes); 1524b8ad29deSMark Brown 1525b90d2f90SMark Brown snd_soc_dapm_new_widgets(&card->dapm); 1526b90d2f90SMark Brown 152775d9ac46SMark Brown for (i = 0; i < card->num_links; i++) { 152875d9ac46SMark Brown dai_link = &card->dai_link[i]; 152975d9ac46SMark Brown 153075d9ac46SMark Brown if (dai_link->dai_fmt) { 153175d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, 153275d9ac46SMark Brown dai_link->dai_fmt); 153375d9ac46SMark Brown if (ret != 0) 153475d9ac46SMark Brown dev_warn(card->rtd[i].codec_dai->dev, 153575d9ac46SMark Brown "Failed to set DAI format: %d\n", 153675d9ac46SMark Brown ret); 153775d9ac46SMark Brown 153875d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, 153975d9ac46SMark Brown dai_link->dai_fmt); 154075d9ac46SMark Brown if (ret != 0) 154175d9ac46SMark Brown dev_warn(card->rtd[i].cpu_dai->dev, 154275d9ac46SMark Brown "Failed to set DAI format: %d\n", 154375d9ac46SMark Brown ret); 154475d9ac46SMark Brown } 154575d9ac46SMark Brown } 154675d9ac46SMark Brown 1547f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1548fe3e78e0SMark Brown "%s", card->name); 1549f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 155022de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1551f0e8ed85SMark Brown snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), 1552f0e8ed85SMark Brown "%s", card->driver_name ? card->driver_name : card->name); 1553f0e8ed85SMark Brown for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { 1554f0e8ed85SMark Brown switch (card->snd_card->driver[i]) { 1555f0e8ed85SMark Brown case '_': 1556f0e8ed85SMark Brown case '-': 1557f0e8ed85SMark Brown case '\0': 1558f0e8ed85SMark Brown break; 1559f0e8ed85SMark Brown default: 1560f0e8ed85SMark Brown if (!isalnum(card->snd_card->driver[i])) 1561f0e8ed85SMark Brown card->snd_card->driver[i] = '_'; 1562f0e8ed85SMark Brown break; 1563f0e8ed85SMark Brown } 1564f0e8ed85SMark Brown } 1565fe3e78e0SMark Brown 156628e9ad92SMark Brown if (card->late_probe) { 156728e9ad92SMark Brown ret = card->late_probe(card); 156828e9ad92SMark Brown if (ret < 0) { 156928e9ad92SMark Brown dev_err(card->dev, "%s late_probe() failed: %d\n", 157028e9ad92SMark Brown card->name, ret); 157128e9ad92SMark Brown goto probe_aux_dev_err; 157228e9ad92SMark Brown } 157328e9ad92SMark Brown } 157428e9ad92SMark Brown 15752dc00213SMark Brown snd_soc_dapm_new_widgets(&card->dapm); 15762dc00213SMark Brown 15771633281bSStephen Warren if (card->fully_routed) 1578b05d8dc1SMark Brown list_for_each_entry(codec, &card->codec_dev_list, card_list) 15791633281bSStephen Warren snd_soc_dapm_auto_nc_codec_pins(codec); 15801633281bSStephen Warren 1581f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1582fe3e78e0SMark Brown if (ret < 0) { 15830837fc62SFabio Estevam pr_err("asoc: failed to register soundcard for %s: %d\n", 15840837fc62SFabio Estevam card->name, ret); 15856b3ed785SAxel Lin goto probe_aux_dev_err; 1586fe3e78e0SMark Brown } 1587fe3e78e0SMark Brown 1588fe3e78e0SMark Brown #ifdef CONFIG_SND_SOC_AC97_BUS 1589f0fba2adSLiam Girdwood /* register any AC97 codecs */ 1590f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1591f0fba2adSLiam Girdwood ret = soc_register_ac97_dai_link(&card->rtd[i]); 1592fe3e78e0SMark Brown if (ret < 0) { 15930837fc62SFabio Estevam pr_err("asoc: failed to register AC97 %s: %d\n", 15940837fc62SFabio Estevam card->name, ret); 15956b3ed785SAxel Lin while (--i >= 0) 15967d8316dfSMark Brown soc_unregister_ac97_dai_link(card->rtd[i].codec); 15976b3ed785SAxel Lin goto probe_aux_dev_err; 1598fe3e78e0SMark Brown } 1599fe3e78e0SMark Brown } 1600fe3e78e0SMark Brown #endif 1601fe3e78e0SMark Brown 1602435c5e25SMark Brown card->instantiated = 1; 16034f4c0072SMark Brown snd_soc_dapm_sync(&card->dapm); 1604f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1605435c5e25SMark Brown return; 1606db2a4165SFrank Mandarino 16072eea392dSJarkko Nikula probe_aux_dev_err: 16082eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 16092eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 16102eea392dSJarkko Nikula 1611f0fba2adSLiam Girdwood probe_dai_err: 16120671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1613fe3e78e0SMark Brown 1614f0fba2adSLiam Girdwood card_probe_error: 161587506549SMark Brown if (card->remove) 1616e7361ec4SMark Brown card->remove(card); 1617f0fba2adSLiam Girdwood 1618f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1619f0fba2adSLiam Girdwood 1620f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1621435c5e25SMark Brown } 1622db2a4165SFrank Mandarino 1623435c5e25SMark Brown /* 1624421f91d2SUwe Kleine-König * Attempt to initialise any uninitialised cards. Must be called with 1625435c5e25SMark Brown * client_mutex. 1626435c5e25SMark Brown */ 1627435c5e25SMark Brown static void snd_soc_instantiate_cards(void) 1628435c5e25SMark Brown { 1629435c5e25SMark Brown struct snd_soc_card *card; 1630435c5e25SMark Brown list_for_each_entry(card, &card_list, list) 1631435c5e25SMark Brown snd_soc_instantiate_card(card); 1632435c5e25SMark Brown } 1633435c5e25SMark Brown 1634435c5e25SMark Brown /* probes a new socdev */ 1635435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1636435c5e25SMark Brown { 1637f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1638435c5e25SMark Brown int ret = 0; 1639435c5e25SMark Brown 164070a7ca34SVinod Koul /* 164170a7ca34SVinod Koul * no card, so machine driver should be registering card 164270a7ca34SVinod Koul * we should not be here in that case so ret error 164370a7ca34SVinod Koul */ 164470a7ca34SVinod Koul if (!card) 164570a7ca34SVinod Koul return -EINVAL; 164670a7ca34SVinod Koul 1647435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1648435c5e25SMark Brown card->dev = &pdev->dev; 1649f0fba2adSLiam Girdwood 1650435c5e25SMark Brown ret = snd_soc_register_card(card); 1651435c5e25SMark Brown if (ret != 0) { 1652435c5e25SMark Brown dev_err(&pdev->dev, "Failed to register card\n"); 1653db2a4165SFrank Mandarino return ret; 1654db2a4165SFrank Mandarino } 1655db2a4165SFrank Mandarino 1656435c5e25SMark Brown return 0; 1657435c5e25SMark Brown } 1658435c5e25SMark Brown 1659b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1660db2a4165SFrank Mandarino { 1661db2a4165SFrank Mandarino int i; 1662db2a4165SFrank Mandarino 1663f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1664f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1665f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 16665b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1667db2a4165SFrank Mandarino } 1668db2a4165SFrank Mandarino 16692eea392dSJarkko Nikula /* remove auxiliary devices */ 16702eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 16712eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 16722eea392dSJarkko Nikula 1673f0fba2adSLiam Girdwood /* remove and free each DAI */ 16740671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1675f0fba2adSLiam Girdwood 1676a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1677a6052154SJarkko Nikula 1678f0fba2adSLiam Girdwood /* remove the card */ 167987506549SMark Brown if (card->remove) 1680e7361ec4SMark Brown card->remove(card); 1681f0fba2adSLiam Girdwood 16820aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 16830aaae527SLars-Peter Clausen 1684f0fba2adSLiam Girdwood kfree(card->rtd); 1685f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1686b0e26485SVinod Koul return 0; 1687b0e26485SVinod Koul 1688b2dfa62cSGuennadi Liakhovetski } 1689b0e26485SVinod Koul 1690b0e26485SVinod Koul /* removes a socdev */ 1691b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1692b0e26485SVinod Koul { 1693b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1694b0e26485SVinod Koul 1695c5af3a2eSMark Brown snd_soc_unregister_card(card); 1696db2a4165SFrank Mandarino return 0; 1697db2a4165SFrank Mandarino } 1698db2a4165SFrank Mandarino 16996f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 170051737470SMark Brown { 17016f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1702f0fba2adSLiam Girdwood int i; 170351737470SMark Brown 170451737470SMark Brown if (!card->instantiated) 1705416356fcSMark Brown return 0; 170651737470SMark Brown 170751737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 170851737470SMark Brown * now, we're shutting down so no imminent restart. */ 1709f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1710f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 17115b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1712f0fba2adSLiam Girdwood } 171351737470SMark Brown 1714f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1715416356fcSMark Brown 1716416356fcSMark Brown return 0; 171751737470SMark Brown } 17186f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 171951737470SMark Brown 17206f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 17215aa44b13SMark Brown SET_SYSTEM_SLEEP_PM_OPS(snd_soc_suspend, snd_soc_resume) 17226f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1723416356fcSMark Brown }; 1724deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1725416356fcSMark Brown 1726db2a4165SFrank Mandarino /* ASoC platform driver */ 1727db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1728db2a4165SFrank Mandarino .driver = { 1729db2a4165SFrank Mandarino .name = "soc-audio", 17308b45a209SKay Sievers .owner = THIS_MODULE, 17316f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1732db2a4165SFrank Mandarino }, 1733db2a4165SFrank Mandarino .probe = soc_probe, 1734db2a4165SFrank Mandarino .remove = soc_remove, 1735db2a4165SFrank Mandarino }; 1736db2a4165SFrank Mandarino 1737096e49d5SMark Brown /** 1738096e49d5SMark Brown * snd_soc_codec_volatile_register: Report if a register is volatile. 1739096e49d5SMark Brown * 1740096e49d5SMark Brown * @codec: CODEC to query. 1741096e49d5SMark Brown * @reg: Register to query. 1742096e49d5SMark Brown * 1743096e49d5SMark Brown * Boolean function indiciating if a CODEC register is volatile. 1744096e49d5SMark Brown */ 1745181e055eSMark Brown int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, 1746181e055eSMark Brown unsigned int reg) 1747096e49d5SMark Brown { 17481500b7b5SDimitris Papastamos if (codec->volatile_register) 17491500b7b5SDimitris Papastamos return codec->volatile_register(codec, reg); 1750096e49d5SMark Brown else 1751096e49d5SMark Brown return 0; 1752096e49d5SMark Brown } 1753096e49d5SMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); 1754096e49d5SMark Brown 1755db2a4165SFrank Mandarino /** 1756239c9706SDimitris Papastamos * snd_soc_codec_readable_register: Report if a register is readable. 1757239c9706SDimitris Papastamos * 1758239c9706SDimitris Papastamos * @codec: CODEC to query. 1759239c9706SDimitris Papastamos * @reg: Register to query. 1760239c9706SDimitris Papastamos * 1761239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is readable. 1762239c9706SDimitris Papastamos */ 1763239c9706SDimitris Papastamos int snd_soc_codec_readable_register(struct snd_soc_codec *codec, 1764239c9706SDimitris Papastamos unsigned int reg) 1765239c9706SDimitris Papastamos { 1766239c9706SDimitris Papastamos if (codec->readable_register) 1767239c9706SDimitris Papastamos return codec->readable_register(codec, reg); 1768239c9706SDimitris Papastamos else 176963fa0a28SLars-Peter Clausen return 1; 1770239c9706SDimitris Papastamos } 1771239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); 1772239c9706SDimitris Papastamos 1773239c9706SDimitris Papastamos /** 1774239c9706SDimitris Papastamos * snd_soc_codec_writable_register: Report if a register is writable. 1775239c9706SDimitris Papastamos * 1776239c9706SDimitris Papastamos * @codec: CODEC to query. 1777239c9706SDimitris Papastamos * @reg: Register to query. 1778239c9706SDimitris Papastamos * 1779239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is writable. 1780239c9706SDimitris Papastamos */ 1781239c9706SDimitris Papastamos int snd_soc_codec_writable_register(struct snd_soc_codec *codec, 1782239c9706SDimitris Papastamos unsigned int reg) 1783239c9706SDimitris Papastamos { 1784239c9706SDimitris Papastamos if (codec->writable_register) 1785239c9706SDimitris Papastamos return codec->writable_register(codec, reg); 1786239c9706SDimitris Papastamos else 178763fa0a28SLars-Peter Clausen return 1; 1788239c9706SDimitris Papastamos } 1789239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); 1790239c9706SDimitris Papastamos 1791f1442bc1SLiam Girdwood int snd_soc_platform_read(struct snd_soc_platform *platform, 1792f1442bc1SLiam Girdwood unsigned int reg) 1793f1442bc1SLiam Girdwood { 1794f1442bc1SLiam Girdwood unsigned int ret; 1795f1442bc1SLiam Girdwood 1796f1442bc1SLiam Girdwood if (!platform->driver->read) { 1797f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no read back\n"); 1798f1442bc1SLiam Girdwood return -1; 1799f1442bc1SLiam Girdwood } 1800f1442bc1SLiam Girdwood 1801f1442bc1SLiam Girdwood ret = platform->driver->read(platform, reg); 1802f1442bc1SLiam Girdwood dev_dbg(platform->dev, "read %x => %x\n", reg, ret); 1803a82ce2aeSLiam Girdwood trace_snd_soc_preg_read(platform, reg, ret); 1804f1442bc1SLiam Girdwood 1805f1442bc1SLiam Girdwood return ret; 1806f1442bc1SLiam Girdwood } 1807f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_read); 1808f1442bc1SLiam Girdwood 1809f1442bc1SLiam Girdwood int snd_soc_platform_write(struct snd_soc_platform *platform, 1810f1442bc1SLiam Girdwood unsigned int reg, unsigned int val) 1811f1442bc1SLiam Girdwood { 1812f1442bc1SLiam Girdwood if (!platform->driver->write) { 1813f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no write back\n"); 1814f1442bc1SLiam Girdwood return -1; 1815f1442bc1SLiam Girdwood } 1816f1442bc1SLiam Girdwood 1817f1442bc1SLiam Girdwood dev_dbg(platform->dev, "write %x = %x\n", reg, val); 1818a82ce2aeSLiam Girdwood trace_snd_soc_preg_write(platform, reg, val); 1819f1442bc1SLiam Girdwood return platform->driver->write(platform, reg, val); 1820f1442bc1SLiam Girdwood } 1821f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_write); 1822f1442bc1SLiam Girdwood 1823239c9706SDimitris Papastamos /** 1824db2a4165SFrank Mandarino * snd_soc_new_ac97_codec - initailise AC97 device 1825db2a4165SFrank Mandarino * @codec: audio codec 1826db2a4165SFrank Mandarino * @ops: AC97 bus operations 1827db2a4165SFrank Mandarino * @num: AC97 codec number 1828db2a4165SFrank Mandarino * 1829db2a4165SFrank Mandarino * Initialises AC97 codec resources for use by ad-hoc devices only. 1830db2a4165SFrank Mandarino */ 1831db2a4165SFrank Mandarino int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 1832db2a4165SFrank Mandarino struct snd_ac97_bus_ops *ops, int num) 1833db2a4165SFrank Mandarino { 1834db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1835db2a4165SFrank Mandarino 1836db2a4165SFrank Mandarino codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 1837db2a4165SFrank Mandarino if (codec->ac97 == NULL) { 1838db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1839db2a4165SFrank Mandarino return -ENOMEM; 1840db2a4165SFrank Mandarino } 1841db2a4165SFrank Mandarino 1842db2a4165SFrank Mandarino codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); 1843db2a4165SFrank Mandarino if (codec->ac97->bus == NULL) { 1844db2a4165SFrank Mandarino kfree(codec->ac97); 1845db2a4165SFrank Mandarino codec->ac97 = NULL; 1846db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1847db2a4165SFrank Mandarino return -ENOMEM; 1848db2a4165SFrank Mandarino } 1849db2a4165SFrank Mandarino 1850db2a4165SFrank Mandarino codec->ac97->bus->ops = ops; 1851db2a4165SFrank Mandarino codec->ac97->num = num; 18520562f788SMika Westerberg 18530562f788SMika Westerberg /* 18540562f788SMika Westerberg * Mark the AC97 device to be created by us. This way we ensure that the 18550562f788SMika Westerberg * device will be registered with the device subsystem later on. 18560562f788SMika Westerberg */ 18570562f788SMika Westerberg codec->ac97_created = 1; 18580562f788SMika Westerberg 1859db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1860db2a4165SFrank Mandarino return 0; 1861db2a4165SFrank Mandarino } 1862db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 1863db2a4165SFrank Mandarino 1864db2a4165SFrank Mandarino /** 1865db2a4165SFrank Mandarino * snd_soc_free_ac97_codec - free AC97 codec device 1866db2a4165SFrank Mandarino * @codec: audio codec 1867db2a4165SFrank Mandarino * 1868db2a4165SFrank Mandarino * Frees AC97 codec device resources. 1869db2a4165SFrank Mandarino */ 1870db2a4165SFrank Mandarino void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 1871db2a4165SFrank Mandarino { 1872db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1873f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1874f0fba2adSLiam Girdwood soc_unregister_ac97_dai_link(codec); 1875f0fba2adSLiam Girdwood #endif 1876db2a4165SFrank Mandarino kfree(codec->ac97->bus); 1877db2a4165SFrank Mandarino kfree(codec->ac97); 1878db2a4165SFrank Mandarino codec->ac97 = NULL; 18790562f788SMika Westerberg codec->ac97_created = 0; 1880db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1881db2a4165SFrank Mandarino } 1882db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 1883db2a4165SFrank Mandarino 1884c3753707SMark Brown unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) 1885c3753707SMark Brown { 1886c3753707SMark Brown unsigned int ret; 1887c3753707SMark Brown 1888c3acec26SMark Brown ret = codec->read(codec, reg); 1889c3753707SMark Brown dev_dbg(codec->dev, "read %x => %x\n", reg, ret); 1890a8b1d34fSMark Brown trace_snd_soc_reg_read(codec, reg, ret); 1891c3753707SMark Brown 1892c3753707SMark Brown return ret; 1893c3753707SMark Brown } 1894c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_read); 1895c3753707SMark Brown 1896c3753707SMark Brown unsigned int snd_soc_write(struct snd_soc_codec *codec, 1897c3753707SMark Brown unsigned int reg, unsigned int val) 1898c3753707SMark Brown { 1899c3753707SMark Brown dev_dbg(codec->dev, "write %x = %x\n", reg, val); 1900a8b1d34fSMark Brown trace_snd_soc_reg_write(codec, reg, val); 1901c3acec26SMark Brown return codec->write(codec, reg, val); 1902c3753707SMark Brown } 1903c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_write); 1904c3753707SMark Brown 19055fb609d4SDimitris Papastamos unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, 19065fb609d4SDimitris Papastamos unsigned int reg, const void *data, size_t len) 19075fb609d4SDimitris Papastamos { 19085fb609d4SDimitris Papastamos return codec->bulk_write_raw(codec, reg, data, len); 19095fb609d4SDimitris Papastamos } 19105fb609d4SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); 19115fb609d4SDimitris Papastamos 1912db2a4165SFrank Mandarino /** 1913db2a4165SFrank Mandarino * snd_soc_update_bits - update codec register bits 1914db2a4165SFrank Mandarino * @codec: audio codec 1915db2a4165SFrank Mandarino * @reg: codec register 1916db2a4165SFrank Mandarino * @mask: register mask 1917db2a4165SFrank Mandarino * @value: new value 1918db2a4165SFrank Mandarino * 1919db2a4165SFrank Mandarino * Writes new register value. 1920db2a4165SFrank Mandarino * 1921180c329dSTimur Tabi * Returns 1 for change, 0 for no change, or negative error code. 1922db2a4165SFrank Mandarino */ 1923db2a4165SFrank Mandarino int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, 192446f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1925db2a4165SFrank Mandarino { 19268a713da8SMark Brown bool change; 192746f5822fSDaniel Ribeiro unsigned int old, new; 1928180c329dSTimur Tabi int ret; 1929db2a4165SFrank Mandarino 19308a713da8SMark Brown if (codec->using_regmap) { 19318a713da8SMark Brown ret = regmap_update_bits_check(codec->control_data, reg, 19328a713da8SMark Brown mask, value, &change); 19338a713da8SMark Brown } else { 1934180c329dSTimur Tabi ret = snd_soc_read(codec, reg); 1935180c329dSTimur Tabi if (ret < 0) 1936180c329dSTimur Tabi return ret; 1937180c329dSTimur Tabi 1938180c329dSTimur Tabi old = ret; 193978bf3c9aSMark Brown new = (old & ~mask) | (value & mask); 1940db2a4165SFrank Mandarino change = old != new; 19418a713da8SMark Brown if (change) 1942180c329dSTimur Tabi ret = snd_soc_write(codec, reg, new); 19438a713da8SMark Brown } 19448a713da8SMark Brown 1945180c329dSTimur Tabi if (ret < 0) 1946180c329dSTimur Tabi return ret; 1947db2a4165SFrank Mandarino 1948db2a4165SFrank Mandarino return change; 1949db2a4165SFrank Mandarino } 1950db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_update_bits); 1951db2a4165SFrank Mandarino 1952db2a4165SFrank Mandarino /** 19536c508c62SEero Nurkkala * snd_soc_update_bits_locked - update codec register bits 19546c508c62SEero Nurkkala * @codec: audio codec 19556c508c62SEero Nurkkala * @reg: codec register 19566c508c62SEero Nurkkala * @mask: register mask 19576c508c62SEero Nurkkala * @value: new value 19586c508c62SEero Nurkkala * 19596c508c62SEero Nurkkala * Writes new register value, and takes the codec mutex. 19606c508c62SEero Nurkkala * 19616c508c62SEero Nurkkala * Returns 1 for change else 0. 19626c508c62SEero Nurkkala */ 1963dd1b3d53SMark Brown int snd_soc_update_bits_locked(struct snd_soc_codec *codec, 19646c508c62SEero Nurkkala unsigned short reg, unsigned int mask, 19656c508c62SEero Nurkkala unsigned int value) 19666c508c62SEero Nurkkala { 19676c508c62SEero Nurkkala int change; 19686c508c62SEero Nurkkala 19696c508c62SEero Nurkkala mutex_lock(&codec->mutex); 19706c508c62SEero Nurkkala change = snd_soc_update_bits(codec, reg, mask, value); 19716c508c62SEero Nurkkala mutex_unlock(&codec->mutex); 19726c508c62SEero Nurkkala 19736c508c62SEero Nurkkala return change; 19746c508c62SEero Nurkkala } 1975dd1b3d53SMark Brown EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); 19766c508c62SEero Nurkkala 19776c508c62SEero Nurkkala /** 1978db2a4165SFrank Mandarino * snd_soc_test_bits - test register for change 1979db2a4165SFrank Mandarino * @codec: audio codec 1980db2a4165SFrank Mandarino * @reg: codec register 1981db2a4165SFrank Mandarino * @mask: register mask 1982db2a4165SFrank Mandarino * @value: new value 1983db2a4165SFrank Mandarino * 1984db2a4165SFrank Mandarino * Tests a register with a new value and checks if the new value is 1985db2a4165SFrank Mandarino * different from the old value. 1986db2a4165SFrank Mandarino * 1987db2a4165SFrank Mandarino * Returns 1 for change else 0. 1988db2a4165SFrank Mandarino */ 1989db2a4165SFrank Mandarino int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, 199046f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1991db2a4165SFrank Mandarino { 1992db2a4165SFrank Mandarino int change; 199346f5822fSDaniel Ribeiro unsigned int old, new; 1994db2a4165SFrank Mandarino 1995db2a4165SFrank Mandarino old = snd_soc_read(codec, reg); 1996db2a4165SFrank Mandarino new = (old & ~mask) | value; 1997db2a4165SFrank Mandarino change = old != new; 1998db2a4165SFrank Mandarino 1999db2a4165SFrank Mandarino return change; 2000db2a4165SFrank Mandarino } 2001db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_test_bits); 2002db2a4165SFrank Mandarino 2003db2a4165SFrank Mandarino /** 2004db2a4165SFrank Mandarino * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 2005db2a4165SFrank Mandarino * @substream: the pcm substream 2006db2a4165SFrank Mandarino * @hw: the hardware parameters 2007db2a4165SFrank Mandarino * 2008db2a4165SFrank Mandarino * Sets the substream runtime hardware parameters. 2009db2a4165SFrank Mandarino */ 2010db2a4165SFrank Mandarino int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 2011db2a4165SFrank Mandarino const struct snd_pcm_hardware *hw) 2012db2a4165SFrank Mandarino { 2013db2a4165SFrank Mandarino struct snd_pcm_runtime *runtime = substream->runtime; 2014db2a4165SFrank Mandarino runtime->hw.info = hw->info; 2015db2a4165SFrank Mandarino runtime->hw.formats = hw->formats; 2016db2a4165SFrank Mandarino runtime->hw.period_bytes_min = hw->period_bytes_min; 2017db2a4165SFrank Mandarino runtime->hw.period_bytes_max = hw->period_bytes_max; 2018db2a4165SFrank Mandarino runtime->hw.periods_min = hw->periods_min; 2019db2a4165SFrank Mandarino runtime->hw.periods_max = hw->periods_max; 2020db2a4165SFrank Mandarino runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; 2021db2a4165SFrank Mandarino runtime->hw.fifo_size = hw->fifo_size; 2022db2a4165SFrank Mandarino return 0; 2023db2a4165SFrank Mandarino } 2024db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); 2025db2a4165SFrank Mandarino 2026db2a4165SFrank Mandarino /** 2027db2a4165SFrank Mandarino * snd_soc_cnew - create new control 2028db2a4165SFrank Mandarino * @_template: control template 2029db2a4165SFrank Mandarino * @data: control private data 2030ac11a2b3SMark Brown * @long_name: control long name 2031efb7ac3fSMark Brown * @prefix: control name prefix 2032db2a4165SFrank Mandarino * 2033db2a4165SFrank Mandarino * Create a new mixer control from a template control. 2034db2a4165SFrank Mandarino * 2035db2a4165SFrank Mandarino * Returns 0 for success, else error. 2036db2a4165SFrank Mandarino */ 2037db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 20383056557fSMark Brown void *data, const char *long_name, 2039efb7ac3fSMark Brown const char *prefix) 2040db2a4165SFrank Mandarino { 2041db2a4165SFrank Mandarino struct snd_kcontrol_new template; 2042efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 2043efb7ac3fSMark Brown char *name = NULL; 2044efb7ac3fSMark Brown int name_len; 2045db2a4165SFrank Mandarino 2046db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 2047db2a4165SFrank Mandarino template.index = 0; 2048db2a4165SFrank Mandarino 2049efb7ac3fSMark Brown if (!long_name) 2050efb7ac3fSMark Brown long_name = template.name; 2051efb7ac3fSMark Brown 2052efb7ac3fSMark Brown if (prefix) { 2053efb7ac3fSMark Brown name_len = strlen(long_name) + strlen(prefix) + 2; 205457cf9d45SAxel Lin name = kmalloc(name_len, GFP_KERNEL); 2055efb7ac3fSMark Brown if (!name) 2056efb7ac3fSMark Brown return NULL; 2057efb7ac3fSMark Brown 2058efb7ac3fSMark Brown snprintf(name, name_len, "%s %s", prefix, long_name); 2059efb7ac3fSMark Brown 2060efb7ac3fSMark Brown template.name = name; 2061efb7ac3fSMark Brown } else { 2062efb7ac3fSMark Brown template.name = long_name; 2063efb7ac3fSMark Brown } 2064efb7ac3fSMark Brown 2065efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 2066efb7ac3fSMark Brown 2067efb7ac3fSMark Brown kfree(name); 2068efb7ac3fSMark Brown 2069efb7ac3fSMark Brown return kcontrol; 2070db2a4165SFrank Mandarino } 2071db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 2072db2a4165SFrank Mandarino 2073022658beSLiam Girdwood static int snd_soc_add_controls(struct snd_card *card, struct device *dev, 2074022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls, 2075022658beSLiam Girdwood const char *prefix, void *data) 2076022658beSLiam Girdwood { 2077022658beSLiam Girdwood int err, i; 2078022658beSLiam Girdwood 2079022658beSLiam Girdwood for (i = 0; i < num_controls; i++) { 2080022658beSLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 2081022658beSLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, data, 2082022658beSLiam Girdwood control->name, prefix)); 2083022658beSLiam Girdwood if (err < 0) { 2084022658beSLiam Girdwood dev_err(dev, "Failed to add %s: %d\n", control->name, err); 2085022658beSLiam Girdwood return err; 2086022658beSLiam Girdwood } 2087022658beSLiam Girdwood } 2088022658beSLiam Girdwood 2089022658beSLiam Girdwood return 0; 2090022658beSLiam Girdwood } 2091022658beSLiam Girdwood 2092db2a4165SFrank Mandarino /** 2093022658beSLiam Girdwood * snd_soc_add_codec_controls - add an array of controls to a codec. 2094022658beSLiam Girdwood * Convenience function to add a list of controls. Many codecs were 20953e8e1952SIan Molton * duplicating this code. 20963e8e1952SIan Molton * 20973e8e1952SIan Molton * @codec: codec to add controls to 20983e8e1952SIan Molton * @controls: array of controls to add 20993e8e1952SIan Molton * @num_controls: number of elements in the array 21003e8e1952SIan Molton * 21013e8e1952SIan Molton * Return 0 for success, else error. 21023e8e1952SIan Molton */ 2103022658beSLiam Girdwood int snd_soc_add_codec_controls(struct snd_soc_codec *codec, 21043e8e1952SIan Molton const struct snd_kcontrol_new *controls, int num_controls) 21053e8e1952SIan Molton { 2106f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 21073e8e1952SIan Molton 2108022658beSLiam Girdwood return snd_soc_add_controls(card, codec->dev, controls, num_controls, 2109022658beSLiam Girdwood codec->name_prefix, codec); 21103e8e1952SIan Molton } 2111022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); 21123e8e1952SIan Molton 21133e8e1952SIan Molton /** 2114a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 2115022658beSLiam Girdwood * Convenience function to add a list of controls. 2116a491a5c8SLiam Girdwood * 2117a491a5c8SLiam Girdwood * @platform: platform to add controls to 2118a491a5c8SLiam Girdwood * @controls: array of controls to add 2119a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 2120a491a5c8SLiam Girdwood * 2121a491a5c8SLiam Girdwood * Return 0 for success, else error. 2122a491a5c8SLiam Girdwood */ 2123a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 2124a491a5c8SLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2125a491a5c8SLiam Girdwood { 2126a491a5c8SLiam Girdwood struct snd_card *card = platform->card->snd_card; 2127a491a5c8SLiam Girdwood 2128022658beSLiam Girdwood return snd_soc_add_controls(card, platform->dev, controls, num_controls, 2129022658beSLiam Girdwood NULL, platform); 2130a491a5c8SLiam Girdwood } 2131a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 2132a491a5c8SLiam Girdwood 2133a491a5c8SLiam Girdwood /** 2134022658beSLiam Girdwood * snd_soc_add_card_controls - add an array of controls to a SoC card. 2135022658beSLiam Girdwood * Convenience function to add a list of controls. 2136022658beSLiam Girdwood * 2137022658beSLiam Girdwood * @soc_card: SoC card to add controls to 2138022658beSLiam Girdwood * @controls: array of controls to add 2139022658beSLiam Girdwood * @num_controls: number of elements in the array 2140022658beSLiam Girdwood * 2141022658beSLiam Girdwood * Return 0 for success, else error. 2142022658beSLiam Girdwood */ 2143022658beSLiam Girdwood int snd_soc_add_card_controls(struct snd_soc_card *soc_card, 2144022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2145022658beSLiam Girdwood { 2146022658beSLiam Girdwood struct snd_card *card = soc_card->snd_card; 2147022658beSLiam Girdwood 2148022658beSLiam Girdwood return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, 2149022658beSLiam Girdwood NULL, soc_card); 2150022658beSLiam Girdwood } 2151022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); 2152022658beSLiam Girdwood 2153022658beSLiam Girdwood /** 2154022658beSLiam Girdwood * snd_soc_add_dai_controls - add an array of controls to a DAI. 2155022658beSLiam Girdwood * Convienience function to add a list of controls. 2156022658beSLiam Girdwood * 2157022658beSLiam Girdwood * @dai: DAI to add controls to 2158022658beSLiam Girdwood * @controls: array of controls to add 2159022658beSLiam Girdwood * @num_controls: number of elements in the array 2160022658beSLiam Girdwood * 2161022658beSLiam Girdwood * Return 0 for success, else error. 2162022658beSLiam Girdwood */ 2163022658beSLiam Girdwood int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 2164022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2165022658beSLiam Girdwood { 2166022658beSLiam Girdwood struct snd_card *card = dai->card->snd_card; 2167022658beSLiam Girdwood 2168022658beSLiam Girdwood return snd_soc_add_controls(card, dai->dev, controls, num_controls, 2169022658beSLiam Girdwood NULL, dai); 2170022658beSLiam Girdwood } 2171022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); 2172022658beSLiam Girdwood 2173022658beSLiam Girdwood /** 2174db2a4165SFrank Mandarino * snd_soc_info_enum_double - enumerated double mixer info callback 2175db2a4165SFrank Mandarino * @kcontrol: mixer control 2176db2a4165SFrank Mandarino * @uinfo: control element information 2177db2a4165SFrank Mandarino * 2178db2a4165SFrank Mandarino * Callback to provide information about a double enumerated 2179db2a4165SFrank Mandarino * mixer control. 2180db2a4165SFrank Mandarino * 2181db2a4165SFrank Mandarino * Returns 0 for success. 2182db2a4165SFrank Mandarino */ 2183db2a4165SFrank Mandarino int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 2184db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2185db2a4165SFrank Mandarino { 2186db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2187db2a4165SFrank Mandarino 2188db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2189db2a4165SFrank Mandarino uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2190f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2191db2a4165SFrank Mandarino 2192f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2193f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2194db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2195db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2196db2a4165SFrank Mandarino return 0; 2197db2a4165SFrank Mandarino } 2198db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); 2199db2a4165SFrank Mandarino 2200db2a4165SFrank Mandarino /** 2201db2a4165SFrank Mandarino * snd_soc_get_enum_double - enumerated double mixer get callback 2202db2a4165SFrank Mandarino * @kcontrol: mixer control 2203ac11a2b3SMark Brown * @ucontrol: control element information 2204db2a4165SFrank Mandarino * 2205db2a4165SFrank Mandarino * Callback to get the value of a double enumerated mixer. 2206db2a4165SFrank Mandarino * 2207db2a4165SFrank Mandarino * Returns 0 for success. 2208db2a4165SFrank Mandarino */ 2209db2a4165SFrank Mandarino int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 2210db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2211db2a4165SFrank Mandarino { 2212db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2213db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 221446f5822fSDaniel Ribeiro unsigned int val, bitmask; 2215db2a4165SFrank Mandarino 2216f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2217db2a4165SFrank Mandarino ; 2218db2a4165SFrank Mandarino val = snd_soc_read(codec, e->reg); 22193ff3f64bSMark Brown ucontrol->value.enumerated.item[0] 22203ff3f64bSMark Brown = (val >> e->shift_l) & (bitmask - 1); 2221db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) 2222db2a4165SFrank Mandarino ucontrol->value.enumerated.item[1] = 2223db2a4165SFrank Mandarino (val >> e->shift_r) & (bitmask - 1); 2224db2a4165SFrank Mandarino 2225db2a4165SFrank Mandarino return 0; 2226db2a4165SFrank Mandarino } 2227db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); 2228db2a4165SFrank Mandarino 2229db2a4165SFrank Mandarino /** 2230db2a4165SFrank Mandarino * snd_soc_put_enum_double - enumerated double mixer put callback 2231db2a4165SFrank Mandarino * @kcontrol: mixer control 2232ac11a2b3SMark Brown * @ucontrol: control element information 2233db2a4165SFrank Mandarino * 2234db2a4165SFrank Mandarino * Callback to set the value of a double enumerated mixer. 2235db2a4165SFrank Mandarino * 2236db2a4165SFrank Mandarino * Returns 0 for success. 2237db2a4165SFrank Mandarino */ 2238db2a4165SFrank Mandarino int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 2239db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2240db2a4165SFrank Mandarino { 2241db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2242db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 224346f5822fSDaniel Ribeiro unsigned int val; 224446f5822fSDaniel Ribeiro unsigned int mask, bitmask; 2245db2a4165SFrank Mandarino 2246f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2247db2a4165SFrank Mandarino ; 2248f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[0] > e->max - 1) 2249db2a4165SFrank Mandarino return -EINVAL; 2250db2a4165SFrank Mandarino val = ucontrol->value.enumerated.item[0] << e->shift_l; 2251db2a4165SFrank Mandarino mask = (bitmask - 1) << e->shift_l; 2252db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) { 2253f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[1] > e->max - 1) 2254db2a4165SFrank Mandarino return -EINVAL; 2255db2a4165SFrank Mandarino val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2256db2a4165SFrank Mandarino mask |= (bitmask - 1) << e->shift_r; 2257db2a4165SFrank Mandarino } 2258db2a4165SFrank Mandarino 22596c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2260db2a4165SFrank Mandarino } 2261db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2262db2a4165SFrank Mandarino 2263db2a4165SFrank Mandarino /** 22642e72f8e3SPeter Ujfalusi * snd_soc_get_value_enum_double - semi enumerated double mixer get callback 22652e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 22662e72f8e3SPeter Ujfalusi * @ucontrol: control element information 22672e72f8e3SPeter Ujfalusi * 22682e72f8e3SPeter Ujfalusi * Callback to get the value of a double semi enumerated mixer. 22692e72f8e3SPeter Ujfalusi * 22702e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 22712e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 22722e72f8e3SPeter Ujfalusi * 22732e72f8e3SPeter Ujfalusi * Returns 0 for success. 22742e72f8e3SPeter Ujfalusi */ 22752e72f8e3SPeter Ujfalusi int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, 22762e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 22772e72f8e3SPeter Ujfalusi { 22782e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 227974155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 228046f5822fSDaniel Ribeiro unsigned int reg_val, val, mux; 22812e72f8e3SPeter Ujfalusi 22822e72f8e3SPeter Ujfalusi reg_val = snd_soc_read(codec, e->reg); 22832e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_l) & e->mask; 22842e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 22852e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 22862e72f8e3SPeter Ujfalusi break; 22872e72f8e3SPeter Ujfalusi } 22882e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[0] = mux; 22892e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 22902e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_r) & e->mask; 22912e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 22922e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 22932e72f8e3SPeter Ujfalusi break; 22942e72f8e3SPeter Ujfalusi } 22952e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[1] = mux; 22962e72f8e3SPeter Ujfalusi } 22972e72f8e3SPeter Ujfalusi 22982e72f8e3SPeter Ujfalusi return 0; 22992e72f8e3SPeter Ujfalusi } 23002e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); 23012e72f8e3SPeter Ujfalusi 23022e72f8e3SPeter Ujfalusi /** 23032e72f8e3SPeter Ujfalusi * snd_soc_put_value_enum_double - semi enumerated double mixer put callback 23042e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 23052e72f8e3SPeter Ujfalusi * @ucontrol: control element information 23062e72f8e3SPeter Ujfalusi * 23072e72f8e3SPeter Ujfalusi * Callback to set the value of a double semi enumerated mixer. 23082e72f8e3SPeter Ujfalusi * 23092e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 23102e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 23112e72f8e3SPeter Ujfalusi * 23122e72f8e3SPeter Ujfalusi * Returns 0 for success. 23132e72f8e3SPeter Ujfalusi */ 23142e72f8e3SPeter Ujfalusi int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, 23152e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 23162e72f8e3SPeter Ujfalusi { 23172e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 231874155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 231946f5822fSDaniel Ribeiro unsigned int val; 232046f5822fSDaniel Ribeiro unsigned int mask; 23212e72f8e3SPeter Ujfalusi 23222e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[0] > e->max - 1) 23232e72f8e3SPeter Ujfalusi return -EINVAL; 23242e72f8e3SPeter Ujfalusi val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 23252e72f8e3SPeter Ujfalusi mask = e->mask << e->shift_l; 23262e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 23272e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[1] > e->max - 1) 23282e72f8e3SPeter Ujfalusi return -EINVAL; 23292e72f8e3SPeter Ujfalusi val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 23302e72f8e3SPeter Ujfalusi mask |= e->mask << e->shift_r; 23312e72f8e3SPeter Ujfalusi } 23322e72f8e3SPeter Ujfalusi 23336c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 23342e72f8e3SPeter Ujfalusi } 23352e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); 23362e72f8e3SPeter Ujfalusi 23372e72f8e3SPeter Ujfalusi /** 2338db2a4165SFrank Mandarino * snd_soc_info_enum_ext - external enumerated single mixer info callback 2339db2a4165SFrank Mandarino * @kcontrol: mixer control 2340db2a4165SFrank Mandarino * @uinfo: control element information 2341db2a4165SFrank Mandarino * 2342db2a4165SFrank Mandarino * Callback to provide information about an external enumerated 2343db2a4165SFrank Mandarino * single mixer. 2344db2a4165SFrank Mandarino * 2345db2a4165SFrank Mandarino * Returns 0 for success. 2346db2a4165SFrank Mandarino */ 2347db2a4165SFrank Mandarino int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, 2348db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2349db2a4165SFrank Mandarino { 2350db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2351db2a4165SFrank Mandarino 2352db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2353db2a4165SFrank Mandarino uinfo->count = 1; 2354f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2355db2a4165SFrank Mandarino 2356f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2357f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2358db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2359db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2360db2a4165SFrank Mandarino return 0; 2361db2a4165SFrank Mandarino } 2362db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); 2363db2a4165SFrank Mandarino 2364db2a4165SFrank Mandarino /** 2365db2a4165SFrank Mandarino * snd_soc_info_volsw_ext - external single mixer info callback 2366db2a4165SFrank Mandarino * @kcontrol: mixer control 2367db2a4165SFrank Mandarino * @uinfo: control element information 2368db2a4165SFrank Mandarino * 2369db2a4165SFrank Mandarino * Callback to provide information about a single external mixer control. 2370db2a4165SFrank Mandarino * 2371db2a4165SFrank Mandarino * Returns 0 for success. 2372db2a4165SFrank Mandarino */ 2373db2a4165SFrank Mandarino int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, 2374db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2375db2a4165SFrank Mandarino { 2376a7a4ac86SPhilipp Zabel int max = kcontrol->private_value; 2377db2a4165SFrank Mandarino 2378fd5dfad9SMark Brown if (max == 1 && !strstr(kcontrol->id.name, " Volume")) 2379a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2380a7a4ac86SPhilipp Zabel else 2381a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2382a7a4ac86SPhilipp Zabel 2383db2a4165SFrank Mandarino uinfo->count = 1; 2384db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2385a7a4ac86SPhilipp Zabel uinfo->value.integer.max = max; 2386db2a4165SFrank Mandarino return 0; 2387db2a4165SFrank Mandarino } 2388db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); 2389db2a4165SFrank Mandarino 2390db2a4165SFrank Mandarino /** 2391db2a4165SFrank Mandarino * snd_soc_info_volsw - single mixer info callback 2392db2a4165SFrank Mandarino * @kcontrol: mixer control 2393db2a4165SFrank Mandarino * @uinfo: control element information 2394db2a4165SFrank Mandarino * 2395e8f5a103SPeter Ujfalusi * Callback to provide information about a single mixer control, or a double 2396e8f5a103SPeter Ujfalusi * mixer control that spans 2 registers. 2397db2a4165SFrank Mandarino * 2398db2a4165SFrank Mandarino * Returns 0 for success. 2399db2a4165SFrank Mandarino */ 2400db2a4165SFrank Mandarino int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 2401db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2402db2a4165SFrank Mandarino { 24034eaa9819SJon Smirl struct soc_mixer_control *mc = 24044eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2405d11bb4a9SPeter Ujfalusi int platform_max; 2406db2a4165SFrank Mandarino 2407d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2408d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2409d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2410d11bb4a9SPeter Ujfalusi 2411d11bb4a9SPeter Ujfalusi if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) 2412a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2413a7a4ac86SPhilipp Zabel else 2414a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2415a7a4ac86SPhilipp Zabel 2416e8f5a103SPeter Ujfalusi uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; 2417db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2418d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max; 2419db2a4165SFrank Mandarino return 0; 2420db2a4165SFrank Mandarino } 2421db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw); 2422db2a4165SFrank Mandarino 2423db2a4165SFrank Mandarino /** 2424db2a4165SFrank Mandarino * snd_soc_get_volsw - single mixer get callback 2425db2a4165SFrank Mandarino * @kcontrol: mixer control 2426ac11a2b3SMark Brown * @ucontrol: control element information 2427db2a4165SFrank Mandarino * 2428f7915d99SPeter Ujfalusi * Callback to get the value of a single mixer control, or a double mixer 2429f7915d99SPeter Ujfalusi * control that spans 2 registers. 2430db2a4165SFrank Mandarino * 2431db2a4165SFrank Mandarino * Returns 0 for success. 2432db2a4165SFrank Mandarino */ 2433db2a4165SFrank Mandarino int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 2434db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2435db2a4165SFrank Mandarino { 24364eaa9819SJon Smirl struct soc_mixer_control *mc = 24374eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2438db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2439815ecf8dSJon Smirl unsigned int reg = mc->reg; 2440f7915d99SPeter Ujfalusi unsigned int reg2 = mc->rreg; 2441815ecf8dSJon Smirl unsigned int shift = mc->shift; 2442815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 24434eaa9819SJon Smirl int max = mc->max; 2444815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2445815ecf8dSJon Smirl unsigned int invert = mc->invert; 2446db2a4165SFrank Mandarino 2447db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2448db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> shift) & mask; 2449f7915d99SPeter Ujfalusi if (invert) 2450db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2451a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[0]; 2452f7915d99SPeter Ujfalusi 2453f7915d99SPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2454f7915d99SPeter Ujfalusi if (reg == reg2) 2455f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2456f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg) >> rshift) & mask; 2457f7915d99SPeter Ujfalusi else 2458f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2459f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg2) >> shift) & mask; 2460f7915d99SPeter Ujfalusi if (invert) 2461db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2462a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[1]; 2463db2a4165SFrank Mandarino } 2464db2a4165SFrank Mandarino 2465db2a4165SFrank Mandarino return 0; 2466db2a4165SFrank Mandarino } 2467db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw); 2468db2a4165SFrank Mandarino 2469db2a4165SFrank Mandarino /** 2470db2a4165SFrank Mandarino * snd_soc_put_volsw - single mixer put callback 2471db2a4165SFrank Mandarino * @kcontrol: mixer control 2472ac11a2b3SMark Brown * @ucontrol: control element information 2473db2a4165SFrank Mandarino * 2474974815baSPeter Ujfalusi * Callback to set the value of a single mixer control, or a double mixer 2475974815baSPeter Ujfalusi * control that spans 2 registers. 2476db2a4165SFrank Mandarino * 2477db2a4165SFrank Mandarino * Returns 0 for success. 2478db2a4165SFrank Mandarino */ 2479db2a4165SFrank Mandarino int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 2480db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2481db2a4165SFrank Mandarino { 24824eaa9819SJon Smirl struct soc_mixer_control *mc = 24834eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2484db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2485815ecf8dSJon Smirl unsigned int reg = mc->reg; 2486974815baSPeter Ujfalusi unsigned int reg2 = mc->rreg; 2487815ecf8dSJon Smirl unsigned int shift = mc->shift; 2488815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 24894eaa9819SJon Smirl int max = mc->max; 2490815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2491815ecf8dSJon Smirl unsigned int invert = mc->invert; 2492974815baSPeter Ujfalusi int err; 2493974815baSPeter Ujfalusi bool type_2r = 0; 2494974815baSPeter Ujfalusi unsigned int val2 = 0; 2495974815baSPeter Ujfalusi unsigned int val, val_mask; 2496db2a4165SFrank Mandarino 2497db2a4165SFrank Mandarino val = (ucontrol->value.integer.value[0] & mask); 2498db2a4165SFrank Mandarino if (invert) 2499a7a4ac86SPhilipp Zabel val = max - val; 2500db2a4165SFrank Mandarino val_mask = mask << shift; 2501db2a4165SFrank Mandarino val = val << shift; 2502974815baSPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2503db2a4165SFrank Mandarino val2 = (ucontrol->value.integer.value[1] & mask); 2504db2a4165SFrank Mandarino if (invert) 2505a7a4ac86SPhilipp Zabel val2 = max - val2; 2506974815baSPeter Ujfalusi if (reg == reg2) { 2507db2a4165SFrank Mandarino val_mask |= mask << rshift; 2508db2a4165SFrank Mandarino val |= val2 << rshift; 2509974815baSPeter Ujfalusi } else { 2510db2a4165SFrank Mandarino val2 = val2 << shift; 2511974815baSPeter Ujfalusi type_2r = 1; 2512974815baSPeter Ujfalusi } 2513974815baSPeter Ujfalusi } 25146c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 25153ff3f64bSMark Brown if (err < 0) 2516db2a4165SFrank Mandarino return err; 2517db2a4165SFrank Mandarino 2518974815baSPeter Ujfalusi if (type_2r) 25196c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); 2520974815baSPeter Ujfalusi 2521db2a4165SFrank Mandarino return err; 2522db2a4165SFrank Mandarino } 2523974815baSPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 2524db2a4165SFrank Mandarino 2525e13ac2e9SMark Brown /** 2526e13ac2e9SMark Brown * snd_soc_info_volsw_s8 - signed mixer info callback 2527e13ac2e9SMark Brown * @kcontrol: mixer control 2528e13ac2e9SMark Brown * @uinfo: control element information 2529e13ac2e9SMark Brown * 2530e13ac2e9SMark Brown * Callback to provide information about a signed mixer control. 2531e13ac2e9SMark Brown * 2532e13ac2e9SMark Brown * Returns 0 for success. 2533e13ac2e9SMark Brown */ 2534e13ac2e9SMark Brown int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, 2535e13ac2e9SMark Brown struct snd_ctl_elem_info *uinfo) 2536e13ac2e9SMark Brown { 25374eaa9819SJon Smirl struct soc_mixer_control *mc = 25384eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2539d11bb4a9SPeter Ujfalusi int platform_max; 25404eaa9819SJon Smirl int min = mc->min; 2541e13ac2e9SMark Brown 2542d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2543d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2544d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2545d11bb4a9SPeter Ujfalusi 2546e13ac2e9SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2547e13ac2e9SMark Brown uinfo->count = 2; 2548e13ac2e9SMark Brown uinfo->value.integer.min = 0; 2549d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max - min; 2550e13ac2e9SMark Brown return 0; 2551e13ac2e9SMark Brown } 2552e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); 2553e13ac2e9SMark Brown 2554e13ac2e9SMark Brown /** 2555e13ac2e9SMark Brown * snd_soc_get_volsw_s8 - signed mixer get callback 2556e13ac2e9SMark Brown * @kcontrol: mixer control 2557ac11a2b3SMark Brown * @ucontrol: control element information 2558e13ac2e9SMark Brown * 2559e13ac2e9SMark Brown * Callback to get the value of a signed mixer control. 2560e13ac2e9SMark Brown * 2561e13ac2e9SMark Brown * Returns 0 for success. 2562e13ac2e9SMark Brown */ 2563e13ac2e9SMark Brown int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, 2564e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2565e13ac2e9SMark Brown { 25664eaa9819SJon Smirl struct soc_mixer_control *mc = 25674eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2568e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2569815ecf8dSJon Smirl unsigned int reg = mc->reg; 25704eaa9819SJon Smirl int min = mc->min; 2571e13ac2e9SMark Brown int val = snd_soc_read(codec, reg); 2572e13ac2e9SMark Brown 2573e13ac2e9SMark Brown ucontrol->value.integer.value[0] = 2574e13ac2e9SMark Brown ((signed char)(val & 0xff))-min; 2575e13ac2e9SMark Brown ucontrol->value.integer.value[1] = 2576e13ac2e9SMark Brown ((signed char)((val >> 8) & 0xff))-min; 2577e13ac2e9SMark Brown return 0; 2578e13ac2e9SMark Brown } 2579e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); 2580e13ac2e9SMark Brown 2581e13ac2e9SMark Brown /** 2582e13ac2e9SMark Brown * snd_soc_put_volsw_sgn - signed mixer put callback 2583e13ac2e9SMark Brown * @kcontrol: mixer control 2584ac11a2b3SMark Brown * @ucontrol: control element information 2585e13ac2e9SMark Brown * 2586e13ac2e9SMark Brown * Callback to set the value of a signed mixer control. 2587e13ac2e9SMark Brown * 2588e13ac2e9SMark Brown * Returns 0 for success. 2589e13ac2e9SMark Brown */ 2590e13ac2e9SMark Brown int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, 2591e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2592e13ac2e9SMark Brown { 25934eaa9819SJon Smirl struct soc_mixer_control *mc = 25944eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2595e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2596815ecf8dSJon Smirl unsigned int reg = mc->reg; 25974eaa9819SJon Smirl int min = mc->min; 259846f5822fSDaniel Ribeiro unsigned int val; 2599e13ac2e9SMark Brown 2600e13ac2e9SMark Brown val = (ucontrol->value.integer.value[0]+min) & 0xff; 2601e13ac2e9SMark Brown val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2602e13ac2e9SMark Brown 26036c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, reg, 0xffff, val); 2604e13ac2e9SMark Brown } 2605e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2606e13ac2e9SMark Brown 26078c6529dbSLiam Girdwood /** 2608637d3847SPeter Ujfalusi * snd_soc_limit_volume - Set new limit to an existing volume control. 2609637d3847SPeter Ujfalusi * 2610637d3847SPeter Ujfalusi * @codec: where to look for the control 2611637d3847SPeter Ujfalusi * @name: Name of the control 2612637d3847SPeter Ujfalusi * @max: new maximum limit 2613637d3847SPeter Ujfalusi * 2614637d3847SPeter Ujfalusi * Return 0 for success, else error. 2615637d3847SPeter Ujfalusi */ 2616637d3847SPeter Ujfalusi int snd_soc_limit_volume(struct snd_soc_codec *codec, 2617637d3847SPeter Ujfalusi const char *name, int max) 2618637d3847SPeter Ujfalusi { 2619f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 2620637d3847SPeter Ujfalusi struct snd_kcontrol *kctl; 2621637d3847SPeter Ujfalusi struct soc_mixer_control *mc; 2622637d3847SPeter Ujfalusi int found = 0; 2623637d3847SPeter Ujfalusi int ret = -EINVAL; 2624637d3847SPeter Ujfalusi 2625637d3847SPeter Ujfalusi /* Sanity check for name and max */ 2626637d3847SPeter Ujfalusi if (unlikely(!name || max <= 0)) 2627637d3847SPeter Ujfalusi return -EINVAL; 2628637d3847SPeter Ujfalusi 2629637d3847SPeter Ujfalusi list_for_each_entry(kctl, &card->controls, list) { 2630637d3847SPeter Ujfalusi if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { 2631637d3847SPeter Ujfalusi found = 1; 2632637d3847SPeter Ujfalusi break; 2633637d3847SPeter Ujfalusi } 2634637d3847SPeter Ujfalusi } 2635637d3847SPeter Ujfalusi if (found) { 2636637d3847SPeter Ujfalusi mc = (struct soc_mixer_control *)kctl->private_value; 2637637d3847SPeter Ujfalusi if (max <= mc->max) { 2638d11bb4a9SPeter Ujfalusi mc->platform_max = max; 2639637d3847SPeter Ujfalusi ret = 0; 2640637d3847SPeter Ujfalusi } 2641637d3847SPeter Ujfalusi } 2642637d3847SPeter Ujfalusi return ret; 2643637d3847SPeter Ujfalusi } 2644637d3847SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_limit_volume); 2645637d3847SPeter Ujfalusi 2646637d3847SPeter Ujfalusi /** 2647b6f4bb38Sapatard@mandriva.com * snd_soc_info_volsw_2r_sx - double with tlv and variable data size 2648b6f4bb38Sapatard@mandriva.com * mixer info callback 2649b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2650b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2651b6f4bb38Sapatard@mandriva.com * 2652b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2653b6f4bb38Sapatard@mandriva.com */ 2654b6f4bb38Sapatard@mandriva.com int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2655b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_info *uinfo) 2656b6f4bb38Sapatard@mandriva.com { 2657b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2658b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2659b6f4bb38Sapatard@mandriva.com int max = mc->max; 2660b6f4bb38Sapatard@mandriva.com int min = mc->min; 2661b6f4bb38Sapatard@mandriva.com 2662b6f4bb38Sapatard@mandriva.com uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2663b6f4bb38Sapatard@mandriva.com uinfo->count = 2; 2664b6f4bb38Sapatard@mandriva.com uinfo->value.integer.min = 0; 2665b6f4bb38Sapatard@mandriva.com uinfo->value.integer.max = max-min; 2666b6f4bb38Sapatard@mandriva.com 2667b6f4bb38Sapatard@mandriva.com return 0; 2668b6f4bb38Sapatard@mandriva.com } 2669b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); 2670b6f4bb38Sapatard@mandriva.com 2671b6f4bb38Sapatard@mandriva.com /** 2672b6f4bb38Sapatard@mandriva.com * snd_soc_get_volsw_2r_sx - double with tlv and variable data size 2673b6f4bb38Sapatard@mandriva.com * mixer get callback 2674b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2675b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2676b6f4bb38Sapatard@mandriva.com * 2677b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2678b6f4bb38Sapatard@mandriva.com */ 2679b6f4bb38Sapatard@mandriva.com int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2680b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2681b6f4bb38Sapatard@mandriva.com { 2682b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2683b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2684b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2685b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2686b6f4bb38Sapatard@mandriva.com int min = mc->min; 2687b6f4bb38Sapatard@mandriva.com int val = snd_soc_read(codec, mc->reg) & mask; 2688b6f4bb38Sapatard@mandriva.com int valr = snd_soc_read(codec, mc->rreg) & mask; 2689b6f4bb38Sapatard@mandriva.com 269020630c7fSStuart Longland ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; 269120630c7fSStuart Longland ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; 2692b6f4bb38Sapatard@mandriva.com return 0; 2693b6f4bb38Sapatard@mandriva.com } 2694b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); 2695b6f4bb38Sapatard@mandriva.com 2696b6f4bb38Sapatard@mandriva.com /** 2697b6f4bb38Sapatard@mandriva.com * snd_soc_put_volsw_2r_sx - double with tlv and variable data size 2698b6f4bb38Sapatard@mandriva.com * mixer put callback 2699b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2700b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2701b6f4bb38Sapatard@mandriva.com * 2702b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2703b6f4bb38Sapatard@mandriva.com */ 2704b6f4bb38Sapatard@mandriva.com int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2705b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2706b6f4bb38Sapatard@mandriva.com { 2707b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2708b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2709b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2710b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2711b6f4bb38Sapatard@mandriva.com int min = mc->min; 2712b6f4bb38Sapatard@mandriva.com int ret; 2713b6f4bb38Sapatard@mandriva.com unsigned int val, valr, oval, ovalr; 2714b6f4bb38Sapatard@mandriva.com 2715b6f4bb38Sapatard@mandriva.com val = ((ucontrol->value.integer.value[0]+min) & 0xff); 2716b6f4bb38Sapatard@mandriva.com val &= mask; 2717b6f4bb38Sapatard@mandriva.com valr = ((ucontrol->value.integer.value[1]+min) & 0xff); 2718b6f4bb38Sapatard@mandriva.com valr &= mask; 2719b6f4bb38Sapatard@mandriva.com 2720b6f4bb38Sapatard@mandriva.com oval = snd_soc_read(codec, mc->reg) & mask; 2721b6f4bb38Sapatard@mandriva.com ovalr = snd_soc_read(codec, mc->rreg) & mask; 2722b6f4bb38Sapatard@mandriva.com 2723b6f4bb38Sapatard@mandriva.com ret = 0; 2724b6f4bb38Sapatard@mandriva.com if (oval != val) { 2725b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->reg, val); 2726b6f4bb38Sapatard@mandriva.com if (ret < 0) 2727f1df5aecSMark Brown return ret; 2728b6f4bb38Sapatard@mandriva.com } 2729b6f4bb38Sapatard@mandriva.com if (ovalr != valr) { 2730b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->rreg, valr); 2731b6f4bb38Sapatard@mandriva.com if (ret < 0) 2732f1df5aecSMark Brown return ret; 2733b6f4bb38Sapatard@mandriva.com } 2734b6f4bb38Sapatard@mandriva.com 2735b6f4bb38Sapatard@mandriva.com return 0; 2736b6f4bb38Sapatard@mandriva.com } 2737b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); 2738b6f4bb38Sapatard@mandriva.com 273971d08516SMark Brown int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 274071d08516SMark Brown struct snd_ctl_elem_info *uinfo) 274171d08516SMark Brown { 274271d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 274371d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 274471d08516SMark Brown 274571d08516SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 274671d08516SMark Brown uinfo->count = params->num_regs * codec->val_bytes; 274771d08516SMark Brown 274871d08516SMark Brown return 0; 274971d08516SMark Brown } 275071d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_info); 275171d08516SMark Brown 275271d08516SMark Brown int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, 275371d08516SMark Brown struct snd_ctl_elem_value *ucontrol) 275471d08516SMark Brown { 275571d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 275671d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 275771d08516SMark Brown int ret; 275871d08516SMark Brown 275971d08516SMark Brown if (codec->using_regmap) 276071d08516SMark Brown ret = regmap_raw_read(codec->control_data, params->base, 276171d08516SMark Brown ucontrol->value.bytes.data, 276271d08516SMark Brown params->num_regs * codec->val_bytes); 276371d08516SMark Brown else 276471d08516SMark Brown ret = -EINVAL; 276571d08516SMark Brown 2766*f831b055SMark Brown /* Hide any masked bytes to ensure consistent data reporting */ 2767*f831b055SMark Brown if (ret == 0 && params->mask) { 2768*f831b055SMark Brown switch (codec->val_bytes) { 2769*f831b055SMark Brown case 1: 2770*f831b055SMark Brown ucontrol->value.bytes.data[0] &= ~params->mask; 2771*f831b055SMark Brown break; 2772*f831b055SMark Brown case 2: 2773*f831b055SMark Brown ((u16 *)(&ucontrol->value.bytes.data))[0] 2774*f831b055SMark Brown &= ~params->mask; 2775*f831b055SMark Brown break; 2776*f831b055SMark Brown case 4: 2777*f831b055SMark Brown ((u32 *)(&ucontrol->value.bytes.data))[0] 2778*f831b055SMark Brown &= ~params->mask; 2779*f831b055SMark Brown break; 2780*f831b055SMark Brown default: 2781*f831b055SMark Brown return -EINVAL; 2782*f831b055SMark Brown } 2783*f831b055SMark Brown } 2784*f831b055SMark Brown 278571d08516SMark Brown return ret; 278671d08516SMark Brown } 278771d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_get); 278871d08516SMark Brown 278971d08516SMark Brown int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, 279071d08516SMark Brown struct snd_ctl_elem_value *ucontrol) 279171d08516SMark Brown { 279271d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 279371d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2794*f831b055SMark Brown int ret, len; 2795*f831b055SMark Brown unsigned int val; 2796*f831b055SMark Brown void *data; 279771d08516SMark Brown 2798*f831b055SMark Brown if (!codec->using_regmap) 2799*f831b055SMark Brown return -EINVAL; 2800*f831b055SMark Brown 2801*f831b055SMark Brown data = ucontrol->value.bytes.data; 2802*f831b055SMark Brown len = params->num_regs * codec->val_bytes; 2803*f831b055SMark Brown 2804*f831b055SMark Brown /* 2805*f831b055SMark Brown * If we've got a mask then we need to preserve the register 2806*f831b055SMark Brown * bits. We shouldn't modify the incoming data so take a 2807*f831b055SMark Brown * copy. 2808*f831b055SMark Brown */ 2809*f831b055SMark Brown if (params->mask) { 2810*f831b055SMark Brown ret = regmap_read(codec->control_data, params->base, &val); 2811*f831b055SMark Brown if (ret != 0) 2812*f831b055SMark Brown return ret; 2813*f831b055SMark Brown 2814*f831b055SMark Brown val &= params->mask; 2815*f831b055SMark Brown 2816*f831b055SMark Brown data = kmemdup(data, len, GFP_KERNEL); 2817*f831b055SMark Brown if (!data) 2818*f831b055SMark Brown return -ENOMEM; 2819*f831b055SMark Brown 2820*f831b055SMark Brown switch (codec->val_bytes) { 2821*f831b055SMark Brown case 1: 2822*f831b055SMark Brown ((u8 *)data)[0] &= ~params->mask; 2823*f831b055SMark Brown ((u8 *)data)[0] |= val; 2824*f831b055SMark Brown break; 2825*f831b055SMark Brown case 2: 2826*f831b055SMark Brown ((u16 *)data)[0] &= cpu_to_be16(~params->mask); 2827*f831b055SMark Brown ((u16 *)data)[0] |= cpu_to_be16(val); 2828*f831b055SMark Brown break; 2829*f831b055SMark Brown case 4: 2830*f831b055SMark Brown ((u32 *)data)[0] &= cpu_to_be32(~params->mask); 2831*f831b055SMark Brown ((u32 *)data)[0] |= cpu_to_be32(val); 2832*f831b055SMark Brown break; 2833*f831b055SMark Brown default: 2834*f831b055SMark Brown return -EINVAL; 2835*f831b055SMark Brown } 2836*f831b055SMark Brown } 2837*f831b055SMark Brown 283871d08516SMark Brown ret = regmap_raw_write(codec->control_data, params->base, 2839*f831b055SMark Brown data, len); 2840*f831b055SMark Brown 2841*f831b055SMark Brown if (params->mask) 2842*f831b055SMark Brown kfree(data); 284371d08516SMark Brown 284471d08516SMark Brown return ret; 284571d08516SMark Brown } 284671d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_put); 284771d08516SMark Brown 2848b6f4bb38Sapatard@mandriva.com /** 28498c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 28508c6529dbSLiam Girdwood * @dai: DAI 28518c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 28528c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 28538c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 28548c6529dbSLiam Girdwood * 28558c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 28568c6529dbSLiam Girdwood */ 28578c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 28588c6529dbSLiam Girdwood unsigned int freq, int dir) 28598c6529dbSLiam Girdwood { 2860f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 2861f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2862ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 2863da1c6ea6SMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, 2864ec4ee52aSMark Brown freq, dir); 28658c6529dbSLiam Girdwood else 28668c6529dbSLiam Girdwood return -EINVAL; 28678c6529dbSLiam Girdwood } 28688c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 28698c6529dbSLiam Girdwood 28708c6529dbSLiam Girdwood /** 2871ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 2872ec4ee52aSMark Brown * @codec: CODEC 2873ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 2874da1c6ea6SMark Brown * @source: Source for the clock 2875ec4ee52aSMark Brown * @freq: new clock frequency in Hz 2876ec4ee52aSMark Brown * @dir: new clock direction - input/output. 2877ec4ee52aSMark Brown * 2878ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 2879ec4ee52aSMark Brown */ 2880ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 2881da1c6ea6SMark Brown int source, unsigned int freq, int dir) 2882ec4ee52aSMark Brown { 2883ec4ee52aSMark Brown if (codec->driver->set_sysclk) 2884da1c6ea6SMark Brown return codec->driver->set_sysclk(codec, clk_id, source, 2885da1c6ea6SMark Brown freq, dir); 2886ec4ee52aSMark Brown else 2887ec4ee52aSMark Brown return -EINVAL; 2888ec4ee52aSMark Brown } 2889ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 2890ec4ee52aSMark Brown 2891ec4ee52aSMark Brown /** 28928c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 28938c6529dbSLiam Girdwood * @dai: DAI 2894ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 28958c6529dbSLiam Girdwood * @div: new clock divisor. 28968c6529dbSLiam Girdwood * 28978c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 28988c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 28998c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 29008c6529dbSLiam Girdwood */ 29018c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 29028c6529dbSLiam Girdwood int div_id, int div) 29038c6529dbSLiam Girdwood { 2904f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 2905f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 29068c6529dbSLiam Girdwood else 29078c6529dbSLiam Girdwood return -EINVAL; 29088c6529dbSLiam Girdwood } 29098c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 29108c6529dbSLiam Girdwood 29118c6529dbSLiam Girdwood /** 29128c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 29138c6529dbSLiam Girdwood * @dai: DAI 29148c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 291585488037SMark Brown * @source: DAI specific source for the PLL 29168c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 29178c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 29188c6529dbSLiam Girdwood * 29198c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 29208c6529dbSLiam Girdwood */ 292185488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 292285488037SMark Brown unsigned int freq_in, unsigned int freq_out) 29238c6529dbSLiam Girdwood { 2924f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 2925f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 292685488037SMark Brown freq_in, freq_out); 2927ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 2928ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 2929ec4ee52aSMark Brown freq_in, freq_out); 29308c6529dbSLiam Girdwood else 29318c6529dbSLiam Girdwood return -EINVAL; 29328c6529dbSLiam Girdwood } 29338c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 29348c6529dbSLiam Girdwood 2935ec4ee52aSMark Brown /* 2936ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 2937ec4ee52aSMark Brown * @codec: CODEC 2938ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 2939ec4ee52aSMark Brown * @source: DAI specific source for the PLL 2940ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 2941ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 2942ec4ee52aSMark Brown * 2943ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 2944ec4ee52aSMark Brown */ 2945ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 2946ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 2947ec4ee52aSMark Brown { 2948ec4ee52aSMark Brown if (codec->driver->set_pll) 2949ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 2950ec4ee52aSMark Brown freq_in, freq_out); 2951ec4ee52aSMark Brown else 2952ec4ee52aSMark Brown return -EINVAL; 2953ec4ee52aSMark Brown } 2954ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 2955ec4ee52aSMark Brown 29568c6529dbSLiam Girdwood /** 29578c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 29588c6529dbSLiam Girdwood * @dai: DAI 29598c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 29608c6529dbSLiam Girdwood * 29618c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 29628c6529dbSLiam Girdwood */ 29638c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 29648c6529dbSLiam Girdwood { 2965f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_fmt) 2966f0fba2adSLiam Girdwood return dai->driver->ops->set_fmt(dai, fmt); 29678c6529dbSLiam Girdwood else 29688c6529dbSLiam Girdwood return -EINVAL; 29698c6529dbSLiam Girdwood } 29708c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 29718c6529dbSLiam Girdwood 29728c6529dbSLiam Girdwood /** 29738c6529dbSLiam Girdwood * snd_soc_dai_set_tdm_slot - configure DAI TDM. 29748c6529dbSLiam Girdwood * @dai: DAI 2975a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 2976a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 29778c6529dbSLiam Girdwood * @slots: Number of slots in use. 2978a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 29798c6529dbSLiam Girdwood * 29808c6529dbSLiam Girdwood * Configures a DAI for TDM operation. Both mask and slots are codec and DAI 29818c6529dbSLiam Girdwood * specific. 29828c6529dbSLiam Girdwood */ 29838c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2984a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 29858c6529dbSLiam Girdwood { 2986f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 2987f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2988a5479e38SDaniel Ribeiro slots, slot_width); 29898c6529dbSLiam Girdwood else 29908c6529dbSLiam Girdwood return -EINVAL; 29918c6529dbSLiam Girdwood } 29928c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 29938c6529dbSLiam Girdwood 29948c6529dbSLiam Girdwood /** 2995472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 2996472df3cbSBarry Song * @dai: DAI 2997472df3cbSBarry Song * @tx_num: how many TX channels 2998472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 2999472df3cbSBarry Song * 0~num-1 uses 3000472df3cbSBarry Song * @rx_num: how many RX channels 3001472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 3002472df3cbSBarry Song * 0~num-1 uses 3003472df3cbSBarry Song * 3004472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 3005472df3cbSBarry Song */ 3006472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 3007472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 3008472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 3009472df3cbSBarry Song { 3010f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 3011f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 3012472df3cbSBarry Song rx_num, rx_slot); 3013472df3cbSBarry Song else 3014472df3cbSBarry Song return -EINVAL; 3015472df3cbSBarry Song } 3016472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 3017472df3cbSBarry Song 3018472df3cbSBarry Song /** 30198c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 30208c6529dbSLiam Girdwood * @dai: DAI 30218c6529dbSLiam Girdwood * @tristate: tristate enable 30228c6529dbSLiam Girdwood * 30238c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 30248c6529dbSLiam Girdwood */ 30258c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 30268c6529dbSLiam Girdwood { 3027f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 3028f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 30298c6529dbSLiam Girdwood else 30308c6529dbSLiam Girdwood return -EINVAL; 30318c6529dbSLiam Girdwood } 30328c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 30338c6529dbSLiam Girdwood 30348c6529dbSLiam Girdwood /** 30358c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 30368c6529dbSLiam Girdwood * @dai: DAI 30378c6529dbSLiam Girdwood * @mute: mute enable 30388c6529dbSLiam Girdwood * 30398c6529dbSLiam Girdwood * Mutes the DAI DAC. 30408c6529dbSLiam Girdwood */ 30418c6529dbSLiam Girdwood int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 30428c6529dbSLiam Girdwood { 3043f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->digital_mute) 3044f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 30458c6529dbSLiam Girdwood else 30468c6529dbSLiam Girdwood return -EINVAL; 30478c6529dbSLiam Girdwood } 30488c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 30498c6529dbSLiam Girdwood 3050c5af3a2eSMark Brown /** 3051c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 3052c5af3a2eSMark Brown * 3053ac11a2b3SMark Brown * @card: Card to register 3054c5af3a2eSMark Brown * 3055c5af3a2eSMark Brown */ 305670a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 3057c5af3a2eSMark Brown { 3058f0fba2adSLiam Girdwood int i; 3059f0fba2adSLiam Girdwood 3060c5af3a2eSMark Brown if (!card->name || !card->dev) 3061c5af3a2eSMark Brown return -EINVAL; 3062c5af3a2eSMark Brown 30635a504963SStephen Warren for (i = 0; i < card->num_links; i++) { 30645a504963SStephen Warren struct snd_soc_dai_link *link = &card->dai_link[i]; 30655a504963SStephen Warren 30665a504963SStephen Warren /* 30675a504963SStephen Warren * Codec must be specified by 1 of name or OF node, 30685a504963SStephen Warren * not both or neither. 30695a504963SStephen Warren */ 30705a504963SStephen Warren if (!!link->codec_name == !!link->codec_of_node) { 30715a504963SStephen Warren dev_err(card->dev, 30723b09bb82SLiam Girdwood "Neither/both codec name/of_node are set for %s\n", 30733b09bb82SLiam Girdwood link->name); 30745a504963SStephen Warren return -EINVAL; 30755a504963SStephen Warren } 30765a504963SStephen Warren 30775a504963SStephen Warren /* 30785a504963SStephen Warren * Platform may be specified by either name or OF node, but 30795a504963SStephen Warren * can be left unspecified, and a dummy platform will be used. 30805a504963SStephen Warren */ 30815a504963SStephen Warren if (link->platform_name && link->platform_of_node) { 30825a504963SStephen Warren dev_err(card->dev, 30833b09bb82SLiam Girdwood "Both platform name/of_node are set for %s\n", link->name); 30845a504963SStephen Warren return -EINVAL; 30855a504963SStephen Warren } 30865a504963SStephen Warren 30875a504963SStephen Warren /* 30885a504963SStephen Warren * CPU DAI must be specified by 1 of name or OF node, 30895a504963SStephen Warren * not both or neither. 30905a504963SStephen Warren */ 30915a504963SStephen Warren if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) { 30925a504963SStephen Warren dev_err(card->dev, 30933b09bb82SLiam Girdwood "Neither/both cpu_dai name/of_node are set for %s\n", 30943b09bb82SLiam Girdwood link->name); 30955a504963SStephen Warren return -EINVAL; 30965a504963SStephen Warren } 30975a504963SStephen Warren } 30985a504963SStephen Warren 3099ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 3100ed77cc12SMark Brown 3101111c6419SStephen Warren snd_soc_initialize_card_lists(card); 3102111c6419SStephen Warren 3103150dd2f8SVinod Koul soc_init_card_debugfs(card); 3104150dd2f8SVinod Koul 31052eea392dSJarkko Nikula card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * 31062eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 3107f0fba2adSLiam Girdwood GFP_KERNEL); 3108f0fba2adSLiam Girdwood if (card->rtd == NULL) 3109f0fba2adSLiam Girdwood return -ENOMEM; 31102eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 3111f0fba2adSLiam Girdwood 3112f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 3113f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 3114f0fba2adSLiam Girdwood 3115c5af3a2eSMark Brown INIT_LIST_HEAD(&card->list); 3116db432b41SMark Brown INIT_LIST_HEAD(&card->dapm_dirty); 3117c5af3a2eSMark Brown card->instantiated = 0; 3118f0fba2adSLiam Girdwood mutex_init(&card->mutex); 3119c5af3a2eSMark Brown 3120c5af3a2eSMark Brown mutex_lock(&client_mutex); 3121c5af3a2eSMark Brown list_add(&card->list, &card_list); 3122435c5e25SMark Brown snd_soc_instantiate_cards(); 3123c5af3a2eSMark Brown mutex_unlock(&client_mutex); 3124c5af3a2eSMark Brown 3125c5af3a2eSMark Brown dev_dbg(card->dev, "Registered card '%s'\n", card->name); 3126c5af3a2eSMark Brown 3127c5af3a2eSMark Brown return 0; 3128c5af3a2eSMark Brown } 312970a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 3130c5af3a2eSMark Brown 3131c5af3a2eSMark Brown /** 3132c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 3133c5af3a2eSMark Brown * 3134ac11a2b3SMark Brown * @card: Card to unregister 3135c5af3a2eSMark Brown * 3136c5af3a2eSMark Brown */ 313770a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 3138c5af3a2eSMark Brown { 3139b0e26485SVinod Koul if (card->instantiated) 3140b0e26485SVinod Koul soc_cleanup_card_resources(card); 3141c5af3a2eSMark Brown mutex_lock(&client_mutex); 3142c5af3a2eSMark Brown list_del(&card->list); 3143c5af3a2eSMark Brown mutex_unlock(&client_mutex); 3144c5af3a2eSMark Brown dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); 3145c5af3a2eSMark Brown 3146c5af3a2eSMark Brown return 0; 3147c5af3a2eSMark Brown } 314870a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 3149c5af3a2eSMark Brown 3150f0fba2adSLiam Girdwood /* 3151f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 3152f0fba2adSLiam Girdwood * and sanitizing names. 3153f0fba2adSLiam Girdwood */ 31540b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 3155f0fba2adSLiam Girdwood { 3156f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 3157f0fba2adSLiam Girdwood int id1, id2; 3158f0fba2adSLiam Girdwood 3159f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 3160f0fba2adSLiam Girdwood return NULL; 3161f0fba2adSLiam Girdwood 316258818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 3163f0fba2adSLiam Girdwood 3164f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 3165f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 3166f0fba2adSLiam Girdwood if (found) { 3167f0fba2adSLiam Girdwood /* get ID */ 3168f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 3169f0fba2adSLiam Girdwood 3170f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 3171f0fba2adSLiam Girdwood if (*id == -1) 3172f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 3173f0fba2adSLiam Girdwood } 3174f0fba2adSLiam Girdwood 3175f0fba2adSLiam Girdwood } else { 3176f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 3177f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 3178f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 3179f0fba2adSLiam Girdwood 3180f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 318105899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 3182f0fba2adSLiam Girdwood 3183f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 3184f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 318558818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 3186f0fba2adSLiam Girdwood } else 3187f0fba2adSLiam Girdwood *id = 0; 3188f0fba2adSLiam Girdwood } 3189f0fba2adSLiam Girdwood 3190f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 3191f0fba2adSLiam Girdwood } 3192f0fba2adSLiam Girdwood 3193f0fba2adSLiam Girdwood /* 3194f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 3195f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 3196f0fba2adSLiam Girdwood */ 3197f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 3198f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 3199f0fba2adSLiam Girdwood { 3200f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 32010837fc62SFabio Estevam pr_err("asoc: error - multiple DAI %s registered with no name\n", 3202f0fba2adSLiam Girdwood dev_name(dev)); 3203f0fba2adSLiam Girdwood return NULL; 3204f0fba2adSLiam Girdwood } 3205f0fba2adSLiam Girdwood 3206f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 3207f0fba2adSLiam Girdwood } 3208f0fba2adSLiam Girdwood 32099115171aSMark Brown /** 32109115171aSMark Brown * snd_soc_register_dai - Register a DAI with the ASoC core 32119115171aSMark Brown * 3212ac11a2b3SMark Brown * @dai: DAI to register 32139115171aSMark Brown */ 3214f0fba2adSLiam Girdwood int snd_soc_register_dai(struct device *dev, 3215f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 32169115171aSMark Brown { 3217f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 32189115171aSMark Brown 3219f0fba2adSLiam Girdwood dev_dbg(dev, "dai register %s\n", dev_name(dev)); 32209115171aSMark Brown 3221f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3222f0fba2adSLiam Girdwood if (dai == NULL) 3223f0fba2adSLiam Girdwood return -ENOMEM; 32246335d055SEric Miao 3225f0fba2adSLiam Girdwood /* create DAI component name */ 3226f0fba2adSLiam Girdwood dai->name = fmt_single_name(dev, &dai->id); 3227f0fba2adSLiam Girdwood if (dai->name == NULL) { 3228f0fba2adSLiam Girdwood kfree(dai); 3229f0fba2adSLiam Girdwood return -ENOMEM; 3230f0fba2adSLiam Girdwood } 3231f0fba2adSLiam Girdwood 3232f0fba2adSLiam Girdwood dai->dev = dev; 3233f0fba2adSLiam Girdwood dai->driver = dai_drv; 3234f0fba2adSLiam Girdwood if (!dai->driver->ops) 3235f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 32369115171aSMark Brown 32379115171aSMark Brown mutex_lock(&client_mutex); 32389115171aSMark Brown list_add(&dai->list, &dai_list); 3239435c5e25SMark Brown snd_soc_instantiate_cards(); 32409115171aSMark Brown mutex_unlock(&client_mutex); 32419115171aSMark Brown 32429115171aSMark Brown pr_debug("Registered DAI '%s'\n", dai->name); 32439115171aSMark Brown 32449115171aSMark Brown return 0; 32459115171aSMark Brown } 32469115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dai); 32479115171aSMark Brown 32489115171aSMark Brown /** 32499115171aSMark Brown * snd_soc_unregister_dai - Unregister a DAI from the ASoC core 32509115171aSMark Brown * 3251ac11a2b3SMark Brown * @dai: DAI to unregister 32529115171aSMark Brown */ 3253f0fba2adSLiam Girdwood void snd_soc_unregister_dai(struct device *dev) 32549115171aSMark Brown { 3255f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3256f0fba2adSLiam Girdwood 3257f0fba2adSLiam Girdwood list_for_each_entry(dai, &dai_list, list) { 3258f0fba2adSLiam Girdwood if (dev == dai->dev) 3259f0fba2adSLiam Girdwood goto found; 3260f0fba2adSLiam Girdwood } 3261f0fba2adSLiam Girdwood return; 3262f0fba2adSLiam Girdwood 3263f0fba2adSLiam Girdwood found: 32649115171aSMark Brown mutex_lock(&client_mutex); 32659115171aSMark Brown list_del(&dai->list); 32669115171aSMark Brown mutex_unlock(&client_mutex); 32679115171aSMark Brown 32689115171aSMark Brown pr_debug("Unregistered DAI '%s'\n", dai->name); 3269f0fba2adSLiam Girdwood kfree(dai->name); 3270f0fba2adSLiam Girdwood kfree(dai); 32719115171aSMark Brown } 32729115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); 32739115171aSMark Brown 32749115171aSMark Brown /** 32759115171aSMark Brown * snd_soc_register_dais - Register multiple DAIs with the ASoC core 32769115171aSMark Brown * 3277ac11a2b3SMark Brown * @dai: Array of DAIs to register 3278ac11a2b3SMark Brown * @count: Number of DAIs 32799115171aSMark Brown */ 3280f0fba2adSLiam Girdwood int snd_soc_register_dais(struct device *dev, 3281f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv, size_t count) 32829115171aSMark Brown { 3283f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3284f0fba2adSLiam Girdwood int i, ret = 0; 3285f0fba2adSLiam Girdwood 3286720ffa4cSLiam Girdwood dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count); 32879115171aSMark Brown 32889115171aSMark Brown for (i = 0; i < count; i++) { 3289f0fba2adSLiam Girdwood 3290f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3291c46e0079SAxel Lin if (dai == NULL) { 3292c46e0079SAxel Lin ret = -ENOMEM; 3293c46e0079SAxel Lin goto err; 3294c46e0079SAxel Lin } 3295f0fba2adSLiam Girdwood 3296f0fba2adSLiam Girdwood /* create DAI component name */ 3297f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3298f0fba2adSLiam Girdwood if (dai->name == NULL) { 3299f0fba2adSLiam Girdwood kfree(dai); 3300f0fba2adSLiam Girdwood ret = -EINVAL; 33019115171aSMark Brown goto err; 33029115171aSMark Brown } 33039115171aSMark Brown 3304f0fba2adSLiam Girdwood dai->dev = dev; 3305f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 33060f9141c9SMark Brown if (dai->driver->id) 33070f9141c9SMark Brown dai->id = dai->driver->id; 33080f9141c9SMark Brown else 33090f9141c9SMark Brown dai->id = i; 3310f0fba2adSLiam Girdwood if (!dai->driver->ops) 3311f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 3312f0fba2adSLiam Girdwood 3313f0fba2adSLiam Girdwood mutex_lock(&client_mutex); 3314f0fba2adSLiam Girdwood list_add(&dai->list, &dai_list); 3315f0fba2adSLiam Girdwood mutex_unlock(&client_mutex); 3316f0fba2adSLiam Girdwood 3317f0fba2adSLiam Girdwood pr_debug("Registered DAI '%s'\n", dai->name); 3318f0fba2adSLiam Girdwood } 3319f0fba2adSLiam Girdwood 33201dcb4f38SAxel Lin mutex_lock(&client_mutex); 3321f0fba2adSLiam Girdwood snd_soc_instantiate_cards(); 33221dcb4f38SAxel Lin mutex_unlock(&client_mutex); 33239115171aSMark Brown return 0; 33249115171aSMark Brown 33259115171aSMark Brown err: 33269115171aSMark Brown for (i--; i >= 0; i--) 3327f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 33289115171aSMark Brown 33299115171aSMark Brown return ret; 33309115171aSMark Brown } 33319115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dais); 33329115171aSMark Brown 33339115171aSMark Brown /** 33349115171aSMark Brown * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core 33359115171aSMark Brown * 3336ac11a2b3SMark Brown * @dai: Array of DAIs to unregister 3337ac11a2b3SMark Brown * @count: Number of DAIs 33389115171aSMark Brown */ 3339f0fba2adSLiam Girdwood void snd_soc_unregister_dais(struct device *dev, size_t count) 33409115171aSMark Brown { 33419115171aSMark Brown int i; 33429115171aSMark Brown 33439115171aSMark Brown for (i = 0; i < count; i++) 3344f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 33459115171aSMark Brown } 33469115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); 33479115171aSMark Brown 334812a48a8cSMark Brown /** 334912a48a8cSMark Brown * snd_soc_register_platform - Register a platform with the ASoC core 335012a48a8cSMark Brown * 3351ac11a2b3SMark Brown * @platform: platform to register 335212a48a8cSMark Brown */ 3353f0fba2adSLiam Girdwood int snd_soc_register_platform(struct device *dev, 3354f0fba2adSLiam Girdwood struct snd_soc_platform_driver *platform_drv) 335512a48a8cSMark Brown { 3356f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 335712a48a8cSMark Brown 3358f0fba2adSLiam Girdwood dev_dbg(dev, "platform register %s\n", dev_name(dev)); 3359f0fba2adSLiam Girdwood 3360f0fba2adSLiam Girdwood platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 3361f0fba2adSLiam Girdwood if (platform == NULL) 3362f0fba2adSLiam Girdwood return -ENOMEM; 3363f0fba2adSLiam Girdwood 3364f0fba2adSLiam Girdwood /* create platform component name */ 3365f0fba2adSLiam Girdwood platform->name = fmt_single_name(dev, &platform->id); 3366f0fba2adSLiam Girdwood if (platform->name == NULL) { 3367f0fba2adSLiam Girdwood kfree(platform); 3368f0fba2adSLiam Girdwood return -ENOMEM; 3369f0fba2adSLiam Girdwood } 3370f0fba2adSLiam Girdwood 3371f0fba2adSLiam Girdwood platform->dev = dev; 3372f0fba2adSLiam Girdwood platform->driver = platform_drv; 3373b7950641SLiam Girdwood platform->dapm.dev = dev; 3374b7950641SLiam Girdwood platform->dapm.platform = platform; 337564a648c2SLiam Girdwood platform->dapm.stream_event = platform_drv->stream_event; 337612a48a8cSMark Brown 337712a48a8cSMark Brown mutex_lock(&client_mutex); 337812a48a8cSMark Brown list_add(&platform->list, &platform_list); 3379435c5e25SMark Brown snd_soc_instantiate_cards(); 338012a48a8cSMark Brown mutex_unlock(&client_mutex); 338112a48a8cSMark Brown 338212a48a8cSMark Brown pr_debug("Registered platform '%s'\n", platform->name); 338312a48a8cSMark Brown 338412a48a8cSMark Brown return 0; 338512a48a8cSMark Brown } 338612a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 338712a48a8cSMark Brown 338812a48a8cSMark Brown /** 338912a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 339012a48a8cSMark Brown * 3391ac11a2b3SMark Brown * @platform: platform to unregister 339212a48a8cSMark Brown */ 3393f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 339412a48a8cSMark Brown { 3395f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 3396f0fba2adSLiam Girdwood 3397f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 3398f0fba2adSLiam Girdwood if (dev == platform->dev) 3399f0fba2adSLiam Girdwood goto found; 3400f0fba2adSLiam Girdwood } 3401f0fba2adSLiam Girdwood return; 3402f0fba2adSLiam Girdwood 3403f0fba2adSLiam Girdwood found: 340412a48a8cSMark Brown mutex_lock(&client_mutex); 340512a48a8cSMark Brown list_del(&platform->list); 340612a48a8cSMark Brown mutex_unlock(&client_mutex); 340712a48a8cSMark Brown 340812a48a8cSMark Brown pr_debug("Unregistered platform '%s'\n", platform->name); 3409f0fba2adSLiam Girdwood kfree(platform->name); 3410f0fba2adSLiam Girdwood kfree(platform); 341112a48a8cSMark Brown } 341212a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 341312a48a8cSMark Brown 3414151ab22cSMark Brown static u64 codec_format_map[] = { 3415151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 3416151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 3417151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 3418151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 3419151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 3420151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 3421151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3422151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3423151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 3424151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 3425151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 3426151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 3427151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 3428151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 3429151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 3430151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 3431151ab22cSMark Brown }; 3432151ab22cSMark Brown 3433151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 3434151ab22cSMark Brown * the endianness of the data but we're using the CPU format 3435151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 3436151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 3437151ab22cSMark Brown */ 3438151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 3439151ab22cSMark Brown { 3440151ab22cSMark Brown int i; 3441151ab22cSMark Brown 3442151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 3443151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 3444151ab22cSMark Brown stream->formats |= codec_format_map[i]; 3445151ab22cSMark Brown } 3446151ab22cSMark Brown 34470d0cf00aSMark Brown /** 34480d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 34490d0cf00aSMark Brown * 3450ac11a2b3SMark Brown * @codec: codec to register 34510d0cf00aSMark Brown */ 3452f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 3453001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 3454001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 3455001ae4c0SMark Brown int num_dai) 34560d0cf00aSMark Brown { 34573335ddcaSDimitris Papastamos size_t reg_size; 3458f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3459f0fba2adSLiam Girdwood int ret, i; 3460151ab22cSMark Brown 3461f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 34620d0cf00aSMark Brown 3463f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 3464f0fba2adSLiam Girdwood if (codec == NULL) 3465f0fba2adSLiam Girdwood return -ENOMEM; 34660d0cf00aSMark Brown 3467f0fba2adSLiam Girdwood /* create CODEC component name */ 3468f0fba2adSLiam Girdwood codec->name = fmt_single_name(dev, &codec->id); 3469f0fba2adSLiam Girdwood if (codec->name == NULL) { 3470f0fba2adSLiam Girdwood kfree(codec); 3471f0fba2adSLiam Girdwood return -ENOMEM; 3472151ab22cSMark Brown } 3473151ab22cSMark Brown 347423bbce34SDimitris Papastamos if (codec_drv->compress_type) 347523bbce34SDimitris Papastamos codec->compress_type = codec_drv->compress_type; 347623bbce34SDimitris Papastamos else 347723bbce34SDimitris Papastamos codec->compress_type = SND_SOC_FLAT_COMPRESSION; 347823bbce34SDimitris Papastamos 3479c3acec26SMark Brown codec->write = codec_drv->write; 3480c3acec26SMark Brown codec->read = codec_drv->read; 34811500b7b5SDimitris Papastamos codec->volatile_register = codec_drv->volatile_register; 34821500b7b5SDimitris Papastamos codec->readable_register = codec_drv->readable_register; 34838020454cSDimitris Papastamos codec->writable_register = codec_drv->writable_register; 34845124e69eSMark Brown codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time; 3485ce6120ccSLiam Girdwood codec->dapm.bias_level = SND_SOC_BIAS_OFF; 3486ce6120ccSLiam Girdwood codec->dapm.dev = dev; 3487ce6120ccSLiam Girdwood codec->dapm.codec = codec; 3488474b62d6SMark Brown codec->dapm.seq_notifier = codec_drv->seq_notifier; 348964a648c2SLiam Girdwood codec->dapm.stream_event = codec_drv->stream_event; 3490f0fba2adSLiam Girdwood codec->dev = dev; 3491f0fba2adSLiam Girdwood codec->driver = codec_drv; 3492f0fba2adSLiam Girdwood codec->num_dai = num_dai; 3493f0fba2adSLiam Girdwood mutex_init(&codec->mutex); 3494f0fba2adSLiam Girdwood 34957a30a3dbSDimitris Papastamos /* allocate CODEC register cache */ 34967a30a3dbSDimitris Papastamos if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 34973335ddcaSDimitris Papastamos reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 3498aea170a0SDimitris Papastamos codec->reg_size = reg_size; 34993335ddcaSDimitris Papastamos /* it is necessary to make a copy of the default register cache 35003335ddcaSDimitris Papastamos * because in the case of using a compression type that requires 35013335ddcaSDimitris Papastamos * the default register cache to be marked as __devinitconst the 35023335ddcaSDimitris Papastamos * kernel might have freed the array by the time we initialize 35033335ddcaSDimitris Papastamos * the cache. 35043335ddcaSDimitris Papastamos */ 35052aa86323SDimitris Papastamos if (codec_drv->reg_cache_default) { 35063335ddcaSDimitris Papastamos codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, 35073335ddcaSDimitris Papastamos reg_size, GFP_KERNEL); 35083335ddcaSDimitris Papastamos if (!codec->reg_def_copy) { 35093335ddcaSDimitris Papastamos ret = -ENOMEM; 3510fdf0f54dSDimitris Papastamos goto fail; 35117a30a3dbSDimitris Papastamos } 35127a30a3dbSDimitris Papastamos } 35132aa86323SDimitris Papastamos } 35147a30a3dbSDimitris Papastamos 35151500b7b5SDimitris Papastamos if (codec_drv->reg_access_size && codec_drv->reg_access_default) { 35161500b7b5SDimitris Papastamos if (!codec->volatile_register) 35171500b7b5SDimitris Papastamos codec->volatile_register = snd_soc_default_volatile_register; 35181500b7b5SDimitris Papastamos if (!codec->readable_register) 35191500b7b5SDimitris Papastamos codec->readable_register = snd_soc_default_readable_register; 35208020454cSDimitris Papastamos if (!codec->writable_register) 35218020454cSDimitris Papastamos codec->writable_register = snd_soc_default_writable_register; 35221500b7b5SDimitris Papastamos } 35231500b7b5SDimitris Papastamos 3524f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 3525f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 3526f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 3527f0fba2adSLiam Girdwood } 3528f0fba2adSLiam Girdwood 352926b01ccdSMark Brown /* register any DAIs */ 353026b01ccdSMark Brown if (num_dai) { 3531f0fba2adSLiam Girdwood ret = snd_soc_register_dais(dev, dai_drv, num_dai); 3532f0fba2adSLiam Girdwood if (ret < 0) 3533fdf0f54dSDimitris Papastamos goto fail; 353426b01ccdSMark Brown } 3535f0fba2adSLiam Girdwood 35360d0cf00aSMark Brown mutex_lock(&client_mutex); 35370d0cf00aSMark Brown list_add(&codec->list, &codec_list); 35380d0cf00aSMark Brown snd_soc_instantiate_cards(); 35390d0cf00aSMark Brown mutex_unlock(&client_mutex); 35400d0cf00aSMark Brown 35410d0cf00aSMark Brown pr_debug("Registered codec '%s'\n", codec->name); 35420d0cf00aSMark Brown return 0; 3543f0fba2adSLiam Girdwood 3544fdf0f54dSDimitris Papastamos fail: 35453335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 35463335ddcaSDimitris Papastamos codec->reg_def_copy = NULL; 3547f0fba2adSLiam Girdwood kfree(codec->name); 3548f0fba2adSLiam Girdwood kfree(codec); 3549f0fba2adSLiam Girdwood return ret; 35500d0cf00aSMark Brown } 35510d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 35520d0cf00aSMark Brown 35530d0cf00aSMark Brown /** 35540d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 35550d0cf00aSMark Brown * 3556ac11a2b3SMark Brown * @codec: codec to unregister 35570d0cf00aSMark Brown */ 3558f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 35590d0cf00aSMark Brown { 3560f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3561f0fba2adSLiam Girdwood int i; 3562f0fba2adSLiam Girdwood 3563f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 3564f0fba2adSLiam Girdwood if (dev == codec->dev) 3565f0fba2adSLiam Girdwood goto found; 3566f0fba2adSLiam Girdwood } 3567f0fba2adSLiam Girdwood return; 3568f0fba2adSLiam Girdwood 3569f0fba2adSLiam Girdwood found: 357026b01ccdSMark Brown if (codec->num_dai) 3571f0fba2adSLiam Girdwood for (i = 0; i < codec->num_dai; i++) 3572f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 3573f0fba2adSLiam Girdwood 35740d0cf00aSMark Brown mutex_lock(&client_mutex); 35750d0cf00aSMark Brown list_del(&codec->list); 35760d0cf00aSMark Brown mutex_unlock(&client_mutex); 35770d0cf00aSMark Brown 35780d0cf00aSMark Brown pr_debug("Unregistered codec '%s'\n", codec->name); 3579f0fba2adSLiam Girdwood 35807a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 35813335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 35821aafcd4dSDimitris Papastamos kfree(codec->name); 3583f0fba2adSLiam Girdwood kfree(codec); 35840d0cf00aSMark Brown } 35850d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 35860d0cf00aSMark Brown 3587bec4fa05SStephen Warren /* Retrieve a card's name from device tree */ 3588bec4fa05SStephen Warren int snd_soc_of_parse_card_name(struct snd_soc_card *card, 3589bec4fa05SStephen Warren const char *propname) 3590bec4fa05SStephen Warren { 3591bec4fa05SStephen Warren struct device_node *np = card->dev->of_node; 3592bec4fa05SStephen Warren int ret; 3593bec4fa05SStephen Warren 3594bec4fa05SStephen Warren ret = of_property_read_string_index(np, propname, 0, &card->name); 3595bec4fa05SStephen Warren /* 3596bec4fa05SStephen Warren * EINVAL means the property does not exist. This is fine providing 3597bec4fa05SStephen Warren * card->name was previously set, which is checked later in 3598bec4fa05SStephen Warren * snd_soc_register_card. 3599bec4fa05SStephen Warren */ 3600bec4fa05SStephen Warren if (ret < 0 && ret != -EINVAL) { 3601bec4fa05SStephen Warren dev_err(card->dev, 3602bec4fa05SStephen Warren "Property '%s' could not be read: %d\n", 3603bec4fa05SStephen Warren propname, ret); 3604bec4fa05SStephen Warren return ret; 3605bec4fa05SStephen Warren } 3606bec4fa05SStephen Warren 3607bec4fa05SStephen Warren return 0; 3608bec4fa05SStephen Warren } 3609bec4fa05SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 3610bec4fa05SStephen Warren 3611a4a54dd5SStephen Warren int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 3612a4a54dd5SStephen Warren const char *propname) 3613a4a54dd5SStephen Warren { 3614a4a54dd5SStephen Warren struct device_node *np = card->dev->of_node; 3615a4a54dd5SStephen Warren int num_routes; 3616a4a54dd5SStephen Warren struct snd_soc_dapm_route *routes; 3617a4a54dd5SStephen Warren int i, ret; 3618a4a54dd5SStephen Warren 3619a4a54dd5SStephen Warren num_routes = of_property_count_strings(np, propname); 3620a4a54dd5SStephen Warren if (num_routes & 1) { 3621a4a54dd5SStephen Warren dev_err(card->dev, 3622a4a54dd5SStephen Warren "Property '%s's length is not even\n", 3623a4a54dd5SStephen Warren propname); 3624a4a54dd5SStephen Warren return -EINVAL; 3625a4a54dd5SStephen Warren } 3626a4a54dd5SStephen Warren num_routes /= 2; 3627a4a54dd5SStephen Warren if (!num_routes) { 3628a4a54dd5SStephen Warren dev_err(card->dev, 3629a4a54dd5SStephen Warren "Property '%s's length is zero\n", 3630a4a54dd5SStephen Warren propname); 3631a4a54dd5SStephen Warren return -EINVAL; 3632a4a54dd5SStephen Warren } 3633a4a54dd5SStephen Warren 3634a4a54dd5SStephen Warren routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), 3635a4a54dd5SStephen Warren GFP_KERNEL); 3636a4a54dd5SStephen Warren if (!routes) { 3637a4a54dd5SStephen Warren dev_err(card->dev, 3638a4a54dd5SStephen Warren "Could not allocate DAPM route table\n"); 3639a4a54dd5SStephen Warren return -EINVAL; 3640a4a54dd5SStephen Warren } 3641a4a54dd5SStephen Warren 3642a4a54dd5SStephen Warren for (i = 0; i < num_routes; i++) { 3643a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3644a4a54dd5SStephen Warren 2 * i, &routes[i].sink); 3645a4a54dd5SStephen Warren if (ret) { 3646a4a54dd5SStephen Warren dev_err(card->dev, 3647a4a54dd5SStephen Warren "Property '%s' index %d could not be read: %d\n", 3648a4a54dd5SStephen Warren propname, 2 * i, ret); 3649a4a54dd5SStephen Warren return -EINVAL; 3650a4a54dd5SStephen Warren } 3651a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 3652a4a54dd5SStephen Warren (2 * i) + 1, &routes[i].source); 3653a4a54dd5SStephen Warren if (ret) { 3654a4a54dd5SStephen Warren dev_err(card->dev, 3655a4a54dd5SStephen Warren "Property '%s' index %d could not be read: %d\n", 3656a4a54dd5SStephen Warren propname, (2 * i) + 1, ret); 3657a4a54dd5SStephen Warren return -EINVAL; 3658a4a54dd5SStephen Warren } 3659a4a54dd5SStephen Warren } 3660a4a54dd5SStephen Warren 3661a4a54dd5SStephen Warren card->num_dapm_routes = num_routes; 3662a4a54dd5SStephen Warren card->dapm_routes = routes; 3663a4a54dd5SStephen Warren 3664a4a54dd5SStephen Warren return 0; 3665a4a54dd5SStephen Warren } 3666a4a54dd5SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); 3667a4a54dd5SStephen Warren 3668c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 3669db2a4165SFrank Mandarino { 3670384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 36718a9dab1aSMark Brown snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); 36728a9dab1aSMark Brown if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { 36730837fc62SFabio Estevam pr_warn("ASoC: Failed to create debugfs directory\n"); 36748a9dab1aSMark Brown snd_soc_debugfs_root = NULL; 3675384c89e2SMark Brown } 3676c3c5a19aSMark Brown 36778a9dab1aSMark Brown if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, 3678c3c5a19aSMark Brown &codec_list_fops)) 3679c3c5a19aSMark Brown pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); 3680c3c5a19aSMark Brown 36818a9dab1aSMark Brown if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, 3682f3208780SMark Brown &dai_list_fops)) 3683f3208780SMark Brown pr_warn("ASoC: Failed to create DAI list debugfs file\n"); 368419c7ac27SMark Brown 36858a9dab1aSMark Brown if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, 368619c7ac27SMark Brown &platform_list_fops)) 368719c7ac27SMark Brown pr_warn("ASoC: Failed to create platform list debugfs file\n"); 3688384c89e2SMark Brown #endif 3689384c89e2SMark Brown 3690fb257897SMark Brown snd_soc_util_init(); 3691fb257897SMark Brown 3692db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 3693db2a4165SFrank Mandarino } 36944abe8e16SMark Brown module_init(snd_soc_init); 3695db2a4165SFrank Mandarino 36967d8c16a6SMark Brown static void __exit snd_soc_exit(void) 3697db2a4165SFrank Mandarino { 3698fb257897SMark Brown snd_soc_util_exit(); 3699fb257897SMark Brown 3700384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 37018a9dab1aSMark Brown debugfs_remove_recursive(snd_soc_debugfs_root); 3702384c89e2SMark Brown #endif 3703db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 3704db2a4165SFrank Mandarino } 3705db2a4165SFrank Mandarino module_exit(snd_soc_exit); 3706db2a4165SFrank Mandarino 3707db2a4165SFrank Mandarino /* Module information */ 3708d331124dSLiam Girdwood MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 3709db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 3710db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 37118b45a209SKay Sievers MODULE_ALIAS("platform:soc-audio"); 3712