1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/i2c.h>
22#include <linux/input/cma3000.h>
23#include "cma3000_d0x.h"
24
25static int cma3000_i2c_set(struct device *dev,
26 u8 reg, u8 val, char *msg)
27{
28 struct i2c_client *client = to_i2c_client(dev);
29 int ret;
30
31 ret = i2c_smbus_write_byte_data(client, reg, val);
32 if (ret < 0)
33 dev_err(&client->dev,
34 "%s failed (%s, %d)\n", __func__, msg, ret);
35 return ret;
36}
37
38static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg)
39{
40 struct i2c_client *client = to_i2c_client(dev);
41 int ret;
42
43 ret = i2c_smbus_read_byte_data(client, reg);
44 if (ret < 0)
45 dev_err(&client->dev,
46 "%s failed (%s, %d)\n", __func__, msg, ret);
47 return ret;
48}
49
50static const struct cma3000_bus_ops cma3000_i2c_bops = {
51 .bustype = BUS_I2C,
52#define CMA3000_BUSI2C (0 << 4)
53 .ctrl_mod = CMA3000_BUSI2C,
54 .read = cma3000_i2c_read,
55 .write = cma3000_i2c_set,
56};
57
58static int cma3000_i2c_probe(struct i2c_client *client,
59 const struct i2c_device_id *id)
60{
61 struct cma3000_accl_data *data;
62
63 data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops);
64 if (IS_ERR(data))
65 return PTR_ERR(data);
66
67 i2c_set_clientdata(client, data);
68
69 return 0;
70}
71
72static int cma3000_i2c_remove(struct i2c_client *client)
73{
74 struct cma3000_accl_data *data = i2c_get_clientdata(client);
75
76 cma3000_exit(data);
77
78 return 0;
79}
80
81#ifdef CONFIG_PM
82static int cma3000_i2c_suspend(struct device *dev)
83{
84 struct i2c_client *client = to_i2c_client(dev);
85 struct cma3000_accl_data *data = i2c_get_clientdata(client);
86
87 cma3000_suspend(data);
88
89 return 0;
90}
91
92static int cma3000_i2c_resume(struct device *dev)
93{
94 struct i2c_client *client = to_i2c_client(dev);
95 struct cma3000_accl_data *data = i2c_get_clientdata(client);
96
97 cma3000_resume(data);
98
99 return 0;
100}
101
102static const struct dev_pm_ops cma3000_i2c_pm_ops = {
103 .suspend = cma3000_i2c_suspend,
104 .resume = cma3000_i2c_resume,
105};
106#endif
107
108static const struct i2c_device_id cma3000_i2c_id[] = {
109 { "cma3000_d01", 0 },
110 { },
111};
112
113MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
114
115static struct i2c_driver cma3000_i2c_driver = {
116 .probe = cma3000_i2c_probe,
117 .remove = cma3000_i2c_remove,
118 .id_table = cma3000_i2c_id,
119 .driver = {
120 .name = "cma3000_i2c_accl",
121 .owner = THIS_MODULE,
122#ifdef CONFIG_PM
123 .pm = &cma3000_i2c_pm_ops,
124#endif
125 },
126};
127
128module_i2c_driver(cma3000_i2c_driver);
129
130MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");
131MODULE_LICENSE("GPL");
132MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");
133