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

iio: dac: ad5755: make use of of_device_id table

Store pointers to chip info (struct ad5755_chip_info) in driver match
data, instead of enum, so every value will be != 0, populate the
of_device_id table and use it in driver. Even though it is one change,
it gives multiple benefits:
1. Allows to use spi_get_device_match_data() dropping local 'type'
variable.
2. Makes both ID tables usable, so kernel can match via any of these
methods.
3. Code is more obvious as both tables are properly filled.
4. Fixes W=1 warning:
ad5755.c:866:34: error: unused variable 'ad5755_of_match' [-Werror,-Wunused-const-variable]

Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240413154511.52576-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Krzysztof Kozlowski and committed by
Jonathan Cameron
62d3fb9d 88b49449

+12 -12
+12 -12
drivers/iio/dac/ad5755.c
··· 809 809 810 810 static int ad5755_probe(struct spi_device *spi) 811 811 { 812 - enum ad5755_type type = spi_get_device_id(spi)->driver_data; 813 812 const struct ad5755_platform_data *pdata; 814 813 struct iio_dev *indio_dev; 815 814 struct ad5755_state *st; ··· 823 824 st = iio_priv(indio_dev); 824 825 spi_set_drvdata(spi, indio_dev); 825 826 826 - st->chip_info = &ad5755_chip_info_tbl[type]; 827 + st->chip_info = spi_get_device_match_data(spi); 827 828 st->spi = spi; 828 829 st->pwr_down = 0xf; 829 830 ··· 853 854 } 854 855 855 856 static const struct spi_device_id ad5755_id[] = { 856 - { "ad5755", ID_AD5755 }, 857 - { "ad5755-1", ID_AD5755 }, 858 - { "ad5757", ID_AD5757 }, 859 - { "ad5735", ID_AD5735 }, 860 - { "ad5737", ID_AD5737 }, 857 + { "ad5755", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] }, 858 + { "ad5755-1", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] }, 859 + { "ad5757", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5757] }, 860 + { "ad5735", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5735] }, 861 + { "ad5737", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5737] }, 861 862 {} 862 863 }; 863 864 MODULE_DEVICE_TABLE(spi, ad5755_id); 864 865 865 866 static const struct of_device_id ad5755_of_match[] = { 866 - { .compatible = "adi,ad5755" }, 867 - { .compatible = "adi,ad5755-1" }, 868 - { .compatible = "adi,ad5757" }, 869 - { .compatible = "adi,ad5735" }, 870 - { .compatible = "adi,ad5737" }, 867 + { .compatible = "adi,ad5755", &ad5755_chip_info_tbl[ID_AD5755] }, 868 + { .compatible = "adi,ad5755-1", &ad5755_chip_info_tbl[ID_AD5755] }, 869 + { .compatible = "adi,ad5757", &ad5755_chip_info_tbl[ID_AD5757] }, 870 + { .compatible = "adi,ad5735", &ad5755_chip_info_tbl[ID_AD5735] }, 871 + { .compatible = "adi,ad5737", &ad5755_chip_info_tbl[ID_AD5737] }, 871 872 { } 872 873 }; 873 874 MODULE_DEVICE_TABLE(of, ad5755_of_match); ··· 875 876 static struct spi_driver ad5755_driver = { 876 877 .driver = { 877 878 .name = "ad5755", 879 + .of_match_table = ad5755_of_match, 878 880 }, 879 881 .probe = ad5755_probe, 880 882 .id_table = ad5755_id,