11a6e4b74SViresh Kumar /* 21a6e4b74SViresh Kumar * ST Microelectronics MFD: stmpe's i2c client specific driver 31a6e4b74SViresh Kumar * 41a6e4b74SViresh Kumar * Copyright (C) ST-Ericsson SA 2010 51a6e4b74SViresh Kumar * Copyright (C) ST Microelectronics SA 2011 61a6e4b74SViresh Kumar * 71a6e4b74SViresh Kumar * License Terms: GNU General Public License, version 2 81a6e4b74SViresh Kumar * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson 910d8935fSViresh Kumar * Author: Viresh Kumar <viresh.linux@gmail.com> for ST Microelectronics 101a6e4b74SViresh Kumar */ 111a6e4b74SViresh Kumar 121a6e4b74SViresh Kumar #include <linux/i2c.h> 131a6e4b74SViresh Kumar #include <linux/interrupt.h> 141a6e4b74SViresh Kumar #include <linux/kernel.h> 151a6e4b74SViresh Kumar #include <linux/module.h> 161a6e4b74SViresh Kumar #include <linux/types.h> 171a6e4b74SViresh Kumar #include "stmpe.h" 181a6e4b74SViresh Kumar 191a6e4b74SViresh Kumar static int i2c_reg_read(struct stmpe *stmpe, u8 reg) 201a6e4b74SViresh Kumar { 211a6e4b74SViresh Kumar struct i2c_client *i2c = stmpe->client; 221a6e4b74SViresh Kumar 231a6e4b74SViresh Kumar return i2c_smbus_read_byte_data(i2c, reg); 241a6e4b74SViresh Kumar } 251a6e4b74SViresh Kumar 261a6e4b74SViresh Kumar static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val) 271a6e4b74SViresh Kumar { 281a6e4b74SViresh Kumar struct i2c_client *i2c = stmpe->client; 291a6e4b74SViresh Kumar 301a6e4b74SViresh Kumar return i2c_smbus_write_byte_data(i2c, reg, val); 311a6e4b74SViresh Kumar } 321a6e4b74SViresh Kumar 331a6e4b74SViresh Kumar static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values) 341a6e4b74SViresh Kumar { 351a6e4b74SViresh Kumar struct i2c_client *i2c = stmpe->client; 361a6e4b74SViresh Kumar 371a6e4b74SViresh Kumar return i2c_smbus_read_i2c_block_data(i2c, reg, length, values); 381a6e4b74SViresh Kumar } 391a6e4b74SViresh Kumar 401a6e4b74SViresh Kumar static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length, 411a6e4b74SViresh Kumar const u8 *values) 421a6e4b74SViresh Kumar { 431a6e4b74SViresh Kumar struct i2c_client *i2c = stmpe->client; 441a6e4b74SViresh Kumar 451a6e4b74SViresh Kumar return i2c_smbus_write_i2c_block_data(i2c, reg, length, values); 461a6e4b74SViresh Kumar } 471a6e4b74SViresh Kumar 481a6e4b74SViresh Kumar static struct stmpe_client_info i2c_ci = { 491a6e4b74SViresh Kumar .read_byte = i2c_reg_read, 501a6e4b74SViresh Kumar .write_byte = i2c_reg_write, 511a6e4b74SViresh Kumar .read_block = i2c_block_read, 521a6e4b74SViresh Kumar .write_block = i2c_block_write, 531a6e4b74SViresh Kumar }; 541a6e4b74SViresh Kumar 55f791be49SBill Pemberton static int 561a6e4b74SViresh Kumar stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) 571a6e4b74SViresh Kumar { 581a6e4b74SViresh Kumar i2c_ci.data = (void *)id; 591a6e4b74SViresh Kumar i2c_ci.irq = i2c->irq; 601a6e4b74SViresh Kumar i2c_ci.client = i2c; 611a6e4b74SViresh Kumar i2c_ci.dev = &i2c->dev; 621a6e4b74SViresh Kumar 631a6e4b74SViresh Kumar return stmpe_probe(&i2c_ci, id->driver_data); 641a6e4b74SViresh Kumar } 651a6e4b74SViresh Kumar 664740f73fSBill Pemberton static int stmpe_i2c_remove(struct i2c_client *i2c) 671a6e4b74SViresh Kumar { 681a6e4b74SViresh Kumar struct stmpe *stmpe = dev_get_drvdata(&i2c->dev); 691a6e4b74SViresh Kumar 701a6e4b74SViresh Kumar return stmpe_remove(stmpe); 711a6e4b74SViresh Kumar } 721a6e4b74SViresh Kumar 731a6e4b74SViresh Kumar static const struct i2c_device_id stmpe_i2c_id[] = { 741cda2394SViresh Kumar { "stmpe610", STMPE610 }, 757f7f4ea1SViresh Kumar { "stmpe801", STMPE801 }, 761a6e4b74SViresh Kumar { "stmpe811", STMPE811 }, 771a6e4b74SViresh Kumar { "stmpe1601", STMPE1601 }, 78*230f13a5SJean-Nicolas Graux { "stmpe1801", STMPE1801 }, 791a6e4b74SViresh Kumar { "stmpe2401", STMPE2401 }, 801a6e4b74SViresh Kumar { "stmpe2403", STMPE2403 }, 811a6e4b74SViresh Kumar { } 821a6e4b74SViresh Kumar }; 831a6e4b74SViresh Kumar MODULE_DEVICE_TABLE(i2c, stmpe_id); 841a6e4b74SViresh Kumar 851a6e4b74SViresh Kumar static struct i2c_driver stmpe_i2c_driver = { 8632533983SViresh Kumar .driver = { 8732533983SViresh Kumar .name = "stmpe-i2c", 8832533983SViresh Kumar .owner = THIS_MODULE, 891a6e4b74SViresh Kumar #ifdef CONFIG_PM 9032533983SViresh Kumar .pm = &stmpe_dev_pm_ops, 911a6e4b74SViresh Kumar #endif 9232533983SViresh Kumar }, 931a6e4b74SViresh Kumar .probe = stmpe_i2c_probe, 9484449216SBill Pemberton .remove = stmpe_i2c_remove, 951a6e4b74SViresh Kumar .id_table = stmpe_i2c_id, 961a6e4b74SViresh Kumar }; 971a6e4b74SViresh Kumar 981a6e4b74SViresh Kumar static int __init stmpe_init(void) 991a6e4b74SViresh Kumar { 1001a6e4b74SViresh Kumar return i2c_add_driver(&stmpe_i2c_driver); 1011a6e4b74SViresh Kumar } 1021a6e4b74SViresh Kumar subsys_initcall(stmpe_init); 1031a6e4b74SViresh Kumar 1041a6e4b74SViresh Kumar static void __exit stmpe_exit(void) 1051a6e4b74SViresh Kumar { 1061a6e4b74SViresh Kumar i2c_del_driver(&stmpe_i2c_driver); 1071a6e4b74SViresh Kumar } 1081a6e4b74SViresh Kumar module_exit(stmpe_exit); 1091a6e4b74SViresh Kumar 1101a6e4b74SViresh Kumar MODULE_LICENSE("GPL v2"); 1111a6e4b74SViresh Kumar MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver"); 1121a6e4b74SViresh Kumar MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>"); 113