1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2b029ffafSHemanth V /* 3b029ffafSHemanth V * Implements I2C interface for VTI CMA300_D0x Accelerometer driver 4b029ffafSHemanth V * 5b029ffafSHemanth V * Copyright (C) 2010 Texas Instruments 6b029ffafSHemanth V * Author: Hemanth V <hemanthv@ti.com> 7b029ffafSHemanth V */ 8b029ffafSHemanth V 9b029ffafSHemanth V #include <linux/module.h> 10b029ffafSHemanth V #include <linux/i2c.h> 11b029ffafSHemanth V #include <linux/input/cma3000.h> 12b029ffafSHemanth V #include "cma3000_d0x.h" 13b029ffafSHemanth V 14b029ffafSHemanth V static int cma3000_i2c_set(struct device *dev, 15b029ffafSHemanth V u8 reg, u8 val, char *msg) 16b029ffafSHemanth V { 17b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev); 18b029ffafSHemanth V int ret; 19b029ffafSHemanth V 20b029ffafSHemanth V ret = i2c_smbus_write_byte_data(client, reg, val); 21b029ffafSHemanth V if (ret < 0) 22b029ffafSHemanth V dev_err(&client->dev, 23b029ffafSHemanth V "%s failed (%s, %d)\n", __func__, msg, ret); 24b029ffafSHemanth V return ret; 25b029ffafSHemanth V } 26b029ffafSHemanth V 27b029ffafSHemanth V static int cma3000_i2c_read(struct device *dev, u8 reg, char *msg) 28b029ffafSHemanth V { 29b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev); 30b029ffafSHemanth V int ret; 31b029ffafSHemanth V 32b029ffafSHemanth V ret = i2c_smbus_read_byte_data(client, reg); 33b029ffafSHemanth V if (ret < 0) 34b029ffafSHemanth V dev_err(&client->dev, 35b029ffafSHemanth V "%s failed (%s, %d)\n", __func__, msg, ret); 36b029ffafSHemanth V return ret; 37b029ffafSHemanth V } 38b029ffafSHemanth V 39b029ffafSHemanth V static const struct cma3000_bus_ops cma3000_i2c_bops = { 40b029ffafSHemanth V .bustype = BUS_I2C, 41b029ffafSHemanth V #define CMA3000_BUSI2C (0 << 4) 42b029ffafSHemanth V .ctrl_mod = CMA3000_BUSI2C, 43b029ffafSHemanth V .read = cma3000_i2c_read, 44b029ffafSHemanth V .write = cma3000_i2c_set, 45b029ffafSHemanth V }; 46b029ffafSHemanth V 475298cc4cSBill Pemberton static int cma3000_i2c_probe(struct i2c_client *client, 48b029ffafSHemanth V const struct i2c_device_id *id) 49b029ffafSHemanth V { 50b029ffafSHemanth V struct cma3000_accl_data *data; 51b029ffafSHemanth V 52b029ffafSHemanth V data = cma3000_init(&client->dev, client->irq, &cma3000_i2c_bops); 53b029ffafSHemanth V if (IS_ERR(data)) 54b029ffafSHemanth V return PTR_ERR(data); 55b029ffafSHemanth V 56b029ffafSHemanth V i2c_set_clientdata(client, data); 57b029ffafSHemanth V 58b029ffafSHemanth V return 0; 59b029ffafSHemanth V } 60b029ffafSHemanth V 61*ed5c2f5fSUwe Kleine-König static void cma3000_i2c_remove(struct i2c_client *client) 62b029ffafSHemanth V { 63b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client); 64b029ffafSHemanth V 65b029ffafSHemanth V cma3000_exit(data); 66b029ffafSHemanth V } 67b029ffafSHemanth V 68b029ffafSHemanth V #ifdef CONFIG_PM 69b029ffafSHemanth V static int cma3000_i2c_suspend(struct device *dev) 70b029ffafSHemanth V { 71b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev); 72b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client); 73b029ffafSHemanth V 74b029ffafSHemanth V cma3000_suspend(data); 75b029ffafSHemanth V 76b029ffafSHemanth V return 0; 77b029ffafSHemanth V } 78b029ffafSHemanth V 79b029ffafSHemanth V static int cma3000_i2c_resume(struct device *dev) 80b029ffafSHemanth V { 81b029ffafSHemanth V struct i2c_client *client = to_i2c_client(dev); 82b029ffafSHemanth V struct cma3000_accl_data *data = i2c_get_clientdata(client); 83b029ffafSHemanth V 84b029ffafSHemanth V cma3000_resume(data); 85b029ffafSHemanth V 86b029ffafSHemanth V return 0; 87b029ffafSHemanth V } 88b029ffafSHemanth V 89b029ffafSHemanth V static const struct dev_pm_ops cma3000_i2c_pm_ops = { 90b029ffafSHemanth V .suspend = cma3000_i2c_suspend, 91b029ffafSHemanth V .resume = cma3000_i2c_resume, 92b029ffafSHemanth V }; 93b029ffafSHemanth V #endif 94b029ffafSHemanth V 95b029ffafSHemanth V static const struct i2c_device_id cma3000_i2c_id[] = { 96b029ffafSHemanth V { "cma3000_d01", 0 }, 97b029ffafSHemanth V { }, 98b029ffafSHemanth V }; 99b029ffafSHemanth V 100356c6f65SDmitry Torokhov MODULE_DEVICE_TABLE(i2c, cma3000_i2c_id); 101356c6f65SDmitry Torokhov 102b029ffafSHemanth V static struct i2c_driver cma3000_i2c_driver = { 103b029ffafSHemanth V .probe = cma3000_i2c_probe, 1041cb0aa88SBill Pemberton .remove = cma3000_i2c_remove, 105b029ffafSHemanth V .id_table = cma3000_i2c_id, 106b029ffafSHemanth V .driver = { 107b029ffafSHemanth V .name = "cma3000_i2c_accl", 108b029ffafSHemanth V #ifdef CONFIG_PM 109b029ffafSHemanth V .pm = &cma3000_i2c_pm_ops, 110b029ffafSHemanth V #endif 111b029ffafSHemanth V }, 112b029ffafSHemanth V }; 113b029ffafSHemanth V 1141b92c1cfSAxel Lin module_i2c_driver(cma3000_i2c_driver); 115b029ffafSHemanth V 116b029ffafSHemanth V MODULE_DESCRIPTION("CMA3000-D0x Accelerometer I2C Driver"); 117b029ffafSHemanth V MODULE_LICENSE("GPL"); 118b029ffafSHemanth V MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>"); 119