|
@@ -15,13 +15,12 @@
|
|
|
#include <linux/init.h>
|
|
|
#include <linux/delay.h>
|
|
|
#include <linux/pm.h>
|
|
|
-#include <linux/of_gpio.h>
|
|
|
#include <linux/regmap.h>
|
|
|
#include <linux/i2c.h>
|
|
|
#include <linux/platform_device.h>
|
|
|
#include <linux/spi/spi.h>
|
|
|
#include <linux/firmware.h>
|
|
|
-#include <linux/gpio.h>
|
|
|
+#include <linux/property.h>
|
|
|
#include <sound/core.h>
|
|
|
#include <sound/pcm.h>
|
|
|
#include <sound/pcm_params.h>
|
|
@@ -746,14 +745,14 @@ static int rt5677_set_dsp_vad(struct snd_soc_codec *codec, bool on)
|
|
|
ret = request_firmware(&rt5677->fw1, RT5677_FIRMWARE1,
|
|
|
codec->dev);
|
|
|
if (ret == 0) {
|
|
|
- rt5677_spi_burst_write(0x50000000, rt5677->fw1);
|
|
|
+ rt5677_spi_write_firmware(0x50000000, rt5677->fw1);
|
|
|
release_firmware(rt5677->fw1);
|
|
|
}
|
|
|
|
|
|
ret = request_firmware(&rt5677->fw2, RT5677_FIRMWARE2,
|
|
|
codec->dev);
|
|
|
if (ret == 0) {
|
|
|
- rt5677_spi_burst_write(0x60000000, rt5677->fw2);
|
|
|
+ rt5677_spi_write_firmware(0x60000000, rt5677->fw2);
|
|
|
release_firmware(rt5677->fw2);
|
|
|
}
|
|
|
|
|
@@ -4767,10 +4766,8 @@ static int rt5677_remove(struct snd_soc_codec *codec)
|
|
|
struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec);
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2))
|
|
|
- gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
|
|
|
- if (gpio_is_valid(rt5677->reset_pin))
|
|
|
- gpio_set_value_cansleep(rt5677->reset_pin, 0);
|
|
|
+ gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
|
|
|
+ gpiod_set_value_cansleep(rt5677->reset_pin, 0);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -4784,10 +4781,8 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
|
|
|
regcache_cache_only(rt5677->regmap, true);
|
|
|
regcache_mark_dirty(rt5677->regmap);
|
|
|
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2))
|
|
|
- gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
|
|
|
- if (gpio_is_valid(rt5677->reset_pin))
|
|
|
- gpio_set_value_cansleep(rt5677->reset_pin, 0);
|
|
|
+ gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
|
|
|
+ gpiod_set_value_cansleep(rt5677->reset_pin, 0);
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
@@ -4798,12 +4793,9 @@ static int rt5677_resume(struct snd_soc_codec *codec)
|
|
|
struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
if (!rt5677->dsp_vad_en) {
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2))
|
|
|
- gpio_set_value_cansleep(rt5677->pow_ldo2, 1);
|
|
|
- if (gpio_is_valid(rt5677->reset_pin))
|
|
|
- gpio_set_value_cansleep(rt5677->reset_pin, 1);
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2) ||
|
|
|
- gpio_is_valid(rt5677->reset_pin))
|
|
|
+ gpiod_set_value_cansleep(rt5677->pow_ldo2, 1);
|
|
|
+ gpiod_set_value_cansleep(rt5677->reset_pin, 1);
|
|
|
+ if (rt5677->pow_ldo2 || rt5677->reset_pin)
|
|
|
msleep(10);
|
|
|
|
|
|
regcache_cache_only(rt5677->regmap, false);
|
|
@@ -5027,45 +5019,29 @@ static const struct i2c_device_id rt5677_i2c_id[] = {
|
|
|
};
|
|
|
MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id);
|
|
|
|
|
|
-static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np)
|
|
|
+static void rt5677_read_device_properties(struct rt5677_priv *rt5677,
|
|
|
+ struct device *dev)
|
|
|
{
|
|
|
- rt5677->pdata.in1_diff = of_property_read_bool(np,
|
|
|
- "realtek,in1-differential");
|
|
|
- rt5677->pdata.in2_diff = of_property_read_bool(np,
|
|
|
- "realtek,in2-differential");
|
|
|
- rt5677->pdata.lout1_diff = of_property_read_bool(np,
|
|
|
- "realtek,lout1-differential");
|
|
|
- rt5677->pdata.lout2_diff = of_property_read_bool(np,
|
|
|
- "realtek,lout2-differential");
|
|
|
- rt5677->pdata.lout3_diff = of_property_read_bool(np,
|
|
|
- "realtek,lout3-differential");
|
|
|
-
|
|
|
- rt5677->pow_ldo2 = of_get_named_gpio(np,
|
|
|
- "realtek,pow-ldo2-gpio", 0);
|
|
|
- rt5677->reset_pin = of_get_named_gpio(np,
|
|
|
- "realtek,reset-gpio", 0);
|
|
|
-
|
|
|
- /*
|
|
|
- * POW_LDO2 is optional (it may be statically tied on the board).
|
|
|
- * -ENOENT means that the property doesn't exist, i.e. there is no
|
|
|
- * GPIO, so is not an error. Any other error code means the property
|
|
|
- * exists, but could not be parsed.
|
|
|
- */
|
|
|
- if (!gpio_is_valid(rt5677->pow_ldo2) &&
|
|
|
- (rt5677->pow_ldo2 != -ENOENT))
|
|
|
- return rt5677->pow_ldo2;
|
|
|
- if (!gpio_is_valid(rt5677->reset_pin) &&
|
|
|
- (rt5677->reset_pin != -ENOENT))
|
|
|
- return rt5677->reset_pin;
|
|
|
-
|
|
|
- of_property_read_u8_array(np, "realtek,gpio-config",
|
|
|
- rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
|
|
|
-
|
|
|
- of_property_read_u32(np, "realtek,jd1-gpio", &rt5677->pdata.jd1_gpio);
|
|
|
- of_property_read_u32(np, "realtek,jd2-gpio", &rt5677->pdata.jd2_gpio);
|
|
|
- of_property_read_u32(np, "realtek,jd3-gpio", &rt5677->pdata.jd3_gpio);
|
|
|
-
|
|
|
- return 0;
|
|
|
+ rt5677->pdata.in1_diff = device_property_read_bool(dev,
|
|
|
+ "realtek,in1-differential");
|
|
|
+ rt5677->pdata.in2_diff = device_property_read_bool(dev,
|
|
|
+ "realtek,in2-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",
|
|
|
+ rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
|
|
|
+
|
|
|
+ device_property_read_u32(dev, "realtek,jd1-gpio",
|
|
|
+ &rt5677->pdata.jd1_gpio);
|
|
|
+ device_property_read_u32(dev, "realtek,jd2-gpio",
|
|
|
+ &rt5677->pdata.jd2_gpio);
|
|
|
+ device_property_read_u32(dev, "realtek,jd3-gpio",
|
|
|
+ &rt5677->pdata.jd3_gpio);
|
|
|
}
|
|
|
|
|
|
static struct regmap_irq rt5677_irqs[] = {
|
|
@@ -5148,43 +5124,29 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
|
|
|
|
|
|
if (pdata)
|
|
|
rt5677->pdata = *pdata;
|
|
|
+ else
|
|
|
+ rt5677_read_device_properties(rt5677, &i2c->dev);
|
|
|
|
|
|
- if (i2c->dev.of_node) {
|
|
|
- ret = rt5677_parse_dt(rt5677, i2c->dev.of_node);
|
|
|
- if (ret) {
|
|
|
- dev_err(&i2c->dev, "Failed to parse device tree: %d\n",
|
|
|
- ret);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- } else {
|
|
|
- rt5677->pow_ldo2 = -EINVAL;
|
|
|
- rt5677->reset_pin = -EINVAL;
|
|
|
- }
|
|
|
-
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2)) {
|
|
|
- ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2,
|
|
|
- GPIOF_OUT_INIT_HIGH,
|
|
|
- "RT5677 POW_LDO2");
|
|
|
- if (ret < 0) {
|
|
|
- dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n",
|
|
|
- rt5677->pow_ldo2, ret);
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ /* pow-ldo2 and reset are optional. The codec pins may be statically
|
|
|
+ * connected on the board without gpios. If the gpio device property
|
|
|
+ * isn't specified, devm_gpiod_get_optional returns NULL.
|
|
|
+ */
|
|
|
+ rt5677->pow_ldo2 = devm_gpiod_get_optional(&i2c->dev,
|
|
|
+ "realtek,pow-ldo2", GPIOD_OUT_HIGH);
|
|
|
+ if (IS_ERR(rt5677->pow_ldo2)) {
|
|
|
+ ret = PTR_ERR(rt5677->pow_ldo2);
|
|
|
+ dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret);
|
|
|
+ return ret;
|
|
|
}
|
|
|
-
|
|
|
- if (gpio_is_valid(rt5677->reset_pin)) {
|
|
|
- ret = devm_gpio_request_one(&i2c->dev, rt5677->reset_pin,
|
|
|
- GPIOF_OUT_INIT_HIGH,
|
|
|
- "RT5677 RESET");
|
|
|
- if (ret < 0) {
|
|
|
- dev_err(&i2c->dev, "Failed to request RESET %d: %d\n",
|
|
|
- rt5677->reset_pin, ret);
|
|
|
- return ret;
|
|
|
- }
|
|
|
+ rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev,
|
|
|
+ "realtek,reset", GPIOD_OUT_HIGH);
|
|
|
+ if (IS_ERR(rt5677->reset_pin)) {
|
|
|
+ ret = PTR_ERR(rt5677->reset_pin);
|
|
|
+ dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
- if (gpio_is_valid(rt5677->pow_ldo2) ||
|
|
|
- gpio_is_valid(rt5677->reset_pin)) {
|
|
|
+ if (rt5677->pow_ldo2 || rt5677->reset_pin) {
|
|
|
/* Wait a while until I2C bus becomes available. The datasheet
|
|
|
* does not specify the exact we should wait but startup
|
|
|
* sequence mentiones at least a few milliseconds.
|
|
@@ -5212,7 +5174,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
|
|
|
regmap_read(rt5677->regmap, RT5677_VENDOR_ID2, &val);
|
|
|
if (val != RT5677_DEVICE_ID) {
|
|
|
dev_err(&i2c->dev,
|
|
|
- "Device with ID register %x is not rt5677\n", val);
|
|
|
+ "Device with ID register %#x is not rt5677\n", val);
|
|
|
return -ENODEV;
|
|
|
}
|
|
|
|