109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2bf96f6e8SLinus Walleij #include <linux/device.h>
3bf96f6e8SLinus Walleij #include <linux/kernel.h>
4bf96f6e8SLinus Walleij #include <linux/spi/spi.h>
5bf96f6e8SLinus Walleij #include <linux/module.h>
6*1e0bda8cSJonathan Cameron #include <linux/mod_devicetable.h>
7bf96f6e8SLinus Walleij #include <linux/slab.h>
80d1fb2d5SLinus Walleij #include <linux/regmap.h>
9bf96f6e8SLinus Walleij
10bf96f6e8SLinus Walleij #include "kxsd9.h"
11bf96f6e8SLinus Walleij
kxsd9_spi_probe(struct spi_device * spi)12bf96f6e8SLinus Walleij static int kxsd9_spi_probe(struct spi_device *spi)
13bf96f6e8SLinus Walleij {
140d1fb2d5SLinus Walleij static const struct regmap_config config = {
150d1fb2d5SLinus Walleij .reg_bits = 8,
160d1fb2d5SLinus Walleij .val_bits = 8,
170d1fb2d5SLinus Walleij .max_register = 0x0e,
180d1fb2d5SLinus Walleij };
190d1fb2d5SLinus Walleij struct regmap *regmap;
20bf96f6e8SLinus Walleij
21bf96f6e8SLinus Walleij spi->mode = SPI_MODE_0;
220d1fb2d5SLinus Walleij regmap = devm_regmap_init_spi(spi, &config);
230d1fb2d5SLinus Walleij if (IS_ERR(regmap)) {
240d1fb2d5SLinus Walleij dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
250d1fb2d5SLinus Walleij __func__, PTR_ERR(regmap));
260d1fb2d5SLinus Walleij return PTR_ERR(regmap);
270d1fb2d5SLinus Walleij }
28bf96f6e8SLinus Walleij
290d1fb2d5SLinus Walleij return kxsd9_common_probe(&spi->dev,
300d1fb2d5SLinus Walleij regmap,
31bf96f6e8SLinus Walleij spi_get_device_id(spi)->name);
32bf96f6e8SLinus Walleij }
33bf96f6e8SLinus Walleij
kxsd9_spi_remove(struct spi_device * spi)34a0386bbaSUwe Kleine-König static void kxsd9_spi_remove(struct spi_device *spi)
35bf96f6e8SLinus Walleij {
36df2171c6SUwe Kleine-König kxsd9_common_remove(&spi->dev);
37bf96f6e8SLinus Walleij }
38bf96f6e8SLinus Walleij
39bf96f6e8SLinus Walleij static const struct spi_device_id kxsd9_spi_id[] = {
40bf96f6e8SLinus Walleij {"kxsd9", 0},
41bf96f6e8SLinus Walleij { },
42bf96f6e8SLinus Walleij };
43bf96f6e8SLinus Walleij MODULE_DEVICE_TABLE(spi, kxsd9_spi_id);
44bf96f6e8SLinus Walleij
4517b16c3cSDaniel Gomez static const struct of_device_id kxsd9_of_match[] = {
4617b16c3cSDaniel Gomez { .compatible = "kionix,kxsd9" },
4794059c52SPaul Lemmermann { }
4817b16c3cSDaniel Gomez };
4917b16c3cSDaniel Gomez MODULE_DEVICE_TABLE(of, kxsd9_of_match);
5017b16c3cSDaniel Gomez
51bf96f6e8SLinus Walleij static struct spi_driver kxsd9_spi_driver = {
52bf96f6e8SLinus Walleij .driver = {
53bf96f6e8SLinus Walleij .name = "kxsd9",
54cb490b10SJonathan Cameron .pm = pm_ptr(&kxsd9_dev_pm_ops),
5517b16c3cSDaniel Gomez .of_match_table = kxsd9_of_match,
56bf96f6e8SLinus Walleij },
57bf96f6e8SLinus Walleij .probe = kxsd9_spi_probe,
58bf96f6e8SLinus Walleij .remove = kxsd9_spi_remove,
59bf96f6e8SLinus Walleij .id_table = kxsd9_spi_id,
60bf96f6e8SLinus Walleij };
61bf96f6e8SLinus Walleij module_spi_driver(kxsd9_spi_driver);
62bf96f6e8SLinus Walleij
63bf96f6e8SLinus Walleij MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
64bf96f6e8SLinus Walleij MODULE_DESCRIPTION("Kionix KXSD9 SPI driver");
65bf96f6e8SLinus Walleij MODULE_LICENSE("GPL v2");
66c24ef124SJonathan Cameron MODULE_IMPORT_NS(IIO_KXSD9);
67