* [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function
@ 2013-05-23 11:58 Daniel Mack
2013-05-23 11:58 ` [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings Daniel Mack
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Daniel Mack @ 2013-05-23 11:58 UTC (permalink / raw)
To: alsa-devel; +Cc: broonie, lars, lgirdwood, Daniel Mack
Pass a struct i2c_client * to adau1701_load_firmware directly to make
the code more readable.
Signed-off-by: Daniel Mack <zonque@gmail.com>
---
sound/soc/codecs/adau1701.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index dafdbe8..95e1677 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -180,9 +180,9 @@ static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg)
return value;
}
-static int adau1701_load_firmware(struct snd_soc_codec *codec)
+static int adau1701_load_firmware(struct i2c_client *client)
{
- return process_sigma_firmware(codec->control_data, ADAU1701_FIRMWARE);
+ return process_sigma_firmware(client, ADAU1701_FIRMWARE);
}
static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec,
@@ -455,10 +455,11 @@ static struct snd_soc_dai_driver adau1701_dai = {
static int adau1701_probe(struct snd_soc_codec *codec)
{
int ret;
+ struct i2c_client *client = to_i2c_client(codec->dev);
- codec->control_data = to_i2c_client(codec->dev);
+ codec->control_data = client;
- ret = adau1701_load_firmware(codec);
+ ret = adau1701_load_firmware(client);
if (ret)
dev_warn(codec->dev, "Failed to load firmware\n");
--
1.8.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings
2013-05-23 11:58 [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Daniel Mack
@ 2013-05-23 11:58 ` Daniel Mack
2013-05-23 13:20 ` Lars-Peter Clausen
2013-05-23 13:13 ` [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Lars-Peter Clausen
2013-05-23 14:00 ` Mark Brown
2 siblings, 1 reply; 5+ messages in thread
From: Daniel Mack @ 2013-05-23 11:58 UTC (permalink / raw)
To: alsa-devel; +Cc: broonie, lars, lgirdwood, Daniel Mack
Apart from pure matching, the bindings also support setting the the
reset gpio line.
Signed-off-by: Daniel Mack <zonque@gmail.com>
---
.../devicetree/bindings/sound/adi,adau1701.txt | 23 ++++++++++++++++
sound/soc/codecs/adau1701.c | 31 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 Documentation/devicetree/bindings/sound/adi,adau1701.txt
diff --git a/Documentation/devicetree/bindings/sound/adi,adau1701.txt b/Documentation/devicetree/bindings/sound/adi,adau1701.txt
new file mode 100644
index 0000000..3afeda7
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/adi,adau1701.txt
@@ -0,0 +1,23 @@
+Analog Devices ADAU1701
+
+Required properties:
+
+ - compatible: Should contain "adi,adau1701"
+ - reg: The i2c address. Value depends on the state of ADDR0
+ and ADDR1, as wired in hardware.
+
+Optional properties:
+
+ - reset-gpio: A GPIO spec to define which pin is connected to the
+ chip's !RESET pin. If specified, the driver will
+ assert a hardware reset at probe time.
+
+Examples:
+
+ i2c_bus {
+ adau1701@34 {
+ compatible = "adi,adau1701";
+ reg = <0x34>;
+ reset-gpio = <&gpio 23 0>;
+ };
+ };
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index 95e1677..6515ba7 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -13,6 +13,9 @@
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/of_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -452,13 +455,40 @@ static struct snd_soc_dai_driver adau1701_dai = {
.symmetric_rates = 1,
};
+#ifdef CONFIG_OF
+static const struct of_device_id adau1701_dt_ids[] = {
+ { .compatible = "adi,adau1701", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, adau1701_dt_ids);
+#endif
+
static int adau1701_probe(struct snd_soc_codec *codec)
{
int ret;
+ struct device *dev = codec->dev;
struct i2c_client *client = to_i2c_client(codec->dev);
+ int gpio_nreset = -EINVAL;
codec->control_data = client;
+ if (of_match_device(of_match_ptr(adau1701_dt_ids), dev))
+ gpio_nreset = of_get_named_gpio(dev->of_node,
+ "reset-gpio", 0);
+
+ if (gpio_is_valid(gpio_nreset)) {
+ if (devm_gpio_request_one(codec->dev, gpio_nreset,
+ GPIOF_OUT_INIT_LOW,
+ "ADAU1701 Reset") < 0)
+ return -EINVAL;
+
+ /* minimum reset time is 20ns */
+ udelay(1);
+ gpio_set_value(gpio_nreset, 1);
+ /* power-up time may be as long as 85ms */
+ mdelay(85);
+ }
+
ret = adau1701_load_firmware(client);
if (ret)
dev_warn(codec->dev, "Failed to load firmware\n");
@@ -522,6 +552,7 @@ static struct i2c_driver adau1701_i2c_driver = {
.driver = {
.name = "adau1701",
.owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(adau1701_dt_ids),
},
.probe = adau1701_i2c_probe,
.remove = adau1701_i2c_remove,
--
1.8.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function
2013-05-23 11:58 [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Daniel Mack
2013-05-23 11:58 ` [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings Daniel Mack
@ 2013-05-23 13:13 ` Lars-Peter Clausen
2013-05-23 14:00 ` Mark Brown
2 siblings, 0 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2013-05-23 13:13 UTC (permalink / raw)
To: Daniel Mack; +Cc: alsa-devel, broonie, lgirdwood
On 05/23/2013 01:58 PM, Daniel Mack wrote:
> Pass a struct i2c_client * to adau1701_load_firmware directly to make
> the code more readable.
>
> Signed-off-by: Daniel Mack <zonque@gmail.com>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> sound/soc/codecs/adau1701.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
> index dafdbe8..95e1677 100644
> --- a/sound/soc/codecs/adau1701.c
> +++ b/sound/soc/codecs/adau1701.c
> @@ -180,9 +180,9 @@ static unsigned int adau1701_read(struct snd_soc_codec *codec, unsigned int reg)
> return value;
> }
>
> -static int adau1701_load_firmware(struct snd_soc_codec *codec)
> +static int adau1701_load_firmware(struct i2c_client *client)
> {
> - return process_sigma_firmware(codec->control_data, ADAU1701_FIRMWARE);
> + return process_sigma_firmware(client, ADAU1701_FIRMWARE);
> }
>
> static int adau1701_set_capture_pcm_format(struct snd_soc_codec *codec,
> @@ -455,10 +455,11 @@ static struct snd_soc_dai_driver adau1701_dai = {
> static int adau1701_probe(struct snd_soc_codec *codec)
> {
> int ret;
> + struct i2c_client *client = to_i2c_client(codec->dev);
>
> - codec->control_data = to_i2c_client(codec->dev);
> + codec->control_data = client;
>
> - ret = adau1701_load_firmware(codec);
> + ret = adau1701_load_firmware(client);
> if (ret)
> dev_warn(codec->dev, "Failed to load firmware\n");
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings
2013-05-23 11:58 ` [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings Daniel Mack
@ 2013-05-23 13:20 ` Lars-Peter Clausen
0 siblings, 0 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2013-05-23 13:20 UTC (permalink / raw)
To: Daniel Mack; +Cc: alsa-devel, broonie, lgirdwood
On 05/23/2013 01:58 PM, Daniel Mack wrote:
[...]
> +#ifdef CONFIG_OF
> +static const struct of_device_id adau1701_dt_ids[] = {
> + { .compatible = "adi,adau1701", },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, adau1701_dt_ids);
> +#endif
> +
> static int adau1701_probe(struct snd_soc_codec *codec)
> {
> int ret;
> + struct device *dev = codec->dev;
> struct i2c_client *client = to_i2c_client(codec->dev);
> + int gpio_nreset = -EINVAL;
>
> codec->control_data = client;
>
> + if (of_match_device(of_match_ptr(adau1701_dt_ids), dev))
I think just checking for dev->of_node should be simpler.
> + gpio_nreset = of_get_named_gpio(dev->of_node,
> + "reset-gpio", 0);
This should check for errors. E.g. we definitely want to handle
-EPROBE_DEFER, but it makes sense to also return an error if the property is
present but something is wrong.
E.g something like
if (gpio_nreset < 0 && gpio_nreset != -ENOENT)
return gpio_nreset;
> +
> + if (gpio_is_valid(gpio_nreset)) {
> + if (devm_gpio_request_one(codec->dev, gpio_nreset,
> + GPIOF_OUT_INIT_LOW,
> + "ADAU1701 Reset") < 0)
> + return -EINVAL;
> +
> + /* minimum reset time is 20ns */
> + udelay(1);
> + gpio_set_value(gpio_nreset, 1);
> + /* power-up time may be as long as 85ms */
> + mdelay(85);
> + }
I think it is better to request the gpio and reset the device in the i2c
probe function.
> +
> ret = adau1701_load_firmware(client);
> if (ret)
> dev_warn(codec->dev, "Failed to load firmware\n");
> @@ -522,6 +552,7 @@ static struct i2c_driver adau1701_i2c_driver = {
> .driver = {
> .name = "adau1701",
> .owner = THIS_MODULE,
> + .of_match_table = of_match_ptr(adau1701_dt_ids),
> },
> .probe = adau1701_i2c_probe,
> .remove = adau1701_i2c_remove,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function
2013-05-23 11:58 [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Daniel Mack
2013-05-23 11:58 ` [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings Daniel Mack
2013-05-23 13:13 ` [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Lars-Peter Clausen
@ 2013-05-23 14:00 ` Mark Brown
2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2013-05-23 14:00 UTC (permalink / raw)
To: Daniel Mack; +Cc: alsa-devel, lars, lgirdwood
[-- Attachment #1.1: Type: text/plain, Size: 177 bytes --]
On Thu, May 23, 2013 at 01:58:00PM +0200, Daniel Mack wrote:
> Pass a struct i2c_client * to adau1701_load_firmware directly to make
> the code more readable.
Applied, thanks.
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-05-23 14:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-23 11:58 [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Daniel Mack
2013-05-23 11:58 ` [PATCH 2/2] ASoC: codecs: adau1701: add DT bindings Daniel Mack
2013-05-23 13:20 ` Lars-Peter Clausen
2013-05-23 13:13 ` [PATCH 1/2] ASoC: codecs: adau1701: refactor firmware loading function Lars-Peter Clausen
2013-05-23 14:00 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.