1db2a4165SFrank Mandarino /* 2db2a4165SFrank Mandarino * soc-core.c -- ALSA SoC Audio Layer 3db2a4165SFrank Mandarino * 4db2a4165SFrank Mandarino * Copyright 2005 Wolfson Microelectronics PLC. 50664d888SLiam Girdwood * Copyright 2005 Openedhand Ltd. 6f0fba2adSLiam Girdwood * Copyright (C) 2010 Slimlogic Ltd. 7f0fba2adSLiam Girdwood * Copyright (C) 2010 Texas Instruments Inc. 80664d888SLiam Girdwood * 9d331124dSLiam Girdwood * Author: Liam Girdwood <lrg@slimlogic.co.uk> 100664d888SLiam Girdwood * with code, comments and ideas from :- 110664d888SLiam Girdwood * Richard Purdie <richard@openedhand.com> 12db2a4165SFrank Mandarino * 13db2a4165SFrank Mandarino * This program is free software; you can redistribute it and/or modify it 14db2a4165SFrank Mandarino * under the terms of the GNU General Public License as published by the 15db2a4165SFrank Mandarino * Free Software Foundation; either version 2 of the License, or (at your 16db2a4165SFrank Mandarino * option) any later version. 17db2a4165SFrank Mandarino * 18db2a4165SFrank Mandarino * TODO: 19db2a4165SFrank Mandarino * o Add hw rules to enforce rates, etc. 20db2a4165SFrank Mandarino * o More testing with other codecs/machines. 21db2a4165SFrank Mandarino * o Add more codecs and platforms to ensure good API coverage. 22db2a4165SFrank Mandarino * o Support TDM on PCM and I2S 23db2a4165SFrank Mandarino */ 24db2a4165SFrank Mandarino 25db2a4165SFrank Mandarino #include <linux/module.h> 26db2a4165SFrank Mandarino #include <linux/moduleparam.h> 27db2a4165SFrank Mandarino #include <linux/init.h> 28db2a4165SFrank Mandarino #include <linux/delay.h> 29db2a4165SFrank Mandarino #include <linux/pm.h> 30db2a4165SFrank Mandarino #include <linux/bitops.h> 3112ef193dSTroy Kisky #include <linux/debugfs.h> 32db2a4165SFrank Mandarino #include <linux/platform_device.h> 33f0e8ed85SMark Brown #include <linux/ctype.h> 345a0e3ad6STejun Heo #include <linux/slab.h> 35474828a4SMarek Vasut #include <sound/ac97_codec.h> 36db2a4165SFrank Mandarino #include <sound/core.h> 373028eb8cSMark Brown #include <sound/jack.h> 38db2a4165SFrank Mandarino #include <sound/pcm.h> 39db2a4165SFrank Mandarino #include <sound/pcm_params.h> 40db2a4165SFrank Mandarino #include <sound/soc.h> 41db2a4165SFrank Mandarino #include <sound/initval.h> 42db2a4165SFrank Mandarino 43a8b1d34fSMark Brown #define CREATE_TRACE_POINTS 44a8b1d34fSMark Brown #include <trace/events/asoc.h> 45a8b1d34fSMark Brown 46f0fba2adSLiam Girdwood #define NAME_SIZE 32 47f0fba2adSLiam Girdwood 48db2a4165SFrank Mandarino static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 49db2a4165SFrank Mandarino 50384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 518a9dab1aSMark Brown struct dentry *snd_soc_debugfs_root; 528a9dab1aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); 53384c89e2SMark Brown #endif 54384c89e2SMark Brown 55c5af3a2eSMark Brown static DEFINE_MUTEX(client_mutex); 56c5af3a2eSMark Brown static LIST_HEAD(card_list); 579115171aSMark Brown static LIST_HEAD(dai_list); 5812a48a8cSMark Brown static LIST_HEAD(platform_list); 590d0cf00aSMark Brown static LIST_HEAD(codec_list); 60c5af3a2eSMark Brown 61ddee627cSLiam Girdwood int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); 62c5af3a2eSMark Brown 63db2a4165SFrank Mandarino /* 64db2a4165SFrank Mandarino * This is a timeout to do a DAPM powerdown after a stream is closed(). 65db2a4165SFrank Mandarino * It can be used to eliminate pops between different playback streams, e.g. 66db2a4165SFrank Mandarino * between two audio tracks. 67db2a4165SFrank Mandarino */ 68db2a4165SFrank Mandarino static int pmdown_time = 5000; 69db2a4165SFrank Mandarino module_param(pmdown_time, int, 0); 70db2a4165SFrank Mandarino MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 71db2a4165SFrank Mandarino 722bc9a81eSDimitris Papastamos /* returns the minimum number of bytes needed to represent 732bc9a81eSDimitris Papastamos * a particular given value */ 742bc9a81eSDimitris Papastamos static int min_bytes_needed(unsigned long val) 752bc9a81eSDimitris Papastamos { 762bc9a81eSDimitris Papastamos int c = 0; 772bc9a81eSDimitris Papastamos int i; 782bc9a81eSDimitris Papastamos 792bc9a81eSDimitris Papastamos for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) 802bc9a81eSDimitris Papastamos if (val & (1UL << i)) 812bc9a81eSDimitris Papastamos break; 822bc9a81eSDimitris Papastamos c = (sizeof val * 8) - c; 832bc9a81eSDimitris Papastamos if (!c || (c % 8)) 842bc9a81eSDimitris Papastamos c = (c + 8) / 8; 852bc9a81eSDimitris Papastamos else 862bc9a81eSDimitris Papastamos c /= 8; 872bc9a81eSDimitris Papastamos return c; 882bc9a81eSDimitris Papastamos } 892bc9a81eSDimitris Papastamos 9013fd179fSDimitris Papastamos /* fill buf which is 'len' bytes with a formatted 9113fd179fSDimitris Papastamos * string of the form 'reg: value\n' */ 9213fd179fSDimitris Papastamos static int format_register_str(struct snd_soc_codec *codec, 9313fd179fSDimitris Papastamos unsigned int reg, char *buf, size_t len) 942624d5faSMark Brown { 9500b317a4SStephen Warren int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 9600b317a4SStephen Warren int regsize = codec->driver->reg_word_size * 2; 9713fd179fSDimitris Papastamos int ret; 9813fd179fSDimitris Papastamos char tmpbuf[len + 1]; 9913fd179fSDimitris Papastamos char regbuf[regsize + 1]; 10013fd179fSDimitris Papastamos 10113fd179fSDimitris Papastamos /* since tmpbuf is allocated on the stack, warn the callers if they 10213fd179fSDimitris Papastamos * try to abuse this function */ 10313fd179fSDimitris Papastamos WARN_ON(len > 63); 10413fd179fSDimitris Papastamos 10513fd179fSDimitris Papastamos /* +2 for ': ' and + 1 for '\n' */ 10613fd179fSDimitris Papastamos if (wordsize + regsize + 2 + 1 != len) 10713fd179fSDimitris Papastamos return -EINVAL; 10813fd179fSDimitris Papastamos 10913fd179fSDimitris Papastamos ret = snd_soc_read(codec, reg); 11013fd179fSDimitris Papastamos if (ret < 0) { 11113fd179fSDimitris Papastamos memset(regbuf, 'X', regsize); 11213fd179fSDimitris Papastamos regbuf[regsize] = '\0'; 11313fd179fSDimitris Papastamos } else { 11413fd179fSDimitris Papastamos snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); 11513fd179fSDimitris Papastamos } 11613fd179fSDimitris Papastamos 11713fd179fSDimitris Papastamos /* prepare the buffer */ 11813fd179fSDimitris Papastamos snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); 11913fd179fSDimitris Papastamos /* copy it back to the caller without the '\0' */ 12013fd179fSDimitris Papastamos memcpy(buf, tmpbuf, len); 12113fd179fSDimitris Papastamos 12213fd179fSDimitris Papastamos return 0; 12313fd179fSDimitris Papastamos } 12413fd179fSDimitris Papastamos 12513fd179fSDimitris Papastamos /* codec register dump */ 12613fd179fSDimitris Papastamos static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, 12713fd179fSDimitris Papastamos size_t count, loff_t pos) 12813fd179fSDimitris Papastamos { 12913fd179fSDimitris Papastamos int i, step = 1; 1302bc9a81eSDimitris Papastamos int wordsize, regsize; 13113fd179fSDimitris Papastamos int len; 13213fd179fSDimitris Papastamos size_t total = 0; 13313fd179fSDimitris Papastamos loff_t p = 0; 1342bc9a81eSDimitris Papastamos 13500b317a4SStephen Warren wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; 13600b317a4SStephen Warren regsize = codec->driver->reg_word_size * 2; 1372624d5faSMark Brown 13813fd179fSDimitris Papastamos len = wordsize + regsize + 2 + 1; 13913fd179fSDimitris Papastamos 140f0fba2adSLiam Girdwood if (!codec->driver->reg_cache_size) 1412624d5faSMark Brown return 0; 1422624d5faSMark Brown 143f0fba2adSLiam Girdwood if (codec->driver->reg_cache_step) 144f0fba2adSLiam Girdwood step = codec->driver->reg_cache_step; 1452624d5faSMark Brown 146f0fba2adSLiam Girdwood for (i = 0; i < codec->driver->reg_cache_size; i += step) { 147b92d150bSLars-Peter Clausen if (!snd_soc_codec_readable_register(codec, i)) 1482624d5faSMark Brown continue; 149f0fba2adSLiam Girdwood if (codec->driver->display_register) { 150f0fba2adSLiam Girdwood count += codec->driver->display_register(codec, buf + count, 1512624d5faSMark Brown PAGE_SIZE - count, i); 1525164d74dSMark Brown } else { 15313fd179fSDimitris Papastamos /* only support larger than PAGE_SIZE bytes debugfs 15413fd179fSDimitris Papastamos * entries for the default case */ 15513fd179fSDimitris Papastamos if (p >= pos) { 15613fd179fSDimitris Papastamos if (total + len >= count - 1) 1572624d5faSMark Brown break; 15813fd179fSDimitris Papastamos format_register_str(codec, i, buf + total, len); 15913fd179fSDimitris Papastamos total += len; 16013fd179fSDimitris Papastamos } 16113fd179fSDimitris Papastamos p += len; 16213fd179fSDimitris Papastamos } 1632624d5faSMark Brown } 1642624d5faSMark Brown 16513fd179fSDimitris Papastamos total = min(total, count - 1); 1662624d5faSMark Brown 16713fd179fSDimitris Papastamos return total; 1682624d5faSMark Brown } 16913fd179fSDimitris Papastamos 1702624d5faSMark Brown static ssize_t codec_reg_show(struct device *dev, 1712624d5faSMark Brown struct device_attribute *attr, char *buf) 1722624d5faSMark Brown { 173f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 174f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 175f0fba2adSLiam Girdwood 17613fd179fSDimitris Papastamos return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 1772624d5faSMark Brown } 1782624d5faSMark Brown 1792624d5faSMark Brown static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1802624d5faSMark Brown 181dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev, 182dbe21408SMark Brown struct device_attribute *attr, char *buf) 183dbe21408SMark Brown { 184f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 185f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 186dbe21408SMark Brown 187f0fba2adSLiam Girdwood return sprintf(buf, "%ld\n", rtd->pmdown_time); 188dbe21408SMark Brown } 189dbe21408SMark Brown 190dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev, 191dbe21408SMark Brown struct device_attribute *attr, 192dbe21408SMark Brown const char *buf, size_t count) 193dbe21408SMark Brown { 194f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = 195f0fba2adSLiam Girdwood container_of(dev, struct snd_soc_pcm_runtime, dev); 196c593b520SMark Brown int ret; 197dbe21408SMark Brown 198c593b520SMark Brown ret = strict_strtol(buf, 10, &rtd->pmdown_time); 199c593b520SMark Brown if (ret) 200c593b520SMark Brown return ret; 201dbe21408SMark Brown 202dbe21408SMark Brown return count; 203dbe21408SMark Brown } 204dbe21408SMark Brown 205dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 206dbe21408SMark Brown 2072624d5faSMark Brown #ifdef CONFIG_DEBUG_FS 2082624d5faSMark Brown static int codec_reg_open_file(struct inode *inode, struct file *file) 2092624d5faSMark Brown { 2102624d5faSMark Brown file->private_data = inode->i_private; 2112624d5faSMark Brown return 0; 2122624d5faSMark Brown } 2132624d5faSMark Brown 2142624d5faSMark Brown static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 2152624d5faSMark Brown size_t count, loff_t *ppos) 2162624d5faSMark Brown { 2172624d5faSMark Brown ssize_t ret; 2182624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 21913fd179fSDimitris Papastamos char *buf; 22013fd179fSDimitris Papastamos 22113fd179fSDimitris Papastamos if (*ppos < 0 || !count) 22213fd179fSDimitris Papastamos return -EINVAL; 22313fd179fSDimitris Papastamos 22413fd179fSDimitris Papastamos buf = kmalloc(count, GFP_KERNEL); 2252624d5faSMark Brown if (!buf) 2262624d5faSMark Brown return -ENOMEM; 22713fd179fSDimitris Papastamos 22813fd179fSDimitris Papastamos ret = soc_codec_reg_show(codec, buf, count, *ppos); 22913fd179fSDimitris Papastamos if (ret >= 0) { 23013fd179fSDimitris Papastamos if (copy_to_user(user_buf, buf, ret)) { 23113fd179fSDimitris Papastamos kfree(buf); 23213fd179fSDimitris Papastamos return -EFAULT; 23313fd179fSDimitris Papastamos } 23413fd179fSDimitris Papastamos *ppos += ret; 23513fd179fSDimitris Papastamos } 23613fd179fSDimitris Papastamos 2372624d5faSMark Brown kfree(buf); 2382624d5faSMark Brown return ret; 2392624d5faSMark Brown } 2402624d5faSMark Brown 2412624d5faSMark Brown static ssize_t codec_reg_write_file(struct file *file, 2422624d5faSMark Brown const char __user *user_buf, size_t count, loff_t *ppos) 2432624d5faSMark Brown { 2442624d5faSMark Brown char buf[32]; 24534e268d8SStephen Boyd size_t buf_size; 2462624d5faSMark Brown char *start = buf; 2472624d5faSMark Brown unsigned long reg, value; 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 2552624d5faSMark Brown while (*start == ' ') 2562624d5faSMark Brown start++; 2572624d5faSMark Brown reg = simple_strtoul(start, &start, 16); 2582624d5faSMark Brown while (*start == ' ') 2592624d5faSMark Brown start++; 2602624d5faSMark Brown if (strict_strtoul(start, 16, &value)) 2612624d5faSMark Brown return -EINVAL; 2620d51a9cbSMark Brown 2630d51a9cbSMark Brown /* Userspace has been fiddling around behind the kernel's back */ 2640d51a9cbSMark Brown add_taint(TAINT_USER); 2650d51a9cbSMark Brown 266e4f078d8SDimitris Papastamos snd_soc_write(codec, reg, value); 2672624d5faSMark Brown return buf_size; 2682624d5faSMark Brown } 2692624d5faSMark Brown 2702624d5faSMark Brown static const struct file_operations codec_reg_fops = { 2712624d5faSMark Brown .open = codec_reg_open_file, 2722624d5faSMark Brown .read = codec_reg_read_file, 2732624d5faSMark Brown .write = codec_reg_write_file, 2746038f373SArnd Bergmann .llseek = default_llseek, 2752624d5faSMark Brown }; 2762624d5faSMark Brown 2772624d5faSMark Brown static void soc_init_codec_debugfs(struct snd_soc_codec *codec) 2782624d5faSMark Brown { 279d6ce4cf3SJarkko Nikula struct dentry *debugfs_card_root = codec->card->debugfs_card_root; 280d6ce4cf3SJarkko Nikula 2816ba6c9c3SMark Brown codec->debugfs_codec_root = debugfs_create_dir(codec->name, 282d6ce4cf3SJarkko Nikula debugfs_card_root); 2832624d5faSMark Brown if (!codec->debugfs_codec_root) { 2842624d5faSMark Brown printk(KERN_WARNING 2852624d5faSMark Brown "ASoC: Failed to create codec debugfs directory\n"); 2862624d5faSMark Brown return; 2872624d5faSMark Brown } 2882624d5faSMark Brown 289aaee8ef1SMark Brown debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, 290aaee8ef1SMark Brown &codec->cache_sync); 291aaee8ef1SMark Brown debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, 292aaee8ef1SMark Brown &codec->cache_only); 293aaee8ef1SMark Brown 2942624d5faSMark Brown codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 2952624d5faSMark Brown codec->debugfs_codec_root, 2962624d5faSMark Brown codec, &codec_reg_fops); 2972624d5faSMark Brown if (!codec->debugfs_reg) 2982624d5faSMark Brown printk(KERN_WARNING 2992624d5faSMark Brown "ASoC: Failed to create codec register debugfs file\n"); 3002624d5faSMark Brown 3018eecaf62SLars-Peter Clausen snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); 3022624d5faSMark Brown } 3032624d5faSMark Brown 3042624d5faSMark Brown static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 3052624d5faSMark Brown { 3062624d5faSMark Brown debugfs_remove_recursive(codec->debugfs_codec_root); 3072624d5faSMark Brown } 3082624d5faSMark Brown 309c3c5a19aSMark Brown static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, 310c3c5a19aSMark Brown size_t count, loff_t *ppos) 311c3c5a19aSMark Brown { 312c3c5a19aSMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3132b194f9dSMark Brown ssize_t len, ret = 0; 314c3c5a19aSMark Brown struct snd_soc_codec *codec; 315c3c5a19aSMark Brown 316c3c5a19aSMark Brown if (!buf) 317c3c5a19aSMark Brown return -ENOMEM; 318c3c5a19aSMark Brown 3192b194f9dSMark Brown list_for_each_entry(codec, &codec_list, list) { 3202b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 321c3c5a19aSMark Brown codec->name); 3222b194f9dSMark Brown if (len >= 0) 3232b194f9dSMark Brown ret += len; 3242b194f9dSMark Brown if (ret > PAGE_SIZE) { 3252b194f9dSMark Brown ret = PAGE_SIZE; 3262b194f9dSMark Brown break; 3272b194f9dSMark Brown } 3282b194f9dSMark Brown } 329c3c5a19aSMark Brown 330c3c5a19aSMark Brown if (ret >= 0) 331c3c5a19aSMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 332c3c5a19aSMark Brown 333c3c5a19aSMark Brown kfree(buf); 334c3c5a19aSMark Brown 335c3c5a19aSMark Brown return ret; 336c3c5a19aSMark Brown } 337c3c5a19aSMark Brown 338c3c5a19aSMark Brown static const struct file_operations codec_list_fops = { 339c3c5a19aSMark Brown .read = codec_list_read_file, 340c3c5a19aSMark Brown .llseek = default_llseek,/* read accesses f_pos */ 341c3c5a19aSMark Brown }; 342c3c5a19aSMark Brown 343f3208780SMark Brown static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, 344f3208780SMark Brown size_t count, loff_t *ppos) 345f3208780SMark Brown { 346f3208780SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3472b194f9dSMark Brown ssize_t len, ret = 0; 348f3208780SMark Brown struct snd_soc_dai *dai; 349f3208780SMark Brown 350f3208780SMark Brown if (!buf) 351f3208780SMark Brown return -ENOMEM; 352f3208780SMark Brown 3532b194f9dSMark Brown list_for_each_entry(dai, &dai_list, list) { 3542b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); 3552b194f9dSMark Brown if (len >= 0) 3562b194f9dSMark Brown ret += len; 3572b194f9dSMark Brown if (ret > PAGE_SIZE) { 3582b194f9dSMark Brown ret = PAGE_SIZE; 3592b194f9dSMark Brown break; 3602b194f9dSMark Brown } 3612b194f9dSMark Brown } 362f3208780SMark Brown 363f3208780SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 364f3208780SMark Brown 365f3208780SMark Brown kfree(buf); 366f3208780SMark Brown 367f3208780SMark Brown return ret; 368f3208780SMark Brown } 369f3208780SMark Brown 370f3208780SMark Brown static const struct file_operations dai_list_fops = { 371f3208780SMark Brown .read = dai_list_read_file, 372f3208780SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 373f3208780SMark Brown }; 374f3208780SMark Brown 37519c7ac27SMark Brown static ssize_t platform_list_read_file(struct file *file, 37619c7ac27SMark Brown char __user *user_buf, 37719c7ac27SMark Brown size_t count, loff_t *ppos) 37819c7ac27SMark Brown { 37919c7ac27SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3802b194f9dSMark Brown ssize_t len, ret = 0; 38119c7ac27SMark Brown struct snd_soc_platform *platform; 38219c7ac27SMark Brown 38319c7ac27SMark Brown if (!buf) 38419c7ac27SMark Brown return -ENOMEM; 38519c7ac27SMark Brown 3862b194f9dSMark Brown list_for_each_entry(platform, &platform_list, list) { 3872b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 38819c7ac27SMark Brown platform->name); 3892b194f9dSMark Brown if (len >= 0) 3902b194f9dSMark Brown ret += len; 3912b194f9dSMark Brown if (ret > PAGE_SIZE) { 3922b194f9dSMark Brown ret = PAGE_SIZE; 3932b194f9dSMark Brown break; 3942b194f9dSMark Brown } 3952b194f9dSMark Brown } 39619c7ac27SMark Brown 39719c7ac27SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 39819c7ac27SMark Brown 39919c7ac27SMark Brown kfree(buf); 40019c7ac27SMark Brown 40119c7ac27SMark Brown return ret; 40219c7ac27SMark Brown } 40319c7ac27SMark Brown 40419c7ac27SMark Brown static const struct file_operations platform_list_fops = { 40519c7ac27SMark Brown .read = platform_list_read_file, 40619c7ac27SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 40719c7ac27SMark Brown }; 40819c7ac27SMark Brown 409a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card) 410a6052154SJarkko Nikula { 411a6052154SJarkko Nikula card->debugfs_card_root = debugfs_create_dir(card->name, 4128a9dab1aSMark Brown snd_soc_debugfs_root); 4133a45b867SJarkko Nikula if (!card->debugfs_card_root) { 414a6052154SJarkko Nikula dev_warn(card->dev, 415a6052154SJarkko Nikula "ASoC: Failed to create codec debugfs directory\n"); 4163a45b867SJarkko Nikula return; 4173a45b867SJarkko Nikula } 4183a45b867SJarkko Nikula 4193a45b867SJarkko Nikula card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 4203a45b867SJarkko Nikula card->debugfs_card_root, 4213a45b867SJarkko Nikula &card->pop_time); 4223a45b867SJarkko Nikula if (!card->debugfs_pop_time) 4233a45b867SJarkko Nikula dev_warn(card->dev, 4243a45b867SJarkko Nikula "Failed to create pop time debugfs file\n"); 425a6052154SJarkko Nikula } 426a6052154SJarkko Nikula 427a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card) 428a6052154SJarkko Nikula { 429a6052154SJarkko Nikula debugfs_remove_recursive(card->debugfs_card_root); 430a6052154SJarkko Nikula } 431a6052154SJarkko Nikula 4322624d5faSMark Brown #else 4332624d5faSMark Brown 4342624d5faSMark Brown static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) 4352624d5faSMark Brown { 4362624d5faSMark Brown } 4372624d5faSMark Brown 4382624d5faSMark Brown static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 4392624d5faSMark Brown { 4402624d5faSMark Brown } 441b95fccbcSAxel Lin 442b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card) 443b95fccbcSAxel Lin { 444b95fccbcSAxel Lin } 445b95fccbcSAxel Lin 446b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) 447b95fccbcSAxel Lin { 448b95fccbcSAxel Lin } 4492624d5faSMark Brown #endif 4502624d5faSMark Brown 451db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS 452db2a4165SFrank Mandarino /* unregister ac97 codec */ 453db2a4165SFrank Mandarino static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 454db2a4165SFrank Mandarino { 455db2a4165SFrank Mandarino if (codec->ac97->dev.bus) 456db2a4165SFrank Mandarino device_unregister(&codec->ac97->dev); 457db2a4165SFrank Mandarino return 0; 458db2a4165SFrank Mandarino } 459db2a4165SFrank Mandarino 460db2a4165SFrank Mandarino /* stop no dev release warning */ 461db2a4165SFrank Mandarino static void soc_ac97_device_release(struct device *dev){} 462db2a4165SFrank Mandarino 463db2a4165SFrank Mandarino /* register ac97 codec to bus */ 464db2a4165SFrank Mandarino static int soc_ac97_dev_register(struct snd_soc_codec *codec) 465db2a4165SFrank Mandarino { 466db2a4165SFrank Mandarino int err; 467db2a4165SFrank Mandarino 468db2a4165SFrank Mandarino codec->ac97->dev.bus = &ac97_bus_type; 4694ac5c61fSMark Brown codec->ac97->dev.parent = codec->card->dev; 470db2a4165SFrank Mandarino codec->ac97->dev.release = soc_ac97_device_release; 471db2a4165SFrank Mandarino 472bb072bf0SKay Sievers dev_set_name(&codec->ac97->dev, "%d-%d:%s", 473f0fba2adSLiam Girdwood codec->card->snd_card->number, 0, codec->name); 474db2a4165SFrank Mandarino err = device_register(&codec->ac97->dev); 475db2a4165SFrank Mandarino if (err < 0) { 476db2a4165SFrank Mandarino snd_printk(KERN_ERR "Can't register ac97 bus\n"); 477db2a4165SFrank Mandarino codec->ac97->dev.bus = NULL; 478db2a4165SFrank Mandarino return err; 479db2a4165SFrank Mandarino } 480db2a4165SFrank Mandarino return 0; 481db2a4165SFrank Mandarino } 482db2a4165SFrank Mandarino #endif 483db2a4165SFrank Mandarino 4846f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP 485db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */ 4866f8ab4acSMark Brown int snd_soc_suspend(struct device *dev) 487db2a4165SFrank Mandarino { 4886f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 4892eea392dSJarkko Nikula struct snd_soc_codec *codec; 490db2a4165SFrank Mandarino int i; 491db2a4165SFrank Mandarino 492e3509ff0SDaniel Mack /* If the initialization of this soc device failed, there is no codec 493e3509ff0SDaniel Mack * associated with it. Just bail out in this case. 494e3509ff0SDaniel Mack */ 495f0fba2adSLiam Girdwood if (list_empty(&card->codec_dev_list)) 496e3509ff0SDaniel Mack return 0; 497e3509ff0SDaniel Mack 4986ed25978SAndy Green /* Due to the resume being scheduled into a workqueue we could 4996ed25978SAndy Green * suspend before that's finished - wait for it to complete. 5006ed25978SAndy Green */ 501f0fba2adSLiam Girdwood snd_power_lock(card->snd_card); 502f0fba2adSLiam Girdwood snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); 503f0fba2adSLiam Girdwood snd_power_unlock(card->snd_card); 5046ed25978SAndy Green 5056ed25978SAndy Green /* we're going to block userspace touching us until resume completes */ 506f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 5076ed25978SAndy Green 508a00f90f9SMark Brown /* mute any active DACs */ 509f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 510f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 511f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 5123efab7dcSMark Brown 513f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5143efab7dcSMark Brown continue; 5153efab7dcSMark Brown 516f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 517f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 1); 518db2a4165SFrank Mandarino } 519db2a4165SFrank Mandarino 5204ccab3e7SLiam Girdwood /* suspend all pcms */ 521f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 522f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5233efab7dcSMark Brown continue; 5243efab7dcSMark Brown 525f0fba2adSLiam Girdwood snd_pcm_suspend_all(card->rtd[i].pcm); 5263efab7dcSMark Brown } 5274ccab3e7SLiam Girdwood 52887506549SMark Brown if (card->suspend_pre) 52970b2ac12SMark Brown card->suspend_pre(card); 530db2a4165SFrank Mandarino 531f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 532f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 533f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 5343efab7dcSMark Brown 535f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5363efab7dcSMark Brown continue; 5373efab7dcSMark Brown 538f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) 539f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 540f0fba2adSLiam Girdwood if (platform->driver->suspend && !platform->suspended) { 541f0fba2adSLiam Girdwood platform->driver->suspend(cpu_dai); 542f0fba2adSLiam Girdwood platform->suspended = 1; 543f0fba2adSLiam Girdwood } 544db2a4165SFrank Mandarino } 545db2a4165SFrank Mandarino 546db2a4165SFrank Mandarino /* close any waiting streams and save state */ 547f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 5485b84ba26STejun Heo flush_delayed_work_sync(&card->rtd[i].delayed_work); 549ce6120ccSLiam Girdwood card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; 550f0fba2adSLiam Girdwood } 551db2a4165SFrank Mandarino 552f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 553f0fba2adSLiam Girdwood struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; 5543efab7dcSMark Brown 555f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5563efab7dcSMark Brown continue; 5573efab7dcSMark Brown 558f0fba2adSLiam Girdwood if (driver->playback.stream_name != NULL) 559f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, 560db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 561f0fba2adSLiam Girdwood 562f0fba2adSLiam Girdwood if (driver->capture.stream_name != NULL) 563f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, 564db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 565db2a4165SFrank Mandarino } 566db2a4165SFrank Mandarino 567f0fba2adSLiam Girdwood /* suspend all CODECs */ 5682eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 5691547aba9SMark Brown /* If there are paths active then the CODEC will be held with 5701547aba9SMark Brown * bias _ON and should not be suspended. */ 571f0fba2adSLiam Girdwood if (!codec->suspended && codec->driver->suspend) { 572ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 5731547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 5741547aba9SMark Brown case SND_SOC_BIAS_OFF: 575f0fba2adSLiam Girdwood codec->driver->suspend(codec, PMSG_SUSPEND); 576f0fba2adSLiam Girdwood codec->suspended = 1; 5777be4ba24SMark Brown codec->cache_sync = 1; 5781547aba9SMark Brown break; 5791547aba9SMark Brown default: 580f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC is on over suspend\n"); 5811547aba9SMark Brown break; 5821547aba9SMark Brown } 5831547aba9SMark Brown } 584f0fba2adSLiam Girdwood } 585db2a4165SFrank Mandarino 586f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 587f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 5883efab7dcSMark Brown 589f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5903efab7dcSMark Brown continue; 5913efab7dcSMark Brown 592f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 593f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 594db2a4165SFrank Mandarino } 595db2a4165SFrank Mandarino 59687506549SMark Brown if (card->suspend_post) 59770b2ac12SMark Brown card->suspend_post(card); 598db2a4165SFrank Mandarino 599db2a4165SFrank Mandarino return 0; 600db2a4165SFrank Mandarino } 6016f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 602db2a4165SFrank Mandarino 6036ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 6046ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 6056ed25978SAndy Green */ 6066ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 607db2a4165SFrank Mandarino { 608f0fba2adSLiam Girdwood struct snd_soc_card *card = 609f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 6102eea392dSJarkko Nikula struct snd_soc_codec *codec; 611db2a4165SFrank Mandarino int i; 612db2a4165SFrank Mandarino 6136ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 6146ed25978SAndy Green * so userspace apps are blocked from touching us 6156ed25978SAndy Green */ 6166ed25978SAndy Green 617f0fba2adSLiam Girdwood dev_dbg(card->dev, "starting resume work\n"); 6186ed25978SAndy Green 6199949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 620f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 6219949788bSMark Brown 62287506549SMark Brown if (card->resume_pre) 62370b2ac12SMark Brown card->resume_pre(card); 624db2a4165SFrank Mandarino 625f0fba2adSLiam Girdwood /* resume AC97 DAIs */ 626f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 627f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6283efab7dcSMark Brown 629f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6303efab7dcSMark Brown continue; 6313efab7dcSMark Brown 632f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) 633f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 634db2a4165SFrank Mandarino } 635db2a4165SFrank Mandarino 6362eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 6371547aba9SMark Brown /* If the CODEC was idle over suspend then it will have been 6381547aba9SMark Brown * left with bias OFF or STANDBY and suspended so we must now 6391547aba9SMark Brown * resume. Otherwise the suspend was suppressed. 6401547aba9SMark Brown */ 641f0fba2adSLiam Girdwood if (codec->driver->resume && codec->suspended) { 642ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 6431547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 6441547aba9SMark Brown case SND_SOC_BIAS_OFF: 645f0fba2adSLiam Girdwood codec->driver->resume(codec); 646f0fba2adSLiam Girdwood codec->suspended = 0; 6471547aba9SMark Brown break; 6481547aba9SMark Brown default: 649f0fba2adSLiam Girdwood dev_dbg(codec->dev, "CODEC was on over suspend\n"); 6501547aba9SMark Brown break; 6511547aba9SMark Brown } 6521547aba9SMark Brown } 653f0fba2adSLiam Girdwood } 654db2a4165SFrank Mandarino 655f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 656f0fba2adSLiam Girdwood struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; 6573efab7dcSMark Brown 658f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6593efab7dcSMark Brown continue; 6603efab7dcSMark Brown 661f0fba2adSLiam Girdwood if (driver->playback.stream_name != NULL) 662f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, 663db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 664f0fba2adSLiam Girdwood 665f0fba2adSLiam Girdwood if (driver->capture.stream_name != NULL) 666f0fba2adSLiam Girdwood snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, 667db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 668db2a4165SFrank Mandarino } 669db2a4165SFrank Mandarino 6703ff3f64bSMark Brown /* unmute any active DACs */ 671f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 672f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 673f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 6743efab7dcSMark Brown 675f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6763efab7dcSMark Brown continue; 6773efab7dcSMark Brown 678f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 679f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 680db2a4165SFrank Mandarino } 681db2a4165SFrank Mandarino 682f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 683f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 684f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 6853efab7dcSMark Brown 686f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6873efab7dcSMark Brown continue; 6883efab7dcSMark Brown 689f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) 690f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 691f0fba2adSLiam Girdwood if (platform->driver->resume && platform->suspended) { 692f0fba2adSLiam Girdwood platform->driver->resume(cpu_dai); 693f0fba2adSLiam Girdwood platform->suspended = 0; 694f0fba2adSLiam Girdwood } 695db2a4165SFrank Mandarino } 696db2a4165SFrank Mandarino 69787506549SMark Brown if (card->resume_post) 69870b2ac12SMark Brown card->resume_post(card); 699db2a4165SFrank Mandarino 700f0fba2adSLiam Girdwood dev_dbg(card->dev, "resume work completed\n"); 7016ed25978SAndy Green 7026ed25978SAndy Green /* userspace can access us now we are back as we were before */ 703f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 7046ed25978SAndy Green } 7056ed25978SAndy Green 7066ed25978SAndy Green /* powers up audio subsystem after a suspend */ 7076f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 7086ed25978SAndy Green { 7096f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 71082e14e8bSStephen Warren int i, ac97_control = 0; 711b9dd94a8SPeter Ujfalusi 71264ab9baaSMark Brown /* AC97 devices might have other drivers hanging off them so 71364ab9baaSMark Brown * need to resume immediately. Other drivers don't have that 71464ab9baaSMark Brown * problem and may take a substantial amount of time to resume 71564ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 71664ab9baaSMark Brown */ 717f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 718f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 71982e14e8bSStephen Warren ac97_control |= cpu_dai->driver->ac97_control; 72082e14e8bSStephen Warren } 72182e14e8bSStephen Warren if (ac97_control) { 722f0fba2adSLiam Girdwood dev_dbg(dev, "Resuming AC97 immediately\n"); 72364ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 72464ab9baaSMark Brown } else { 725f0fba2adSLiam Girdwood dev_dbg(dev, "Scheduling resume work\n"); 7266308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 727f0fba2adSLiam Girdwood dev_err(dev, "resume work item may be lost\n"); 728f0fba2adSLiam Girdwood } 7296ed25978SAndy Green 730db2a4165SFrank Mandarino return 0; 731db2a4165SFrank Mandarino } 7326f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 733db2a4165SFrank Mandarino #else 7346f8ab4acSMark Brown #define snd_soc_suspend NULL 7356f8ab4acSMark Brown #define snd_soc_resume NULL 736db2a4165SFrank Mandarino #endif 737db2a4165SFrank Mandarino 73802a06d30SBarry Song static struct snd_soc_dai_ops null_dai_ops = { 73902a06d30SBarry Song }; 74002a06d30SBarry Song 741f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 742db2a4165SFrank Mandarino { 743f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 744f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 745fe3e78e0SMark Brown struct snd_soc_codec *codec; 746435c5e25SMark Brown struct snd_soc_platform *platform; 747f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai, *cpu_dai; 748848dd8beSMark Brown const char *platform_name; 749db2a4165SFrank Mandarino 750f0fba2adSLiam Girdwood if (rtd->complete) 751f0fba2adSLiam Girdwood return 1; 752f0fba2adSLiam Girdwood dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); 7536308419aSMark Brown 754f0fba2adSLiam Girdwood /* do we already have the CPU DAI for this link ? */ 755f0fba2adSLiam Girdwood if (rtd->cpu_dai) { 756f0fba2adSLiam Girdwood goto find_codec; 757435c5e25SMark Brown } 758f0fba2adSLiam Girdwood /* no, then find CPU DAI from registered DAIs*/ 759f0fba2adSLiam Girdwood list_for_each_entry(cpu_dai, &dai_list, list) { 760f0fba2adSLiam Girdwood if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) { 761f0fba2adSLiam Girdwood rtd->cpu_dai = cpu_dai; 762f0fba2adSLiam Girdwood goto find_codec; 763f0fba2adSLiam Girdwood } 764f0fba2adSLiam Girdwood } 765f0fba2adSLiam Girdwood dev_dbg(card->dev, "CPU DAI %s not registered\n", 766f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 767f0fba2adSLiam Girdwood 768f0fba2adSLiam Girdwood find_codec: 769f0fba2adSLiam Girdwood /* do we already have the CODEC for this link ? */ 770f0fba2adSLiam Girdwood if (rtd->codec) { 771f0fba2adSLiam Girdwood goto find_platform; 772c5af3a2eSMark Brown } 773c5af3a2eSMark Brown 774f0fba2adSLiam Girdwood /* no, then find CODEC from registered CODECs*/ 775f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 776f0fba2adSLiam Girdwood if (!strcmp(codec->name, dai_link->codec_name)) { 777f0fba2adSLiam Girdwood rtd->codec = codec; 778f0fba2adSLiam Girdwood 779f0fba2adSLiam Girdwood /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/ 780f0fba2adSLiam Girdwood list_for_each_entry(codec_dai, &dai_list, list) { 781f0fba2adSLiam Girdwood if (codec->dev == codec_dai->dev && 782f0fba2adSLiam Girdwood !strcmp(codec_dai->name, dai_link->codec_dai_name)) { 783f0fba2adSLiam Girdwood rtd->codec_dai = codec_dai; 784f0fba2adSLiam Girdwood goto find_platform; 785435c5e25SMark Brown } 786f0fba2adSLiam Girdwood } 787f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC DAI %s not registered\n", 788f0fba2adSLiam Girdwood dai_link->codec_dai_name); 789f0fba2adSLiam Girdwood 790f0fba2adSLiam Girdwood goto find_platform; 791f0fba2adSLiam Girdwood } 792f0fba2adSLiam Girdwood } 793f0fba2adSLiam Girdwood dev_dbg(card->dev, "CODEC %s not registered\n", 794f0fba2adSLiam Girdwood dai_link->codec_name); 795f0fba2adSLiam Girdwood 796f0fba2adSLiam Girdwood find_platform: 797848dd8beSMark Brown /* do we need a platform? */ 798848dd8beSMark Brown if (rtd->platform) 799f0fba2adSLiam Girdwood goto out; 800848dd8beSMark Brown 801848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 802848dd8beSMark Brown platform_name = dai_link->platform_name; 803848dd8beSMark Brown if (!platform_name) 804848dd8beSMark Brown platform_name = "snd-soc-dummy"; 805848dd8beSMark Brown 806848dd8beSMark Brown /* no, then find one from the set of registered platforms */ 807f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 808848dd8beSMark Brown if (!strcmp(platform->name, platform_name)) { 809f0fba2adSLiam Girdwood rtd->platform = platform; 810f0fba2adSLiam Girdwood goto out; 811f0fba2adSLiam Girdwood } 812435c5e25SMark Brown } 8136b05eda6SMark Brown 814f0fba2adSLiam Girdwood dev_dbg(card->dev, "platform %s not registered\n", 815f0fba2adSLiam Girdwood dai_link->platform_name); 816f0fba2adSLiam Girdwood return 0; 817f0fba2adSLiam Girdwood 818f0fba2adSLiam Girdwood out: 819f0fba2adSLiam Girdwood /* mark rtd as complete if we found all 4 of our client devices */ 820f0fba2adSLiam Girdwood if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) { 821f0fba2adSLiam Girdwood rtd->complete = 1; 822f0fba2adSLiam Girdwood card->num_rtd++; 823f0fba2adSLiam Girdwood } 824f0fba2adSLiam Girdwood return 1; 8256b05eda6SMark Brown } 8266b05eda6SMark Brown 827589c3563SJarkko Nikula static void soc_remove_codec(struct snd_soc_codec *codec) 828589c3563SJarkko Nikula { 829589c3563SJarkko Nikula int err; 830589c3563SJarkko Nikula 831589c3563SJarkko Nikula if (codec->driver->remove) { 832589c3563SJarkko Nikula err = codec->driver->remove(codec); 833589c3563SJarkko Nikula if (err < 0) 834589c3563SJarkko Nikula dev_err(codec->dev, 835589c3563SJarkko Nikula "asoc: failed to remove %s: %d\n", 836589c3563SJarkko Nikula codec->name, err); 837589c3563SJarkko Nikula } 838589c3563SJarkko Nikula 839589c3563SJarkko Nikula /* Make sure all DAPM widgets are freed */ 840589c3563SJarkko Nikula snd_soc_dapm_free(&codec->dapm); 841589c3563SJarkko Nikula 842589c3563SJarkko Nikula soc_cleanup_codec_debugfs(codec); 843589c3563SJarkko Nikula codec->probed = 0; 844589c3563SJarkko Nikula list_del(&codec->card_list); 845589c3563SJarkko Nikula module_put(codec->dev->driver->owner); 846589c3563SJarkko Nikula } 847589c3563SJarkko Nikula 8480168bf0dSLiam Girdwood static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) 849f0fba2adSLiam Girdwood { 850f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 851f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 852f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 853f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 854f0fba2adSLiam Girdwood int err; 855f0fba2adSLiam Girdwood 856f0fba2adSLiam Girdwood /* unregister the rtd device */ 857f0fba2adSLiam Girdwood if (rtd->dev_registered) { 858f0fba2adSLiam Girdwood device_remove_file(&rtd->dev, &dev_attr_pmdown_time); 859589c3563SJarkko Nikula device_remove_file(&rtd->dev, &dev_attr_codec_reg); 860f0fba2adSLiam Girdwood device_unregister(&rtd->dev); 861f0fba2adSLiam Girdwood rtd->dev_registered = 0; 86202a06d30SBarry Song } 86302a06d30SBarry Song 864f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 8650168bf0dSLiam Girdwood if (codec_dai && codec_dai->probed && 8660168bf0dSLiam Girdwood codec_dai->driver->remove_order == order) { 867f0fba2adSLiam Girdwood if (codec_dai->driver->remove) { 868f0fba2adSLiam Girdwood err = codec_dai->driver->remove(codec_dai); 869f0fba2adSLiam Girdwood if (err < 0) 870f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name); 871f0fba2adSLiam Girdwood } 872f0fba2adSLiam Girdwood codec_dai->probed = 0; 873f0fba2adSLiam Girdwood list_del(&codec_dai->card_list); 874f0fba2adSLiam Girdwood } 875f0fba2adSLiam Girdwood 876f0fba2adSLiam Girdwood /* remove the platform */ 8770168bf0dSLiam Girdwood if (platform && platform->probed && 8780168bf0dSLiam Girdwood platform->driver->remove_order == order) { 879f0fba2adSLiam Girdwood if (platform->driver->remove) { 880f0fba2adSLiam Girdwood err = platform->driver->remove(platform); 881f0fba2adSLiam Girdwood if (err < 0) 882f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", platform->name); 883f0fba2adSLiam Girdwood } 884f0fba2adSLiam Girdwood platform->probed = 0; 885f0fba2adSLiam Girdwood list_del(&platform->card_list); 886f0fba2adSLiam Girdwood module_put(platform->dev->driver->owner); 887f0fba2adSLiam Girdwood } 888f0fba2adSLiam Girdwood 889f0fba2adSLiam Girdwood /* remove the CODEC */ 8900168bf0dSLiam Girdwood if (codec && codec->probed && 8910168bf0dSLiam Girdwood codec->driver->remove_order == order) 892589c3563SJarkko Nikula soc_remove_codec(codec); 893f0fba2adSLiam Girdwood 894f0fba2adSLiam Girdwood /* remove the cpu_dai */ 8950168bf0dSLiam Girdwood if (cpu_dai && cpu_dai->probed && 8960168bf0dSLiam Girdwood cpu_dai->driver->remove_order == order) { 897f0fba2adSLiam Girdwood if (cpu_dai->driver->remove) { 898f0fba2adSLiam Girdwood err = cpu_dai->driver->remove(cpu_dai); 899f0fba2adSLiam Girdwood if (err < 0) 900f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name); 901f0fba2adSLiam Girdwood } 902f0fba2adSLiam Girdwood cpu_dai->probed = 0; 903f0fba2adSLiam Girdwood list_del(&cpu_dai->card_list); 904f0fba2adSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 905f0fba2adSLiam Girdwood } 906f0fba2adSLiam Girdwood } 907f0fba2adSLiam Girdwood 9080671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 9090671fd8eSKuninori Morimoto { 9100168bf0dSLiam Girdwood int dai, order; 9110671fd8eSKuninori Morimoto 9120168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 9130168bf0dSLiam Girdwood order++) { 9140168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 9150168bf0dSLiam Girdwood soc_remove_dai_link(card, dai, order); 9160168bf0dSLiam Girdwood } 9170671fd8eSKuninori Morimoto card->num_rtd = 0; 9180671fd8eSKuninori Morimoto } 9190671fd8eSKuninori Morimoto 920ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 921ead9b919SJarkko Nikula struct snd_soc_codec *codec) 922ead9b919SJarkko Nikula { 923ead9b919SJarkko Nikula int i; 924ead9b919SJarkko Nikula 925ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 926ead9b919SJarkko Nikula return; 927ead9b919SJarkko Nikula 928ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 929ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 930ead9b919SJarkko Nikula if (map->dev_name && !strcmp(codec->name, map->dev_name)) { 931ead9b919SJarkko Nikula codec->name_prefix = map->name_prefix; 932ead9b919SJarkko Nikula break; 933ead9b919SJarkko Nikula } 934ead9b919SJarkko Nikula } 935ead9b919SJarkko Nikula } 936ead9b919SJarkko Nikula 937589c3563SJarkko Nikula static int soc_probe_codec(struct snd_soc_card *card, 938589c3563SJarkko Nikula struct snd_soc_codec *codec) 939589c3563SJarkko Nikula { 940589c3563SJarkko Nikula int ret = 0; 94189b95ac0SMark Brown const struct snd_soc_codec_driver *driver = codec->driver; 942589c3563SJarkko Nikula 943589c3563SJarkko Nikula codec->card = card; 944589c3563SJarkko Nikula codec->dapm.card = card; 945589c3563SJarkko Nikula soc_set_name_prefix(card, codec); 946589c3563SJarkko Nikula 94770d29331SJarkko Nikula if (!try_module_get(codec->dev->driver->owner)) 94870d29331SJarkko Nikula return -ENODEV; 94970d29331SJarkko Nikula 950d5d1e0beSLars-Peter Clausen soc_init_codec_debugfs(codec); 951d5d1e0beSLars-Peter Clausen 95277530150SLars-Peter Clausen if (driver->dapm_widgets) 95377530150SLars-Peter Clausen snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, 95477530150SLars-Peter Clausen driver->num_dapm_widgets); 95577530150SLars-Peter Clausen 95633c5f969SMark Brown codec->dapm.idle_bias_off = driver->idle_bias_off; 95733c5f969SMark Brown 95889b95ac0SMark Brown if (driver->probe) { 95989b95ac0SMark Brown ret = driver->probe(codec); 960589c3563SJarkko Nikula if (ret < 0) { 961589c3563SJarkko Nikula dev_err(codec->dev, 962589c3563SJarkko Nikula "asoc: failed to probe CODEC %s: %d\n", 963589c3563SJarkko Nikula codec->name, ret); 96470d29331SJarkko Nikula goto err_probe; 965589c3563SJarkko Nikula } 966589c3563SJarkko Nikula } 967589c3563SJarkko Nikula 968b7af1dafSMark Brown if (driver->controls) 969b7af1dafSMark Brown snd_soc_add_controls(codec, driver->controls, 970b7af1dafSMark Brown driver->num_controls); 97189b95ac0SMark Brown if (driver->dapm_routes) 97289b95ac0SMark Brown snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, 97389b95ac0SMark Brown driver->num_dapm_routes); 97489b95ac0SMark Brown 975589c3563SJarkko Nikula /* mark codec as probed and add to card codec list */ 976589c3563SJarkko Nikula codec->probed = 1; 977589c3563SJarkko Nikula list_add(&codec->card_list, &card->codec_dev_list); 9787be31be8SJarkko Nikula list_add(&codec->dapm.list, &card->dapm_list); 979589c3563SJarkko Nikula 98070d29331SJarkko Nikula return 0; 98170d29331SJarkko Nikula 98270d29331SJarkko Nikula err_probe: 983d5d1e0beSLars-Peter Clausen soc_cleanup_codec_debugfs(codec); 98470d29331SJarkko Nikula module_put(codec->dev->driver->owner); 98570d29331SJarkko Nikula 986589c3563SJarkko Nikula return ret; 987589c3563SJarkko Nikula } 988589c3563SJarkko Nikula 989956245e9SLiam Girdwood static int soc_probe_platform(struct snd_soc_card *card, 990956245e9SLiam Girdwood struct snd_soc_platform *platform) 991956245e9SLiam Girdwood { 992956245e9SLiam Girdwood int ret = 0; 993956245e9SLiam Girdwood const struct snd_soc_platform_driver *driver = platform->driver; 994956245e9SLiam Girdwood 995956245e9SLiam Girdwood platform->card = card; 996b7950641SLiam Girdwood platform->dapm.card = card; 997956245e9SLiam Girdwood 998956245e9SLiam Girdwood if (!try_module_get(platform->dev->driver->owner)) 999956245e9SLiam Girdwood return -ENODEV; 1000956245e9SLiam Girdwood 1001cb2cf612SLiam Girdwood if (driver->dapm_widgets) 1002cb2cf612SLiam Girdwood snd_soc_dapm_new_controls(&platform->dapm, 1003cb2cf612SLiam Girdwood driver->dapm_widgets, driver->num_dapm_widgets); 1004cb2cf612SLiam Girdwood 1005956245e9SLiam Girdwood if (driver->probe) { 1006956245e9SLiam Girdwood ret = driver->probe(platform); 1007956245e9SLiam Girdwood if (ret < 0) { 1008956245e9SLiam Girdwood dev_err(platform->dev, 1009956245e9SLiam Girdwood "asoc: failed to probe platform %s: %d\n", 1010956245e9SLiam Girdwood platform->name, ret); 1011956245e9SLiam Girdwood goto err_probe; 1012956245e9SLiam Girdwood } 1013956245e9SLiam Girdwood } 1014956245e9SLiam Girdwood 1015cb2cf612SLiam Girdwood if (driver->controls) 1016cb2cf612SLiam Girdwood snd_soc_add_platform_controls(platform, driver->controls, 1017cb2cf612SLiam Girdwood driver->num_controls); 1018cb2cf612SLiam Girdwood if (driver->dapm_routes) 1019cb2cf612SLiam Girdwood snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, 1020cb2cf612SLiam Girdwood driver->num_dapm_routes); 1021cb2cf612SLiam Girdwood 1022956245e9SLiam Girdwood /* mark platform as probed and add to card platform list */ 1023956245e9SLiam Girdwood platform->probed = 1; 1024956245e9SLiam Girdwood list_add(&platform->card_list, &card->platform_dev_list); 1025b7950641SLiam Girdwood list_add(&platform->dapm.list, &card->dapm_list); 1026956245e9SLiam Girdwood 1027956245e9SLiam Girdwood return 0; 1028956245e9SLiam Girdwood 1029956245e9SLiam Girdwood err_probe: 1030956245e9SLiam Girdwood module_put(platform->dev->driver->owner); 1031956245e9SLiam Girdwood 1032956245e9SLiam Girdwood return ret; 1033956245e9SLiam Girdwood } 1034956245e9SLiam Girdwood 1035f0fba2adSLiam Girdwood static void rtd_release(struct device *dev) {} 1036f0fba2adSLiam Girdwood 1037589c3563SJarkko Nikula static int soc_post_component_init(struct snd_soc_card *card, 1038589c3563SJarkko Nikula struct snd_soc_codec *codec, 1039589c3563SJarkko Nikula int num, int dailess) 1040589c3563SJarkko Nikula { 1041589c3563SJarkko Nikula struct snd_soc_dai_link *dai_link = NULL; 1042589c3563SJarkko Nikula struct snd_soc_aux_dev *aux_dev = NULL; 1043589c3563SJarkko Nikula struct snd_soc_pcm_runtime *rtd; 1044589c3563SJarkko Nikula const char *temp, *name; 1045589c3563SJarkko Nikula int ret = 0; 1046589c3563SJarkko Nikula 1047589c3563SJarkko Nikula if (!dailess) { 1048589c3563SJarkko Nikula dai_link = &card->dai_link[num]; 1049589c3563SJarkko Nikula rtd = &card->rtd[num]; 1050589c3563SJarkko Nikula name = dai_link->name; 1051589c3563SJarkko Nikula } else { 1052589c3563SJarkko Nikula aux_dev = &card->aux_dev[num]; 1053589c3563SJarkko Nikula rtd = &card->rtd_aux[num]; 1054589c3563SJarkko Nikula name = aux_dev->name; 1055589c3563SJarkko Nikula } 10560962bb21SJanusz Krzysztofik rtd->card = card; 1057589c3563SJarkko Nikula 1058589c3563SJarkko Nikula /* machine controls, routes and widgets are not prefixed */ 1059589c3563SJarkko Nikula temp = codec->name_prefix; 1060589c3563SJarkko Nikula codec->name_prefix = NULL; 1061589c3563SJarkko Nikula 10620b07ab92SMark Brown /* Make sure all DAPM widgets are instantiated */ 10630b07ab92SMark Brown snd_soc_dapm_new_widgets(&codec->dapm); 10640b07ab92SMark Brown 1065589c3563SJarkko Nikula /* do machine specific initialization */ 1066589c3563SJarkko Nikula if (!dailess && dai_link->init) 1067589c3563SJarkko Nikula ret = dai_link->init(rtd); 1068589c3563SJarkko Nikula else if (dailess && aux_dev->init) 1069589c3563SJarkko Nikula ret = aux_dev->init(&codec->dapm); 1070589c3563SJarkko Nikula if (ret < 0) { 1071589c3563SJarkko Nikula dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret); 1072589c3563SJarkko Nikula return ret; 1073589c3563SJarkko Nikula } 1074589c3563SJarkko Nikula codec->name_prefix = temp; 1075589c3563SJarkko Nikula 1076589c3563SJarkko Nikula /* register the rtd device */ 1077589c3563SJarkko Nikula rtd->codec = codec; 1078589c3563SJarkko Nikula rtd->dev.parent = card->dev; 1079589c3563SJarkko Nikula rtd->dev.release = rtd_release; 1080589c3563SJarkko Nikula rtd->dev.init_name = name; 1081b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 1082589c3563SJarkko Nikula ret = device_register(&rtd->dev); 1083589c3563SJarkko Nikula if (ret < 0) { 1084589c3563SJarkko Nikula dev_err(card->dev, 1085589c3563SJarkko Nikula "asoc: failed to register runtime device: %d\n", ret); 1086589c3563SJarkko Nikula return ret; 1087589c3563SJarkko Nikula } 1088589c3563SJarkko Nikula rtd->dev_registered = 1; 1089589c3563SJarkko Nikula 1090589c3563SJarkko Nikula /* add DAPM sysfs entries for this codec */ 1091589c3563SJarkko Nikula ret = snd_soc_dapm_sys_add(&rtd->dev); 1092589c3563SJarkko Nikula if (ret < 0) 1093589c3563SJarkko Nikula dev_err(codec->dev, 1094589c3563SJarkko Nikula "asoc: failed to add codec dapm sysfs entries: %d\n", 1095589c3563SJarkko Nikula ret); 1096589c3563SJarkko Nikula 1097589c3563SJarkko Nikula /* add codec sysfs entries */ 1098589c3563SJarkko Nikula ret = device_create_file(&rtd->dev, &dev_attr_codec_reg); 1099589c3563SJarkko Nikula if (ret < 0) 1100589c3563SJarkko Nikula dev_err(codec->dev, 1101589c3563SJarkko Nikula "asoc: failed to add codec sysfs files: %d\n", ret); 1102589c3563SJarkko Nikula 1103589c3563SJarkko Nikula return 0; 1104589c3563SJarkko Nikula } 1105589c3563SJarkko Nikula 11060168bf0dSLiam Girdwood static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) 1107f0fba2adSLiam Girdwood { 1108f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1109f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1110f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 1111f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 1112f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 1113f0fba2adSLiam Girdwood int ret; 1114f0fba2adSLiam Girdwood 11150168bf0dSLiam Girdwood dev_dbg(card->dev, "probe %s dai link %d late %d\n", 11160168bf0dSLiam Girdwood card->name, num, order); 1117f0fba2adSLiam Girdwood 1118f0fba2adSLiam Girdwood /* config components */ 1119f0fba2adSLiam Girdwood codec_dai->codec = codec; 1120f0fba2adSLiam Girdwood cpu_dai->platform = platform; 1121f0fba2adSLiam Girdwood codec_dai->card = card; 1122f0fba2adSLiam Girdwood cpu_dai->card = card; 1123f0fba2adSLiam Girdwood 1124f0fba2adSLiam Girdwood /* set default power off timeout */ 1125f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1126f0fba2adSLiam Girdwood 1127f0fba2adSLiam Girdwood /* probe the cpu_dai */ 11280168bf0dSLiam Girdwood if (!cpu_dai->probed && 11290168bf0dSLiam Girdwood cpu_dai->driver->probe_order == order) { 113061b61e3cSLiam Girdwood if (!try_module_get(cpu_dai->dev->driver->owner)) 113161b61e3cSLiam Girdwood return -ENODEV; 113261b61e3cSLiam Girdwood 1133f0fba2adSLiam Girdwood if (cpu_dai->driver->probe) { 1134f0fba2adSLiam Girdwood ret = cpu_dai->driver->probe(cpu_dai); 1135f0fba2adSLiam Girdwood if (ret < 0) { 1136f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n", 1137f0fba2adSLiam Girdwood cpu_dai->name); 113861b61e3cSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 1139f0fba2adSLiam Girdwood return ret; 1140f0fba2adSLiam Girdwood } 1141f0fba2adSLiam Girdwood } 1142f0fba2adSLiam Girdwood cpu_dai->probed = 1; 11431c8371d6SWolfram Sang /* mark cpu_dai as probed and add to card dai list */ 1144f0fba2adSLiam Girdwood list_add(&cpu_dai->card_list, &card->dai_dev_list); 1145f0fba2adSLiam Girdwood } 1146f0fba2adSLiam Girdwood 1147f0fba2adSLiam Girdwood /* probe the CODEC */ 11480168bf0dSLiam Girdwood if (!codec->probed && 11490168bf0dSLiam Girdwood codec->driver->probe_order == order) { 1150589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 1151589c3563SJarkko Nikula if (ret < 0) 1152f0fba2adSLiam Girdwood return ret; 1153f0fba2adSLiam Girdwood } 1154f0fba2adSLiam Girdwood 1155f0fba2adSLiam Girdwood /* probe the platform */ 11560168bf0dSLiam Girdwood if (!platform->probed && 11570168bf0dSLiam Girdwood platform->driver->probe_order == order) { 1158956245e9SLiam Girdwood ret = soc_probe_platform(card, platform); 1159956245e9SLiam Girdwood if (ret < 0) 1160f0fba2adSLiam Girdwood return ret; 1161f0fba2adSLiam Girdwood } 1162f0fba2adSLiam Girdwood 1163f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 11640168bf0dSLiam Girdwood if (!codec_dai->probed && codec_dai->driver->probe_order == order) { 1165f0fba2adSLiam Girdwood if (codec_dai->driver->probe) { 1166f0fba2adSLiam Girdwood ret = codec_dai->driver->probe(codec_dai); 1167f0fba2adSLiam Girdwood if (ret < 0) { 1168f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n", 1169f0fba2adSLiam Girdwood codec_dai->name); 1170f0fba2adSLiam Girdwood return ret; 1171f0fba2adSLiam Girdwood } 1172f0fba2adSLiam Girdwood } 1173f0fba2adSLiam Girdwood 11741c8371d6SWolfram Sang /* mark codec_dai as probed and add to card dai list */ 1175f0fba2adSLiam Girdwood codec_dai->probed = 1; 1176f0fba2adSLiam Girdwood list_add(&codec_dai->card_list, &card->dai_dev_list); 1177f0fba2adSLiam Girdwood } 1178f0fba2adSLiam Girdwood 11790168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 11800168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 11810168bf0dSLiam Girdwood return 0; 11820168bf0dSLiam Girdwood 1183589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 0); 1184589c3563SJarkko Nikula if (ret) 1185f0fba2adSLiam Girdwood return ret; 1186f0fba2adSLiam Girdwood 1187f0fba2adSLiam Girdwood ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); 1188f0fba2adSLiam Girdwood if (ret < 0) 1189f0fba2adSLiam Girdwood printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); 1190f0fba2adSLiam Girdwood 1191f0fba2adSLiam Girdwood /* create the pcm */ 1192f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1193f0fba2adSLiam Girdwood if (ret < 0) { 1194f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name); 1195f0fba2adSLiam Girdwood return ret; 1196f0fba2adSLiam Girdwood } 1197f0fba2adSLiam Girdwood 1198f0fba2adSLiam Girdwood /* add platform data for AC97 devices */ 1199f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control) 1200f0fba2adSLiam Girdwood snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); 1201f0fba2adSLiam Girdwood 1202f0fba2adSLiam Girdwood return 0; 1203f0fba2adSLiam Girdwood } 1204f0fba2adSLiam Girdwood 1205f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1206f0fba2adSLiam Girdwood static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) 1207f0fba2adSLiam Girdwood { 1208f0fba2adSLiam Girdwood int ret; 1209f0fba2adSLiam Girdwood 1210f0fba2adSLiam Girdwood /* Only instantiate AC97 if not already done by the adaptor 1211f0fba2adSLiam Girdwood * for the generic AC97 subsystem. 12126b05eda6SMark Brown */ 1213f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { 12140562f788SMika Westerberg /* 12150562f788SMika Westerberg * It is possible that the AC97 device is already registered to 12160562f788SMika Westerberg * the device subsystem. This happens when the device is created 12170562f788SMika Westerberg * via snd_ac97_mixer(). Currently only SoC codec that does so 12180562f788SMika Westerberg * is the generic AC97 glue but others migh emerge. 12190562f788SMika Westerberg * 12200562f788SMika Westerberg * In those cases we don't try to register the device again. 12210562f788SMika Westerberg */ 12220562f788SMika Westerberg if (!rtd->codec->ac97_created) 12230562f788SMika Westerberg return 0; 1224f0fba2adSLiam Girdwood 1225f0fba2adSLiam Girdwood ret = soc_ac97_dev_register(rtd->codec); 1226f0fba2adSLiam Girdwood if (ret < 0) { 1227f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: AC97 device register failed\n"); 1228f0fba2adSLiam Girdwood return ret; 1229435c5e25SMark Brown } 1230435c5e25SMark Brown 1231f0fba2adSLiam Girdwood rtd->codec->ac97_registered = 1; 1232f0fba2adSLiam Girdwood } 1233f0fba2adSLiam Girdwood return 0; 1234f0fba2adSLiam Girdwood } 1235435c5e25SMark Brown 1236f0fba2adSLiam Girdwood static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) 1237f0fba2adSLiam Girdwood { 1238f0fba2adSLiam Girdwood if (codec->ac97_registered) { 1239f0fba2adSLiam Girdwood soc_ac97_dev_unregister(codec); 1240f0fba2adSLiam Girdwood codec->ac97_registered = 0; 1241f0fba2adSLiam Girdwood } 1242f0fba2adSLiam Girdwood } 1243f0fba2adSLiam Girdwood #endif 1244435c5e25SMark Brown 12452eea392dSJarkko Nikula static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 12462eea392dSJarkko Nikula { 12472eea392dSJarkko Nikula struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 12482eea392dSJarkko Nikula struct snd_soc_codec *codec; 1249676ad98aSJarkko Nikula int ret = -ENODEV; 12502eea392dSJarkko Nikula 12512eea392dSJarkko Nikula /* find CODEC from registered CODECs*/ 12522eea392dSJarkko Nikula list_for_each_entry(codec, &codec_list, list) { 12532eea392dSJarkko Nikula if (!strcmp(codec->name, aux_dev->codec_name)) { 12542eea392dSJarkko Nikula if (codec->probed) { 12552eea392dSJarkko Nikula dev_err(codec->dev, 12562eea392dSJarkko Nikula "asoc: codec already probed"); 12572eea392dSJarkko Nikula ret = -EBUSY; 12582eea392dSJarkko Nikula goto out; 12592eea392dSJarkko Nikula } 1260676ad98aSJarkko Nikula goto found; 12612eea392dSJarkko Nikula } 12622eea392dSJarkko Nikula } 1263676ad98aSJarkko Nikula /* codec not found */ 1264676ad98aSJarkko Nikula dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); 1265676ad98aSJarkko Nikula goto out; 12662eea392dSJarkko Nikula 1267676ad98aSJarkko Nikula found: 1268589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 12692eea392dSJarkko Nikula if (ret < 0) 1270589c3563SJarkko Nikula return ret; 12712eea392dSJarkko Nikula 1272589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 1); 12732eea392dSJarkko Nikula 12742eea392dSJarkko Nikula out: 12752eea392dSJarkko Nikula return ret; 12762eea392dSJarkko Nikula } 12772eea392dSJarkko Nikula 12782eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 12792eea392dSJarkko Nikula { 12802eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 12812eea392dSJarkko Nikula struct snd_soc_codec *codec = rtd->codec; 12822eea392dSJarkko Nikula 12832eea392dSJarkko Nikula /* unregister the rtd device */ 12842eea392dSJarkko Nikula if (rtd->dev_registered) { 1285589c3563SJarkko Nikula device_remove_file(&rtd->dev, &dev_attr_codec_reg); 12862eea392dSJarkko Nikula device_unregister(&rtd->dev); 12872eea392dSJarkko Nikula rtd->dev_registered = 0; 12882eea392dSJarkko Nikula } 12892eea392dSJarkko Nikula 1290589c3563SJarkko Nikula if (codec && codec->probed) 1291589c3563SJarkko Nikula soc_remove_codec(codec); 12922eea392dSJarkko Nikula } 12932eea392dSJarkko Nikula 1294fdf0f54dSDimitris Papastamos static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, 1295fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type) 1296fdf0f54dSDimitris Papastamos { 1297fdf0f54dSDimitris Papastamos int ret; 1298fdf0f54dSDimitris Papastamos 1299fdf0f54dSDimitris Papastamos if (codec->cache_init) 1300fdf0f54dSDimitris Papastamos return 0; 1301fdf0f54dSDimitris Papastamos 1302fdf0f54dSDimitris Papastamos /* override the compress_type if necessary */ 1303fdf0f54dSDimitris Papastamos if (compress_type && codec->compress_type != compress_type) 1304fdf0f54dSDimitris Papastamos codec->compress_type = compress_type; 1305fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1306fdf0f54dSDimitris Papastamos if (ret < 0) { 1307fdf0f54dSDimitris Papastamos dev_err(codec->dev, "Failed to set cache compression type: %d\n", 1308fdf0f54dSDimitris Papastamos ret); 1309fdf0f54dSDimitris Papastamos return ret; 1310fdf0f54dSDimitris Papastamos } 1311fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1312fdf0f54dSDimitris Papastamos return 0; 1313fdf0f54dSDimitris Papastamos } 1314fdf0f54dSDimitris Papastamos 1315f0fba2adSLiam Girdwood static void snd_soc_instantiate_card(struct snd_soc_card *card) 1316f0fba2adSLiam Girdwood { 1317fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1318fdf0f54dSDimitris Papastamos struct snd_soc_codec_conf *codec_conf; 1319fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type; 132075d9ac46SMark Brown struct snd_soc_dai_link *dai_link; 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 143375d9ac46SMark Brown for (i = 0; i < card->num_links; i++) { 143475d9ac46SMark Brown dai_link = &card->dai_link[i]; 143575d9ac46SMark Brown 143675d9ac46SMark Brown if (dai_link->dai_fmt) { 143775d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, 143875d9ac46SMark Brown dai_link->dai_fmt); 143975d9ac46SMark Brown if (ret != 0) 144075d9ac46SMark Brown dev_warn(card->rtd[i].codec_dai->dev, 144175d9ac46SMark Brown "Failed to set DAI format: %d\n", 144275d9ac46SMark Brown ret); 144375d9ac46SMark Brown 144475d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, 144575d9ac46SMark Brown dai_link->dai_fmt); 144675d9ac46SMark Brown if (ret != 0) 144775d9ac46SMark Brown dev_warn(card->rtd[i].cpu_dai->dev, 144875d9ac46SMark Brown "Failed to set DAI format: %d\n", 144975d9ac46SMark Brown ret); 145075d9ac46SMark Brown } 145175d9ac46SMark Brown } 145275d9ac46SMark Brown 1453f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1454fe3e78e0SMark Brown "%s", card->name); 1455f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 145622de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1457f0e8ed85SMark Brown snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), 1458f0e8ed85SMark Brown "%s", card->driver_name ? card->driver_name : card->name); 1459f0e8ed85SMark Brown for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { 1460f0e8ed85SMark Brown switch (card->snd_card->driver[i]) { 1461f0e8ed85SMark Brown case '_': 1462f0e8ed85SMark Brown case '-': 1463f0e8ed85SMark Brown case '\0': 1464f0e8ed85SMark Brown break; 1465f0e8ed85SMark Brown default: 1466f0e8ed85SMark Brown if (!isalnum(card->snd_card->driver[i])) 1467f0e8ed85SMark Brown card->snd_card->driver[i] = '_'; 1468f0e8ed85SMark Brown break; 1469f0e8ed85SMark Brown } 1470f0e8ed85SMark Brown } 1471fe3e78e0SMark Brown 147228e9ad92SMark Brown if (card->late_probe) { 147328e9ad92SMark Brown ret = card->late_probe(card); 147428e9ad92SMark Brown if (ret < 0) { 147528e9ad92SMark Brown dev_err(card->dev, "%s late_probe() failed: %d\n", 147628e9ad92SMark Brown card->name, ret); 147728e9ad92SMark Brown goto probe_aux_dev_err; 147828e9ad92SMark Brown } 147928e9ad92SMark Brown } 148028e9ad92SMark Brown 1481f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1482fe3e78e0SMark Brown if (ret < 0) { 1483f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name); 14846b3ed785SAxel Lin goto probe_aux_dev_err; 1485fe3e78e0SMark Brown } 1486fe3e78e0SMark Brown 1487fe3e78e0SMark Brown #ifdef CONFIG_SND_SOC_AC97_BUS 1488f0fba2adSLiam Girdwood /* register any AC97 codecs */ 1489f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1490f0fba2adSLiam Girdwood ret = soc_register_ac97_dai_link(&card->rtd[i]); 1491fe3e78e0SMark Brown if (ret < 0) { 1492f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); 14936b3ed785SAxel Lin while (--i >= 0) 14947d8316dfSMark Brown soc_unregister_ac97_dai_link(card->rtd[i].codec); 14956b3ed785SAxel Lin goto probe_aux_dev_err; 1496fe3e78e0SMark Brown } 1497fe3e78e0SMark Brown } 1498fe3e78e0SMark Brown #endif 1499fe3e78e0SMark Brown 1500435c5e25SMark Brown card->instantiated = 1; 1501f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1502435c5e25SMark Brown return; 1503db2a4165SFrank Mandarino 15042eea392dSJarkko Nikula probe_aux_dev_err: 15052eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 15062eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 15072eea392dSJarkko Nikula 1508f0fba2adSLiam Girdwood probe_dai_err: 15090671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1510fe3e78e0SMark Brown 1511f0fba2adSLiam Girdwood card_probe_error: 151287506549SMark Brown if (card->remove) 1513e7361ec4SMark Brown card->remove(card); 1514f0fba2adSLiam Girdwood 1515f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1516f0fba2adSLiam Girdwood 1517f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1518435c5e25SMark Brown } 1519db2a4165SFrank Mandarino 1520435c5e25SMark Brown /* 1521421f91d2SUwe Kleine-König * Attempt to initialise any uninitialised cards. Must be called with 1522435c5e25SMark Brown * client_mutex. 1523435c5e25SMark Brown */ 1524435c5e25SMark Brown static void snd_soc_instantiate_cards(void) 1525435c5e25SMark Brown { 1526435c5e25SMark Brown struct snd_soc_card *card; 1527435c5e25SMark Brown list_for_each_entry(card, &card_list, list) 1528435c5e25SMark Brown snd_soc_instantiate_card(card); 1529435c5e25SMark Brown } 1530435c5e25SMark Brown 1531435c5e25SMark Brown /* probes a new socdev */ 1532435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1533435c5e25SMark Brown { 1534f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1535435c5e25SMark Brown int ret = 0; 1536435c5e25SMark Brown 153770a7ca34SVinod Koul /* 153870a7ca34SVinod Koul * no card, so machine driver should be registering card 153970a7ca34SVinod Koul * we should not be here in that case so ret error 154070a7ca34SVinod Koul */ 154170a7ca34SVinod Koul if (!card) 154270a7ca34SVinod Koul return -EINVAL; 154370a7ca34SVinod Koul 1544435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1545435c5e25SMark Brown card->dev = &pdev->dev; 1546f0fba2adSLiam Girdwood 1547435c5e25SMark Brown ret = snd_soc_register_card(card); 1548435c5e25SMark Brown if (ret != 0) { 1549435c5e25SMark Brown dev_err(&pdev->dev, "Failed to register card\n"); 1550db2a4165SFrank Mandarino return ret; 1551db2a4165SFrank Mandarino } 1552db2a4165SFrank Mandarino 1553435c5e25SMark Brown return 0; 1554435c5e25SMark Brown } 1555435c5e25SMark Brown 1556b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1557db2a4165SFrank Mandarino { 1558db2a4165SFrank Mandarino int i; 1559db2a4165SFrank Mandarino 1560f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1561f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1562f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 15635b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1564db2a4165SFrank Mandarino } 1565db2a4165SFrank Mandarino 15662eea392dSJarkko Nikula /* remove auxiliary devices */ 15672eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 15682eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 15692eea392dSJarkko Nikula 1570f0fba2adSLiam Girdwood /* remove and free each DAI */ 15710671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1572f0fba2adSLiam Girdwood 1573a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1574a6052154SJarkko Nikula 1575f0fba2adSLiam Girdwood /* remove the card */ 157687506549SMark Brown if (card->remove) 1577e7361ec4SMark Brown card->remove(card); 1578f0fba2adSLiam Girdwood 15790aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 15800aaae527SLars-Peter Clausen 1581f0fba2adSLiam Girdwood kfree(card->rtd); 1582f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1583b0e26485SVinod Koul return 0; 1584b0e26485SVinod Koul 1585b2dfa62cSGuennadi Liakhovetski } 1586b0e26485SVinod Koul 1587b0e26485SVinod Koul /* removes a socdev */ 1588b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1589b0e26485SVinod Koul { 1590b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1591b0e26485SVinod Koul 1592c5af3a2eSMark Brown snd_soc_unregister_card(card); 1593db2a4165SFrank Mandarino return 0; 1594db2a4165SFrank Mandarino } 1595db2a4165SFrank Mandarino 15966f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 159751737470SMark Brown { 15986f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1599f0fba2adSLiam Girdwood int i; 160051737470SMark Brown 160151737470SMark Brown if (!card->instantiated) 1602416356fcSMark Brown return 0; 160351737470SMark Brown 160451737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 160551737470SMark Brown * now, we're shutting down so no imminent restart. */ 1606f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1607f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 16085b84ba26STejun Heo flush_delayed_work_sync(&rtd->delayed_work); 1609f0fba2adSLiam Girdwood } 161051737470SMark Brown 1611f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1612416356fcSMark Brown 1613416356fcSMark Brown return 0; 161451737470SMark Brown } 16156f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 161651737470SMark Brown 16176f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 16186f8ab4acSMark Brown .suspend = snd_soc_suspend, 16196f8ab4acSMark Brown .resume = snd_soc_resume, 16206f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1621416356fcSMark Brown }; 1622deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1623416356fcSMark Brown 1624db2a4165SFrank Mandarino /* ASoC platform driver */ 1625db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1626db2a4165SFrank Mandarino .driver = { 1627db2a4165SFrank Mandarino .name = "soc-audio", 16288b45a209SKay Sievers .owner = THIS_MODULE, 16296f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1630db2a4165SFrank Mandarino }, 1631db2a4165SFrank Mandarino .probe = soc_probe, 1632db2a4165SFrank Mandarino .remove = soc_remove, 1633db2a4165SFrank Mandarino }; 1634db2a4165SFrank Mandarino 1635096e49d5SMark Brown /** 1636096e49d5SMark Brown * snd_soc_codec_volatile_register: Report if a register is volatile. 1637096e49d5SMark Brown * 1638096e49d5SMark Brown * @codec: CODEC to query. 1639096e49d5SMark Brown * @reg: Register to query. 1640096e49d5SMark Brown * 1641096e49d5SMark Brown * Boolean function indiciating if a CODEC register is volatile. 1642096e49d5SMark Brown */ 1643181e055eSMark Brown int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, 1644181e055eSMark Brown unsigned int reg) 1645096e49d5SMark Brown { 16461500b7b5SDimitris Papastamos if (codec->volatile_register) 16471500b7b5SDimitris Papastamos return codec->volatile_register(codec, reg); 1648096e49d5SMark Brown else 1649096e49d5SMark Brown return 0; 1650096e49d5SMark Brown } 1651096e49d5SMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); 1652096e49d5SMark Brown 1653db2a4165SFrank Mandarino /** 1654239c9706SDimitris Papastamos * snd_soc_codec_readable_register: Report if a register is readable. 1655239c9706SDimitris Papastamos * 1656239c9706SDimitris Papastamos * @codec: CODEC to query. 1657239c9706SDimitris Papastamos * @reg: Register to query. 1658239c9706SDimitris Papastamos * 1659239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is readable. 1660239c9706SDimitris Papastamos */ 1661239c9706SDimitris Papastamos int snd_soc_codec_readable_register(struct snd_soc_codec *codec, 1662239c9706SDimitris Papastamos unsigned int reg) 1663239c9706SDimitris Papastamos { 1664239c9706SDimitris Papastamos if (codec->readable_register) 1665239c9706SDimitris Papastamos return codec->readable_register(codec, reg); 1666239c9706SDimitris Papastamos else 166763fa0a28SLars-Peter Clausen return 1; 1668239c9706SDimitris Papastamos } 1669239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); 1670239c9706SDimitris Papastamos 1671239c9706SDimitris Papastamos /** 1672239c9706SDimitris Papastamos * snd_soc_codec_writable_register: Report if a register is writable. 1673239c9706SDimitris Papastamos * 1674239c9706SDimitris Papastamos * @codec: CODEC to query. 1675239c9706SDimitris Papastamos * @reg: Register to query. 1676239c9706SDimitris Papastamos * 1677239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is writable. 1678239c9706SDimitris Papastamos */ 1679239c9706SDimitris Papastamos int snd_soc_codec_writable_register(struct snd_soc_codec *codec, 1680239c9706SDimitris Papastamos unsigned int reg) 1681239c9706SDimitris Papastamos { 1682239c9706SDimitris Papastamos if (codec->writable_register) 1683239c9706SDimitris Papastamos return codec->writable_register(codec, reg); 1684239c9706SDimitris Papastamos else 168563fa0a28SLars-Peter Clausen return 1; 1686239c9706SDimitris Papastamos } 1687239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); 1688239c9706SDimitris Papastamos 1689f1442bc1SLiam Girdwood int snd_soc_platform_read(struct snd_soc_platform *platform, 1690f1442bc1SLiam Girdwood unsigned int reg) 1691f1442bc1SLiam Girdwood { 1692f1442bc1SLiam Girdwood unsigned int ret; 1693f1442bc1SLiam Girdwood 1694f1442bc1SLiam Girdwood if (!platform->driver->read) { 1695f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no read back\n"); 1696f1442bc1SLiam Girdwood return -1; 1697f1442bc1SLiam Girdwood } 1698f1442bc1SLiam Girdwood 1699f1442bc1SLiam Girdwood ret = platform->driver->read(platform, reg); 1700f1442bc1SLiam Girdwood dev_dbg(platform->dev, "read %x => %x\n", reg, ret); 1701a82ce2aeSLiam Girdwood trace_snd_soc_preg_read(platform, reg, ret); 1702f1442bc1SLiam Girdwood 1703f1442bc1SLiam Girdwood return ret; 1704f1442bc1SLiam Girdwood } 1705f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_read); 1706f1442bc1SLiam Girdwood 1707f1442bc1SLiam Girdwood int snd_soc_platform_write(struct snd_soc_platform *platform, 1708f1442bc1SLiam Girdwood unsigned int reg, unsigned int val) 1709f1442bc1SLiam Girdwood { 1710f1442bc1SLiam Girdwood if (!platform->driver->write) { 1711f1442bc1SLiam Girdwood dev_err(platform->dev, "platform has no write back\n"); 1712f1442bc1SLiam Girdwood return -1; 1713f1442bc1SLiam Girdwood } 1714f1442bc1SLiam Girdwood 1715f1442bc1SLiam Girdwood dev_dbg(platform->dev, "write %x = %x\n", reg, val); 1716a82ce2aeSLiam Girdwood trace_snd_soc_preg_write(platform, reg, val); 1717f1442bc1SLiam Girdwood return platform->driver->write(platform, reg, val); 1718f1442bc1SLiam Girdwood } 1719f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_write); 1720f1442bc1SLiam Girdwood 1721239c9706SDimitris Papastamos /** 1722db2a4165SFrank Mandarino * snd_soc_new_ac97_codec - initailise AC97 device 1723db2a4165SFrank Mandarino * @codec: audio codec 1724db2a4165SFrank Mandarino * @ops: AC97 bus operations 1725db2a4165SFrank Mandarino * @num: AC97 codec number 1726db2a4165SFrank Mandarino * 1727db2a4165SFrank Mandarino * Initialises AC97 codec resources for use by ad-hoc devices only. 1728db2a4165SFrank Mandarino */ 1729db2a4165SFrank Mandarino int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 1730db2a4165SFrank Mandarino struct snd_ac97_bus_ops *ops, int num) 1731db2a4165SFrank Mandarino { 1732db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1733db2a4165SFrank Mandarino 1734db2a4165SFrank Mandarino codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 1735db2a4165SFrank Mandarino if (codec->ac97 == NULL) { 1736db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1737db2a4165SFrank Mandarino return -ENOMEM; 1738db2a4165SFrank Mandarino } 1739db2a4165SFrank Mandarino 1740db2a4165SFrank Mandarino codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); 1741db2a4165SFrank Mandarino if (codec->ac97->bus == NULL) { 1742db2a4165SFrank Mandarino kfree(codec->ac97); 1743db2a4165SFrank Mandarino codec->ac97 = NULL; 1744db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1745db2a4165SFrank Mandarino return -ENOMEM; 1746db2a4165SFrank Mandarino } 1747db2a4165SFrank Mandarino 1748db2a4165SFrank Mandarino codec->ac97->bus->ops = ops; 1749db2a4165SFrank Mandarino codec->ac97->num = num; 17500562f788SMika Westerberg 17510562f788SMika Westerberg /* 17520562f788SMika Westerberg * Mark the AC97 device to be created by us. This way we ensure that the 17530562f788SMika Westerberg * device will be registered with the device subsystem later on. 17540562f788SMika Westerberg */ 17550562f788SMika Westerberg codec->ac97_created = 1; 17560562f788SMika Westerberg 1757db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1758db2a4165SFrank Mandarino return 0; 1759db2a4165SFrank Mandarino } 1760db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 1761db2a4165SFrank Mandarino 1762db2a4165SFrank Mandarino /** 1763db2a4165SFrank Mandarino * snd_soc_free_ac97_codec - free AC97 codec device 1764db2a4165SFrank Mandarino * @codec: audio codec 1765db2a4165SFrank Mandarino * 1766db2a4165SFrank Mandarino * Frees AC97 codec device resources. 1767db2a4165SFrank Mandarino */ 1768db2a4165SFrank Mandarino void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 1769db2a4165SFrank Mandarino { 1770db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 1771f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1772f0fba2adSLiam Girdwood soc_unregister_ac97_dai_link(codec); 1773f0fba2adSLiam Girdwood #endif 1774db2a4165SFrank Mandarino kfree(codec->ac97->bus); 1775db2a4165SFrank Mandarino kfree(codec->ac97); 1776db2a4165SFrank Mandarino codec->ac97 = NULL; 17770562f788SMika Westerberg codec->ac97_created = 0; 1778db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 1779db2a4165SFrank Mandarino } 1780db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 1781db2a4165SFrank Mandarino 1782c3753707SMark Brown unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) 1783c3753707SMark Brown { 1784c3753707SMark Brown unsigned int ret; 1785c3753707SMark Brown 1786c3acec26SMark Brown ret = codec->read(codec, reg); 1787c3753707SMark Brown dev_dbg(codec->dev, "read %x => %x\n", reg, ret); 1788a8b1d34fSMark Brown trace_snd_soc_reg_read(codec, reg, ret); 1789c3753707SMark Brown 1790c3753707SMark Brown return ret; 1791c3753707SMark Brown } 1792c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_read); 1793c3753707SMark Brown 1794c3753707SMark Brown unsigned int snd_soc_write(struct snd_soc_codec *codec, 1795c3753707SMark Brown unsigned int reg, unsigned int val) 1796c3753707SMark Brown { 1797c3753707SMark Brown dev_dbg(codec->dev, "write %x = %x\n", reg, val); 1798a8b1d34fSMark Brown trace_snd_soc_reg_write(codec, reg, val); 1799c3acec26SMark Brown return codec->write(codec, reg, val); 1800c3753707SMark Brown } 1801c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_write); 1802c3753707SMark Brown 18035fb609d4SDimitris Papastamos unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, 18045fb609d4SDimitris Papastamos unsigned int reg, const void *data, size_t len) 18055fb609d4SDimitris Papastamos { 18065fb609d4SDimitris Papastamos return codec->bulk_write_raw(codec, reg, data, len); 18075fb609d4SDimitris Papastamos } 18085fb609d4SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); 18095fb609d4SDimitris Papastamos 1810db2a4165SFrank Mandarino /** 1811db2a4165SFrank Mandarino * snd_soc_update_bits - update codec register bits 1812db2a4165SFrank Mandarino * @codec: audio codec 1813db2a4165SFrank Mandarino * @reg: codec register 1814db2a4165SFrank Mandarino * @mask: register mask 1815db2a4165SFrank Mandarino * @value: new value 1816db2a4165SFrank Mandarino * 1817db2a4165SFrank Mandarino * Writes new register value. 1818db2a4165SFrank Mandarino * 1819180c329dSTimur Tabi * Returns 1 for change, 0 for no change, or negative error code. 1820db2a4165SFrank Mandarino */ 1821db2a4165SFrank Mandarino int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, 182246f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1823db2a4165SFrank Mandarino { 1824db2a4165SFrank Mandarino int change; 182546f5822fSDaniel Ribeiro unsigned int old, new; 1826180c329dSTimur Tabi int ret; 1827db2a4165SFrank Mandarino 1828180c329dSTimur Tabi ret = snd_soc_read(codec, reg); 1829180c329dSTimur Tabi if (ret < 0) 1830180c329dSTimur Tabi return ret; 1831180c329dSTimur Tabi 1832180c329dSTimur Tabi old = ret; 183378bf3c9aSMark Brown new = (old & ~mask) | (value & mask); 1834db2a4165SFrank Mandarino change = old != new; 1835180c329dSTimur Tabi if (change) { 1836180c329dSTimur Tabi ret = snd_soc_write(codec, reg, new); 1837180c329dSTimur Tabi if (ret < 0) 1838180c329dSTimur Tabi return ret; 1839180c329dSTimur Tabi } 1840db2a4165SFrank Mandarino 1841db2a4165SFrank Mandarino return change; 1842db2a4165SFrank Mandarino } 1843db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_update_bits); 1844db2a4165SFrank Mandarino 1845db2a4165SFrank Mandarino /** 18466c508c62SEero Nurkkala * snd_soc_update_bits_locked - update codec register bits 18476c508c62SEero Nurkkala * @codec: audio codec 18486c508c62SEero Nurkkala * @reg: codec register 18496c508c62SEero Nurkkala * @mask: register mask 18506c508c62SEero Nurkkala * @value: new value 18516c508c62SEero Nurkkala * 18526c508c62SEero Nurkkala * Writes new register value, and takes the codec mutex. 18536c508c62SEero Nurkkala * 18546c508c62SEero Nurkkala * Returns 1 for change else 0. 18556c508c62SEero Nurkkala */ 1856dd1b3d53SMark Brown int snd_soc_update_bits_locked(struct snd_soc_codec *codec, 18576c508c62SEero Nurkkala unsigned short reg, unsigned int mask, 18586c508c62SEero Nurkkala unsigned int value) 18596c508c62SEero Nurkkala { 18606c508c62SEero Nurkkala int change; 18616c508c62SEero Nurkkala 18626c508c62SEero Nurkkala mutex_lock(&codec->mutex); 18636c508c62SEero Nurkkala change = snd_soc_update_bits(codec, reg, mask, value); 18646c508c62SEero Nurkkala mutex_unlock(&codec->mutex); 18656c508c62SEero Nurkkala 18666c508c62SEero Nurkkala return change; 18676c508c62SEero Nurkkala } 1868dd1b3d53SMark Brown EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); 18696c508c62SEero Nurkkala 18706c508c62SEero Nurkkala /** 1871db2a4165SFrank Mandarino * snd_soc_test_bits - test register for change 1872db2a4165SFrank Mandarino * @codec: audio codec 1873db2a4165SFrank Mandarino * @reg: codec register 1874db2a4165SFrank Mandarino * @mask: register mask 1875db2a4165SFrank Mandarino * @value: new value 1876db2a4165SFrank Mandarino * 1877db2a4165SFrank Mandarino * Tests a register with a new value and checks if the new value is 1878db2a4165SFrank Mandarino * different from the old value. 1879db2a4165SFrank Mandarino * 1880db2a4165SFrank Mandarino * Returns 1 for change else 0. 1881db2a4165SFrank Mandarino */ 1882db2a4165SFrank Mandarino int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, 188346f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 1884db2a4165SFrank Mandarino { 1885db2a4165SFrank Mandarino int change; 188646f5822fSDaniel Ribeiro unsigned int old, new; 1887db2a4165SFrank Mandarino 1888db2a4165SFrank Mandarino old = snd_soc_read(codec, reg); 1889db2a4165SFrank Mandarino new = (old & ~mask) | value; 1890db2a4165SFrank Mandarino change = old != new; 1891db2a4165SFrank Mandarino 1892db2a4165SFrank Mandarino return change; 1893db2a4165SFrank Mandarino } 1894db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_test_bits); 1895db2a4165SFrank Mandarino 1896db2a4165SFrank Mandarino /** 1897db2a4165SFrank Mandarino * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 1898db2a4165SFrank Mandarino * @substream: the pcm substream 1899db2a4165SFrank Mandarino * @hw: the hardware parameters 1900db2a4165SFrank Mandarino * 1901db2a4165SFrank Mandarino * Sets the substream runtime hardware parameters. 1902db2a4165SFrank Mandarino */ 1903db2a4165SFrank Mandarino int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 1904db2a4165SFrank Mandarino const struct snd_pcm_hardware *hw) 1905db2a4165SFrank Mandarino { 1906db2a4165SFrank Mandarino struct snd_pcm_runtime *runtime = substream->runtime; 1907db2a4165SFrank Mandarino runtime->hw.info = hw->info; 1908db2a4165SFrank Mandarino runtime->hw.formats = hw->formats; 1909db2a4165SFrank Mandarino runtime->hw.period_bytes_min = hw->period_bytes_min; 1910db2a4165SFrank Mandarino runtime->hw.period_bytes_max = hw->period_bytes_max; 1911db2a4165SFrank Mandarino runtime->hw.periods_min = hw->periods_min; 1912db2a4165SFrank Mandarino runtime->hw.periods_max = hw->periods_max; 1913db2a4165SFrank Mandarino runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; 1914db2a4165SFrank Mandarino runtime->hw.fifo_size = hw->fifo_size; 1915db2a4165SFrank Mandarino return 0; 1916db2a4165SFrank Mandarino } 1917db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); 1918db2a4165SFrank Mandarino 1919db2a4165SFrank Mandarino /** 1920db2a4165SFrank Mandarino * snd_soc_cnew - create new control 1921db2a4165SFrank Mandarino * @_template: control template 1922db2a4165SFrank Mandarino * @data: control private data 1923ac11a2b3SMark Brown * @long_name: control long name 1924efb7ac3fSMark Brown * @prefix: control name prefix 1925db2a4165SFrank Mandarino * 1926db2a4165SFrank Mandarino * Create a new mixer control from a template control. 1927db2a4165SFrank Mandarino * 1928db2a4165SFrank Mandarino * Returns 0 for success, else error. 1929db2a4165SFrank Mandarino */ 1930db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 1931efb7ac3fSMark Brown void *data, char *long_name, 1932efb7ac3fSMark Brown const char *prefix) 1933db2a4165SFrank Mandarino { 1934db2a4165SFrank Mandarino struct snd_kcontrol_new template; 1935efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 1936efb7ac3fSMark Brown char *name = NULL; 1937efb7ac3fSMark Brown int name_len; 1938db2a4165SFrank Mandarino 1939db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 1940db2a4165SFrank Mandarino template.index = 0; 1941db2a4165SFrank Mandarino 1942efb7ac3fSMark Brown if (!long_name) 1943efb7ac3fSMark Brown long_name = template.name; 1944efb7ac3fSMark Brown 1945efb7ac3fSMark Brown if (prefix) { 1946efb7ac3fSMark Brown name_len = strlen(long_name) + strlen(prefix) + 2; 194757cf9d45SAxel Lin name = kmalloc(name_len, GFP_KERNEL); 1948efb7ac3fSMark Brown if (!name) 1949efb7ac3fSMark Brown return NULL; 1950efb7ac3fSMark Brown 1951efb7ac3fSMark Brown snprintf(name, name_len, "%s %s", prefix, long_name); 1952efb7ac3fSMark Brown 1953efb7ac3fSMark Brown template.name = name; 1954efb7ac3fSMark Brown } else { 1955efb7ac3fSMark Brown template.name = long_name; 1956efb7ac3fSMark Brown } 1957efb7ac3fSMark Brown 1958efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 1959efb7ac3fSMark Brown 1960efb7ac3fSMark Brown kfree(name); 1961efb7ac3fSMark Brown 1962efb7ac3fSMark Brown return kcontrol; 1963db2a4165SFrank Mandarino } 1964db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 1965db2a4165SFrank Mandarino 1966db2a4165SFrank Mandarino /** 19673e8e1952SIan Molton * snd_soc_add_controls - add an array of controls to a codec. 19683e8e1952SIan Molton * Convienience function to add a list of controls. Many codecs were 19693e8e1952SIan Molton * duplicating this code. 19703e8e1952SIan Molton * 19713e8e1952SIan Molton * @codec: codec to add controls to 19723e8e1952SIan Molton * @controls: array of controls to add 19733e8e1952SIan Molton * @num_controls: number of elements in the array 19743e8e1952SIan Molton * 19753e8e1952SIan Molton * Return 0 for success, else error. 19763e8e1952SIan Molton */ 19773e8e1952SIan Molton int snd_soc_add_controls(struct snd_soc_codec *codec, 19783e8e1952SIan Molton const struct snd_kcontrol_new *controls, int num_controls) 19793e8e1952SIan Molton { 1980f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 19813e8e1952SIan Molton int err, i; 19823e8e1952SIan Molton 19833e8e1952SIan Molton for (i = 0; i < num_controls; i++) { 19843e8e1952SIan Molton const struct snd_kcontrol_new *control = &controls[i]; 1985efb7ac3fSMark Brown err = snd_ctl_add(card, snd_soc_cnew(control, codec, 1986efb7ac3fSMark Brown control->name, 1987efb7ac3fSMark Brown codec->name_prefix)); 19883e8e1952SIan Molton if (err < 0) { 1989082100dcSMark Brown dev_err(codec->dev, "%s: Failed to add %s: %d\n", 1990efb7ac3fSMark Brown codec->name, control->name, err); 19913e8e1952SIan Molton return err; 19923e8e1952SIan Molton } 19933e8e1952SIan Molton } 19943e8e1952SIan Molton 19953e8e1952SIan Molton return 0; 19963e8e1952SIan Molton } 19973e8e1952SIan Molton EXPORT_SYMBOL_GPL(snd_soc_add_controls); 19983e8e1952SIan Molton 19993e8e1952SIan Molton /** 2000a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 2001a491a5c8SLiam Girdwood * Convienience function to add a list of controls. 2002a491a5c8SLiam Girdwood * 2003a491a5c8SLiam Girdwood * @platform: platform to add controls to 2004a491a5c8SLiam Girdwood * @controls: array of controls to add 2005a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 2006a491a5c8SLiam Girdwood * 2007a491a5c8SLiam Girdwood * Return 0 for success, else error. 2008a491a5c8SLiam Girdwood */ 2009a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 2010a491a5c8SLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2011a491a5c8SLiam Girdwood { 2012a491a5c8SLiam Girdwood struct snd_card *card = platform->card->snd_card; 2013a491a5c8SLiam Girdwood int err, i; 2014a491a5c8SLiam Girdwood 2015a491a5c8SLiam Girdwood for (i = 0; i < num_controls; i++) { 2016a491a5c8SLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 2017a491a5c8SLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, platform, 2018a491a5c8SLiam Girdwood control->name, NULL)); 2019a491a5c8SLiam Girdwood if (err < 0) { 2020a491a5c8SLiam Girdwood dev_err(platform->dev, "Failed to add %s %d\n",control->name, err); 2021a491a5c8SLiam Girdwood return err; 2022a491a5c8SLiam Girdwood } 2023a491a5c8SLiam Girdwood } 2024a491a5c8SLiam Girdwood 2025a491a5c8SLiam Girdwood return 0; 2026a491a5c8SLiam Girdwood } 2027a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 2028a491a5c8SLiam Girdwood 2029a491a5c8SLiam Girdwood /** 2030db2a4165SFrank Mandarino * snd_soc_info_enum_double - enumerated double mixer info callback 2031db2a4165SFrank Mandarino * @kcontrol: mixer control 2032db2a4165SFrank Mandarino * @uinfo: control element information 2033db2a4165SFrank Mandarino * 2034db2a4165SFrank Mandarino * Callback to provide information about a double enumerated 2035db2a4165SFrank Mandarino * mixer control. 2036db2a4165SFrank Mandarino * 2037db2a4165SFrank Mandarino * Returns 0 for success. 2038db2a4165SFrank Mandarino */ 2039db2a4165SFrank Mandarino int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 2040db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2041db2a4165SFrank Mandarino { 2042db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2043db2a4165SFrank Mandarino 2044db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2045db2a4165SFrank Mandarino uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2046f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2047db2a4165SFrank Mandarino 2048f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2049f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2050db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2051db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2052db2a4165SFrank Mandarino return 0; 2053db2a4165SFrank Mandarino } 2054db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); 2055db2a4165SFrank Mandarino 2056db2a4165SFrank Mandarino /** 2057db2a4165SFrank Mandarino * snd_soc_get_enum_double - enumerated double mixer get callback 2058db2a4165SFrank Mandarino * @kcontrol: mixer control 2059ac11a2b3SMark Brown * @ucontrol: control element information 2060db2a4165SFrank Mandarino * 2061db2a4165SFrank Mandarino * Callback to get the value of a double enumerated mixer. 2062db2a4165SFrank Mandarino * 2063db2a4165SFrank Mandarino * Returns 0 for success. 2064db2a4165SFrank Mandarino */ 2065db2a4165SFrank Mandarino int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 2066db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2067db2a4165SFrank Mandarino { 2068db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2069db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 207046f5822fSDaniel Ribeiro unsigned int val, bitmask; 2071db2a4165SFrank Mandarino 2072f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2073db2a4165SFrank Mandarino ; 2074db2a4165SFrank Mandarino val = snd_soc_read(codec, e->reg); 20753ff3f64bSMark Brown ucontrol->value.enumerated.item[0] 20763ff3f64bSMark Brown = (val >> e->shift_l) & (bitmask - 1); 2077db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) 2078db2a4165SFrank Mandarino ucontrol->value.enumerated.item[1] = 2079db2a4165SFrank Mandarino (val >> e->shift_r) & (bitmask - 1); 2080db2a4165SFrank Mandarino 2081db2a4165SFrank Mandarino return 0; 2082db2a4165SFrank Mandarino } 2083db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); 2084db2a4165SFrank Mandarino 2085db2a4165SFrank Mandarino /** 2086db2a4165SFrank Mandarino * snd_soc_put_enum_double - enumerated double mixer put callback 2087db2a4165SFrank Mandarino * @kcontrol: mixer control 2088ac11a2b3SMark Brown * @ucontrol: control element information 2089db2a4165SFrank Mandarino * 2090db2a4165SFrank Mandarino * Callback to set the value of a double enumerated mixer. 2091db2a4165SFrank Mandarino * 2092db2a4165SFrank Mandarino * Returns 0 for success. 2093db2a4165SFrank Mandarino */ 2094db2a4165SFrank Mandarino int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 2095db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2096db2a4165SFrank Mandarino { 2097db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2098db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 209946f5822fSDaniel Ribeiro unsigned int val; 210046f5822fSDaniel Ribeiro unsigned int mask, bitmask; 2101db2a4165SFrank Mandarino 2102f8ba0b7bSJon Smirl for (bitmask = 1; bitmask < e->max; bitmask <<= 1) 2103db2a4165SFrank Mandarino ; 2104f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[0] > e->max - 1) 2105db2a4165SFrank Mandarino return -EINVAL; 2106db2a4165SFrank Mandarino val = ucontrol->value.enumerated.item[0] << e->shift_l; 2107db2a4165SFrank Mandarino mask = (bitmask - 1) << e->shift_l; 2108db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) { 2109f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[1] > e->max - 1) 2110db2a4165SFrank Mandarino return -EINVAL; 2111db2a4165SFrank Mandarino val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2112db2a4165SFrank Mandarino mask |= (bitmask - 1) << e->shift_r; 2113db2a4165SFrank Mandarino } 2114db2a4165SFrank Mandarino 21156c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2116db2a4165SFrank Mandarino } 2117db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2118db2a4165SFrank Mandarino 2119db2a4165SFrank Mandarino /** 21202e72f8e3SPeter Ujfalusi * snd_soc_get_value_enum_double - semi enumerated double mixer get callback 21212e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 21222e72f8e3SPeter Ujfalusi * @ucontrol: control element information 21232e72f8e3SPeter Ujfalusi * 21242e72f8e3SPeter Ujfalusi * Callback to get the value of a double semi enumerated mixer. 21252e72f8e3SPeter Ujfalusi * 21262e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 21272e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 21282e72f8e3SPeter Ujfalusi * 21292e72f8e3SPeter Ujfalusi * Returns 0 for success. 21302e72f8e3SPeter Ujfalusi */ 21312e72f8e3SPeter Ujfalusi int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, 21322e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 21332e72f8e3SPeter Ujfalusi { 21342e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 213574155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 213646f5822fSDaniel Ribeiro unsigned int reg_val, val, mux; 21372e72f8e3SPeter Ujfalusi 21382e72f8e3SPeter Ujfalusi reg_val = snd_soc_read(codec, e->reg); 21392e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_l) & e->mask; 21402e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 21412e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 21422e72f8e3SPeter Ujfalusi break; 21432e72f8e3SPeter Ujfalusi } 21442e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[0] = mux; 21452e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 21462e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_r) & e->mask; 21472e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 21482e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 21492e72f8e3SPeter Ujfalusi break; 21502e72f8e3SPeter Ujfalusi } 21512e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[1] = mux; 21522e72f8e3SPeter Ujfalusi } 21532e72f8e3SPeter Ujfalusi 21542e72f8e3SPeter Ujfalusi return 0; 21552e72f8e3SPeter Ujfalusi } 21562e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); 21572e72f8e3SPeter Ujfalusi 21582e72f8e3SPeter Ujfalusi /** 21592e72f8e3SPeter Ujfalusi * snd_soc_put_value_enum_double - semi enumerated double mixer put callback 21602e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 21612e72f8e3SPeter Ujfalusi * @ucontrol: control element information 21622e72f8e3SPeter Ujfalusi * 21632e72f8e3SPeter Ujfalusi * Callback to set the value of a double semi enumerated mixer. 21642e72f8e3SPeter Ujfalusi * 21652e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 21662e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 21672e72f8e3SPeter Ujfalusi * 21682e72f8e3SPeter Ujfalusi * Returns 0 for success. 21692e72f8e3SPeter Ujfalusi */ 21702e72f8e3SPeter Ujfalusi int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, 21712e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 21722e72f8e3SPeter Ujfalusi { 21732e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 217474155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 217546f5822fSDaniel Ribeiro unsigned int val; 217646f5822fSDaniel Ribeiro unsigned int mask; 21772e72f8e3SPeter Ujfalusi 21782e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[0] > e->max - 1) 21792e72f8e3SPeter Ujfalusi return -EINVAL; 21802e72f8e3SPeter Ujfalusi val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 21812e72f8e3SPeter Ujfalusi mask = e->mask << e->shift_l; 21822e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 21832e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[1] > e->max - 1) 21842e72f8e3SPeter Ujfalusi return -EINVAL; 21852e72f8e3SPeter Ujfalusi val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 21862e72f8e3SPeter Ujfalusi mask |= e->mask << e->shift_r; 21872e72f8e3SPeter Ujfalusi } 21882e72f8e3SPeter Ujfalusi 21896c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 21902e72f8e3SPeter Ujfalusi } 21912e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); 21922e72f8e3SPeter Ujfalusi 21932e72f8e3SPeter Ujfalusi /** 2194db2a4165SFrank Mandarino * snd_soc_info_enum_ext - external enumerated single mixer info callback 2195db2a4165SFrank Mandarino * @kcontrol: mixer control 2196db2a4165SFrank Mandarino * @uinfo: control element information 2197db2a4165SFrank Mandarino * 2198db2a4165SFrank Mandarino * Callback to provide information about an external enumerated 2199db2a4165SFrank Mandarino * single mixer. 2200db2a4165SFrank Mandarino * 2201db2a4165SFrank Mandarino * Returns 0 for success. 2202db2a4165SFrank Mandarino */ 2203db2a4165SFrank Mandarino int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, 2204db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2205db2a4165SFrank Mandarino { 2206db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2207db2a4165SFrank Mandarino 2208db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2209db2a4165SFrank Mandarino uinfo->count = 1; 2210f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2211db2a4165SFrank Mandarino 2212f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2213f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2214db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2215db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2216db2a4165SFrank Mandarino return 0; 2217db2a4165SFrank Mandarino } 2218db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); 2219db2a4165SFrank Mandarino 2220db2a4165SFrank Mandarino /** 2221db2a4165SFrank Mandarino * snd_soc_info_volsw_ext - external single mixer info callback 2222db2a4165SFrank Mandarino * @kcontrol: mixer control 2223db2a4165SFrank Mandarino * @uinfo: control element information 2224db2a4165SFrank Mandarino * 2225db2a4165SFrank Mandarino * Callback to provide information about a single external mixer control. 2226db2a4165SFrank Mandarino * 2227db2a4165SFrank Mandarino * Returns 0 for success. 2228db2a4165SFrank Mandarino */ 2229db2a4165SFrank Mandarino int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, 2230db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2231db2a4165SFrank Mandarino { 2232a7a4ac86SPhilipp Zabel int max = kcontrol->private_value; 2233db2a4165SFrank Mandarino 2234fd5dfad9SMark Brown if (max == 1 && !strstr(kcontrol->id.name, " Volume")) 2235a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2236a7a4ac86SPhilipp Zabel else 2237a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2238a7a4ac86SPhilipp Zabel 2239db2a4165SFrank Mandarino uinfo->count = 1; 2240db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2241a7a4ac86SPhilipp Zabel uinfo->value.integer.max = max; 2242db2a4165SFrank Mandarino return 0; 2243db2a4165SFrank Mandarino } 2244db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); 2245db2a4165SFrank Mandarino 2246db2a4165SFrank Mandarino /** 2247db2a4165SFrank Mandarino * snd_soc_info_volsw - single mixer info callback 2248db2a4165SFrank Mandarino * @kcontrol: mixer control 2249db2a4165SFrank Mandarino * @uinfo: control element information 2250db2a4165SFrank Mandarino * 2251e8f5a103SPeter Ujfalusi * Callback to provide information about a single mixer control, or a double 2252e8f5a103SPeter Ujfalusi * mixer control that spans 2 registers. 2253db2a4165SFrank Mandarino * 2254db2a4165SFrank Mandarino * Returns 0 for success. 2255db2a4165SFrank Mandarino */ 2256db2a4165SFrank Mandarino int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 2257db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2258db2a4165SFrank Mandarino { 22594eaa9819SJon Smirl struct soc_mixer_control *mc = 22604eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2261d11bb4a9SPeter Ujfalusi int platform_max; 2262db2a4165SFrank Mandarino 2263d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2264d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2265d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2266d11bb4a9SPeter Ujfalusi 2267d11bb4a9SPeter Ujfalusi if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) 2268a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2269a7a4ac86SPhilipp Zabel else 2270a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2271a7a4ac86SPhilipp Zabel 2272e8f5a103SPeter Ujfalusi uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; 2273db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2274d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max; 2275db2a4165SFrank Mandarino return 0; 2276db2a4165SFrank Mandarino } 2277db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw); 2278db2a4165SFrank Mandarino 2279db2a4165SFrank Mandarino /** 2280db2a4165SFrank Mandarino * snd_soc_get_volsw - single mixer get callback 2281db2a4165SFrank Mandarino * @kcontrol: mixer control 2282ac11a2b3SMark Brown * @ucontrol: control element information 2283db2a4165SFrank Mandarino * 2284f7915d99SPeter Ujfalusi * Callback to get the value of a single mixer control, or a double mixer 2285f7915d99SPeter Ujfalusi * control that spans 2 registers. 2286db2a4165SFrank Mandarino * 2287db2a4165SFrank Mandarino * Returns 0 for success. 2288db2a4165SFrank Mandarino */ 2289db2a4165SFrank Mandarino int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 2290db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2291db2a4165SFrank Mandarino { 22924eaa9819SJon Smirl struct soc_mixer_control *mc = 22934eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2294db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2295815ecf8dSJon Smirl unsigned int reg = mc->reg; 2296f7915d99SPeter Ujfalusi unsigned int reg2 = mc->rreg; 2297815ecf8dSJon Smirl unsigned int shift = mc->shift; 2298815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 22994eaa9819SJon Smirl int max = mc->max; 2300815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2301815ecf8dSJon Smirl unsigned int invert = mc->invert; 2302db2a4165SFrank Mandarino 2303db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2304db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> shift) & mask; 2305f7915d99SPeter Ujfalusi if (invert) 2306db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2307a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[0]; 2308f7915d99SPeter Ujfalusi 2309f7915d99SPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2310f7915d99SPeter Ujfalusi if (reg == reg2) 2311f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2312f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg) >> rshift) & mask; 2313f7915d99SPeter Ujfalusi else 2314f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2315f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg2) >> shift) & mask; 2316f7915d99SPeter Ujfalusi if (invert) 2317db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2318a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[1]; 2319db2a4165SFrank Mandarino } 2320db2a4165SFrank Mandarino 2321db2a4165SFrank Mandarino return 0; 2322db2a4165SFrank Mandarino } 2323db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw); 2324db2a4165SFrank Mandarino 2325db2a4165SFrank Mandarino /** 2326db2a4165SFrank Mandarino * snd_soc_put_volsw - single mixer put callback 2327db2a4165SFrank Mandarino * @kcontrol: mixer control 2328ac11a2b3SMark Brown * @ucontrol: control element information 2329db2a4165SFrank Mandarino * 2330*974815baSPeter Ujfalusi * Callback to set the value of a single mixer control, or a double mixer 2331*974815baSPeter Ujfalusi * control that spans 2 registers. 2332db2a4165SFrank Mandarino * 2333db2a4165SFrank Mandarino * Returns 0 for success. 2334db2a4165SFrank Mandarino */ 2335db2a4165SFrank Mandarino int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 2336db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2337db2a4165SFrank Mandarino { 23384eaa9819SJon Smirl struct soc_mixer_control *mc = 23394eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2340db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2341815ecf8dSJon Smirl unsigned int reg = mc->reg; 2342*974815baSPeter Ujfalusi unsigned int reg2 = mc->rreg; 2343815ecf8dSJon Smirl unsigned int shift = mc->shift; 2344815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 23454eaa9819SJon Smirl int max = mc->max; 2346815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2347815ecf8dSJon Smirl unsigned int invert = mc->invert; 2348*974815baSPeter Ujfalusi int err; 2349*974815baSPeter Ujfalusi bool type_2r = 0; 2350*974815baSPeter Ujfalusi unsigned int val2 = 0; 2351*974815baSPeter Ujfalusi unsigned int val, val_mask; 2352db2a4165SFrank Mandarino 2353db2a4165SFrank Mandarino val = (ucontrol->value.integer.value[0] & mask); 2354db2a4165SFrank Mandarino if (invert) 2355a7a4ac86SPhilipp Zabel val = max - val; 2356db2a4165SFrank Mandarino val_mask = mask << shift; 2357db2a4165SFrank Mandarino val = val << shift; 2358*974815baSPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2359db2a4165SFrank Mandarino val2 = (ucontrol->value.integer.value[1] & mask); 2360db2a4165SFrank Mandarino if (invert) 2361a7a4ac86SPhilipp Zabel val2 = max - val2; 2362*974815baSPeter Ujfalusi if (reg == reg2) { 2363db2a4165SFrank Mandarino val_mask |= mask << rshift; 2364db2a4165SFrank Mandarino val |= val2 << rshift; 2365*974815baSPeter Ujfalusi } else { 2366db2a4165SFrank Mandarino val2 = val2 << shift; 2367*974815baSPeter Ujfalusi type_2r = 1; 2368*974815baSPeter Ujfalusi } 2369*974815baSPeter Ujfalusi } 23706c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 23713ff3f64bSMark Brown if (err < 0) 2372db2a4165SFrank Mandarino return err; 2373db2a4165SFrank Mandarino 2374*974815baSPeter Ujfalusi if (type_2r) 23756c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); 2376*974815baSPeter Ujfalusi 2377db2a4165SFrank Mandarino return err; 2378db2a4165SFrank Mandarino } 2379*974815baSPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 2380db2a4165SFrank Mandarino 2381e13ac2e9SMark Brown /** 2382e13ac2e9SMark Brown * snd_soc_info_volsw_s8 - signed mixer info callback 2383e13ac2e9SMark Brown * @kcontrol: mixer control 2384e13ac2e9SMark Brown * @uinfo: control element information 2385e13ac2e9SMark Brown * 2386e13ac2e9SMark Brown * Callback to provide information about a signed mixer control. 2387e13ac2e9SMark Brown * 2388e13ac2e9SMark Brown * Returns 0 for success. 2389e13ac2e9SMark Brown */ 2390e13ac2e9SMark Brown int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, 2391e13ac2e9SMark Brown struct snd_ctl_elem_info *uinfo) 2392e13ac2e9SMark Brown { 23934eaa9819SJon Smirl struct soc_mixer_control *mc = 23944eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2395d11bb4a9SPeter Ujfalusi int platform_max; 23964eaa9819SJon Smirl int min = mc->min; 2397e13ac2e9SMark Brown 2398d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2399d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2400d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2401d11bb4a9SPeter Ujfalusi 2402e13ac2e9SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2403e13ac2e9SMark Brown uinfo->count = 2; 2404e13ac2e9SMark Brown uinfo->value.integer.min = 0; 2405d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max - min; 2406e13ac2e9SMark Brown return 0; 2407e13ac2e9SMark Brown } 2408e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); 2409e13ac2e9SMark Brown 2410e13ac2e9SMark Brown /** 2411e13ac2e9SMark Brown * snd_soc_get_volsw_s8 - signed mixer get callback 2412e13ac2e9SMark Brown * @kcontrol: mixer control 2413ac11a2b3SMark Brown * @ucontrol: control element information 2414e13ac2e9SMark Brown * 2415e13ac2e9SMark Brown * Callback to get the value of a signed mixer control. 2416e13ac2e9SMark Brown * 2417e13ac2e9SMark Brown * Returns 0 for success. 2418e13ac2e9SMark Brown */ 2419e13ac2e9SMark Brown int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, 2420e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2421e13ac2e9SMark Brown { 24224eaa9819SJon Smirl struct soc_mixer_control *mc = 24234eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2424e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2425815ecf8dSJon Smirl unsigned int reg = mc->reg; 24264eaa9819SJon Smirl int min = mc->min; 2427e13ac2e9SMark Brown int val = snd_soc_read(codec, reg); 2428e13ac2e9SMark Brown 2429e13ac2e9SMark Brown ucontrol->value.integer.value[0] = 2430e13ac2e9SMark Brown ((signed char)(val & 0xff))-min; 2431e13ac2e9SMark Brown ucontrol->value.integer.value[1] = 2432e13ac2e9SMark Brown ((signed char)((val >> 8) & 0xff))-min; 2433e13ac2e9SMark Brown return 0; 2434e13ac2e9SMark Brown } 2435e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); 2436e13ac2e9SMark Brown 2437e13ac2e9SMark Brown /** 2438e13ac2e9SMark Brown * snd_soc_put_volsw_sgn - signed mixer put callback 2439e13ac2e9SMark Brown * @kcontrol: mixer control 2440ac11a2b3SMark Brown * @ucontrol: control element information 2441e13ac2e9SMark Brown * 2442e13ac2e9SMark Brown * Callback to set the value of a signed mixer control. 2443e13ac2e9SMark Brown * 2444e13ac2e9SMark Brown * Returns 0 for success. 2445e13ac2e9SMark Brown */ 2446e13ac2e9SMark Brown int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, 2447e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2448e13ac2e9SMark Brown { 24494eaa9819SJon Smirl struct soc_mixer_control *mc = 24504eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2451e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2452815ecf8dSJon Smirl unsigned int reg = mc->reg; 24534eaa9819SJon Smirl int min = mc->min; 245446f5822fSDaniel Ribeiro unsigned int val; 2455e13ac2e9SMark Brown 2456e13ac2e9SMark Brown val = (ucontrol->value.integer.value[0]+min) & 0xff; 2457e13ac2e9SMark Brown val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2458e13ac2e9SMark Brown 24596c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, reg, 0xffff, val); 2460e13ac2e9SMark Brown } 2461e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2462e13ac2e9SMark Brown 24638c6529dbSLiam Girdwood /** 2464637d3847SPeter Ujfalusi * snd_soc_limit_volume - Set new limit to an existing volume control. 2465637d3847SPeter Ujfalusi * 2466637d3847SPeter Ujfalusi * @codec: where to look for the control 2467637d3847SPeter Ujfalusi * @name: Name of the control 2468637d3847SPeter Ujfalusi * @max: new maximum limit 2469637d3847SPeter Ujfalusi * 2470637d3847SPeter Ujfalusi * Return 0 for success, else error. 2471637d3847SPeter Ujfalusi */ 2472637d3847SPeter Ujfalusi int snd_soc_limit_volume(struct snd_soc_codec *codec, 2473637d3847SPeter Ujfalusi const char *name, int max) 2474637d3847SPeter Ujfalusi { 2475f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 2476637d3847SPeter Ujfalusi struct snd_kcontrol *kctl; 2477637d3847SPeter Ujfalusi struct soc_mixer_control *mc; 2478637d3847SPeter Ujfalusi int found = 0; 2479637d3847SPeter Ujfalusi int ret = -EINVAL; 2480637d3847SPeter Ujfalusi 2481637d3847SPeter Ujfalusi /* Sanity check for name and max */ 2482637d3847SPeter Ujfalusi if (unlikely(!name || max <= 0)) 2483637d3847SPeter Ujfalusi return -EINVAL; 2484637d3847SPeter Ujfalusi 2485637d3847SPeter Ujfalusi list_for_each_entry(kctl, &card->controls, list) { 2486637d3847SPeter Ujfalusi if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { 2487637d3847SPeter Ujfalusi found = 1; 2488637d3847SPeter Ujfalusi break; 2489637d3847SPeter Ujfalusi } 2490637d3847SPeter Ujfalusi } 2491637d3847SPeter Ujfalusi if (found) { 2492637d3847SPeter Ujfalusi mc = (struct soc_mixer_control *)kctl->private_value; 2493637d3847SPeter Ujfalusi if (max <= mc->max) { 2494d11bb4a9SPeter Ujfalusi mc->platform_max = max; 2495637d3847SPeter Ujfalusi ret = 0; 2496637d3847SPeter Ujfalusi } 2497637d3847SPeter Ujfalusi } 2498637d3847SPeter Ujfalusi return ret; 2499637d3847SPeter Ujfalusi } 2500637d3847SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_limit_volume); 2501637d3847SPeter Ujfalusi 2502637d3847SPeter Ujfalusi /** 2503b6f4bb38Sapatard@mandriva.com * snd_soc_info_volsw_2r_sx - double with tlv and variable data size 2504b6f4bb38Sapatard@mandriva.com * mixer info callback 2505b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2506b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2507b6f4bb38Sapatard@mandriva.com * 2508b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2509b6f4bb38Sapatard@mandriva.com */ 2510b6f4bb38Sapatard@mandriva.com int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2511b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_info *uinfo) 2512b6f4bb38Sapatard@mandriva.com { 2513b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2514b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2515b6f4bb38Sapatard@mandriva.com int max = mc->max; 2516b6f4bb38Sapatard@mandriva.com int min = mc->min; 2517b6f4bb38Sapatard@mandriva.com 2518b6f4bb38Sapatard@mandriva.com uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2519b6f4bb38Sapatard@mandriva.com uinfo->count = 2; 2520b6f4bb38Sapatard@mandriva.com uinfo->value.integer.min = 0; 2521b6f4bb38Sapatard@mandriva.com uinfo->value.integer.max = max-min; 2522b6f4bb38Sapatard@mandriva.com 2523b6f4bb38Sapatard@mandriva.com return 0; 2524b6f4bb38Sapatard@mandriva.com } 2525b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); 2526b6f4bb38Sapatard@mandriva.com 2527b6f4bb38Sapatard@mandriva.com /** 2528b6f4bb38Sapatard@mandriva.com * snd_soc_get_volsw_2r_sx - double with tlv and variable data size 2529b6f4bb38Sapatard@mandriva.com * mixer get callback 2530b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2531b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2532b6f4bb38Sapatard@mandriva.com * 2533b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2534b6f4bb38Sapatard@mandriva.com */ 2535b6f4bb38Sapatard@mandriva.com int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2536b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2537b6f4bb38Sapatard@mandriva.com { 2538b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2539b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2540b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2541b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2542b6f4bb38Sapatard@mandriva.com int min = mc->min; 2543b6f4bb38Sapatard@mandriva.com int val = snd_soc_read(codec, mc->reg) & mask; 2544b6f4bb38Sapatard@mandriva.com int valr = snd_soc_read(codec, mc->rreg) & mask; 2545b6f4bb38Sapatard@mandriva.com 254620630c7fSStuart Longland ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; 254720630c7fSStuart Longland ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; 2548b6f4bb38Sapatard@mandriva.com return 0; 2549b6f4bb38Sapatard@mandriva.com } 2550b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); 2551b6f4bb38Sapatard@mandriva.com 2552b6f4bb38Sapatard@mandriva.com /** 2553b6f4bb38Sapatard@mandriva.com * snd_soc_put_volsw_2r_sx - double with tlv and variable data size 2554b6f4bb38Sapatard@mandriva.com * mixer put callback 2555b6f4bb38Sapatard@mandriva.com * @kcontrol: mixer control 2556b6f4bb38Sapatard@mandriva.com * @uinfo: control element information 2557b6f4bb38Sapatard@mandriva.com * 2558b6f4bb38Sapatard@mandriva.com * Returns 0 for success. 2559b6f4bb38Sapatard@mandriva.com */ 2560b6f4bb38Sapatard@mandriva.com int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, 2561b6f4bb38Sapatard@mandriva.com struct snd_ctl_elem_value *ucontrol) 2562b6f4bb38Sapatard@mandriva.com { 2563b6f4bb38Sapatard@mandriva.com struct soc_mixer_control *mc = 2564b6f4bb38Sapatard@mandriva.com (struct soc_mixer_control *)kcontrol->private_value; 2565b6f4bb38Sapatard@mandriva.com struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2566b6f4bb38Sapatard@mandriva.com unsigned int mask = (1<<mc->shift)-1; 2567b6f4bb38Sapatard@mandriva.com int min = mc->min; 2568b6f4bb38Sapatard@mandriva.com int ret; 2569b6f4bb38Sapatard@mandriva.com unsigned int val, valr, oval, ovalr; 2570b6f4bb38Sapatard@mandriva.com 2571b6f4bb38Sapatard@mandriva.com val = ((ucontrol->value.integer.value[0]+min) & 0xff); 2572b6f4bb38Sapatard@mandriva.com val &= mask; 2573b6f4bb38Sapatard@mandriva.com valr = ((ucontrol->value.integer.value[1]+min) & 0xff); 2574b6f4bb38Sapatard@mandriva.com valr &= mask; 2575b6f4bb38Sapatard@mandriva.com 2576b6f4bb38Sapatard@mandriva.com oval = snd_soc_read(codec, mc->reg) & mask; 2577b6f4bb38Sapatard@mandriva.com ovalr = snd_soc_read(codec, mc->rreg) & mask; 2578b6f4bb38Sapatard@mandriva.com 2579b6f4bb38Sapatard@mandriva.com ret = 0; 2580b6f4bb38Sapatard@mandriva.com if (oval != val) { 2581b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->reg, val); 2582b6f4bb38Sapatard@mandriva.com if (ret < 0) 2583f1df5aecSMark Brown return ret; 2584b6f4bb38Sapatard@mandriva.com } 2585b6f4bb38Sapatard@mandriva.com if (ovalr != valr) { 2586b6f4bb38Sapatard@mandriva.com ret = snd_soc_write(codec, mc->rreg, valr); 2587b6f4bb38Sapatard@mandriva.com if (ret < 0) 2588f1df5aecSMark Brown return ret; 2589b6f4bb38Sapatard@mandriva.com } 2590b6f4bb38Sapatard@mandriva.com 2591b6f4bb38Sapatard@mandriva.com return 0; 2592b6f4bb38Sapatard@mandriva.com } 2593b6f4bb38Sapatard@mandriva.com EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); 2594b6f4bb38Sapatard@mandriva.com 2595b6f4bb38Sapatard@mandriva.com /** 25968c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 25978c6529dbSLiam Girdwood * @dai: DAI 25988c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 25998c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 26008c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 26018c6529dbSLiam Girdwood * 26028c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 26038c6529dbSLiam Girdwood */ 26048c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 26058c6529dbSLiam Girdwood unsigned int freq, int dir) 26068c6529dbSLiam Girdwood { 2607f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 2608f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2609ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 2610da1c6ea6SMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, 2611ec4ee52aSMark Brown freq, dir); 26128c6529dbSLiam Girdwood else 26138c6529dbSLiam Girdwood return -EINVAL; 26148c6529dbSLiam Girdwood } 26158c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 26168c6529dbSLiam Girdwood 26178c6529dbSLiam Girdwood /** 2618ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 2619ec4ee52aSMark Brown * @codec: CODEC 2620ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 2621da1c6ea6SMark Brown * @source: Source for the clock 2622ec4ee52aSMark Brown * @freq: new clock frequency in Hz 2623ec4ee52aSMark Brown * @dir: new clock direction - input/output. 2624ec4ee52aSMark Brown * 2625ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 2626ec4ee52aSMark Brown */ 2627ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 2628da1c6ea6SMark Brown int source, unsigned int freq, int dir) 2629ec4ee52aSMark Brown { 2630ec4ee52aSMark Brown if (codec->driver->set_sysclk) 2631da1c6ea6SMark Brown return codec->driver->set_sysclk(codec, clk_id, source, 2632da1c6ea6SMark Brown freq, dir); 2633ec4ee52aSMark Brown else 2634ec4ee52aSMark Brown return -EINVAL; 2635ec4ee52aSMark Brown } 2636ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 2637ec4ee52aSMark Brown 2638ec4ee52aSMark Brown /** 26398c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 26408c6529dbSLiam Girdwood * @dai: DAI 2641ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 26428c6529dbSLiam Girdwood * @div: new clock divisor. 26438c6529dbSLiam Girdwood * 26448c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 26458c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 26468c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 26478c6529dbSLiam Girdwood */ 26488c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 26498c6529dbSLiam Girdwood int div_id, int div) 26508c6529dbSLiam Girdwood { 2651f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 2652f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 26538c6529dbSLiam Girdwood else 26548c6529dbSLiam Girdwood return -EINVAL; 26558c6529dbSLiam Girdwood } 26568c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 26578c6529dbSLiam Girdwood 26588c6529dbSLiam Girdwood /** 26598c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 26608c6529dbSLiam Girdwood * @dai: DAI 26618c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 266285488037SMark Brown * @source: DAI specific source for the PLL 26638c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 26648c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 26658c6529dbSLiam Girdwood * 26668c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 26678c6529dbSLiam Girdwood */ 266885488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 266985488037SMark Brown unsigned int freq_in, unsigned int freq_out) 26708c6529dbSLiam Girdwood { 2671f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 2672f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 267385488037SMark Brown freq_in, freq_out); 2674ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 2675ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 2676ec4ee52aSMark Brown freq_in, freq_out); 26778c6529dbSLiam Girdwood else 26788c6529dbSLiam Girdwood return -EINVAL; 26798c6529dbSLiam Girdwood } 26808c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 26818c6529dbSLiam Girdwood 2682ec4ee52aSMark Brown /* 2683ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 2684ec4ee52aSMark Brown * @codec: CODEC 2685ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 2686ec4ee52aSMark Brown * @source: DAI specific source for the PLL 2687ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 2688ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 2689ec4ee52aSMark Brown * 2690ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 2691ec4ee52aSMark Brown */ 2692ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 2693ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 2694ec4ee52aSMark Brown { 2695ec4ee52aSMark Brown if (codec->driver->set_pll) 2696ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 2697ec4ee52aSMark Brown freq_in, freq_out); 2698ec4ee52aSMark Brown else 2699ec4ee52aSMark Brown return -EINVAL; 2700ec4ee52aSMark Brown } 2701ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 2702ec4ee52aSMark Brown 27038c6529dbSLiam Girdwood /** 27048c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 27058c6529dbSLiam Girdwood * @dai: DAI 27068c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 27078c6529dbSLiam Girdwood * 27088c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 27098c6529dbSLiam Girdwood */ 27108c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 27118c6529dbSLiam Girdwood { 2712f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_fmt) 2713f0fba2adSLiam Girdwood return dai->driver->ops->set_fmt(dai, fmt); 27148c6529dbSLiam Girdwood else 27158c6529dbSLiam Girdwood return -EINVAL; 27168c6529dbSLiam Girdwood } 27178c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 27188c6529dbSLiam Girdwood 27198c6529dbSLiam Girdwood /** 27208c6529dbSLiam Girdwood * snd_soc_dai_set_tdm_slot - configure DAI TDM. 27218c6529dbSLiam Girdwood * @dai: DAI 2722a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 2723a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 27248c6529dbSLiam Girdwood * @slots: Number of slots in use. 2725a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 27268c6529dbSLiam Girdwood * 27278c6529dbSLiam Girdwood * Configures a DAI for TDM operation. Both mask and slots are codec and DAI 27288c6529dbSLiam Girdwood * specific. 27298c6529dbSLiam Girdwood */ 27308c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2731a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 27328c6529dbSLiam Girdwood { 2733f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 2734f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2735a5479e38SDaniel Ribeiro slots, slot_width); 27368c6529dbSLiam Girdwood else 27378c6529dbSLiam Girdwood return -EINVAL; 27388c6529dbSLiam Girdwood } 27398c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 27408c6529dbSLiam Girdwood 27418c6529dbSLiam Girdwood /** 2742472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 2743472df3cbSBarry Song * @dai: DAI 2744472df3cbSBarry Song * @tx_num: how many TX channels 2745472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 2746472df3cbSBarry Song * 0~num-1 uses 2747472df3cbSBarry Song * @rx_num: how many RX channels 2748472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 2749472df3cbSBarry Song * 0~num-1 uses 2750472df3cbSBarry Song * 2751472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 2752472df3cbSBarry Song */ 2753472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 2754472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 2755472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 2756472df3cbSBarry Song { 2757f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 2758f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 2759472df3cbSBarry Song rx_num, rx_slot); 2760472df3cbSBarry Song else 2761472df3cbSBarry Song return -EINVAL; 2762472df3cbSBarry Song } 2763472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 2764472df3cbSBarry Song 2765472df3cbSBarry Song /** 27668c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 27678c6529dbSLiam Girdwood * @dai: DAI 27688c6529dbSLiam Girdwood * @tristate: tristate enable 27698c6529dbSLiam Girdwood * 27708c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 27718c6529dbSLiam Girdwood */ 27728c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 27738c6529dbSLiam Girdwood { 2774f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 2775f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 27768c6529dbSLiam Girdwood else 27778c6529dbSLiam Girdwood return -EINVAL; 27788c6529dbSLiam Girdwood } 27798c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 27808c6529dbSLiam Girdwood 27818c6529dbSLiam Girdwood /** 27828c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 27838c6529dbSLiam Girdwood * @dai: DAI 27848c6529dbSLiam Girdwood * @mute: mute enable 27858c6529dbSLiam Girdwood * 27868c6529dbSLiam Girdwood * Mutes the DAI DAC. 27878c6529dbSLiam Girdwood */ 27888c6529dbSLiam Girdwood int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 27898c6529dbSLiam Girdwood { 2790f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->digital_mute) 2791f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 27928c6529dbSLiam Girdwood else 27938c6529dbSLiam Girdwood return -EINVAL; 27948c6529dbSLiam Girdwood } 27958c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 27968c6529dbSLiam Girdwood 2797c5af3a2eSMark Brown /** 2798c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 2799c5af3a2eSMark Brown * 2800ac11a2b3SMark Brown * @card: Card to register 2801c5af3a2eSMark Brown * 2802c5af3a2eSMark Brown */ 280370a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 2804c5af3a2eSMark Brown { 2805f0fba2adSLiam Girdwood int i; 2806f0fba2adSLiam Girdwood 2807c5af3a2eSMark Brown if (!card->name || !card->dev) 2808c5af3a2eSMark Brown return -EINVAL; 2809c5af3a2eSMark Brown 2810ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 2811ed77cc12SMark Brown 2812111c6419SStephen Warren snd_soc_initialize_card_lists(card); 2813111c6419SStephen Warren 2814150dd2f8SVinod Koul soc_init_card_debugfs(card); 2815150dd2f8SVinod Koul 28162eea392dSJarkko Nikula card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * 28172eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 2818f0fba2adSLiam Girdwood GFP_KERNEL); 2819f0fba2adSLiam Girdwood if (card->rtd == NULL) 2820f0fba2adSLiam Girdwood return -ENOMEM; 28212eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 2822f0fba2adSLiam Girdwood 2823f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 2824f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 2825f0fba2adSLiam Girdwood 2826c5af3a2eSMark Brown INIT_LIST_HEAD(&card->list); 2827db432b41SMark Brown INIT_LIST_HEAD(&card->dapm_dirty); 2828c5af3a2eSMark Brown card->instantiated = 0; 2829f0fba2adSLiam Girdwood mutex_init(&card->mutex); 2830c5af3a2eSMark Brown 2831c5af3a2eSMark Brown mutex_lock(&client_mutex); 2832c5af3a2eSMark Brown list_add(&card->list, &card_list); 2833435c5e25SMark Brown snd_soc_instantiate_cards(); 2834c5af3a2eSMark Brown mutex_unlock(&client_mutex); 2835c5af3a2eSMark Brown 2836c5af3a2eSMark Brown dev_dbg(card->dev, "Registered card '%s'\n", card->name); 2837c5af3a2eSMark Brown 2838c5af3a2eSMark Brown return 0; 2839c5af3a2eSMark Brown } 284070a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 2841c5af3a2eSMark Brown 2842c5af3a2eSMark Brown /** 2843c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 2844c5af3a2eSMark Brown * 2845ac11a2b3SMark Brown * @card: Card to unregister 2846c5af3a2eSMark Brown * 2847c5af3a2eSMark Brown */ 284870a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 2849c5af3a2eSMark Brown { 2850b0e26485SVinod Koul if (card->instantiated) 2851b0e26485SVinod Koul soc_cleanup_card_resources(card); 2852c5af3a2eSMark Brown mutex_lock(&client_mutex); 2853c5af3a2eSMark Brown list_del(&card->list); 2854c5af3a2eSMark Brown mutex_unlock(&client_mutex); 2855c5af3a2eSMark Brown dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); 2856c5af3a2eSMark Brown 2857c5af3a2eSMark Brown return 0; 2858c5af3a2eSMark Brown } 285970a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 2860c5af3a2eSMark Brown 2861f0fba2adSLiam Girdwood /* 2862f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 2863f0fba2adSLiam Girdwood * and sanitizing names. 2864f0fba2adSLiam Girdwood */ 28650b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 2866f0fba2adSLiam Girdwood { 2867f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 2868f0fba2adSLiam Girdwood int id1, id2; 2869f0fba2adSLiam Girdwood 2870f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 2871f0fba2adSLiam Girdwood return NULL; 2872f0fba2adSLiam Girdwood 287358818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 2874f0fba2adSLiam Girdwood 2875f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 2876f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 2877f0fba2adSLiam Girdwood if (found) { 2878f0fba2adSLiam Girdwood /* get ID */ 2879f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 2880f0fba2adSLiam Girdwood 2881f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 2882f0fba2adSLiam Girdwood if (*id == -1) 2883f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 2884f0fba2adSLiam Girdwood } 2885f0fba2adSLiam Girdwood 2886f0fba2adSLiam Girdwood } else { 2887f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 2888f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 2889f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 2890f0fba2adSLiam Girdwood 2891f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 289205899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 2893f0fba2adSLiam Girdwood 2894f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 2895f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 289658818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 2897f0fba2adSLiam Girdwood } else 2898f0fba2adSLiam Girdwood *id = 0; 2899f0fba2adSLiam Girdwood } 2900f0fba2adSLiam Girdwood 2901f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 2902f0fba2adSLiam Girdwood } 2903f0fba2adSLiam Girdwood 2904f0fba2adSLiam Girdwood /* 2905f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 2906f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 2907f0fba2adSLiam Girdwood */ 2908f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 2909f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 2910f0fba2adSLiam Girdwood { 2911f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 2912f0fba2adSLiam Girdwood printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n", 2913f0fba2adSLiam Girdwood dev_name(dev)); 2914f0fba2adSLiam Girdwood return NULL; 2915f0fba2adSLiam Girdwood } 2916f0fba2adSLiam Girdwood 2917f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 2918f0fba2adSLiam Girdwood } 2919f0fba2adSLiam Girdwood 29209115171aSMark Brown /** 29219115171aSMark Brown * snd_soc_register_dai - Register a DAI with the ASoC core 29229115171aSMark Brown * 2923ac11a2b3SMark Brown * @dai: DAI to register 29249115171aSMark Brown */ 2925f0fba2adSLiam Girdwood int snd_soc_register_dai(struct device *dev, 2926f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 29279115171aSMark Brown { 2928f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 29299115171aSMark Brown 2930f0fba2adSLiam Girdwood dev_dbg(dev, "dai register %s\n", dev_name(dev)); 29319115171aSMark Brown 2932f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 2933f0fba2adSLiam Girdwood if (dai == NULL) 2934f0fba2adSLiam Girdwood return -ENOMEM; 29356335d055SEric Miao 2936f0fba2adSLiam Girdwood /* create DAI component name */ 2937f0fba2adSLiam Girdwood dai->name = fmt_single_name(dev, &dai->id); 2938f0fba2adSLiam Girdwood if (dai->name == NULL) { 2939f0fba2adSLiam Girdwood kfree(dai); 2940f0fba2adSLiam Girdwood return -ENOMEM; 2941f0fba2adSLiam Girdwood } 2942f0fba2adSLiam Girdwood 2943f0fba2adSLiam Girdwood dai->dev = dev; 2944f0fba2adSLiam Girdwood dai->driver = dai_drv; 2945f0fba2adSLiam Girdwood if (!dai->driver->ops) 2946f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 29479115171aSMark Brown 29489115171aSMark Brown mutex_lock(&client_mutex); 29499115171aSMark Brown list_add(&dai->list, &dai_list); 2950435c5e25SMark Brown snd_soc_instantiate_cards(); 29519115171aSMark Brown mutex_unlock(&client_mutex); 29529115171aSMark Brown 29539115171aSMark Brown pr_debug("Registered DAI '%s'\n", dai->name); 29549115171aSMark Brown 29559115171aSMark Brown return 0; 29569115171aSMark Brown } 29579115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dai); 29589115171aSMark Brown 29599115171aSMark Brown /** 29609115171aSMark Brown * snd_soc_unregister_dai - Unregister a DAI from the ASoC core 29619115171aSMark Brown * 2962ac11a2b3SMark Brown * @dai: DAI to unregister 29639115171aSMark Brown */ 2964f0fba2adSLiam Girdwood void snd_soc_unregister_dai(struct device *dev) 29659115171aSMark Brown { 2966f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 2967f0fba2adSLiam Girdwood 2968f0fba2adSLiam Girdwood list_for_each_entry(dai, &dai_list, list) { 2969f0fba2adSLiam Girdwood if (dev == dai->dev) 2970f0fba2adSLiam Girdwood goto found; 2971f0fba2adSLiam Girdwood } 2972f0fba2adSLiam Girdwood return; 2973f0fba2adSLiam Girdwood 2974f0fba2adSLiam Girdwood found: 29759115171aSMark Brown mutex_lock(&client_mutex); 29769115171aSMark Brown list_del(&dai->list); 29779115171aSMark Brown mutex_unlock(&client_mutex); 29789115171aSMark Brown 29799115171aSMark Brown pr_debug("Unregistered DAI '%s'\n", dai->name); 2980f0fba2adSLiam Girdwood kfree(dai->name); 2981f0fba2adSLiam Girdwood kfree(dai); 29829115171aSMark Brown } 29839115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); 29849115171aSMark Brown 29859115171aSMark Brown /** 29869115171aSMark Brown * snd_soc_register_dais - Register multiple DAIs with the ASoC core 29879115171aSMark Brown * 2988ac11a2b3SMark Brown * @dai: Array of DAIs to register 2989ac11a2b3SMark Brown * @count: Number of DAIs 29909115171aSMark Brown */ 2991f0fba2adSLiam Girdwood int snd_soc_register_dais(struct device *dev, 2992f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv, size_t count) 29939115171aSMark Brown { 2994f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 2995f0fba2adSLiam Girdwood int i, ret = 0; 2996f0fba2adSLiam Girdwood 2997720ffa4cSLiam Girdwood dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count); 29989115171aSMark Brown 29999115171aSMark Brown for (i = 0; i < count; i++) { 3000f0fba2adSLiam Girdwood 3001f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3002c46e0079SAxel Lin if (dai == NULL) { 3003c46e0079SAxel Lin ret = -ENOMEM; 3004c46e0079SAxel Lin goto err; 3005c46e0079SAxel Lin } 3006f0fba2adSLiam Girdwood 3007f0fba2adSLiam Girdwood /* create DAI component name */ 3008f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3009f0fba2adSLiam Girdwood if (dai->name == NULL) { 3010f0fba2adSLiam Girdwood kfree(dai); 3011f0fba2adSLiam Girdwood ret = -EINVAL; 30129115171aSMark Brown goto err; 30139115171aSMark Brown } 30149115171aSMark Brown 3015f0fba2adSLiam Girdwood dai->dev = dev; 3016f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 30170f9141c9SMark Brown if (dai->driver->id) 30180f9141c9SMark Brown dai->id = dai->driver->id; 30190f9141c9SMark Brown else 30200f9141c9SMark Brown dai->id = i; 3021f0fba2adSLiam Girdwood if (!dai->driver->ops) 3022f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 3023f0fba2adSLiam Girdwood 3024f0fba2adSLiam Girdwood mutex_lock(&client_mutex); 3025f0fba2adSLiam Girdwood list_add(&dai->list, &dai_list); 3026f0fba2adSLiam Girdwood mutex_unlock(&client_mutex); 3027f0fba2adSLiam Girdwood 3028f0fba2adSLiam Girdwood pr_debug("Registered DAI '%s'\n", dai->name); 3029f0fba2adSLiam Girdwood } 3030f0fba2adSLiam Girdwood 30311dcb4f38SAxel Lin mutex_lock(&client_mutex); 3032f0fba2adSLiam Girdwood snd_soc_instantiate_cards(); 30331dcb4f38SAxel Lin mutex_unlock(&client_mutex); 30349115171aSMark Brown return 0; 30359115171aSMark Brown 30369115171aSMark Brown err: 30379115171aSMark Brown for (i--; i >= 0; i--) 3038f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 30399115171aSMark Brown 30409115171aSMark Brown return ret; 30419115171aSMark Brown } 30429115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_dais); 30439115171aSMark Brown 30449115171aSMark Brown /** 30459115171aSMark Brown * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core 30469115171aSMark Brown * 3047ac11a2b3SMark Brown * @dai: Array of DAIs to unregister 3048ac11a2b3SMark Brown * @count: Number of DAIs 30499115171aSMark Brown */ 3050f0fba2adSLiam Girdwood void snd_soc_unregister_dais(struct device *dev, size_t count) 30519115171aSMark Brown { 30529115171aSMark Brown int i; 30539115171aSMark Brown 30549115171aSMark Brown for (i = 0; i < count; i++) 3055f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 30569115171aSMark Brown } 30579115171aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); 30589115171aSMark Brown 305912a48a8cSMark Brown /** 306012a48a8cSMark Brown * snd_soc_register_platform - Register a platform with the ASoC core 306112a48a8cSMark Brown * 3062ac11a2b3SMark Brown * @platform: platform to register 306312a48a8cSMark Brown */ 3064f0fba2adSLiam Girdwood int snd_soc_register_platform(struct device *dev, 3065f0fba2adSLiam Girdwood struct snd_soc_platform_driver *platform_drv) 306612a48a8cSMark Brown { 3067f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 306812a48a8cSMark Brown 3069f0fba2adSLiam Girdwood dev_dbg(dev, "platform register %s\n", dev_name(dev)); 3070f0fba2adSLiam Girdwood 3071f0fba2adSLiam Girdwood platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 3072f0fba2adSLiam Girdwood if (platform == NULL) 3073f0fba2adSLiam Girdwood return -ENOMEM; 3074f0fba2adSLiam Girdwood 3075f0fba2adSLiam Girdwood /* create platform component name */ 3076f0fba2adSLiam Girdwood platform->name = fmt_single_name(dev, &platform->id); 3077f0fba2adSLiam Girdwood if (platform->name == NULL) { 3078f0fba2adSLiam Girdwood kfree(platform); 3079f0fba2adSLiam Girdwood return -ENOMEM; 3080f0fba2adSLiam Girdwood } 3081f0fba2adSLiam Girdwood 3082f0fba2adSLiam Girdwood platform->dev = dev; 3083f0fba2adSLiam Girdwood platform->driver = platform_drv; 3084b7950641SLiam Girdwood platform->dapm.dev = dev; 3085b7950641SLiam Girdwood platform->dapm.platform = platform; 308664a648c2SLiam Girdwood platform->dapm.stream_event = platform_drv->stream_event; 308712a48a8cSMark Brown 308812a48a8cSMark Brown mutex_lock(&client_mutex); 308912a48a8cSMark Brown list_add(&platform->list, &platform_list); 3090435c5e25SMark Brown snd_soc_instantiate_cards(); 309112a48a8cSMark Brown mutex_unlock(&client_mutex); 309212a48a8cSMark Brown 309312a48a8cSMark Brown pr_debug("Registered platform '%s'\n", platform->name); 309412a48a8cSMark Brown 309512a48a8cSMark Brown return 0; 309612a48a8cSMark Brown } 309712a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 309812a48a8cSMark Brown 309912a48a8cSMark Brown /** 310012a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 310112a48a8cSMark Brown * 3102ac11a2b3SMark Brown * @platform: platform to unregister 310312a48a8cSMark Brown */ 3104f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 310512a48a8cSMark Brown { 3106f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 3107f0fba2adSLiam Girdwood 3108f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 3109f0fba2adSLiam Girdwood if (dev == platform->dev) 3110f0fba2adSLiam Girdwood goto found; 3111f0fba2adSLiam Girdwood } 3112f0fba2adSLiam Girdwood return; 3113f0fba2adSLiam Girdwood 3114f0fba2adSLiam Girdwood found: 311512a48a8cSMark Brown mutex_lock(&client_mutex); 311612a48a8cSMark Brown list_del(&platform->list); 311712a48a8cSMark Brown mutex_unlock(&client_mutex); 311812a48a8cSMark Brown 311912a48a8cSMark Brown pr_debug("Unregistered platform '%s'\n", platform->name); 3120f0fba2adSLiam Girdwood kfree(platform->name); 3121f0fba2adSLiam Girdwood kfree(platform); 312212a48a8cSMark Brown } 312312a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 312412a48a8cSMark Brown 3125151ab22cSMark Brown static u64 codec_format_map[] = { 3126151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 3127151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 3128151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 3129151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 3130151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 3131151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 3132151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3133151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 3134151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 3135151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 3136151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 3137151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 3138151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 3139151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 3140151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 3141151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 3142151ab22cSMark Brown }; 3143151ab22cSMark Brown 3144151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 3145151ab22cSMark Brown * the endianness of the data but we're using the CPU format 3146151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 3147151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 3148151ab22cSMark Brown */ 3149151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 3150151ab22cSMark Brown { 3151151ab22cSMark Brown int i; 3152151ab22cSMark Brown 3153151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 3154151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 3155151ab22cSMark Brown stream->formats |= codec_format_map[i]; 3156151ab22cSMark Brown } 3157151ab22cSMark Brown 31580d0cf00aSMark Brown /** 31590d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 31600d0cf00aSMark Brown * 3161ac11a2b3SMark Brown * @codec: codec to register 31620d0cf00aSMark Brown */ 3163f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 3164001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 3165001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 3166001ae4c0SMark Brown int num_dai) 31670d0cf00aSMark Brown { 31683335ddcaSDimitris Papastamos size_t reg_size; 3169f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3170f0fba2adSLiam Girdwood int ret, i; 3171151ab22cSMark Brown 3172f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 31730d0cf00aSMark Brown 3174f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 3175f0fba2adSLiam Girdwood if (codec == NULL) 3176f0fba2adSLiam Girdwood return -ENOMEM; 31770d0cf00aSMark Brown 3178f0fba2adSLiam Girdwood /* create CODEC component name */ 3179f0fba2adSLiam Girdwood codec->name = fmt_single_name(dev, &codec->id); 3180f0fba2adSLiam Girdwood if (codec->name == NULL) { 3181f0fba2adSLiam Girdwood kfree(codec); 3182f0fba2adSLiam Girdwood return -ENOMEM; 3183151ab22cSMark Brown } 3184151ab22cSMark Brown 318523bbce34SDimitris Papastamos if (codec_drv->compress_type) 318623bbce34SDimitris Papastamos codec->compress_type = codec_drv->compress_type; 318723bbce34SDimitris Papastamos else 318823bbce34SDimitris Papastamos codec->compress_type = SND_SOC_FLAT_COMPRESSION; 318923bbce34SDimitris Papastamos 3190c3acec26SMark Brown codec->write = codec_drv->write; 3191c3acec26SMark Brown codec->read = codec_drv->read; 31921500b7b5SDimitris Papastamos codec->volatile_register = codec_drv->volatile_register; 31931500b7b5SDimitris Papastamos codec->readable_register = codec_drv->readable_register; 31948020454cSDimitris Papastamos codec->writable_register = codec_drv->writable_register; 3195ce6120ccSLiam Girdwood codec->dapm.bias_level = SND_SOC_BIAS_OFF; 3196ce6120ccSLiam Girdwood codec->dapm.dev = dev; 3197ce6120ccSLiam Girdwood codec->dapm.codec = codec; 3198474b62d6SMark Brown codec->dapm.seq_notifier = codec_drv->seq_notifier; 319964a648c2SLiam Girdwood codec->dapm.stream_event = codec_drv->stream_event; 3200f0fba2adSLiam Girdwood codec->dev = dev; 3201f0fba2adSLiam Girdwood codec->driver = codec_drv; 3202f0fba2adSLiam Girdwood codec->num_dai = num_dai; 3203f0fba2adSLiam Girdwood mutex_init(&codec->mutex); 3204f0fba2adSLiam Girdwood 32057a30a3dbSDimitris Papastamos /* allocate CODEC register cache */ 32067a30a3dbSDimitris Papastamos if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 32073335ddcaSDimitris Papastamos reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 3208aea170a0SDimitris Papastamos codec->reg_size = reg_size; 32093335ddcaSDimitris Papastamos /* it is necessary to make a copy of the default register cache 32103335ddcaSDimitris Papastamos * because in the case of using a compression type that requires 32113335ddcaSDimitris Papastamos * the default register cache to be marked as __devinitconst the 32123335ddcaSDimitris Papastamos * kernel might have freed the array by the time we initialize 32133335ddcaSDimitris Papastamos * the cache. 32143335ddcaSDimitris Papastamos */ 32152aa86323SDimitris Papastamos if (codec_drv->reg_cache_default) { 32163335ddcaSDimitris Papastamos codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, 32173335ddcaSDimitris Papastamos reg_size, GFP_KERNEL); 32183335ddcaSDimitris Papastamos if (!codec->reg_def_copy) { 32193335ddcaSDimitris Papastamos ret = -ENOMEM; 3220fdf0f54dSDimitris Papastamos goto fail; 32217a30a3dbSDimitris Papastamos } 32227a30a3dbSDimitris Papastamos } 32232aa86323SDimitris Papastamos } 32247a30a3dbSDimitris Papastamos 32251500b7b5SDimitris Papastamos if (codec_drv->reg_access_size && codec_drv->reg_access_default) { 32261500b7b5SDimitris Papastamos if (!codec->volatile_register) 32271500b7b5SDimitris Papastamos codec->volatile_register = snd_soc_default_volatile_register; 32281500b7b5SDimitris Papastamos if (!codec->readable_register) 32291500b7b5SDimitris Papastamos codec->readable_register = snd_soc_default_readable_register; 32308020454cSDimitris Papastamos if (!codec->writable_register) 32318020454cSDimitris Papastamos codec->writable_register = snd_soc_default_writable_register; 32321500b7b5SDimitris Papastamos } 32331500b7b5SDimitris Papastamos 3234f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 3235f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 3236f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 3237f0fba2adSLiam Girdwood } 3238f0fba2adSLiam Girdwood 323926b01ccdSMark Brown /* register any DAIs */ 324026b01ccdSMark Brown if (num_dai) { 3241f0fba2adSLiam Girdwood ret = snd_soc_register_dais(dev, dai_drv, num_dai); 3242f0fba2adSLiam Girdwood if (ret < 0) 3243fdf0f54dSDimitris Papastamos goto fail; 324426b01ccdSMark Brown } 3245f0fba2adSLiam Girdwood 32460d0cf00aSMark Brown mutex_lock(&client_mutex); 32470d0cf00aSMark Brown list_add(&codec->list, &codec_list); 32480d0cf00aSMark Brown snd_soc_instantiate_cards(); 32490d0cf00aSMark Brown mutex_unlock(&client_mutex); 32500d0cf00aSMark Brown 32510d0cf00aSMark Brown pr_debug("Registered codec '%s'\n", codec->name); 32520d0cf00aSMark Brown return 0; 3253f0fba2adSLiam Girdwood 3254fdf0f54dSDimitris Papastamos fail: 32553335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 32563335ddcaSDimitris Papastamos codec->reg_def_copy = NULL; 3257f0fba2adSLiam Girdwood kfree(codec->name); 3258f0fba2adSLiam Girdwood kfree(codec); 3259f0fba2adSLiam Girdwood return ret; 32600d0cf00aSMark Brown } 32610d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 32620d0cf00aSMark Brown 32630d0cf00aSMark Brown /** 32640d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 32650d0cf00aSMark Brown * 3266ac11a2b3SMark Brown * @codec: codec to unregister 32670d0cf00aSMark Brown */ 3268f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 32690d0cf00aSMark Brown { 3270f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 3271f0fba2adSLiam Girdwood int i; 3272f0fba2adSLiam Girdwood 3273f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 3274f0fba2adSLiam Girdwood if (dev == codec->dev) 3275f0fba2adSLiam Girdwood goto found; 3276f0fba2adSLiam Girdwood } 3277f0fba2adSLiam Girdwood return; 3278f0fba2adSLiam Girdwood 3279f0fba2adSLiam Girdwood found: 328026b01ccdSMark Brown if (codec->num_dai) 3281f0fba2adSLiam Girdwood for (i = 0; i < codec->num_dai; i++) 3282f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 3283f0fba2adSLiam Girdwood 32840d0cf00aSMark Brown mutex_lock(&client_mutex); 32850d0cf00aSMark Brown list_del(&codec->list); 32860d0cf00aSMark Brown mutex_unlock(&client_mutex); 32870d0cf00aSMark Brown 32880d0cf00aSMark Brown pr_debug("Unregistered codec '%s'\n", codec->name); 3289f0fba2adSLiam Girdwood 32907a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 32913335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 32921aafcd4dSDimitris Papastamos kfree(codec->name); 3293f0fba2adSLiam Girdwood kfree(codec); 32940d0cf00aSMark Brown } 32950d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 32960d0cf00aSMark Brown 3297c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 3298db2a4165SFrank Mandarino { 3299384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 33008a9dab1aSMark Brown snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); 33018a9dab1aSMark Brown if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { 3302384c89e2SMark Brown printk(KERN_WARNING 3303384c89e2SMark Brown "ASoC: Failed to create debugfs directory\n"); 33048a9dab1aSMark Brown snd_soc_debugfs_root = NULL; 3305384c89e2SMark Brown } 3306c3c5a19aSMark Brown 33078a9dab1aSMark Brown if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, 3308c3c5a19aSMark Brown &codec_list_fops)) 3309c3c5a19aSMark Brown pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); 3310c3c5a19aSMark Brown 33118a9dab1aSMark Brown if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, 3312f3208780SMark Brown &dai_list_fops)) 3313f3208780SMark Brown pr_warn("ASoC: Failed to create DAI list debugfs file\n"); 331419c7ac27SMark Brown 33158a9dab1aSMark Brown if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, 331619c7ac27SMark Brown &platform_list_fops)) 331719c7ac27SMark Brown pr_warn("ASoC: Failed to create platform list debugfs file\n"); 3318384c89e2SMark Brown #endif 3319384c89e2SMark Brown 3320fb257897SMark Brown snd_soc_util_init(); 3321fb257897SMark Brown 3322db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 3323db2a4165SFrank Mandarino } 33244abe8e16SMark Brown module_init(snd_soc_init); 3325db2a4165SFrank Mandarino 33267d8c16a6SMark Brown static void __exit snd_soc_exit(void) 3327db2a4165SFrank Mandarino { 3328fb257897SMark Brown snd_soc_util_exit(); 3329fb257897SMark Brown 3330384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 33318a9dab1aSMark Brown debugfs_remove_recursive(snd_soc_debugfs_root); 3332384c89e2SMark Brown #endif 3333db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 3334db2a4165SFrank Mandarino } 3335db2a4165SFrank Mandarino module_exit(snd_soc_exit); 3336db2a4165SFrank Mandarino 3337db2a4165SFrank Mandarino /* Module information */ 3338d331124dSLiam Girdwood MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 3339db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 3340db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 33418b45a209SKay Sievers MODULE_ALIAS("platform:soc-audio"); 3342