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