|
28 | 28 | #include <linux/platform_device.h> |
29 | 29 | #include <linux/i2c/twl.h> |
30 | 30 | #include <linux/slab.h> |
| 31 | +#include <linux/gpio.h> |
31 | 32 | #include <sound/core.h> |
32 | 33 | #include <sound/pcm.h> |
33 | 34 | #include <sound/pcm_params.h> |
@@ -302,6 +303,22 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) |
302 | 303 | u8 reg, byte; |
303 | 304 | int i = 0; |
304 | 305 |
|
| 306 | + if (pdata && pdata->hs_extmute && |
| 307 | + gpio_is_valid(pdata->hs_extmute_gpio)) { |
| 308 | + int ret; |
| 309 | + |
| 310 | + if (!pdata->hs_extmute_gpio) |
| 311 | + dev_warn(codec->dev, |
| 312 | + "Extmute GPIO is 0 is this correct?\n"); |
| 313 | + |
| 314 | + ret = gpio_request_one(pdata->hs_extmute_gpio, |
| 315 | + GPIOF_OUT_INIT_LOW, "hs_extmute"); |
| 316 | + if (ret) { |
| 317 | + dev_err(codec->dev, "Failed to get hs_extmute GPIO\n"); |
| 318 | + pdata->hs_extmute_gpio = -1; |
| 319 | + } |
| 320 | + } |
| 321 | + |
305 | 322 | /* Check defaults, if instructed before anything else */ |
306 | 323 | if (pdata && pdata->check_defaults) |
307 | 324 | twl4030_check_defaults(codec); |
@@ -748,7 +765,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp) |
748 | 765 | /* Enable external mute control, this dramatically reduces |
749 | 766 | * the pop-noise */ |
750 | 767 | if (pdata && pdata->hs_extmute) { |
751 | | - if (pdata->set_hs_extmute) { |
| 768 | + if (gpio_is_valid(pdata->hs_extmute_gpio)) { |
| 769 | + gpio_set_value(pdata->hs_extmute_gpio, 1); |
| 770 | + } else if (pdata->set_hs_extmute) { |
| 771 | + dev_warn(codec->dev, "set_hs_extmute is deprecated\n"); |
752 | 772 | pdata->set_hs_extmute(1); |
753 | 773 | } else { |
754 | 774 | hs_pop |= TWL4030_EXTMUTE; |
@@ -786,7 +806,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp) |
786 | 806 |
|
787 | 807 | /* Disable external mute */ |
788 | 808 | if (pdata && pdata->hs_extmute) { |
789 | | - if (pdata->set_hs_extmute) { |
| 809 | + if (gpio_is_valid(pdata->hs_extmute_gpio)) { |
| 810 | + gpio_set_value(pdata->hs_extmute_gpio, 0); |
| 811 | + } else if (pdata->set_hs_extmute) { |
| 812 | + dev_warn(codec->dev, "set_hs_extmute is deprecated\n"); |
790 | 813 | pdata->set_hs_extmute(0); |
791 | 814 | } else { |
792 | 815 | hs_pop &= ~TWL4030_EXTMUTE; |
@@ -2236,12 +2259,17 @@ static int twl4030_soc_probe(struct snd_soc_codec *codec) |
2236 | 2259 |
|
2237 | 2260 | static int twl4030_soc_remove(struct snd_soc_codec *codec) |
2238 | 2261 | { |
| 2262 | + struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); |
2239 | 2263 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
2240 | 2264 |
|
2241 | 2265 | /* Reset registers to their chip default before leaving */ |
2242 | 2266 | twl4030_reset_registers(codec); |
2243 | 2267 | twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); |
2244 | 2268 | kfree(twl4030); |
| 2269 | + |
| 2270 | + if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio)) |
| 2271 | + gpio_free(pdata->hs_extmute_gpio); |
| 2272 | + |
2245 | 2273 | return 0; |
2246 | 2274 | } |
2247 | 2275 |
|
|
0 commit comments