summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx-2.6.24/patches/pxav4l3-8.patch.eml
blob: 22abad6b1c3bb0fbd270438a356ed33b98a5ce6f (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
Path: news.gmane.org!not-for-mail
From: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Newsgroups: gmane.comp.video.video4linux,gmane.linux.drivers.i2c
Subject: [RFC PATCH 3/8] Philips PCA9536 4 bit I2C GPIO extender driver
Date: Wed, 23 Jan 2008 18:41:39 +0100 (CET)
Lines: 210
Approved: news@gmane.org
Message-ID: <Pine.LNX.4.64.0801231820060.4932@axis700.grange>
References: <Pine.LNX.4.64.0801231646090.4932@axis700.grange>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Trace: ger.gmane.org 1201110131 28782 80.91.229.12 (23 Jan 2008 17:42:11 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 23 Jan 2008 17:42:11 +0000 (UTC)
Cc: i2c@lm-sensors.org
To: video4linux-list@redhat.com
Original-X-From: video4linux-list-bounces@redhat.com Wed Jan 23 18:42:30 2008
Return-path: <video4linux-list-bounces@redhat.com>
Envelope-to: rh-video4linux-list@gmane.org
Original-Received: from hormel.redhat.com ([209.132.177.30])
	by lo.gmane.org with esmtp (Exim 4.50)
	id 1JHjcK-0002zY-Jd
	for rh-video4linux-list@gmane.org; Wed, 23 Jan 2008 18:42:29 +0100
Original-Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110])
	by hormel.redhat.com (Postfix) with ESMTP
	id 1D07D72F5C; Wed, 23 Jan 2008 12:42:02 -0500 (EST)
Original-Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254])
	by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id
	m0NHfx7t017217 for <video4linux-list@listman.util.phx.redhat.com>;
	Wed, 23 Jan 2008 12:41:59 -0500
Original-Received: from mx3.redhat.com (mx3.redhat.com [172.16.48.32])
	by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m0NHfxW4028112
	for <video4linux-list@redhat.com>; Wed, 23 Jan 2008 12:41:59 -0500
Original-Received: from mail.gmx.net (mail.gmx.net [213.165.64.20])
	by mx3.redhat.com (8.13.1/8.13.1) with SMTP id m0NHfPdF000786
	for <video4linux-list@redhat.com>; Wed, 23 Jan 2008 12:41:25 -0500
Original-Received: (qmail invoked by alias); 23 Jan 2008 17:41:19 -0000
Original-Received: from p57BD2F1F.dip0.t-ipconnect.de (EHLO axis700.grange)
	[87.189.47.31]
	by mail.gmx.net (mp021) with SMTP; 23 Jan 2008 18:41:19 +0100
X-Authenticated: #20450766
X-Provags-ID: V01U2FsdGVkX18gZ14xakQgr3grhg4ys0olRWzKeUW5G+x4WUV9jY
	iLvi2phxgtwjvM
Original-Received: from lyakh (helo=localhost)
	by axis700.grange with local-esmtp (Exim 4.63)
	(envelope-from <g.liakhovetski@gmx.de>)
	id 1JHjbX-00029t-5A; Wed, 23 Jan 2008 18:41:39 +0100
X-X-Sender: lyakh@axis700.grange
In-Reply-To: <Pine.LNX.4.64.0801231646090.4932@axis700.grange>
X-Y-GMX-Trusted: 0
X-RedHat-Spam-Score: 0 
X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254
X-Scanned-By: MIMEDefang 2.58 on 172.16.48.32
X-loop: video4linux-list@redhat.com
X-BeenThere: video4linux-list@redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux and Kernel Video <video4linux-list.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/video4linux-list>, 
	<mailto:video4linux-list-request@redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/mailman/private/video4linux-list>
List-Post: <mailto:video4linux-list@redhat.com>
List-Help: <mailto:video4linux-list-request@redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/video4linux-list>,
	<mailto:video4linux-list-request@redhat.com?subject=subscribe>
Original-Sender: video4linux-list-bounces@redhat.com
Errors-To: video4linux-list-bounces@redhat.com
Xref: news.gmane.org gmane.comp.video.video4linux:36471 gmane.linux.drivers.i2c:251
Archived-At: <http://permalink.gmane.org/gmane.comp.video.video4linux/36471>

This driver will be used by the mt9m001 and the mt9v022 camera drivers,
that can use a pca9536 to switch between 8 and 10 bit modes.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
---
 drivers/i2c/chips/Kconfig   |   10 +++
 drivers/i2c/chips/Makefile  |    1 +
 drivers/i2c/chips/pca9536.c |  153 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/chips/pca9536.c

diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 2e1c24f..6f492f1 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -65,6 +65,16 @@ config SENSORS_PCF8574
 	  These devices are hard to detect and rarely found on mainstream
 	  hardware.  If unsure, say N.
 
+config SENSORS_PCA9536
+	tristate "Philips PCA9536 4-bit I/O port"
+	depends on EXPERIMENTAL
+	help
+	  If you say yes here you get support for the Philips PCA9539
+	  4-bit I/O port.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called pca9536.
+
 config SENSORS_PCA9539
 	tristate "Philips PCA9539 16-bit I/O port"
 	depends on EXPERIMENTAL
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index ca924e1..e24c582 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DS1682)		+= ds1682.o
 obj-$(CONFIG_SENSORS_EEPROM)	+= eeprom.o
 obj-$(CONFIG_SENSORS_MAX6875)	+= max6875.o
 obj-$(CONFIG_SENSORS_M41T00)	+= m41t00.o
+obj-$(CONFIG_SENSORS_PCA9536)	+= pca9536.o
 obj-$(CONFIG_SENSORS_PCA9539)	+= pca9539.o
 obj-$(CONFIG_SENSORS_PCF8574)	+= pcf8574.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
diff --git a/drivers/i2c/chips/pca9536.c b/drivers/i2c/chips/pca9536.c
new file mode 100644
index 0000000..08e5d8b
--- /dev/null
+++ b/drivers/i2c/chips/pca9536.c
@@ -0,0 +1,152 @@
+/*
+ * Driver for PCA9536 I/O Expander
+ *
+ * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
+ *
+ * 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/videodev.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/hwmon-sysfs.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+
+#define PCA9536_INPUT 0
+#define PCA9536_OUTPUT 1
+#define PCA9536_INVERT 2
+#define PCA9536_DIRECTION 3
+
+/* following are the sysfs callback functions */
+static ssize_t pca9536_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+
+	return sprintf(buf, "%d\n", i2c_smbus_read_byte_data(client,
+							     psa->index));
+}
+
+static ssize_t pca9536_store(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t count)
+{
+	struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	unsigned long val = simple_strtoul(buf, NULL, 0);
+
+	if (val > 0xff)
+		return -EINVAL;
+
+	i2c_smbus_write_byte_data(client, psa->index, val);
+	return count;
+}
+
+int pca9536_set_level(struct i2c_client *client, u8 pin, u8 level)
+{
+	s32 data;
+
+	if (pin > 3)
+		return -EINVAL;
+
+	/* Switch to output */
+	data = i2c_smbus_read_byte_data(client, PCA9536_DIRECTION);
+	if (data < 0)
+		return data;
+	data = i2c_smbus_write_byte_data(client, PCA9536_DIRECTION,
+					 data & ~(1 << pin));
+	if (data < 0)
+		return data;
+
+	/* Set level */
+	data = i2c_smbus_read_byte_data(client, PCA9536_OUTPUT);
+	if (data < 0)
+		return data;
+	if (level)
+		data |= (1 << pin);
+	else
+		data &= ~(1 << pin);
+	data = i2c_smbus_write_byte_data(client, PCA9536_OUTPUT, data);
+
+	return data;
+}
+EXPORT_SYMBOL(pca9536_set_level);
+
+/* Define the device attributes */
+
+#define PCA9536_ENTRY_RO(name, reg) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO, pca9536_show, NULL, reg)
+
+#define PCA9536_ENTRY_RW(name, reg) \
+	static SENSOR_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, pca9536_show, \
+				  pca9536_store, reg)
+
+PCA9536_ENTRY_RO(input, PCA9536_INPUT);
+PCA9536_ENTRY_RW(output, PCA9536_OUTPUT);
+PCA9536_ENTRY_RW(invert, PCA9536_INVERT);
+PCA9536_ENTRY_RW(direction, PCA9536_DIRECTION);
+
+static struct attribute *pca9536_attributes[] = {
+	&sensor_dev_attr_input.dev_attr.attr,
+	&sensor_dev_attr_output.dev_attr.attr,
+	&sensor_dev_attr_invert.dev_attr.attr,
+	&sensor_dev_attr_direction.dev_attr.attr,
+	NULL
+};
+
+static struct attribute_group pca9536_defattr_group = {
+	.attrs = pca9536_attributes,
+};
+
+static int pca9536_probe(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+		pr_debug("%s: I2C-Adapter doesn't support I2C_FUNC_SMBUS_BYTE\n", __FUNCTION__);
+		return -EIO;
+	}
+
+	if (client->dev.platform_data)
+		/* This chip is going to be used from the kernel */
+		*(struct i2c_client **)client->dev.platform_data = client;
+
+	/* Register sysfs hooks */
+	return sysfs_create_group(&client->dev.kobj,
+				  &pca9536_defattr_group);
+}
+
+static int pca9536_remove(struct i2c_client *client)
+{
+	sysfs_remove_group(&client->dev.kobj, &pca9536_defattr_group);
+	return 0;
+}
+
+static struct i2c_driver pca9536_i2c_driver = {
+	.driver = {
+		.name = "pca9536",
+	},
+	.probe		= pca9536_probe,
+	.remove		= pca9536_remove,
+};
+
+static int __init pca9536_mod_init(void)
+{
+	return i2c_add_driver(&pca9536_i2c_driver);
+}
+
+static void __exit pca9536_mod_exit(void)
+{
+	i2c_del_driver(&pca9536_i2c_driver);
+}
+
+module_init(pca9536_mod_init);
+module_exit(pca9536_mod_exit);
+
+MODULE_DESCRIPTION("PCA9536 driver");
+MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
+MODULE_LICENSE("GPL");
-- 
1.5.3.4

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list