1 // SPDX-License-Identifier: GPL-2.0-only 2 #include <linux/device.h> 3 #include <linux/kernel.h> 4 #include <linux/spi/spi.h> 5 #include <linux/module.h> 6 #include <linux/slab.h> 7 #include <linux/regmap.h> 8 9 #include "kxsd9.h" 10 11 static int kxsd9_spi_probe(struct spi_device *spi) 12 { 13 static const struct regmap_config config = { 14 .reg_bits = 8, 15 .val_bits = 8, 16 .max_register = 0x0e, 17 }; 18 struct regmap *regmap; 19 20 spi->mode = SPI_MODE_0; 21 regmap = devm_regmap_init_spi(spi, &config); 22 if (IS_ERR(regmap)) { 23 dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", 24 __func__, PTR_ERR(regmap)); 25 return PTR_ERR(regmap); 26 } 27 28 return kxsd9_common_probe(&spi->dev, 29 regmap, 30 spi_get_device_id(spi)->name); 31 } 32 33 static int kxsd9_spi_remove(struct spi_device *spi) 34 { 35 return kxsd9_common_remove(&spi->dev); 36 } 37 38 static const struct spi_device_id kxsd9_spi_id[] = { 39 {"kxsd9", 0}, 40 { }, 41 }; 42 MODULE_DEVICE_TABLE(spi, kxsd9_spi_id); 43 44 static struct spi_driver kxsd9_spi_driver = { 45 .driver = { 46 .name = "kxsd9", 47 .pm = &kxsd9_dev_pm_ops, 48 }, 49 .probe = kxsd9_spi_probe, 50 .remove = kxsd9_spi_remove, 51 .id_table = kxsd9_spi_id, 52 }; 53 module_spi_driver(kxsd9_spi_driver); 54 55 MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 56 MODULE_DESCRIPTION("Kionix KXSD9 SPI driver"); 57 MODULE_LICENSE("GPL v2"); 58