summaryrefslogtreecommitdiffstats
path: root/drivers/iio/accel/mma7455_i2c.c
blob: 3cab5fb4a3c499d81551d929f15d4b93aeaa7bdd (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
/*
 * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer
 * Copyright 2015 Joachim Eastwood <manabian@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/regmap.h>

#include "mma7455.h"

static int mma7455_i2c_probe(struct i2c_client *i2c,
			     const struct i2c_device_id *id)
{
	struct regmap *regmap;
	const char *name = NULL;

	regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap);
	if (IS_ERR(regmap))
		return PTR_ERR(regmap);

	if (id)
		name = id->name;

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

static int mma7455_i2c_remove(struct i2c_client *i2c)
{
	return mma7455_core_remove(&i2c->dev);
}

static const struct i2c_device_id mma7455_i2c_ids[] = {
	{ "mma7455", 0 },
	{ "mma7456", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids);

static struct i2c_driver mma7455_i2c_driver = {
	.probe = mma7455_i2c_probe,
	.remove = mma7455_i2c_remove,
	.id_table = mma7455_i2c_ids,
	.driver = {
		.name	= "mma7455-i2c",
	},
};
module_i2c_driver(mma7455_i2c_driver);

MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver");
MODULE_LICENSE("GPL v2");