109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2bf96f6e8SLinus Walleij #include <linux/device.h> 3bf96f6e8SLinus Walleij #include <linux/kernel.h> 417b16c3cSDaniel Gomez #include <linux/of.h> 517b16c3cSDaniel Gomez #include <linux/of_device.h> 6bf96f6e8SLinus Walleij #include <linux/spi/spi.h> 7bf96f6e8SLinus Walleij #include <linux/module.h> 8bf96f6e8SLinus Walleij #include <linux/slab.h> 90d1fb2d5SLinus Walleij #include <linux/regmap.h> 10bf96f6e8SLinus Walleij 11bf96f6e8SLinus Walleij #include "kxsd9.h" 12bf96f6e8SLinus Walleij 13bf96f6e8SLinus Walleij static int kxsd9_spi_probe(struct spi_device *spi) 14bf96f6e8SLinus Walleij { 150d1fb2d5SLinus Walleij static const struct regmap_config config = { 160d1fb2d5SLinus Walleij .reg_bits = 8, 170d1fb2d5SLinus Walleij .val_bits = 8, 180d1fb2d5SLinus Walleij .max_register = 0x0e, 190d1fb2d5SLinus Walleij }; 200d1fb2d5SLinus Walleij struct regmap *regmap; 21bf96f6e8SLinus Walleij 22bf96f6e8SLinus Walleij spi->mode = SPI_MODE_0; 230d1fb2d5SLinus Walleij regmap = devm_regmap_init_spi(spi, &config); 240d1fb2d5SLinus Walleij if (IS_ERR(regmap)) { 250d1fb2d5SLinus Walleij dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", 260d1fb2d5SLinus Walleij __func__, PTR_ERR(regmap)); 270d1fb2d5SLinus Walleij return PTR_ERR(regmap); 280d1fb2d5SLinus Walleij } 29bf96f6e8SLinus Walleij 300d1fb2d5SLinus Walleij return kxsd9_common_probe(&spi->dev, 310d1fb2d5SLinus Walleij regmap, 32bf96f6e8SLinus Walleij spi_get_device_id(spi)->name); 33bf96f6e8SLinus Walleij } 34bf96f6e8SLinus Walleij 35bf96f6e8SLinus Walleij static int kxsd9_spi_remove(struct spi_device *spi) 36bf96f6e8SLinus Walleij { 37*df2171c6SUwe Kleine-König kxsd9_common_remove(&spi->dev); 38*df2171c6SUwe Kleine-König 39*df2171c6SUwe Kleine-König return 0; 40bf96f6e8SLinus Walleij } 41bf96f6e8SLinus Walleij 42bf96f6e8SLinus Walleij static const struct spi_device_id kxsd9_spi_id[] = { 43bf96f6e8SLinus Walleij {"kxsd9", 0}, 44bf96f6e8SLinus Walleij { }, 45bf96f6e8SLinus Walleij }; 46bf96f6e8SLinus Walleij MODULE_DEVICE_TABLE(spi, kxsd9_spi_id); 47bf96f6e8SLinus Walleij 4817b16c3cSDaniel Gomez static const struct of_device_id kxsd9_of_match[] = { 4917b16c3cSDaniel Gomez { .compatible = "kionix,kxsd9" }, 5017b16c3cSDaniel Gomez { }, 5117b16c3cSDaniel Gomez }; 5217b16c3cSDaniel Gomez MODULE_DEVICE_TABLE(of, kxsd9_of_match); 5317b16c3cSDaniel Gomez 54bf96f6e8SLinus Walleij static struct spi_driver kxsd9_spi_driver = { 55bf96f6e8SLinus Walleij .driver = { 56bf96f6e8SLinus Walleij .name = "kxsd9", 579a9a369dSLinus Walleij .pm = &kxsd9_dev_pm_ops, 5817b16c3cSDaniel Gomez .of_match_table = kxsd9_of_match, 59bf96f6e8SLinus Walleij }, 60bf96f6e8SLinus Walleij .probe = kxsd9_spi_probe, 61bf96f6e8SLinus Walleij .remove = kxsd9_spi_remove, 62bf96f6e8SLinus Walleij .id_table = kxsd9_spi_id, 63bf96f6e8SLinus Walleij }; 64bf96f6e8SLinus Walleij module_spi_driver(kxsd9_spi_driver); 65bf96f6e8SLinus Walleij 66bf96f6e8SLinus Walleij MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 67bf96f6e8SLinus Walleij MODULE_DESCRIPTION("Kionix KXSD9 SPI driver"); 68bf96f6e8SLinus Walleij MODULE_LICENSE("GPL v2"); 69