xref: /linux/drivers/iio/accel/kionix-kx022a-i2c.c (revision 1b0975ee3bdd3eb19a47371c26fd7ef8f7f6b599)
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/i2c.h>
9 #include <linux/interrupt.h>
10 #include <linux/module.h>
11 #include <linux/regmap.h>
12 
13 #include "kionix-kx022a.h"
14 
15 static int kx022a_i2c_probe(struct i2c_client *i2c)
16 {
17 	struct device *dev = &i2c->dev;
18 	struct regmap *regmap;
19 
20 	if (!i2c->irq) {
21 		dev_err(dev, "No IRQ configured\n");
22 		return -EINVAL;
23 	}
24 
25 	regmap = devm_regmap_init_i2c(i2c, &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 of_device_id kx022a_of_match[] = {
34 	{ .compatible = "kionix,kx022a", },
35 	{ }
36 };
37 MODULE_DEVICE_TABLE(of, kx022a_of_match);
38 
39 static struct i2c_driver kx022a_i2c_driver = {
40 	.driver = {
41 		.name  = "kx022a-i2c",
42 		.of_match_table = kx022a_of_match,
43 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
44 	  },
45 	.probe        = kx022a_i2c_probe,
46 };
47 module_i2c_driver(kx022a_i2c_driver);
48 
49 MODULE_DESCRIPTION("ROHM/Kionix KX022A accelerometer driver");
50 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
51 MODULE_LICENSE("GPL");
52 MODULE_IMPORT_NS(IIO_KX022A);
53