1616#include <linux/types.h>
1717#include <linux/slab.h>
1818#include <linux/errno.h>
19- #include <linux/gpio.h>
19+ #include <linux/gpio/consumer .h>
2020#include <linux/delay.h>
2121#include <linux/i2c.h>
22+ #include <linux/property.h>
2223#include <linux/workqueue.h>
2324#include <sound/core.h>
2425#include <sound/control.h>
2526#include <sound/initval.h>
2627#include <sound/soc.h>
2728#include <sound/tlv.h>
28- #include <sound/uda1380.h>
29+
30+ #define UDA1380_DAC_CLK_SYSCLK 0
31+ #define UDA1380_DAC_CLK_WSPLL 1
2932
3033#include "uda1380.h"
3134
@@ -36,6 +39,8 @@ struct uda1380_priv {
3639 struct work_struct work ;
3740 struct i2c_client * i2c ;
3841 u16 * reg_cache ;
42+ struct gpio_desc * power ;
43+ struct gpio_desc * reset ;
3944};
4045
4146/*
@@ -169,13 +174,12 @@ static void uda1380_sync_cache(struct snd_soc_component *component)
169174
170175static int uda1380_reset (struct snd_soc_component * component )
171176{
172- struct uda1380_platform_data * pdata = component -> dev -> platform_data ;
173177 struct uda1380_priv * uda1380 = snd_soc_component_get_drvdata (component );
174178
175- if (gpio_is_valid ( pdata -> gpio_reset ) ) {
176- gpio_set_value ( pdata -> gpio_reset , 1 );
179+ if (uda1380 -> reset ) {
180+ gpiod_set_value ( uda1380 -> reset , 1 );
177181 mdelay (1 );
178- gpio_set_value ( pdata -> gpio_reset , 0 );
182+ gpiod_set_value ( uda1380 -> reset , 0 );
179183 } else {
180184 u8 data [3 ];
181185
@@ -608,9 +612,9 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
608612 enum snd_soc_bias_level level )
609613{
610614 struct snd_soc_dapm_context * dapm = snd_soc_component_to_dapm (component );
615+ struct uda1380_priv * uda1380 = snd_soc_component_get_drvdata (component );
611616 int pm = uda1380_read_reg_cache (component , UDA1380_PM );
612617 int reg ;
613- struct uda1380_platform_data * pdata = component -> dev -> platform_data ;
614618
615619 switch (level ) {
616620 case SND_SOC_BIAS_ON :
@@ -620,8 +624,8 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
620624 break ;
621625 case SND_SOC_BIAS_STANDBY :
622626 if (snd_soc_dapm_get_bias_level (dapm ) == SND_SOC_BIAS_OFF ) {
623- if (gpio_is_valid ( pdata -> gpio_power ) ) {
624- gpio_set_value ( pdata -> gpio_power , 1 );
627+ if (uda1380 -> power ) {
628+ gpiod_set_value ( uda1380 -> power , 1 );
625629 mdelay (1 );
626630 uda1380_reset (component );
627631 }
@@ -631,10 +635,10 @@ static int uda1380_set_bias_level(struct snd_soc_component *component,
631635 uda1380_write (component , UDA1380_PM , 0x0 );
632636 break ;
633637 case SND_SOC_BIAS_OFF :
634- if (!gpio_is_valid ( pdata -> gpio_power ) )
638+ if (!uda1380 -> power )
635639 break ;
636640
637- gpio_set_value ( pdata -> gpio_power , 0 );
641+ gpiod_set_value ( uda1380 -> power , 0 );
638642
639643 /* Mark mixer regs cache dirty to sync them with
640644 * codec regs on power on.
@@ -713,13 +717,12 @@ static struct snd_soc_dai_driver uda1380_dai[] = {
713717
714718static int uda1380_probe (struct snd_soc_component * component )
715719{
716- struct uda1380_platform_data * pdata = component -> dev -> platform_data ;
717720 struct uda1380_priv * uda1380 = snd_soc_component_get_drvdata (component );
718721 int ret ;
719722
720723 uda1380 -> component = component ;
721724
722- if (!gpio_is_valid ( pdata -> gpio_power ) ) {
725+ if (!uda1380 -> power ) {
723726 ret = uda1380_reset (component );
724727 if (ret )
725728 return ret ;
@@ -728,7 +731,7 @@ static int uda1380_probe(struct snd_soc_component *component)
728731 INIT_WORK (& uda1380 -> work , uda1380_flush_work );
729732
730733 /* set clock input */
731- switch (pdata -> dac_clk ) {
734+ switch (uda1380 -> dac_clk ) {
732735 case UDA1380_DAC_CLK_SYSCLK :
733736 uda1380_write_reg_cache (component , UDA1380_CLK , 0 );
734737 break ;
@@ -760,31 +763,31 @@ static const struct snd_soc_component_driver soc_component_dev_uda1380 = {
760763
761764static int uda1380_i2c_probe (struct i2c_client * i2c )
762765{
763- struct uda1380_platform_data * pdata = i2c -> dev . platform_data ;
766+ struct device * dev = & i2c -> dev ;
764767 struct uda1380_priv * uda1380 ;
765768 int ret ;
766769
767- if (!pdata )
768- return - EINVAL ;
769-
770770 uda1380 = devm_kzalloc (& i2c -> dev , sizeof (struct uda1380_priv ),
771771 GFP_KERNEL );
772772 if (uda1380 == NULL )
773773 return - ENOMEM ;
774774
775- if (gpio_is_valid (pdata -> gpio_reset )) {
776- ret = devm_gpio_request_one (& i2c -> dev , pdata -> gpio_reset ,
777- GPIOF_OUT_INIT_LOW , "uda1380 reset" );
778- if (ret )
779- return ret ;
780- }
781-
782- if (gpio_is_valid (pdata -> gpio_power )) {
783- ret = devm_gpio_request_one (& i2c -> dev , pdata -> gpio_power ,
784- GPIOF_OUT_INIT_LOW , "uda1380 power" );
785- if (ret )
786- return ret ;
787- }
775+ uda1380 -> reset = devm_gpiod_get_optional (dev , "reset" , GPIOD_OUT_LOW );
776+ if (IS_ERR (uda1380 -> reset ))
777+ return dev_err_probe (dev , PTR_ERR (uda1380 -> reset ),
778+ "error obtaining reset GPIO\n" );
779+ gpiod_set_consumer_name (uda1380 -> reset , "uda1380 reset" );
780+
781+ uda1380 -> power = devm_gpiod_get_optional (dev , "power" , GPIOD_OUT_LOW );
782+ if (IS_ERR (uda1380 -> power ))
783+ return dev_err_probe (dev , PTR_ERR (uda1380 -> power ),
784+ "error obtaining power GPIO\n" );
785+ gpiod_set_consumer_name (uda1380 -> power , "uda1380 power" );
786+
787+ /* This is just some default */
788+ uda1380 -> dac_clk = UDA1380_DAC_CLK_SYSCLK ;
789+ if (device_property_match_string (dev , "dac-clk" , "wspll" ) >= 0 )
790+ uda1380 -> dac_clk = UDA1380_DAC_CLK_WSPLL ;
788791
789792 uda1380 -> reg_cache = devm_kmemdup_array (& i2c -> dev , uda1380_reg , ARRAY_SIZE (uda1380_reg ),
790793 sizeof (uda1380_reg [0 ]), GFP_KERNEL );
0 commit comments