diff options
Diffstat (limited to 'sound/soc/sh/rcar/dvc.c')
-rw-r--r-- | sound/soc/sh/rcar/dvc.c | 177 |
1 files changed, 15 insertions, 162 deletions
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c index e2c8473..5380a48 100644 --- a/sound/soc/sh/rcar/dvc.c +++ b/sound/soc/sh/rcar/dvc.c @@ -11,36 +11,18 @@ #include "rsnd.h" #define RSND_DVC_NAME_SIZE 16 -#define RSND_DVC_CHANNELS 2 #define DVC_NAME "dvc" -struct rsnd_dvc_cfg { - unsigned int max; - unsigned int size; - u32 *val; - const char * const *texts; -}; - -struct rsnd_dvc_cfg_m { - struct rsnd_dvc_cfg cfg; - u32 val[RSND_DVC_CHANNELS]; -}; - -struct rsnd_dvc_cfg_s { - struct rsnd_dvc_cfg cfg; - u32 val; -}; - struct rsnd_dvc { struct rsnd_dvc_platform_info *info; /* rcar_snd.h */ struct rsnd_mod mod; struct clk *clk; - struct rsnd_dvc_cfg_m volume; - struct rsnd_dvc_cfg_m mute; - struct rsnd_dvc_cfg_s ren; /* Ramp Enable */ - struct rsnd_dvc_cfg_s rup; /* Ramp Rate Up */ - struct rsnd_dvc_cfg_s rdown; /* Ramp Rate Down */ + struct rsnd_kctrl_cfg_m volume; + struct rsnd_kctrl_cfg_m mute; + struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */ + struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */ + struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ }; #define rsnd_mod_to_dvc(_mod) \ @@ -222,140 +204,6 @@ static int rsnd_dvc_stop(struct rsnd_mod *mod, return 0; } -static int rsnd_dvc_volume_info(struct snd_kcontrol *kctrl, - struct snd_ctl_elem_info *uinfo) -{ - struct rsnd_dvc_cfg *cfg = (struct rsnd_dvc_cfg *)kctrl->private_value; - - if (cfg->texts) { - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; - uinfo->count = cfg->size; - uinfo->value.enumerated.items = cfg->max; - if (uinfo->value.enumerated.item >= cfg->max) - uinfo->value.enumerated.item = cfg->max - 1; - strlcpy(uinfo->value.enumerated.name, - cfg->texts[uinfo->value.enumerated.item], - sizeof(uinfo->value.enumerated.name)); - } else { - uinfo->count = cfg->size; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = cfg->max; - uinfo->type = (cfg->max == 1) ? - SNDRV_CTL_ELEM_TYPE_BOOLEAN : - SNDRV_CTL_ELEM_TYPE_INTEGER; - } - - return 0; -} - -static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl, - struct snd_ctl_elem_value *ucontrol) -{ - struct rsnd_dvc_cfg *cfg = (struct rsnd_dvc_cfg *)kctrl->private_value; - int i; - - for (i = 0; i < cfg->size; i++) - if (cfg->texts) - ucontrol->value.enumerated.item[i] = cfg->val[i]; - else - ucontrol->value.integer.value[i] = cfg->val[i]; - - return 0; -} - -static int rsnd_dvc_volume_put(struct snd_kcontrol *kctrl, - struct snd_ctl_elem_value *ucontrol) -{ - struct rsnd_mod *mod = snd_kcontrol_chip(kctrl); - struct rsnd_dvc_cfg *cfg = (struct rsnd_dvc_cfg *)kctrl->private_value; - int i, change = 0; - - for (i = 0; i < cfg->size; i++) { - if (cfg->texts) { - change |= (ucontrol->value.enumerated.item[i] != cfg->val[i]); - cfg->val[i] = ucontrol->value.enumerated.item[i]; - } else { - change |= (ucontrol->value.integer.value[i] != cfg->val[i]); - cfg->val[i] = ucontrol->value.integer.value[i]; - } - } - - if (change) - rsnd_dvc_volume_update(mod); - - return change; -} - -static int __rsnd_dvc_pcm_new(struct rsnd_mod *mod, - struct rsnd_dai *rdai, - struct snd_soc_pcm_runtime *rtd, - const unsigned char *name, - struct rsnd_dvc_cfg *private) -{ - struct snd_card *card = rtd->card->snd_card; - struct snd_kcontrol *kctrl; - struct snd_kcontrol_new knew = { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = name, - .info = rsnd_dvc_volume_info, - .get = rsnd_dvc_volume_get, - .put = rsnd_dvc_volume_put, - .private_value = (unsigned long)private, - }; - int ret; - - kctrl = snd_ctl_new1(&knew, mod); - if (!kctrl) - return -ENOMEM; - - ret = snd_ctl_add(card, kctrl); - if (ret < 0) - return ret; - - return 0; -} - -static int _rsnd_dvc_pcm_new_m(struct rsnd_mod *mod, - struct rsnd_dai *rdai, - struct snd_soc_pcm_runtime *rtd, - const unsigned char *name, - struct rsnd_dvc_cfg_m *private, - u32 max) -{ - private->cfg.max = max; - private->cfg.size = RSND_DVC_CHANNELS; - private->cfg.val = private->val; - return __rsnd_dvc_pcm_new(mod, rdai, rtd, name, &private->cfg); -} - -static int _rsnd_dvc_pcm_new_s(struct rsnd_mod *mod, - struct rsnd_dai *rdai, - struct snd_soc_pcm_runtime *rtd, - const unsigned char *name, - struct rsnd_dvc_cfg_s *private, - u32 max) -{ - private->cfg.max = max; - private->cfg.size = 1; - private->cfg.val = &private->val; - return __rsnd_dvc_pcm_new(mod, rdai, rtd, name, &private->cfg); -} - -static int _rsnd_dvc_pcm_new_e(struct rsnd_mod *mod, - struct rsnd_dai *rdai, - struct snd_soc_pcm_runtime *rtd, - const unsigned char *name, - struct rsnd_dvc_cfg_s *private, - const char * const *texts, - u32 max) -{ - private->cfg.max = max; - private->cfg.size = 1; - private->cfg.val = &private->val; - private->cfg.texts = texts; - return __rsnd_dvc_pcm_new(mod, rdai, rtd, name, &private->cfg); -} - static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, struct rsnd_dai *rdai, struct snd_soc_pcm_runtime *rtd) @@ -365,41 +213,46 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, int ret; /* Volume */ - ret = _rsnd_dvc_pcm_new_m(mod, rdai, rtd, + ret = rsnd_kctrl_new_m(mod, rdai, rtd, rsnd_dai_is_play(rdai, io) ? "DVC Out Playback Volume" : "DVC In Capture Volume", + rsnd_dvc_volume_update, &dvc->volume, 0x00800000 - 1); if (ret < 0) return ret; /* Mute */ - ret = _rsnd_dvc_pcm_new_m(mod, rdai, rtd, + ret = rsnd_kctrl_new_m(mod, rdai, rtd, rsnd_dai_is_play(rdai, io) ? "DVC Out Mute Switch" : "DVC In Mute Switch", + rsnd_dvc_volume_update, &dvc->mute, 1); if (ret < 0) return ret; /* Ramp */ - ret = _rsnd_dvc_pcm_new_s(mod, rdai, rtd, + ret = rsnd_kctrl_new_s(mod, rdai, rtd, rsnd_dai_is_play(rdai, io) ? "DVC Out Ramp Switch" : "DVC In Ramp Switch", + rsnd_dvc_volume_update, &dvc->ren, 1); if (ret < 0) return ret; - ret = _rsnd_dvc_pcm_new_e(mod, rdai, rtd, + ret = rsnd_kctrl_new_e(mod, rdai, rtd, rsnd_dai_is_play(rdai, io) ? "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate", &dvc->rup, + rsnd_dvc_volume_update, dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate)); if (ret < 0) return ret; - ret = _rsnd_dvc_pcm_new_e(mod, rdai, rtd, + ret = rsnd_kctrl_new_e(mod, rdai, rtd, rsnd_dai_is_play(rdai, io) ? "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate", &dvc->rdown, + rsnd_dvc_volume_update, dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate)); if (ret < 0) |