1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2b029ffafSHemanth V /*
3b029ffafSHemanth V * Implements I2C interface for VTI CMA300_D0x Accelerometer driver
4b029ffafSHemanth V *
5b029ffafSHemanth V * Copyright (C) 2010 Texas Instruments
6b029ffafSHemanth V * Author: Hemanth V <hemanthv@ti.com>
7b029ffafSHemanth V */
8b029ffafSHemanth V
9b029ffafSHemanth V #include <linux/module.h>
10b029ffafSHemanth V #include <linux/i2c.h>
11b029ffafSHemanth V #include <linux/input/cma3000.h>
12b029ffafSHemanth V #include "cma3000_d0x.h"
13b029ffafSHemanth V
cma3000_i2c_set(struct device * dev,u8 reg,u8 val,char * msg)14b029ffafSHemanth V static int cma3000_i2c_set(struct device *dev,
15b029ffafSHemanth V u8 reg, u8 val, char *msg)
16b029ffafSHemanth V {
17b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev);
18b029ffafSHemanth V int ret;
19b029ffafSHemanth V
20b029ffafSHemanth V ret = i2c_smbus_write_byte_data(client, reg, val);
21b029ffafSHemanth V if (ret < 0)
22b029ffafSHemanth V dev_err(&client->dev,
23b029ffafSHemanth V "%s failed (%s, %d)\n", __func__, msg, ret);
24b029ffafSHemanth V return ret;
25b029ffafSHemanth V }
26b029ffafSHemanth V
cma3000_i2c_read(struct device * dev,u8 reg,char * msg)27b029ffafSHemanth V static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg)
28b029ffafSHemanth V {
29b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev);
30b029ffafSHemanth V int ret;
31b029ffafSHemanth V
32b029ffafSHemanth V ret = i2c_smbus_read_byte_data(client, reg);
33b029ffafSHemanth V if (ret < 0)
34b029ffafSHemanth V dev_err(&client->dev,
35b029ffafSHemanth V "%s failed (%s, %d)\n", __func__, msg, ret);
36b029ffafSHemanth V return ret;
37b029ffafSHemanth V }
38b029ffafSHemanth V
39b029ffafSHemanth V static const struct cma3000_bus_ops cma3000_i2c_bops = {
40b029ffafSHemanth V .bustype = BUS_I2C,
41b029ffafSHemanth V #define CMA3000_BUSI2C (0 << 4)
42b029ffafSHemanth V .ctrl_mod = CMA3000_BUSI2C,
43b029ffafSHemanth V .read = cma3000_i2c_read,
44b029ffafSHemanth V .write = cma3000_i2c_set,
45b029ffafSHemanth V };
46b029ffafSHemanth V
cma3000_i2c_probe(struct i2c_client * client)47c1ae0e98SUwe Kleine-König static int cma3000_i2c_probe(struct i2c_client *client)
48b029ffafSHemanth V {
49b029ffafSHemanth V struct cma3000_accl_data *data;
50b029ffafSHemanth V
51b029ffafSHemanth V data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops);
52b029ffafSHemanth V if (IS_ERR(data))
53b029ffafSHemanth V return PTR_ERR(data);
54b029ffafSHemanth V
55b029ffafSHemanth V i2c_set_clientdata(client, data);
56b029ffafSHemanth V
57b029ffafSHemanth V return 0;
58b029ffafSHemanth V }
59b029ffafSHemanth V
cma3000_i2c_remove(struct i2c_client * client)60ed5c2f5fSUwe Kleine-König static void cma3000_i2c_remove(struct i2c_client *client)
61b029ffafSHemanth V {
62b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client);
63b029ffafSHemanth V
64b029ffafSHemanth V cma3000_exit(data);
65b029ffafSHemanth V }
66b029ffafSHemanth V
cma3000_i2c_suspend(struct device * dev)67b029ffafSHemanth V static int cma3000_i2c_suspend(struct device *dev)
68b029ffafSHemanth V {
69b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev);
70b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client);
71b029ffafSHemanth V
72b029ffafSHemanth V cma3000_suspend(data);
73b029ffafSHemanth V
74b029ffafSHemanth V return 0;
75b029ffafSHemanth V }
76b029ffafSHemanth V
cma3000_i2c_resume(struct device * dev)77b029ffafSHemanth V static int cma3000_i2c_resume(struct device *dev)
78b029ffafSHemanth V {
79b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev);
80b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client);
81b029ffafSHemanth V
82b029ffafSHemanth V cma3000_resume(data);
83b029ffafSHemanth V
84b029ffafSHemanth V return 0;
85b029ffafSHemanth V }
86b029ffafSHemanth V
87b029ffafSHemanth V static const struct dev_pm_ops cma3000_i2c_pm_ops = {
88b029ffafSHemanth V .suspend = cma3000_i2c_suspend,
89b029ffafSHemanth V .resume = cma3000_i2c_resume,
90b029ffafSHemanth V };
91b029ffafSHemanth V
92b029ffafSHemanth V static const struct i2c_device_id cma3000_i2c_id[] = {
93b029ffafSHemanth V { "cma3000_d01", 0 },
94b029ffafSHemanth V { },
95b029ffafSHemanth V };
96b029ffafSHemanth V
97356c6f65SDmitry Torokhov MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
98356c6f65SDmitry Torokhov
99b029ffafSHemanth V static struct i2c_driver cma3000_i2c_driver = {
100*d8bde56dSUwe Kleine-König .probe = cma3000_i2c_probe,
1011cb0aa88SBill Pemberton .remove = cma3000_i2c_remove,
102b029ffafSHemanth V .id_table = cma3000_i2c_id,
103b029ffafSHemanth V .driver = {
104b029ffafSHemanth V .name = "cma3000_i2c_accl",
105f33f61a7SJonathan Cameron .pm = pm_sleep_ptr(&cma3000_i2c_pm_ops),
106b029ffafSHemanth V },
107b029ffafSHemanth V };
108b029ffafSHemanth V
1091b92c1cfSAxel Lin module_i2c_driver(cma3000_i2c_driver);
110b029ffafSHemanth V
111b029ffafSHemanth V MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");
112b029ffafSHemanth V MODULE_LICENSE("GPL");
113b029ffafSHemanth V MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");
114