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