From: Mark Brown Date: Mon, 8 Dec 2014 13:11:45 +0000 (+0000) Subject: Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ad193x', 'asoc/topic... X-Git-Tag: v3.19-rc1~119^2~20^2~23 X-Git-Url: https://git.kernelconcepts.de/?a=commitdiff_plain;h=0a7e4ca1aad65458edebb718e1b915d1899056e7;hp=-c;p=karo-tx-linux.git Merge remote-tracking branches 'asoc/topic/ac97', 'asoc/topic/ad193x', 'asoc/topic/adau1373' and 'asoc/topic/adau17x1' into asoc-next --- 0a7e4ca1aad65458edebb718e1b915d1899056e7 diff --combined include/sound/soc-dai.h index 373d1775ecba,a3738be45563,e8b3080d196a,e8b3080d196a,e8b3080d196a..2df96b1384c7 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@@@@@ -206,7 -206,6 -206,7 -206,7 -206,7 +206,6 @@@@@@ struct snd_soc_dai_driver /* DAI description */ const char *name; unsigned int id; - --- int ac97_control; unsigned int base; /* DAI driver callbacks */ @@@@@@ -216,6 -215,8 -216,6 -216,6 -216,6 +215,8 @@@@@@ int (*resume)(struct snd_soc_dai *dai); /* compress dai */ bool compress_dai; + +++ /* DAI is also used for the control bus */ + +++ bool bus_control; /* ops */ const struct snd_soc_dai_ops *ops; @@@@@@ -241,7 -242,6 -241,7 -241,7 -241,7 +242,6 @@@@@@ struct snd_soc_dai const char *name; int id; struct device *dev; - --- void *ac97_pdata; /* platform_data for the ac97 codec */ /* driver ops */ struct snd_soc_dai_driver *driver; @@@@@@ -268,6 -268,7 -268,7 -268,7 -268,7 +268,6 @@@@@@ unsigned int sample_bits; /* parent platform/codec */ ---- struct snd_soc_platform *platform; struct snd_soc_codec *codec; struct snd_soc_component *component; @@@@@@ -275,6 -276,8 -276,8 -276,8 -276,8 +275,6 @@@@@@ unsigned int tx_mask; unsigned int rx_mask; ---- struct snd_soc_card *card; ---- struct list_head list; }; diff --combined include/sound/soc.h index 38769cc900c9,b53234835936,7ba7130037a0,7ba7130037a0,7ba7130037a0..a765c684bd7b --- a/include/sound/soc.h +++ b/include/sound/soc.h @@@@@@ -36,11 -36,6 -36,6 -36,6 -36,6 +36,11 @@@@@@ {.reg = xreg, .rreg = xreg, .shift = shift_left, \ .rshift = shift_right, .max = xmax, .platform_max = xmax, \ .invert = xinvert, .autodisable = xautodisable}) ++++#define SOC_DOUBLE_S_VALUE(xreg, shift_left, shift_right, xmin, xmax, xsign_bit, xinvert, xautodisable) \ ++++ ((unsigned long)&(struct soc_mixer_control) \ ++++ {.reg = xreg, .rreg = xreg, .shift = shift_left, \ ++++ .rshift = shift_right, .min = xmin, .max = xmax, .platform_max = xmax, \ ++++ .sign_bit = xsign_bit, .invert = xinvert, .autodisable = xautodisable}) #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert, xautodisable) \ SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert, xautodisable) #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \ @@@@@@ -176,9 -171,11 -171,11 -171,11 -171,11 +176,9 @@@@@@ .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ SNDRV_CTL_ELEM_ACCESS_READWRITE, \ .tlv.p = (tlv_array), \ ---- .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \ ---- .put = snd_soc_put_volsw_s8, \ ---- .private_value = (unsigned long)&(struct soc_mixer_control) \ ---- {.reg = xreg, .min = xmin, .max = xmax, \ ---- .platform_max = xmax} } ++++ .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ ++++ .put = snd_soc_put_volsw, \ ++++ .private_value = SOC_DOUBLE_S_VALUE(xreg, 0, 8, xmin, xmax, 7, 0, 0) } #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \ { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ .items = xitems, .texts = xtexts, \ @@@@@@ -369,8 -366,6 -366,8 -366,8 -366,8 +369,6 @@@@@@ struct snd_soc_jack_gpio typedef int (*hw_write_t)(void *,const char* ,int); - ---extern struct snd_ac97_bus_ops *soc_ac97_ops; - --- enum snd_soc_pcm_subclass { SND_SOC_PCM_CLASS_PCM = 0, SND_SOC_PCM_CLASS_BE = 1, @@@@@@ -412,9 -407,13 -409,13 -409,13 -409,13 +410,9 @@@@@@ int devm_snd_soc_register_component(str const struct snd_soc_component_driver *cmpnt_drv, struct snd_soc_dai_driver *dai_drv, int num_dai); void snd_soc_unregister_component(struct device *dev); ----int snd_soc_cache_sync(struct snd_soc_codec *codec); int snd_soc_cache_init(struct snd_soc_codec *codec); int snd_soc_cache_exit(struct snd_soc_codec *codec); ----int snd_soc_cache_write(struct snd_soc_codec *codec, ---- unsigned int reg, unsigned int value); ----int snd_soc_cache_read(struct snd_soc_codec *codec, ---- unsigned int reg, unsigned int *value); ++++ int snd_soc_platform_read(struct snd_soc_platform *platform, unsigned int reg); int snd_soc_platform_write(struct snd_soc_platform *platform, @@@@@@ -499,14 -498,28 -500,14 -500,14 -500,14 +497,28 @@@@@@ int snd_soc_update_bits_locked(struct s int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned int reg, unsigned int mask, unsigned int value); - ---int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, - --- struct snd_ac97_bus_ops *ops, int num); - ---void snd_soc_free_ac97_codec(struct snd_soc_codec *codec); + +++#ifdef CONFIG_SND_SOC_AC97_BUS + +++struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec); + +++void snd_soc_free_ac97_codec(struct snd_ac97 *ac97); int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops); int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, struct platform_device *pdev); + +++extern struct snd_ac97_bus_ops *soc_ac97_ops; + +++#else + +++static inline int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, + +++ struct platform_device *pdev) + +++{ + +++ return 0; + +++} + +++ + +++static inline int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops) + +++{ + +++ return 0; + +++} + +++#endif + +++ /* *Controls */ @@@@@@ -544,6 -557,12 -545,12 -545,12 -545,12 +556,6 @@@@@@ int snd_soc_get_volsw_sx(struct snd_kco struct snd_ctl_elem_value *ucontrol); int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); ----int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, ---- struct snd_ctl_elem_info *uinfo); ----int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, ---- struct snd_ctl_elem_value *ucontrol); ----int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, ---- struct snd_ctl_elem_value *ucontrol); int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, @@@@@@ -778,17 -797,16 -785,19 -785,19 -785,19 +790,14 @@@@@@ struct snd_soc_codec struct list_head card_list; /* runtime */ - --- struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ unsigned int cache_bypass:1; /* Suppress access to the cache */ unsigned int suspended:1; /* Codec is in suspend PM state */ - --- unsigned int ac97_registered:1; /* Codec has been AC97 registered */ - --- unsigned int ac97_created:1; /* Codec has been created by SoC */ unsigned int cache_init:1; /* codec cache has been initialized */ ---- u32 cache_sync; /* Cache needs to be synced to hardware */ /* codec IO */ void *control_data; /* codec control (i2c/3wire) data */ hw_write_t hw_write; void *reg_cache; ---- struct mutex cache_rw_mutex; /* component */ struct snd_soc_component component; @@@@@@ -851,6 -869,8 -860,8 -860,8 -860,8 +860,6 @@@@@@ struct snd_soc_platform_driver int (*probe)(struct snd_soc_platform *); int (*remove)(struct snd_soc_platform *); ---- int (*suspend)(struct snd_soc_dai *dai); ---- int (*resume)(struct snd_soc_dai *dai); struct snd_soc_component_driver component_driver; /* pcm creation and destruction */ @@@@@@ -875,7 -895,7 -886,7 -886,7 -886,7 +884,7 @@@@@@ struct snd_soc_dai_link_component { const char *name; ---- const struct device_node *of_node; ++++ struct device_node *of_node; const char *dai_name; }; @@@@@@ -883,6 -903,8 -894,8 -894,8 -894,8 +892,6 @@@@@@ struct snd_soc_platform struct device *dev; const struct snd_soc_platform_driver *driver; ---- unsigned int suspended:1; /* platform is suspended */ ---- struct list_head list; struct snd_soc_component component; @@@@@@ -977,7 -999,7 -990,7 -990,7 -990,7 +986,7 @@@@@@ struct snd_soc_codec_conf * DT/OF node, but not both. */ const char *dev_name; ---- const struct device_node *of_node; ++++ struct device_node *of_node; /* * optional map of kcontrol, widget and path name prefixes that are @@@@@@ -994,7 -1016,7 -1007,7 -1007,7 -1007,7 +1003,7 @@@@@@ struct snd_soc_aux_dev * DT/OF node, but not both. */ const char *codec_name; ---- const struct device_node *codec_of_node; ++++ struct device_node *codec_of_node; /* codec/machine specific init - e.g. add machine controls */ int (*init)(struct snd_soc_component *component); @@@@@@ -1251,17 -1273,6 -1264,6 -1264,6 -1264,6 +1260,17 @@@@@@ unsigned int snd_soc_read(struct snd_so int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int val); ++++/** ++++ * snd_soc_cache_sync() - Sync the register cache with the hardware ++++ * @codec: CODEC to sync ++++ * ++++ * Note: This function will call regcache_sync() ++++ */ ++++static inline int snd_soc_cache_sync(struct snd_soc_codec *codec) ++++{ ++++ return regcache_sync(codec->component.regmap); ++++} ++++ /* component IO */ int snd_soc_component_read(struct snd_soc_component *component, unsigned int reg, unsigned int *val); @@@@@@ -1275,6 -1286,45 -1277,6 -1277,6 -1277,6 +1284,45 @@@@@@ void snd_soc_component_async_complete(s int snd_soc_component_test_bits(struct snd_soc_component *component, unsigned int reg, unsigned int mask, unsigned int value); + +++#ifdef CONFIG_REGMAP + +++ + +++void snd_soc_component_init_regmap(struct snd_soc_component *component, + +++ struct regmap *regmap); + +++void snd_soc_component_exit_regmap(struct snd_soc_component *component); + +++ + +++/** + +++ * snd_soc_codec_init_regmap() - Initialize regmap instance for the CODEC + +++ * @codec: The CODEC for which to initialize the regmap instance + +++ * @regmap: The regmap instance that should be used by the CODEC + +++ * + +++ * This function allows deferred assignment of the regmap instance that is + +++ * associated with the CODEC. Only use this if the regmap instance is not yet + +++ * ready when the CODEC is registered. The function must also be called before + +++ * the first IO attempt of the CODEC. + +++ */ + +++static inline void snd_soc_codec_init_regmap(struct snd_soc_codec *codec, + +++ struct regmap *regmap) + +++{ + +++ snd_soc_component_init_regmap(&codec->component, regmap); + +++} + +++ + +++/** + +++ * snd_soc_codec_exit_regmap() - De-initialize regmap instance for the CODEC + +++ * @codec: The CODEC for which to de-initialize the regmap instance + +++ * + +++ * Calls regmap_exit() on the regmap instance associated to the CODEC and + +++ * removes the regmap instance from the CODEC. + +++ * + +++ * This function should only be used if snd_soc_codec_init_regmap() was used to + +++ * initialize the regmap instance. + +++ */ + +++static inline void snd_soc_codec_exit_regmap(struct snd_soc_codec *codec) + +++{ + +++ snd_soc_component_exit_regmap(&codec->component); + +++} + +++ + +++#endif + +++ /* device driver data */ static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card, diff --combined sound/soc/Makefile index 2a043804a2bc,0fded1bb613f,534714a1ca44,534714a1ca44,534714a1ca44..865e090c8061 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile @@@@@@ -1,10 -1,14 -1,10 -1,10 -1,10 +1,14 @@@@@@ snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o ----snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o ++++snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) snd-soc-core-objs += soc-generic-dmaengine-pcm.o endif + +++ifneq ($(CONFIG_SND_SOC_AC97_BUS),) + +++snd-soc-core-objs += soc-ac97.o + +++endif + +++ obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ obj-$(CONFIG_SND_SOC) += generic/ @@@@@@ -26,6 -30,7 -26,7 -26,7 -26,7 +30,6 @@@@@@ obj-$(CONFIG_SND_SOC) += kirkwood obj-$(CONFIG_SND_SOC) += pxa/ obj-$(CONFIG_SND_SOC) += rockchip/ obj-$(CONFIG_SND_SOC) += samsung/ ----obj-$(CONFIG_SND_SOC) += s6000/ obj-$(CONFIG_SND_SOC) += sh/ obj-$(CONFIG_SND_SOC) += sirf/ obj-$(CONFIG_SND_SOC) += spear/ diff --combined sound/soc/codecs/adau1761.c index 91f60282fd2f,5518ebd6947c,5518ebd6947c,5518ebd6947c,3dddb286d08d..16093dc89441 --- a/sound/soc/codecs/adau1761.c +++ b/sound/soc/codecs/adau1761.c @@@@@@ -255,7 -255,7 -255,7 -255,7 -255,8 +255,8 @@@@@@ static const struct snd_kcontrol_new ad static int adau1761_dejitter_fixup(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { ---- struct adau *adau = snd_soc_codec_get_drvdata(w->codec); ++++ struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); ++++ struct adau *adau = snd_soc_codec_get_drvdata(codec); /* After any power changes have been made the dejitter circuit * has to be reinitialized. */ @@@@@@ -405,7 -405,6 -405,6 -405,6 -406,6 +406,7 @@@@@@ static const struct snd_soc_dapm_widge 2, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("Slew Clock", ADAU1761_CLK_ENABLE0, 6, 0, NULL, 0), ++++ SND_SOC_DAPM_SUPPLY("ALC Clock", ADAU1761_CLK_ENABLE0, 5, 0, NULL, 0), SND_SOC_DAPM_SUPPLY_S("Digital Clock 0", 1, ADAU1761_CLK_ENABLE1, 0, 0, NULL, 0), @@@@@@ -437,9 -436,6 -436,6 -436,6 -437,6 +438,9 @@@@@@ static const struct snd_soc_dapm_route { "Right Playback Mixer", NULL, "Slew Clock" }, { "Left Playback Mixer", NULL, "Slew Clock" }, ++++ { "Left Input Mixer", NULL, "ALC Clock" }, ++++ { "Right Input Mixer", NULL, "ALC Clock" }, ++++ { "Digital Clock 0", NULL, "SYSCLK" }, { "Digital Clock 1", NULL, "SYSCLK" }, }; diff --combined sound/soc/soc-core.c index d8d5449cc48e,1edc519d6286,4c8f8a23a0e9,4c8f8a23a0e9,4c8f8a23a0e9..e0d3b6f109c4 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@@@@@ -34,9 -34,6 -34,9 -34,9 -34,9 +34,6 @@@@@@ #include #include #include - ---#include - ---#include - ---#include #include #include #include @@@@@@ -69,16 -66,6 -69,16 -69,16 -69,16 +66,6 @@@@@@ static int pmdown_time = 5000 module_param(pmdown_time, int, 0); MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); - ---struct snd_ac97_reset_cfg { - --- struct pinctrl *pctl; - --- struct pinctrl_state *pstate_reset; - --- struct pinctrl_state *pstate_warm_reset; - --- struct pinctrl_state *pstate_run; - --- int gpio_sdata; - --- int gpio_sync; - --- int gpio_reset; - ---}; - --- /* returns the minimum number of bytes needed to represent * a particular given value */ static int min_bytes_needed(unsigned long val) @@@@@@ -309,6 -296,9 -309,9 -309,9 -309,9 +296,6 @@@@@@ static void soc_init_codec_debugfs(stru { struct snd_soc_codec *codec = snd_soc_component_to_codec(component); ---- debugfs_create_bool("cache_sync", 0444, codec->component.debugfs_root, ---- &codec->cache_sync); ---- codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, codec->component.debugfs_root, codec, &codec_reg_fops); @@@@@@ -496,40 -486,6 -499,40 -499,40 -499,40 +483,6 @@@@@@ struct snd_soc_pcm_runtime *snd_soc_get } EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); - ---#ifdef CONFIG_SND_SOC_AC97_BUS - ---/* unregister ac97 codec */ - ---static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) - ---{ - --- if (codec->ac97->dev.bus) - --- device_unregister(&codec->ac97->dev); - --- return 0; - ---} - --- - ---/* stop no dev release warning */ - ---static void soc_ac97_device_release(struct device *dev){} - --- - ---/* register ac97 codec to bus */ - ---static int soc_ac97_dev_register(struct snd_soc_codec *codec) - ---{ - --- int err; - --- - --- codec->ac97->dev.bus = &ac97_bus_type; - --- codec->ac97->dev.parent = codec->component.card->dev; - --- codec->ac97->dev.release = soc_ac97_device_release; - --- - --- dev_set_name(&codec->ac97->dev, "%d-%d:%s", - --- codec->component.card->snd_card->number, 0, - --- codec->component.name); - --- err = device_register(&codec->ac97->dev); - --- if (err < 0) { - --- dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); - --- codec->ac97->dev.bus = NULL; - --- return err; - --- } - --- return 0; - ---} - ---#endif - --- static void codec2codec_close_delayed_work(struct work_struct *work) { /* Currently nothing to do for c2c links @@@@@@ -589,12 -545,17 -592,17 -592,17 -592,17 +542,12 @@@@@@ int snd_soc_suspend(struct device *dev for (i = 0; i < card->num_rtd; i++) { struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; ---- struct snd_soc_platform *platform = card->rtd[i].platform; if (card->rtd[i].dai_link->ignore_suspend) continue; - --- if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) + +++ if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control) cpu_dai->driver->suspend(cpu_dai); ---- if (platform->driver->suspend && !platform->suspended) { ---- platform->driver->suspend(cpu_dai); ---- platform->suspended = 1; ---- } } /* close any waiting streams and save state */ @@@@@@ -621,8 -582,8 -629,8 -629,8 -629,8 +574,8 @@@@@@ SND_SOC_DAPM_STREAM_SUSPEND); } ---- /* Recheck all analogue paths too */ ---- dapm_mark_io_dirty(&card->dapm); ++++ /* Recheck all endpoints too, their state is affected by suspend */ ++++ dapm_mark_endpoints_dirty(card); snd_soc_dapm_sync(&card->dapm); /* suspend all CODECs */ @@@@@@ -648,6 -609,7 -656,7 -656,7 -656,7 +601,6 @@@@@@ if (codec->driver->suspend) codec->driver->suspend(codec); codec->suspended = 1; ---- codec->cache_sync = 1; if (codec->component.regmap) regcache_mark_dirty(codec->component.regmap); /* deactivate pins to sleep state */ @@@@@@ -667,7 -629,7 -676,7 -676,7 -676,7 +620,7 @@@@@@ if (card->rtd[i].dai_link->ignore_suspend) continue; - --- if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) + +++ if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control) cpu_dai->driver->suspend(cpu_dai); /* deactivate pins to sleep state */ @@@@@@ -703,14 -665,14 -712,14 -712,14 -712,14 +656,14 @@@@@@ static void soc_resume_deferred(struct if (card->resume_pre) card->resume_pre(card); - --- /* resume AC97 DAIs */ + +++ /* resume control bus DAIs */ for (i = 0; i < card->num_rtd; i++) { struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; if (card->rtd[i].dai_link->ignore_suspend) continue; - --- if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) + +++ if (cpu_dai->driver->resume && cpu_dai->driver->bus_control) cpu_dai->driver->resume(cpu_dai); } @@@@@@ -766,12 -728,17 -775,17 -775,17 -775,17 +719,12 @@@@@@ for (i = 0; i < card->num_rtd; i++) { struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; ---- struct snd_soc_platform *platform = card->rtd[i].platform; if (card->rtd[i].dai_link->ignore_suspend) continue; - --- if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) + +++ if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control) cpu_dai->driver->resume(cpu_dai); ---- if (platform->driver->resume && platform->suspended) { ---- platform->driver->resume(cpu_dai); ---- platform->suspended = 0; ---- } } if (card->resume_post) @@@@@@ -782,8 -749,8 -796,8 -796,8 -796,8 +735,8 @@@@@@ /* userspace can access us now we are back as we were before */ snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); ---- /* Recheck all analogue paths too */ ---- dapm_mark_io_dirty(&card->dapm); ++++ /* Recheck all endpoints too, their state is affected by suspend */ ++++ dapm_mark_endpoints_dirty(card); snd_soc_dapm_sync(&card->dapm); } @@@@@@ -791,7 -758,8 -805,7 -805,7 -805,7 +744,8 @@@@@@ int snd_soc_resume(struct device *dev) { struct snd_soc_card *card = dev_get_drvdata(dev); - --- int i, ac97_control = 0; + +++ bool bus_control = false; + +++ int i; /* If the card is not initialized yet there is nothing to do */ if (!card->instantiated) @@@@@@ -814,17 -782,18 -828,17 -828,17 -828,17 +768,18 @@@@@@ } } - --- /* AC97 devices might have other drivers hanging off them so - --- * need to resume immediately. Other drivers don't have that - --- * problem and may take a substantial amount of time to resume + +++ /* + +++ * DAIs that also act as the control bus master might have other drivers + +++ * hanging off them so need to resume immediately. Other drivers don't + +++ * have that problem and may take a substantial amount of time to resume * due to I/O costs and anti-pop so handle them out of line. */ for (i = 0; i < card->num_rtd; i++) { struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; - --- ac97_control |= cpu_dai->driver->ac97_control; + +++ bus_control |= cpu_dai->driver->bus_control; } - --- if (ac97_control) { - --- dev_dbg(dev, "ASoC: Resuming AC97 immediately\n"); + +++ if (bus_control) { + +++ dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); soc_resume_deferred(&card->deferred_resume_work); } else { dev_dbg(dev, "ASoC: Scheduling resume work\n"); @@@@@@ -870,7 -839,7 -884,7 -884,7 -884,7 +825,7 @@@@@@ static struct snd_soc_dai *snd_soc_find list_for_each_entry(component, &component_list, list) { if (dlc->of_node && component->dev->of_node != dlc->of_node) continue; ---- if (dlc->name && strcmp(dev_name(component->dev), dlc->name)) ++++ if (dlc->name && strcmp(component->name, dlc->name)) continue; list_for_each_entry(dai, &component->dai_list, list) { if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) @@@@@@ -1237,22 -1206,25 -1251,25 -1251,25 -1251,25 +1192,22 @@@@@@ static int soc_probe_link_components(st return 0; } ----static int soc_probe_codec_dai(struct snd_soc_card *card, ---- struct snd_soc_dai *codec_dai, ---- int order) ++++static int soc_probe_dai(struct snd_soc_dai *dai, int order) { int ret; ---- if (!codec_dai->probed && codec_dai->driver->probe_order == order) { ---- if (codec_dai->driver->probe) { ---- ret = codec_dai->driver->probe(codec_dai); ++++ if (!dai->probed && dai->driver->probe_order == order) { ++++ if (dai->driver->probe) { ++++ ret = dai->driver->probe(dai); if (ret < 0) { ---- dev_err(codec_dai->dev, ---- "ASoC: failed to probe CODEC DAI %s: %d\n", ---- codec_dai->name, ret); ++++ dev_err(dai->dev, ++++ "ASoC: failed to probe DAI %s: %d\n", ++++ dai->name, ret); return ret; } } ---- /* mark codec_dai as probed and add to card dai list */ ---- codec_dai->probed = 1; ++++ dai->probed = 1; } return 0; @@@@@@ -1302,22 -1274,40 -1319,40 -1319,40 -1319,40 +1257,22 @@@@@@ static int soc_probe_link_dais(struct s { struct snd_soc_dai_link *dai_link = &card->dai_link[num]; struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; ---- struct snd_soc_platform *platform = rtd->platform; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int i, ret; dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", card->name, num, order); ---- /* config components */ ---- cpu_dai->platform = platform; ---- cpu_dai->card = card; ---- for (i = 0; i < rtd->num_codecs; i++) ---- rtd->codec_dais[i]->card = card; ---- /* set default power off timeout */ rtd->pmdown_time = pmdown_time; ---- /* probe the cpu_dai */ ---- if (!cpu_dai->probed && ---- cpu_dai->driver->probe_order == order) { ---- if (cpu_dai->driver->probe) { ---- ret = cpu_dai->driver->probe(cpu_dai); ---- if (ret < 0) { ---- dev_err(cpu_dai->dev, ---- "ASoC: failed to probe CPU DAI %s: %d\n", ---- cpu_dai->name, ret); ---- return ret; ---- } ---- } ---- cpu_dai->probed = 1; ---- } ++++ ret = soc_probe_dai(cpu_dai, order); ++++ if (ret) ++++ return ret; /* probe the CODEC DAI */ for (i = 0; i < rtd->num_codecs; i++) { ---- ret = soc_probe_codec_dai(card, rtd->codec_dais[i], order); ++++ ret = soc_probe_dai(rtd->codec_dais[i], order); if (ret) return ret; } @@@@@@ -1387,84 -1377,9 -1422,84 -1422,84 -1422,84 +1342,9 @@@@@@ } } - --- /* add platform data for AC97 devices */ - --- for (i = 0; i < rtd->num_codecs; i++) { - --- if (rtd->codec_dais[i]->driver->ac97_control) - --- snd_ac97_dev_add_pdata(rtd->codec_dais[i]->codec->ac97, - --- rtd->cpu_dai->ac97_pdata); --- } --- --- return 0; ---} --- ---#ifdef CONFIG_SND_SOC_AC97_BUS ---static int soc_register_ac97_codec(struct snd_soc_codec *codec, --- struct snd_soc_dai *codec_dai) ---{ --- int ret; --- --- /* Only instantiate AC97 if not already done by the adaptor --- * for the generic AC97 subsystem. --- */ --- if (codec_dai->driver->ac97_control && !codec->ac97_registered) { --- /* --- * It is possible that the AC97 device is already registered to --- * the device subsystem. This happens when the device is created --- * via snd_ac97_mixer(). Currently only SoC codec that does so --- * is the generic AC97 glue but others migh emerge. --- * --- * In those cases we don't try to register the device again. --- */ --- if (!codec->ac97_created) --- return 0; --- --- ret = soc_ac97_dev_register(codec); --- if (ret < 0) { --- dev_err(codec->dev, --- "ASoC: AC97 device register failed: %d\n", ret); --- return ret; --- } --- --- codec->ac97_registered = 1; --- } --- return 0; ---} --- ---static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) ---{ --- if (codec->ac97_registered) { --- soc_ac97_dev_unregister(codec); --- codec->ac97_registered = 0; --- } ---} --- ---static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) ---{ --- int i, ret; --- --- for (i = 0; i < rtd->num_codecs; i++) { --- struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; --- --- ret = soc_register_ac97_codec(codec_dai->codec, codec_dai); --- if (ret) { --- while (--i >= 0) --- soc_unregister_ac97_codec(codec_dai->codec); --- return ret; --- } - --- } - --- return 0; } - #ifdef CONFIG_SND_SOC_AC97_BUS - static int soc_register_ac97_codec(struct snd_soc_codec *codec, - struct snd_soc_dai *codec_dai) - { - int ret; - - /* Only instantiate AC97 if not already done by the adaptor - * for the generic AC97 subsystem. - */ - if (codec_dai->driver->ac97_control && !codec->ac97_registered) { - /* - * It is possible that the AC97 device is already registered to - * the device subsystem. This happens when the device is created - * via snd_ac97_mixer(). Currently only SoC codec that does so - * is the generic AC97 glue but others migh emerge. - * - * In those cases we don't try to register the device again. - */ - if (!codec->ac97_created) - return 0; - - ret = soc_ac97_dev_register(codec); - if (ret < 0) { - dev_err(codec->dev, - "ASoC: AC97 device register failed: %d\n", ret); - return ret; - } - - codec->ac97_registered = 1; - } - return 0; - } - - static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) - { - if (codec->ac97_registered) { - soc_ac97_dev_unregister(codec); - codec->ac97_registered = 0; - } - } - - static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) - { - int i, ret; - - for (i = 0; i < rtd->num_codecs; i++) { - struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; - - ret = soc_register_ac97_codec(codec_dai->codec, codec_dai); - if (ret) { - while (--i >= 0) - soc_unregister_ac97_codec(codec_dai->codec); - return ret; - } - } - - return 0; - } - - ---static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) - ---{ - --- int i; - --- - --- for (i = 0; i < rtd->num_codecs; i++) - --- soc_unregister_ac97_codec(rtd->codec_dais[i]->codec); - ---} - ---#endif - --- static int soc_bind_aux_dev(struct snd_soc_card *card, int num) { struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; @@@@@@ -1758,20 -1673,6 -1793,20 -1793,20 -1793,20 +1638,6 @@@@@@ static int snd_soc_instantiate_card(str goto probe_aux_dev_err; } - ---#ifdef CONFIG_SND_SOC_AC97_BUS - --- /* register any AC97 codecs */ - --- for (i = 0; i < card->num_rtd; i++) { - --- ret = soc_register_ac97_dai_link(&card->rtd[i]); - --- if (ret < 0) { - --- dev_err(card->dev, - --- "ASoC: failed to register AC97: %d\n", ret); - --- while (--i >= 0) - --- soc_unregister_ac97_dai_link(&card->rtd[i]); - --- goto probe_aux_dev_err; - --- } - --- } - ---#endif - --- card->instantiated = 1; snd_soc_dapm_sync(&card->dapm); mutex_unlock(&card->mutex); @@@@@@ -1913,216 -1814,6 -1948,216 -1948,216 -1948,216 +1779,6 @@@@@@ static struct platform_driver soc_drive .remove = soc_remove, }; - ---/** - --- * snd_soc_new_ac97_codec - initailise AC97 device - --- * @codec: audio codec - --- * @ops: AC97 bus operations - --- * @num: AC97 codec number - --- * - --- * Initialises AC97 codec resources for use by ad-hoc devices only. - --- */ - ---int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, - --- struct snd_ac97_bus_ops *ops, int num) - ---{ - --- codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); - --- if (codec->ac97 == NULL) - --- return -ENOMEM; - --- - --- codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); - --- if (codec->ac97->bus == NULL) { - --- kfree(codec->ac97); - --- codec->ac97 = NULL; - --- return -ENOMEM; - --- } - --- - --- codec->ac97->bus->ops = ops; - --- codec->ac97->num = num; - --- - --- /* - --- * Mark the AC97 device to be created by us. This way we ensure that the - --- * device will be registered with the device subsystem later on. - --- */ - --- codec->ac97_created = 1; - --- - --- return 0; - ---} - ---EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); - --- - ---static struct snd_ac97_reset_cfg snd_ac97_rst_cfg; - --- - ---static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97) - ---{ - --- struct pinctrl *pctl = snd_ac97_rst_cfg.pctl; - --- - --- pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset); - --- - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1); - --- - --- udelay(10); - --- - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0); - --- - --- pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run); - --- msleep(2); - ---} - --- - ---static void snd_soc_ac97_reset(struct snd_ac97 *ac97) - ---{ - --- struct pinctrl *pctl = snd_ac97_rst_cfg.pctl; - --- - --- pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset); - --- - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0); - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0); - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0); - --- - --- udelay(10); - --- - --- gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1); - --- - --- pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run); - --- msleep(2); - ---} - --- - ---static int snd_soc_ac97_parse_pinctl(struct device *dev, - --- struct snd_ac97_reset_cfg *cfg) - ---{ - --- struct pinctrl *p; - --- struct pinctrl_state *state; - --- int gpio; - --- int ret; - --- - --- p = devm_pinctrl_get(dev); - --- if (IS_ERR(p)) { - --- dev_err(dev, "Failed to get pinctrl\n"); - --- return PTR_ERR(p); - --- } - --- cfg->pctl = p; - --- - --- state = pinctrl_lookup_state(p, "ac97-reset"); - --- if (IS_ERR(state)) { - --- dev_err(dev, "Can't find pinctrl state ac97-reset\n"); - --- return PTR_ERR(state); - --- } - --- cfg->pstate_reset = state; - --- - --- state = pinctrl_lookup_state(p, "ac97-warm-reset"); - --- if (IS_ERR(state)) { - --- dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n"); - --- return PTR_ERR(state); - --- } - --- cfg->pstate_warm_reset = state; - --- - --- state = pinctrl_lookup_state(p, "ac97-running"); - --- if (IS_ERR(state)) { - --- dev_err(dev, "Can't find pinctrl state ac97-running\n"); - --- return PTR_ERR(state); - --- } - --- cfg->pstate_run = state; - --- - --- gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0); - --- if (gpio < 0) { - --- dev_err(dev, "Can't find ac97-sync gpio\n"); - --- return gpio; - --- } - --- ret = devm_gpio_request(dev, gpio, "AC97 link sync"); - --- if (ret) { - --- dev_err(dev, "Failed requesting ac97-sync gpio\n"); - --- return ret; - --- } - --- cfg->gpio_sync = gpio; - --- - --- gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1); - --- if (gpio < 0) { - --- dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio); - --- return gpio; - --- } - --- ret = devm_gpio_request(dev, gpio, "AC97 link sdata"); - --- if (ret) { - --- dev_err(dev, "Failed requesting ac97-sdata gpio\n"); - --- return ret; - --- } - --- cfg->gpio_sdata = gpio; - --- - --- gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2); - --- if (gpio < 0) { - --- dev_err(dev, "Can't find ac97-reset gpio\n"); - --- return gpio; - --- } - --- ret = devm_gpio_request(dev, gpio, "AC97 link reset"); - --- if (ret) { - --- dev_err(dev, "Failed requesting ac97-reset gpio\n"); - --- return ret; - --- } - --- cfg->gpio_reset = gpio; - --- - --- return 0; - ---} - --- - ---struct snd_ac97_bus_ops *soc_ac97_ops; - ---EXPORT_SYMBOL_GPL(soc_ac97_ops); - --- - ---int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops) - ---{ - --- if (ops == soc_ac97_ops) - --- return 0; - --- - --- if (soc_ac97_ops && ops) - --- return -EBUSY; - --- - --- soc_ac97_ops = ops; - --- - --- return 0; - ---} - ---EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops); - --- - ---/** - --- * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions - --- * - --- * This function sets the reset and warm_reset properties of ops and parses - --- * the device node of pdev to get pinctrl states and gpio numbers to use. - --- */ - ---int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, - --- struct platform_device *pdev) - ---{ - --- struct device *dev = &pdev->dev; - --- struct snd_ac97_reset_cfg cfg; - --- int ret; - --- - --- ret = snd_soc_ac97_parse_pinctl(dev, &cfg); - --- if (ret) - --- return ret; - --- - --- ret = snd_soc_set_ac97_ops(ops); - --- if (ret) - --- return ret; - --- - --- ops->warm_reset = snd_soc_ac97_warm_reset; - --- ops->reset = snd_soc_ac97_reset; - --- - --- snd_ac97_rst_cfg = cfg; - --- return 0; - ---} - ---EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset); - --- - ---/** - --- * snd_soc_free_ac97_codec - free AC97 codec device - --- * @codec: audio codec - --- * - --- * Frees AC97 codec device resources. - --- */ - ---void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) - ---{ - ---#ifdef CONFIG_SND_SOC_AC97_BUS - --- soc_unregister_ac97_codec(codec); - ---#endif - --- kfree(codec->ac97->bus); - --- kfree(codec->ac97); - --- codec->ac97 = NULL; - --- codec->ac97_created = 0; - ---} - ---EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); - --- /** * snd_soc_cnew - create new control * @_template: control template @@@@@@ -2291,99 -1982,1113 -2326,1113 -2326,1113 -2326,1113 +1947,99 @@@@@@ EXPORT_SYMBOL_GPL(snd_soc_add_card_cont int snd_soc_add_dai_controls(struct snd_soc_dai *dai, const struct snd_kcontrol_new *controls, int num_controls) { ---- struct snd_card *card = dai->card->snd_card; ++++ struct snd_card *card = dai->component->card->snd_card; return snd_soc_add_controls(card, dai->dev, controls, num_controls, NULL, dai); } EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); - /** - * snd_soc_info_enum_double - enumerated double mixer info callback - * @kcontrol: mixer control - * @uinfo: control element information - * - * Callback to provide information about a double enumerated - * mixer control. - * - * Returns 0 for success. - */ - int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; - - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; - uinfo->count = e->shift_l == e->shift_r ? 1 : 2; - uinfo->value.enumerated.items = e->items; - - if (uinfo->value.enumerated.item >= e->items) - uinfo->value.enumerated.item = e->items - 1; - strlcpy(uinfo->value.enumerated.name, - e->texts[uinfo->value.enumerated.item], - sizeof(uinfo->value.enumerated.name)); - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); - - /** - * snd_soc_get_enum_double - enumerated double mixer get callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to get the value of a double enumerated mixer. - * - * Returns 0 for success. - */ - int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; - unsigned int val, item; - unsigned int reg_val; - int ret; - - ret = snd_soc_component_read(component, e->reg, ®_val); - if (ret) - return ret; - val = (reg_val >> e->shift_l) & e->mask; - item = snd_soc_enum_val_to_item(e, val); - ucontrol->value.enumerated.item[0] = item; - if (e->shift_l != e->shift_r) { - val = (reg_val >> e->shift_l) & e->mask; - item = snd_soc_enum_val_to_item(e, val); - ucontrol->value.enumerated.item[1] = item; - } - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); - - /** - * snd_soc_put_enum_double - enumerated double mixer put callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to set the value of a double enumerated mixer. - * - * Returns 0 for success. - */ - int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; - unsigned int *item = ucontrol->value.enumerated.item; - unsigned int val; - unsigned int mask; - - if (item[0] >= e->items) - return -EINVAL; - val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; - mask = e->mask << e->shift_l; - if (e->shift_l != e->shift_r) { - if (item[1] >= e->items) - return -EINVAL; - val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; - mask |= e->mask << e->shift_r; - } - - return snd_soc_component_update_bits(component, e->reg, mask, val); - } - EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); - - /** - * snd_soc_read_signed - Read a codec register and interprete as signed value - * @component: component - * @reg: Register to read - * @mask: Mask to use after shifting the register value - * @shift: Right shift of register value - * @sign_bit: Bit that describes if a number is negative or not. - * @signed_val: Pointer to where the read value should be stored - * - * This functions reads a codec register. The register value is shifted right - * by 'shift' bits and masked with the given 'mask'. Afterwards it translates - * the given registervalue into a signed integer if sign_bit is non-zero. - * - * Returns 0 on sucess, otherwise an error value - */ - static int snd_soc_read_signed(struct snd_soc_component *component, - unsigned int reg, unsigned int mask, unsigned int shift, - unsigned int sign_bit, int *signed_val) - { - int ret; - unsigned int val; - - ret = snd_soc_component_read(component, reg, &val); - if (ret < 0) - return ret; - - val = (val >> shift) & mask; - - if (!sign_bit) { - *signed_val = val; - return 0; - } - - /* non-negative number */ - if (!(val & BIT(sign_bit))) { - *signed_val = val; - return 0; - } - - ret = val; - - /* - * The register most probably does not contain a full-sized int. - * Instead we have an arbitrary number of bits in a signed - * representation which has to be translated into a full-sized int. - * This is done by filling up all bits above the sign-bit. - */ - ret |= ~((int)(BIT(sign_bit) - 1)); - - *signed_val = ret; - - return 0; - } - - /** - * snd_soc_info_volsw - single mixer info callback - * @kcontrol: mixer control - * @uinfo: control element information - * - * Callback to provide information about a single mixer control, or a double - * mixer control that spans 2 registers. - * - * Returns 0 for success. - */ - int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - int platform_max; - - if (!mc->platform_max) - mc->platform_max = mc->max; - platform_max = mc->platform_max; - - if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - else - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - - uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = platform_max - mc->min; - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_info_volsw); - - /** - * snd_soc_get_volsw - single mixer get callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to get the value of a single mixer control, or a double mixer - * control that spans 2 registers. - * - * Returns 0 for success. - */ - int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int reg2 = mc->rreg; - unsigned int shift = mc->shift; - unsigned int rshift = mc->rshift; - int max = mc->max; - int min = mc->min; - int sign_bit = mc->sign_bit; - unsigned int mask = (1 << fls(max)) - 1; - unsigned int invert = mc->invert; - int val; - int ret; - - if (sign_bit) - mask = BIT(sign_bit + 1) - 1; - - ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val); - if (ret) - return ret; - - ucontrol->value.integer.value[0] = val - min; - if (invert) - ucontrol->value.integer.value[0] = - max - ucontrol->value.integer.value[0]; - - if (snd_soc_volsw_is_stereo(mc)) { - if (reg == reg2) - ret = snd_soc_read_signed(component, reg, mask, rshift, - sign_bit, &val); - else - ret = snd_soc_read_signed(component, reg2, mask, shift, - sign_bit, &val); - if (ret) - return ret; - - ucontrol->value.integer.value[1] = val - min; - if (invert) - ucontrol->value.integer.value[1] = - max - ucontrol->value.integer.value[1]; - } - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_volsw); - - /** - * snd_soc_put_volsw - single mixer put callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to set the value of a single mixer control, or a double mixer - * control that spans 2 registers. - * - * Returns 0 for success. - */ - int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int reg2 = mc->rreg; - unsigned int shift = mc->shift; - unsigned int rshift = mc->rshift; - int max = mc->max; - int min = mc->min; - unsigned int sign_bit = mc->sign_bit; - unsigned int mask = (1 << fls(max)) - 1; - unsigned int invert = mc->invert; - int err; - bool type_2r = false; - unsigned int val2 = 0; - unsigned int val, val_mask; - - if (sign_bit) - mask = BIT(sign_bit + 1) - 1; - - val = ((ucontrol->value.integer.value[0] + min) & mask); - if (invert) - val = max - val; - val_mask = mask << shift; - val = val << shift; - if (snd_soc_volsw_is_stereo(mc)) { - val2 = ((ucontrol->value.integer.value[1] + min) & mask); - if (invert) - val2 = max - val2; - if (reg == reg2) { - val_mask |= mask << rshift; - val |= val2 << rshift; - } else { - val2 = val2 << shift; - type_2r = true; - } - } - err = snd_soc_component_update_bits(component, reg, val_mask, val); - if (err < 0) - return err; - - if (type_2r) - err = snd_soc_component_update_bits(component, reg2, val_mask, - val2); - - return err; - } - EXPORT_SYMBOL_GPL(snd_soc_put_volsw); - - /** - * snd_soc_get_volsw_sx - single mixer get callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to get the value of a single mixer control, or a double mixer - * control that spans 2 registers. - * - * Returns 0 for success. - */ - int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int reg2 = mc->rreg; - unsigned int shift = mc->shift; - unsigned int rshift = mc->rshift; - int max = mc->max; - int min = mc->min; - int mask = (1 << (fls(min + max) - 1)) - 1; - unsigned int val; - int ret; - - ret = snd_soc_component_read(component, reg, &val); - if (ret < 0) - return ret; - - ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask; - - if (snd_soc_volsw_is_stereo(mc)) { - ret = snd_soc_component_read(component, reg2, &val); - if (ret < 0) - return ret; - - val = ((val >> rshift) - min) & mask; - ucontrol->value.integer.value[1] = val; - } - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); - - /** - * snd_soc_put_volsw_sx - double mixer set callback - * @kcontrol: mixer control - * @uinfo: control element information - * - * Callback to set the value of a double mixer control that spans 2 registers. - * - * Returns 0 for success. - */ - int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - - unsigned int reg = mc->reg; - unsigned int reg2 = mc->rreg; - unsigned int shift = mc->shift; - unsigned int rshift = mc->rshift; - int max = mc->max; - int min = mc->min; - int mask = (1 << (fls(min + max) - 1)) - 1; - int err = 0; - unsigned int val, val_mask, val2 = 0; - - val_mask = mask << shift; - val = (ucontrol->value.integer.value[0] + min) & mask; - val = val << shift; - - err = snd_soc_component_update_bits(component, reg, val_mask, val); - if (err < 0) - return err; - - if (snd_soc_volsw_is_stereo(mc)) { - val_mask = mask << rshift; - val2 = (ucontrol->value.integer.value[1] + min) & mask; - val2 = val2 << rshift; - - err = snd_soc_component_update_bits(component, reg2, val_mask, - val2); - } - return err; - } - EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); - - /** - * snd_soc_info_volsw_s8 - signed mixer info callback - * @kcontrol: mixer control - * @uinfo: control element information - * - * Callback to provide information about a signed mixer control. - * - * Returns 0 for success. - */ - int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - int platform_max; - int min = mc->min; - - if (!mc->platform_max) - mc->platform_max = mc->max; - platform_max = mc->platform_max; - - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - uinfo->count = 2; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = platform_max - min; - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); - - /** - * snd_soc_get_volsw_s8 - signed mixer get callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to get the value of a signed mixer control. - * - * Returns 0 for success. - */ - int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - unsigned int reg = mc->reg; - unsigned int val; - int min = mc->min; - int ret; - - ret = snd_soc_component_read(component, reg, &val); - if (ret) - return ret; - - ucontrol->value.integer.value[0] = - ((signed char)(val & 0xff))-min; - ucontrol->value.integer.value[1] = - ((signed char)((val >> 8) & 0xff))-min; - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); - - /** - * snd_soc_put_volsw_sgn - signed mixer put callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to set the value of a signed mixer control. - * - * Returns 0 for success. - */ - int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - unsigned int reg = mc->reg; - int min = mc->min; - unsigned int val; - - val = (ucontrol->value.integer.value[0]+min) & 0xff; - val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; - - return snd_soc_component_update_bits(component, reg, 0xffff, val); - } - EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); - - /** - * snd_soc_info_volsw_range - single mixer info callback with range. - * @kcontrol: mixer control - * @uinfo: control element information - * - * Callback to provide information, within a range, about a single - * mixer control. - * - * returns 0 for success. - */ - int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - int platform_max; - int min = mc->min; - - if (!mc->platform_max) - mc->platform_max = mc->max; - platform_max = mc->platform_max; - - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = platform_max - min; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range); - - /** - * snd_soc_put_volsw_range - single mixer put value callback with range. - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to set the value, within a range, for a single mixer control. - * - * Returns 0 for success. - */ - int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - unsigned int reg = mc->reg; - unsigned int rreg = mc->rreg; - unsigned int shift = mc->shift; - int min = mc->min; - int max = mc->max; - unsigned int mask = (1 << fls(max)) - 1; - unsigned int invert = mc->invert; - unsigned int val, val_mask; - int ret; - - if (invert) - val = (max - ucontrol->value.integer.value[0]) & mask; - else - val = ((ucontrol->value.integer.value[0] + min) & mask); - val_mask = mask << shift; - val = val << shift; - - ret = snd_soc_component_update_bits(component, reg, val_mask, val); - if (ret < 0) - return ret; - - if (snd_soc_volsw_is_stereo(mc)) { - if (invert) - val = (max - ucontrol->value.integer.value[1]) & mask; - else - val = ((ucontrol->value.integer.value[1] + min) & mask); - val_mask = mask << shift; - val = val << shift; - - ret = snd_soc_component_update_bits(component, rreg, val_mask, - val); - } - - return ret; - } - EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range); - - /** - * snd_soc_get_volsw_range - single mixer get callback with range - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback to get the value, within a range, of a single mixer control. - * - * Returns 0 for success. - */ - int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int rreg = mc->rreg; - unsigned int shift = mc->shift; - int min = mc->min; - int max = mc->max; - unsigned int mask = (1 << fls(max)) - 1; - unsigned int invert = mc->invert; - unsigned int val; - int ret; - - ret = snd_soc_component_read(component, reg, &val); - if (ret) - return ret; - - ucontrol->value.integer.value[0] = (val >> shift) & mask; - if (invert) - ucontrol->value.integer.value[0] = - max - ucontrol->value.integer.value[0]; - else - ucontrol->value.integer.value[0] = - ucontrol->value.integer.value[0] - min; - - if (snd_soc_volsw_is_stereo(mc)) { - ret = snd_soc_component_read(component, rreg, &val); - if (ret) - return ret; - - ucontrol->value.integer.value[1] = (val >> shift) & mask; - if (invert) - ucontrol->value.integer.value[1] = - max - ucontrol->value.integer.value[1]; - else - ucontrol->value.integer.value[1] = - ucontrol->value.integer.value[1] - min; - } - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); - - /** - * snd_soc_limit_volume - Set new limit to an existing volume control. - * - * @codec: where to look for the control - * @name: Name of the control - * @max: new maximum limit - * - * Return 0 for success, else error. - */ - int snd_soc_limit_volume(struct snd_soc_codec *codec, - const char *name, int max) - { - struct snd_card *card = codec->component.card->snd_card; - struct snd_kcontrol *kctl; - struct soc_mixer_control *mc; - int found = 0; - int ret = -EINVAL; - - /* Sanity check for name and max */ - if (unlikely(!name || max <= 0)) - return -EINVAL; - - list_for_each_entry(kctl, &card->controls, list) { - if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { - found = 1; - break; - } - } - if (found) { - mc = (struct soc_mixer_control *)kctl->private_value; - if (max <= mc->max) { - mc->platform_max = max; - ret = 0; - } - } - return ret; - } - EXPORT_SYMBOL_GPL(snd_soc_limit_volume); - - int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_bytes *params = (void *)kcontrol->private_value; - - uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; - uinfo->count = params->num_regs * component->val_bytes; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_bytes_info); - - int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_bytes *params = (void *)kcontrol->private_value; - int ret; - - if (component->regmap) - ret = regmap_raw_read(component->regmap, params->base, - ucontrol->value.bytes.data, - params->num_regs * component->val_bytes); - else - ret = -EINVAL; - - /* Hide any masked bytes to ensure consistent data reporting */ - if (ret == 0 && params->mask) { - switch (component->val_bytes) { - case 1: - ucontrol->value.bytes.data[0] &= ~params->mask; - break; - case 2: - ((u16 *)(&ucontrol->value.bytes.data))[0] - &= cpu_to_be16(~params->mask); - break; - case 4: - ((u32 *)(&ucontrol->value.bytes.data))[0] - &= cpu_to_be32(~params->mask); - break; - default: - return -EINVAL; - } - } - - return ret; - } - EXPORT_SYMBOL_GPL(snd_soc_bytes_get); - - int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_bytes *params = (void *)kcontrol->private_value; - int ret, len; - unsigned int val, mask; - void *data; - - if (!component->regmap || !params->num_regs) - return -EINVAL; - - len = params->num_regs * component->val_bytes; - - data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); - if (!data) - return -ENOMEM; - - /* - * If we've got a mask then we need to preserve the register - * bits. We shouldn't modify the incoming data so take a - * copy. - */ - if (params->mask) { - ret = regmap_read(component->regmap, params->base, &val); - if (ret != 0) - goto out; - - val &= params->mask; - - switch (component->val_bytes) { - case 1: - ((u8 *)data)[0] &= ~params->mask; - ((u8 *)data)[0] |= val; - break; - case 2: - mask = ~params->mask; - ret = regmap_parse_val(component->regmap, - &mask, &mask); - if (ret != 0) - goto out; - - ((u16 *)data)[0] &= mask; - - ret = regmap_parse_val(component->regmap, - &val, &val); - if (ret != 0) - goto out; - - ((u16 *)data)[0] |= val; - break; - case 4: - mask = ~params->mask; - ret = regmap_parse_val(component->regmap, - &mask, &mask); - if (ret != 0) - goto out; - - ((u32 *)data)[0] &= mask; - - ret = regmap_parse_val(component->regmap, - &val, &val); - if (ret != 0) - goto out; - - ((u32 *)data)[0] |= val; - break; - default: - ret = -EINVAL; - goto out; - } - } - - ret = regmap_raw_write(component->regmap, params->base, - data, len); - - out: - kfree(data); - - return ret; - } - EXPORT_SYMBOL_GPL(snd_soc_bytes_put); - - int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *ucontrol) - { - struct soc_bytes_ext *params = (void *)kcontrol->private_value; - - ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES; - ucontrol->count = params->max; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext); - - int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, - unsigned int size, unsigned int __user *tlv) - { - struct soc_bytes_ext *params = (void *)kcontrol->private_value; - unsigned int count = size < params->max ? size : params->max; - int ret = -ENXIO; - - switch (op_flag) { - case SNDRV_CTL_TLV_OP_READ: - if (params->get) - ret = params->get(tlv, count); - break; - case SNDRV_CTL_TLV_OP_WRITE: - if (params->put) - ret = params->put(tlv, count); - break; - } - return ret; - } - EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback); - - /** - * snd_soc_info_xr_sx - signed multi register info callback - * @kcontrol: mreg control - * @uinfo: control element information - * - * Callback to provide information of a control that can - * span multiple codec registers which together - * forms a single signed value in a MSB/LSB manner. - * - * Returns 0 for success. - */ - int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) - { - struct soc_mreg_control *mc = - (struct soc_mreg_control *)kcontrol->private_value; - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - uinfo->count = 1; - uinfo->value.integer.min = mc->min; - uinfo->value.integer.max = mc->max; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); - - /** - * snd_soc_get_xr_sx - signed multi register get callback - * @kcontrol: mreg control - * @ucontrol: control element information - * - * Callback to get the value of a control that can span - * multiple codec registers which together forms a single - * signed value in a MSB/LSB manner. The control supports - * specifying total no of bits used to allow for bitfields - * across the multiple codec registers. - * - * Returns 0 for success. - */ - int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mreg_control *mc = - (struct soc_mreg_control *)kcontrol->private_value; - unsigned int regbase = mc->regbase; - unsigned int regcount = mc->regcount; - unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; - unsigned int regwmask = (1<invert; - unsigned long mask = (1UL<nbits)-1; - long min = mc->min; - long max = mc->max; - long val = 0; - unsigned int regval; - unsigned int i; - int ret; - - for (i = 0; i < regcount; i++) { - ret = snd_soc_component_read(component, regbase+i, ®val); - if (ret) - return ret; - val |= (regval & regwmask) << (regwshift*(regcount-i-1)); - } - val &= mask; - if (min < 0 && val > max) - val |= ~mask; - if (invert) - val = max - val; - ucontrol->value.integer.value[0] = val; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); - - /** - * snd_soc_put_xr_sx - signed multi register get callback - * @kcontrol: mreg control - * @ucontrol: control element information - * - * Callback to set the value of a control that can span - * multiple codec registers which together forms a single - * signed value in a MSB/LSB manner. The control supports - * specifying total no of bits used to allow for bitfields - * across the multiple codec registers. - * - * Returns 0 for success. - */ - int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mreg_control *mc = - (struct soc_mreg_control *)kcontrol->private_value; - unsigned int regbase = mc->regbase; - unsigned int regcount = mc->regcount; - unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; - unsigned int regwmask = (1<invert; - unsigned long mask = (1UL<nbits)-1; - long max = mc->max; - long val = ucontrol->value.integer.value[0]; - unsigned int i, regval, regmask; - int err; - - if (invert) - val = max - val; - val &= mask; - for (i = 0; i < regcount; i++) { - regval = (val >> (regwshift*(regcount-i-1))) & regwmask; - regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; - err = snd_soc_component_update_bits(component, regbase+i, - regmask, regval); - if (err < 0) - return err; - } - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); - - /** - * snd_soc_get_strobe - strobe get callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback get the value of a strobe mixer control. - * - * Returns 0 for success. - */ - int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int shift = mc->shift; - unsigned int mask = 1 << shift; - unsigned int invert = mc->invert != 0; - unsigned int val; - int ret; - - ret = snd_soc_component_read(component, reg, &val); - if (ret) - return ret; - - val &= mask; - - if (shift != 0 && val != 0) - val = val >> shift; - ucontrol->value.enumerated.item[0] = val ^ invert; - - return 0; - } - EXPORT_SYMBOL_GPL(snd_soc_get_strobe); - - /** - * snd_soc_put_strobe - strobe put callback - * @kcontrol: mixer control - * @ucontrol: control element information - * - * Callback strobe a register bit to high then low (or the inverse) - * in one pass of a single mixer enum control. - * - * Returns 1 for success. - */ - int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) - { - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - unsigned int reg = mc->reg; - unsigned int shift = mc->shift; - unsigned int mask = 1 << shift; - unsigned int invert = mc->invert != 0; - unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; - unsigned int val1 = (strobe ^ invert) ? mask : 0; - unsigned int val2 = (strobe ^ invert) ? 0 : mask; - int err; - - err = snd_soc_component_update_bits(component, reg, mask, val1); - if (err < 0) - return err; - - return snd_soc_component_update_bits(component, reg, mask, val2); - } - EXPORT_SYMBOL_GPL(snd_soc_put_strobe); - /** --- * snd_soc_info_enum_double - enumerated double mixer info callback --- * @kcontrol: mixer control --- * @uinfo: control element information --- * --- * Callback to provide information about a double enumerated --- * mixer control. +++ * snd_soc_dai_set_sysclk - configure DAI system or master clock. +++ * @dai: DAI +++ * @clk_id: DAI specific clock ID +++ * @freq: new clock frequency in Hz +++ * @dir: new clock direction - input/output. * --- * Returns 0 for success. +++ * Configures the DAI master (MCLK) or system (SYSCLK) clocking. */ ---int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) +++int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, +++ unsigned int freq, int dir) { --- struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; --- --- uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; --- uinfo->count = e->shift_l == e->shift_r ? 1 : 2; --- uinfo->value.enumerated.items = e->items; --- --- if (uinfo->value.enumerated.item >= e->items) --- uinfo->value.enumerated.item = e->items - 1; --- strlcpy(uinfo->value.enumerated.name, --- e->texts[uinfo->value.enumerated.item], --- sizeof(uinfo->value.enumerated.name)); --- return 0; +++ if (dai->driver && dai->driver->ops->set_sysclk) +++ return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); +++ else if (dai->codec && dai->codec->driver->set_sysclk) +++ return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, +++ freq, dir); +++ else +++ return -ENOTSUPP; } ---EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); +++EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); /** --- * snd_soc_get_enum_double - enumerated double mixer get callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to get the value of a double enumerated mixer. +++ * snd_soc_codec_set_sysclk - configure CODEC system or master clock. +++ * @codec: CODEC +++ * @clk_id: DAI specific clock ID +++ * @source: Source for the clock +++ * @freq: new clock frequency in Hz +++ * @dir: new clock direction - input/output. * --- * Returns 0 for success. +++ * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. */ ---int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) +++int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, +++ int source, unsigned int freq, int dir) { --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; --- unsigned int val, item; --- unsigned int reg_val; --- int ret; --- --- ret = snd_soc_component_read(component, e->reg, ®_val); --- if (ret) --- return ret; --- val = (reg_val >> e->shift_l) & e->mask; --- item = snd_soc_enum_val_to_item(e, val); --- ucontrol->value.enumerated.item[0] = item; --- if (e->shift_l != e->shift_r) { --- val = (reg_val >> e->shift_l) & e->mask; --- item = snd_soc_enum_val_to_item(e, val); --- ucontrol->value.enumerated.item[1] = item; --- } --- --- return 0; +++ if (codec->driver->set_sysclk) +++ return codec->driver->set_sysclk(codec, clk_id, source, +++ freq, dir); +++ else +++ return -ENOTSUPP; } ---EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); +++EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); /** --- * snd_soc_put_enum_double - enumerated double mixer put callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to set the value of a double enumerated mixer. +++ * snd_soc_dai_set_clkdiv - configure DAI clock dividers. +++ * @dai: DAI +++ * @div_id: DAI specific clock divider ID +++ * @div: new clock divisor. * --- * Returns 0 for success. +++ * Configures the clock dividers. This is used to derive the best DAI bit and +++ * frame clocks from the system or master clock. It's best to set the DAI bit +++ * and frame clocks as low as possible to save system power. */ ---int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) +++int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, +++ int div_id, int div) { --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; --- unsigned int *item = ucontrol->value.enumerated.item; --- unsigned int val; --- unsigned int mask; --- --- if (item[0] >= e->items) +++ if (dai->driver && dai->driver->ops->set_clkdiv) +++ return dai->driver->ops->set_clkdiv(dai, div_id, div); +++ else return -EINVAL; --- val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; --- mask = e->mask << e->shift_l; --- if (e->shift_l != e->shift_r) { --- if (item[1] >= e->items) --- return -EINVAL; --- val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; --- mask |= e->mask << e->shift_r; --- } --- --- return snd_soc_component_update_bits(component, e->reg, mask, val); } ---EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); +++EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); /** --- * snd_soc_read_signed - Read a codec register and interprete as signed value --- * @component: component --- * @reg: Register to read --- * @mask: Mask to use after shifting the register value --- * @shift: Right shift of register value --- * @sign_bit: Bit that describes if a number is negative or not. --- * @signed_val: Pointer to where the read value should be stored --- * --- * This functions reads a codec register. The register value is shifted right --- * by 'shift' bits and masked with the given 'mask'. Afterwards it translates --- * the given registervalue into a signed integer if sign_bit is non-zero. +++ * snd_soc_dai_set_pll - configure DAI PLL. +++ * @dai: DAI +++ * @pll_id: DAI specific PLL ID +++ * @source: DAI specific source for the PLL +++ * @freq_in: PLL input clock frequency in Hz +++ * @freq_out: requested PLL output clock frequency in Hz * --- * Returns 0 on sucess, otherwise an error value +++ * Configures and enables PLL to generate output clock based on input clock. */ ---static int snd_soc_read_signed(struct snd_soc_component *component, --- unsigned int reg, unsigned int mask, unsigned int shift, --- unsigned int sign_bit, int *signed_val) +++int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, +++ unsigned int freq_in, unsigned int freq_out) { --- int ret; --- unsigned int val; --- --- ret = snd_soc_component_read(component, reg, &val); --- if (ret < 0) --- return ret; --- --- val = (val >> shift) & mask; --- --- if (!sign_bit) { --- *signed_val = val; --- return 0; --- } --- --- /* non-negative number */ --- if (!(val & BIT(sign_bit))) { --- *signed_val = val; --- return 0; --- } --- --- ret = val; --- --- /* --- * The register most probably does not contain a full-sized int. --- * Instead we have an arbitrary number of bits in a signed --- * representation which has to be translated into a full-sized int. --- * This is done by filling up all bits above the sign-bit. --- */ --- ret |= ~((int)(BIT(sign_bit) - 1)); --- --- *signed_val = ret; --- --- return 0; ---} --- ---/** --- * snd_soc_info_volsw - single mixer info callback --- * @kcontrol: mixer control --- * @uinfo: control element information --- * --- * Callback to provide information about a single mixer control, or a double --- * mixer control that spans 2 registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- int platform_max; --- --- if (!mc->platform_max) --- mc->platform_max = mc->max; --- platform_max = mc->platform_max; --- --- if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) --- uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; --- else --- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; --- --- uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; --- uinfo->value.integer.min = 0; --- uinfo->value.integer.max = platform_max - mc->min; --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_info_volsw); --- ---/** --- * snd_soc_get_volsw - single mixer get callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to get the value of a single mixer control, or a double mixer --- * control that spans 2 registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int reg2 = mc->rreg; --- unsigned int shift = mc->shift; --- unsigned int rshift = mc->rshift; --- int max = mc->max; --- int min = mc->min; --- int sign_bit = mc->sign_bit; --- unsigned int mask = (1 << fls(max)) - 1; --- unsigned int invert = mc->invert; --- int val; --- int ret; --- --- if (sign_bit) --- mask = BIT(sign_bit + 1) - 1; --- --- ret = snd_soc_read_signed(component, reg, mask, shift, sign_bit, &val); --- if (ret) --- return ret; --- --- ucontrol->value.integer.value[0] = val - min; --- if (invert) --- ucontrol->value.integer.value[0] = --- max - ucontrol->value.integer.value[0]; --- --- if (snd_soc_volsw_is_stereo(mc)) { --- if (reg == reg2) --- ret = snd_soc_read_signed(component, reg, mask, rshift, --- sign_bit, &val); --- else --- ret = snd_soc_read_signed(component, reg2, mask, shift, --- sign_bit, &val); --- if (ret) --- return ret; --- --- ucontrol->value.integer.value[1] = val - min; --- if (invert) --- ucontrol->value.integer.value[1] = --- max - ucontrol->value.integer.value[1]; --- } --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_volsw); --- ---/** --- * snd_soc_put_volsw - single mixer put callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to set the value of a single mixer control, or a double mixer --- * control that spans 2 registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int reg2 = mc->rreg; --- unsigned int shift = mc->shift; --- unsigned int rshift = mc->rshift; --- int max = mc->max; --- int min = mc->min; --- unsigned int sign_bit = mc->sign_bit; --- unsigned int mask = (1 << fls(max)) - 1; --- unsigned int invert = mc->invert; --- int err; --- bool type_2r = false; --- unsigned int val2 = 0; --- unsigned int val, val_mask; --- --- if (sign_bit) --- mask = BIT(sign_bit + 1) - 1; --- --- val = ((ucontrol->value.integer.value[0] + min) & mask); --- if (invert) --- val = max - val; --- val_mask = mask << shift; --- val = val << shift; --- if (snd_soc_volsw_is_stereo(mc)) { --- val2 = ((ucontrol->value.integer.value[1] + min) & mask); --- if (invert) --- val2 = max - val2; --- if (reg == reg2) { --- val_mask |= mask << rshift; --- val |= val2 << rshift; --- } else { --- val2 = val2 << shift; --- type_2r = true; --- } --- } --- err = snd_soc_component_update_bits(component, reg, val_mask, val); --- if (err < 0) --- return err; --- --- if (type_2r) --- err = snd_soc_component_update_bits(component, reg2, val_mask, --- val2); --- --- return err; ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_volsw); --- ---/** --- * snd_soc_get_volsw_sx - single mixer get callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to get the value of a single mixer control, or a double mixer --- * control that spans 2 registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int reg2 = mc->rreg; --- unsigned int shift = mc->shift; --- unsigned int rshift = mc->rshift; --- int max = mc->max; --- int min = mc->min; --- int mask = (1 << (fls(min + max) - 1)) - 1; --- unsigned int val; --- int ret; --- --- ret = snd_soc_component_read(component, reg, &val); --- if (ret < 0) --- return ret; --- --- ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask; --- --- if (snd_soc_volsw_is_stereo(mc)) { --- ret = snd_soc_component_read(component, reg2, &val); --- if (ret < 0) --- return ret; --- --- val = ((val >> rshift) - min) & mask; --- ucontrol->value.integer.value[1] = val; --- } --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx); --- ---/** --- * snd_soc_put_volsw_sx - double mixer set callback --- * @kcontrol: mixer control --- * @uinfo: control element information --- * --- * Callback to set the value of a double mixer control that spans 2 registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- --- unsigned int reg = mc->reg; --- unsigned int reg2 = mc->rreg; --- unsigned int shift = mc->shift; --- unsigned int rshift = mc->rshift; --- int max = mc->max; --- int min = mc->min; --- int mask = (1 << (fls(min + max) - 1)) - 1; --- int err = 0; --- unsigned int val, val_mask, val2 = 0; --- --- val_mask = mask << shift; --- val = (ucontrol->value.integer.value[0] + min) & mask; --- val = val << shift; --- --- err = snd_soc_component_update_bits(component, reg, val_mask, val); --- if (err < 0) --- return err; --- --- if (snd_soc_volsw_is_stereo(mc)) { --- val_mask = mask << rshift; --- val2 = (ucontrol->value.integer.value[1] + min) & mask; --- val2 = val2 << rshift; --- --- err = snd_soc_component_update_bits(component, reg2, val_mask, --- val2); --- } --- return err; ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx); --- ---/** --- * snd_soc_info_volsw_s8 - signed mixer info callback --- * @kcontrol: mixer control --- * @uinfo: control element information --- * --- * Callback to provide information about a signed mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- int platform_max; --- int min = mc->min; --- --- if (!mc->platform_max) --- mc->platform_max = mc->max; --- platform_max = mc->platform_max; --- --- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; --- uinfo->count = 2; --- uinfo->value.integer.min = 0; --- uinfo->value.integer.max = platform_max - min; --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); --- ---/** --- * snd_soc_get_volsw_s8 - signed mixer get callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to get the value of a signed mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- unsigned int reg = mc->reg; --- unsigned int val; --- int min = mc->min; --- int ret; --- --- ret = snd_soc_component_read(component, reg, &val); --- if (ret) --- return ret; --- --- ucontrol->value.integer.value[0] = --- ((signed char)(val & 0xff))-min; --- ucontrol->value.integer.value[1] = --- ((signed char)((val >> 8) & 0xff))-min; --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); --- ---/** --- * snd_soc_put_volsw_sgn - signed mixer put callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to set the value of a signed mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- unsigned int reg = mc->reg; --- int min = mc->min; --- unsigned int val; --- --- val = (ucontrol->value.integer.value[0]+min) & 0xff; --- val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; --- --- return snd_soc_component_update_bits(component, reg, 0xffff, val); ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); --- ---/** --- * snd_soc_info_volsw_range - single mixer info callback with range. --- * @kcontrol: mixer control --- * @uinfo: control element information --- * --- * Callback to provide information, within a range, about a single --- * mixer control. --- * --- * returns 0 for success. --- */ ---int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- int platform_max; --- int min = mc->min; --- --- if (!mc->platform_max) --- mc->platform_max = mc->max; --- platform_max = mc->platform_max; --- --- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; --- uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; --- uinfo->value.integer.min = 0; --- uinfo->value.integer.max = platform_max - min; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range); --- ---/** --- * snd_soc_put_volsw_range - single mixer put value callback with range. --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to set the value, within a range, for a single mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- unsigned int reg = mc->reg; --- unsigned int rreg = mc->rreg; --- unsigned int shift = mc->shift; --- int min = mc->min; --- int max = mc->max; --- unsigned int mask = (1 << fls(max)) - 1; --- unsigned int invert = mc->invert; --- unsigned int val, val_mask; --- int ret; --- --- if (invert) --- val = (max - ucontrol->value.integer.value[0]) & mask; --- else --- val = ((ucontrol->value.integer.value[0] + min) & mask); --- val_mask = mask << shift; --- val = val << shift; --- --- ret = snd_soc_component_update_bits(component, reg, val_mask, val); --- if (ret < 0) --- return ret; --- --- if (snd_soc_volsw_is_stereo(mc)) { --- if (invert) --- val = (max - ucontrol->value.integer.value[1]) & mask; --- else --- val = ((ucontrol->value.integer.value[1] + min) & mask); --- val_mask = mask << shift; --- val = val << shift; --- --- ret = snd_soc_component_update_bits(component, rreg, val_mask, --- val); --- } --- --- return ret; ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range); --- ---/** --- * snd_soc_get_volsw_range - single mixer get callback with range --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback to get the value, within a range, of a single mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int rreg = mc->rreg; --- unsigned int shift = mc->shift; --- int min = mc->min; --- int max = mc->max; --- unsigned int mask = (1 << fls(max)) - 1; --- unsigned int invert = mc->invert; --- unsigned int val; --- int ret; --- --- ret = snd_soc_component_read(component, reg, &val); --- if (ret) --- return ret; --- --- ucontrol->value.integer.value[0] = (val >> shift) & mask; --- if (invert) --- ucontrol->value.integer.value[0] = --- max - ucontrol->value.integer.value[0]; --- else --- ucontrol->value.integer.value[0] = --- ucontrol->value.integer.value[0] - min; --- --- if (snd_soc_volsw_is_stereo(mc)) { --- ret = snd_soc_component_read(component, rreg, &val); --- if (ret) --- return ret; --- --- ucontrol->value.integer.value[1] = (val >> shift) & mask; --- if (invert) --- ucontrol->value.integer.value[1] = --- max - ucontrol->value.integer.value[1]; --- else --- ucontrol->value.integer.value[1] = --- ucontrol->value.integer.value[1] - min; --- } --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); --- ---/** --- * snd_soc_limit_volume - Set new limit to an existing volume control. --- * --- * @codec: where to look for the control --- * @name: Name of the control --- * @max: new maximum limit --- * --- * Return 0 for success, else error. --- */ ---int snd_soc_limit_volume(struct snd_soc_codec *codec, --- const char *name, int max) ---{ --- struct snd_card *card = codec->component.card->snd_card; --- struct snd_kcontrol *kctl; --- struct soc_mixer_control *mc; --- int found = 0; --- int ret = -EINVAL; --- --- /* Sanity check for name and max */ --- if (unlikely(!name || max <= 0)) --- return -EINVAL; --- --- list_for_each_entry(kctl, &card->controls, list) { --- if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { --- found = 1; --- break; --- } --- } --- if (found) { --- mc = (struct soc_mixer_control *)kctl->private_value; --- if (max <= mc->max) { --- mc->platform_max = max; --- ret = 0; --- } --- } --- return ret; ---} ---EXPORT_SYMBOL_GPL(snd_soc_limit_volume); --- ---int snd_soc_bytes_info(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_bytes *params = (void *)kcontrol->private_value; --- --- uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; --- uinfo->count = params->num_regs * component->val_bytes; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_bytes_info); --- ---int snd_soc_bytes_get(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_bytes *params = (void *)kcontrol->private_value; --- int ret; --- --- if (component->regmap) --- ret = regmap_raw_read(component->regmap, params->base, --- ucontrol->value.bytes.data, --- params->num_regs * component->val_bytes); --- else --- ret = -EINVAL; --- --- /* Hide any masked bytes to ensure consistent data reporting */ --- if (ret == 0 && params->mask) { --- switch (component->val_bytes) { --- case 1: --- ucontrol->value.bytes.data[0] &= ~params->mask; --- break; --- case 2: --- ((u16 *)(&ucontrol->value.bytes.data))[0] --- &= cpu_to_be16(~params->mask); --- break; --- case 4: --- ((u32 *)(&ucontrol->value.bytes.data))[0] --- &= cpu_to_be32(~params->mask); --- break; --- default: --- return -EINVAL; --- } --- } --- --- return ret; ---} ---EXPORT_SYMBOL_GPL(snd_soc_bytes_get); --- ---int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_bytes *params = (void *)kcontrol->private_value; --- int ret, len; --- unsigned int val, mask; --- void *data; --- --- if (!component->regmap || !params->num_regs) --- return -EINVAL; --- --- len = params->num_regs * component->val_bytes; --- --- data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); --- if (!data) --- return -ENOMEM; --- --- /* --- * If we've got a mask then we need to preserve the register --- * bits. We shouldn't modify the incoming data so take a --- * copy. --- */ --- if (params->mask) { --- ret = regmap_read(component->regmap, params->base, &val); --- if (ret != 0) --- goto out; --- --- val &= params->mask; --- --- switch (component->val_bytes) { --- case 1: --- ((u8 *)data)[0] &= ~params->mask; --- ((u8 *)data)[0] |= val; --- break; --- case 2: --- mask = ~params->mask; --- ret = regmap_parse_val(component->regmap, --- &mask, &mask); --- if (ret != 0) --- goto out; --- --- ((u16 *)data)[0] &= mask; --- --- ret = regmap_parse_val(component->regmap, --- &val, &val); --- if (ret != 0) --- goto out; --- --- ((u16 *)data)[0] |= val; --- break; --- case 4: --- mask = ~params->mask; --- ret = regmap_parse_val(component->regmap, --- &mask, &mask); --- if (ret != 0) --- goto out; --- --- ((u32 *)data)[0] &= mask; --- --- ret = regmap_parse_val(component->regmap, --- &val, &val); --- if (ret != 0) --- goto out; --- --- ((u32 *)data)[0] |= val; --- break; --- default: --- ret = -EINVAL; --- goto out; --- } --- } --- --- ret = regmap_raw_write(component->regmap, params->base, --- data, len); --- ---out: --- kfree(data); --- --- return ret; ---} ---EXPORT_SYMBOL_GPL(snd_soc_bytes_put); --- ---int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *ucontrol) ---{ --- struct soc_bytes_ext *params = (void *)kcontrol->private_value; --- --- ucontrol->type = SNDRV_CTL_ELEM_TYPE_BYTES; --- ucontrol->count = params->max; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext); --- ---int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, --- unsigned int size, unsigned int __user *tlv) ---{ --- struct soc_bytes_ext *params = (void *)kcontrol->private_value; --- unsigned int count = size < params->max ? size : params->max; --- int ret = -ENXIO; --- --- switch (op_flag) { --- case SNDRV_CTL_TLV_OP_READ: --- if (params->get) --- ret = params->get(tlv, count); --- break; --- case SNDRV_CTL_TLV_OP_WRITE: --- if (params->put) --- ret = params->put(tlv, count); --- break; --- } --- return ret; ---} ---EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback); --- ---/** --- * snd_soc_info_xr_sx - signed multi register info callback --- * @kcontrol: mreg control --- * @uinfo: control element information --- * --- * Callback to provide information of a control that can --- * span multiple codec registers which together --- * forms a single signed value in a MSB/LSB manner. --- * --- * Returns 0 for success. --- */ ---int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_info *uinfo) ---{ --- struct soc_mreg_control *mc = --- (struct soc_mreg_control *)kcontrol->private_value; --- uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; --- uinfo->count = 1; --- uinfo->value.integer.min = mc->min; --- uinfo->value.integer.max = mc->max; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx); --- ---/** --- * snd_soc_get_xr_sx - signed multi register get callback --- * @kcontrol: mreg control --- * @ucontrol: control element information --- * --- * Callback to get the value of a control that can span --- * multiple codec registers which together forms a single --- * signed value in a MSB/LSB manner. The control supports --- * specifying total no of bits used to allow for bitfields --- * across the multiple codec registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mreg_control *mc = --- (struct soc_mreg_control *)kcontrol->private_value; --- unsigned int regbase = mc->regbase; --- unsigned int regcount = mc->regcount; --- unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; --- unsigned int regwmask = (1<invert; --- unsigned long mask = (1UL<nbits)-1; --- long min = mc->min; --- long max = mc->max; --- long val = 0; --- unsigned int regval; --- unsigned int i; --- int ret; --- --- for (i = 0; i < regcount; i++) { --- ret = snd_soc_component_read(component, regbase+i, ®val); --- if (ret) --- return ret; --- val |= (regval & regwmask) << (regwshift*(regcount-i-1)); --- } --- val &= mask; --- if (min < 0 && val > max) --- val |= ~mask; --- if (invert) --- val = max - val; --- ucontrol->value.integer.value[0] = val; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx); --- ---/** --- * snd_soc_put_xr_sx - signed multi register get callback --- * @kcontrol: mreg control --- * @ucontrol: control element information --- * --- * Callback to set the value of a control that can span --- * multiple codec registers which together forms a single --- * signed value in a MSB/LSB manner. The control supports --- * specifying total no of bits used to allow for bitfields --- * across the multiple codec registers. --- * --- * Returns 0 for success. --- */ ---int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mreg_control *mc = --- (struct soc_mreg_control *)kcontrol->private_value; --- unsigned int regbase = mc->regbase; --- unsigned int regcount = mc->regcount; --- unsigned int regwshift = component->val_bytes * BITS_PER_BYTE; --- unsigned int regwmask = (1<invert; --- unsigned long mask = (1UL<nbits)-1; --- long max = mc->max; --- long val = ucontrol->value.integer.value[0]; --- unsigned int i, regval, regmask; --- int err; --- --- if (invert) --- val = max - val; --- val &= mask; --- for (i = 0; i < regcount; i++) { --- regval = (val >> (regwshift*(regcount-i-1))) & regwmask; --- regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask; --- err = snd_soc_component_update_bits(component, regbase+i, --- regmask, regval); --- if (err < 0) --- return err; --- } --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx); --- ---/** --- * snd_soc_get_strobe - strobe get callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback get the value of a strobe mixer control. --- * --- * Returns 0 for success. --- */ ---int snd_soc_get_strobe(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int shift = mc->shift; --- unsigned int mask = 1 << shift; --- unsigned int invert = mc->invert != 0; --- unsigned int val; --- int ret; --- --- ret = snd_soc_component_read(component, reg, &val); --- if (ret) --- return ret; --- --- val &= mask; --- --- if (shift != 0 && val != 0) --- val = val >> shift; --- ucontrol->value.enumerated.item[0] = val ^ invert; --- --- return 0; ---} ---EXPORT_SYMBOL_GPL(snd_soc_get_strobe); --- ---/** --- * snd_soc_put_strobe - strobe put callback --- * @kcontrol: mixer control --- * @ucontrol: control element information --- * --- * Callback strobe a register bit to high then low (or the inverse) --- * in one pass of a single mixer enum control. --- * --- * Returns 1 for success. --- */ ---int snd_soc_put_strobe(struct snd_kcontrol *kcontrol, --- struct snd_ctl_elem_value *ucontrol) ---{ --- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); --- struct soc_mixer_control *mc = --- (struct soc_mixer_control *)kcontrol->private_value; --- unsigned int reg = mc->reg; --- unsigned int shift = mc->shift; --- unsigned int mask = 1 << shift; --- unsigned int invert = mc->invert != 0; --- unsigned int strobe = ucontrol->value.enumerated.item[0] != 0; --- unsigned int val1 = (strobe ^ invert) ? mask : 0; --- unsigned int val2 = (strobe ^ invert) ? 0 : mask; --- int err; --- --- err = snd_soc_component_update_bits(component, reg, mask, val1); --- if (err < 0) --- return err; --- --- return snd_soc_component_update_bits(component, reg, mask, val2); ---} ---EXPORT_SYMBOL_GPL(snd_soc_put_strobe); --- ---/** --- * snd_soc_dai_set_sysclk - configure DAI system or master clock. --- * @dai: DAI --- * @clk_id: DAI specific clock ID --- * @freq: new clock frequency in Hz --- * @dir: new clock direction - input/output. --- * --- * Configures the DAI master (MCLK) or system (SYSCLK) clocking. --- */ ---int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, --- unsigned int freq, int dir) ---{ --- if (dai->driver && dai->driver->ops->set_sysclk) --- return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); --- else if (dai->codec && dai->codec->driver->set_sysclk) --- return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, --- freq, dir); --- else --- return -ENOTSUPP; ---} ---EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); --- ---/** --- * snd_soc_codec_set_sysclk - configure CODEC system or master clock. --- * @codec: CODEC --- * @clk_id: DAI specific clock ID --- * @source: Source for the clock --- * @freq: new clock frequency in Hz --- * @dir: new clock direction - input/output. --- * --- * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. --- */ ---int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, --- int source, unsigned int freq, int dir) ---{ --- if (codec->driver->set_sysclk) --- return codec->driver->set_sysclk(codec, clk_id, source, --- freq, dir); --- else --- return -ENOTSUPP; ---} ---EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); --- ---/** --- * snd_soc_dai_set_clkdiv - configure DAI clock dividers. --- * @dai: DAI --- * @div_id: DAI specific clock divider ID --- * @div: new clock divisor. --- * --- * Configures the clock dividers. This is used to derive the best DAI bit and --- * frame clocks from the system or master clock. It's best to set the DAI bit --- * and frame clocks as low as possible to save system power. --- */ ---int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, --- int div_id, int div) ---{ --- if (dai->driver && dai->driver->ops->set_clkdiv) --- return dai->driver->ops->set_clkdiv(dai, div_id, div); --- else --- return -EINVAL; ---} ---EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); --- ---/** --- * snd_soc_dai_set_pll - configure DAI PLL. --- * @dai: DAI --- * @pll_id: DAI specific PLL ID --- * @source: DAI specific source for the PLL --- * @freq_in: PLL input clock frequency in Hz --- * @freq_out: requested PLL output clock frequency in Hz --- * --- * Configures and enables PLL to generate output clock based on input clock. --- */ ---int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, --- unsigned int freq_in, unsigned int freq_out) ---{ --- if (dai->driver && dai->driver->ops->set_pll) --- return dai->driver->ops->set_pll(dai, pll_id, source, --- freq_in, freq_out); --- else if (dai->codec && dai->codec->driver->set_pll) --- return dai->codec->driver->set_pll(dai->codec, pll_id, source, --- freq_in, freq_out); --- else --- return -EINVAL; ---} ---EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); +++ if (dai->driver && dai->driver->ops->set_pll) +++ return dai->driver->ops->set_pll(dai, pll_id, source, +++ freq_in, freq_out); +++ else if (dai->codec && dai->codec->driver->set_pll) +++ return dai->codec->driver->set_pll(dai->codec, pll_id, source, +++ freq_in, freq_out); +++ else +++ return -EINVAL; +++} +++EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); /* * snd_soc_codec_set_pll - configure codec PLL. @@@@@@ -2947,22 -3652,62 -3996,22 -3996,22 -3996,22 +2603,62 @@@@@@ static int snd_soc_component_initialize return 0; } - ---static void snd_soc_component_init_regmap(struct snd_soc_component *component) + +++static void snd_soc_component_setup_regmap(struct snd_soc_component *component) { - --- if (!component->regmap) - --- component->regmap = dev_get_regmap(component->dev, NULL); - --- if (component->regmap) { - --- int val_bytes = regmap_get_val_bytes(component->regmap); - --- /* Errors are legitimate for non-integer byte multiples */ - --- if (val_bytes > 0) - --- component->val_bytes = val_bytes; - --- } + +++ int val_bytes = regmap_get_val_bytes(component->regmap); + +++ + +++ /* Errors are legitimate for non-integer byte multiples */ + +++ if (val_bytes > 0) + +++ component->val_bytes = val_bytes; + +++} + +++ + +++#ifdef CONFIG_REGMAP + +++ + +++/** + +++ * snd_soc_component_init_regmap() - Initialize regmap instance for the component + +++ * @component: The component for which to initialize the regmap instance + +++ * @regmap: The regmap instance that should be used by the component + +++ * + +++ * This function allows deferred assignment of the regmap instance that is + +++ * associated with the component. Only use this if the regmap instance is not + +++ * yet ready when the component is registered. The function must also be called + +++ * before the first IO attempt of the component. + +++ */ + +++void snd_soc_component_init_regmap(struct snd_soc_component *component, + +++ struct regmap *regmap) + +++{ + +++ component->regmap = regmap; + +++ snd_soc_component_setup_regmap(component); } + +++EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); + +++ + +++/** + +++ * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component + +++ * @component: The component for which to de-initialize the regmap instance + +++ * + +++ * Calls regmap_exit() on the regmap instance associated to the component and + +++ * removes the regmap instance from the component. + +++ * + +++ * This function should only be used if snd_soc_component_init_regmap() was used + +++ * to initialize the regmap instance. + +++ */ + +++void snd_soc_component_exit_regmap(struct snd_soc_component *component) + +++{ + +++ regmap_exit(component->regmap); + +++ component->regmap = NULL; + +++} + +++EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); + +++ + +++#endif static void snd_soc_component_add_unlocked(struct snd_soc_component *component) { - --- if (!component->write && !component->read) - --- snd_soc_component_init_regmap(component); + +++ if (!component->write && !component->read) { + +++ if (!component->regmap) + +++ component->regmap = dev_get_regmap(component->dev, NULL); + +++ if (component->regmap) + +++ snd_soc_component_setup_regmap(component); + +++ } list_add(&component->list, &component_list); } @@@@@@ -3536,7 -4281,7 -4585,7 -4585,7 -4585,7 +3232,7 @@@@@@ int snd_soc_of_parse_audio_routing(stru const char *propname) { struct device_node *np = card->dev->of_node; ---- int num_routes; ++++ int num_routes, old_routes; struct snd_soc_dapm_route *routes; int i, ret; @@@@@@ -3554,9 -4299,7 -4603,7 -4603,7 -4603,7 +3250,9 @@@@@@ return -EINVAL; } ---- routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), ++++ old_routes = card->num_dapm_routes; ++++ routes = devm_kzalloc(card->dev, ++++ (old_routes + num_routes) * sizeof(*routes), GFP_KERNEL); if (!routes) { dev_err(card->dev, @@@@@@ -3564,11 -4307,9 -4611,9 -4611,9 -4611,9 +3260,11 @@@@@@ return -EINVAL; } ++++ memcpy(routes, card->dapm_routes, old_routes * sizeof(*routes)); ++++ for (i = 0; i < num_routes; i++) { ret = of_property_read_string_index(np, propname, ---- 2 * i, &routes[i].sink); ++++ 2 * i, &routes[old_routes + i].sink); if (ret) { dev_err(card->dev, "ASoC: Property '%s' index %d could not be read: %d\n", @@@@@@ -3576,7 -4317,7 -4621,7 -4621,7 -4621,7 +3272,7 @@@@@@ return -EINVAL; } ret = of_property_read_string_index(np, propname, ---- (2 * i) + 1, &routes[i].source); ++++ (2 * i) + 1, &routes[old_routes + i].source); if (ret) { dev_err(card->dev, "ASoC: Property '%s' index %d could not be read: %d\n", @@@@@@ -3585,7 -4326,7 -4630,7 -4630,7 -4630,7 +3281,7 @@@@@@ } } ---- card->num_dapm_routes = num_routes; ++++ card->num_dapm_routes += num_routes; card->dapm_routes = routes; return 0;