aboutsummaryrefslogtreecommitdiff
path: root/drivers/iio/accel/kxsd9-i2c.c
blob: 38411e1c155bd38c93ba0d559b4f5f0c025594ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: GPL-2.0
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/regmap.h>

#include "kxsd9.h"

static int kxsd9_i2c_probe(struct i2c_client *i2c,
			   const struct i2c_device_id *id)
{
	static const struct regmap_config config = {
		.reg_bits = 8,
		.val_bits = 8,
		.max_register = 0x0e,
	};
	struct regmap *regmap;

	regmap = devm_regmap_init_i2c(i2c, &config);
	if (IS_ERR(regmap)) {
		dev_err(&i2c->dev, "Failed to register i2c regmap %d\n",
			(int)PTR_ERR(regmap));
		return PTR_ERR(regmap);
	}

	return kxsd9_common_probe(&i2c->dev,
				  regmap,
				  i2c->name);
}

static int kxsd9_i2c_remove(struct i2c_client *client)
{
	return kxsd9_common_remove(&client->dev);
}

#ifdef CONFIG_OF
static const struct of_device_id kxsd9_of_match[] = {
	{ .compatible = "kionix,kxsd9", },
	{ },
};
MODULE_DEVICE_TABLE(of, kxsd9_of_match);
#else
#define kxsd9_of_match NULL
#endif

static const struct i2c_device_id kxsd9_i2c_id[] = {
	{"kxsd9", 0},
	{ },
};
MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);

static struct i2c_driver kxsd9_i2c_driver = {
	.driver = {
		.name	= "kxsd9",
		.of_match_table = of_match_ptr(kxsd9_of_match),
		.pm = &kxsd9_dev_pm_ops,
	},
	.probe		= kxsd9_i2c_probe,
	.remove		= kxsd9_i2c_remove,
	.id_table	= kxsd9_i2c_id,
};
module_i2c_driver(kxsd9_i2c_driver);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");