tegra:fairfax: Enable TI AMP for headset
ericz [Wed, 15 Jan 2014 10:42:31 +0000 (18:42 +0800)]
Bug: 1430485

Change-Id: Idc2fca3edcc7205ac9e80e9a8f419920b818b1a7
Signed-off-by: ericz <ericz@nvidia.com>
Reviewed-on: http://git-master/r/360343
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Simon Je <sje@nvidia.com>
Reviewed-by: Gabby Lee <galee@nvidia.com>
Tested-by: Gabby Lee <galee@nvidia.com>

arch/arm/mach-tegra/board-tegratab.c
sound/soc/codecs/tpa6130a2.c
sound/soc/codecs/tpa6130a2.h
sound/soc/tegra/Kconfig
sound/soc/tegra/tegra_rt5640.c

index 00697d8..3fa65ca 100644 (file)
@@ -69,6 +69,9 @@
 #include <mach/tegra_wakeup_monitor.h>
 #include <mach/hardware.h>
 #include <mach/dc.h>
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+#include <sound/tpa6130a2-plat.h>
+#endif
 
 #include "board-touch-raydium.h"
 #include "board.h"
@@ -236,6 +239,18 @@ static struct tegra_i2c_platform_data tegratab_i2c5_platform_data = {
 };
 #endif
 
+
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+static struct tpa6130a2_platform_data tpa6130a2_pdata = {
+       /*.power_gpio = TEGRA_GPIO_HP_EN,*/
+};
+
+static struct i2c_board_info __initdata tpa6130a2_board_info = {
+       I2C_BOARD_INFO("tpa6130a2", 0x60),
+       .platform_data = &tpa6130a2_pdata,
+};
+#endif
+
 static struct i2c_board_info __initdata rt5640_board_info = {
        I2C_BOARD_INFO("rt5640", 0x1c),
 };
@@ -255,6 +270,9 @@ static void tegratab_i2c_init(void)
                i2c_register_board_info(0, &rt5639_board_info, 1);
        else
                i2c_register_board_info(0, &rt5640_board_info, 1);
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+       i2c_register_board_info(0, &tpa6130a2_board_info, 1);
+#endif
 }
 
 static struct platform_device *tegratab_uart_devices[] __initdata = {
index 6fe4aa3..e156507 100644 (file)
@@ -2,6 +2,7 @@
  * ALSA SoC Texas Instruments TPA6130A2 headset stereo amplifier driver
  *
  * Copyright (C) Nokia Corporation
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
  *
@@ -44,8 +45,6 @@ static struct i2c_client *tpa6130a2_client;
 struct tpa6130a2_data {
        struct mutex mutex;
        unsigned char regs[TPA6130A2_CACHEREGNUM];
-       struct regulator *supply;
-       int power_gpio;
        u8 power_state:1;
        enum tpa_model id;
 };
@@ -121,13 +120,14 @@ static int tpa6130a2_initialize(void)
        return ret;
 }
 
-static int tpa6130a2_power(u8 power)
+int tpa6130a2_power(u8 power)
 {
        struct  tpa6130a2_data *data;
        u8      val;
        int     ret = 0;
 
-       BUG_ON(tpa6130a2_client == NULL);
+       if (tpa6130a2_client == NULL)
+               return -1;
        data = i2c_get_clientdata(tpa6130a2_client);
 
        mutex_lock(&data->mutex);
@@ -135,24 +135,12 @@ static int tpa6130a2_power(u8 power)
                goto exit;
 
        if (power) {
-               ret = regulator_enable(data->supply);
-               if (ret != 0) {
-                       dev_err(&tpa6130a2_client->dev,
-                               "Failed to enable supply: %d\n", ret);
-                       goto exit;
-               }
                /* Power on */
-               if (data->power_gpio >= 0)
-                       gpio_set_value(data->power_gpio, 1);
-
                data->power_state = 1;
                ret = tpa6130a2_initialize();
                if (ret < 0) {
                        dev_err(&tpa6130a2_client->dev,
                                "Failed to initialize chip\n");
-                       if (data->power_gpio >= 0)
-                               gpio_set_value(data->power_gpio, 0);
-                       regulator_disable(data->supply);
                        data->power_state = 0;
                        goto exit;
                }
@@ -162,11 +150,6 @@ static int tpa6130a2_power(u8 power)
                val |= TPA6130A2_SWS;
                tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
 
-               /* Power off */
-               if (data->power_gpio >= 0)
-                       gpio_set_value(data->power_gpio, 0);
-
-               ret = regulator_disable(data->supply);
                if (ret != 0) {
                        dev_err(&tpa6130a2_client->dev,
                                "Failed to disable supply: %d\n", ret);
@@ -180,6 +163,7 @@ exit:
        mutex_unlock(&data->mutex);
        return ret;
 }
+EXPORT_SYMBOL_GPL(tpa6130a2_power);
 
 static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
                struct snd_ctl_elem_value *ucontrol)
@@ -325,6 +309,8 @@ static void tpa6130a2_channel_enable(u8 channel, int enable)
 int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
 {
        int ret = 0;
+       if (tpa6130a2_client == NULL)
+               return -1;
        if (enable) {
                ret = tpa6130a2_power(1);
                if (ret < 0)
@@ -387,7 +373,6 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
        i2c_set_clientdata(tpa6130a2_client, data);
 
        pdata = client->dev.platform_data;
-       data->power_gpio = pdata->power_gpio;
        data->id = id->driver_data;
 
        mutex_init(&data->mutex);
@@ -397,16 +382,6 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
        data->regs[TPA6130A2_REG_VOL_MUTE] =    TPA6130A2_MUTE_R |
                                                TPA6130A2_MUTE_L;
 
-       if (data->power_gpio >= 0) {
-               ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
-               if (ret < 0) {
-                       dev_err(dev, "Failed to request power GPIO (%d)\n",
-                               data->power_gpio);
-                       goto err_gpio;
-               }
-               gpio_direction_output(data->power_gpio, 0);
-       }
-
        switch (data->id) {
        default:
                dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
@@ -419,13 +394,6 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
                break;
        }
 
-       data->supply = regulator_get(dev, regulator);
-       if (IS_ERR(data->supply)) {
-               ret = PTR_ERR(data->supply);
-               dev_err(dev, "Failed to request supply: %d\n", ret);
-               goto err_regulator;
-       }
-
        ret = tpa6130a2_power(1);
        if (ret != 0)
                goto err_power;
@@ -439,16 +407,10 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
 
        /* Disable the chip */
        ret = tpa6130a2_power(0);
-       if (ret != 0)
-               goto err_power;
 
        return 0;
 
 err_power:
-       regulator_put(data->supply);
-err_regulator:
-       if (data->power_gpio >= 0)
-               gpio_free(data->power_gpio);
 err_gpio:
        tpa6130a2_client = NULL;
 
@@ -461,10 +423,6 @@ static int __devexit tpa6130a2_remove(struct i2c_client *client)
 
        tpa6130a2_power(0);
 
-       if (data->power_gpio >= 0)
-               gpio_free(data->power_gpio);
-
-       regulator_put(data->supply);
        tpa6130a2_client = NULL;
 
        return 0;
index 4174440..927db3d 100644 (file)
@@ -2,6 +2,7 @@
  * ALSA SoC TPA6130A2 amplifier driver
  *
  * Copyright (C) Nokia Corporation
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
  *
@@ -58,5 +59,6 @@
 
 extern int tpa6130a2_add_controls(struct snd_soc_codec *codec);
 extern int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable);
+extern int tpa6130a2_power(u8 power);
 
 #endif /* __TPA6130A2_H__ */
index 4348565..e272eba 100644 (file)
@@ -216,6 +216,16 @@ config SND_SOC_TEGRA_RT5640
          boards using the ALC5640 codec. Currently, the supported boards
          are Kai,Cardhu,Dalmore and Macallan.
 
+config SND_SOC_TI_TPA6130A2
+       tristate "SoC Audio support for Tegra boards using a TPA6130A2 amp"
+       bool "Enable system DMA driver for NVIDIA Tegra SoCs"
+       select SND_SOC_TPA6130A2
+       help
+         Enable support for the
+         Tegra PWM controller(s).
+         This item is just
+         used for project with TPA6130A2.
+
 config MACH_HAS_SND_SOC_TEGRA_MAX98095
        bool
        help
index 8c4eaaf..a91e3a8 100644 (file)
@@ -50,6 +50,9 @@
 #include <sound/soc.h>
 #include "../codecs/rt5639.h"
 #include "../codecs/rt5640.h"
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+#include "../codecs/tpa6130a2.h"
+#endif
 
 #include "tegra_pcm.h"
 #include "tegra_asoc_utils.h"
@@ -1366,7 +1369,14 @@ static int tegra_rt5640_event_hp(struct snd_soc_dapm_widget *w,
        struct snd_soc_card *card = dapm->card;
        struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
        struct tegra_asoc_platform_data *pdata = machine->pdata;
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+       struct snd_soc_codec *codec = card->rtd[DAI_LINK_HIFI].codec;
 
+               if (SND_SOC_DAPM_EVENT_ON(event))
+                       tpa6130a2_stereo_enable(codec, 1);
+               else
+                       tpa6130a2_stereo_enable(codec, 0);
+#endif
        if (!(machine->gpio_requested & GPIO_HP_MUTE))
                return 0;
 
@@ -1909,7 +1919,6 @@ static __devinit int tegra_rt5640_driver_probe(struct platform_device *pdev)
        }
 #endif
 
-
        if (!pdata->edp_support)
                return 0;
 
@@ -1957,7 +1966,9 @@ static __devinit int tegra_rt5640_driver_probe(struct platform_device *pdev)
                        machine->spk_edp_client = NULL;
                }
        }
-
+#ifdef CONFIG_SND_SOC_TI_TPA6130A2
+       tpa6130a2_add_controls(card->rtd[DAI_LINK_HIFI].codec);
+#endif
        return 0;
 
 err_unregister_card: