6
6
*/
7
7
8
8
#include <linux/delay.h>
9
- #include <linux/gpio.h>
9
+ #include <linux/gpio/consumer .h>
10
10
#include <linux/i2c.h>
11
11
#include <linux/init.h>
12
12
#include <linux/mfd/twl.h>
13
13
#include <linux/mfd/twl4030-audio.h>
14
14
#include <linux/module.h>
15
15
#include <linux/moduleparam.h>
16
16
#include <linux/of.h>
17
- #include <linux/of_gpio.h>
18
17
#include <linux/pm.h>
19
18
#include <linux/platform_device.h>
20
19
#include <linux/slab.h>
@@ -37,7 +36,7 @@ struct twl4030_board_params {
37
36
unsigned int ramp_delay_value ;
38
37
unsigned int offset_cncl_path ;
39
38
unsigned int hs_extmute :1 ;
40
- int hs_extmute_gpio ;
39
+ struct gpio_desc * hs_extmute_gpio ;
41
40
};
42
41
43
42
/* codec private data */
@@ -211,8 +210,7 @@ twl4030_get_board_param_values(struct twl4030_board_params *board_params,
211
210
if (!of_property_read_u32 (node , "ti,hs_extmute" , & value ))
212
211
board_params -> hs_extmute = value ;
213
212
214
- board_params -> hs_extmute_gpio = of_get_named_gpio (node , "ti,hs_extmute_gpio" , 0 );
215
- if (gpio_is_valid (board_params -> hs_extmute_gpio ))
213
+ if (of_property_present (node , "ti,hs_extmute_gpio" ))
216
214
board_params -> hs_extmute = 1 ;
217
215
}
218
216
@@ -240,7 +238,7 @@ twl4030_get_board_params(struct snd_soc_component *component)
240
238
return board_params ;
241
239
}
242
240
243
- static void twl4030_init_chip (struct snd_soc_component * component )
241
+ static int twl4030_init_chip (struct snd_soc_component * component )
244
242
{
245
243
struct twl4030_board_params * board_params ;
246
244
struct twl4030_priv * twl4030 = snd_soc_component_get_drvdata (component );
@@ -250,24 +248,20 @@ static void twl4030_init_chip(struct snd_soc_component *component)
250
248
board_params = twl4030_get_board_params (component );
251
249
252
250
if (board_params && board_params -> hs_extmute ) {
253
- if (gpio_is_valid (board_params -> hs_extmute_gpio )) {
254
- int ret ;
255
-
256
- if (!board_params -> hs_extmute_gpio )
257
- dev_warn (component -> dev ,
258
- "Extmute GPIO is 0 is this correct?\n" );
259
-
260
- ret = gpio_request_one (board_params -> hs_extmute_gpio ,
261
- GPIOF_OUT_INIT_LOW ,
262
- "hs_extmute" );
263
- if (ret ) {
264
- dev_err (component -> dev ,
265
- "Failed to get hs_extmute GPIO\n" );
266
- board_params -> hs_extmute_gpio = -1 ;
267
- }
251
+ board_params -> hs_extmute_gpio = devm_gpiod_get_optional (component -> dev ,
252
+ "ti,hs_extmute" ,
253
+ GPIOD_OUT_LOW );
254
+ if (IS_ERR (board_params -> hs_extmute_gpio ))
255
+ return dev_err_probe (component -> dev , PTR_ERR (board_params -> hs_extmute_gpio ),
256
+ "Failed to get hs_extmute GPIO\n" );
257
+
258
+ if (board_params -> hs_extmute_gpio ) {
259
+ gpiod_set_consumer_name (board_params -> hs_extmute_gpio , "hs_extmute" );
268
260
} else {
269
261
u8 pin_mux ;
270
262
263
+ dev_info (component -> dev , "use TWL4030 GPIO6\n" );
264
+
271
265
/* Set TWL4030 GPIO6 as EXTMUTE signal */
272
266
twl_i2c_read_u8 (TWL4030_MODULE_INTBR , & pin_mux ,
273
267
TWL4030_PMBR1_REG );
@@ -295,7 +289,7 @@ static void twl4030_init_chip(struct snd_soc_component *component)
295
289
296
290
/* Machine dependent setup */
297
291
if (!board_params )
298
- return ;
292
+ return 0 ;
299
293
300
294
twl4030 -> board_params = board_params ;
301
295
@@ -330,6 +324,8 @@ static void twl4030_init_chip(struct snd_soc_component *component)
330
324
TWL4030_CNCL_OFFSET_START ));
331
325
332
326
twl4030_codec_enable (component , 0 );
327
+
328
+ return 0 ;
333
329
}
334
330
335
331
static void twl4030_apll_enable (struct snd_soc_component * component , int enable )
@@ -712,8 +708,8 @@ static void headset_ramp(struct snd_soc_component *component, int ramp)
712
708
/* Enable external mute control, this dramatically reduces
713
709
* the pop-noise */
714
710
if (board_params && board_params -> hs_extmute ) {
715
- if (gpio_is_valid ( board_params -> hs_extmute_gpio ) ) {
716
- gpio_set_value (board_params -> hs_extmute_gpio , 1 );
711
+ if (board_params -> hs_extmute_gpio ) {
712
+ gpiod_set_value (board_params -> hs_extmute_gpio , 1 );
717
713
} else {
718
714
hs_pop |= TWL4030_EXTMUTE ;
719
715
twl4030_write (component , TWL4030_REG_HS_POPN_SET , hs_pop );
@@ -748,8 +744,8 @@ static void headset_ramp(struct snd_soc_component *component, int ramp)
748
744
749
745
/* Disable external mute */
750
746
if (board_params && board_params -> hs_extmute ) {
751
- if (gpio_is_valid ( board_params -> hs_extmute_gpio ) ) {
752
- gpio_set_value (board_params -> hs_extmute_gpio , 0 );
747
+ if (board_params -> hs_extmute_gpio ) {
748
+ gpiod_set_value (board_params -> hs_extmute_gpio , 0 );
753
749
} else {
754
750
hs_pop &= ~TWL4030_EXTMUTE ;
755
751
twl4030_write (component , TWL4030_REG_HS_POPN_SET , hs_pop );
@@ -2166,24 +2162,11 @@ static int twl4030_soc_probe(struct snd_soc_component *component)
2166
2162
/* Set the defaults, and power up the codec */
2167
2163
twl4030 -> sysclk = twl4030_audio_get_mclk () / 1000 ;
2168
2164
2169
- twl4030_init_chip (component );
2170
-
2171
- return 0 ;
2172
- }
2173
-
2174
- static void twl4030_soc_remove (struct snd_soc_component * component )
2175
- {
2176
- struct twl4030_priv * twl4030 = snd_soc_component_get_drvdata (component );
2177
- struct twl4030_board_params * board_params = twl4030 -> board_params ;
2178
-
2179
- if (board_params && board_params -> hs_extmute &&
2180
- gpio_is_valid (board_params -> hs_extmute_gpio ))
2181
- gpio_free (board_params -> hs_extmute_gpio );
2165
+ return twl4030_init_chip (component );
2182
2166
}
2183
2167
2184
2168
static const struct snd_soc_component_driver soc_component_dev_twl4030 = {
2185
2169
.probe = twl4030_soc_probe ,
2186
- .remove = twl4030_soc_remove ,
2187
2170
.read = twl4030_read ,
2188
2171
.write = twl4030_write ,
2189
2172
.set_bias_level = twl4030_set_bias_level ,
0 commit comments