1db2a4165SFrank Mandarino /* 2db2a4165SFrank Mandarino * soc-core.c -- ALSA SoC Audio Layer 3db2a4165SFrank Mandarino * 4db2a4165SFrank Mandarino * Copyright 2005 Wolfson Microelectronics PLC. 50664d888SLiam Girdwood * Copyright 2005 Openedhand Ltd. 6f0fba2adSLiam Girdwood * Copyright (C) 2010 Slimlogic Ltd. 7f0fba2adSLiam Girdwood * Copyright (C) 2010 Texas Instruments Inc. 80664d888SLiam Girdwood * 9d331124dSLiam Girdwood * Author: Liam Girdwood <lrg@slimlogic.co.uk> 100664d888SLiam Girdwood * with code, comments and ideas from :- 110664d888SLiam Girdwood * Richard Purdie <richard@openedhand.com> 12db2a4165SFrank Mandarino * 13db2a4165SFrank Mandarino * This program is free software; you can redistribute it and/or modify it 14db2a4165SFrank Mandarino * under the terms of the GNU General Public License as published by the 15db2a4165SFrank Mandarino * Free Software Foundation; either version 2 of the License, or (at your 16db2a4165SFrank Mandarino * option) any later version. 17db2a4165SFrank Mandarino * 18db2a4165SFrank Mandarino * TODO: 19db2a4165SFrank Mandarino * o Add hw rules to enforce rates, etc. 20db2a4165SFrank Mandarino * o More testing with other codecs/machines. 21db2a4165SFrank Mandarino * o Add more codecs and platforms to ensure good API coverage. 22db2a4165SFrank Mandarino * o Support TDM on PCM and I2S 23db2a4165SFrank Mandarino */ 24db2a4165SFrank Mandarino 25db2a4165SFrank Mandarino #include <linux/module.h> 26db2a4165SFrank Mandarino #include <linux/moduleparam.h> 27db2a4165SFrank Mandarino #include <linux/init.h> 28db2a4165SFrank Mandarino #include <linux/delay.h> 29db2a4165SFrank Mandarino #include <linux/pm.h> 30db2a4165SFrank Mandarino #include <linux/bitops.h> 3112ef193dSTroy Kisky #include <linux/debugfs.h> 32db2a4165SFrank Mandarino #include <linux/platform_device.h> 33f0e8ed85SMark Brown #include <linux/ctype.h> 345a0e3ad6STejun Heo #include <linux/slab.h> 35bec4fa05SStephen Warren #include <linux/of.h> 36474828a4SMarek Vasut #include <sound/ac97_codec.h> 37db2a4165SFrank Mandarino #include <sound/core.h> 383028eb8cSMark Brown #include <sound/jack.h> 39db2a4165SFrank Mandarino #include <sound/pcm.h> 40db2a4165SFrank Mandarino #include <sound/pcm_params.h> 41db2a4165SFrank Mandarino #include <sound/soc.h> 4201d7584cSLiam Girdwood #include <sound/soc-dpcm.h> 43db2a4165SFrank Mandarino #include <sound/initval.h> 44db2a4165SFrank Mandarino 45a8b1d34fSMark Brown #define CREATE_TRACE_POINTS 46a8b1d34fSMark Brown #include <trace/events/asoc.h> 47a8b1d34fSMark Brown 48f0fba2adSLiam Girdwood #define NAME_SIZE 32 49f0fba2adSLiam Girdwood 50db2a4165SFrank Mandarino static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 51db2a4165SFrank Mandarino 52384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 538a9dab1aSMark Brown struct dentry *snd_soc_debugfs_root; 548a9dab1aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); 55384c89e2SMark Brown #endif 56384c89e2SMark Brown 57c5af3a2eSMark Brown static DEFINE_MUTEX(client_mutex); 589115171aSMark Brown static LIST_HEAD(dai_list); 5912a48a8cSMark Brown static LIST_HEAD(platform_list); 600d0cf00aSMark Brown static LIST_HEAD(codec_list); 61030e79f6SKuninori Morimoto static LIST_HEAD(component_list); 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 { 17336ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 174f0fba2adSLiam Girdwood 17513fd179fSDimitris Papastamos return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); 1762624d5faSMark Brown } 1772624d5faSMark Brown 1782624d5faSMark Brown static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1792624d5faSMark Brown 180dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev, 181dbe21408SMark Brown struct device_attribute *attr, char *buf) 182dbe21408SMark Brown { 18336ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 184dbe21408SMark Brown 185f0fba2adSLiam Girdwood return sprintf(buf, "%ld\n", rtd->pmdown_time); 186dbe21408SMark Brown } 187dbe21408SMark Brown 188dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev, 189dbe21408SMark Brown struct device_attribute *attr, 190dbe21408SMark Brown const char *buf, size_t count) 191dbe21408SMark Brown { 19236ae1a96SMark Brown struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 193c593b520SMark Brown int ret; 194dbe21408SMark Brown 195c593b520SMark Brown ret = strict_strtol(buf, 10, &rtd->pmdown_time); 196c593b520SMark Brown if (ret) 197c593b520SMark Brown return ret; 198dbe21408SMark Brown 199dbe21408SMark Brown return count; 200dbe21408SMark Brown } 201dbe21408SMark Brown 202dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 203dbe21408SMark Brown 2042624d5faSMark Brown #ifdef CONFIG_DEBUG_FS 2052624d5faSMark Brown static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 2062624d5faSMark Brown size_t count, loff_t *ppos) 2072624d5faSMark Brown { 2082624d5faSMark Brown ssize_t ret; 2092624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 21013fd179fSDimitris Papastamos char *buf; 21113fd179fSDimitris Papastamos 21213fd179fSDimitris Papastamos if (*ppos < 0 || !count) 21313fd179fSDimitris Papastamos return -EINVAL; 21413fd179fSDimitris Papastamos 21513fd179fSDimitris Papastamos buf = kmalloc(count, GFP_KERNEL); 2162624d5faSMark Brown if (!buf) 2172624d5faSMark Brown return -ENOMEM; 21813fd179fSDimitris Papastamos 21913fd179fSDimitris Papastamos ret = soc_codec_reg_show(codec, buf, count, *ppos); 22013fd179fSDimitris Papastamos if (ret >= 0) { 22113fd179fSDimitris Papastamos if (copy_to_user(user_buf, buf, ret)) { 22213fd179fSDimitris Papastamos kfree(buf); 22313fd179fSDimitris Papastamos return -EFAULT; 22413fd179fSDimitris Papastamos } 22513fd179fSDimitris Papastamos *ppos += ret; 22613fd179fSDimitris Papastamos } 22713fd179fSDimitris Papastamos 2282624d5faSMark Brown kfree(buf); 2292624d5faSMark Brown return ret; 2302624d5faSMark Brown } 2312624d5faSMark Brown 2322624d5faSMark Brown static ssize_t codec_reg_write_file(struct file *file, 2332624d5faSMark Brown const char __user *user_buf, size_t count, loff_t *ppos) 2342624d5faSMark Brown { 2352624d5faSMark Brown char buf[32]; 23634e268d8SStephen Boyd size_t buf_size; 2372624d5faSMark Brown char *start = buf; 2382624d5faSMark Brown unsigned long reg, value; 2392624d5faSMark Brown struct snd_soc_codec *codec = file->private_data; 2402624d5faSMark Brown 2412624d5faSMark Brown buf_size = min(count, (sizeof(buf)-1)); 2422624d5faSMark Brown if (copy_from_user(buf, user_buf, buf_size)) 2432624d5faSMark Brown return -EFAULT; 2442624d5faSMark Brown buf[buf_size] = 0; 2452624d5faSMark Brown 2462624d5faSMark Brown while (*start == ' ') 2472624d5faSMark Brown start++; 2482624d5faSMark Brown reg = simple_strtoul(start, &start, 16); 2492624d5faSMark Brown while (*start == ' ') 2502624d5faSMark Brown start++; 2512624d5faSMark Brown if (strict_strtoul(start, 16, &value)) 2522624d5faSMark Brown return -EINVAL; 2530d51a9cbSMark Brown 2540d51a9cbSMark Brown /* Userspace has been fiddling around behind the kernel's back */ 255373d4d09SRusty Russell add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); 2560d51a9cbSMark Brown 257e4f078d8SDimitris Papastamos snd_soc_write(codec, reg, value); 2582624d5faSMark Brown return buf_size; 2592624d5faSMark Brown } 2602624d5faSMark Brown 2612624d5faSMark Brown static const struct file_operations codec_reg_fops = { 262234e3405SStephen Boyd .open = simple_open, 2632624d5faSMark Brown .read = codec_reg_read_file, 2642624d5faSMark Brown .write = codec_reg_write_file, 2656038f373SArnd Bergmann .llseek = default_llseek, 2662624d5faSMark Brown }; 2672624d5faSMark Brown 2682624d5faSMark Brown static void soc_init_codec_debugfs(struct snd_soc_codec *codec) 2692624d5faSMark Brown { 270d6ce4cf3SJarkko Nikula struct dentry *debugfs_card_root = codec->card->debugfs_card_root; 271d6ce4cf3SJarkko Nikula 2726ba6c9c3SMark Brown codec->debugfs_codec_root = debugfs_create_dir(codec->name, 273d6ce4cf3SJarkko Nikula debugfs_card_root); 2742624d5faSMark Brown if (!codec->debugfs_codec_root) { 275f110bfc7SLiam Girdwood dev_warn(codec->dev, "ASoC: Failed to create codec debugfs" 276f110bfc7SLiam Girdwood " directory\n"); 2772624d5faSMark Brown return; 2782624d5faSMark Brown } 2792624d5faSMark Brown 280aaee8ef1SMark Brown debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, 281aaee8ef1SMark Brown &codec->cache_sync); 282aaee8ef1SMark Brown debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, 283aaee8ef1SMark Brown &codec->cache_only); 284aaee8ef1SMark Brown 2852624d5faSMark Brown codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, 2862624d5faSMark Brown codec->debugfs_codec_root, 2872624d5faSMark Brown codec, &codec_reg_fops); 2882624d5faSMark Brown if (!codec->debugfs_reg) 289f110bfc7SLiam Girdwood dev_warn(codec->dev, "ASoC: Failed to create codec register" 290f110bfc7SLiam Girdwood " debugfs file\n"); 2912624d5faSMark Brown 2928eecaf62SLars-Peter Clausen snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); 2932624d5faSMark Brown } 2942624d5faSMark Brown 2952624d5faSMark Brown static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 2962624d5faSMark Brown { 2972624d5faSMark Brown debugfs_remove_recursive(codec->debugfs_codec_root); 2982624d5faSMark Brown } 2992624d5faSMark Brown 300731f1ab2SSebastien Guiriec static void soc_init_platform_debugfs(struct snd_soc_platform *platform) 301731f1ab2SSebastien Guiriec { 302731f1ab2SSebastien Guiriec struct dentry *debugfs_card_root = platform->card->debugfs_card_root; 303731f1ab2SSebastien Guiriec 304731f1ab2SSebastien Guiriec platform->debugfs_platform_root = debugfs_create_dir(platform->name, 305731f1ab2SSebastien Guiriec debugfs_card_root); 306731f1ab2SSebastien Guiriec if (!platform->debugfs_platform_root) { 307731f1ab2SSebastien Guiriec dev_warn(platform->dev, 308f110bfc7SLiam Girdwood "ASoC: Failed to create platform debugfs directory\n"); 309731f1ab2SSebastien Guiriec return; 310731f1ab2SSebastien Guiriec } 311731f1ab2SSebastien Guiriec 312731f1ab2SSebastien Guiriec snd_soc_dapm_debugfs_init(&platform->dapm, 313731f1ab2SSebastien Guiriec platform->debugfs_platform_root); 314731f1ab2SSebastien Guiriec } 315731f1ab2SSebastien Guiriec 316731f1ab2SSebastien Guiriec static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) 317731f1ab2SSebastien Guiriec { 318731f1ab2SSebastien Guiriec debugfs_remove_recursive(platform->debugfs_platform_root); 319731f1ab2SSebastien Guiriec } 320731f1ab2SSebastien Guiriec 321c3c5a19aSMark Brown static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, 322c3c5a19aSMark Brown size_t count, loff_t *ppos) 323c3c5a19aSMark Brown { 324c3c5a19aSMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3252b194f9dSMark Brown ssize_t len, ret = 0; 326c3c5a19aSMark Brown struct snd_soc_codec *codec; 327c3c5a19aSMark Brown 328c3c5a19aSMark Brown if (!buf) 329c3c5a19aSMark Brown return -ENOMEM; 330c3c5a19aSMark Brown 3312b194f9dSMark Brown list_for_each_entry(codec, &codec_list, list) { 3322b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 333c3c5a19aSMark Brown codec->name); 3342b194f9dSMark Brown if (len >= 0) 3352b194f9dSMark Brown ret += len; 3362b194f9dSMark Brown if (ret > PAGE_SIZE) { 3372b194f9dSMark Brown ret = PAGE_SIZE; 3382b194f9dSMark Brown break; 3392b194f9dSMark Brown } 3402b194f9dSMark Brown } 341c3c5a19aSMark Brown 342c3c5a19aSMark Brown if (ret >= 0) 343c3c5a19aSMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 344c3c5a19aSMark Brown 345c3c5a19aSMark Brown kfree(buf); 346c3c5a19aSMark Brown 347c3c5a19aSMark Brown return ret; 348c3c5a19aSMark Brown } 349c3c5a19aSMark Brown 350c3c5a19aSMark Brown static const struct file_operations codec_list_fops = { 351c3c5a19aSMark Brown .read = codec_list_read_file, 352c3c5a19aSMark Brown .llseek = default_llseek,/* read accesses f_pos */ 353c3c5a19aSMark Brown }; 354c3c5a19aSMark Brown 355f3208780SMark Brown static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, 356f3208780SMark Brown size_t count, loff_t *ppos) 357f3208780SMark Brown { 358f3208780SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3592b194f9dSMark Brown ssize_t len, ret = 0; 360f3208780SMark Brown struct snd_soc_dai *dai; 361f3208780SMark Brown 362f3208780SMark Brown if (!buf) 363f3208780SMark Brown return -ENOMEM; 364f3208780SMark Brown 3652b194f9dSMark Brown list_for_each_entry(dai, &dai_list, list) { 3662b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); 3672b194f9dSMark Brown if (len >= 0) 3682b194f9dSMark Brown ret += len; 3692b194f9dSMark Brown if (ret > PAGE_SIZE) { 3702b194f9dSMark Brown ret = PAGE_SIZE; 3712b194f9dSMark Brown break; 3722b194f9dSMark Brown } 3732b194f9dSMark Brown } 374f3208780SMark Brown 375f3208780SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 376f3208780SMark Brown 377f3208780SMark Brown kfree(buf); 378f3208780SMark Brown 379f3208780SMark Brown return ret; 380f3208780SMark Brown } 381f3208780SMark Brown 382f3208780SMark Brown static const struct file_operations dai_list_fops = { 383f3208780SMark Brown .read = dai_list_read_file, 384f3208780SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 385f3208780SMark Brown }; 386f3208780SMark Brown 38719c7ac27SMark Brown static ssize_t platform_list_read_file(struct file *file, 38819c7ac27SMark Brown char __user *user_buf, 38919c7ac27SMark Brown size_t count, loff_t *ppos) 39019c7ac27SMark Brown { 39119c7ac27SMark Brown char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 3922b194f9dSMark Brown ssize_t len, ret = 0; 39319c7ac27SMark Brown struct snd_soc_platform *platform; 39419c7ac27SMark Brown 39519c7ac27SMark Brown if (!buf) 39619c7ac27SMark Brown return -ENOMEM; 39719c7ac27SMark Brown 3982b194f9dSMark Brown list_for_each_entry(platform, &platform_list, list) { 3992b194f9dSMark Brown len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", 40019c7ac27SMark Brown platform->name); 4012b194f9dSMark Brown if (len >= 0) 4022b194f9dSMark Brown ret += len; 4032b194f9dSMark Brown if (ret > PAGE_SIZE) { 4042b194f9dSMark Brown ret = PAGE_SIZE; 4052b194f9dSMark Brown break; 4062b194f9dSMark Brown } 4072b194f9dSMark Brown } 40819c7ac27SMark Brown 40919c7ac27SMark Brown ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 41019c7ac27SMark Brown 41119c7ac27SMark Brown kfree(buf); 41219c7ac27SMark Brown 41319c7ac27SMark Brown return ret; 41419c7ac27SMark Brown } 41519c7ac27SMark Brown 41619c7ac27SMark Brown static const struct file_operations platform_list_fops = { 41719c7ac27SMark Brown .read = platform_list_read_file, 41819c7ac27SMark Brown .llseek = default_llseek,/* read accesses f_pos */ 41919c7ac27SMark Brown }; 42019c7ac27SMark Brown 421a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card) 422a6052154SJarkko Nikula { 423a6052154SJarkko Nikula card->debugfs_card_root = debugfs_create_dir(card->name, 4248a9dab1aSMark Brown snd_soc_debugfs_root); 4253a45b867SJarkko Nikula if (!card->debugfs_card_root) { 426a6052154SJarkko Nikula dev_warn(card->dev, 4277c08be84SLothar Waßmann "ASoC: Failed to create card debugfs directory\n"); 4283a45b867SJarkko Nikula return; 4293a45b867SJarkko Nikula } 4303a45b867SJarkko Nikula 4313a45b867SJarkko Nikula card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, 4323a45b867SJarkko Nikula card->debugfs_card_root, 4333a45b867SJarkko Nikula &card->pop_time); 4343a45b867SJarkko Nikula if (!card->debugfs_pop_time) 4353a45b867SJarkko Nikula dev_warn(card->dev, 436f110bfc7SLiam Girdwood "ASoC: Failed to create pop time debugfs file\n"); 437a6052154SJarkko Nikula } 438a6052154SJarkko Nikula 439a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card) 440a6052154SJarkko Nikula { 441a6052154SJarkko Nikula debugfs_remove_recursive(card->debugfs_card_root); 442a6052154SJarkko Nikula } 443a6052154SJarkko Nikula 4442624d5faSMark Brown #else 4452624d5faSMark Brown 4462624d5faSMark Brown static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) 4472624d5faSMark Brown { 4482624d5faSMark Brown } 4492624d5faSMark Brown 4502624d5faSMark Brown static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) 4512624d5faSMark Brown { 4522624d5faSMark Brown } 453b95fccbcSAxel Lin 454731f1ab2SSebastien Guiriec static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform) 455731f1ab2SSebastien Guiriec { 456731f1ab2SSebastien Guiriec } 457731f1ab2SSebastien Guiriec 458731f1ab2SSebastien Guiriec static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) 459731f1ab2SSebastien Guiriec { 460731f1ab2SSebastien Guiriec } 461731f1ab2SSebastien Guiriec 462b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card) 463b95fccbcSAxel Lin { 464b95fccbcSAxel Lin } 465b95fccbcSAxel Lin 466b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) 467b95fccbcSAxel Lin { 468b95fccbcSAxel Lin } 4692624d5faSMark Brown #endif 4702624d5faSMark Brown 47147c88fffSLiam Girdwood struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, 47247c88fffSLiam Girdwood const char *dai_link, int stream) 47347c88fffSLiam Girdwood { 47447c88fffSLiam Girdwood int i; 47547c88fffSLiam Girdwood 47647c88fffSLiam Girdwood for (i = 0; i < card->num_links; i++) { 47747c88fffSLiam Girdwood if (card->rtd[i].dai_link->no_pcm && 47847c88fffSLiam Girdwood !strcmp(card->rtd[i].dai_link->name, dai_link)) 47947c88fffSLiam Girdwood return card->rtd[i].pcm->streams[stream].substream; 48047c88fffSLiam Girdwood } 481f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link); 48247c88fffSLiam Girdwood return NULL; 48347c88fffSLiam Girdwood } 48447c88fffSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); 48547c88fffSLiam Girdwood 48647c88fffSLiam Girdwood struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, 48747c88fffSLiam Girdwood const char *dai_link) 48847c88fffSLiam Girdwood { 48947c88fffSLiam Girdwood int i; 49047c88fffSLiam Girdwood 49147c88fffSLiam Girdwood for (i = 0; i < card->num_links; i++) { 49247c88fffSLiam Girdwood if (!strcmp(card->rtd[i].dai_link->name, dai_link)) 49347c88fffSLiam Girdwood return &card->rtd[i]; 49447c88fffSLiam Girdwood } 495f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link); 49647c88fffSLiam Girdwood return NULL; 49747c88fffSLiam Girdwood } 49847c88fffSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); 49947c88fffSLiam Girdwood 500db2a4165SFrank Mandarino #ifdef CONFIG_SND_SOC_AC97_BUS 501db2a4165SFrank Mandarino /* unregister ac97 codec */ 502db2a4165SFrank Mandarino static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) 503db2a4165SFrank Mandarino { 504db2a4165SFrank Mandarino if (codec->ac97->dev.bus) 505db2a4165SFrank Mandarino device_unregister(&codec->ac97->dev); 506db2a4165SFrank Mandarino return 0; 507db2a4165SFrank Mandarino } 508db2a4165SFrank Mandarino 509db2a4165SFrank Mandarino /* stop no dev release warning */ 510db2a4165SFrank Mandarino static void soc_ac97_device_release(struct device *dev){} 511db2a4165SFrank Mandarino 512db2a4165SFrank Mandarino /* register ac97 codec to bus */ 513db2a4165SFrank Mandarino static int soc_ac97_dev_register(struct snd_soc_codec *codec) 514db2a4165SFrank Mandarino { 515db2a4165SFrank Mandarino int err; 516db2a4165SFrank Mandarino 517db2a4165SFrank Mandarino codec->ac97->dev.bus = &ac97_bus_type; 5184ac5c61fSMark Brown codec->ac97->dev.parent = codec->card->dev; 519db2a4165SFrank Mandarino codec->ac97->dev.release = soc_ac97_device_release; 520db2a4165SFrank Mandarino 521bb072bf0SKay Sievers dev_set_name(&codec->ac97->dev, "%d-%d:%s", 522f0fba2adSLiam Girdwood codec->card->snd_card->number, 0, codec->name); 523db2a4165SFrank Mandarino err = device_register(&codec->ac97->dev); 524db2a4165SFrank Mandarino if (err < 0) { 525f110bfc7SLiam Girdwood dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); 526db2a4165SFrank Mandarino codec->ac97->dev.bus = NULL; 527db2a4165SFrank Mandarino return err; 528db2a4165SFrank Mandarino } 529db2a4165SFrank Mandarino return 0; 530db2a4165SFrank Mandarino } 531db2a4165SFrank Mandarino #endif 532db2a4165SFrank Mandarino 5336f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP 534db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */ 5356f8ab4acSMark Brown int snd_soc_suspend(struct device *dev) 536db2a4165SFrank Mandarino { 5376f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 5382eea392dSJarkko Nikula struct snd_soc_codec *codec; 539db2a4165SFrank Mandarino int i; 540db2a4165SFrank Mandarino 541e3509ff0SDaniel Mack /* If the initialization of this soc device failed, there is no codec 542e3509ff0SDaniel Mack * associated with it. Just bail out in this case. 543e3509ff0SDaniel Mack */ 544f0fba2adSLiam Girdwood if (list_empty(&card->codec_dev_list)) 545e3509ff0SDaniel Mack return 0; 546e3509ff0SDaniel Mack 5476ed25978SAndy Green /* Due to the resume being scheduled into a workqueue we could 5486ed25978SAndy Green * suspend before that's finished - wait for it to complete. 5496ed25978SAndy Green */ 550f0fba2adSLiam Girdwood snd_power_lock(card->snd_card); 551f0fba2adSLiam Girdwood snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); 552f0fba2adSLiam Girdwood snd_power_unlock(card->snd_card); 5536ed25978SAndy Green 5546ed25978SAndy Green /* we're going to block userspace touching us until resume completes */ 555f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); 5566ed25978SAndy Green 557a00f90f9SMark Brown /* mute any active DACs */ 558f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 559f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 560f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 5613efab7dcSMark Brown 562f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5633efab7dcSMark Brown continue; 5643efab7dcSMark Brown 565f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 566f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 1); 567db2a4165SFrank Mandarino } 568db2a4165SFrank Mandarino 5694ccab3e7SLiam Girdwood /* suspend all pcms */ 570f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 571f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5723efab7dcSMark Brown continue; 5733efab7dcSMark Brown 574f0fba2adSLiam Girdwood snd_pcm_suspend_all(card->rtd[i].pcm); 5753efab7dcSMark Brown } 5764ccab3e7SLiam Girdwood 57787506549SMark Brown if (card->suspend_pre) 57870b2ac12SMark Brown card->suspend_pre(card); 579db2a4165SFrank Mandarino 580f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 581f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 582f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 5833efab7dcSMark Brown 584f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 5853efab7dcSMark Brown continue; 5863efab7dcSMark Brown 587f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) 588f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 589f0fba2adSLiam Girdwood if (platform->driver->suspend && !platform->suspended) { 590f0fba2adSLiam Girdwood platform->driver->suspend(cpu_dai); 591f0fba2adSLiam Girdwood platform->suspended = 1; 592f0fba2adSLiam Girdwood } 593db2a4165SFrank Mandarino } 594db2a4165SFrank Mandarino 595db2a4165SFrank Mandarino /* close any waiting streams and save state */ 596f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 59743829731STejun Heo flush_delayed_work(&card->rtd[i].delayed_work); 598ce6120ccSLiam Girdwood card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; 599f0fba2adSLiam Girdwood } 600db2a4165SFrank Mandarino 601f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 6023efab7dcSMark Brown 603f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6043efab7dcSMark Brown continue; 6053efab7dcSMark Brown 6067bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 6077bd3a6f3SMark Brown SNDRV_PCM_STREAM_PLAYBACK, 608db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 609f0fba2adSLiam Girdwood 6107bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 6117bd3a6f3SMark Brown SNDRV_PCM_STREAM_CAPTURE, 612db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_SUSPEND); 613db2a4165SFrank Mandarino } 614db2a4165SFrank Mandarino 615e2d32ff6SMark Brown /* Recheck all analogue paths too */ 616e2d32ff6SMark Brown dapm_mark_io_dirty(&card->dapm); 617e2d32ff6SMark Brown snd_soc_dapm_sync(&card->dapm); 618e2d32ff6SMark Brown 619f0fba2adSLiam Girdwood /* suspend all CODECs */ 6202eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 6211547aba9SMark Brown /* If there are paths active then the CODEC will be held with 6221547aba9SMark Brown * bias _ON and should not be suspended. */ 623f0fba2adSLiam Girdwood if (!codec->suspended && codec->driver->suspend) { 624ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 6251547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 626125a25daSMark Brown /* 627125a25daSMark Brown * If the CODEC is capable of idle 628125a25daSMark Brown * bias off then being in STANDBY 629125a25daSMark Brown * means it's doing something, 630125a25daSMark Brown * otherwise fall through. 631125a25daSMark Brown */ 632125a25daSMark Brown if (codec->dapm.idle_bias_off) { 633125a25daSMark Brown dev_dbg(codec->dev, 634f110bfc7SLiam Girdwood "ASoC: idle_bias_off CODEC on" 635f110bfc7SLiam Girdwood " over suspend\n"); 636125a25daSMark Brown break; 637125a25daSMark Brown } 6381547aba9SMark Brown case SND_SOC_BIAS_OFF: 63984b315eeSLars-Peter Clausen codec->driver->suspend(codec); 640f0fba2adSLiam Girdwood codec->suspended = 1; 6417be4ba24SMark Brown codec->cache_sync = 1; 642da8b8e0fSMark Brown if (codec->using_regmap) 643da8b8e0fSMark Brown regcache_mark_dirty(codec->control_data); 6441547aba9SMark Brown break; 6451547aba9SMark Brown default: 646f110bfc7SLiam Girdwood dev_dbg(codec->dev, "ASoC: CODEC is on" 647f110bfc7SLiam Girdwood " over suspend\n"); 6481547aba9SMark Brown break; 6491547aba9SMark Brown } 6501547aba9SMark Brown } 651f0fba2adSLiam Girdwood } 652db2a4165SFrank Mandarino 653f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 654f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6553efab7dcSMark Brown 656f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6573efab7dcSMark Brown continue; 6583efab7dcSMark Brown 659f0fba2adSLiam Girdwood if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) 660f0fba2adSLiam Girdwood cpu_dai->driver->suspend(cpu_dai); 661db2a4165SFrank Mandarino } 662db2a4165SFrank Mandarino 66387506549SMark Brown if (card->suspend_post) 66470b2ac12SMark Brown card->suspend_post(card); 665db2a4165SFrank Mandarino 666db2a4165SFrank Mandarino return 0; 667db2a4165SFrank Mandarino } 6686f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend); 669db2a4165SFrank Mandarino 6706ed25978SAndy Green /* deferred resume work, so resume can complete before we finished 6716ed25978SAndy Green * setting our codec back up, which can be very slow on I2C 6726ed25978SAndy Green */ 6736ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work) 674db2a4165SFrank Mandarino { 675f0fba2adSLiam Girdwood struct snd_soc_card *card = 676f0fba2adSLiam Girdwood container_of(work, struct snd_soc_card, deferred_resume_work); 6772eea392dSJarkko Nikula struct snd_soc_codec *codec; 678db2a4165SFrank Mandarino int i; 679db2a4165SFrank Mandarino 6806ed25978SAndy Green /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 6816ed25978SAndy Green * so userspace apps are blocked from touching us 6826ed25978SAndy Green */ 6836ed25978SAndy Green 684f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: starting resume work\n"); 6856ed25978SAndy Green 6869949788bSMark Brown /* Bring us up into D2 so that DAPM starts enabling things */ 687f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); 6889949788bSMark Brown 68987506549SMark Brown if (card->resume_pre) 69070b2ac12SMark Brown card->resume_pre(card); 691db2a4165SFrank Mandarino 692f0fba2adSLiam Girdwood /* resume AC97 DAIs */ 693f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 694f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 6953efab7dcSMark Brown 696f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 6973efab7dcSMark Brown continue; 6983efab7dcSMark Brown 699f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) 700f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 701db2a4165SFrank Mandarino } 702db2a4165SFrank Mandarino 7032eea392dSJarkko Nikula list_for_each_entry(codec, &card->codec_dev_list, card_list) { 7041547aba9SMark Brown /* If the CODEC was idle over suspend then it will have been 7051547aba9SMark Brown * left with bias OFF or STANDBY and suspended so we must now 7061547aba9SMark Brown * resume. Otherwise the suspend was suppressed. 7071547aba9SMark Brown */ 708f0fba2adSLiam Girdwood if (codec->driver->resume && codec->suspended) { 709ce6120ccSLiam Girdwood switch (codec->dapm.bias_level) { 7101547aba9SMark Brown case SND_SOC_BIAS_STANDBY: 7111547aba9SMark Brown case SND_SOC_BIAS_OFF: 712f0fba2adSLiam Girdwood codec->driver->resume(codec); 713f0fba2adSLiam Girdwood codec->suspended = 0; 7141547aba9SMark Brown break; 7151547aba9SMark Brown default: 716f110bfc7SLiam Girdwood dev_dbg(codec->dev, "ASoC: CODEC was on over" 717f110bfc7SLiam Girdwood " suspend\n"); 7181547aba9SMark Brown break; 7191547aba9SMark Brown } 7201547aba9SMark Brown } 721f0fba2adSLiam Girdwood } 722db2a4165SFrank Mandarino 723f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 7243efab7dcSMark Brown 725f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7263efab7dcSMark Brown continue; 7273efab7dcSMark Brown 7287bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 729d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_PLAYBACK, 730db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 731f0fba2adSLiam Girdwood 7327bd3a6f3SMark Brown snd_soc_dapm_stream_event(&card->rtd[i], 733d9b0951bSLiam Girdwood SNDRV_PCM_STREAM_CAPTURE, 734db2a4165SFrank Mandarino SND_SOC_DAPM_STREAM_RESUME); 735db2a4165SFrank Mandarino } 736db2a4165SFrank Mandarino 7373ff3f64bSMark Brown /* unmute any active DACs */ 738f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 739f0fba2adSLiam Girdwood struct snd_soc_dai *dai = card->rtd[i].codec_dai; 740f0fba2adSLiam Girdwood struct snd_soc_dai_driver *drv = dai->driver; 7413efab7dcSMark Brown 742f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7433efab7dcSMark Brown continue; 7443efab7dcSMark Brown 745f0fba2adSLiam Girdwood if (drv->ops->digital_mute && dai->playback_active) 746f0fba2adSLiam Girdwood drv->ops->digital_mute(dai, 0); 747db2a4165SFrank Mandarino } 748db2a4165SFrank Mandarino 749f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 750f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 751f0fba2adSLiam Girdwood struct snd_soc_platform *platform = card->rtd[i].platform; 7523efab7dcSMark Brown 753f0fba2adSLiam Girdwood if (card->rtd[i].dai_link->ignore_suspend) 7543efab7dcSMark Brown continue; 7553efab7dcSMark Brown 756f0fba2adSLiam Girdwood if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) 757f0fba2adSLiam Girdwood cpu_dai->driver->resume(cpu_dai); 758f0fba2adSLiam Girdwood if (platform->driver->resume && platform->suspended) { 759f0fba2adSLiam Girdwood platform->driver->resume(cpu_dai); 760f0fba2adSLiam Girdwood platform->suspended = 0; 761f0fba2adSLiam Girdwood } 762db2a4165SFrank Mandarino } 763db2a4165SFrank Mandarino 76487506549SMark Brown if (card->resume_post) 76570b2ac12SMark Brown card->resume_post(card); 766db2a4165SFrank Mandarino 767f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: resume work completed\n"); 7686ed25978SAndy Green 7696ed25978SAndy Green /* userspace can access us now we are back as we were before */ 770f0fba2adSLiam Girdwood snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); 771e2d32ff6SMark Brown 772e2d32ff6SMark Brown /* Recheck all analogue paths too */ 773e2d32ff6SMark Brown dapm_mark_io_dirty(&card->dapm); 774e2d32ff6SMark Brown snd_soc_dapm_sync(&card->dapm); 7756ed25978SAndy Green } 7766ed25978SAndy Green 7776ed25978SAndy Green /* powers up audio subsystem after a suspend */ 7786f8ab4acSMark Brown int snd_soc_resume(struct device *dev) 7796ed25978SAndy Green { 7806f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 78182e14e8bSStephen Warren int i, ac97_control = 0; 782b9dd94a8SPeter Ujfalusi 7835ff1ddf2SEric Miao /* If the initialization of this soc device failed, there is no codec 7845ff1ddf2SEric Miao * associated with it. Just bail out in this case. 7855ff1ddf2SEric Miao */ 7865ff1ddf2SEric Miao if (list_empty(&card->codec_dev_list)) 7875ff1ddf2SEric Miao return 0; 7885ff1ddf2SEric Miao 78964ab9baaSMark Brown /* AC97 devices might have other drivers hanging off them so 79064ab9baaSMark Brown * need to resume immediately. Other drivers don't have that 79164ab9baaSMark Brown * problem and may take a substantial amount of time to resume 79264ab9baaSMark Brown * due to I/O costs and anti-pop so handle them out of line. 79364ab9baaSMark Brown */ 794f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 795f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; 79682e14e8bSStephen Warren ac97_control |= cpu_dai->driver->ac97_control; 79782e14e8bSStephen Warren } 79882e14e8bSStephen Warren if (ac97_control) { 799f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Resuming AC97 immediately\n"); 80064ab9baaSMark Brown soc_resume_deferred(&card->deferred_resume_work); 80164ab9baaSMark Brown } else { 802f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Scheduling resume work\n"); 8036308419aSMark Brown if (!schedule_work(&card->deferred_resume_work)) 804f110bfc7SLiam Girdwood dev_err(dev, "ASoC: resume work item may be lost\n"); 805f0fba2adSLiam Girdwood } 8066ed25978SAndy Green 807db2a4165SFrank Mandarino return 0; 808db2a4165SFrank Mandarino } 8096f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume); 810db2a4165SFrank Mandarino #else 8116f8ab4acSMark Brown #define snd_soc_suspend NULL 8126f8ab4acSMark Brown #define snd_soc_resume NULL 813db2a4165SFrank Mandarino #endif 814db2a4165SFrank Mandarino 81585e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops null_dai_ops = { 81602a06d30SBarry Song }; 81702a06d30SBarry Song 818f0fba2adSLiam Girdwood static int soc_bind_dai_link(struct snd_soc_card *card, int num) 819db2a4165SFrank Mandarino { 820f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 821f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 822fe3e78e0SMark Brown struct snd_soc_codec *codec; 823435c5e25SMark Brown struct snd_soc_platform *platform; 824f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai, *cpu_dai; 825848dd8beSMark Brown const char *platform_name; 826db2a4165SFrank Mandarino 827f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 8286308419aSMark Brown 829b19e6e7bSMark Brown /* Find CPU DAI from registered DAIs*/ 830f0fba2adSLiam Girdwood list_for_each_entry(cpu_dai, &dai_list, list) { 831bc92657aSStephen Warren if (dai_link->cpu_of_node && 832bc92657aSStephen Warren (cpu_dai->dev->of_node != dai_link->cpu_of_node)) 8335a504963SStephen Warren continue; 834bc92657aSStephen Warren if (dai_link->cpu_name && 835bc92657aSStephen Warren strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name)) 8362610ab77SStephen Warren continue; 837bc92657aSStephen Warren if (dai_link->cpu_dai_name && 838bc92657aSStephen Warren strcmp(cpu_dai->name, dai_link->cpu_dai_name)) 839bc92657aSStephen Warren continue; 8402610ab77SStephen Warren 841f0fba2adSLiam Girdwood rtd->cpu_dai = cpu_dai; 842f0fba2adSLiam Girdwood } 843b19e6e7bSMark Brown 844b19e6e7bSMark Brown if (!rtd->cpu_dai) { 845f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", 846f0fba2adSLiam Girdwood dai_link->cpu_dai_name); 847b19e6e7bSMark Brown return -EPROBE_DEFER; 848c5af3a2eSMark Brown } 849c5af3a2eSMark Brown 850b19e6e7bSMark Brown /* Find CODEC from registered CODECs */ 851f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 8525a504963SStephen Warren if (dai_link->codec_of_node) { 8535a504963SStephen Warren if (codec->dev->of_node != dai_link->codec_of_node) 8545a504963SStephen Warren continue; 8555a504963SStephen Warren } else { 8562610ab77SStephen Warren if (strcmp(codec->name, dai_link->codec_name)) 8572610ab77SStephen Warren continue; 8585a504963SStephen Warren } 8592610ab77SStephen Warren 860f0fba2adSLiam Girdwood rtd->codec = codec; 861f0fba2adSLiam Girdwood 8622610ab77SStephen Warren /* 8632610ab77SStephen Warren * CODEC found, so find CODEC DAI from registered DAIs from 8642610ab77SStephen Warren * this CODEC 8652610ab77SStephen Warren */ 866f0fba2adSLiam Girdwood list_for_each_entry(codec_dai, &dai_list, list) { 867f0fba2adSLiam Girdwood if (codec->dev == codec_dai->dev && 8682610ab77SStephen Warren !strcmp(codec_dai->name, 8692610ab77SStephen Warren dai_link->codec_dai_name)) { 8702610ab77SStephen Warren 871f0fba2adSLiam Girdwood rtd->codec_dai = codec_dai; 872435c5e25SMark Brown } 873f0fba2adSLiam Girdwood } 874b19e6e7bSMark Brown 875b19e6e7bSMark Brown if (!rtd->codec_dai) { 876f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", 877f0fba2adSLiam Girdwood dai_link->codec_dai_name); 878b19e6e7bSMark Brown return -EPROBE_DEFER; 879f0fba2adSLiam Girdwood } 880b19e6e7bSMark Brown } 881b19e6e7bSMark Brown 882b19e6e7bSMark Brown if (!rtd->codec) { 883f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: CODEC %s not registered\n", 884f0fba2adSLiam Girdwood dai_link->codec_name); 885b19e6e7bSMark Brown return -EPROBE_DEFER; 886b19e6e7bSMark Brown } 887848dd8beSMark Brown 888848dd8beSMark Brown /* if there's no platform we match on the empty platform */ 889848dd8beSMark Brown platform_name = dai_link->platform_name; 8905a504963SStephen Warren if (!platform_name && !dai_link->platform_of_node) 891848dd8beSMark Brown platform_name = "snd-soc-dummy"; 892848dd8beSMark Brown 893b19e6e7bSMark Brown /* find one from the set of registered platforms */ 894f0fba2adSLiam Girdwood list_for_each_entry(platform, &platform_list, list) { 8955a504963SStephen Warren if (dai_link->platform_of_node) { 8965a504963SStephen Warren if (platform->dev->of_node != 8975a504963SStephen Warren dai_link->platform_of_node) 8985a504963SStephen Warren continue; 8995a504963SStephen Warren } else { 9002610ab77SStephen Warren if (strcmp(platform->name, platform_name)) 9012610ab77SStephen Warren continue; 9025a504963SStephen Warren } 9032610ab77SStephen Warren 904f0fba2adSLiam Girdwood rtd->platform = platform; 905f0fba2adSLiam Girdwood } 906b19e6e7bSMark Brown if (!rtd->platform) { 907f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: platform %s not registered\n", 908f0fba2adSLiam Girdwood dai_link->platform_name); 909b19e6e7bSMark Brown return -EPROBE_DEFER; 910f0fba2adSLiam Girdwood } 911b19e6e7bSMark Brown 912b19e6e7bSMark Brown card->num_rtd++; 913b19e6e7bSMark Brown 914b19e6e7bSMark Brown return 0; 9156b05eda6SMark Brown } 9166b05eda6SMark Brown 917d12cd198SStephen Warren static int soc_remove_platform(struct snd_soc_platform *platform) 918d12cd198SStephen Warren { 919d12cd198SStephen Warren int ret; 920d12cd198SStephen Warren 921d12cd198SStephen Warren if (platform->driver->remove) { 922d12cd198SStephen Warren ret = platform->driver->remove(platform); 923d12cd198SStephen Warren if (ret < 0) 924f110bfc7SLiam Girdwood dev_err(platform->dev, "ASoC: failed to remove %d\n", 925f110bfc7SLiam Girdwood ret); 926d12cd198SStephen Warren } 927d12cd198SStephen Warren 928d12cd198SStephen Warren /* Make sure all DAPM widgets are freed */ 929d12cd198SStephen Warren snd_soc_dapm_free(&platform->dapm); 930d12cd198SStephen Warren 931d12cd198SStephen Warren soc_cleanup_platform_debugfs(platform); 932d12cd198SStephen Warren platform->probed = 0; 933d12cd198SStephen Warren list_del(&platform->card_list); 934d12cd198SStephen Warren module_put(platform->dev->driver->owner); 935d12cd198SStephen Warren 936d12cd198SStephen Warren return 0; 937d12cd198SStephen Warren } 938d12cd198SStephen Warren 939589c3563SJarkko Nikula static void soc_remove_codec(struct snd_soc_codec *codec) 940589c3563SJarkko Nikula { 941589c3563SJarkko Nikula int err; 942589c3563SJarkko Nikula 943589c3563SJarkko Nikula if (codec->driver->remove) { 944589c3563SJarkko Nikula err = codec->driver->remove(codec); 945589c3563SJarkko Nikula if (err < 0) 946f110bfc7SLiam Girdwood dev_err(codec->dev, "ASoC: failed to remove %d\n", err); 947589c3563SJarkko Nikula } 948589c3563SJarkko Nikula 949589c3563SJarkko Nikula /* Make sure all DAPM widgets are freed */ 950589c3563SJarkko Nikula snd_soc_dapm_free(&codec->dapm); 951589c3563SJarkko Nikula 952589c3563SJarkko Nikula soc_cleanup_codec_debugfs(codec); 953589c3563SJarkko Nikula codec->probed = 0; 954589c3563SJarkko Nikula list_del(&codec->card_list); 955589c3563SJarkko Nikula module_put(codec->dev->driver->owner); 956589c3563SJarkko Nikula } 957589c3563SJarkko Nikula 95862ae68faSStephen Warren static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) 959f0fba2adSLiam Girdwood { 960f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 961f0fba2adSLiam Girdwood struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; 962f0fba2adSLiam Girdwood int err; 963f0fba2adSLiam Girdwood 964f0fba2adSLiam Girdwood /* unregister the rtd device */ 965f0fba2adSLiam Girdwood if (rtd->dev_registered) { 96636ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_pmdown_time); 96736ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_codec_reg); 96836ae1a96SMark Brown device_unregister(rtd->dev); 969f0fba2adSLiam Girdwood rtd->dev_registered = 0; 97002a06d30SBarry Song } 97102a06d30SBarry Song 972f0fba2adSLiam Girdwood /* remove the CODEC DAI */ 9730168bf0dSLiam Girdwood if (codec_dai && codec_dai->probed && 9740168bf0dSLiam Girdwood codec_dai->driver->remove_order == order) { 975f0fba2adSLiam Girdwood if (codec_dai->driver->remove) { 976f0fba2adSLiam Girdwood err = codec_dai->driver->remove(codec_dai); 977f0fba2adSLiam Girdwood if (err < 0) 978f110bfc7SLiam Girdwood dev_err(codec_dai->dev, 979f110bfc7SLiam Girdwood "ASoC: failed to remove %s: %d\n", 9800837fc62SFabio Estevam codec_dai->name, err); 981f0fba2adSLiam Girdwood } 982f0fba2adSLiam Girdwood codec_dai->probed = 0; 983f0fba2adSLiam Girdwood list_del(&codec_dai->card_list); 984f0fba2adSLiam Girdwood } 985f0fba2adSLiam Girdwood 986f0fba2adSLiam Girdwood /* remove the cpu_dai */ 9870168bf0dSLiam Girdwood if (cpu_dai && cpu_dai->probed && 9880168bf0dSLiam Girdwood cpu_dai->driver->remove_order == order) { 989f0fba2adSLiam Girdwood if (cpu_dai->driver->remove) { 990f0fba2adSLiam Girdwood err = cpu_dai->driver->remove(cpu_dai); 991f0fba2adSLiam Girdwood if (err < 0) 992f110bfc7SLiam Girdwood dev_err(cpu_dai->dev, 993f110bfc7SLiam Girdwood "ASoC: failed to remove %s: %d\n", 9940837fc62SFabio Estevam cpu_dai->name, err); 995f0fba2adSLiam Girdwood } 996f0fba2adSLiam Girdwood cpu_dai->probed = 0; 997f0fba2adSLiam Girdwood list_del(&cpu_dai->card_list); 998a9db7dbeSStephen Warren 99918d75644SStephen Warren if (!cpu_dai->codec) { 100018d75644SStephen Warren snd_soc_dapm_free(&cpu_dai->dapm); 1001f0fba2adSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 1002f0fba2adSLiam Girdwood } 1003f0fba2adSLiam Girdwood } 100418d75644SStephen Warren } 1005f0fba2adSLiam Girdwood 100662ae68faSStephen Warren static void soc_remove_link_components(struct snd_soc_card *card, int num, 100762ae68faSStephen Warren int order) 100862ae68faSStephen Warren { 100962ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 101062ae68faSStephen Warren struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 101162ae68faSStephen Warren struct snd_soc_dai *codec_dai = rtd->codec_dai; 101262ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 101362ae68faSStephen Warren struct snd_soc_codec *codec; 101462ae68faSStephen Warren 101562ae68faSStephen Warren /* remove the platform */ 101662ae68faSStephen Warren if (platform && platform->probed && 101762ae68faSStephen Warren platform->driver->remove_order == order) { 101862ae68faSStephen Warren soc_remove_platform(platform); 101962ae68faSStephen Warren } 102062ae68faSStephen Warren 102162ae68faSStephen Warren /* remove the CODEC-side CODEC */ 102262ae68faSStephen Warren if (codec_dai) { 102362ae68faSStephen Warren codec = codec_dai->codec; 102462ae68faSStephen Warren if (codec && codec->probed && 102562ae68faSStephen Warren codec->driver->remove_order == order) 102662ae68faSStephen Warren soc_remove_codec(codec); 102762ae68faSStephen Warren } 102862ae68faSStephen Warren 102962ae68faSStephen Warren /* remove any CPU-side CODEC */ 103062ae68faSStephen Warren if (cpu_dai) { 103162ae68faSStephen Warren codec = cpu_dai->codec; 103262ae68faSStephen Warren if (codec && codec->probed && 103362ae68faSStephen Warren codec->driver->remove_order == order) 103462ae68faSStephen Warren soc_remove_codec(codec); 103562ae68faSStephen Warren } 103662ae68faSStephen Warren } 103762ae68faSStephen Warren 10380671fd8eSKuninori Morimoto static void soc_remove_dai_links(struct snd_soc_card *card) 10390671fd8eSKuninori Morimoto { 10400168bf0dSLiam Girdwood int dai, order; 10410671fd8eSKuninori Morimoto 10420168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 10430168bf0dSLiam Girdwood order++) { 10440168bf0dSLiam Girdwood for (dai = 0; dai < card->num_rtd; dai++) 104562ae68faSStephen Warren soc_remove_link_dais(card, dai, order); 10460168bf0dSLiam Girdwood } 104762ae68faSStephen Warren 104862ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 104962ae68faSStephen Warren order++) { 105062ae68faSStephen Warren for (dai = 0; dai < card->num_rtd; dai++) 105162ae68faSStephen Warren soc_remove_link_components(card, dai, order); 105262ae68faSStephen Warren } 105362ae68faSStephen Warren 10540671fd8eSKuninori Morimoto card->num_rtd = 0; 10550671fd8eSKuninori Morimoto } 10560671fd8eSKuninori Morimoto 1057ead9b919SJarkko Nikula static void soc_set_name_prefix(struct snd_soc_card *card, 1058ead9b919SJarkko Nikula struct snd_soc_codec *codec) 1059ead9b919SJarkko Nikula { 1060ead9b919SJarkko Nikula int i; 1061ead9b919SJarkko Nikula 1062ff819b83SDimitris Papastamos if (card->codec_conf == NULL) 1063ead9b919SJarkko Nikula return; 1064ead9b919SJarkko Nikula 1065ff819b83SDimitris Papastamos for (i = 0; i < card->num_configs; i++) { 1066ff819b83SDimitris Papastamos struct snd_soc_codec_conf *map = &card->codec_conf[i]; 1067ead9b919SJarkko Nikula if (map->dev_name && !strcmp(codec->name, map->dev_name)) { 1068ead9b919SJarkko Nikula codec->name_prefix = map->name_prefix; 1069ead9b919SJarkko Nikula break; 1070ead9b919SJarkko Nikula } 1071ead9b919SJarkko Nikula } 1072ead9b919SJarkko Nikula } 1073ead9b919SJarkko Nikula 1074589c3563SJarkko Nikula static int soc_probe_codec(struct snd_soc_card *card, 1075589c3563SJarkko Nikula struct snd_soc_codec *codec) 1076589c3563SJarkko Nikula { 1077589c3563SJarkko Nikula int ret = 0; 107889b95ac0SMark Brown const struct snd_soc_codec_driver *driver = codec->driver; 1079888df395SMark Brown struct snd_soc_dai *dai; 1080589c3563SJarkko Nikula 1081589c3563SJarkko Nikula codec->card = card; 1082589c3563SJarkko Nikula codec->dapm.card = card; 1083589c3563SJarkko Nikula soc_set_name_prefix(card, codec); 1084589c3563SJarkko Nikula 108570d29331SJarkko Nikula if (!try_module_get(codec->dev->driver->owner)) 108670d29331SJarkko Nikula return -ENODEV; 108770d29331SJarkko Nikula 1088d5d1e0beSLars-Peter Clausen soc_init_codec_debugfs(codec); 1089d5d1e0beSLars-Peter Clausen 109077530150SLars-Peter Clausen if (driver->dapm_widgets) 109177530150SLars-Peter Clausen snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, 109277530150SLars-Peter Clausen driver->num_dapm_widgets); 109377530150SLars-Peter Clausen 1094888df395SMark Brown /* Create DAPM widgets for each DAI stream */ 1095888df395SMark Brown list_for_each_entry(dai, &dai_list, list) { 1096888df395SMark Brown if (dai->dev != codec->dev) 1097888df395SMark Brown continue; 1098888df395SMark Brown 1099888df395SMark Brown snd_soc_dapm_new_dai_widgets(&codec->dapm, dai); 1100888df395SMark Brown } 1101888df395SMark Brown 110233c5f969SMark Brown codec->dapm.idle_bias_off = driver->idle_bias_off; 110333c5f969SMark Brown 110489b95ac0SMark Brown if (driver->probe) { 110589b95ac0SMark Brown ret = driver->probe(codec); 1106589c3563SJarkko Nikula if (ret < 0) { 1107589c3563SJarkko Nikula dev_err(codec->dev, 1108f110bfc7SLiam Girdwood "ASoC: failed to probe CODEC %d\n", ret); 110970d29331SJarkko Nikula goto err_probe; 1110589c3563SJarkko Nikula } 1111ff541f4bSChuansheng Liu WARN(codec->dapm.idle_bias_off && 1112ff541f4bSChuansheng Liu codec->dapm.bias_level != SND_SOC_BIAS_OFF, 1113ff541f4bSChuansheng Liu "codec %s can not start from non-off bias" 1114ff541f4bSChuansheng Liu " with idle_bias_off==1\n", codec->name); 1115589c3563SJarkko Nikula } 1116589c3563SJarkko Nikula 111738cbf959SMark Brown /* If the driver didn't set I/O up try regmap */ 111898d3088eSMark Brown if (!codec->write && dev_get_regmap(codec->dev, NULL)) 111938cbf959SMark Brown snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP); 112038cbf959SMark Brown 1121b7af1dafSMark Brown if (driver->controls) 1122022658beSLiam Girdwood snd_soc_add_codec_controls(codec, driver->controls, 1123b7af1dafSMark Brown driver->num_controls); 112489b95ac0SMark Brown if (driver->dapm_routes) 112589b95ac0SMark Brown snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, 112689b95ac0SMark Brown driver->num_dapm_routes); 112789b95ac0SMark Brown 1128589c3563SJarkko Nikula /* mark codec as probed and add to card codec list */ 1129589c3563SJarkko Nikula codec->probed = 1; 1130589c3563SJarkko Nikula list_add(&codec->card_list, &card->codec_dev_list); 11317be31be8SJarkko Nikula list_add(&codec->dapm.list, &card->dapm_list); 1132589c3563SJarkko Nikula 113370d29331SJarkko Nikula return 0; 113470d29331SJarkko Nikula 113570d29331SJarkko Nikula err_probe: 1136d5d1e0beSLars-Peter Clausen soc_cleanup_codec_debugfs(codec); 113770d29331SJarkko Nikula module_put(codec->dev->driver->owner); 113870d29331SJarkko Nikula 1139589c3563SJarkko Nikula return ret; 1140589c3563SJarkko Nikula } 1141589c3563SJarkko Nikula 1142956245e9SLiam Girdwood static int soc_probe_platform(struct snd_soc_card *card, 1143956245e9SLiam Girdwood struct snd_soc_platform *platform) 1144956245e9SLiam Girdwood { 1145956245e9SLiam Girdwood int ret = 0; 1146956245e9SLiam Girdwood const struct snd_soc_platform_driver *driver = platform->driver; 1147be09ad90SLiam Girdwood struct snd_soc_dai *dai; 1148956245e9SLiam Girdwood 1149956245e9SLiam Girdwood platform->card = card; 1150b7950641SLiam Girdwood platform->dapm.card = card; 1151956245e9SLiam Girdwood 1152956245e9SLiam Girdwood if (!try_module_get(platform->dev->driver->owner)) 1153956245e9SLiam Girdwood return -ENODEV; 1154956245e9SLiam Girdwood 1155731f1ab2SSebastien Guiriec soc_init_platform_debugfs(platform); 1156731f1ab2SSebastien Guiriec 1157cb2cf612SLiam Girdwood if (driver->dapm_widgets) 1158cb2cf612SLiam Girdwood snd_soc_dapm_new_controls(&platform->dapm, 1159cb2cf612SLiam Girdwood driver->dapm_widgets, driver->num_dapm_widgets); 1160cb2cf612SLiam Girdwood 1161be09ad90SLiam Girdwood /* Create DAPM widgets for each DAI stream */ 1162be09ad90SLiam Girdwood list_for_each_entry(dai, &dai_list, list) { 1163be09ad90SLiam Girdwood if (dai->dev != platform->dev) 1164be09ad90SLiam Girdwood continue; 1165be09ad90SLiam Girdwood 1166be09ad90SLiam Girdwood snd_soc_dapm_new_dai_widgets(&platform->dapm, dai); 1167be09ad90SLiam Girdwood } 1168be09ad90SLiam Girdwood 11693fec6b6dSStephen Warren platform->dapm.idle_bias_off = 1; 11703fec6b6dSStephen Warren 1171956245e9SLiam Girdwood if (driver->probe) { 1172956245e9SLiam Girdwood ret = driver->probe(platform); 1173956245e9SLiam Girdwood if (ret < 0) { 1174956245e9SLiam Girdwood dev_err(platform->dev, 1175f110bfc7SLiam Girdwood "ASoC: failed to probe platform %d\n", ret); 1176956245e9SLiam Girdwood goto err_probe; 1177956245e9SLiam Girdwood } 1178956245e9SLiam Girdwood } 1179956245e9SLiam Girdwood 1180cb2cf612SLiam Girdwood if (driver->controls) 1181cb2cf612SLiam Girdwood snd_soc_add_platform_controls(platform, driver->controls, 1182cb2cf612SLiam Girdwood driver->num_controls); 1183cb2cf612SLiam Girdwood if (driver->dapm_routes) 1184cb2cf612SLiam Girdwood snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, 1185cb2cf612SLiam Girdwood driver->num_dapm_routes); 1186cb2cf612SLiam Girdwood 1187956245e9SLiam Girdwood /* mark platform as probed and add to card platform list */ 1188956245e9SLiam Girdwood platform->probed = 1; 1189956245e9SLiam Girdwood list_add(&platform->card_list, &card->platform_dev_list); 1190b7950641SLiam Girdwood list_add(&platform->dapm.list, &card->dapm_list); 1191956245e9SLiam Girdwood 1192956245e9SLiam Girdwood return 0; 1193956245e9SLiam Girdwood 1194956245e9SLiam Girdwood err_probe: 119502db1103SLiam Girdwood soc_cleanup_platform_debugfs(platform); 1196956245e9SLiam Girdwood module_put(platform->dev->driver->owner); 1197956245e9SLiam Girdwood 1198956245e9SLiam Girdwood return ret; 1199956245e9SLiam Girdwood } 1200956245e9SLiam Girdwood 120136ae1a96SMark Brown static void rtd_release(struct device *dev) 120236ae1a96SMark Brown { 120336ae1a96SMark Brown kfree(dev); 120436ae1a96SMark Brown } 1205f0fba2adSLiam Girdwood 1206589c3563SJarkko Nikula static int soc_post_component_init(struct snd_soc_card *card, 1207589c3563SJarkko Nikula struct snd_soc_codec *codec, 1208589c3563SJarkko Nikula int num, int dailess) 1209589c3563SJarkko Nikula { 1210589c3563SJarkko Nikula struct snd_soc_dai_link *dai_link = NULL; 1211589c3563SJarkko Nikula struct snd_soc_aux_dev *aux_dev = NULL; 1212589c3563SJarkko Nikula struct snd_soc_pcm_runtime *rtd; 1213589c3563SJarkko Nikula const char *temp, *name; 1214589c3563SJarkko Nikula int ret = 0; 1215589c3563SJarkko Nikula 1216589c3563SJarkko Nikula if (!dailess) { 1217589c3563SJarkko Nikula dai_link = &card->dai_link[num]; 1218589c3563SJarkko Nikula rtd = &card->rtd[num]; 1219589c3563SJarkko Nikula name = dai_link->name; 1220589c3563SJarkko Nikula } else { 1221589c3563SJarkko Nikula aux_dev = &card->aux_dev[num]; 1222589c3563SJarkko Nikula rtd = &card->rtd_aux[num]; 1223589c3563SJarkko Nikula name = aux_dev->name; 1224589c3563SJarkko Nikula } 12250962bb21SJanusz Krzysztofik rtd->card = card; 1226589c3563SJarkko Nikula 12274b1cfcb4SMark Brown /* Make sure all DAPM widgets are instantiated */ 12284b1cfcb4SMark Brown snd_soc_dapm_new_widgets(&codec->dapm); 12294b1cfcb4SMark Brown 1230589c3563SJarkko Nikula /* machine controls, routes and widgets are not prefixed */ 1231589c3563SJarkko Nikula temp = codec->name_prefix; 1232589c3563SJarkko Nikula codec->name_prefix = NULL; 1233589c3563SJarkko Nikula 1234589c3563SJarkko Nikula /* do machine specific initialization */ 1235589c3563SJarkko Nikula if (!dailess && dai_link->init) 1236589c3563SJarkko Nikula ret = dai_link->init(rtd); 1237589c3563SJarkko Nikula else if (dailess && aux_dev->init) 1238589c3563SJarkko Nikula ret = aux_dev->init(&codec->dapm); 1239589c3563SJarkko Nikula if (ret < 0) { 1240f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret); 1241589c3563SJarkko Nikula return ret; 1242589c3563SJarkko Nikula } 1243589c3563SJarkko Nikula codec->name_prefix = temp; 1244589c3563SJarkko Nikula 1245589c3563SJarkko Nikula /* register the rtd device */ 1246589c3563SJarkko Nikula rtd->codec = codec; 124736ae1a96SMark Brown 124836ae1a96SMark Brown rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); 124936ae1a96SMark Brown if (!rtd->dev) 125036ae1a96SMark Brown return -ENOMEM; 125136ae1a96SMark Brown device_initialize(rtd->dev); 125236ae1a96SMark Brown rtd->dev->parent = card->dev; 125336ae1a96SMark Brown rtd->dev->release = rtd_release; 125436ae1a96SMark Brown rtd->dev->init_name = name; 125536ae1a96SMark Brown dev_set_drvdata(rtd->dev, rtd); 1256b8c0dab9SLiam Girdwood mutex_init(&rtd->pcm_mutex); 125701d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); 125801d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); 125901d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); 126001d7584cSLiam Girdwood INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); 126136ae1a96SMark Brown ret = device_add(rtd->dev); 1262589c3563SJarkko Nikula if (ret < 0) { 1263865df9cbSChuansheng Liu /* calling put_device() here to free the rtd->dev */ 1264865df9cbSChuansheng Liu put_device(rtd->dev); 1265589c3563SJarkko Nikula dev_err(card->dev, 1266f110bfc7SLiam Girdwood "ASoC: failed to register runtime device: %d\n", ret); 1267589c3563SJarkko Nikula return ret; 1268589c3563SJarkko Nikula } 1269589c3563SJarkko Nikula rtd->dev_registered = 1; 1270589c3563SJarkko Nikula 1271589c3563SJarkko Nikula /* add DAPM sysfs entries for this codec */ 127236ae1a96SMark Brown ret = snd_soc_dapm_sys_add(rtd->dev); 1273589c3563SJarkko Nikula if (ret < 0) 1274589c3563SJarkko Nikula dev_err(codec->dev, 1275f110bfc7SLiam Girdwood "ASoC: failed to add codec dapm sysfs entries: %d\n", ret); 1276589c3563SJarkko Nikula 1277589c3563SJarkko Nikula /* add codec sysfs entries */ 127836ae1a96SMark Brown ret = device_create_file(rtd->dev, &dev_attr_codec_reg); 1279589c3563SJarkko Nikula if (ret < 0) 1280589c3563SJarkko Nikula dev_err(codec->dev, 1281f110bfc7SLiam Girdwood "ASoC: failed to add codec sysfs files: %d\n", ret); 1282589c3563SJarkko Nikula 1283f86dcef8SLiam Girdwood #ifdef CONFIG_DEBUG_FS 1284f86dcef8SLiam Girdwood /* add DPCM sysfs entries */ 1285cd0f8911SLiam Girdwood if (!dailess && !dai_link->dynamic) 1286f86dcef8SLiam Girdwood goto out; 1287f86dcef8SLiam Girdwood 1288f86dcef8SLiam Girdwood ret = soc_dpcm_debugfs_add(rtd); 1289f86dcef8SLiam Girdwood if (ret < 0) 1290f110bfc7SLiam Girdwood dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret); 1291f86dcef8SLiam Girdwood 1292f86dcef8SLiam Girdwood out: 1293f86dcef8SLiam Girdwood #endif 1294589c3563SJarkko Nikula return 0; 1295589c3563SJarkko Nikula } 1296589c3563SJarkko Nikula 129762ae68faSStephen Warren static int soc_probe_link_components(struct snd_soc_card *card, int num, 129862ae68faSStephen Warren int order) 129962ae68faSStephen Warren { 130062ae68faSStephen Warren struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 130162ae68faSStephen Warren struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 130262ae68faSStephen Warren struct snd_soc_dai *codec_dai = rtd->codec_dai; 130362ae68faSStephen Warren struct snd_soc_platform *platform = rtd->platform; 130462ae68faSStephen Warren int ret; 130562ae68faSStephen Warren 130662ae68faSStephen Warren /* probe the CPU-side component, if it is a CODEC */ 130762ae68faSStephen Warren if (cpu_dai->codec && 130862ae68faSStephen Warren !cpu_dai->codec->probed && 130962ae68faSStephen Warren cpu_dai->codec->driver->probe_order == order) { 131062ae68faSStephen Warren ret = soc_probe_codec(card, cpu_dai->codec); 131162ae68faSStephen Warren if (ret < 0) 131262ae68faSStephen Warren return ret; 131362ae68faSStephen Warren } 131462ae68faSStephen Warren 131562ae68faSStephen Warren /* probe the CODEC-side component */ 131662ae68faSStephen Warren if (!codec_dai->codec->probed && 131762ae68faSStephen Warren codec_dai->codec->driver->probe_order == order) { 131862ae68faSStephen Warren ret = soc_probe_codec(card, codec_dai->codec); 131962ae68faSStephen Warren if (ret < 0) 132062ae68faSStephen Warren return ret; 132162ae68faSStephen Warren } 132262ae68faSStephen Warren 132362ae68faSStephen Warren /* probe the platform */ 132462ae68faSStephen Warren if (!platform->probed && 132562ae68faSStephen Warren platform->driver->probe_order == order) { 132662ae68faSStephen Warren ret = soc_probe_platform(card, platform); 132762ae68faSStephen Warren if (ret < 0) 132862ae68faSStephen Warren return ret; 132962ae68faSStephen Warren } 133062ae68faSStephen Warren 133162ae68faSStephen Warren return 0; 133262ae68faSStephen Warren } 133362ae68faSStephen Warren 133462ae68faSStephen Warren static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) 1335f0fba2adSLiam Girdwood { 1336f0fba2adSLiam Girdwood struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 1337f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 1338f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 1339f0fba2adSLiam Girdwood struct snd_soc_platform *platform = rtd->platform; 1340c74184edSMark Brown struct snd_soc_dai *codec_dai = rtd->codec_dai; 1341c74184edSMark Brown struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1342c74184edSMark Brown struct snd_soc_dapm_widget *play_w, *capture_w; 1343f0fba2adSLiam Girdwood int ret; 1344f0fba2adSLiam Girdwood 1345f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", 13460168bf0dSLiam Girdwood card->name, num, order); 1347f0fba2adSLiam Girdwood 1348f0fba2adSLiam Girdwood /* config components */ 1349f0fba2adSLiam Girdwood cpu_dai->platform = platform; 1350f0fba2adSLiam Girdwood codec_dai->card = card; 1351f0fba2adSLiam Girdwood cpu_dai->card = card; 1352f0fba2adSLiam Girdwood 1353f0fba2adSLiam Girdwood /* set default power off timeout */ 1354f0fba2adSLiam Girdwood rtd->pmdown_time = pmdown_time; 1355f0fba2adSLiam Girdwood 1356f0fba2adSLiam Girdwood /* probe the cpu_dai */ 13570168bf0dSLiam Girdwood if (!cpu_dai->probed && 13580168bf0dSLiam Girdwood cpu_dai->driver->probe_order == order) { 1359a9db7dbeSStephen Warren if (!cpu_dai->codec) { 1360be09ad90SLiam Girdwood cpu_dai->dapm.card = card; 136161b61e3cSLiam Girdwood if (!try_module_get(cpu_dai->dev->driver->owner)) 136261b61e3cSLiam Girdwood return -ENODEV; 136361b61e3cSLiam Girdwood 136418d75644SStephen Warren list_add(&cpu_dai->dapm.list, &card->dapm_list); 1365be09ad90SLiam Girdwood snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai); 1366a9db7dbeSStephen Warren } 1367be09ad90SLiam Girdwood 1368f0fba2adSLiam Girdwood if (cpu_dai->driver->probe) { 1369f0fba2adSLiam Girdwood ret = cpu_dai->driver->probe(cpu_dai); 1370f0fba2adSLiam Girdwood if (ret < 0) { 1371f110bfc7SLiam Girdwood dev_err(cpu_dai->dev, 1372f110bfc7SLiam Girdwood "ASoC: failed to probe CPU DAI %s: %d\n", 13730837fc62SFabio Estevam cpu_dai->name, ret); 137461b61e3cSLiam Girdwood module_put(cpu_dai->dev->driver->owner); 1375f0fba2adSLiam Girdwood return ret; 1376f0fba2adSLiam Girdwood } 1377f0fba2adSLiam Girdwood } 1378f0fba2adSLiam Girdwood cpu_dai->probed = 1; 13791c8371d6SWolfram Sang /* mark cpu_dai as probed and add to card dai list */ 1380f0fba2adSLiam Girdwood list_add(&cpu_dai->card_list, &card->dai_dev_list); 1381f0fba2adSLiam Girdwood } 1382f0fba2adSLiam Girdwood 1383f0fba2adSLiam Girdwood /* probe the CODEC DAI */ 13840168bf0dSLiam Girdwood if (!codec_dai->probed && codec_dai->driver->probe_order == order) { 1385f0fba2adSLiam Girdwood if (codec_dai->driver->probe) { 1386f0fba2adSLiam Girdwood ret = codec_dai->driver->probe(codec_dai); 1387f0fba2adSLiam Girdwood if (ret < 0) { 1388f110bfc7SLiam Girdwood dev_err(codec_dai->dev, 1389f110bfc7SLiam Girdwood "ASoC: failed to probe CODEC DAI %s: %d\n", 13900837fc62SFabio Estevam codec_dai->name, ret); 1391f0fba2adSLiam Girdwood return ret; 1392f0fba2adSLiam Girdwood } 1393f0fba2adSLiam Girdwood } 1394f0fba2adSLiam Girdwood 13951c8371d6SWolfram Sang /* mark codec_dai as probed and add to card dai list */ 1396f0fba2adSLiam Girdwood codec_dai->probed = 1; 1397f0fba2adSLiam Girdwood list_add(&codec_dai->card_list, &card->dai_dev_list); 1398f0fba2adSLiam Girdwood } 1399f0fba2adSLiam Girdwood 14000168bf0dSLiam Girdwood /* complete DAI probe during last probe */ 14010168bf0dSLiam Girdwood if (order != SND_SOC_COMP_ORDER_LAST) 14020168bf0dSLiam Girdwood return 0; 14030168bf0dSLiam Girdwood 1404589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 0); 1405589c3563SJarkko Nikula if (ret) 1406f0fba2adSLiam Girdwood return ret; 1407f0fba2adSLiam Girdwood 140836ae1a96SMark Brown ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); 1409f0fba2adSLiam Girdwood if (ret < 0) 1410f110bfc7SLiam Girdwood dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", 1411f110bfc7SLiam Girdwood ret); 1412f0fba2adSLiam Girdwood 14131245b700SNamarta Kohli if (cpu_dai->driver->compress_dai) { 14141245b700SNamarta Kohli /*create compress_device"*/ 14151245b700SNamarta Kohli ret = soc_new_compress(rtd, num); 14161245b700SNamarta Kohli if (ret < 0) { 1417f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create compress %s\n", 14181245b700SNamarta Kohli dai_link->stream_name); 14191245b700SNamarta Kohli return ret; 14201245b700SNamarta Kohli } 14211245b700SNamarta Kohli } else { 14221245b700SNamarta Kohli 1423c74184edSMark Brown if (!dai_link->params) { 1424f0fba2adSLiam Girdwood /* create the pcm */ 1425f0fba2adSLiam Girdwood ret = soc_new_pcm(rtd, num); 1426f0fba2adSLiam Girdwood if (ret < 0) { 1427f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", 14280837fc62SFabio Estevam dai_link->stream_name, ret); 1429f0fba2adSLiam Girdwood return ret; 1430f0fba2adSLiam Girdwood } 1431c74184edSMark Brown } else { 1432c74184edSMark Brown /* link the DAI widgets */ 1433c74184edSMark Brown play_w = codec_dai->playback_widget; 1434c74184edSMark Brown capture_w = cpu_dai->capture_widget; 1435c74184edSMark Brown if (play_w && capture_w) { 1436c74184edSMark Brown ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1437c74184edSMark Brown capture_w, play_w); 1438c74184edSMark Brown if (ret != 0) { 1439f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 1440c74184edSMark Brown play_w->name, capture_w->name, ret); 1441c74184edSMark Brown return ret; 1442c74184edSMark Brown } 1443c74184edSMark Brown } 1444c74184edSMark Brown 1445c74184edSMark Brown play_w = cpu_dai->playback_widget; 1446c74184edSMark Brown capture_w = codec_dai->capture_widget; 1447c74184edSMark Brown if (play_w && capture_w) { 1448c74184edSMark Brown ret = snd_soc_dapm_new_pcm(card, dai_link->params, 1449c74184edSMark Brown capture_w, play_w); 1450c74184edSMark Brown if (ret != 0) { 1451f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", 1452c74184edSMark Brown play_w->name, capture_w->name, ret); 1453c74184edSMark Brown return ret; 1454c74184edSMark Brown } 1455c74184edSMark Brown } 1456c74184edSMark Brown } 14571245b700SNamarta Kohli } 1458f0fba2adSLiam Girdwood 1459f0fba2adSLiam Girdwood /* add platform data for AC97 devices */ 1460f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control) 1461f0fba2adSLiam Girdwood snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); 1462f0fba2adSLiam Girdwood 1463f0fba2adSLiam Girdwood return 0; 1464f0fba2adSLiam Girdwood } 1465f0fba2adSLiam Girdwood 1466f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 1467f0fba2adSLiam Girdwood static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) 1468f0fba2adSLiam Girdwood { 1469f0fba2adSLiam Girdwood int ret; 1470f0fba2adSLiam Girdwood 1471f0fba2adSLiam Girdwood /* Only instantiate AC97 if not already done by the adaptor 1472f0fba2adSLiam Girdwood * for the generic AC97 subsystem. 14736b05eda6SMark Brown */ 1474f0fba2adSLiam Girdwood if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { 14750562f788SMika Westerberg /* 14760562f788SMika Westerberg * It is possible that the AC97 device is already registered to 14770562f788SMika Westerberg * the device subsystem. This happens when the device is created 14780562f788SMika Westerberg * via snd_ac97_mixer(). Currently only SoC codec that does so 14790562f788SMika Westerberg * is the generic AC97 glue but others migh emerge. 14800562f788SMika Westerberg * 14810562f788SMika Westerberg * In those cases we don't try to register the device again. 14820562f788SMika Westerberg */ 14830562f788SMika Westerberg if (!rtd->codec->ac97_created) 14840562f788SMika Westerberg return 0; 1485f0fba2adSLiam Girdwood 1486f0fba2adSLiam Girdwood ret = soc_ac97_dev_register(rtd->codec); 1487f0fba2adSLiam Girdwood if (ret < 0) { 1488f110bfc7SLiam Girdwood dev_err(rtd->codec->dev, 1489f110bfc7SLiam Girdwood "ASoC: AC97 device register failed: %d\n", ret); 1490f0fba2adSLiam Girdwood return ret; 1491435c5e25SMark Brown } 1492435c5e25SMark Brown 1493f0fba2adSLiam Girdwood rtd->codec->ac97_registered = 1; 1494f0fba2adSLiam Girdwood } 1495f0fba2adSLiam Girdwood return 0; 1496f0fba2adSLiam Girdwood } 1497435c5e25SMark Brown 1498f0fba2adSLiam Girdwood static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) 1499f0fba2adSLiam Girdwood { 1500f0fba2adSLiam Girdwood if (codec->ac97_registered) { 1501f0fba2adSLiam Girdwood soc_ac97_dev_unregister(codec); 1502f0fba2adSLiam Girdwood codec->ac97_registered = 0; 1503f0fba2adSLiam Girdwood } 1504f0fba2adSLiam Girdwood } 1505f0fba2adSLiam Girdwood #endif 1506435c5e25SMark Brown 1507b19e6e7bSMark Brown static int soc_check_aux_dev(struct snd_soc_card *card, int num) 1508b19e6e7bSMark Brown { 1509b19e6e7bSMark Brown struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 1510b19e6e7bSMark Brown struct snd_soc_codec *codec; 1511b19e6e7bSMark Brown 1512b19e6e7bSMark Brown /* find CODEC from registered CODECs*/ 1513b19e6e7bSMark Brown list_for_each_entry(codec, &codec_list, list) { 1514b19e6e7bSMark Brown if (!strcmp(codec->name, aux_dev->codec_name)) 1515b19e6e7bSMark Brown return 0; 1516b19e6e7bSMark Brown } 1517b19e6e7bSMark Brown 1518f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name); 1519fb099cb7SMark Brown 1520b19e6e7bSMark Brown return -EPROBE_DEFER; 1521b19e6e7bSMark Brown } 1522b19e6e7bSMark Brown 15232eea392dSJarkko Nikula static int soc_probe_aux_dev(struct snd_soc_card *card, int num) 15242eea392dSJarkko Nikula { 15252eea392dSJarkko Nikula struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; 15262eea392dSJarkko Nikula struct snd_soc_codec *codec; 1527676ad98aSJarkko Nikula int ret = -ENODEV; 15282eea392dSJarkko Nikula 15292eea392dSJarkko Nikula /* find CODEC from registered CODECs*/ 15302eea392dSJarkko Nikula list_for_each_entry(codec, &codec_list, list) { 15312eea392dSJarkko Nikula if (!strcmp(codec->name, aux_dev->codec_name)) { 15322eea392dSJarkko Nikula if (codec->probed) { 15332eea392dSJarkko Nikula dev_err(codec->dev, 1534f110bfc7SLiam Girdwood "ASoC: codec already probed"); 15352eea392dSJarkko Nikula ret = -EBUSY; 15362eea392dSJarkko Nikula goto out; 15372eea392dSJarkko Nikula } 1538676ad98aSJarkko Nikula goto found; 15392eea392dSJarkko Nikula } 15402eea392dSJarkko Nikula } 1541676ad98aSJarkko Nikula /* codec not found */ 1542f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name); 1543b19e6e7bSMark Brown return -EPROBE_DEFER; 15442eea392dSJarkko Nikula 1545676ad98aSJarkko Nikula found: 1546589c3563SJarkko Nikula ret = soc_probe_codec(card, codec); 15472eea392dSJarkko Nikula if (ret < 0) 1548589c3563SJarkko Nikula return ret; 15492eea392dSJarkko Nikula 1550589c3563SJarkko Nikula ret = soc_post_component_init(card, codec, num, 1); 15512eea392dSJarkko Nikula 15522eea392dSJarkko Nikula out: 15532eea392dSJarkko Nikula return ret; 15542eea392dSJarkko Nikula } 15552eea392dSJarkko Nikula 15562eea392dSJarkko Nikula static void soc_remove_aux_dev(struct snd_soc_card *card, int num) 15572eea392dSJarkko Nikula { 15582eea392dSJarkko Nikula struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; 15592eea392dSJarkko Nikula struct snd_soc_codec *codec = rtd->codec; 15602eea392dSJarkko Nikula 15612eea392dSJarkko Nikula /* unregister the rtd device */ 15622eea392dSJarkko Nikula if (rtd->dev_registered) { 156336ae1a96SMark Brown device_remove_file(rtd->dev, &dev_attr_codec_reg); 1564d3bf1561SChuansheng Liu device_unregister(rtd->dev); 15652eea392dSJarkko Nikula rtd->dev_registered = 0; 15662eea392dSJarkko Nikula } 15672eea392dSJarkko Nikula 1568589c3563SJarkko Nikula if (codec && codec->probed) 1569589c3563SJarkko Nikula soc_remove_codec(codec); 15702eea392dSJarkko Nikula } 15712eea392dSJarkko Nikula 1572fdf0f54dSDimitris Papastamos static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, 1573fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type) 1574fdf0f54dSDimitris Papastamos { 1575fdf0f54dSDimitris Papastamos int ret; 1576fdf0f54dSDimitris Papastamos 1577fdf0f54dSDimitris Papastamos if (codec->cache_init) 1578fdf0f54dSDimitris Papastamos return 0; 1579fdf0f54dSDimitris Papastamos 1580fdf0f54dSDimitris Papastamos /* override the compress_type if necessary */ 1581fdf0f54dSDimitris Papastamos if (compress_type && codec->compress_type != compress_type) 1582fdf0f54dSDimitris Papastamos codec->compress_type = compress_type; 1583fdf0f54dSDimitris Papastamos ret = snd_soc_cache_init(codec); 1584fdf0f54dSDimitris Papastamos if (ret < 0) { 1585f110bfc7SLiam Girdwood dev_err(codec->dev, "ASoC: Failed to set cache compression" 1586f110bfc7SLiam Girdwood " type: %d\n", ret); 1587fdf0f54dSDimitris Papastamos return ret; 1588fdf0f54dSDimitris Papastamos } 1589fdf0f54dSDimitris Papastamos codec->cache_init = 1; 1590fdf0f54dSDimitris Papastamos return 0; 1591fdf0f54dSDimitris Papastamos } 1592fdf0f54dSDimitris Papastamos 1593b19e6e7bSMark Brown static int snd_soc_instantiate_card(struct snd_soc_card *card) 1594f0fba2adSLiam Girdwood { 1595fdf0f54dSDimitris Papastamos struct snd_soc_codec *codec; 1596fdf0f54dSDimitris Papastamos struct snd_soc_codec_conf *codec_conf; 1597fdf0f54dSDimitris Papastamos enum snd_soc_compress_type compress_type; 159875d9ac46SMark Brown struct snd_soc_dai_link *dai_link; 1599f04209a7SMark Brown int ret, i, order, dai_fmt; 160096dd3622SMark Brown 160101b9d99aSLiam Girdwood mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); 1602f0fba2adSLiam Girdwood 1603b19e6e7bSMark Brown /* bind DAIs */ 1604b19e6e7bSMark Brown for (i = 0; i < card->num_links; i++) { 1605b19e6e7bSMark Brown ret = soc_bind_dai_link(card, i); 1606b19e6e7bSMark Brown if (ret != 0) 1607b19e6e7bSMark Brown goto base_error; 1608db2a4165SFrank Mandarino } 1609db2a4165SFrank Mandarino 1610b19e6e7bSMark Brown /* check aux_devs too */ 1611b19e6e7bSMark Brown for (i = 0; i < card->num_aux_devs; i++) { 1612b19e6e7bSMark Brown ret = soc_check_aux_dev(card, i); 1613b19e6e7bSMark Brown if (ret != 0) 1614b19e6e7bSMark Brown goto base_error; 1615db2a4165SFrank Mandarino } 1616db2a4165SFrank Mandarino 1617fdf0f54dSDimitris Papastamos /* initialize the register cache for each available codec */ 1618fdf0f54dSDimitris Papastamos list_for_each_entry(codec, &codec_list, list) { 1619fdf0f54dSDimitris Papastamos if (codec->cache_init) 1620fdf0f54dSDimitris Papastamos continue; 1621861f2fafSDimitris Papastamos /* by default we don't override the compress_type */ 1622861f2fafSDimitris Papastamos compress_type = 0; 1623fdf0f54dSDimitris Papastamos /* check to see if we need to override the compress_type */ 1624fdf0f54dSDimitris Papastamos for (i = 0; i < card->num_configs; ++i) { 1625fdf0f54dSDimitris Papastamos codec_conf = &card->codec_conf[i]; 1626fdf0f54dSDimitris Papastamos if (!strcmp(codec->name, codec_conf->dev_name)) { 1627fdf0f54dSDimitris Papastamos compress_type = codec_conf->compress_type; 1628fdf0f54dSDimitris Papastamos if (compress_type && compress_type 1629fdf0f54dSDimitris Papastamos != codec->compress_type) 1630fdf0f54dSDimitris Papastamos break; 1631fdf0f54dSDimitris Papastamos } 1632fdf0f54dSDimitris Papastamos } 1633fdf0f54dSDimitris Papastamos ret = snd_soc_init_codec_cache(codec, compress_type); 1634b19e6e7bSMark Brown if (ret < 0) 1635b19e6e7bSMark Brown goto base_error; 1636fdf0f54dSDimitris Papastamos } 1637fdf0f54dSDimitris Papastamos 1638f0fba2adSLiam Girdwood /* card bind complete so register a sound card */ 1639f0fba2adSLiam Girdwood ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1640f0fba2adSLiam Girdwood card->owner, 0, &card->snd_card); 1641f0fba2adSLiam Girdwood if (ret < 0) { 1642f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: can't create sound card for" 1643f110bfc7SLiam Girdwood " card %s: %d\n", card->name, ret); 1644b19e6e7bSMark Brown goto base_error; 1645db2a4165SFrank Mandarino } 1646f0fba2adSLiam Girdwood card->snd_card->dev = card->dev; 1647db2a4165SFrank Mandarino 1648e37a4970SMark Brown card->dapm.bias_level = SND_SOC_BIAS_OFF; 1649e37a4970SMark Brown card->dapm.dev = card->dev; 1650e37a4970SMark Brown card->dapm.card = card; 1651e37a4970SMark Brown list_add(&card->dapm.list, &card->dapm_list); 1652e37a4970SMark Brown 1653d5d1e0beSLars-Peter Clausen #ifdef CONFIG_DEBUG_FS 1654d5d1e0beSLars-Peter Clausen snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); 1655d5d1e0beSLars-Peter Clausen #endif 1656d5d1e0beSLars-Peter Clausen 165788ee1c61SMark Brown #ifdef CONFIG_PM_SLEEP 16586ed25978SAndy Green /* deferred resume work */ 16596308419aSMark Brown INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 16601301a964SRandy Dunlap #endif 16616ed25978SAndy Green 16629a841ebbSMark Brown if (card->dapm_widgets) 16639a841ebbSMark Brown snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, 16649a841ebbSMark Brown card->num_dapm_widgets); 16659a841ebbSMark Brown 1666f0fba2adSLiam Girdwood /* initialise the sound card only once */ 1667f0fba2adSLiam Girdwood if (card->probe) { 1668e7361ec4SMark Brown ret = card->probe(card); 1669f0fba2adSLiam Girdwood if (ret < 0) 1670f0fba2adSLiam Girdwood goto card_probe_error; 1671f0fba2adSLiam Girdwood } 1672f0fba2adSLiam Girdwood 167362ae68faSStephen Warren /* probe all components used by DAI links on this card */ 16740168bf0dSLiam Girdwood for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 16750168bf0dSLiam Girdwood order++) { 1676fe3e78e0SMark Brown for (i = 0; i < card->num_links; i++) { 167762ae68faSStephen Warren ret = soc_probe_link_components(card, i, order); 167862ae68faSStephen Warren if (ret < 0) { 1679f110bfc7SLiam Girdwood dev_err(card->dev, 1680f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1681f110bfc7SLiam Girdwood ret); 168262ae68faSStephen Warren goto probe_dai_err; 168362ae68faSStephen Warren } 168462ae68faSStephen Warren } 168562ae68faSStephen Warren } 168662ae68faSStephen Warren 168762ae68faSStephen Warren /* probe all DAI links on this card */ 168862ae68faSStephen Warren for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; 168962ae68faSStephen Warren order++) { 169062ae68faSStephen Warren for (i = 0; i < card->num_links; i++) { 169162ae68faSStephen Warren ret = soc_probe_link_dais(card, i, order); 1692fe3e78e0SMark Brown if (ret < 0) { 1693f110bfc7SLiam Girdwood dev_err(card->dev, 1694f110bfc7SLiam Girdwood "ASoC: failed to instantiate card %d\n", 1695f110bfc7SLiam Girdwood ret); 1696f0fba2adSLiam Girdwood goto probe_dai_err; 1697fe3e78e0SMark Brown } 1698fe3e78e0SMark Brown } 16990168bf0dSLiam Girdwood } 1700fe3e78e0SMark Brown 17012eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) { 17022eea392dSJarkko Nikula ret = soc_probe_aux_dev(card, i); 17032eea392dSJarkko Nikula if (ret < 0) { 1704f110bfc7SLiam Girdwood dev_err(card->dev, 1705f110bfc7SLiam Girdwood "ASoC: failed to add auxiliary devices %d\n", 1706f110bfc7SLiam Girdwood ret); 17072eea392dSJarkko Nikula goto probe_aux_dev_err; 17082eea392dSJarkko Nikula } 17092eea392dSJarkko Nikula } 17102eea392dSJarkko Nikula 1711888df395SMark Brown snd_soc_dapm_link_dai_widgets(card); 1712888df395SMark Brown 1713b7af1dafSMark Brown if (card->controls) 1714022658beSLiam Girdwood snd_soc_add_card_controls(card, card->controls, card->num_controls); 1715b7af1dafSMark Brown 1716b8ad29deSMark Brown if (card->dapm_routes) 1717b8ad29deSMark Brown snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, 1718b8ad29deSMark Brown card->num_dapm_routes); 1719b8ad29deSMark Brown 1720b90d2f90SMark Brown snd_soc_dapm_new_widgets(&card->dapm); 1721b90d2f90SMark Brown 172275d9ac46SMark Brown for (i = 0; i < card->num_links; i++) { 172375d9ac46SMark Brown dai_link = &card->dai_link[i]; 1724f04209a7SMark Brown dai_fmt = dai_link->dai_fmt; 172575d9ac46SMark Brown 1726f04209a7SMark Brown if (dai_fmt) { 172775d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, 1728f04209a7SMark Brown dai_fmt); 17295e4ba569SShawn Guo if (ret != 0 && ret != -ENOTSUPP) 173075d9ac46SMark Brown dev_warn(card->rtd[i].codec_dai->dev, 1731f110bfc7SLiam Girdwood "ASoC: Failed to set DAI format: %d\n", 173275d9ac46SMark Brown ret); 1733f04209a7SMark Brown } 1734f04209a7SMark Brown 1735f04209a7SMark Brown /* If this is a regular CPU link there will be a platform */ 1736fe33d4c5SStephen Warren if (dai_fmt && 1737fe33d4c5SStephen Warren (dai_link->platform_name || dai_link->platform_of_node)) { 1738f04209a7SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, 1739f04209a7SMark Brown dai_fmt); 1740f04209a7SMark Brown if (ret != 0 && ret != -ENOTSUPP) 1741f04209a7SMark Brown dev_warn(card->rtd[i].cpu_dai->dev, 1742f110bfc7SLiam Girdwood "ASoC: Failed to set DAI format: %d\n", 1743f04209a7SMark Brown ret); 1744f04209a7SMark Brown } else if (dai_fmt) { 1745f04209a7SMark Brown /* Flip the polarity for the "CPU" end */ 1746f04209a7SMark Brown dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK; 1747f04209a7SMark Brown switch (dai_link->dai_fmt & 1748f04209a7SMark Brown SND_SOC_DAIFMT_MASTER_MASK) { 1749f04209a7SMark Brown case SND_SOC_DAIFMT_CBM_CFM: 1750f04209a7SMark Brown dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; 1751f04209a7SMark Brown break; 1752f04209a7SMark Brown case SND_SOC_DAIFMT_CBM_CFS: 1753f04209a7SMark Brown dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; 1754f04209a7SMark Brown break; 1755f04209a7SMark Brown case SND_SOC_DAIFMT_CBS_CFM: 1756f04209a7SMark Brown dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; 1757f04209a7SMark Brown break; 1758f04209a7SMark Brown case SND_SOC_DAIFMT_CBS_CFS: 1759f04209a7SMark Brown dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 1760f04209a7SMark Brown break; 1761f04209a7SMark Brown } 176275d9ac46SMark Brown 176375d9ac46SMark Brown ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, 1764f04209a7SMark Brown dai_fmt); 17655e4ba569SShawn Guo if (ret != 0 && ret != -ENOTSUPP) 176675d9ac46SMark Brown dev_warn(card->rtd[i].cpu_dai->dev, 1767f110bfc7SLiam Girdwood "ASoC: Failed to set DAI format: %d\n", 176875d9ac46SMark Brown ret); 176975d9ac46SMark Brown } 177075d9ac46SMark Brown } 177175d9ac46SMark Brown 1772f0fba2adSLiam Girdwood snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1773fe3e78e0SMark Brown "%s", card->name); 1774f0fba2adSLiam Girdwood snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), 177522de71baSLiam Girdwood "%s", card->long_name ? card->long_name : card->name); 1776f0e8ed85SMark Brown snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), 1777f0e8ed85SMark Brown "%s", card->driver_name ? card->driver_name : card->name); 1778f0e8ed85SMark Brown for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { 1779f0e8ed85SMark Brown switch (card->snd_card->driver[i]) { 1780f0e8ed85SMark Brown case '_': 1781f0e8ed85SMark Brown case '-': 1782f0e8ed85SMark Brown case '\0': 1783f0e8ed85SMark Brown break; 1784f0e8ed85SMark Brown default: 1785f0e8ed85SMark Brown if (!isalnum(card->snd_card->driver[i])) 1786f0e8ed85SMark Brown card->snd_card->driver[i] = '_'; 1787f0e8ed85SMark Brown break; 1788f0e8ed85SMark Brown } 1789f0e8ed85SMark Brown } 1790fe3e78e0SMark Brown 179128e9ad92SMark Brown if (card->late_probe) { 179228e9ad92SMark Brown ret = card->late_probe(card); 179328e9ad92SMark Brown if (ret < 0) { 1794f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", 179528e9ad92SMark Brown card->name, ret); 179628e9ad92SMark Brown goto probe_aux_dev_err; 179728e9ad92SMark Brown } 179828e9ad92SMark Brown } 179928e9ad92SMark Brown 18002dc00213SMark Brown snd_soc_dapm_new_widgets(&card->dapm); 18012dc00213SMark Brown 18021633281bSStephen Warren if (card->fully_routed) 1803b05d8dc1SMark Brown list_for_each_entry(codec, &card->codec_dev_list, card_list) 18041633281bSStephen Warren snd_soc_dapm_auto_nc_codec_pins(codec); 18051633281bSStephen Warren 1806f0fba2adSLiam Girdwood ret = snd_card_register(card->snd_card); 1807fe3e78e0SMark Brown if (ret < 0) { 1808f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: failed to register soundcard %d\n", 1809f110bfc7SLiam Girdwood ret); 18106b3ed785SAxel Lin goto probe_aux_dev_err; 1811fe3e78e0SMark Brown } 1812fe3e78e0SMark Brown 1813fe3e78e0SMark Brown #ifdef CONFIG_SND_SOC_AC97_BUS 1814f0fba2adSLiam Girdwood /* register any AC97 codecs */ 1815f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1816f0fba2adSLiam Girdwood ret = soc_register_ac97_dai_link(&card->rtd[i]); 1817fe3e78e0SMark Brown if (ret < 0) { 1818f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: failed to register AC97:" 1819f110bfc7SLiam Girdwood " %d\n", ret); 18206b3ed785SAxel Lin while (--i >= 0) 18217d8316dfSMark Brown soc_unregister_ac97_dai_link(card->rtd[i].codec); 18226b3ed785SAxel Lin goto probe_aux_dev_err; 1823fe3e78e0SMark Brown } 1824fe3e78e0SMark Brown } 1825fe3e78e0SMark Brown #endif 1826fe3e78e0SMark Brown 1827435c5e25SMark Brown card->instantiated = 1; 18284f4c0072SMark Brown snd_soc_dapm_sync(&card->dapm); 1829f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1830b19e6e7bSMark Brown 1831b19e6e7bSMark Brown return 0; 1832db2a4165SFrank Mandarino 18332eea392dSJarkko Nikula probe_aux_dev_err: 18342eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 18352eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 18362eea392dSJarkko Nikula 1837f0fba2adSLiam Girdwood probe_dai_err: 18380671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1839fe3e78e0SMark Brown 1840f0fba2adSLiam Girdwood card_probe_error: 184187506549SMark Brown if (card->remove) 1842e7361ec4SMark Brown card->remove(card); 1843f0fba2adSLiam Girdwood 1844f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1845f0fba2adSLiam Girdwood 1846b19e6e7bSMark Brown base_error: 1847f0fba2adSLiam Girdwood mutex_unlock(&card->mutex); 1848db2a4165SFrank Mandarino 1849b19e6e7bSMark Brown return ret; 1850435c5e25SMark Brown } 1851435c5e25SMark Brown 1852435c5e25SMark Brown /* probes a new socdev */ 1853435c5e25SMark Brown static int soc_probe(struct platform_device *pdev) 1854435c5e25SMark Brown { 1855f0fba2adSLiam Girdwood struct snd_soc_card *card = platform_get_drvdata(pdev); 1856435c5e25SMark Brown 185770a7ca34SVinod Koul /* 185870a7ca34SVinod Koul * no card, so machine driver should be registering card 185970a7ca34SVinod Koul * we should not be here in that case so ret error 186070a7ca34SVinod Koul */ 186170a7ca34SVinod Koul if (!card) 186270a7ca34SVinod Koul return -EINVAL; 186370a7ca34SVinod Koul 1864fe4085e8SMark Brown dev_warn(&pdev->dev, 1865f110bfc7SLiam Girdwood "ASoC: machine %s should use snd_soc_register_card()\n", 1866fe4085e8SMark Brown card->name); 1867fe4085e8SMark Brown 1868435c5e25SMark Brown /* Bodge while we unpick instantiation */ 1869435c5e25SMark Brown card->dev = &pdev->dev; 1870f0fba2adSLiam Girdwood 187128d528c8SMark Brown return snd_soc_register_card(card); 1872435c5e25SMark Brown } 1873435c5e25SMark Brown 1874b0e26485SVinod Koul static int soc_cleanup_card_resources(struct snd_soc_card *card) 1875db2a4165SFrank Mandarino { 1876db2a4165SFrank Mandarino int i; 1877db2a4165SFrank Mandarino 1878f0fba2adSLiam Girdwood /* make sure any delayed work runs */ 1879f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1880f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 188143829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1882db2a4165SFrank Mandarino } 1883db2a4165SFrank Mandarino 18842eea392dSJarkko Nikula /* remove auxiliary devices */ 18852eea392dSJarkko Nikula for (i = 0; i < card->num_aux_devs; i++) 18862eea392dSJarkko Nikula soc_remove_aux_dev(card, i); 18872eea392dSJarkko Nikula 1888f0fba2adSLiam Girdwood /* remove and free each DAI */ 18890671fd8eSKuninori Morimoto soc_remove_dai_links(card); 1890f0fba2adSLiam Girdwood 1891a6052154SJarkko Nikula soc_cleanup_card_debugfs(card); 1892a6052154SJarkko Nikula 1893f0fba2adSLiam Girdwood /* remove the card */ 189487506549SMark Brown if (card->remove) 1895e7361ec4SMark Brown card->remove(card); 1896f0fba2adSLiam Girdwood 18970aaae527SLars-Peter Clausen snd_soc_dapm_free(&card->dapm); 18980aaae527SLars-Peter Clausen 1899f0fba2adSLiam Girdwood snd_card_free(card->snd_card); 1900b0e26485SVinod Koul return 0; 1901b0e26485SVinod Koul 1902b2dfa62cSGuennadi Liakhovetski } 1903b0e26485SVinod Koul 1904b0e26485SVinod Koul /* removes a socdev */ 1905b0e26485SVinod Koul static int soc_remove(struct platform_device *pdev) 1906b0e26485SVinod Koul { 1907b0e26485SVinod Koul struct snd_soc_card *card = platform_get_drvdata(pdev); 1908b0e26485SVinod Koul 1909c5af3a2eSMark Brown snd_soc_unregister_card(card); 1910db2a4165SFrank Mandarino return 0; 1911db2a4165SFrank Mandarino } 1912db2a4165SFrank Mandarino 19136f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev) 191451737470SMark Brown { 19156f8ab4acSMark Brown struct snd_soc_card *card = dev_get_drvdata(dev); 1916f0fba2adSLiam Girdwood int i; 191751737470SMark Brown 191851737470SMark Brown if (!card->instantiated) 1919416356fcSMark Brown return 0; 192051737470SMark Brown 192151737470SMark Brown /* Flush out pmdown_time work - we actually do want to run it 192251737470SMark Brown * now, we're shutting down so no imminent restart. */ 1923f0fba2adSLiam Girdwood for (i = 0; i < card->num_rtd; i++) { 1924f0fba2adSLiam Girdwood struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 192543829731STejun Heo flush_delayed_work(&rtd->delayed_work); 1926f0fba2adSLiam Girdwood } 192751737470SMark Brown 1928f0fba2adSLiam Girdwood snd_soc_dapm_shutdown(card); 1929416356fcSMark Brown 1930416356fcSMark Brown return 0; 193151737470SMark Brown } 19326f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff); 193351737470SMark Brown 19346f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = { 1935b1dd5897SViresh Kumar .suspend = snd_soc_suspend, 1936b1dd5897SViresh Kumar .resume = snd_soc_resume, 1937b1dd5897SViresh Kumar .freeze = snd_soc_suspend, 1938b1dd5897SViresh Kumar .thaw = snd_soc_resume, 19396f8ab4acSMark Brown .poweroff = snd_soc_poweroff, 1940b1dd5897SViresh Kumar .restore = snd_soc_resume, 1941416356fcSMark Brown }; 1942deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops); 1943416356fcSMark Brown 1944db2a4165SFrank Mandarino /* ASoC platform driver */ 1945db2a4165SFrank Mandarino static struct platform_driver soc_driver = { 1946db2a4165SFrank Mandarino .driver = { 1947db2a4165SFrank Mandarino .name = "soc-audio", 19488b45a209SKay Sievers .owner = THIS_MODULE, 19496f8ab4acSMark Brown .pm = &snd_soc_pm_ops, 1950db2a4165SFrank Mandarino }, 1951db2a4165SFrank Mandarino .probe = soc_probe, 1952db2a4165SFrank Mandarino .remove = soc_remove, 1953db2a4165SFrank Mandarino }; 1954db2a4165SFrank Mandarino 1955096e49d5SMark Brown /** 1956096e49d5SMark Brown * snd_soc_codec_volatile_register: Report if a register is volatile. 1957096e49d5SMark Brown * 1958096e49d5SMark Brown * @codec: CODEC to query. 1959096e49d5SMark Brown * @reg: Register to query. 1960096e49d5SMark Brown * 1961096e49d5SMark Brown * Boolean function indiciating if a CODEC register is volatile. 1962096e49d5SMark Brown */ 1963181e055eSMark Brown int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, 1964181e055eSMark Brown unsigned int reg) 1965096e49d5SMark Brown { 19661500b7b5SDimitris Papastamos if (codec->volatile_register) 19671500b7b5SDimitris Papastamos return codec->volatile_register(codec, reg); 1968096e49d5SMark Brown else 1969096e49d5SMark Brown return 0; 1970096e49d5SMark Brown } 1971096e49d5SMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); 1972096e49d5SMark Brown 1973db2a4165SFrank Mandarino /** 1974239c9706SDimitris Papastamos * snd_soc_codec_readable_register: Report if a register is readable. 1975239c9706SDimitris Papastamos * 1976239c9706SDimitris Papastamos * @codec: CODEC to query. 1977239c9706SDimitris Papastamos * @reg: Register to query. 1978239c9706SDimitris Papastamos * 1979239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is readable. 1980239c9706SDimitris Papastamos */ 1981239c9706SDimitris Papastamos int snd_soc_codec_readable_register(struct snd_soc_codec *codec, 1982239c9706SDimitris Papastamos unsigned int reg) 1983239c9706SDimitris Papastamos { 1984239c9706SDimitris Papastamos if (codec->readable_register) 1985239c9706SDimitris Papastamos return codec->readable_register(codec, reg); 1986239c9706SDimitris Papastamos else 198763fa0a28SLars-Peter Clausen return 1; 1988239c9706SDimitris Papastamos } 1989239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); 1990239c9706SDimitris Papastamos 1991239c9706SDimitris Papastamos /** 1992239c9706SDimitris Papastamos * snd_soc_codec_writable_register: Report if a register is writable. 1993239c9706SDimitris Papastamos * 1994239c9706SDimitris Papastamos * @codec: CODEC to query. 1995239c9706SDimitris Papastamos * @reg: Register to query. 1996239c9706SDimitris Papastamos * 1997239c9706SDimitris Papastamos * Boolean function indicating if a CODEC register is writable. 1998239c9706SDimitris Papastamos */ 1999239c9706SDimitris Papastamos int snd_soc_codec_writable_register(struct snd_soc_codec *codec, 2000239c9706SDimitris Papastamos unsigned int reg) 2001239c9706SDimitris Papastamos { 2002239c9706SDimitris Papastamos if (codec->writable_register) 2003239c9706SDimitris Papastamos return codec->writable_register(codec, reg); 2004239c9706SDimitris Papastamos else 200563fa0a28SLars-Peter Clausen return 1; 2006239c9706SDimitris Papastamos } 2007239c9706SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); 2008239c9706SDimitris Papastamos 2009f1442bc1SLiam Girdwood int snd_soc_platform_read(struct snd_soc_platform *platform, 2010f1442bc1SLiam Girdwood unsigned int reg) 2011f1442bc1SLiam Girdwood { 2012f1442bc1SLiam Girdwood unsigned int ret; 2013f1442bc1SLiam Girdwood 2014f1442bc1SLiam Girdwood if (!platform->driver->read) { 2015f110bfc7SLiam Girdwood dev_err(platform->dev, "ASoC: platform has no read back\n"); 2016f1442bc1SLiam Girdwood return -1; 2017f1442bc1SLiam Girdwood } 2018f1442bc1SLiam Girdwood 2019f1442bc1SLiam Girdwood ret = platform->driver->read(platform, reg); 2020f1442bc1SLiam Girdwood dev_dbg(platform->dev, "read %x => %x\n", reg, ret); 2021a82ce2aeSLiam Girdwood trace_snd_soc_preg_read(platform, reg, ret); 2022f1442bc1SLiam Girdwood 2023f1442bc1SLiam Girdwood return ret; 2024f1442bc1SLiam Girdwood } 2025f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_read); 2026f1442bc1SLiam Girdwood 2027f1442bc1SLiam Girdwood int snd_soc_platform_write(struct snd_soc_platform *platform, 2028f1442bc1SLiam Girdwood unsigned int reg, unsigned int val) 2029f1442bc1SLiam Girdwood { 2030f1442bc1SLiam Girdwood if (!platform->driver->write) { 2031f110bfc7SLiam Girdwood dev_err(platform->dev, "ASoC: platform has no write back\n"); 2032f1442bc1SLiam Girdwood return -1; 2033f1442bc1SLiam Girdwood } 2034f1442bc1SLiam Girdwood 2035f1442bc1SLiam Girdwood dev_dbg(platform->dev, "write %x = %x\n", reg, val); 2036a82ce2aeSLiam Girdwood trace_snd_soc_preg_write(platform, reg, val); 2037f1442bc1SLiam Girdwood return platform->driver->write(platform, reg, val); 2038f1442bc1SLiam Girdwood } 2039f1442bc1SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_platform_write); 2040f1442bc1SLiam Girdwood 2041239c9706SDimitris Papastamos /** 2042db2a4165SFrank Mandarino * snd_soc_new_ac97_codec - initailise AC97 device 2043db2a4165SFrank Mandarino * @codec: audio codec 2044db2a4165SFrank Mandarino * @ops: AC97 bus operations 2045db2a4165SFrank Mandarino * @num: AC97 codec number 2046db2a4165SFrank Mandarino * 2047db2a4165SFrank Mandarino * Initialises AC97 codec resources for use by ad-hoc devices only. 2048db2a4165SFrank Mandarino */ 2049db2a4165SFrank Mandarino int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, 2050db2a4165SFrank Mandarino struct snd_ac97_bus_ops *ops, int num) 2051db2a4165SFrank Mandarino { 2052db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 2053db2a4165SFrank Mandarino 2054db2a4165SFrank Mandarino codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 2055db2a4165SFrank Mandarino if (codec->ac97 == NULL) { 2056db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 2057db2a4165SFrank Mandarino return -ENOMEM; 2058db2a4165SFrank Mandarino } 2059db2a4165SFrank Mandarino 2060db2a4165SFrank Mandarino codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); 2061db2a4165SFrank Mandarino if (codec->ac97->bus == NULL) { 2062db2a4165SFrank Mandarino kfree(codec->ac97); 2063db2a4165SFrank Mandarino codec->ac97 = NULL; 2064db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 2065db2a4165SFrank Mandarino return -ENOMEM; 2066db2a4165SFrank Mandarino } 2067db2a4165SFrank Mandarino 2068db2a4165SFrank Mandarino codec->ac97->bus->ops = ops; 2069db2a4165SFrank Mandarino codec->ac97->num = num; 20700562f788SMika Westerberg 20710562f788SMika Westerberg /* 20720562f788SMika Westerberg * Mark the AC97 device to be created by us. This way we ensure that the 20730562f788SMika Westerberg * device will be registered with the device subsystem later on. 20740562f788SMika Westerberg */ 20750562f788SMika Westerberg codec->ac97_created = 1; 20760562f788SMika Westerberg 2077db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 2078db2a4165SFrank Mandarino return 0; 2079db2a4165SFrank Mandarino } 2080db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 2081db2a4165SFrank Mandarino 2082*b047e1ccSMark Brown struct snd_ac97_bus_ops *soc_ac97_ops; 2083*b047e1ccSMark Brown 2084*b047e1ccSMark Brown int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops) 2085*b047e1ccSMark Brown { 2086*b047e1ccSMark Brown if (ops == soc_ac97_ops) 2087*b047e1ccSMark Brown return 0; 2088*b047e1ccSMark Brown 2089*b047e1ccSMark Brown if (soc_ac97_ops && ops) 2090*b047e1ccSMark Brown return -EBUSY; 2091*b047e1ccSMark Brown 2092*b047e1ccSMark Brown soc_ac97_ops = ops; 2093*b047e1ccSMark Brown 2094*b047e1ccSMark Brown return 0; 2095*b047e1ccSMark Brown } 2096*b047e1ccSMark Brown EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops); 2097*b047e1ccSMark Brown 2098db2a4165SFrank Mandarino /** 2099db2a4165SFrank Mandarino * snd_soc_free_ac97_codec - free AC97 codec device 2100db2a4165SFrank Mandarino * @codec: audio codec 2101db2a4165SFrank Mandarino * 2102db2a4165SFrank Mandarino * Frees AC97 codec device resources. 2103db2a4165SFrank Mandarino */ 2104db2a4165SFrank Mandarino void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 2105db2a4165SFrank Mandarino { 2106db2a4165SFrank Mandarino mutex_lock(&codec->mutex); 2107f0fba2adSLiam Girdwood #ifdef CONFIG_SND_SOC_AC97_BUS 2108f0fba2adSLiam Girdwood soc_unregister_ac97_dai_link(codec); 2109f0fba2adSLiam Girdwood #endif 2110db2a4165SFrank Mandarino kfree(codec->ac97->bus); 2111db2a4165SFrank Mandarino kfree(codec->ac97); 2112db2a4165SFrank Mandarino codec->ac97 = NULL; 21130562f788SMika Westerberg codec->ac97_created = 0; 2114db2a4165SFrank Mandarino mutex_unlock(&codec->mutex); 2115db2a4165SFrank Mandarino } 2116db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); 2117db2a4165SFrank Mandarino 2118c3753707SMark Brown unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) 2119c3753707SMark Brown { 2120c3753707SMark Brown unsigned int ret; 2121c3753707SMark Brown 2122c3acec26SMark Brown ret = codec->read(codec, reg); 2123c3753707SMark Brown dev_dbg(codec->dev, "read %x => %x\n", reg, ret); 2124a8b1d34fSMark Brown trace_snd_soc_reg_read(codec, reg, ret); 2125c3753707SMark Brown 2126c3753707SMark Brown return ret; 2127c3753707SMark Brown } 2128c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_read); 2129c3753707SMark Brown 2130c3753707SMark Brown unsigned int snd_soc_write(struct snd_soc_codec *codec, 2131c3753707SMark Brown unsigned int reg, unsigned int val) 2132c3753707SMark Brown { 2133c3753707SMark Brown dev_dbg(codec->dev, "write %x = %x\n", reg, val); 2134a8b1d34fSMark Brown trace_snd_soc_reg_write(codec, reg, val); 2135c3acec26SMark Brown return codec->write(codec, reg, val); 2136c3753707SMark Brown } 2137c3753707SMark Brown EXPORT_SYMBOL_GPL(snd_soc_write); 2138c3753707SMark Brown 21395fb609d4SDimitris Papastamos unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, 21405fb609d4SDimitris Papastamos unsigned int reg, const void *data, size_t len) 21415fb609d4SDimitris Papastamos { 21425fb609d4SDimitris Papastamos return codec->bulk_write_raw(codec, reg, data, len); 21435fb609d4SDimitris Papastamos } 21445fb609d4SDimitris Papastamos EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); 21455fb609d4SDimitris Papastamos 2146db2a4165SFrank Mandarino /** 2147db2a4165SFrank Mandarino * snd_soc_update_bits - update codec register bits 2148db2a4165SFrank Mandarino * @codec: audio codec 2149db2a4165SFrank Mandarino * @reg: codec register 2150db2a4165SFrank Mandarino * @mask: register mask 2151db2a4165SFrank Mandarino * @value: new value 2152db2a4165SFrank Mandarino * 2153db2a4165SFrank Mandarino * Writes new register value. 2154db2a4165SFrank Mandarino * 2155180c329dSTimur Tabi * Returns 1 for change, 0 for no change, or negative error code. 2156db2a4165SFrank Mandarino */ 2157db2a4165SFrank Mandarino int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, 215846f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 2159db2a4165SFrank Mandarino { 21608a713da8SMark Brown bool change; 216146f5822fSDaniel Ribeiro unsigned int old, new; 2162180c329dSTimur Tabi int ret; 2163db2a4165SFrank Mandarino 21648a713da8SMark Brown if (codec->using_regmap) { 21658a713da8SMark Brown ret = regmap_update_bits_check(codec->control_data, reg, 21668a713da8SMark Brown mask, value, &change); 21678a713da8SMark Brown } else { 2168180c329dSTimur Tabi ret = snd_soc_read(codec, reg); 2169180c329dSTimur Tabi if (ret < 0) 2170180c329dSTimur Tabi return ret; 2171180c329dSTimur Tabi 2172180c329dSTimur Tabi old = ret; 217378bf3c9aSMark Brown new = (old & ~mask) | (value & mask); 2174db2a4165SFrank Mandarino change = old != new; 21758a713da8SMark Brown if (change) 2176180c329dSTimur Tabi ret = snd_soc_write(codec, reg, new); 21778a713da8SMark Brown } 21788a713da8SMark Brown 2179180c329dSTimur Tabi if (ret < 0) 2180180c329dSTimur Tabi return ret; 2181db2a4165SFrank Mandarino 2182db2a4165SFrank Mandarino return change; 2183db2a4165SFrank Mandarino } 2184db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_update_bits); 2185db2a4165SFrank Mandarino 2186db2a4165SFrank Mandarino /** 21876c508c62SEero Nurkkala * snd_soc_update_bits_locked - update codec register bits 21886c508c62SEero Nurkkala * @codec: audio codec 21896c508c62SEero Nurkkala * @reg: codec register 21906c508c62SEero Nurkkala * @mask: register mask 21916c508c62SEero Nurkkala * @value: new value 21926c508c62SEero Nurkkala * 21936c508c62SEero Nurkkala * Writes new register value, and takes the codec mutex. 21946c508c62SEero Nurkkala * 21956c508c62SEero Nurkkala * Returns 1 for change else 0. 21966c508c62SEero Nurkkala */ 2197dd1b3d53SMark Brown int snd_soc_update_bits_locked(struct snd_soc_codec *codec, 21986c508c62SEero Nurkkala unsigned short reg, unsigned int mask, 21996c508c62SEero Nurkkala unsigned int value) 22006c508c62SEero Nurkkala { 22016c508c62SEero Nurkkala int change; 22026c508c62SEero Nurkkala 22036c508c62SEero Nurkkala mutex_lock(&codec->mutex); 22046c508c62SEero Nurkkala change = snd_soc_update_bits(codec, reg, mask, value); 22056c508c62SEero Nurkkala mutex_unlock(&codec->mutex); 22066c508c62SEero Nurkkala 22076c508c62SEero Nurkkala return change; 22086c508c62SEero Nurkkala } 2209dd1b3d53SMark Brown EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); 22106c508c62SEero Nurkkala 22116c508c62SEero Nurkkala /** 2212db2a4165SFrank Mandarino * snd_soc_test_bits - test register for change 2213db2a4165SFrank Mandarino * @codec: audio codec 2214db2a4165SFrank Mandarino * @reg: codec register 2215db2a4165SFrank Mandarino * @mask: register mask 2216db2a4165SFrank Mandarino * @value: new value 2217db2a4165SFrank Mandarino * 2218db2a4165SFrank Mandarino * Tests a register with a new value and checks if the new value is 2219db2a4165SFrank Mandarino * different from the old value. 2220db2a4165SFrank Mandarino * 2221db2a4165SFrank Mandarino * Returns 1 for change else 0. 2222db2a4165SFrank Mandarino */ 2223db2a4165SFrank Mandarino int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, 222446f5822fSDaniel Ribeiro unsigned int mask, unsigned int value) 2225db2a4165SFrank Mandarino { 2226db2a4165SFrank Mandarino int change; 222746f5822fSDaniel Ribeiro unsigned int old, new; 2228db2a4165SFrank Mandarino 2229db2a4165SFrank Mandarino old = snd_soc_read(codec, reg); 2230db2a4165SFrank Mandarino new = (old & ~mask) | value; 2231db2a4165SFrank Mandarino change = old != new; 2232db2a4165SFrank Mandarino 2233db2a4165SFrank Mandarino return change; 2234db2a4165SFrank Mandarino } 2235db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_test_bits); 2236db2a4165SFrank Mandarino 2237db2a4165SFrank Mandarino /** 2238db2a4165SFrank Mandarino * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 2239db2a4165SFrank Mandarino * @substream: the pcm substream 2240db2a4165SFrank Mandarino * @hw: the hardware parameters 2241db2a4165SFrank Mandarino * 2242db2a4165SFrank Mandarino * Sets the substream runtime hardware parameters. 2243db2a4165SFrank Mandarino */ 2244db2a4165SFrank Mandarino int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 2245db2a4165SFrank Mandarino const struct snd_pcm_hardware *hw) 2246db2a4165SFrank Mandarino { 2247db2a4165SFrank Mandarino struct snd_pcm_runtime *runtime = substream->runtime; 2248db2a4165SFrank Mandarino runtime->hw.info = hw->info; 2249db2a4165SFrank Mandarino runtime->hw.formats = hw->formats; 2250db2a4165SFrank Mandarino runtime->hw.period_bytes_min = hw->period_bytes_min; 2251db2a4165SFrank Mandarino runtime->hw.period_bytes_max = hw->period_bytes_max; 2252db2a4165SFrank Mandarino runtime->hw.periods_min = hw->periods_min; 2253db2a4165SFrank Mandarino runtime->hw.periods_max = hw->periods_max; 2254db2a4165SFrank Mandarino runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; 2255db2a4165SFrank Mandarino runtime->hw.fifo_size = hw->fifo_size; 2256db2a4165SFrank Mandarino return 0; 2257db2a4165SFrank Mandarino } 2258db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); 2259db2a4165SFrank Mandarino 2260db2a4165SFrank Mandarino /** 2261db2a4165SFrank Mandarino * snd_soc_cnew - create new control 2262db2a4165SFrank Mandarino * @_template: control template 2263db2a4165SFrank Mandarino * @data: control private data 2264ac11a2b3SMark Brown * @long_name: control long name 2265efb7ac3fSMark Brown * @prefix: control name prefix 2266db2a4165SFrank Mandarino * 2267db2a4165SFrank Mandarino * Create a new mixer control from a template control. 2268db2a4165SFrank Mandarino * 2269db2a4165SFrank Mandarino * Returns 0 for success, else error. 2270db2a4165SFrank Mandarino */ 2271db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 22723056557fSMark Brown void *data, const char *long_name, 2273efb7ac3fSMark Brown const char *prefix) 2274db2a4165SFrank Mandarino { 2275db2a4165SFrank Mandarino struct snd_kcontrol_new template; 2276efb7ac3fSMark Brown struct snd_kcontrol *kcontrol; 2277efb7ac3fSMark Brown char *name = NULL; 2278efb7ac3fSMark Brown int name_len; 2279db2a4165SFrank Mandarino 2280db2a4165SFrank Mandarino memcpy(&template, _template, sizeof(template)); 2281db2a4165SFrank Mandarino template.index = 0; 2282db2a4165SFrank Mandarino 2283efb7ac3fSMark Brown if (!long_name) 2284efb7ac3fSMark Brown long_name = template.name; 2285efb7ac3fSMark Brown 2286efb7ac3fSMark Brown if (prefix) { 2287efb7ac3fSMark Brown name_len = strlen(long_name) + strlen(prefix) + 2; 228857cf9d45SAxel Lin name = kmalloc(name_len, GFP_KERNEL); 2289efb7ac3fSMark Brown if (!name) 2290efb7ac3fSMark Brown return NULL; 2291efb7ac3fSMark Brown 2292efb7ac3fSMark Brown snprintf(name, name_len, "%s %s", prefix, long_name); 2293efb7ac3fSMark Brown 2294efb7ac3fSMark Brown template.name = name; 2295efb7ac3fSMark Brown } else { 2296efb7ac3fSMark Brown template.name = long_name; 2297efb7ac3fSMark Brown } 2298efb7ac3fSMark Brown 2299efb7ac3fSMark Brown kcontrol = snd_ctl_new1(&template, data); 2300efb7ac3fSMark Brown 2301efb7ac3fSMark Brown kfree(name); 2302efb7ac3fSMark Brown 2303efb7ac3fSMark Brown return kcontrol; 2304db2a4165SFrank Mandarino } 2305db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew); 2306db2a4165SFrank Mandarino 2307022658beSLiam Girdwood static int snd_soc_add_controls(struct snd_card *card, struct device *dev, 2308022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls, 2309022658beSLiam Girdwood const char *prefix, void *data) 2310022658beSLiam Girdwood { 2311022658beSLiam Girdwood int err, i; 2312022658beSLiam Girdwood 2313022658beSLiam Girdwood for (i = 0; i < num_controls; i++) { 2314022658beSLiam Girdwood const struct snd_kcontrol_new *control = &controls[i]; 2315022658beSLiam Girdwood err = snd_ctl_add(card, snd_soc_cnew(control, data, 2316022658beSLiam Girdwood control->name, prefix)); 2317022658beSLiam Girdwood if (err < 0) { 2318f110bfc7SLiam Girdwood dev_err(dev, "ASoC: Failed to add %s: %d\n", 2319f110bfc7SLiam Girdwood control->name, err); 2320022658beSLiam Girdwood return err; 2321022658beSLiam Girdwood } 2322022658beSLiam Girdwood } 2323022658beSLiam Girdwood 2324022658beSLiam Girdwood return 0; 2325022658beSLiam Girdwood } 2326022658beSLiam Girdwood 2327db2a4165SFrank Mandarino /** 2328022658beSLiam Girdwood * snd_soc_add_codec_controls - add an array of controls to a codec. 2329022658beSLiam Girdwood * Convenience function to add a list of controls. Many codecs were 23303e8e1952SIan Molton * duplicating this code. 23313e8e1952SIan Molton * 23323e8e1952SIan Molton * @codec: codec to add controls to 23333e8e1952SIan Molton * @controls: array of controls to add 23343e8e1952SIan Molton * @num_controls: number of elements in the array 23353e8e1952SIan Molton * 23363e8e1952SIan Molton * Return 0 for success, else error. 23373e8e1952SIan Molton */ 2338022658beSLiam Girdwood int snd_soc_add_codec_controls(struct snd_soc_codec *codec, 23393e8e1952SIan Molton const struct snd_kcontrol_new *controls, int num_controls) 23403e8e1952SIan Molton { 2341f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 23423e8e1952SIan Molton 2343022658beSLiam Girdwood return snd_soc_add_controls(card, codec->dev, controls, num_controls, 2344022658beSLiam Girdwood codec->name_prefix, codec); 23453e8e1952SIan Molton } 2346022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); 23473e8e1952SIan Molton 23483e8e1952SIan Molton /** 2349a491a5c8SLiam Girdwood * snd_soc_add_platform_controls - add an array of controls to a platform. 2350022658beSLiam Girdwood * Convenience function to add a list of controls. 2351a491a5c8SLiam Girdwood * 2352a491a5c8SLiam Girdwood * @platform: platform to add controls to 2353a491a5c8SLiam Girdwood * @controls: array of controls to add 2354a491a5c8SLiam Girdwood * @num_controls: number of elements in the array 2355a491a5c8SLiam Girdwood * 2356a491a5c8SLiam Girdwood * Return 0 for success, else error. 2357a491a5c8SLiam Girdwood */ 2358a491a5c8SLiam Girdwood int snd_soc_add_platform_controls(struct snd_soc_platform *platform, 2359a491a5c8SLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2360a491a5c8SLiam Girdwood { 2361a491a5c8SLiam Girdwood struct snd_card *card = platform->card->snd_card; 2362a491a5c8SLiam Girdwood 2363022658beSLiam Girdwood return snd_soc_add_controls(card, platform->dev, controls, num_controls, 2364022658beSLiam Girdwood NULL, platform); 2365a491a5c8SLiam Girdwood } 2366a491a5c8SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); 2367a491a5c8SLiam Girdwood 2368a491a5c8SLiam Girdwood /** 2369022658beSLiam Girdwood * snd_soc_add_card_controls - add an array of controls to a SoC card. 2370022658beSLiam Girdwood * Convenience function to add a list of controls. 2371022658beSLiam Girdwood * 2372022658beSLiam Girdwood * @soc_card: SoC card to add controls to 2373022658beSLiam Girdwood * @controls: array of controls to add 2374022658beSLiam Girdwood * @num_controls: number of elements in the array 2375022658beSLiam Girdwood * 2376022658beSLiam Girdwood * Return 0 for success, else error. 2377022658beSLiam Girdwood */ 2378022658beSLiam Girdwood int snd_soc_add_card_controls(struct snd_soc_card *soc_card, 2379022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2380022658beSLiam Girdwood { 2381022658beSLiam Girdwood struct snd_card *card = soc_card->snd_card; 2382022658beSLiam Girdwood 2383022658beSLiam Girdwood return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, 2384022658beSLiam Girdwood NULL, soc_card); 2385022658beSLiam Girdwood } 2386022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); 2387022658beSLiam Girdwood 2388022658beSLiam Girdwood /** 2389022658beSLiam Girdwood * snd_soc_add_dai_controls - add an array of controls to a DAI. 2390022658beSLiam Girdwood * Convienience function to add a list of controls. 2391022658beSLiam Girdwood * 2392022658beSLiam Girdwood * @dai: DAI to add controls to 2393022658beSLiam Girdwood * @controls: array of controls to add 2394022658beSLiam Girdwood * @num_controls: number of elements in the array 2395022658beSLiam Girdwood * 2396022658beSLiam Girdwood * Return 0 for success, else error. 2397022658beSLiam Girdwood */ 2398022658beSLiam Girdwood int snd_soc_add_dai_controls(struct snd_soc_dai *dai, 2399022658beSLiam Girdwood const struct snd_kcontrol_new *controls, int num_controls) 2400022658beSLiam Girdwood { 2401022658beSLiam Girdwood struct snd_card *card = dai->card->snd_card; 2402022658beSLiam Girdwood 2403022658beSLiam Girdwood return snd_soc_add_controls(card, dai->dev, controls, num_controls, 2404022658beSLiam Girdwood NULL, dai); 2405022658beSLiam Girdwood } 2406022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); 2407022658beSLiam Girdwood 2408022658beSLiam Girdwood /** 2409db2a4165SFrank Mandarino * snd_soc_info_enum_double - enumerated double mixer info callback 2410db2a4165SFrank Mandarino * @kcontrol: mixer control 2411db2a4165SFrank Mandarino * @uinfo: control element information 2412db2a4165SFrank Mandarino * 2413db2a4165SFrank Mandarino * Callback to provide information about a double enumerated 2414db2a4165SFrank Mandarino * mixer control. 2415db2a4165SFrank Mandarino * 2416db2a4165SFrank Mandarino * Returns 0 for success. 2417db2a4165SFrank Mandarino */ 2418db2a4165SFrank Mandarino int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 2419db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2420db2a4165SFrank Mandarino { 2421db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2422db2a4165SFrank Mandarino 2423db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2424db2a4165SFrank Mandarino uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2425f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2426db2a4165SFrank Mandarino 2427f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2428f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2429db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2430db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2431db2a4165SFrank Mandarino return 0; 2432db2a4165SFrank Mandarino } 2433db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); 2434db2a4165SFrank Mandarino 2435db2a4165SFrank Mandarino /** 2436db2a4165SFrank Mandarino * snd_soc_get_enum_double - enumerated double mixer get callback 2437db2a4165SFrank Mandarino * @kcontrol: mixer control 2438ac11a2b3SMark Brown * @ucontrol: control element information 2439db2a4165SFrank Mandarino * 2440db2a4165SFrank Mandarino * Callback to get the value of a double enumerated mixer. 2441db2a4165SFrank Mandarino * 2442db2a4165SFrank Mandarino * Returns 0 for success. 2443db2a4165SFrank Mandarino */ 2444db2a4165SFrank Mandarino int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, 2445db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2446db2a4165SFrank Mandarino { 2447db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2448db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 244986767b7dSLars-Peter Clausen unsigned int val; 2450db2a4165SFrank Mandarino 2451db2a4165SFrank Mandarino val = snd_soc_read(codec, e->reg); 24523ff3f64bSMark Brown ucontrol->value.enumerated.item[0] 245386767b7dSLars-Peter Clausen = (val >> e->shift_l) & e->mask; 2454db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) 2455db2a4165SFrank Mandarino ucontrol->value.enumerated.item[1] = 245686767b7dSLars-Peter Clausen (val >> e->shift_r) & e->mask; 2457db2a4165SFrank Mandarino 2458db2a4165SFrank Mandarino return 0; 2459db2a4165SFrank Mandarino } 2460db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); 2461db2a4165SFrank Mandarino 2462db2a4165SFrank Mandarino /** 2463db2a4165SFrank Mandarino * snd_soc_put_enum_double - enumerated double mixer put callback 2464db2a4165SFrank Mandarino * @kcontrol: mixer control 2465ac11a2b3SMark Brown * @ucontrol: control element information 2466db2a4165SFrank Mandarino * 2467db2a4165SFrank Mandarino * Callback to set the value of a double enumerated mixer. 2468db2a4165SFrank Mandarino * 2469db2a4165SFrank Mandarino * Returns 0 for success. 2470db2a4165SFrank Mandarino */ 2471db2a4165SFrank Mandarino int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 2472db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2473db2a4165SFrank Mandarino { 2474db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2475db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 247646f5822fSDaniel Ribeiro unsigned int val; 247786767b7dSLars-Peter Clausen unsigned int mask; 2478db2a4165SFrank Mandarino 2479f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[0] > e->max - 1) 2480db2a4165SFrank Mandarino return -EINVAL; 2481db2a4165SFrank Mandarino val = ucontrol->value.enumerated.item[0] << e->shift_l; 248286767b7dSLars-Peter Clausen mask = e->mask << e->shift_l; 2483db2a4165SFrank Mandarino if (e->shift_l != e->shift_r) { 2484f8ba0b7bSJon Smirl if (ucontrol->value.enumerated.item[1] > e->max - 1) 2485db2a4165SFrank Mandarino return -EINVAL; 2486db2a4165SFrank Mandarino val |= ucontrol->value.enumerated.item[1] << e->shift_r; 248786767b7dSLars-Peter Clausen mask |= e->mask << e->shift_r; 2488db2a4165SFrank Mandarino } 2489db2a4165SFrank Mandarino 24906c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2491db2a4165SFrank Mandarino } 2492db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2493db2a4165SFrank Mandarino 2494db2a4165SFrank Mandarino /** 24952e72f8e3SPeter Ujfalusi * snd_soc_get_value_enum_double - semi enumerated double mixer get callback 24962e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 24972e72f8e3SPeter Ujfalusi * @ucontrol: control element information 24982e72f8e3SPeter Ujfalusi * 24992e72f8e3SPeter Ujfalusi * Callback to get the value of a double semi enumerated mixer. 25002e72f8e3SPeter Ujfalusi * 25012e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 25022e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 25032e72f8e3SPeter Ujfalusi * 25042e72f8e3SPeter Ujfalusi * Returns 0 for success. 25052e72f8e3SPeter Ujfalusi */ 25062e72f8e3SPeter Ujfalusi int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, 25072e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 25082e72f8e3SPeter Ujfalusi { 25092e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 251074155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 251146f5822fSDaniel Ribeiro unsigned int reg_val, val, mux; 25122e72f8e3SPeter Ujfalusi 25132e72f8e3SPeter Ujfalusi reg_val = snd_soc_read(codec, e->reg); 25142e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_l) & e->mask; 25152e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 25162e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 25172e72f8e3SPeter Ujfalusi break; 25182e72f8e3SPeter Ujfalusi } 25192e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[0] = mux; 25202e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 25212e72f8e3SPeter Ujfalusi val = (reg_val >> e->shift_r) & e->mask; 25222e72f8e3SPeter Ujfalusi for (mux = 0; mux < e->max; mux++) { 25232e72f8e3SPeter Ujfalusi if (val == e->values[mux]) 25242e72f8e3SPeter Ujfalusi break; 25252e72f8e3SPeter Ujfalusi } 25262e72f8e3SPeter Ujfalusi ucontrol->value.enumerated.item[1] = mux; 25272e72f8e3SPeter Ujfalusi } 25282e72f8e3SPeter Ujfalusi 25292e72f8e3SPeter Ujfalusi return 0; 25302e72f8e3SPeter Ujfalusi } 25312e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); 25322e72f8e3SPeter Ujfalusi 25332e72f8e3SPeter Ujfalusi /** 25342e72f8e3SPeter Ujfalusi * snd_soc_put_value_enum_double - semi enumerated double mixer put callback 25352e72f8e3SPeter Ujfalusi * @kcontrol: mixer control 25362e72f8e3SPeter Ujfalusi * @ucontrol: control element information 25372e72f8e3SPeter Ujfalusi * 25382e72f8e3SPeter Ujfalusi * Callback to set the value of a double semi enumerated mixer. 25392e72f8e3SPeter Ujfalusi * 25402e72f8e3SPeter Ujfalusi * Semi enumerated mixer: the enumerated items are referred as values. Can be 25412e72f8e3SPeter Ujfalusi * used for handling bitfield coded enumeration for example. 25422e72f8e3SPeter Ujfalusi * 25432e72f8e3SPeter Ujfalusi * Returns 0 for success. 25442e72f8e3SPeter Ujfalusi */ 25452e72f8e3SPeter Ujfalusi int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, 25462e72f8e3SPeter Ujfalusi struct snd_ctl_elem_value *ucontrol) 25472e72f8e3SPeter Ujfalusi { 25482e72f8e3SPeter Ujfalusi struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 254974155556SPeter Ujfalusi struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 255046f5822fSDaniel Ribeiro unsigned int val; 255146f5822fSDaniel Ribeiro unsigned int mask; 25522e72f8e3SPeter Ujfalusi 25532e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[0] > e->max - 1) 25542e72f8e3SPeter Ujfalusi return -EINVAL; 25552e72f8e3SPeter Ujfalusi val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 25562e72f8e3SPeter Ujfalusi mask = e->mask << e->shift_l; 25572e72f8e3SPeter Ujfalusi if (e->shift_l != e->shift_r) { 25582e72f8e3SPeter Ujfalusi if (ucontrol->value.enumerated.item[1] > e->max - 1) 25592e72f8e3SPeter Ujfalusi return -EINVAL; 25602e72f8e3SPeter Ujfalusi val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 25612e72f8e3SPeter Ujfalusi mask |= e->mask << e->shift_r; 25622e72f8e3SPeter Ujfalusi } 25632e72f8e3SPeter Ujfalusi 25646c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, e->reg, mask, val); 25652e72f8e3SPeter Ujfalusi } 25662e72f8e3SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); 25672e72f8e3SPeter Ujfalusi 25682e72f8e3SPeter Ujfalusi /** 2569db2a4165SFrank Mandarino * snd_soc_info_enum_ext - external enumerated single mixer info callback 2570db2a4165SFrank Mandarino * @kcontrol: mixer control 2571db2a4165SFrank Mandarino * @uinfo: control element information 2572db2a4165SFrank Mandarino * 2573db2a4165SFrank Mandarino * Callback to provide information about an external enumerated 2574db2a4165SFrank Mandarino * single mixer. 2575db2a4165SFrank Mandarino * 2576db2a4165SFrank Mandarino * Returns 0 for success. 2577db2a4165SFrank Mandarino */ 2578db2a4165SFrank Mandarino int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, 2579db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2580db2a4165SFrank Mandarino { 2581db2a4165SFrank Mandarino struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2582db2a4165SFrank Mandarino 2583db2a4165SFrank Mandarino uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2584db2a4165SFrank Mandarino uinfo->count = 1; 2585f8ba0b7bSJon Smirl uinfo->value.enumerated.items = e->max; 2586db2a4165SFrank Mandarino 2587f8ba0b7bSJon Smirl if (uinfo->value.enumerated.item > e->max - 1) 2588f8ba0b7bSJon Smirl uinfo->value.enumerated.item = e->max - 1; 2589db2a4165SFrank Mandarino strcpy(uinfo->value.enumerated.name, 2590db2a4165SFrank Mandarino e->texts[uinfo->value.enumerated.item]); 2591db2a4165SFrank Mandarino return 0; 2592db2a4165SFrank Mandarino } 2593db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); 2594db2a4165SFrank Mandarino 2595db2a4165SFrank Mandarino /** 2596db2a4165SFrank Mandarino * snd_soc_info_volsw_ext - external single mixer info callback 2597db2a4165SFrank Mandarino * @kcontrol: mixer control 2598db2a4165SFrank Mandarino * @uinfo: control element information 2599db2a4165SFrank Mandarino * 2600db2a4165SFrank Mandarino * Callback to provide information about a single external mixer control. 2601db2a4165SFrank Mandarino * 2602db2a4165SFrank Mandarino * Returns 0 for success. 2603db2a4165SFrank Mandarino */ 2604db2a4165SFrank Mandarino int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, 2605db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2606db2a4165SFrank Mandarino { 2607a7a4ac86SPhilipp Zabel int max = kcontrol->private_value; 2608db2a4165SFrank Mandarino 2609fd5dfad9SMark Brown if (max == 1 && !strstr(kcontrol->id.name, " Volume")) 2610a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2611a7a4ac86SPhilipp Zabel else 2612a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2613a7a4ac86SPhilipp Zabel 2614db2a4165SFrank Mandarino uinfo->count = 1; 2615db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2616a7a4ac86SPhilipp Zabel uinfo->value.integer.max = max; 2617db2a4165SFrank Mandarino return 0; 2618db2a4165SFrank Mandarino } 2619db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); 2620db2a4165SFrank Mandarino 2621db2a4165SFrank Mandarino /** 2622db2a4165SFrank Mandarino * snd_soc_info_volsw - single mixer info callback 2623db2a4165SFrank Mandarino * @kcontrol: mixer control 2624db2a4165SFrank Mandarino * @uinfo: control element information 2625db2a4165SFrank Mandarino * 2626e8f5a103SPeter Ujfalusi * Callback to provide information about a single mixer control, or a double 2627e8f5a103SPeter Ujfalusi * mixer control that spans 2 registers. 2628db2a4165SFrank Mandarino * 2629db2a4165SFrank Mandarino * Returns 0 for success. 2630db2a4165SFrank Mandarino */ 2631db2a4165SFrank Mandarino int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 2632db2a4165SFrank Mandarino struct snd_ctl_elem_info *uinfo) 2633db2a4165SFrank Mandarino { 26344eaa9819SJon Smirl struct soc_mixer_control *mc = 26354eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2636d11bb4a9SPeter Ujfalusi int platform_max; 2637db2a4165SFrank Mandarino 2638d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2639d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2640d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2641d11bb4a9SPeter Ujfalusi 2642d11bb4a9SPeter Ujfalusi if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) 2643a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 2644a7a4ac86SPhilipp Zabel else 2645a7a4ac86SPhilipp Zabel uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2646a7a4ac86SPhilipp Zabel 2647e8f5a103SPeter Ujfalusi uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; 2648db2a4165SFrank Mandarino uinfo->value.integer.min = 0; 2649d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max; 2650db2a4165SFrank Mandarino return 0; 2651db2a4165SFrank Mandarino } 2652db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_info_volsw); 2653db2a4165SFrank Mandarino 2654db2a4165SFrank Mandarino /** 2655db2a4165SFrank Mandarino * snd_soc_get_volsw - single mixer get callback 2656db2a4165SFrank Mandarino * @kcontrol: mixer control 2657ac11a2b3SMark Brown * @ucontrol: control element information 2658db2a4165SFrank Mandarino * 2659f7915d99SPeter Ujfalusi * Callback to get the value of a single mixer control, or a double mixer 2660f7915d99SPeter Ujfalusi * control that spans 2 registers. 2661db2a4165SFrank Mandarino * 2662db2a4165SFrank Mandarino * Returns 0 for success. 2663db2a4165SFrank Mandarino */ 2664db2a4165SFrank Mandarino int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, 2665db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2666db2a4165SFrank Mandarino { 26674eaa9819SJon Smirl struct soc_mixer_control *mc = 26684eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2669db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2670815ecf8dSJon Smirl unsigned int reg = mc->reg; 2671f7915d99SPeter Ujfalusi unsigned int reg2 = mc->rreg; 2672815ecf8dSJon Smirl unsigned int shift = mc->shift; 2673815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 26744eaa9819SJon Smirl int max = mc->max; 2675815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2676815ecf8dSJon Smirl unsigned int invert = mc->invert; 2677db2a4165SFrank Mandarino 2678db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2679db2a4165SFrank Mandarino (snd_soc_read(codec, reg) >> shift) & mask; 2680f7915d99SPeter Ujfalusi if (invert) 2681db2a4165SFrank Mandarino ucontrol->value.integer.value[0] = 2682a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[0]; 2683f7915d99SPeter Ujfalusi 2684f7915d99SPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2685f7915d99SPeter Ujfalusi if (reg == reg2) 2686f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2687f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg) >> rshift) & mask; 2688f7915d99SPeter Ujfalusi else 2689f7915d99SPeter Ujfalusi ucontrol->value.integer.value[1] = 2690f7915d99SPeter Ujfalusi (snd_soc_read(codec, reg2) >> shift) & mask; 2691f7915d99SPeter Ujfalusi if (invert) 2692db2a4165SFrank Mandarino ucontrol->value.integer.value[1] = 2693a7a4ac86SPhilipp Zabel max - ucontrol->value.integer.value[1]; 2694db2a4165SFrank Mandarino } 2695db2a4165SFrank Mandarino 2696db2a4165SFrank Mandarino return 0; 2697db2a4165SFrank Mandarino } 2698db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_get_volsw); 2699db2a4165SFrank Mandarino 2700db2a4165SFrank Mandarino /** 2701db2a4165SFrank Mandarino * snd_soc_put_volsw - single mixer put callback 2702db2a4165SFrank Mandarino * @kcontrol: mixer control 2703ac11a2b3SMark Brown * @ucontrol: control element information 2704db2a4165SFrank Mandarino * 2705974815baSPeter Ujfalusi * Callback to set the value of a single mixer control, or a double mixer 2706974815baSPeter Ujfalusi * control that spans 2 registers. 2707db2a4165SFrank Mandarino * 2708db2a4165SFrank Mandarino * Returns 0 for success. 2709db2a4165SFrank Mandarino */ 2710db2a4165SFrank Mandarino int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, 2711db2a4165SFrank Mandarino struct snd_ctl_elem_value *ucontrol) 2712db2a4165SFrank Mandarino { 27134eaa9819SJon Smirl struct soc_mixer_control *mc = 27144eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2715db2a4165SFrank Mandarino struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2716815ecf8dSJon Smirl unsigned int reg = mc->reg; 2717974815baSPeter Ujfalusi unsigned int reg2 = mc->rreg; 2718815ecf8dSJon Smirl unsigned int shift = mc->shift; 2719815ecf8dSJon Smirl unsigned int rshift = mc->rshift; 27204eaa9819SJon Smirl int max = mc->max; 2721815ecf8dSJon Smirl unsigned int mask = (1 << fls(max)) - 1; 2722815ecf8dSJon Smirl unsigned int invert = mc->invert; 2723974815baSPeter Ujfalusi int err; 2724974815baSPeter Ujfalusi bool type_2r = 0; 2725974815baSPeter Ujfalusi unsigned int val2 = 0; 2726974815baSPeter Ujfalusi unsigned int val, val_mask; 2727db2a4165SFrank Mandarino 2728db2a4165SFrank Mandarino val = (ucontrol->value.integer.value[0] & mask); 2729db2a4165SFrank Mandarino if (invert) 2730a7a4ac86SPhilipp Zabel val = max - val; 2731db2a4165SFrank Mandarino val_mask = mask << shift; 2732db2a4165SFrank Mandarino val = val << shift; 2733974815baSPeter Ujfalusi if (snd_soc_volsw_is_stereo(mc)) { 2734db2a4165SFrank Mandarino val2 = (ucontrol->value.integer.value[1] & mask); 2735db2a4165SFrank Mandarino if (invert) 2736a7a4ac86SPhilipp Zabel val2 = max - val2; 2737974815baSPeter Ujfalusi if (reg == reg2) { 2738db2a4165SFrank Mandarino val_mask |= mask << rshift; 2739db2a4165SFrank Mandarino val |= val2 << rshift; 2740974815baSPeter Ujfalusi } else { 2741db2a4165SFrank Mandarino val2 = val2 << shift; 2742974815baSPeter Ujfalusi type_2r = 1; 2743974815baSPeter Ujfalusi } 2744974815baSPeter Ujfalusi } 27456c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 27463ff3f64bSMark Brown if (err < 0) 2747db2a4165SFrank Mandarino return err; 2748db2a4165SFrank Mandarino 2749974815baSPeter Ujfalusi if (type_2r) 27506c508c62SEero Nurkkala err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); 2751974815baSPeter Ujfalusi 2752db2a4165SFrank Mandarino return err; 2753db2a4165SFrank Mandarino } 2754974815baSPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_put_volsw); 2755db2a4165SFrank Mandarino 2756e13ac2e9SMark Brown /** 27571d99f243SBrian Austin * snd_soc_get_volsw_sx - single mixer get callback 27581d99f243SBrian Austin * @kcontrol: mixer control 27591d99f243SBrian Austin * @ucontrol: control element information 27601d99f243SBrian Austin * 27611d99f243SBrian Austin * Callback to get the value of a single mixer control, or a double mixer 27621d99f243SBrian Austin * control that spans 2 registers. 27631d99f243SBrian Austin * 27641d99f243SBrian Austin * Returns 0 for success. 27651d99f243SBrian Austin */ 27661d99f243SBrian Austin int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, 27671d99f243SBrian Austin struct snd_ctl_elem_value *ucontrol) 27681d99f243SBrian Austin { 27691d99f243SBrian Austin struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 27701d99f243SBrian Austin struct soc_mixer_control *mc = 27711d99f243SBrian Austin (struct soc_mixer_control *)kcontrol->private_value; 27721d99f243SBrian Austin 27731d99f243SBrian Austin unsigned int reg = mc->reg; 27741d99f243SBrian Austin unsigned int reg2 = mc->rreg; 27751d99f243SBrian Austin unsigned int shift = mc->shift; 27761d99f243SBrian Austin unsigned int rshift = mc->rshift; 27771d99f243SBrian Austin int max = mc->max; 27781d99f243SBrian Austin int min = mc->min; 27791d99f243SBrian Austin int mask = (1 << (fls(min + max) - 1)) - 1; 27801d99f243SBrian Austin 27811d99f243SBrian Austin ucontrol->value.integer.value[0] = 27821d99f243SBrian Austin ((snd_soc_read(codec, reg) >> shift) - min) & mask; 27831d99f243SBrian Austin 27841d99f243SBrian Austin if (snd_soc_volsw_is_stereo(mc)) 27851d99f243SBrian Austin ucontrol->value.integer.value[1] = 27861d99f243SBrian Austin ((snd_soc_read(codec, reg2) >> rshift) - min) & mask; 27871d99f243SBrian Austin 27881d99f243SBrian Austin return 0; 27891d99f243SBrian Austin } 27901d99f243SBrian Austin EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); 27911d99f243SBrian Austin 27921d99f243SBrian Austin /** 27931d99f243SBrian Austin * snd_soc_put_volsw_sx - double mixer set callback 27941d99f243SBrian Austin * @kcontrol: mixer control 27951d99f243SBrian Austin * @uinfo: control element information 27961d99f243SBrian Austin * 27971d99f243SBrian Austin * Callback to set the value of a double mixer control that spans 2 registers. 27981d99f243SBrian Austin * 27991d99f243SBrian Austin * Returns 0 for success. 28001d99f243SBrian Austin */ 28011d99f243SBrian Austin int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, 28021d99f243SBrian Austin struct snd_ctl_elem_value *ucontrol) 28031d99f243SBrian Austin { 28041d99f243SBrian Austin struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 28051d99f243SBrian Austin struct soc_mixer_control *mc = 28061d99f243SBrian Austin (struct soc_mixer_control *)kcontrol->private_value; 28071d99f243SBrian Austin 28081d99f243SBrian Austin unsigned int reg = mc->reg; 28091d99f243SBrian Austin unsigned int reg2 = mc->rreg; 28101d99f243SBrian Austin unsigned int shift = mc->shift; 28111d99f243SBrian Austin unsigned int rshift = mc->rshift; 28121d99f243SBrian Austin int max = mc->max; 28131d99f243SBrian Austin int min = mc->min; 28141d99f243SBrian Austin int mask = (1 << (fls(min + max) - 1)) - 1; 281527f1d759SBrian Austin int err = 0; 28161d99f243SBrian Austin unsigned short val, val_mask, val2 = 0; 28171d99f243SBrian Austin 28181d99f243SBrian Austin val_mask = mask << shift; 28191d99f243SBrian Austin val = (ucontrol->value.integer.value[0] + min) & mask; 28201d99f243SBrian Austin val = val << shift; 28211d99f243SBrian Austin 2822d055852eSMukund Navada err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 2823d055852eSMukund Navada if (err < 0) 28241d99f243SBrian Austin return err; 28251d99f243SBrian Austin 28261d99f243SBrian Austin if (snd_soc_volsw_is_stereo(mc)) { 28271d99f243SBrian Austin val_mask = mask << rshift; 28281d99f243SBrian Austin val2 = (ucontrol->value.integer.value[1] + min) & mask; 28291d99f243SBrian Austin val2 = val2 << rshift; 28301d99f243SBrian Austin 28311d99f243SBrian Austin if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2)) 28321d99f243SBrian Austin return err; 28331d99f243SBrian Austin } 28341d99f243SBrian Austin return 0; 28351d99f243SBrian Austin } 28361d99f243SBrian Austin EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); 28371d99f243SBrian Austin 28381d99f243SBrian Austin /** 2839e13ac2e9SMark Brown * snd_soc_info_volsw_s8 - signed mixer info callback 2840e13ac2e9SMark Brown * @kcontrol: mixer control 2841e13ac2e9SMark Brown * @uinfo: control element information 2842e13ac2e9SMark Brown * 2843e13ac2e9SMark Brown * Callback to provide information about a signed mixer control. 2844e13ac2e9SMark Brown * 2845e13ac2e9SMark Brown * Returns 0 for success. 2846e13ac2e9SMark Brown */ 2847e13ac2e9SMark Brown int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, 2848e13ac2e9SMark Brown struct snd_ctl_elem_info *uinfo) 2849e13ac2e9SMark Brown { 28504eaa9819SJon Smirl struct soc_mixer_control *mc = 28514eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2852d11bb4a9SPeter Ujfalusi int platform_max; 28534eaa9819SJon Smirl int min = mc->min; 2854e13ac2e9SMark Brown 2855d11bb4a9SPeter Ujfalusi if (!mc->platform_max) 2856d11bb4a9SPeter Ujfalusi mc->platform_max = mc->max; 2857d11bb4a9SPeter Ujfalusi platform_max = mc->platform_max; 2858d11bb4a9SPeter Ujfalusi 2859e13ac2e9SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 2860e13ac2e9SMark Brown uinfo->count = 2; 2861e13ac2e9SMark Brown uinfo->value.integer.min = 0; 2862d11bb4a9SPeter Ujfalusi uinfo->value.integer.max = platform_max - min; 2863e13ac2e9SMark Brown return 0; 2864e13ac2e9SMark Brown } 2865e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); 2866e13ac2e9SMark Brown 2867e13ac2e9SMark Brown /** 2868e13ac2e9SMark Brown * snd_soc_get_volsw_s8 - signed mixer get callback 2869e13ac2e9SMark Brown * @kcontrol: mixer control 2870ac11a2b3SMark Brown * @ucontrol: control element information 2871e13ac2e9SMark Brown * 2872e13ac2e9SMark Brown * Callback to get the value of a signed mixer control. 2873e13ac2e9SMark Brown * 2874e13ac2e9SMark Brown * Returns 0 for success. 2875e13ac2e9SMark Brown */ 2876e13ac2e9SMark Brown int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, 2877e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2878e13ac2e9SMark Brown { 28794eaa9819SJon Smirl struct soc_mixer_control *mc = 28804eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2881e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2882815ecf8dSJon Smirl unsigned int reg = mc->reg; 28834eaa9819SJon Smirl int min = mc->min; 2884e13ac2e9SMark Brown int val = snd_soc_read(codec, reg); 2885e13ac2e9SMark Brown 2886e13ac2e9SMark Brown ucontrol->value.integer.value[0] = 2887e13ac2e9SMark Brown ((signed char)(val & 0xff))-min; 2888e13ac2e9SMark Brown ucontrol->value.integer.value[1] = 2889e13ac2e9SMark Brown ((signed char)((val >> 8) & 0xff))-min; 2890e13ac2e9SMark Brown return 0; 2891e13ac2e9SMark Brown } 2892e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); 2893e13ac2e9SMark Brown 2894e13ac2e9SMark Brown /** 2895e13ac2e9SMark Brown * snd_soc_put_volsw_sgn - signed mixer put callback 2896e13ac2e9SMark Brown * @kcontrol: mixer control 2897ac11a2b3SMark Brown * @ucontrol: control element information 2898e13ac2e9SMark Brown * 2899e13ac2e9SMark Brown * Callback to set the value of a signed mixer control. 2900e13ac2e9SMark Brown * 2901e13ac2e9SMark Brown * Returns 0 for success. 2902e13ac2e9SMark Brown */ 2903e13ac2e9SMark Brown int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, 2904e13ac2e9SMark Brown struct snd_ctl_elem_value *ucontrol) 2905e13ac2e9SMark Brown { 29064eaa9819SJon Smirl struct soc_mixer_control *mc = 29074eaa9819SJon Smirl (struct soc_mixer_control *)kcontrol->private_value; 2908e13ac2e9SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2909815ecf8dSJon Smirl unsigned int reg = mc->reg; 29104eaa9819SJon Smirl int min = mc->min; 291146f5822fSDaniel Ribeiro unsigned int val; 2912e13ac2e9SMark Brown 2913e13ac2e9SMark Brown val = (ucontrol->value.integer.value[0]+min) & 0xff; 2914e13ac2e9SMark Brown val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; 2915e13ac2e9SMark Brown 29166c508c62SEero Nurkkala return snd_soc_update_bits_locked(codec, reg, 0xffff, val); 2917e13ac2e9SMark Brown } 2918e13ac2e9SMark Brown EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); 2919e13ac2e9SMark Brown 29208c6529dbSLiam Girdwood /** 29216c9d8cf6SAdam Thomson * snd_soc_info_volsw_range - single mixer info callback with range. 29226c9d8cf6SAdam Thomson * @kcontrol: mixer control 29236c9d8cf6SAdam Thomson * @uinfo: control element information 29246c9d8cf6SAdam Thomson * 29256c9d8cf6SAdam Thomson * Callback to provide information, within a range, about a single 29266c9d8cf6SAdam Thomson * mixer control. 29276c9d8cf6SAdam Thomson * 29286c9d8cf6SAdam Thomson * returns 0 for success. 29296c9d8cf6SAdam Thomson */ 29306c9d8cf6SAdam Thomson int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, 29316c9d8cf6SAdam Thomson struct snd_ctl_elem_info *uinfo) 29326c9d8cf6SAdam Thomson { 29336c9d8cf6SAdam Thomson struct soc_mixer_control *mc = 29346c9d8cf6SAdam Thomson (struct soc_mixer_control *)kcontrol->private_value; 29356c9d8cf6SAdam Thomson int platform_max; 29366c9d8cf6SAdam Thomson int min = mc->min; 29376c9d8cf6SAdam Thomson 29386c9d8cf6SAdam Thomson if (!mc->platform_max) 29396c9d8cf6SAdam Thomson mc->platform_max = mc->max; 29406c9d8cf6SAdam Thomson platform_max = mc->platform_max; 29416c9d8cf6SAdam Thomson 29426c9d8cf6SAdam Thomson uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 29439bde4f0bSMark Brown uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; 29446c9d8cf6SAdam Thomson uinfo->value.integer.min = 0; 29456c9d8cf6SAdam Thomson uinfo->value.integer.max = platform_max - min; 29466c9d8cf6SAdam Thomson 29476c9d8cf6SAdam Thomson return 0; 29486c9d8cf6SAdam Thomson } 29496c9d8cf6SAdam Thomson EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range); 29506c9d8cf6SAdam Thomson 29516c9d8cf6SAdam Thomson /** 29526c9d8cf6SAdam Thomson * snd_soc_put_volsw_range - single mixer put value callback with range. 29536c9d8cf6SAdam Thomson * @kcontrol: mixer control 29546c9d8cf6SAdam Thomson * @ucontrol: control element information 29556c9d8cf6SAdam Thomson * 29566c9d8cf6SAdam Thomson * Callback to set the value, within a range, for a single mixer control. 29576c9d8cf6SAdam Thomson * 29586c9d8cf6SAdam Thomson * Returns 0 for success. 29596c9d8cf6SAdam Thomson */ 29606c9d8cf6SAdam Thomson int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, 29616c9d8cf6SAdam Thomson struct snd_ctl_elem_value *ucontrol) 29626c9d8cf6SAdam Thomson { 29636c9d8cf6SAdam Thomson struct soc_mixer_control *mc = 29646c9d8cf6SAdam Thomson (struct soc_mixer_control *)kcontrol->private_value; 29656c9d8cf6SAdam Thomson struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 29666c9d8cf6SAdam Thomson unsigned int reg = mc->reg; 29679bde4f0bSMark Brown unsigned int rreg = mc->rreg; 29686c9d8cf6SAdam Thomson unsigned int shift = mc->shift; 29696c9d8cf6SAdam Thomson int min = mc->min; 29706c9d8cf6SAdam Thomson int max = mc->max; 29716c9d8cf6SAdam Thomson unsigned int mask = (1 << fls(max)) - 1; 29726c9d8cf6SAdam Thomson unsigned int invert = mc->invert; 29736c9d8cf6SAdam Thomson unsigned int val, val_mask; 29749bde4f0bSMark Brown int ret; 29756c9d8cf6SAdam Thomson 29766c9d8cf6SAdam Thomson val = ((ucontrol->value.integer.value[0] + min) & mask); 29776c9d8cf6SAdam Thomson if (invert) 29786c9d8cf6SAdam Thomson val = max - val; 29796c9d8cf6SAdam Thomson val_mask = mask << shift; 29806c9d8cf6SAdam Thomson val = val << shift; 29816c9d8cf6SAdam Thomson 29829bde4f0bSMark Brown ret = snd_soc_update_bits_locked(codec, reg, val_mask, val); 29830eaa6ccaSJoonyoung Shim if (ret < 0) 29849bde4f0bSMark Brown return ret; 29859bde4f0bSMark Brown 29869bde4f0bSMark Brown if (snd_soc_volsw_is_stereo(mc)) { 29879bde4f0bSMark Brown val = ((ucontrol->value.integer.value[1] + min) & mask); 29889bde4f0bSMark Brown if (invert) 29899bde4f0bSMark Brown val = max - val; 29909bde4f0bSMark Brown val_mask = mask << shift; 29919bde4f0bSMark Brown val = val << shift; 29929bde4f0bSMark Brown 29939bde4f0bSMark Brown ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val); 29949bde4f0bSMark Brown } 29959bde4f0bSMark Brown 29969bde4f0bSMark Brown return ret; 29976c9d8cf6SAdam Thomson } 29986c9d8cf6SAdam Thomson EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range); 29996c9d8cf6SAdam Thomson 30006c9d8cf6SAdam Thomson /** 30016c9d8cf6SAdam Thomson * snd_soc_get_volsw_range - single mixer get callback with range 30026c9d8cf6SAdam Thomson * @kcontrol: mixer control 30036c9d8cf6SAdam Thomson * @ucontrol: control element information 30046c9d8cf6SAdam Thomson * 30056c9d8cf6SAdam Thomson * Callback to get the value, within a range, of a single mixer control. 30066c9d8cf6SAdam Thomson * 30076c9d8cf6SAdam Thomson * Returns 0 for success. 30086c9d8cf6SAdam Thomson */ 30096c9d8cf6SAdam Thomson int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, 30106c9d8cf6SAdam Thomson struct snd_ctl_elem_value *ucontrol) 30116c9d8cf6SAdam Thomson { 30126c9d8cf6SAdam Thomson struct soc_mixer_control *mc = 30136c9d8cf6SAdam Thomson (struct soc_mixer_control *)kcontrol->private_value; 30146c9d8cf6SAdam Thomson struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 30156c9d8cf6SAdam Thomson unsigned int reg = mc->reg; 30169bde4f0bSMark Brown unsigned int rreg = mc->rreg; 30176c9d8cf6SAdam Thomson unsigned int shift = mc->shift; 30186c9d8cf6SAdam Thomson int min = mc->min; 30196c9d8cf6SAdam Thomson int max = mc->max; 30206c9d8cf6SAdam Thomson unsigned int mask = (1 << fls(max)) - 1; 30216c9d8cf6SAdam Thomson unsigned int invert = mc->invert; 30226c9d8cf6SAdam Thomson 30236c9d8cf6SAdam Thomson ucontrol->value.integer.value[0] = 30246c9d8cf6SAdam Thomson (snd_soc_read(codec, reg) >> shift) & mask; 30256c9d8cf6SAdam Thomson if (invert) 30266c9d8cf6SAdam Thomson ucontrol->value.integer.value[0] = 30276c9d8cf6SAdam Thomson max - ucontrol->value.integer.value[0]; 30286c9d8cf6SAdam Thomson ucontrol->value.integer.value[0] = 30296c9d8cf6SAdam Thomson ucontrol->value.integer.value[0] - min; 30306c9d8cf6SAdam Thomson 30319bde4f0bSMark Brown if (snd_soc_volsw_is_stereo(mc)) { 30329bde4f0bSMark Brown ucontrol->value.integer.value[1] = 30339bde4f0bSMark Brown (snd_soc_read(codec, rreg) >> shift) & mask; 30349bde4f0bSMark Brown if (invert) 30359bde4f0bSMark Brown ucontrol->value.integer.value[1] = 30369bde4f0bSMark Brown max - ucontrol->value.integer.value[1]; 30379bde4f0bSMark Brown ucontrol->value.integer.value[1] = 30389bde4f0bSMark Brown ucontrol->value.integer.value[1] - min; 30399bde4f0bSMark Brown } 30409bde4f0bSMark Brown 30416c9d8cf6SAdam Thomson return 0; 30426c9d8cf6SAdam Thomson } 30436c9d8cf6SAdam Thomson EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); 30446c9d8cf6SAdam Thomson 30456c9d8cf6SAdam Thomson /** 3046637d3847SPeter Ujfalusi * snd_soc_limit_volume - Set new limit to an existing volume control. 3047637d3847SPeter Ujfalusi * 3048637d3847SPeter Ujfalusi * @codec: where to look for the control 3049637d3847SPeter Ujfalusi * @name: Name of the control 3050637d3847SPeter Ujfalusi * @max: new maximum limit 3051637d3847SPeter Ujfalusi * 3052637d3847SPeter Ujfalusi * Return 0 for success, else error. 3053637d3847SPeter Ujfalusi */ 3054637d3847SPeter Ujfalusi int snd_soc_limit_volume(struct snd_soc_codec *codec, 3055637d3847SPeter Ujfalusi const char *name, int max) 3056637d3847SPeter Ujfalusi { 3057f0fba2adSLiam Girdwood struct snd_card *card = codec->card->snd_card; 3058637d3847SPeter Ujfalusi struct snd_kcontrol *kctl; 3059637d3847SPeter Ujfalusi struct soc_mixer_control *mc; 3060637d3847SPeter Ujfalusi int found = 0; 3061637d3847SPeter Ujfalusi int ret = -EINVAL; 3062637d3847SPeter Ujfalusi 3063637d3847SPeter Ujfalusi /* Sanity check for name and max */ 3064637d3847SPeter Ujfalusi if (unlikely(!name || max <= 0)) 3065637d3847SPeter Ujfalusi return -EINVAL; 3066637d3847SPeter Ujfalusi 3067637d3847SPeter Ujfalusi list_for_each_entry(kctl, &card->controls, list) { 3068637d3847SPeter Ujfalusi if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { 3069637d3847SPeter Ujfalusi found = 1; 3070637d3847SPeter Ujfalusi break; 3071637d3847SPeter Ujfalusi } 3072637d3847SPeter Ujfalusi } 3073637d3847SPeter Ujfalusi if (found) { 3074637d3847SPeter Ujfalusi mc = (struct soc_mixer_control *)kctl->private_value; 3075637d3847SPeter Ujfalusi if (max <= mc->max) { 3076d11bb4a9SPeter Ujfalusi mc->platform_max = max; 3077637d3847SPeter Ujfalusi ret = 0; 3078637d3847SPeter Ujfalusi } 3079637d3847SPeter Ujfalusi } 3080637d3847SPeter Ujfalusi return ret; 3081637d3847SPeter Ujfalusi } 3082637d3847SPeter Ujfalusi EXPORT_SYMBOL_GPL(snd_soc_limit_volume); 3083637d3847SPeter Ujfalusi 308471d08516SMark Brown int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, 308571d08516SMark Brown struct snd_ctl_elem_info *uinfo) 308671d08516SMark Brown { 308771d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 308871d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 308971d08516SMark Brown 309071d08516SMark Brown uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 309171d08516SMark Brown uinfo->count = params->num_regs * codec->val_bytes; 309271d08516SMark Brown 309371d08516SMark Brown return 0; 309471d08516SMark Brown } 309571d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_info); 309671d08516SMark Brown 309771d08516SMark Brown int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, 309871d08516SMark Brown struct snd_ctl_elem_value *ucontrol) 309971d08516SMark Brown { 310071d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 310171d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 310271d08516SMark Brown int ret; 310371d08516SMark Brown 310471d08516SMark Brown if (codec->using_regmap) 310571d08516SMark Brown ret = regmap_raw_read(codec->control_data, params->base, 310671d08516SMark Brown ucontrol->value.bytes.data, 310771d08516SMark Brown params->num_regs * codec->val_bytes); 310871d08516SMark Brown else 310971d08516SMark Brown ret = -EINVAL; 311071d08516SMark Brown 3111f831b055SMark Brown /* Hide any masked bytes to ensure consistent data reporting */ 3112f831b055SMark Brown if (ret == 0 && params->mask) { 3113f831b055SMark Brown switch (codec->val_bytes) { 3114f831b055SMark Brown case 1: 3115f831b055SMark Brown ucontrol->value.bytes.data[0] &= ~params->mask; 3116f831b055SMark Brown break; 3117f831b055SMark Brown case 2: 3118f831b055SMark Brown ((u16 *)(&ucontrol->value.bytes.data))[0] 3119f831b055SMark Brown &= ~params->mask; 3120f831b055SMark Brown break; 3121f831b055SMark Brown case 4: 3122f831b055SMark Brown ((u32 *)(&ucontrol->value.bytes.data))[0] 3123f831b055SMark Brown &= ~params->mask; 3124f831b055SMark Brown break; 3125f831b055SMark Brown default: 3126f831b055SMark Brown return -EINVAL; 3127f831b055SMark Brown } 3128f831b055SMark Brown } 3129f831b055SMark Brown 313071d08516SMark Brown return ret; 313171d08516SMark Brown } 313271d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_get); 313371d08516SMark Brown 313471d08516SMark Brown int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, 313571d08516SMark Brown struct snd_ctl_elem_value *ucontrol) 313671d08516SMark Brown { 313771d08516SMark Brown struct soc_bytes *params = (void *)kcontrol->private_value; 313871d08516SMark Brown struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 3139f831b055SMark Brown int ret, len; 3140f831b055SMark Brown unsigned int val; 3141f831b055SMark Brown void *data; 314271d08516SMark Brown 3143f831b055SMark Brown if (!codec->using_regmap) 3144f831b055SMark Brown return -EINVAL; 3145f831b055SMark Brown 3146f831b055SMark Brown len = params->num_regs * codec->val_bytes; 3147f831b055SMark Brown 3148b5a8fe43SMark Brown data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); 3149b5a8fe43SMark Brown if (!data) 3150b5a8fe43SMark Brown return -ENOMEM; 3151b5a8fe43SMark Brown 3152f831b055SMark Brown /* 3153f831b055SMark Brown * If we've got a mask then we need to preserve the register 3154f831b055SMark Brown * bits. We shouldn't modify the incoming data so take a 3155f831b055SMark Brown * copy. 3156f831b055SMark Brown */ 3157f831b055SMark Brown if (params->mask) { 3158f831b055SMark Brown ret = regmap_read(codec->control_data, params->base, &val); 3159f831b055SMark Brown if (ret != 0) 3160e8b18addSWei Yongjun goto out; 3161f831b055SMark Brown 3162f831b055SMark Brown val &= params->mask; 3163f831b055SMark Brown 3164f831b055SMark Brown switch (codec->val_bytes) { 3165f831b055SMark Brown case 1: 3166f831b055SMark Brown ((u8 *)data)[0] &= ~params->mask; 3167f831b055SMark Brown ((u8 *)data)[0] |= val; 3168f831b055SMark Brown break; 3169f831b055SMark Brown case 2: 3170f831b055SMark Brown ((u16 *)data)[0] &= cpu_to_be16(~params->mask); 3171f831b055SMark Brown ((u16 *)data)[0] |= cpu_to_be16(val); 3172f831b055SMark Brown break; 3173f831b055SMark Brown case 4: 3174f831b055SMark Brown ((u32 *)data)[0] &= cpu_to_be32(~params->mask); 3175f831b055SMark Brown ((u32 *)data)[0] |= cpu_to_be32(val); 3176f831b055SMark Brown break; 3177f831b055SMark Brown default: 3178e8b18addSWei Yongjun ret = -EINVAL; 3179e8b18addSWei Yongjun goto out; 3180f831b055SMark Brown } 3181f831b055SMark Brown } 3182f831b055SMark Brown 318371d08516SMark Brown ret = regmap_raw_write(codec->control_data, params->base, 3184f831b055SMark Brown data, len); 3185f831b055SMark Brown 3186e8b18addSWei Yongjun out: 3187f831b055SMark Brown kfree(data); 318871d08516SMark Brown 318971d08516SMark Brown return ret; 319071d08516SMark Brown } 319171d08516SMark Brown EXPORT_SYMBOL_GPL(snd_soc_bytes_put); 319271d08516SMark Brown 3193b6f4bb38Sapatard@mandriva.com /** 31944183eed2SKristoffer KARLSSON * snd_soc_info_xr_sx - signed multi register info callback 31954183eed2SKristoffer KARLSSON * @kcontrol: mreg control 31964183eed2SKristoffer KARLSSON * @uinfo: control element information 31974183eed2SKristoffer KARLSSON * 31984183eed2SKristoffer KARLSSON * Callback to provide information of a control that can 31994183eed2SKristoffer KARLSSON * span multiple codec registers which together 32004183eed2SKristoffer KARLSSON * forms a single signed value in a MSB/LSB manner. 32014183eed2SKristoffer KARLSSON * 32024183eed2SKristoffer KARLSSON * Returns 0 for success. 32034183eed2SKristoffer KARLSSON */ 32044183eed2SKristoffer KARLSSON int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, 32054183eed2SKristoffer KARLSSON struct snd_ctl_elem_info *uinfo) 32064183eed2SKristoffer KARLSSON { 32074183eed2SKristoffer KARLSSON struct soc_mreg_control *mc = 32084183eed2SKristoffer KARLSSON (struct soc_mreg_control *)kcontrol->private_value; 32094183eed2SKristoffer KARLSSON uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 32104183eed2SKristoffer KARLSSON uinfo->count = 1; 32114183eed2SKristoffer KARLSSON uinfo->value.integer.min = mc->min; 32124183eed2SKristoffer KARLSSON uinfo->value.integer.max = mc->max; 32134183eed2SKristoffer KARLSSON 32144183eed2SKristoffer KARLSSON return 0; 32154183eed2SKristoffer KARLSSON } 32164183eed2SKristoffer KARLSSON EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); 32174183eed2SKristoffer KARLSSON 32184183eed2SKristoffer KARLSSON /** 32194183eed2SKristoffer KARLSSON * snd_soc_get_xr_sx - signed multi register get callback 32204183eed2SKristoffer KARLSSON * @kcontrol: mreg control 32214183eed2SKristoffer KARLSSON * @ucontrol: control element information 32224183eed2SKristoffer KARLSSON * 32234183eed2SKristoffer KARLSSON * Callback to get the value of a control that can span 32244183eed2SKristoffer KARLSSON * multiple codec registers which together forms a single 32254183eed2SKristoffer KARLSSON * signed value in a MSB/LSB manner. The control supports 32264183eed2SKristoffer KARLSSON * specifying total no of bits used to allow for bitfields 32274183eed2SKristoffer KARLSSON * across the multiple codec registers. 32284183eed2SKristoffer KARLSSON * 32294183eed2SKristoffer KARLSSON * Returns 0 for success. 32304183eed2SKristoffer KARLSSON */ 32314183eed2SKristoffer KARLSSON int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, 32324183eed2SKristoffer KARLSSON struct snd_ctl_elem_value *ucontrol) 32334183eed2SKristoffer KARLSSON { 32344183eed2SKristoffer KARLSSON struct soc_mreg_control *mc = 32354183eed2SKristoffer KARLSSON (struct soc_mreg_control *)kcontrol->private_value; 32364183eed2SKristoffer KARLSSON struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 32374183eed2SKristoffer KARLSSON unsigned int regbase = mc->regbase; 32384183eed2SKristoffer KARLSSON unsigned int regcount = mc->regcount; 32394183eed2SKristoffer KARLSSON unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; 32404183eed2SKristoffer KARLSSON unsigned int regwmask = (1<<regwshift)-1; 32414183eed2SKristoffer KARLSSON unsigned int invert = mc->invert; 32424183eed2SKristoffer KARLSSON unsigned long mask = (1UL<<mc->nbits)-1; 32434183eed2SKristoffer KARLSSON long min = mc->min; 32444183eed2SKristoffer KARLSSON long max = mc->max; 32454183eed2SKristoffer KARLSSON long val = 0; 32464183eed2SKristoffer KARLSSON unsigned long regval; 32474183eed2SKristoffer KARLSSON unsigned int i; 32484183eed2SKristoffer KARLSSON 32494183eed2SKristoffer KARLSSON for (i = 0; i < regcount; i++) { 32504183eed2SKristoffer KARLSSON regval = snd_soc_read(codec, regbase+i) & regwmask; 32514183eed2SKristoffer KARLSSON val |= regval << (regwshift*(regcount-i-1)); 32524183eed2SKristoffer KARLSSON } 32534183eed2SKristoffer KARLSSON val &= mask; 32544183eed2SKristoffer KARLSSON if (min < 0 && val > max) 32554183eed2SKristoffer KARLSSON val |= ~mask; 32564183eed2SKristoffer KARLSSON if (invert) 32574183eed2SKristoffer KARLSSON val = max - val; 32584183eed2SKristoffer KARLSSON ucontrol->value.integer.value[0] = val; 32594183eed2SKristoffer KARLSSON 32604183eed2SKristoffer KARLSSON return 0; 32614183eed2SKristoffer KARLSSON } 32624183eed2SKristoffer KARLSSON EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); 32634183eed2SKristoffer KARLSSON 32644183eed2SKristoffer KARLSSON /** 32654183eed2SKristoffer KARLSSON * snd_soc_put_xr_sx - signed multi register get callback 32664183eed2SKristoffer KARLSSON * @kcontrol: mreg control 32674183eed2SKristoffer KARLSSON * @ucontrol: control element information 32684183eed2SKristoffer KARLSSON * 32694183eed2SKristoffer KARLSSON * Callback to set the value of a control that can span 32704183eed2SKristoffer KARLSSON * multiple codec registers which together forms a single 32714183eed2SKristoffer KARLSSON * signed value in a MSB/LSB manner. The control supports 32724183eed2SKristoffer KARLSSON * specifying total no of bits used to allow for bitfields 32734183eed2SKristoffer KARLSSON * across the multiple codec registers. 32744183eed2SKristoffer KARLSSON * 32754183eed2SKristoffer KARLSSON * Returns 0 for success. 32764183eed2SKristoffer KARLSSON */ 32774183eed2SKristoffer KARLSSON int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, 32784183eed2SKristoffer KARLSSON struct snd_ctl_elem_value *ucontrol) 32794183eed2SKristoffer KARLSSON { 32804183eed2SKristoffer KARLSSON struct soc_mreg_control *mc = 32814183eed2SKristoffer KARLSSON (struct soc_mreg_control *)kcontrol->private_value; 32824183eed2SKristoffer KARLSSON struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 32834183eed2SKristoffer KARLSSON unsigned int regbase = mc->regbase; 32844183eed2SKristoffer KARLSSON unsigned int regcount = mc->regcount; 32854183eed2SKristoffer KARLSSON unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE; 32864183eed2SKristoffer KARLSSON unsigned int regwmask = (1<<regwshift)-1; 32874183eed2SKristoffer KARLSSON unsigned int invert = mc->invert; 32884183eed2SKristoffer KARLSSON unsigned long mask = (1UL<<mc->nbits)-1; 32894183eed2SKristoffer KARLSSON long max = mc->max; 32904183eed2SKristoffer KARLSSON long val = ucontrol->value.integer.value[0]; 32914183eed2SKristoffer KARLSSON unsigned int i, regval, regmask; 32924183eed2SKristoffer KARLSSON int err; 32934183eed2SKristoffer KARLSSON 32944183eed2SKristoffer KARLSSON if (invert) 32954183eed2SKristoffer KARLSSON val = max - val; 32964183eed2SKristoffer KARLSSON val &= mask; 32974183eed2SKristoffer KARLSSON for (i = 0; i < regcount; i++) { 32984183eed2SKristoffer KARLSSON regval = (val >> (regwshift*(regcount-i-1))) & regwmask; 32994183eed2SKristoffer KARLSSON regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; 33004183eed2SKristoffer KARLSSON err = snd_soc_update_bits_locked(codec, regbase+i, 33014183eed2SKristoffer KARLSSON regmask, regval); 33024183eed2SKristoffer KARLSSON if (err < 0) 33034183eed2SKristoffer KARLSSON return err; 33044183eed2SKristoffer KARLSSON } 33054183eed2SKristoffer KARLSSON 33064183eed2SKristoffer KARLSSON return 0; 33074183eed2SKristoffer KARLSSON } 33084183eed2SKristoffer KARLSSON EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); 33094183eed2SKristoffer KARLSSON 33104183eed2SKristoffer KARLSSON /** 3311dd7b10b3SKristoffer KARLSSON * snd_soc_get_strobe - strobe get callback 3312dd7b10b3SKristoffer KARLSSON * @kcontrol: mixer control 3313dd7b10b3SKristoffer KARLSSON * @ucontrol: control element information 3314dd7b10b3SKristoffer KARLSSON * 3315dd7b10b3SKristoffer KARLSSON * Callback get the value of a strobe mixer control. 3316dd7b10b3SKristoffer KARLSSON * 3317dd7b10b3SKristoffer KARLSSON * Returns 0 for success. 3318dd7b10b3SKristoffer KARLSSON */ 3319dd7b10b3SKristoffer KARLSSON int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, 3320dd7b10b3SKristoffer KARLSSON struct snd_ctl_elem_value *ucontrol) 3321dd7b10b3SKristoffer KARLSSON { 3322dd7b10b3SKristoffer KARLSSON struct soc_mixer_control *mc = 3323dd7b10b3SKristoffer KARLSSON (struct soc_mixer_control *)kcontrol->private_value; 3324dd7b10b3SKristoffer KARLSSON struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 3325dd7b10b3SKristoffer KARLSSON unsigned int reg = mc->reg; 3326dd7b10b3SKristoffer KARLSSON unsigned int shift = mc->shift; 3327dd7b10b3SKristoffer KARLSSON unsigned int mask = 1 << shift; 3328dd7b10b3SKristoffer KARLSSON unsigned int invert = mc->invert != 0; 3329dd7b10b3SKristoffer KARLSSON unsigned int val = snd_soc_read(codec, reg) & mask; 3330dd7b10b3SKristoffer KARLSSON 3331dd7b10b3SKristoffer KARLSSON if (shift != 0 && val != 0) 3332dd7b10b3SKristoffer KARLSSON val = val >> shift; 3333dd7b10b3SKristoffer KARLSSON ucontrol->value.enumerated.item[0] = val ^ invert; 3334dd7b10b3SKristoffer KARLSSON 3335dd7b10b3SKristoffer KARLSSON return 0; 3336dd7b10b3SKristoffer KARLSSON } 3337dd7b10b3SKristoffer KARLSSON EXPORT_SYMBOL_GPL(snd_soc_get_strobe); 3338dd7b10b3SKristoffer KARLSSON 3339dd7b10b3SKristoffer KARLSSON /** 3340dd7b10b3SKristoffer KARLSSON * snd_soc_put_strobe - strobe put callback 3341dd7b10b3SKristoffer KARLSSON * @kcontrol: mixer control 3342dd7b10b3SKristoffer KARLSSON * @ucontrol: control element information 3343dd7b10b3SKristoffer KARLSSON * 3344dd7b10b3SKristoffer KARLSSON * Callback strobe a register bit to high then low (or the inverse) 3345dd7b10b3SKristoffer KARLSSON * in one pass of a single mixer enum control. 3346dd7b10b3SKristoffer KARLSSON * 3347dd7b10b3SKristoffer KARLSSON * Returns 1 for success. 3348dd7b10b3SKristoffer KARLSSON */ 3349dd7b10b3SKristoffer KARLSSON int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, 3350dd7b10b3SKristoffer KARLSSON struct snd_ctl_elem_value *ucontrol) 3351dd7b10b3SKristoffer KARLSSON { 3352dd7b10b3SKristoffer KARLSSON struct soc_mixer_control *mc = 3353dd7b10b3SKristoffer KARLSSON (struct soc_mixer_control *)kcontrol->private_value; 3354dd7b10b3SKristoffer KARLSSON struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 3355dd7b10b3SKristoffer KARLSSON unsigned int reg = mc->reg; 3356dd7b10b3SKristoffer KARLSSON unsigned int shift = mc->shift; 3357dd7b10b3SKristoffer KARLSSON unsigned int mask = 1 << shift; 3358dd7b10b3SKristoffer KARLSSON unsigned int invert = mc->invert != 0; 3359dd7b10b3SKristoffer KARLSSON unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; 3360dd7b10b3SKristoffer KARLSSON unsigned int val1 = (strobe ^ invert) ? mask : 0; 3361dd7b10b3SKristoffer KARLSSON unsigned int val2 = (strobe ^ invert) ? 0 : mask; 3362dd7b10b3SKristoffer KARLSSON int err; 3363dd7b10b3SKristoffer KARLSSON 3364dd7b10b3SKristoffer KARLSSON err = snd_soc_update_bits_locked(codec, reg, mask, val1); 3365dd7b10b3SKristoffer KARLSSON if (err < 0) 3366dd7b10b3SKristoffer KARLSSON return err; 3367dd7b10b3SKristoffer KARLSSON 3368dd7b10b3SKristoffer KARLSSON err = snd_soc_update_bits_locked(codec, reg, mask, val2); 3369dd7b10b3SKristoffer KARLSSON return err; 3370dd7b10b3SKristoffer KARLSSON } 3371dd7b10b3SKristoffer KARLSSON EXPORT_SYMBOL_GPL(snd_soc_put_strobe); 3372dd7b10b3SKristoffer KARLSSON 3373dd7b10b3SKristoffer KARLSSON /** 33748c6529dbSLiam Girdwood * snd_soc_dai_set_sysclk - configure DAI system or master clock. 33758c6529dbSLiam Girdwood * @dai: DAI 33768c6529dbSLiam Girdwood * @clk_id: DAI specific clock ID 33778c6529dbSLiam Girdwood * @freq: new clock frequency in Hz 33788c6529dbSLiam Girdwood * @dir: new clock direction - input/output. 33798c6529dbSLiam Girdwood * 33808c6529dbSLiam Girdwood * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 33818c6529dbSLiam Girdwood */ 33828c6529dbSLiam Girdwood int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 33838c6529dbSLiam Girdwood unsigned int freq, int dir) 33848c6529dbSLiam Girdwood { 3385f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_sysclk) 3386f0fba2adSLiam Girdwood return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 3387ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_sysclk) 3388da1c6ea6SMark Brown return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, 3389ec4ee52aSMark Brown freq, dir); 33908c6529dbSLiam Girdwood else 33918c6529dbSLiam Girdwood return -EINVAL; 33928c6529dbSLiam Girdwood } 33938c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 33948c6529dbSLiam Girdwood 33958c6529dbSLiam Girdwood /** 3396ec4ee52aSMark Brown * snd_soc_codec_set_sysclk - configure CODEC system or master clock. 3397ec4ee52aSMark Brown * @codec: CODEC 3398ec4ee52aSMark Brown * @clk_id: DAI specific clock ID 3399da1c6ea6SMark Brown * @source: Source for the clock 3400ec4ee52aSMark Brown * @freq: new clock frequency in Hz 3401ec4ee52aSMark Brown * @dir: new clock direction - input/output. 3402ec4ee52aSMark Brown * 3403ec4ee52aSMark Brown * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 3404ec4ee52aSMark Brown */ 3405ec4ee52aSMark Brown int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, 3406da1c6ea6SMark Brown int source, unsigned int freq, int dir) 3407ec4ee52aSMark Brown { 3408ec4ee52aSMark Brown if (codec->driver->set_sysclk) 3409da1c6ea6SMark Brown return codec->driver->set_sysclk(codec, clk_id, source, 3410da1c6ea6SMark Brown freq, dir); 3411ec4ee52aSMark Brown else 3412ec4ee52aSMark Brown return -EINVAL; 3413ec4ee52aSMark Brown } 3414ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); 3415ec4ee52aSMark Brown 3416ec4ee52aSMark Brown /** 34178c6529dbSLiam Girdwood * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 34188c6529dbSLiam Girdwood * @dai: DAI 3419ac11a2b3SMark Brown * @div_id: DAI specific clock divider ID 34208c6529dbSLiam Girdwood * @div: new clock divisor. 34218c6529dbSLiam Girdwood * 34228c6529dbSLiam Girdwood * Configures the clock dividers. This is used to derive the best DAI bit and 34238c6529dbSLiam Girdwood * frame clocks from the system or master clock. It's best to set the DAI bit 34248c6529dbSLiam Girdwood * and frame clocks as low as possible to save system power. 34258c6529dbSLiam Girdwood */ 34268c6529dbSLiam Girdwood int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 34278c6529dbSLiam Girdwood int div_id, int div) 34288c6529dbSLiam Girdwood { 3429f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_clkdiv) 3430f0fba2adSLiam Girdwood return dai->driver->ops->set_clkdiv(dai, div_id, div); 34318c6529dbSLiam Girdwood else 34328c6529dbSLiam Girdwood return -EINVAL; 34338c6529dbSLiam Girdwood } 34348c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 34358c6529dbSLiam Girdwood 34368c6529dbSLiam Girdwood /** 34378c6529dbSLiam Girdwood * snd_soc_dai_set_pll - configure DAI PLL. 34388c6529dbSLiam Girdwood * @dai: DAI 34398c6529dbSLiam Girdwood * @pll_id: DAI specific PLL ID 344085488037SMark Brown * @source: DAI specific source for the PLL 34418c6529dbSLiam Girdwood * @freq_in: PLL input clock frequency in Hz 34428c6529dbSLiam Girdwood * @freq_out: requested PLL output clock frequency in Hz 34438c6529dbSLiam Girdwood * 34448c6529dbSLiam Girdwood * Configures and enables PLL to generate output clock based on input clock. 34458c6529dbSLiam Girdwood */ 344685488037SMark Brown int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 344785488037SMark Brown unsigned int freq_in, unsigned int freq_out) 34488c6529dbSLiam Girdwood { 3449f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_pll) 3450f0fba2adSLiam Girdwood return dai->driver->ops->set_pll(dai, pll_id, source, 345185488037SMark Brown freq_in, freq_out); 3452ec4ee52aSMark Brown else if (dai->codec && dai->codec->driver->set_pll) 3453ec4ee52aSMark Brown return dai->codec->driver->set_pll(dai->codec, pll_id, source, 3454ec4ee52aSMark Brown freq_in, freq_out); 34558c6529dbSLiam Girdwood else 34568c6529dbSLiam Girdwood return -EINVAL; 34578c6529dbSLiam Girdwood } 34588c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 34598c6529dbSLiam Girdwood 3460ec4ee52aSMark Brown /* 3461ec4ee52aSMark Brown * snd_soc_codec_set_pll - configure codec PLL. 3462ec4ee52aSMark Brown * @codec: CODEC 3463ec4ee52aSMark Brown * @pll_id: DAI specific PLL ID 3464ec4ee52aSMark Brown * @source: DAI specific source for the PLL 3465ec4ee52aSMark Brown * @freq_in: PLL input clock frequency in Hz 3466ec4ee52aSMark Brown * @freq_out: requested PLL output clock frequency in Hz 3467ec4ee52aSMark Brown * 3468ec4ee52aSMark Brown * Configures and enables PLL to generate output clock based on input clock. 3469ec4ee52aSMark Brown */ 3470ec4ee52aSMark Brown int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, 3471ec4ee52aSMark Brown unsigned int freq_in, unsigned int freq_out) 3472ec4ee52aSMark Brown { 3473ec4ee52aSMark Brown if (codec->driver->set_pll) 3474ec4ee52aSMark Brown return codec->driver->set_pll(codec, pll_id, source, 3475ec4ee52aSMark Brown freq_in, freq_out); 3476ec4ee52aSMark Brown else 3477ec4ee52aSMark Brown return -EINVAL; 3478ec4ee52aSMark Brown } 3479ec4ee52aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); 3480ec4ee52aSMark Brown 34818c6529dbSLiam Girdwood /** 34828c6529dbSLiam Girdwood * snd_soc_dai_set_fmt - configure DAI hardware audio format. 34838c6529dbSLiam Girdwood * @dai: DAI 34848c6529dbSLiam Girdwood * @fmt: SND_SOC_DAIFMT_ format value. 34858c6529dbSLiam Girdwood * 34868c6529dbSLiam Girdwood * Configures the DAI hardware format and clocking. 34878c6529dbSLiam Girdwood */ 34888c6529dbSLiam Girdwood int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 34898c6529dbSLiam Girdwood { 34905e4ba569SShawn Guo if (dai->driver == NULL) 34918c6529dbSLiam Girdwood return -EINVAL; 34925e4ba569SShawn Guo if (dai->driver->ops->set_fmt == NULL) 34935e4ba569SShawn Guo return -ENOTSUPP; 34945e4ba569SShawn Guo return dai->driver->ops->set_fmt(dai, fmt); 34958c6529dbSLiam Girdwood } 34968c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 34978c6529dbSLiam Girdwood 34988c6529dbSLiam Girdwood /** 34998c6529dbSLiam Girdwood * snd_soc_dai_set_tdm_slot - configure DAI TDM. 35008c6529dbSLiam Girdwood * @dai: DAI 3501a5479e38SDaniel Ribeiro * @tx_mask: bitmask representing active TX slots. 3502a5479e38SDaniel Ribeiro * @rx_mask: bitmask representing active RX slots. 35038c6529dbSLiam Girdwood * @slots: Number of slots in use. 3504a5479e38SDaniel Ribeiro * @slot_width: Width in bits for each slot. 35058c6529dbSLiam Girdwood * 35068c6529dbSLiam Girdwood * Configures a DAI for TDM operation. Both mask and slots are codec and DAI 35078c6529dbSLiam Girdwood * specific. 35088c6529dbSLiam Girdwood */ 35098c6529dbSLiam Girdwood int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 3510a5479e38SDaniel Ribeiro unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 35118c6529dbSLiam Girdwood { 3512f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tdm_slot) 3513f0fba2adSLiam Girdwood return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 3514a5479e38SDaniel Ribeiro slots, slot_width); 35158c6529dbSLiam Girdwood else 35168c6529dbSLiam Girdwood return -EINVAL; 35178c6529dbSLiam Girdwood } 35188c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 35198c6529dbSLiam Girdwood 35208c6529dbSLiam Girdwood /** 3521472df3cbSBarry Song * snd_soc_dai_set_channel_map - configure DAI audio channel map 3522472df3cbSBarry Song * @dai: DAI 3523472df3cbSBarry Song * @tx_num: how many TX channels 3524472df3cbSBarry Song * @tx_slot: pointer to an array which imply the TX slot number channel 3525472df3cbSBarry Song * 0~num-1 uses 3526472df3cbSBarry Song * @rx_num: how many RX channels 3527472df3cbSBarry Song * @rx_slot: pointer to an array which imply the RX slot number channel 3528472df3cbSBarry Song * 0~num-1 uses 3529472df3cbSBarry Song * 3530472df3cbSBarry Song * configure the relationship between channel number and TDM slot number. 3531472df3cbSBarry Song */ 3532472df3cbSBarry Song int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 3533472df3cbSBarry Song unsigned int tx_num, unsigned int *tx_slot, 3534472df3cbSBarry Song unsigned int rx_num, unsigned int *rx_slot) 3535472df3cbSBarry Song { 3536f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_channel_map) 3537f0fba2adSLiam Girdwood return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 3538472df3cbSBarry Song rx_num, rx_slot); 3539472df3cbSBarry Song else 3540472df3cbSBarry Song return -EINVAL; 3541472df3cbSBarry Song } 3542472df3cbSBarry Song EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 3543472df3cbSBarry Song 3544472df3cbSBarry Song /** 35458c6529dbSLiam Girdwood * snd_soc_dai_set_tristate - configure DAI system or master clock. 35468c6529dbSLiam Girdwood * @dai: DAI 35478c6529dbSLiam Girdwood * @tristate: tristate enable 35488c6529dbSLiam Girdwood * 35498c6529dbSLiam Girdwood * Tristates the DAI so that others can use it. 35508c6529dbSLiam Girdwood */ 35518c6529dbSLiam Girdwood int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 35528c6529dbSLiam Girdwood { 3553f0fba2adSLiam Girdwood if (dai->driver && dai->driver->ops->set_tristate) 3554f0fba2adSLiam Girdwood return dai->driver->ops->set_tristate(dai, tristate); 35558c6529dbSLiam Girdwood else 35568c6529dbSLiam Girdwood return -EINVAL; 35578c6529dbSLiam Girdwood } 35588c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 35598c6529dbSLiam Girdwood 35608c6529dbSLiam Girdwood /** 35618c6529dbSLiam Girdwood * snd_soc_dai_digital_mute - configure DAI system or master clock. 35628c6529dbSLiam Girdwood * @dai: DAI 35638c6529dbSLiam Girdwood * @mute: mute enable 3564da18396fSMark Brown * @direction: stream to mute 35658c6529dbSLiam Girdwood * 35668c6529dbSLiam Girdwood * Mutes the DAI DAC. 35678c6529dbSLiam Girdwood */ 3568da18396fSMark Brown int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, 3569da18396fSMark Brown int direction) 35708c6529dbSLiam Girdwood { 3571da18396fSMark Brown if (!dai->driver) 3572da18396fSMark Brown return -ENOTSUPP; 3573da18396fSMark Brown 3574da18396fSMark Brown if (dai->driver->ops->mute_stream) 3575da18396fSMark Brown return dai->driver->ops->mute_stream(dai, mute, direction); 3576da18396fSMark Brown else if (direction == SNDRV_PCM_STREAM_PLAYBACK && 3577da18396fSMark Brown dai->driver->ops->digital_mute) 3578f0fba2adSLiam Girdwood return dai->driver->ops->digital_mute(dai, mute); 35798c6529dbSLiam Girdwood else 358004570c62SMark Brown return -ENOTSUPP; 35818c6529dbSLiam Girdwood } 35828c6529dbSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 35838c6529dbSLiam Girdwood 3584c5af3a2eSMark Brown /** 3585c5af3a2eSMark Brown * snd_soc_register_card - Register a card with the ASoC core 3586c5af3a2eSMark Brown * 3587ac11a2b3SMark Brown * @card: Card to register 3588c5af3a2eSMark Brown * 3589c5af3a2eSMark Brown */ 359070a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card) 3591c5af3a2eSMark Brown { 3592b19e6e7bSMark Brown int i, ret; 3593f0fba2adSLiam Girdwood 3594c5af3a2eSMark Brown if (!card->name || !card->dev) 3595c5af3a2eSMark Brown return -EINVAL; 3596c5af3a2eSMark Brown 35975a504963SStephen Warren for (i = 0; i < card->num_links; i++) { 35985a504963SStephen Warren struct snd_soc_dai_link *link = &card->dai_link[i]; 35995a504963SStephen Warren 36005a504963SStephen Warren /* 36015a504963SStephen Warren * Codec must be specified by 1 of name or OF node, 36025a504963SStephen Warren * not both or neither. 36035a504963SStephen Warren */ 36045a504963SStephen Warren if (!!link->codec_name == !!link->codec_of_node) { 3605f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Neither/both codec" 3606f110bfc7SLiam Girdwood " name/of_node are set for %s\n", link->name); 36075a504963SStephen Warren return -EINVAL; 36085a504963SStephen Warren } 3609bc92657aSStephen Warren /* Codec DAI name must be specified */ 3610bc92657aSStephen Warren if (!link->codec_dai_name) { 3611f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: codec_dai_name not" 3612f110bfc7SLiam Girdwood " set for %s\n", link->name); 3613bc92657aSStephen Warren return -EINVAL; 3614bc92657aSStephen Warren } 36155a504963SStephen Warren 36165a504963SStephen Warren /* 36175a504963SStephen Warren * Platform may be specified by either name or OF node, but 36185a504963SStephen Warren * can be left unspecified, and a dummy platform will be used. 36195a504963SStephen Warren */ 36205a504963SStephen Warren if (link->platform_name && link->platform_of_node) { 3621f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Both platform name/of_node" 3622f110bfc7SLiam Girdwood " are set for %s\n", link->name); 36235a504963SStephen Warren return -EINVAL; 36245a504963SStephen Warren } 36255a504963SStephen Warren 36265a504963SStephen Warren /* 3627bc92657aSStephen Warren * CPU device may be specified by either name or OF node, but 3628bc92657aSStephen Warren * can be left unspecified, and will be matched based on DAI 3629bc92657aSStephen Warren * name alone.. 36305a504963SStephen Warren */ 3631bc92657aSStephen Warren if (link->cpu_name && link->cpu_of_node) { 3632f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Neither/both " 3633f110bfc7SLiam Girdwood "cpu name/of_node are set for %s\n",link->name); 3634bc92657aSStephen Warren return -EINVAL; 3635bc92657aSStephen Warren } 3636bc92657aSStephen Warren /* 3637bc92657aSStephen Warren * At least one of CPU DAI name or CPU device name/node must be 3638bc92657aSStephen Warren * specified 3639bc92657aSStephen Warren */ 3640bc92657aSStephen Warren if (!link->cpu_dai_name && 3641bc92657aSStephen Warren !(link->cpu_name || link->cpu_of_node)) { 3642f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Neither cpu_dai_name nor " 3643f110bfc7SLiam Girdwood "cpu_name/of_node are set for %s\n", link->name); 36445a504963SStephen Warren return -EINVAL; 36455a504963SStephen Warren } 36465a504963SStephen Warren } 36475a504963SStephen Warren 3648ed77cc12SMark Brown dev_set_drvdata(card->dev, card); 3649ed77cc12SMark Brown 3650111c6419SStephen Warren snd_soc_initialize_card_lists(card); 3651111c6419SStephen Warren 3652150dd2f8SVinod Koul soc_init_card_debugfs(card); 3653150dd2f8SVinod Koul 3654181a6892SMark Brown card->rtd = devm_kzalloc(card->dev, 3655181a6892SMark Brown sizeof(struct snd_soc_pcm_runtime) * 36562eea392dSJarkko Nikula (card->num_links + card->num_aux_devs), 3657f0fba2adSLiam Girdwood GFP_KERNEL); 3658f0fba2adSLiam Girdwood if (card->rtd == NULL) 3659f0fba2adSLiam Girdwood return -ENOMEM; 3660a7dbb603SLiam Girdwood card->num_rtd = 0; 36612eea392dSJarkko Nikula card->rtd_aux = &card->rtd[card->num_links]; 3662f0fba2adSLiam Girdwood 3663f0fba2adSLiam Girdwood for (i = 0; i < card->num_links; i++) 3664f0fba2adSLiam Girdwood card->rtd[i].dai_link = &card->dai_link[i]; 3665f0fba2adSLiam Girdwood 3666c5af3a2eSMark Brown INIT_LIST_HEAD(&card->list); 3667db432b41SMark Brown INIT_LIST_HEAD(&card->dapm_dirty); 3668c5af3a2eSMark Brown card->instantiated = 0; 3669f0fba2adSLiam Girdwood mutex_init(&card->mutex); 3670a73fb2dfSLiam Girdwood mutex_init(&card->dapm_mutex); 3671c5af3a2eSMark Brown 3672b19e6e7bSMark Brown ret = snd_soc_instantiate_card(card); 3673b19e6e7bSMark Brown if (ret != 0) 3674b19e6e7bSMark Brown soc_cleanup_card_debugfs(card); 3675c5af3a2eSMark Brown 3676b19e6e7bSMark Brown return ret; 3677c5af3a2eSMark Brown } 367870a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card); 3679c5af3a2eSMark Brown 3680c5af3a2eSMark Brown /** 3681c5af3a2eSMark Brown * snd_soc_unregister_card - Unregister a card with the ASoC core 3682c5af3a2eSMark Brown * 3683ac11a2b3SMark Brown * @card: Card to unregister 3684c5af3a2eSMark Brown * 3685c5af3a2eSMark Brown */ 368670a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card) 3687c5af3a2eSMark Brown { 3688b0e26485SVinod Koul if (card->instantiated) 3689b0e26485SVinod Koul soc_cleanup_card_resources(card); 3690f110bfc7SLiam Girdwood dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); 3691c5af3a2eSMark Brown 3692c5af3a2eSMark Brown return 0; 3693c5af3a2eSMark Brown } 369470a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card); 3695c5af3a2eSMark Brown 3696f0fba2adSLiam Girdwood /* 3697f0fba2adSLiam Girdwood * Simplify DAI link configuration by removing ".-1" from device names 3698f0fba2adSLiam Girdwood * and sanitizing names. 3699f0fba2adSLiam Girdwood */ 37000b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id) 3701f0fba2adSLiam Girdwood { 3702f0fba2adSLiam Girdwood char *found, name[NAME_SIZE]; 3703f0fba2adSLiam Girdwood int id1, id2; 3704f0fba2adSLiam Girdwood 3705f0fba2adSLiam Girdwood if (dev_name(dev) == NULL) 3706f0fba2adSLiam Girdwood return NULL; 3707f0fba2adSLiam Girdwood 370858818a77SDimitris Papastamos strlcpy(name, dev_name(dev), NAME_SIZE); 3709f0fba2adSLiam Girdwood 3710f0fba2adSLiam Girdwood /* are we a "%s.%d" name (platform and SPI components) */ 3711f0fba2adSLiam Girdwood found = strstr(name, dev->driver->name); 3712f0fba2adSLiam Girdwood if (found) { 3713f0fba2adSLiam Girdwood /* get ID */ 3714f0fba2adSLiam Girdwood if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { 3715f0fba2adSLiam Girdwood 3716f0fba2adSLiam Girdwood /* discard ID from name if ID == -1 */ 3717f0fba2adSLiam Girdwood if (*id == -1) 3718f0fba2adSLiam Girdwood found[strlen(dev->driver->name)] = '\0'; 3719f0fba2adSLiam Girdwood } 3720f0fba2adSLiam Girdwood 3721f0fba2adSLiam Girdwood } else { 3722f0fba2adSLiam Girdwood /* I2C component devices are named "bus-addr" */ 3723f0fba2adSLiam Girdwood if (sscanf(name, "%x-%x", &id1, &id2) == 2) { 3724f0fba2adSLiam Girdwood char tmp[NAME_SIZE]; 3725f0fba2adSLiam Girdwood 3726f0fba2adSLiam Girdwood /* create unique ID number from I2C addr and bus */ 372705899446SJarkko Nikula *id = ((id1 & 0xffff) << 16) + id2; 3728f0fba2adSLiam Girdwood 3729f0fba2adSLiam Girdwood /* sanitize component name for DAI link creation */ 3730f0fba2adSLiam Girdwood snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); 373158818a77SDimitris Papastamos strlcpy(name, tmp, NAME_SIZE); 3732f0fba2adSLiam Girdwood } else 3733f0fba2adSLiam Girdwood *id = 0; 3734f0fba2adSLiam Girdwood } 3735f0fba2adSLiam Girdwood 3736f0fba2adSLiam Girdwood return kstrdup(name, GFP_KERNEL); 3737f0fba2adSLiam Girdwood } 3738f0fba2adSLiam Girdwood 3739f0fba2adSLiam Girdwood /* 3740f0fba2adSLiam Girdwood * Simplify DAI link naming for single devices with multiple DAIs by removing 3741f0fba2adSLiam Girdwood * any ".-1" and using the DAI name (instead of device name). 3742f0fba2adSLiam Girdwood */ 3743f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev, 3744f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 3745f0fba2adSLiam Girdwood { 3746f0fba2adSLiam Girdwood if (dai_drv->name == NULL) { 3747f110bfc7SLiam Girdwood dev_err(dev, "ASoC: error - multiple DAI %s registered with" 3748f110bfc7SLiam Girdwood " no name\n", dev_name(dev)); 3749f0fba2adSLiam Girdwood return NULL; 3750f0fba2adSLiam Girdwood } 3751f0fba2adSLiam Girdwood 3752f0fba2adSLiam Girdwood return kstrdup(dai_drv->name, GFP_KERNEL); 3753f0fba2adSLiam Girdwood } 3754f0fba2adSLiam Girdwood 37559115171aSMark Brown /** 37569115171aSMark Brown * snd_soc_register_dai - Register a DAI with the ASoC core 37579115171aSMark Brown * 3758ac11a2b3SMark Brown * @dai: DAI to register 37599115171aSMark Brown */ 3760f53179c0SKuninori Morimoto static int snd_soc_register_dai(struct device *dev, 3761f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv) 37629115171aSMark Brown { 3763054880feSMark Brown struct snd_soc_codec *codec; 3764f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 37659115171aSMark Brown 3766f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev)); 37679115171aSMark Brown 3768f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3769f0fba2adSLiam Girdwood if (dai == NULL) 3770f0fba2adSLiam Girdwood return -ENOMEM; 37716335d055SEric Miao 3772f0fba2adSLiam Girdwood /* create DAI component name */ 3773f0fba2adSLiam Girdwood dai->name = fmt_single_name(dev, &dai->id); 3774f0fba2adSLiam Girdwood if (dai->name == NULL) { 3775f0fba2adSLiam Girdwood kfree(dai); 3776f0fba2adSLiam Girdwood return -ENOMEM; 3777f0fba2adSLiam Girdwood } 3778f0fba2adSLiam Girdwood 3779f0fba2adSLiam Girdwood dai->dev = dev; 3780f0fba2adSLiam Girdwood dai->driver = dai_drv; 3781be09ad90SLiam Girdwood dai->dapm.dev = dev; 3782f0fba2adSLiam Girdwood if (!dai->driver->ops) 3783f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 37849115171aSMark Brown 37859115171aSMark Brown mutex_lock(&client_mutex); 3786054880feSMark Brown 3787054880feSMark Brown list_for_each_entry(codec, &codec_list, list) { 3788054880feSMark Brown if (codec->dev == dev) { 3789f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n", 3790054880feSMark Brown dai->name, codec->name); 3791054880feSMark Brown dai->codec = codec; 3792054880feSMark Brown break; 3793054880feSMark Brown } 3794054880feSMark Brown } 3795054880feSMark Brown 37965f800080SPeter Ujfalusi if (!dai->codec) 37975f800080SPeter Ujfalusi dai->dapm.idle_bias_off = 1; 37985f800080SPeter Ujfalusi 37999115171aSMark Brown list_add(&dai->list, &dai_list); 3800054880feSMark Brown 38019115171aSMark Brown mutex_unlock(&client_mutex); 38029115171aSMark Brown 3803f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); 38049115171aSMark Brown 38059115171aSMark Brown return 0; 38069115171aSMark Brown } 38079115171aSMark Brown 38089115171aSMark Brown /** 38099115171aSMark Brown * snd_soc_unregister_dai - Unregister a DAI from the ASoC core 38109115171aSMark Brown * 3811ac11a2b3SMark Brown * @dai: DAI to unregister 38129115171aSMark Brown */ 3813f53179c0SKuninori Morimoto static void snd_soc_unregister_dai(struct device *dev) 38149115171aSMark Brown { 3815f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3816f0fba2adSLiam Girdwood 3817f0fba2adSLiam Girdwood list_for_each_entry(dai, &dai_list, list) { 3818f0fba2adSLiam Girdwood if (dev == dai->dev) 3819f0fba2adSLiam Girdwood goto found; 3820f0fba2adSLiam Girdwood } 3821f0fba2adSLiam Girdwood return; 3822f0fba2adSLiam Girdwood 3823f0fba2adSLiam Girdwood found: 38249115171aSMark Brown mutex_lock(&client_mutex); 38259115171aSMark Brown list_del(&dai->list); 38269115171aSMark Brown mutex_unlock(&client_mutex); 38279115171aSMark Brown 3828f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name); 3829f0fba2adSLiam Girdwood kfree(dai->name); 3830f0fba2adSLiam Girdwood kfree(dai); 38319115171aSMark Brown } 38329115171aSMark Brown 38339115171aSMark Brown /** 38349115171aSMark Brown * snd_soc_register_dais - Register multiple DAIs with the ASoC core 38359115171aSMark Brown * 3836ac11a2b3SMark Brown * @dai: Array of DAIs to register 3837ac11a2b3SMark Brown * @count: Number of DAIs 38389115171aSMark Brown */ 3839f53179c0SKuninori Morimoto static int snd_soc_register_dais(struct device *dev, 3840f0fba2adSLiam Girdwood struct snd_soc_dai_driver *dai_drv, size_t count) 38419115171aSMark Brown { 3842054880feSMark Brown struct snd_soc_codec *codec; 3843f0fba2adSLiam Girdwood struct snd_soc_dai *dai; 3844f0fba2adSLiam Girdwood int i, ret = 0; 3845f0fba2adSLiam Girdwood 3846f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); 38479115171aSMark Brown 38489115171aSMark Brown for (i = 0; i < count; i++) { 3849f0fba2adSLiam Girdwood 3850f0fba2adSLiam Girdwood dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3851c46e0079SAxel Lin if (dai == NULL) { 3852c46e0079SAxel Lin ret = -ENOMEM; 3853c46e0079SAxel Lin goto err; 3854c46e0079SAxel Lin } 3855f0fba2adSLiam Girdwood 3856f0fba2adSLiam Girdwood /* create DAI component name */ 3857f0fba2adSLiam Girdwood dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3858f0fba2adSLiam Girdwood if (dai->name == NULL) { 3859f0fba2adSLiam Girdwood kfree(dai); 3860f0fba2adSLiam Girdwood ret = -EINVAL; 38619115171aSMark Brown goto err; 38629115171aSMark Brown } 38639115171aSMark Brown 3864f0fba2adSLiam Girdwood dai->dev = dev; 3865f0fba2adSLiam Girdwood dai->driver = &dai_drv[i]; 38660f9141c9SMark Brown if (dai->driver->id) 38670f9141c9SMark Brown dai->id = dai->driver->id; 38680f9141c9SMark Brown else 38690f9141c9SMark Brown dai->id = i; 3870be09ad90SLiam Girdwood dai->dapm.dev = dev; 3871f0fba2adSLiam Girdwood if (!dai->driver->ops) 3872f0fba2adSLiam Girdwood dai->driver->ops = &null_dai_ops; 3873f0fba2adSLiam Girdwood 3874f0fba2adSLiam Girdwood mutex_lock(&client_mutex); 3875054880feSMark Brown 3876054880feSMark Brown list_for_each_entry(codec, &codec_list, list) { 3877054880feSMark Brown if (codec->dev == dev) { 3878f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Mapped DAI %s to " 3879f110bfc7SLiam Girdwood "CODEC %s\n", dai->name, codec->name); 3880054880feSMark Brown dai->codec = codec; 3881054880feSMark Brown break; 3882054880feSMark Brown } 3883054880feSMark Brown } 3884054880feSMark Brown 38855f800080SPeter Ujfalusi if (!dai->codec) 38865f800080SPeter Ujfalusi dai->dapm.idle_bias_off = 1; 38875f800080SPeter Ujfalusi 3888f0fba2adSLiam Girdwood list_add(&dai->list, &dai_list); 3889054880feSMark Brown 3890f0fba2adSLiam Girdwood mutex_unlock(&client_mutex); 3891f0fba2adSLiam Girdwood 3892f110bfc7SLiam Girdwood dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name); 3893f0fba2adSLiam Girdwood } 3894f0fba2adSLiam Girdwood 38959115171aSMark Brown return 0; 38969115171aSMark Brown 38979115171aSMark Brown err: 38989115171aSMark Brown for (i--; i >= 0; i--) 3899f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 39009115171aSMark Brown 39019115171aSMark Brown return ret; 39029115171aSMark Brown } 39039115171aSMark Brown 39049115171aSMark Brown /** 39059115171aSMark Brown * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core 39069115171aSMark Brown * 3907ac11a2b3SMark Brown * @dai: Array of DAIs to unregister 3908ac11a2b3SMark Brown * @count: Number of DAIs 39099115171aSMark Brown */ 3910f53179c0SKuninori Morimoto static void snd_soc_unregister_dais(struct device *dev, size_t count) 39119115171aSMark Brown { 39129115171aSMark Brown int i; 39139115171aSMark Brown 39149115171aSMark Brown for (i = 0; i < count; i++) 3915f0fba2adSLiam Girdwood snd_soc_unregister_dai(dev); 39169115171aSMark Brown } 39179115171aSMark Brown 391812a48a8cSMark Brown /** 391971a45cdaSLars-Peter Clausen * snd_soc_add_platform - Add a platform to the ASoC core 392071a45cdaSLars-Peter Clausen * @dev: The parent device for the platform 392171a45cdaSLars-Peter Clausen * @platform: The platform to add 392271a45cdaSLars-Peter Clausen * @platform_driver: The driver for the platform 392312a48a8cSMark Brown */ 392471a45cdaSLars-Peter Clausen int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, 3925d79e57dbSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 392612a48a8cSMark Brown { 3927f0fba2adSLiam Girdwood /* create platform component name */ 3928f0fba2adSLiam Girdwood platform->name = fmt_single_name(dev, &platform->id); 3929f0fba2adSLiam Girdwood if (platform->name == NULL) { 3930f0fba2adSLiam Girdwood kfree(platform); 3931f0fba2adSLiam Girdwood return -ENOMEM; 3932f0fba2adSLiam Girdwood } 3933f0fba2adSLiam Girdwood 3934f0fba2adSLiam Girdwood platform->dev = dev; 3935f0fba2adSLiam Girdwood platform->driver = platform_drv; 3936b7950641SLiam Girdwood platform->dapm.dev = dev; 3937b7950641SLiam Girdwood platform->dapm.platform = platform; 393864a648c2SLiam Girdwood platform->dapm.stream_event = platform_drv->stream_event; 3939cc22d37eSLiam Girdwood mutex_init(&platform->mutex); 394012a48a8cSMark Brown 394112a48a8cSMark Brown mutex_lock(&client_mutex); 394212a48a8cSMark Brown list_add(&platform->list, &platform_list); 394312a48a8cSMark Brown mutex_unlock(&client_mutex); 394412a48a8cSMark Brown 3945f110bfc7SLiam Girdwood dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name); 394612a48a8cSMark Brown 394712a48a8cSMark Brown return 0; 394812a48a8cSMark Brown } 394971a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_platform); 395071a45cdaSLars-Peter Clausen 395171a45cdaSLars-Peter Clausen /** 395271a45cdaSLars-Peter Clausen * snd_soc_register_platform - Register a platform with the ASoC core 395371a45cdaSLars-Peter Clausen * 395471a45cdaSLars-Peter Clausen * @platform: platform to register 395571a45cdaSLars-Peter Clausen */ 395671a45cdaSLars-Peter Clausen int snd_soc_register_platform(struct device *dev, 395771a45cdaSLars-Peter Clausen const struct snd_soc_platform_driver *platform_drv) 395871a45cdaSLars-Peter Clausen { 395971a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 396071a45cdaSLars-Peter Clausen int ret; 396171a45cdaSLars-Peter Clausen 396271a45cdaSLars-Peter Clausen dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); 396371a45cdaSLars-Peter Clausen 396471a45cdaSLars-Peter Clausen platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); 396571a45cdaSLars-Peter Clausen if (platform == NULL) 396671a45cdaSLars-Peter Clausen return -ENOMEM; 396771a45cdaSLars-Peter Clausen 396871a45cdaSLars-Peter Clausen ret = snd_soc_add_platform(dev, platform, platform_drv); 396971a45cdaSLars-Peter Clausen if (ret) 397071a45cdaSLars-Peter Clausen kfree(platform); 397171a45cdaSLars-Peter Clausen 397271a45cdaSLars-Peter Clausen return ret; 397371a45cdaSLars-Peter Clausen } 397412a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_platform); 397512a48a8cSMark Brown 397612a48a8cSMark Brown /** 397771a45cdaSLars-Peter Clausen * snd_soc_remove_platform - Remove a platform from the ASoC core 397871a45cdaSLars-Peter Clausen * @platform: the platform to remove 397971a45cdaSLars-Peter Clausen */ 398071a45cdaSLars-Peter Clausen void snd_soc_remove_platform(struct snd_soc_platform *platform) 398171a45cdaSLars-Peter Clausen { 398271a45cdaSLars-Peter Clausen mutex_lock(&client_mutex); 398371a45cdaSLars-Peter Clausen list_del(&platform->list); 398471a45cdaSLars-Peter Clausen mutex_unlock(&client_mutex); 398571a45cdaSLars-Peter Clausen 398671a45cdaSLars-Peter Clausen dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", 398771a45cdaSLars-Peter Clausen platform->name); 398871a45cdaSLars-Peter Clausen kfree(platform->name); 398971a45cdaSLars-Peter Clausen } 399071a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_remove_platform); 399171a45cdaSLars-Peter Clausen 399271a45cdaSLars-Peter Clausen struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) 399371a45cdaSLars-Peter Clausen { 399471a45cdaSLars-Peter Clausen struct snd_soc_platform *platform; 399571a45cdaSLars-Peter Clausen 399671a45cdaSLars-Peter Clausen list_for_each_entry(platform, &platform_list, list) { 399771a45cdaSLars-Peter Clausen if (dev == platform->dev) 399871a45cdaSLars-Peter Clausen return platform; 399971a45cdaSLars-Peter Clausen } 400071a45cdaSLars-Peter Clausen 400171a45cdaSLars-Peter Clausen return NULL; 400271a45cdaSLars-Peter Clausen } 400371a45cdaSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); 400471a45cdaSLars-Peter Clausen 400571a45cdaSLars-Peter Clausen /** 400612a48a8cSMark Brown * snd_soc_unregister_platform - Unregister a platform from the ASoC core 400712a48a8cSMark Brown * 4008ac11a2b3SMark Brown * @platform: platform to unregister 400912a48a8cSMark Brown */ 4010f0fba2adSLiam Girdwood void snd_soc_unregister_platform(struct device *dev) 401112a48a8cSMark Brown { 4012f0fba2adSLiam Girdwood struct snd_soc_platform *platform; 4013f0fba2adSLiam Girdwood 401471a45cdaSLars-Peter Clausen platform = snd_soc_lookup_platform(dev); 401571a45cdaSLars-Peter Clausen if (!platform) 4016f0fba2adSLiam Girdwood return; 4017f0fba2adSLiam Girdwood 401871a45cdaSLars-Peter Clausen snd_soc_remove_platform(platform); 4019f0fba2adSLiam Girdwood kfree(platform); 402012a48a8cSMark Brown } 402112a48a8cSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 402212a48a8cSMark Brown 4023151ab22cSMark Brown static u64 codec_format_map[] = { 4024151ab22cSMark Brown SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, 4025151ab22cSMark Brown SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, 4026151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, 4027151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, 4028151ab22cSMark Brown SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 4029151ab22cSMark Brown SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, 4030151ab22cSMark Brown SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 4031151ab22cSMark Brown SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, 4032151ab22cSMark Brown SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, 4033151ab22cSMark Brown SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, 4034151ab22cSMark Brown SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, 4035151ab22cSMark Brown SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, 4036151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, 4037151ab22cSMark Brown SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, 4038151ab22cSMark Brown SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE 4039151ab22cSMark Brown | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, 4040151ab22cSMark Brown }; 4041151ab22cSMark Brown 4042151ab22cSMark Brown /* Fix up the DAI formats for endianness: codecs don't actually see 4043151ab22cSMark Brown * the endianness of the data but we're using the CPU format 4044151ab22cSMark Brown * definitions which do need to include endianness so we ensure that 4045151ab22cSMark Brown * codec DAIs always have both big and little endian variants set. 4046151ab22cSMark Brown */ 4047151ab22cSMark Brown static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) 4048151ab22cSMark Brown { 4049151ab22cSMark Brown int i; 4050151ab22cSMark Brown 4051151ab22cSMark Brown for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) 4052151ab22cSMark Brown if (stream->formats & codec_format_map[i]) 4053151ab22cSMark Brown stream->formats |= codec_format_map[i]; 4054151ab22cSMark Brown } 4055151ab22cSMark Brown 40560d0cf00aSMark Brown /** 40570d0cf00aSMark Brown * snd_soc_register_codec - Register a codec with the ASoC core 40580d0cf00aSMark Brown * 4059ac11a2b3SMark Brown * @codec: codec to register 40600d0cf00aSMark Brown */ 4061f0fba2adSLiam Girdwood int snd_soc_register_codec(struct device *dev, 4062001ae4c0SMark Brown const struct snd_soc_codec_driver *codec_drv, 4063001ae4c0SMark Brown struct snd_soc_dai_driver *dai_drv, 4064001ae4c0SMark Brown int num_dai) 40650d0cf00aSMark Brown { 40663335ddcaSDimitris Papastamos size_t reg_size; 4067f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 4068f0fba2adSLiam Girdwood int ret, i; 4069151ab22cSMark Brown 4070f0fba2adSLiam Girdwood dev_dbg(dev, "codec register %s\n", dev_name(dev)); 40710d0cf00aSMark Brown 4072f0fba2adSLiam Girdwood codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 4073f0fba2adSLiam Girdwood if (codec == NULL) 4074f0fba2adSLiam Girdwood return -ENOMEM; 40750d0cf00aSMark Brown 4076f0fba2adSLiam Girdwood /* create CODEC component name */ 4077f0fba2adSLiam Girdwood codec->name = fmt_single_name(dev, &codec->id); 4078f0fba2adSLiam Girdwood if (codec->name == NULL) { 4079f790b94dSKuninori Morimoto ret = -ENOMEM; 4080f790b94dSKuninori Morimoto goto fail_codec; 4081151ab22cSMark Brown } 4082151ab22cSMark Brown 408323bbce34SDimitris Papastamos if (codec_drv->compress_type) 408423bbce34SDimitris Papastamos codec->compress_type = codec_drv->compress_type; 408523bbce34SDimitris Papastamos else 408623bbce34SDimitris Papastamos codec->compress_type = SND_SOC_FLAT_COMPRESSION; 408723bbce34SDimitris Papastamos 4088c3acec26SMark Brown codec->write = codec_drv->write; 4089c3acec26SMark Brown codec->read = codec_drv->read; 40901500b7b5SDimitris Papastamos codec->volatile_register = codec_drv->volatile_register; 40911500b7b5SDimitris Papastamos codec->readable_register = codec_drv->readable_register; 40928020454cSDimitris Papastamos codec->writable_register = codec_drv->writable_register; 40935124e69eSMark Brown codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time; 4094ce6120ccSLiam Girdwood codec->dapm.bias_level = SND_SOC_BIAS_OFF; 4095ce6120ccSLiam Girdwood codec->dapm.dev = dev; 4096ce6120ccSLiam Girdwood codec->dapm.codec = codec; 4097474b62d6SMark Brown codec->dapm.seq_notifier = codec_drv->seq_notifier; 409864a648c2SLiam Girdwood codec->dapm.stream_event = codec_drv->stream_event; 4099f0fba2adSLiam Girdwood codec->dev = dev; 4100f0fba2adSLiam Girdwood codec->driver = codec_drv; 4101f0fba2adSLiam Girdwood codec->num_dai = num_dai; 4102f0fba2adSLiam Girdwood mutex_init(&codec->mutex); 4103f0fba2adSLiam Girdwood 41047a30a3dbSDimitris Papastamos /* allocate CODEC register cache */ 41057a30a3dbSDimitris Papastamos if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 41063335ddcaSDimitris Papastamos reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 4107aea170a0SDimitris Papastamos codec->reg_size = reg_size; 41083335ddcaSDimitris Papastamos /* it is necessary to make a copy of the default register cache 41093335ddcaSDimitris Papastamos * because in the case of using a compression type that requires 4110f6e65744SBill Pemberton * the default register cache to be marked as the 41113335ddcaSDimitris Papastamos * kernel might have freed the array by the time we initialize 41123335ddcaSDimitris Papastamos * the cache. 41133335ddcaSDimitris Papastamos */ 41142aa86323SDimitris Papastamos if (codec_drv->reg_cache_default) { 41153335ddcaSDimitris Papastamos codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, 41163335ddcaSDimitris Papastamos reg_size, GFP_KERNEL); 41173335ddcaSDimitris Papastamos if (!codec->reg_def_copy) { 41183335ddcaSDimitris Papastamos ret = -ENOMEM; 4119f790b94dSKuninori Morimoto goto fail_codec_name; 41207a30a3dbSDimitris Papastamos } 41217a30a3dbSDimitris Papastamos } 41222aa86323SDimitris Papastamos } 41237a30a3dbSDimitris Papastamos 41241500b7b5SDimitris Papastamos if (codec_drv->reg_access_size && codec_drv->reg_access_default) { 41251500b7b5SDimitris Papastamos if (!codec->volatile_register) 41261500b7b5SDimitris Papastamos codec->volatile_register = snd_soc_default_volatile_register; 41271500b7b5SDimitris Papastamos if (!codec->readable_register) 41281500b7b5SDimitris Papastamos codec->readable_register = snd_soc_default_readable_register; 41298020454cSDimitris Papastamos if (!codec->writable_register) 41308020454cSDimitris Papastamos codec->writable_register = snd_soc_default_writable_register; 41311500b7b5SDimitris Papastamos } 41321500b7b5SDimitris Papastamos 4133f0fba2adSLiam Girdwood for (i = 0; i < num_dai; i++) { 4134f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].playback); 4135f0fba2adSLiam Girdwood fixup_codec_formats(&dai_drv[i].capture); 4136f0fba2adSLiam Girdwood } 4137f0fba2adSLiam Girdwood 4138054880feSMark Brown mutex_lock(&client_mutex); 4139054880feSMark Brown list_add(&codec->list, &codec_list); 4140054880feSMark Brown mutex_unlock(&client_mutex); 4141054880feSMark Brown 414226b01ccdSMark Brown /* register any DAIs */ 4143f0fba2adSLiam Girdwood ret = snd_soc_register_dais(dev, dai_drv, num_dai); 41445acd7dfbSKuninori Morimoto if (ret < 0) { 41455acd7dfbSKuninori Morimoto dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret); 41465acd7dfbSKuninori Morimoto goto fail_codec_name; 414726b01ccdSMark Brown } 4148f0fba2adSLiam Girdwood 4149f110bfc7SLiam Girdwood dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name); 41500d0cf00aSMark Brown return 0; 4151f0fba2adSLiam Girdwood 4152f790b94dSKuninori Morimoto fail_codec_name: 4153e1328a83SKuninori Morimoto mutex_lock(&client_mutex); 4154e1328a83SKuninori Morimoto list_del(&codec->list); 4155e1328a83SKuninori Morimoto mutex_unlock(&client_mutex); 4156e1328a83SKuninori Morimoto 4157f0fba2adSLiam Girdwood kfree(codec->name); 4158f790b94dSKuninori Morimoto fail_codec: 4159f0fba2adSLiam Girdwood kfree(codec); 4160f0fba2adSLiam Girdwood return ret; 41610d0cf00aSMark Brown } 41620d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_register_codec); 41630d0cf00aSMark Brown 41640d0cf00aSMark Brown /** 41650d0cf00aSMark Brown * snd_soc_unregister_codec - Unregister a codec from the ASoC core 41660d0cf00aSMark Brown * 4167ac11a2b3SMark Brown * @codec: codec to unregister 41680d0cf00aSMark Brown */ 4169f0fba2adSLiam Girdwood void snd_soc_unregister_codec(struct device *dev) 41700d0cf00aSMark Brown { 4171f0fba2adSLiam Girdwood struct snd_soc_codec *codec; 4172f0fba2adSLiam Girdwood 4173f0fba2adSLiam Girdwood list_for_each_entry(codec, &codec_list, list) { 4174f0fba2adSLiam Girdwood if (dev == codec->dev) 4175f0fba2adSLiam Girdwood goto found; 4176f0fba2adSLiam Girdwood } 4177f0fba2adSLiam Girdwood return; 4178f0fba2adSLiam Girdwood 4179f0fba2adSLiam Girdwood found: 41805acd7dfbSKuninori Morimoto snd_soc_unregister_dais(dev, codec->num_dai); 4181f0fba2adSLiam Girdwood 41820d0cf00aSMark Brown mutex_lock(&client_mutex); 41830d0cf00aSMark Brown list_del(&codec->list); 41840d0cf00aSMark Brown mutex_unlock(&client_mutex); 41850d0cf00aSMark Brown 4186f110bfc7SLiam Girdwood dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name); 4187f0fba2adSLiam Girdwood 41887a30a3dbSDimitris Papastamos snd_soc_cache_exit(codec); 41893335ddcaSDimitris Papastamos kfree(codec->reg_def_copy); 41901aafcd4dSDimitris Papastamos kfree(codec->name); 4191f0fba2adSLiam Girdwood kfree(codec); 41920d0cf00aSMark Brown } 41930d0cf00aSMark Brown EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 41940d0cf00aSMark Brown 4195030e79f6SKuninori Morimoto 4196030e79f6SKuninori Morimoto /** 4197030e79f6SKuninori Morimoto * snd_soc_register_component - Register a component with the ASoC core 4198030e79f6SKuninori Morimoto * 4199030e79f6SKuninori Morimoto */ 4200030e79f6SKuninori Morimoto int snd_soc_register_component(struct device *dev, 4201030e79f6SKuninori Morimoto const struct snd_soc_component_driver *cmpnt_drv, 4202030e79f6SKuninori Morimoto struct snd_soc_dai_driver *dai_drv, 4203030e79f6SKuninori Morimoto int num_dai) 4204030e79f6SKuninori Morimoto { 4205030e79f6SKuninori Morimoto struct snd_soc_component *cmpnt; 4206030e79f6SKuninori Morimoto int ret; 4207030e79f6SKuninori Morimoto 4208030e79f6SKuninori Morimoto dev_dbg(dev, "component register %s\n", dev_name(dev)); 4209030e79f6SKuninori Morimoto 4210030e79f6SKuninori Morimoto cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL); 4211030e79f6SKuninori Morimoto if (!cmpnt) { 4212030e79f6SKuninori Morimoto dev_err(dev, "ASoC: Failed to allocate memory\n"); 4213030e79f6SKuninori Morimoto return -ENOMEM; 4214030e79f6SKuninori Morimoto } 4215030e79f6SKuninori Morimoto 4216030e79f6SKuninori Morimoto cmpnt->name = fmt_single_name(dev, &cmpnt->id); 4217030e79f6SKuninori Morimoto if (!cmpnt->name) { 4218030e79f6SKuninori Morimoto dev_err(dev, "ASoC: Failed to simplifying name\n"); 4219030e79f6SKuninori Morimoto return -ENOMEM; 4220030e79f6SKuninori Morimoto } 4221030e79f6SKuninori Morimoto 4222030e79f6SKuninori Morimoto cmpnt->dev = dev; 4223030e79f6SKuninori Morimoto cmpnt->driver = cmpnt_drv; 4224030e79f6SKuninori Morimoto cmpnt->num_dai = num_dai; 4225030e79f6SKuninori Morimoto 4226a1422b8cSKuninori Morimoto /* 4227a1422b8cSKuninori Morimoto * snd_soc_register_dai() uses fmt_single_name(), and 4228a1422b8cSKuninori Morimoto * snd_soc_register_dais() uses fmt_multiple_name() 4229a1422b8cSKuninori Morimoto * for dai->name which is used for name based matching 4230a1422b8cSKuninori Morimoto */ 4231a1422b8cSKuninori Morimoto if (1 == num_dai) 4232a1422b8cSKuninori Morimoto ret = snd_soc_register_dai(dev, dai_drv); 4233a1422b8cSKuninori Morimoto else 4234030e79f6SKuninori Morimoto ret = snd_soc_register_dais(dev, dai_drv, num_dai); 4235030e79f6SKuninori Morimoto if (ret < 0) { 4236030e79f6SKuninori Morimoto dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); 4237030e79f6SKuninori Morimoto goto error_component_name; 4238030e79f6SKuninori Morimoto } 4239030e79f6SKuninori Morimoto 4240030e79f6SKuninori Morimoto mutex_lock(&client_mutex); 4241030e79f6SKuninori Morimoto list_add(&cmpnt->list, &component_list); 4242030e79f6SKuninori Morimoto mutex_unlock(&client_mutex); 4243030e79f6SKuninori Morimoto 4244030e79f6SKuninori Morimoto dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name); 4245030e79f6SKuninori Morimoto 4246030e79f6SKuninori Morimoto return ret; 4247030e79f6SKuninori Morimoto 4248030e79f6SKuninori Morimoto error_component_name: 4249030e79f6SKuninori Morimoto kfree(cmpnt->name); 4250030e79f6SKuninori Morimoto 4251030e79f6SKuninori Morimoto return ret; 4252030e79f6SKuninori Morimoto } 42532e1cc199SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_register_component); 4254030e79f6SKuninori Morimoto 4255030e79f6SKuninori Morimoto /** 4256030e79f6SKuninori Morimoto * snd_soc_unregister_component - Unregister a component from the ASoC core 4257030e79f6SKuninori Morimoto * 4258030e79f6SKuninori Morimoto */ 4259030e79f6SKuninori Morimoto void snd_soc_unregister_component(struct device *dev) 4260030e79f6SKuninori Morimoto { 4261030e79f6SKuninori Morimoto struct snd_soc_component *cmpnt; 4262030e79f6SKuninori Morimoto 4263030e79f6SKuninori Morimoto list_for_each_entry(cmpnt, &component_list, list) { 4264030e79f6SKuninori Morimoto if (dev == cmpnt->dev) 4265030e79f6SKuninori Morimoto goto found; 4266030e79f6SKuninori Morimoto } 4267030e79f6SKuninori Morimoto return; 4268030e79f6SKuninori Morimoto 4269030e79f6SKuninori Morimoto found: 4270030e79f6SKuninori Morimoto snd_soc_unregister_dais(dev, cmpnt->num_dai); 4271030e79f6SKuninori Morimoto 4272030e79f6SKuninori Morimoto mutex_lock(&client_mutex); 4273030e79f6SKuninori Morimoto list_del(&cmpnt->list); 4274030e79f6SKuninori Morimoto mutex_unlock(&client_mutex); 4275030e79f6SKuninori Morimoto 4276030e79f6SKuninori Morimoto dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name); 4277030e79f6SKuninori Morimoto kfree(cmpnt->name); 4278030e79f6SKuninori Morimoto } 42792e1cc199SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_unregister_component); 4280030e79f6SKuninori Morimoto 4281bec4fa05SStephen Warren /* Retrieve a card's name from device tree */ 4282bec4fa05SStephen Warren int snd_soc_of_parse_card_name(struct snd_soc_card *card, 4283bec4fa05SStephen Warren const char *propname) 4284bec4fa05SStephen Warren { 4285bec4fa05SStephen Warren struct device_node *np = card->dev->of_node; 4286bec4fa05SStephen Warren int ret; 4287bec4fa05SStephen Warren 4288bec4fa05SStephen Warren ret = of_property_read_string_index(np, propname, 0, &card->name); 4289bec4fa05SStephen Warren /* 4290bec4fa05SStephen Warren * EINVAL means the property does not exist. This is fine providing 4291bec4fa05SStephen Warren * card->name was previously set, which is checked later in 4292bec4fa05SStephen Warren * snd_soc_register_card. 4293bec4fa05SStephen Warren */ 4294bec4fa05SStephen Warren if (ret < 0 && ret != -EINVAL) { 4295bec4fa05SStephen Warren dev_err(card->dev, 4296f110bfc7SLiam Girdwood "ASoC: Property '%s' could not be read: %d\n", 4297bec4fa05SStephen Warren propname, ret); 4298bec4fa05SStephen Warren return ret; 4299bec4fa05SStephen Warren } 4300bec4fa05SStephen Warren 4301bec4fa05SStephen Warren return 0; 4302bec4fa05SStephen Warren } 4303bec4fa05SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 4304bec4fa05SStephen Warren 4305a4a54dd5SStephen Warren int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 4306a4a54dd5SStephen Warren const char *propname) 4307a4a54dd5SStephen Warren { 4308a4a54dd5SStephen Warren struct device_node *np = card->dev->of_node; 4309a4a54dd5SStephen Warren int num_routes; 4310a4a54dd5SStephen Warren struct snd_soc_dapm_route *routes; 4311a4a54dd5SStephen Warren int i, ret; 4312a4a54dd5SStephen Warren 4313a4a54dd5SStephen Warren num_routes = of_property_count_strings(np, propname); 4314c34ce320SRichard Zhao if (num_routes < 0 || num_routes & 1) { 4315f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Property '%s' does not exist or its" 4316f110bfc7SLiam Girdwood " length is not even\n", propname); 4317a4a54dd5SStephen Warren return -EINVAL; 4318a4a54dd5SStephen Warren } 4319a4a54dd5SStephen Warren num_routes /= 2; 4320a4a54dd5SStephen Warren if (!num_routes) { 4321f110bfc7SLiam Girdwood dev_err(card->dev, "ASoC: Property '%s's length is zero\n", 4322a4a54dd5SStephen Warren propname); 4323a4a54dd5SStephen Warren return -EINVAL; 4324a4a54dd5SStephen Warren } 4325a4a54dd5SStephen Warren 4326a4a54dd5SStephen Warren routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), 4327a4a54dd5SStephen Warren GFP_KERNEL); 4328a4a54dd5SStephen Warren if (!routes) { 4329a4a54dd5SStephen Warren dev_err(card->dev, 4330f110bfc7SLiam Girdwood "ASoC: Could not allocate DAPM route table\n"); 4331a4a54dd5SStephen Warren return -EINVAL; 4332a4a54dd5SStephen Warren } 4333a4a54dd5SStephen Warren 4334a4a54dd5SStephen Warren for (i = 0; i < num_routes; i++) { 4335a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 4336a4a54dd5SStephen Warren 2 * i, &routes[i].sink); 4337a4a54dd5SStephen Warren if (ret) { 4338c871bd0bSMark Brown dev_err(card->dev, 4339c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 4340c871bd0bSMark Brown propname, 2 * i, ret); 4341a4a54dd5SStephen Warren return -EINVAL; 4342a4a54dd5SStephen Warren } 4343a4a54dd5SStephen Warren ret = of_property_read_string_index(np, propname, 4344a4a54dd5SStephen Warren (2 * i) + 1, &routes[i].source); 4345a4a54dd5SStephen Warren if (ret) { 4346a4a54dd5SStephen Warren dev_err(card->dev, 4347c871bd0bSMark Brown "ASoC: Property '%s' index %d could not be read: %d\n", 4348c871bd0bSMark Brown propname, (2 * i) + 1, ret); 4349a4a54dd5SStephen Warren return -EINVAL; 4350a4a54dd5SStephen Warren } 4351a4a54dd5SStephen Warren } 4352a4a54dd5SStephen Warren 4353a4a54dd5SStephen Warren card->num_dapm_routes = num_routes; 4354a4a54dd5SStephen Warren card->dapm_routes = routes; 4355a4a54dd5SStephen Warren 4356a4a54dd5SStephen Warren return 0; 4357a4a54dd5SStephen Warren } 4358a4a54dd5SStephen Warren EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); 4359a4a54dd5SStephen Warren 4360a7930ed4SKuninori Morimoto unsigned int snd_soc_of_parse_daifmt(struct device_node *np, 4361a7930ed4SKuninori Morimoto const char *prefix) 4362a7930ed4SKuninori Morimoto { 4363a7930ed4SKuninori Morimoto int ret, i; 4364a7930ed4SKuninori Morimoto char prop[128]; 4365a7930ed4SKuninori Morimoto unsigned int format = 0; 4366a7930ed4SKuninori Morimoto int bit, frame; 4367a7930ed4SKuninori Morimoto const char *str; 4368a7930ed4SKuninori Morimoto struct { 4369a7930ed4SKuninori Morimoto char *name; 4370a7930ed4SKuninori Morimoto unsigned int val; 4371a7930ed4SKuninori Morimoto } of_fmt_table[] = { 4372a7930ed4SKuninori Morimoto { "i2s", SND_SOC_DAIFMT_I2S }, 4373a7930ed4SKuninori Morimoto { "right_j", SND_SOC_DAIFMT_RIGHT_J }, 4374a7930ed4SKuninori Morimoto { "left_j", SND_SOC_DAIFMT_LEFT_J }, 4375a7930ed4SKuninori Morimoto { "dsp_a", SND_SOC_DAIFMT_DSP_A }, 4376a7930ed4SKuninori Morimoto { "dsp_b", SND_SOC_DAIFMT_DSP_B }, 4377a7930ed4SKuninori Morimoto { "ac97", SND_SOC_DAIFMT_AC97 }, 4378a7930ed4SKuninori Morimoto { "pdm", SND_SOC_DAIFMT_PDM}, 4379a7930ed4SKuninori Morimoto { "msb", SND_SOC_DAIFMT_MSB }, 4380a7930ed4SKuninori Morimoto { "lsb", SND_SOC_DAIFMT_LSB }, 4381a7930ed4SKuninori Morimoto }; 4382a7930ed4SKuninori Morimoto 4383a7930ed4SKuninori Morimoto if (!prefix) 4384a7930ed4SKuninori Morimoto prefix = ""; 4385a7930ed4SKuninori Morimoto 4386a7930ed4SKuninori Morimoto /* 4387a7930ed4SKuninori Morimoto * check "[prefix]format = xxx" 4388a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_FORMAT_MASK area 4389a7930ed4SKuninori Morimoto */ 4390a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sformat", prefix); 4391a7930ed4SKuninori Morimoto ret = of_property_read_string(np, prop, &str); 4392a7930ed4SKuninori Morimoto if (ret == 0) { 4393a7930ed4SKuninori Morimoto for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { 4394a7930ed4SKuninori Morimoto if (strcmp(str, of_fmt_table[i].name) == 0) { 4395a7930ed4SKuninori Morimoto format |= of_fmt_table[i].val; 4396a7930ed4SKuninori Morimoto break; 4397a7930ed4SKuninori Morimoto } 4398a7930ed4SKuninori Morimoto } 4399a7930ed4SKuninori Morimoto } 4400a7930ed4SKuninori Morimoto 4401a7930ed4SKuninori Morimoto /* 44028c2d6a9fSKuninori Morimoto * check "[prefix]continuous-clock" 4403a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_CLOCK_MASK area 4404a7930ed4SKuninori Morimoto */ 44058c2d6a9fSKuninori Morimoto snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); 44068c2d6a9fSKuninori Morimoto if (of_get_property(np, prop, NULL)) 44078c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_CONT; 44088c2d6a9fSKuninori Morimoto else 44098c2d6a9fSKuninori Morimoto format |= SND_SOC_DAIFMT_GATED; 4410a7930ed4SKuninori Morimoto 4411a7930ed4SKuninori Morimoto /* 4412a7930ed4SKuninori Morimoto * check "[prefix]bitclock-inversion" 4413a7930ed4SKuninori Morimoto * check "[prefix]frame-inversion" 4414a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_INV_MASK area 4415a7930ed4SKuninori Morimoto */ 4416a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); 4417a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 4418a7930ed4SKuninori Morimoto 4419a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); 4420a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 4421a7930ed4SKuninori Morimoto 4422a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 4423a7930ed4SKuninori Morimoto case 0x11: 4424a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_IF; 4425a7930ed4SKuninori Morimoto break; 4426a7930ed4SKuninori Morimoto case 0x10: 4427a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_IB_NF; 4428a7930ed4SKuninori Morimoto break; 4429a7930ed4SKuninori Morimoto case 0x01: 4430a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_NB_IF; 4431a7930ed4SKuninori Morimoto break; 4432a7930ed4SKuninori Morimoto default: 4433a7930ed4SKuninori Morimoto /* SND_SOC_DAIFMT_NB_NF is default */ 4434a7930ed4SKuninori Morimoto break; 4435a7930ed4SKuninori Morimoto } 4436a7930ed4SKuninori Morimoto 4437a7930ed4SKuninori Morimoto /* 4438a7930ed4SKuninori Morimoto * check "[prefix]bitclock-master" 4439a7930ed4SKuninori Morimoto * check "[prefix]frame-master" 4440a7930ed4SKuninori Morimoto * SND_SOC_DAIFMT_MASTER_MASK area 4441a7930ed4SKuninori Morimoto */ 4442a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); 4443a7930ed4SKuninori Morimoto bit = !!of_get_property(np, prop, NULL); 4444a7930ed4SKuninori Morimoto 4445a7930ed4SKuninori Morimoto snprintf(prop, sizeof(prop), "%sframe-master", prefix); 4446a7930ed4SKuninori Morimoto frame = !!of_get_property(np, prop, NULL); 4447a7930ed4SKuninori Morimoto 4448a7930ed4SKuninori Morimoto switch ((bit << 4) + frame) { 4449a7930ed4SKuninori Morimoto case 0x11: 4450a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFM; 4451a7930ed4SKuninori Morimoto break; 4452a7930ed4SKuninori Morimoto case 0x10: 4453a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBM_CFS; 4454a7930ed4SKuninori Morimoto break; 4455a7930ed4SKuninori Morimoto case 0x01: 4456a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFM; 4457a7930ed4SKuninori Morimoto break; 4458a7930ed4SKuninori Morimoto default: 4459a7930ed4SKuninori Morimoto format |= SND_SOC_DAIFMT_CBS_CFS; 4460a7930ed4SKuninori Morimoto break; 4461a7930ed4SKuninori Morimoto } 4462a7930ed4SKuninori Morimoto 4463a7930ed4SKuninori Morimoto return format; 4464a7930ed4SKuninori Morimoto } 4465a7930ed4SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); 4466a7930ed4SKuninori Morimoto 4467c9b3a40fSTakashi Iwai static int __init snd_soc_init(void) 4468db2a4165SFrank Mandarino { 4469384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 44708a9dab1aSMark Brown snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); 44718a9dab1aSMark Brown if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { 44720837fc62SFabio Estevam pr_warn("ASoC: Failed to create debugfs directory\n"); 44738a9dab1aSMark Brown snd_soc_debugfs_root = NULL; 4474384c89e2SMark Brown } 4475c3c5a19aSMark Brown 44768a9dab1aSMark Brown if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, 4477c3c5a19aSMark Brown &codec_list_fops)) 4478c3c5a19aSMark Brown pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); 4479c3c5a19aSMark Brown 44808a9dab1aSMark Brown if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, 4481f3208780SMark Brown &dai_list_fops)) 4482f3208780SMark Brown pr_warn("ASoC: Failed to create DAI list debugfs file\n"); 448319c7ac27SMark Brown 44848a9dab1aSMark Brown if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, 448519c7ac27SMark Brown &platform_list_fops)) 448619c7ac27SMark Brown pr_warn("ASoC: Failed to create platform list debugfs file\n"); 4487384c89e2SMark Brown #endif 4488384c89e2SMark Brown 4489fb257897SMark Brown snd_soc_util_init(); 4490fb257897SMark Brown 4491db2a4165SFrank Mandarino return platform_driver_register(&soc_driver); 4492db2a4165SFrank Mandarino } 44934abe8e16SMark Brown module_init(snd_soc_init); 4494db2a4165SFrank Mandarino 44957d8c16a6SMark Brown static void __exit snd_soc_exit(void) 4496db2a4165SFrank Mandarino { 4497fb257897SMark Brown snd_soc_util_exit(); 4498fb257897SMark Brown 4499384c89e2SMark Brown #ifdef CONFIG_DEBUG_FS 45008a9dab1aSMark Brown debugfs_remove_recursive(snd_soc_debugfs_root); 4501384c89e2SMark Brown #endif 4502db2a4165SFrank Mandarino platform_driver_unregister(&soc_driver); 4503db2a4165SFrank Mandarino } 4504db2a4165SFrank Mandarino module_exit(snd_soc_exit); 4505db2a4165SFrank Mandarino 4506db2a4165SFrank Mandarino /* Module information */ 4507d331124dSLiam Girdwood MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); 4508db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core"); 4509db2a4165SFrank Mandarino MODULE_LICENSE("GPL"); 45108b45a209SKay Sievers MODULE_ALIAS("platform:soc-audio"); 4511