drm/radeon/kms: move panel mode setup into encoder mode set
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / input / misc / cma3000_d0x_i2c.c
blobd100cc5c57834e87236561776bf1a656ad7df9a1
1 /*
2 * Implements I2C interface for VTI CMA300_D0x Accelerometer driver
4 * Copyright (C) 2010 Texas Instruments
5 * Author: Hemanth V <hemanthv@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/input/cma3000.h>
23 #include "cma3000_d0x.h"
25 static int cma3000_i2c_set(struct device *dev,
26 u8 reg, u8 val, char *msg)
28 struct i2c_client *client = to_i2c_client(dev);
29 int ret;
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;
38 static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg)
40 struct i2c_client *client = to_i2c_client(dev);
41 int ret;
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;
50 static 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,
58 static int __devinit cma3000_i2c_probe(struct i2c_client *client,
59 const struct i2c_device_id *id)
61 struct cma3000_accl_data *data;
63 data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops);
64 if (IS_ERR(data))
65 return PTR_ERR(data);
67 i2c_set_clientdata(client, data);
69 return 0;
72 static int __devexit cma3000_i2c_remove(struct i2c_client *client)
74 struct cma3000_accl_data *data = i2c_get_clientdata(client);
76 cma3000_exit(data);
78 return 0;
81 #ifdef CONFIG_PM
82 static int cma3000_i2c_suspend(struct device *dev)
84 struct i2c_client *client = to_i2c_client(dev);
85 struct cma3000_accl_data *data = i2c_get_clientdata(client);
87 cma3000_suspend(data);
89 return 0;
92 static int cma3000_i2c_resume(struct device *dev)
94 struct i2c_client *client = to_i2c_client(dev);
95 struct cma3000_accl_data *data = i2c_get_clientdata(client);
97 cma3000_resume(data);
99 return 0;
102 static const struct dev_pm_ops cma3000_i2c_pm_ops = {
103 .suspend = cma3000_i2c_suspend,
104 .resume = cma3000_i2c_resume,
106 #endif
108 static const struct i2c_device_id cma3000_i2c_id[] = {
109 { "cma3000_d01", 0 },
110 { },
113 MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);
115 static struct i2c_driver cma3000_i2c_driver = {
116 .probe = cma3000_i2c_probe,
117 .remove = __devexit_p(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
128 static int __init cma3000_i2c_init(void)
130 return i2c_add_driver(&cma3000_i2c_driver);
133 static void __exit cma3000_i2c_exit(void)
135 i2c_del_driver(&cma3000_i2c_driver);
138 module_init(cma3000_i2c_init);
139 module_exit(cma3000_i2c_exit);
141 MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");
142 MODULE_LICENSE("GPL");
143 MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");