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.
10 #include <linux/input.h> /* BUS_I2C */
11 #include <linux/i2c.h>
12 #include <linux/module.h>
13 #include <linux/types.h>
16 static int adxl34x_smbus_read(struct device
*dev
, unsigned char reg
)
18 struct i2c_client
*client
= to_i2c_client(dev
);
20 return i2c_smbus_read_byte_data(client
, reg
);
23 static int adxl34x_smbus_write(struct device
*dev
,
24 unsigned char reg
, unsigned char val
)
26 struct i2c_client
*client
= to_i2c_client(dev
);
28 return i2c_smbus_write_byte_data(client
, reg
, val
);
31 static int adxl34x_smbus_read_block(struct device
*dev
,
32 unsigned char reg
, int count
,
35 struct i2c_client
*client
= to_i2c_client(dev
);
37 return i2c_smbus_read_i2c_block_data(client
, reg
, count
, buf
);
40 static int adxl34x_i2c_read_block(struct device
*dev
,
41 unsigned char reg
, int count
,
44 struct i2c_client
*client
= to_i2c_client(dev
);
47 ret
= i2c_master_send(client
, ®
, 1);
51 ret
= i2c_master_recv(client
, buf
, count
);
61 static const struct adxl34x_bus_ops adxl34x_smbus_bops
= {
63 .write
= adxl34x_smbus_write
,
64 .read
= adxl34x_smbus_read
,
65 .read_block
= adxl34x_smbus_read_block
,
68 static const struct adxl34x_bus_ops adxl34x_i2c_bops
= {
70 .write
= adxl34x_smbus_write
,
71 .read
= adxl34x_smbus_read
,
72 .read_block
= adxl34x_i2c_read_block
,
75 static int __devinit
adxl34x_i2c_probe(struct i2c_client
*client
,
76 const struct i2c_device_id
*id
)
81 error
= i2c_check_functionality(client
->adapter
,
82 I2C_FUNC_SMBUS_BYTE_DATA
);
84 dev_err(&client
->dev
, "SMBUS Byte Data not Supported\n");
88 ac
= adxl34x_probe(&client
->dev
, client
->irq
, false,
89 i2c_check_functionality(client
->adapter
,
90 I2C_FUNC_SMBUS_READ_I2C_BLOCK
) ?
91 &adxl34x_smbus_bops
: &adxl34x_i2c_bops
);
95 i2c_set_clientdata(client
, ac
);
100 static int __devexit
adxl34x_i2c_remove(struct i2c_client
*client
)
102 struct adxl34x
*ac
= i2c_get_clientdata(client
);
104 return adxl34x_remove(ac
);
108 static int adxl34x_i2c_suspend(struct i2c_client
*client
, pm_message_t message
)
110 struct adxl34x
*ac
= i2c_get_clientdata(client
);
117 static int adxl34x_i2c_resume(struct i2c_client
*client
)
119 struct adxl34x
*ac
= i2c_get_clientdata(client
);
126 # define adxl34x_i2c_suspend NULL
127 # define adxl34x_i2c_resume NULL
130 static const struct i2c_device_id adxl34x_id
[] = {
135 MODULE_DEVICE_TABLE(i2c
, adxl34x_id
);
137 static struct i2c_driver adxl34x_driver
= {
140 .owner
= THIS_MODULE
,
142 .probe
= adxl34x_i2c_probe
,
143 .remove
= __devexit_p(adxl34x_i2c_remove
),
144 .suspend
= adxl34x_i2c_suspend
,
145 .resume
= adxl34x_i2c_resume
,
146 .id_table
= adxl34x_id
,
149 static int __init
adxl34x_i2c_init(void)
151 return i2c_add_driver(&adxl34x_driver
);
153 module_init(adxl34x_i2c_init
);
155 static void __exit
adxl34x_i2c_exit(void)
157 i2c_del_driver(&adxl34x_driver
);
159 module_exit(adxl34x_i2c_exit
);
161 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
162 MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer I2C Bus Driver");
163 MODULE_LICENSE("GPL");