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,
}, .probe = adau1701_i2c_probe, .remove = adau1701_i2c_remove,.of_match_table = of_match_ptr(adau1701_dt_ids),