Skip to content

Commit a2a43fd

Browse files
espirikijic23
authored andcommitted
iio: dac: dac5571: Fix chip id detection for OF devices
When matching an OF device, the match mechanism tries all components of the compatible property. This can result with a device matched with a compatible string that isn't the first in the compatible list. For instance, with a compatible property set to compatible = "ti,dac081c081", "ti,dac5571"; the driver will match the second compatible string, as the first one isn't listed in the of_device_id table. The device will however be named "dac081c081" by the I2C core. This causes an issue when identifying the chip. The probe function receives a i2c_device_id that comes from the module's I2C device ID table. There is no entry in that table for "dac081c081", which results in a NULL pointer passed to the probe function. To fix this, add chip_id information in the data field of the OF device ID table, and retrieve it with device_get_match_data() for OF devices. Signed-off-by: Jose Cazarin <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d926054 commit a2a43fd

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

drivers/iio/dac/ti-dac5571.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/i2c.h>
2020
#include <linux/module.h>
2121
#include <linux/mod_devicetable.h>
22+
#include <linux/property.h>
2223
#include <linux/regulator/consumer.h>
2324

2425
enum chip_id {
@@ -311,6 +312,7 @@ static int dac5571_probe(struct i2c_client *client,
311312
const struct dac5571_spec *spec;
312313
struct dac5571_data *data;
313314
struct iio_dev *indio_dev;
315+
enum chip_id chip_id;
314316
int ret, i;
315317

316318
indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
@@ -326,7 +328,13 @@ static int dac5571_probe(struct i2c_client *client,
326328
indio_dev->modes = INDIO_DIRECT_MODE;
327329
indio_dev->channels = dac5571_channels;
328330

329-
spec = &dac5571_spec[id->driver_data];
331+
if (dev_fwnode(dev))
332+
chip_id = (uintptr_t)device_get_match_data(dev);
333+
else
334+
chip_id = id->driver_data;
335+
336+
spec = &dac5571_spec[chip_id];
337+
330338
indio_dev->num_channels = spec->num_channels;
331339
data->spec = spec;
332340

@@ -385,15 +393,15 @@ static int dac5571_remove(struct i2c_client *i2c)
385393
}
386394

387395
static const struct of_device_id dac5571_of_id[] = {
388-
{.compatible = "ti,dac5571"},
389-
{.compatible = "ti,dac6571"},
390-
{.compatible = "ti,dac7571"},
391-
{.compatible = "ti,dac5574"},
392-
{.compatible = "ti,dac6574"},
393-
{.compatible = "ti,dac7574"},
394-
{.compatible = "ti,dac5573"},
395-
{.compatible = "ti,dac6573"},
396-
{.compatible = "ti,dac7573"},
396+
{.compatible = "ti,dac5571", .data = (void *)single_8bit},
397+
{.compatible = "ti,dac6571", .data = (void *)single_10bit},
398+
{.compatible = "ti,dac7571", .data = (void *)single_12bit},
399+
{.compatible = "ti,dac5574", .data = (void *)quad_8bit},
400+
{.compatible = "ti,dac6574", .data = (void *)quad_10bit},
401+
{.compatible = "ti,dac7574", .data = (void *)quad_12bit},
402+
{.compatible = "ti,dac5573", .data = (void *)quad_8bit},
403+
{.compatible = "ti,dac6573", .data = (void *)quad_10bit},
404+
{.compatible = "ti,dac7573", .data = (void *)quad_12bit},
397405
{}
398406
};
399407
MODULE_DEVICE_TABLE(of, dac5571_of_id);

0 commit comments

Comments
 (0)