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> 335a0e3ad6STejun Heo #include <linux/slab.h> 34474828a4SMarek Vasut #include <sound/ac97_codec.h> 35db2a4165SFrank Mandarino #include <sound/core.h> 363028eb8cSMark Brown #include <sound/jack.h> 37db2a4165SFrank Mandarino #include <sound/pcm.h> 38db2a4165SFrank Mandarino #include <sound/pcm_params.h> 39db2a4165SFrank Mandarino #include <sound/soc.h> 40db2a4165SFrank Mandarino #include <sound/initval.h> 41db2a4165SFrank Mandarino 42a8b1d34fSMark Brown #define CREATE_TRACE_POINTS 43a8b1d34fSMark Brown #include <trace/events/asoc.h> 44a8b1d34fSMark Brown 45f0fba2adSLiam Girdwood #define NAME_SIZE 32 46f0fba2adSLiam Girdwood 47db2a4165SFrank Mandarino static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 48db2a4165SFrank Mandarino 49384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 508a9dab1aSMark Brown struct dentry *snd_soc_debugfs_root; 518a9dab1aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); 52384c89e2SMark Brown #endif 53384c89e2SMark Brown 54c5af3a2eSMark Brown static DEFINE_MUTEX(client_mutex); 55c5af3a2eSMark Brown static LIST_HEAD(card_list); 569115171aSMark Brown static LIST_HEAD(dai_list); 5712a48a8cSMark Brown static LIST_HEAD(platform_list); 580d0cf00aSMark Brown static LIST_HEAD(codec_list); 59c5af3a2eSMark Brown 60ddee627cSLiam Girdwood int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); 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) { 1461500b7b5SDimitris Papastamos if (codec->readable_register && !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 { 172f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 173f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 174f0fba2adSLiam Girdwood 17513fd179fSDimitris Papastamos return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 1762624d5faSMark Brown } 1772624d5faSMark Brown 1782624d5faSMark Brown static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1792624d5faSMark Brown 180dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev, 181dbe21408SMark Brown struct device_attribute *attr, char *buf) 182dbe21408SMark Brown { 183f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 184f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 185dbe21408SMark Brown 186f0fba2adSLiam Girdwood return sprintf(buf, "%ld\n", rtd->pmdown_time); 187dbe21408SMark Brown } 188dbe21408SMark Brown 189dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev, 190dbe21408SMark Brown struct device_attribute *attr, 191dbe21408SMark Brown const char *buf, size_t count) 192dbe21408SMark Brown { 193f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 194f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 195c593b520SMark Brown int ret; 196dbe21408SMark Brown 197c593b520SMark Brown ret = strict_strtol(buf, 10, &rtd->pmdown_time); 198c593b520SMark Brown if (ret) 199c593b520SMark Brown return ret; 200dbe21408SMark Brown 201dbe21408SMark Brown return count; 202dbe21408SMark Brown } 203dbe21408SMark Brown 204dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 205dbe21408SMark Brown 2062624d5faSMark Brown #ifdef CONFIG_DEBUG_FS 2072624d5faSMark Brown static int codec_reg_open_file(struct inode *inode, struct file *file) 2082624d5faSMark Brown { 2092624d5faSMark Brown file->private_data = inode->i_private; 2102624d5faSMark Brown return 0; 2112624d5faSMark Brown } 2122624d5faSMark Brown 2132624d5faSMark Brown static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 2142624d5faSMark Brown size_t count, loff_t *ppos) 2152624d5faSMark Brown { 2162624d5faSMark Brown ssize_t ret; 2172624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 21813fd179fSDimitris Papastamos char *buf; 21913fd179fSDimitris Papastamos 22013fd179fSDimitris Papastamos if (*ppos < 0 || !count) 22113fd179fSDimitris Papastamos return -EINVAL; 22213fd179fSDimitris Papastamos 22313fd179fSDimitris Papastamos buf = kmalloc(count, GFP_KERNEL); 2242624d5faSMark Brown if (!buf) 2252624d5faSMark Brown return -ENOMEM; 22613fd179fSDimitris Papastamos 22713fd179fSDimitris Papastamos ret = soc_codec_reg_show(codec, buf, count, *ppos); 22813fd179fSDimitris Papastamos if (ret >= 0) { 22913fd179fSDimitris Papastamos if (copy_to_user(user_buf, buf, ret)) { 23013fd179fSDimitris Papastamos kfree(buf); 23113fd179fSDimitris Papastamos return -EFAULT; 23213fd179fSDimitris Papastamos } 23313fd179fSDimitris Papastamos *ppos += ret; 23413fd179fSDimitris Papastamos } 23513fd179fSDimitris Papastamos 2362624d5faSMark Brown kfree(buf); 2372624d5faSMark Brown return ret; 2382624d5faSMark Brown } 2392624d5faSMark Brown 2402624d5faSMark Brown static ssize_t codec_reg_write_file(struct file *file, 2412624d5faSMark Brown const char __user *user_buf, size_t count, loff_t *ppos) 2422624d5faSMark Brown { 2432624d5faSMark Brown char buf[32]; 24434e268d8SStephen Boyd size_t buf_size; 2452624d5faSMark Brown char *start = buf; 2462624d5faSMark Brown unsigned long reg, value; 2472624d5faSMark Brown int step = 1; 2482624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 2492624d5faSMark Brown 2502624d5faSMark Brown buf_size = min(count, (sizeof(buf)-1)); 2512624d5faSMark Brown if (copy_from_user(buf, user_buf, buf_size)) 2522624d5faSMark Brown return -EFAULT; 2532624d5faSMark Brown buf[buf_size] = 0; 2542624d5faSMark Brown 255f0fba2adSLiam Girdwood if (codec->driver->reg_cache_step) 256f0fba2adSLiam Girdwood step = codec->driver->reg_cache_step; 2572624d5faSMark Brown 2582624d5faSMark Brown while (*start == ' ') 2592624d5faSMark Brown start++; 2602624d5faSMark Brown reg = simple_strtoul(start, &start, 16); 2612624d5faSMark Brown while (*start == ' ') 2622624d5faSMark Brown start++; 2632624d5faSMark Brown if (strict_strtoul(start, 16, &value)) 2642624d5faSMark Brown return -EINVAL; 2650d51a9cbSMark Brown 2660d51a9cbSMark Brown /* Userspace has been fiddling around behind the kernel's back */ 2670d51a9cbSMark Brown add_taint(TAINT_USER); 2680d51a9cbSMark Brown 269e4f078d8SDimitris Papastamos snd_soc_write(codec, reg, value); 2702624d5faSMark Brown return buf_size; 2712624d5faSMark Brown } 2722624d5faSMark Brown 2732624d5faSMark Brown static const struct file_operations codec_reg_fops = { 2742624d5faSMark Brown .open = codec_reg_open_file, 2752624d5faSMark Brown .read = codec_reg_read_file, 2762624d5faSMark Brown .write = codec_reg_write_file, 2776038f373SArnd Bergmann .llseek = default_llseek, 2782624d5faSMark Brown }; 2792624d5faSMark Brown 2802624d5faSMark Brown static void soc_init_codec_debugfs(struct snd_soc_codec *codec) 2812624d5faSMark Brown { 282d6ce4cf3SJarkko Nikula struct dentry *debugfs_card_root = codec->card->debugfs_card_root; 283d6ce4cf3SJarkko Nikula 2846ba6c9c3SMark Brown codec->debugfs_codec_root = debugfs_create_dir(codec->name, 285d6ce4cf3SJarkko Nikula debugfs_card_root); 2862624d5faSMark Brown if (!codec->debugfs_codec_root) { 2872624d5faSMark Brown printk(KERN_WARNING 2882624d5faSMark Brown "ASoC: Failed to create codec debugfs directory\n"); 2892624d5faSMark Brown return; 2902624d5faSMark Brown } 2912624d5faSMark Brown 292aaee8ef1SMark Brown debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, 293aaee8ef1SMark Brown &codec->cache_sync); 294aaee8ef1SMark Brown debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, 295aaee8ef1SMark Brown &codec->cache_only); 296aaee8ef1SMark Brown 2972624d5faSMark Brown codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 2982624d5faSMark Brown codec->debugfs_codec_root, 2992624d5faSMark Brown codec, &codec_reg_fops); 3002624d5faSMark Brown if (!codec->debugfs_reg) 3012624d5faSMark Brown printk(KERN_WARNING 3022624d5faSMark Brown "ASoC: Failed to create codec register debugfs file\n"); 3032624d5faSMark Brown 3048eecaf62SLars-Peter Clausen snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); 3052624d5faSMark Brown } 3062624d5faSMark Brown 3072624d5faSMark Brown static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 3082624d5faSMark Brown { 3092624d5faSMark Brown debugfs_remove_recursive(codec->debugfs_codec_root); 3102624d5faSMark Brown } 3112624d5faSMark Brown 312c3c5a19aSMark Brown static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, 313c3c5a19aSMark Brown size_t count, loff_t *ppos) 314c3c5a19aSMark Brown { 315c3c5a19aSMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3162b194f9dSMark Brown ssize_t len, ret = 0; 317c3c5a19aSMark Brown struct snd_soc_codec *codec; 318c3c5a19aSMark Brown 319c3c5a19aSMark Brown if (!buf) 320c3c5a19aSMark Brown return -ENOMEM; 321c3c5a19aSMark Brown 3222b194f9dSMark Brown list_for_each_entry(codec, &codec_list, list) { 3232b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 324c3c5a19aSMark Brown codec->name); 3252b194f9dSMark Brown if (len >= 0) 3262b194f9dSMark Brown ret += len; 3272b194f9dSMark Brown if (ret > PAGE_SIZE) { 3282b194f9dSMark Brown ret = PAGE_SIZE; 3292b194f9dSMark Brown break; 3302b194f9dSMark Brown } 3312b194f9dSMark Brown } 332c3c5a19aSMark Brown 333c3c5a19aSMark Brown if (ret >= 0) 334c3c5a19aSMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 335c3c5a19aSMark Brown 336c3c5a19aSMark Brown kfree(buf); 337c3c5a19aSMark Brown 338c3c5a19aSMark Brown return ret; 339c3c5a19aSMark Brown } 340c3c5a19aSMark Brown 341c3c5a19aSMark Brown static const struct file_operations codec_list_fops = { 342c3c5a19aSMark Brown .read = codec_list_read_file, 343c3c5a19aSMark Brown .llseek = default_llseek,/* read accesses f_pos */ 344c3c5a19aSMark Brown }; 345c3c5a19aSMark Brown 346f3208780SMark Brown static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, 347f3208780SMark Brown size_t count, loff_t *ppos) 348f3208780SMark Brown { 349f3208780SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3502b194f9dSMark Brown ssize_t len, ret = 0; 351f3208780SMark Brown struct snd_soc_dai *dai; 352f3208780SMark Brown 353f3208780SMark Brown if (!buf) 354f3208780SMark Brown return -ENOMEM; 355f3208780SMark Brown 3562b194f9dSMark Brown list_for_each_entry(dai, &dai_list, list) { 3572b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); 3582b194f9dSMark Brown if (len >= 0) 3592b194f9dSMark Brown ret += len; 3602b194f9dSMark Brown if (ret > PAGE_SIZE) { 3612b194f9dSMark Brown ret = PAGE_SIZE; 3622b194f9dSMark Brown break; 3632b194f9dSMark Brown } 3642b194f9dSMark Brown } 365f3208780SMark Brown 366f3208780SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 367f3208780SMark Brown 368f3208780SMark Brown kfree(buf); 369f3208780SMark Brown 370f3208780SMark Brown return ret; 371f3208780SMark Brown } 372f3208780SMark Brown 373f3208780SMark Brown static const struct file_operations dai_list_fops = { 374f3208780SMark Brown .read = dai_list_read_file, 375f3208780SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 376f3208780SMark Brown }; 377f3208780SMark Brown 37819c7ac27SMark Brown static ssize_t platform_list_read_file(struct file *file, 37919c7ac27SMark Brown char __user *user_buf, 38019c7ac27SMark Brown size_t count, loff_t *ppos) 38119c7ac27SMark Brown { 38219c7ac27SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3832b194f9dSMark Brown ssize_t len, ret = 0; 38419c7ac27SMark Brown struct snd_soc_platform *platform; 38519c7ac27SMark Brown 38619c7ac27SMark Brown if (!buf) 38719c7ac27SMark Brown return -ENOMEM; 38819c7ac27SMark Brown 3892b194f9dSMark Brown list_for_each_entry(platform, &platform_list, list) { 3902b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 39119c7ac27SMark Brown platform->name); 3922b194f9dSMark Brown if (len >= 0) 3932b194f9dSMark Brown ret += len; 3942b194f9dSMark Brown if (ret > PAGE_SIZE) { 3952b194f9dSMark Brown ret = PAGE_SIZE; 3962b194f9dSMark Brown break; 3972b194f9dSMark Brown } 3982b194f9dSMark Brown } 39919c7ac27SMark Brown 40019c7ac27SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 40119c7ac27SMark Brown 40219c7ac27SMark Brown kfree(buf); 40319c7ac27SMark Brown 40419c7ac27SMark Brown return ret; 40519c7ac27SMark Brown } 40619c7ac27SMark Brown 40719c7ac27SMark Brown static const struct file_operations platform_list_fops = { 40819c7ac27SMark Brown .read = platform_list_read_file, 40919c7ac27SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 41019c7ac27SMark Brown }; 41119c7ac27SMark Brown 412a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card) 413a6052154SJarkko Nikula { 414a6052154SJarkko Nikula card->debugfs_card_root = debugfs_create_dir(card->name, 4158a9dab1aSMark Brown snd_soc_debugfs_root); 4163a45b867SJarkko Nikula if (!card->debugfs_card_root) { 417a6052154SJarkko Nikula dev_warn(card->dev, 418a6052154SJarkko Nikula "ASoC: Failed to create codec debugfs directory\n"); 4193a45b867SJarkko Nikula return; 4203a45b867SJarkko Nikula } 4213a45b867SJarkko Nikula 4223a45b867SJarkko Nikula card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 4233a45b867SJarkko Nikula card->debugfs_card_root, 4243a45b867SJarkko Nikula &card->pop_time); 4253a45b867SJarkko Nikula if (!card->debugfs_pop_time) 4263a45b867SJarkko Nikula dev_warn(card->dev, 4273a45b867SJarkko Nikula "Failed to create pop time debugfs file\n"); 428a6052154SJarkko Nikula } 429a6052154SJarkko Nikula 430a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card) 431a6052154SJarkko Nikula { 432a6052154SJarkko Nikula debugfs_remove_recursive(card->debugfs_card_root); 433a6052154SJarkko Nikula } 434a6052154SJarkko Nikula 4352624d5faSMark Brown #else 4362624d5faSMark Brown 4372624d5faSMark Brown static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) 4382624d5faSMark Brown { 4392624d5faSMark Brown } 4402624d5faSMark Brown 4412624d5faSMark Brown static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 4422624d5faSMark Brown { 4432624d5faSMark Brown } 444b95fccbcSAxel Lin 445b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card) 446b95fccbcSAxel Lin { 447b95fccbcSAxel Lin } 448b95fccbcSAxel Lin 449b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) 450b95fccbcSAxel Lin { 451b95fccbcSAxel Lin } 4522624d5faSMark Brown #endif 4532624d5faSMark Brown 454db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS 455db2a4165SFrank Mandarino /* unregister ac97 codec */ 456db2a4165SFrank Mandarino static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 457db2a4165SFrank Mandarino { 458db2a4165SFrank Mandarino if (codec->ac97->dev.bus) 459db2a4165SFrank Mandarino device_unregister(&codec->ac97->dev); 460db2a4165SFrank Mandarino return 0; 461db2a4165SFrank Mandarino } 462db2a4165SFrank Mandarino 463db2a4165SFrank Mandarino /* stop no dev release warning */ 464db2a4165SFrank Mandarino static void soc_ac97_device_release(struct device *dev){} 465db2a4165SFrank Mandarino 466db2a4165SFrank Mandarino /* register ac97 codec to bus */ 467db2a4165SFrank Mandarino static int soc_ac97_dev_register(struct snd_soc_codec *codec) 468db2a4165SFrank Mandarino { 469db2a4165SFrank Mandarino int err; 470db2a4165SFrank Mandarino 471db2a4165SFrank Mandarino codec->ac97->dev.bus = &ac97_bus_type; 4724ac5c61fSMark Brown codec->ac97->dev.parent = codec->card->dev; 473db2a4165SFrank Mandarino codec->ac97->dev.release = soc_ac97_device_release; 474db2a4165SFrank Mandarino 475bb072bf0SKay Sievers dev_set_name(&codec->ac97->dev, "%d-%d:%s", 476f0fba2adSLiam Girdwood codec->card->snd_card->number, 0, codec->name); 477db2a4165SFrank Mandarino err = device_register(&codec->ac97->dev); 478db2a4165SFrank Mandarino if (err < 0) { 479db2a4165SFrank Mandarino snd_printk(KERN_ERR "Can't register ac97 bus\n"); 480db2a4165SFrank Mandarino codec->ac97->dev.bus = NULL; 481db2a4165SFrank Mandarino return err; 482db2a4165SFrank Mandarino } 483db2a4165SFrank Mandarino return 0; 484db2a4165SFrank Mandarino } 485db2a4165SFrank Mandarino #endif 486db2a4165SFrank Mandarino 4876f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP 488db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */ 4896f8ab4acSMark Brown int snd_soc_suspend(struct device *dev) 490db2a4165SFrank Mandarino { 4916f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 4922eea392dSJarkko Nikula struct snd_soc_codec *codec; 493db2a4165SFrank Mandarino int i; 494db2a4165SFrank Mandarino 495e3509ff0SDaniel Mack /* If the initialization of this soc device failed, there is no codec 496e3509ff0SDaniel Mack * associated with it. Just bail out in this case. 497e3509ff0SDaniel Mack */ 498f0fba2adSLiam Girdwood if (list_empty(&card->codec_dev_list)) 499e3509ff0SDaniel Mack return 0; 500e3509ff0SDaniel Mack 5016ed25978SAndy Green /* Due to the resume being scheduled into a workqueue we could 5026ed25978SAndy Green * suspend before that's finished - wait for it to complete. 5036ed25978SAndy Green */ 504f0fba2adSLiam Girdwood snd_power_lock(card->snd_card); 505f0fba2adSLiam Girdwood snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); 506f0fba2adSLiam Girdwood snd_power_unlock(card->snd_card); 5076ed25978SAndy Green 5086ed25978SAndy Green /* we're going to block userspace touching us until resume completes */ 509f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 5106ed25978SAndy Green 511a00f90f9SMark Brown /* mute any active DACs */ 512f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 513f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 514f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 5153efab7dcSMark Brown 516f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5173efab7dcSMark Brown continue; 5183efab7dcSMark Brown 519f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 520f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 1); 521db2a4165SFrank Mandarino } 522db2a4165SFrank Mandarino 5234ccab3e7SLiam Girdwood /* suspend all pcms */ 524f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 525f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5263efab7dcSMark Brown continue; 5273efab7dcSMark Brown 528f0fba2adSLiam Girdwood snd_pcm_suspend_all(card->rtd[i].pcm); 5293efab7dcSMark Brown } 5304ccab3e7SLiam Girdwood 53187506549SMark Brown if (card->suspend_pre) 53270b2ac12SMark Brown card->suspend_pre(card); 533db2a4165SFrank Mandarino 534f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 535f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 536f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 5373efab7dcSMark Brown 538f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5393efab7dcSMark Brown continue; 5403efab7dcSMark Brown 541f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) 542f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 543f0fba2adSLiam Girdwood if (platform->driver->suspend && !platform->suspended) { 544f0fba2adSLiam Girdwood platform->driver->suspend(cpu_dai); 545f0fba2adSLiam Girdwood platform->suspended = 1; 546f0fba2adSLiam Girdwood } 547db2a4165SFrank Mandarino } 548db2a4165SFrank Mandarino 549db2a4165SFrank Mandarino /* close any waiting streams and save state */ 550f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 5515b84ba26STejun Heo flush_delayed_work_sync(&card->rtd[i].delayed_work); 552ce6120ccSLiam Girdwood card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; 553f0fba2adSLiam Girdwood } 554db2a4165SFrank Mandarino 555f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 556f0fba2adSLiam Girdwood struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; 5573efab7dcSMark Brown 558f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5593efab7dcSMark Brown continue; 5603efab7dcSMark Brown 561f0fba2adSLiam Girdwood if (driver->playback.stream_name != NULL) 562f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, 563db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 564f0fba2adSLiam Girdwood 565f0fba2adSLiam Girdwood if (driver->capture.stream_name != NULL) 566f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, 567db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 568db2a4165SFrank Mandarino } 569db2a4165SFrank Mandarino 570f0fba2adSLiam Girdwood /* suspend all CODECs */ 5712eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 5721547aba9SMark Brown /* If there are paths active then the CODEC will be held with 5731547aba9SMark Brown * bias _ON and should not be suspended. */ 574f0fba2adSLiam Girdwood if (!codec->suspended && codec->driver->suspend) { 575ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 5761547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 5771547aba9SMark Brown case SND_SOC_BIAS_OFF: 578f0fba2adSLiam Girdwood codec->driver->suspend(codec, PMSG_SUSPEND); 579f0fba2adSLiam Girdwood codec->suspended = 1; 5807be4ba24SMark Brown codec->cache_sync = 1; 5811547aba9SMark Brown break; 5821547aba9SMark Brown default: 583f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC is on over suspend\n"); 5841547aba9SMark Brown break; 5851547aba9SMark Brown } 5861547aba9SMark Brown } 587f0fba2adSLiam Girdwood } 588db2a4165SFrank Mandarino 589f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 590f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 5913efab7dcSMark Brown 592f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5933efab7dcSMark Brown continue; 5943efab7dcSMark Brown 595f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 596f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 597db2a4165SFrank Mandarino } 598db2a4165SFrank Mandarino 59987506549SMark Brown if (card->suspend_post) 60070b2ac12SMark Brown card->suspend_post(card); 601db2a4165SFrank Mandarino 602db2a4165SFrank Mandarino return 0; 603db2a4165SFrank Mandarino } 6046f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 605db2a4165SFrank Mandarino 6066ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 6076ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 6086ed25978SAndy Green */ 6096ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 610db2a4165SFrank Mandarino { 611f0fba2adSLiam Girdwood struct snd_soc_card *card = 612f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 6132eea392dSJarkko Nikula struct snd_soc_codec *codec; 614db2a4165SFrank Mandarino int i; 615db2a4165SFrank Mandarino 6166ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 6176ed25978SAndy Green * so userspace apps are blocked from touching us 6186ed25978SAndy Green */ 6196ed25978SAndy Green 620f0fba2adSLiam Girdwood dev_dbg(card->dev, "starting resume work\n"); 6216ed25978SAndy Green 6229949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 623f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 6249949788bSMark Brown 62587506549SMark Brown if (card->resume_pre) 62670b2ac12SMark Brown card->resume_pre(card); 627db2a4165SFrank Mandarino 628f0fba2adSLiam Girdwood /* resume AC97 DAIs */ 629f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 630f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6313efab7dcSMark Brown 632f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6333efab7dcSMark Brown continue; 6343efab7dcSMark Brown 635f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) 636f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 637db2a4165SFrank Mandarino } 638db2a4165SFrank Mandarino 6392eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 6401547aba9SMark Brown /* If the CODEC was idle over suspend then it will have been 6411547aba9SMark Brown * left with bias OFF or STANDBY and suspended so we must now 6421547aba9SMark Brown * resume. Otherwise the suspend was suppressed. 6431547aba9SMark Brown */ 644f0fba2adSLiam Girdwood if (codec->driver->resume && codec->suspended) { 645ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 6461547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 6471547aba9SMark Brown case SND_SOC_BIAS_OFF: 648f0fba2adSLiam Girdwood codec->driver->resume(codec); 649f0fba2adSLiam Girdwood codec->suspended = 0; 6501547aba9SMark Brown break; 6511547aba9SMark Brown default: 652f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC was on over suspend\n"); 6531547aba9SMark Brown break; 6541547aba9SMark Brown } 6551547aba9SMark Brown } 656f0fba2adSLiam Girdwood } 657db2a4165SFrank Mandarino 658f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 659f0fba2adSLiam Girdwood struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; 6603efab7dcSMark Brown 661f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6623efab7dcSMark Brown continue; 6633efab7dcSMark Brown 664f0fba2adSLiam Girdwood if (driver->playback.stream_name != NULL) 665f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, 666db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 667f0fba2adSLiam Girdwood 668f0fba2adSLiam Girdwood if (driver->capture.stream_name != NULL) 669f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, 670db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 671db2a4165SFrank Mandarino } 672db2a4165SFrank Mandarino 6733ff3f64bSMark Brown /* unmute any active DACs */ 674f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 675f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 676f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 6773efab7dcSMark Brown 678f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6793efab7dcSMark Brown continue; 6803efab7dcSMark Brown 681f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 682f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 683db2a4165SFrank Mandarino } 684db2a4165SFrank Mandarino 685f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 686f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 687f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 6883efab7dcSMark Brown 689f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6903efab7dcSMark Brown continue; 6913efab7dcSMark Brown 692f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) 693f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 694f0fba2adSLiam Girdwood if (platform->driver->resume && platform->suspended) { 695f0fba2adSLiam Girdwood platform->driver->resume(cpu_dai); 696f0fba2adSLiam Girdwood platform->suspended = 0; 697f0fba2adSLiam Girdwood } 698db2a4165SFrank Mandarino } 699db2a4165SFrank Mandarino 70087506549SMark Brown if (card->resume_post) 70170b2ac12SMark Brown card->resume_post(card); 702db2a4165SFrank Mandarino 703f0fba2adSLiam Girdwood dev_dbg(card->dev, "resume work completed\n"); 7046ed25978SAndy Green 7056ed25978SAndy Green /* userspace can access us now we are back as we were before */ 706f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 7076ed25978SAndy Green } 7086ed25978SAndy Green 7096ed25978SAndy Green /* powers up audio subsystem after a suspend */ 7106f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 7116ed25978SAndy Green { 7126f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 71382e14e8bSStephen Warren int i, ac97_control = 0; 714b9dd94a8SPeter Ujfalusi 71564ab9baaSMark Brown /* AC97 devices might have other drivers hanging off them so 71664ab9baaSMark Brown * need to resume immediately. Other drivers don't have that 71764ab9baaSMark Brown * problem and may take a substantial amount of time to resume 71864ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 71964ab9baaSMark Brown */ 720f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 721f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 72282e14e8bSStephen Warren ac97_control |= cpu_dai->driver->ac97_control; 72382e14e8bSStephen Warren } 72482e14e8bSStephen Warren if (ac97_control) { 725f0fba2adSLiam Girdwood dev_dbg(dev, "Resuming AC97 immediately\n"); 72664ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 72764ab9baaSMark Brown } else { 728f0fba2adSLiam Girdwood dev_dbg(dev, "Scheduling resume work\n"); 7296308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 730f0fba2adSLiam Girdwood dev_err(dev, "resume work item may be lost\n"); 731f0fba2adSLiam Girdwood } 7326ed25978SAndy Green 733db2a4165SFrank Mandarino return 0; 734db2a4165SFrank Mandarino } 7356f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 736db2a4165SFrank Mandarino #else 7376f8ab4acSMark Brown #define snd_soc_suspend NULL 7386f8ab4acSMark Brown #define snd_soc_resume NULL 739db2a4165SFrank Mandarino #endif 740db2a4165SFrank Mandarino 74102a06d30SBarry Song static struct snd_soc_dai_ops null_dai_ops = { 74202a06d30SBarry Song }; 74302a06d30SBarry Song 744f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 745db2a4165SFrank Mandarino { 746f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 747f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 748fe3e78e0SMark Brown struct snd_soc_codec *codec; 749435c5e25SMark Brown struct snd_soc_platform *platform; 750f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai, *cpu_dai; 751848dd8beSMark Brown const char *platform_name; 752db2a4165SFrank Mandarino 753f0fba2adSLiam Girdwood if (rtd->complete) 754f0fba2adSLiam Girdwood return 1; 755f0fba2adSLiam Girdwood dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); 7566308419aSMark Brown 757f0fba2adSLiam Girdwood /* do we already have the CPU DAI for this link ? */ 758f0fba2adSLiam Girdwood if (rtd->cpu_dai) { 759f0fba2adSLiam Girdwood goto find_codec; 760435c5e25SMark Brown } 761f0fba2adSLiam Girdwood /* no, then find CPU DAI from registered DAIs*/ 762f0fba2adSLiam Girdwood list_for_each_entry(cpu_dai, &dai_list, list) { 763f0fba2adSLiam Girdwood if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) { 764f0fba2adSLiam Girdwood rtd->cpu_dai = cpu_dai; 765f0fba2adSLiam Girdwood goto find_codec; 766f0fba2adSLiam Girdwood } 767f0fba2adSLiam Girdwood } 768f0fba2adSLiam Girdwood dev_dbg(card->dev, "CPU DAI %s not registered\n", 769f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 770f0fba2adSLiam Girdwood 771f0fba2adSLiam Girdwood find_codec: 772f0fba2adSLiam Girdwood /* do we already have the CODEC for this link ? */ 773f0fba2adSLiam Girdwood if (rtd->codec) { 774f0fba2adSLiam Girdwood goto find_platform; 775c5af3a2eSMark Brown } 776c5af3a2eSMark Brown 777f0fba2adSLiam Girdwood /* no, then find CODEC from registered CODECs*/ 778f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 779f0fba2adSLiam Girdwood if (!strcmp(codec->name, dai_link->codec_name)) { 780f0fba2adSLiam Girdwood rtd->codec = codec; 781f0fba2adSLiam Girdwood 782f0fba2adSLiam Girdwood /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/ 783f0fba2adSLiam Girdwood list_for_each_entry(codec_dai, &dai_list, list) { 784f0fba2adSLiam Girdwood if (codec->dev == codec_dai->dev && 785f0fba2adSLiam Girdwood !strcmp(codec_dai->name, dai_link->codec_dai_name)) { 786f0fba2adSLiam Girdwood rtd->codec_dai = codec_dai; 787f0fba2adSLiam Girdwood goto find_platform; 788435c5e25SMark Brown } 789f0fba2adSLiam Girdwood } 790f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC DAI %s not registered\n", 791f0fba2adSLiam Girdwood dai_link->codec_dai_name); 792f0fba2adSLiam Girdwood 793f0fba2adSLiam Girdwood goto find_platform; 794f0fba2adSLiam Girdwood } 795f0fba2adSLiam Girdwood } 796f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC %s not registered\n", 797f0fba2adSLiam Girdwood dai_link->codec_name); 798f0fba2adSLiam Girdwood 799f0fba2adSLiam Girdwood find_platform: 800848dd8beSMark Brown /* do we need a platform? */ 801848dd8beSMark Brown if (rtd->platform) 802f0fba2adSLiam Girdwood goto out; 803848dd8beSMark Brown 804848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 805848dd8beSMark Brown platform_name = dai_link->platform_name; 806848dd8beSMark Brown if (!platform_name) 807848dd8beSMark Brown platform_name = "snd-soc-dummy"; 808848dd8beSMark Brown 809848dd8beSMark Brown /* no, then find one from the set of registered platforms */ 810f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 811848dd8beSMark Brown if (!strcmp(platform->name, platform_name)) { 812f0fba2adSLiam Girdwood rtd->platform = platform; 813f0fba2adSLiam Girdwood goto out; 814f0fba2adSLiam Girdwood } 815435c5e25SMark Brown } 8166b05eda6SMark Brown 817f0fba2adSLiam Girdwood dev_dbg(card->dev, "platform %s not registered\n", 818f0fba2adSLiam Girdwood dai_link->platform_name); 819f0fba2adSLiam Girdwood return 0; 820f0fba2adSLiam Girdwood 821f0fba2adSLiam Girdwood out: 822f0fba2adSLiam Girdwood /* mark rtd as complete if we found all 4 of our client devices */ 823f0fba2adSLiam Girdwood if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) { 824f0fba2adSLiam Girdwood rtd->complete = 1; 825f0fba2adSLiam Girdwood card->num_rtd++; 826f0fba2adSLiam Girdwood } 827f0fba2adSLiam Girdwood return 1; 8286b05eda6SMark Brown } 8296b05eda6SMark Brown 830589c3563SJarkko Nikula static void soc_remove_codec(struct snd_soc_codec *codec) 831589c3563SJarkko Nikula { 832589c3563SJarkko Nikula int err; 833589c3563SJarkko Nikula 834589c3563SJarkko Nikula if (codec->driver->remove) { 835589c3563SJarkko Nikula err = codec->driver->remove(codec); 836589c3563SJarkko Nikula if (err < 0) 837589c3563SJarkko Nikula dev_err(codec->dev, 838589c3563SJarkko Nikula "asoc: failed to remove %s: %d\n", 839589c3563SJarkko Nikula codec->name, err); 840589c3563SJarkko Nikula } 841589c3563SJarkko Nikula 842589c3563SJarkko Nikula /* Make sure all DAPM widgets are freed */ 843589c3563SJarkko Nikula snd_soc_dapm_free(&codec->dapm); 844589c3563SJarkko Nikula 845589c3563SJarkko Nikula soc_cleanup_codec_debugfs(codec); 846589c3563SJarkko Nikula codec->probed = 0; 847589c3563SJarkko Nikula list_del(&codec->card_list); 848589c3563SJarkko Nikula module_put(codec->dev->driver->owner); 849589c3563SJarkko Nikula } 850589c3563SJarkko Nikula 8510168bf0dSLiam Girdwood static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) 852f0fba2adSLiam Girdwood { 853f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 854f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 855f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 856f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 857f0fba2adSLiam Girdwood int err; 858f0fba2adSLiam Girdwood 859f0fba2adSLiam Girdwood /* unregister the rtd device */ 860f0fba2adSLiam Girdwood if (rtd->dev_registered) { 861f0fba2adSLiam Girdwood device_remove_file(&rtd->dev, &dev_attr_pmdown_time); 862589c3563SJarkko Nikula device_remove_file(&rtd->dev, &dev_attr_codec_reg); 863f0fba2adSLiam Girdwood device_unregister(&rtd->dev); 864f0fba2adSLiam Girdwood rtd->dev_registered = 0; 86502a06d30SBarry Song } 86602a06d30SBarry Song 867f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 8680168bf0dSLiam Girdwood if (codec_dai && codec_dai->probed && 8690168bf0dSLiam Girdwood codec_dai->driver->remove_order == order) { 870f0fba2adSLiam Girdwood if (codec_dai->driver->remove) { 871f0fba2adSLiam Girdwood err = codec_dai->driver->remove(codec_dai); 872f0fba2adSLiam Girdwood if (err < 0) 873f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name); 874f0fba2adSLiam Girdwood } 875f0fba2adSLiam Girdwood codec_dai->probed = 0; 876f0fba2adSLiam Girdwood list_del(&codec_dai->card_list); 877f0fba2adSLiam Girdwood } 878f0fba2adSLiam Girdwood 879f0fba2adSLiam Girdwood /* remove the platform */ 8800168bf0dSLiam Girdwood if (platform && platform->probed && 8810168bf0dSLiam Girdwood platform->driver->remove_order == order) { 882f0fba2adSLiam Girdwood if (platform->driver->remove) { 883f0fba2adSLiam Girdwood err = platform->driver->remove(platform); 884f0fba2adSLiam Girdwood if (err < 0) 885f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", platform->name); 886f0fba2adSLiam Girdwood } 887f0fba2adSLiam Girdwood platform->probed = 0; 888f0fba2adSLiam Girdwood list_del(&platform->card_list); 889f0fba2adSLiam Girdwood module_put(platform->dev->driver->owner); 890f0fba2adSLiam Girdwood } 891f0fba2adSLiam Girdwood 892f0fba2adSLiam Girdwood /* remove the CODEC */ 8930168bf0dSLiam Girdwood if (codec && codec->probed && 8940168bf0dSLiam Girdwood codec->driver->remove_order == order) 895589c3563SJarkko Nikula soc_remove_codec(codec); 896f0fba2adSLiam Girdwood 897f0fba2adSLiam Girdwood /* remove the cpu_dai */ 8980168bf0dSLiam Girdwood if (cpu_dai && cpu_dai->probed && 8990168bf0dSLiam Girdwood cpu_dai->driver->remove_order == order) { 900f0fba2adSLiam Girdwood if (cpu_dai->driver->remove) { 901f0fba2adSLiam Girdwood err = cpu_dai->driver->remove(cpu_dai); 902f0fba2adSLiam Girdwood if (err < 0) 903f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name); 904f0fba2adSLiam Girdwood } 905f0fba2adSLiam Girdwood cpu_dai->probed = 0; 906f0fba2adSLiam Girdwood list_del(&cpu_dai->card_list); 907f0fba2adSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 908f0fba2adSLiam Girdwood } 909f0fba2adSLiam Girdwood } 910f0fba2adSLiam Girdwood 9110671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 9120671fd8eSKuninori Morimoto { 9130168bf0dSLiam Girdwood int dai, order; 9140671fd8eSKuninori Morimoto 9150168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 9160168bf0dSLiam Girdwood order++) { 9170168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 9180168bf0dSLiam Girdwood soc_remove_dai_link(card, dai, order); 9190168bf0dSLiam Girdwood } 9200671fd8eSKuninori Morimoto card->num_rtd = 0; 9210671fd8eSKuninori Morimoto } 9220671fd8eSKuninori Morimoto 923ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 924ead9b919SJarkko Nikula struct snd_soc_codec *codec) 925ead9b919SJarkko Nikula { 926ead9b919SJarkko Nikula int i; 927ead9b919SJarkko Nikula 928ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 929ead9b919SJarkko Nikula return; 930ead9b919SJarkko Nikula 931ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 932ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 933ead9b919SJarkko Nikula if (map->dev_name && !strcmp(codec->name, map->dev_name)) { 934ead9b919SJarkko Nikula codec->name_prefix = map->name_prefix; 935ead9b919SJarkko Nikula break; 936ead9b919SJarkko Nikula } 937ead9b919SJarkko Nikula } 938ead9b919SJarkko Nikula } 939ead9b919SJarkko Nikula 940589c3563SJarkko Nikula static int soc_probe_codec(struct snd_soc_card *card, 941589c3563SJarkko Nikula struct snd_soc_codec *codec) 942589c3563SJarkko Nikula { 943589c3563SJarkko Nikula int ret = 0; 94489b95ac0SMark Brown const struct snd_soc_codec_driver *driver = codec->driver; 945589c3563SJarkko Nikula 946589c3563SJarkko Nikula codec->card = card; 947589c3563SJarkko Nikula codec->dapm.card = card; 948589c3563SJarkko Nikula soc_set_name_prefix(card, codec); 949589c3563SJarkko Nikula 95070d29331SJarkko Nikula if (!try_module_get(codec->dev->driver->owner)) 95170d29331SJarkko Nikula return -ENODEV; 95270d29331SJarkko Nikula 953d5d1e0beSLars-Peter Clausen soc_init_codec_debugfs(codec); 954d5d1e0beSLars-Peter Clausen 95577530150SLars-Peter Clausen if (driver->dapm_widgets) 95677530150SLars-Peter Clausen snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, 95777530150SLars-Peter Clausen driver->num_dapm_widgets); 95877530150SLars-Peter Clausen 95989b95ac0SMark Brown if (driver->probe) { 96089b95ac0SMark Brown ret = driver->probe(codec); 961589c3563SJarkko Nikula if (ret < 0) { 962589c3563SJarkko Nikula dev_err(codec->dev, 963589c3563SJarkko Nikula "asoc: failed to probe CODEC %s: %d\n", 964589c3563SJarkko Nikula codec->name, ret); 96570d29331SJarkko Nikula goto err_probe; 966589c3563SJarkko Nikula } 967589c3563SJarkko Nikula } 968589c3563SJarkko Nikula 969b7af1dafSMark Brown if (driver->controls) 970b7af1dafSMark Brown snd_soc_add_controls(codec, driver->controls, 971b7af1dafSMark Brown driver->num_controls); 97289b95ac0SMark Brown if (driver->dapm_routes) 97389b95ac0SMark Brown snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, 97489b95ac0SMark Brown driver->num_dapm_routes); 97589b95ac0SMark Brown 976589c3563SJarkko Nikula /* mark codec as probed and add to card codec list */ 977589c3563SJarkko Nikula codec->probed = 1; 978589c3563SJarkko Nikula list_add(&codec->card_list, &card->codec_dev_list); 9797be31be8SJarkko Nikula list_add(&codec->dapm.list, &card->dapm_list); 980589c3563SJarkko Nikula 98170d29331SJarkko Nikula return 0; 98270d29331SJarkko Nikula 98370d29331SJarkko Nikula err_probe: 984d5d1e0beSLars-Peter Clausen soc_cleanup_codec_debugfs(codec); 98570d29331SJarkko Nikula module_put(codec->dev->driver->owner); 98670d29331SJarkko Nikula 987589c3563SJarkko Nikula return ret; 988589c3563SJarkko Nikula } 989589c3563SJarkko Nikula 990956245e9SLiam Girdwood static int soc_probe_platform(struct snd_soc_card *card, 991956245e9SLiam Girdwood struct snd_soc_platform *platform) 992956245e9SLiam Girdwood { 993956245e9SLiam Girdwood int ret = 0; 994956245e9SLiam Girdwood const struct snd_soc_platform_driver *driver = platform->driver; 995956245e9SLiam Girdwood 996956245e9SLiam Girdwood platform->card = card; 997b7950641SLiam Girdwood platform->dapm.card = card; 998956245e9SLiam Girdwood 999956245e9SLiam Girdwood if (!try_module_get(platform->dev->driver->owner)) 1000956245e9SLiam Girdwood return -ENODEV; 1001956245e9SLiam Girdwood 1002cb2cf612SLiam Girdwood if (driver->dapm_widgets) 1003cb2cf612SLiam Girdwood snd_soc_dapm_new_controls(&platform->dapm, 1004cb2cf612SLiam Girdwood driver->dapm_widgets, driver->num_dapm_widgets); 1005cb2cf612SLiam Girdwood 1006956245e9SLiam Girdwood if (driver->probe) { 1007956245e9SLiam Girdwood ret = driver->probe(platform); 1008956245e9SLiam Girdwood if (ret < 0) { 1009956245e9SLiam Girdwood dev_err(platform->dev, 1010956245e9SLiam Girdwood "asoc: failed to probe platform %s: %d\n", 1011956245e9SLiam Girdwood platform->name, ret); 1012956245e9SLiam Girdwood goto err_probe; 1013956245e9SLiam Girdwood } 1014956245e9SLiam Girdwood } 1015956245e9SLiam Girdwood 1016cb2cf612SLiam Girdwood if (driver->controls) 1017cb2cf612SLiam Girdwood snd_soc_add_platform_controls(platform, driver->controls, 1018cb2cf612SLiam Girdwood driver->num_controls); 1019cb2cf612SLiam Girdwood if (driver->dapm_routes) 1020cb2cf612SLiam Girdwood snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, 1021cb2cf612SLiam Girdwood driver->num_dapm_routes); 1022cb2cf612SLiam Girdwood 1023956245e9SLiam Girdwood /* mark platform as probed and add to card platform list */ 1024956245e9SLiam Girdwood platform->probed = 1; 1025956245e9SLiam Girdwood list_add(&platform->card_list, &card->platform_dev_list); 1026b7950641SLiam Girdwood list_add(&platform->dapm.list, &card->dapm_list); 1027956245e9SLiam Girdwood 1028956245e9SLiam Girdwood return 0; 1029956245e9SLiam Girdwood 1030956245e9SLiam Girdwood err_probe: 1031956245e9SLiam Girdwood module_put(platform->dev->driver->owner); 1032956245e9SLiam Girdwood 1033956245e9SLiam Girdwood return ret; 1034956245e9SLiam Girdwood } 1035956245e9SLiam Girdwood 1036f0fba2adSLiam Girdwood static void rtd_release(struct device *dev) {} 1037f0fba2adSLiam Girdwood 1038589c3563SJarkko Nikula static int soc_post_component_init(struct snd_soc_card *card, 1039589c3563SJarkko Nikula struct snd_soc_codec *codec, 1040589c3563SJarkko Nikula int num, int dailess) 1041589c3563SJarkko Nikula { 1042589c3563SJarkko Nikula struct snd_soc_dai_link *dai_link = NULL; 1043589c3563SJarkko Nikula struct snd_soc_aux_dev *aux_dev = NULL; 1044589c3563SJarkko Nikula struct snd_soc_pcm_runtime *rtd; 1045589c3563SJarkko Nikula const char *temp, *name; 1046589c3563SJarkko Nikula int ret = 0; 1047589c3563SJarkko Nikula 1048589c3563SJarkko Nikula if (!dailess) { 1049589c3563SJarkko Nikula dai_link = &card->dai_link[num]; 1050589c3563SJarkko Nikula rtd = &card->rtd[num]; 1051589c3563SJarkko Nikula name = dai_link->name; 1052589c3563SJarkko Nikula } else { 1053589c3563SJarkko Nikula aux_dev = &card->aux_dev[num]; 1054589c3563SJarkko Nikula rtd = &card->rtd_aux[num]; 1055589c3563SJarkko Nikula name = aux_dev->name; 1056589c3563SJarkko Nikula } 10570962bb21SJanusz Krzysztofik rtd->card = card; 1058589c3563SJarkko Nikula 1059589c3563SJarkko Nikula /* machine controls, routes and widgets are not prefixed */ 1060589c3563SJarkko Nikula temp = codec->name_prefix; 1061589c3563SJarkko Nikula codec->name_prefix = NULL; 1062589c3563SJarkko Nikula 1063589c3563SJarkko Nikula /* do machine specific initialization */ 1064589c3563SJarkko Nikula if (!dailess && dai_link->init) 1065589c3563SJarkko Nikula ret = dai_link->init(rtd); 1066589c3563SJarkko Nikula else if (dailess && aux_dev->init) 1067589c3563SJarkko Nikula ret = aux_dev->init(&codec->dapm); 1068589c3563SJarkko Nikula if (ret < 0) { 1069589c3563SJarkko Nikula dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret); 1070589c3563SJarkko Nikula return ret; 1071589c3563SJarkko Nikula } 1072589c3563SJarkko Nikula codec->name_prefix = temp; 1073589c3563SJarkko Nikula 1074589c3563SJarkko Nikula /* Make sure all DAPM widgets are instantiated */ 1075589c3563SJarkko Nikula snd_soc_dapm_new_widgets(&codec->dapm); 1076589c3563SJarkko Nikula 1077589c3563SJarkko Nikula /* register the rtd device */ 1078589c3563SJarkko Nikula rtd->codec = codec; 1079589c3563SJarkko Nikula rtd->dev.parent = card->dev; 1080589c3563SJarkko Nikula rtd->dev.release = rtd_release; 1081589c3563SJarkko Nikula rtd->dev.init_name = name; 1082b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 1083589c3563SJarkko Nikula ret = device_register(&rtd->dev); 1084589c3563SJarkko Nikula if (ret < 0) { 1085589c3563SJarkko Nikula dev_err(card->dev, 1086589c3563SJarkko Nikula "asoc: failed to register runtime device: %d\n", ret); 1087589c3563SJarkko Nikula return ret; 1088589c3563SJarkko Nikula } 1089589c3563SJarkko Nikula rtd->dev_registered = 1; 1090589c3563SJarkko Nikula 1091589c3563SJarkko Nikula /* add DAPM sysfs entries for this codec */ 1092589c3563SJarkko Nikula ret = snd_soc_dapm_sys_add(&rtd->dev); 1093589c3563SJarkko Nikula if (ret < 0) 1094589c3563SJarkko Nikula dev_err(codec->dev, 1095589c3563SJarkko Nikula "asoc: failed to add codec dapm sysfs entries: %d\n", 1096589c3563SJarkko Nikula ret); 1097589c3563SJarkko Nikula 1098589c3563SJarkko Nikula /* add codec sysfs entries */ 1099589c3563SJarkko Nikula ret = device_create_file(&rtd->dev, &dev_attr_codec_reg); 1100589c3563SJarkko Nikula if (ret < 0) 1101589c3563SJarkko Nikula dev_err(codec->dev, 1102589c3563SJarkko Nikula "asoc: failed to add codec sysfs files: %d\n", ret); 1103589c3563SJarkko Nikula 1104589c3563SJarkko Nikula return 0; 1105589c3563SJarkko Nikula } 1106589c3563SJarkko Nikula 11070168bf0dSLiam Girdwood static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) 1108f0fba2adSLiam Girdwood { 1109f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1110f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1111f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 1112f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 1113f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1114f0fba2adSLiam Girdwood int ret; 1115f0fba2adSLiam Girdwood 11160168bf0dSLiam Girdwood dev_dbg(card->dev, "probe %s dai link %d late %d\n", 11170168bf0dSLiam Girdwood card->name, num, order); 1118f0fba2adSLiam Girdwood 1119f0fba2adSLiam Girdwood /* config components */ 1120f0fba2adSLiam Girdwood codec_dai->codec = codec; 1121f0fba2adSLiam Girdwood cpu_dai->platform = platform; 1122f0fba2adSLiam Girdwood codec_dai->card = card; 1123f0fba2adSLiam Girdwood cpu_dai->card = card; 1124f0fba2adSLiam Girdwood 1125f0fba2adSLiam Girdwood /* set default power off timeout */ 1126f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1127f0fba2adSLiam Girdwood 1128f0fba2adSLiam Girdwood /* probe the cpu_dai */ 11290168bf0dSLiam Girdwood if (!cpu_dai->probed && 11300168bf0dSLiam Girdwood cpu_dai->driver->probe_order == order) { 113161b61e3cSLiam Girdwood if (!try_module_get(cpu_dai->dev->driver->owner)) 113261b61e3cSLiam Girdwood return -ENODEV; 113361b61e3cSLiam Girdwood 1134f0fba2adSLiam Girdwood if (cpu_dai->driver->probe) { 1135f0fba2adSLiam Girdwood ret = cpu_dai->driver->probe(cpu_dai); 1136f0fba2adSLiam Girdwood if (ret < 0) { 1137f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n", 1138f0fba2adSLiam Girdwood cpu_dai->name); 113961b61e3cSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 1140f0fba2adSLiam Girdwood return ret; 1141f0fba2adSLiam Girdwood } 1142f0fba2adSLiam Girdwood } 1143f0fba2adSLiam Girdwood cpu_dai->probed = 1; 11441c8371d6SWolfram Sang /* mark cpu_dai as probed and add to card dai list */ 1145f0fba2adSLiam Girdwood list_add(&cpu_dai->card_list, &card->dai_dev_list); 1146f0fba2adSLiam Girdwood } 1147f0fba2adSLiam Girdwood 1148f0fba2adSLiam Girdwood /* probe the CODEC */ 11490168bf0dSLiam Girdwood if (!codec->probed && 11500168bf0dSLiam Girdwood codec->driver->probe_order == order) { 1151589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 1152589c3563SJarkko Nikula if (ret < 0) 1153f0fba2adSLiam Girdwood return ret; 1154f0fba2adSLiam Girdwood } 1155f0fba2adSLiam Girdwood 1156f0fba2adSLiam Girdwood /* probe the platform */ 11570168bf0dSLiam Girdwood if (!platform->probed && 11580168bf0dSLiam Girdwood platform->driver->probe_order == order) { 1159956245e9SLiam Girdwood ret = soc_probe_platform(card, platform); 1160956245e9SLiam Girdwood if (ret < 0) 1161f0fba2adSLiam Girdwood return ret; 1162f0fba2adSLiam Girdwood } 1163f0fba2adSLiam Girdwood 1164f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 11650168bf0dSLiam Girdwood if (!codec_dai->probed && codec_dai->driver->probe_order == order) { 1166f0fba2adSLiam Girdwood if (codec_dai->driver->probe) { 1167f0fba2adSLiam Girdwood ret = codec_dai->driver->probe(codec_dai); 1168f0fba2adSLiam Girdwood if (ret < 0) { 1169f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n", 1170f0fba2adSLiam Girdwood codec_dai->name); 1171f0fba2adSLiam Girdwood return ret; 1172f0fba2adSLiam Girdwood } 1173f0fba2adSLiam Girdwood } 1174f0fba2adSLiam Girdwood 11751c8371d6SWolfram Sang /* mark codec_dai as probed and add to card dai list */ 1176f0fba2adSLiam Girdwood codec_dai->probed = 1; 1177f0fba2adSLiam Girdwood list_add(&codec_dai->card_list, &card->dai_dev_list); 1178f0fba2adSLiam Girdwood } 1179f0fba2adSLiam Girdwood 11800168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 11810168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 11820168bf0dSLiam Girdwood return 0; 11830168bf0dSLiam Girdwood 1184589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 0); 1185589c3563SJarkko Nikula if (ret) 1186f0fba2adSLiam Girdwood return ret; 1187f0fba2adSLiam Girdwood 1188f0fba2adSLiam Girdwood ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); 1189f0fba2adSLiam Girdwood if (ret < 0) 1190f0fba2adSLiam Girdwood printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); 1191f0fba2adSLiam Girdwood 1192f0fba2adSLiam Girdwood /* create the pcm */ 1193f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1194f0fba2adSLiam Girdwood if (ret < 0) { 1195f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name); 1196f0fba2adSLiam Girdwood return ret; 1197f0fba2adSLiam Girdwood } 1198f0fba2adSLiam Girdwood 1199f0fba2adSLiam Girdwood /* add platform data for AC97 devices */ 1200f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control) 1201f0fba2adSLiam Girdwood snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); 1202f0fba2adSLiam Girdwood 1203f0fba2adSLiam Girdwood return 0; 1204f0fba2adSLiam Girdwood } 1205f0fba2adSLiam Girdwood 1206f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1207f0fba2adSLiam Girdwood static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) 1208f0fba2adSLiam Girdwood { 1209f0fba2adSLiam Girdwood int ret; 1210f0fba2adSLiam Girdwood 1211f0fba2adSLiam Girdwood /* Only instantiate AC97 if not already done by the adaptor 1212f0fba2adSLiam Girdwood * for the generic AC97 subsystem. 12136b05eda6SMark Brown */ 1214f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { 12150562f788SMika Westerberg /* 12160562f788SMika Westerberg * It is possible that the AC97 device is already registered to 12170562f788SMika Westerberg * the device subsystem. This happens when the device is created 12180562f788SMika Westerberg * via snd_ac97_mixer(). Currently only SoC codec that does so 12190562f788SMika Westerberg * is the generic AC97 glue but others migh emerge. 12200562f788SMika Westerberg * 12210562f788SMika Westerberg * In those cases we don't try to register the device again. 12220562f788SMika Westerberg */ 12230562f788SMika Westerberg if (!rtd->codec->ac97_created) 12240562f788SMika Westerberg return 0; 1225f0fba2adSLiam Girdwood 1226f0fba2adSLiam Girdwood ret = soc_ac97_dev_register(rtd->codec); 1227f0fba2adSLiam Girdwood if (ret < 0) { 1228f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: AC97 device register failed\n"); 1229f0fba2adSLiam Girdwood return ret; 1230435c5e25SMark Brown } 1231435c5e25SMark Brown 1232f0fba2adSLiam Girdwood rtd->codec->ac97_registered = 1; 1233f0fba2adSLiam Girdwood } 1234f0fba2adSLiam Girdwood return 0; 1235f0fba2adSLiam Girdwood } 1236435c5e25SMark Brown 1237f0fba2adSLiam Girdwood static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) 1238f0fba2adSLiam Girdwood { 1239f0fba2adSLiam Girdwood if (codec->ac97_registered) { 1240f0fba2adSLiam Girdwood soc_ac97_dev_unregister(codec); 1241f0fba2adSLiam Girdwood codec->ac97_registered = 0; 1242f0fba2adSLiam Girdwood } 1243f0fba2adSLiam Girdwood } 1244f0fba2adSLiam Girdwood #endif 1245435c5e25SMark Brown 12462eea392dSJarkko Nikula static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 12472eea392dSJarkko Nikula { 12482eea392dSJarkko Nikula struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 12492eea392dSJarkko Nikula struct snd_soc_codec *codec; 1250676ad98aSJarkko Nikula int ret = -ENODEV; 12512eea392dSJarkko Nikula 12522eea392dSJarkko Nikula /* find CODEC from registered CODECs*/ 12532eea392dSJarkko Nikula list_for_each_entry(codec, &codec_list, list) { 12542eea392dSJarkko Nikula if (!strcmp(codec->name, aux_dev->codec_name)) { 12552eea392dSJarkko Nikula if (codec->probed) { 12562eea392dSJarkko Nikula dev_err(codec->dev, 12572eea392dSJarkko Nikula "asoc: codec already probed"); 12582eea392dSJarkko Nikula ret = -EBUSY; 12592eea392dSJarkko Nikula goto out; 12602eea392dSJarkko Nikula } 1261676ad98aSJarkko Nikula goto found; 12622eea392dSJarkko Nikula } 12632eea392dSJarkko Nikula } 1264676ad98aSJarkko Nikula /* codec not found */ 1265676ad98aSJarkko Nikula dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); 1266676ad98aSJarkko Nikula goto out; 12672eea392dSJarkko Nikula 1268676ad98aSJarkko Nikula found: 1269589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 12702eea392dSJarkko Nikula if (ret < 0) 1271589c3563SJarkko Nikula return ret; 12722eea392dSJarkko Nikula 1273589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 1); 12742eea392dSJarkko Nikula 12752eea392dSJarkko Nikula out: 12762eea392dSJarkko Nikula return ret; 12772eea392dSJarkko Nikula } 12782eea392dSJarkko Nikula 12792eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 12802eea392dSJarkko Nikula { 12812eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 12822eea392dSJarkko Nikula struct snd_soc_codec *codec = rtd->codec; 12832eea392dSJarkko Nikula 12842eea392dSJarkko Nikula /* unregister the rtd device */ 12852eea392dSJarkko Nikula if (rtd->dev_registered) { 1286589c3563SJarkko Nikula device_remove_file(&rtd->dev, &dev_attr_codec_reg); 12872eea392dSJarkko Nikula device_unregister(&rtd->dev); 12882eea392dSJarkko Nikula rtd->dev_registered = 0; 12892eea392dSJarkko Nikula } 12902eea392dSJarkko Nikula 1291589c3563SJarkko Nikula if (codec && codec->probed) 1292589c3563SJarkko Nikula soc_remove_codec(codec); 12932eea392dSJarkko Nikula } 12942eea392dSJarkko Nikula 1295fdf0f54dSDimitris Papastamos static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, 1296fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type) 1297fdf0f54dSDimitris Papastamos { 1298fdf0f54dSDimitris Papastamos int ret; 1299fdf0f54dSDimitris Papastamos 1300fdf0f54dSDimitris Papastamos if (codec->cache_init) 1301fdf0f54dSDimitris Papastamos return 0; 1302fdf0f54dSDimitris Papastamos 1303fdf0f54dSDimitris Papastamos /* override the compress_type if necessary */ 1304fdf0f54dSDimitris Papastamos if (compress_type && codec->compress_type != compress_type) 1305fdf0f54dSDimitris Papastamos codec->compress_type = compress_type; 1306fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1307fdf0f54dSDimitris Papastamos if (ret < 0) { 1308fdf0f54dSDimitris Papastamos dev_err(codec->dev, "Failed to set cache compression type: %d\n", 1309fdf0f54dSDimitris Papastamos ret); 1310fdf0f54dSDimitris Papastamos return ret; 1311fdf0f54dSDimitris Papastamos } 1312fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1313fdf0f54dSDimitris Papastamos return 0; 1314fdf0f54dSDimitris Papastamos } 1315fdf0f54dSDimitris Papastamos 1316f0fba2adSLiam Girdwood static void snd_soc_instantiate_card(struct snd_soc_card *card) 1317f0fba2adSLiam Girdwood { 1318fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1319fdf0f54dSDimitris Papastamos struct snd_soc_codec_conf *codec_conf; 1320fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type; 13210168bf0dSLiam Girdwood int ret, i, order; 132296dd3622SMark Brown 1323f0fba2adSLiam Girdwood mutex_lock(&card->mutex); 1324f0fba2adSLiam Girdwood 1325f0fba2adSLiam Girdwood if (card->instantiated) { 1326f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1327435c5e25SMark Brown return; 1328db2a4165SFrank Mandarino } 1329db2a4165SFrank Mandarino 1330f0fba2adSLiam Girdwood /* bind DAIs */ 1331f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 1332f0fba2adSLiam Girdwood soc_bind_dai_link(card, i); 1333f0fba2adSLiam Girdwood 1334f0fba2adSLiam Girdwood /* bind completed ? */ 1335f0fba2adSLiam Girdwood if (card->num_rtd != card->num_links) { 1336f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1337f0fba2adSLiam Girdwood return; 1338db2a4165SFrank Mandarino } 1339db2a4165SFrank Mandarino 1340fdf0f54dSDimitris Papastamos /* initialize the register cache for each available codec */ 1341fdf0f54dSDimitris Papastamos list_for_each_entry(codec, &codec_list, list) { 1342fdf0f54dSDimitris Papastamos if (codec->cache_init) 1343fdf0f54dSDimitris Papastamos continue; 1344861f2fafSDimitris Papastamos /* by default we don't override the compress_type */ 1345861f2fafSDimitris Papastamos compress_type = 0; 1346fdf0f54dSDimitris Papastamos /* check to see if we need to override the compress_type */ 1347fdf0f54dSDimitris Papastamos for (i = 0; i < card->num_configs; ++i) { 1348fdf0f54dSDimitris Papastamos codec_conf = &card->codec_conf[i]; 1349fdf0f54dSDimitris Papastamos if (!strcmp(codec->name, codec_conf->dev_name)) { 1350fdf0f54dSDimitris Papastamos compress_type = codec_conf->compress_type; 1351fdf0f54dSDimitris Papastamos if (compress_type && compress_type 1352fdf0f54dSDimitris Papastamos != codec->compress_type) 1353fdf0f54dSDimitris Papastamos break; 1354fdf0f54dSDimitris Papastamos } 1355fdf0f54dSDimitris Papastamos } 1356fdf0f54dSDimitris Papastamos ret = snd_soc_init_codec_cache(codec, compress_type); 1357fdf0f54dSDimitris Papastamos if (ret < 0) { 1358fdf0f54dSDimitris Papastamos mutex_unlock(&card->mutex); 1359fdf0f54dSDimitris Papastamos return; 1360fdf0f54dSDimitris Papastamos } 1361fdf0f54dSDimitris Papastamos } 1362fdf0f54dSDimitris Papastamos 1363f0fba2adSLiam Girdwood /* card bind complete so register a sound card */ 1364f0fba2adSLiam Girdwood ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1365f0fba2adSLiam Girdwood card->owner, 0, &card->snd_card); 1366f0fba2adSLiam Girdwood if (ret < 0) { 1367f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: can't create sound card for card %s\n", 1368f0fba2adSLiam Girdwood card->name); 1369f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1370f0fba2adSLiam Girdwood return; 1371db2a4165SFrank Mandarino } 1372f0fba2adSLiam Girdwood card->snd_card->dev = card->dev; 1373db2a4165SFrank Mandarino 1374e37a4970SMark Brown card->dapm.bias_level = SND_SOC_BIAS_OFF; 1375e37a4970SMark Brown card->dapm.dev = card->dev; 1376e37a4970SMark Brown card->dapm.card = card; 1377e37a4970SMark Brown list_add(&card->dapm.list, &card->dapm_list); 1378e37a4970SMark Brown 1379d5d1e0beSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 1380d5d1e0beSLars-Peter Clausen snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); 1381d5d1e0beSLars-Peter Clausen #endif 1382d5d1e0beSLars-Peter Clausen 138388ee1c61SMark Brown #ifdef CONFIG_PM_SLEEP 13846ed25978SAndy Green /* deferred resume work */ 13856308419aSMark Brown INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 13861301a964SRandy Dunlap #endif 13876ed25978SAndy Green 13889a841ebbSMark Brown if (card->dapm_widgets) 13899a841ebbSMark Brown snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 13909a841ebbSMark Brown card->num_dapm_widgets); 13919a841ebbSMark Brown 1392f0fba2adSLiam Girdwood /* initialise the sound card only once */ 1393f0fba2adSLiam Girdwood if (card->probe) { 1394e7361ec4SMark Brown ret = card->probe(card); 1395f0fba2adSLiam Girdwood if (ret < 0) 1396f0fba2adSLiam Girdwood goto card_probe_error; 1397f0fba2adSLiam Girdwood } 1398f0fba2adSLiam Girdwood 13990168bf0dSLiam Girdwood /* early DAI link probe */ 14000168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 14010168bf0dSLiam Girdwood order++) { 1402fe3e78e0SMark Brown for (i = 0; i < card->num_links; i++) { 14030168bf0dSLiam Girdwood ret = soc_probe_dai_link(card, i, order); 1404fe3e78e0SMark Brown if (ret < 0) { 1405321de0d0SMark Brown pr_err("asoc: failed to instantiate card %s: %d\n", 1406321de0d0SMark Brown card->name, ret); 1407f0fba2adSLiam Girdwood goto probe_dai_err; 1408fe3e78e0SMark Brown } 1409fe3e78e0SMark Brown } 14100168bf0dSLiam Girdwood } 1411fe3e78e0SMark Brown 14122eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) { 14132eea392dSJarkko Nikula ret = soc_probe_aux_dev(card, i); 14142eea392dSJarkko Nikula if (ret < 0) { 14152eea392dSJarkko Nikula pr_err("asoc: failed to add auxiliary devices %s: %d\n", 14162eea392dSJarkko Nikula card->name, ret); 14172eea392dSJarkko Nikula goto probe_aux_dev_err; 14182eea392dSJarkko Nikula } 14192eea392dSJarkko Nikula } 14202eea392dSJarkko Nikula 1421b7af1dafSMark Brown /* We should have a non-codec control add function but we don't */ 1422b7af1dafSMark Brown if (card->controls) 1423b7af1dafSMark Brown snd_soc_add_controls(list_first_entry(&card->codec_dev_list, 1424b7af1dafSMark Brown struct snd_soc_codec, 1425b7af1dafSMark Brown card_list), 1426b7af1dafSMark Brown card->controls, 1427b7af1dafSMark Brown card->num_controls); 1428b7af1dafSMark Brown 1429b8ad29deSMark Brown if (card->dapm_routes) 1430b8ad29deSMark Brown snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1431b8ad29deSMark Brown card->num_dapm_routes); 1432b8ad29deSMark Brown 1433f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1434fe3e78e0SMark Brown "%s", card->name); 1435f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 143622de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1437873bd4cbSTakashi Iwai if (card->driver_name) 1438873bd4cbSTakashi Iwai strlcpy(card->snd_card->driver, card->driver_name, 1439873bd4cbSTakashi Iwai sizeof(card->snd_card->driver)); 1440fe3e78e0SMark Brown 144128e9ad92SMark Brown if (card->late_probe) { 144228e9ad92SMark Brown ret = card->late_probe(card); 144328e9ad92SMark Brown if (ret < 0) { 144428e9ad92SMark Brown dev_err(card->dev, "%s late_probe() failed: %d\n", 144528e9ad92SMark Brown card->name, ret); 144628e9ad92SMark Brown goto probe_aux_dev_err; 144728e9ad92SMark Brown } 144828e9ad92SMark Brown } 144928e9ad92SMark Brown 1450f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1451fe3e78e0SMark Brown if (ret < 0) { 1452f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name); 14536b3ed785SAxel Lin goto probe_aux_dev_err; 1454fe3e78e0SMark Brown } 1455fe3e78e0SMark Brown 1456fe3e78e0SMark Brown #ifdef CONFIG_SND_SOC_AC97_BUS 1457f0fba2adSLiam Girdwood /* register any AC97 codecs */ 1458f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1459f0fba2adSLiam Girdwood ret = soc_register_ac97_dai_link(&card->rtd[i]); 1460fe3e78e0SMark Brown if (ret < 0) { 1461f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); 14626b3ed785SAxel Lin while (--i >= 0) 14637d8316dfSMark Brown soc_unregister_ac97_dai_link(card->rtd[i].codec); 14646b3ed785SAxel Lin goto probe_aux_dev_err; 1465fe3e78e0SMark Brown } 1466fe3e78e0SMark Brown } 1467fe3e78e0SMark Brown #endif 1468fe3e78e0SMark Brown 1469435c5e25SMark Brown card->instantiated = 1; 1470f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1471435c5e25SMark Brown return; 1472db2a4165SFrank Mandarino 14732eea392dSJarkko Nikula probe_aux_dev_err: 14742eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 14752eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 14762eea392dSJarkko Nikula 1477f0fba2adSLiam Girdwood probe_dai_err: 14780671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1479fe3e78e0SMark Brown 1480f0fba2adSLiam Girdwood card_probe_error: 148187506549SMark Brown if (card->remove) 1482e7361ec4SMark Brown card->remove(card); 1483f0fba2adSLiam Girdwood 1484f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1485f0fba2adSLiam Girdwood 1486f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1487435c5e25SMark Brown } 1488db2a4165SFrank Mandarino 1489435c5e25SMark Brown /* 1490421f91d2SUwe Kleine-König * Attempt to initialise any uninitialised cards. Must be called with 1491435c5e25SMark Brown * client_mutex. 1492435c5e25SMark Brown */ 1493435c5e25SMark Brown static void snd_soc_instantiate_cards(void) 1494435c5e25SMark Brown { 1495435c5e25SMark Brown struct snd_soc_card *card; 1496435c5e25SMark Brown list_for_each_entry(card, &card_list, list) 1497435c5e25SMark Brown snd_soc_instantiate_card(card); 1498435c5e25SMark Brown } 1499435c5e25SMark Brown 1500435c5e25SMark Brown /* probes a new socdev */ 1501435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1502435c5e25SMark Brown { 1503f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1504435c5e25SMark Brown int ret = 0; 1505435c5e25SMark Brown 150670a7ca34SVinod Koul /* 150770a7ca34SVinod Koul * no card, so machine driver should be registering card 150870a7ca34SVinod Koul * we should not be here in that case so ret error 150970a7ca34SVinod Koul */ 151070a7ca34SVinod Koul if (!card) 151170a7ca34SVinod Koul return -EINVAL; 151270a7ca34SVinod Koul 1513435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1514435c5e25SMark Brown card->dev = &pdev->dev; 1515f0fba2adSLiam Girdwood 1516435c5e25SMark Brown ret = snd_soc_register_card(card); 1517435c5e25SMark Brown if (ret != 0) { 1518435c5e25SMark Brown dev_err(&pdev->dev, "Failed to register card\n"); 1519db2a4165SFrank Mandarino return ret; 1520db2a4165SFrank Mandarino } 1521db2a4165SFrank Mandarino 1522435c5e25SMark Brown return 0; 1523435c5e25SMark Brown } 1524435c5e25SMark Brown 1525b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1526db2a4165SFrank Mandarino { 1527db2a4165SFrank Mandarino int i; 1528db2a4165SFrank Mandarino 1529f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1530f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1531f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 15325b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1533db2a4165SFrank Mandarino } 1534db2a4165SFrank Mandarino 15352eea392dSJarkko Nikula /* remove auxiliary devices */ 15362eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 15372eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 15382eea392dSJarkko Nikula 1539f0fba2adSLiam Girdwood /* remove and free each DAI */ 15400671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1541f0fba2adSLiam Girdwood 1542a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1543a6052154SJarkko Nikula 1544f0fba2adSLiam Girdwood /* remove the card */ 154587506549SMark Brown if (card->remove) 1546e7361ec4SMark Brown card->remove(card); 1547f0fba2adSLiam Girdwood 15480aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 15490aaae527SLars-Peter Clausen 1550f0fba2adSLiam Girdwood kfree(card->rtd); 1551f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1552b0e26485SVinod Koul return 0; 1553b0e26485SVinod Koul 1554b2dfa62cSGuennadi Liakhovetski } 1555b0e26485SVinod Koul 1556b0e26485SVinod Koul /* removes a socdev */ 1557b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1558b0e26485SVinod Koul { 1559b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1560b0e26485SVinod Koul 1561c5af3a2eSMark Brown snd_soc_unregister_card(card); 1562db2a4165SFrank Mandarino return 0; 1563db2a4165SFrank Mandarino } 1564db2a4165SFrank Mandarino 15656f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 156651737470SMark Brown { 15676f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1568f0fba2adSLiam Girdwood int i; 156951737470SMark Brown 157051737470SMark Brown if (!card->instantiated) 1571416356fcSMark Brown return 0; 157251737470SMark Brown 157351737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 157451737470SMark Brown * now, we're shutting down so no imminent restart. */ 1575f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1576f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 15775b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1578f0fba2adSLiam Girdwood } 157951737470SMark Brown 1580f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1581416356fcSMark Brown 1582416356fcSMark Brown return 0; 158351737470SMark Brown } 15846f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 158551737470SMark Brown 15866f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 15876f8ab4acSMark Brown .suspend = snd_soc_suspend, 15886f8ab4acSMark Brown .resume = snd_soc_resume, 15896f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1590416356fcSMark Brown }; 1591deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1592416356fcSMark Brown 1593db2a4165SFrank Mandarino /* ASoC platform driver */ 1594db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1595db2a4165SFrank Mandarino .driver = { 1596db2a4165SFrank Mandarino .name = "soc-audio", 15978b45a209SKay Sievers .owner = THIS_MODULE, 15986f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1599db2a4165SFrank Mandarino }, 1600db2a4165SFrank Mandarino .probe = soc_probe, 1601db2a4165SFrank Mandarino .remove = soc_remove, 1602db2a4165SFrank Mandarino }; 1603db2a4165SFrank Mandarino 1604096e49d5SMark Brown /** 1605096e49d5SMark Brown * snd_soc_codec_volatile_register: Report if a register is volatile. 1606096e49d5SMark Brown * 1607096e49d5SMark Brown * @codec: CODEC to query. 1608096e49d5SMark Brown * @reg: Register to query. 1609096e49d5SMark Brown * 1610096e49d5SMark Brown * Boolean function indiciating if a CODEC register is volatile. 1611096e49d5SMark Brown */ 1612181e055eSMark Brown int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, 1613181e055eSMark Brown unsigned int reg) 1614096e49d5SMark Brown { 16151500b7b5SDimitris Papastamos if (codec->volatile_register) 16161500b7b5SDimitris Papastamos return codec->volatile_register(codec, reg); 1617096e49d5SMark Brown else 1618096e49d5SMark Brown return 0; 1619096e49d5SMark Brown } 1620096e49d5SMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); 1621096e49d5SMark Brown 1622db2a4165SFrank Mandarino /** 1623239c9706SDimitris Papastamos * snd_soc_codec_readable_register: Report if a register is readable. 1624239c9706SDimitris Papastamos * 1625239c9706SDimitris Papastamos * @codec: CODEC to query. 1626239c9706SDimitris Papastamos * @reg: Register to query. 1627239c9706SDimitris Papastamos * 1628239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is readable. 1629239c9706SDimitris Papastamos */ 1630239c9706SDimitris Papastamos int snd_soc_codec_readable_register(struct snd_soc_codec *codec, 1631239c9706SDimitris Papastamos unsigned int reg) 1632239c9706SDimitris Papastamos { 1633239c9706SDimitris Papastamos if (codec->readable_register) 1634239c9706SDimitris Papastamos return codec->readable_register(codec, reg); 1635239c9706SDimitris Papastamos else 1636239c9706SDimitris Papastamos return 0; 1637239c9706SDimitris Papastamos } 1638239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); 1639239c9706SDimitris Papastamos 1640239c9706SDimitris Papastamos /** 1641239c9706SDimitris Papastamos * snd_soc_codec_writable_register: Report if a register is writable. 1642239c9706SDimitris Papastamos * 1643239c9706SDimitris Papastamos * @codec: CODEC to query. 1644239c9706SDimitris Papastamos * @reg: Register to query. 1645239c9706SDimitris Papastamos * 1646239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is writable. 1647239c9706SDimitris Papastamos */ 1648239c9706SDimitris Papastamos int snd_soc_codec_writable_register(struct snd_soc_codec *codec, 1649239c9706SDimitris Papastamos unsigned int reg) 1650239c9706SDimitris Papastamos { 1651239c9706SDimitris Papastamos if (codec->writable_register) 1652239c9706SDimitris Papastamos return codec->writable_register(codec, reg); 1653239c9706SDimitris Papastamos else 1654239c9706SDimitris Papastamos return 0; 1655239c9706SDimitris Papastamos } 1656239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); 1657239c9706SDimitris Papastamos 1658f1442bc1SLiam Girdwood int snd_soc_platform_read(struct snd_soc_platform *platform, 1659f1442bc1SLiam Girdwood unsigned int reg) 1660f1442bc1SLiam Girdwood { 1661f1442bc1SLiam Girdwood unsigned int ret; 1662f1442bc1SLiam Girdwood 1663f1442bc1SLiam Girdwood if (!platform->driver->read) { 1664f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no read back\n"); 1665f1442bc1SLiam Girdwood return -1; 1666f1442bc1SLiam Girdwood } 1667f1442bc1SLiam Girdwood 1668f1442bc1SLiam Girdwood ret = platform->driver->read(platform, reg); 1669f1442bc1SLiam Girdwood dev_dbg(platform->dev, "read %x => %x\n", reg, ret); 1670a82ce2aeSLiam Girdwood trace_snd_soc_preg_read(platform, reg, ret); 1671f1442bc1SLiam Girdwood 1672f1442bc1SLiam Girdwood return ret; 1673f1442bc1SLiam Girdwood } 1674f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_read); 1675f1442bc1SLiam Girdwood 1676f1442bc1SLiam Girdwood int snd_soc_platform_write(struct snd_soc_platform *platform, 1677f1442bc1SLiam Girdwood unsigned int reg, unsigned int val) 1678f1442bc1SLiam Girdwood { 1679f1442bc1SLiam Girdwood if (!platform->driver->write) { 1680f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no write back\n"); 1681f1442bc1SLiam Girdwood return -1; 1682f1442bc1SLiam Girdwood } 1683f1442bc1SLiam Girdwood 1684f1442bc1SLiam Girdwood dev_dbg(platform->dev, "write %x = %x\n", reg, val); 1685a82ce2aeSLiam Girdwood trace_snd_soc_preg_write(platform, reg, val); 1686f1442bc1SLiam Girdwood return platform->driver->write(platform, reg, val); 1687f1442bc1SLiam Girdwood } 1688f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_write); 1689f1442bc1SLiam Girdwood 1690239c9706SDimitris Papastamos /** 1691db2a4165SFrank Mandarino * snd_soc_new_ac97_codec - initailise AC97 device 1692db2a4165SFrank Mandarino * @codec: audio codec 1693db2a4165SFrank Mandarino * @ops: AC97 bus operations 1694db2a4165SFrank Mandarino * @num: AC97 codec number 1695db2a4165SFrank Mandarino * 1696db2a4165SFrank Mandarino * Initialises AC97 codec resources for use by ad-hoc devices only. 1697db2a4165SFrank Mandarino */ 1698db2a4165SFrank Mandarino int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 1699db2a4165SFrank Mandarino struct snd_ac97_bus_ops *ops, int num) 1700db2a4165SFrank Mandarino { 1701db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1702db2a4165SFrank Mandarino 1703db2a4165SFrank Mandarino codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 1704db2a4165SFrank Mandarino if (codec->ac97 == NULL) { 1705db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1706db2a4165SFrank Mandarino return -ENOMEM; 1707db2a4165SFrank Mandarino } 1708db2a4165SFrank Mandarino 1709db2a4165SFrank Mandarino codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); 1710db2a4165SFrank Mandarino if (codec->ac97->bus == NULL) { 1711db2a4165SFrank Mandarino kfree(codec->ac97); 1712db2a4165SFrank Mandarino codec->ac97 = NULL; 1713db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1714db2a4165SFrank Mandarino return -ENOMEM; 1715db2a4165SFrank Mandarino } 1716db2a4165SFrank Mandarino 1717db2a4165SFrank Mandarino codec->ac97->bus->ops = ops; 1718db2a4165SFrank Mandarino codec->ac97->num = num; 17190562f788SMika Westerberg 17200562f788SMika Westerberg /* 17210562f788SMika Westerberg * Mark the AC97 device to be created by us. This way we ensure that the 17220562f788SMika Westerberg * device will be registered with the device subsystem later on. 17230562f788SMika Westerberg */ 17240562f788SMika Westerberg codec->ac97_created = 1; 17250562f788SMika Westerberg 1726db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1727db2a4165SFrank Mandarino return 0; 1728db2a4165SFrank Mandarino } 1729db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 1730db2a4165SFrank Mandarino 1731db2a4165SFrank Mandarino /** 1732db2a4165SFrank Mandarino * snd_soc_free_ac97_codec - free AC97 codec device 1733db2a4165SFrank Mandarino * @codec: audio codec 1734db2a4165SFrank Mandarino * 1735db2a4165SFrank Mandarino * Frees AC97 codec device resources. 1736db2a4165SFrank Mandarino */ 1737db2a4165SFrank Mandarino void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 1738db2a4165SFrank Mandarino { 1739db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1740f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1741f0fba2adSLiam Girdwood soc_unregister_ac97_dai_link(codec); 1742f0fba2adSLiam Girdwood #endif 1743db2a4165SFrank Mandarino kfree(codec->ac97->bus); 1744db2a4165SFrank Mandarino kfree(codec->ac97); 1745db2a4165SFrank Mandarino codec->ac97 = NULL; 17460562f788SMika Westerberg codec->ac97_created = 0; 1747db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1748db2a4165SFrank Mandarino } 1749db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 1750db2a4165SFrank Mandarino 1751c3753707SMark Brown unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) 1752c3753707SMark Brown { 1753c3753707SMark Brown unsigned int ret; 1754c3753707SMark Brown 1755c3acec26SMark Brown ret = codec->read(codec, reg); 1756c3753707SMark Brown dev_dbg(codec->dev, "read %x => %x\n", reg, ret); 1757a8b1d34fSMark Brown trace_snd_soc_reg_read(codec, reg, ret); 1758c3753707SMark Brown 1759c3753707SMark Brown return ret; 1760c3753707SMark Brown } 1761c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_read); 1762c3753707SMark Brown 1763c3753707SMark Brown unsigned int snd_soc_write(struct snd_soc_codec *codec, 1764c3753707SMark Brown unsigned int reg, unsigned int val) 1765c3753707SMark Brown { 1766c3753707SMark Brown dev_dbg(codec->dev, "write %x = %x\n", reg, val); 1767a8b1d34fSMark Brown trace_snd_soc_reg_write(codec, reg, val); 1768c3acec26SMark Brown return codec->write(codec, reg, val); 1769c3753707SMark Brown } 1770c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_write); 1771c3753707SMark Brown 17725fb609d4SDimitris Papastamos unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, 17735fb609d4SDimitris Papastamos unsigned int reg, const void *data, size_t len) 17745fb609d4SDimitris Papastamos { 17755fb609d4SDimitris Papastamos return codec->bulk_write_raw(codec, reg, data, len); 17765fb609d4SDimitris Papastamos } 17775fb609d4SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); 17785fb609d4SDimitris Papastamos 1779db2a4165SFrank Mandarino /** 1780db2a4165SFrank Mandarino * snd_soc_update_bits - update codec register bits 1781db2a4165SFrank Mandarino * @codec: audio codec 1782db2a4165SFrank Mandarino * @reg: codec register 1783db2a4165SFrank Mandarino * @mask: register mask 1784db2a4165SFrank Mandarino * @value: new value 1785db2a4165SFrank Mandarino * 1786db2a4165SFrank Mandarino * Writes new register value. 1787db2a4165SFrank Mandarino * 1788180c329dSTimur Tabi * Returns 1 for change, 0 for no change, or negative error code. 1789db2a4165SFrank Mandarino */ 1790db2a4165SFrank Mandarino int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, 179146f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1792db2a4165SFrank Mandarino { 1793db2a4165SFrank Mandarino int change; 179446f5822fSDaniel Ribeiro unsigned int old, new; 1795180c329dSTimur Tabi int ret; 1796db2a4165SFrank Mandarino 1797180c329dSTimur Tabi ret = snd_soc_read(codec, reg); 1798180c329dSTimur Tabi if (ret < 0) 1799180c329dSTimur Tabi return ret; 1800180c329dSTimur Tabi 1801180c329dSTimur Tabi old = ret; 180278bf3c9aSMark Brown new = (old & ~mask) | (value & mask); 1803db2a4165SFrank Mandarino change = old != new; 1804180c329dSTimur Tabi if (change) { 1805180c329dSTimur Tabi ret = snd_soc_write(codec, reg, new); 1806180c329dSTimur Tabi if (ret < 0) 1807180c329dSTimur Tabi return ret; 1808180c329dSTimur Tabi } 1809db2a4165SFrank Mandarino 1810db2a4165SFrank Mandarino return change; 1811db2a4165SFrank Mandarino } 1812db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_update_bits); 1813db2a4165SFrank Mandarino 1814db2a4165SFrank Mandarino /** 18156c508c62SEero Nurkkala * snd_soc_update_bits_locked - update codec register bits 18166c508c62SEero Nurkkala * @codec: audio codec 18176c508c62SEero Nurkkala * @reg: codec register 18186c508c62SEero Nurkkala * @mask: register mask 18196c508c62SEero Nurkkala * @value: new value 18206c508c62SEero Nurkkala * 18216c508c62SEero Nurkkala * Writes new register value, and takes the codec mutex. 18226c508c62SEero Nurkkala * 18236c508c62SEero Nurkkala * Returns 1 for change else 0. 18246c508c62SEero Nurkkala */ 1825dd1b3d53SMark Brown int snd_soc_update_bits_locked(struct snd_soc_codec *codec, 18266c508c62SEero Nurkkala unsigned short reg, unsigned int mask, 18276c508c62SEero Nurkkala unsigned int value) 18286c508c62SEero Nurkkala { 18296c508c62SEero Nurkkala int change; 18306c508c62SEero Nurkkala 18316c508c62SEero Nurkkala mutex_lock(&codec->mutex); 18326c508c62SEero Nurkkala change = snd_soc_update_bits(codec, reg, mask, value); 18336c508c62SEero Nurkkala mutex_unlock(&codec->mutex); 18346c508c62SEero Nurkkala 18356c508c62SEero Nurkkala return change; 18366c508c62SEero Nurkkala } 1837dd1b3d53SMark Brown EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); 18386c508c62SEero Nurkkala 18396c508c62SEero Nurkkala /** 1840db2a4165SFrank Mandarino * snd_soc_test_bits - test register for change 1841db2a4165SFrank Mandarino * @codec: audio codec 1842db2a4165SFrank Mandarino * @reg: codec register 1843db2a4165SFrank Mandarino * @mask: register mask 1844db2a4165SFrank Mandarino * @value: new value 1845db2a4165SFrank Mandarino * 1846db2a4165SFrank Mandarino * Tests a register with a new value and checks if the new value is 1847db2a4165SFrank Mandarino * different from the old value. 1848db2a4165SFrank Mandarino * 1849db2a4165SFrank Mandarino * Returns 1 for change else 0. 1850db2a4165SFrank Mandarino */ 1851db2a4165SFrank Mandarino int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, 185246f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1853db2a4165SFrank Mandarino { 1854db2a4165SFrank Mandarino int change; 185546f5822fSDaniel Ribeiro unsigned int old, new; 1856db2a4165SFrank Mandarino 1857db2a4165SFrank Mandarino old = snd_soc_read(codec, reg); 1858db2a4165SFrank Mandarino new = (old & ~mask) | value; 1859db2a4165SFrank Mandarino change = old != new; 1860db2a4165SFrank Mandarino 1861db2a4165SFrank Mandarino return change; 1862db2a4165SFrank Mandarino } 1863db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_test_bits); 1864db2a4165SFrank Mandarino 1865db2a4165SFrank Mandarino /** 1866db2a4165SFrank Mandarino * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 1867db2a4165SFrank Mandarino * @substream: the pcm substream 1868db2a4165SFrank Mandarino * @hw: the hardware parameters 1869db2a4165SFrank Mandarino * 1870db2a4165SFrank Mandarino * Sets the substream runtime hardware parameters. 1871db2a4165SFrank Mandarino */ 1872db2a4165SFrank Mandarino int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 1873db2a4165SFrank Mandarino const struct snd_pcm_hardware *hw) 1874db2a4165SFrank Mandarino { 1875db2a4165SFrank Mandarino struct snd_pcm_runtime *runtime = substream->runtime; 1876db2a4165SFrank Mandarino runtime->hw.info = hw->info; 1877db2a4165SFrank Mandarino runtime->hw.formats = hw->formats; 1878db2a4165SFrank Mandarino runtime->hw.period_bytes_min = hw->period_bytes_min; 1879db2a4165SFrank Mandarino runtime->hw.period_bytes_max = hw->period_bytes_max; 1880db2a4165SFrank Mandarino runtime->hw.periods_min = hw->periods_min; 1881db2a4165SFrank Mandarino runtime->hw.periods_max = hw->periods_max; 1882db2a4165SFrank Mandarino runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; 1883db2a4165SFrank Mandarino runtime->hw.fifo_size = hw->fifo_size; 1884db2a4165SFrank Mandarino return 0; 1885db2a4165SFrank Mandarino } 1886db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); 1887db2a4165SFrank Mandarino 1888db2a4165SFrank Mandarino /** 1889db2a4165SFrank Mandarino * snd_soc_cnew - create new control 1890db2a4165SFrank Mandarino * @_template: control template 1891db2a4165SFrank Mandarino * @data: control private data 1892ac11a2b3SMark Brown * @long_name: control long name 1893efb7ac3fSMark Brown * @prefix: control name prefix 1894db2a4165SFrank Mandarino * 1895db2a4165SFrank Mandarino * Create a new mixer control from a template control. 1896db2a4165SFrank Mandarino * 1897db2a4165SFrank Mandarino * Returns 0 for success, else error. 1898db2a4165SFrank Mandarino */ 1899db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 1900efb7ac3fSMark Brown void *data, char *long_name, 1901efb7ac3fSMark Brown const char *prefix) 1902db2a4165SFrank Mandarino { 1903db2a4165SFrank Mandarino struct snd_kcontrol_new template; 1904efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 1905efb7ac3fSMark Brown char *name = NULL; 1906efb7ac3fSMark Brown int name_len; 1907db2a4165SFrank Mandarino 1908db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 1909db2a4165SFrank Mandarino template.index = 0; 1910db2a4165SFrank Mandarino 1911efb7ac3fSMark Brown if (!long_name) 1912efb7ac3fSMark Brown long_name = template.name; 1913efb7ac3fSMark Brown 1914efb7ac3fSMark Brown if (prefix) { 1915efb7ac3fSMark Brown name_len = strlen(long_name) + strlen(prefix) + 2; 1916efb7ac3fSMark Brown name = kmalloc(name_len, GFP_ATOMIC); 1917efb7ac3fSMark Brown if (!name) 1918efb7ac3fSMark Brown return NULL; 1919efb7ac3fSMark Brown 1920efb7ac3fSMark Brown snprintf(name, name_len, "%s %s", prefix, long_name); 1921efb7ac3fSMark Brown 1922efb7ac3fSMark Brown template.name = name; 1923efb7ac3fSMark Brown } else { 1924efb7ac3fSMark Brown template.name = long_name; 1925efb7ac3fSMark Brown } 1926efb7ac3fSMark Brown 1927efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 1928efb7ac3fSMark Brown 1929efb7ac3fSMark Brown kfree(name); 1930efb7ac3fSMark Brown 1931efb7ac3fSMark Brown return kcontrol; 1932db2a4165SFrank Mandarino } 1933db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 1934db2a4165SFrank Mandarino 1935db2a4165SFrank Mandarino /** 19363e8e1952SIan Molton * snd_soc_add_controls - add an array of controls to a codec. 19373e8e1952SIan Molton * Convienience function to add a list of controls. Many codecs were 19383e8e1952SIan Molton * duplicating this code. 19393e8e1952SIan Molton * 19403e8e1952SIan Molton * @codec: codec to add controls to 19413e8e1952SIan Molton * @controls: array of controls to add 19423e8e1952SIan Molton * @num_controls: number of elements in the array 19433e8e1952SIan Molton * 19443e8e1952SIan Molton * Return 0 for success, else error. 19453e8e1952SIan Molton */ 19463e8e1952SIan Molton int snd_soc_add_controls(struct snd_soc_codec *codec, 19473e8e1952SIan Molton const struct snd_kcontrol_new *controls, int num_controls) 19483e8e1952SIan Molton { 1949f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 19503e8e1952SIan Molton int err, i; 19513e8e1952SIan Molton 19523e8e1952SIan Molton for (i = 0; i < num_controls; i++) { 19533e8e1952SIan Molton const struct snd_kcontrol_new *control = &controls[i]; 1954efb7ac3fSMark Brown err = snd_ctl_add(card, snd_soc_cnew(control, codec, 1955efb7ac3fSMark Brown control->name, 1956efb7ac3fSMark Brown codec->name_prefix)); 19573e8e1952SIan Molton if (err < 0) { 1958082100dcSMark Brown dev_err(codec->dev, "%s: Failed to add %s: %d\n", 1959efb7ac3fSMark Brown codec->name, control->name, err); 19603e8e1952SIan Molton return err; 19613e8e1952SIan Molton } 19623e8e1952SIan Molton } 19633e8e1952SIan Molton 19643e8e1952SIan Molton return 0; 19653e8e1952SIan Molton } 19663e8e1952SIan Molton EXPORT_SYMBOL_GPL(snd_soc_add_controls); 19673e8e1952SIan Molton 19683e8e1952SIan Molton /** 1969a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 1970a491a5c8SLiam Girdwood * Convienience function to add a list of controls. 1971a491a5c8SLiam Girdwood * 1972a491a5c8SLiam Girdwood * @platform: platform to add controls to 1973a491a5c8SLiam Girdwood * @controls: array of controls to add 1974a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 1975a491a5c8SLiam Girdwood * 1976a491a5c8SLiam Girdwood * Return 0 for success, else error. 1977a491a5c8SLiam Girdwood */ 1978a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 1979a491a5c8SLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 1980a491a5c8SLiam Girdwood { 1981a491a5c8SLiam Girdwood struct snd_card *card = platform->card->snd_card; 1982a491a5c8SLiam Girdwood int err, i; 1983a491a5c8SLiam Girdwood 1984a491a5c8SLiam Girdwood for (i = 0; i < num_controls; i++) { 1985a491a5c8SLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 1986a491a5c8SLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, platform, 1987a491a5c8SLiam Girdwood control->name, NULL)); 1988a491a5c8SLiam Girdwood if (err < 0) { 1989a491a5c8SLiam Girdwood dev_err(platform->dev, "Failed to add %s %d\n",control->name, err); 1990a491a5c8SLiam Girdwood return err; 1991a491a5c8SLiam Girdwood } 1992a491a5c8SLiam Girdwood } 1993a491a5c8SLiam Girdwood 1994a491a5c8SLiam Girdwood return 0; 1995a491a5c8SLiam Girdwood } 1996a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 1997a491a5c8SLiam Girdwood 1998a491a5c8SLiam Girdwood /** 1999db2a4165SFrank Mandarino * snd_soc_info_enum_double - enumerated double mixer info callback 2000db2a4165SFrank Mandarino * @kcontrol: mixer control 2001db2a4165SFrank Mandarino * @uinfo: control element information 2002db2a4165SFrank Mandarino * 2003db2a4165SFrank Mandarino * Callback to provide information about a double enumerated 2004db2a4165SFrank Mandarino * mixer control. 2005db2a4165SFrank Mandarino * 2006db2a4165SFrank Mandarino * Returns 0 for success. 2007db2a4165SFrank Mandarino */ 2008db2a4165SFrank Mandarino int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 2009db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2010db2a4165SFrank Mandarino { 2011db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2012db2a4165SFrank Mandarino 2013db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2014db2a4165SFrank Mandarino uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2015f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2016db2a4165SFrank Mandarino 2017f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2018f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2019db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2020db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2021db2a4165SFrank Mandarino return 0; 2022db2a4165SFrank Mandarino } 2023db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); 2024db2a4165SFrank Mandarino 2025db2a4165SFrank Mandarino /** 2026db2a4165SFrank Mandarino * snd_soc_get_enum_double - enumerated double mixer get callback 2027db2a4165SFrank Mandarino * @kcontrol: mixer control 2028ac11a2b3SMark Brown * @ucontrol: control element information 2029db2a4165SFrank Mandarino * 2030db2a4165SFrank Mandarino * Callback to get the value of a double enumerated mixer. 2031db2a4165SFrank Mandarino * 2032db2a4165SFrank Mandarino * Returns 0 for success. 2033db2a4165SFrank Mandarino */ 2034db2a4165SFrank Mandarino int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 2035db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2036db2a4165SFrank Mandarino { 2037db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2038db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 203946f5822fSDaniel Ribeiro unsigned int val, bitmask; 2040db2a4165SFrank Mandarino 2041f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2042db2a4165SFrank Mandarino ; 2043db2a4165SFrank Mandarino val = snd_soc_read(codec, e->reg); 20443ff3f64bSMark Brown ucontrol->value.enumerated.item[0] 20453ff3f64bSMark Brown = (val >> e->shift_l) & (bitmask - 1); 2046db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) 2047db2a4165SFrank Mandarino ucontrol->value.enumerated.item[1] = 2048db2a4165SFrank Mandarino (val >> e->shift_r) & (bitmask - 1); 2049db2a4165SFrank Mandarino 2050db2a4165SFrank Mandarino return 0; 2051db2a4165SFrank Mandarino } 2052db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); 2053db2a4165SFrank Mandarino 2054db2a4165SFrank Mandarino /** 2055db2a4165SFrank Mandarino * snd_soc_put_enum_double - enumerated double mixer put callback 2056db2a4165SFrank Mandarino * @kcontrol: mixer control 2057ac11a2b3SMark Brown * @ucontrol: control element information 2058db2a4165SFrank Mandarino * 2059db2a4165SFrank Mandarino * Callback to set the value of a double enumerated mixer. 2060db2a4165SFrank Mandarino * 2061db2a4165SFrank Mandarino * Returns 0 for success. 2062db2a4165SFrank Mandarino */ 2063db2a4165SFrank Mandarino int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 2064db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2065db2a4165SFrank Mandarino { 2066db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2067db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 206846f5822fSDaniel Ribeiro unsigned int val; 206946f5822fSDaniel Ribeiro unsigned int mask, bitmask; 2070db2a4165SFrank Mandarino 2071f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2072db2a4165SFrank Mandarino ; 2073f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[0] > e->max - 1) 2074db2a4165SFrank Mandarino return -EINVAL; 2075db2a4165SFrank Mandarino val = ucontrol->value.enumerated.item[0] << e->shift_l; 2076db2a4165SFrank Mandarino mask = (bitmask - 1) << e->shift_l; 2077db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) { 2078f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[1] > e->max - 1) 2079db2a4165SFrank Mandarino return -EINVAL; 2080db2a4165SFrank Mandarino val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2081db2a4165SFrank Mandarino mask |= (bitmask - 1) << e->shift_r; 2082db2a4165SFrank Mandarino } 2083db2a4165SFrank Mandarino 20846c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2085db2a4165SFrank Mandarino } 2086db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2087db2a4165SFrank Mandarino 2088db2a4165SFrank Mandarino /** 20892e72f8e3SPeter Ujfalusi * snd_soc_get_value_enum_double - semi enumerated double mixer get callback 20902e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 20912e72f8e3SPeter Ujfalusi * @ucontrol: control element information 20922e72f8e3SPeter Ujfalusi * 20932e72f8e3SPeter Ujfalusi * Callback to get the value of a double semi enumerated mixer. 20942e72f8e3SPeter Ujfalusi * 20952e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 20962e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 20972e72f8e3SPeter Ujfalusi * 20982e72f8e3SPeter Ujfalusi * Returns 0 for success. 20992e72f8e3SPeter Ujfalusi */ 21002e72f8e3SPeter Ujfalusi int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, 21012e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 21022e72f8e3SPeter Ujfalusi { 21032e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 210474155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 210546f5822fSDaniel Ribeiro unsigned int reg_val, val, mux; 21062e72f8e3SPeter Ujfalusi 21072e72f8e3SPeter Ujfalusi reg_val = snd_soc_read(codec, e->reg); 21082e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_l) & e->mask; 21092e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 21102e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 21112e72f8e3SPeter Ujfalusi break; 21122e72f8e3SPeter Ujfalusi } 21132e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[0] = mux; 21142e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 21152e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_r) & e->mask; 21162e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 21172e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 21182e72f8e3SPeter Ujfalusi break; 21192e72f8e3SPeter Ujfalusi } 21202e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[1] = mux; 21212e72f8e3SPeter Ujfalusi } 21222e72f8e3SPeter Ujfalusi 21232e72f8e3SPeter Ujfalusi return 0; 21242e72f8e3SPeter Ujfalusi } 21252e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); 21262e72f8e3SPeter Ujfalusi 21272e72f8e3SPeter Ujfalusi /** 21282e72f8e3SPeter Ujfalusi * snd_soc_put_value_enum_double - semi enumerated double mixer put callback 21292e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 21302e72f8e3SPeter Ujfalusi * @ucontrol: control element information 21312e72f8e3SPeter Ujfalusi * 21322e72f8e3SPeter Ujfalusi * Callback to set the value of a double semi enumerated mixer. 21332e72f8e3SPeter Ujfalusi * 21342e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 21352e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 21362e72f8e3SPeter Ujfalusi * 21372e72f8e3SPeter Ujfalusi * Returns 0 for success. 21382e72f8e3SPeter Ujfalusi */ 21392e72f8e3SPeter Ujfalusi int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, 21402e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 21412e72f8e3SPeter Ujfalusi { 21422e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 214374155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 214446f5822fSDaniel Ribeiro unsigned int val; 214546f5822fSDaniel Ribeiro unsigned int mask; 21462e72f8e3SPeter Ujfalusi 21472e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[0] > e->max - 1) 21482e72f8e3SPeter Ujfalusi return -EINVAL; 21492e72f8e3SPeter Ujfalusi val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 21502e72f8e3SPeter Ujfalusi mask = e->mask << e->shift_l; 21512e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 21522e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[1] > e->max - 1) 21532e72f8e3SPeter Ujfalusi return -EINVAL; 21542e72f8e3SPeter Ujfalusi val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 21552e72f8e3SPeter Ujfalusi mask |= e->mask << e->shift_r; 21562e72f8e3SPeter Ujfalusi } 21572e72f8e3SPeter Ujfalusi 21586c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 21592e72f8e3SPeter Ujfalusi } 21602e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); 21612e72f8e3SPeter Ujfalusi 21622e72f8e3SPeter Ujfalusi /** 2163db2a4165SFrank Mandarino * snd_soc_info_enum_ext - external enumerated single mixer info callback 2164db2a4165SFrank Mandarino * @kcontrol: mixer control 2165db2a4165SFrank Mandarino * @uinfo: control element information 2166db2a4165SFrank Mandarino * 2167db2a4165SFrank Mandarino * Callback to provide information about an external enumerated 2168db2a4165SFrank Mandarino * single mixer. 2169db2a4165SFrank Mandarino * 2170db2a4165SFrank Mandarino * Returns 0 for success. 2171db2a4165SFrank Mandarino */ 2172db2a4165SFrank Mandarino int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, 2173db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2174db2a4165SFrank Mandarino { 2175db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2176db2a4165SFrank Mandarino 2177db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2178db2a4165SFrank Mandarino uinfo->count = 1; 2179f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2180db2a4165SFrank Mandarino 2181f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2182f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2183db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2184db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2185db2a4165SFrank Mandarino return 0; 2186db2a4165SFrank Mandarino } 2187db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); 2188db2a4165SFrank Mandarino 2189db2a4165SFrank Mandarino /** 2190db2a4165SFrank Mandarino * snd_soc_info_volsw_ext - external single mixer info callback 2191db2a4165SFrank Mandarino * @kcontrol: mixer control 2192db2a4165SFrank Mandarino * @uinfo: control element information 2193db2a4165SFrank Mandarino * 2194db2a4165SFrank Mandarino * Callback to provide information about a single external mixer control. 2195db2a4165SFrank Mandarino * 2196db2a4165SFrank Mandarino * Returns 0 for success. 2197db2a4165SFrank Mandarino */ 2198db2a4165SFrank Mandarino int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, 2199db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2200db2a4165SFrank Mandarino { 2201a7a4ac86SPhilipp Zabel int max = kcontrol->private_value; 2202db2a4165SFrank Mandarino 2203fd5dfad9SMark Brown if (max == 1 && !strstr(kcontrol->id.name, " Volume")) 2204a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2205a7a4ac86SPhilipp Zabel else 2206a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2207a7a4ac86SPhilipp Zabel 2208db2a4165SFrank Mandarino uinfo->count = 1; 2209db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2210a7a4ac86SPhilipp Zabel uinfo->value.integer.max = max; 2211db2a4165SFrank Mandarino return 0; 2212db2a4165SFrank Mandarino } 2213db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); 2214db2a4165SFrank Mandarino 2215db2a4165SFrank Mandarino /** 2216db2a4165SFrank Mandarino * snd_soc_info_volsw - single mixer info callback 2217db2a4165SFrank Mandarino * @kcontrol: mixer control 2218db2a4165SFrank Mandarino * @uinfo: control element information 2219db2a4165SFrank Mandarino * 2220db2a4165SFrank Mandarino * Callback to provide information about a single mixer control. 2221db2a4165SFrank Mandarino * 2222db2a4165SFrank Mandarino * Returns 0 for success. 2223db2a4165SFrank Mandarino */ 2224db2a4165SFrank Mandarino int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 2225db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2226db2a4165SFrank Mandarino { 22274eaa9819SJon Smirl struct soc_mixer_control *mc = 22284eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2229d11bb4a9SPeter Ujfalusi int platform_max; 2230762b8df7SMark Brown unsigned int shift = mc->shift; 2231815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 2232db2a4165SFrank Mandarino 2233d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2234d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2235d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2236d11bb4a9SPeter Ujfalusi 2237d11bb4a9SPeter Ujfalusi if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) 2238a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2239a7a4ac86SPhilipp Zabel else 2240a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2241a7a4ac86SPhilipp Zabel 2242db2a4165SFrank Mandarino uinfo->count = shift == rshift ? 1 : 2; 2243db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2244d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max; 2245db2a4165SFrank Mandarino return 0; 2246db2a4165SFrank Mandarino } 2247db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw); 2248db2a4165SFrank Mandarino 2249db2a4165SFrank Mandarino /** 2250db2a4165SFrank Mandarino * snd_soc_get_volsw - single mixer get callback 2251db2a4165SFrank Mandarino * @kcontrol: mixer control 2252ac11a2b3SMark Brown * @ucontrol: control element information 2253db2a4165SFrank Mandarino * 2254db2a4165SFrank Mandarino * Callback to get the value of a single mixer control. 2255db2a4165SFrank Mandarino * 2256db2a4165SFrank Mandarino * Returns 0 for success. 2257db2a4165SFrank Mandarino */ 2258db2a4165SFrank Mandarino int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 2259db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2260db2a4165SFrank Mandarino { 22614eaa9819SJon Smirl struct soc_mixer_control *mc = 22624eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2263db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2264815ecf8dSJon Smirl unsigned int reg = mc->reg; 2265815ecf8dSJon Smirl unsigned int shift = mc->shift; 2266815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 22674eaa9819SJon Smirl int max = mc->max; 2268815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2269815ecf8dSJon Smirl unsigned int invert = mc->invert; 2270db2a4165SFrank Mandarino 2271db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2272db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> shift) & mask; 2273db2a4165SFrank Mandarino if (shift != rshift) 2274db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2275db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> rshift) & mask; 2276db2a4165SFrank Mandarino if (invert) { 2277db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2278a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[0]; 2279db2a4165SFrank Mandarino if (shift != rshift) 2280db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2281a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[1]; 2282db2a4165SFrank Mandarino } 2283db2a4165SFrank Mandarino 2284db2a4165SFrank Mandarino return 0; 2285db2a4165SFrank Mandarino } 2286db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw); 2287db2a4165SFrank Mandarino 2288db2a4165SFrank Mandarino /** 2289db2a4165SFrank Mandarino * snd_soc_put_volsw - single mixer put callback 2290db2a4165SFrank Mandarino * @kcontrol: mixer control 2291ac11a2b3SMark Brown * @ucontrol: control element information 2292db2a4165SFrank Mandarino * 2293db2a4165SFrank Mandarino * Callback to set the value of a single mixer control. 2294db2a4165SFrank Mandarino * 2295db2a4165SFrank Mandarino * Returns 0 for success. 2296db2a4165SFrank Mandarino */ 2297db2a4165SFrank Mandarino int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 2298db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2299db2a4165SFrank Mandarino { 23004eaa9819SJon Smirl struct soc_mixer_control *mc = 23014eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2302db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2303815ecf8dSJon Smirl unsigned int reg = mc->reg; 2304815ecf8dSJon Smirl unsigned int shift = mc->shift; 2305815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 23064eaa9819SJon Smirl int max = mc->max; 2307815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2308815ecf8dSJon Smirl unsigned int invert = mc->invert; 230946f5822fSDaniel Ribeiro unsigned int val, val2, val_mask; 2310db2a4165SFrank Mandarino 2311db2a4165SFrank Mandarino val = (ucontrol->value.integer.value[0] & mask); 2312db2a4165SFrank Mandarino if (invert) 2313a7a4ac86SPhilipp Zabel val = max - val; 2314db2a4165SFrank Mandarino val_mask = mask << shift; 2315db2a4165SFrank Mandarino val = val << shift; 2316db2a4165SFrank Mandarino if (shift != rshift) { 2317db2a4165SFrank Mandarino val2 = (ucontrol->value.integer.value[1] & mask); 2318db2a4165SFrank Mandarino if (invert) 2319a7a4ac86SPhilipp Zabel val2 = max - val2; 2320db2a4165SFrank Mandarino val_mask |= mask << rshift; 2321db2a4165SFrank Mandarino val |= val2 << rshift; 2322db2a4165SFrank Mandarino } 23236c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, reg, val_mask, val); 2324db2a4165SFrank Mandarino } 2325db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 2326db2a4165SFrank Mandarino 2327db2a4165SFrank Mandarino /** 2328db2a4165SFrank Mandarino * snd_soc_info_volsw_2r - double mixer info callback 2329db2a4165SFrank Mandarino * @kcontrol: mixer control 2330db2a4165SFrank Mandarino * @uinfo: control element information 2331db2a4165SFrank Mandarino * 2332db2a4165SFrank Mandarino * Callback to provide information about a double mixer control that 2333db2a4165SFrank Mandarino * spans 2 codec registers. 2334db2a4165SFrank Mandarino * 2335db2a4165SFrank Mandarino * Returns 0 for success. 2336db2a4165SFrank Mandarino */ 2337db2a4165SFrank Mandarino int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, 2338db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2339db2a4165SFrank Mandarino { 23404eaa9819SJon Smirl struct soc_mixer_control *mc = 23414eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2342d11bb4a9SPeter Ujfalusi int platform_max; 2343db2a4165SFrank Mandarino 2344d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2345d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2346d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2347d11bb4a9SPeter Ujfalusi 2348d11bb4a9SPeter Ujfalusi if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) 2349a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2350a7a4ac86SPhilipp Zabel else 2351a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2352a7a4ac86SPhilipp Zabel 2353db2a4165SFrank Mandarino uinfo->count = 2; 2354db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2355d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max; 2356db2a4165SFrank Mandarino return 0; 2357db2a4165SFrank Mandarino } 2358db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r); 2359db2a4165SFrank Mandarino 2360db2a4165SFrank Mandarino /** 2361db2a4165SFrank Mandarino * snd_soc_get_volsw_2r - double mixer get callback 2362db2a4165SFrank Mandarino * @kcontrol: mixer control 2363ac11a2b3SMark Brown * @ucontrol: control element information 2364db2a4165SFrank Mandarino * 2365db2a4165SFrank Mandarino * Callback to get the value of a double mixer control that spans 2 registers. 2366db2a4165SFrank Mandarino * 2367db2a4165SFrank Mandarino * Returns 0 for success. 2368db2a4165SFrank Mandarino */ 2369db2a4165SFrank Mandarino int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol, 2370db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2371db2a4165SFrank Mandarino { 23724eaa9819SJon Smirl struct soc_mixer_control *mc = 23734eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2374db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2375815ecf8dSJon Smirl unsigned int reg = mc->reg; 2376815ecf8dSJon Smirl unsigned int reg2 = mc->rreg; 2377815ecf8dSJon Smirl unsigned int shift = mc->shift; 23784eaa9819SJon Smirl int max = mc->max; 2379815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2380815ecf8dSJon Smirl unsigned int invert = mc->invert; 2381db2a4165SFrank Mandarino 2382db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2383db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> shift) & mask; 2384db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2385db2a4165SFrank Mandarino (snd_soc_read(codec, reg2) >> shift) & mask; 2386db2a4165SFrank Mandarino if (invert) { 2387db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2388a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[0]; 2389db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2390a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[1]; 2391db2a4165SFrank Mandarino } 2392db2a4165SFrank Mandarino 2393db2a4165SFrank Mandarino return 0; 2394db2a4165SFrank Mandarino } 2395db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r); 2396db2a4165SFrank Mandarino 2397db2a4165SFrank Mandarino /** 2398db2a4165SFrank Mandarino * snd_soc_put_volsw_2r - double mixer set callback 2399db2a4165SFrank Mandarino * @kcontrol: mixer control 2400ac11a2b3SMark Brown * @ucontrol: control element information 2401db2a4165SFrank Mandarino * 2402db2a4165SFrank Mandarino * Callback to set the value of a double mixer control that spans 2 registers. 2403db2a4165SFrank Mandarino * 2404db2a4165SFrank Mandarino * Returns 0 for success. 2405db2a4165SFrank Mandarino */ 2406db2a4165SFrank Mandarino int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol, 2407db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2408db2a4165SFrank Mandarino { 24094eaa9819SJon Smirl struct soc_mixer_control *mc = 24104eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2411db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2412815ecf8dSJon Smirl unsigned int reg = mc->reg; 2413815ecf8dSJon Smirl unsigned int reg2 = mc->rreg; 2414815ecf8dSJon Smirl unsigned int shift = mc->shift; 24154eaa9819SJon Smirl int max = mc->max; 2416815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2417815ecf8dSJon Smirl unsigned int invert = mc->invert; 2418db2a4165SFrank Mandarino int err; 241946f5822fSDaniel Ribeiro unsigned int val, val2, val_mask; 2420db2a4165SFrank Mandarino 2421db2a4165SFrank Mandarino val_mask = mask << shift; 2422db2a4165SFrank Mandarino val = (ucontrol->value.integer.value[0] & mask); 2423db2a4165SFrank Mandarino val2 = (ucontrol->value.integer.value[1] & mask); 2424db2a4165SFrank Mandarino 2425db2a4165SFrank Mandarino if (invert) { 2426a7a4ac86SPhilipp Zabel val = max - val; 2427a7a4ac86SPhilipp Zabel val2 = max - val2; 2428db2a4165SFrank Mandarino } 2429db2a4165SFrank Mandarino 2430db2a4165SFrank Mandarino val = val << shift; 2431db2a4165SFrank Mandarino val2 = val2 << shift; 2432db2a4165SFrank Mandarino 24336c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 24343ff3f64bSMark Brown if (err < 0) 2435db2a4165SFrank Mandarino return err; 2436db2a4165SFrank Mandarino 24376c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); 2438db2a4165SFrank Mandarino return err; 2439db2a4165SFrank Mandarino } 2440db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r); 2441db2a4165SFrank Mandarino 2442e13ac2e9SMark Brown /** 2443e13ac2e9SMark Brown * snd_soc_info_volsw_s8 - signed mixer info callback 2444e13ac2e9SMark Brown * @kcontrol: mixer control 2445e13ac2e9SMark Brown * @uinfo: control element information 2446e13ac2e9SMark Brown * 2447e13ac2e9SMark Brown * Callback to provide information about a signed mixer control. 2448e13ac2e9SMark Brown * 2449e13ac2e9SMark Brown * Returns 0 for success. 2450e13ac2e9SMark Brown */ 2451e13ac2e9SMark Brown int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, 2452e13ac2e9SMark Brown struct snd_ctl_elem_info *uinfo) 2453e13ac2e9SMark Brown { 24544eaa9819SJon Smirl struct soc_mixer_control *mc = 24554eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2456d11bb4a9SPeter Ujfalusi int platform_max; 24574eaa9819SJon Smirl int min = mc->min; 2458e13ac2e9SMark Brown 2459d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2460d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2461d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2462d11bb4a9SPeter Ujfalusi 2463e13ac2e9SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2464e13ac2e9SMark Brown uinfo->count = 2; 2465e13ac2e9SMark Brown uinfo->value.integer.min = 0; 2466d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max - min; 2467e13ac2e9SMark Brown return 0; 2468e13ac2e9SMark Brown } 2469e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); 2470e13ac2e9SMark Brown 2471e13ac2e9SMark Brown /** 2472e13ac2e9SMark Brown * snd_soc_get_volsw_s8 - signed mixer get callback 2473e13ac2e9SMark Brown * @kcontrol: mixer control 2474ac11a2b3SMark Brown * @ucontrol: control element information 2475e13ac2e9SMark Brown * 2476e13ac2e9SMark Brown * Callback to get the value of a signed mixer control. 2477e13ac2e9SMark Brown * 2478e13ac2e9SMark Brown * Returns 0 for success. 2479e13ac2e9SMark Brown */ 2480e13ac2e9SMark Brown int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, 2481e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2482e13ac2e9SMark Brown { 24834eaa9819SJon Smirl struct soc_mixer_control *mc = 24844eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2485e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2486815ecf8dSJon Smirl unsigned int reg = mc->reg; 24874eaa9819SJon Smirl int min = mc->min; 2488e13ac2e9SMark Brown int val = snd_soc_read(codec, reg); 2489e13ac2e9SMark Brown 2490e13ac2e9SMark Brown ucontrol->value.integer.value[0] = 2491e13ac2e9SMark Brown ((signed char)(val & 0xff))-min; 2492e13ac2e9SMark Brown ucontrol->value.integer.value[1] = 2493e13ac2e9SMark Brown ((signed char)((val >> 8) & 0xff))-min; 2494e13ac2e9SMark Brown return 0; 2495e13ac2e9SMark Brown } 2496e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); 2497e13ac2e9SMark Brown 2498e13ac2e9SMark Brown /** 2499e13ac2e9SMark Brown * snd_soc_put_volsw_sgn - signed mixer put callback 2500e13ac2e9SMark Brown * @kcontrol: mixer control 2501ac11a2b3SMark Brown * @ucontrol: control element information 2502e13ac2e9SMark Brown * 2503e13ac2e9SMark Brown * Callback to set the value of a signed mixer control. 2504e13ac2e9SMark Brown * 2505e13ac2e9SMark Brown * Returns 0 for success. 2506e13ac2e9SMark Brown */ 2507e13ac2e9SMark Brown int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, 2508e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2509e13ac2e9SMark Brown { 25104eaa9819SJon Smirl struct soc_mixer_control *mc = 25114eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2512e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2513815ecf8dSJon Smirl unsigned int reg = mc->reg; 25144eaa9819SJon Smirl int min = mc->min; 251546f5822fSDaniel Ribeiro unsigned int val; 2516e13ac2e9SMark Brown 2517e13ac2e9SMark Brown val = (ucontrol->value.integer.value[0]+min) & 0xff; 2518e13ac2e9SMark Brown val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2519e13ac2e9SMark Brown 25206c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, reg, 0xffff, val); 2521e13ac2e9SMark Brown } 2522e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2523e13ac2e9SMark Brown 25248c6529dbSLiam Girdwood /** 2525637d3847SPeter Ujfalusi * snd_soc_limit_volume - Set new limit to an existing volume control. 2526637d3847SPeter Ujfalusi * 2527637d3847SPeter Ujfalusi * @codec: where to look for the control 2528637d3847SPeter Ujfalusi * @name: Name of the control 2529637d3847SPeter Ujfalusi * @max: new maximum limit 2530637d3847SPeter Ujfalusi * 2531637d3847SPeter Ujfalusi * Return 0 for success, else error. 2532637d3847SPeter Ujfalusi */ 2533637d3847SPeter Ujfalusi int snd_soc_limit_volume(struct snd_soc_codec *codec, 2534637d3847SPeter Ujfalusi const char *name, int max) 2535637d3847SPeter Ujfalusi { 2536f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 2537637d3847SPeter Ujfalusi struct snd_kcontrol *kctl; 2538637d3847SPeter Ujfalusi struct soc_mixer_control *mc; 2539637d3847SPeter Ujfalusi int found = 0; 2540637d3847SPeter Ujfalusi int ret = -EINVAL; 2541637d3847SPeter Ujfalusi 2542637d3847SPeter Ujfalusi /* Sanity check for name and max */ 2543637d3847SPeter Ujfalusi if (unlikely(!name || max <= 0)) 2544637d3847SPeter Ujfalusi return -EINVAL; 2545637d3847SPeter Ujfalusi 2546637d3847SPeter Ujfalusi list_for_each_entry(kctl, &card->controls, list) { 2547637d3847SPeter Ujfalusi if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { 2548637d3847SPeter Ujfalusi found = 1; 2549637d3847SPeter Ujfalusi break; 2550637d3847SPeter Ujfalusi } 2551637d3847SPeter Ujfalusi } 2552637d3847SPeter Ujfalusi if (found) { 2553637d3847SPeter Ujfalusi mc = (struct soc_mixer_control *)kctl->private_value; 2554637d3847SPeter Ujfalusi if (max <= mc->max) { 2555d11bb4a9SPeter Ujfalusi mc->platform_max = max; 2556637d3847SPeter Ujfalusi ret = 0; 2557637d3847SPeter Ujfalusi } 2558637d3847SPeter Ujfalusi } 2559637d3847SPeter Ujfalusi return ret; 2560637d3847SPeter Ujfalusi } 2561637d3847SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_limit_volume); 2562637d3847SPeter Ujfalusi 2563637d3847SPeter Ujfalusi /** 2564b6f4bb38Sapatard@mandriva.com * snd_soc_info_volsw_2r_sx - double with tlv and variable data size 2565b6f4bb38Sapatard@mandriva.com * mixer info callback 2566b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2567b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2568b6f4bb38Sapatard@mandriva.com * 2569b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2570b6f4bb38Sapatard@mandriva.com */ 2571b6f4bb38Sapatard@mandriva.com int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2572b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_info *uinfo) 2573b6f4bb38Sapatard@mandriva.com { 2574b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2575b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2576b6f4bb38Sapatard@mandriva.com int max = mc->max; 2577b6f4bb38Sapatard@mandriva.com int min = mc->min; 2578b6f4bb38Sapatard@mandriva.com 2579b6f4bb38Sapatard@mandriva.com uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2580b6f4bb38Sapatard@mandriva.com uinfo->count = 2; 2581b6f4bb38Sapatard@mandriva.com uinfo->value.integer.min = 0; 2582b6f4bb38Sapatard@mandriva.com uinfo->value.integer.max = max-min; 2583b6f4bb38Sapatard@mandriva.com 2584b6f4bb38Sapatard@mandriva.com return 0; 2585b6f4bb38Sapatard@mandriva.com } 2586b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); 2587b6f4bb38Sapatard@mandriva.com 2588b6f4bb38Sapatard@mandriva.com /** 2589b6f4bb38Sapatard@mandriva.com * snd_soc_get_volsw_2r_sx - double with tlv and variable data size 2590b6f4bb38Sapatard@mandriva.com * mixer get callback 2591b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2592b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2593b6f4bb38Sapatard@mandriva.com * 2594b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2595b6f4bb38Sapatard@mandriva.com */ 2596b6f4bb38Sapatard@mandriva.com int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2597b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2598b6f4bb38Sapatard@mandriva.com { 2599b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2600b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2601b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2602b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2603b6f4bb38Sapatard@mandriva.com int min = mc->min; 2604b6f4bb38Sapatard@mandriva.com int val = snd_soc_read(codec, mc->reg) & mask; 2605b6f4bb38Sapatard@mandriva.com int valr = snd_soc_read(codec, mc->rreg) & mask; 2606b6f4bb38Sapatard@mandriva.com 260720630c7fSStuart Longland ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; 260820630c7fSStuart Longland ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; 2609b6f4bb38Sapatard@mandriva.com return 0; 2610b6f4bb38Sapatard@mandriva.com } 2611b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); 2612b6f4bb38Sapatard@mandriva.com 2613b6f4bb38Sapatard@mandriva.com /** 2614b6f4bb38Sapatard@mandriva.com * snd_soc_put_volsw_2r_sx - double with tlv and variable data size 2615b6f4bb38Sapatard@mandriva.com * mixer put callback 2616b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2617b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2618b6f4bb38Sapatard@mandriva.com * 2619b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2620b6f4bb38Sapatard@mandriva.com */ 2621b6f4bb38Sapatard@mandriva.com int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2622b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2623b6f4bb38Sapatard@mandriva.com { 2624b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2625b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2626b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2627b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2628b6f4bb38Sapatard@mandriva.com int min = mc->min; 2629b6f4bb38Sapatard@mandriva.com int ret; 2630b6f4bb38Sapatard@mandriva.com unsigned int val, valr, oval, ovalr; 2631b6f4bb38Sapatard@mandriva.com 2632b6f4bb38Sapatard@mandriva.com val = ((ucontrol->value.integer.value[0]+min) & 0xff); 2633b6f4bb38Sapatard@mandriva.com val &= mask; 2634b6f4bb38Sapatard@mandriva.com valr = ((ucontrol->value.integer.value[1]+min) & 0xff); 2635b6f4bb38Sapatard@mandriva.com valr &= mask; 2636b6f4bb38Sapatard@mandriva.com 2637b6f4bb38Sapatard@mandriva.com oval = snd_soc_read(codec, mc->reg) & mask; 2638b6f4bb38Sapatard@mandriva.com ovalr = snd_soc_read(codec, mc->rreg) & mask; 2639b6f4bb38Sapatard@mandriva.com 2640b6f4bb38Sapatard@mandriva.com ret = 0; 2641b6f4bb38Sapatard@mandriva.com if (oval != val) { 2642b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->reg, val); 2643b6f4bb38Sapatard@mandriva.com if (ret < 0) 2644f1df5aecSMark Brown return ret; 2645b6f4bb38Sapatard@mandriva.com } 2646b6f4bb38Sapatard@mandriva.com if (ovalr != valr) { 2647b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->rreg, valr); 2648b6f4bb38Sapatard@mandriva.com if (ret < 0) 2649f1df5aecSMark Brown return ret; 2650b6f4bb38Sapatard@mandriva.com } 2651b6f4bb38Sapatard@mandriva.com 2652b6f4bb38Sapatard@mandriva.com return 0; 2653b6f4bb38Sapatard@mandriva.com } 2654b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); 2655b6f4bb38Sapatard@mandriva.com 2656b6f4bb38Sapatard@mandriva.com /** 26578c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 26588c6529dbSLiam Girdwood * @dai: DAI 26598c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 26608c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 26618c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 26628c6529dbSLiam Girdwood * 26638c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 26648c6529dbSLiam Girdwood */ 26658c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 26668c6529dbSLiam Girdwood unsigned int freq, int dir) 26678c6529dbSLiam Girdwood { 2668f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 2669f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2670ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 2671ec4ee52aSMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 2672ec4ee52aSMark Brown freq, dir); 26738c6529dbSLiam Girdwood else 26748c6529dbSLiam Girdwood return -EINVAL; 26758c6529dbSLiam Girdwood } 26768c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 26778c6529dbSLiam Girdwood 26788c6529dbSLiam Girdwood /** 2679ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 2680ec4ee52aSMark Brown * @codec: CODEC 2681ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 2682ec4ee52aSMark Brown * @freq: new clock frequency in Hz 2683ec4ee52aSMark Brown * @dir: new clock direction - input/output. 2684ec4ee52aSMark Brown * 2685ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 2686ec4ee52aSMark Brown */ 2687ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 2688ec4ee52aSMark Brown unsigned int freq, int dir) 2689ec4ee52aSMark Brown { 2690ec4ee52aSMark Brown if (codec->driver->set_sysclk) 2691ec4ee52aSMark Brown return codec->driver->set_sysclk(codec, clk_id, freq, dir); 2692ec4ee52aSMark Brown else 2693ec4ee52aSMark Brown return -EINVAL; 2694ec4ee52aSMark Brown } 2695ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 2696ec4ee52aSMark Brown 2697ec4ee52aSMark Brown /** 26988c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 26998c6529dbSLiam Girdwood * @dai: DAI 2700ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 27018c6529dbSLiam Girdwood * @div: new clock divisor. 27028c6529dbSLiam Girdwood * 27038c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 27048c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 27058c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 27068c6529dbSLiam Girdwood */ 27078c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 27088c6529dbSLiam Girdwood int div_id, int div) 27098c6529dbSLiam Girdwood { 2710f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 2711f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 27128c6529dbSLiam Girdwood else 27138c6529dbSLiam Girdwood return -EINVAL; 27148c6529dbSLiam Girdwood } 27158c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 27168c6529dbSLiam Girdwood 27178c6529dbSLiam Girdwood /** 27188c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 27198c6529dbSLiam Girdwood * @dai: DAI 27208c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 272185488037SMark Brown * @source: DAI specific source for the PLL 27228c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 27238c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 27248c6529dbSLiam Girdwood * 27258c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 27268c6529dbSLiam Girdwood */ 272785488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 272885488037SMark Brown unsigned int freq_in, unsigned int freq_out) 27298c6529dbSLiam Girdwood { 2730f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 2731f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 273285488037SMark Brown freq_in, freq_out); 2733ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 2734ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 2735ec4ee52aSMark Brown freq_in, freq_out); 27368c6529dbSLiam Girdwood else 27378c6529dbSLiam Girdwood return -EINVAL; 27388c6529dbSLiam Girdwood } 27398c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 27408c6529dbSLiam Girdwood 2741ec4ee52aSMark Brown /* 2742ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 2743ec4ee52aSMark Brown * @codec: CODEC 2744ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 2745ec4ee52aSMark Brown * @source: DAI specific source for the PLL 2746ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 2747ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 2748ec4ee52aSMark Brown * 2749ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 2750ec4ee52aSMark Brown */ 2751ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 2752ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 2753ec4ee52aSMark Brown { 2754ec4ee52aSMark Brown if (codec->driver->set_pll) 2755ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 2756ec4ee52aSMark Brown freq_in, freq_out); 2757ec4ee52aSMark Brown else 2758ec4ee52aSMark Brown return -EINVAL; 2759ec4ee52aSMark Brown } 2760ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 2761ec4ee52aSMark Brown 27628c6529dbSLiam Girdwood /** 27638c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 27648c6529dbSLiam Girdwood * @dai: DAI 27658c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 27668c6529dbSLiam Girdwood * 27678c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 27688c6529dbSLiam Girdwood */ 27698c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 27708c6529dbSLiam Girdwood { 2771f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_fmt) 2772f0fba2adSLiam Girdwood return dai->driver->ops->set_fmt(dai, fmt); 27738c6529dbSLiam Girdwood else 27748c6529dbSLiam Girdwood return -EINVAL; 27758c6529dbSLiam Girdwood } 27768c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 27778c6529dbSLiam Girdwood 27788c6529dbSLiam Girdwood /** 27798c6529dbSLiam Girdwood * snd_soc_dai_set_tdm_slot - configure DAI TDM. 27808c6529dbSLiam Girdwood * @dai: DAI 2781a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 2782a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 27838c6529dbSLiam Girdwood * @slots: Number of slots in use. 2784a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 27858c6529dbSLiam Girdwood * 27868c6529dbSLiam Girdwood * Configures a DAI for TDM operation. Both mask and slots are codec and DAI 27878c6529dbSLiam Girdwood * specific. 27888c6529dbSLiam Girdwood */ 27898c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2790a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 27918c6529dbSLiam Girdwood { 2792f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 2793f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2794a5479e38SDaniel Ribeiro slots, slot_width); 27958c6529dbSLiam Girdwood else 27968c6529dbSLiam Girdwood return -EINVAL; 27978c6529dbSLiam Girdwood } 27988c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 27998c6529dbSLiam Girdwood 28008c6529dbSLiam Girdwood /** 2801472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 2802472df3cbSBarry Song * @dai: DAI 2803472df3cbSBarry Song * @tx_num: how many TX channels 2804472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 2805472df3cbSBarry Song * 0~num-1 uses 2806472df3cbSBarry Song * @rx_num: how many RX channels 2807472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 2808472df3cbSBarry Song * 0~num-1 uses 2809472df3cbSBarry Song * 2810472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 2811472df3cbSBarry Song */ 2812472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 2813472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 2814472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 2815472df3cbSBarry Song { 2816f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 2817f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 2818472df3cbSBarry Song rx_num, rx_slot); 2819472df3cbSBarry Song else 2820472df3cbSBarry Song return -EINVAL; 2821472df3cbSBarry Song } 2822472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 2823472df3cbSBarry Song 2824472df3cbSBarry Song /** 28258c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 28268c6529dbSLiam Girdwood * @dai: DAI 28278c6529dbSLiam Girdwood * @tristate: tristate enable 28288c6529dbSLiam Girdwood * 28298c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 28308c6529dbSLiam Girdwood */ 28318c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 28328c6529dbSLiam Girdwood { 2833f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 2834f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 28358c6529dbSLiam Girdwood else 28368c6529dbSLiam Girdwood return -EINVAL; 28378c6529dbSLiam Girdwood } 28388c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 28398c6529dbSLiam Girdwood 28408c6529dbSLiam Girdwood /** 28418c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 28428c6529dbSLiam Girdwood * @dai: DAI 28438c6529dbSLiam Girdwood * @mute: mute enable 28448c6529dbSLiam Girdwood * 28458c6529dbSLiam Girdwood * Mutes the DAI DAC. 28468c6529dbSLiam Girdwood */ 28478c6529dbSLiam Girdwood int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 28488c6529dbSLiam Girdwood { 2849f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->digital_mute) 2850f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 28518c6529dbSLiam Girdwood else 28528c6529dbSLiam Girdwood return -EINVAL; 28538c6529dbSLiam Girdwood } 28548c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 28558c6529dbSLiam Girdwood 2856c5af3a2eSMark Brown /** 2857c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 2858c5af3a2eSMark Brown * 2859ac11a2b3SMark Brown * @card: Card to register 2860c5af3a2eSMark Brown * 2861c5af3a2eSMark Brown */ 286270a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 2863c5af3a2eSMark Brown { 2864f0fba2adSLiam Girdwood int i; 2865f0fba2adSLiam Girdwood 2866c5af3a2eSMark Brown if (!card->name || !card->dev) 2867c5af3a2eSMark Brown return -EINVAL; 2868c5af3a2eSMark Brown 2869ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 2870ed77cc12SMark Brown 2871111c6419SStephen Warren snd_soc_initialize_card_lists(card); 2872111c6419SStephen Warren 2873150dd2f8SVinod Koul soc_init_card_debugfs(card); 2874150dd2f8SVinod Koul 28752eea392dSJarkko Nikula card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * 28762eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 2877f0fba2adSLiam Girdwood GFP_KERNEL); 2878f0fba2adSLiam Girdwood if (card->rtd == NULL) 2879f0fba2adSLiam Girdwood return -ENOMEM; 28802eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 2881f0fba2adSLiam Girdwood 2882f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 2883f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 2884f0fba2adSLiam Girdwood 2885c5af3a2eSMark Brown INIT_LIST_HEAD(&card->list); 2886c5af3a2eSMark Brown card->instantiated = 0; 2887f0fba2adSLiam Girdwood mutex_init(&card->mutex); 2888c5af3a2eSMark Brown 2889c5af3a2eSMark Brown mutex_lock(&client_mutex); 2890c5af3a2eSMark Brown list_add(&card->list, &card_list); 2891435c5e25SMark Brown snd_soc_instantiate_cards(); 2892c5af3a2eSMark Brown mutex_unlock(&client_mutex); 2893c5af3a2eSMark Brown 2894c5af3a2eSMark Brown dev_dbg(card->dev, "Registered card '%s'\n", card->name); 2895c5af3a2eSMark Brown 2896c5af3a2eSMark Brown return 0; 2897c5af3a2eSMark Brown } 289870a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 2899c5af3a2eSMark Brown 2900c5af3a2eSMark Brown /** 2901c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 2902c5af3a2eSMark Brown * 2903ac11a2b3SMark Brown * @card: Card to unregister 2904c5af3a2eSMark Brown * 2905c5af3a2eSMark Brown */ 290670a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 2907c5af3a2eSMark Brown { 2908b0e26485SVinod Koul if (card->instantiated) 2909b0e26485SVinod Koul soc_cleanup_card_resources(card); 2910c5af3a2eSMark Brown mutex_lock(&client_mutex); 2911c5af3a2eSMark Brown list_del(&card->list); 2912c5af3a2eSMark Brown mutex_unlock(&client_mutex); 2913c5af3a2eSMark Brown dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); 2914c5af3a2eSMark Brown 2915c5af3a2eSMark Brown return 0; 2916c5af3a2eSMark Brown } 291770a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 2918c5af3a2eSMark Brown 2919f0fba2adSLiam Girdwood /* 2920f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 2921f0fba2adSLiam Girdwood * and sanitizing names. 2922f0fba2adSLiam Girdwood */ 29230b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 2924f0fba2adSLiam Girdwood { 2925f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 2926f0fba2adSLiam Girdwood int id1, id2; 2927f0fba2adSLiam Girdwood 2928f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 2929f0fba2adSLiam Girdwood return NULL; 2930f0fba2adSLiam Girdwood 293158818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 2932f0fba2adSLiam Girdwood 2933f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 2934f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 2935f0fba2adSLiam Girdwood if (found) { 2936f0fba2adSLiam Girdwood /* get ID */ 2937f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 2938f0fba2adSLiam Girdwood 2939f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 2940f0fba2adSLiam Girdwood if (*id == -1) 2941f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 2942f0fba2adSLiam Girdwood } 2943f0fba2adSLiam Girdwood 2944f0fba2adSLiam Girdwood } else { 2945f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 2946f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 2947f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 2948f0fba2adSLiam Girdwood 2949f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 295005899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 2951f0fba2adSLiam Girdwood 2952f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 2953f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 295458818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 2955f0fba2adSLiam Girdwood } else 2956f0fba2adSLiam Girdwood *id = 0; 2957f0fba2adSLiam Girdwood } 2958f0fba2adSLiam Girdwood 2959f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 2960f0fba2adSLiam Girdwood } 2961f0fba2adSLiam Girdwood 2962f0fba2adSLiam Girdwood /* 2963f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 2964f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 2965f0fba2adSLiam Girdwood */ 2966f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 2967f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 2968f0fba2adSLiam Girdwood { 2969f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 2970f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n", 2971f0fba2adSLiam Girdwood dev_name(dev)); 2972f0fba2adSLiam Girdwood return NULL; 2973f0fba2adSLiam Girdwood } 2974f0fba2adSLiam Girdwood 2975f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 2976f0fba2adSLiam Girdwood } 2977f0fba2adSLiam Girdwood 29789115171aSMark Brown /** 29799115171aSMark Brown * snd_soc_register_dai - Register a DAI with the ASoC core 29809115171aSMark Brown * 2981ac11a2b3SMark Brown * @dai: DAI to register 29829115171aSMark Brown */ 2983f0fba2adSLiam Girdwood int snd_soc_register_dai(struct device *dev, 2984f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 29859115171aSMark Brown { 2986f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 29879115171aSMark Brown 2988f0fba2adSLiam Girdwood dev_dbg(dev, "dai register %s\n", dev_name(dev)); 29899115171aSMark Brown 2990f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 2991f0fba2adSLiam Girdwood if (dai == NULL) 2992f0fba2adSLiam Girdwood return -ENOMEM; 29936335d055SEric Miao 2994f0fba2adSLiam Girdwood /* create DAI component name */ 2995f0fba2adSLiam Girdwood dai->name = fmt_single_name(dev, &dai->id); 2996f0fba2adSLiam Girdwood if (dai->name == NULL) { 2997f0fba2adSLiam Girdwood kfree(dai); 2998f0fba2adSLiam Girdwood return -ENOMEM; 2999f0fba2adSLiam Girdwood } 3000f0fba2adSLiam Girdwood 3001f0fba2adSLiam Girdwood dai->dev = dev; 3002f0fba2adSLiam Girdwood dai->driver = dai_drv; 3003f0fba2adSLiam Girdwood if (!dai->driver->ops) 3004f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 30059115171aSMark Brown 30069115171aSMark Brown mutex_lock(&client_mutex); 30079115171aSMark Brown list_add(&dai->list, &dai_list); 3008435c5e25SMark Brown snd_soc_instantiate_cards(); 30099115171aSMark Brown mutex_unlock(&client_mutex); 30109115171aSMark Brown 30119115171aSMark Brown pr_debug("Registered DAI '%s'\n", dai->name); 30129115171aSMark Brown 30139115171aSMark Brown return 0; 30149115171aSMark Brown } 30159115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dai); 30169115171aSMark Brown 30179115171aSMark Brown /** 30189115171aSMark Brown * snd_soc_unregister_dai - Unregister a DAI from the ASoC core 30199115171aSMark Brown * 3020ac11a2b3SMark Brown * @dai: DAI to unregister 30219115171aSMark Brown */ 3022f0fba2adSLiam Girdwood void snd_soc_unregister_dai(struct device *dev) 30239115171aSMark Brown { 3024f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3025f0fba2adSLiam Girdwood 3026f0fba2adSLiam Girdwood list_for_each_entry(dai, &dai_list, list) { 3027f0fba2adSLiam Girdwood if (dev == dai->dev) 3028f0fba2adSLiam Girdwood goto found; 3029f0fba2adSLiam Girdwood } 3030f0fba2adSLiam Girdwood return; 3031f0fba2adSLiam Girdwood 3032f0fba2adSLiam Girdwood found: 30339115171aSMark Brown mutex_lock(&client_mutex); 30349115171aSMark Brown list_del(&dai->list); 30359115171aSMark Brown mutex_unlock(&client_mutex); 30369115171aSMark Brown 30379115171aSMark Brown pr_debug("Unregistered DAI '%s'\n", dai->name); 3038f0fba2adSLiam Girdwood kfree(dai->name); 3039f0fba2adSLiam Girdwood kfree(dai); 30409115171aSMark Brown } 30419115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); 30429115171aSMark Brown 30439115171aSMark Brown /** 30449115171aSMark Brown * snd_soc_register_dais - Register multiple DAIs with the ASoC core 30459115171aSMark Brown * 3046ac11a2b3SMark Brown * @dai: Array of DAIs to register 3047ac11a2b3SMark Brown * @count: Number of DAIs 30489115171aSMark Brown */ 3049f0fba2adSLiam Girdwood int snd_soc_register_dais(struct device *dev, 3050f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv, size_t count) 30519115171aSMark Brown { 3052f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3053f0fba2adSLiam Girdwood int i, ret = 0; 3054f0fba2adSLiam Girdwood 3055720ffa4cSLiam Girdwood dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count); 30569115171aSMark Brown 30579115171aSMark Brown for (i = 0; i < count; i++) { 3058f0fba2adSLiam Girdwood 3059f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3060c46e0079SAxel Lin if (dai == NULL) { 3061c46e0079SAxel Lin ret = -ENOMEM; 3062c46e0079SAxel Lin goto err; 3063c46e0079SAxel Lin } 3064f0fba2adSLiam Girdwood 3065f0fba2adSLiam Girdwood /* create DAI component name */ 3066f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3067f0fba2adSLiam Girdwood if (dai->name == NULL) { 3068f0fba2adSLiam Girdwood kfree(dai); 3069f0fba2adSLiam Girdwood ret = -EINVAL; 30709115171aSMark Brown goto err; 30719115171aSMark Brown } 30729115171aSMark Brown 3073f0fba2adSLiam Girdwood dai->dev = dev; 3074f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 30750f9141c9SMark Brown if (dai->driver->id) 30760f9141c9SMark Brown dai->id = dai->driver->id; 30770f9141c9SMark Brown else 30780f9141c9SMark Brown dai->id = i; 3079f0fba2adSLiam Girdwood if (!dai->driver->ops) 3080f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 3081f0fba2adSLiam Girdwood 3082f0fba2adSLiam Girdwood mutex_lock(&client_mutex); 3083f0fba2adSLiam Girdwood list_add(&dai->list, &dai_list); 3084f0fba2adSLiam Girdwood mutex_unlock(&client_mutex); 3085f0fba2adSLiam Girdwood 3086f0fba2adSLiam Girdwood pr_debug("Registered DAI '%s'\n", dai->name); 3087f0fba2adSLiam Girdwood } 3088f0fba2adSLiam Girdwood 30891dcb4f38SAxel Lin mutex_lock(&client_mutex); 3090f0fba2adSLiam Girdwood snd_soc_instantiate_cards(); 30911dcb4f38SAxel Lin mutex_unlock(&client_mutex); 30929115171aSMark Brown return 0; 30939115171aSMark Brown 30949115171aSMark Brown err: 30959115171aSMark Brown for (i--; i >= 0; i--) 3096f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 30979115171aSMark Brown 30989115171aSMark Brown return ret; 30999115171aSMark Brown } 31009115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dais); 31019115171aSMark Brown 31029115171aSMark Brown /** 31039115171aSMark Brown * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core 31049115171aSMark Brown * 3105ac11a2b3SMark Brown * @dai: Array of DAIs to unregister 3106ac11a2b3SMark Brown * @count: Number of DAIs 31079115171aSMark Brown */ 3108f0fba2adSLiam Girdwood void snd_soc_unregister_dais(struct device *dev, size_t count) 31099115171aSMark Brown { 31109115171aSMark Brown int i; 31119115171aSMark Brown 31129115171aSMark Brown for (i = 0; i < count; i++) 3113f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 31149115171aSMark Brown } 31159115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); 31169115171aSMark Brown 311712a48a8cSMark Brown /** 311812a48a8cSMark Brown * snd_soc_register_platform - Register a platform with the ASoC core 311912a48a8cSMark Brown * 3120ac11a2b3SMark Brown * @platform: platform to register 312112a48a8cSMark Brown */ 3122f0fba2adSLiam Girdwood int snd_soc_register_platform(struct device *dev, 3123f0fba2adSLiam Girdwood struct snd_soc_platform_driver *platform_drv) 312412a48a8cSMark Brown { 3125f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 312612a48a8cSMark Brown 3127f0fba2adSLiam Girdwood dev_dbg(dev, "platform register %s\n", dev_name(dev)); 3128f0fba2adSLiam Girdwood 3129f0fba2adSLiam Girdwood platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 3130f0fba2adSLiam Girdwood if (platform == NULL) 3131f0fba2adSLiam Girdwood return -ENOMEM; 3132f0fba2adSLiam Girdwood 3133f0fba2adSLiam Girdwood /* create platform component name */ 3134f0fba2adSLiam Girdwood platform->name = fmt_single_name(dev, &platform->id); 3135f0fba2adSLiam Girdwood if (platform->name == NULL) { 3136f0fba2adSLiam Girdwood kfree(platform); 3137f0fba2adSLiam Girdwood return -ENOMEM; 3138f0fba2adSLiam Girdwood } 3139f0fba2adSLiam Girdwood 3140f0fba2adSLiam Girdwood platform->dev = dev; 3141f0fba2adSLiam Girdwood platform->driver = platform_drv; 3142b7950641SLiam Girdwood platform->dapm.dev = dev; 3143b7950641SLiam Girdwood platform->dapm.platform = platform; 3144*64a648c2SLiam Girdwood platform->dapm.stream_event = platform_drv->stream_event; 314512a48a8cSMark Brown 314612a48a8cSMark Brown mutex_lock(&client_mutex); 314712a48a8cSMark Brown list_add(&platform->list, &platform_list); 3148435c5e25SMark Brown snd_soc_instantiate_cards(); 314912a48a8cSMark Brown mutex_unlock(&client_mutex); 315012a48a8cSMark Brown 315112a48a8cSMark Brown pr_debug("Registered platform '%s'\n", platform->name); 315212a48a8cSMark Brown 315312a48a8cSMark Brown return 0; 315412a48a8cSMark Brown } 315512a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 315612a48a8cSMark Brown 315712a48a8cSMark Brown /** 315812a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 315912a48a8cSMark Brown * 3160ac11a2b3SMark Brown * @platform: platform to unregister 316112a48a8cSMark Brown */ 3162f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 316312a48a8cSMark Brown { 3164f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 3165f0fba2adSLiam Girdwood 3166f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 3167f0fba2adSLiam Girdwood if (dev == platform->dev) 3168f0fba2adSLiam Girdwood goto found; 3169f0fba2adSLiam Girdwood } 3170f0fba2adSLiam Girdwood return; 3171f0fba2adSLiam Girdwood 3172f0fba2adSLiam Girdwood found: 317312a48a8cSMark Brown mutex_lock(&client_mutex); 317412a48a8cSMark Brown list_del(&platform->list); 317512a48a8cSMark Brown mutex_unlock(&client_mutex); 317612a48a8cSMark Brown 317712a48a8cSMark Brown pr_debug("Unregistered platform '%s'\n", platform->name); 3178f0fba2adSLiam Girdwood kfree(platform->name); 3179f0fba2adSLiam Girdwood kfree(platform); 318012a48a8cSMark Brown } 318112a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 318212a48a8cSMark Brown 3183151ab22cSMark Brown static u64 codec_format_map[] = { 3184151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 3185151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 3186151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 3187151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 3188151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 3189151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 3190151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3191151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3192151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 3193151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 3194151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 3195151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 3196151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 3197151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 3198151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 3199151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 3200151ab22cSMark Brown }; 3201151ab22cSMark Brown 3202151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 3203151ab22cSMark Brown * the endianness of the data but we're using the CPU format 3204151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 3205151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 3206151ab22cSMark Brown */ 3207151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 3208151ab22cSMark Brown { 3209151ab22cSMark Brown int i; 3210151ab22cSMark Brown 3211151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 3212151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 3213151ab22cSMark Brown stream->formats |= codec_format_map[i]; 3214151ab22cSMark Brown } 3215151ab22cSMark Brown 32160d0cf00aSMark Brown /** 32170d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 32180d0cf00aSMark Brown * 3219ac11a2b3SMark Brown * @codec: codec to register 32200d0cf00aSMark Brown */ 3221f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 3222001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 3223001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 3224001ae4c0SMark Brown int num_dai) 32250d0cf00aSMark Brown { 32263335ddcaSDimitris Papastamos size_t reg_size; 3227f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3228f0fba2adSLiam Girdwood int ret, i; 3229151ab22cSMark Brown 3230f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 32310d0cf00aSMark Brown 3232f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 3233f0fba2adSLiam Girdwood if (codec == NULL) 3234f0fba2adSLiam Girdwood return -ENOMEM; 32350d0cf00aSMark Brown 3236f0fba2adSLiam Girdwood /* create CODEC component name */ 3237f0fba2adSLiam Girdwood codec->name = fmt_single_name(dev, &codec->id); 3238f0fba2adSLiam Girdwood if (codec->name == NULL) { 3239f0fba2adSLiam Girdwood kfree(codec); 3240f0fba2adSLiam Girdwood return -ENOMEM; 3241151ab22cSMark Brown } 3242151ab22cSMark Brown 324323bbce34SDimitris Papastamos if (codec_drv->compress_type) 324423bbce34SDimitris Papastamos codec->compress_type = codec_drv->compress_type; 324523bbce34SDimitris Papastamos else 324623bbce34SDimitris Papastamos codec->compress_type = SND_SOC_FLAT_COMPRESSION; 324723bbce34SDimitris Papastamos 3248c3acec26SMark Brown codec->write = codec_drv->write; 3249c3acec26SMark Brown codec->read = codec_drv->read; 32501500b7b5SDimitris Papastamos codec->volatile_register = codec_drv->volatile_register; 32511500b7b5SDimitris Papastamos codec->readable_register = codec_drv->readable_register; 32528020454cSDimitris Papastamos codec->writable_register = codec_drv->writable_register; 3253ce6120ccSLiam Girdwood codec->dapm.bias_level = SND_SOC_BIAS_OFF; 3254ce6120ccSLiam Girdwood codec->dapm.dev = dev; 3255ce6120ccSLiam Girdwood codec->dapm.codec = codec; 3256474b62d6SMark Brown codec->dapm.seq_notifier = codec_drv->seq_notifier; 3257*64a648c2SLiam Girdwood codec->dapm.stream_event = codec_drv->stream_event; 3258f0fba2adSLiam Girdwood codec->dev = dev; 3259f0fba2adSLiam Girdwood codec->driver = codec_drv; 3260f0fba2adSLiam Girdwood codec->num_dai = num_dai; 3261f0fba2adSLiam Girdwood mutex_init(&codec->mutex); 3262f0fba2adSLiam Girdwood 32637a30a3dbSDimitris Papastamos /* allocate CODEC register cache */ 32647a30a3dbSDimitris Papastamos if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 32653335ddcaSDimitris Papastamos reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 3266aea170a0SDimitris Papastamos codec->reg_size = reg_size; 32673335ddcaSDimitris Papastamos /* it is necessary to make a copy of the default register cache 32683335ddcaSDimitris Papastamos * because in the case of using a compression type that requires 32693335ddcaSDimitris Papastamos * the default register cache to be marked as __devinitconst the 32703335ddcaSDimitris Papastamos * kernel might have freed the array by the time we initialize 32713335ddcaSDimitris Papastamos * the cache. 32723335ddcaSDimitris Papastamos */ 32732aa86323SDimitris Papastamos if (codec_drv->reg_cache_default) { 32743335ddcaSDimitris Papastamos codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, 32753335ddcaSDimitris Papastamos reg_size, GFP_KERNEL); 32763335ddcaSDimitris Papastamos if (!codec->reg_def_copy) { 32773335ddcaSDimitris Papastamos ret = -ENOMEM; 3278fdf0f54dSDimitris Papastamos goto fail; 32797a30a3dbSDimitris Papastamos } 32807a30a3dbSDimitris Papastamos } 32812aa86323SDimitris Papastamos } 32827a30a3dbSDimitris Papastamos 32831500b7b5SDimitris Papastamos if (codec_drv->reg_access_size && codec_drv->reg_access_default) { 32841500b7b5SDimitris Papastamos if (!codec->volatile_register) 32851500b7b5SDimitris Papastamos codec->volatile_register = snd_soc_default_volatile_register; 32861500b7b5SDimitris Papastamos if (!codec->readable_register) 32871500b7b5SDimitris Papastamos codec->readable_register = snd_soc_default_readable_register; 32888020454cSDimitris Papastamos if (!codec->writable_register) 32898020454cSDimitris Papastamos codec->writable_register = snd_soc_default_writable_register; 32901500b7b5SDimitris Papastamos } 32911500b7b5SDimitris Papastamos 3292f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 3293f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 3294f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 3295f0fba2adSLiam Girdwood } 3296f0fba2adSLiam Girdwood 329726b01ccdSMark Brown /* register any DAIs */ 329826b01ccdSMark Brown if (num_dai) { 3299f0fba2adSLiam Girdwood ret = snd_soc_register_dais(dev, dai_drv, num_dai); 3300f0fba2adSLiam Girdwood if (ret < 0) 3301fdf0f54dSDimitris Papastamos goto fail; 330226b01ccdSMark Brown } 3303f0fba2adSLiam Girdwood 33040d0cf00aSMark Brown mutex_lock(&client_mutex); 33050d0cf00aSMark Brown list_add(&codec->list, &codec_list); 33060d0cf00aSMark Brown snd_soc_instantiate_cards(); 33070d0cf00aSMark Brown mutex_unlock(&client_mutex); 33080d0cf00aSMark Brown 33090d0cf00aSMark Brown pr_debug("Registered codec '%s'\n", codec->name); 33100d0cf00aSMark Brown return 0; 3311f0fba2adSLiam Girdwood 3312fdf0f54dSDimitris Papastamos fail: 33133335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 33143335ddcaSDimitris Papastamos codec->reg_def_copy = NULL; 3315f0fba2adSLiam Girdwood kfree(codec->name); 3316f0fba2adSLiam Girdwood kfree(codec); 3317f0fba2adSLiam Girdwood return ret; 33180d0cf00aSMark Brown } 33190d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 33200d0cf00aSMark Brown 33210d0cf00aSMark Brown /** 33220d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 33230d0cf00aSMark Brown * 3324ac11a2b3SMark Brown * @codec: codec to unregister 33250d0cf00aSMark Brown */ 3326f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 33270d0cf00aSMark Brown { 3328f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3329f0fba2adSLiam Girdwood int i; 3330f0fba2adSLiam Girdwood 3331f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 3332f0fba2adSLiam Girdwood if (dev == codec->dev) 3333f0fba2adSLiam Girdwood goto found; 3334f0fba2adSLiam Girdwood } 3335f0fba2adSLiam Girdwood return; 3336f0fba2adSLiam Girdwood 3337f0fba2adSLiam Girdwood found: 333826b01ccdSMark Brown if (codec->num_dai) 3339f0fba2adSLiam Girdwood for (i = 0; i < codec->num_dai; i++) 3340f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 3341f0fba2adSLiam Girdwood 33420d0cf00aSMark Brown mutex_lock(&client_mutex); 33430d0cf00aSMark Brown list_del(&codec->list); 33440d0cf00aSMark Brown mutex_unlock(&client_mutex); 33450d0cf00aSMark Brown 33460d0cf00aSMark Brown pr_debug("Unregistered codec '%s'\n", codec->name); 3347f0fba2adSLiam Girdwood 33487a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 33493335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 33501aafcd4dSDimitris Papastamos kfree(codec->name); 3351f0fba2adSLiam Girdwood kfree(codec); 33520d0cf00aSMark Brown } 33530d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 33540d0cf00aSMark Brown 3355c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 3356db2a4165SFrank Mandarino { 3357384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 33588a9dab1aSMark Brown snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); 33598a9dab1aSMark Brown if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { 3360384c89e2SMark Brown printk(KERN_WARNING 3361384c89e2SMark Brown "ASoC: Failed to create debugfs directory\n"); 33628a9dab1aSMark Brown snd_soc_debugfs_root = NULL; 3363384c89e2SMark Brown } 3364c3c5a19aSMark Brown 33658a9dab1aSMark Brown if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, 3366c3c5a19aSMark Brown &codec_list_fops)) 3367c3c5a19aSMark Brown pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); 3368c3c5a19aSMark Brown 33698a9dab1aSMark Brown if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, 3370f3208780SMark Brown &dai_list_fops)) 3371f3208780SMark Brown pr_warn("ASoC: Failed to create DAI list debugfs file\n"); 337219c7ac27SMark Brown 33738a9dab1aSMark Brown if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, 337419c7ac27SMark Brown &platform_list_fops)) 337519c7ac27SMark Brown pr_warn("ASoC: Failed to create platform list debugfs file\n"); 3376384c89e2SMark Brown #endif 3377384c89e2SMark Brown 3378fb257897SMark Brown snd_soc_util_init(); 3379fb257897SMark Brown 3380db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 3381db2a4165SFrank Mandarino } 33824abe8e16SMark Brown module_init(snd_soc_init); 3383db2a4165SFrank Mandarino 33847d8c16a6SMark Brown static void __exit snd_soc_exit(void) 3385db2a4165SFrank Mandarino { 3386fb257897SMark Brown snd_soc_util_exit(); 3387fb257897SMark Brown 3388384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 33898a9dab1aSMark Brown debugfs_remove_recursive(snd_soc_debugfs_root); 3390384c89e2SMark Brown #endif 3391db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 3392db2a4165SFrank Mandarino } 3393db2a4165SFrank Mandarino module_exit(snd_soc_exit); 3394db2a4165SFrank Mandarino 3395db2a4165SFrank Mandarino /* Module information */ 3396d331124dSLiam Girdwood MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 3397db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 3398db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 33998b45a209SKay Sievers MODULE_ALIAS("platform:soc-audio"); 3400