Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1601040 > unrolled thread

[PATCH v2 12/17] iio: adc: ti-ads1015: Add OF device ID table

Started byJavier Martinez Canillas <javier@osg.samsung.com>
First post2017-03-15 05:50 +0100
Last post2017-03-19 12:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 12/17] iio: adc: ti-ads1015: Add OF device ID table Javier Martinez Canillas <javier@osg.samsung.com> - 2017-03-15 05:50 +0100
    Re: [PATCH v2 12/17] iio: adc: ti-ads1015: Add OF device ID table Jonathan Cameron <jic23@kernel.org> - 2017-03-19 12:00 +0100

#1601040 — [PATCH v2 12/17] iio: adc: ti-ads1015: Add OF device ID table

FromJavier Martinez Canillas <javier@osg.samsung.com>
Date2017-03-15 05:50 +0100
Subject[PATCH v2 12/17] iio: adc: ti-ads1015: Add OF device ID table
Message-ID<tl92O-2mK-23@gated-at.bofh.it>
The driver doesn't have a struct of_device_id table but supported devices
are registered via Device Trees. This is working on the assumption that a
I2C device registered via OF will always match a legacy I2C device ID and
that the MODALIAS reported will always be of the form i2c:<device>.

But this could change in the future so the correct approach is to have an
OF device ID table if the devices are registered via OF.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---

 drivers/iio/adc/ti-ads1015.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 422b314f5a3f..f76d979fb7e8 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/init.h>
 #include <linux/i2c.h>
 #include <linux/regmap.h>
@@ -55,7 +56,7 @@
 #define ADS1015_DEFAULT_DATA_RATE	4
 #define ADS1015_DEFAULT_CHAN		0
 
-enum {
+enum chip_ids {
 	ADS1015,
 	ADS1115,
 };
@@ -578,6 +579,7 @@ static int ads1015_probe(struct i2c_client *client,
 	struct iio_dev *indio_dev;
 	struct ads1015_data *data;
 	int ret;
+	enum chip_ids chip;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
 	if (!indio_dev)
@@ -593,7 +595,11 @@ static int ads1015_probe(struct i2c_client *client,
 	indio_dev->name = ADS1015_DRV_NAME;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	switch (id->driver_data) {
+	if (client->dev.of_node)
+		chip = (enum chip_ids)of_device_get_match_data(&client->dev);
+	else
+		chip = id->driver_data;
+	switch (chip) {
 	case ADS1015:
 		indio_dev->channels = ads1015_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ads1015_channels);
@@ -698,9 +704,23 @@ static const struct i2c_device_id ads1015_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, ads1015_id);
 
+static const struct of_device_id ads1015_of_match[] = {
+	{
+		.compatible = "ti,ads1015",
+		.data = (void *)ADS1015
+	},
+	{
+		.compatible = "ti,ads1115",
+		.data = (void *)ADS1115
+	},
+	{}
+};
+MODULE_DEVICE_TABLE(of, ads1015_of_match);
+
 static struct i2c_driver ads1015_driver = {
 	.driver = {
 		.name = ADS1015_DRV_NAME,
+		.of_match_table = ads1015_of_match,
 		.pm = &ads1015_pm_ops,
 	},
 	.probe		= ads1015_probe,
-- 
2.9.3

[toc] | [next] | [standalone]


#1603946

FromJonathan Cameron <jic23@kernel.org>
Date2017-03-19 12:00 +0100
Message-ID<tmGJ4-4r7-21@gated-at.bofh.it>
In reply to#1601040
On 15/03/17 04:45, Javier Martinez Canillas wrote:
> The driver doesn't have a struct of_device_id table but supported devices
> are registered via Device Trees. This is working on the assumption that a
> I2C device registered via OF will always match a legacy I2C device ID and
> that the MODALIAS reported will always be of the form i2c:<device>.
> 
> But this could change in the future so the correct approach is to have an
> OF device ID table if the devices are registered via OF.
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Applied.
> ---
> 
>  drivers/iio/adc/ti-ads1015.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 422b314f5a3f..f76d979fb7e8 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -15,6 +15,7 @@
>   */
>  
>  #include <linux/module.h>
> +#include <linux/of_device.h>
>  #include <linux/init.h>
>  #include <linux/i2c.h>
>  #include <linux/regmap.h>
> @@ -55,7 +56,7 @@
>  #define ADS1015_DEFAULT_DATA_RATE	4
>  #define ADS1015_DEFAULT_CHAN		0
>  
> -enum {
> +enum chip_ids {
>  	ADS1015,
>  	ADS1115,
>  };
> @@ -578,6 +579,7 @@ static int ads1015_probe(struct i2c_client *client,
>  	struct iio_dev *indio_dev;
>  	struct ads1015_data *data;
>  	int ret;
> +	enum chip_ids chip;
>  
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>  	if (!indio_dev)
> @@ -593,7 +595,11 @@ static int ads1015_probe(struct i2c_client *client,
>  	indio_dev->name = ADS1015_DRV_NAME;
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  
> -	switch (id->driver_data) {
> +	if (client->dev.of_node)
> +		chip = (enum chip_ids)of_device_get_match_data(&client->dev);
> +	else
> +		chip = id->driver_data;
> +	switch (chip) {
>  	case ADS1015:
>  		indio_dev->channels = ads1015_channels;
>  		indio_dev->num_channels = ARRAY_SIZE(ads1015_channels);
> @@ -698,9 +704,23 @@ static const struct i2c_device_id ads1015_id[] = {
>  };
>  MODULE_DEVICE_TABLE(i2c, ads1015_id);
>  
> +static const struct of_device_id ads1015_of_match[] = {
> +	{
> +		.compatible = "ti,ads1015",
> +		.data = (void *)ADS1015
> +	},
> +	{
> +		.compatible = "ti,ads1115",
> +		.data = (void *)ADS1115
> +	},
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, ads1015_of_match);
> +
>  static struct i2c_driver ads1015_driver = {
>  	.driver = {
>  		.name = ADS1015_DRV_NAME,
> +		.of_match_table = ads1015_of_match,
>  		.pm = &ads1015_pm_ops,
>  	},
>  	.probe		= ads1015_probe,
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web