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