blob: d3eedf3d607eaf89882f57af972e14c32c059112 [file] [log] [blame]
Thomas Gleixner1f67b5992019-06-04 10:10:57 +02001// SPDX-License-Identifier: GPL-2.0-only
Viresh Kumar1a6e4b72011-11-17 11:02:20 +05302/*
3 * ST Microelectronics MFD: stmpe's i2c client specific driver
4 *
5 * Copyright (C) ST-Ericsson SA 2010
6 * Copyright (C) ST Microelectronics SA 2011
7 *
Viresh Kumar1a6e4b72011-11-17 11:02:20 +05308 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
Viresh Kumarda899472015-07-17 16:23:50 -07009 * Author: Viresh Kumar <vireshk@kernel.org> 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>
Linus Walleij5a826fe2014-04-23 23:35:58 +020017#include <linux/of_device.h>
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053018#include "stmpe.h"
19
20static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
21{
22 struct i2c_client *i2c = stmpe->client;
23
24 return i2c_smbus_read_byte_data(i2c, reg);
25}
26
27static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
28{
29 struct i2c_client *i2c = stmpe->client;
30
31 return i2c_smbus_write_byte_data(i2c, reg, val);
32}
33
34static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
35{
36 struct i2c_client *i2c = stmpe->client;
37
38 return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
39}
40
41static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
42 const u8 *values)
43{
44 struct i2c_client *i2c = stmpe->client;
45
46 return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
47}
48
49static struct stmpe_client_info i2c_ci = {
50 .read_byte = i2c_reg_read,
51 .write_byte = i2c_reg_write,
52 .read_block = i2c_block_read,
53 .write_block = i2c_block_write,
54};
55
Linus Walleij5a826fe2014-04-23 23:35:58 +020056static const struct of_device_id stmpe_of_match[] = {
57 { .compatible = "st,stmpe610", .data = (void *)STMPE610, },
58 { .compatible = "st,stmpe801", .data = (void *)STMPE801, },
59 { .compatible = "st,stmpe811", .data = (void *)STMPE811, },
Patrice Chotard6bb9f0d2016-08-10 09:39:14 +020060 { .compatible = "st,stmpe1600", .data = (void *)STMPE1600, },
Linus Walleij5a826fe2014-04-23 23:35:58 +020061 { .compatible = "st,stmpe1601", .data = (void *)STMPE1601, },
62 { .compatible = "st,stmpe1801", .data = (void *)STMPE1801, },
63 { .compatible = "st,stmpe2401", .data = (void *)STMPE2401, },
64 { .compatible = "st,stmpe2403", .data = (void *)STMPE2403, },
65 {},
66};
67MODULE_DEVICE_TABLE(of, stmpe_of_match);
68
Bill Pembertonf791be42012-11-19 13:23:04 -050069static int
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053070stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
71{
Lee Jonesc00572b2014-07-02 11:54:32 +010072 enum stmpe_partnum partnum;
Linus Walleij5a826fe2014-04-23 23:35:58 +020073 const struct of_device_id *of_id;
74
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053075 i2c_ci.data = (void *)id;
76 i2c_ci.irq = i2c->irq;
77 i2c_ci.client = i2c;
78 i2c_ci.dev = &i2c->dev;
79
Linus Walleij5a826fe2014-04-23 23:35:58 +020080 of_id = of_match_device(stmpe_of_match, &i2c->dev);
81 if (!of_id) {
82 /*
83 * This happens when the I2C ID matches the node name
84 * but no real compatible string has been given.
85 */
86 dev_info(&i2c->dev, "matching on node name, compatible is preferred\n");
87 partnum = id->driver_data;
88 } else
Lee Jonesc00572b2014-07-02 11:54:32 +010089 partnum = (enum stmpe_partnum)of_id->data;
Linus Walleij5a826fe2014-04-23 23:35:58 +020090
91 return stmpe_probe(&i2c_ci, partnum);
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053092}
93
Bill Pemberton4740f732012-11-19 13:26:01 -050094static int stmpe_i2c_remove(struct i2c_client *i2c)
Viresh Kumar1a6e4b72011-11-17 11:02:20 +053095{
96 struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
97
Uwe Kleine-König356bbab2021-10-12 17:39:34 +020098 stmpe_remove(stmpe);
99
100 return 0;
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530101}
102
103static const struct i2c_device_id stmpe_i2c_id[] = {
Viresh Kumar1cda2392011-11-17 11:02:22 +0530104 { "stmpe610", STMPE610 },
Viresh Kumar7f7f4ea2011-11-17 11:02:23 +0530105 { "stmpe801", STMPE801 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530106 { "stmpe811", STMPE811 },
Patrice Chotard6bb9f0d2016-08-10 09:39:14 +0200107 { "stmpe1600", STMPE1600 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530108 { "stmpe1601", STMPE1601 },
Jean-Nicolas Graux230f13a2013-04-09 10:35:19 +0200109 { "stmpe1801", STMPE1801 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530110 { "stmpe2401", STMPE2401 },
111 { "stmpe2403", STMPE2403 },
112 { }
113};
Zou Wei4700ef322021-05-12 14:33:46 +0800114MODULE_DEVICE_TABLE(i2c, stmpe_i2c_id);
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530115
116static struct i2c_driver stmpe_i2c_driver = {
Viresh Kumar32533982012-11-23 00:26:19 +0530117 .driver = {
118 .name = "stmpe-i2c",
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530119#ifdef CONFIG_PM
Viresh Kumar32533982012-11-23 00:26:19 +0530120 .pm = &stmpe_dev_pm_ops,
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530121#endif
Linus Walleij5a826fe2014-04-23 23:35:58 +0200122 .of_match_table = stmpe_of_match,
Viresh Kumar32533982012-11-23 00:26:19 +0530123 },
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530124 .probe = stmpe_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500125 .remove = stmpe_i2c_remove,
Viresh Kumar1a6e4b72011-11-17 11:02:20 +0530126 .id_table = stmpe_i2c_id,
127};
128
129static int __init stmpe_init(void)
130{
131 return i2c_add_driver(&stmpe_i2c_driver);
132}
133subsys_initcall(stmpe_init);
134
135static void __exit stmpe_exit(void)
136{
137 i2c_del_driver(&stmpe_i2c_driver);
138}
139module_exit(stmpe_exit);
140
141MODULE_LICENSE("GPL v2");
142MODULE_DESCRIPTION("STMPE MFD I2C Interface Driver");
143MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");