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
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
);
31 ret
= i2c_smbus_write_byte_data(client
, reg
, val
);
34 "%s failed (%s, %d)\n", __func__
, msg
, ret
);
38 static int cma3000_i2c_read(struct device
*dev
, u8 reg
, char *msg
)
40 struct i2c_client
*client
= to_i2c_client(dev
);
43 ret
= i2c_smbus_read_byte_data(client
, reg
);
46 "%s failed (%s, %d)\n", __func__
, msg
, ret
);
50 static const struct cma3000_bus_ops cma3000_i2c_bops
= {
52 #define CMA3000_BUSI2C (0 << 4)
53 .ctrl_mod
= CMA3000_BUSI2C
,
54 .read
= cma3000_i2c_read
,
55 .write
= cma3000_i2c_set
,
58 static int 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
);
67 i2c_set_clientdata(client
, data
);
72 static int cma3000_i2c_remove(struct i2c_client
*client
)
74 struct cma3000_accl_data
*data
= i2c_get_clientdata(client
);
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
);
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
);
102 static const struct dev_pm_ops cma3000_i2c_pm_ops
= {
103 .suspend
= cma3000_i2c_suspend
,
104 .resume
= cma3000_i2c_resume
,
108 static const struct i2c_device_id cma3000_i2c_id
[] = {
109 { "cma3000_d01", 0 },
113 MODULE_DEVICE_TABLE(i2c
, cma3000_i2c_id
);
115 static struct i2c_driver cma3000_i2c_driver
= {
116 .probe
= cma3000_i2c_probe
,
117 .remove
= cma3000_i2c_remove
,
118 .id_table
= cma3000_i2c_id
,
120 .name
= "cma3000_i2c_accl",
121 .owner
= THIS_MODULE
,
123 .pm
= &cma3000_i2c_pm_ops
,
128 module_i2c_driver(cma3000_i2c_driver
);
130 MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");
131 MODULE_LICENSE("GPL");
132 MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");