iio: potentiometer: mcp4131: use of_device_get_match_data()

Try to get the device's data using OF API. In case of failure, fallback
to the spi_get_device_id() method.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Slawomir Stepien 2018-11-16 10:47:21 +01:00 committed by Jonathan Cameron
parent cc9c58ef6e
commit 853bfaf435

View File

@ -42,6 +42,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#define MCP4131_WRITE (0x00 << 2) #define MCP4131_WRITE (0x00 << 2)
@ -243,7 +244,7 @@ static int mcp4131_probe(struct spi_device *spi)
{ {
int err; int err;
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
unsigned long devid = spi_get_device_id(spi)->driver_data; unsigned long devid;
struct mcp4131_data *data; struct mcp4131_data *data;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
@ -254,7 +255,11 @@ static int mcp4131_probe(struct spi_device *spi)
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
data->spi = spi; data->spi = spi;
data->cfg = &mcp4131_cfg[devid]; data->cfg = of_device_get_match_data(&spi->dev);
if (!data->cfg) {
devid = spi_get_device_id(spi)->driver_data;
data->cfg = &mcp4131_cfg[devid];
}
mutex_init(&data->lock); mutex_init(&data->lock);
@ -273,7 +278,6 @@ static int mcp4131_probe(struct spi_device *spi)
return 0; return 0;
} }
#if defined(CONFIG_OF)
static const struct of_device_id mcp4131_dt_ids[] = { static const struct of_device_id mcp4131_dt_ids[] = {
{ .compatible = "microchip,mcp4131-502", { .compatible = "microchip,mcp4131-502",
.data = &mcp4131_cfg[MCP413x_502] }, .data = &mcp4131_cfg[MCP413x_502] },
@ -406,7 +410,6 @@ static const struct of_device_id mcp4131_dt_ids[] = {
{} {}
}; };
MODULE_DEVICE_TABLE(of, mcp4131_dt_ids); MODULE_DEVICE_TABLE(of, mcp4131_dt_ids);
#endif /* CONFIG_OF */
static const struct spi_device_id mcp4131_id[] = { static const struct spi_device_id mcp4131_id[] = {
{ "mcp4131-502", MCP413x_502 }, { "mcp4131-502", MCP413x_502 },