]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-mtx-1-2.4.27/18-i2c-au1x00gpio.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-mtx-1-2.4.27 / 18-i2c-au1x00gpio.patch
1 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
2 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Config.in    2004-12-13 18:03:18.000000000 +0100
3 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Config.in      2004-12-13 18:11:02.000000000 +0100
4 @@ -17,6 +17,11 @@
5           int  '    GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
6           int  '    GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
7        fi
8 +      dep_tristate '  I2C using Au1x00 GPIO pins' CONFIG_I2C_AU1X00GPIO $CONFIG_I2C_ALGOBIT
9 +      if [ "$CONFIG_I2C_AU1X00GPIO" != "n" ]; then
10 +         int  '    GPIO pin used for SCL' CONFIG_I2C_AU1X00GPIO_SCL 206
11 +         int  '    GPIO pin used for SDA' CONFIG_I2C_AU1X00GPIO_SDA 207
12 +      fi
13     fi
14  
15     dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
16 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
17 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/i2c-au1x00gpio.c     1970-01-01 01:00:00.000000000 +0100
18 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/i2c-au1x00gpio.c       2004-12-13 18:12:50.000000000 +0100
19 @@ -0,0 +1,426 @@
20 +/* ------------------------------------------------------------------------- */
21 +/* i2c-au1x00gpio.c i2c-hw access for Au1x00 GPIO pins.                      */
22 +/* ------------------------------------------------------------------------- */
23 +/*   Copyright (C) 1995-2000 Michael Stickel
24 +
25 +    This program is free software; you can redistribute it and/or modify
26 +    it under the terms of the GNU General Public License as published by
27 +    the Free Software Foundation; either version 2 of the License, or
28 +    (at your option) any later version.
29 +
30 +    This program is distributed in the hope that it will be useful,
31 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
32 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 +    GNU General Public License for more details.
34 +
35 +    You should have received a copy of the GNU General Public License
36 +    along with this program; if not, write to the Free Software
37 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
38 +/* ------------------------------------------------------------------------- */ 
39 +
40 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
41 +   Frodo Looijaard <frodol@dds.nl>
42 +   Simon G. Vogl
43 +*/
44 +
45 +/* $Id: i2c-au1x00gpio.c,v 1.1.1.2 2004/01/22 15:35:47 br1 Exp $ */
46 +
47 +#include <linux/module.h>
48 +#include <linux/config.h>
49 +#include <linux/types.h>
50 +#include <linux/kernel.h>
51 +#include <linux/init.h>
52 +#include <linux/stddef.h>
53 +#include <linux/ioport.h>
54 +#include <asm/uaccess.h>
55 +#include <asm/io.h>
56 +#include <asm/au1000.h>
57 +#include <asm/au1000_gpio.h>
58 +
59 +#include <linux/slab.h>
60 +#include <linux/mm.h>
61 +
62 +#include <linux/i2c.h>
63 +#include <linux/i2c-algo-bit.h>
64 +
65 +#ifndef __exit
66 +#define __exit __init
67 +#endif
68 +
69 +
70 +struct i2c_au1x00gpio
71 +{
72 +       struct i2c_au1x00gpio *next;
73 +
74 +       short  scl_gpio;
75 +       short  sda_gpio;
76 +
77 +       unsigned long scl_mask;
78 +       unsigned long sda_mask;
79 +
80 +       struct i2c_adapter adapter;
81 +       struct i2c_algo_bit_data bit_au1x00gpio_data;
82 +};
83 +
84 +static struct i2c_au1x00gpio *adapter_list;
85 +
86 +
87 +
88 +/* ----- global defines -----------------------------------------------        */
89 +#define DEB(x)         /* should be reasonable open, close &c.         */
90 +#define DEB2(x)        /* low level debugging - very slow              */
91 +#define DEBE(x)        x       /* error messages                               */
92 +
93 +/* ----- printer port defines ------------------------------------------*/
94 +
95 +/* ----- local functions ----------------------------------------------        */
96 +
97 +
98 +//-- Primary GPIO
99 +static void bit_au1x00gpio_setscl(void *data, int state)
100 +{
101 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
102 +  if (state)
103 +    au_writel(adapter->scl_mask, SYS_TRIOUTCLR); // Disable Driver: Switch off Transistor => 1
104 +  else
105 +    au_writel(adapter->scl_mask, SYS_OUTPUTCLR); // Clear Output and switch on Transistor => 0
106 +}
107 +
108 +
109 +static void bit_au1x00gpio_setsda(void *data, int state)
110 +{
111 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
112 +  if (state)
113 +    au_writel(adapter->sda_mask, SYS_TRIOUTCLR);
114 +  else
115 +    au_writel(adapter->sda_mask, SYS_OUTPUTCLR);
116 +}
117 +
118 +
119 +static int bit_au1x00gpio_getscl(void *data)
120 +{
121 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
122 +  return (au_readl(SYS_PINSTATERD) & adapter->scl_mask) ? 1 : 0;
123 +}
124 +
125 +
126 +static int bit_au1x00gpio_getsda(void *data)
127 +{
128 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
129 +  return (au_readl(SYS_PINSTATERD) & adapter->sda_mask) ? 1 : 0;
130 +}
131 +
132 +
133 +
134 +
135 +/*--
136 + *-- Functions for accessing GPIO-2
137 + *--
138 + */
139 +static void bit_au1x00gpio2_setscl(void *data, int state)
140 +{
141 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
142 +  if (state)
143 +    {
144 +      au_writel(au_readl(GPIO2_DIR) & ~adapter->scl_mask, GPIO2_DIR);
145 +    }
146 +  else
147 +    {
148 +      au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->scl_mask, GPIO2_OUTPUT);
149 +      au_writel(au_readl(GPIO2_DIR) | adapter->scl_mask, GPIO2_DIR);
150 +    }
151 +}
152 +
153 +static void bit_au1x00gpio2_setsda(void *data, int state)
154 +{
155 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
156 +  if (state)
157 +    {
158 +      au_writel(au_readl(GPIO2_DIR) & ~adapter->sda_mask, GPIO2_DIR);
159 +    }
160 +  else
161 +    {
162 +      au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->sda_mask, GPIO2_OUTPUT);
163 +      au_writel(au_readl(GPIO2_DIR) | adapter->sda_mask, GPIO2_DIR);
164 +    }
165 +}
166 +
167 +static int bit_au1x00gpio2_getscl(void *data)
168 +{
169 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
170 +  return (au_readl(GPIO2_PINSTATE) & adapter->scl_mask) ? 1 : 0;
171 +}
172 +
173 +static int bit_au1x00gpio2_getsda(void *data)
174 +{
175 +  struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
176 +  return (au_readl(GPIO2_PINSTATE) & adapter->sda_mask) ? 1 : 0;
177 +}
178 +
179 +
180 +
181 +static int check_i2c_au1x00gpio_adapter(struct i2c_au1x00gpio *adapter)
182 +{
183 +  int state = 0;
184 +
185 +  adapter->bit_au1x00gpio_data.setsda (adapter, 1);
186 +  adapter->bit_au1x00gpio_data.setscl (adapter, 1);
187 +
188 +  if (adapter->bit_au1x00gpio_data.getsda(adapter)==0)
189 +    {
190 +      printk ("i2c-au1x00gpio: sda line should read 1 but reads 0\n");
191 +      state = -1;
192 +    }
193 +  if (adapter->bit_au1x00gpio_data.getscl(adapter)==0)
194 +    {
195 +      printk ("i2c-au1x00gpio: scl line should read 1 but reads 0\n");
196 +      state = -1;
197 +    }
198 +
199 +
200 +  adapter->bit_au1x00gpio_data.setsda (adapter, 0);
201 +  adapter->bit_au1x00gpio_data.setscl (adapter, 0);
202 +
203 +  if (adapter->bit_au1x00gpio_data.getsda(adapter)==1)
204 +    {
205 +      printk ("i2c-au1x00gpio: sda line should read 0 but reads 1\n");
206 +      state = -1;
207 +    }
208 +  if (adapter->bit_au1x00gpio_data.getscl(adapter)==1)
209 +    {
210 +      printk ("i2c-au1x00gpio: scl line should read 0 but reads 1\n");
211 +      state = -1;
212 +    }
213 +
214 +  if (state==0)
215 +    printk ("i2c-au1x00gpio: adapter with scl=GPIO%d,sda=GPIO%d is working\n",
216 +           adapter->scl_gpio, adapter->sda_gpio
217 +           );
218 +  return state;
219 +}
220 +
221 +
222 +
223 +#if 0
224 +static int bit_au1x00gpio_reg(struct i2c_client *client)
225 +{
226 +       return 0;
227 +}
228 +
229 +static int bit_au1x00gpio_unreg(struct i2c_client *client)
230 +{
231 +       return 0;
232 +}
233 +
234 +static void bit_au1x00gpio_inc_use(struct i2c_adapter *adap)
235 +{
236 +       MOD_INC_USE_COUNT;
237 +}
238 +
239 +static void bit_au1x00gpio_dec_use(struct i2c_adapter *adap)
240 +{
241 +       MOD_DEC_USE_COUNT;
242 +}
243 +#endif
244
245 +
246 +
247 +static struct i2c_algo_bit_data bit_au1x00gpio_data = {
248 +       .setsda = bit_au1x00gpio_setsda,
249 +       .setscl = bit_au1x00gpio_setscl,
250 +       .getsda = bit_au1x00gpio_getsda,
251 +       .getscl = bit_au1x00gpio_getscl,
252 +       .udelay = 80,
253 +       .mdelay = 80,
254 +       .timeout = HZ
255 +}; 
256 +
257 +
258 +static struct i2c_adapter bit_au1x00gpio_ops = {
259 +        .owner          = THIS_MODULE,
260 +        .name           = "Au1x00 GPIO I2C adapter",
261 +        .id             = I2C_HW_B_AU1x00GPIO,
262 +};
263 +
264 +
265 +
266 +/*
267 + * scl_gpio:
268 + *   0..31 for primary GPIO's
269 + *   200..215 for secondary GPIO's
270 + *
271 + * sda_gpio:
272 + *   0..31 for primary GPIO's
273 + *   200..215 for secondary GPIO's
274 + *
275 + * You can even mix primary and secondary GPIO's.
276 + * E.g.:  i2c_au1x00gpio_create(4,206);
277 + */
278 +
279 +static int i2c_au1x00gpio_create (int scl_gpio, int sda_gpio)
280 +{
281 +  if ((scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)) &&
282 +      (scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)))
283 +    {
284 +       struct i2c_au1x00gpio *adapter = kmalloc(sizeof(struct i2c_au1x00gpio),
285 +                                         GFP_KERNEL);
286 +       if (!adapter) {
287 +               printk(KERN_ERR "i2c-au1x00-gpio: Unable to malloc.\n");
288 +               return -1;
289 +       }
290 +
291 +       printk(KERN_DEBUG "i2c-au1x00-gpio.o: attaching to SCL=GPIO%d, SDA=GPIO%d\n",
292 +              scl_gpio, sda_gpio);
293 +
294 +       memset (adapter, 0, sizeof(struct i2c_au1x00gpio));
295 +
296 +       adapter->adapter = bit_au1x00gpio_ops;
297 +
298 +       adapter->adapter.algo_data = &adapter->bit_au1x00gpio_data;
299 +       adapter->bit_au1x00gpio_data = bit_au1x00gpio_data;
300 +       adapter->bit_au1x00gpio_data.data = adapter;
301 +
302 +       adapter->bit_au1x00gpio_data.data = adapter;
303 +
304 +       adapter->scl_gpio = scl_gpio;
305 +       adapter->sda_gpio = sda_gpio;
306 +
307 +        if (sda_gpio < 32)
308 +          {
309 +           adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio_setsda;
310 +           adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio_getsda;
311 +            adapter->sda_mask = 1<<sda_gpio;
312 +          }
313 +        else if (sda_gpio >= 200 && sda_gpio <= 215)
314 +          {
315 +           adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio2_setsda;
316 +           adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio2_getsda;
317 +            adapter->sda_mask = 1<<(sda_gpio-200);
318 +          }
319 +
320 +
321 +        if (scl_gpio < 32)
322 +          {
323 +           adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio_setscl;
324 +           adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio_getscl;
325 +            adapter->scl_mask = 1<<scl_gpio;
326 +          }
327 +        else if (scl_gpio >= 200 && scl_gpio <= 215)
328 +          {
329 +           adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio2_setscl;
330 +           adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio2_getscl;
331 +            adapter->scl_mask = 1<<(scl_gpio-200);
332 +          }
333 +
334 +       au_writel(0L, SYS_PININPUTEN);
335 +       if (check_i2c_au1x00gpio_adapter(adapter)==0)
336 +         {
337 +           adapter->bit_au1x00gpio_data.setsda (adapter, 1);
338 +           adapter->bit_au1x00gpio_data.setscl (adapter, 1);
339 +
340 +           if (i2c_bit_add_bus(&adapter->adapter) < 0)
341 +             {
342 +               printk(KERN_ERR "i2c-au1x00-gpio: Unable to register with I2C.\n");
343 +               kfree(adapter);
344 +               return -1;              /* No good */
345 +             }
346 +           
347 +           adapter->next = adapter_list;
348 +           adapter_list = adapter;
349 +           return 0;
350 +         }
351 +    }
352 +  else
353 +    printk(KERN_ERR "i2c-au1x00-gpio: Invalid argument scl_gpio=%d, sda_gpio=%d.\n", scl_gpio, sda_gpio);
354 +  return -1;
355 +}
356 +
357 +
358 +
359 +static void i2c_au1x00gpio_delete (int scl_gpio, int sda_gpio)
360 +{
361 +       struct i2c_au1x00gpio *adapter, *prev = NULL;
362 +
363 +       for (adapter = adapter_list; adapter; adapter = adapter->next)
364 +       {
365 +               if (adapter->scl_gpio == scl_gpio &&
366 +                   adapter->sda_gpio == sda_gpio)
367 +               {
368 +                       i2c_bit_del_bus(&adapter->adapter);
369 +                       if (prev)
370 +                               prev->next = adapter->next;
371 +                       else
372 +                               adapter_list = adapter->next;
373 +                       kfree(adapter);
374 +                       return;
375 +               }
376 +               prev = adapter;
377 +       }
378 +}
379 +
380 +
381 +
382 +
383 +
384 +#ifndef CONFIG_I2C_AU1X00GPIO_SCL
385 +#define CONFIG_I2C_AU1X00GPIO_SCL (216)
386 +#endif
387 +
388 +#ifndef CONFIG_I2C_AU1X00GPIO_SDA
389 +#define CONFIG_I2C_AU1X00GPIO_SDA (217)
390 +#endif
391 +
392 +static int au1x00gpiopin_scl = CONFIG_I2C_AU1X00GPIO_SCL;
393 +static int au1x00gpiopin_sda = CONFIG_I2C_AU1X00GPIO_SDA;
394 +
395 +
396 +
397 +int __init i2c_bit_au1x00gpio_init(void)
398 +{
399 +  printk(KERN_INFO "i2c-au1x00gpio.o: i2c Au1x00 GPIO adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
400 +
401 +  if (i2c_au1x00gpio_create (au1x00gpiopin_scl, au1x00gpiopin_sda) == 0)
402 +    {
403 +      printk(KERN_INFO "i2c-au1x00gpio.o: registered I2C-Bus for GPIO%d,GPIO%d\n",
404 +            au1x00gpiopin_scl, au1x00gpiopin_sda
405 +            );
406 +      return 0;
407 +    }
408 +  printk(KERN_INFO "i2c-au1x00gpio.o: failed to register I2C-Bus for GPIO%d,GPIO%d\n",
409 +            au1x00gpiopin_scl, au1x00gpiopin_sda
410 +        );
411 +  return -1;
412 +}
413 +
414 +
415 +void __exit i2c_bit_au1x00gpio_exit(void)
416 +{
417 +  i2c_au1x00gpio_delete (au1x00gpiopin_scl, au1x00gpiopin_sda);
418 +}
419 +
420 +
421 +
422 +EXPORT_NO_SYMBOLS;
423 +
424 +MODULE_PARM(au1x00gpiopin_scl, "i");
425 +MODULE_PARM_DESC(au1x00gpiopin_scl, "GPIO pin number used for SCL pin.");
426 +
427 +MODULE_PARM(au1x00gpiopin_sda, "i");
428 +MODULE_PARM_DESC(au1x00gpiopin_sda, "GPIO pin number used for SDA pin.");
429 +
430 +MODULE_AUTHOR("Michael Stickel <michael@cubic.org>");
431 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Au1x00 GPIO adapter.");
432 +MODULE_LICENSE("GPL");
433 +
434 +
435 +#ifdef MODULE
436 +int init_module(void)
437 +{
438 +       return i2c_bit_au1x00gpio_init();
439 +}
440 +
441 +void cleanup_module(void)
442 +{
443 +       i2c_bit_au1x00gpio_exit();
444 +}
445 +#endif
446 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
447 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Makefile     2004-12-13 18:03:18.000000000 +0100
448 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Makefile       2004-12-13 18:11:59.000000000 +0100
449 @@ -25,6 +25,7 @@
450  obj-$(CONFIG_I2C_ALGO_SIBYTE)  += i2c-algo-sibyte.o i2c-sibyte.o
451  obj-$(CONFIG_I2C_MAX1617)      += i2c-max1617.o
452  obj-$(CONFIG_I2C_ALGO_SGI)     += i2c-algo-sgi.o
453 +obj-$(CONFIG_I2C_AU1X00GPIO)   += i2c-au1x00gpio.o
454  obj-$(CONFIG_I2C_ALGO_AU1550)  += i2c-algo-au1550.o i2c-au1550.o
455  
456  # This is needed for automatic patch generation: sensors code starts here
457 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/include/linux/i2c-id.h   2004-12-13 21:09:52.000000000 +0100
458 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/include/linux/i2c-id.h     2004-12-13 21:36:14.000000000 +0100
459 @@ -242,6 +242,7 @@
460  #define I2C_HW_B_S3VIA 0x18    /* S3Via ProSavage adapter              */
461  #define I2C_HW_B_ZR36067 0x19  /* Zoran-36057/36067 based boards       */
462  #define I2C_HW_B_PCILYNX 0x1a  /* TI PCILynx I2C adapter               */
463 +#define I2C_HW_B_AU1x00GPIO 0x1b /* Au1x00 GPIO adapter                 */
464  
465  /* --- PCF 8584 based algorithms                                       */
466  #define I2C_HW_P_LP    0x00    /* Parallel port interface              */