Commit 8893cba2 authored by Fletcher Woodruff's avatar Fletcher Woodruff Committed by Mark Brown

ASoC: rt5677: fall back to DT prop names on error

The rt5677 driver uses ACPI-style property names to read from the
device API. However, these do not match the property names in _DSD
used on the Chromebook Pixel 2015, which are closer to the Device Tree
style.  Unify the two functions for reading from the device API so that
they try ACPI-style names first and fall back to the DT names on error.

With this patch, plugging and unplugging the headphone jack switches
between headphones and speakers automatically.
Signed-off-by: default avatarFletcher Woodruff <fletcherw@chromium.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9de7eadd
...@@ -5020,48 +5020,50 @@ static const struct acpi_device_id rt5677_acpi_match[] = { ...@@ -5020,48 +5020,50 @@ static const struct acpi_device_id rt5677_acpi_match[] = {
}; };
MODULE_DEVICE_TABLE(acpi, rt5677_acpi_match); MODULE_DEVICE_TABLE(acpi, rt5677_acpi_match);
static void rt5677_read_acpi_properties(struct rt5677_priv *rt5677, static void rt5677_read_device_properties(struct rt5677_priv *rt5677,
struct device *dev) struct device *dev)
{ {
u32 val; u32 val;
if (!device_property_read_u32(dev, "DCLK", &val)) rt5677->pdata.in1_diff =
rt5677->pdata.dmic2_clk_pin = val; device_property_read_bool(dev, "IN1") ||
device_property_read_bool(dev, "realtek,in1-differential");
rt5677->pdata.in1_diff = device_property_read_bool(dev, "IN1"); rt5677->pdata.in2_diff =
rt5677->pdata.in2_diff = device_property_read_bool(dev, "IN2"); device_property_read_bool(dev, "IN2") ||
rt5677->pdata.lout1_diff = device_property_read_bool(dev, "OUT1"); device_property_read_bool(dev, "realtek,in2-differential");
rt5677->pdata.lout2_diff = device_property_read_bool(dev, "OUT2");
rt5677->pdata.lout3_diff = device_property_read_bool(dev, "OUT3");
device_property_read_u32(dev, "JD1", &rt5677->pdata.jd1_gpio); rt5677->pdata.lout1_diff =
device_property_read_u32(dev, "JD2", &rt5677->pdata.jd2_gpio); device_property_read_bool(dev, "OUT1") ||
device_property_read_u32(dev, "JD3", &rt5677->pdata.jd3_gpio); device_property_read_bool(dev, "realtek,lout1-differential");
}
static void rt5677_read_device_properties(struct rt5677_priv *rt5677, rt5677->pdata.lout2_diff =
struct device *dev) device_property_read_bool(dev, "OUT2") ||
{ device_property_read_bool(dev, "realtek,lout2-differential");
rt5677->pdata.in1_diff = device_property_read_bool(dev,
"realtek,in1-differential"); rt5677->pdata.lout3_diff =
rt5677->pdata.in2_diff = device_property_read_bool(dev, device_property_read_bool(dev, "OUT3") ||
"realtek,in2-differential"); device_property_read_bool(dev, "realtek,lout3-differential");
rt5677->pdata.lout1_diff = device_property_read_bool(dev,
"realtek,lout1-differential");
rt5677->pdata.lout2_diff = device_property_read_bool(dev,
"realtek,lout2-differential");
rt5677->pdata.lout3_diff = device_property_read_bool(dev,
"realtek,lout3-differential");
device_property_read_u8_array(dev, "realtek,gpio-config", device_property_read_u8_array(dev, "realtek,gpio-config",
rt5677->pdata.gpio_config, RT5677_GPIO_NUM); rt5677->pdata.gpio_config,
RT5677_GPIO_NUM);
device_property_read_u32(dev, "realtek,jd1-gpio",
&rt5677->pdata.jd1_gpio); if (!device_property_read_u32(dev, "DCLK", &val) ||
device_property_read_u32(dev, "realtek,jd2-gpio", !device_property_read_u32(dev, "realtek,dmic2_clk_pin", &val))
&rt5677->pdata.jd2_gpio); rt5677->pdata.dmic2_clk_pin = val;
device_property_read_u32(dev, "realtek,jd3-gpio",
&rt5677->pdata.jd3_gpio); if (!device_property_read_u32(dev, "JD1", &val) ||
!device_property_read_u32(dev, "realtek,jd1-gpio", &val))
rt5677->pdata.jd1_gpio = val;
if (!device_property_read_u32(dev, "JD2", &val) ||
!device_property_read_u32(dev, "realtek,jd2-gpio", &val))
rt5677->pdata.jd2_gpio = val;
if (!device_property_read_u32(dev, "JD3", &val) ||
!device_property_read_u32(dev, "realtek,jd3-gpio", &val))
rt5677->pdata.jd3_gpio = val;
} }
static struct regmap_irq rt5677_irqs[] = { static struct regmap_irq rt5677_irqs[] = {
...@@ -5144,20 +5146,18 @@ static int rt5677_i2c_probe(struct i2c_client *i2c) ...@@ -5144,20 +5146,18 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
match_id = of_match_device(rt5677_of_match, &i2c->dev); match_id = of_match_device(rt5677_of_match, &i2c->dev);
if (match_id) if (match_id)
rt5677->type = (enum rt5677_type)match_id->data; rt5677->type = (enum rt5677_type)match_id->data;
rt5677_read_device_properties(rt5677, &i2c->dev);
} else if (ACPI_HANDLE(&i2c->dev)) { } else if (ACPI_HANDLE(&i2c->dev)) {
const struct acpi_device_id *acpi_id; const struct acpi_device_id *acpi_id;
acpi_id = acpi_match_device(rt5677_acpi_match, &i2c->dev); acpi_id = acpi_match_device(rt5677_acpi_match, &i2c->dev);
if (acpi_id) if (acpi_id)
rt5677->type = (enum rt5677_type)acpi_id->driver_data; rt5677->type = (enum rt5677_type)acpi_id->driver_data;
rt5677_read_acpi_properties(rt5677, &i2c->dev);
} else { } else {
return -EINVAL; return -EINVAL;
} }
rt5677_read_device_properties(rt5677, &i2c->dev);
/* pow-ldo2 and reset are optional. The codec pins may be statically /* pow-ldo2 and reset are optional. The codec pins may be statically
* connected on the board without gpios. If the gpio device property * connected on the board without gpios. If the gpio device property
* isn't specified, devm_gpiod_get_optional returns NULL. * isn't specified, devm_gpiod_get_optional returns NULL.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment