summaryrefslogtreecommitdiff
path: root/drivers/iio/accel/kionix-kx022a-spi.c
diff options
context:
space:
mode:
authorMehdi Djait <mehdi.djait.k@gmail.com>2023-09-16 15:38:51 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2023-09-17 12:44:31 +0300
commite7123a4dfcd732c4d10620748588e3715f362802 (patch)
treeab28f207586b60b78e15e8119893df4e0c51b636 /drivers/iio/accel/kionix-kx022a-spi.c
parent13d5398a8eebcb19e3424979658d97fbe1b21891 (diff)
downloadlinux-e7123a4dfcd732c4d10620748588e3715f362802.tar.xz
iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Add the chip_info structure to the driver's private data to hold all the device specific infos. Refactor the kx022a driver implementation to make it more generic and extensible. Acked-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Mehdi Djait <mehdi.djait.k@gmail.com> Link: https://lore.kernel.org/r/7a31d0cdefba15d7c791252ec8bc5db553b3996b.1694867379.git.mehdi.djait.k@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/accel/kionix-kx022a-spi.c')
-rw-r--r--drivers/iio/accel/kionix-kx022a-spi.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c
index f45a46899a5f..c21494ade157 100644
--- a/drivers/iio/accel/kionix-kx022a-spi.c
+++ b/drivers/iio/accel/kionix-kx022a-spi.c
@@ -15,6 +15,7 @@
static int kx022a_spi_probe(struct spi_device *spi)
{
struct device *dev = &spi->dev;
+ const struct kx022a_chip_info *chip_info;
struct regmap *regmap;
if (!spi->irq) {
@@ -22,22 +23,26 @@ static int kx022a_spi_probe(struct spi_device *spi)
return -EINVAL;
}
- regmap = devm_regmap_init_spi(spi, &kx022a_regmap);
+ chip_info = spi_get_device_match_data(spi);
+ if (!chip_info)
+ return -EINVAL;
+
+ regmap = devm_regmap_init_spi(spi, chip_info->regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(dev, PTR_ERR(regmap),
"Failed to initialize Regmap\n");
- return kx022a_probe_internal(dev);
+ return kx022a_probe_internal(dev, chip_info);
}
static const struct spi_device_id kx022a_id[] = {
- { "kx022a" },
+ { .name = "kx022a", .driver_data = (kernel_ulong_t)&kx022a_chip_info },
{ }
};
MODULE_DEVICE_TABLE(spi, kx022a_id);
static const struct of_device_id kx022a_of_match[] = {
- { .compatible = "kionix,kx022a", },
+ { .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
{ }
};
MODULE_DEVICE_TABLE(of, kx022a_of_match);