aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/stmpe-i2c.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@st.com>2011-11-17 00:32:20 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2012-01-08 18:37:42 -0500
commit1a6e4b7415339e3b11a87cff0d701b8a2e55f062 (patch)
treefbd5151ac34bf908826f4bbf8b298404660a8de1 /drivers/mfd/stmpe-i2c.c
parent71e58782d2e054798f91473f5452ffe65e2a5ff8 (diff)
mfd: Separate out STMPE controller and interface specific code
Few STMPE controller can have register interface over SPI or I2C. Current implementation only supports I2C and all code is present in a single file stmpe.c. It would be better to separate out I2C interface specific code from controller specific code. Later SPI specific code can be added in a separate file. This patch separates out I2C and controller specific code into separate files, making stmpe.c independent of I2C. Signed-off-by: Viresh Kumar <viresh.kumar@st.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/stmpe-i2c.c')
-rw-r--r--drivers/mfd/stmpe-i2c.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
new file mode 100644
index 000000000000..0a4365902e36
--- /dev/null
+++ b/drivers/mfd/stmpe-i2c.c
@@ -0,0 +1,107 @@
1/*
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
9 * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
10 */
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
55static int __devinit
56stmpe_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
66static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
67{
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[] = {
74 { "stmpe811", STMPE811 },
75 { "stmpe1601", STMPE1601 },
76 { "stmpe2401", STMPE2401 },
77 { "stmpe2403", STMPE2403 },
78 { }
79};
80MODULE_DEVICE_TABLE(i2c, stmpe_id);
81
82static struct i2c_driver stmpe_i2c_driver = {
83 .driver.name = "stmpe-i2c",
84 .driver.owner = THIS_MODULE,
85#ifdef CONFIG_PM
86 .driver.pm = &stmpe_dev_pm_ops,
87#endif
88 .probe = stmpe_i2c_probe,
89 .remove = __devexit_p(stmpe_i2c_remove),
90 .id_table = stmpe_i2c_id,
91};
92
93static int __init stmpe_init(void)
94{
95 return i2c_add_driver(&stmpe_i2c_driver);
96}
97subsys_initcall(stmpe_init);
98
99static void __exit stmpe_exit(void)
100{
101 i2c_del_driver(&stmpe_i2c_driver);
102}
103module_exit(stmpe_exit);
104
105MODULE_LICENSE("GPL v2");
106MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
107MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");