aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-handheld-4.0/locomo/0011-i2c-add-locomo-i2c-driver.patch
blob: 43a2bd3ccc9a6abca200b86f96a2e34795b681d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
From 37279f73cbea78da52a4eac4a4c13406ff5500da Mon Sep 17 00:00:00 2001
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Date: Fri, 14 Nov 2014 16:07:58 +0300
Subject: [PATCH 11/20] i2c: add locomo i2c driver

LoCoMo chip contains a tiny i2c controller destined to control
M62332 DAC. Provide a separate I2C driver for this cell.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
---
 drivers/i2c/busses/Kconfig      |  12 ++++
 drivers/i2c/busses/Makefile     |   1 +
 drivers/i2c/busses/i2c-locomo.c | 136 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-locomo.c

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 22da9c2..a4b20ba 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -584,6 +584,18 @@ config I2C_KEMPLD
 	  This driver can also be built as a module. If so, the module
 	  will be called i2c-kempld.
 
+config I2C_LOCOMO
+	tristate "I2C bus support for LoCoMo chips"
+	depends on MFD_LOCOMO
+	select I2C_ALGOBIT
+	help
+	  Say yes if you will run the kernel on Sharp SL-5x00 family of devices.
+
+	  If you don't know what to do here, say N.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-locomo.
+
 config I2C_MESON
 	tristate "Amlogic Meson I2C controller"
 	depends on ARCH_MESON
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 3638feb..d31ae1a 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_I2C_IMG)		+= i2c-img-scb.o
 obj-$(CONFIG_I2C_IMX)		+= i2c-imx.o
 obj-$(CONFIG_I2C_IOP3XX)	+= i2c-iop3xx.o
 obj-$(CONFIG_I2C_KEMPLD)	+= i2c-kempld.o
+obj-$(CONFIG_I2C_LOCOMO)	+= i2c-locomo.o
 obj-$(CONFIG_I2C_MESON)		+= i2c-meson.o
 obj-$(CONFIG_I2C_MPC)		+= i2c-mpc.o
 obj-$(CONFIG_I2C_MV64XXX)	+= i2c-mv64xxx.o
diff --git a/drivers/i2c/busses/i2c-locomo.c b/drivers/i2c/busses/i2c-locomo.c
new file mode 100644
index 0000000..640b46cd
--- /dev/null
+++ b/drivers/i2c/busses/i2c-locomo.c
@@ -0,0 +1,136 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/mfd/locomo.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+
+struct locomo_i2c {
+	struct regmap		*regmap;
+	struct i2c_adapter	 adap;
+	struct i2c_algo_bit_data bit;
+};
+
+static void locomo_i2c_setsda(void *data, int state)
+{
+	struct locomo_i2c *li2c = data;
+
+	regmap_update_bits(li2c->regmap, LOCOMO_DAC,
+			LOCOMO_DAC_SDAOEB,
+			state ? LOCOMO_DAC_SDAOEB : 0);
+}
+
+static void locomo_i2c_setscl(void *data, int state)
+{
+	struct locomo_i2c *li2c = data;
+
+	regmap_update_bits(li2c->regmap, LOCOMO_DAC,
+			LOCOMO_DAC_SCLOEB,
+			state ? LOCOMO_DAC_SCLOEB : 0);
+}
+
+static int locomo_i2c_getsda(void *data)
+{
+	struct locomo_i2c *li2c = data;
+	unsigned int r;
+
+	regmap_read(li2c->regmap, LOCOMO_DAC, &r);
+
+	return !!(r & LOCOMO_DAC_SDA);
+}
+
+static int locomo_i2c_probe(struct platform_device *dev)
+{
+	struct locomo_i2c *li2c;
+	int ret;
+
+	li2c = devm_kzalloc(&dev->dev, sizeof(struct locomo_i2c), GFP_KERNEL);
+	if (li2c == NULL)
+		return -ENOMEM;
+
+	li2c->regmap = dev_get_regmap(dev->dev.parent, NULL);
+	if (!li2c->regmap)
+		return -ENODEV;
+
+	li2c->adap.owner = THIS_MODULE;
+	li2c->adap.dev.parent = &dev->dev;
+	li2c->adap.dev.of_node = dev->dev.of_node;
+	li2c->adap.algo_data = &li2c->bit;
+	li2c->adap.nr = 1; /* On poodle, 0 is pxa internal bus */
+
+	strlcpy(li2c->adap.name, "LoCoMo I2C", sizeof(li2c->adap.name));
+
+	li2c->bit.data = li2c;
+	li2c->bit.setsda = locomo_i2c_setsda;
+	li2c->bit.setscl = locomo_i2c_setscl;
+	li2c->bit.getsda = locomo_i2c_getsda;
+	li2c->bit.udelay = 6;
+	li2c->bit.timeout = HZ;
+
+	ret = i2c_bit_add_numbered_bus(&li2c->adap);
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(dev, li2c);
+
+	return 0;
+}
+
+static int locomo_i2c_remove(struct platform_device *dev)
+{
+	struct locomo_i2c *li2c = platform_get_drvdata(dev);
+
+	i2c_del_adapter(&li2c->adap);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int locomo_i2c_suspend(struct device *dev)
+{
+	struct locomo_i2c *li2c = dev_get_drvdata(dev);
+
+	regmap_write(li2c->regmap, LOCOMO_DAC, 0x00);
+
+	return 0;
+}
+
+static int locomo_i2c_resume(struct device *dev)
+{
+	struct locomo_i2c *li2c = dev_get_drvdata(dev);
+
+	regmap_write(li2c->regmap, LOCOMO_DAC,
+			LOCOMO_DAC_SDAOEB | LOCOMO_DAC_SCLOEB);
+
+	return 0;
+}
+static SIMPLE_DEV_PM_OPS(locomo_i2c_pm, locomo_i2c_suspend, locomo_i2c_resume);
+#define LOCOMO_I2C_PM	(&locomo_i2c_pm)
+#else
+#define LOCOMO_I2C_PM	NULL
+#endif
+
+
+static struct platform_driver locomo_i2c_driver = {
+	.driver		= {
+		.name	= "locomo-i2c",
+		.pm	= LOCOMO_I2C_PM,
+	},
+	.probe		= locomo_i2c_probe,
+	.remove		= locomo_i2c_remove,
+};
+
+module_platform_driver(locomo_i2c_driver);
+
+MODULE_DESCRIPTION("LoCoMo i2c bus driver");
+MODULE_AUTHOR("Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:locomo-i2c");
-- 
1.9.1