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