• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2022 ROHM Semiconductors
4  *
5  * ROHM/KIONIX KX022A accelerometer driver
6  */
7 
8 #include <linux/interrupt.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
11 #include <linux/spi/spi.h>
12 
13 #include "kionix-kx022a.h"
14 
kx022a_spi_probe(struct spi_device * spi)15 static int kx022a_spi_probe(struct spi_device *spi)
16 {
17 	struct device *dev = &spi->dev;
18 	struct regmap *regmap;
19 
20 	if (!spi->irq) {
21 		dev_err(dev, "No IRQ configured\n");
22 		return -EINVAL;
23 	}
24 
25 	regmap = devm_regmap_init_spi(spi, &kx022a_regmap);
26 	if (IS_ERR(regmap))
27 		return dev_err_probe(dev, PTR_ERR(regmap),
28 				     "Failed to initialize Regmap\n");
29 
30 	return kx022a_probe_internal(dev);
31 }
32 
33 static const struct spi_device_id kx022a_id[] = {
34 	{ "kx022a" },
35 	{ }
36 };
37 MODULE_DEVICE_TABLE(spi, kx022a_id);
38 
39 static const struct of_device_id kx022a_of_match[] = {
40 	{ .compatible = "kionix,kx022a", },
41 	{ }
42 };
43 MODULE_DEVICE_TABLE(of, kx022a_of_match);
44 
45 static struct spi_driver kx022a_spi_driver = {
46 	.driver = {
47 		.name   = "kx022a-spi",
48 		.of_match_table = kx022a_of_match,
49 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
50 	},
51 	.probe = kx022a_spi_probe,
52 	.id_table = kx022a_id,
53 };
54 module_spi_driver(kx022a_spi_driver);
55 
56 MODULE_DESCRIPTION("ROHM/Kionix kx022A accelerometer driver");
57 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
58 MODULE_LICENSE("GPL");
59 MODULE_IMPORT_NS(IIO_KX022A);
60