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 <[email protected]>
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
Changes in v3:
1. Use pointers, according to Jonathan comments.
v2: https://lore.kernel.org/all/20240226192555.14aa178e@jic23-huawei/
An old v1:
https://lore.kernel.org/all/[email protected]/
---
drivers/iio/dac/ad5755.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
index 404865e35460..0b24cb19ac9d 100644
--- a/drivers/iio/dac/ad5755.c
+++ b/drivers/iio/dac/ad5755.c
@@ -809,7 +809,6 @@ static struct ad5755_platform_data *ad5755_parse_fw(struct device *dev)
static int ad5755_probe(struct spi_device *spi)
{
- enum ad5755_type type = spi_get_device_id(spi)->driver_data;
const struct ad5755_platform_data *pdata;
struct iio_dev *indio_dev;
struct ad5755_state *st;
@@ -824,7 +823,7 @@ static int ad5755_probe(struct spi_device *spi)
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
- st->chip_info = &ad5755_chip_info_tbl[type];
+ st->chip_info = spi_get_device_match_data(spi);
st->spi = spi;
st->pwr_down = 0xf;
@@ -854,21 +853,21 @@ static int ad5755_probe(struct spi_device *spi)
}
static const struct spi_device_id ad5755_id[] = {
- { "ad5755", ID_AD5755 },
- { "ad5755-1", ID_AD5755 },
- { "ad5757", ID_AD5757 },
- { "ad5735", ID_AD5735 },
- { "ad5737", ID_AD5737 },
+ { "ad5755", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] },
+ { "ad5755-1", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] },
+ { "ad5757", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5757] },
+ { "ad5735", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5735] },
+ { "ad5737", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5737] },
{}
};
MODULE_DEVICE_TABLE(spi, ad5755_id);
static const struct of_device_id ad5755_of_match[] = {
- { .compatible = "adi,ad5755" },
- { .compatible = "adi,ad5755-1" },
- { .compatible = "adi,ad5757" },
- { .compatible = "adi,ad5735" },
- { .compatible = "adi,ad5737" },
+ { .compatible = "adi,ad5755", &ad5755_chip_info_tbl[ID_AD5755] },
+ { .compatible = "adi,ad5755-1", &ad5755_chip_info_tbl[ID_AD5755] },
+ { .compatible = "adi,ad5757", &ad5755_chip_info_tbl[ID_AD5757] },
+ { .compatible = "adi,ad5735", &ad5755_chip_info_tbl[ID_AD5735] },
+ { .compatible = "adi,ad5737", &ad5755_chip_info_tbl[ID_AD5737] },
{ }
};
MODULE_DEVICE_TABLE(of, ad5755_of_match);
@@ -876,6 +875,7 @@ MODULE_DEVICE_TABLE(of, ad5755_of_match);
static struct spi_driver ad5755_driver = {
.driver = {
.name = "ad5755",
+ .of_match_table = ad5755_of_match,
},
.probe = ad5755_probe,
.id_table = ad5755_id,
--
2.34.1
On Sat, 13 Apr 2024 17:45:11 +0200
Krzysztof Kozlowski <[email protected]> wrote:
> 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 <[email protected]>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>
Applied but only pushed out as testing for 0-day so far, so I can rebase
to add tags (or pull it if anyone finds an issue!)
Thanks for doing this Krzysztof.
Jonathan
> ---
>
> Changes in v3:
> 1. Use pointers, according to Jonathan comments.
>
> v2: https://lore.kernel.org/all/20240226192555.14aa178e@jic23-huawei/
>
> An old v1:
> https://lore.kernel.org/all/[email protected]/
> ---
> drivers/iio/dac/ad5755.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
> index 404865e35460..0b24cb19ac9d 100644
> --- a/drivers/iio/dac/ad5755.c
> +++ b/drivers/iio/dac/ad5755.c
> @@ -809,7 +809,6 @@ static struct ad5755_platform_data *ad5755_parse_fw(struct device *dev)
>
> static int ad5755_probe(struct spi_device *spi)
> {
> - enum ad5755_type type = spi_get_device_id(spi)->driver_data;
> const struct ad5755_platform_data *pdata;
> struct iio_dev *indio_dev;
> struct ad5755_state *st;
> @@ -824,7 +823,7 @@ static int ad5755_probe(struct spi_device *spi)
> st = iio_priv(indio_dev);
> spi_set_drvdata(spi, indio_dev);
>
> - st->chip_info = &ad5755_chip_info_tbl[type];
> + st->chip_info = spi_get_device_match_data(spi);
> st->spi = spi;
> st->pwr_down = 0xf;
>
> @@ -854,21 +853,21 @@ static int ad5755_probe(struct spi_device *spi)
> }
>
> static const struct spi_device_id ad5755_id[] = {
> - { "ad5755", ID_AD5755 },
> - { "ad5755-1", ID_AD5755 },
> - { "ad5757", ID_AD5757 },
> - { "ad5735", ID_AD5735 },
> - { "ad5737", ID_AD5737 },
> + { "ad5755", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] },
> + { "ad5755-1", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5755] },
> + { "ad5757", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5757] },
> + { "ad5735", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5735] },
> + { "ad5737", (kernel_ulong_t)&ad5755_chip_info_tbl[ID_AD5737] },
> {}
> };
> MODULE_DEVICE_TABLE(spi, ad5755_id);
>
> static const struct of_device_id ad5755_of_match[] = {
> - { .compatible = "adi,ad5755" },
> - { .compatible = "adi,ad5755-1" },
> - { .compatible = "adi,ad5757" },
> - { .compatible = "adi,ad5735" },
> - { .compatible = "adi,ad5737" },
> + { .compatible = "adi,ad5755", &ad5755_chip_info_tbl[ID_AD5755] },
> + { .compatible = "adi,ad5755-1", &ad5755_chip_info_tbl[ID_AD5755] },
> + { .compatible = "adi,ad5757", &ad5755_chip_info_tbl[ID_AD5757] },
> + { .compatible = "adi,ad5735", &ad5755_chip_info_tbl[ID_AD5735] },
> + { .compatible = "adi,ad5737", &ad5755_chip_info_tbl[ID_AD5737] },
> { }
> };
> MODULE_DEVICE_TABLE(of, ad5755_of_match);
> @@ -876,6 +875,7 @@ MODULE_DEVICE_TABLE(of, ad5755_of_match);
> static struct spi_driver ad5755_driver = {
> .driver = {
> .name = "ad5755",
> + .of_match_table = ad5755_of_match,
> },
> .probe = ad5755_probe,
> .id_table = ad5755_id,