#include <linux/types.h>
#include <linux/slab.h>
#include <linux/errno.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/delay.h>
#include <linux/i2c.h>
+#include <linux/property.h>
#include <linux/workqueue.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/initval.h>
#include <sound/soc.h>
#include <sound/tlv.h>
-#include <sound/uda1380.h>
+
+#define UDA1380_DAC_CLK_SYSCLK 0
+#define UDA1380_DAC_CLK_WSPLL 1
#include "uda1380.h"
struct work_struct work;
struct i2c_client *i2c;
u16 *reg_cache;
+ struct gpio_desc *power;
+ struct gpio_desc *reset;
};
/*
static int uda1380_reset(struct snd_soc_component *component)
{
- struct uda1380_platform_data *pdata = component->dev->platform_data;
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
- if (gpio_is_valid(pdata->gpio_reset)) {
- gpio_set_value(pdata->gpio_reset, 1);
+ if (uda1380->reset) {
+ gpiod_set_value(uda1380->reset, 1);
mdelay(1);
- gpio_set_value(pdata->gpio_reset, 0);
+ gpiod_set_value(uda1380->reset, 0);
} else {
u8 data[3];
enum snd_soc_bias_level level)
{
struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
+ struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
int pm = uda1380_read_reg_cache(component, UDA1380_PM);
int reg;
- struct uda1380_platform_data *pdata = component->dev->platform_data;
switch (level) {
case SND_SOC_BIAS_ON:
break;
case SND_SOC_BIAS_STANDBY:
if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
- if (gpio_is_valid(pdata->gpio_power)) {
- gpio_set_value(pdata->gpio_power, 1);
+ if (uda1380->power) {
+ gpiod_set_value(uda1380->power, 1);
mdelay(1);
uda1380_reset(component);
}
uda1380_write(component, UDA1380_PM, 0x0);
break;
case SND_SOC_BIAS_OFF:
- if (!gpio_is_valid(pdata->gpio_power))
+ if (!uda1380->power)
break;
- gpio_set_value(pdata->gpio_power, 0);
+ gpiod_set_value(uda1380->power, 0);
/* Mark mixer regs cache dirty to sync them with
* codec regs on power on.
static int uda1380_probe(struct snd_soc_component *component)
{
- struct uda1380_platform_data *pdata =component->dev->platform_data;
struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
int ret;
uda1380->component = component;
- if (!gpio_is_valid(pdata->gpio_power)) {
+ if (!uda1380->power) {
ret = uda1380_reset(component);
if (ret)
return ret;
INIT_WORK(&uda1380->work, uda1380_flush_work);
/* set clock input */
- switch (pdata->dac_clk) {
+ switch (uda1380->dac_clk) {
case UDA1380_DAC_CLK_SYSCLK:
uda1380_write_reg_cache(component, UDA1380_CLK, 0);
break;
static int uda1380_i2c_probe(struct i2c_client *i2c)
{
- struct uda1380_platform_data *pdata = i2c->dev.platform_data;
+ struct device *dev = &i2c->dev;
struct uda1380_priv *uda1380;
int ret;
- if (!pdata)
- return -EINVAL;
-
uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv),
GFP_KERNEL);
if (uda1380 == NULL)
return -ENOMEM;
- if (gpio_is_valid(pdata->gpio_reset)) {
- ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset,
- GPIOF_OUT_INIT_LOW, "uda1380 reset");
- if (ret)
- return ret;
- }
-
- if (gpio_is_valid(pdata->gpio_power)) {
- ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power,
- GPIOF_OUT_INIT_LOW, "uda1380 power");
- if (ret)
- return ret;
- }
+ uda1380->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(uda1380->reset))
+ return dev_err_probe(dev, PTR_ERR(uda1380->reset),
+ "error obtaining reset GPIO\n");
+ gpiod_set_consumer_name(uda1380->reset, "uda1380 reset");
+
+ uda1380->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
+ if (IS_ERR(uda1380->power))
+ return dev_err_probe(dev, PTR_ERR(uda1380->power),
+ "error obtaining power GPIO\n");
+ gpiod_set_consumer_name(uda1380->power, "uda1380 power");
+
+ /* This is just some default */
+ uda1380->dac_clk = UDA1380_DAC_CLK_SYSCLK;
+ if (device_property_match_string(dev, "dac-clk", "wspll") >= 0)
+ uda1380->dac_clk = UDA1380_DAC_CLK_WSPLL;
uda1380->reg_cache = devm_kmemdup_array(&i2c->dev, uda1380_reg, ARRAY_SIZE(uda1380_reg),
sizeof(uda1380_reg[0]), GFP_KERNEL);