soc: tegra: rt5640: support speaker volume edp table
Simon Je [Thu, 18 Jul 2013 12:05:35 +0000 (21:05 +0900)]
To support different gains of volume edp for each platform
in single machine driver, add edp_vol table to tegra_asoc_platform_data,
and add edp_vol values to tegratab and macallan board file.

Bug 1321224

Change-Id: Ia74c17dcc3eabe27d3d6356d6d0e51b2623976b1
Signed-off-by: Simon Je <sje@nvidia.com>
Reviewed-on: http://git-master/r/250746
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>

arch/arm/mach-tegra/board-macallan.c
arch/arm/mach-tegra/board-tegratab.c
arch/arm/mach-tegra/include/mach/tegra_asoc_pdata.h
sound/soc/tegra/tegra_rt5640.c

index 435ee5b..2b779ef 100644 (file)
@@ -335,7 +335,8 @@ static struct tegra_asoc_platform_data macallan_audio_pdata = {
        .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
        .gpio_ldo1_en           = TEGRA_GPIO_LDO1_EN,
        .edp_support            = true,
-       .edp_states             = {1100, 858, 0},
+       .edp_states             = {1100, 1100, 0},
+       .edp_vol                = {0x8, 0x8, 0x27},
        .gpio_codec1 = TEGRA_GPIO_CODEC1_EN,
        .gpio_codec2 = TEGRA_GPIO_CODEC2_EN,
        .gpio_codec3 = TEGRA_GPIO_CODEC3_EN,
index bfa3941..0bd7625 100644 (file)
@@ -346,6 +346,9 @@ static struct tegra_asoc_platform_data tegratab_audio_pdata = {
                .is_i2s_master  = 1,
                .i2s_mode       = TEGRA_DAIFMT_DSP_A,
        },
+       .edp_support    = true,
+       .edp_states     = {4760, 4760, 0},
+       .edp_vol        = {0x8, 0x8, 0x27},
 };
 
 static struct platform_device tegratab_audio_device = {
index 627a93f..0a889d8 100644 (file)
@@ -60,5 +60,6 @@ struct tegra_asoc_platform_data {
        unsigned int debounce_time_hp;
        bool edp_support;
        unsigned int edp_states[TEGRA_SPK_EDP_NUM_STATES];
+       int edp_vol[TEGRA_SPK_EDP_NUM_STATES];
        struct i2s_config i2s_param[NUM_I2S_DEVICES];
 };
index 93c3c5f..7afdf27 100644 (file)
@@ -466,26 +466,24 @@ static void tegra_speaker_throttle(unsigned int new_state,  void *priv_data)
        struct tegra_rt5640 *machine = priv_data;
        struct snd_soc_card *card;
        struct snd_soc_codec *codec;
+       int *edp_vol;
 
        if (!machine)
                return;
 
        card = machine->pcard;
        codec = card->rtd[DAI_LINK_HIFI].codec;
+       edp_vol = machine->pdata->edp_vol;
 
        /* set codec volume to reflect the new E-state */
        switch (new_state) {
        case TEGRA_SPK_EDP_NEG_1:
-               /* set codec voulme to 0dB (100%), E-1 state */
-               tegra_speaker_edp_set_volume(codec, 0x0, 0x0);
-               break;
        case TEGRA_SPK_EDP_ZERO:
-               /* set codec volume to -16.5dB (78%), E0 state */
-               tegra_speaker_edp_set_volume(codec, 0x13, 0x13);
-               break;
        case TEGRA_SPK_EDP_1:
-               /* turn off codec volume, -46.5 dB, E1 state */
-               tegra_speaker_edp_set_volume(codec, 0x27, 0x27);
+               tegra_speaker_edp_set_volume(codec, edp_vol[new_state],
+                               edp_vol[new_state]);
+               dev_info(card->dev, "%s new_state=%d, edp_vol=0x%x\n",
+                               __func__, new_state, edp_vol[new_state]);
                break;
        default:
                pr_err("%s: New E-state %d don't support!\n",
@@ -504,6 +502,7 @@ static int tegra_rt5640_event_int_spk(struct snd_soc_dapm_widget *w,
        struct tegra_asoc_platform_data *pdata = machine->pdata;
        struct snd_soc_codec *codec = card->rtd[DAI_LINK_HIFI].codec;
        unsigned int approved = TEGRA_SPK_EDP_NUM_STATES;
+       int *edp_vol = pdata->edp_vol;
        int ret;
 
        if (machine->spk_reg) {
@@ -536,17 +535,12 @@ static int tegra_rt5640_event_int_spk(struct snd_soc_dapm_widget *w,
                ret = edp_update_client_request(machine->spk_edp_client,
                                                TEGRA_SPK_EDP_NEG_1,
                                                &approved);
-               if (ret || approved != TEGRA_SPK_EDP_NEG_1) {
-                       if (approved == TEGRA_SPK_EDP_ZERO)
-                               /* set codec volume to -16.5dB (78%),E0 state */
-                               tegra_speaker_edp_set_volume(codec, 0x13, 0x13);
-                       else if (approved == TEGRA_SPK_EDP_1)
-                               /* turn off codec volume,-46.5 dB, E1 state */
-                               tegra_speaker_edp_set_volume(codec, 0x27, 0x27);
-               } else {
-                       /* set codec voulme to 0dB (100%), E-1 state */
-                       tegra_speaker_edp_set_volume(codec, 0x0, 0x0);
-               }
+               approved = approved < TEGRA_SPK_EDP_NUM_STATES ?
+                               approved : TEGRA_SPK_EDP_NEG_1;
+               tegra_speaker_edp_set_volume(codec,
+                               edp_vol[approved], edp_vol[approved]);
+               dev_info(card->dev, "%s approved=%d, edp_vol=0x%x\n",
+                               __func__, approved, edp_vol[approved]);
        } else {
                ret = edp_update_client_request(machine->spk_edp_client,
                                                TEGRA_SPK_EDP_1,