Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: ina2xx: Add OF device ID table

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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Javier Martinez Canillas and committed by
Jonathan Cameron
62aaca0d 7fa6790c

+33 -1
+33 -1
drivers/iio/adc/ina2xx-adc.c
··· 28 28 #include <linux/iio/sysfs.h> 29 29 #include <linux/kthread.h> 30 30 #include <linux/module.h> 31 + #include <linux/of_device.h> 31 32 #include <linux/regmap.h> 32 33 #include <linux/util_macros.h> 33 34 ··· 636 635 struct iio_dev *indio_dev; 637 636 struct iio_buffer *buffer; 638 637 unsigned int val; 638 + enum ina2xx_ids type; 639 639 int ret; 640 640 641 641 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); ··· 654 652 return PTR_ERR(chip->regmap); 655 653 } 656 654 657 - chip->config = &ina2xx_config[id->driver_data]; 655 + if (client->dev.of_node) 656 + type = (enum ina2xx_ids)of_device_get_match_data(&client->dev); 657 + else 658 + type = id->driver_data; 659 + chip->config = &ina2xx_config[type]; 658 660 659 661 mutex_init(&chip->state_lock); 660 662 ··· 732 726 }; 733 727 MODULE_DEVICE_TABLE(i2c, ina2xx_id); 734 728 729 + static const struct of_device_id ina2xx_of_match[] = { 730 + { 731 + .compatible = "ti,ina219", 732 + .data = (void *)ina219 733 + }, 734 + { 735 + .compatible = "ti,ina220", 736 + .data = (void *)ina219 737 + }, 738 + { 739 + .compatible = "ti,ina226", 740 + .data = (void *)ina226 741 + }, 742 + { 743 + .compatible = "ti,ina230", 744 + .data = (void *)ina226 745 + }, 746 + { 747 + .compatible = "ti,ina231", 748 + .data = (void *)ina226 749 + }, 750 + {}, 751 + }; 752 + MODULE_DEVICE_TABLE(of, ina2xx_of_match); 753 + 735 754 static struct i2c_driver ina2xx_driver = { 736 755 .driver = { 737 756 .name = KBUILD_MODNAME, 757 + .of_match_table = ina2xx_of_match, 738 758 }, 739 759 .probe = ina2xx_probe, 740 760 .remove = ina2xx_remove,