summaryrefslogtreecommitdiff
path: root/packages/linux/linux-mtx-1-2.4.27/18-i2c-au1x00gpio.patch
blob: 2dccf681ebba64a40b5147c728055620dceb8c82 (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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Config.in linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Config.in
--- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Config.in	2004-12-13 18:03:18.000000000 +0100
+++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Config.in	2004-12-13 18:11:02.000000000 +0100
@@ -17,6 +17,11 @@
          int  '    GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
          int  '    GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
       fi
+      dep_tristate '  I2C using Au1x00 GPIO pins' CONFIG_I2C_AU1X00GPIO $CONFIG_I2C_ALGOBIT
+      if [ "$CONFIG_I2C_AU1X00GPIO" != "n" ]; then
+         int  '    GPIO pin used for SCL' CONFIG_I2C_AU1X00GPIO_SCL 206
+         int  '    GPIO pin used for SDA' CONFIG_I2C_AU1X00GPIO_SDA 207
+      fi
    fi
 
    dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/i2c-au1x00gpio.c linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/i2c-au1x00gpio.c
--- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/i2c-au1x00gpio.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/i2c-au1x00gpio.c	2004-12-13 18:12:50.000000000 +0100
@@ -0,0 +1,426 @@
+/* ------------------------------------------------------------------------- */
+/* i2c-au1x00gpio.c i2c-hw access for Au1x00 GPIO pins.                      */
+/* ------------------------------------------------------------------------- */
+/*   Copyright (C) 1995-2000 Michael Stickel
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.		     */
+/* ------------------------------------------------------------------------- */ 
+
+/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
+   Frodo Looijaard <frodol@dds.nl>
+   Simon G. Vogl
+*/
+
+/* $Id: i2c-au1x00gpio.c,v 1.1.1.2 2004/01/22 15:35:47 br1 Exp $ */
+
+#include <linux/module.h>
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/stddef.h>
+#include <linux/ioport.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <asm/au1000.h>
+#include <asm/au1000_gpio.h>
+
+#include <linux/slab.h>
+#include <linux/mm.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+
+#ifndef __exit
+#define __exit __init
+#endif
+
+
+struct i2c_au1x00gpio
+{
+	struct i2c_au1x00gpio *next;
+
+	short  scl_gpio;
+	short  sda_gpio;
+
+	unsigned long scl_mask;
+	unsigned long sda_mask;
+
+	struct i2c_adapter adapter;
+	struct i2c_algo_bit_data bit_au1x00gpio_data;
+};
+
+static struct i2c_au1x00gpio *adapter_list;
+
+
+
+/* ----- global defines -----------------------------------------------	*/
+#define DEB(x)		/* should be reasonable open, close &c. 	*/
+#define DEB2(x) 	/* low level debugging - very slow 		*/
+#define DEBE(x)	x	/* error messages 				*/
+
+/* ----- printer port defines ------------------------------------------*/
+
+/* ----- local functions ----------------------------------------------	*/
+
+
+//-- Primary GPIO
+static void bit_au1x00gpio_setscl(void *data, int state)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  if (state)
+    au_writel(adapter->scl_mask, SYS_TRIOUTCLR); // Disable Driver: Switch off Transistor => 1
+  else
+    au_writel(adapter->scl_mask, SYS_OUTPUTCLR); // Clear Output and switch on Transistor => 0
+}
+
+
+static void bit_au1x00gpio_setsda(void *data, int state)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  if (state)
+    au_writel(adapter->sda_mask, SYS_TRIOUTCLR);
+  else
+    au_writel(adapter->sda_mask, SYS_OUTPUTCLR);
+}
+
+
+static int bit_au1x00gpio_getscl(void *data)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  return (au_readl(SYS_PINSTATERD) & adapter->scl_mask) ? 1 : 0;
+}
+
+
+static int bit_au1x00gpio_getsda(void *data)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  return (au_readl(SYS_PINSTATERD) & adapter->sda_mask) ? 1 : 0;
+}
+
+
+
+
+/*--
+ *-- Functions for accessing GPIO-2
+ *--
+ */
+static void bit_au1x00gpio2_setscl(void *data, int state)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  if (state)
+    {
+      au_writel(au_readl(GPIO2_DIR) & ~adapter->scl_mask, GPIO2_DIR);
+    }
+  else
+    {
+      au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->scl_mask, GPIO2_OUTPUT);
+      au_writel(au_readl(GPIO2_DIR) | adapter->scl_mask, GPIO2_DIR);
+    }
+}
+
+static void bit_au1x00gpio2_setsda(void *data, int state)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  if (state)
+    {
+      au_writel(au_readl(GPIO2_DIR) & ~adapter->sda_mask, GPIO2_DIR);
+    }
+  else
+    {
+      au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->sda_mask, GPIO2_OUTPUT);
+      au_writel(au_readl(GPIO2_DIR) | adapter->sda_mask, GPIO2_DIR);
+    }
+}
+
+static int bit_au1x00gpio2_getscl(void *data)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  return (au_readl(GPIO2_PINSTATE) & adapter->scl_mask) ? 1 : 0;
+}
+
+static int bit_au1x00gpio2_getsda(void *data)
+{
+  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
+  return (au_readl(GPIO2_PINSTATE) & adapter->sda_mask) ? 1 : 0;
+}
+
+
+
+static int check_i2c_au1x00gpio_adapter(struct i2c_au1x00gpio *adapter)
+{
+  int state = 0;
+
+  adapter->bit_au1x00gpio_data.setsda (adapter, 1);
+  adapter->bit_au1x00gpio_data.setscl (adapter, 1);
+
+  if (adapter->bit_au1x00gpio_data.getsda(adapter)==0)
+    {
+      printk ("i2c-au1x00gpio: sda line should read 1 but reads 0\n");
+      state = -1;
+    }
+  if (adapter->bit_au1x00gpio_data.getscl(adapter)==0)
+    {
+      printk ("i2c-au1x00gpio: scl line should read 1 but reads 0\n");
+      state = -1;
+    }
+
+
+  adapter->bit_au1x00gpio_data.setsda (adapter, 0);
+  adapter->bit_au1x00gpio_data.setscl (adapter, 0);
+
+  if (adapter->bit_au1x00gpio_data.getsda(adapter)==1)
+    {
+      printk ("i2c-au1x00gpio: sda line should read 0 but reads 1\n");
+      state = -1;
+    }
+  if (adapter->bit_au1x00gpio_data.getscl(adapter)==1)
+    {
+      printk ("i2c-au1x00gpio: scl line should read 0 but reads 1\n");
+      state = -1;
+    }
+
+  if (state==0)
+    printk ("i2c-au1x00gpio: adapter with scl=GPIO%d,sda=GPIO%d is working\n",
+	    adapter->scl_gpio, adapter->sda_gpio
+	    );
+  return state;
+}
+
+
+
+#if 0
+static int bit_au1x00gpio_reg(struct i2c_client *client)
+{
+	return 0;
+}
+
+static int bit_au1x00gpio_unreg(struct i2c_client *client)
+{
+	return 0;
+}
+
+static void bit_au1x00gpio_inc_use(struct i2c_adapter *adap)
+{
+	MOD_INC_USE_COUNT;
+}
+
+static void bit_au1x00gpio_dec_use(struct i2c_adapter *adap)
+{
+	MOD_DEC_USE_COUNT;
+}
+#endif
+ 
+
+
+static struct i2c_algo_bit_data bit_au1x00gpio_data = {
+	.setsda = bit_au1x00gpio_setsda,
+	.setscl = bit_au1x00gpio_setscl,
+	.getsda = bit_au1x00gpio_getsda,
+	.getscl = bit_au1x00gpio_getscl,
+	.udelay = 80,
+	.mdelay = 80,
+	.timeout = HZ
+}; 
+
+
+static struct i2c_adapter bit_au1x00gpio_ops = {
+        .owner          = THIS_MODULE,
+        .name           = "Au1x00 GPIO I2C adapter",
+        .id             = I2C_HW_B_AU1x00GPIO,
+};
+
+
+
+/*
+ * scl_gpio:
+ *   0..31 for primary GPIO's
+ *   200..215 for secondary GPIO's
+ *
+ * sda_gpio:
+ *   0..31 for primary GPIO's
+ *   200..215 for secondary GPIO's
+ *
+ * You can even mix primary and secondary GPIO's.
+ * E.g.:  i2c_au1x00gpio_create(4,206);
+ */
+
+static int i2c_au1x00gpio_create (int scl_gpio, int sda_gpio)
+{
+  if ((scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)) &&
+      (scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)))
+    {
+	struct i2c_au1x00gpio *adapter = kmalloc(sizeof(struct i2c_au1x00gpio),
+					  GFP_KERNEL);
+	if (!adapter) {
+		printk(KERN_ERR "i2c-au1x00-gpio: Unable to malloc.\n");
+		return -1;
+	}
+
+	printk(KERN_DEBUG "i2c-au1x00-gpio.o: attaching to SCL=GPIO%d, SDA=GPIO%d\n",
+	       scl_gpio, sda_gpio);
+
+	memset (adapter, 0, sizeof(struct i2c_au1x00gpio));
+
+	adapter->adapter = bit_au1x00gpio_ops;
+
+	adapter->adapter.algo_data = &adapter->bit_au1x00gpio_data;
+	adapter->bit_au1x00gpio_data = bit_au1x00gpio_data;
+	adapter->bit_au1x00gpio_data.data = adapter;
+
+	adapter->bit_au1x00gpio_data.data = adapter;
+
+	adapter->scl_gpio = scl_gpio;
+	adapter->sda_gpio = sda_gpio;
+
+        if (sda_gpio < 32)
+          {
+	    adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio_setsda;
+	    adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio_getsda;
+            adapter->sda_mask = 1<<sda_gpio;
+          }
+        else if (sda_gpio >= 200 && sda_gpio <= 215)
+          {
+	    adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio2_setsda;
+	    adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio2_getsda;
+            adapter->sda_mask = 1<<(sda_gpio-200);
+          }
+
+
+        if (scl_gpio < 32)
+          {
+	    adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio_setscl;
+	    adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio_getscl;
+            adapter->scl_mask = 1<<scl_gpio;
+          }
+        else if (scl_gpio >= 200 && scl_gpio <= 215)
+          {
+ 	    adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio2_setscl;
+	    adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio2_getscl;
+            adapter->scl_mask = 1<<(scl_gpio-200);
+          }
+
+	au_writel(0L, SYS_PININPUTEN);
+	if (check_i2c_au1x00gpio_adapter(adapter)==0)
+	  {
+	    adapter->bit_au1x00gpio_data.setsda (adapter, 1);
+	    adapter->bit_au1x00gpio_data.setscl (adapter, 1);
+
+	    if (i2c_bit_add_bus(&adapter->adapter) < 0)
+	      {
+		printk(KERN_ERR "i2c-au1x00-gpio: Unable to register with I2C.\n");
+		kfree(adapter);
+		return -1;		/* No good */
+	      }
+	    
+	    adapter->next = adapter_list;
+	    adapter_list = adapter;
+	    return 0;
+	  }
+    }
+  else
+    printk(KERN_ERR "i2c-au1x00-gpio: Invalid argument scl_gpio=%d, sda_gpio=%d.\n", scl_gpio, sda_gpio);
+  return -1;
+}
+
+
+
+static void i2c_au1x00gpio_delete (int scl_gpio, int sda_gpio)
+{
+	struct i2c_au1x00gpio *adapter, *prev = NULL;
+
+	for (adapter = adapter_list; adapter; adapter = adapter->next)
+	{
+		if (adapter->scl_gpio == scl_gpio &&
+		    adapter->sda_gpio == sda_gpio)
+		{
+			i2c_bit_del_bus(&adapter->adapter);
+			if (prev)
+				prev->next = adapter->next;
+			else
+				adapter_list = adapter->next;
+			kfree(adapter);
+			return;
+		}
+		prev = adapter;
+	}
+}
+
+
+
+
+
+#ifndef CONFIG_I2C_AU1X00GPIO_SCL
+#define CONFIG_I2C_AU1X00GPIO_SCL (216)
+#endif
+
+#ifndef CONFIG_I2C_AU1X00GPIO_SDA
+#define CONFIG_I2C_AU1X00GPIO_SDA (217)
+#endif
+
+static int au1x00gpiopin_scl = CONFIG_I2C_AU1X00GPIO_SCL;
+static int au1x00gpiopin_sda = CONFIG_I2C_AU1X00GPIO_SDA;
+
+
+
+int __init i2c_bit_au1x00gpio_init(void)
+{
+  printk(KERN_INFO "i2c-au1x00gpio.o: i2c Au1x00 GPIO adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
+
+  if (i2c_au1x00gpio_create (au1x00gpiopin_scl, au1x00gpiopin_sda) == 0)
+    {
+      printk(KERN_INFO "i2c-au1x00gpio.o: registered I2C-Bus for GPIO%d,GPIO%d\n",
+            au1x00gpiopin_scl, au1x00gpiopin_sda
+            );
+      return 0;
+    }
+  printk(KERN_INFO "i2c-au1x00gpio.o: failed to register I2C-Bus for GPIO%d,GPIO%d\n",
+            au1x00gpiopin_scl, au1x00gpiopin_sda
+        );
+  return -1;
+}
+
+
+void __exit i2c_bit_au1x00gpio_exit(void)
+{
+  i2c_au1x00gpio_delete (au1x00gpiopin_scl, au1x00gpiopin_sda);
+}
+
+
+
+EXPORT_NO_SYMBOLS;
+
+MODULE_PARM(au1x00gpiopin_scl, "i");
+MODULE_PARM_DESC(au1x00gpiopin_scl, "GPIO pin number used for SCL pin.");
+
+MODULE_PARM(au1x00gpiopin_sda, "i");
+MODULE_PARM_DESC(au1x00gpiopin_sda, "GPIO pin number used for SDA pin.");
+
+MODULE_AUTHOR("Michael Stickel <michael@cubic.org>");
+MODULE_DESCRIPTION("I2C-Bus adapter routines for Au1x00 GPIO adapter.");
+MODULE_LICENSE("GPL");
+
+
+#ifdef MODULE
+int init_module(void)
+{
+	return i2c_bit_au1x00gpio_init();
+}
+
+void cleanup_module(void)
+{
+	i2c_bit_au1x00gpio_exit();
+}
+#endif
diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Makefile linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Makefile
--- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Makefile	2004-12-13 18:03:18.000000000 +0100
+++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Makefile	2004-12-13 18:11:59.000000000 +0100
@@ -25,6 +25,7 @@
 obj-$(CONFIG_I2C_ALGO_SIBYTE)	+= i2c-algo-sibyte.o i2c-sibyte.o
 obj-$(CONFIG_I2C_MAX1617)	+= i2c-max1617.o
 obj-$(CONFIG_I2C_ALGO_SGI)	+= i2c-algo-sgi.o
+obj-$(CONFIG_I2C_AU1X00GPIO)	+= i2c-au1x00gpio.o
 obj-$(CONFIG_I2C_ALGO_AU1550)	+= i2c-algo-au1550.o i2c-au1550.o
 
 # This is needed for automatic patch generation: sensors code starts here
--- linux-2.4.27-mtx1-lm_sensors-2.8.8/include/linux/i2c-id.h	2004-12-13 21:09:52.000000000 +0100
+++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/include/linux/i2c-id.h	2004-12-13 21:36:14.000000000 +0100
@@ -242,6 +242,7 @@
 #define I2C_HW_B_S3VIA	0x18	/* S3Via ProSavage adapter		*/
 #define I2C_HW_B_ZR36067 0x19	/* Zoran-36057/36067 based boards	*/
 #define I2C_HW_B_PCILYNX 0x1a	/* TI PCILynx I2C adapter		*/
+#define I2C_HW_B_AU1x00GPIO 0x1b /* Au1x00 GPIO adapter                 */
 
 /* --- PCF 8584 based algorithms					*/
 #define I2C_HW_P_LP	0x00	/* Parallel port interface		*/