blob: fd5fcb63068548d57c44ed3cd0d777228fdbcaec [file] [log] [blame]
Viresh Kumar1a6e4b72011-11-17 11:02:20 +05301/*
2 * ST Microelectronics MFD: stmpe's i2c client specific driver
3 *
4 * Copyright (C) ST-Ericsson SA 2010
5 * Copyright (C) ST Microelectronics SA 2011
6 *
7 * License Terms: GNU General Public License, version 2
8 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
Viresh Kumar10d89352012-06-20 12:53:02 -07009 * Author: Viresh Kumar <viresh.linux@gmail.com> for ST Microelectronics
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053010 */
11
12#include <linux/i2c.h>
13#include <linux/interrupt.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/types.h>
17#include "stmpe.h"
18
19static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
20{
21 struct i2c_client *i2c = stmpe->client;
22
23 return i2c_smbus_read_byte_data(i2c, reg);
24}
25
26static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
27{
28 struct i2c_client *i2c = stmpe->client;
29
30 return i2c_smbus_write_byte_data(i2c, reg, val);
31}
32
33static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
34{
35 struct i2c_client *i2c = stmpe->client;
36
37 return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
38}
39
40static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
41 const u8 *values)
42{
43 struct i2c_client *i2c = stmpe->client;
44
45 return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
46}
47
48static struct stmpe_client_info i2c_ci = {
49 .read_byte = i2c_reg_read,
50 .write_byte = i2c_reg_write,
51 .read_block = i2c_block_read,
52 .write_block = i2c_block_write,
53};
54
Bill Pembertonf791be42012-11-19 13:23:04 -050055static int
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053056stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
57{
58 i2c_ci.data = (void *)id;
59 i2c_ci.irq = i2c->irq;
60 i2c_ci.client = i2c;
61 i2c_ci.dev = &i2c->dev;
62
63 return stmpe_probe(&i2c_ci, id->driver_data);
64}
65
Bill Pemberton4740f732012-11-19 13:26:01 -050066static int stmpe_i2c_remove(struct i2c_client *i2c)
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053067{
68 struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
69
70 return stmpe_remove(stmpe);
71}
72
73static const struct i2c_device_id stmpe_i2c_id[] = {
Viresh Kumar1cda2392011-11-17 11:02:22 +053074 { "stmpe610", STMPE610 },
Viresh Kumar7f7f4ea2011-11-17 11:02:23 +053075 { "stmpe801", STMPE801 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053076 { "stmpe811", STMPE811 },
77 { "stmpe1601", STMPE1601 },
78 { "stmpe2401", STMPE2401 },
79 { "stmpe2403", STMPE2403 },
80 { }
81};
82MODULE_DEVICE_TABLE(i2c, stmpe_id);
83
84static struct i2c_driver stmpe_i2c_driver = {
Viresh Kumar32533982012-11-23 00:26:19 +053085 .driver = {
86 .name = "stmpe-i2c",
87 .owner = THIS_MODULE,
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053088#ifdef CONFIG_PM
Viresh Kumar32533982012-11-23 00:26:19 +053089 .pm = &stmpe_dev_pm_ops,
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053090#endif
Viresh Kumar32533982012-11-23 00:26:19 +053091 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053092 .probe = stmpe_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -050093 .remove = stmpe_i2c_remove,
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053094 .id_table = stmpe_i2c_id,
95};
96
97static int __init stmpe_init(void)
98{
99 return i2c_add_driver(&stmpe_i2c_driver);
100}
101subsys_initcall(stmpe_init);
102
103static void __exit stmpe_exit(void)
104{
105 i2c_del_driver(&stmpe_i2c_driver);
106}
107module_exit(stmpe_exit);
108
109MODULE_LICENSE("GPL v2");
110MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
111MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");