]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.25-i2c-2.8.3-1.patch
- obsolete
[packages/kernel.git] / linux-2.4.25-i2c-2.8.3-1.patch
1 diff -urN linux-2.4.24.org/Documentation/Configure.help linux-2.4.24/Documentation/Configure.help
2 --- linux-2.4.24.org/Documentation/Configure.help       2004-02-04 22:35:48.287889651 +0100
3 +++ linux-2.4.24/Documentation/Configure.help   2004-02-04 22:36:36.607840921 +0100
4 @@ -20127,6 +20127,16 @@
5    <file:Documentation/modules.txt>.
6    The module will be called i2c-velleman.o.
7  
8 +Basic I2C on Parallel Port adapter
9 +CONFIG_I2C_PPORT
10 +  This supports directly connecting I2C devices to the parallel port.
11 +  See <file:Documentation/i2c/i2c-pport> for more information.
12 +
13 +  This driver is also available as a module.  If you want to compile
14 +  it as a module, say M here and read
15 +  <file:Documentation/modules.txt>.
16 +  The module will be called i2c-pport.o.
17 +
18  I2C PCF 8584 interfaces
19  CONFIG_I2C_ALGOPCF
20    This allows you to use a range of I2C adapters called PCF adapters.
21 @@ -20148,6 +20158,15 @@
22    <file:Documentation/modules.txt>.
23    The module will be called i2c-elektor.o.
24  
25 +PCF on the EPP Parallel Port
26 +CONFIG_I2C_PCFEPP
27 +  This supports the PCF8584 connected to the parallel port.
28 +
29 +  This driver is also available as a module.  If you want to compile
30 +  it as a module, say M here and read
31 +  <file:Documentation/modules.txt>.
32 +  The module will be called i2c-pcf-epp.o.
33 +
34  ITE I2C Algorithm
35  CONFIG_ITE_I2C_ALGO
36    This supports the use the ITE8172 I2C interface found on some MIPS
37 @@ -20185,6 +20204,51 @@
38    Supports the SGI interfaces like the ones found on SGI Indy VINO
39    or SGI O2 MACE.
40  
41 +Motorola 8xx I2C algorithm
42 +CONFIG_I2C_ALGO8XX
43 +  This is the algorithm that allows you to use Motorola 8xx I2C adapters.
44 +
45 +  This driver is also available as a module.  If you want to compile
46 +  it as a module, say M here and read
47 +  <file:Documentation/modules.txt>.
48 +  The module will be called i2c-algo-8xx.o.
49 +
50 +Motorola 8xx I2C interface
51 +CONFIG_I2C_RPXLITE
52 +  This supports the Motorola 8xx I2C device.
53 +
54 +  This driver is also available as a module.  If you want to compile
55 +  it as a module, say M here and read
56 +  <file:Documentation/modules.txt>.
57 +  The module will be called i2c-rpx.o.
58 +
59 +IBM 405 I2C algorithm
60 +CONFIG_I2C_IBM_OCP_ALGO
61 +  This is the algorithm that allows you to use IBM 405 I2C adapters.
62 +
63 +  This driver is also available as a module.  If you want to compile
64 +  it as a module, say M here and read
65 +  <file:Documentation/modules.txt>.
66 +  The module will be called i2c-algo-ibm_ocp.o.
67 +
68 +IBM 405 I2C interface
69 +CONFIG_I2C_IBM_OCP_ADAP
70 +  This supports the IBM 405 I2C device.
71 +
72 +  This driver is also available as a module.  If you want to compile
73 +  it as a module, say M here and read
74 +  <file:Documentation/modules.txt>.
75 +  The module will be called i2c-adap-ibm_ocp.o.
76 +
77 +StrongARM SA-1110 interface
78 +CONFIG_I2C_FRODO
79 +  This supports the StrongARM SA-1110 Development Board.
80 +
81 +  This driver is also available as a module.  If you want to compile
82 +  it as a module, say M here and read
83 +  <file:Documentation/modules.txt>.
84 +  The module will be called i2c-frodo.o.
85 +
86  I2C device interface
87  CONFIG_I2C_CHARDEV
88    Say Y here to use i2c-* device files, usually found in the /dev
89 diff -urN linux-2.4.24.org/Documentation/i2c/dev-interface linux-2.4.24/Documentation/i2c/dev-interface
90 --- linux-2.4.24.org/Documentation/i2c/dev-interface    2004-02-04 22:35:46.529255353 +0100
91 +++ linux-2.4.24/Documentation/i2c/dev-interface        2004-02-04 22:36:36.612839881 +0100
92 @@ -89,6 +89,11 @@
93    Selects ten bit addresses if select not equals 0, selects normal 7 bit
94    addresses if select equals 0. Default 0.
95  
96 +ioctl(file,I2C_PEC,long select)
97 +  Selects SMBus PEC (packet error checking) generation and verification
98 +  if select not equals 0, disables if select equals 0. Default 0.
99 +  Used only for SMBus transactions.
100 +
101  ioctl(file,I2C_FUNCS,unsigned long *funcs)
102    Gets the adapter functionality and puts it in *funcs.
103  
104 diff -urN linux-2.4.24.org/Documentation/i2c/i2c-pport linux-2.4.24/Documentation/i2c/i2c-pport
105 --- linux-2.4.24.org/Documentation/i2c/i2c-pport        1970-01-01 01:00:00.000000000 +0100
106 +++ linux-2.4.24/Documentation/i2c/i2c-pport    2004-02-04 22:36:36.619838425 +0100
107 @@ -0,0 +1,67 @@
108 +Parallel Port Adapters
109 +----------------------
110 +If you are installing parallel port adapters it means you are probably messing 
111 +around with wires and IC's and the like. If you have purchased a card that 
112 +provides an external i2c/smbus this will require combined algorithm and 
113 +adapter code in a single module.
114 +If you are doing it yourself by using the parallel port there 
115 +are basically 2 options.
116 +
117 +1) Using the parallel port and using the i2c-pport adapter module and the 
118 +i2c-algo-bit algorithm module together to enable you to wire up your parallel 
119 +port to act as an i2c/smbus. This provides a bus that will enable most 
120 +sensors to work but doesn't support the entire i2c/smbus capability.
121 +
122 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c 
123 +adapter chip. You will need to build a bit of a circuit to do this. This 
124 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf 
125 +algorithm module. This support almost all of the i2c/smbus capabilities.
126 +
127 +
128 +i2c-pport Documentation
129 +-----------------------
130 +This is a primitive parallel port driver for the i2c bus, which exploits 
131 +features of modern bidirectional parallel ports. 
132 +
133 +Bidirectional ports have particular bits connected in following way:
134 +   
135 +                        |
136 +            /-----|     R
137 +         --o|     |-----|
138 +      read  \-----|     /------- Out pin
139 +                      |/
140 +                   - -|\
141 +                write   V
142 +                        |
143 +                       ---  
144 +
145 +
146 +It means when output is set to 1 we can read the port. Therefore 
147 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It 
148 +is not necessary to add any external - additional parts, we can 
149 +read and write the same port simultaneously.
150 +       I only use register base+2 so it is possible to use all 
151 +8 data bits of parallel port for other applications (I have 
152 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
153 + Port. The only disadvantage is we can only support 5V chips.
154 +
155 +Layout:
156 +
157 +Cannon 25 pin
158 +
159 +SDA - connect to pin 14 (Auto Linefeed)
160 +SCL - connect to pin 16 (Initialize Printer)
161 +GND - connect to pin 18-25
162 ++5V - use external supply (I use 5V from 3.5" floppy connector)
163 +      
164 +no pullups  requied
165 +
166 +Module parameters:
167 +
168 +base = 0xXXX
169 +XXX - 278 or 378
170 +
171 +That's all.
172 +
173 +Daniel Smolik
174 +marvin@sitour.cz
175 diff -urN linux-2.4.24.org/Documentation/i2c/i2c-protocol linux-2.4.24/Documentation/i2c/i2c-protocol
176 --- linux-2.4.24.org/Documentation/i2c/i2c-protocol     2004-02-04 22:35:46.532254730 +0100
177 +++ linux-2.4.24/Documentation/i2c/i2c-protocol 2004-02-04 22:36:36.621838010 +0100
178 @@ -65,3 +65,12 @@
179      need to emit an Rd instead of a Wr, or vice versa, you set this
180      flag. For example:
181        S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
182 +
183 +  Flags I2C_M_IGNORE_NAK
184 +    Normally message is interrupted immediately if there is [NA] from the
185 +    client. Setting this flag treats any [NA] asĀ [A], and all of
186 +    message is sent.
187 +    These messages may still fail to SCL lo->hi timeout.
188 +
189 +  Flags I2C_M_NO_RD_ACK
190 +    In a read message, master A/NA bit is skipped.
191 diff -urN linux-2.4.24.org/Documentation/i2c/summary linux-2.4.24/Documentation/i2c/summary
192 --- linux-2.4.24.org/Documentation/i2c/summary  2004-02-04 22:35:46.582244335 +0100
193 +++ linux-2.4.24/Documentation/i2c/summary      2004-02-04 22:36:36.624837386 +0100
194 @@ -59,16 +59,16 @@
195  i2c-algo-8xx:    An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
196  i2c-algo-bit:    A bit-banging algorithm
197  i2c-algo-pcf:    A PCF 8584 style algorithm
198 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
199 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
200  
201  Adapter drivers
202  ---------------
203  
204  i2c-elektor:     Elektor ISA card (uses i2c-algo-pcf)
205  i2c-elv:         ELV parallel port adapter (uses i2c-algo-bit)
206 -i2c-pcf-epp:     PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
207 +i2c-pcf-epp:     PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
208  i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
209 -i2c-ppc405:      IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
210 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
211  i2c-pport:       Primitive parallel port adapter (uses i2c-algo-bit)
212  i2c-rpx:         RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
213  i2c-velleman:    Velleman K8000 parallel port adapter (uses i2c-algo-bit)
214 diff -urN linux-2.4.24.org/Documentation/i2c/writing-clients linux-2.4.24/Documentation/i2c/writing-clients
215 --- linux-2.4.24.org/Documentation/i2c/writing-clients  2004-02-04 22:35:46.605239553 +0100
216 +++ linux-2.4.24/Documentation/i2c/writing-clients      2004-02-04 22:36:36.629836346 +0100
217 @@ -24,16 +24,14 @@
218  routines, a client structure specific information like the actual I2C
219  address.
220  
221 -  struct i2c_driver foo_driver
222 -  {  
223 -    /* name           */  "Foo version 2.3 and later driver",
224 -    /* id             */  I2C_DRIVERID_FOO,
225 -    /* flags          */  I2C_DF_NOTIFY,
226 -    /* attach_adapter */  &foo_attach_adapter,
227 -    /* detach_client  */  &foo_detach_client,
228 -    /* command        */  &foo_command,   /* May be NULL */
229 -    /* inc_use        */  &foo_inc_use,   /* May be NULL */
230 -    /* dec_use        */  &foo_dec_use    /* May be NULL */
231 +  static struct i2c_driver foo_driver = {
232 +    .owner          = THIS_MODULE,
233 +    .name           = "Foo version 2.3 driver",
234 +    .id             = I2C_DRIVERID_FOO, /* usually from i2c-id.h */
235 +    .flags          = I2C_DF_NOTIFY,
236 +    .attach_adapter = &foo_attach_adapter,
237 +    .detach_client  = &foo_detach_client,
238 +    .command        = &foo_command /* may be NULL */
239    }
240   
241  The name can be chosen freely, and may be upto 40 characters long. Please
242 @@ -50,43 +48,8 @@
243  All other fields are for call-back functions which will be explained 
244  below.
245  
246 -
247 -Module usage count
248 -==================
249 -
250 -If your driver can also be compiled as a module, there are moments at 
251 -which the module can not be removed from memory. For example, when you
252 -are doing a lengthy transaction, or when you create a /proc directory,
253 -and some process has entered that directory (this last case is the
254 -main reason why these call-backs were introduced).
255 -
256 -To increase or decrease the module usage count, you can use the
257 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
258 -which needs to get its usage count changed; that is why each driver
259 -module has to implement its own callback.
260 -
261 -  void foo_inc_use (struct i2c_client *client)
262 -  {
263 -  #ifdef MODULE
264 -    MOD_INC_USE_COUNT;
265 -  #endif
266 -  }
267 -
268 -  void foo_dec_use (struct i2c_client *client)
269 -  {
270 -  #ifdef MODULE
271 -    MOD_DEC_USE_COUNT;
272 -  #endif
273 -  }
274 -
275 -Do not call these call-back functions directly; instead, use one of the
276 -following functions defined in i2c.h:
277 -  void i2c_inc_use_client(struct i2c_client *);
278 -  void i2c_dec_use_client(struct i2c_client *);
279 -
280 -You should *not* increase the module count just because a device is
281 -detected and a client created. This would make it impossible to remove
282 -an adapter driver! 
283 +There use to be two additional fields in this structure, inc_use et dec_use,
284 +for module usage count, but these fields were obsoleted and removed.
285  
286  
287  Extra client data
288 diff -urN linux-2.4.24.org/drivers/i2c/i2c-adap-ibm_ocp.c linux-2.4.24/drivers/i2c/i2c-adap-ibm_ocp.c
289 --- linux-2.4.24.org/drivers/i2c/i2c-adap-ibm_ocp.c     1970-01-01 01:00:00.000000000 +0100
290 +++ linux-2.4.24/drivers/i2c/i2c-adap-ibm_ocp.c 2004-02-04 22:36:36.635835098 +0100
291 @@ -0,0 +1,346 @@
292 +/*
293 +   -------------------------------------------------------------------------
294 +   i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
295 +   -------------------------------------------------------------------------
296 +  
297 +   Ian DaSilva, MontaVista Software, Inc.
298 +   idasilva@mvista.com or source@mvista.com
299 +
300 +   Copyright 2000 MontaVista Software Inc.
301 +
302 +   Changes made to support the IIC peripheral on the IBM PPC 405 
303 +
304 +
305 +   ----------------------------------------------------------------------------
306 +   This file was highly leveraged from i2c-elektor.c, which was created
307 +   by Simon G. Vogl and Hans Berglund:
308 +
309
310 +     Copyright (C) 1995-97 Simon G. Vogl
311 +                   1998-99 Hans Berglund
312 +
313 +   With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
314 +   Frodo Looijaard <frodol@dds.nl>
315 +
316 +
317 +    This program is free software; you can redistribute it and/or modify
318 +    it under the terms of the GNU General Public License as published by
319 +    the Free Software Foundation; either version 2 of the License, or
320 +    (at your option) any later version.
321 +
322 +    This program is distributed in the hope that it will be useful,
323 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
324 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
325 +    GNU General Public License for more details.
326 +
327 +    You should have received a copy of the GNU General Public License
328 +    along with this program; if not, write to the Free Software
329 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
330 +   ----------------------------------------------------------------------------
331 +
332 +   History: 01/20/12 - Armin
333 +       akuster@mvista.com
334 +       ported up to 2.4.16+    
335 +
336 +   Version 02/03/25 - Armin
337 +       converted to ocp format
338 +       removed commented out or #if 0 code
339 +
340 +   TODO: convert to ocp_register
341 +         add PM hooks
342 +
343 +*/
344 +
345 +
346 +#include <linux/kernel.h>
347 +#include <linux/ioport.h>
348 +#include <linux/module.h>
349 +#include <linux/delay.h>
350 +#include <linux/slab.h>
351 +#include <linux/init.h>
352 +#include <linux/i2c.h>
353 +#include <linux/i2c-algo-ibm_ocp.h>
354 +#include <asm/irq.h>
355 +#include <asm/io.h>
356 +#include <asm/ocp.h>
357 +
358 +/*
359 + * This next section is configurable, and it is used to set the number
360 + * of i2c controllers in the system.  The default number of instances is 1,
361 + * however, this should be changed to reflect your system's configuration.
362 + */ 
363 +
364 +/*
365 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
366 + */
367 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
368 +extern iic_t *IIC_ADDR[];
369 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
370 +
371 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
372 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
373 +
374 +static int i2c_debug=0;
375 +static wait_queue_head_t iic_wait[IIC_NUMS];
376 +static int iic_pending;
377 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
378 +
379 +
380 +/* ----- global defines -----------------------------------------------        */
381 +#define DEB(x) if (i2c_debug>=1) x
382 +#define DEB2(x) if (i2c_debug>=2) x
383 +#define DEB3(x) if (i2c_debug>=3) x
384 +#define DEBE(x)        x       /* error messages                               */
385 +
386 +/* ----- local functions ----------------------------------------------        */
387 +
388 +//
389 +// Description: Write a byte to IIC hardware
390 +//
391 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
392 +{
393 +   // writeb resolves to a write to the specified memory location
394 +   // plus a call to eieio.  eieio ensures that all instructions
395 +   // preceding it are completed before any further stores are
396 +   // completed.
397 +   // Delays at this level (to protect writes) are not needed here.
398 +   writeb(val, ctl);
399 +}
400 +
401 +
402 +//
403 +// Description: Read a byte from IIC hardware
404 +//
405 +static int iic_ibmocp_getbyte(void *data, int ctl)
406 +{
407 +   int val;
408 +
409 +   val = readb(ctl);
410 +   return (val);
411 +}
412 +
413 +
414 +//
415 +// Description: Return our slave address.  This is the address
416 +// put on the I2C bus when another master on the bus wants to address us
417 +// as a slave
418 +//
419 +static int iic_ibmocp_getown(void *data)
420 +{
421 +   return(((struct iic_ibm *)(data))->iic_own);
422 +}
423 +
424 +
425 +//
426 +// Description: Return the clock rate
427 +//
428 +static int iic_ibmocp_getclock(void *data)
429 +{
430 +   return(((struct iic_ibm *)(data))->iic_clock);
431 +}
432 +
433 +
434 +
435 +//
436 +// Description:  Put this process to sleep.  We will wake up when the
437 +// IIC controller interrupts.
438 +//
439 +static void iic_ibmocp_waitforpin(void *data) {
440 +
441 +   int timeout = 2;
442 +   struct iic_ibm *priv_data = data;
443 +
444 +   //
445 +   // If interrupts are enabled (which they are), then put the process to
446 +   // sleep.  This process will be awakened by two events -- either the
447 +   // the IIC peripheral interrupts or the timeout expires. 
448 +   //
449 +   if (priv_data->iic_irq > 0) {
450 +      spin_lock_irq(&irq_driver_lock);
451 +      if (iic_pending == 0) {
452 +        interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
453 +      } else
454 +        iic_pending = 0;
455 +      spin_unlock_irq(&irq_driver_lock);
456 +   } else {
457 +      //
458 +      // If interrupts are not enabled then delay for a reasonable amount
459 +      // of time and return.  We expect that by time we return to the calling
460 +      // function that the IIC has finished our requested transaction and
461 +      // the status bit reflects this.
462 +      //
463 +      // udelay is probably not the best choice for this since it is
464 +      // the equivalent of a busy wait
465 +      //
466 +      udelay(100);
467 +   }
468 +   //printk("iic_ibmocp_waitforpin: exitting\n");
469 +}
470 +
471 +
472 +//
473 +// Description: The registered interrupt handler
474 +//
475 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs) 
476 +{
477 +   int ret;
478 +   struct iic_regs *iic;
479 +   struct iic_ibm *priv_data = dev_id;
480 +   iic = (struct iic_regs *) priv_data->iic_base;
481 +   iic_pending = 1;
482 +   DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
483 +   // Read status register
484 +   ret = readb((int) &(iic->sts));
485 +   DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
486 +   // Clear status register.  See IBM PPC 405 reference manual for details
487 +   writeb(0x0a, (int) &(iic->sts));
488 +   wake_up_interruptible(&(iic_wait[priv_data->index]));
489 +}
490 +
491 +
492 +//
493 +// Description: This function is very hardware dependent.  First, we lock
494 +// the region of memory where out registers exist.  Next, we request our
495 +// interrupt line and register its associated handler.  Our IIC peripheral
496 +// uses interrupt number 2, as specified by the 405 reference manual.
497 +//
498 +static int iic_hw_resrc_init(int instance)
499 +{
500 +
501 +   DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
502 +   iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
503 +
504 +   DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
505 +
506 +   if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
507 +       
508 +      if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
509 +       0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
510 +         printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
511 +          iic_ibmocp_adaps[instance]->iic_irq);
512 +        iic_ibmocp_adaps[instance]->iic_irq = 0;
513 +      } else {
514 +         DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
515 +      }
516 +   }
517 +   return 0;
518 +}
519 +
520 +
521 +//
522 +// Description: Release irq and memory
523 +//
524 +static void iic_ibmocp_release(void)
525 +{
526 +   int i;
527 +
528 +   for(i=0; i<IIC_NUMS; i++) {
529 +      struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
530 +      if (priv_data->iic_irq > 0) {
531 +         disable_irq(priv_data->iic_irq);
532 +         free_irq(priv_data->iic_irq, 0);
533 +      }
534 +      kfree(iic_ibmocp_data[i]);
535 +      kfree(iic_ibmocp_ops[i]);
536 +   }
537 +}
538 +
539 +
540 +//
541 +// Description: Called when the module is loaded.  This function starts the
542 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
543 +//  algorithm layer and into to the core layer)
544 +//
545 +static int __init iic_ibmocp_init(void) 
546 +{
547 +   int i;
548 +
549 +   printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
550
551 +   for(i=0; i<IIC_NUMS; i++) {
552 +      iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
553 +      if(iic_ibmocp_data[i] == NULL) {
554 +         return -ENOMEM;
555 +      }
556 +      memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
557 +      
558 +      switch (i) {
559 +             case 0:
560 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
561 +             break;
562 +             case 1:
563 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
564 +             break;
565 +      }
566 +      iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
567 +      iic_ibmocp_adaps[i]->iic_own = IIC_OWN; 
568 +      iic_ibmocp_adaps[i]->index = i;
569
570 +      DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
571 +      DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
572 +      DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
573 +      DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
574 +
575 +
576 +      iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i]; 
577 +      iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
578 +      iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
579 +      iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
580 +      iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
581 +      iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
582 +      iic_ibmocp_data[i]->udelay = 80;
583 +      iic_ibmocp_data[i]->mdelay = 80;
584 +      iic_ibmocp_data[i]->timeout = HZ;
585 +      
586 +            iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
587 +      if(iic_ibmocp_ops[i] == NULL) {
588 +         return -ENOMEM;
589 +      }
590 +      memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
591 +      strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
592 +      iic_ibmocp_ops[i]->owner = THIS_MODULE;
593 +      iic_ibmocp_ops[i]->id = I2C_HW_OCP;
594 +      iic_ibmocp_ops[i]->algo = NULL;
595 +      iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
596 +       
597 +      
598 +      init_waitqueue_head(&(iic_wait[i]));
599 +      if (iic_hw_resrc_init(i) == 0) {
600 +         if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
601 +         return -ENODEV;
602 +      } else {
603 +         return -ENODEV;
604 +      }
605 +      DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
606 +   }
607 +   return 0;
608 +}
609 +
610 +
611 +static void __exit iic_ibmocp_exit(void)
612 +{
613 +   int i;
614 +
615 +   for(i=0; i<IIC_NUMS; i++) {
616 +      i2c_ocp_del_bus(iic_ibmocp_ops[i]);
617 +   }
618 +   iic_ibmocp_release();
619 +}
620 +
621 +//
622 +// If modules is NOT defined when this file is compiled, then the MODULE_*
623 +// macros will resolve to nothing
624 +//
625 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
626 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
627 +MODULE_LICENSE("GPL");
628 +
629 +MODULE_PARM(base, "i");
630 +MODULE_PARM(irq, "i");
631 +MODULE_PARM(clock, "i");
632 +MODULE_PARM(own, "i");
633 +MODULE_PARM(i2c_debug,"i");
634 +
635 +
636 +module_init(iic_ibmocp_init);
637 +module_exit(iic_ibmocp_exit); 
638 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-8xx.c linux-2.4.24/drivers/i2c/i2c-algo-8xx.c
639 --- linux-2.4.24.org/drivers/i2c/i2c-algo-8xx.c 1970-01-01 01:00:00.000000000 +0100
640 +++ linux-2.4.24/drivers/i2c/i2c-algo-8xx.c     2004-02-04 22:36:36.640834059 +0100
641 @@ -0,0 +1,616 @@
642 +/*
643 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
644 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
645 + *
646 +    This program is free software; you can redistribute it and/or modify
647 +    it under the terms of the GNU General Public License as published by
648 +    the Free Software Foundation; either version 2 of the License, or
649 +    (at your option) any later version.
650 +
651 +    This program is distributed in the hope that it will be useful,
652 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
653 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
654 +    GNU General Public License for more details.
655 +
656 +    You should have received a copy of the GNU General Public License
657 +    along with this program; if not, write to the Free Software
658 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
659 + *
660 + * moved into proper i2c interface; separated out platform specific 
661 + * parts into i2c-rpx.c
662 + * Brad Parker (brad@heeltoe.com)
663 + */
664 +
665 +// XXX todo
666 +// timeout sleep?
667 +
668 +/* $Id$ */
669 +
670 +#include <linux/kernel.h>
671 +#include <linux/module.h>
672 +#include <linux/delay.h>
673 +#include <linux/slab.h>
674 +#include <linux/init.h>
675 +#include <linux/errno.h>
676 +#include <linux/sched.h>
677 +#include <linux/i2c.h>
678 +#include <linux/i2c-algo-8xx.h>
679 +#include <asm/mpc8xx.h>
680 +#include <asm/commproc.h>
681 +
682 +
683 +#define CPM_MAX_READ   513
684 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
685 +static wait_queue_head_t iic_wait;
686 +static ushort r_tbase, r_rbase;
687 +
688 +int cpm_debug = 0;
689 +
690 +static  void
691 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
692 +{
693 +       volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
694 +       if (cpm_debug > 1)
695 +               printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
696 +#if 0
697 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
698 +        /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
699 +        /* Someone with a buggy CPU needs to confirm that */
700 +       i2c->i2c_i2mod &= ~1;
701 +#endif
702 +       /* Clear interrupt.
703 +       */
704 +       i2c->i2c_i2cer = 0xff;
705 +
706 +       /* Get 'me going again.
707 +       */
708 +       wake_up_interruptible(&iic_wait);
709 +}
710 +
711 +static void
712 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
713 +{
714 +       volatile iic_t          *iip = cpm->iip;
715 +       volatile i2c8xx_t       *i2c = cpm->i2c;
716 +       unsigned char brg;
717 +       bd_t *bd = (bd_t *)__res;
718 +
719 +       if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
720 +
721 +       /* Initialize the parameter ram.
722 +        * We need to make sure many things are initialized to zero,
723 +        * especially in the case of a microcode patch.
724 +        */
725 +       iip->iic_rstate = 0;
726 +       iip->iic_rdp = 0;
727 +       iip->iic_rbptr = 0;
728 +       iip->iic_rbc = 0;
729 +       iip->iic_rxtmp = 0;
730 +       iip->iic_tstate = 0;
731 +       iip->iic_tdp = 0;
732 +       iip->iic_tbptr = 0;
733 +       iip->iic_tbc = 0;
734 +       iip->iic_txtmp = 0;
735 +
736 +       /* Set up the IIC parameters in the parameter ram.
737 +       */
738 +       iip->iic_tbase = r_tbase = cpm->dp_addr;
739 +       iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
740 +
741 +       iip->iic_tfcr = SMC_EB;
742 +       iip->iic_rfcr = SMC_EB;
743 +
744 +       /* Set maximum receive size.
745 +       */
746 +       iip->iic_mrblr = CPM_MAX_READ;
747 +
748 +       /* Initialize Tx/Rx parameters.
749 +       */
750 +       if (cpm->reloc == 0) {
751 +               volatile cpm8xx_t *cp = cpm->cp;
752 +
753 +               cp->cp_cpcr =
754 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
755 +               while (cp->cp_cpcr & CPM_CR_FLG);
756 +       } else {
757 +               iip->iic_rbptr = iip->iic_rbase;
758 +               iip->iic_tbptr = iip->iic_tbase;
759 +               iip->iic_rstate = 0;
760 +               iip->iic_tstate = 0;
761 +       }
762 +
763 +       /* Select an arbitrary address.  Just make sure it is unique.
764 +       */
765 +       i2c->i2c_i2add = 0xfe;
766 +
767 +       /* Make clock run at 60 KHz.
768 +       */
769 +       brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
770 +       i2c->i2c_i2brg = brg;
771 +
772 +       i2c->i2c_i2mod = 0x00; 
773 +       i2c->i2c_i2com = 0x01; /* Master mode */
774 +
775 +       /* Disable interrupts.
776 +       */
777 +       i2c->i2c_i2cmr = 0;
778 +       i2c->i2c_i2cer = 0xff;
779 +
780 +       init_waitqueue_head(&iic_wait);
781 +
782 +       /* Install interrupt handler.
783 +       */
784 +       if (cpm_debug) {
785 +               printk ("%s[%d] Install ISR for IRQ %d\n",
786 +                       __func__,__LINE__, CPMVEC_I2C);
787 +       }
788 +       (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
789 +}
790 +
791 +
792 +static int
793 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
794 +{
795 +       volatile i2c8xx_t *i2c = cpm->i2c;
796 +
797 +       /* Shut down IIC.
798 +       */
799 +       i2c->i2c_i2mod &= ~1;
800 +       i2c->i2c_i2cmr = 0;
801 +       i2c->i2c_i2cer = 0xff;
802 +
803 +       return(0);
804 +}
805 +
806 +static void 
807 +cpm_reset_iic_params(volatile iic_t *iip)
808 +{
809 +       iip->iic_tbase = r_tbase;
810 +       iip->iic_rbase = r_rbase;
811 +
812 +       iip->iic_tfcr = SMC_EB;
813 +       iip->iic_rfcr = SMC_EB;
814 +
815 +       iip->iic_mrblr = CPM_MAX_READ;
816 +
817 +       iip->iic_rstate = 0;
818 +       iip->iic_rdp = 0;
819 +       iip->iic_rbptr = iip->iic_rbase;
820 +       iip->iic_rbc = 0;
821 +       iip->iic_rxtmp = 0;
822 +       iip->iic_tstate = 0;
823 +       iip->iic_tdp = 0;
824 +       iip->iic_tbptr = iip->iic_tbase;
825 +       iip->iic_tbc = 0;
826 +       iip->iic_txtmp = 0;
827 +}
828 +
829 +#define BD_SC_NAK              ((ushort)0x0004) /* NAK - did not respond */
830 +#define BD_SC_OV               ((ushort)0x0002) /* OV - receive overrun */
831 +#define CPM_CR_CLOSE_RXBD      ((ushort)0x0007)
832 +
833 +static void force_close(struct i2c_algo_8xx_data *cpm)
834 +{
835 +       volatile i2c8xx_t *i2c = cpm->i2c;
836 +       if (cpm->reloc == 0) { /* micro code disabled */
837 +               volatile cpm8xx_t *cp = cpm->cp;
838 +
839 +               if (cpm_debug) printk("force_close()\n");
840 +               cp->cp_cpcr =
841 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
842 +                       CPM_CR_FLG;
843 +
844 +               while (cp->cp_cpcr & CPM_CR_FLG);
845 +       }
846 +       i2c->i2c_i2cmr = 0x00;  /* Disable all interrupts */
847 +       i2c->i2c_i2cer = 0xff; 
848 +}
849 +
850 +
851 +/* Read from IIC...
852 + * abyte = address byte, with r/w flag already set
853 + */
854 +static int
855 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
856 +{
857 +       volatile iic_t *iip = cpm->iip;
858 +       volatile i2c8xx_t *i2c = cpm->i2c;
859 +       volatile cpm8xx_t *cp = cpm->cp;
860 +       volatile cbd_t  *tbdf, *rbdf;
861 +       u_char *tb;
862 +       unsigned long flags, tmo;
863 +
864 +       if (count >= CPM_MAX_READ)
865 +               return -EINVAL;
866 +
867 +       /* check for and use a microcode relocation patch */
868 +       if (cpm->reloc) {
869 +               cpm_reset_iic_params(iip);
870 +       }
871 +
872 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
873 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
874 +
875 +       /* To read, we need an empty buffer of the proper length.
876 +        * All that is used is the first byte for address, the remainder
877 +        * is just used for timing (and doesn't really have to exist).
878 +        */
879 +       tb = cpm->temp;
880 +       tb = (u_char *)(((uint)tb + 15) & ~15);
881 +       tb[0] = abyte;          /* Device address byte w/rw flag */
882 +
883 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
884 +
885 +       if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
886 +
887 +       tbdf->cbd_bufaddr = __pa(tb);
888 +       tbdf->cbd_datlen = count + 1;
889 +       tbdf->cbd_sc =
890 +               BD_SC_READY | BD_SC_LAST |
891 +               BD_SC_WRAP | BD_IIC_START;
892 +
893 +       iip->iic_mrblr = count +1; /* prevent excessive read, +1
894 +                                     is needed otherwise will the
895 +                                     RXB interrupt come too early */
896 +
897 +       /* flush will invalidate too. */
898 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
899 +
900 +       rbdf->cbd_datlen = 0;
901 +       rbdf->cbd_bufaddr = __pa(buf);
902 +       rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
903 +       if(count > 16){
904 +               /* Chip bug, set enable here */
905 +               local_irq_save(flags);
906 +               i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
907 +               i2c->i2c_i2cer = 0xff;
908 +               i2c->i2c_i2mod |= 1;    /* Enable */
909 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
910 +
911 +               /* Wait for IIC transfer */
912 +               tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
913 +               local_irq_restore(flags);
914 +       } else { /* busy wait for small transfers, its faster */
915 +               i2c->i2c_i2cmr = 0x00;  /* Disable I2C interupts */
916 +               i2c->i2c_i2cer = 0xff;
917 +               i2c->i2c_i2mod |= 1;    /* Enable */
918 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
919 +               tmo = jiffies + 1*HZ; 
920 +               while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
921 +       }               
922 +
923 +       if (signal_pending(current) || !tmo){
924 +               force_close(cpm);
925 +               if(cpm_debug) 
926 +                       printk("IIC read: timeout!\n");
927 +               return -EIO;
928 +       }
929 +#ifdef I2C_CHIP_ERRATA
930 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
931 +        Disabling I2C too early may cause too short stop condition */
932 +       udelay(4);
933 +       i2c->i2c_i2mod &= ~1;
934 +#endif
935 +       if (cpm_debug) {
936 +               printk("tx sc %04x, rx sc %04x\n",
937 +                      tbdf->cbd_sc, rbdf->cbd_sc);
938 +       }
939 +
940 +       if (tbdf->cbd_sc & BD_SC_READY) {
941 +               printk("IIC read; complete but tbuf ready\n");
942 +               force_close(cpm);
943 +               printk("tx sc %04x, rx sc %04x\n",
944 +                      tbdf->cbd_sc, rbdf->cbd_sc);
945 +       }
946 +
947 +       if (tbdf->cbd_sc & BD_SC_NAK) {
948 +               if (cpm_debug)
949 +                       printk("IIC read; no ack\n");
950 +               return -EREMOTEIO;
951 +       }
952 +
953 +       if (rbdf->cbd_sc & BD_SC_EMPTY) {
954 +               /* force_close(cpm); */
955 +               if (cpm_debug){
956 +                       printk("IIC read; complete but rbuf empty\n");
957 +                       printk("tx sc %04x, rx sc %04x\n",
958 +                              tbdf->cbd_sc, rbdf->cbd_sc);
959 +               }
960 +               return -EREMOTEIO;
961 +       }
962 +
963 +       if (rbdf->cbd_sc & BD_SC_OV) {
964 +               if (cpm_debug)
965 +                       printk("IIC read; Overrun\n");
966 +               return -EREMOTEIO;;
967 +       }
968 +
969 +       if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
970 +
971 +       if (rbdf->cbd_datlen < count) {
972 +               if (cpm_debug)
973 +                       printk("IIC read; short, wanted %d got %d\n",
974 +                              count, rbdf->cbd_datlen);
975 +               return 0;
976 +       }
977 +
978 +       return count;
979 +}
980 +
981 +/* Write to IIC...
982 + * addr = address byte, with r/w flag already set
983 + */
984 +static int
985 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
986 +{
987 +       volatile iic_t *iip = cpm->iip;
988 +       volatile i2c8xx_t *i2c = cpm->i2c;
989 +       volatile cpm8xx_t *cp = cpm->cp;
990 +       volatile cbd_t  *tbdf;
991 +       u_char *tb;
992 +       unsigned long flags, tmo;
993 +
994 +       /* check for and use a microcode relocation patch */
995 +       if (cpm->reloc) {
996 +               cpm_reset_iic_params(iip);
997 +       }
998 +       tb = cpm->temp;
999 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1000 +       *tb = abyte;            /* Device address byte w/rw flag */
1001 +
1002 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1003 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1004 +
1005 +       if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1006 +
1007 +       /* set up 2 descriptors */
1008 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1009 +
1010 +       tbdf[0].cbd_bufaddr = __pa(tb);
1011 +       tbdf[0].cbd_datlen = 1;
1012 +       tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1013 +
1014 +       tbdf[1].cbd_bufaddr = __pa(buf);
1015 +       tbdf[1].cbd_datlen = count;
1016 +       tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1017 +
1018 +       if(count > 16){
1019 +               /* Chip bug, set enable here */
1020 +               local_irq_save(flags);
1021 +               i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
1022 +               i2c->i2c_i2cer = 0xff;
1023 +               i2c->i2c_i2mod |= 1;    /* Enable */
1024 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1025 +               
1026 +               /* Wait for IIC transfer */
1027 +               tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1028 +               local_irq_restore(flags);
1029 +       } else {  /* busy wait for small transfers, its faster */
1030 +               i2c->i2c_i2cmr = 0x00;  /* Disable I2C interupts */
1031 +               i2c->i2c_i2cer = 0xff;
1032 +               i2c->i2c_i2mod |= 1;    /* Enable */
1033 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1034 +               tmo = jiffies + 1*HZ; 
1035 +               while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1036 +       }               
1037 +
1038 +       if (signal_pending(current) || !tmo){
1039 +               force_close(cpm);
1040 +               if(cpm_debug && !tmo) 
1041 +                       printk("IIC write: timeout!\n");
1042 +               return -EIO;
1043 +       }
1044 +       
1045 +#if I2C_CHIP_ERRATA
1046 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1047 +        Disabling I2C too early may cause too short stop condition */
1048 +       udelay(4);
1049 +       i2c->i2c_i2mod &= ~1;
1050 +#endif
1051 +       if (cpm_debug) {
1052 +               printk("tx0 sc %04x, tx1 sc %04x\n",
1053 +                      tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1054 +       }
1055 +
1056 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1057 +               if (cpm_debug) 
1058 +                       printk("IIC write; no ack\n");
1059 +               return 0;
1060 +       }
1061 +         
1062 +       if (tbdf->cbd_sc & BD_SC_READY) {
1063 +               if (cpm_debug)
1064 +                       printk("IIC write; complete but tbuf ready\n");
1065 +               return 0;
1066 +       }
1067 +
1068 +       return count;
1069 +}
1070 +
1071 +/* See if an IIC address exists..
1072 + * addr = 7 bit address, unshifted
1073 + */
1074 +static int
1075 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1076 +{
1077 +       volatile iic_t *iip = cpm->iip;
1078 +       volatile i2c8xx_t *i2c = cpm->i2c;
1079 +       volatile cpm8xx_t *cp = cpm->cp;
1080 +       volatile cbd_t *tbdf, *rbdf;
1081 +       u_char *tb;
1082 +       unsigned long flags, len, tmo;
1083 +
1084 +       if (cpm_debug > 1)
1085 +               printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1086 +
1087 +       /* check for and use a microcode relocation patch */
1088 +       if (cpm->reloc) {
1089 +               cpm_reset_iic_params(iip);
1090 +       }
1091 +
1092 +       if (cpm_debug && addr == 0) {
1093 +               printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1094 +               printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1095 +       }
1096 +
1097 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1098 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1099 +
1100 +       tb = cpm->temp;
1101 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1102 +
1103 +       /* do a simple read */
1104 +       tb[0] = (addr << 1) | 1;        /* device address (+ read) */
1105 +       len = 2;
1106 +
1107 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1108 +
1109 +       tbdf->cbd_bufaddr = __pa(tb);
1110 +       tbdf->cbd_datlen = len;
1111 +       tbdf->cbd_sc =
1112 +               BD_SC_READY | BD_SC_LAST |
1113 +               BD_SC_WRAP | BD_IIC_START;
1114 +
1115 +       rbdf->cbd_datlen = 0;
1116 +       rbdf->cbd_bufaddr = __pa(tb+2);
1117 +       rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1118 +
1119 +       local_irq_save(flags);
1120 +       i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
1121 +       i2c->i2c_i2cer = 0xff;
1122 +       i2c->i2c_i2mod |= 1;    /* Enable */
1123 +       i2c->i2c_i2com |= 0x80; /* Begin transmission */
1124 +
1125 +       if (cpm_debug > 1) printk("about to sleep\n");
1126 +
1127 +       /* wait for IIC transfer */
1128 +       tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1129 +       local_irq_restore(flags);
1130 +
1131 +#ifdef I2C_CHIP_ERRATA
1132 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1133 +        Disabling I2C too early may cause too short stop condition */
1134 +       udelay(4);
1135 +       i2c->i2c_i2mod &= ~1;
1136 +#endif
1137 +
1138 +       if (signal_pending(current) || !tmo){
1139 +               force_close(cpm);
1140 +               if(cpm_debug && !tmo) 
1141 +                       printk("IIC tryaddress: timeout!\n");
1142 +               return -EIO;
1143 +       }
1144 +
1145 +       if (cpm_debug > 1) printk("back from sleep\n");
1146 +
1147 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1148 +               if (cpm_debug > 1) printk("IIC try; no ack\n");
1149 +               return 0;
1150 +       }
1151 +         
1152 +       if (tbdf->cbd_sc & BD_SC_READY) {
1153 +               printk("IIC try; complete but tbuf ready\n");
1154 +       }
1155 +       
1156 +       return 1;
1157 +}
1158 +
1159 +static int cpm_xfer(struct i2c_adapter *adap,
1160 +                   struct i2c_msg msgs[], 
1161 +                   int num)
1162 +{
1163 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1164 +       struct i2c_msg *pmsg;
1165 +       int i, ret;
1166 +       u_char addr;
1167 +    
1168 +       for (i = 0; i < num; i++) {
1169 +               pmsg = &msgs[i];
1170 +
1171 +               if (cpm_debug)
1172 +                       printk("i2c-algo-8xx.o: "
1173 +                              "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1174 +                              i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1175 +
1176 +               addr = pmsg->addr << 1;
1177 +               if (pmsg->flags & I2C_M_RD )
1178 +                       addr |= 1;
1179 +               if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1180 +                       addr ^= 1;
1181 +    
1182 +               if (!(pmsg->flags & I2C_M_NOSTART)) {
1183 +               }
1184 +               if (pmsg->flags & I2C_M_RD ) {
1185 +                       /* read bytes into buffer*/
1186 +                       ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1187 +                       if (cpm_debug)
1188 +                               printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1189 +                       if (ret < pmsg->len ) {
1190 +                               return (ret<0)? ret : -EREMOTEIO;
1191 +                       }
1192 +               } else {
1193 +                       /* write bytes from buffer */
1194 +                       ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1195 +                       if (cpm_debug)
1196 +                               printk("i2c-algo-8xx.o: wrote %d\n", ret);
1197 +                       if (ret < pmsg->len ) {
1198 +                               return (ret<0) ? ret : -EREMOTEIO;
1199 +                       }
1200 +               }
1201 +       }
1202 +       return (num);
1203 +}
1204 +
1205 +static u32 cpm_func(struct i2c_adapter *adap)
1206 +{
1207 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
1208 +              I2C_FUNC_PROTOCOL_MANGLING; 
1209 +}
1210 +
1211 +/* -----exported algorithm data: ------------------------------------- */
1212 +
1213 +static struct i2c_algorithm cpm_algo = {
1214 +       .owner          = THIS_MODULE,
1215 +       .name           = "MPC8xx CPM algorithm",
1216 +       .id             = I2C_ALGO_MPC8XX,
1217 +       .master_xfer    = cpm_xfer,
1218 +       .functionality  = cpm_func,
1219 +};
1220 +
1221 +/* 
1222 + * registering functions to load algorithms at runtime 
1223 + */
1224 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1225 +{
1226 +       int i;
1227 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1228 +
1229 +       if (cpm_debug)
1230 +               printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1231 +                      adap->name);
1232 +
1233 +       /* register new adapter to i2c module... */
1234 +
1235 +       adap->id |= cpm_algo.id;
1236 +       adap->algo = &cpm_algo;
1237 +
1238 +       i2c_add_adapter(adap);
1239 +       cpm_iic_init(cpm);
1240 +}
1241 +
1242 +
1243 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1244 +{
1245 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1246 +
1247 +       cpm_iic_shutdown(cpm);
1248 +
1249 +       return i2c_del_adapter(adap);
1250 +}
1251 +
1252 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1253 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1254 +
1255 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1256 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1257 +MODULE_LICENSE("GPL");
1258 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-bit.c linux-2.4.24/drivers/i2c/i2c-algo-bit.c
1259 --- linux-2.4.24.org/drivers/i2c/i2c-algo-bit.c 2004-02-04 22:33:47.392029625 +0100
1260 +++ linux-2.4.24/drivers/i2c/i2c-algo-bit.c     2004-02-04 22:36:36.644833227 +0100
1261 @@ -18,24 +18,22 @@
1262      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
1263  /* ------------------------------------------------------------------------- */
1264  
1265 -/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
1266 -   Frodo Looijaard <frodol@dds.nl> */
1267 +/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyƶsti MƤlkki
1268 +   <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
1269  
1270 -/* $Id$ */
1271 +/* $Id$ */
1272  
1273  #include <linux/kernel.h>
1274  #include <linux/module.h>
1275  #include <linux/delay.h>
1276  #include <linux/slab.h>
1277  #include <linux/init.h>
1278 -#include <asm/uaccess.h>
1279 -#include <linux/ioport.h>
1280  #include <linux/errno.h>
1281  #include <linux/sched.h>
1282 -
1283  #include <linux/i2c.h>
1284  #include <linux/i2c-algo-bit.h>
1285  
1286 +
1287  /* ----- global defines ----------------------------------------------- */
1288  #define DEB(x) if (i2c_debug>=1) x;
1289  #define DEB2(x) if (i2c_debug>=2) x;
1290 @@ -43,27 +41,13 @@
1291  #define DEBPROTO(x) if (i2c_debug>=9) { x; }
1292         /* debug the protocol by showing transferred bits */
1293  
1294 -/* debugging - slow down transfer to have a look at the data ..        */
1295 -/* I use this with two leds&resistors, each one connected to sda,scl   */
1296 -/* respectively. This makes sure that the algorithm works. Some chips   */
1297 -/* might not like this, as they have an internal timeout of some mils  */
1298 -/*
1299 -#define SLO_IO      jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1300 -                        if (need_resched) schedule();
1301 -*/
1302 -
1303  
1304  /* ----- global variables ---------------------------------------------        */
1305  
1306 -#ifdef SLO_IO
1307 -       int jif;
1308 -#endif
1309 -
1310  /* module parameters:
1311   */
1312  static int i2c_debug;
1313  static int bit_test;   /* see if the line-setting functions work       */
1314 -static int bit_scan;   /* have a look at what's hanging 'round         */
1315  
1316  /* --- setting states on the bus with the right timing: ---------------        */
1317  
1318 @@ -88,9 +72,6 @@
1319  {
1320         setscl(adap,0);
1321         udelay(adap->udelay);
1322 -#ifdef SLO_IO
1323 -       SLO_IO
1324 -#endif
1325  }
1326  
1327  /*
1328 @@ -99,33 +80,35 @@
1329   */
1330  static inline int sclhi(struct i2c_algo_bit_data *adap)
1331  {
1332 -       int start=jiffies;
1333 +       int start;
1334  
1335         setscl(adap,1);
1336  
1337 -       udelay(adap->udelay);
1338 -
1339         /* Not all adapters have scl sense line... */
1340 -       if (adap->getscl == NULL )
1341 +       if (adap->getscl == NULL ) {
1342 +               udelay(adap->udelay);
1343                 return 0;
1344 +       }
1345  
1346 -       while (! getscl(adap) ) {       
1347 +       start=jiffies;
1348 +       while (! getscl(adap) ) {       
1349                 /* the hw knows how to read the clock line,
1350                  * so we wait until it actually gets high.
1351                  * This is safer as some chips may hold it low
1352                  * while they are processing data internally. 
1353                  */
1354 -               setscl(adap,1);
1355                 if (time_after_eq(jiffies, start+adap->timeout)) {
1356                         return -ETIMEDOUT;
1357                 }
1358 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1359                 if (current->need_resched)
1360                         schedule();
1361 +#else
1362 +               cond_resched();
1363 +#endif
1364         }
1365         DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1366 -#ifdef SLO_IO
1367 -       SLO_IO
1368 -#endif
1369 +       udelay(adap->udelay);
1370         return 0;
1371  } 
1372  
1373 @@ -144,7 +127,7 @@
1374         /* scl, sda may not be high */
1375         DEBPROTO(printk(" Sr "));
1376         setsda(adap,1);
1377 -       setscl(adap,1);
1378 +       sclhi(adap);
1379         udelay(adap->udelay);
1380         
1381         sdalo(adap);
1382 @@ -178,7 +161,6 @@
1383         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1384  
1385         /* assert: scl is low */
1386 -       DEB2(printk(KERN_DEBUG " i2c_outb:%2.2X\n",c&0xff));
1387         for ( i=7 ; i>=0 ; i-- ) {
1388                 sb = c & ( 1 << i );
1389                 setsda(adap,sb);
1390 @@ -186,6 +168,7 @@
1391                 DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1392                 if (sclhi(adap)<0) { /* timed out */
1393                         sdahi(adap); /* we don't want to block the net */
1394 +                       DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1395                         return -ETIMEDOUT;
1396                 };
1397                 /* do arbitration here: 
1398 @@ -196,11 +179,12 @@
1399         }
1400         sdahi(adap);
1401         if (sclhi(adap)<0){ /* timeout */
1402 +               DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1403                 return -ETIMEDOUT;
1404         };
1405         /* read ack: SDA should be pulled down by slave */
1406         ack=getsda(adap);       /* ack: sda is pulled low ->success.     */
1407 -       DEB2(printk(KERN_DEBUG " i2c_outb: getsda() =  0x%2.2x\n", ~ack ));
1408 +       DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1409  
1410         DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1411         DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1412 @@ -219,11 +203,10 @@
1413         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1414  
1415         /* assert: scl is low */
1416 -       DEB2(printk(KERN_DEBUG "i2c_inb.\n"));
1417 -
1418         sdahi(adap);
1419         for (i=0;i<8;i++) {
1420                 if (sclhi(adap)<0) { /* timeout */
1421 +                       DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1422                         return -ETIMEDOUT;
1423                 };
1424                 indata *= 2;
1425 @@ -232,6 +215,8 @@
1426                 scllo(adap);
1427         }
1428         /* assert: scl is low */
1429 +       DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1430 +
1431         DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1432         return (int) (indata & 0xff);
1433  }
1434 @@ -242,71 +227,75 @@
1435   */
1436  static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
1437         int scl,sda;
1438 +
1439 +       if (adap->getscl==NULL)
1440 +               printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, "
1441 +                       "SCL is not readable.\n");
1442 +
1443         sda=getsda(adap);
1444 -       if (adap->getscl==NULL) {
1445 -               printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1446 -               return 0;               
1447 -       }
1448 -       scl=getscl(adap);
1449 -       printk("i2c-algo-bit.o: Adapter: %s scl: %d  sda: %d -- testing...\n",
1450 -              name,getscl(adap),getsda(adap));
1451 +       scl=(adap->getscl==NULL?1:getscl(adap));
1452 +       printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
1453         if (!scl || !sda ) {
1454 -               printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1455 +               printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name);
1456                 goto bailout;
1457         }
1458 +
1459         sdalo(adap);
1460 -       printk("i2c-algo-bit.o:1 scl: %d  sda: %d \n",getscl(adap),
1461 -              getsda(adap));
1462 -       if ( 0 != getsda(adap) ) {
1463 -               printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1464 -               sdahi(adap);
1465 +       sda=getsda(adap);
1466 +       scl=(adap->getscl==NULL?1:getscl(adap));
1467 +       printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
1468 +       if ( 0 != sda ) {
1469 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n");
1470                 goto bailout;
1471         }
1472 -       if ( 0 == getscl(adap) ) {
1473 -               printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1474 -                       name);
1475 +       if ( 0 == scl ) {
1476 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1477 +                       "while pulling SDA low!\n");
1478                 goto bailout;
1479         }               
1480 +
1481         sdahi(adap);
1482 -       printk("i2c-algo-bit.o:2 scl: %d  sda: %d \n",getscl(adap),
1483 -              getsda(adap));
1484 -       if ( 0 == getsda(adap) ) {
1485 -               printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1486 -               sdahi(adap);
1487 +       sda=getsda(adap);
1488 +       scl=(adap->getscl==NULL?1:getscl(adap));
1489 +       printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
1490 +       if ( 0 == sda ) {
1491 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n");
1492                 goto bailout;
1493         }
1494 -       if ( 0 == getscl(adap) ) {
1495 -               printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1496 -                      name);
1497 -       goto bailout;
1498 +       if ( 0 == scl ) {
1499 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1500 +                       "while pulling SDA high!\n");
1501 +               goto bailout;
1502         }
1503 +
1504         scllo(adap);
1505 -       printk("i2c-algo-bit.o:3 scl: %d  sda: %d \n",getscl(adap),
1506 -              getsda(adap));
1507 -       if ( 0 != getscl(adap) ) {
1508 -               printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1509 -               sclhi(adap);
1510 +       sda=getsda(adap);
1511 +       scl=(adap->getscl==NULL?0:getscl(adap));
1512 +       printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
1513 +       if ( 0 != scl ) {
1514 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n");
1515                 goto bailout;
1516         }
1517 -       if ( 0 == getsda(adap) ) {
1518 -               printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1519 -                       name);
1520 +       if ( 0 == sda ) {
1521 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1522 +                       "while pulling SCL low!\n");
1523                 goto bailout;
1524         }
1525 +       
1526         sclhi(adap);
1527 -       printk("i2c-algo-bit.o:4 scl: %d  sda: %d \n",getscl(adap),
1528 -              getsda(adap));
1529 -       if ( 0 == getscl(adap) ) {
1530 -               printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
1531 -               sclhi(adap);
1532 +       sda=getsda(adap);
1533 +       scl=(adap->getscl==NULL?1:getscl(adap));
1534 +       printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
1535 +       if ( 0 == scl ) {
1536 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n");
1537                 goto bailout;
1538         }
1539 -       if ( 0 == getsda(adap) ) {
1540 -               printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
1541 -                       name);
1542 +       if ( 0 == sda ) {
1543 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1544 +                       "while pulling SCL high!\n");
1545                 goto bailout;
1546         }
1547 -       printk("i2c-algo-bit.o: %s passed test.\n",name);
1548 +       printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
1549         return 0;
1550  bailout:
1551         sdahi(adap);
1552 @@ -340,16 +329,21 @@
1553                 i2c_start(adap);
1554                 udelay(adap->udelay);
1555         }
1556 -       DEB2(if (i) printk(KERN_DEBUG "i2c-algo-bit.o: needed %d retries for %d\n",
1557 -                          i,addr));
1558 +       DEB2(if (i)
1559 +            printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
1560 +                   i+1, addr & 1 ? "read" : "write", addr>>1,
1561 +                   ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
1562 +           );
1563         return ret;
1564  }
1565  
1566 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
1567 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1568  {
1569         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1570         char c;
1571 -       const char *temp = buf;
1572 +       const char *temp = msg->buf;
1573 +       int count = msg->len;
1574 +       unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 
1575         int retval;
1576         int wrcount=0;
1577  
1578 @@ -358,7 +352,7 @@
1579                 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
1580                             i2c_adap->name, c&0xff));
1581                 retval = i2c_outb(i2c_adap,c);
1582 -               if (retval>0) {
1583 +               if ((retval>0) || (nak_ok && (retval==0)))  { /* ok or ignored NAK */
1584                         count--; 
1585                         temp++;
1586                         wrcount++;
1587 @@ -377,12 +371,18 @@
1588         return wrcount;
1589  }
1590  
1591 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
1592 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1593  {
1594 -       char *temp = buf;
1595         int inval;
1596         int rdcount=0;          /* counts bytes read */
1597         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1598 +       char *temp = msg->buf;
1599 +       int count = msg->len;
1600 +       int recv_len = 0;
1601 +
1602 +       /* Receive [Count] for I2C_SMBUS_BLOCK_DATA or I2C_SMBUS_BLOCK_PROC_CALL protocol */
1603 +       if (msg->flags & I2C_M_RECV_LEN)
1604 +               recv_len = 1;
1605  
1606         while (count > 0) {
1607                 inval = i2c_inb(i2c_adap);
1608 @@ -395,6 +395,20 @@
1609                         break;
1610                 }
1611  
1612 +               if (recv_len) {
1613 +                       recv_len = 0;
1614 +                       /* [Count] should be between 1 and 31 (I2C_SMBUS_BLOCK_MAX - 1). */
1615 +                       if (inval > 0 && inval < I2C_SMBUS_BLOCK_MAX) {
1616 +                               count = inval + 1;      /* plus one for [Count] itself */
1617 +                               msg->len = count;
1618 +                               if (msg->flags & I2C_M_RECV_PEC)
1619 +                                       count++; /* plus one for PEC */
1620 +                       } else {
1621 +                               printk(KERN_ERR "i2c-algo-bit.o: readbytes: bad block count (%d).\n", inval);
1622 +                               break;
1623 +                       }
1624 +               }
1625 +               
1626                 if ( count > 1 ) {              /* send ack */
1627                         sdalo(adap);
1628                         DEBPROTO(printk(" Am "));
1629 @@ -419,31 +433,34 @@
1630   * try_address) and transmits the address in the necessary format to handle
1631   * reads, writes as well as 10bit-addresses.
1632   * returns:
1633 - *  0 everything went okay, the chip ack'ed
1634 + *  0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
1635   * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
1636   *     -ETIMEDOUT, for example if the lines are stuck...) 
1637   */
1638 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
1639 -                                struct i2c_msg *msg, int retries) 
1640 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 
1641  {
1642         unsigned short flags = msg->flags;
1643 +       unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1644         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1645  
1646         unsigned char addr;
1647 -       int ret;
1648 +       int ret, retries;
1649 +
1650 +       retries = nak_ok ? 0 : i2c_adap->retries;
1651 +       
1652         if ( (flags & I2C_M_TEN)  ) { 
1653                 /* a ten bit address */
1654                 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
1655                 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
1656                 /* try extended address code...*/
1657                 ret = try_address(i2c_adap, addr, retries);
1658 -               if (ret!=1) {
1659 +               if ((ret != 1) && !nak_ok)  {
1660                         printk(KERN_ERR "died at extended address code.\n");
1661                         return -EREMOTEIO;
1662                 }
1663                 /* the remaining 8 bit address */
1664                 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
1665 -               if (ret != 1) {
1666 +               if ((ret != 1) && !nak_ok) {
1667                         /* the chip did not ack / xmission error occurred */
1668                         printk(KERN_ERR "died at 2nd address code.\n");
1669                         return -EREMOTEIO;
1670 @@ -453,7 +470,7 @@
1671                         /* okay, now switch into reading mode */
1672                         addr |= 0x01;
1673                         ret = try_address(i2c_adap, addr, retries);
1674 -                       if (ret!=1) {
1675 +                       if ((ret!=1) && !nak_ok) {
1676                                 printk(KERN_ERR "died at extended address code.\n");
1677                                 return -EREMOTEIO;
1678                         }
1679 @@ -465,10 +482,10 @@
1680                 if (flags & I2C_M_REV_DIR_ADDR )
1681                         addr ^= 1;
1682                 ret = try_address(i2c_adap, addr, retries);
1683 -               if (ret!=1) {
1684 +               if ((ret!=1) && !nak_ok)
1685                         return -EREMOTEIO;
1686 -               }
1687         }
1688 +
1689         return 0;
1690  }
1691  
1692 @@ -479,16 +496,18 @@
1693         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1694         
1695         int i,ret;
1696 +       unsigned short nak_ok;
1697  
1698         i2c_start(adap);
1699         for (i=0;i<num;i++) {
1700                 pmsg = &msgs[i];
1701 +               nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 
1702                 if (!(pmsg->flags & I2C_M_NOSTART)) {
1703                         if (i) {
1704                                 i2c_repstart(adap);
1705                         }
1706 -                       ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
1707 -                       if (ret != 0) {
1708 +                       ret = bit_doAddress(i2c_adap, pmsg);
1709 +                       if ((ret != 0) && !nak_ok) {
1710                                 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n",
1711                                         msgs[i].addr,i));
1712                                 return (ret<0) ? ret : -EREMOTEIO;
1713 @@ -496,14 +515,14 @@
1714                 }
1715                 if (pmsg->flags & I2C_M_RD ) {
1716                         /* read bytes into buffer*/
1717 -                       ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
1718 +                       ret = readbytes(i2c_adap, pmsg);
1719                         DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
1720                         if (ret < pmsg->len ) {
1721                                 return (ret<0)? ret : -EREMOTEIO;
1722                         }
1723                 } else {
1724                         /* write bytes from buffer */
1725 -                       ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
1726 +                       ret = sendbytes(i2c_adap, pmsg);
1727                         DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
1728                         if (ret < pmsg->len ) {
1729                                 return (ret<0) ? ret : -EREMOTEIO;
1730 @@ -514,30 +533,25 @@
1731         return num;
1732  }
1733  
1734 -static int algo_control(struct i2c_adapter *adapter, 
1735 -       unsigned int cmd, unsigned long arg)
1736 -{
1737 -       return 0;
1738 -}
1739 -
1740 -static u32 bit_func(struct i2c_adapter *adap)
1741 +static u32 bit_func(struct i2c_adapter *i2c_adap)
1742  {
1743         return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
1744 -              I2C_FUNC_PROTOCOL_MANGLING;
1745 +              I2C_FUNC_PROTOCOL_MANGLING |
1746 +              I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
1747 +              I2C_FUNC_SMBUS_READ_BLOCK_DATA |
1748 +              I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC |
1749 +              I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC;
1750  }
1751  
1752  
1753  /* -----exported algorithm data: ------------------------------------- */
1754  
1755  static struct i2c_algorithm i2c_bit_algo = {
1756 -       "Bit-shift algorithm",
1757 -       I2C_ALGO_BIT,
1758 -       bit_xfer,
1759 -       NULL,
1760 -       NULL,                           /* slave_xmit           */
1761 -       NULL,                           /* slave_recv           */
1762 -       algo_control,                   /* ioctl                */
1763 -       bit_func,                       /* functionality        */
1764 +       .owner          = THIS_MODULE,
1765 +       .name           = "Bit-shift algorithm",
1766 +       .id             = I2C_ALGO_BIT,
1767 +       .master_xfer    = bit_xfer,
1768 +       .functionality  = bit_func,
1769  };
1770  
1771  /* 
1772 @@ -545,7 +559,6 @@
1773   */
1774  int i2c_bit_add_bus(struct i2c_adapter *adap)
1775  {
1776 -       int i;
1777         struct i2c_algo_bit_data *bit_adap = adap->algo_data;
1778  
1779         if (bit_test) {
1780 @@ -565,78 +578,26 @@
1781         adap->timeout = 100;    /* default values, should       */
1782         adap->retries = 3;      /* be replaced by defines       */
1783  
1784 -       /* scan bus */
1785 -       if (bit_scan) {
1786 -               int ack;
1787 -               printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
1788 -                      adap->name);
1789 -               for (i = 0x00; i < 0xff; i+=2) {
1790 -                       i2c_start(bit_adap);
1791 -                       ack = i2c_outb(adap,i);
1792 -                       i2c_stop(bit_adap);
1793 -                       if (ack>0) {
1794 -                               printk("(%02x)",i>>1); 
1795 -                       } else 
1796 -                               printk("."); 
1797 -               }
1798 -               printk("\n");
1799 -       }
1800 -
1801 -#ifdef MODULE
1802 -       MOD_INC_USE_COUNT;
1803 -#endif
1804         i2c_add_adapter(adap);
1805 -
1806         return 0;
1807  }
1808  
1809  
1810  int i2c_bit_del_bus(struct i2c_adapter *adap)
1811  {
1812 -       int res;
1813 -
1814 -       if ((res = i2c_del_adapter(adap)) < 0)
1815 -               return res;
1816 -
1817 -       DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
1818 -
1819 -#ifdef MODULE
1820 -       MOD_DEC_USE_COUNT;
1821 -#endif
1822 -       return 0;
1823 -}
1824 -
1825 -int __init i2c_algo_bit_init (void)
1826 -{
1827 -       printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
1828 -       return 0;
1829 +       return i2c_del_adapter(adap);
1830  }
1831  
1832 -
1833 -
1834  EXPORT_SYMBOL(i2c_bit_add_bus);
1835  EXPORT_SYMBOL(i2c_bit_del_bus);
1836  
1837 -#ifdef MODULE
1838  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1839  MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
1840  MODULE_LICENSE("GPL");
1841  
1842  MODULE_PARM(bit_test, "i");
1843 -MODULE_PARM(bit_scan, "i");
1844  MODULE_PARM(i2c_debug,"i");
1845  
1846  MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
1847 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
1848  MODULE_PARM_DESC(i2c_debug,
1849              "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
1850 -
1851 -int init_module(void) 
1852 -{
1853 -       return i2c_algo_bit_init();
1854 -}
1855 -
1856 -void cleanup_module(void) 
1857 -{
1858 -}
1859 -#endif
1860 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-ibm_ocp.c linux-2.4.24/drivers/i2c/i2c-algo-ibm_ocp.c
1861 --- linux-2.4.24.org/drivers/i2c/i2c-algo-ibm_ocp.c     1970-01-01 01:00:00.000000000 +0100
1862 +++ linux-2.4.24/drivers/i2c/i2c-algo-ibm_ocp.c 2004-02-04 22:36:36.653831355 +0100
1863 @@ -0,0 +1,901 @@
1864 +/*
1865 +   -------------------------------------------------------------------------
1866 +   i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters       
1867 +   -------------------------------------------------------------------------
1868 +      
1869 +   Ian DaSilva, MontaVista Software, Inc.
1870 +   idasilva@mvista.com or source@mvista.com
1871 +
1872 +   Copyright 2000 MontaVista Software Inc.
1873 +
1874 +   Changes made to support the IIC peripheral on the IBM PPC 405
1875 +
1876 +
1877 +   ---------------------------------------------------------------------------
1878 +   This file was highly leveraged from i2c-algo-pcf.c, which was created
1879 +   by Simon G. Vogl and Hans Berglund:
1880 +
1881 +
1882 +     Copyright (C) 1995-1997 Simon G. Vogl
1883 +                   1998-2000 Hans Berglund
1884 +
1885 +   With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and 
1886 +   Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
1887 +   <mbailey@littlefeet-inc.com>
1888 +
1889 +
1890 +    This program is free software; you can redistribute it and/or modify
1891 +    it under the terms of the GNU General Public License as published by
1892 +    the Free Software Foundation; either version 2 of the License, or
1893 +    (at your option) any later version.
1894 +
1895 +    This program is distributed in the hope that it will be useful,
1896 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
1897 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1898 +    GNU General Public License for more details.
1899 +
1900 +    You should have received a copy of the GNU General Public License
1901 +    along with this program; if not, write to the Free Software
1902 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1903 +   ---------------------------------------------------------------------------
1904 +
1905 +   History: 01/20/12 - Armin
1906 +       akuster@mvista.com
1907 +       ported up to 2.4.16+    
1908 +
1909 +   Version 02/03/25 - Armin
1910 +       converted to ocp format
1911 +       removed commented out or #if 0 code
1912 +       added GĆ©rard Basler's fix to iic_combined_transaction() such that it 
1913 +       returns the number of successfully completed transfers .
1914 +*/
1915 +
1916 +
1917 +#include <linux/kernel.h>
1918 +#include <linux/module.h>
1919 +#include <linux/delay.h>
1920 +#include <linux/slab.h>
1921 +#include <linux/init.h>
1922 +#include <linux/errno.h>
1923 +#include <linux/sched.h>
1924 +#include <linux/i2c.h>
1925 +#include <linux/i2c-algo-ibm_ocp.h>
1926 +#include <asm/ocp.h>
1927 +
1928 +
1929 +/* ----- global defines ----------------------------------------------- */
1930 +#define DEB(x) if (i2c_debug>=1) x
1931 +#define DEB2(x) if (i2c_debug>=2) x
1932 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
1933 +#define DEBPROTO(x) if (i2c_debug>=9) x;
1934 +       /* debug the protocol by showing transferred bits */
1935 +#define DEF_TIMEOUT 5
1936 +
1937 +
1938 +/* ----- global variables ---------------------------------------------        */
1939 +
1940 +
1941 +/* module parameters:
1942 + */
1943 +static int i2c_debug=0;
1944 +
1945 +/* --- setting states on the bus with the right timing: ---------------        */
1946 +
1947 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
1948 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
1949 +
1950 +#define IICO_I2C_SDAHIGH       0x0780
1951 +#define IICO_I2C_SDALOW                0x0781
1952 +#define IICO_I2C_SCLHIGH       0x0782
1953 +#define IICO_I2C_SCLLOW                0x0783
1954 +#define IICO_I2C_LINEREAD      0x0784
1955 +
1956 +#define IIC_SINGLE_XFER                0
1957 +#define IIC_COMBINED_XFER      1
1958 +
1959 +#define IIC_ERR_LOST_ARB        -2
1960 +#define IIC_ERR_INCOMPLETE_XFR  -3
1961 +#define IIC_ERR_NACK            -1
1962 +
1963 +/* --- other auxiliary functions --------------------------------------        */
1964 +
1965 +
1966 +//
1967 +// Description: Puts this process to sleep for a period equal to timeout 
1968 +//
1969 +static inline void iic_sleep(unsigned long timeout)
1970 +{
1971 +       schedule_timeout( timeout * HZ);
1972 +}
1973 +
1974 +
1975 +//
1976 +// Description: This performs the IBM PPC 405 IIC initialization sequence
1977 +// as described in the PPC405GP data book.
1978 +//
1979 +static int iic_init (struct i2c_algo_iic_data *adap)
1980 +{
1981 +       struct iic_regs *iic;   
1982 +       struct iic_ibm *adap_priv_data = adap->data;
1983 +       unsigned short  retval;
1984 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
1985 +
1986 +        /* Clear master low master address */
1987 +        iic_outb(adap,iic->lmadr, 0);
1988 +
1989 +        /* Clear high master address */
1990 +        iic_outb(adap,iic->hmadr, 0);
1991 +
1992 +        /* Clear low slave address */
1993 +        iic_outb(adap,iic->lsadr, 0);
1994 +
1995 +        /* Clear high slave address */
1996 +        iic_outb(adap,iic->hsadr, 0);
1997 +
1998 +        /* Clear status */
1999 +        iic_outb(adap,iic->sts, 0x0a);
2000 +
2001 +        /* Clear extended status */
2002 +        iic_outb(adap,iic->extsts, 0x8f);
2003 +
2004 +        /* Set clock division */
2005 +        iic_outb(adap,iic->clkdiv, 0x04);
2006 +
2007 +       retval = iic_inb(adap, iic->clkdiv);
2008 +       DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2009 +
2010 +        /* Enable interrupts on Requested Master Transfer Complete */
2011 +        iic_outb(adap,iic->intmsk, 0x01);
2012 +
2013 +        /* Clear transfer count */
2014 +        iic_outb(adap,iic->xfrcnt, 0x0);
2015 +
2016 +        /* Clear extended control and status */
2017 +        iic_outb(adap,iic->xtcntlss, 0xf0);
2018 +
2019 +        /* Set mode control (flush master data buf, enable hold SCL, exit */
2020 +        /* unknown state.                                                 */
2021 +        iic_outb(adap,iic->mdcntl, 0x47);
2022 +
2023 +        /* Clear control register */
2024 +        iic_outb(adap,iic->cntl, 0x0);
2025 +
2026 +        DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2027 +        return 0;
2028 +}
2029 +
2030 +
2031 +//
2032 +// Description: After we issue a transaction on the IIC bus, this function
2033 +// is called.  It puts this process to sleep until we get an interrupt from
2034 +// from the controller telling us that the transaction we requested in complete.
2035 +//
2036 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status) 
2037 +{
2038 +
2039 +       int timeout = DEF_TIMEOUT;
2040 +       int retval;
2041 +       struct iic_regs *iic;
2042 +       struct iic_ibm *adap_priv_data = adap->data;
2043 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2044 +
2045 +
2046 +       *status = iic_inb(adap, iic->sts);
2047 +#ifndef STUB_I2C
2048 +
2049 +       while (timeout-- && (*status & 0x01)) {
2050 +          adap->waitforpin(adap->data);
2051 +          *status = iic_inb(adap, iic->sts);
2052 +       }
2053 +#endif
2054 +       if (timeout <= 0) {
2055 +          /* Issue stop signal on the bus, and force an interrupt */
2056 +           retval = iic_inb(adap, iic->cntl);
2057 +           iic_outb(adap, iic->cntl, retval | 0x80);
2058 +           /* Clear status register */
2059 +          iic_outb(adap, iic->sts, 0x0a);
2060 +          /* Exit unknown bus state */
2061 +          retval = iic_inb(adap, iic->mdcntl);
2062 +          iic_outb(adap, iic->mdcntl, (retval | 0x02));
2063 +
2064 +          // Check the status of the controller.  Does it still see a
2065 +          // pending transfer, even though we've tried to stop any
2066 +          // ongoing transaction?
2067 +           retval = iic_inb(adap, iic->sts);
2068 +           retval = retval & 0x01;
2069 +           if(retval) {
2070 +             // The iic controller is hosed.  It is not responding to any
2071 +             // of our commands.  We have already tried to force it into
2072 +             // a known state, but it has not worked.  Our only choice now
2073 +             // is a soft reset, which will clear all registers, and force
2074 +             // us to re-initialize the controller.
2075 +             /* Soft reset */
2076 +              iic_outb(adap, iic->xtcntlss, 0x01);
2077 +              udelay(500);
2078 +              iic_init(adap);
2079 +             /* Is the pending transfer bit in the sts reg finally cleared? */
2080 +              retval = iic_inb(adap, iic->sts);
2081 +              retval = retval & 0x01;
2082 +              if(retval) {
2083 +                 printk(KERN_CRIT "The IIC Controller is hosed.  A processor reset is required\n");
2084 +              }
2085 +             // For some reason, even though the interrupt bit in this
2086 +             // register was set during iic_init, it didn't take.  We
2087 +             // need to set it again.  Don't ask me why....this is just what
2088 +             // I saw when testing timeouts.
2089 +              iic_outb(adap, iic->intmsk, 0x01);
2090 +           }
2091 +          return(-1);
2092 +       }
2093 +       else
2094 +          return(0);
2095 +}
2096 +
2097 +
2098 +//------------------------------------
2099 +// Utility functions
2100 +//
2101 +
2102 +
2103 +//
2104 +// Description: Look at the status register to see if there was an error
2105 +// in the requested transaction.  If there is, look at the extended status
2106 +// register and determine the exact cause.
2107 +//
2108 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2109 +{
2110 +   int ret;
2111 +   struct iic_regs *iic;
2112 +   struct iic_ibm *adap_priv_data = adap->data;
2113 +   iic = (struct iic_regs *) adap_priv_data->iic_base;
2114 +
2115 +       
2116 +   ret = iic_inb(adap, iic->sts);
2117 +   if(ret & 0x04) {
2118 +      // Error occurred
2119 +      ret = iic_inb(adap, iic->extsts);
2120 +      if(ret & 0x04) {
2121 +         // Lost arbitration
2122 +         *error_code =  IIC_ERR_LOST_ARB;
2123 +      }
2124 +      if(ret & 0x02) {
2125 +         // Incomplete transfer
2126 +         *error_code = IIC_ERR_INCOMPLETE_XFR;
2127 +      }
2128 +      if(ret & 0x01) {
2129 +         // Master transfer aborted by a NACK during the transfer of the 
2130 +        // address byte
2131 +         *error_code = IIC_ERR_NACK;
2132 +      }
2133 +      return -1;
2134 +   }
2135 +   return 0;
2136 +}
2137 +
2138 +
2139 +//
2140 +// Description: This function is called by the upper layers to do the
2141 +// grunt work for a master send transaction
2142 +//
2143 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2144 +                         int count, int xfer_flag)
2145 +{
2146 +       struct iic_regs *iic;
2147 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2148 +       struct iic_ibm *adap_priv_data = adap->data;
2149 +       int wrcount, status, timeout;
2150 +       int loops, remainder, i, j;
2151 +       int ret, error_code;
2152 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2153 +
2154
2155 +       if( count == 0 ) return 0;
2156 +       wrcount = 0;
2157 +       loops =  count / 4;
2158 +       remainder = count % 4;
2159 +
2160 +       if((loops > 1) && (remainder == 0)) {
2161 +          for(i=0; i<(loops-1); i++) {
2162 +                     //
2163 +             // Write four bytes to master data buffer
2164 +             //
2165 +             for(j=0; j<4; j++) {
2166 +                iic_outb(adap, iic->mdbuf, 
2167 +                buf[wrcount++]);
2168 +             }
2169 +             //
2170 +             // Issue command to IICO device to begin transmission
2171 +             //
2172 +             iic_outb(adap, iic->cntl, 0x35);
2173 +             //
2174 +             // Wait for transmission to complete.  When it does, 
2175 +             //loop to the top of the for statement and write the 
2176 +             // next four bytes.
2177 +             //
2178 +             timeout = wait_for_pin(adap, &status);
2179 +             if(timeout < 0) {
2180 +                //
2181 +                // Error handling
2182 +                //
2183 +                 //printk(KERN_ERR "Error: write timeout\n");
2184 +                 return wrcount;
2185 +             }
2186 +             ret = analyze_status(adap, &error_code);
2187 +             if(ret < 0) {
2188 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2189 +                    // Return the number of bytes transferred
2190 +                    ret = iic_inb(adap, iic->xfrcnt);
2191 +                    ret = ret & 0x07;
2192 +                    return (wrcount-4+ret);
2193 +                 }
2194 +                 else return error_code;
2195 +              }
2196 +           }
2197 +       }
2198 +       else if((loops >= 1) && (remainder > 0)){
2199 +          //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2200 +          for(i=0; i<loops; i++) {
2201 +              //
2202 +              // Write four bytes to master data buffer
2203 +              //
2204 +              for(j=0; j<4; j++) {
2205 +                 iic_outb(adap, iic->mdbuf,
2206 +                 buf[wrcount++]);
2207 +              }
2208 +              //
2209 +              // Issue command to IICO device to begin transmission
2210 +              //
2211 +              iic_outb(adap, iic->cntl, 0x35);
2212 +              //
2213 +              // Wait for transmission to complete.  When it does,
2214 +              //loop to the top of the for statement and write the
2215 +              // next four bytes.
2216 +              //
2217 +              timeout = wait_for_pin(adap, &status);
2218 +              if(timeout < 0) {
2219 +                 //
2220 +                 // Error handling
2221 +                 //
2222 +                 //printk(KERN_ERR "Error: write timeout\n");
2223 +                 return wrcount;
2224 +              }
2225 +              ret = analyze_status(adap, &error_code);
2226 +              if(ret < 0) {
2227 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2228 +                    // Return the number of bytes transferred
2229 +                    ret = iic_inb(adap, iic->xfrcnt);
2230 +                    ret = ret & 0x07;
2231 +                    return (wrcount-4+ret);
2232 +                 }
2233 +                 else return error_code;
2234 +              }
2235 +           }
2236 +        }
2237 +
2238 +       //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2239 +       if(remainder == 0) remainder = 4;
2240 +       // remainder = remainder - 1;
2241 +       //
2242 +       // Write the remaining bytes (less than or equal to 4)
2243 +       //
2244 +       for(i=0; i<remainder; i++) {
2245 +          iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2246 +          //printk(KERN_DEBUG "iic_sendbytes:  data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2247 +       }
2248 +        //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2249 +
2250 +        if(xfer_flag == IIC_COMBINED_XFER) {
2251 +           iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2252 +        }
2253 +       else {
2254 +           iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2255 +        }
2256 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2257 +       timeout = wait_for_pin(adap, &status);
2258 +        if(timeout < 0) {
2259 +                  //
2260 +           // Error handling
2261 +           //
2262 +           //printk(KERN_ERR "Error: write timeout\n");
2263 +           return wrcount;
2264 +        }
2265 +        ret = analyze_status(adap, &error_code);
2266 +        if(ret < 0) {
2267 +           if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2268 +              // Return the number of bytes transferred
2269 +              ret = iic_inb(adap, iic->xfrcnt);
2270 +              ret = ret & 0x07;
2271 +              return (wrcount-4+ret);
2272 +           }
2273 +           else return error_code;
2274 +        }
2275 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2276 +       return wrcount;
2277 +}
2278 +
2279 +
2280 +//
2281 +// Description: Called by the upper layers to do the grunt work for
2282 +// a master read transaction.
2283 +//
2284 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2285 +{
2286 +       struct iic_regs *iic;
2287 +       int rdcount=0, i, status, timeout;
2288 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2289 +       struct iic_ibm *adap_priv_data = adap->data;
2290 +       int loops, remainder, j;
2291 +        int ret, error_code;
2292 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2293 +
2294 +       if(count == 0) return 0;
2295 +       loops = count / 4;
2296 +       remainder = count % 4;
2297 +
2298 +       //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2299 +
2300 +       if((loops > 1) && (remainder == 0)) {
2301 +       //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2302 +          for(i=0; i<(loops-1); i++) {
2303 +             //
2304 +              // Issue command to begin master read (4 bytes maximum)
2305 +              //
2306 +             //printk(KERN_DEBUG "--->Issued read command\n");
2307 +             iic_outb(adap, iic->cntl, 0x37);
2308 +             //
2309 +              // Wait for transmission to complete.  When it does,
2310 +              // loop to the top of the for statement and write the
2311 +              // next four bytes.
2312 +              //
2313 +             //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2314 +              timeout = wait_for_pin(adap, &status);
2315 +              if(timeout < 0) {
2316 +                // Error Handler
2317 +                //printk(KERN_ERR "Error: read timed out\n");
2318 +                 return rdcount;
2319 +             }
2320 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2321 +
2322 +              ret = analyze_status(adap, &error_code);
2323 +             if(ret < 0) {
2324 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2325 +                    return rdcount;
2326 +                 else
2327 +                    return error_code;
2328 +              }
2329 +
2330 +             for(j=0; j<4; j++) {
2331 +                 // Wait for data to shuffle to top of data buffer
2332 +                 // This value needs to optimized.
2333 +                udelay(1);
2334 +                buf[rdcount] = iic_inb(adap, iic->mdbuf);
2335 +                rdcount++;
2336 +                //printk(KERN_DEBUG "--->Read one byte\n");
2337 +              }
2338 +           }
2339 +       }
2340 +
2341 +       else if((loops >= 1) && (remainder > 0)){
2342 +       //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2343 +          for(i=0; i<loops; i++) {
2344 +              //
2345 +              // Issue command to begin master read (4 bytes maximum)
2346 +              //
2347 +              //printk(KERN_DEBUG "--->Issued read command\n");
2348 +              iic_outb(adap, iic->cntl, 0x37);
2349 +              //
2350 +              // Wait for transmission to complete.  When it does,
2351 +              // loop to the top of the for statement and write the
2352 +              // next four bytes.
2353 +              //
2354 +              //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2355 +              timeout = wait_for_pin(adap, &status);
2356 +              if(timeout < 0) {
2357 +                 // Error Handler
2358 +                 //printk(KERN_ERR "Error: read timed out\n");
2359 +                 return rdcount;
2360 +              }
2361 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2362 +
2363 +              ret = analyze_status(adap, &error_code);
2364 +              if(ret < 0) {
2365 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2366 +                    return rdcount;
2367 +                 else
2368 +                    return error_code;
2369 +              }
2370 +
2371 +              for(j=0; j<4; j++) {
2372 +                 // Wait for data to shuffle to top of data buffer
2373 +                 // This value needs to optimized.
2374 +                 udelay(1);
2375 +                 buf[rdcount] = iic_inb(adap, iic->mdbuf);
2376 +                 rdcount++;
2377 +                 //printk(KERN_DEBUG "--->Read one byte\n");
2378 +              }
2379 +           }
2380 +        }
2381 +
2382 +       //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2383 +       if(remainder == 0) remainder = 4;
2384 +       DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2385 +
2386 +       if(xfer_type == IIC_COMBINED_XFER) {
2387 +          iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2388 +        }
2389 +        else {
2390 +          iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2391 +        }
2392 +       DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2393 +        timeout = wait_for_pin(adap, &status);
2394 +       DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2395 +        if(timeout < 0) {
2396 +           // Error Handler
2397 +          //printk(KERN_ERR "Error: read timed out\n");
2398 +           return rdcount;
2399 +        }
2400 +
2401 +        ret = analyze_status(adap, &error_code);
2402 +        if(ret < 0) {
2403 +           if(error_code == IIC_ERR_INCOMPLETE_XFR)
2404 +              return rdcount;
2405 +           else
2406 +              return error_code;
2407 +        }
2408 +
2409 +       //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2410 +       for(i=0; i<remainder; i++) {
2411 +          buf[rdcount] = iic_inb(adap, iic->mdbuf);
2412 +          // printk(KERN_DEBUG "iic_readbytes:  Character read = %x\n", buf[rdcount]);
2413 +           rdcount++;
2414 +       }
2415 +
2416 +       return rdcount;
2417 +}
2418 +
2419 +
2420 +//
2421 +// Description:  This function implements combined transactions.  Combined
2422 +// transactions consist of combinations of reading and writing blocks of data.
2423 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2424 +// condition.
2425 +//
2426 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 
2427 +{
2428 +   int i;
2429 +   struct i2c_msg *pmsg;
2430 +   int ret;
2431 +
2432 +   DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2433 +       for(i=0; i < num; i++) {
2434 +               pmsg = &msgs[i];
2435 +               if(pmsg->flags & I2C_M_RD) {
2436 +
2437 +                       // Last read or write segment needs to be terminated with a stop
2438 +                       if(i < num-1) {
2439 +                               DEB2(printk(KERN_DEBUG "This one is a read\n"));
2440 +                       }
2441 +                       else {
2442 +                               DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2443 +                       }
2444 +                       ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2445 +
2446 +                       if (ret != pmsg->len) {
2447 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2448 +                                                       "only read %d bytes.\n",ret));
2449 +                               return i;
2450 +                       }
2451 +                       else {
2452 +                               DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2453 +                       }
2454 +               }
2455 +               else if(!(pmsg->flags & I2C_M_RD)) {
2456 +
2457 +                       // Last read or write segment needs to be terminated with a stop
2458 +                       if(i < num-1) {
2459 +                               DEB2(printk(KERN_DEBUG "This one is a write\n"));
2460 +                       }
2461 +                       else {
2462 +                               DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2463 +                       }
2464 +                       ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2465 +
2466 +                       if (ret != pmsg->len) {
2467 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2468 +                                                       "only wrote %d bytes.\n",ret));
2469 +                               return i;
2470 +                       }
2471 +                       else {
2472 +                               DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2473 +                       }
2474 +               }
2475 +       }
2476
2477 +       return num;
2478 +}
2479 +
2480 +
2481 +//
2482 +// Description: Whenever we initiate a transaction, the first byte clocked
2483 +// onto the bus after the start condition is the address (7 bit) of the
2484 +// device we want to talk to.  This function manipulates the address specified
2485 +// so that it makes sense to the hardware when written to the IIC peripheral.
2486 +//
2487 +// Note: 10 bit addresses are not supported in this driver, although they are
2488 +// supported by the hardware.  This functionality needs to be implemented.
2489 +//
2490 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
2491 +                                struct i2c_msg *msg, int retries) 
2492 +{
2493 +       struct iic_regs *iic;
2494 +       unsigned short flags = msg->flags;
2495 +       unsigned char addr;
2496 +       struct iic_ibm *adap_priv_data = adap->data;
2497 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2498 +
2499 +//
2500 +// The following segment for 10 bit addresses needs to be ported
2501 +//
2502 +/* Ten bit addresses not supported right now
2503 +       if ( (flags & I2C_M_TEN)  ) { 
2504 +               // a ten bit address
2505 +               addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2506 +               DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2507 +               // try extended address code...
2508 +               ret = try_address(adap, addr, retries);
2509 +               if (ret!=1) {
2510 +                       printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2511 +                       return -EREMOTEIO;
2512 +               }
2513 +               // the remaining 8 bit address
2514 +               iic_outb(adap,msg->addr & 0x7f);
2515 +               // Status check comes here
2516 +               if (ret != 1) {
2517 +                       printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
2518 +                       return -EREMOTEIO;
2519 +               }
2520 +               if ( flags & I2C_M_RD ) {
2521 +                       i2c_repstart(adap);
2522 +                       // okay, now switch into reading mode
2523 +                       addr |= 0x01;
2524 +                       ret = try_address(adap, addr, retries);
2525 +                       if (ret!=1) {
2526 +                               printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2527 +                               return -EREMOTEIO;
2528 +                       }
2529 +               }
2530 +       } else ----------> // normal 7 bit address
2531 +
2532 +Ten bit addresses not supported yet */
2533 +
2534 +       addr = ( msg->addr << 1 );
2535 +       if (flags & I2C_M_RD )
2536 +               addr |= 1;
2537 +       if (flags & I2C_M_REV_DIR_ADDR )
2538 +               addr ^= 1;
2539 +       //
2540 +       // Write to the low slave address
2541 +       //
2542 +       iic_outb(adap, iic->lmadr, addr);
2543 +       //
2544 +       // Write zero to the high slave register since we are
2545 +       // only using 7 bit addresses
2546 +       //
2547 +       iic_outb(adap, iic->hmadr, 0);
2548 +
2549 +       return 0;
2550 +}
2551 +
2552 +
2553 +//
2554 +// Description: Prepares the controller for a transaction (clearing status
2555 +// registers, data buffers, etc), and then calls either iic_readbytes or
2556 +// iic_sendbytes to do the actual transaction.
2557 +//
2558 +static int iic_xfer(struct i2c_adapter *i2c_adap,
2559 +                   struct i2c_msg msgs[], 
2560 +                   int num)
2561 +{
2562 +       struct iic_regs *iic;
2563 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2564 +       struct iic_ibm *adap_priv_data = adap->data;
2565 +       struct i2c_msg *pmsg;
2566 +       int i = 0;
2567 +       int ret;
2568 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2569 +
2570 +       pmsg = &msgs[i];
2571 +
2572 +       //
2573 +       // Clear status register
2574 +       //
2575 +       DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
2576 +       iic_outb(adap, iic->sts, 0x0a);
2577 +
2578 +       //
2579 +       // Wait for any pending transfers to complete
2580 +       //
2581 +       DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
2582 +       while((ret = iic_inb(adap, iic->sts)) == 0x01) {
2583 +               ;
2584 +       }
2585 +
2586 +       //
2587 +       // Flush master data buf
2588 +       //
2589 +       DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));             
2590 +       ret = iic_inb(adap, iic->mdcntl);
2591 +       iic_outb(adap, iic->mdcntl, ret | 0x40);
2592 +
2593 +       //
2594 +       // Load slave address
2595 +       //
2596 +       DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
2597 +       ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
2598 +
2599 +        //
2600 +        // Check to see if the bus is busy
2601 +        //
2602 +        ret = iic_inb(adap, iic->extsts);
2603 +        // Mask off the irrelevent bits
2604 +        ret = ret & 0x70;
2605 +        // When the bus is free, the BCS bits in the EXTSTS register are 0b100
2606 +        if(ret != 0x40) return IIC_ERR_LOST_ARB;
2607 +
2608 +       //
2609 +       // Combined transaction (read and write)
2610 +       //
2611 +       if(num > 1) {
2612 +           DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
2613 +           ret = iic_combined_transaction(i2c_adap, msgs, num);
2614 +        }
2615 +       //
2616 +       // Read only
2617 +       //
2618 +       else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
2619 +          //
2620 +          // Tell device to begin reading data from the  master data 
2621 +          //
2622 +          DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
2623 +          ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2624 +       } 
2625 +        //
2626 +       // Write only
2627 +       //
2628 +       else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
2629 +          //
2630 +          // Write data to master data buffers and tell our device
2631 +          // to begin transmitting
2632 +          //
2633 +          DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
2634 +          ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2635 +       }       
2636 +
2637 +       return ret;   
2638 +}
2639 +
2640 +
2641 +//
2642 +// Description: Implements device specific ioctls.  Higher level ioctls can
2643 +// be found in i2c-core.c and are typical of any i2c controller (specifying
2644 +// slave address, timeouts, etc).  These ioctls take advantage of any hardware
2645 +// features built into the controller for which this algorithm-adapter set
2646 +// was written.  These ioctls allow you to take control of the data and clock
2647 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
2648 +// similar to a GPIO pin.
2649 +//
2650 +static int algo_control(struct i2c_adapter *adapter, 
2651 +       unsigned int cmd, unsigned long arg)
2652 +{
2653 +       struct iic_regs *iic;
2654 +       struct i2c_algo_iic_data *adap = adapter->algo_data;
2655 +       struct iic_ibm *adap_priv_data = adap->data;
2656 +       int ret=0;
2657 +       int lines;
2658 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2659 +
2660 +       lines = iic_inb(adap, iic->directcntl);
2661 +
2662 +       if (cmd == IICO_I2C_SDAHIGH) {
2663 +             lines = lines & 0x01;
2664 +             if( lines ) lines = 0x04;
2665 +             else lines = 0;
2666 +             iic_outb(adap, iic->directcntl,(0x08|lines));
2667 +       }
2668 +       else if (cmd == IICO_I2C_SDALOW) {
2669 +             lines = lines & 0x01;
2670 +             if( lines ) lines = 0x04;
2671 +              else lines = 0;
2672 +              iic_outb(adap, iic->directcntl,(0x00|lines));
2673 +       }
2674 +       else if (cmd == IICO_I2C_SCLHIGH) {
2675 +              lines = lines & 0x02;
2676 +              if( lines ) lines = 0x08;
2677 +              else lines = 0;
2678 +              iic_outb(adap, iic->directcntl,(0x04|lines));
2679 +       }
2680 +       else if (cmd == IICO_I2C_SCLLOW) {
2681 +              lines = lines & 0x02;
2682 +             if( lines ) lines = 0x08;
2683 +              else lines = 0;
2684 +              iic_outb(adap, iic->directcntl,(0x00|lines));
2685 +       }
2686 +       else if (cmd == IICO_I2C_LINEREAD) {
2687 +             ret = lines;
2688 +       }
2689 +       return ret;
2690 +}
2691 +
2692 +
2693 +static u32 iic_func(struct i2c_adapter *adap)
2694 +{
2695 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
2696 +              I2C_FUNC_PROTOCOL_MANGLING; 
2697 +}
2698 +
2699 +
2700 +/* -----exported algorithm data: ------------------------------------- */
2701 +
2702 +static struct i2c_algorithm iic_algo = {
2703 +       .owner          = THIS_MODULE,
2704 +       .name           = "IBM on-chip IIC algorithm",
2705 +       .id             = I2C_ALGO_OCP,
2706 +       .master_xfer    = iic_xfer,
2707 +       .algo_control   = algo_control,
2708 +       .functionality  = iic_func,
2709 +};
2710 +
2711 +/* 
2712 + * registering functions to load algorithms at runtime 
2713 + */
2714 +
2715 +
2716 +//
2717 +// Description: Register bus structure
2718 +//
2719 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
2720 +{
2721 +       struct i2c_algo_iic_data *iic_adap = adap->algo_data;
2722 +
2723 +       DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
2724 +                   adap->name));
2725 +
2726 +       /* register new adapter to i2c module... */
2727 +
2728 +       adap->id |= iic_algo.id;
2729 +       adap->algo = &iic_algo;
2730 +
2731 +       adap->timeout = 100;    /* default values, should       */
2732 +       adap->retries = 3;              /* be replaced by defines       */
2733 +
2734 +       iic_init(iic_adap);
2735 +       i2c_add_adapter(adap);
2736 +       return 0;
2737 +}
2738 +
2739 +
2740 +//
2741 +// Done
2742 +//
2743 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
2744 +{
2745 +       return i2c_del_adapter(adap);
2746 +}
2747 +
2748 +
2749 +EXPORT_SYMBOL(i2c_ocp_add_bus);
2750 +EXPORT_SYMBOL(i2c_ocp_del_bus);
2751 +
2752 +//
2753 +// The MODULE_* macros resolve to nothing if MODULES is not defined
2754 +// when this file is compiled.
2755 +//
2756 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
2757 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
2758 +MODULE_LICENSE("GPL");
2759 +
2760 +MODULE_PARM(i2c_debug,"i");
2761 +
2762 +MODULE_PARM_DESC(i2c_debug,
2763 +        "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
2764 +
2765 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-pcf.c linux-2.4.24/drivers/i2c/i2c-algo-pcf.c
2766 --- linux-2.4.24.org/drivers/i2c/i2c-algo-pcf.c 2004-02-04 22:33:47.589988460 +0100
2767 +++ linux-2.4.24/drivers/i2c/i2c-algo-pcf.c     2004-02-04 22:36:36.656830731 +0100
2768 @@ -32,14 +32,11 @@
2769  #include <linux/delay.h>
2770  #include <linux/slab.h>
2771  #include <linux/init.h>
2772 -#include <asm/uaccess.h>
2773 -#include <linux/ioport.h>
2774  #include <linux/errno.h>
2775  #include <linux/sched.h>
2776 -
2777  #include <linux/i2c.h>
2778  #include <linux/i2c-algo-pcf.h>
2779 -#include "i2c-pcf8584.h"
2780 +
2781  
2782  /* ----- global defines ----------------------------------------------- */
2783  #define DEB(x) if (i2c_debug>=1) x
2784 @@ -52,7 +49,6 @@
2785  /* module parameters:
2786   */
2787  static int i2c_debug=0;
2788 -static int pcf_scan=0; /* have a look at what's hanging 'round         */
2789  
2790  /* --- setting states on the bus with the right timing: ---------------        */
2791  
2792 @@ -149,8 +145,7 @@
2793         set_pcf(adap, 1, I2C_PCF_PIN);
2794         /* check to see S1 now used as R/W ctrl -
2795            PCF8584 does that when ESO is zero */
2796 -       /* PCF also resets PIN bit */
2797 -       if ((temp = get_pcf(adap, 1)) != (0)) {
2798 +       if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
2799                 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
2800                 return -ENXIO; /* definetly not PCF8584 */
2801         }
2802 @@ -166,7 +161,7 @@
2803         /* S1=0xA0, next byte in S2                                     */
2804         set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
2805         /* check to see S2 now selected */
2806 -       if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
2807 +       if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
2808                 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
2809                 return -ENXIO;
2810         }
2811 @@ -427,12 +422,6 @@
2812         return (i);
2813  }
2814  
2815 -static int algo_control(struct i2c_adapter *adapter, 
2816 -       unsigned int cmd, unsigned long arg)
2817 -{
2818 -       return 0;
2819 -}
2820 -
2821  static u32 pcf_func(struct i2c_adapter *adap)
2822  {
2823         return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
2824 @@ -442,14 +431,11 @@
2825  /* -----exported algorithm data: ------------------------------------- */
2826  
2827  static struct i2c_algorithm pcf_algo = {
2828 -       "PCF8584 algorithm",
2829 -       I2C_ALGO_PCF,
2830 -       pcf_xfer,
2831 -       NULL,
2832 -       NULL,                           /* slave_xmit           */
2833 -       NULL,                           /* slave_recv           */
2834 -       algo_control,                   /* ioctl                */
2835 -       pcf_func,                       /* functionality        */
2836 +       .owner          = THIS_MODULE,
2837 +       .name           = "PCF8584 algorithm",
2838 +       .id             = I2C_ALGO_PCF,
2839 +       .master_xfer    = pcf_xfer,
2840 +       .functionality  = pcf_func,
2841  };
2842  
2843  /* 
2844 @@ -457,7 +443,7 @@
2845   */
2846  int i2c_pcf_add_bus(struct i2c_adapter *adap)
2847  {
2848 -       int i, status;
2849 +       int i;
2850         struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
2851  
2852         DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
2853 @@ -475,81 +461,23 @@
2854                 return i;
2855         }
2856  
2857 -#ifdef MODULE
2858 -       MOD_INC_USE_COUNT;
2859 -#endif
2860 -
2861         i2c_add_adapter(adap);
2862 -
2863 -       /* scan bus */
2864 -       if (pcf_scan) {
2865 -               printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
2866 -                      adap->name);
2867 -               for (i = 0x00; i < 0xff; i+=2) {
2868 -                       if (wait_for_bb(pcf_adap)) {
2869 -                       printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
2870 -                          adap->name);
2871 -                           break;
2872 -                       }
2873 -                       i2c_outb(pcf_adap, i);
2874 -                       i2c_start(pcf_adap);
2875 -                       if ((wait_for_pin(pcf_adap, &status) >= 0) && 
2876 -                           ((status & I2C_PCF_LRB) == 0)) { 
2877 -                               printk("(%02x)",i>>1); 
2878 -                       } else {
2879 -                               printk("."); 
2880 -                       }
2881 -                       i2c_stop(pcf_adap);
2882 -                       udelay(pcf_adap->udelay);
2883 -               }
2884 -               printk("\n");
2885 -       }
2886         return 0;
2887  }
2888  
2889  
2890  int i2c_pcf_del_bus(struct i2c_adapter *adap)
2891  {
2892 -       int res;
2893 -       if ((res = i2c_del_adapter(adap)) < 0)
2894 -               return res;
2895 -       DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
2896 -
2897 -#ifdef MODULE
2898 -       MOD_DEC_USE_COUNT;
2899 -#endif
2900 -       return 0;
2901 -}
2902 -
2903 -int __init i2c_algo_pcf_init (void)
2904 -{
2905 -       printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
2906 -       return 0;
2907 +       return i2c_del_adapter(adap);
2908  }
2909  
2910 -
2911  EXPORT_SYMBOL(i2c_pcf_add_bus);
2912  EXPORT_SYMBOL(i2c_pcf_del_bus);
2913  
2914 -#ifdef MODULE
2915  MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
2916  MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
2917  MODULE_LICENSE("GPL");
2918  
2919 -MODULE_PARM(pcf_scan, "i");
2920  MODULE_PARM(i2c_debug,"i");
2921 -
2922 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
2923  MODULE_PARM_DESC(i2c_debug,
2924          "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
2925 -
2926 -
2927 -int init_module(void) 
2928 -{
2929 -       return i2c_algo_pcf_init();
2930 -}
2931 -
2932 -void cleanup_module(void) 
2933 -{
2934 -}
2935 -#endif
2936 diff -urN linux-2.4.24.org/drivers/i2c/i2c-core.c linux-2.4.24/drivers/i2c/i2c-core.c
2937 --- linux-2.4.24.org/drivers/i2c/i2c-core.c     2004-02-04 22:33:47.354037526 +0100
2938 +++ linux-2.4.24/drivers/i2c/i2c-core.c 2004-02-04 22:36:36.665828860 +0100
2939 @@ -18,56 +18,33 @@
2940  /* ------------------------------------------------------------------------- */
2941  
2942  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi>.
2943 -   All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
2944 +   All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
2945 +   SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com>                */
2946  
2947 -/* $Id$ */
2948 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
2949  
2950  #include <linux/module.h>
2951  #include <linux/kernel.h>
2952  #include <linux/errno.h>
2953  #include <linux/slab.h>
2954  #include <linux/proc_fs.h>
2955 -#include <linux/config.h>
2956 -
2957 -#include <linux/i2c.h>
2958 -
2959 -/* ----- compatibility stuff ----------------------------------------------- */
2960 -
2961  #include <linux/init.h>
2962 -
2963 +#include <linux/i2c.h>
2964  #include <asm/uaccess.h>
2965  
2966  /* ----- global defines ---------------------------------------------------- */
2967  
2968 -/* exclusive access to the bus */
2969 -#define I2C_LOCK(adap) down(&adap->lock)
2970 -#define I2C_UNLOCK(adap) up(&adap->lock) 
2971 -
2972 -#define ADAP_LOCK()    down(&adap_lock)
2973 -#define ADAP_UNLOCK()  up(&adap_lock)
2974 -
2975 -#define DRV_LOCK()     down(&driver_lock)
2976 -#define DRV_UNLOCK()   up(&driver_lock)
2977 -
2978  #define DEB(x) if (i2c_debug>=1) x;
2979  #define DEB2(x) if (i2c_debug>=2) x;
2980  
2981  /* ----- global variables -------------------------------------------------- */
2982  
2983 -/**** lock for writing to global variables: the adapter & driver list */
2984 -struct semaphore adap_lock;
2985 -struct semaphore driver_lock;
2986 -
2987 -/**** adapter list */
2988 +DECLARE_MUTEX(core_lists);
2989  static struct i2c_adapter *adapters[I2C_ADAP_MAX];
2990 -static int adap_count;
2991 -
2992 -/**** drivers list */
2993  static struct i2c_driver *drivers[I2C_DRIVER_MAX];
2994 -static int driver_count;
2995  
2996  /**** debug level */
2997 -static int i2c_debug=1;
2998 +static int i2c_debug;
2999  
3000  /* ---------------------------------------------------
3001   * /proc entry declarations
3002 @@ -75,10 +52,6 @@
3003   */
3004  
3005  #ifdef CONFIG_PROC_FS
3006 -
3007 -static int i2cproc_init(void);
3008 -static int i2cproc_cleanup(void);
3009 -
3010  static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, 
3011                                  loff_t *ppos);
3012  static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
3013 @@ -87,15 +60,11 @@
3014  /* To implement the dynamic /proc/bus/i2c-? files, we need our own 
3015     implementation of the read hook */
3016  static struct file_operations i2cproc_operations = {
3017 -       read:           i2cproc_bus_read,
3018 +       .read           = i2cproc_bus_read,
3019  };
3020  
3021 -static int i2cproc_initialized = 0;
3022 -
3023 -#else /* undef CONFIG_PROC_FS */
3024 -
3025 -#define i2cproc_init() 0
3026 -#define i2cproc_cleanup() 0
3027 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3028 +static void i2cproc_remove(int bus);
3029  
3030  #endif /* CONFIG_PROC_FS */
3031  
3032 @@ -112,9 +81,9 @@
3033   */
3034  int i2c_add_adapter(struct i2c_adapter *adap)
3035  {
3036 -       int i,j,res;
3037 +       int i,j,res = 0;
3038  
3039 -       ADAP_LOCK();
3040 +       down(&core_lists);
3041         for (i = 0; i < I2C_ADAP_MAX; i++)
3042                 if (NULL == adapters[i])
3043                         break;
3044 @@ -125,68 +94,39 @@
3045                 res = -ENOMEM;
3046                 goto ERROR0;
3047         }
3048 +       
3049 +#ifdef CONFIG_PROC_FS
3050 +       res = i2cproc_register(adap, i);
3051 +       if (res<0)
3052 +           goto ERROR0;
3053 +#endif /* def CONFIG_PROC_FS */
3054  
3055         adapters[i] = adap;
3056 -       adap_count++;
3057 -       ADAP_UNLOCK();
3058         
3059         /* init data types */
3060 -       init_MUTEX(&adap->lock);
3061 -
3062 -#ifdef CONFIG_PROC_FS
3063 -
3064 -       if (i2cproc_initialized) {
3065 -               char name[8];
3066 -               struct proc_dir_entry *proc_entry;
3067 -
3068 -               sprintf(name,"i2c-%d", i);
3069 -
3070 -               proc_entry = create_proc_entry(name,0,proc_bus);
3071 -               if (! proc_entry) {
3072 -                       printk("i2c-core.o: Could not create /proc/bus/%s\n",
3073 -                              name);
3074 -                       res = -ENOENT;
3075 -                       goto ERROR1;
3076 -               }
3077 -
3078 -               proc_entry->proc_fops = &i2cproc_operations;
3079 -               proc_entry->owner = THIS_MODULE;
3080 -               adap->inode = proc_entry->low_ino;
3081 -       }
3082 -
3083 -#endif /* def CONFIG_PROC_FS */
3084 +       init_MUTEX(&adap->bus);
3085 +       init_MUTEX(&adap->list);
3086  
3087         /* inform drivers of new adapters */
3088 -       DRV_LOCK();     
3089         for (j=0;j<I2C_DRIVER_MAX;j++)
3090                 if (drivers[j]!=NULL && 
3091                     (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
3092                         /* We ignore the return code; if it fails, too bad */
3093                         drivers[j]->attach_adapter(adap);
3094 -       DRV_UNLOCK();
3095         
3096         DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3097                    adap->name,i));
3098 -
3099 -       return 0;       
3100 -
3101 -
3102 -ERROR1:
3103 -       ADAP_LOCK();
3104 -       adapters[i] = NULL;
3105 -       adap_count--;
3106  ERROR0:
3107 -       ADAP_UNLOCK();
3108 +       up(&core_lists);
3109         return res;
3110  }
3111  
3112  
3113  int i2c_del_adapter(struct i2c_adapter *adap)
3114  {
3115 -       int i,j,res;
3116 -
3117 -       ADAP_LOCK();
3118 +       int i,j,res = 0;
3119  
3120 +       down(&core_lists);
3121         for (i = 0; i < I2C_ADAP_MAX; i++)
3122                 if (adap == adapters[i])
3123                         break;
3124 @@ -202,17 +142,14 @@
3125          * *detach* it! Of course, each dummy driver should know about
3126          * this or hell will break loose...
3127          */
3128 -       DRV_LOCK();
3129         for (j = 0; j < I2C_DRIVER_MAX; j++) 
3130                 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3131                         if ((res = drivers[j]->attach_adapter(adap))) {
3132                                 printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3133                                        "while detaching driver %s: driver not "
3134                                        "detached!",adap->name,drivers[j]->name);
3135 -                               goto ERROR1;    
3136 +                               goto ERROR0;
3137                         }
3138 -       DRV_UNLOCK();
3139 -
3140  
3141         /* detach any active clients. This must be done first, because
3142          * it can fail; in which case we give upp. */
3143 @@ -231,26 +168,15 @@
3144                                 goto ERROR0;
3145                         }
3146         }
3147 +
3148  #ifdef CONFIG_PROC_FS
3149 -       if (i2cproc_initialized) {
3150 -               char name[8];
3151 -               sprintf(name,"i2c-%d", i);
3152 -               remove_proc_entry(name,proc_bus);
3153 -       }
3154 +       i2cproc_remove(i);
3155  #endif /* def CONFIG_PROC_FS */
3156  
3157         adapters[i] = NULL;
3158 -       adap_count--;
3159 -       
3160 -       ADAP_UNLOCK();  
3161         DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
3162 -       return 0;
3163 -
3164  ERROR0:
3165 -       ADAP_UNLOCK();
3166 -       return res;
3167 -ERROR1:
3168 -       DRV_UNLOCK();
3169 +       up(&core_lists);
3170         return res;
3171  }
3172  
3173 @@ -264,7 +190,8 @@
3174  int i2c_add_driver(struct i2c_driver *driver)
3175  {
3176         int i;
3177 -       DRV_LOCK();
3178 +
3179 +       down(&core_lists);
3180         for (i = 0; i < I2C_DRIVER_MAX; i++)
3181                 if (NULL == drivers[i])
3182                         break;
3183 @@ -273,19 +200,12 @@
3184                        " i2c-core.o: register_driver(%s) "
3185                        "- enlarge I2C_DRIVER_MAX.\n",
3186                         driver->name);
3187 -               DRV_UNLOCK();
3188 +               up(&core_lists);
3189                 return -ENOMEM;
3190         }
3191 -
3192         drivers[i] = driver;
3193 -       driver_count++;
3194 -       
3195 -       DRV_UNLOCK();   /* driver was successfully added */
3196 -       
3197         DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
3198         
3199 -       ADAP_LOCK();
3200 -
3201         /* now look for instances of driver on our adapters
3202          */
3203         if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
3204 @@ -294,15 +214,15 @@
3205                                 /* Ignore errors */
3206                                 driver->attach_adapter(adapters[i]);
3207         }
3208 -       ADAP_UNLOCK();
3209 +       up(&core_lists);
3210         return 0;
3211  }
3212  
3213  int i2c_del_driver(struct i2c_driver *driver)
3214  {
3215 -       int i,j,k,res;
3216 +       int i,j,k,res = 0;
3217  
3218 -       DRV_LOCK();
3219 +       down(&core_lists);
3220         for (i = 0; i < I2C_DRIVER_MAX; i++)
3221                 if (driver == drivers[i])
3222                         break;
3223 @@ -310,7 +230,7 @@
3224                 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
3225                                     "[%s] not found\n",
3226                         driver->name);
3227 -               DRV_UNLOCK();
3228 +               up(&core_lists);
3229                 return -ENODEV;
3230         }
3231         /* Have a look at each adapter, if clients of this driver are still
3232 @@ -322,7 +242,6 @@
3233          * invalid operation might (will!) result, when using stale client
3234          * pointers.
3235          */
3236 -       ADAP_LOCK(); /* should be moved inside the if statement... */
3237         for (k=0;k<I2C_ADAP_MAX;k++) {
3238                 struct i2c_adapter *adap = adapters[k];
3239                 if (adap == NULL) /* skip empty entries. */
3240 @@ -341,8 +260,7 @@
3241                                        "not be detached properly; driver "
3242                                        "not unloaded!",driver->name,
3243                                        adap->name);
3244 -                               ADAP_UNLOCK();
3245 -                               return res;
3246 +                               goto ERROR0;
3247                         }
3248                 } else {
3249                         for (j=0;j<I2C_CLIENT_MAX;j++) { 
3250 @@ -359,37 +277,47 @@
3251                                                        "unregistering driver "
3252                                                        "`%s', the client at "
3253                                                        "address %02x of "
3254 -                                                      "adapter `%s' could not"
3255 -                                                      "be detached; driver"
3256 +                                                      "adapter `%s' could not "
3257 +                                                      "be detached; driver "
3258                                                        "not unloaded!",
3259                                                        driver->name,
3260                                                        client->addr,
3261                                                        adap->name);
3262 -                                               ADAP_UNLOCK();
3263 -                                               return res;
3264 +                                               goto ERROR0;
3265                                         }
3266                                 }
3267                         }
3268                 }
3269         }
3270 -       ADAP_UNLOCK();
3271         drivers[i] = NULL;
3272 -       driver_count--;
3273 -       DRV_UNLOCK();
3274 -       
3275         DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
3276 -       return 0;
3277 +
3278 +ERROR0:
3279 +       up(&core_lists);
3280 +       return res;
3281  }
3282  
3283 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3284 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
3285  {
3286         int i;
3287         for (i = 0; i < I2C_CLIENT_MAX ; i++) 
3288                 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
3289                         return -EBUSY;
3290 +
3291         return 0;
3292  }
3293  
3294 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3295 +{
3296 +       int rval;
3297 +
3298 +       down(&adapter->list);
3299 +       rval = __i2c_check_addr(adapter, addr);
3300 +       up(&adapter->list);
3301 +
3302 +       return rval;
3303 +}
3304 +
3305  int i2c_attach_client(struct i2c_client *client)
3306  {
3307         struct i2c_adapter *adapter = client->adapter;
3308 @@ -398,6 +326,7 @@
3309         if (i2c_check_addr(client->adapter,client->addr))
3310                 return -EBUSY;
3311  
3312 +       down(&adapter->list);
3313         for (i = 0; i < I2C_CLIENT_MAX; i++)
3314                 if (NULL == adapter->clients[i])
3315                         break;
3316 @@ -405,11 +334,11 @@
3317                 printk(KERN_WARNING 
3318                        " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
3319                         client->name);
3320 +               up(&adapter->list);
3321                 return -ENOMEM;
3322         }
3323 -
3324         adapter->clients[i] = client;
3325 -       adapter->client_count++;
3326 +       up(&adapter->list);
3327         
3328         if (adapter->client_register) 
3329                 if (adapter->client_register(client)) 
3330 @@ -431,16 +360,6 @@
3331         struct i2c_adapter *adapter = client->adapter;
3332         int i,res;
3333  
3334 -       for (i = 0; i < I2C_CLIENT_MAX; i++)
3335 -               if (client == adapter->clients[i])
3336 -                       break;
3337 -       if (I2C_CLIENT_MAX == i) {
3338 -               printk(KERN_WARNING " i2c-core.o: unregister_client "
3339 -                                   "[%s] not found\n",
3340 -                       client->name);
3341 -               return -ENODEV;
3342 -       }
3343 -       
3344         if( (client->flags & I2C_CLIENT_ALLOW_USE) && 
3345             (client->usage_count>0))
3346                 return -EBUSY;
3347 @@ -452,33 +371,41 @@
3348                         return res;
3349                 }
3350  
3351 +       down(&adapter->list);
3352 +       for (i = 0; i < I2C_CLIENT_MAX; i++)
3353 +               if (client == adapter->clients[i])
3354 +                       break;
3355 +       if (I2C_CLIENT_MAX == i) {
3356 +               printk(KERN_WARNING " i2c-core.o: unregister_client "
3357 +                                   "[%s] not found\n",
3358 +                       client->name);
3359 +               up(&adapter->list);
3360 +               return -ENODEV;
3361 +       }
3362         adapter->clients[i] = NULL;
3363 -       adapter->client_count--;
3364 +       up(&adapter->list);
3365  
3366         DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
3367         return 0;
3368  }
3369  
3370 -void i2c_inc_use_client(struct i2c_client *client)
3371 +static void i2c_inc_use_client(struct i2c_client *client)
3372  {
3373 -
3374 -       if (client->driver->inc_use != NULL)
3375 -               client->driver->inc_use(client);
3376 -
3377 -       if (client->adapter->inc_use != NULL)
3378 -               client->adapter->inc_use(client->adapter);
3379 +       if(client->driver->owner)
3380 +               __MOD_INC_USE_COUNT(client->driver->owner);
3381 +       if(client->adapter->owner)
3382 +               __MOD_INC_USE_COUNT(client->adapter->owner);
3383  }
3384  
3385 -void i2c_dec_use_client(struct i2c_client *client)
3386 +static void i2c_dec_use_client(struct i2c_client *client)
3387  {
3388 -       
3389 -       if (client->driver->dec_use != NULL)
3390 -               client->driver->dec_use(client);
3391 -
3392 -       if (client->adapter->dec_use != NULL)
3393 -               client->adapter->dec_use(client->adapter);
3394 +       if(client->driver->owner)
3395 +               __MOD_DEC_USE_COUNT(client->driver->owner);
3396 +       if(client->adapter->owner)
3397 +               __MOD_DEC_USE_COUNT(client->adapter->owner);
3398  }
3399  
3400 +#if 0 /* just forget about this for now --km */
3401  struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
3402                                         struct i2c_client *prev)
3403  {
3404 @@ -545,18 +472,17 @@
3405  
3406         return 0;
3407  }
3408 +#endif
3409  
3410  int i2c_use_client(struct i2c_client *client)
3411  {
3412 -       if(client->flags & I2C_CLIENT_ALLOW_USE) {
3413 -               if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE) 
3414 +       if (client->flags & I2C_CLIENT_ALLOW_USE) {
3415 +               if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
3416 +                       client->usage_count++;
3417 +               else if (client->usage_count > 0) 
3418 +                       return -EBUSY;
3419 +               else 
3420                         client->usage_count++;
3421 -               else {
3422 -                       if(client->usage_count > 0) 
3423 -                               return -EBUSY;
3424 -                        else 
3425 -                               client->usage_count++;
3426 -               }
3427         }
3428  
3429         i2c_inc_use_client(client);
3430 @@ -589,12 +515,13 @@
3431  #ifdef CONFIG_PROC_FS
3432  
3433  /* This function generates the output for /proc/bus/i2c */
3434 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 
3435 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 
3436                   void *private)
3437  {
3438         int i;
3439         int nr = 0;
3440         /* Note that it is safe to write a `little' beyond len. Yes, really. */
3441 +       down(&core_lists);
3442         for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
3443                 if (adapters[i]) {
3444                         nr += sprintf(buf+nr, "i2c-%d\t", i);
3445 @@ -611,6 +538,7 @@
3446                                       adapters[i]->name,
3447                                       adapters[i]->algo->name);
3448                 }
3449 +       up(&core_lists);
3450         return nr;
3451  }
3452  
3453 @@ -621,98 +549,125 @@
3454         struct inode * inode = file->f_dentry->d_inode;
3455         char *kbuf;
3456         struct i2c_client *client;
3457 +       struct i2c_adapter *adap;
3458         int i,j,k,order_nr,len=0;
3459         size_t len_total;
3460         int order[I2C_CLIENT_MAX];
3461 +#define OUTPUT_LENGTH_PER_LINE 70
3462  
3463 -       if (count > 4000)
3464 -               return -EINVAL; 
3465         len_total = file->f_pos + count;
3466 -       /* Too bad if this gets longer (unlikely) */
3467 -       if (len_total > 4000)
3468 -               len_total = 4000;
3469 -       for (i = 0; i < I2C_ADAP_MAX; i++)
3470 -               if (adapters[i]->inode == inode->i_ino) {
3471 -               /* We need a bit of slack in the kernel buffer; this makes the
3472 -                  sprintf safe. */
3473 -                       if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
3474 -                               return -ENOMEM;
3475 -                       /* Order will hold the indexes of the clients
3476 -                          sorted by address */
3477 -                       order_nr=0;
3478 -                       for (j = 0; j < I2C_CLIENT_MAX; j++) {
3479 -                               if ((client = adapters[i]->clients[j]) && 
3480 -                                   (client->driver->id != I2C_DRIVERID_I2CDEV))  {
3481 -                                       for(k = order_nr; 
3482 -                                           (k > 0) && 
3483 -                                           adapters[i]->clients[order[k-1]]->
3484 -                                                    addr > client->addr; 
3485 -                                           k--)
3486 -                                               order[k] = order[k-1];
3487 -                                       order[k] = j;
3488 -                                       order_nr++;
3489 -                               }
3490 -                       }
3491 -
3492 -
3493 -                       for (j = 0; (j < order_nr) && (len < len_total); j++) {
3494 -                               client = adapters[i]->clients[order[j]];
3495 -                               len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3496 -                                             client->addr,
3497 -                                             client->name,
3498 -                                             client->driver->name);
3499 -                       }
3500 -                       len = len - file->f_pos;
3501 -                       if (len > count)
3502 -                               len = count;
3503 -                       if (len < 0) 
3504 -                               len = 0;
3505 -                       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3506 -                               kfree(kbuf);
3507 -                               return -EFAULT;
3508 -                       }
3509 -                       file->f_pos += len;
3510 -                       kfree(kbuf);
3511 -                       return len;
3512 -               }
3513 -       return -ENOENT;
3514 +       if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
3515 +               /* adjust to maximum file size */
3516 +               len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
3517 +
3518 +       down(&core_lists);
3519 +       /* adap = file->private_data; ?? --km */
3520 +       for (i = 0; i < I2C_ADAP_MAX; i++) {
3521 +           adap = adapters[i];
3522 +           if (adap && (adap->inode == inode->i_ino))
3523 +               break;
3524 +       }
3525 +       if ( I2C_ADAP_MAX == i ) {
3526 +           up(&core_lists);
3527 +           return -ENOENT;
3528 +       }
3529 +
3530 +       /* We need a bit of slack in the kernel buffer; this makes the
3531 +          sprintf safe. */
3532 +       if (! (kbuf = kmalloc(len_total +
3533 +                             OUTPUT_LENGTH_PER_LINE,
3534 +                             GFP_KERNEL)))
3535 +           return -ENOMEM;
3536 +
3537 +       /* Order will hold the indexes of the clients
3538 +          sorted by address */
3539 +       order_nr=0;
3540 +       down(&adap->list);
3541 +       for (j = 0; j < I2C_CLIENT_MAX; j++) {
3542 +           if ((client = adap->clients[j]) && 
3543 +               (client->driver->id != I2C_DRIVERID_I2CDEV))  {
3544 +               for(k = order_nr; 
3545 +                   (k > 0) && 
3546 +                       adap->clients[order[k-1]]->
3547 +                       addr > client->addr; 
3548 +                   k--)
3549 +                   order[k] = order[k-1];
3550 +               order[k] = j;
3551 +               order_nr++;
3552 +           }
3553 +       }
3554 +
3555 +
3556 +       for (j = 0; (j < order_nr) && (len < len_total); j++) {
3557 +           client = adap->clients[order[j]];
3558 +           len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3559 +                          client->addr,
3560 +                          client->name,
3561 +                          client->driver->name);
3562 +       }
3563 +       up(&adap->list);
3564 +       up(&core_lists);
3565 +       
3566 +       len = len - file->f_pos;
3567 +       if (len > count)
3568 +           len = count;
3569 +       if (len < 0) 
3570 +           len = 0;
3571 +       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3572 +           kfree(kbuf);
3573 +           return -EFAULT;
3574 +       }
3575 +       file->f_pos += len;
3576 +       kfree(kbuf);
3577 +       return len;
3578 +}
3579 +
3580 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
3581 +{
3582 +       char name[8];
3583 +       struct proc_dir_entry *proc_entry;
3584 +
3585 +       sprintf(name,"i2c-%d", bus);
3586 +       proc_entry = create_proc_entry(name,0,proc_bus);
3587 +       if (! proc_entry) {
3588 +               printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
3589 +                      name);
3590 +               return -ENOENT;
3591 +       }
3592 +           
3593 +       proc_entry->proc_fops = &i2cproc_operations;
3594 +       proc_entry->owner = adap->owner;
3595 +       adap->inode = proc_entry->low_ino;
3596 +       return 0;
3597  }
3598  
3599 -int i2cproc_init(void)
3600 +static void i2cproc_remove(int bus)
3601  {
3602 +       char name[8];
3603 +       sprintf(name,"i2c-%d", bus);
3604 +       remove_proc_entry(name, proc_bus);
3605 +}
3606  
3607 +static int __init i2cproc_init(void)
3608 +{
3609         struct proc_dir_entry *proc_bus_i2c;
3610  
3611 -       i2cproc_initialized = 0;
3612 -
3613 -       if (! proc_bus) {
3614 -               printk("i2c-core.o: /proc/bus/ does not exist");
3615 -               i2cproc_cleanup();
3616 -               return -ENOENT;
3617 -       } 
3618         proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
3619         if (!proc_bus_i2c) {
3620                 printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
3621 -               i2cproc_cleanup();
3622                 return -ENOENT;
3623         }
3624 +
3625         proc_bus_i2c->read_proc = &read_bus_i2c;
3626         proc_bus_i2c->owner = THIS_MODULE;
3627 -       i2cproc_initialized += 2;
3628         return 0;
3629  }
3630  
3631 -int i2cproc_cleanup(void)
3632 +static void __exit i2cproc_cleanup(void)
3633  {
3634 -
3635 -       if (i2cproc_initialized >= 1) {
3636 -               remove_proc_entry("i2c",proc_bus);
3637 -               i2cproc_initialized -= 2;
3638 -       }
3639 -       return 0;
3640 +       remove_proc_entry("i2c",proc_bus);
3641  }
3642  
3643 -
3644  #endif /* def CONFIG_PROC_FS */
3645  
3646  /* ----------------------------------------------------
3647 @@ -728,9 +683,9 @@
3648                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
3649                             adap->name,num));
3650  
3651 -               I2C_LOCK(adap);
3652 +               down(&adap->bus);
3653                 ret = adap->algo->master_xfer(adap,msgs,num);
3654 -               I2C_UNLOCK(adap);
3655 +               up(&adap->bus);
3656  
3657                 return ret;
3658         } else {
3659 @@ -755,9 +710,9 @@
3660                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
3661                         count,client->adapter->name));
3662         
3663 -               I2C_LOCK(adap);
3664 +               down(&adap->bus);
3665                 ret = adap->algo->master_xfer(adap,&msg,1);
3666 -               I2C_UNLOCK(adap);
3667 +               up(&adap->bus);
3668  
3669                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
3670                  * transmitted, else error code.
3671 @@ -785,9 +740,9 @@
3672                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
3673                         count,client->adapter->name));
3674         
3675 -               I2C_LOCK(adap);
3676 +               down(&adap->bus);
3677                 ret = adap->algo->master_xfer(adap,&msg,1);
3678 -               I2C_UNLOCK(adap);
3679 +               up(&adap->bus);
3680         
3681                 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
3682                         ret, count, client->addr));
3683 @@ -965,6 +920,123 @@
3684  
3685  /* The SMBus parts */
3686  
3687 +#define POLY    (0x1070U << 3) 
3688 +static u8
3689 +crc8(u16 data)
3690 +{
3691 +       int i;
3692 +  
3693 +       for(i = 0; i < 8; i++) {
3694 +               if (data & 0x8000) 
3695 +                       data = data ^ POLY;
3696 +               data = data << 1;
3697 +       }
3698 +       return (u8)(data >> 8);
3699 +}
3700 +
3701 +/* CRC over count bytes in the first array plus the bytes in the rest
3702 +   array if it is non-null. rest[0] is the (length of rest) - 1
3703 +   and is included. */
3704 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
3705 +{
3706 +       int i;
3707 +
3708 +       for(i = 0; i < count; i++)
3709 +               crc = crc8((crc ^ first[i]) << 8);
3710 +       if(rest != NULL)
3711 +               for(i = 0; i <= rest[0]; i++)
3712 +                       crc = crc8((crc ^ rest[i]) << 8);
3713 +       return crc;
3714 +}
3715 +
3716 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
3717 +{
3718 +       return i2c_smbus_partial_pec(0, count, first, rest);
3719 +}
3720 +
3721 +/* Returns new "size" (transaction type)
3722 +   Note that we convert byte to byte_data and byte_data to word_data
3723 +   rather than invent new xxx_PEC transactions. */
3724 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
3725 +                      union i2c_smbus_data *data)
3726 +{
3727 +       u8 buf[3];
3728 +
3729 +       buf[0] = addr << 1;
3730 +       buf[1] = command;
3731 +       switch(size) {
3732 +               case I2C_SMBUS_BYTE:
3733 +                       data->byte = i2c_smbus_pec(2, buf, NULL);
3734 +                       size = I2C_SMBUS_BYTE_DATA;
3735 +                       break;
3736 +               case I2C_SMBUS_BYTE_DATA:
3737 +                       buf[2] = data->byte;
3738 +                       data->word = buf[2] ||
3739 +                                   (i2c_smbus_pec(3, buf, NULL) << 8);
3740 +                       size = I2C_SMBUS_WORD_DATA;
3741 +                       break;
3742 +               case I2C_SMBUS_WORD_DATA:
3743 +                       /* unsupported */
3744 +                       break;
3745 +               case I2C_SMBUS_BLOCK_DATA:
3746 +                       data->block[data->block[0] + 1] =
3747 +                                    i2c_smbus_pec(2, buf, data->block);
3748 +                       size = I2C_SMBUS_BLOCK_DATA_PEC;
3749 +                       break;
3750 +       }
3751 +       return size;    
3752 +}
3753 +
3754 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
3755 +                        union i2c_smbus_data *data)
3756 +{
3757 +       u8 buf[3], rpec, cpec;
3758 +
3759 +       buf[1] = command;
3760 +       switch(size) {
3761 +               case I2C_SMBUS_BYTE_DATA:
3762 +                       buf[0] = (addr << 1) | 1;
3763 +                       cpec = i2c_smbus_pec(2, buf, NULL);
3764 +                       rpec = data->byte;
3765 +                       break;
3766 +               case I2C_SMBUS_WORD_DATA:
3767 +                       buf[0] = (addr << 1) | 1;
3768 +                       buf[2] = data->word & 0xff;
3769 +                       cpec = i2c_smbus_pec(3, buf, NULL);
3770 +                       rpec = data->word >> 8;
3771 +                       break;
3772 +               case I2C_SMBUS_WORD_DATA_PEC:
3773 +                       /* unsupported */
3774 +                       cpec = rpec = 0;
3775 +                       break;
3776 +               case I2C_SMBUS_PROC_CALL_PEC:
3777 +                       /* unsupported */
3778 +                       cpec = rpec = 0;
3779 +                       break;
3780 +               case I2C_SMBUS_BLOCK_DATA_PEC:
3781 +                       buf[0] = (addr << 1);
3782 +                       buf[2] = (addr << 1) | 1;
3783 +                       cpec = i2c_smbus_pec(3, buf, data->block);
3784 +                       rpec = data->block[data->block[0] + 1];
3785 +                       break;
3786 +               case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3787 +                       buf[0] = (addr << 1) | 1;
3788 +                       rpec = i2c_smbus_partial_pec(partial, 1,
3789 +                                                    buf, data->block);
3790 +                       cpec = data->block[data->block[0] + 1];
3791 +                       break;
3792 +               default:
3793 +                       cpec = rpec = 0;
3794 +                       break;
3795 +       }
3796 +       if(rpec != cpec) {
3797 +               DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
3798 +                          rpec, cpec));
3799 +               return -1;
3800 +       }
3801 +       return 0;       
3802 +}
3803 +
3804  extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
3805  {
3806         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3807 @@ -983,8 +1055,9 @@
3808  
3809  extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
3810  {
3811 +       union i2c_smbus_data data;      /* only for PEC */
3812         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3813 -                             I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
3814 +                             I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
3815  }
3816  
3817  extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
3818 @@ -1072,6 +1145,43 @@
3819                               I2C_SMBUS_BLOCK_DATA,&data);
3820  }
3821  
3822 +/* Returns the number of read bytes */
3823 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
3824 +                                        u8 command, u8 length, u8 *values)
3825 +{
3826 +       union i2c_smbus_data data;
3827 +       int i;
3828 +       if (length > I2C_SMBUS_BLOCK_MAX - 1)
3829 +               return -1;
3830 +       data.block[0] = length;
3831 +       for (i = 1; i <= length; i++)
3832 +               data.block[i] = values[i-1];
3833 +       if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3834 +                         I2C_SMBUS_WRITE, command,
3835 +                         I2C_SMBUS_BLOCK_PROC_CALL, &data))
3836 +               return -1;
3837 +       for (i = 1; i <= data.block[0]; i++)
3838 +               values[i-1] = data.block[i];
3839 +       return data.block[0];
3840 +}
3841 +
3842 +/* Returns the number of read bytes */
3843 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
3844 +                                         u8 command, u8 *values)
3845 +{
3846 +       union i2c_smbus_data data;
3847 +       int i;
3848 +       if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3849 +                             I2C_SMBUS_READ,command,
3850 +                             I2C_SMBUS_I2C_BLOCK_DATA,&data))
3851 +               return -1;
3852 +       else {
3853 +               for (i = 1; i <= data.block[0]; i++)
3854 +                       values[i-1] = data.block[i];
3855 +               return data.block[0];
3856 +       }
3857 +}
3858 +
3859  extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
3860                                            u8 command, u8 length, u8 *values)
3861  {
3862 @@ -1098,13 +1208,13 @@
3863           need to use only one message; when reading, we need two. We initialize
3864           most things with sane defaults, to keep the code below somewhat
3865           simpler. */
3866 -       unsigned char msgbuf0[34];
3867 -       unsigned char msgbuf1[34];
3868 +       unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+2];
3869 +       unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
3870         int num = read_write == I2C_SMBUS_READ?2:1;
3871         struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 
3872                                   { addr, flags | I2C_M_RD, 0, msgbuf1 }
3873                                 };
3874 -       int i;
3875 +       int i, len;
3876  
3877         msgbuf0[0] = command;
3878         switch(size) {
3879 @@ -1140,16 +1250,30 @@
3880                 break;
3881         case I2C_SMBUS_PROC_CALL:
3882                 num = 2; /* Special case */
3883 +               read_write = I2C_SMBUS_READ;
3884                 msg[0].len = 3;
3885                 msg[1].len = 2;
3886                 msgbuf0[1] = data->word & 0xff;
3887                 msgbuf0[2] = (data->word >> 8) & 0xff;
3888                 break;
3889         case I2C_SMBUS_BLOCK_DATA:
3890 +       case I2C_SMBUS_BLOCK_DATA_PEC:
3891                 if (read_write == I2C_SMBUS_READ) {
3892 -                       printk(KERN_ERR "i2c-core.o: Block read not supported "
3893 -                              "under I2C emulation!\n");
3894 -                       return -1;
3895 +                       /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_READ_BLOCK_DATA */
3896 +                       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
3897 +                               printk(KERN_ERR "i2c-core.o: Block read not supported "
3898 +                                      "under I2C emulation!\n");
3899 +                               return -1;
3900 +                       }
3901 +                       /* set send message */
3902 +                       msg[0].len = 1;
3903 +                       /* set recv message */
3904 +                       msg[1].flags |= I2C_M_RECV_LEN;
3905 +                       msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
3906 +                       if (size == I2C_SMBUS_BLOCK_DATA_PEC) {
3907 +                               msg[1].len++;
3908 +                               msg[1].flags |= I2C_M_RECV_PEC;
3909 +                       }
3910                 } else {
3911                         msg[0].len = data->block[0] + 2;
3912                         if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
3913 @@ -1158,10 +1282,57 @@
3914                                        data->block[0]);
3915                                 return -1;
3916                         }
3917 +                       if(size == I2C_SMBUS_BLOCK_DATA_PEC)
3918 +                               (msg[0].len)++;
3919                         for (i = 1; i <= msg[0].len; i++)
3920                                 msgbuf0[i] = data->block[i-1];
3921                 }
3922                 break;
3923 +       case I2C_SMBUS_BLOCK_PROC_CALL:
3924 +       case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3925 +               /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_BLOCK_PROC_CALL */
3926 +               if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_PROC_CALL)) {
3927 +                       printk(KERN_ERR "i2c-core.o: adapter doesn't support block process call!\n");
3928 +                       return -1;
3929 +               }
3930 +
3931 +               /* Another special case */
3932 +               num = 2;
3933 +               read_write = I2C_SMBUS_READ;
3934 +               
3935 +               /* set send message */
3936 +               msg[0].len = data->block[0] + 2;
3937 +               if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
3938 +                       printk(KERN_ERR "i2c-core.o: smbus_access called with "
3939 +                               "invalid block write size (%d)\n", data->block[0]);
3940 +                       return -1;
3941 +               }
3942 +               for (i = 1; i <= msg[0].len; i++)
3943 +                       msgbuf0[i] = data->block[i-1];
3944 +               
3945 +               /* set recv message */
3946 +               msg[1].flags |= I2C_M_RECV_LEN;
3947 +               msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
3948 +               if (size == I2C_SMBUS_BLOCK_PROC_CALL_PEC) {
3949 +                       msg[1].len++;
3950 +                       msg[1].flags |= I2C_M_RECV_PEC;
3951 +               }
3952 +               break;
3953 +       case I2C_SMBUS_I2C_BLOCK_DATA:
3954 +               if (read_write == I2C_SMBUS_READ) {
3955 +                       msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
3956 +               } else {
3957 +                       msg[0].len = data->block[0] + 1;
3958 +                       if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
3959 +                               printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
3960 +                                      "invalid block write size (%d)\n",
3961 +                                      data->block[0]);
3962 +                               return -1;
3963 +                       }
3964 +                       for (i = 1; i <= data->block[0]; i++)
3965 +                               msgbuf0[i] = data->block[i];
3966 +               }
3967 +               break;
3968         default:
3969                 printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
3970                        size);
3971 @@ -1183,25 +1354,72 @@
3972                         case I2C_SMBUS_PROC_CALL:
3973                                 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
3974                                 break;
3975 +                       case I2C_SMBUS_I2C_BLOCK_DATA:
3976 +                               /* fixed at 32 for now */
3977 +                               data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
3978 +                               for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
3979 +                                       data->block[i+1] = msgbuf1[i];
3980 +                               break;
3981 +                       case I2C_SMBUS_BLOCK_DATA:
3982 +                       case I2C_SMBUS_BLOCK_PROC_CALL:
3983 +                       case I2C_SMBUS_BLOCK_DATA_PEC:
3984 +                       case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3985 +                               len = msgbuf1[0] + 1;
3986 +                               if(size == I2C_SMBUS_BLOCK_DATA_PEC ||
3987 +                                  size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)
3988 +                                       len++;
3989 +                               for (i = 0; i < len; i++)
3990 +                                       data->block[i] = msgbuf1[i];
3991 +                               break;
3992                 }
3993         return 0;
3994  }
3995  
3996  
3997 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
3998 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
3999                     char read_write, u8 command, int size, 
4000                     union i2c_smbus_data * data)
4001  {
4002         s32 res;
4003 -       flags = flags & I2C_M_TEN;
4004 -       if (adapter->algo->smbus_xfer) {
4005 -               I2C_LOCK(adapter);
4006 -               res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4007 +       int swpec = 0;
4008 +       u8 partial = 0;
4009 +
4010 +       flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4011 +       if((flags & I2C_CLIENT_PEC) &&
4012 +          !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4013 +               swpec = 1;
4014 +               if(read_write == I2C_SMBUS_READ &&
4015 +                  size == I2C_SMBUS_BLOCK_DATA)
4016 +                       size = I2C_SMBUS_BLOCK_DATA_PEC;
4017 +               else if(size == I2C_SMBUS_PROC_CALL)
4018 +                       size = I2C_SMBUS_PROC_CALL_PEC;
4019 +               else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
4020 +                       i2c_smbus_add_pec(addr, command,
4021 +                                         I2C_SMBUS_BLOCK_DATA, data);
4022 +                       partial = data->block[data->block[0] + 1];
4023 +                       size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
4024 +               } else if(read_write == I2C_SMBUS_WRITE &&
4025 +                         size != I2C_SMBUS_QUICK &&
4026 +                         size != I2C_SMBUS_I2C_BLOCK_DATA)
4027 +                       size = i2c_smbus_add_pec(addr, command, size, data);
4028 +       }
4029 +
4030 +       if (adap->algo->smbus_xfer) {
4031 +               down(&adap->bus);
4032 +               res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
4033                                                 command,size,data);
4034 -               I2C_UNLOCK(adapter);
4035 +               up(&adap->bus);
4036         } else
4037 -               res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
4038 +               res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
4039                                               command,size,data);
4040 +
4041 +       if(res >= 0 && swpec &&
4042 +          size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
4043 +          (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
4044 +           size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
4045 +               if(i2c_smbus_check_pec(addr, command, size, partial, data))
4046 +                       return -1;
4047 +       }
4048         return res;
4049  }
4050  
4051 @@ -1228,136 +1446,37 @@
4052         printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4053         memset(adapters,0,sizeof(adapters));
4054         memset(drivers,0,sizeof(drivers));
4055 -       adap_count=0;
4056 -       driver_count=0;
4057  
4058 -       init_MUTEX(&adap_lock);
4059 -       init_MUTEX(&driver_lock);
4060 -       
4061 -       i2cproc_init();
4062 -       
4063 +#ifdef CONFIG_PROC_FS
4064 +       return i2cproc_init();
4065 +#else
4066         return 0;
4067 -}
4068 -
4069 -#ifndef MODULE
4070 -#ifdef CONFIG_I2C_CHARDEV
4071 -       extern int i2c_dev_init(void);
4072 -#endif
4073 -#ifdef CONFIG_I2C_ALGOBIT
4074 -       extern int i2c_algo_bit_init(void);
4075 -#endif
4076 -#ifdef CONFIG_I2C_PHILIPSPAR
4077 -       extern int i2c_bitlp_init(void);
4078 -#endif
4079 -#ifdef CONFIG_I2C_ELV
4080 -       extern int i2c_bitelv_init(void);
4081 -#endif
4082 -#ifdef CONFIG_I2C_VELLEMAN
4083 -       extern int i2c_bitvelle_init(void);
4084 -#endif
4085 -#ifdef CONFIG_I2C_BITVIA
4086 -       extern int i2c_bitvia_init(void);
4087 -#endif
4088 -
4089 -#ifdef CONFIG_I2C_ALGOPCF
4090 -       extern int i2c_algo_pcf_init(void);     
4091 -#endif
4092 -#ifdef CONFIG_I2C_ELEKTOR
4093 -       extern int i2c_pcfisa_init(void);
4094 -#endif
4095 -
4096 -#ifdef CONFIG_I2C_ALGO8XX
4097 -       extern int i2c_algo_8xx_init(void);
4098 -#endif
4099 -#ifdef CONFIG_I2C_RPXLITE
4100 -       extern int i2c_rpx_init(void);
4101 -#endif
4102 -
4103 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4104 -       extern int i2c_algo_sibyte_init(void);
4105 -       extern int i2c_sibyte_init(void);
4106 -#endif
4107 -#ifdef CONFIG_I2C_MAX1617
4108 -       extern int i2c_max1617_init(void);
4109  #endif
4110 +}
4111  
4112 -#ifdef CONFIG_I2C_PROC
4113 -       extern int sensors_init(void);
4114 +static void __exit i2c_exit(void) 
4115 +{
4116 +#ifdef CONFIG_PROC_FS
4117 +       i2cproc_cleanup();
4118  #endif
4119 +}
4120  
4121 -/* This is needed for automatic patch generation: sensors code starts here */
4122 -/* This is needed for automatic patch generation: sensors code ends here   */
4123 -
4124 +/* leave this in for now simply to make patching easier so we don't have
4125 +   to remove the call in drivers/char/mem.c */
4126  int __init i2c_init_all(void)
4127  {
4128 -       /* --------------------- global ----- */
4129 -       i2c_init();
4130 -
4131 -#ifdef CONFIG_I2C_CHARDEV
4132 -       i2c_dev_init();
4133 -#endif
4134 -       /* --------------------- bit -------- */
4135 -#ifdef CONFIG_I2C_ALGOBIT
4136 -       i2c_algo_bit_init();
4137 -#endif
4138 -#ifdef CONFIG_I2C_PHILIPSPAR
4139 -       i2c_bitlp_init();
4140 -#endif
4141 -#ifdef CONFIG_I2C_ELV
4142 -       i2c_bitelv_init();
4143 -#endif
4144 -#ifdef CONFIG_I2C_VELLEMAN
4145 -       i2c_bitvelle_init();
4146 -#endif
4147 -
4148 -       /* --------------------- pcf -------- */
4149 -#ifdef CONFIG_I2C_ALGOPCF
4150 -       i2c_algo_pcf_init();    
4151 -#endif
4152 -#ifdef CONFIG_I2C_ELEKTOR
4153 -       i2c_pcfisa_init();
4154 -#endif
4155 -
4156 -       /* --------------------- 8xx -------- */
4157 -#ifdef CONFIG_I2C_ALGO8XX
4158 -       i2c_algo_8xx_init();
4159 -#endif
4160 -#ifdef CONFIG_I2C_RPXLITE
4161 -       i2c_rpx_init();
4162 -#endif
4163 -
4164 -       /* --------------------- SiByte -------- */
4165 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4166 -       i2c_algo_sibyte_init();
4167 -       i2c_sibyte_init();
4168 -#endif
4169 -#ifdef CONFIG_I2C_MAX1617
4170 -       i2c_max1617_init();
4171 -#endif
4172 -
4173 -       /* -------------- proc interface ---- */
4174 -#ifdef CONFIG_I2C_PROC
4175 -       sensors_init();
4176 -#endif
4177 -/* This is needed for automatic patch generation: sensors code starts here */
4178 -/* This is needed for automatic patch generation: sensors code ends here */
4179 -
4180         return 0;
4181  }
4182  
4183 -#endif
4184 -
4185 -
4186 -
4187  EXPORT_SYMBOL(i2c_add_adapter);
4188  EXPORT_SYMBOL(i2c_del_adapter);
4189  EXPORT_SYMBOL(i2c_add_driver);
4190  EXPORT_SYMBOL(i2c_del_driver);
4191  EXPORT_SYMBOL(i2c_attach_client);
4192  EXPORT_SYMBOL(i2c_detach_client);
4193 -EXPORT_SYMBOL(i2c_inc_use_client);
4194 -EXPORT_SYMBOL(i2c_dec_use_client);
4195 +#if 0
4196  EXPORT_SYMBOL(i2c_get_client);
4197 +#endif
4198  EXPORT_SYMBOL(i2c_use_client);
4199  EXPORT_SYMBOL(i2c_release_client);
4200  EXPORT_SYMBOL(i2c_check_addr);
4201 @@ -1381,11 +1500,12 @@
4202  EXPORT_SYMBOL(i2c_smbus_process_call);
4203  EXPORT_SYMBOL(i2c_smbus_read_block_data);
4204  EXPORT_SYMBOL(i2c_smbus_write_block_data);
4205 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
4206 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
4207  
4208  EXPORT_SYMBOL(i2c_get_functionality);
4209  EXPORT_SYMBOL(i2c_check_functionality);
4210  
4211 -#ifdef MODULE
4212  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4213  MODULE_DESCRIPTION("I2C-Bus main module");
4214  MODULE_LICENSE("GPL");
4215 @@ -1393,13 +1513,5 @@
4216  MODULE_PARM(i2c_debug, "i");
4217  MODULE_PARM_DESC(i2c_debug,"debug level");
4218  
4219 -int init_module(void) 
4220 -{
4221 -       return i2c_init();
4222 -}
4223 -
4224 -void cleanup_module(void) 
4225 -{
4226 -       i2cproc_cleanup();
4227 -}
4228 -#endif
4229 +module_init(i2c_init);
4230 +module_exit(i2c_exit);
4231 diff -urN linux-2.4.24.org/drivers/i2c/i2c-dev.c linux-2.4.24/drivers/i2c/i2c-dev.c
4232 --- linux-2.4.24.org/drivers/i2c/i2c-dev.c      2004-02-04 22:33:47.320044595 +0100
4233 +++ linux-2.4.24/drivers/i2c/i2c-dev.c  2004-02-04 22:36:36.672827404 +0100
4234 @@ -28,9 +28,8 @@
4235  /* The devfs code is contributed by Philipp Matthias Hahn 
4236     <pmhahn@titan.lahn.de> */
4237  
4238 -/* $Id$ */
4239 +/* $Id$ */
4240  
4241 -#include <linux/config.h>
4242  #include <linux/kernel.h>
4243  #include <linux/module.h>
4244  #include <linux/fs.h>
4245 @@ -39,21 +38,14 @@
4246  #ifdef CONFIG_DEVFS_FS
4247  #include <linux/devfs_fs_kernel.h>
4248  #endif
4249 -
4250 -
4251 -/* If you want debugging uncomment: */
4252 -/* #define DEBUG */
4253 -
4254  #include <linux/init.h>
4255 -#include <asm/uaccess.h>
4256 -
4257  #include <linux/i2c.h>
4258  #include <linux/i2c-dev.h>
4259 +#include <asm/uaccess.h>
4260 +
4261 +/* If you want debugging uncomment: */
4262 +/* #define DEBUG */
4263  
4264 -#ifdef MODULE
4265 -extern int init_module(void);
4266 -extern int cleanup_module(void);
4267 -#endif /* def MODULE */
4268  
4269  /* struct file_operations changed too often in the 2.1 series for nice code */
4270  
4271 @@ -73,22 +65,14 @@
4272  static int i2cdev_command(struct i2c_client *client, unsigned int cmd,
4273                             void *arg);
4274  
4275 -#ifdef MODULE
4276 -static
4277 -#else
4278 -extern
4279 -#endif
4280 -       int __init i2c_dev_init(void);
4281 -static int i2cdev_cleanup(void);
4282 -
4283  static struct file_operations i2cdev_fops = {
4284 -       owner:          THIS_MODULE,
4285 -       llseek:         no_llseek,
4286 -       read:           i2cdev_read,
4287 -       write:          i2cdev_write,
4288 -       ioctl:          i2cdev_ioctl,
4289 -       open:           i2cdev_open,
4290 -       release:        i2cdev_release,
4291 +       .owner          = THIS_MODULE,
4292 +       .llseek         = no_llseek,
4293 +       .read           = i2cdev_read,
4294 +       .write          = i2cdev_write,
4295 +       .ioctl          = i2cdev_ioctl,
4296 +       .open           = i2cdev_open,
4297 +       .release        = i2cdev_release,
4298  };
4299  
4300  #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
4301 @@ -99,28 +83,22 @@
4302  #endif
4303  
4304  static struct i2c_driver i2cdev_driver = {
4305 -       name:           "i2c-dev dummy driver",
4306 -       id:             I2C_DRIVERID_I2CDEV,
4307 -       flags:          I2C_DF_DUMMY,
4308 -       attach_adapter: i2cdev_attach_adapter,
4309 -       detach_client:  i2cdev_detach_client,
4310 -       command:        i2cdev_command,
4311 -/*     inc_use:        NULL,
4312 -       dec_use:        NULL, */
4313 +       .owner          = THIS_MODULE, /* not really used */
4314 +       .name           = "i2c-dev dummy driver",
4315 +       .id             = I2C_DRIVERID_I2CDEV,
4316 +       .flags          = I2C_DF_DUMMY,
4317 +       .attach_adapter = i2cdev_attach_adapter,
4318 +       .detach_client  = i2cdev_detach_client,
4319 +       .command        = i2cdev_command,
4320  };
4321  
4322  static struct i2c_client i2cdev_client_template = {
4323 -       name:           "I2C /dev entry",
4324 -       id:             1,
4325 -       flags:          0,
4326 -       addr:           -1,
4327 -/*     adapter:        NULL, */
4328 -       driver:         &i2cdev_driver,
4329 -/*     data:           NULL */
4330 +       .name           = "I2C /dev entry",
4331 +       .id             = 1,
4332 +       .addr           = -1,
4333 +       .driver         = &i2cdev_driver,
4334  };
4335  
4336 -static int i2cdev_initialized;
4337 -
4338  static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
4339                              loff_t *offset)
4340  {
4341 @@ -142,7 +120,7 @@
4342                 return -ENOMEM;
4343  
4344  #ifdef DEBUG
4345 -       printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
4346 +       printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
4347                count);
4348  #endif
4349  
4350 @@ -177,7 +155,7 @@
4351         }
4352  
4353  #ifdef DEBUG
4354 -       printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
4355 +       printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
4356                count);
4357  #endif
4358         ret = i2c_master_send(client,tmp,count);
4359 @@ -199,7 +177,7 @@
4360  
4361  #ifdef DEBUG
4362         printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", 
4363 -              MINOR(inode->i_rdev),cmd, arg);
4364 +              minor(inode->i_rdev),cmd, arg);
4365  #endif /* DEBUG */
4366  
4367         switch ( cmd ) {
4368 @@ -218,6 +196,12 @@
4369                 else
4370                         client->flags &= ~I2C_M_TEN;
4371                 return 0;
4372 +       case I2C_PEC:
4373 +               if (arg)
4374 +                       client->flags |= I2C_CLIENT_PEC;
4375 +               else
4376 +                       client->flags &= ~I2C_CLIENT_PEC;
4377 +               return 0;
4378         case I2C_FUNCS:
4379                 funcs = i2c_get_functionality(client->adapter);
4380                 return (copy_to_user((unsigned long *)arg,&funcs,
4381 @@ -318,7 +302,8 @@
4382                     (data_arg.size != I2C_SMBUS_WORD_DATA) &&
4383                     (data_arg.size != I2C_SMBUS_PROC_CALL) &&
4384                     (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
4385 -                   (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
4386 +                   (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
4387 +                   (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
4388  #ifdef DEBUG
4389                         printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
4390                                data_arg.size);
4391 @@ -361,10 +346,11 @@
4392                 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || 
4393                          (data_arg.size == I2C_SMBUS_PROC_CALL))
4394                         datasize = sizeof(data_arg.data->word);
4395 -               else /* size == I2C_SMBUS_BLOCK_DATA */
4396 +               else /* size == smbus block, i2c block, or block proc. call */
4397                         datasize = sizeof(data_arg.data->block);
4398  
4399                 if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 
4400 +                   (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 
4401                     (data_arg.read_write == I2C_SMBUS_WRITE)) {
4402                         if (copy_from_user(&temp, data_arg.data, datasize))
4403                                 return -EFAULT;
4404 @@ -373,6 +359,7 @@
4405                       data_arg.read_write,
4406                       data_arg.command,data_arg.size,&temp);
4407                 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || 
4408 +                             (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 
4409                               (data_arg.read_write == I2C_SMBUS_READ))) {
4410                         if (copy_to_user(data_arg.data, &temp, datasize))
4411                                 return -EFAULT;
4412 @@ -387,7 +374,7 @@
4413  
4414  int i2cdev_open (struct inode *inode, struct file *file)
4415  {
4416 -       unsigned int minor = MINOR(inode->i_rdev);
4417 +       unsigned int minor = minor(inode->i_rdev);
4418         struct i2c_client *client;
4419  
4420         if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
4421 @@ -403,11 +390,13 @@
4422         if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
4423                 return -ENOMEM;
4424         memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
4425 +
4426 +       /* registered with adapter, passed as client to user */
4427         client->adapter = i2cdev_adaps[minor];
4428         file->private_data = client;
4429  
4430 -       if (i2cdev_adaps[minor]->inc_use)
4431 -               i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
4432 +       if(client->adapter->owner)
4433 +               __MOD_INC_USE_COUNT(client->adapter->owner);
4434  
4435  #ifdef DEBUG
4436         printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
4437 @@ -417,16 +406,19 @@
4438  
4439  static int i2cdev_release (struct inode *inode, struct file *file)
4440  {
4441 -       unsigned int minor = MINOR(inode->i_rdev);
4442 -       kfree(file->private_data);
4443 -       file->private_data=NULL;
4444 +       struct i2c_client *client;
4445 +#ifdef DEBUG
4446 +       unsigned int minor = minor(inode->i_rdev);
4447 +#endif
4448 +
4449 +       client = file->private_data;
4450 +       file->private_data = NULL;
4451 +       if(client->adapter->owner)
4452 +               __MOD_DEC_USE_COUNT(client->adapter->owner);
4453 +       kfree(client);
4454  #ifdef DEBUG
4455         printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
4456  #endif
4457 -       lock_kernel();
4458 -       if (i2cdev_adaps[minor]->dec_use)
4459 -               i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
4460 -       unlock_kernel();
4461         return 0;
4462  }
4463  
4464 @@ -451,7 +443,7 @@
4465                 devfs_i2c[i] = devfs_register (devfs_handle, name,
4466                         DEVFS_FL_DEFAULT, I2C_MAJOR, i,
4467                         S_IFCHR | S_IRUSR | S_IWUSR,
4468 -                       &i2cdev_fops, NULL);
4469 +                       &i2cdev_fops, adap);
4470  #endif
4471                 printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
4472         } else {
4473 @@ -479,13 +471,12 @@
4474         return -1;
4475  }
4476  
4477 -int __init i2c_dev_init(void)
4478 +static int __init i2c_dev_init(void)
4479  {
4480         int res;
4481  
4482         printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4483  
4484 -       i2cdev_initialized = 0;
4485  #ifdef CONFIG_DEVFS_FS
4486         if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
4487  #else
4488 @@ -498,63 +489,31 @@
4489  #ifdef CONFIG_DEVFS_FS
4490         devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
4491  #endif
4492 -       i2cdev_initialized ++;
4493 -
4494         if ((res = i2c_add_driver(&i2cdev_driver))) {
4495                 printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
4496 -               i2cdev_cleanup();
4497 +#ifdef CONFIG_DEVFS_FS
4498 +               devfs_unregister(devfs_handle);
4499 +#endif
4500 +               unregister_chrdev(I2C_MAJOR,"i2c");
4501                 return res;
4502         }
4503 -       i2cdev_initialized ++;
4504         return 0;
4505  }
4506  
4507 -int i2cdev_cleanup(void)
4508 +static void __exit i2c_dev_exit(void)
4509  {
4510 -       int res;
4511 -
4512 -       if (i2cdev_initialized >= 2) {
4513 -               if ((res = i2c_del_driver(&i2cdev_driver))) {
4514 -                       printk("i2c-dev.o: Driver deregistration failed, "
4515 -                              "module not removed.\n");
4516 -                       return res;
4517 -               }
4518 -       i2cdev_initialized --;
4519 -       }
4520 -
4521 -       if (i2cdev_initialized >= 1) {
4522 +       i2c_del_driver(&i2cdev_driver);
4523  #ifdef CONFIG_DEVFS_FS
4524 -               devfs_unregister(devfs_handle);
4525 -               if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
4526 -#else
4527 -               if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
4528 +       devfs_unregister(devfs_handle);
4529  #endif
4530 -                       printk("i2c-dev.o: unable to release major %d for i2c bus\n",
4531 -                              I2C_MAJOR);
4532 -                       return res;
4533 -               }
4534 -               i2cdev_initialized --;
4535 -       }
4536 -       return 0;
4537 +       unregister_chrdev(I2C_MAJOR,"i2c");
4538  }
4539  
4540  EXPORT_NO_SYMBOLS;
4541  
4542 -#ifdef MODULE
4543 -
4544  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4545  MODULE_DESCRIPTION("I2C /dev entries driver");
4546  MODULE_LICENSE("GPL");
4547  
4548 -int init_module(void)
4549 -{
4550 -       return i2c_dev_init();
4551 -}
4552 -
4553 -int cleanup_module(void)
4554 -{
4555 -       return i2cdev_cleanup();
4556 -}
4557 -
4558 -#endif /* def MODULE */
4559 -
4560 +module_init(i2c_dev_init);
4561 +module_exit(i2c_dev_exit);
4562 diff -urN linux-2.4.24.org/drivers/i2c/i2c-elektor.c linux-2.4.24/drivers/i2c/i2c-elektor.c
4563 --- linux-2.4.24.org/drivers/i2c/i2c-elektor.c  2004-02-04 22:33:47.601985965 +0100
4564 +++ linux-2.4.24/drivers/i2c/i2c-elektor.c      2004-02-04 22:36:36.682825325 +0100
4565 @@ -31,23 +31,22 @@
4566  #include <linux/delay.h>
4567  #include <linux/slab.h>
4568  #include <linux/init.h>
4569 +#include <linux/interrupt.h>
4570  #include <linux/pci.h>
4571 -#include <asm/irq.h>
4572 -#include <asm/io.h>
4573 -
4574 +#include <linux/wait.h>
4575  #include <linux/i2c.h>
4576  #include <linux/i2c-algo-pcf.h>
4577 -#include <linux/i2c-elektor.h>
4578 -#include "i2c-pcf8584.h"
4579 +#include <asm/io.h>
4580 +#include <asm/irq.h>
4581  
4582  #define DEFAULT_BASE 0x330
4583  
4584 -static int base   = 0;
4585 -static int irq    = 0;
4586 +static int base;
4587 +static int irq;
4588  static int clock  = 0x1c;
4589  static int own    = 0x55;
4590 -static int mmapped = 0;
4591 -static int i2c_debug = 0;
4592 +static int mmapped;
4593 +static int i2c_debug;
4594  
4595  /* vdovikin: removed static struct i2c_pcf_isa gpi; code - 
4596    this module in real supports only one device, due to missing arguments
4597 @@ -56,6 +55,7 @@
4598  
4599  static wait_queue_head_t pcf_wait;
4600  static int pcf_pending;
4601 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
4602  
4603  /* ----- global defines -----------------------------------------------        */
4604  #define DEB(x) if (i2c_debug>=1) x
4605 @@ -63,13 +63,24 @@
4606  #define DEB3(x) if (i2c_debug>=3) x
4607  #define DEBE(x)        x       /* error messages                               */
4608  
4609 +
4610 +/* compatibility */
4611 +#ifndef isa_readb
4612 +#define isa_readb readb
4613 +#endif
4614 +
4615 +#ifndef isa_writeb
4616 +#define isa_writeb writeb
4617 +#endif
4618 +
4619  /* ----- local functions ----------------------------------------------        */
4620  
4621  static void pcf_isa_setbyte(void *data, int ctl, int val)
4622  {
4623         int address = ctl ? (base + 1) : base;
4624  
4625 -       if (ctl && irq) {
4626 +       /* enable irq if any specified for serial operation */
4627 +       if (ctl && irq && (val & I2C_PCF_ESO)) {
4628                 val |= I2C_PCF_ENI;
4629         }
4630  
4631 @@ -81,10 +92,10 @@
4632                 break;
4633         case 2: /* double mapped I/O needed for UP2000 board,
4634                     I don't know why this... */
4635 -               writeb(val, address);
4636 +               isa_writeb(val, address);
4637                 /* fall */
4638         case 1: /* memory mapped I/O */
4639 -               writeb(val, address);
4640 +               isa_writeb(val, address);
4641                 break;
4642         }
4643  }
4644 @@ -92,7 +103,7 @@
4645  static int pcf_isa_getbyte(void *data, int ctl)
4646  {
4647         int address = ctl ? (base + 1) : base;
4648 -       int val = mmapped ? readb(address) : inb(address);
4649 +       int val = mmapped ? isa_readb(address) : inb(address);
4650  
4651         DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
4652  
4653 @@ -115,12 +126,12 @@
4654         int timeout = 2;
4655  
4656         if (irq > 0) {
4657 -               cli();
4658 +               spin_lock_irq(&irq_driver_lock);
4659                 if (pcf_pending == 0) {
4660                         interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
4661                 } else
4662                         pcf_pending = 0;
4663 -               sti();
4664 +               spin_unlock_irq(&irq_driver_lock);
4665         } else {
4666                 udelay(100);
4667         }
4668 @@ -136,13 +147,11 @@
4669  static int pcf_isa_init(void)
4670  {
4671         if (!mmapped) {
4672 -               if (check_region(base, 2) < 0 ) {
4673 +               if (!request_region(base, 2, "i2c (isa bus adapter)")) {
4674                         printk(KERN_ERR
4675                                "i2c-elektor.o: requested I/O region (0x%X:2) "
4676                                "is in use.\n", base);
4677                         return -ENODEV;
4678 -               } else {
4679 -                       request_region(base, 2, "i2c (isa bus adapter)");
4680                 }
4681         }
4682         if (irq > 0) {
4683 @@ -156,70 +165,29 @@
4684  }
4685  
4686  
4687 -static void __exit pcf_isa_exit(void)
4688 -{
4689 -       if (irq > 0) {
4690 -               disable_irq(irq);
4691 -               free_irq(irq, 0);
4692 -       }
4693 -       if (!mmapped) {
4694 -               release_region(base , 2);
4695 -       }
4696 -}
4697 -
4698 -
4699 -static int pcf_isa_reg(struct i2c_client *client)
4700 -{
4701 -       return 0;
4702 -}
4703 -
4704 -
4705 -static int pcf_isa_unreg(struct i2c_client *client)
4706 -{
4707 -       return 0;
4708 -}
4709 -
4710 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
4711 -{
4712 -#ifdef MODULE
4713 -       MOD_INC_USE_COUNT;
4714 -#endif
4715 -}
4716 -
4717 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
4718 -{
4719 -#ifdef MODULE
4720 -       MOD_DEC_USE_COUNT;
4721 -#endif
4722 -}
4723 -
4724 -
4725  /* ------------------------------------------------------------------------
4726   * Encapsulate the above functions in the correct operations structure.
4727   * This is only done when more than one hardware adapter is supported.
4728   */
4729  static struct i2c_algo_pcf_data pcf_isa_data = {
4730 -       NULL,
4731 -       pcf_isa_setbyte,
4732 -       pcf_isa_getbyte,
4733 -       pcf_isa_getown,
4734 -       pcf_isa_getclock,
4735 -       pcf_isa_waitforpin,
4736 -       10, 10, 100,            /*      waits, timeout */
4737 +       .setpcf     = pcf_isa_setbyte,
4738 +       .getpcf     = pcf_isa_getbyte,
4739 +       .getown     = pcf_isa_getown,
4740 +       .getclock   = pcf_isa_getclock,
4741 +       .waitforpin = pcf_isa_waitforpin,
4742 +       .udelay     = 10,
4743 +       .mdelay     = 10,
4744 +       .timeout    = HZ,
4745  };
4746  
4747  static struct i2c_adapter pcf_isa_ops = {
4748 -       "PCF8584 ISA adapter",
4749 -       I2C_HW_P_ELEK,
4750 -       NULL,
4751 -       &pcf_isa_data,
4752 -       pcf_isa_inc_use,
4753 -       pcf_isa_dec_use,
4754 -       pcf_isa_reg,
4755 -       pcf_isa_unreg,
4756 +       .owner             = THIS_MODULE,
4757 +       .name              = "PCF8584 ISA adapter",
4758 +       .id                = I2C_HW_P_ELEK,
4759 +       .algo_data         = &pcf_isa_data,
4760  };
4761  
4762 -int __init i2c_pcfisa_init(void) 
4763 +static int __init i2c_pcfisa_init(void) 
4764  {
4765  #ifdef __alpha__
4766         /* check to see we have memory mapped PCF8584 connected to the 
4767 @@ -277,22 +245,41 @@
4768         }
4769  
4770         init_waitqueue_head(&pcf_wait);
4771 -       if (pcf_isa_init() == 0) {
4772 -               if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
4773 -                       return -ENODEV;
4774 -       } else {
4775 +       if (pcf_isa_init())
4776                 return -ENODEV;
4777 -       }
4778 +       if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
4779 +               goto fail;
4780         
4781         printk(KERN_DEBUG "i2c-elektor.o: found device at %#x.\n", base);
4782  
4783         return 0;
4784 +
4785 + fail:
4786 +       if (irq > 0) {
4787 +               disable_irq(irq);
4788 +               free_irq(irq, 0);
4789 +       }
4790 +
4791 +       if (!mmapped)
4792 +               release_region(base , 2);
4793 +       return -ENODEV;
4794  }
4795  
4796 +static void __exit i2c_pcfisa_exit(void)
4797 +{
4798 +       i2c_pcf_del_bus(&pcf_isa_ops);
4799 +
4800 +       if (irq > 0) {
4801 +               disable_irq(irq);
4802 +               free_irq(irq, 0);
4803 +       }
4804 +
4805 +       if (!mmapped)
4806 +               release_region(base , 2);
4807 +}
4808  
4809  EXPORT_NO_SYMBOLS;
4810  
4811 -#ifdef MODULE
4812  MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
4813  MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
4814  MODULE_LICENSE("GPL");
4815 @@ -304,15 +291,5 @@
4816  MODULE_PARM(mmapped, "i");
4817  MODULE_PARM(i2c_debug, "i");
4818  
4819 -int init_module(void) 
4820 -{
4821 -       return i2c_pcfisa_init();
4822 -}
4823 -
4824 -void cleanup_module(void) 
4825 -{
4826 -       i2c_pcf_del_bus(&pcf_isa_ops);
4827 -       pcf_isa_exit();
4828 -}
4829 -
4830 -#endif
4831 +module_init(i2c_pcfisa_init);
4832 +module_exit(i2c_pcfisa_exit);
4833 diff -urN linux-2.4.24.org/drivers/i2c/i2c-elv.c linux-2.4.24/drivers/i2c/i2c-elv.c
4834 --- linux-2.4.24.org/drivers/i2c/i2c-elv.c      2004-02-04 22:33:47.624981184 +0100
4835 +++ linux-2.4.24/drivers/i2c/i2c-elv.c  2004-02-04 22:36:36.688824077 +0100
4836 @@ -21,21 +21,18 @@
4837  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
4838     Frodo Looijaard <frodol@dds.nl> */
4839  
4840 -/* $Id$ */
4841 +/* $Id$ */
4842  
4843  #include <linux/kernel.h>
4844  #include <linux/module.h>
4845  #include <linux/delay.h>
4846  #include <linux/slab.h>
4847  #include <linux/init.h>
4848 -
4849 -#include <asm/uaccess.h>
4850 -
4851  #include <linux/ioport.h>
4852 -#include <asm/io.h>
4853  #include <linux/errno.h>
4854  #include <linux/i2c.h>
4855  #include <linux/i2c-algo-bit.h>
4856 +#include <asm/io.h>
4857  
4858  #define DEFAULT_BASE 0x378
4859  static int base=0;
4860 @@ -89,58 +86,31 @@
4861  
4862  static int bit_elv_init(void)
4863  {
4864 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
4865 -               return -ENODEV; 
4866 -       } else {
4867 -                                               /* test for ELV adap.   */
4868 -               if (inb(base+1) & 0x80) {       /* BUSY should be high  */
4869 -                       DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
4870 -                       return -ENODEV;
4871 -               } else {
4872 -                       outb(0x0c,base+2);      /* SLCT auf low         */
4873 -                       udelay(400);
4874 -                       if ( !(inb(base+1) && 0x10) ) {
4875 -                               outb(0x04,base+2);
4876 -                               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
4877 -                               return -ENODEV;
4878 -                       }
4879 -               }
4880 -               request_region(base,(base == 0x3bc)? 3 : 8,
4881 -                       "i2c (ELV adapter)");
4882 -               PortData = 0;
4883 -               bit_elv_setsda((void*)base,1);
4884 -               bit_elv_setscl((void*)base,1);
4885 +       if (!request_region(base, (base == 0x3bc) ? 3 : 8,
4886 +                               "i2c (ELV adapter)"))
4887 +               return -ENODEV;
4888 +
4889 +       if (inb(base+1) & 0x80) {       /* BUSY should be high  */
4890 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
4891 +               goto fail;
4892 +       } 
4893 +
4894 +       outb(0x0c,base+2);      /* SLCT auf low         */
4895 +       udelay(400);
4896 +       if (!(inb(base+1) && 0x10)) {
4897 +               outb(0x04,base+2);
4898 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
4899 +               goto fail;
4900         }
4901 -       return 0;
4902 -}
4903 -
4904 -static void __exit bit_elv_exit(void)
4905 -{
4906 -       release_region( base , (base == 0x3bc)? 3 : 8 );
4907 -}
4908 -
4909 -static int bit_elv_reg(struct i2c_client *client)
4910 -{
4911 -       return 0;
4912 -}
4913  
4914 -static int bit_elv_unreg(struct i2c_client *client)
4915 -{
4916 +       PortData = 0;
4917 +       bit_elv_setsda((void*)base,1);
4918 +       bit_elv_setscl((void*)base,1);
4919         return 0;
4920 -}
4921  
4922 -static void bit_elv_inc_use(struct i2c_adapter *adap)
4923 -{
4924 -#ifdef MODULE
4925 -       MOD_INC_USE_COUNT;
4926 -#endif
4927 -}
4928 -
4929 -static void bit_elv_dec_use(struct i2c_adapter *adap)
4930 -{
4931 -#ifdef MODULE
4932 -       MOD_DEC_USE_COUNT;
4933 -#endif
4934 +fail:
4935 +       release_region(base , (base == 0x3bc) ? 3 : 8);
4936 +       return -ENODEV;
4937  }
4938  
4939  /* ------------------------------------------------------------------------
4940 @@ -148,26 +118,23 @@
4941   * This is only done when more than one hardware adapter is supported.
4942   */
4943  static struct i2c_algo_bit_data bit_elv_data = {
4944 -       NULL,
4945 -       bit_elv_setsda,
4946 -       bit_elv_setscl,
4947 -       bit_elv_getsda,
4948 -       bit_elv_getscl,
4949 -       80, 80, 100,            /*      waits, timeout */
4950 +       .setsda         = bit_elv_setsda,
4951 +       .setscl         = bit_elv_setscl,
4952 +       .getsda         = bit_elv_getsda,
4953 +       .getscl         = bit_elv_getscl,
4954 +       .udelay         = 80,
4955 +       .mdelay         = 80,
4956 +       .timeout        = HZ
4957  };
4958  
4959  static struct i2c_adapter bit_elv_ops = {
4960 -       "ELV Parallel port adaptor",
4961 -       I2C_HW_B_ELV,
4962 -       NULL,
4963 -       &bit_elv_data,
4964 -       bit_elv_inc_use,
4965 -       bit_elv_dec_use,
4966 -       bit_elv_reg,
4967 -       bit_elv_unreg,  
4968 +       .owner          = THIS_MODULE,
4969 +       .name           = "ELV Parallel port adaptor",
4970 +       .id             = I2C_HW_B_ELV,
4971 +       .algo_data      = &bit_elv_data,
4972  };
4973  
4974 -int __init i2c_bitelv_init(void)
4975 +static int __init i2c_bitelv_init(void)
4976  {
4977         printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4978         if (base==0) {
4979 @@ -193,25 +160,19 @@
4980         return 0;
4981  }
4982  
4983 +static void __exit i2c_bitelv_exit(void)
4984 +{
4985 +       i2c_bit_del_bus(&bit_elv_ops);
4986 +       release_region(base, (base == 0x3bc) ? 3 : 8);
4987 +}
4988  
4989  EXPORT_NO_SYMBOLS;
4990  
4991 -#ifdef MODULE
4992  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4993  MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
4994  MODULE_LICENSE("GPL");
4995  
4996  MODULE_PARM(base, "i");
4997  
4998 -int init_module(void)
4999 -{
5000 -       return i2c_bitelv_init();
5001 -}
5002 -
5003 -void cleanup_module(void)
5004 -{
5005 -       i2c_bit_del_bus(&bit_elv_ops);
5006 -       bit_elv_exit();
5007 -}
5008 -
5009 -#endif
5010 +module_init(i2c_bitelv_init);
5011 +module_exit(i2c_bitelv_exit);
5012 diff -urN linux-2.4.24.org/drivers/i2c/i2c-frodo.c linux-2.4.24/drivers/i2c/i2c-frodo.c
5013 --- linux-2.4.24.org/drivers/i2c/i2c-frodo.c    1970-01-01 01:00:00.000000000 +0100
5014 +++ linux-2.4.24/drivers/i2c/i2c-frodo.c        2004-02-04 22:36:36.692823246 +0100
5015 @@ -0,0 +1,83 @@
5016 +
5017 +/*
5018 + * linux/drivers/i2c/i2c-frodo.c
5019 + *
5020 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
5021 + *
5022 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
5023 + * Development board (Frodo).
5024 + *
5025 + * This source code is free software; you can redistribute it and/or
5026 + * modify it under the terms of the GNU General Public License
5027 + * version 2 as published by the Free Software Foundation.
5028 + */
5029 +
5030 +#include <linux/module.h>
5031 +#include <linux/kernel.h>
5032 +#include <linux/init.h>
5033 +#include <linux/delay.h>
5034 +#include <linux/i2c.h>
5035 +#include <linux/i2c-algo-bit.h>
5036 +#include <asm/hardware.h>
5037 +
5038 +
5039 +static void frodo_setsda (void *data,int state)
5040 +{
5041 +       if (state)
5042 +               FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
5043 +       else
5044 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
5045 +}
5046 +
5047 +static void frodo_setscl (void *data,int state)
5048 +{
5049 +       if (state)
5050 +               FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
5051 +       else
5052 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
5053 +}
5054 +
5055 +static int frodo_getsda (void *data)
5056 +{
5057 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
5058 +}
5059 +
5060 +static int frodo_getscl (void *data)
5061 +{
5062 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
5063 +}
5064 +
5065 +static struct i2c_algo_bit_data bit_frodo_data = {
5066 +       .setsda         = frodo_setsda,
5067 +       .setscl         = frodo_setscl,
5068 +       .getsda         = frodo_getsda,
5069 +       .getscl         = frodo_getscl,
5070 +       .udelay         = 80,
5071 +       .mdelay         = 80,
5072 +       .timeout        = HZ
5073 +};
5074 +
5075 +static struct i2c_adapter frodo_ops = {
5076 +       .owner                  = THIS_MODULE,
5077 +       .name                   = "Frodo adapter driver",
5078 +       .id                     = I2C_HW_B_FRODO,
5079 +       .algo_data              = &bit_frodo_data,
5080 +};
5081 +
5082 +static int __init i2c_frodo_init (void)
5083 +{
5084 +       return i2c_bit_add_bus(&frodo_ops);
5085 +}
5086 +
5087 +static void __exit i2c_frodo_exit (void)
5088 +{
5089 +       i2c_bit_del_bus(&frodo_ops);
5090 +}
5091 +
5092 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
5093 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
5094 +MODULE_LICENSE ("GPL");
5095 +
5096 +module_init (i2c_frodo_init);
5097 +module_exit (i2c_frodo_exit);
5098 +
5099 diff -urN linux-2.4.24.org/drivers/i2c/i2c-pcf-epp.c linux-2.4.24/drivers/i2c/i2c-pcf-epp.c
5100 --- linux-2.4.24.org/drivers/i2c/i2c-pcf-epp.c  1970-01-01 01:00:00.000000000 +0100
5101 +++ linux-2.4.24/drivers/i2c/i2c-pcf-epp.c      2004-02-04 22:36:36.696822414 +0100
5102 @@ -0,0 +1,281 @@
5103 +/* ------------------------------------------------------------------------- */
5104 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters  */
5105 +/* ------------------------------------------------------------------------- */
5106 +/*   Copyright (C) 1998-99 Hans Berglund
5107 +
5108 +    This program is free software; you can redistribute it and/or modify
5109 +    it under the terms of the GNU General Public License as published by
5110 +    the Free Software Foundation; either version 2 of the License, or
5111 +    (at your option) any later version.
5112 +
5113 +    This program is distributed in the hope that it will be useful,
5114 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
5115 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5116 +    GNU General Public License for more details.
5117 +
5118 +    You should have received a copy of the GNU General Public License
5119 +    along with this program; if not, write to the Free Software
5120 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
5121 +/* ------------------------------------------------------------------------- */
5122 +
5123 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
5124 +
5125 +#include <linux/kernel.h>
5126 +#include <linux/ioport.h>
5127 +#include <linux/module.h>
5128 +#include <linux/delay.h>
5129 +#include <linux/slab.h>
5130 +#include <linux/init.h>
5131 +#include <linux/parport.h>
5132 +#include <linux/i2c.h>
5133 +#include <linux/i2c-algo-pcf.h>
5134 +#include <asm/irq.h>
5135 +#include <asm/io.h>
5136 +
5137 +
5138 +struct  i2c_pcf_epp {
5139 +  int pe_base;
5140 +  int pe_irq;
5141 +  int pe_clock;
5142 +  int pe_own;
5143 +} ;
5144 +
5145 +#define DEFAULT_BASE 0x378
5146 +#define DEFAULT_IRQ      7
5147 +#define DEFAULT_CLOCK 0x1c
5148 +#define DEFAULT_OWN   0x55
5149 +
5150 +static int base  = 0;
5151 +static int irq   = 0;
5152 +static int clock = 0;
5153 +static int own   = 0;
5154 +static int i2c_debug=0;
5155 +static struct i2c_pcf_epp gpe;
5156 +static wait_queue_head_t pcf_wait;
5157 +static int pcf_pending;
5158 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5159 +
5160 +/* ----- global defines -----------------------------------------------        */
5161 +#define DEB(x) if (i2c_debug>=1) x
5162 +#define DEB2(x) if (i2c_debug>=2) x
5163 +#define DEB3(x) if (i2c_debug>=3) x
5164 +#define DEBE(x)        x       /* error messages                               */
5165 +
5166 +/* --- Convenience defines for the EPP/SPP port:                       */
5167 +#define BASE   ((struct i2c_pcf_epp *)(data))->pe_base
5168 +// #define DATA        BASE                    /* SPP data port */
5169 +#define STAT   (BASE+1)                /* SPP status port */
5170 +#define CTRL   (BASE+2)                /* SPP control port */
5171 +#define EADD   (BASE+3)                /* EPP address port */
5172 +#define EDAT   (BASE+4)                /* EPP data port */
5173 +
5174 +/* ----- local functions ----------------------------------------------        */
5175 +
5176 +static void pcf_epp_setbyte(void *data, int ctl, int val)
5177 +{
5178 +  if (ctl) {
5179 +    if (gpe.pe_irq > 0) {
5180 +      DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
5181 +                 val|I2C_PCF_ENI));
5182 +      // set A0 pin HIGH
5183 +      outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5184 +      // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5185 +      // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5186 +      
5187 +      // EPP write data cycle
5188 +      outb(val | I2C_PCF_ENI, EDAT);
5189 +    } else {
5190 +      DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
5191 +      // set A0 pin HIGH
5192 +      outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5193 +      outb(val, CTRL);
5194 +    }
5195 +  } else {
5196 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
5197 +    // set A0 pin LO
5198 +    outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5199 +    // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5200 +    // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5201 +    outb(val, EDAT);
5202 +  }
5203 +}
5204 +
5205 +static int pcf_epp_getbyte(void *data, int ctl)
5206 +{
5207 +  int val;
5208 +
5209 +  if (ctl) {
5210 +    // set A0 pin HIGH
5211 +    outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5212 +    val = inb(EDAT);
5213 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
5214 +  } else {
5215 +    // set A0 pin LOW
5216 +    outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5217 +    val = inb(EDAT);
5218 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
5219 +  }
5220 +  return (val);
5221 +}
5222 +
5223 +static int pcf_epp_getown(void *data)
5224 +{
5225 +  return (gpe.pe_own);
5226 +}
5227 +
5228 +
5229 +static int pcf_epp_getclock(void *data)
5230 +{
5231 +  return (gpe.pe_clock);
5232 +}
5233 +
5234 +#if 0
5235 +static void pcf_epp_sleep(unsigned long timeout)
5236 +{
5237 +  schedule_timeout( timeout * HZ);
5238 +}
5239 +#endif
5240 +
5241 +static void pcf_epp_waitforpin(void) {
5242 +  int timeout = 10;
5243 +
5244 +  if (gpe.pe_irq > 0) {
5245 +    spin_lock_irq(&irq_driver_lock);
5246 +    if (pcf_pending == 0) {
5247 +      interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
5248 +      //udelay(100);
5249 +    } else {
5250 +      pcf_pending = 0;
5251 +    }
5252 +    spin_unlock_irq(&irq_driver_lock);
5253 +  } else {
5254 +    udelay(100);
5255 +  }
5256 +}
5257 +
5258 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
5259 +  pcf_pending = 1;
5260 +  wake_up_interruptible(&pcf_wait);
5261 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
5262 +}
5263 +
5264 +
5265 +static int pcf_epp_init(void *data)
5266 +{
5267 +  if (check_region(gpe.pe_base, 5) < 0 ) {
5268 +    
5269 +    printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
5270 +    return -ENODEV;
5271 +  } else {
5272 +    request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
5273 +  }
5274 +
5275 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
5276 +  
5277 +  if (gpe.pe_irq > 0) {
5278 +    if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
5279 +      printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
5280 +      gpe.pe_irq = 0;
5281 +    } else
5282 +      disable_irq(gpe.pe_irq);
5283 +      enable_irq(gpe.pe_irq);
5284 +  }
5285 +  // EPP mode initialize
5286 +  // enable interrupt from nINTR pin
5287 +  outb(inb(CTRL)|0x14, CTRL);
5288 +  // clear ERROR bit of STAT
5289 +  outb(inb(STAT)|0x01, STAT);
5290 +  outb(inb(STAT)&~0x01,STAT);
5291 +  
5292 +  return 0;
5293 +}
5294 +
5295 +/* ------------------------------------------------------------------------
5296 + * Encapsulate the above functions in the correct operations structure.
5297 + * This is only done when more than one hardware adapter is supported.
5298 + */
5299 +static struct i2c_algo_pcf_data pcf_epp_data = {
5300 +       .setpcf     = pcf_epp_setbyte,
5301 +       .getpcf     = pcf_epp_getbyte,
5302 +       .getown     = pcf_epp_getown,
5303 +       .getclock   = pcf_epp_getclock,
5304 +       .waitforpin = pcf_epp_waitforpin,
5305 +       .udelay     = 80,
5306 +       .mdelay     = 80,
5307 +       .timeout    = HZ,
5308 +};
5309 +
5310 +static struct i2c_adapter pcf_epp_ops = {
5311 +       .owner          = THIS_MODULE,
5312 +       .name           = "PCF8584 EPP adapter",
5313 +       .id             = I2C_HW_P_LP,
5314 +       .algo_data      = &pcf_epp_data,
5315 +};
5316 +
5317 +static int __init i2c_pcfepp_init(void) 
5318 +{
5319 +  struct i2c_pcf_epp *pepp = &gpe;
5320 +
5321 +  printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5322 +  if (base == 0)
5323 +    pepp->pe_base = DEFAULT_BASE;
5324 +  else
5325 +    pepp->pe_base = base;
5326 +
5327 +  if (irq == 0)
5328 +    pepp->pe_irq = DEFAULT_IRQ;
5329 +  else if (irq<0) {
5330 +    // switch off irq
5331 +    pepp->pe_irq=0;
5332 +  } else {
5333 +    pepp->pe_irq = irq;
5334 +  }
5335 +  if (clock == 0)
5336 +    pepp->pe_clock = DEFAULT_CLOCK;
5337 +  else
5338 +    pepp->pe_clock = clock;
5339 +
5340 +  if (own == 0)
5341 +    pepp->pe_own = DEFAULT_OWN;
5342 +  else
5343 +    pepp->pe_own = own;
5344 +
5345 +  pcf_epp_data.data = (void *)pepp;
5346 +  init_waitqueue_head(&pcf_wait);
5347 +  if (pcf_epp_init(pepp) == 0) {
5348 +    int ret;
5349 +    if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
5350 +      printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
5351 +      release_region(pepp->pe_base , 5);
5352 +      return ret;
5353 +    }
5354 +  } else {
5355 +    
5356 +    return -ENODEV;
5357 +  }
5358 +  printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
5359 +  return 0;
5360 +}
5361 +
5362 +static void __exit pcf_epp_exit(void)
5363 +{
5364 +  i2c_pcf_del_bus(&pcf_epp_ops);
5365 +  if (gpe.pe_irq > 0) {
5366 +    disable_irq(gpe.pe_irq);
5367 +    free_irq(gpe.pe_irq, 0);
5368 +  }
5369 +  release_region(gpe.pe_base , 5);
5370 +}
5371 +
5372 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
5373 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
5374 +MODULE_LICENSE("GPL");
5375 +
5376 +MODULE_PARM(base, "i");
5377 +MODULE_PARM(irq, "i");
5378 +MODULE_PARM(clock, "i");
5379 +MODULE_PARM(own, "i");
5380 +MODULE_PARM(i2c_debug, "i");
5381 +
5382 +module_init(i2c_pcfepp_init);
5383 +module_exit(pcf_epp_exit);
5384 diff -urN linux-2.4.24.org/drivers/i2c/i2c-philips-par.c linux-2.4.24/drivers/i2c/i2c-philips-par.c
5385 --- linux-2.4.24.org/drivers/i2c/i2c-philips-par.c      2004-02-04 22:33:47.661973491 +0100
5386 +++ linux-2.4.24/drivers/i2c/i2c-philips-par.c  2004-02-04 22:37:38.775910804 +0100
5387 @@ -21,7 +21,7 @@
5388  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
5389     Frodo Looijaard <frodol@dds.nl> */
5390  
5391 -/* $Id$ */
5392 +/* $Id$ */
5393  
5394  #include <linux/kernel.h>
5395  #include <linux/ioport.h>
5396 @@ -29,14 +29,10 @@
5397  #include <linux/init.h>
5398  #include <linux/stddef.h>
5399  #include <linux/parport.h>
5400 -
5401 +#include <linux/slab.h>
5402  #include <linux/i2c.h>
5403  #include <linux/i2c-algo-bit.h>
5404  
5405 -#ifndef __exit
5406 -#define __exit __init
5407 -#endif
5408 -
5409  static int type;
5410  
5411  struct i2c_par
5412 @@ -130,59 +126,34 @@
5413                                      PARPORT_STATUS_BUSY) ? 0 : 1;
5414  }
5415  
5416 -static int bit_lp_reg(struct i2c_client *client)
5417 -{
5418 -       return 0;
5419 -}
5420 -
5421 -static int bit_lp_unreg(struct i2c_client *client)
5422 -{
5423 -       return 0;
5424 -}
5425 -
5426 -static void bit_lp_inc_use(struct i2c_adapter *adap)
5427 -{
5428 -       MOD_INC_USE_COUNT;
5429 -}
5430 -
5431 -static void bit_lp_dec_use(struct i2c_adapter *adap)
5432 -{
5433 -       MOD_DEC_USE_COUNT;
5434 -}
5435 -
5436  /* ------------------------------------------------------------------------
5437   * Encapsulate the above functions in the correct operations structure.
5438   * This is only done when more than one hardware adapter is supported.
5439   */
5440   
5441  static struct i2c_algo_bit_data bit_lp_data = {
5442 -       NULL,
5443 -       bit_lp_setsda,
5444 -       bit_lp_setscl,
5445 -       bit_lp_getsda,
5446 -       bit_lp_getscl,
5447 -       80, 80, 100,            /*      waits, timeout */
5448 +       .setsda         = bit_lp_setsda,
5449 +       .setscl         = bit_lp_setscl,
5450 +       .getsda         = bit_lp_getsda,
5451 +       .getscl         = bit_lp_getscl,
5452 +       .udelay         = 80,
5453 +       .mdelay         = 80,
5454 +       .timeout        = HZ
5455  }; 
5456  
5457  static struct i2c_algo_bit_data bit_lp_data2 = {
5458 -       NULL,
5459 -       bit_lp_setsda2,
5460 -       bit_lp_setscl2,
5461 -       bit_lp_getsda2,
5462 -       NULL,
5463 -       80, 80, 100,            /*      waits, timeout */
5464 +       .setsda         = bit_lp_setsda2,
5465 +       .setscl         = bit_lp_setscl2,
5466 +       .getsda         = bit_lp_getsda2,
5467 +       .udelay         = 80,
5468 +       .mdelay         = 80,
5469 +       .timeout        = HZ
5470  }; 
5471  
5472  static struct i2c_adapter bit_lp_ops = {
5473 -       "Philips Parallel port adapter",
5474 -       I2C_HW_B_LP,
5475 -       NULL,
5476 -       NULL,
5477 -       bit_lp_inc_use,
5478 -       bit_lp_dec_use,
5479 -       bit_lp_reg,
5480 -
5481 -       bit_lp_unreg,
5482 +       .owner          = THIS_MODULE,
5483 +       .name           = "Philips Parallel port adapter",
5484 +       .id             = I2C_HW_B_LP,
5485  };
5486  
5487  static void i2c_parport_attach (struct parport *port)
5488 @@ -202,6 +173,7 @@
5489                                                 NULL);
5490         if (!adapter->pdev) {
5491                 printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
5492 +               kfree(adapter);
5493                 return;
5494         }
5495  
5496 @@ -211,7 +183,11 @@
5497         adapter->bit_lp_data.data = port;
5498  
5499         /* reset hardware to sane state */
5500 -       parport_claim_or_block(adapter->pdev);
5501 +       if (parport_claim_or_block(adapter->pdev) < 0 ) {
5502 +               printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
5503 +               kfree(adapter);
5504 +               return;
5505 +       }
5506         adapter->bit_lp_data.setsda(port, 1);
5507         adapter->bit_lp_data.setscl(port, 1);
5508         parport_release(adapter->pdev);
5509 @@ -257,7 +233,7 @@
5510         NULL
5511  };
5512  
5513 -int __init i2c_bitlp_init(void)
5514 +static int __init i2c_bitlp_init(void)
5515  {
5516         printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5517  
5518 @@ -266,7 +242,7 @@
5519         return 0;
5520  }
5521  
5522 -void __exit i2c_bitlp_exit(void)
5523 +static void __exit i2c_bitlp_exit(void)
5524  {
5525         parport_unregister_driver(&i2c_driver);
5526  }
5527 @@ -279,14 +255,5 @@
5528  
5529  MODULE_PARM(type, "i");
5530  
5531 -#ifdef MODULE
5532 -int init_module(void)
5533 -{
5534 -       return i2c_bitlp_init();
5535 -}
5536 -
5537 -void cleanup_module(void)
5538 -{
5539 -       i2c_bitlp_exit();
5540 -}
5541 -#endif
5542 +module_init(i2c_bitlp_init);
5543 +module_exit(i2c_bitlp_exit);
5544 diff -urN linux-2.4.24.org/drivers/i2c/i2c-pport.c linux-2.4.24/drivers/i2c/i2c-pport.c
5545 --- linux-2.4.24.org/drivers/i2c/i2c-pport.c    1970-01-01 01:00:00.000000000 +0100
5546 +++ linux-2.4.24/drivers/i2c/i2c-pport.c        2004-02-04 22:36:36.706820334 +0100
5547 @@ -0,0 +1,205 @@
5548 +/* ------------------------------------------------------------------------- */
5549 +/* i2c-pport.c i2c-hw access  for primitive i2c par. port adapter           */
5550 +/* ------------------------------------------------------------------------- */
5551 +/*   Copyright (C) 2001    Daniel Smolik
5552 +
5553 +    This program is free software; you can redistribute it and/or modify
5554 +    it under the terms of the GNU General Public License as published by
5555 +    the Free Software Foundation; either version 2 of the License, or
5556 +    (at your option) any later version.
5557 +
5558 +    This program is distributed in the hope that it will be useful,
5559 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
5560 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5561 +    GNU General Public License for more details.
5562 +
5563 +    You should have received a copy of the GNU General Public License
5564 +    along with this program; if not, write to the Free Software
5565 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
5566 +/* ------------------------------------------------------------------------- */
5567 +
5568 +/*
5569 +       See doc/i2c-pport for instructions on wiring to the
5570 +       parallel port connector.
5571 +
5572 +       Cut & paste :-)  based on Velleman K8000 driver by Simon G. Vogl
5573 +*/
5574 +
5575 +
5576 +#include <linux/kernel.h>
5577 +#include <linux/module.h>
5578 +#include <linux/delay.h>
5579 +#include <linux/slab.h>
5580 +#include <linux/init.h>
5581 +#include <linux/ioport.h>
5582 +#include <linux/errno.h>
5583 +#include <linux/i2c.h>
5584 +#include <linux/i2c-algo-bit.h>
5585 +#include <asm/io.h>
5586 +
5587 +
5588 +#define DEFAULT_BASE 0x378
5589 +static int base=0;
5590 +static unsigned char PortData = 0;
5591 +
5592 +/* ----- global defines -----------------------------------------------        */
5593 +#define DEB(x)         /* should be reasonable open, close &c.         */
5594 +#define DEB2(x)        /* low level debugging - very slow              */
5595 +#define DEBE(x)        x       /* error messages                               */
5596 +#define DEBINIT(x) x   /* detection status messages                    */
5597 +
5598 +/* --- Convenience defines for the parallel port:                      */
5599 +#define BASE   (unsigned int)(data)
5600 +#define DATA   BASE                    /* Centronics data port         */
5601 +#define STAT   (BASE+1)                /* Centronics status port       */
5602 +#define CTRL   (BASE+2)                /* Centronics control port      */
5603 +
5604 +/* we will use SDA  - Auto Linefeed(14)   bit 1  POUT   */
5605 +/* we will use SCL - Initialize printer(16)    BUSY bit 2*/
5606 +
5607 +#define  SET_SCL    | 0x04
5608 +#define  CLR_SCL    & 0xFB
5609 +
5610 +
5611 +
5612 +
5613 +#define  SET_SDA    & 0x04
5614 +#define  CLR_SDA    | 0x02
5615 +
5616 +
5617 +/* ----- local functions ----------------------------------------------        */
5618 +
5619 +
5620 +static void bit_pport_setscl(void *data, int state)
5621 +{
5622 +       if (state) {
5623 +               //high
5624 +               PortData = PortData SET_SCL;
5625 +       } else {
5626 +               //low
5627 +               PortData = PortData CLR_SCL; 
5628 +       }
5629 +       outb(PortData, CTRL);
5630 +}
5631 +
5632 +static void bit_pport_setsda(void *data, int state)
5633 +{
5634 +       if (state) {
5635 +               
5636 +               PortData = PortData SET_SDA;
5637 +       } else {
5638 +
5639 +               PortData = PortData CLR_SDA;
5640 +       }
5641 +       outb(PortData, CTRL);
5642 +} 
5643 +
5644 +static int bit_pport_getscl(void *data)
5645 +{
5646 +
5647 +       return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
5648 +}
5649 +
5650 +static int bit_pport_getsda(void *data)
5651 +{
5652 +       return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
5653 +}
5654 +
5655 +static int bit_pport_init(void)
5656 +{
5657 +       if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
5658 +               return -ENODEV; 
5659 +       } else {
5660 +               /* test for PPORT adap.         */
5661 +       
5662 +
5663 +               PortData=inb(base+2);
5664 +               PortData= (PortData SET_SDA) SET_SCL;
5665 +               outb(PortData,base+2);                          
5666 +
5667 +               if (!(inb(base+2) | 0x06)) {    /* SDA and SCL will be high     */
5668 +                       DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
5669 +                       return -ENODEV;
5670 +               } else {
5671 +               
5672 +                       /*SCL high and SDA low*/
5673 +                       PortData = PortData SET_SCL CLR_SDA;
5674 +                       outb(PortData,base+2);  
5675 +                       schedule_timeout(400);
5676 +                       if ( !(inb(base+2) | 0x4) ) {
5677 +                               //outb(0x04,base+2);
5678 +                               DEBINIT(printk("i2c-port.o: SDA was high.\n"));
5679 +                               return -ENODEV;
5680 +                       }
5681 +               }
5682 +               bit_pport_setsda((void*)base,1);
5683 +               bit_pport_setscl((void*)base,1);
5684 +       }
5685 +       return 0;
5686 +}
5687 +
5688 +
5689 +/* ------------------------------------------------------------------------
5690 + * Encapsulate the above functions in the correct operations structure.
5691 + * This is only done when more than one hardware adapter is supported.
5692 + */
5693 +static struct i2c_algo_bit_data bit_pport_data = {
5694 +       .setsda         = bit_pport_setsda,
5695 +       .setscl         = bit_pport_setscl,
5696 +       .getsda         = bit_pport_getsda,
5697 +       .getscl         = bit_pport_getscl,
5698 +       .udelay         = 40,
5699 +       .mdelay         = 80,
5700 +       .timeout        = HZ
5701 +};
5702 +
5703 +static struct i2c_adapter bit_pport_ops = {
5704 +       .owner          = THIS_MODULE,
5705 +       .name           = "Primitive Parallel port adaptor",
5706 +       .id             = I2C_HW_B_PPORT,
5707 +       .algo_data      = &bit_pport_data,
5708 +};
5709 +
5710 +static int __init i2c_bitpport_init(void)
5711 +{
5712 +       printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5713 +
5714 +       if (base==0) {
5715 +               /* probe some values */
5716 +               base=DEFAULT_BASE;
5717 +               bit_pport_data.data=(void*)DEFAULT_BASE;
5718 +               if (bit_pport_init()==0) {
5719 +                       if(i2c_bit_add_bus(&bit_pport_ops) < 0)
5720 +                               return -ENODEV;
5721 +               } else {
5722 +                       return -ENODEV;
5723 +               }
5724 +       } else {
5725 +               bit_pport_data.data=(void*)base;
5726 +               if (bit_pport_init()==0) {
5727 +                       if(i2c_bit_add_bus(&bit_pport_ops) < 0)
5728 +                               return -ENODEV;
5729 +               } else {
5730 +                       return -ENODEV;
5731 +               }
5732 +       }
5733 +       printk("i2c-pport.o: found device at %#x.\n",base);
5734 +       return 0;
5735 +}
5736 +
5737 +static void __exit i2c_bitpport_exit(void)
5738 +{
5739 +       i2c_bit_del_bus(&bit_pport_ops);
5740 +       release_region((base+2),1);
5741 +}
5742 +
5743 +EXPORT_NO_SYMBOLS;
5744 +
5745 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
5746 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
5747 +MODULE_LICENSE("GPL");
5748 +
5749 +MODULE_PARM(base, "i");
5750 +
5751 +module_init(i2c_bitpport_init);
5752 +module_exit(i2c_bitpport_exit);
5753 diff -urN linux-2.4.24.org/drivers/i2c/i2c-proc.c linux-2.4.24/drivers/i2c/i2c-proc.c
5754 --- linux-2.4.24.org/drivers/i2c/i2c-proc.c     2004-02-04 22:33:47.507005716 +0100
5755 +++ linux-2.4.24/drivers/i2c/i2c-proc.c 2004-02-04 22:36:36.711819295 +0100
5756 @@ -29,23 +29,15 @@
5757  #include <linux/ctype.h>
5758  #include <linux/sysctl.h>
5759  #include <linux/proc_fs.h>
5760 +#include <linux/init.h>
5761  #include <linux/ioport.h>
5762 -#include <asm/uaccess.h>
5763 -
5764  #include <linux/i2c.h>
5765  #include <linux/i2c-proc.h>
5766 +#include <asm/uaccess.h>
5767  
5768 -#include <linux/init.h>
5769 -
5770 -#ifndef THIS_MODULE
5771 -#define THIS_MODULE NULL
5772 -#endif
5773 -
5774 -static int i2c_create_name(char **name, const char *prefix,
5775 -                              struct i2c_adapter *adapter, int addr);
5776  static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
5777                                long *results, int magnitude);
5778 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
5779 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
5780                                long *results, int magnitude);
5781  static int i2c_proc_chips(ctl_table * ctl, int write,
5782                               struct file *filp, void *buffer,
5783 @@ -55,22 +47,10 @@
5784                                 void *newval, size_t newlen,
5785                                 void **context);
5786  
5787 -int __init sensors_init(void);
5788 -
5789  #define SENSORS_ENTRY_MAX 20
5790  static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
5791  
5792  static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
5793 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
5794 -
5795 -static ctl_table sysctl_table[] = {
5796 -       {CTL_DEV, "dev", NULL, 0, 0555},
5797 -       {0},
5798 -       {DEV_SENSORS, "sensors", NULL, 0, 0555},
5799 -       {0},
5800 -       {0, NULL, NULL, 0, 0555},
5801 -       {0}
5802 -};
5803  
5804  static ctl_table i2c_proc_dev_sensors[] = {
5805         {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips,
5806 @@ -91,31 +71,45 @@
5807  
5808  
5809  static struct ctl_table_header *i2c_proc_header;
5810 -static int i2c_initialized;
5811  
5812  /* This returns a nice name for a new directory; for example lm78-isa-0310
5813     (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for
5814     a LM75 chip on the third i2c bus at address 0x4e).  
5815     name is allocated first. */
5816 -int i2c_create_name(char **name, const char *prefix,
5817 -                       struct i2c_adapter *adapter, int addr)
5818 +static char *generate_name(struct i2c_client *client, const char *prefix)
5819  {
5820 -       char name_buffer[50];
5821 -       int id;
5822 -       if (i2c_is_isa_adapter(adapter))
5823 +       struct i2c_adapter *adapter = client->adapter;
5824 +       int addr = client->addr;
5825 +       char name_buffer[50], *name;
5826 +
5827 +       if (i2c_is_isa_adapter(adapter)) {
5828                 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
5829 -       else {
5830 -               if ((id = i2c_adapter_id(adapter)) < 0)
5831 -                       return -ENOENT;
5832 +       } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
5833 +               int id = i2c_adapter_id(adapter);
5834 +               if (id < 0)
5835 +                       return ERR_PTR(-ENOENT);
5836                 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
5837 +       } else {        /* dummy adapter, generate prefix */
5838 +               int end, i;
5839 +
5840 +               sprintf(name_buffer, "%s-", prefix);
5841 +               end = strlen(name_buffer);
5842 +
5843 +               for (i = 0; i < 32; i++) {
5844 +                       if (adapter->algo->name[i] == ' ')
5845 +                               break;
5846 +                       name_buffer[end++] = tolower(adapter->algo->name[i]);
5847 +               }
5848 +
5849 +               name_buffer[end] = 0;
5850 +               sprintf(name_buffer + end, "-%04x", addr);
5851         }
5852 -       *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
5853 -       if (!*name) {
5854 -               printk (KERN_WARNING "i2c_create_name: not enough memory\n");
5855 -               return -ENOMEM;
5856 -       }
5857 -       strcpy(*name, name_buffer);
5858 -       return 0;
5859 +
5860 +       name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
5861 +       if (!name)
5862 +               return ERR_PTR(-ENOMEM);
5863 +       strcpy(name, name_buffer);
5864 +       return name;
5865  }
5866  
5867  /* This rather complex function must be called when you want to add an entry
5868 @@ -124,139 +118,91 @@
5869     ctl_template should be a template of the newly created directory. It is
5870     copied in memory. The extra2 field of each file is set to point to client.
5871     If any driver wants subdirectories within the newly created directory,
5872 -   this function must be updated! 
5873 -   controlling_mod is the controlling module. It should usually be
5874 -   THIS_MODULE when calling. Note that this symbol is not defined in
5875 -   kernels before 2.3.13; define it to NULL in that case. We will not use it
5876 -   for anything older than 2.3.27 anyway. */
5877 +   this function must be updated!  */
5878  int i2c_register_entry(struct i2c_client *client, const char *prefix,
5879 -                          ctl_table * ctl_template,
5880 -                          struct module *controlling_mod)
5881 +                      struct ctl_table *ctl_template)
5882  {
5883 -       int i, res, len, id;
5884 -       ctl_table *new_table;
5885 -       char *name;
5886 -       struct ctl_table_header *new_header;
5887 +       struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
5888 +       struct ctl_table_header *hdr;
5889 +       struct ctl_table *tmp, *leaf;
5890 +       const char *name;
5891 +       int id, len = 0;
5892  
5893 -       if ((res = i2c_create_name(&name, prefix, client->adapter,
5894 -                                      client->addr))) return res;
5895 +       name = generate_name(client, prefix);
5896 +       if (IS_ERR(name))
5897 +               return PTR_ERR(name);
5898  
5899 -       for (id = 0; id < SENSORS_ENTRY_MAX; id++)
5900 -               if (!i2c_entries[id]) {
5901 -                       break;
5902 -               }
5903 -       if (id == SENSORS_ENTRY_MAX) {
5904 -               kfree(name);
5905 -               return -ENOMEM;
5906 +       for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
5907 +               if (!i2c_entries[id])
5908 +                       goto free_slot;
5909         }
5910 -       id += 256;
5911  
5912 -       len = 0;
5913 +       goto out_free_name;
5914 +
5915 + free_slot:
5916         while (ctl_template[len].procname)
5917                 len++;
5918 -       len += 7;
5919 -       if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
5920 -               kfree(name);
5921 -               return -ENOMEM;
5922 -       }
5923 -
5924 -       memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
5925 -       new_table[0].child = &new_table[2];
5926 -       new_table[2].child = &new_table[4];
5927 -       new_table[4].child = &new_table[6];
5928 -       new_table[4].procname = name;
5929 -       new_table[4].ctl_name = id;
5930 -       memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
5931 -       for (i = 6; i < len; i++)
5932 -               new_table[i].extra2 = client;
5933 -
5934 -       if (!(new_header = register_sysctl_table(new_table, 0))) {
5935 -               kfree(new_table);
5936 -               kfree(name);
5937 -               return -ENOMEM;
5938 -       }
5939 -
5940 -       i2c_entries[id - 256] = new_header;
5941 -
5942 -       i2c_clients[id - 256] = client;
5943 -#ifdef DEBUG
5944 -       if (!new_header || !new_header->ctl_table ||
5945 -           !new_header->ctl_table->child ||
5946 -           !new_header->ctl_table->child->child ||
5947 -           !new_header->ctl_table->child->child->de) {
5948 -               printk
5949 -                   ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
5950 -               return id;
5951 -       }
5952 -#endif                         /* DEBUG */
5953 -       i2c_inodes[id - 256] =
5954 -           new_header->ctl_table->child->child->de->low_ino;
5955 -       new_header->ctl_table->child->child->de->owner = controlling_mod;
5956 -
5957 -       return id;
5958 +       tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1), 
5959 +                                 GFP_KERNEL);
5960 +       if (!tbl)
5961 +               goto out_free_name;
5962 +       memset(tbl, 0, sizeof(*tbl));
5963 +
5964 +       /* The client sysctls */
5965 +       leaf = (struct ctl_table *) (tbl + 1);
5966 +       memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
5967 +       for (tmp = leaf; tmp->ctl_name; tmp++)
5968 +               tmp->extra2 = client;
5969 +
5970 +       tbl->sensors->ctl_name = id+256;
5971 +       tbl->sensors->procname = name;
5972 +       tbl->sensors->mode = 0555;
5973 +       tbl->sensors->child = leaf;
5974 +
5975 +       tbl->dev->ctl_name = DEV_SENSORS;
5976 +       tbl->dev->procname = "sensors";
5977 +       tbl->dev->mode = 0555;
5978 +       tbl->dev->child = tbl->sensors;
5979 +
5980 +       tbl->root->ctl_name = CTL_DEV;
5981 +       tbl->root->procname = "dev";
5982 +       tbl->root->mode = 0555;
5983 +       tbl->root->child = tbl->dev;
5984 +
5985 +       hdr = register_sysctl_table(tbl->root, 0);
5986 +       if (!hdr)
5987 +               goto out_free_tbl;
5988 +
5989 +       i2c_entries[id] = hdr;
5990 +       i2c_clients[id] = client;
5991 +
5992 +       return (id + 256);      /* XXX(hch) why?? */
5993 +
5994 + out_free_tbl:
5995 +       kfree(tbl);
5996 + out_free_name:
5997 +       kfree(name);
5998 +       return -ENOMEM;
5999  }
6000  
6001  void i2c_deregister_entry(int id)
6002  {
6003 -       ctl_table *table;
6004 -       char *temp;
6005         id -= 256;
6006 -       if (i2c_entries[id]) {
6007 -               table = i2c_entries[id]->ctl_table;
6008 -               unregister_sysctl_table(i2c_entries[id]);
6009 -               /* 2-step kfree needed to keep gcc happy about const points */
6010 -               (const char *) temp = table[4].procname;
6011 -               kfree(temp);
6012 -               kfree(table);
6013 -               i2c_entries[id] = NULL;
6014 -               i2c_clients[id] = NULL;
6015 -       }
6016 -}
6017  
6018 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o 
6019 -   impossible if some process still uses it or some file in it */
6020 -void i2c_fill_inode(struct inode *inode, int fill)
6021 -{
6022 -       if (fill)
6023 -               MOD_INC_USE_COUNT;
6024 -       else
6025 -               MOD_DEC_USE_COUNT;
6026 -}
6027 -
6028 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
6029 -   the corresponding module impossible if some process still uses it or
6030 -   some file in it */
6031 -void i2c_dir_fill_inode(struct inode *inode, int fill)
6032 -{
6033 -       int i;
6034 -       struct i2c_client *client;
6035 +       if (i2c_entries[id]) {
6036 +               struct ctl_table_header *hdr = i2c_entries[id];
6037 +               struct ctl_table *tbl = hdr->ctl_table;
6038  
6039 -#ifdef DEBUG
6040 -       if (!inode) {
6041 -               printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
6042 -               return;
6043 +               unregister_sysctl_table(hdr);
6044 +               kfree(tbl->child->child->procname);
6045 +               kfree(tbl); /* actually the whole anonymous struct */
6046         }
6047 -#endif                         /* def DEBUG */
6048  
6049 -       for (i = 0; i < SENSORS_ENTRY_MAX; i++)
6050 -               if (i2c_clients[i]
6051 -                   && (i2c_inodes[i] == inode->i_ino)) break;
6052 -#ifdef DEBUG
6053 -       if (i == SENSORS_ENTRY_MAX) {
6054 -               printk
6055 -                   ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
6056 -                    inode->i_ino);
6057 -               return;
6058 -       }
6059 -#endif                         /* def DEBUG */
6060 -       client = i2c_clients[i];
6061 -       if (fill)
6062 -               client->driver->inc_use(client);
6063 -       else
6064 -               client->driver->dec_use(client);
6065 +       i2c_entries[id] = NULL;
6066 +       i2c_clients[id] = NULL;
6067  }
6068  
6069 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6070 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6071                        void *buffer, size_t * lenp)
6072  {
6073         char BUF[SENSORS_PREFIX_MAX + 30];
6074 @@ -294,7 +240,7 @@
6075         return 0;
6076  }
6077  
6078 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6079 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6080                          void *oldval, size_t * oldlenp, void *newval,
6081                          size_t newlen, void **context)
6082  {
6083 @@ -456,7 +402,7 @@
6084     WARNING! This is tricky code. I have tested it, but there may still be
6085              hidden bugs in it, even leading to crashes and things!
6086  */
6087 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6088 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6089                          long *results, int magnitude)
6090  {
6091         int maxels, min, mag;
6092 @@ -557,7 +503,7 @@
6093         return 0;
6094  }
6095  
6096 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
6097 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
6098                          long *results, int magnitude)
6099  {
6100  #define BUFLEN 20
6101 @@ -646,6 +592,7 @@
6102                                         I2C_FUNC_SMBUS_QUICK)) return -1;
6103  
6104         for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
6105 +               /* XXX: WTF is going on here??? */
6106                 if ((is_isa && check_region(addr, 1)) ||
6107                     (!is_isa && i2c_check_addr(adapter, addr)))
6108                         continue;
6109 @@ -846,46 +793,33 @@
6110         return 0;
6111  }
6112  
6113 -int __init sensors_init(void)
6114 +static int __init i2c_proc_init(void)
6115  {
6116         printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
6117 -       i2c_initialized = 0;
6118         if (!
6119             (i2c_proc_header =
6120 -            register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
6121 +            register_sysctl_table(i2c_proc, 0))) {
6122 +               printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
6123 +               return -EPERM;
6124 +       }
6125         i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
6126 -       i2c_initialized++;
6127         return 0;
6128  }
6129  
6130 +static void __exit i2c_proc_exit(void)
6131 +{
6132 +       unregister_sysctl_table(i2c_proc_header);
6133 +}
6134 +
6135 +EXPORT_SYMBOL(i2c_register_entry);
6136  EXPORT_SYMBOL(i2c_deregister_entry);
6137 -EXPORT_SYMBOL(i2c_detect);
6138  EXPORT_SYMBOL(i2c_proc_real);
6139 -EXPORT_SYMBOL(i2c_register_entry);
6140  EXPORT_SYMBOL(i2c_sysctl_real);
6141 -
6142 -#ifdef MODULE
6143 +EXPORT_SYMBOL(i2c_detect);
6144  
6145  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
6146  MODULE_DESCRIPTION("i2c-proc driver");
6147  MODULE_LICENSE("GPL");
6148  
6149 -int i2c_cleanup(void)
6150 -{
6151 -       if (i2c_initialized >= 1) {
6152 -               unregister_sysctl_table(i2c_proc_header);
6153 -               i2c_initialized--;
6154 -       }
6155 -       return 0;
6156 -}
6157 -
6158 -int init_module(void)
6159 -{
6160 -       return sensors_init();
6161 -}
6162 -
6163 -int cleanup_module(void)
6164 -{
6165 -       return i2c_cleanup();
6166 -}
6167 -#endif                         /* MODULE */
6168 +module_init(i2c_proc_init);
6169 +module_exit(i2c_proc_exit);
6170 diff -urN linux-2.4.24.org/drivers/i2c/i2c-rpx.c linux-2.4.24/drivers/i2c/i2c-rpx.c
6171 --- linux-2.4.24.org/drivers/i2c/i2c-rpx.c      1970-01-01 01:00:00.000000000 +0100
6172 +++ linux-2.4.24/drivers/i2c/i2c-rpx.c  2004-02-04 22:36:36.715818463 +0100
6173 @@ -0,0 +1,101 @@
6174 +/*
6175 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
6176 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
6177 + *
6178 + * moved into proper i2c interface;
6179 + * Brad Parker (brad@heeltoe.com)
6180 + *
6181 + * RPX lite specific parts of the i2c interface
6182 + * Update:  There actually isn't anything RPXLite-specific about this module.
6183 + * This should work for most any 8xx board.  The console messages have been 
6184 + * changed to eliminate RPXLite references.
6185 + */
6186 +
6187 +#include <linux/kernel.h>
6188 +#include <linux/module.h>
6189 +#include <linux/init.h>
6190 +#include <linux/stddef.h>
6191 +#include <linux/i2c.h>
6192 +#include <linux/i2c-algo-8xx.h>
6193 +#include <asm/mpc8xx.h>
6194 +#include <asm/commproc.h>
6195 +
6196 +
6197 +static void
6198 +rpx_iic_init(struct i2c_algo_8xx_data *data)
6199 +{
6200 +       volatile cpm8xx_t *cp;
6201 +       volatile immap_t *immap;
6202 +
6203 +       cp = cpmp;      /* Get pointer to Communication Processor */
6204 +       immap = (immap_t *)IMAP_ADDR;   /* and to internal registers */
6205 +
6206 +       data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
6207 +
6208 +       /* Check for and use a microcode relocation patch.
6209 +       */
6210 +       if ((data->reloc = data->iip->iic_rpbase))
6211 +               data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
6212 +               
6213 +       data->i2c = (i2c8xx_t *)&(immap->im_i2c);
6214 +       data->cp = cp;
6215 +
6216 +       /* Initialize Port B IIC pins.
6217 +       */
6218 +       cp->cp_pbpar |= 0x00000030;
6219 +       cp->cp_pbdir |= 0x00000030;
6220 +       cp->cp_pbodr |= 0x00000030;
6221 +
6222 +       /* Allocate space for two transmit and two receive buffer
6223 +        * descriptors in the DP ram.
6224 +        */
6225 +       data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
6226 +
6227 +       /* ptr to i2c area */
6228 +       data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
6229 +}
6230 +
6231 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
6232 +{
6233 +       /* install interrupt handler */
6234 +       cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
6235 +
6236 +       return 0;
6237 +}
6238 +
6239 +static struct i2c_algo_8xx_data rpx_data = {
6240 +       .setisr = rpx_install_isr
6241 +};
6242 +
6243 +static struct i2c_adapter rpx_ops = {
6244 +       .owner          = THIS_MODULE,
6245 +       .name           = "m8xx",
6246 +       .id             = I2C_HW_MPC8XX_EPON,
6247 +       .algo_data      = &rpx_data,
6248 +};
6249 +
6250 +static int __init i2c_rpx_init(void)
6251 +{
6252 +       printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6253 +
6254 +       /* reset hardware to sane state */
6255 +       rpx_iic_init(&rpx_data);
6256 +
6257 +       if (i2c_8xx_add_bus(&rpx_ops) < 0) {
6258 +               printk("i2c-rpx: Unable to register with I2C\n");
6259 +               return -ENODEV;
6260 +       }
6261 +
6262 +       return 0;
6263 +}
6264 +
6265 +static void __exit i2c_rpx_exit(void)
6266 +{
6267 +       i2c_8xx_del_bus(&rpx_ops);
6268 +}
6269 +
6270 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
6271 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
6272 +
6273 +module_init(i2c_rpx_init);
6274 +module_exit(i2c_rpx_exit);
6275 diff -urN linux-2.4.24.org/drivers/i2c/i2c-velleman.c linux-2.4.24/drivers/i2c/i2c-velleman.c
6276 --- linux-2.4.24.org/drivers/i2c/i2c-velleman.c 2004-02-04 22:33:47.695966422 +0100
6277 +++ linux-2.4.24/drivers/i2c/i2c-velleman.c     2004-02-04 22:36:36.718817839 +0100
6278 @@ -18,18 +18,18 @@
6279      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
6280  /* ------------------------------------------------------------------------- */
6281  
6282 -/* $Id$ */
6283 +/* $Id$ */
6284  
6285  #include <linux/kernel.h>
6286  #include <linux/ioport.h>
6287  #include <linux/module.h>
6288  #include <linux/init.h>
6289 -#include <linux/string.h>  /* for 2.0 kernels to get NULL   */
6290 -#include <asm/errno.h>     /* for 2.0 kernels to get ENODEV */
6291 -#include <asm/io.h>
6292 -
6293 +#include <linux/errno.h>
6294 +#include <linux/delay.h>
6295  #include <linux/i2c.h>
6296  #include <linux/i2c-algo-bit.h>
6297 +#include <asm/io.h>
6298 +#include <asm/param.h> /* for HZ */
6299  
6300  /* ----- global defines -----------------------------------------------        */
6301  #define DEB(x)         /* should be reasonable open, close &c.         */
6302 @@ -90,75 +90,38 @@
6303  
6304  static int bit_velle_init(void)
6305  {
6306 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6307 -               DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
6308 -                    base));
6309 +       if (!request_region(base, (base == 0x3bc) ? 3 : 8, 
6310 +                       "i2c (Vellemann adapter)"))
6311                 return -ENODEV;
6312 -       } else {
6313 -               request_region(base, (base == 0x3bc)? 3 : 8, 
6314 -                       "i2c (Vellemann adapter)");
6315 -               bit_velle_setsda((void*)base,1);
6316 -               bit_velle_setscl((void*)base,1);
6317 -       }
6318 -       return 0;
6319 -}
6320  
6321 -static void __exit bit_velle_exit(void)
6322 -{      
6323 -       release_region( base , (base == 0x3bc)? 3 : 8 );
6324 -}
6325 -
6326 -
6327 -static int bit_velle_reg(struct i2c_client *client)
6328 -{
6329 -       return 0;
6330 -}
6331 -
6332 -static int bit_velle_unreg(struct i2c_client *client)
6333 -{
6334 +       bit_velle_setsda((void*)base,1);
6335 +       bit_velle_setscl((void*)base,1);
6336         return 0;
6337  }
6338  
6339 -static void bit_velle_inc_use(struct i2c_adapter *adap)
6340 -{
6341 -#ifdef MODULE
6342 -       MOD_INC_USE_COUNT;
6343 -#endif
6344 -}
6345 -
6346 -static void bit_velle_dec_use(struct i2c_adapter *adap)
6347 -{
6348 -#ifdef MODULE
6349 -       MOD_DEC_USE_COUNT;
6350 -#endif
6351 -}
6352 -
6353  /* ------------------------------------------------------------------------
6354   * Encapsulate the above functions in the correct operations structure.
6355   * This is only done when more than one hardware adapter is supported.
6356   */
6357  
6358  static struct i2c_algo_bit_data bit_velle_data = {
6359 -       NULL,
6360 -       bit_velle_setsda,
6361 -       bit_velle_setscl,
6362 -       bit_velle_getsda,
6363 -       bit_velle_getscl,
6364 -       10, 10, 100,            /*      waits, timeout */
6365 +       .setsda         = bit_velle_setsda,
6366 +       .setscl         = bit_velle_setscl,
6367 +       .getsda         = bit_velle_getsda,
6368 +       .getscl         = bit_velle_getscl,
6369 +       .udelay         = 10,
6370 +       .mdelay         = 10,
6371 +       .timeout        = HZ
6372  };
6373  
6374  static struct i2c_adapter bit_velle_ops = {
6375 -       "Velleman K8000",
6376 -       I2C_HW_B_VELLE,
6377 -       NULL,
6378 -       &bit_velle_data,
6379 -       bit_velle_inc_use,
6380 -       bit_velle_dec_use,
6381 -       bit_velle_reg,
6382 -       bit_velle_unreg,
6383 +       .owner          = THIS_MODULE,
6384 +       .name           = "Velleman K8000",
6385 +       .id             = I2C_HW_B_VELLE,
6386 +       .algo_data      = &bit_velle_data,
6387  };
6388  
6389 -int __init  i2c_bitvelle_init(void)
6390 +static int __init i2c_bitvelle_init(void)
6391  {
6392         printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6393         if (base==0) {
6394 @@ -184,24 +147,19 @@
6395         return 0;
6396  }
6397  
6398 +static void __exit i2c_bitvelle_exit(void)
6399 +{      
6400 +       i2c_bit_del_bus(&bit_velle_ops);
6401 +       release_region(base, (base == 0x3bc) ? 3 : 8);
6402 +}
6403 +
6404  EXPORT_NO_SYMBOLS;
6405  
6406 -#ifdef MODULE
6407  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
6408  MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
6409  MODULE_LICENSE("GPL");
6410  
6411  MODULE_PARM(base, "i");
6412  
6413 -int init_module(void) 
6414 -{
6415 -       return i2c_bitvelle_init();
6416 -}
6417 -
6418 -void cleanup_module(void) 
6419 -{
6420 -       i2c_bit_del_bus(&bit_velle_ops);
6421 -       bit_velle_exit();
6422 -}
6423 -
6424 -#endif
6425 +module_init(i2c_bitvelle_init);
6426 +module_exit(i2c_bitvelle_exit);
6427 diff -urN linux-2.4.24.org/drivers/i2c/scx200_acb.c linux-2.4.24/drivers/i2c/scx200_acb.c
6428 --- linux-2.4.24.org/drivers/i2c/scx200_acb.c   2004-02-04 22:33:47.486010082 +0100
6429 +++ linux-2.4.24/drivers/i2c/scx200_acb.c       2004-02-04 22:36:36.724816591 +0100
6430 @@ -408,16 +408,6 @@
6431         return 0;
6432  }
6433  
6434 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
6435 -{
6436 -       MOD_INC_USE_COUNT;
6437 -}
6438 -
6439 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
6440 -{
6441 -       MOD_DEC_USE_COUNT;
6442 -}
6443 -
6444  /* For now, we only handle combined mode (smbus) */
6445  static struct i2c_algorithm scx200_acb_algorithm = {
6446         name:           "NatSemi SCx200 ACCESS.bus",
6447 @@ -482,8 +472,6 @@
6448         sprintf(adapter->name, "SCx200 ACB%d", index);
6449         adapter->id = I2C_ALGO_SMBUS;
6450         adapter->algo = &scx200_acb_algorithm;
6451 -       adapter->inc_use = scx200_acb_inc_use;
6452 -       adapter->dec_use = scx200_acb_dec_use;
6453         adapter->client_register = scx200_acb_reg;
6454         adapter->client_unregister = scx200_acb_unreg;
6455  
6456 diff -urN linux-2.4.24.org/drivers/i2c/scx200_i2c.c linux-2.4.24/drivers/i2c/scx200_i2c.c
6457 --- linux-2.4.24.org/drivers/i2c/scx200_i2c.c   2004-02-04 22:33:47.451017359 +0100
6458 +++ linux-2.4.24/drivers/i2c/scx200_i2c.c       2004-02-04 22:36:36.728815760 +0100
6459 @@ -76,16 +76,6 @@
6460         return 0;
6461  }
6462  
6463 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
6464 -{
6465 -       MOD_INC_USE_COUNT;
6466 -}
6467 -
6468 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
6469 -{
6470 -       MOD_DEC_USE_COUNT;
6471 -}
6472 -
6473  /* ------------------------------------------------------------------------
6474   * Encapsulate the above functions in the correct operations structure.
6475   * This is only done when more than one hardware adapter is supported.
6476 @@ -104,8 +94,6 @@
6477         .name              = "NatSemi SCx200 I2C",
6478         .id                = I2C_HW_B_VELLE,
6479         .algo_data         = &scx200_i2c_data,
6480 -       .inc_use           = scx200_i2c_inc_use,
6481 -       .dec_use           = scx200_i2c_dec_use,
6482         .client_register   = scx200_i2c_reg,
6483         .client_unregister = scx200_i2c_unreg,
6484  };
6485 diff -urN linux-2.4.24.org/drivers/media/video/saa5249.c linux-2.4.24/drivers/media/video/saa5249.c
6486 --- linux-2.4.24.org/drivers/media/video/saa5249.c      2004-02-04 22:33:53.966662445 +0100
6487 +++ linux-2.4.24/drivers/media/video/saa5249.c  2004-02-04 22:36:37.042750465 +0100
6488 @@ -258,12 +258,12 @@
6489  
6490  static struct i2c_driver i2c_driver_videotext = 
6491  {
6492 -       IF_NAME,                /* name */
6493 -       I2C_DRIVERID_SAA5249, /* in i2c.h */
6494 -       I2C_DF_NOTIFY,
6495 -       saa5249_probe,
6496 -       saa5249_detach,
6497 -       saa5249_command
6498 +       .name = IF_NAME,                /* name */
6499 +       .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
6500 +       .flags = I2C_DF_NOTIFY,
6501 +       .attach_adapter = saa5249_probe,
6502 +       .detach_client = saa5249_detach,
6503 +       .command = saa5249_command
6504  };
6505  
6506  static struct i2c_client client_template = {
6507 diff -urN linux-2.4.24.org/drivers/media/video/tuner-3036.c linux-2.4.24/drivers/media/video/tuner-3036.c
6508 --- linux-2.4.24.org/drivers/media/video/tuner-3036.c   2004-02-04 22:33:54.024650387 +0100
6509 +++ linux-2.4.24/drivers/media/video/tuner-3036.c       2004-02-04 22:36:37.049749010 +0100
6510 @@ -185,12 +185,12 @@
6511  static struct i2c_driver 
6512  i2c_driver_tuner = 
6513  {
6514 -       "sab3036",              /* name       */
6515 -       I2C_DRIVERID_SAB3036,   /* ID         */
6516 -        I2C_DF_NOTIFY,
6517 -       tuner_probe,
6518 -       tuner_detach,
6519 -       tuner_command
6520 +       .name = "sab3036",              /* name       */
6521 +       .id = I2C_DRIVERID_SAB3036,     /* ID         */
6522 +        .flags = I2C_DF_NOTIFY,
6523 +       .attach_adapter = tuner_probe,
6524 +       .detach_client = tuner_detach,
6525 +       .command = tuner_command
6526  };
6527  
6528  static struct i2c_client client_template =
6529 diff -urN linux-2.4.24.org/drivers/video/matrox/i2c-matroxfb.c linux-2.4.24/drivers/video/matrox/i2c-matroxfb.c
6530 --- linux-2.4.24.org/drivers/video/matrox/i2c-matroxfb.c        2004-02-04 22:33:29.409768997 +0100
6531 +++ linux-2.4.24/drivers/video/matrox/i2c-matroxfb.c    2004-02-04 22:36:37.057747346 +0100
6532 @@ -87,19 +87,9 @@
6533         return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
6534  }
6535  
6536 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
6537 -       MOD_INC_USE_COUNT;
6538 -}
6539 -
6540 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
6541 -       MOD_DEC_USE_COUNT;
6542 -}
6543 -
6544  static struct i2c_adapter matrox_i2c_adapter_template =
6545  {
6546         .id =           I2C_HW_B_G400,
6547 -       .inc_use =      matroxfb_dh_inc_use,
6548 -       .dec_use =      matroxfb_dh_dec_use,
6549  };
6550  
6551  static struct i2c_algo_bit_data matrox_i2c_algo_template =
6552 diff -urN linux-2.4.24.org/drivers/video/matrox/matroxfb_maven.c linux-2.4.24/drivers/video/matrox/matroxfb_maven.c
6553 --- linux-2.4.24.org/drivers/video/matrox/matroxfb_maven.c      2004-02-04 22:33:29.237804756 +0100
6554 +++ linux-2.4.24/drivers/video/matrox/matroxfb_maven.c  2004-02-04 22:36:37.061746514 +0100
6555 @@ -1246,14 +1246,6 @@
6556  static unsigned short normal_i2c_range[] = { MAVEN_I2CID, MAVEN_I2CID, I2C_CLIENT_END };
6557  I2C_CLIENT_INSMOD;
6558  
6559 -static void maven_inc_use(struct i2c_client* clnt) {
6560 -       MOD_INC_USE_COUNT;
6561 -}
6562 -
6563 -static void maven_dec_use(struct i2c_client* clnt) {
6564 -       MOD_DEC_USE_COUNT;
6565 -}
6566 -
6567  static struct i2c_driver maven_driver;
6568  
6569  static int maven_detect_client(struct i2c_adapter* adapter, int address, unsigned short flags,
6570 @@ -1320,14 +1312,12 @@
6571  static int maven_driver_registered = 0;
6572  
6573  static struct i2c_driver maven_driver={
6574 -       "maven",
6575 -       I2C_DRIVERID_MGATVO,
6576 -       I2C_DF_NOTIFY,
6577 -       maven_attach_adapter,
6578 -       maven_detach_client,
6579 -       maven_command,
6580 -       maven_inc_use,
6581 -       maven_dec_use
6582 +       .name = "maven",
6583 +       .id = I2C_DRIVERID_MGATVO,
6584 +       .flags = I2C_DF_NOTIFY,
6585 +       .attach_adapter = maven_attach_adapter,
6586 +       .detach_client = maven_detach_client,
6587 +       .command = maven_command,
6588  };
6589  
6590  /* ************************** */
6591 diff -urN linux-2.4.24.org/include/linux/i2c-algo-8xx.h linux-2.4.24/include/linux/i2c-algo-8xx.h
6592 --- linux-2.4.24.org/include/linux/i2c-algo-8xx.h       1970-01-01 01:00:00.000000000 +0100
6593 +++ linux-2.4.24/include/linux/i2c-algo-8xx.h   2004-02-04 22:36:36.749811393 +0100
6594 @@ -0,0 +1,43 @@
6595 +/* ------------------------------------------------------------------------- */
6596 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM                      */
6597 +/*
6598 +    This program is free software; you can redistribute it and/or modify
6599 +    it under the terms of the GNU General Public License as published by
6600 +    the Free Software Foundation; either version 2 of the License, or
6601 +    (at your option) any later version.
6602 +
6603 +    This program is distributed in the hope that it will be useful,
6604 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
6605 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6606 +    GNU General Public License for more details.
6607 +
6608 +    You should have received a copy of the GNU General Public License
6609 +    along with this program; if not, write to the Free Software
6610 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
6611 +/* ------------------------------------------------------------------------- */
6612 +
6613 +/* $Id$ */
6614 +
6615 +#ifndef _LINUX_I2C_ALGO_8XX_H
6616 +#define _LINUX_I2C_ALGO_8XX_H
6617 +
6618 +#include "asm/commproc.h"
6619 +
6620 +struct i2c_algo_8xx_data {
6621 +       uint dp_addr;
6622 +       int reloc;
6623 +       volatile i2c8xx_t *i2c;
6624 +       volatile iic_t  *iip;
6625 +       volatile cpm8xx_t *cp;
6626 +
6627 +       int     (*setisr) (int irq,
6628 +                          void (*func)(void *, void *),
6629 +                          void *data);
6630 +
6631 +       u_char  temp[513];
6632 +};
6633 +
6634 +int i2c_8xx_add_bus(struct i2c_adapter *);
6635 +int i2c_8xx_del_bus(struct i2c_adapter *);
6636 +
6637 +#endif /* _LINUX_I2C_ALGO_8XX_H */
6638 diff -urN linux-2.4.24.org/include/linux/i2c-algo-bit.h linux-2.4.24/include/linux/i2c-algo-bit.h
6639 --- linux-2.4.24.org/include/linux/i2c-algo-bit.h       2004-02-04 22:30:56.871489160 +0100
6640 +++ linux-2.4.24/include/linux/i2c-algo-bit.h   2004-02-04 22:36:36.784804115 +0100
6641 @@ -21,12 +21,10 @@
6642  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6643     Frodo Looijaard <frodol@dds.nl> */
6644  
6645 -/* $Id$ */
6646 +/* $Id$ */
6647  
6648 -#ifndef I2C_ALGO_BIT_H
6649 -#define I2C_ALGO_BIT_H 1
6650 -
6651 -#include <linux/i2c.h>
6652 +#ifndef _LINUX_I2C_ALGO_BIT_H
6653 +#define _LINUX_I2C_ALGO_BIT_H
6654  
6655  /* --- Defines for bit-adapters ---------------------------------------        */
6656  /*
6657 @@ -42,9 +40,10 @@
6658         int  (*getscl) (void *data);
6659  
6660         /* local settings */
6661 -       int udelay;
6662 -       int mdelay;
6663 -       int timeout;
6664 +       int udelay;             /* half-clock-cycle time in microsecs */
6665 +                               /* i.e. clock is (500 / udelay) KHz */
6666 +       int mdelay;             /* in millisecs, unused */
6667 +       int timeout;            /* in jiffies */
6668  };
6669  
6670  #define I2C_BIT_ADAP_MAX       16
6671 @@ -52,4 +51,4 @@
6672  int i2c_bit_add_bus(struct i2c_adapter *);
6673  int i2c_bit_del_bus(struct i2c_adapter *);
6674  
6675 -#endif /* I2C_ALGO_BIT_H */
6676 +#endif /* _LINUX_I2C_ALGO_BIT_H */
6677 diff -urN linux-2.4.24.org/include/linux/i2c-algo-ibm_ocp.h linux-2.4.24/include/linux/i2c-algo-ibm_ocp.h
6678 --- linux-2.4.24.org/include/linux/i2c-algo-ibm_ocp.h   1970-01-01 01:00:00.000000000 +0100
6679 +++ linux-2.4.24/include/linux/i2c-algo-ibm_ocp.h       2004-02-04 22:36:36.788803283 +0100
6680 @@ -0,0 +1,52 @@
6681 +/* ------------------------------------------------------------------------- */
6682 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters         */
6683 +/* ------------------------------------------------------------------------- */
6684 +/*   Copyright (C) 1995-97 Simon G. Vogl
6685 +                   1998-99 Hans Berglund
6686 +
6687 +    This program is free software; you can redistribute it and/or modify
6688 +    it under the terms of the GNU General Public License as published by
6689 +    the Free Software Foundation; either version 2 of the License, or
6690 +    (at your option) any later version.
6691 +
6692 +    This program is distributed in the hope that it will be useful,
6693 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
6694 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6695 +    GNU General Public License for more details.
6696 +
6697 +    You should have received a copy of the GNU General Public License
6698 +    along with this program; if not, write to the Free Software
6699 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
6700 +/* ------------------------------------------------------------------------- */
6701 +
6702 +/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6703 +   Frodo Looijaard <frodol@dds.nl> */
6704 +
6705 +/* Modifications by MontaVista Software, August 2000
6706 +   Changes made to support the IIC peripheral on the IBM PPC 405 */
6707 +
6708 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
6709 +#define _LINUX_I2C_ALGO_IBM_OCP_H
6710 +
6711 +struct i2c_algo_iic_data {
6712 +       struct iic_regs *data;          /* private data for lolevel routines    */
6713 +       void (*setiic) (void *data, int ctl, int val);
6714 +       int  (*getiic) (void *data, int ctl);
6715 +       int  (*getown) (void *data);
6716 +       int  (*getclock) (void *data);
6717 +       void (*waitforpin) (void *data);     
6718 +
6719 +       /* local settings */
6720 +       int udelay;
6721 +       int mdelay;
6722 +       int timeout;
6723 +};
6724 +
6725 +
6726 +#define I2C_IIC_ADAP_MAX       16
6727 +
6728 +
6729 +int i2c_ocp_add_bus(struct i2c_adapter *);
6730 +int i2c_ocp_del_bus(struct i2c_adapter *);
6731 +
6732 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
6733 diff -urN linux-2.4.24.org/include/linux/i2c-algo-pcf.h linux-2.4.24/include/linux/i2c-algo-pcf.h
6734 --- linux-2.4.24.org/include/linux/i2c-algo-pcf.h       2004-02-04 22:30:56.872488952 +0100
6735 +++ linux-2.4.24/include/linux/i2c-algo-pcf.h   2004-02-04 22:36:36.810798708 +0100
6736 @@ -22,13 +22,12 @@
6737  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6738     Frodo Looijaard <frodol@dds.nl> */
6739  
6740 -/* $Id$ */
6741 +/* $Id$ */
6742  
6743 -#ifndef I2C_ALGO_PCF_H
6744 -#define I2C_ALGO_PCF_H 1
6745 +#ifndef _LINUX_I2C_ALGO_PCF_H
6746 +#define _LINUX_I2C_ALGO_PCF_H
6747  
6748 -/* --- Defines for pcf-adapters ---------------------------------------        */
6749 -#include <linux/i2c.h>
6750 +#include <linux/i2c-pcf8584.h>
6751  
6752  struct i2c_algo_pcf_data {
6753         void *data;             /* private data for lolevel routines    */
6754 @@ -49,4 +48,4 @@
6755  int i2c_pcf_add_bus(struct i2c_adapter *);
6756  int i2c_pcf_del_bus(struct i2c_adapter *);
6757  
6758 -#endif /* I2C_ALGO_PCF_H */
6759 +#endif /* _LINUX_I2C_ALGO_PCF_H */
6760 diff -urN linux-2.4.24.org/include/linux/i2c-dev.h linux-2.4.24/include/linux/i2c-dev.h
6761 --- linux-2.4.24.org/include/linux/i2c-dev.h    2004-02-04 22:30:49.848949493 +0100
6762 +++ linux-2.4.24/include/linux/i2c-dev.h        2004-02-04 22:36:36.831794341 +0100
6763 @@ -19,14 +19,16 @@
6764      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6765  */
6766  
6767 -/* $Id$ */
6768 -
6769 -#ifndef I2C_DEV_H
6770 -#define I2C_DEV_H
6771 +/* $Id$ */
6772  
6773 +#ifndef _LINUX_I2C_DEV_H
6774 +#define _LINUX_I2C_DEV_H
6775  
6776  #include <linux/types.h>
6777 -#include <linux/i2c.h>
6778 +
6779 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
6780 +#define minor(d) MINOR(d)
6781 +#endif
6782  
6783  /* Some IOCTL commands are defined in <linux/i2c.h> */
6784  /* Note: 10-bit addresses are NOT supported! */
6785 @@ -45,137 +47,4 @@
6786         __u32 nmsgs;            /* number of i2c_msgs */
6787  };
6788  
6789 -#ifndef __KERNEL__
6790 -
6791 -#include <sys/ioctl.h>
6792 -
6793 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, 
6794 -                                     int size, union i2c_smbus_data *data)
6795 -{
6796 -       struct i2c_smbus_ioctl_data args;
6797 -
6798 -       args.read_write = read_write;
6799 -       args.command = command;
6800 -       args.size = size;
6801 -       args.data = data;
6802 -       return ioctl(file,I2C_SMBUS,&args);
6803 -}
6804 -
6805 -
6806 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
6807 -{
6808 -       return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
6809 -}
6810 -       
6811 -static inline __s32 i2c_smbus_read_byte(int file)
6812 -{
6813 -       union i2c_smbus_data data;
6814 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
6815 -               return -1;
6816 -       else
6817 -               return 0x0FF & data.byte;
6818 -}
6819 -
6820 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
6821 -{
6822 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
6823 -                               I2C_SMBUS_BYTE,NULL);
6824 -}
6825 -
6826 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
6827 -{
6828 -       union i2c_smbus_data data;
6829 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6830 -                            I2C_SMBUS_BYTE_DATA,&data))
6831 -               return -1;
6832 -       else
6833 -               return 0x0FF & data.byte;
6834 -}
6835 -
6836 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, 
6837 -                                              __u8 value)
6838 -{
6839 -       union i2c_smbus_data data;
6840 -       data.byte = value;
6841 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6842 -                               I2C_SMBUS_BYTE_DATA, &data);
6843 -}
6844 -
6845 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
6846 -{
6847 -       union i2c_smbus_data data;
6848 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6849 -                            I2C_SMBUS_WORD_DATA,&data))
6850 -               return -1;
6851 -       else
6852 -               return 0x0FFFF & data.word;
6853 -}
6854 -
6855 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, 
6856 -                                              __u16 value)
6857 -{
6858 -       union i2c_smbus_data data;
6859 -       data.word = value;
6860 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6861 -                               I2C_SMBUS_WORD_DATA, &data);
6862 -}
6863 -
6864 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
6865 -{
6866 -       union i2c_smbus_data data;
6867 -       data.word = value;
6868 -       if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6869 -                            I2C_SMBUS_PROC_CALL,&data))
6870 -               return -1;
6871 -       else
6872 -               return 0x0FFFF & data.word;
6873 -}
6874 -
6875 -
6876 -/* Returns the number of read bytes */
6877 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command, 
6878 -                                              __u8 *values)
6879 -{
6880 -       union i2c_smbus_data data;
6881 -       int i;
6882 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6883 -                            I2C_SMBUS_BLOCK_DATA,&data))
6884 -               return -1;
6885 -       else {
6886 -               for (i = 1; i <= data.block[0]; i++)
6887 -                       values[i-1] = data.block[i];
6888 -                       return data.block[0];
6889 -       }
6890 -}
6891 -
6892 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, 
6893 -                                               __u8 length, __u8 *values)
6894 -{
6895 -       union i2c_smbus_data data;
6896 -       int i;
6897 -       if (length > 32)
6898 -               length = 32;
6899 -       for (i = 1; i <= length; i++)
6900 -               data.block[i] = values[i-1];
6901 -       data.block[0] = length;
6902 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6903 -                               I2C_SMBUS_BLOCK_DATA, &data);
6904 -}
6905 -
6906 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
6907 -                                               __u8 length, __u8 *values)
6908 -{
6909 -       union i2c_smbus_data data;
6910 -       int i;
6911 -       if (length > 32)
6912 -               length = 32;
6913 -       for (i = 1; i <= length; i++)
6914 -               data.block[i] = values[i-1];
6915 -       data.block[0] = length;
6916 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6917 -                               I2C_SMBUS_I2C_BLOCK_DATA, &data);
6918 -}
6919 -
6920 -#endif /* ndef __KERNEL__ */
6921 -
6922 -#endif
6923 +#endif /* _LINUX_I2C_DEV_H */
6924 diff -urN linux-2.4.24.org/include/linux/i2c-elektor.h linux-2.4.24/include/linux/i2c-elektor.h
6925 --- linux-2.4.24.org/include/linux/i2c-elektor.h        2004-02-04 22:30:56.931476685 +0100
6926 +++ linux-2.4.24/include/linux/i2c-elektor.h    2004-02-04 22:36:36.834793718 +0100
6927 @@ -1,47 +0,0 @@
6928 -/* ------------------------------------------------------------------------- */
6929 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes             */
6930 -/* ------------------------------------------------------------------------- */
6931 -/*   Copyright (C) 1995-97 Simon G. Vogl
6932 -                   1998-99 Hans Berglund
6933 -
6934 -    This program is free software; you can redistribute it and/or modify
6935 -    it under the terms of the GNU General Public License as published by
6936 -    the Free Software Foundation; either version 2 of the License, or
6937 -    (at your option) any later version.
6938 -
6939 -    This program is distributed in the hope that it will be useful,
6940 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
6941 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6942 -    GNU General Public License for more details.
6943 -
6944 -    You should have received a copy of the GNU General Public License
6945 -    along with this program; if not, write to the Free Software
6946 -    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
6947 -/* ------------------------------------------------------------------------- */
6948 -
6949 -/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6950 -   Frodo Looijaard <frodol@dds.nl> */
6951 -
6952 -/* $Id$ */
6953 -
6954 -#ifndef I2C_PCF_ELEKTOR_H
6955 -#define I2C_PCF_ELEKTOR_H 1
6956 -
6957 -/*
6958 - * This struct contains the hw-dependent functions of PCF8584 adapters to
6959 - * manipulate the registers, and to init any hw-specific features.
6960 - * vdovikin: removed: this module in real supports only one device,
6961 - * due to missing arguments in some functions, called from the algo-pcf module.
6962 - * Sometimes it's need to be rewriten -
6963 - * but for now just remove this for simpler reading */
6964 -
6965 -/*
6966 -struct i2c_pcf_isa {
6967 -       int pi_base;
6968 -       int pi_irq;
6969 -       int pi_clock;
6970 -       int pi_own;
6971 -};
6972 -*/
6973 -
6974 -#endif /* PCF_ELEKTOR_H */
6975 diff -urN linux-2.4.24.org/include/linux/i2c.h linux-2.4.24/include/linux/i2c.h
6976 --- linux-2.4.24.org/include/linux/i2c.h        2004-02-04 22:30:49.830953235 +0100
6977 +++ linux-2.4.24/include/linux/i2c.h    2004-02-04 22:36:36.957768140 +0100
6978 @@ -23,36 +23,33 @@
6979  /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and
6980     Frodo Looijaard <frodol@dds.nl> */
6981  
6982 -/* $Id$ */
6983 +/* $Id$ */
6984  
6985 -#ifndef I2C_H
6986 -#define I2C_H
6987 +#ifndef _LINUX_I2C_H
6988 +#define _LINUX_I2C_H
6989  
6990 -#define I2C_DATE "20010830"
6991 -#define I2C_VERSION "2.6.1"
6992 +#define I2C_DATE "20040115"
6993 +#define I2C_VERSION "2.8.3"
6994  
6995 -#include <linux/i2c-id.h>      /* id values of adapters et. al.        */
6996 +#include <linux/module.h>
6997  #include <linux/types.h>
6998 -
6999 -
7000 -struct i2c_msg;
7001 -
7002 -
7003 -#ifdef __KERNEL__
7004 -
7005 -/* --- Includes and compatibility declarations ------------------------ */
7006 -
7007 +#include <linux/errno.h>
7008 +#include <linux/sched.h>
7009  #include <asm/semaphore.h>
7010 -#include <linux/config.h>
7011 +#include <linux/i2c-id.h>
7012 +
7013 +#include <linux/version.h>
7014 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
7015 +#define MODULE_LICENSE(x)
7016 +#endif
7017  
7018  /* --- General options ------------------------------------------------        */
7019  
7020 -#define I2C_ALGO_MAX   4               /* control memory consumption   */
7021 -#define I2C_ADAP_MAX   16
7022 +#define I2C_ADAP_MAX   16              /* control memory consumption   */
7023  #define I2C_DRIVER_MAX 16
7024  #define I2C_CLIENT_MAX 32
7025 -#define I2C_DUMMY_MAX 4
7026  
7027 +struct i2c_msg;
7028  struct i2c_algorithm;
7029  struct i2c_adapter;
7030  struct i2c_client;
7031 @@ -60,7 +57,6 @@
7032  struct i2c_client_address_data;
7033  union i2c_smbus_data;
7034  
7035 -
7036  /*
7037   * The master routines are the ones normally used to transmit data to devices
7038   * on a bus (or read from them). Apart from two basic transfer functions to 
7039 @@ -113,6 +109,8 @@
7040  extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
7041                                        u8 command, u8 length,
7042                                        u8 *values);
7043 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
7044 +                                         u8 command, u8 *values);
7045  extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
7046                                            u8 command, u8 length,
7047                                            u8 *values);
7048 @@ -125,6 +123,7 @@
7049   */
7050  
7051  struct i2c_driver {
7052 +       struct module *owner;
7053         char name[32];
7054         int id;
7055         unsigned int flags;             /* div., see below              */
7056 @@ -148,18 +147,6 @@
7057          * with the device.
7058          */
7059         int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
7060 -       
7061 -       /* These two are mainly used for bookkeeping & dynamic unloading of 
7062 -        * kernel modules. inc_use tells the driver that a client is being  
7063 -        * used by another module & that it should increase its ref. counter.
7064 -        * dec_use is the inverse operation.
7065 -        * NB: Make sure you have no circular dependencies, or else you get a 
7066 -        * deadlock when trying to unload the modules.
7067 -       * You should use the i2c_{inc,dec}_use_client functions instead of
7068 -       * calling this function directly.
7069 -        */
7070 -       void (*inc_use)(struct i2c_client *client);
7071 -       void (*dec_use)(struct i2c_client *client);
7072  };
7073  
7074  /*
7075 @@ -192,6 +179,7 @@
7076   * to name two of the most common.
7077   */
7078  struct i2c_algorithm {
7079 +       struct module *owner;                   /* future use --km      */
7080         char name[32];                          /* textual description  */
7081         unsigned int id;
7082  
7083 @@ -221,16 +209,13 @@
7084   * with the access algorithms necessary to access it.
7085   */
7086  struct i2c_adapter {
7087 +       struct module *owner;
7088         char name[32];  /* some useful name to identify the adapter     */
7089         unsigned int id;/* == is algo->id | hwdep.struct->id,           */
7090                         /* for registered values see below              */
7091         struct i2c_algorithm *algo;/* the algorithm to access the bus   */
7092         void *algo_data;
7093  
7094 -       /* --- These may be NULL, but should increase the module use count */
7095 -       void (*inc_use)(struct i2c_adapter *);
7096 -       void (*dec_use)(struct i2c_adapter *);
7097 -
7098         /* --- administration stuff. */
7099         int (*client_register)(struct i2c_client *);
7100         int (*client_unregister)(struct i2c_client *);
7101 @@ -241,11 +226,11 @@
7102                         /* and can be set via the i2c_ioctl call        */
7103  
7104                         /* data fields that are valid for all devices   */
7105 -       struct semaphore lock;  
7106 +       struct semaphore bus;
7107 +       struct semaphore list;  
7108         unsigned int flags;/* flags specifying div. data                */
7109  
7110         struct i2c_client *clients[I2C_CLIENT_MAX];
7111 -       int client_count;
7112  
7113         int timeout;
7114         int retries;
7115 @@ -264,6 +249,9 @@
7116  #define I2C_CLIENT_ALLOW_USE           0x01    /* Client allows access */
7117  #define I2C_CLIENT_ALLOW_MULTIPLE_USE  0x02    /* Allow multiple access-locks */
7118                                                 /* on an i2c_client */
7119 +#define I2C_CLIENT_PEC  0x04                   /* Use Packet Error Checking */
7120 +#define I2C_CLIENT_TEN 0x10                    /* we have a ten bit chip address       */
7121 +                                               /* Must equal I2C_M_TEN below */
7122  
7123  /* i2c_client_address_data is the struct for holding default client
7124   * addresses for a driver and for the parameters supplied on the
7125 @@ -302,12 +290,6 @@
7126  extern int i2c_attach_client(struct i2c_client *);
7127  extern int i2c_detach_client(struct i2c_client *);
7128  
7129 -/* Only call these if you grab a resource that makes unloading the
7130 -   client and the adapter it is on completely impossible. Like when a
7131 -   /proc directory is entered. */
7132 -extern void i2c_inc_use_client(struct i2c_client *);
7133 -extern void i2c_dec_use_client(struct i2c_client *);
7134 -
7135  /* New function: This is to get an i2c_client-struct for controlling the 
7136     client either by using i2c_control-function or having the 
7137     client-module export functions that can be used with the i2c_client
7138 @@ -341,6 +323,15 @@
7139                 struct i2c_client_address_data *address_data,
7140                 i2c_client_found_addr_proc *found_proc);
7141  
7142 +static inline int i2c_client_command(struct i2c_client *client,
7143 +                                    unsigned int cmd, void *arg)
7144 +{
7145 +       if (client->driver && client->driver->command)
7146 +               return client->driver->command(client, cmd, arg);
7147 +       else
7148 +               return -EINVAL;
7149 +}
7150 +
7151  /* An ioctl like call to set div. parameters of the adapter.
7152   */
7153  extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
7154 @@ -358,8 +349,6 @@
7155  /* Return 1 if adapter supports everything we need, 0 if not. */
7156  extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
7157  
7158 -#endif /* __KERNEL__ */
7159 -
7160  /*
7161   * I2C Message - used for pure i2c transaction, also from /dev interface
7162   */
7163 @@ -370,15 +359,28 @@
7164  #define I2C_M_RD       0x01
7165  #define I2C_M_NOSTART  0x4000
7166  #define I2C_M_REV_DIR_ADDR     0x2000
7167 +#define I2C_M_IGNORE_NAK       0x1000
7168 +#define I2C_M_NO_RD_ACK                0x0800
7169 +#define I2C_M_RECV_LEN         0x0400 /* length will be first received byte */
7170 +#define I2C_M_RECV_PEC         0x0200 /* receive one more than the returned
7171 +                                         length byte for the PEC */
7172         __u16 len;              /* msg length                           */
7173         __u8 *buf;              /* pointer to msg data                  */
7174 +       int err;
7175 +       short done;
7176  };
7177  
7178  /* To determine what functionality is present */
7179  
7180  #define I2C_FUNC_I2C                   0x00000001
7181  #define I2C_FUNC_10BIT_ADDR            0x00000002
7182 -#define I2C_FUNC_PROTOCOL_MANGLING     0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
7183 +#define I2C_FUNC_PROTOCOL_MANGLING     0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
7184 +#define I2C_FUNC_SMBUS_HWPEC_CALC      0x00000008 /* SMBus 2.0 */
7185 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
7186 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
7187 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC   0x00002000 /* SMBus 2.0 */
7188 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
7189 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
7190  #define I2C_FUNC_SMBUS_QUICK           0x00010000 
7191  #define I2C_FUNC_SMBUS_READ_BYTE       0x00020000 
7192  #define I2C_FUNC_SMBUS_WRITE_BYTE      0x00040000 
7193 @@ -389,8 +391,12 @@
7194  #define I2C_FUNC_SMBUS_PROC_CALL       0x00800000 
7195  #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000 
7196  #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 
7197 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK  0x04000000 /* New I2C-like block */
7198 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
7199 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK  0x04000000 /* I2C-like block xfer  */
7200 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
7201 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2         0x10000000 /* I2C-like block xfer  */
7202 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
7203 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
7204 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
7205  
7206  #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
7207                              I2C_FUNC_SMBUS_WRITE_BYTE
7208 @@ -402,13 +408,28 @@
7209                                    I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7210  #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
7211                                    I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
7212 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
7213 +                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
7214 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
7215 +                                      I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
7216 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC  I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
7217 +                                      I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
7218 +
7219 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC           I2C_FUNC_SMBUS_READ_BYTE_DATA
7220 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC          I2C_FUNC_SMBUS_WRITE_BYTE_DATA
7221 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC      I2C_FUNC_SMBUS_READ_WORD_DATA
7222 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC     I2C_FUNC_SMBUS_WRITE_WORD_DATA
7223 +#define I2C_FUNC_SMBUS_BYTE_PEC                        I2C_FUNC_SMBUS_BYTE_DATA
7224 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC           I2C_FUNC_SMBUS_WORD_DATA
7225  
7226  #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
7227                              I2C_FUNC_SMBUS_BYTE | \
7228                              I2C_FUNC_SMBUS_BYTE_DATA | \
7229                              I2C_FUNC_SMBUS_WORD_DATA | \
7230                              I2C_FUNC_SMBUS_PROC_CALL | \
7231 -                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7232 +                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
7233 +                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
7234 +                            I2C_FUNC_SMBUS_I2C_BLOCK
7235  
7236  /* 
7237   * Data for SMBus Messages 
7238 @@ -418,8 +439,9 @@
7239  union i2c_smbus_data {
7240         __u8 byte;
7241         __u16 word;
7242 -       __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
7243 +       __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
7244                           /* one more for read length in block process call */
7245 +                                                   /* and one more for PEC */
7246  };
7247  
7248  /* smbus_access read or write markers */
7249 @@ -435,6 +457,11 @@
7250  #define I2C_SMBUS_PROC_CALL        4
7251  #define I2C_SMBUS_BLOCK_DATA       5
7252  #define I2C_SMBUS_I2C_BLOCK_DATA    6
7253 +#define I2C_SMBUS_BLOCK_PROC_CALL   7          /* SMBus 2.0 */
7254 +#define I2C_SMBUS_BLOCK_DATA_PEC    8          /* SMBus 2.0 */
7255 +#define I2C_SMBUS_PROC_CALL_PEC     9          /* SMBus 2.0 */
7256 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC  10      /* SMBus 2.0 */
7257 +#define I2C_SMBUS_WORD_DATA_PEC           11           /* SMBus 2.0 */
7258  
7259  
7260  /* ----- commands for the ioctl like i2c_command call:
7261 @@ -460,6 +487,7 @@
7262  
7263  #define I2C_FUNCS      0x0705  /* Get the adapter functionality */
7264  #define I2C_RDWR       0x0707  /* Combined R/W transfer (one stop only)*/
7265 +#define I2C_PEC                0x0708  /* != 0 for SMBus PEC                   */
7266  #if 0
7267  #define I2C_ACK_TEST   0x0710  /* See if a slave is at a specific address */
7268  #endif
7269 @@ -475,16 +503,6 @@
7270  
7271  #define I2C_MAJOR      89              /* Device major number          */
7272  
7273 -#ifdef __KERNEL__
7274 -
7275 -#  ifndef NULL
7276 -#    define NULL ( (void *) 0 )
7277 -#  endif
7278 -
7279 -#  ifndef ENODEV
7280 -#    include <asm/errno.h>
7281 -#  endif
7282 -
7283  /* These defines are used for probing i2c client addresses */
7284  /* Default fill of many variables */
7285  #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
7286 @@ -546,5 +564,11 @@
7287  #define i2c_is_isa_adapter(adapptr) \
7288          ((adapptr)->algo->id == I2C_ALGO_ISA)
7289  
7290 -#endif /* def __KERNEL__ */
7291 -#endif /* I2C_H */
7292 +/* Tiny delay function used by the i2c bus drivers */
7293 +static inline void i2c_delay(signed long timeout)
7294 +{
7295 +       set_current_state(TASK_INTERRUPTIBLE);
7296 +       schedule_timeout(timeout);
7297 +}
7298 +
7299 +#endif /* _LINUX_I2C_H */
7300 diff -urN linux-2.4.24.org/include/linux/i2c-id.h linux-2.4.24/include/linux/i2c-id.h
7301 --- linux-2.4.24.org/include/linux/i2c-id.h     2004-02-04 22:30:48.969132451 +0100
7302 +++ linux-2.4.24/include/linux/i2c-id.h 2004-02-04 22:36:37.005758159 +0100
7303 @@ -20,10 +20,11 @@
7304      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
7305  /* ------------------------------------------------------------------------- */
7306  
7307 -/* $Id$ */
7308 +/* $Id$ */
7309 +
7310 +#ifndef LINUX_I2C_ID_H
7311 +#define LINUX_I2C_ID_H
7312  
7313 -#ifndef I2C_ID_H
7314 -#define I2C_ID_H
7315  /*
7316   * This file is part of the i2c-bus package and contains the identifier
7317   * values for drivers, adapters and other folk populating these serial
7318 @@ -90,10 +91,25 @@
7319  #define I2C_DRIVERID_DRP3510   43     /* ADR decoder (Astra Radio)     */
7320  #define I2C_DRIVERID_SP5055    44     /* Satellite tuner               */
7321  #define I2C_DRIVERID_STV0030   45     /* Multipurpose switch           */
7322 +#define I2C_DRIVERID_SAA7108   46     /* video decoder, image scaler   */
7323 +#define I2C_DRIVERID_DS1307    47     /* DS1307 real time clock        */
7324  #define I2C_DRIVERID_ADV7175   48     /* ADV 7175/7176 video encoder   */
7325 -#define I2C_DRIVERID_MAX1617   56     /* temp sensor                   */
7326 -#define I2C_DRIVERID_SAA7191   57     /* video decoder                 */
7327 -#define I2C_DRIVERID_INDYCAM   58     /* SGI IndyCam                   */
7328 +#define I2C_DRIVERID_ZR36067   49     /* Zoran 36067 video encoder     */
7329 +#define I2C_DRIVERID_ZR36120   50     /* Zoran 36120 video encoder     */
7330 +#define I2C_DRIVERID_24LC32A   51      /* Microchip 24LC32A 32k EEPROM */
7331 +#define I2C_DRIVERID_STM41T00  52      /* real time clock              */
7332 +#define I2C_DRIVERID_UDA1342   53      /* UDA1342 audio codec          */
7333 +#define I2C_DRIVERID_ADV7170   54      /* video encoder                */
7334 +#define I2C_DRIVERID_RADEON    55      /* I2C bus on Radeon boards     */
7335 +#define I2C_DRIVERID_MAX1617   56      /* temp sensor                  */
7336 +#define I2C_DRIVERID_SAA7191   57      /* video encoder                */
7337 +#define I2C_DRIVERID_INDYCAM   58      /* SGI IndyCam                  */
7338 +#define I2C_DRIVERID_BT832     59      /* CMOS camera video processor  */
7339 +#define I2C_DRIVERID_TDA9887   60      /* TDA988x IF-PLL demodulator   */
7340 +#define I2C_DRIVERID_OVCAMCHIP 61      /* OmniVision CMOS image sens.  */
7341 +#define I2C_DRIVERID_TDA7313   62      /* TDA7313 audio processor      */
7342 +
7343 +
7344  
7345  #define I2C_DRIVERID_EXP0      0xF0    /* experimental use id's        */
7346  #define I2C_DRIVERID_EXP1      0xF1
7347 @@ -102,6 +118,8 @@
7348  
7349  #define I2C_DRIVERID_I2CDEV    900
7350  #define I2C_DRIVERID_I2CPROC   901
7351 +#define I2C_DRIVERID_ARP        902    /* SMBus ARP Client              */
7352 +#define I2C_DRIVERID_ALERT      903    /* SMBus Alert Responder Client  */
7353  
7354  /* IDs --   Use DRIVERIDs 1000-1999 for sensors. 
7355     These were originally in sensors.h in the lm_sensors package */
7356 @@ -131,6 +149,26 @@
7357  #define I2C_DRIVERID_ADM1024 1025
7358  #define I2C_DRIVERID_IT87 1026
7359  #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
7360 +#define I2C_DRIVERID_FSCPOS 1028
7361 +#define I2C_DRIVERID_FSCSCY 1029
7362 +#define I2C_DRIVERID_PCF8591 1030
7363 +#define I2C_DRIVERID_SMSC47M1 1031
7364 +#define I2C_DRIVERID_VT1211 1032
7365 +#define I2C_DRIVERID_LM92 1033
7366 +#define I2C_DRIVERID_VT8231 1034
7367 +#define I2C_DRIVERID_SMARTBATT 1035
7368 +#define I2C_DRIVERID_BMCSENSORS 1036
7369 +#define I2C_DRIVERID_FS451 1037
7370 +#define I2C_DRIVERID_W83627HF 1038
7371 +#define I2C_DRIVERID_LM85 1039
7372 +#define I2C_DRIVERID_LM83 1040
7373 +#define I2C_DRIVERID_SAA1064 1041
7374 +#define I2C_DRIVERID_LM90 1042
7375 +#define I2C_DRIVERID_ASB100 1043
7376 +#define I2C_DRIVERID_MAX6650 1044
7377 +#define I2C_DRIVERID_XEONTEMP 1045
7378 +#define I2C_DRIVERID_FSCHER 1046
7379 +#define I2C_DRIVERID_W83L785TS 1047
7380  
7381  /*
7382   * ---- Adapter types ----------------------------------------------------
7383 @@ -147,14 +185,21 @@
7384  #define I2C_ALGO_ISA   0x050000        /* lm_sensors ISA pseudo-adapter */
7385  #define I2C_ALGO_SAA7146 0x060000      /* SAA 7146 video decoder bus   */
7386  #define I2C_ALGO_ACB   0x070000        /* ACCESS.bus algorithm         */
7387 -
7388 +#define I2C_ALGO_IIC    0x080000       /* ITE IIC bus */
7389 +#define I2C_ALGO_SAA7134 0x090000
7390 +#define I2C_ALGO_MPC824X 0x0a0000      /* Motorola 8240 / 8245         */
7391 +#define I2C_ALGO_IPMI  0x0b0000        /* IPMI dummy adapter */
7392 +#define I2C_ALGO_IPMB  0x0c0000        /* IPMB adapter */
7393 +#define I2C_ALGO_MPC107 0x0d0000
7394  #define I2C_ALGO_EC     0x100000        /* ACPI embedded controller     */
7395  
7396  #define I2C_ALGO_MPC8XX 0x110000       /* MPC8xx PowerPC I2C algorithm */
7397 -
7398 -#define I2C_ALGO_SIBYTE 0x120000       /* Broadcom SiByte SOCs         */
7399 -
7400 -#define I2C_ALGO_SGI   0x130000        /* SGI algorithm                */
7401 +#define I2C_ALGO_OCP    0x120000       /* IBM or otherwise On-chip I2C algorithm */
7402 +#define I2C_ALGO_BITHS 0x130000        /* enhanced bit style adapters  */
7403 +#define I2C_ALGO_OCP_IOP3XX  0x140000  /* XSCALE IOP3XX On-chip I2C alg */
7404 +#define I2C_ALGO_SIBYTE        0x150000        /* Broadcom SiByte SOCs         */
7405 +#define I2C_ALGO_SGI   0x160000        /* SGI algorithm                */
7406 +#define I2C_ALGO_USB   0x170000        /* USB algorithm                */
7407  
7408  #define I2C_ALGO_EXP   0x800000        /* experimental                 */
7409  
7410 @@ -182,27 +227,45 @@
7411  #define I2C_HW_B_I810  0x0a    /* Intel I810                           */
7412  #define I2C_HW_B_VOO   0x0b    /* 3dfx Voodoo 3 / Banshee              */
7413  #define I2C_HW_B_PPORT  0x0c   /* Primitive parallel port adapter      */
7414 +#define I2C_HW_B_SAVG  0x0d    /* Savage 4                             */
7415 +#define I2C_HW_B_SCX200        0x0e    /* Nat'l Semi SCx200 I2C                */
7416  #define I2C_HW_B_RIVA  0x10    /* Riva based graphics cards            */
7417  #define I2C_HW_B_IOC   0x11    /* IOC bit-wiggling                     */
7418  #define I2C_HW_B_TSUNA  0x12   /* DEC Tsunami chipset                  */
7419 +#define I2C_HW_B_FRODO  0x13    /* 2d3D, Inc. SA-1110 Development Board */
7420 +#define I2C_HW_B_OMAHA  0x14    /* Omaha I2C interface (ARM)           */
7421 +#define I2C_HW_B_GUIDE  0x15    /* Guide bit-basher                    */
7422 +#define I2C_HW_B_IXP2000 0x16  /* GPIO on IXP2000 systems              */
7423 +#define I2C_HW_B_IXP425 0x17   /* GPIO on IXP425 systems               */
7424 +#define I2C_HW_B_S3VIA 0x18    /* S3Via ProSavage adapter              */
7425 +#define I2C_HW_B_ZR36067 0x19  /* Zoran-36057/36067 based boards       */
7426 +#define I2C_HW_B_PCILYNX 0x20  /* TI PCILynx I2C adapter               */
7427  
7428  /* --- PCF 8584 based algorithms                                       */
7429  #define I2C_HW_P_LP    0x00    /* Parallel port interface              */
7430  #define I2C_HW_P_ISA   0x01    /* generic ISA Bus inteface card        */
7431  #define I2C_HW_P_ELEK  0x02    /* Elektor ISA Bus inteface card        */
7432  
7433 +/* --- USB based adapters                                              */
7434 +#define I2C_HW_USB_USBVISION   0x00
7435 +
7436  /* --- ACPI Embedded controller algorithms                              */
7437  #define I2C_HW_ACPI_EC          0x00
7438  
7439 +/* --- MPC824x PowerPC adapters                                                */
7440 +#define I2C_HW_MPC824X 0x00    /* Motorola 8240 / 8245                 */
7441 +
7442  /* --- MPC8xx PowerPC adapters                                         */
7443  #define I2C_HW_MPC8XX_EPON 0x00        /* Eponymous MPC8xx I2C adapter         */
7444  
7445 -/* --- Broadcom SiByte adapters                                                */
7446 -#define I2C_HW_SIBYTE  0x00
7447 +/* --- ITE based algorithms                                            */
7448 +#define I2C_HW_I_IIC   0x00    /* controller on the ITE */
7449 +
7450 +/* --- PowerPC on-chip adapters                                                */
7451 +#define I2C_HW_OCP 0x00        /* IBM on-chip I2C adapter      */
7452  
7453 -/* --- SGI adapters                                                    */
7454 -#define I2C_HW_SGI_VINO        0x00
7455 -#define I2C_HW_SGI_MACE        0x01
7456 +/* --- XSCALE on-chip adapters                          */
7457 +#define I2C_HW_IOP321 0x00
7458  
7459  /* --- SMBus only adapters                                             */
7460  #define I2C_HW_SMBUS_PIIX4     0x00
7461 @@ -213,9 +276,27 @@
7462  #define I2C_HW_SMBUS_AMD756    0x05
7463  #define I2C_HW_SMBUS_SIS5595   0x06
7464  #define I2C_HW_SMBUS_ALI1535   0x07
7465 +#define I2C_HW_SMBUS_SIS630    0x08
7466 +#define I2C_HW_SMBUS_SIS645    0x09
7467 +#define I2C_HW_SMBUS_AMD8111   0x0a
7468 +#define I2C_HW_SMBUS_SCX200    0x0b
7469 +#define I2C_HW_SMBUS_NFORCE2   0x0c
7470  #define I2C_HW_SMBUS_W9968CF   0x0d
7471 +#define I2C_HW_SMBUS_OV511     0x0e    /* OV511(+) USB 1.1 webcam ICs  */
7472 +#define I2C_HW_SMBUS_OV518     0x0f    /* OV518(+) USB 1.1 webcam ICs  */
7473 +#define I2C_HW_SMBUS_OV519     0x10    /* OV519 USB 1.1 webcam IC      */
7474 +#define I2C_HW_SMBUS_OVFX2     0x11    /* Cypress Ez-USB FX2 USB 2.0   */
7475  
7476  /* --- ISA pseudo-adapter                                              */
7477  #define I2C_HW_ISA 0x00
7478  
7479 -#endif /* I2C_ID_H */
7480 +/* --- IPMI pseudo-adapter                                             */
7481 +#define I2C_HW_IPMI 0x00
7482 +
7483 +/* --- IPMB adapter                                            */
7484 +#define I2C_HW_IPMB 0x00
7485 +
7486 +/* --- MCP107 adapter */
7487 +#define I2C_HW_MPC107 0x00
7488 +
7489 +#endif /* LINUX_I2C_ID_H */
7490 diff -urN linux-2.4.24.org/include/linux/i2c-pcf8584.h linux-2.4.24/include/linux/i2c-pcf8584.h
7491 --- linux-2.4.24.org/include/linux/i2c-pcf8584.h        1970-01-01 01:00:00.000000000 +0100
7492 +++ linux-2.4.24/include/linux/i2c-pcf8584.h    2004-02-04 22:36:37.010757119 +0100
7493 @@ -0,0 +1,78 @@
7494 +/* -------------------------------------------------------------------- */
7495 +/* i2c-pcf8584.h: PCF 8584 global defines                              */
7496 +/* -------------------------------------------------------------------- */
7497 +/*   Copyright (C) 1996 Simon G. Vogl
7498 +                   1999 Hans Berglund
7499 +
7500 +    This program is free software; you can redistribute it and/or modify
7501 +    it under the terms of the GNU General Public License as published by
7502 +    the Free Software Foundation; either version 2 of the License, or
7503 +    (at your option) any later version.
7504 +
7505 +    This program is distributed in the hope that it will be useful,
7506 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
7507 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7508 +    GNU General Public License for more details.
7509 +
7510 +    You should have received a copy of the GNU General Public License
7511 +    along with this program; if not, write to the Free Software
7512 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.          */
7513 +/* --------------------------------------------------------------------        */
7514 +
7515 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
7516 +
7517 +/* $Id$ */
7518 +
7519 +#ifndef _LINUX_I2C_PCF8584_H
7520 +#define _LINUX_I2C_PCF8584_H
7521 +
7522 +/* ----- Control register bits ----------------------------------------        */
7523 +#define I2C_PCF_PIN    0x80
7524 +#define I2C_PCF_ESO    0x40
7525 +#define I2C_PCF_ES1    0x20
7526 +#define I2C_PCF_ES2    0x10
7527 +#define I2C_PCF_ENI    0x08
7528 +#define I2C_PCF_STA    0x04
7529 +#define I2C_PCF_STO    0x02
7530 +#define I2C_PCF_ACK    0x01
7531 +
7532 +#define I2C_PCF_START    (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7533 +#define I2C_PCF_STOP     (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
7534 +#define I2C_PCF_REPSTART (              I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7535 +#define I2C_PCF_IDLE     (I2C_PCF_PIN | I2C_PCF_ESO               | I2C_PCF_ACK)
7536 +
7537 +/* ----- Status register bits -----------------------------------------        */
7538 +/*#define I2C_PCF_PIN  0x80    as above*/
7539 +
7540 +#define I2C_PCF_INI 0x40   /* 1 if not initialized */
7541 +#define I2C_PCF_STS 0x20
7542 +#define I2C_PCF_BER 0x10
7543 +#define I2C_PCF_AD0 0x08
7544 +#define I2C_PCF_LRB 0x08
7545 +#define I2C_PCF_AAS 0x04
7546 +#define I2C_PCF_LAB 0x02
7547 +#define I2C_PCF_BB  0x01
7548 +
7549 +/* ----- Chip clock frequencies ---------------------------------------        */
7550 +#define I2C_PCF_CLK3   0x00
7551 +#define I2C_PCF_CLK443 0x10
7552 +#define I2C_PCF_CLK6   0x14
7553 +#define I2C_PCF_CLK    0x18
7554 +#define I2C_PCF_CLK12  0x1c
7555 +
7556 +/* ----- transmission frequencies -------------------------------------        */
7557 +#define I2C_PCF_TRNS90 0x00    /*  90 kHz */
7558 +#define I2C_PCF_TRNS45 0x01    /*  45 kHz */
7559 +#define I2C_PCF_TRNS11 0x02    /*  11 kHz */
7560 +#define I2C_PCF_TRNS15 0x03    /* 1.5 kHz */
7561 +
7562 +
7563 +/* ----- Access to internal registers according to ES1,ES2 ------------        */
7564 +/* they are mapped to the data port ( a0 = 0 )                                 */
7565 +/* available when ESO == 0 :                                           */
7566 +
7567 +#define I2C_PCF_OWNADR 0
7568 +#define I2C_PCF_INTREG I2C_PCF_ES2
7569 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7570 +
7571 +#endif /* _LINUX_I2C_PCF8584_H */
7572 diff -urN linux-2.4.24.org/include/linux/i2c-proc.h linux-2.4.24/include/linux/i2c-proc.h
7573 --- linux-2.4.24.org/include/linux/i2c-proc.h   2004-02-04 22:30:58.421166905 +0100
7574 +++ linux-2.4.24/include/linux/i2c-proc.h       2004-02-04 22:36:37.038751297 +0100
7575 @@ -1,6 +1,7 @@
7576  /*
7577 -    sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7578 -                monitoring
7579 +    i2c-proc.h - Part of the i2c package
7580 +    was originally sensors.h - Part of lm_sensors, Linux kernel modules
7581 +                               for hardware monitoring
7582      Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
7583  
7584      This program is free software; you can redistribute it and/or modify
7585 @@ -18,14 +19,9 @@
7586      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7587  */
7588  
7589 -#ifndef SENSORS_SENSORS_H
7590 -#define SENSORS_SENSORS_H
7591 +#ifndef _LINUX_I2C_PROC_H
7592 +#define _LINUX_I2C_PROC_H
7593  
7594 -#ifdef __KERNEL__
7595 -
7596 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
7597 -#include <linux/types.h>
7598 -#include <linux/fs.h>
7599  #include <linux/sysctl.h>
7600  
7601  /* The type of callback functions used in sensors_{proc,sysctl}_real */
7602 @@ -73,8 +69,7 @@
7603     these functions must be updated! */
7604  extern int i2c_register_entry(struct i2c_client *client,
7605                                   const char *prefix,
7606 -                                 ctl_table * ctl_template,
7607 -                                 struct module *controlling_mod);
7608 +                                 ctl_table * ctl_template);
7609  
7610  extern void i2c_deregister_entry(int id);
7611  
7612 @@ -347,6 +342,31 @@
7613                                                   {NULL}}; \
7614    SENSORS_INSMOD
7615  
7616 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
7617 +  enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
7618 +  SENSORS_MODULE_PARM(force, \
7619 +                      "List of adapter,address pairs to boldly assume " \
7620 +                      "to be present"); \
7621 +  SENSORS_MODULE_PARM_FORCE(chip1); \
7622 +  SENSORS_MODULE_PARM_FORCE(chip2); \
7623 +  SENSORS_MODULE_PARM_FORCE(chip3); \
7624 +  SENSORS_MODULE_PARM_FORCE(chip4); \
7625 +  SENSORS_MODULE_PARM_FORCE(chip5); \
7626 +  SENSORS_MODULE_PARM_FORCE(chip6); \
7627 +  SENSORS_MODULE_PARM_FORCE(chip7); \
7628 +  SENSORS_MODULE_PARM_FORCE(chip8); \
7629 +  static struct i2c_force_data forces[] = {{force,any_chip}, \
7630 +                                                 {force_ ## chip1,chip1}, \
7631 +                                                 {force_ ## chip2,chip2}, \
7632 +                                                 {force_ ## chip3,chip3}, \
7633 +                                                 {force_ ## chip4,chip4}, \
7634 +                                                 {force_ ## chip5,chip5}, \
7635 +                                                 {force_ ## chip6,chip6}, \
7636 +                                                 {force_ ## chip7,chip7}, \
7637 +                                                 {force_ ## chip8,chip8}, \
7638 +                                                 {NULL}}; \
7639 +  SENSORS_INSMOD
7640 +
7641  typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
7642                                     int addr, unsigned short flags,
7643                                     int kind);
7644 @@ -362,7 +382,7 @@
7645  
7646  /* This macro is used to scale user-input to sensible values in almost all
7647     chip drivers. */
7648 -extern inline int SENSORS_LIMIT(long value, long low, long high)
7649 +static inline int SENSORS_LIMIT(long value, long low, long high)
7650  {
7651         if (value < low)
7652                 return low;
7653 @@ -372,8 +392,6 @@
7654                 return value;
7655  }
7656  
7657 -#endif                         /* def __KERNEL__ */
7658 -
7659  
7660  /* The maximum length of the prefix */
7661  #define SENSORS_PREFIX_MAX 20
7662 @@ -392,5 +410,5 @@
7663         char name[SENSORS_PREFIX_MAX + 13];
7664  };
7665  
7666 -#endif                         /* def SENSORS_SENSORS_H */
7667 +#endif                         /* def _LINUX_I2C_PROC_H */
7668  
This page took 0.56969 seconds and 3 git commands to generate.