Path: blob/master/drivers/input/misc/cma3000_d0x_i2c.c
15109 views
/*1* Implements I2C interface for VTI CMA300_D0x Accelerometer driver2*3* Copyright (C) 2010 Texas Instruments4* Author: Hemanth V <[email protected]>5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License version 2 as published by8* the Free Software Foundation.9*10* This program is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for13* more details.14*15* You should have received a copy of the GNU General Public License along with16* this program. If not, see <http://www.gnu.org/licenses/>.17*/1819#include <linux/module.h>20#include <linux/i2c.h>21#include <linux/input/cma3000.h>22#include "cma3000_d0x.h"2324static int cma3000_i2c_set(struct device *dev,25u8 reg, u8 val, char *msg)26{27struct i2c_client *client = to_i2c_client(dev);28int ret;2930ret = i2c_smbus_write_byte_data(client, reg, val);31if (ret < 0)32dev_err(&client->dev,33"%s failed (%s, %d)\n", __func__, msg, ret);34return ret;35}3637static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg)38{39struct i2c_client *client = to_i2c_client(dev);40int ret;4142ret = i2c_smbus_read_byte_data(client, reg);43if (ret < 0)44dev_err(&client->dev,45"%s failed (%s, %d)\n", __func__, msg, ret);46return ret;47}4849static const struct cma3000_bus_ops cma3000_i2c_bops = {50.bustype = BUS_I2C,51#define CMA3000_BUSI2C (0 << 4)52.ctrl_mod = CMA3000_BUSI2C,53.read = cma3000_i2c_read,54.write = cma3000_i2c_set,55};5657static int __devinit cma3000_i2c_probe(struct i2c_client *client,58const struct i2c_device_id *id)59{60struct cma3000_accl_data *data;6162data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops);63if (IS_ERR(data))64return PTR_ERR(data);6566i2c_set_clientdata(client, data);6768return 0;69}7071static int __devexit cma3000_i2c_remove(struct i2c_client *client)72{73struct cma3000_accl_data *data = i2c_get_clientdata(client);7475cma3000_exit(data);7677return 0;78}7980#ifdef CONFIG_PM81static int cma3000_i2c_suspend(struct device *dev)82{83struct i2c_client *client = to_i2c_client(dev);84struct cma3000_accl_data *data = i2c_get_clientdata(client);8586cma3000_suspend(data);8788return 0;89}9091static int cma3000_i2c_resume(struct device *dev)92{93struct i2c_client *client = to_i2c_client(dev);94struct cma3000_accl_data *data = i2c_get_clientdata(client);9596cma3000_resume(data);9798return 0;99}100101static const struct dev_pm_ops cma3000_i2c_pm_ops = {102.suspend = cma3000_i2c_suspend,103.resume = cma3000_i2c_resume,104};105#endif106107static const struct i2c_device_id cma3000_i2c_id[] = {108{ "cma3000_d01", 0 },109{ },110};111112MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id);113114static struct i2c_driver cma3000_i2c_driver = {115.probe = cma3000_i2c_probe,116.remove = __devexit_p(cma3000_i2c_remove),117.id_table = cma3000_i2c_id,118.driver = {119.name = "cma3000_i2c_accl",120.owner = THIS_MODULE,121#ifdef CONFIG_PM122.pm = &cma3000_i2c_pm_ops,123#endif124},125};126127static int __init cma3000_i2c_init(void)128{129return i2c_add_driver(&cma3000_i2c_driver);130}131132static void __exit cma3000_i2c_exit(void)133{134i2c_del_driver(&cma3000_i2c_driver);135}136137module_init(cma3000_i2c_init);138module_exit(cma3000_i2c_exit);139140MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver");141MODULE_LICENSE("GPL");142MODULE_AUTHOR("Hemanth V <[email protected]>");143144145