Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[zen-stable.git] / drivers / input / misc / adxl34x-i2c.c
blobccacf2bb06a4e56c74624dab181ac6398ab56bcc
1 /*
2 * ADLX345/346 Three-Axis Digital Accelerometers (I2C Interface)
4 * Enter bugs at http://blackfin.uclinux.org/
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
10 #include <linux/input.h> /* BUS_I2C */
11 #include <linux/i2c.h>
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/pm.h>
15 #include "adxl34x.h"
17 static int adxl34x_smbus_read(struct device *dev, unsigned char reg)
19 struct i2c_client *client = to_i2c_client(dev);
21 return i2c_smbus_read_byte_data(client, reg);
24 static int adxl34x_smbus_write(struct device *dev,
25 unsigned char reg, unsigned char val)
27 struct i2c_client *client = to_i2c_client(dev);
29 return i2c_smbus_write_byte_data(client, reg, val);
32 static int adxl34x_smbus_read_block(struct device *dev,
33 unsigned char reg, int count,
34 void *buf)
36 struct i2c_client *client = to_i2c_client(dev);
38 return i2c_smbus_read_i2c_block_data(client, reg, count, buf);
41 static int adxl34x_i2c_read_block(struct device *dev,
42 unsigned char reg, int count,
43 void *buf)
45 struct i2c_client *client = to_i2c_client(dev);
46 int ret;
48 ret = i2c_master_send(client, &reg, 1);
49 if (ret < 0)
50 return ret;
52 ret = i2c_master_recv(client, buf, count);
53 if (ret < 0)
54 return ret;
56 if (ret != count)
57 return -EIO;
59 return 0;
62 static const struct adxl34x_bus_ops adxl34x_smbus_bops = {
63 .bustype = BUS_I2C,
64 .write = adxl34x_smbus_write,
65 .read = adxl34x_smbus_read,
66 .read_block = adxl34x_smbus_read_block,
69 static const struct adxl34x_bus_ops adxl34x_i2c_bops = {
70 .bustype = BUS_I2C,
71 .write = adxl34x_smbus_write,
72 .read = adxl34x_smbus_read,
73 .read_block = adxl34x_i2c_read_block,
76 static int __devinit adxl34x_i2c_probe(struct i2c_client *client,
77 const struct i2c_device_id *id)
79 struct adxl34x *ac;
80 int error;
82 error = i2c_check_functionality(client->adapter,
83 I2C_FUNC_SMBUS_BYTE_DATA);
84 if (!error) {
85 dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
86 return -EIO;
89 ac = adxl34x_probe(&client->dev, client->irq, false,
90 i2c_check_functionality(client->adapter,
91 I2C_FUNC_SMBUS_READ_I2C_BLOCK) ?
92 &adxl34x_smbus_bops : &adxl34x_i2c_bops);
93 if (IS_ERR(ac))
94 return PTR_ERR(ac);
96 i2c_set_clientdata(client, ac);
98 return 0;
101 static int __devexit adxl34x_i2c_remove(struct i2c_client *client)
103 struct adxl34x *ac = i2c_get_clientdata(client);
105 return adxl34x_remove(ac);
108 #ifdef CONFIG_PM
109 static int adxl34x_i2c_suspend(struct device *dev)
111 struct i2c_client *client = to_i2c_client(dev);
112 struct adxl34x *ac = i2c_get_clientdata(client);
114 adxl34x_suspend(ac);
116 return 0;
119 static int adxl34x_i2c_resume(struct device *dev)
121 struct i2c_client *client = to_i2c_client(dev);
122 struct adxl34x *ac = i2c_get_clientdata(client);
124 adxl34x_resume(ac);
126 return 0;
128 #endif
130 static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend,
131 adxl34x_i2c_resume);
133 static const struct i2c_device_id adxl34x_id[] = {
134 { "adxl34x", 0 },
138 MODULE_DEVICE_TABLE(i2c, adxl34x_id);
140 static struct i2c_driver adxl34x_driver = {
141 .driver = {
142 .name = "adxl34x",
143 .owner = THIS_MODULE,
144 .pm = &adxl34x_i2c_pm,
146 .probe = adxl34x_i2c_probe,
147 .remove = __devexit_p(adxl34x_i2c_remove),
148 .id_table = adxl34x_id,
151 static int __init adxl34x_i2c_init(void)
153 return i2c_add_driver(&adxl34x_driver);
155 module_init(adxl34x_i2c_init);
157 static void __exit adxl34x_i2c_exit(void)
159 i2c_del_driver(&adxl34x_driver);
161 module_exit(adxl34x_i2c_exit);
163 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
164 MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer I2C Bus Driver");
165 MODULE_LICENSE("GPL");