1 diff -urN linux-2.4.24.org/Documentation/Configure.help linux-2.4.24/Documentation/Configure.help
2 --- linux-2.4.24.org/Documentation/Configure.help 2004-02-04 22:35:48.287889651 +0100
3 +++ linux-2.4.24/Documentation/Configure.help 2004-02-04 22:36:36.607840921 +0100
4 @@ -20127,6 +20127,16 @@
5 <file:Documentation/modules.txt>.
6 The module will be called i2c-velleman.o.
8 +Basic I2C on Parallel Port adapter
10 + This supports directly connecting I2C devices to the parallel port.
11 + See <file:Documentation/i2c/i2c-pport> for more information.
13 + This driver is also available as a module. If you want to compile
14 + it as a module, say M here and read
15 + <file:Documentation/modules.txt>.
16 + The module will be called i2c-pport.o.
18 I2C PCF 8584 interfaces
20 This allows you to use a range of I2C adapters called PCF adapters.
21 @@ -20148,6 +20158,15 @@
22 <file:Documentation/modules.txt>.
23 The module will be called i2c-elektor.o.
25 +PCF on the EPP Parallel Port
27 + This supports the PCF8584 connected to the parallel port.
29 + This driver is also available as a module. If you want to compile
30 + it as a module, say M here and read
31 + <file:Documentation/modules.txt>.
32 + The module will be called i2c-pcf-epp.o.
36 This supports the use the ITE8172 I2C interface found on some MIPS
37 @@ -20185,6 +20204,51 @@
38 Supports the SGI interfaces like the ones found on SGI Indy VINO
41 +Motorola 8xx I2C algorithm
43 + This is the algorithm that allows you to use Motorola 8xx I2C adapters.
45 + This driver is also available as a module. If you want to compile
46 + it as a module, say M here and read
47 + <file:Documentation/modules.txt>.
48 + The module will be called i2c-algo-8xx.o.
50 +Motorola 8xx I2C interface
52 + This supports the Motorola 8xx I2C device.
54 + This driver is also available as a module. If you want to compile
55 + it as a module, say M here and read
56 + <file:Documentation/modules.txt>.
57 + The module will be called i2c-rpx.o.
59 +IBM 405 I2C algorithm
60 +CONFIG_I2C_IBM_OCP_ALGO
61 + This is the algorithm that allows you to use IBM 405 I2C adapters.
63 + This driver is also available as a module. If you want to compile
64 + it as a module, say M here and read
65 + <file:Documentation/modules.txt>.
66 + The module will be called i2c-algo-ibm_ocp.o.
68 +IBM 405 I2C interface
69 +CONFIG_I2C_IBM_OCP_ADAP
70 + This supports the IBM 405 I2C device.
72 + This driver is also available as a module. If you want to compile
73 + it as a module, say M here and read
74 + <file:Documentation/modules.txt>.
75 + The module will be called i2c-adap-ibm_ocp.o.
77 +StrongARM SA-1110 interface
79 + This supports the StrongARM SA-1110 Development Board.
81 + This driver is also available as a module. If you want to compile
82 + it as a module, say M here and read
83 + <file:Documentation/modules.txt>.
84 + The module will be called i2c-frodo.o.
88 Say Y here to use i2c-* device files, usually found in the /dev
89 diff -urN linux-2.4.24.org/Documentation/i2c/dev-interface linux-2.4.24/Documentation/i2c/dev-interface
90 --- linux-2.4.24.org/Documentation/i2c/dev-interface 2004-02-04 22:35:46.529255353 +0100
91 +++ linux-2.4.24/Documentation/i2c/dev-interface 2004-02-04 22:36:36.612839881 +0100
93 Selects ten bit addresses if select not equals 0, selects normal 7 bit
94 addresses if select equals 0. Default 0.
96 +ioctl(file,I2C_PEC,long select)
97 + Selects SMBus PEC (packet error checking) generation and verification
98 + if select not equals 0, disables if select equals 0. Default 0.
99 + Used only for SMBus transactions.
101 ioctl(file,I2C_FUNCS,unsigned long *funcs)
102 Gets the adapter functionality and puts it in *funcs.
104 diff -urN linux-2.4.24.org/Documentation/i2c/i2c-pport linux-2.4.24/Documentation/i2c/i2c-pport
105 --- linux-2.4.24.org/Documentation/i2c/i2c-pport 1970-01-01 01:00:00.000000000 +0100
106 +++ linux-2.4.24/Documentation/i2c/i2c-pport 2004-02-04 22:36:36.619838425 +0100
108 +Parallel Port Adapters
109 +----------------------
110 +If you are installing parallel port adapters it means you are probably messing
111 +around with wires and IC's and the like. If you have purchased a card that
112 +provides an external i2c/smbus this will require combined algorithm and
113 +adapter code in a single module.
114 +If you are doing it yourself by using the parallel port there
115 +are basically 2 options.
117 +1) Using the parallel port and using the i2c-pport adapter module and the
118 +i2c-algo-bit algorithm module together to enable you to wire up your parallel
119 +port to act as an i2c/smbus. This provides a bus that will enable most
120 +sensors to work but doesn't support the entire i2c/smbus capability.
122 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c
123 +adapter chip. You will need to build a bit of a circuit to do this. This
124 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf
125 +algorithm module. This support almost all of the i2c/smbus capabilities.
128 +i2c-pport Documentation
129 +-----------------------
130 +This is a primitive parallel port driver for the i2c bus, which exploits
131 +features of modern bidirectional parallel ports.
133 +Bidirectional ports have particular bits connected in following way:
138 + read \-----| /------- Out pin
146 +It means when output is set to 1 we can read the port. Therefore
147 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It
148 +is not necessary to add any external - additional parts, we can
149 +read and write the same port simultaneously.
150 + I only use register base+2 so it is possible to use all
151 +8 data bits of parallel port for other applications (I have
152 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
153 + Port. The only disadvantage is we can only support 5V chips.
159 +SDA - connect to pin 14 (Auto Linefeed)
160 +SCL - connect to pin 16 (Initialize Printer)
161 +GND - connect to pin 18-25
162 ++5V - use external supply (I use 5V from 3.5" floppy connector)
175 diff -urN linux-2.4.24.org/Documentation/i2c/i2c-protocol linux-2.4.24/Documentation/i2c/i2c-protocol
176 --- linux-2.4.24.org/Documentation/i2c/i2c-protocol 2004-02-04 22:35:46.532254730 +0100
177 +++ linux-2.4.24/Documentation/i2c/i2c-protocol 2004-02-04 22:36:36.621838010 +0100
179 need to emit an Rd instead of a Wr, or vice versa, you set this
181 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
183 + Flags I2C_M_IGNORE_NAK
184 + Normally message is interrupted immediately if there is [NA] from the
185 + client. Setting this flag treats any [NA] asĀ [A], and all of
187 + These messages may still fail to SCL lo->hi timeout.
189 + Flags I2C_M_NO_RD_ACK
190 + In a read message, master A/NA bit is skipped.
191 diff -urN linux-2.4.24.org/Documentation/i2c/summary linux-2.4.24/Documentation/i2c/summary
192 --- linux-2.4.24.org/Documentation/i2c/summary 2004-02-04 22:35:46.582244335 +0100
193 +++ linux-2.4.24/Documentation/i2c/summary 2004-02-04 22:36:36.624837386 +0100
195 i2c-algo-8xx: An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
196 i2c-algo-bit: A bit-banging algorithm
197 i2c-algo-pcf: A PCF 8584 style algorithm
198 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
199 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
204 i2c-elektor: Elektor ISA card (uses i2c-algo-pcf)
205 i2c-elv: ELV parallel port adapter (uses i2c-algo-bit)
206 -i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
207 +i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
208 i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
209 -i2c-ppc405: IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
210 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
211 i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit)
212 i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
213 i2c-velleman: Velleman K8000 parallel port adapter (uses i2c-algo-bit)
214 diff -urN linux-2.4.24.org/Documentation/i2c/writing-clients linux-2.4.24/Documentation/i2c/writing-clients
215 --- linux-2.4.24.org/Documentation/i2c/writing-clients 2004-02-04 22:35:46.605239553 +0100
216 +++ linux-2.4.24/Documentation/i2c/writing-clients 2004-02-04 22:36:36.629836346 +0100
218 routines, a client structure specific information like the actual I2C
221 - struct i2c_driver foo_driver
223 - /* name */ "Foo version 2.3 and later driver",
224 - /* id */ I2C_DRIVERID_FOO,
225 - /* flags */ I2C_DF_NOTIFY,
226 - /* attach_adapter */ &foo_attach_adapter,
227 - /* detach_client */ &foo_detach_client,
228 - /* command */ &foo_command, /* May be NULL */
229 - /* inc_use */ &foo_inc_use, /* May be NULL */
230 - /* dec_use */ &foo_dec_use /* May be NULL */
231 + static struct i2c_driver foo_driver = {
232 + .owner = THIS_MODULE,
233 + .name = "Foo version 2.3 driver",
234 + .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */
235 + .flags = I2C_DF_NOTIFY,
236 + .attach_adapter = &foo_attach_adapter,
237 + .detach_client = &foo_detach_client,
238 + .command = &foo_command /* may be NULL */
241 The name can be chosen freely, and may be upto 40 characters long. Please
243 All other fields are for call-back functions which will be explained
250 -If your driver can also be compiled as a module, there are moments at
251 -which the module can not be removed from memory. For example, when you
252 -are doing a lengthy transaction, or when you create a /proc directory,
253 -and some process has entered that directory (this last case is the
254 -main reason why these call-backs were introduced).
256 -To increase or decrease the module usage count, you can use the
257 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
258 -which needs to get its usage count changed; that is why each driver
259 -module has to implement its own callback.
261 - void foo_inc_use (struct i2c_client *client)
268 - void foo_dec_use (struct i2c_client *client)
275 -Do not call these call-back functions directly; instead, use one of the
276 -following functions defined in i2c.h:
277 - void i2c_inc_use_client(struct i2c_client *);
278 - void i2c_dec_use_client(struct i2c_client *);
280 -You should *not* increase the module count just because a device is
281 -detected and a client created. This would make it impossible to remove
283 +There use to be two additional fields in this structure, inc_use et dec_use,
284 +for module usage count, but these fields were obsoleted and removed.
288 diff -urN linux-2.4.24.org/drivers/i2c/i2c-adap-ibm_ocp.c linux-2.4.24/drivers/i2c/i2c-adap-ibm_ocp.c
289 --- linux-2.4.24.org/drivers/i2c/i2c-adap-ibm_ocp.c 1970-01-01 01:00:00.000000000 +0100
290 +++ linux-2.4.24/drivers/i2c/i2c-adap-ibm_ocp.c 2004-02-04 22:36:36.635835098 +0100
293 + -------------------------------------------------------------------------
294 + i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
295 + -------------------------------------------------------------------------
297 + Ian DaSilva, MontaVista Software, Inc.
298 + idasilva@mvista.com or source@mvista.com
300 + Copyright 2000 MontaVista Software Inc.
302 + Changes made to support the IIC peripheral on the IBM PPC 405
305 + ----------------------------------------------------------------------------
306 + This file was highly leveraged from i2c-elektor.c, which was created
307 + by Simon G. Vogl and Hans Berglund:
310 + Copyright (C) 1995-97 Simon G. Vogl
311 + 1998-99 Hans Berglund
313 + With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
314 + Frodo Looijaard <frodol@dds.nl>
317 + This program is free software; you can redistribute it and/or modify
318 + it under the terms of the GNU General Public License as published by
319 + the Free Software Foundation; either version 2 of the License, or
320 + (at your option) any later version.
322 + This program is distributed in the hope that it will be useful,
323 + but WITHOUT ANY WARRANTY; without even the implied warranty of
324 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325 + GNU General Public License for more details.
327 + You should have received a copy of the GNU General Public License
328 + along with this program; if not, write to the Free Software
329 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
330 + ----------------------------------------------------------------------------
332 + History: 01/20/12 - Armin
334 + ported up to 2.4.16+
336 + Version 02/03/25 - Armin
337 + converted to ocp format
338 + removed commented out or #if 0 code
340 + TODO: convert to ocp_register
346 +#include <linux/kernel.h>
347 +#include <linux/ioport.h>
348 +#include <linux/module.h>
349 +#include <linux/delay.h>
350 +#include <linux/slab.h>
351 +#include <linux/init.h>
352 +#include <linux/i2c.h>
353 +#include <linux/i2c-algo-ibm_ocp.h>
354 +#include <asm/irq.h>
356 +#include <asm/ocp.h>
359 + * This next section is configurable, and it is used to set the number
360 + * of i2c controllers in the system. The default number of instances is 1,
361 + * however, this should be changed to reflect your system's configuration.
365 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
367 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
368 +extern iic_t *IIC_ADDR[];
369 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
371 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
372 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
374 +static int i2c_debug=0;
375 +static wait_queue_head_t iic_wait[IIC_NUMS];
376 +static int iic_pending;
377 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
380 +/* ----- global defines ----------------------------------------------- */
381 +#define DEB(x) if (i2c_debug>=1) x
382 +#define DEB2(x) if (i2c_debug>=2) x
383 +#define DEB3(x) if (i2c_debug>=3) x
384 +#define DEBE(x) x /* error messages */
386 +/* ----- local functions ---------------------------------------------- */
389 +// Description: Write a byte to IIC hardware
391 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
393 + // writeb resolves to a write to the specified memory location
394 + // plus a call to eieio. eieio ensures that all instructions
395 + // preceding it are completed before any further stores are
397 + // Delays at this level (to protect writes) are not needed here.
403 +// Description: Read a byte from IIC hardware
405 +static int iic_ibmocp_getbyte(void *data, int ctl)
415 +// Description: Return our slave address. This is the address
416 +// put on the I2C bus when another master on the bus wants to address us
419 +static int iic_ibmocp_getown(void *data)
421 + return(((struct iic_ibm *)(data))->iic_own);
426 +// Description: Return the clock rate
428 +static int iic_ibmocp_getclock(void *data)
430 + return(((struct iic_ibm *)(data))->iic_clock);
436 +// Description: Put this process to sleep. We will wake up when the
437 +// IIC controller interrupts.
439 +static void iic_ibmocp_waitforpin(void *data) {
442 + struct iic_ibm *priv_data = data;
445 + // If interrupts are enabled (which they are), then put the process to
446 + // sleep. This process will be awakened by two events -- either the
447 + // the IIC peripheral interrupts or the timeout expires.
449 + if (priv_data->iic_irq > 0) {
450 + spin_lock_irq(&irq_driver_lock);
451 + if (iic_pending == 0) {
452 + interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
455 + spin_unlock_irq(&irq_driver_lock);
458 + // If interrupts are not enabled then delay for a reasonable amount
459 + // of time and return. We expect that by time we return to the calling
460 + // function that the IIC has finished our requested transaction and
461 + // the status bit reflects this.
463 + // udelay is probably not the best choice for this since it is
464 + // the equivalent of a busy wait
468 + //printk("iic_ibmocp_waitforpin: exitting\n");
473 +// Description: The registered interrupt handler
475 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs)
478 + struct iic_regs *iic;
479 + struct iic_ibm *priv_data = dev_id;
480 + iic = (struct iic_regs *) priv_data->iic_base;
482 + DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
483 + // Read status register
484 + ret = readb((int) &(iic->sts));
485 + DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
486 + // Clear status register. See IBM PPC 405 reference manual for details
487 + writeb(0x0a, (int) &(iic->sts));
488 + wake_up_interruptible(&(iic_wait[priv_data->index]));
493 +// Description: This function is very hardware dependent. First, we lock
494 +// the region of memory where out registers exist. Next, we request our
495 +// interrupt line and register its associated handler. Our IIC peripheral
496 +// uses interrupt number 2, as specified by the 405 reference manual.
498 +static int iic_hw_resrc_init(int instance)
501 + DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
502 + iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
504 + DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
506 + if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
508 + if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
509 + 0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
510 + printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
511 + iic_ibmocp_adaps[instance]->iic_irq);
512 + iic_ibmocp_adaps[instance]->iic_irq = 0;
514 + DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
522 +// Description: Release irq and memory
524 +static void iic_ibmocp_release(void)
528 + for(i=0; i<IIC_NUMS; i++) {
529 + struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
530 + if (priv_data->iic_irq > 0) {
531 + disable_irq(priv_data->iic_irq);
532 + free_irq(priv_data->iic_irq, 0);
534 + kfree(iic_ibmocp_data[i]);
535 + kfree(iic_ibmocp_ops[i]);
541 +// Description: Called when the module is loaded. This function starts the
542 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
543 +// algorithm layer and into to the core layer)
545 +static int __init iic_ibmocp_init(void)
549 + printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
551 + for(i=0; i<IIC_NUMS; i++) {
552 + iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
553 + if(iic_ibmocp_data[i] == NULL) {
556 + memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
560 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
563 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
566 + iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
567 + iic_ibmocp_adaps[i]->iic_own = IIC_OWN;
568 + iic_ibmocp_adaps[i]->index = i;
570 + DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
571 + DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
572 + DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
573 + DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
576 + iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i];
577 + iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
578 + iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
579 + iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
580 + iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
581 + iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
582 + iic_ibmocp_data[i]->udelay = 80;
583 + iic_ibmocp_data[i]->mdelay = 80;
584 + iic_ibmocp_data[i]->timeout = HZ;
586 + iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
587 + if(iic_ibmocp_ops[i] == NULL) {
590 + memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
591 + strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
592 + iic_ibmocp_ops[i]->owner = THIS_MODULE;
593 + iic_ibmocp_ops[i]->id = I2C_HW_OCP;
594 + iic_ibmocp_ops[i]->algo = NULL;
595 + iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
598 + init_waitqueue_head(&(iic_wait[i]));
599 + if (iic_hw_resrc_init(i) == 0) {
600 + if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
605 + DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
611 +static void __exit iic_ibmocp_exit(void)
615 + for(i=0; i<IIC_NUMS; i++) {
616 + i2c_ocp_del_bus(iic_ibmocp_ops[i]);
618 + iic_ibmocp_release();
622 +// If modules is NOT defined when this file is compiled, then the MODULE_*
623 +// macros will resolve to nothing
625 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
626 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
627 +MODULE_LICENSE("GPL");
629 +MODULE_PARM(base, "i");
630 +MODULE_PARM(irq, "i");
631 +MODULE_PARM(clock, "i");
632 +MODULE_PARM(own, "i");
633 +MODULE_PARM(i2c_debug,"i");
636 +module_init(iic_ibmocp_init);
637 +module_exit(iic_ibmocp_exit);
638 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-8xx.c linux-2.4.24/drivers/i2c/i2c-algo-8xx.c
639 --- linux-2.4.24.org/drivers/i2c/i2c-algo-8xx.c 1970-01-01 01:00:00.000000000 +0100
640 +++ linux-2.4.24/drivers/i2c/i2c-algo-8xx.c 2004-02-04 22:36:36.640834059 +0100
643 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
644 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
646 + This program is free software; you can redistribute it and/or modify
647 + it under the terms of the GNU General Public License as published by
648 + the Free Software Foundation; either version 2 of the License, or
649 + (at your option) any later version.
651 + This program is distributed in the hope that it will be useful,
652 + but WITHOUT ANY WARRANTY; without even the implied warranty of
653 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
654 + GNU General Public License for more details.
656 + You should have received a copy of the GNU General Public License
657 + along with this program; if not, write to the Free Software
658 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
660 + * moved into proper i2c interface; separated out platform specific
661 + * parts into i2c-rpx.c
662 + * Brad Parker (brad@heeltoe.com)
670 +#include <linux/kernel.h>
671 +#include <linux/module.h>
672 +#include <linux/delay.h>
673 +#include <linux/slab.h>
674 +#include <linux/init.h>
675 +#include <linux/errno.h>
676 +#include <linux/sched.h>
677 +#include <linux/i2c.h>
678 +#include <linux/i2c-algo-8xx.h>
679 +#include <asm/mpc8xx.h>
680 +#include <asm/commproc.h>
683 +#define CPM_MAX_READ 513
684 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
685 +static wait_queue_head_t iic_wait;
686 +static ushort r_tbase, r_rbase;
691 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
693 + volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
695 + printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
697 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
698 + /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
699 + /* Someone with a buggy CPU needs to confirm that */
700 + i2c->i2c_i2mod &= ~1;
702 + /* Clear interrupt.
704 + i2c->i2c_i2cer = 0xff;
706 + /* Get 'me going again.
708 + wake_up_interruptible(&iic_wait);
712 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
714 + volatile iic_t *iip = cpm->iip;
715 + volatile i2c8xx_t *i2c = cpm->i2c;
717 + bd_t *bd = (bd_t *)__res;
719 + if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
721 + /* Initialize the parameter ram.
722 + * We need to make sure many things are initialized to zero,
723 + * especially in the case of a microcode patch.
725 + iip->iic_rstate = 0;
727 + iip->iic_rbptr = 0;
729 + iip->iic_rxtmp = 0;
730 + iip->iic_tstate = 0;
732 + iip->iic_tbptr = 0;
734 + iip->iic_txtmp = 0;
736 + /* Set up the IIC parameters in the parameter ram.
738 + iip->iic_tbase = r_tbase = cpm->dp_addr;
739 + iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
741 + iip->iic_tfcr = SMC_EB;
742 + iip->iic_rfcr = SMC_EB;
744 + /* Set maximum receive size.
746 + iip->iic_mrblr = CPM_MAX_READ;
748 + /* Initialize Tx/Rx parameters.
750 + if (cpm->reloc == 0) {
751 + volatile cpm8xx_t *cp = cpm->cp;
754 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
755 + while (cp->cp_cpcr & CPM_CR_FLG);
757 + iip->iic_rbptr = iip->iic_rbase;
758 + iip->iic_tbptr = iip->iic_tbase;
759 + iip->iic_rstate = 0;
760 + iip->iic_tstate = 0;
763 + /* Select an arbitrary address. Just make sure it is unique.
765 + i2c->i2c_i2add = 0xfe;
767 + /* Make clock run at 60 KHz.
769 + brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
770 + i2c->i2c_i2brg = brg;
772 + i2c->i2c_i2mod = 0x00;
773 + i2c->i2c_i2com = 0x01; /* Master mode */
775 + /* Disable interrupts.
777 + i2c->i2c_i2cmr = 0;
778 + i2c->i2c_i2cer = 0xff;
780 + init_waitqueue_head(&iic_wait);
782 + /* Install interrupt handler.
785 + printk ("%s[%d] Install ISR for IRQ %d\n",
786 + __func__,__LINE__, CPMVEC_I2C);
788 + (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
793 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
795 + volatile i2c8xx_t *i2c = cpm->i2c;
799 + i2c->i2c_i2mod &= ~1;
800 + i2c->i2c_i2cmr = 0;
801 + i2c->i2c_i2cer = 0xff;
807 +cpm_reset_iic_params(volatile iic_t *iip)
809 + iip->iic_tbase = r_tbase;
810 + iip->iic_rbase = r_rbase;
812 + iip->iic_tfcr = SMC_EB;
813 + iip->iic_rfcr = SMC_EB;
815 + iip->iic_mrblr = CPM_MAX_READ;
817 + iip->iic_rstate = 0;
819 + iip->iic_rbptr = iip->iic_rbase;
821 + iip->iic_rxtmp = 0;
822 + iip->iic_tstate = 0;
824 + iip->iic_tbptr = iip->iic_tbase;
826 + iip->iic_txtmp = 0;
829 +#define BD_SC_NAK ((ushort)0x0004) /* NAK - did not respond */
830 +#define BD_SC_OV ((ushort)0x0002) /* OV - receive overrun */
831 +#define CPM_CR_CLOSE_RXBD ((ushort)0x0007)
833 +static void force_close(struct i2c_algo_8xx_data *cpm)
835 + volatile i2c8xx_t *i2c = cpm->i2c;
836 + if (cpm->reloc == 0) { /* micro code disabled */
837 + volatile cpm8xx_t *cp = cpm->cp;
839 + if (cpm_debug) printk("force_close()\n");
841 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
844 + while (cp->cp_cpcr & CPM_CR_FLG);
846 + i2c->i2c_i2cmr = 0x00; /* Disable all interrupts */
847 + i2c->i2c_i2cer = 0xff;
852 + * abyte = address byte, with r/w flag already set
855 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
857 + volatile iic_t *iip = cpm->iip;
858 + volatile i2c8xx_t *i2c = cpm->i2c;
859 + volatile cpm8xx_t *cp = cpm->cp;
860 + volatile cbd_t *tbdf, *rbdf;
862 + unsigned long flags, tmo;
864 + if (count >= CPM_MAX_READ)
867 + /* check for and use a microcode relocation patch */
869 + cpm_reset_iic_params(iip);
872 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
873 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
875 + /* To read, we need an empty buffer of the proper length.
876 + * All that is used is the first byte for address, the remainder
877 + * is just used for timing (and doesn't really have to exist).
880 + tb = (u_char *)(((uint)tb + 15) & ~15);
881 + tb[0] = abyte; /* Device address byte w/rw flag */
883 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
885 + if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
887 + tbdf->cbd_bufaddr = __pa(tb);
888 + tbdf->cbd_datlen = count + 1;
890 + BD_SC_READY | BD_SC_LAST |
891 + BD_SC_WRAP | BD_IIC_START;
893 + iip->iic_mrblr = count +1; /* prevent excessive read, +1
894 + is needed otherwise will the
895 + RXB interrupt come too early */
897 + /* flush will invalidate too. */
898 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
900 + rbdf->cbd_datlen = 0;
901 + rbdf->cbd_bufaddr = __pa(buf);
902 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
904 + /* Chip bug, set enable here */
905 + local_irq_save(flags);
906 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
907 + i2c->i2c_i2cer = 0xff;
908 + i2c->i2c_i2mod |= 1; /* Enable */
909 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
911 + /* Wait for IIC transfer */
912 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
913 + local_irq_restore(flags);
914 + } else { /* busy wait for small transfers, its faster */
915 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
916 + i2c->i2c_i2cer = 0xff;
917 + i2c->i2c_i2mod |= 1; /* Enable */
918 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
919 + tmo = jiffies + 1*HZ;
920 + while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
923 + if (signal_pending(current) || !tmo){
926 + printk("IIC read: timeout!\n");
929 +#ifdef I2C_CHIP_ERRATA
930 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
931 + Disabling I2C too early may cause too short stop condition */
933 + i2c->i2c_i2mod &= ~1;
936 + printk("tx sc %04x, rx sc %04x\n",
937 + tbdf->cbd_sc, rbdf->cbd_sc);
940 + if (tbdf->cbd_sc & BD_SC_READY) {
941 + printk("IIC read; complete but tbuf ready\n");
943 + printk("tx sc %04x, rx sc %04x\n",
944 + tbdf->cbd_sc, rbdf->cbd_sc);
947 + if (tbdf->cbd_sc & BD_SC_NAK) {
949 + printk("IIC read; no ack\n");
953 + if (rbdf->cbd_sc & BD_SC_EMPTY) {
954 + /* force_close(cpm); */
956 + printk("IIC read; complete but rbuf empty\n");
957 + printk("tx sc %04x, rx sc %04x\n",
958 + tbdf->cbd_sc, rbdf->cbd_sc);
963 + if (rbdf->cbd_sc & BD_SC_OV) {
965 + printk("IIC read; Overrun\n");
966 + return -EREMOTEIO;;
969 + if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
971 + if (rbdf->cbd_datlen < count) {
973 + printk("IIC read; short, wanted %d got %d\n",
974 + count, rbdf->cbd_datlen);
982 + * addr = address byte, with r/w flag already set
985 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
987 + volatile iic_t *iip = cpm->iip;
988 + volatile i2c8xx_t *i2c = cpm->i2c;
989 + volatile cpm8xx_t *cp = cpm->cp;
990 + volatile cbd_t *tbdf;
992 + unsigned long flags, tmo;
994 + /* check for and use a microcode relocation patch */
996 + cpm_reset_iic_params(iip);
999 + tb = (u_char *)(((uint)tb + 15) & ~15);
1000 + *tb = abyte; /* Device address byte w/rw flag */
1002 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1003 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1005 + if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1007 + /* set up 2 descriptors */
1008 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1010 + tbdf[0].cbd_bufaddr = __pa(tb);
1011 + tbdf[0].cbd_datlen = 1;
1012 + tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1014 + tbdf[1].cbd_bufaddr = __pa(buf);
1015 + tbdf[1].cbd_datlen = count;
1016 + tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1019 + /* Chip bug, set enable here */
1020 + local_irq_save(flags);
1021 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1022 + i2c->i2c_i2cer = 0xff;
1023 + i2c->i2c_i2mod |= 1; /* Enable */
1024 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1026 + /* Wait for IIC transfer */
1027 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1028 + local_irq_restore(flags);
1029 + } else { /* busy wait for small transfers, its faster */
1030 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1031 + i2c->i2c_i2cer = 0xff;
1032 + i2c->i2c_i2mod |= 1; /* Enable */
1033 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1034 + tmo = jiffies + 1*HZ;
1035 + while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1038 + if (signal_pending(current) || !tmo){
1040 + if(cpm_debug && !tmo)
1041 + printk("IIC write: timeout!\n");
1045 +#if I2C_CHIP_ERRATA
1046 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1047 + Disabling I2C too early may cause too short stop condition */
1049 + i2c->i2c_i2mod &= ~1;
1052 + printk("tx0 sc %04x, tx1 sc %04x\n",
1053 + tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1056 + if (tbdf->cbd_sc & BD_SC_NAK) {
1058 + printk("IIC write; no ack\n");
1062 + if (tbdf->cbd_sc & BD_SC_READY) {
1064 + printk("IIC write; complete but tbuf ready\n");
1071 +/* See if an IIC address exists..
1072 + * addr = 7 bit address, unshifted
1075 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1077 + volatile iic_t *iip = cpm->iip;
1078 + volatile i2c8xx_t *i2c = cpm->i2c;
1079 + volatile cpm8xx_t *cp = cpm->cp;
1080 + volatile cbd_t *tbdf, *rbdf;
1082 + unsigned long flags, len, tmo;
1084 + if (cpm_debug > 1)
1085 + printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1087 + /* check for and use a microcode relocation patch */
1089 + cpm_reset_iic_params(iip);
1092 + if (cpm_debug && addr == 0) {
1093 + printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1094 + printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1097 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1098 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1101 + tb = (u_char *)(((uint)tb + 15) & ~15);
1103 + /* do a simple read */
1104 + tb[0] = (addr << 1) | 1; /* device address (+ read) */
1107 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1109 + tbdf->cbd_bufaddr = __pa(tb);
1110 + tbdf->cbd_datlen = len;
1112 + BD_SC_READY | BD_SC_LAST |
1113 + BD_SC_WRAP | BD_IIC_START;
1115 + rbdf->cbd_datlen = 0;
1116 + rbdf->cbd_bufaddr = __pa(tb+2);
1117 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1119 + local_irq_save(flags);
1120 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1121 + i2c->i2c_i2cer = 0xff;
1122 + i2c->i2c_i2mod |= 1; /* Enable */
1123 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1125 + if (cpm_debug > 1) printk("about to sleep\n");
1127 + /* wait for IIC transfer */
1128 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1129 + local_irq_restore(flags);
1131 +#ifdef I2C_CHIP_ERRATA
1132 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1133 + Disabling I2C too early may cause too short stop condition */
1135 + i2c->i2c_i2mod &= ~1;
1138 + if (signal_pending(current) || !tmo){
1140 + if(cpm_debug && !tmo)
1141 + printk("IIC tryaddress: timeout!\n");
1145 + if (cpm_debug > 1) printk("back from sleep\n");
1147 + if (tbdf->cbd_sc & BD_SC_NAK) {
1148 + if (cpm_debug > 1) printk("IIC try; no ack\n");
1152 + if (tbdf->cbd_sc & BD_SC_READY) {
1153 + printk("IIC try; complete but tbuf ready\n");
1159 +static int cpm_xfer(struct i2c_adapter *adap,
1160 + struct i2c_msg msgs[],
1163 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1164 + struct i2c_msg *pmsg;
1168 + for (i = 0; i < num; i++) {
1172 + printk("i2c-algo-8xx.o: "
1173 + "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1174 + i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1176 + addr = pmsg->addr << 1;
1177 + if (pmsg->flags & I2C_M_RD )
1179 + if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1182 + if (!(pmsg->flags & I2C_M_NOSTART)) {
1184 + if (pmsg->flags & I2C_M_RD ) {
1185 + /* read bytes into buffer*/
1186 + ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1188 + printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1189 + if (ret < pmsg->len ) {
1190 + return (ret<0)? ret : -EREMOTEIO;
1193 + /* write bytes from buffer */
1194 + ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1196 + printk("i2c-algo-8xx.o: wrote %d\n", ret);
1197 + if (ret < pmsg->len ) {
1198 + return (ret<0) ? ret : -EREMOTEIO;
1205 +static u32 cpm_func(struct i2c_adapter *adap)
1207 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1208 + I2C_FUNC_PROTOCOL_MANGLING;
1211 +/* -----exported algorithm data: ------------------------------------- */
1213 +static struct i2c_algorithm cpm_algo = {
1214 + .owner = THIS_MODULE,
1215 + .name = "MPC8xx CPM algorithm",
1216 + .id = I2C_ALGO_MPC8XX,
1217 + .master_xfer = cpm_xfer,
1218 + .functionality = cpm_func,
1222 + * registering functions to load algorithms at runtime
1224 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1227 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1230 + printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1233 + /* register new adapter to i2c module... */
1235 + adap->id |= cpm_algo.id;
1236 + adap->algo = &cpm_algo;
1238 + i2c_add_adapter(adap);
1239 + cpm_iic_init(cpm);
1243 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1245 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1247 + cpm_iic_shutdown(cpm);
1249 + return i2c_del_adapter(adap);
1252 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1253 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1255 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1256 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1257 +MODULE_LICENSE("GPL");
1258 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-bit.c linux-2.4.24/drivers/i2c/i2c-algo-bit.c
1259 --- linux-2.4.24.org/drivers/i2c/i2c-algo-bit.c 2004-02-04 22:33:47.392029625 +0100
1260 +++ linux-2.4.24/drivers/i2c/i2c-algo-bit.c 2004-02-04 22:36:36.644833227 +0100
1262 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1263 /* ------------------------------------------------------------------------- */
1265 -/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
1266 - Frodo Looijaard <frodol@dds.nl> */
1267 +/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyƶsti MƤlkki
1268 + <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
1273 #include <linux/kernel.h>
1274 #include <linux/module.h>
1275 #include <linux/delay.h>
1276 #include <linux/slab.h>
1277 #include <linux/init.h>
1278 -#include <asm/uaccess.h>
1279 -#include <linux/ioport.h>
1280 #include <linux/errno.h>
1281 #include <linux/sched.h>
1283 #include <linux/i2c.h>
1284 #include <linux/i2c-algo-bit.h>
1287 /* ----- global defines ----------------------------------------------- */
1288 #define DEB(x) if (i2c_debug>=1) x;
1289 #define DEB2(x) if (i2c_debug>=2) x;
1291 #define DEBPROTO(x) if (i2c_debug>=9) { x; }
1292 /* debug the protocol by showing transferred bits */
1294 -/* debugging - slow down transfer to have a look at the data .. */
1295 -/* I use this with two leds&resistors, each one connected to sda,scl */
1296 -/* respectively. This makes sure that the algorithm works. Some chips */
1297 -/* might not like this, as they have an internal timeout of some mils */
1299 -#define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1300 - if (need_resched) schedule();
1304 /* ----- global variables --------------------------------------------- */
1310 /* module parameters:
1312 static int i2c_debug;
1313 static int bit_test; /* see if the line-setting functions work */
1314 -static int bit_scan; /* have a look at what's hanging 'round */
1316 /* --- setting states on the bus with the right timing: --------------- */
1321 udelay(adap->udelay);
1330 static inline int sclhi(struct i2c_algo_bit_data *adap)
1332 - int start=jiffies;
1337 - udelay(adap->udelay);
1339 /* Not all adapters have scl sense line... */
1340 - if (adap->getscl == NULL )
1341 + if (adap->getscl == NULL ) {
1342 + udelay(adap->udelay);
1346 - while (! getscl(adap) ) {
1348 + while (! getscl(adap) ) {
1349 /* the hw knows how to read the clock line,
1350 * so we wait until it actually gets high.
1351 * This is safer as some chips may hold it low
1352 * while they are processing data internally.
1355 if (time_after_eq(jiffies, start+adap->timeout)) {
1358 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1359 if (current->need_resched)
1365 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1369 + udelay(adap->udelay);
1374 /* scl, sda may not be high */
1375 DEBPROTO(printk(" Sr "));
1379 udelay(adap->udelay);
1383 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1385 /* assert: scl is low */
1386 - DEB2(printk(KERN_DEBUG " i2c_outb:%2.2X\n",c&0xff));
1387 for ( i=7 ; i>=0 ; i-- ) {
1388 sb = c & ( 1 << i );
1391 DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1392 if (sclhi(adap)<0) { /* timed out */
1393 sdahi(adap); /* we don't want to block the net */
1394 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1397 /* do arbitration here:
1398 @@ -196,11 +179,12 @@
1401 if (sclhi(adap)<0){ /* timeout */
1402 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1405 /* read ack: SDA should be pulled down by slave */
1406 ack=getsda(adap); /* ack: sda is pulled low ->success. */
1407 - DEB2(printk(KERN_DEBUG " i2c_outb: getsda() = 0x%2.2x\n", ~ack ));
1408 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1410 DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1411 DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1412 @@ -219,11 +203,10 @@
1413 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1415 /* assert: scl is low */
1416 - DEB2(printk(KERN_DEBUG "i2c_inb.\n"));
1420 if (sclhi(adap)<0) { /* timeout */
1421 + DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1428 /* assert: scl is low */
1429 + DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1431 DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1432 return (int) (indata & 0xff);
1434 @@ -242,71 +227,75 @@
1436 static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
1439 + if (adap->getscl==NULL)
1440 + printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, "
1441 + "SCL is not readable.\n");
1444 - if (adap->getscl==NULL) {
1445 - printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1449 - printk("i2c-algo-bit.o: Adapter: %s scl: %d sda: %d -- testing...\n",
1450 - name,getscl(adap),getsda(adap));
1451 + scl=(adap->getscl==NULL?1:getscl(adap));
1452 + printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
1453 if (!scl || !sda ) {
1454 - printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1455 + printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name);
1460 - printk("i2c-algo-bit.o:1 scl: %d sda: %d \n",getscl(adap),
1462 - if ( 0 != getsda(adap) ) {
1463 - printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1466 + scl=(adap->getscl==NULL?1:getscl(adap));
1467 + printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
1469 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n");
1472 - if ( 0 == getscl(adap) ) {
1473 - printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1476 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1477 + "while pulling SDA low!\n");
1482 - printk("i2c-algo-bit.o:2 scl: %d sda: %d \n",getscl(adap),
1484 - if ( 0 == getsda(adap) ) {
1485 - printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1488 + scl=(adap->getscl==NULL?1:getscl(adap));
1489 + printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
1491 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n");
1494 - if ( 0 == getscl(adap) ) {
1495 - printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1499 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1500 + "while pulling SDA high!\n");
1505 - printk("i2c-algo-bit.o:3 scl: %d sda: %d \n",getscl(adap),
1507 - if ( 0 != getscl(adap) ) {
1508 - printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1511 + scl=(adap->getscl==NULL?0:getscl(adap));
1512 + printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
1514 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n");
1517 - if ( 0 == getsda(adap) ) {
1518 - printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1521 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1522 + "while pulling SCL low!\n");
1527 - printk("i2c-algo-bit.o:4 scl: %d sda: %d \n",getscl(adap),
1529 - if ( 0 == getscl(adap) ) {
1530 - printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
1533 + scl=(adap->getscl==NULL?1:getscl(adap));
1534 + printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
1536 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n");
1539 - if ( 0 == getsda(adap) ) {
1540 - printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
1543 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1544 + "while pulling SCL high!\n");
1547 - printk("i2c-algo-bit.o: %s passed test.\n",name);
1548 + printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
1552 @@ -340,16 +329,21 @@
1554 udelay(adap->udelay);
1556 - DEB2(if (i) printk(KERN_DEBUG "i2c-algo-bit.o: needed %d retries for %d\n",
1559 + printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
1560 + i+1, addr & 1 ? "read" : "write", addr>>1,
1561 + ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
1566 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
1567 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1569 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1571 - const char *temp = buf;
1572 + const char *temp = msg->buf;
1573 + int count = msg->len;
1574 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1579 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
1580 i2c_adap->name, c&0xff));
1581 retval = i2c_outb(i2c_adap,c);
1583 + if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
1587 @@ -377,12 +371,18 @@
1591 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
1592 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1596 int rdcount=0; /* counts bytes read */
1597 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1598 + char *temp = msg->buf;
1599 + int count = msg->len;
1602 + /* Receive [Count] for I2C_SMBUS_BLOCK_DATA or I2C_SMBUS_BLOCK_PROC_CALL protocol */
1603 + if (msg->flags & I2C_M_RECV_LEN)
1607 inval = i2c_inb(i2c_adap);
1608 @@ -395,6 +395,20 @@
1614 + /* [Count] should be between 1 and 31 (I2C_SMBUS_BLOCK_MAX - 1). */
1615 + if (inval > 0 && inval < I2C_SMBUS_BLOCK_MAX) {
1616 + count = inval + 1; /* plus one for [Count] itself */
1618 + if (msg->flags & I2C_M_RECV_PEC)
1619 + count++; /* plus one for PEC */
1621 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: bad block count (%d).\n", inval);
1626 if ( count > 1 ) { /* send ack */
1628 DEBPROTO(printk(" Am "));
1629 @@ -419,31 +433,34 @@
1630 * try_address) and transmits the address in the necessary format to handle
1631 * reads, writes as well as 10bit-addresses.
1633 - * 0 everything went okay, the chip ack'ed
1634 + * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
1635 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
1636 * -ETIMEDOUT, for example if the lines are stuck...)
1638 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
1639 - struct i2c_msg *msg, int retries)
1640 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1642 unsigned short flags = msg->flags;
1643 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1644 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1650 + retries = nak_ok ? 0 : i2c_adap->retries;
1652 if ( (flags & I2C_M_TEN) ) {
1653 /* a ten bit address */
1654 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
1655 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
1656 /* try extended address code...*/
1657 ret = try_address(i2c_adap, addr, retries);
1659 + if ((ret != 1) && !nak_ok) {
1660 printk(KERN_ERR "died at extended address code.\n");
1663 /* the remaining 8 bit address */
1664 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
1666 + if ((ret != 1) && !nak_ok) {
1667 /* the chip did not ack / xmission error occurred */
1668 printk(KERN_ERR "died at 2nd address code.\n");
1671 /* okay, now switch into reading mode */
1673 ret = try_address(i2c_adap, addr, retries);
1675 + if ((ret!=1) && !nak_ok) {
1676 printk(KERN_ERR "died at extended address code.\n");
1679 @@ -465,10 +482,10 @@
1680 if (flags & I2C_M_REV_DIR_ADDR )
1682 ret = try_address(i2c_adap, addr, retries);
1684 + if ((ret!=1) && !nak_ok)
1692 @@ -479,16 +496,18 @@
1693 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1696 + unsigned short nak_ok;
1699 for (i=0;i<num;i++) {
1701 + nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
1702 if (!(pmsg->flags & I2C_M_NOSTART)) {
1706 - ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
1708 + ret = bit_doAddress(i2c_adap, pmsg);
1709 + if ((ret != 0) && !nak_ok) {
1710 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n",
1712 return (ret<0) ? ret : -EREMOTEIO;
1713 @@ -496,14 +515,14 @@
1715 if (pmsg->flags & I2C_M_RD ) {
1716 /* read bytes into buffer*/
1717 - ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
1718 + ret = readbytes(i2c_adap, pmsg);
1719 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
1720 if (ret < pmsg->len ) {
1721 return (ret<0)? ret : -EREMOTEIO;
1724 /* write bytes from buffer */
1725 - ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
1726 + ret = sendbytes(i2c_adap, pmsg);
1727 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
1728 if (ret < pmsg->len ) {
1729 return (ret<0) ? ret : -EREMOTEIO;
1730 @@ -514,30 +533,25 @@
1734 -static int algo_control(struct i2c_adapter *adapter,
1735 - unsigned int cmd, unsigned long arg)
1740 -static u32 bit_func(struct i2c_adapter *adap)
1741 +static u32 bit_func(struct i2c_adapter *i2c_adap)
1743 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1744 - I2C_FUNC_PROTOCOL_MANGLING;
1745 + I2C_FUNC_PROTOCOL_MANGLING |
1746 + I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
1747 + I2C_FUNC_SMBUS_READ_BLOCK_DATA |
1748 + I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC |
1749 + I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC;
1753 /* -----exported algorithm data: ------------------------------------- */
1755 static struct i2c_algorithm i2c_bit_algo = {
1756 - "Bit-shift algorithm",
1760 - NULL, /* slave_xmit */
1761 - NULL, /* slave_recv */
1762 - algo_control, /* ioctl */
1763 - bit_func, /* functionality */
1764 + .owner = THIS_MODULE,
1765 + .name = "Bit-shift algorithm",
1766 + .id = I2C_ALGO_BIT,
1767 + .master_xfer = bit_xfer,
1768 + .functionality = bit_func,
1774 int i2c_bit_add_bus(struct i2c_adapter *adap)
1777 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
1780 @@ -565,78 +578,26 @@
1781 adap->timeout = 100; /* default values, should */
1782 adap->retries = 3; /* be replaced by defines */
1787 - printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
1789 - for (i = 0x00; i < 0xff; i+=2) {
1790 - i2c_start(bit_adap);
1791 - ack = i2c_outb(adap,i);
1792 - i2c_stop(bit_adap);
1794 - printk("(%02x)",i>>1);
1802 - MOD_INC_USE_COUNT;
1804 i2c_add_adapter(adap);
1810 int i2c_bit_del_bus(struct i2c_adapter *adap)
1814 - if ((res = i2c_del_adapter(adap)) < 0)
1817 - DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
1820 - MOD_DEC_USE_COUNT;
1825 -int __init i2c_algo_bit_init (void)
1827 - printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
1829 + return i2c_del_adapter(adap);
1834 EXPORT_SYMBOL(i2c_bit_add_bus);
1835 EXPORT_SYMBOL(i2c_bit_del_bus);
1838 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1839 MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
1840 MODULE_LICENSE("GPL");
1842 MODULE_PARM(bit_test, "i");
1843 -MODULE_PARM(bit_scan, "i");
1844 MODULE_PARM(i2c_debug,"i");
1846 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
1847 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
1848 MODULE_PARM_DESC(i2c_debug,
1849 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
1851 -int init_module(void)
1853 - return i2c_algo_bit_init();
1856 -void cleanup_module(void)
1860 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-ibm_ocp.c linux-2.4.24/drivers/i2c/i2c-algo-ibm_ocp.c
1861 --- linux-2.4.24.org/drivers/i2c/i2c-algo-ibm_ocp.c 1970-01-01 01:00:00.000000000 +0100
1862 +++ linux-2.4.24/drivers/i2c/i2c-algo-ibm_ocp.c 2004-02-04 22:36:36.653831355 +0100
1865 + -------------------------------------------------------------------------
1866 + i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters
1867 + -------------------------------------------------------------------------
1869 + Ian DaSilva, MontaVista Software, Inc.
1870 + idasilva@mvista.com or source@mvista.com
1872 + Copyright 2000 MontaVista Software Inc.
1874 + Changes made to support the IIC peripheral on the IBM PPC 405
1877 + ---------------------------------------------------------------------------
1878 + This file was highly leveraged from i2c-algo-pcf.c, which was created
1879 + by Simon G. Vogl and Hans Berglund:
1882 + Copyright (C) 1995-1997 Simon G. Vogl
1883 + 1998-2000 Hans Berglund
1885 + With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and
1886 + Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
1887 + <mbailey@littlefeet-inc.com>
1890 + This program is free software; you can redistribute it and/or modify
1891 + it under the terms of the GNU General Public License as published by
1892 + the Free Software Foundation; either version 2 of the License, or
1893 + (at your option) any later version.
1895 + This program is distributed in the hope that it will be useful,
1896 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1897 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1898 + GNU General Public License for more details.
1900 + You should have received a copy of the GNU General Public License
1901 + along with this program; if not, write to the Free Software
1902 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1903 + ---------------------------------------------------------------------------
1905 + History: 01/20/12 - Armin
1906 + akuster@mvista.com
1907 + ported up to 2.4.16+
1909 + Version 02/03/25 - Armin
1910 + converted to ocp format
1911 + removed commented out or #if 0 code
1912 + added GĆ©rard Basler's fix to iic_combined_transaction() such that it
1913 + returns the number of successfully completed transfers .
1917 +#include <linux/kernel.h>
1918 +#include <linux/module.h>
1919 +#include <linux/delay.h>
1920 +#include <linux/slab.h>
1921 +#include <linux/init.h>
1922 +#include <linux/errno.h>
1923 +#include <linux/sched.h>
1924 +#include <linux/i2c.h>
1925 +#include <linux/i2c-algo-ibm_ocp.h>
1926 +#include <asm/ocp.h>
1929 +/* ----- global defines ----------------------------------------------- */
1930 +#define DEB(x) if (i2c_debug>=1) x
1931 +#define DEB2(x) if (i2c_debug>=2) x
1932 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
1933 +#define DEBPROTO(x) if (i2c_debug>=9) x;
1934 + /* debug the protocol by showing transferred bits */
1935 +#define DEF_TIMEOUT 5
1938 +/* ----- global variables --------------------------------------------- */
1941 +/* module parameters:
1943 +static int i2c_debug=0;
1945 +/* --- setting states on the bus with the right timing: --------------- */
1947 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
1948 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
1950 +#define IICO_I2C_SDAHIGH 0x0780
1951 +#define IICO_I2C_SDALOW 0x0781
1952 +#define IICO_I2C_SCLHIGH 0x0782
1953 +#define IICO_I2C_SCLLOW 0x0783
1954 +#define IICO_I2C_LINEREAD 0x0784
1956 +#define IIC_SINGLE_XFER 0
1957 +#define IIC_COMBINED_XFER 1
1959 +#define IIC_ERR_LOST_ARB -2
1960 +#define IIC_ERR_INCOMPLETE_XFR -3
1961 +#define IIC_ERR_NACK -1
1963 +/* --- other auxiliary functions -------------------------------------- */
1967 +// Description: Puts this process to sleep for a period equal to timeout
1969 +static inline void iic_sleep(unsigned long timeout)
1971 + schedule_timeout( timeout * HZ);
1976 +// Description: This performs the IBM PPC 405 IIC initialization sequence
1977 +// as described in the PPC405GP data book.
1979 +static int iic_init (struct i2c_algo_iic_data *adap)
1981 + struct iic_regs *iic;
1982 + struct iic_ibm *adap_priv_data = adap->data;
1983 + unsigned short retval;
1984 + iic = (struct iic_regs *) adap_priv_data->iic_base;
1986 + /* Clear master low master address */
1987 + iic_outb(adap,iic->lmadr, 0);
1989 + /* Clear high master address */
1990 + iic_outb(adap,iic->hmadr, 0);
1992 + /* Clear low slave address */
1993 + iic_outb(adap,iic->lsadr, 0);
1995 + /* Clear high slave address */
1996 + iic_outb(adap,iic->hsadr, 0);
1998 + /* Clear status */
1999 + iic_outb(adap,iic->sts, 0x0a);
2001 + /* Clear extended status */
2002 + iic_outb(adap,iic->extsts, 0x8f);
2004 + /* Set clock division */
2005 + iic_outb(adap,iic->clkdiv, 0x04);
2007 + retval = iic_inb(adap, iic->clkdiv);
2008 + DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2010 + /* Enable interrupts on Requested Master Transfer Complete */
2011 + iic_outb(adap,iic->intmsk, 0x01);
2013 + /* Clear transfer count */
2014 + iic_outb(adap,iic->xfrcnt, 0x0);
2016 + /* Clear extended control and status */
2017 + iic_outb(adap,iic->xtcntlss, 0xf0);
2019 + /* Set mode control (flush master data buf, enable hold SCL, exit */
2020 + /* unknown state. */
2021 + iic_outb(adap,iic->mdcntl, 0x47);
2023 + /* Clear control register */
2024 + iic_outb(adap,iic->cntl, 0x0);
2026 + DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2032 +// Description: After we issue a transaction on the IIC bus, this function
2033 +// is called. It puts this process to sleep until we get an interrupt from
2034 +// from the controller telling us that the transaction we requested in complete.
2036 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status)
2039 + int timeout = DEF_TIMEOUT;
2041 + struct iic_regs *iic;
2042 + struct iic_ibm *adap_priv_data = adap->data;
2043 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2046 + *status = iic_inb(adap, iic->sts);
2049 + while (timeout-- && (*status & 0x01)) {
2050 + adap->waitforpin(adap->data);
2051 + *status = iic_inb(adap, iic->sts);
2054 + if (timeout <= 0) {
2055 + /* Issue stop signal on the bus, and force an interrupt */
2056 + retval = iic_inb(adap, iic->cntl);
2057 + iic_outb(adap, iic->cntl, retval | 0x80);
2058 + /* Clear status register */
2059 + iic_outb(adap, iic->sts, 0x0a);
2060 + /* Exit unknown bus state */
2061 + retval = iic_inb(adap, iic->mdcntl);
2062 + iic_outb(adap, iic->mdcntl, (retval | 0x02));
2064 + // Check the status of the controller. Does it still see a
2065 + // pending transfer, even though we've tried to stop any
2066 + // ongoing transaction?
2067 + retval = iic_inb(adap, iic->sts);
2068 + retval = retval & 0x01;
2070 + // The iic controller is hosed. It is not responding to any
2071 + // of our commands. We have already tried to force it into
2072 + // a known state, but it has not worked. Our only choice now
2073 + // is a soft reset, which will clear all registers, and force
2074 + // us to re-initialize the controller.
2076 + iic_outb(adap, iic->xtcntlss, 0x01);
2079 + /* Is the pending transfer bit in the sts reg finally cleared? */
2080 + retval = iic_inb(adap, iic->sts);
2081 + retval = retval & 0x01;
2083 + printk(KERN_CRIT "The IIC Controller is hosed. A processor reset is required\n");
2085 + // For some reason, even though the interrupt bit in this
2086 + // register was set during iic_init, it didn't take. We
2087 + // need to set it again. Don't ask me why....this is just what
2088 + // I saw when testing timeouts.
2089 + iic_outb(adap, iic->intmsk, 0x01);
2098 +//------------------------------------
2099 +// Utility functions
2104 +// Description: Look at the status register to see if there was an error
2105 +// in the requested transaction. If there is, look at the extended status
2106 +// register and determine the exact cause.
2108 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2111 + struct iic_regs *iic;
2112 + struct iic_ibm *adap_priv_data = adap->data;
2113 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2116 + ret = iic_inb(adap, iic->sts);
2119 + ret = iic_inb(adap, iic->extsts);
2121 + // Lost arbitration
2122 + *error_code = IIC_ERR_LOST_ARB;
2125 + // Incomplete transfer
2126 + *error_code = IIC_ERR_INCOMPLETE_XFR;
2129 + // Master transfer aborted by a NACK during the transfer of the
2131 + *error_code = IIC_ERR_NACK;
2140 +// Description: This function is called by the upper layers to do the
2141 +// grunt work for a master send transaction
2143 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2144 + int count, int xfer_flag)
2146 + struct iic_regs *iic;
2147 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2148 + struct iic_ibm *adap_priv_data = adap->data;
2149 + int wrcount, status, timeout;
2150 + int loops, remainder, i, j;
2151 + int ret, error_code;
2152 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2155 + if( count == 0 ) return 0;
2157 + loops = count / 4;
2158 + remainder = count % 4;
2160 + if((loops > 1) && (remainder == 0)) {
2161 + for(i=0; i<(loops-1); i++) {
2163 + // Write four bytes to master data buffer
2165 + for(j=0; j<4; j++) {
2166 + iic_outb(adap, iic->mdbuf,
2170 + // Issue command to IICO device to begin transmission
2172 + iic_outb(adap, iic->cntl, 0x35);
2174 + // Wait for transmission to complete. When it does,
2175 + //loop to the top of the for statement and write the
2176 + // next four bytes.
2178 + timeout = wait_for_pin(adap, &status);
2183 + //printk(KERN_ERR "Error: write timeout\n");
2186 + ret = analyze_status(adap, &error_code);
2188 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2189 + // Return the number of bytes transferred
2190 + ret = iic_inb(adap, iic->xfrcnt);
2192 + return (wrcount-4+ret);
2194 + else return error_code;
2198 + else if((loops >= 1) && (remainder > 0)){
2199 + //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2200 + for(i=0; i<loops; i++) {
2202 + // Write four bytes to master data buffer
2204 + for(j=0; j<4; j++) {
2205 + iic_outb(adap, iic->mdbuf,
2209 + // Issue command to IICO device to begin transmission
2211 + iic_outb(adap, iic->cntl, 0x35);
2213 + // Wait for transmission to complete. When it does,
2214 + //loop to the top of the for statement and write the
2215 + // next four bytes.
2217 + timeout = wait_for_pin(adap, &status);
2222 + //printk(KERN_ERR "Error: write timeout\n");
2225 + ret = analyze_status(adap, &error_code);
2227 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2228 + // Return the number of bytes transferred
2229 + ret = iic_inb(adap, iic->xfrcnt);
2231 + return (wrcount-4+ret);
2233 + else return error_code;
2238 + //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2239 + if(remainder == 0) remainder = 4;
2240 + // remainder = remainder - 1;
2242 + // Write the remaining bytes (less than or equal to 4)
2244 + for(i=0; i<remainder; i++) {
2245 + iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2246 + //printk(KERN_DEBUG "iic_sendbytes: data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2248 + //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2250 + if(xfer_flag == IIC_COMBINED_XFER) {
2251 + iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2254 + iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2256 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2257 + timeout = wait_for_pin(adap, &status);
2262 + //printk(KERN_ERR "Error: write timeout\n");
2265 + ret = analyze_status(adap, &error_code);
2267 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2268 + // Return the number of bytes transferred
2269 + ret = iic_inb(adap, iic->xfrcnt);
2271 + return (wrcount-4+ret);
2273 + else return error_code;
2275 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2281 +// Description: Called by the upper layers to do the grunt work for
2282 +// a master read transaction.
2284 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2286 + struct iic_regs *iic;
2287 + int rdcount=0, i, status, timeout;
2288 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2289 + struct iic_ibm *adap_priv_data = adap->data;
2290 + int loops, remainder, j;
2291 + int ret, error_code;
2292 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2294 + if(count == 0) return 0;
2295 + loops = count / 4;
2296 + remainder = count % 4;
2298 + //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2300 + if((loops > 1) && (remainder == 0)) {
2301 + //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2302 + for(i=0; i<(loops-1); i++) {
2304 + // Issue command to begin master read (4 bytes maximum)
2306 + //printk(KERN_DEBUG "--->Issued read command\n");
2307 + iic_outb(adap, iic->cntl, 0x37);
2309 + // Wait for transmission to complete. When it does,
2310 + // loop to the top of the for statement and write the
2311 + // next four bytes.
2313 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2314 + timeout = wait_for_pin(adap, &status);
2317 + //printk(KERN_ERR "Error: read timed out\n");
2320 + //printk(KERN_DEBUG "--->Got interrupt\n");
2322 + ret = analyze_status(adap, &error_code);
2324 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2327 + return error_code;
2330 + for(j=0; j<4; j++) {
2331 + // Wait for data to shuffle to top of data buffer
2332 + // This value needs to optimized.
2334 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2336 + //printk(KERN_DEBUG "--->Read one byte\n");
2341 + else if((loops >= 1) && (remainder > 0)){
2342 + //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2343 + for(i=0; i<loops; i++) {
2345 + // Issue command to begin master read (4 bytes maximum)
2347 + //printk(KERN_DEBUG "--->Issued read command\n");
2348 + iic_outb(adap, iic->cntl, 0x37);
2350 + // Wait for transmission to complete. When it does,
2351 + // loop to the top of the for statement and write the
2352 + // next four bytes.
2354 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2355 + timeout = wait_for_pin(adap, &status);
2358 + //printk(KERN_ERR "Error: read timed out\n");
2361 + //printk(KERN_DEBUG "--->Got interrupt\n");
2363 + ret = analyze_status(adap, &error_code);
2365 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2368 + return error_code;
2371 + for(j=0; j<4; j++) {
2372 + // Wait for data to shuffle to top of data buffer
2373 + // This value needs to optimized.
2375 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2377 + //printk(KERN_DEBUG "--->Read one byte\n");
2382 + //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2383 + if(remainder == 0) remainder = 4;
2384 + DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2386 + if(xfer_type == IIC_COMBINED_XFER) {
2387 + iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2390 + iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2392 + DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2393 + timeout = wait_for_pin(adap, &status);
2394 + DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2397 + //printk(KERN_ERR "Error: read timed out\n");
2401 + ret = analyze_status(adap, &error_code);
2403 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2406 + return error_code;
2409 + //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2410 + for(i=0; i<remainder; i++) {
2411 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2412 + // printk(KERN_DEBUG "iic_readbytes: Character read = %x\n", buf[rdcount]);
2421 +// Description: This function implements combined transactions. Combined
2422 +// transactions consist of combinations of reading and writing blocks of data.
2423 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2426 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
2429 + struct i2c_msg *pmsg;
2432 + DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2433 + for(i=0; i < num; i++) {
2435 + if(pmsg->flags & I2C_M_RD) {
2437 + // Last read or write segment needs to be terminated with a stop
2439 + DEB2(printk(KERN_DEBUG "This one is a read\n"));
2442 + DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2444 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2446 + if (ret != pmsg->len) {
2447 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2448 + "only read %d bytes.\n",ret));
2452 + DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2455 + else if(!(pmsg->flags & I2C_M_RD)) {
2457 + // Last read or write segment needs to be terminated with a stop
2459 + DEB2(printk(KERN_DEBUG "This one is a write\n"));
2462 + DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2464 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2466 + if (ret != pmsg->len) {
2467 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2468 + "only wrote %d bytes.\n",ret));
2472 + DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2482 +// Description: Whenever we initiate a transaction, the first byte clocked
2483 +// onto the bus after the start condition is the address (7 bit) of the
2484 +// device we want to talk to. This function manipulates the address specified
2485 +// so that it makes sense to the hardware when written to the IIC peripheral.
2487 +// Note: 10 bit addresses are not supported in this driver, although they are
2488 +// supported by the hardware. This functionality needs to be implemented.
2490 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
2491 + struct i2c_msg *msg, int retries)
2493 + struct iic_regs *iic;
2494 + unsigned short flags = msg->flags;
2495 + unsigned char addr;
2496 + struct iic_ibm *adap_priv_data = adap->data;
2497 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2500 +// The following segment for 10 bit addresses needs to be ported
2502 +/* Ten bit addresses not supported right now
2503 + if ( (flags & I2C_M_TEN) ) {
2504 + // a ten bit address
2505 + addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2506 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2507 + // try extended address code...
2508 + ret = try_address(adap, addr, retries);
2510 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2511 + return -EREMOTEIO;
2513 + // the remaining 8 bit address
2514 + iic_outb(adap,msg->addr & 0x7f);
2515 + // Status check comes here
2517 + printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
2518 + return -EREMOTEIO;
2520 + if ( flags & I2C_M_RD ) {
2521 + i2c_repstart(adap);
2522 + // okay, now switch into reading mode
2524 + ret = try_address(adap, addr, retries);
2526 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2527 + return -EREMOTEIO;
2530 + } else ----------> // normal 7 bit address
2532 +Ten bit addresses not supported yet */
2534 + addr = ( msg->addr << 1 );
2535 + if (flags & I2C_M_RD )
2537 + if (flags & I2C_M_REV_DIR_ADDR )
2540 + // Write to the low slave address
2542 + iic_outb(adap, iic->lmadr, addr);
2544 + // Write zero to the high slave register since we are
2545 + // only using 7 bit addresses
2547 + iic_outb(adap, iic->hmadr, 0);
2554 +// Description: Prepares the controller for a transaction (clearing status
2555 +// registers, data buffers, etc), and then calls either iic_readbytes or
2556 +// iic_sendbytes to do the actual transaction.
2558 +static int iic_xfer(struct i2c_adapter *i2c_adap,
2559 + struct i2c_msg msgs[],
2562 + struct iic_regs *iic;
2563 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2564 + struct iic_ibm *adap_priv_data = adap->data;
2565 + struct i2c_msg *pmsg;
2568 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2573 + // Clear status register
2575 + DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
2576 + iic_outb(adap, iic->sts, 0x0a);
2579 + // Wait for any pending transfers to complete
2581 + DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
2582 + while((ret = iic_inb(adap, iic->sts)) == 0x01) {
2587 + // Flush master data buf
2589 + DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));
2590 + ret = iic_inb(adap, iic->mdcntl);
2591 + iic_outb(adap, iic->mdcntl, ret | 0x40);
2594 + // Load slave address
2596 + DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
2597 + ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
2600 + // Check to see if the bus is busy
2602 + ret = iic_inb(adap, iic->extsts);
2603 + // Mask off the irrelevent bits
2605 + // When the bus is free, the BCS bits in the EXTSTS register are 0b100
2606 + if(ret != 0x40) return IIC_ERR_LOST_ARB;
2609 + // Combined transaction (read and write)
2612 + DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
2613 + ret = iic_combined_transaction(i2c_adap, msgs, num);
2618 + else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
2620 + // Tell device to begin reading data from the master data
2622 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
2623 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2628 + else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
2630 + // Write data to master data buffers and tell our device
2631 + // to begin transmitting
2633 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
2634 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2642 +// Description: Implements device specific ioctls. Higher level ioctls can
2643 +// be found in i2c-core.c and are typical of any i2c controller (specifying
2644 +// slave address, timeouts, etc). These ioctls take advantage of any hardware
2645 +// features built into the controller for which this algorithm-adapter set
2646 +// was written. These ioctls allow you to take control of the data and clock
2647 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
2648 +// similar to a GPIO pin.
2650 +static int algo_control(struct i2c_adapter *adapter,
2651 + unsigned int cmd, unsigned long arg)
2653 + struct iic_regs *iic;
2654 + struct i2c_algo_iic_data *adap = adapter->algo_data;
2655 + struct iic_ibm *adap_priv_data = adap->data;
2658 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2660 + lines = iic_inb(adap, iic->directcntl);
2662 + if (cmd == IICO_I2C_SDAHIGH) {
2663 + lines = lines & 0x01;
2664 + if( lines ) lines = 0x04;
2666 + iic_outb(adap, iic->directcntl,(0x08|lines));
2668 + else if (cmd == IICO_I2C_SDALOW) {
2669 + lines = lines & 0x01;
2670 + if( lines ) lines = 0x04;
2672 + iic_outb(adap, iic->directcntl,(0x00|lines));
2674 + else if (cmd == IICO_I2C_SCLHIGH) {
2675 + lines = lines & 0x02;
2676 + if( lines ) lines = 0x08;
2678 + iic_outb(adap, iic->directcntl,(0x04|lines));
2680 + else if (cmd == IICO_I2C_SCLLOW) {
2681 + lines = lines & 0x02;
2682 + if( lines ) lines = 0x08;
2684 + iic_outb(adap, iic->directcntl,(0x00|lines));
2686 + else if (cmd == IICO_I2C_LINEREAD) {
2693 +static u32 iic_func(struct i2c_adapter *adap)
2695 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2696 + I2C_FUNC_PROTOCOL_MANGLING;
2700 +/* -----exported algorithm data: ------------------------------------- */
2702 +static struct i2c_algorithm iic_algo = {
2703 + .owner = THIS_MODULE,
2704 + .name = "IBM on-chip IIC algorithm",
2705 + .id = I2C_ALGO_OCP,
2706 + .master_xfer = iic_xfer,
2707 + .algo_control = algo_control,
2708 + .functionality = iic_func,
2712 + * registering functions to load algorithms at runtime
2717 +// Description: Register bus structure
2719 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
2721 + struct i2c_algo_iic_data *iic_adap = adap->algo_data;
2723 + DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
2726 + /* register new adapter to i2c module... */
2728 + adap->id |= iic_algo.id;
2729 + adap->algo = &iic_algo;
2731 + adap->timeout = 100; /* default values, should */
2732 + adap->retries = 3; /* be replaced by defines */
2734 + iic_init(iic_adap);
2735 + i2c_add_adapter(adap);
2743 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
2745 + return i2c_del_adapter(adap);
2749 +EXPORT_SYMBOL(i2c_ocp_add_bus);
2750 +EXPORT_SYMBOL(i2c_ocp_del_bus);
2753 +// The MODULE_* macros resolve to nothing if MODULES is not defined
2754 +// when this file is compiled.
2756 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
2757 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
2758 +MODULE_LICENSE("GPL");
2760 +MODULE_PARM(i2c_debug,"i");
2762 +MODULE_PARM_DESC(i2c_debug,
2763 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
2765 diff -urN linux-2.4.24.org/drivers/i2c/i2c-algo-pcf.c linux-2.4.24/drivers/i2c/i2c-algo-pcf.c
2766 --- linux-2.4.24.org/drivers/i2c/i2c-algo-pcf.c 2004-02-04 22:33:47.589988460 +0100
2767 +++ linux-2.4.24/drivers/i2c/i2c-algo-pcf.c 2004-02-04 22:36:36.656830731 +0100
2769 #include <linux/delay.h>
2770 #include <linux/slab.h>
2771 #include <linux/init.h>
2772 -#include <asm/uaccess.h>
2773 -#include <linux/ioport.h>
2774 #include <linux/errno.h>
2775 #include <linux/sched.h>
2777 #include <linux/i2c.h>
2778 #include <linux/i2c-algo-pcf.h>
2779 -#include "i2c-pcf8584.h"
2782 /* ----- global defines ----------------------------------------------- */
2783 #define DEB(x) if (i2c_debug>=1) x
2785 /* module parameters:
2787 static int i2c_debug=0;
2788 -static int pcf_scan=0; /* have a look at what's hanging 'round */
2790 /* --- setting states on the bus with the right timing: --------------- */
2793 set_pcf(adap, 1, I2C_PCF_PIN);
2794 /* check to see S1 now used as R/W ctrl -
2795 PCF8584 does that when ESO is zero */
2796 - /* PCF also resets PIN bit */
2797 - if ((temp = get_pcf(adap, 1)) != (0)) {
2798 + if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
2799 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
2800 return -ENXIO; /* definetly not PCF8584 */
2803 /* S1=0xA0, next byte in S2 */
2804 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
2805 /* check to see S2 now selected */
2806 - if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
2807 + if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
2808 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
2811 @@ -427,12 +422,6 @@
2815 -static int algo_control(struct i2c_adapter *adapter,
2816 - unsigned int cmd, unsigned long arg)
2821 static u32 pcf_func(struct i2c_adapter *adap)
2823 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2824 @@ -442,14 +431,11 @@
2825 /* -----exported algorithm data: ------------------------------------- */
2827 static struct i2c_algorithm pcf_algo = {
2828 - "PCF8584 algorithm",
2832 - NULL, /* slave_xmit */
2833 - NULL, /* slave_recv */
2834 - algo_control, /* ioctl */
2835 - pcf_func, /* functionality */
2836 + .owner = THIS_MODULE,
2837 + .name = "PCF8584 algorithm",
2838 + .id = I2C_ALGO_PCF,
2839 + .master_xfer = pcf_xfer,
2840 + .functionality = pcf_func,
2846 int i2c_pcf_add_bus(struct i2c_adapter *adap)
2850 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
2852 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
2853 @@ -475,81 +461,23 @@
2858 - MOD_INC_USE_COUNT;
2861 i2c_add_adapter(adap);
2865 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
2867 - for (i = 0x00; i < 0xff; i+=2) {
2868 - if (wait_for_bb(pcf_adap)) {
2869 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
2873 - i2c_outb(pcf_adap, i);
2874 - i2c_start(pcf_adap);
2875 - if ((wait_for_pin(pcf_adap, &status) >= 0) &&
2876 - ((status & I2C_PCF_LRB) == 0)) {
2877 - printk("(%02x)",i>>1);
2881 - i2c_stop(pcf_adap);
2882 - udelay(pcf_adap->udelay);
2890 int i2c_pcf_del_bus(struct i2c_adapter *adap)
2893 - if ((res = i2c_del_adapter(adap)) < 0)
2895 - DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
2898 - MOD_DEC_USE_COUNT;
2903 -int __init i2c_algo_pcf_init (void)
2905 - printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
2907 + return i2c_del_adapter(adap);
2911 EXPORT_SYMBOL(i2c_pcf_add_bus);
2912 EXPORT_SYMBOL(i2c_pcf_del_bus);
2915 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
2916 MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
2917 MODULE_LICENSE("GPL");
2919 -MODULE_PARM(pcf_scan, "i");
2920 MODULE_PARM(i2c_debug,"i");
2922 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
2923 MODULE_PARM_DESC(i2c_debug,
2924 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
2927 -int init_module(void)
2929 - return i2c_algo_pcf_init();
2932 -void cleanup_module(void)
2936 diff -urN linux-2.4.24.org/drivers/i2c/i2c-core.c linux-2.4.24/drivers/i2c/i2c-core.c
2937 --- linux-2.4.24.org/drivers/i2c/i2c-core.c 2004-02-04 22:33:47.354037526 +0100
2938 +++ linux-2.4.24/drivers/i2c/i2c-core.c 2004-02-04 22:36:36.665828860 +0100
2940 /* ------------------------------------------------------------------------- */
2942 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi>.
2943 - All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
2944 + All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
2945 + SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */
2948 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
2950 #include <linux/module.h>
2951 #include <linux/kernel.h>
2952 #include <linux/errno.h>
2953 #include <linux/slab.h>
2954 #include <linux/proc_fs.h>
2955 -#include <linux/config.h>
2957 -#include <linux/i2c.h>
2959 -/* ----- compatibility stuff ----------------------------------------------- */
2961 #include <linux/init.h>
2963 +#include <linux/i2c.h>
2964 #include <asm/uaccess.h>
2966 /* ----- global defines ---------------------------------------------------- */
2968 -/* exclusive access to the bus */
2969 -#define I2C_LOCK(adap) down(&adap->lock)
2970 -#define I2C_UNLOCK(adap) up(&adap->lock)
2972 -#define ADAP_LOCK() down(&adap_lock)
2973 -#define ADAP_UNLOCK() up(&adap_lock)
2975 -#define DRV_LOCK() down(&driver_lock)
2976 -#define DRV_UNLOCK() up(&driver_lock)
2978 #define DEB(x) if (i2c_debug>=1) x;
2979 #define DEB2(x) if (i2c_debug>=2) x;
2981 /* ----- global variables -------------------------------------------------- */
2983 -/**** lock for writing to global variables: the adapter & driver list */
2984 -struct semaphore adap_lock;
2985 -struct semaphore driver_lock;
2987 -/**** adapter list */
2988 +DECLARE_MUTEX(core_lists);
2989 static struct i2c_adapter *adapters[I2C_ADAP_MAX];
2990 -static int adap_count;
2992 -/**** drivers list */
2993 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
2994 -static int driver_count;
2996 /**** debug level */
2997 -static int i2c_debug=1;
2998 +static int i2c_debug;
3000 /* ---------------------------------------------------
3001 * /proc entry declarations
3005 #ifdef CONFIG_PROC_FS
3007 -static int i2cproc_init(void);
3008 -static int i2cproc_cleanup(void);
3010 static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
3012 static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
3014 /* To implement the dynamic /proc/bus/i2c-? files, we need our own
3015 implementation of the read hook */
3016 static struct file_operations i2cproc_operations = {
3017 - read: i2cproc_bus_read,
3018 + .read = i2cproc_bus_read,
3021 -static int i2cproc_initialized = 0;
3023 -#else /* undef CONFIG_PROC_FS */
3025 -#define i2cproc_init() 0
3026 -#define i2cproc_cleanup() 0
3027 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3028 +static void i2cproc_remove(int bus);
3030 #endif /* CONFIG_PROC_FS */
3034 int i2c_add_adapter(struct i2c_adapter *adap)
3040 + down(&core_lists);
3041 for (i = 0; i < I2C_ADAP_MAX; i++)
3042 if (NULL == adapters[i])
3044 @@ -125,68 +94,39 @@
3049 +#ifdef CONFIG_PROC_FS
3050 + res = i2cproc_register(adap, i);
3053 +#endif /* def CONFIG_PROC_FS */
3059 /* init data types */
3060 - init_MUTEX(&adap->lock);
3062 -#ifdef CONFIG_PROC_FS
3064 - if (i2cproc_initialized) {
3066 - struct proc_dir_entry *proc_entry;
3068 - sprintf(name,"i2c-%d", i);
3070 - proc_entry = create_proc_entry(name,0,proc_bus);
3071 - if (! proc_entry) {
3072 - printk("i2c-core.o: Could not create /proc/bus/%s\n",
3078 - proc_entry->proc_fops = &i2cproc_operations;
3079 - proc_entry->owner = THIS_MODULE;
3080 - adap->inode = proc_entry->low_ino;
3083 -#endif /* def CONFIG_PROC_FS */
3084 + init_MUTEX(&adap->bus);
3085 + init_MUTEX(&adap->list);
3087 /* inform drivers of new adapters */
3089 for (j=0;j<I2C_DRIVER_MAX;j++)
3090 if (drivers[j]!=NULL &&
3091 (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
3092 /* We ignore the return code; if it fails, too bad */
3093 drivers[j]->attach_adapter(adap);
3096 DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3104 - adapters[i] = NULL;
3113 int i2c_del_adapter(struct i2c_adapter *adap)
3120 + down(&core_lists);
3121 for (i = 0; i < I2C_ADAP_MAX; i++)
3122 if (adap == adapters[i])
3124 @@ -202,17 +142,14 @@
3125 * *detach* it! Of course, each dummy driver should know about
3126 * this or hell will break loose...
3129 for (j = 0; j < I2C_DRIVER_MAX; j++)
3130 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3131 if ((res = drivers[j]->attach_adapter(adap))) {
3132 printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3133 "while detaching driver %s: driver not "
3134 "detached!",adap->name,drivers[j]->name);
3141 /* detach any active clients. This must be done first, because
3142 * it can fail; in which case we give upp. */
3143 @@ -231,26 +168,15 @@
3148 #ifdef CONFIG_PROC_FS
3149 - if (i2cproc_initialized) {
3151 - sprintf(name,"i2c-%d", i);
3152 - remove_proc_entry(name,proc_bus);
3154 + i2cproc_remove(i);
3155 #endif /* def CONFIG_PROC_FS */
3161 DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
3174 int i2c_add_driver(struct i2c_driver *driver)
3179 + down(&core_lists);
3180 for (i = 0; i < I2C_DRIVER_MAX; i++)
3181 if (NULL == drivers[i])
3183 @@ -273,19 +200,12 @@
3184 " i2c-core.o: register_driver(%s) "
3185 "- enlarge I2C_DRIVER_MAX.\n",
3192 drivers[i] = driver;
3195 - DRV_UNLOCK(); /* driver was successfully added */
3197 DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
3201 /* now look for instances of driver on our adapters
3203 if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
3204 @@ -294,15 +214,15 @@
3206 driver->attach_adapter(adapters[i]);
3213 int i2c_del_driver(struct i2c_driver *driver)
3216 + int i,j,k,res = 0;
3219 + down(&core_lists);
3220 for (i = 0; i < I2C_DRIVER_MAX; i++)
3221 if (driver == drivers[i])
3224 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
3231 /* Have a look at each adapter, if clients of this driver are still
3233 * invalid operation might (will!) result, when using stale client
3236 - ADAP_LOCK(); /* should be moved inside the if statement... */
3237 for (k=0;k<I2C_ADAP_MAX;k++) {
3238 struct i2c_adapter *adap = adapters[k];
3239 if (adap == NULL) /* skip empty entries. */
3241 "not be detached properly; driver "
3242 "not unloaded!",driver->name,
3249 for (j=0;j<I2C_CLIENT_MAX;j++) {
3250 @@ -359,37 +277,47 @@
3251 "unregistering driver "
3252 "`%s', the client at "
3254 - "adapter `%s' could not"
3255 - "be detached; driver"
3256 + "adapter `%s' could not "
3257 + "be detached; driver "
3275 DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
3283 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3284 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
3287 for (i = 0; i < I2C_CLIENT_MAX ; i++)
3288 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
3294 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3298 + down(&adapter->list);
3299 + rval = __i2c_check_addr(adapter, addr);
3300 + up(&adapter->list);
3305 int i2c_attach_client(struct i2c_client *client)
3307 struct i2c_adapter *adapter = client->adapter;
3309 if (i2c_check_addr(client->adapter,client->addr))
3312 + down(&adapter->list);
3313 for (i = 0; i < I2C_CLIENT_MAX; i++)
3314 if (NULL == adapter->clients[i])
3316 @@ -405,11 +334,11 @@
3318 " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
3320 + up(&adapter->list);
3324 adapter->clients[i] = client;
3325 - adapter->client_count++;
3326 + up(&adapter->list);
3328 if (adapter->client_register)
3329 if (adapter->client_register(client))
3330 @@ -431,16 +360,6 @@
3331 struct i2c_adapter *adapter = client->adapter;
3334 - for (i = 0; i < I2C_CLIENT_MAX; i++)
3335 - if (client == adapter->clients[i])
3337 - if (I2C_CLIENT_MAX == i) {
3338 - printk(KERN_WARNING " i2c-core.o: unregister_client "
3339 - "[%s] not found\n",
3344 if( (client->flags & I2C_CLIENT_ALLOW_USE) &&
3345 (client->usage_count>0))
3347 @@ -452,33 +371,41 @@
3351 + down(&adapter->list);
3352 + for (i = 0; i < I2C_CLIENT_MAX; i++)
3353 + if (client == adapter->clients[i])
3355 + if (I2C_CLIENT_MAX == i) {
3356 + printk(KERN_WARNING " i2c-core.o: unregister_client "
3357 + "[%s] not found\n",
3359 + up(&adapter->list);
3362 adapter->clients[i] = NULL;
3363 - adapter->client_count--;
3364 + up(&adapter->list);
3366 DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
3370 -void i2c_inc_use_client(struct i2c_client *client)
3371 +static void i2c_inc_use_client(struct i2c_client *client)
3374 - if (client->driver->inc_use != NULL)
3375 - client->driver->inc_use(client);
3377 - if (client->adapter->inc_use != NULL)
3378 - client->adapter->inc_use(client->adapter);
3379 + if(client->driver->owner)
3380 + __MOD_INC_USE_COUNT(client->driver->owner);
3381 + if(client->adapter->owner)
3382 + __MOD_INC_USE_COUNT(client->adapter->owner);
3385 -void i2c_dec_use_client(struct i2c_client *client)
3386 +static void i2c_dec_use_client(struct i2c_client *client)
3389 - if (client->driver->dec_use != NULL)
3390 - client->driver->dec_use(client);
3392 - if (client->adapter->dec_use != NULL)
3393 - client->adapter->dec_use(client->adapter);
3394 + if(client->driver->owner)
3395 + __MOD_DEC_USE_COUNT(client->driver->owner);
3396 + if(client->adapter->owner)
3397 + __MOD_DEC_USE_COUNT(client->adapter->owner);
3400 +#if 0 /* just forget about this for now --km */
3401 struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
3402 struct i2c_client *prev)
3404 @@ -545,18 +472,17 @@
3410 int i2c_use_client(struct i2c_client *client)
3412 - if(client->flags & I2C_CLIENT_ALLOW_USE) {
3413 - if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
3414 + if (client->flags & I2C_CLIENT_ALLOW_USE) {
3415 + if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
3416 + client->usage_count++;
3417 + else if (client->usage_count > 0)
3420 client->usage_count++;
3422 - if(client->usage_count > 0)
3425 - client->usage_count++;
3429 i2c_inc_use_client(client);
3430 @@ -589,12 +515,13 @@
3431 #ifdef CONFIG_PROC_FS
3433 /* This function generates the output for /proc/bus/i2c */
3434 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
3435 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
3440 /* Note that it is safe to write a `little' beyond len. Yes, really. */
3441 + down(&core_lists);
3442 for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
3444 nr += sprintf(buf+nr, "i2c-%d\t", i);
3447 adapters[i]->algo->name);
3453 @@ -621,98 +549,125 @@
3454 struct inode * inode = file->f_dentry->d_inode;
3456 struct i2c_client *client;
3457 + struct i2c_adapter *adap;
3458 int i,j,k,order_nr,len=0;
3460 int order[I2C_CLIENT_MAX];
3461 +#define OUTPUT_LENGTH_PER_LINE 70
3465 len_total = file->f_pos + count;
3466 - /* Too bad if this gets longer (unlikely) */
3467 - if (len_total > 4000)
3469 - for (i = 0; i < I2C_ADAP_MAX; i++)
3470 - if (adapters[i]->inode == inode->i_ino) {
3471 - /* We need a bit of slack in the kernel buffer; this makes the
3473 - if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
3475 - /* Order will hold the indexes of the clients
3476 - sorted by address */
3478 - for (j = 0; j < I2C_CLIENT_MAX; j++) {
3479 - if ((client = adapters[i]->clients[j]) &&
3480 - (client->driver->id != I2C_DRIVERID_I2CDEV)) {
3483 - adapters[i]->clients[order[k-1]]->
3484 - addr > client->addr;
3486 - order[k] = order[k-1];
3493 - for (j = 0; (j < order_nr) && (len < len_total); j++) {
3494 - client = adapters[i]->clients[order[j]];
3495 - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3498 - client->driver->name);
3500 - len = len - file->f_pos;
3505 - if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3509 - file->f_pos += len;
3514 + if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
3515 + /* adjust to maximum file size */
3516 + len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
3518 + down(&core_lists);
3519 + /* adap = file->private_data; ?? --km */
3520 + for (i = 0; i < I2C_ADAP_MAX; i++) {
3521 + adap = adapters[i];
3522 + if (adap && (adap->inode == inode->i_ino))
3525 + if ( I2C_ADAP_MAX == i ) {
3530 + /* We need a bit of slack in the kernel buffer; this makes the
3532 + if (! (kbuf = kmalloc(len_total +
3533 + OUTPUT_LENGTH_PER_LINE,
3537 + /* Order will hold the indexes of the clients
3538 + sorted by address */
3540 + down(&adap->list);
3541 + for (j = 0; j < I2C_CLIENT_MAX; j++) {
3542 + if ((client = adap->clients[j]) &&
3543 + (client->driver->id != I2C_DRIVERID_I2CDEV)) {
3546 + adap->clients[order[k-1]]->
3547 + addr > client->addr;
3549 + order[k] = order[k-1];
3556 + for (j = 0; (j < order_nr) && (len < len_total); j++) {
3557 + client = adap->clients[order[j]];
3558 + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3561 + client->driver->name);
3566 + len = len - file->f_pos;
3571 + if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3575 + file->f_pos += len;
3580 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
3583 + struct proc_dir_entry *proc_entry;
3585 + sprintf(name,"i2c-%d", bus);
3586 + proc_entry = create_proc_entry(name,0,proc_bus);
3587 + if (! proc_entry) {
3588 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
3593 + proc_entry->proc_fops = &i2cproc_operations;
3594 + proc_entry->owner = adap->owner;
3595 + adap->inode = proc_entry->low_ino;
3599 -int i2cproc_init(void)
3600 +static void i2cproc_remove(int bus)
3603 + sprintf(name,"i2c-%d", bus);
3604 + remove_proc_entry(name, proc_bus);
3607 +static int __init i2cproc_init(void)
3609 struct proc_dir_entry *proc_bus_i2c;
3611 - i2cproc_initialized = 0;
3614 - printk("i2c-core.o: /proc/bus/ does not exist");
3615 - i2cproc_cleanup();
3618 proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
3619 if (!proc_bus_i2c) {
3620 printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
3621 - i2cproc_cleanup();
3625 proc_bus_i2c->read_proc = &read_bus_i2c;
3626 proc_bus_i2c->owner = THIS_MODULE;
3627 - i2cproc_initialized += 2;
3631 -int i2cproc_cleanup(void)
3632 +static void __exit i2cproc_cleanup(void)
3635 - if (i2cproc_initialized >= 1) {
3636 - remove_proc_entry("i2c",proc_bus);
3637 - i2cproc_initialized -= 2;
3640 + remove_proc_entry("i2c",proc_bus);
3644 #endif /* def CONFIG_PROC_FS */
3646 /* ----------------------------------------------------
3648 DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
3653 ret = adap->algo->master_xfer(adap,msgs,num);
3660 DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
3661 count,client->adapter->name));
3665 ret = adap->algo->master_xfer(adap,&msg,1);
3669 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
3670 * transmitted, else error code.
3672 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
3673 count,client->adapter->name));
3677 ret = adap->algo->master_xfer(adap,&msg,1);
3681 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
3682 ret, count, client->addr));
3683 @@ -965,6 +920,123 @@
3685 /* The SMBus parts */
3687 +#define POLY (0x1070U << 3)
3693 + for(i = 0; i < 8; i++) {
3694 + if (data & 0x8000)
3695 + data = data ^ POLY;
3698 + return (u8)(data >> 8);
3701 +/* CRC over count bytes in the first array plus the bytes in the rest
3702 + array if it is non-null. rest[0] is the (length of rest) - 1
3703 + and is included. */
3704 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
3708 + for(i = 0; i < count; i++)
3709 + crc = crc8((crc ^ first[i]) << 8);
3711 + for(i = 0; i <= rest[0]; i++)
3712 + crc = crc8((crc ^ rest[i]) << 8);
3716 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
3718 + return i2c_smbus_partial_pec(0, count, first, rest);
3721 +/* Returns new "size" (transaction type)
3722 + Note that we convert byte to byte_data and byte_data to word_data
3723 + rather than invent new xxx_PEC transactions. */
3724 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
3725 + union i2c_smbus_data *data)
3729 + buf[0] = addr << 1;
3732 + case I2C_SMBUS_BYTE:
3733 + data->byte = i2c_smbus_pec(2, buf, NULL);
3734 + size = I2C_SMBUS_BYTE_DATA;
3736 + case I2C_SMBUS_BYTE_DATA:
3737 + buf[2] = data->byte;
3738 + data->word = buf[2] ||
3739 + (i2c_smbus_pec(3, buf, NULL) << 8);
3740 + size = I2C_SMBUS_WORD_DATA;
3742 + case I2C_SMBUS_WORD_DATA:
3745 + case I2C_SMBUS_BLOCK_DATA:
3746 + data->block[data->block[0] + 1] =
3747 + i2c_smbus_pec(2, buf, data->block);
3748 + size = I2C_SMBUS_BLOCK_DATA_PEC;
3754 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
3755 + union i2c_smbus_data *data)
3757 + u8 buf[3], rpec, cpec;
3761 + case I2C_SMBUS_BYTE_DATA:
3762 + buf[0] = (addr << 1) | 1;
3763 + cpec = i2c_smbus_pec(2, buf, NULL);
3764 + rpec = data->byte;
3766 + case I2C_SMBUS_WORD_DATA:
3767 + buf[0] = (addr << 1) | 1;
3768 + buf[2] = data->word & 0xff;
3769 + cpec = i2c_smbus_pec(3, buf, NULL);
3770 + rpec = data->word >> 8;
3772 + case I2C_SMBUS_WORD_DATA_PEC:
3776 + case I2C_SMBUS_PROC_CALL_PEC:
3780 + case I2C_SMBUS_BLOCK_DATA_PEC:
3781 + buf[0] = (addr << 1);
3782 + buf[2] = (addr << 1) | 1;
3783 + cpec = i2c_smbus_pec(3, buf, data->block);
3784 + rpec = data->block[data->block[0] + 1];
3786 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3787 + buf[0] = (addr << 1) | 1;
3788 + rpec = i2c_smbus_partial_pec(partial, 1,
3789 + buf, data->block);
3790 + cpec = data->block[data->block[0] + 1];
3796 + if(rpec != cpec) {
3797 + DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
3804 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
3806 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3807 @@ -983,8 +1055,9 @@
3809 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
3811 + union i2c_smbus_data data; /* only for PEC */
3812 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3813 - I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
3814 + I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
3817 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
3818 @@ -1072,6 +1145,43 @@
3819 I2C_SMBUS_BLOCK_DATA,&data);
3822 +/* Returns the number of read bytes */
3823 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
3824 + u8 command, u8 length, u8 *values)
3826 + union i2c_smbus_data data;
3828 + if (length > I2C_SMBUS_BLOCK_MAX - 1)
3830 + data.block[0] = length;
3831 + for (i = 1; i <= length; i++)
3832 + data.block[i] = values[i-1];
3833 + if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3834 + I2C_SMBUS_WRITE, command,
3835 + I2C_SMBUS_BLOCK_PROC_CALL, &data))
3837 + for (i = 1; i <= data.block[0]; i++)
3838 + values[i-1] = data.block[i];
3839 + return data.block[0];
3842 +/* Returns the number of read bytes */
3843 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
3844 + u8 command, u8 *values)
3846 + union i2c_smbus_data data;
3848 + if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3849 + I2C_SMBUS_READ,command,
3850 + I2C_SMBUS_I2C_BLOCK_DATA,&data))
3853 + for (i = 1; i <= data.block[0]; i++)
3854 + values[i-1] = data.block[i];
3855 + return data.block[0];
3859 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
3860 u8 command, u8 length, u8 *values)
3862 @@ -1098,13 +1208,13 @@
3863 need to use only one message; when reading, we need two. We initialize
3864 most things with sane defaults, to keep the code below somewhat
3866 - unsigned char msgbuf0[34];
3867 - unsigned char msgbuf1[34];
3868 + unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+2];
3869 + unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
3870 int num = read_write == I2C_SMBUS_READ?2:1;
3871 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
3872 { addr, flags | I2C_M_RD, 0, msgbuf1 }
3877 msgbuf0[0] = command;
3879 @@ -1140,16 +1250,30 @@
3881 case I2C_SMBUS_PROC_CALL:
3882 num = 2; /* Special case */
3883 + read_write = I2C_SMBUS_READ;
3886 msgbuf0[1] = data->word & 0xff;
3887 msgbuf0[2] = (data->word >> 8) & 0xff;
3889 case I2C_SMBUS_BLOCK_DATA:
3890 + case I2C_SMBUS_BLOCK_DATA_PEC:
3891 if (read_write == I2C_SMBUS_READ) {
3892 - printk(KERN_ERR "i2c-core.o: Block read not supported "
3893 - "under I2C emulation!\n");
3895 + /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_READ_BLOCK_DATA */
3896 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
3897 + printk(KERN_ERR "i2c-core.o: Block read not supported "
3898 + "under I2C emulation!\n");
3901 + /* set send message */
3903 + /* set recv message */
3904 + msg[1].flags |= I2C_M_RECV_LEN;
3905 + msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
3906 + if (size == I2C_SMBUS_BLOCK_DATA_PEC) {
3908 + msg[1].flags |= I2C_M_RECV_PEC;
3911 msg[0].len = data->block[0] + 2;
3912 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
3913 @@ -1158,10 +1282,57 @@
3917 + if(size == I2C_SMBUS_BLOCK_DATA_PEC)
3919 for (i = 1; i <= msg[0].len; i++)
3920 msgbuf0[i] = data->block[i-1];
3923 + case I2C_SMBUS_BLOCK_PROC_CALL:
3924 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3925 + /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_BLOCK_PROC_CALL */
3926 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_PROC_CALL)) {
3927 + printk(KERN_ERR "i2c-core.o: adapter doesn't support block process call!\n");
3931 + /* Another special case */
3933 + read_write = I2C_SMBUS_READ;
3935 + /* set send message */
3936 + msg[0].len = data->block[0] + 2;
3937 + if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
3938 + printk(KERN_ERR "i2c-core.o: smbus_access called with "
3939 + "invalid block write size (%d)\n", data->block[0]);
3942 + for (i = 1; i <= msg[0].len; i++)
3943 + msgbuf0[i] = data->block[i-1];
3945 + /* set recv message */
3946 + msg[1].flags |= I2C_M_RECV_LEN;
3947 + msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
3948 + if (size == I2C_SMBUS_BLOCK_PROC_CALL_PEC) {
3950 + msg[1].flags |= I2C_M_RECV_PEC;
3953 + case I2C_SMBUS_I2C_BLOCK_DATA:
3954 + if (read_write == I2C_SMBUS_READ) {
3955 + msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
3957 + msg[0].len = data->block[0] + 1;
3958 + if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
3959 + printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
3960 + "invalid block write size (%d)\n",
3964 + for (i = 1; i <= data->block[0]; i++)
3965 + msgbuf0[i] = data->block[i];
3969 printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
3971 @@ -1183,25 +1354,72 @@
3972 case I2C_SMBUS_PROC_CALL:
3973 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
3975 + case I2C_SMBUS_I2C_BLOCK_DATA:
3976 + /* fixed at 32 for now */
3977 + data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
3978 + for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
3979 + data->block[i+1] = msgbuf1[i];
3981 + case I2C_SMBUS_BLOCK_DATA:
3982 + case I2C_SMBUS_BLOCK_PROC_CALL:
3983 + case I2C_SMBUS_BLOCK_DATA_PEC:
3984 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3985 + len = msgbuf1[0] + 1;
3986 + if(size == I2C_SMBUS_BLOCK_DATA_PEC ||
3987 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)
3989 + for (i = 0; i < len; i++)
3990 + data->block[i] = msgbuf1[i];
3997 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
3998 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
3999 char read_write, u8 command, int size,
4000 union i2c_smbus_data * data)
4003 - flags = flags & I2C_M_TEN;
4004 - if (adapter->algo->smbus_xfer) {
4005 - I2C_LOCK(adapter);
4006 - res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4010 + flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4011 + if((flags & I2C_CLIENT_PEC) &&
4012 + !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4014 + if(read_write == I2C_SMBUS_READ &&
4015 + size == I2C_SMBUS_BLOCK_DATA)
4016 + size = I2C_SMBUS_BLOCK_DATA_PEC;
4017 + else if(size == I2C_SMBUS_PROC_CALL)
4018 + size = I2C_SMBUS_PROC_CALL_PEC;
4019 + else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
4020 + i2c_smbus_add_pec(addr, command,
4021 + I2C_SMBUS_BLOCK_DATA, data);
4022 + partial = data->block[data->block[0] + 1];
4023 + size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
4024 + } else if(read_write == I2C_SMBUS_WRITE &&
4025 + size != I2C_SMBUS_QUICK &&
4026 + size != I2C_SMBUS_I2C_BLOCK_DATA)
4027 + size = i2c_smbus_add_pec(addr, command, size, data);
4030 + if (adap->algo->smbus_xfer) {
4032 + res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
4034 - I2C_UNLOCK(adapter);
4037 - res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
4038 + res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
4041 + if(res >= 0 && swpec &&
4042 + size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
4043 + (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
4044 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
4045 + if(i2c_smbus_check_pec(addr, command, size, partial, data))
4051 @@ -1228,136 +1446,37 @@
4052 printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4053 memset(adapters,0,sizeof(adapters));
4054 memset(drivers,0,sizeof(drivers));
4058 - init_MUTEX(&adap_lock);
4059 - init_MUTEX(&driver_lock);
4063 +#ifdef CONFIG_PROC_FS
4064 + return i2cproc_init();
4070 -#ifdef CONFIG_I2C_CHARDEV
4071 - extern int i2c_dev_init(void);
4073 -#ifdef CONFIG_I2C_ALGOBIT
4074 - extern int i2c_algo_bit_init(void);
4076 -#ifdef CONFIG_I2C_PHILIPSPAR
4077 - extern int i2c_bitlp_init(void);
4079 -#ifdef CONFIG_I2C_ELV
4080 - extern int i2c_bitelv_init(void);
4082 -#ifdef CONFIG_I2C_VELLEMAN
4083 - extern int i2c_bitvelle_init(void);
4085 -#ifdef CONFIG_I2C_BITVIA
4086 - extern int i2c_bitvia_init(void);
4089 -#ifdef CONFIG_I2C_ALGOPCF
4090 - extern int i2c_algo_pcf_init(void);
4092 -#ifdef CONFIG_I2C_ELEKTOR
4093 - extern int i2c_pcfisa_init(void);
4096 -#ifdef CONFIG_I2C_ALGO8XX
4097 - extern int i2c_algo_8xx_init(void);
4099 -#ifdef CONFIG_I2C_RPXLITE
4100 - extern int i2c_rpx_init(void);
4103 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4104 - extern int i2c_algo_sibyte_init(void);
4105 - extern int i2c_sibyte_init(void);
4107 -#ifdef CONFIG_I2C_MAX1617
4108 - extern int i2c_max1617_init(void);
4112 -#ifdef CONFIG_I2C_PROC
4113 - extern int sensors_init(void);
4114 +static void __exit i2c_exit(void)
4116 +#ifdef CONFIG_PROC_FS
4117 + i2cproc_cleanup();
4121 -/* This is needed for automatic patch generation: sensors code starts here */
4122 -/* This is needed for automatic patch generation: sensors code ends here */
4124 +/* leave this in for now simply to make patching easier so we don't have
4125 + to remove the call in drivers/char/mem.c */
4126 int __init i2c_init_all(void)
4128 - /* --------------------- global ----- */
4131 -#ifdef CONFIG_I2C_CHARDEV
4134 - /* --------------------- bit -------- */
4135 -#ifdef CONFIG_I2C_ALGOBIT
4136 - i2c_algo_bit_init();
4138 -#ifdef CONFIG_I2C_PHILIPSPAR
4141 -#ifdef CONFIG_I2C_ELV
4142 - i2c_bitelv_init();
4144 -#ifdef CONFIG_I2C_VELLEMAN
4145 - i2c_bitvelle_init();
4148 - /* --------------------- pcf -------- */
4149 -#ifdef CONFIG_I2C_ALGOPCF
4150 - i2c_algo_pcf_init();
4152 -#ifdef CONFIG_I2C_ELEKTOR
4153 - i2c_pcfisa_init();
4156 - /* --------------------- 8xx -------- */
4157 -#ifdef CONFIG_I2C_ALGO8XX
4158 - i2c_algo_8xx_init();
4160 -#ifdef CONFIG_I2C_RPXLITE
4164 - /* --------------------- SiByte -------- */
4165 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4166 - i2c_algo_sibyte_init();
4167 - i2c_sibyte_init();
4169 -#ifdef CONFIG_I2C_MAX1617
4170 - i2c_max1617_init();
4173 - /* -------------- proc interface ---- */
4174 -#ifdef CONFIG_I2C_PROC
4177 -/* This is needed for automatic patch generation: sensors code starts here */
4178 -/* This is needed for automatic patch generation: sensors code ends here */
4187 EXPORT_SYMBOL(i2c_add_adapter);
4188 EXPORT_SYMBOL(i2c_del_adapter);
4189 EXPORT_SYMBOL(i2c_add_driver);
4190 EXPORT_SYMBOL(i2c_del_driver);
4191 EXPORT_SYMBOL(i2c_attach_client);
4192 EXPORT_SYMBOL(i2c_detach_client);
4193 -EXPORT_SYMBOL(i2c_inc_use_client);
4194 -EXPORT_SYMBOL(i2c_dec_use_client);
4196 EXPORT_SYMBOL(i2c_get_client);
4198 EXPORT_SYMBOL(i2c_use_client);
4199 EXPORT_SYMBOL(i2c_release_client);
4200 EXPORT_SYMBOL(i2c_check_addr);
4201 @@ -1381,11 +1500,12 @@
4202 EXPORT_SYMBOL(i2c_smbus_process_call);
4203 EXPORT_SYMBOL(i2c_smbus_read_block_data);
4204 EXPORT_SYMBOL(i2c_smbus_write_block_data);
4205 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
4206 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
4208 EXPORT_SYMBOL(i2c_get_functionality);
4209 EXPORT_SYMBOL(i2c_check_functionality);
4212 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4213 MODULE_DESCRIPTION("I2C-Bus main module");
4214 MODULE_LICENSE("GPL");
4215 @@ -1393,13 +1513,5 @@
4216 MODULE_PARM(i2c_debug, "i");
4217 MODULE_PARM_DESC(i2c_debug,"debug level");
4219 -int init_module(void)
4221 - return i2c_init();
4224 -void cleanup_module(void)
4226 - i2cproc_cleanup();
4229 +module_init(i2c_init);
4230 +module_exit(i2c_exit);
4231 diff -urN linux-2.4.24.org/drivers/i2c/i2c-dev.c linux-2.4.24/drivers/i2c/i2c-dev.c
4232 --- linux-2.4.24.org/drivers/i2c/i2c-dev.c 2004-02-04 22:33:47.320044595 +0100
4233 +++ linux-2.4.24/drivers/i2c/i2c-dev.c 2004-02-04 22:36:36.672827404 +0100
4235 /* The devfs code is contributed by Philipp Matthias Hahn
4236 <pmhahn@titan.lahn.de> */
4241 -#include <linux/config.h>
4242 #include <linux/kernel.h>
4243 #include <linux/module.h>
4244 #include <linux/fs.h>
4246 #ifdef CONFIG_DEVFS_FS
4247 #include <linux/devfs_fs_kernel.h>
4251 -/* If you want debugging uncomment: */
4252 -/* #define DEBUG */
4254 #include <linux/init.h>
4255 -#include <asm/uaccess.h>
4257 #include <linux/i2c.h>
4258 #include <linux/i2c-dev.h>
4259 +#include <asm/uaccess.h>
4261 +/* If you want debugging uncomment: */
4262 +/* #define DEBUG */
4265 -extern int init_module(void);
4266 -extern int cleanup_module(void);
4267 -#endif /* def MODULE */
4269 /* struct file_operations changed too often in the 2.1 series for nice code */
4272 static int i2cdev_command(struct i2c_client *client, unsigned int cmd,
4280 - int __init i2c_dev_init(void);
4281 -static int i2cdev_cleanup(void);
4283 static struct file_operations i2cdev_fops = {
4284 - owner: THIS_MODULE,
4285 - llseek: no_llseek,
4286 - read: i2cdev_read,
4287 - write: i2cdev_write,
4288 - ioctl: i2cdev_ioctl,
4289 - open: i2cdev_open,
4290 - release: i2cdev_release,
4291 + .owner = THIS_MODULE,
4292 + .llseek = no_llseek,
4293 + .read = i2cdev_read,
4294 + .write = i2cdev_write,
4295 + .ioctl = i2cdev_ioctl,
4296 + .open = i2cdev_open,
4297 + .release = i2cdev_release,
4300 #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
4304 static struct i2c_driver i2cdev_driver = {
4305 - name: "i2c-dev dummy driver",
4306 - id: I2C_DRIVERID_I2CDEV,
4307 - flags: I2C_DF_DUMMY,
4308 - attach_adapter: i2cdev_attach_adapter,
4309 - detach_client: i2cdev_detach_client,
4310 - command: i2cdev_command,
4313 + .owner = THIS_MODULE, /* not really used */
4314 + .name = "i2c-dev dummy driver",
4315 + .id = I2C_DRIVERID_I2CDEV,
4316 + .flags = I2C_DF_DUMMY,
4317 + .attach_adapter = i2cdev_attach_adapter,
4318 + .detach_client = i2cdev_detach_client,
4319 + .command = i2cdev_command,
4322 static struct i2c_client i2cdev_client_template = {
4323 - name: "I2C /dev entry",
4327 -/* adapter: NULL, */
4328 - driver: &i2cdev_driver,
4330 + .name = "I2C /dev entry",
4333 + .driver = &i2cdev_driver,
4336 -static int i2cdev_initialized;
4338 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
4345 - printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
4346 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
4354 - printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
4355 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
4358 ret = i2c_master_send(client,tmp,count);
4362 printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
4363 - MINOR(inode->i_rdev),cmd, arg);
4364 + minor(inode->i_rdev),cmd, arg);
4368 @@ -218,6 +196,12 @@
4370 client->flags &= ~I2C_M_TEN;
4374 + client->flags |= I2C_CLIENT_PEC;
4376 + client->flags &= ~I2C_CLIENT_PEC;
4379 funcs = i2c_get_functionality(client->adapter);
4380 return (copy_to_user((unsigned long *)arg,&funcs,
4382 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
4383 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
4384 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
4385 - (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
4386 + (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
4387 + (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
4389 printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
4391 @@ -361,10 +346,11 @@
4392 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
4393 (data_arg.size == I2C_SMBUS_PROC_CALL))
4394 datasize = sizeof(data_arg.data->word);
4395 - else /* size == I2C_SMBUS_BLOCK_DATA */
4396 + else /* size == smbus block, i2c block, or block proc. call */
4397 datasize = sizeof(data_arg.data->block);
4399 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
4400 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
4401 (data_arg.read_write == I2C_SMBUS_WRITE)) {
4402 if (copy_from_user(&temp, data_arg.data, datasize))
4405 data_arg.read_write,
4406 data_arg.command,data_arg.size,&temp);
4407 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
4408 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
4409 (data_arg.read_write == I2C_SMBUS_READ))) {
4410 if (copy_to_user(data_arg.data, &temp, datasize))
4414 int i2cdev_open (struct inode *inode, struct file *file)
4416 - unsigned int minor = MINOR(inode->i_rdev);
4417 + unsigned int minor = minor(inode->i_rdev);
4418 struct i2c_client *client;
4420 if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
4421 @@ -403,11 +390,13 @@
4422 if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
4424 memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
4426 + /* registered with adapter, passed as client to user */
4427 client->adapter = i2cdev_adaps[minor];
4428 file->private_data = client;
4430 - if (i2cdev_adaps[minor]->inc_use)
4431 - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
4432 + if(client->adapter->owner)
4433 + __MOD_INC_USE_COUNT(client->adapter->owner);
4436 printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
4437 @@ -417,16 +406,19 @@
4439 static int i2cdev_release (struct inode *inode, struct file *file)
4441 - unsigned int minor = MINOR(inode->i_rdev);
4442 - kfree(file->private_data);
4443 - file->private_data=NULL;
4444 + struct i2c_client *client;
4446 + unsigned int minor = minor(inode->i_rdev);
4449 + client = file->private_data;
4450 + file->private_data = NULL;
4451 + if(client->adapter->owner)
4452 + __MOD_DEC_USE_COUNT(client->adapter->owner);
4455 printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
4458 - if (i2cdev_adaps[minor]->dec_use)
4459 - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
4465 devfs_i2c[i] = devfs_register (devfs_handle, name,
4466 DEVFS_FL_DEFAULT, I2C_MAJOR, i,
4467 S_IFCHR | S_IRUSR | S_IWUSR,
4468 - &i2cdev_fops, NULL);
4469 + &i2cdev_fops, adap);
4471 printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
4473 @@ -479,13 +471,12 @@
4477 -int __init i2c_dev_init(void)
4478 +static int __init i2c_dev_init(void)
4482 printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4484 - i2cdev_initialized = 0;
4485 #ifdef CONFIG_DEVFS_FS
4486 if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
4488 @@ -498,63 +489,31 @@
4489 #ifdef CONFIG_DEVFS_FS
4490 devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
4492 - i2cdev_initialized ++;
4494 if ((res = i2c_add_driver(&i2cdev_driver))) {
4495 printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
4497 +#ifdef CONFIG_DEVFS_FS
4498 + devfs_unregister(devfs_handle);
4500 + unregister_chrdev(I2C_MAJOR,"i2c");
4503 - i2cdev_initialized ++;
4507 -int i2cdev_cleanup(void)
4508 +static void __exit i2c_dev_exit(void)
4512 - if (i2cdev_initialized >= 2) {
4513 - if ((res = i2c_del_driver(&i2cdev_driver))) {
4514 - printk("i2c-dev.o: Driver deregistration failed, "
4515 - "module not removed.\n");
4518 - i2cdev_initialized --;
4521 - if (i2cdev_initialized >= 1) {
4522 + i2c_del_driver(&i2cdev_driver);
4523 #ifdef CONFIG_DEVFS_FS
4524 - devfs_unregister(devfs_handle);
4525 - if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
4527 - if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
4528 + devfs_unregister(devfs_handle);
4530 - printk("i2c-dev.o: unable to release major %d for i2c bus\n",
4534 - i2cdev_initialized --;
4537 + unregister_chrdev(I2C_MAJOR,"i2c");
4544 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4545 MODULE_DESCRIPTION("I2C /dev entries driver");
4546 MODULE_LICENSE("GPL");
4548 -int init_module(void)
4550 - return i2c_dev_init();
4553 -int cleanup_module(void)
4555 - return i2cdev_cleanup();
4558 -#endif /* def MODULE */
4560 +module_init(i2c_dev_init);
4561 +module_exit(i2c_dev_exit);
4562 diff -urN linux-2.4.24.org/drivers/i2c/i2c-elektor.c linux-2.4.24/drivers/i2c/i2c-elektor.c
4563 --- linux-2.4.24.org/drivers/i2c/i2c-elektor.c 2004-02-04 22:33:47.601985965 +0100
4564 +++ linux-2.4.24/drivers/i2c/i2c-elektor.c 2004-02-04 22:36:36.682825325 +0100
4566 #include <linux/delay.h>
4567 #include <linux/slab.h>
4568 #include <linux/init.h>
4569 +#include <linux/interrupt.h>
4570 #include <linux/pci.h>
4571 -#include <asm/irq.h>
4572 -#include <asm/io.h>
4574 +#include <linux/wait.h>
4575 #include <linux/i2c.h>
4576 #include <linux/i2c-algo-pcf.h>
4577 -#include <linux/i2c-elektor.h>
4578 -#include "i2c-pcf8584.h"
4579 +#include <asm/io.h>
4580 +#include <asm/irq.h>
4582 #define DEFAULT_BASE 0x330
4584 -static int base = 0;
4585 -static int irq = 0;
4588 static int clock = 0x1c;
4589 static int own = 0x55;
4590 -static int mmapped = 0;
4591 -static int i2c_debug = 0;
4592 +static int mmapped;
4593 +static int i2c_debug;
4595 /* vdovikin: removed static struct i2c_pcf_isa gpi; code -
4596 this module in real supports only one device, due to missing arguments
4599 static wait_queue_head_t pcf_wait;
4600 static int pcf_pending;
4601 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
4603 /* ----- global defines ----------------------------------------------- */
4604 #define DEB(x) if (i2c_debug>=1) x
4606 #define DEB3(x) if (i2c_debug>=3) x
4607 #define DEBE(x) x /* error messages */
4610 +/* compatibility */
4612 +#define isa_readb readb
4616 +#define isa_writeb writeb
4619 /* ----- local functions ---------------------------------------------- */
4621 static void pcf_isa_setbyte(void *data, int ctl, int val)
4623 int address = ctl ? (base + 1) : base;
4626 + /* enable irq if any specified for serial operation */
4627 + if (ctl && irq && (val & I2C_PCF_ESO)) {
4633 case 2: /* double mapped I/O needed for UP2000 board,
4634 I don't know why this... */
4635 - writeb(val, address);
4636 + isa_writeb(val, address);
4638 case 1: /* memory mapped I/O */
4639 - writeb(val, address);
4640 + isa_writeb(val, address);
4645 static int pcf_isa_getbyte(void *data, int ctl)
4647 int address = ctl ? (base + 1) : base;
4648 - int val = mmapped ? readb(address) : inb(address);
4649 + int val = mmapped ? isa_readb(address) : inb(address);
4651 DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
4653 @@ -115,12 +126,12 @@
4658 + spin_lock_irq(&irq_driver_lock);
4659 if (pcf_pending == 0) {
4660 interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
4664 + spin_unlock_irq(&irq_driver_lock);
4668 @@ -136,13 +147,11 @@
4669 static int pcf_isa_init(void)
4672 - if (check_region(base, 2) < 0 ) {
4673 + if (!request_region(base, 2, "i2c (isa bus adapter)")) {
4675 "i2c-elektor.o: requested I/O region (0x%X:2) "
4676 "is in use.\n", base);
4679 - request_region(base, 2, "i2c (isa bus adapter)");
4683 @@ -156,70 +165,29 @@
4687 -static void __exit pcf_isa_exit(void)
4694 - release_region(base , 2);
4699 -static int pcf_isa_reg(struct i2c_client *client)
4705 -static int pcf_isa_unreg(struct i2c_client *client)
4710 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
4713 - MOD_INC_USE_COUNT;
4717 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
4720 - MOD_DEC_USE_COUNT;
4725 /* ------------------------------------------------------------------------
4726 * Encapsulate the above functions in the correct operations structure.
4727 * This is only done when more than one hardware adapter is supported.
4729 static struct i2c_algo_pcf_data pcf_isa_data = {
4735 - pcf_isa_waitforpin,
4736 - 10, 10, 100, /* waits, timeout */
4737 + .setpcf = pcf_isa_setbyte,
4738 + .getpcf = pcf_isa_getbyte,
4739 + .getown = pcf_isa_getown,
4740 + .getclock = pcf_isa_getclock,
4741 + .waitforpin = pcf_isa_waitforpin,
4747 static struct i2c_adapter pcf_isa_ops = {
4748 - "PCF8584 ISA adapter",
4756 + .owner = THIS_MODULE,
4757 + .name = "PCF8584 ISA adapter",
4758 + .id = I2C_HW_P_ELEK,
4759 + .algo_data = &pcf_isa_data,
4762 -int __init i2c_pcfisa_init(void)
4763 +static int __init i2c_pcfisa_init(void)
4766 /* check to see we have memory mapped PCF8584 connected to the
4767 @@ -277,22 +245,41 @@
4770 init_waitqueue_head(&pcf_wait);
4771 - if (pcf_isa_init() == 0) {
4772 - if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
4775 + if (pcf_isa_init())
4778 + if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
4781 printk(KERN_DEBUG "i2c-elektor.o: found device at %#x.\n", base);
4792 + release_region(base , 2);
4796 +static void __exit i2c_pcfisa_exit(void)
4798 + i2c_pcf_del_bus(&pcf_isa_ops);
4806 + release_region(base , 2);
4812 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
4813 MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
4814 MODULE_LICENSE("GPL");
4815 @@ -304,15 +291,5 @@
4816 MODULE_PARM(mmapped, "i");
4817 MODULE_PARM(i2c_debug, "i");
4819 -int init_module(void)
4821 - return i2c_pcfisa_init();
4824 -void cleanup_module(void)
4826 - i2c_pcf_del_bus(&pcf_isa_ops);
4831 +module_init(i2c_pcfisa_init);
4832 +module_exit(i2c_pcfisa_exit);
4833 diff -urN linux-2.4.24.org/drivers/i2c/i2c-elv.c linux-2.4.24/drivers/i2c/i2c-elv.c
4834 --- linux-2.4.24.org/drivers/i2c/i2c-elv.c 2004-02-04 22:33:47.624981184 +0100
4835 +++ linux-2.4.24/drivers/i2c/i2c-elv.c 2004-02-04 22:36:36.688824077 +0100
4837 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
4838 Frodo Looijaard <frodol@dds.nl> */
4843 #include <linux/kernel.h>
4844 #include <linux/module.h>
4845 #include <linux/delay.h>
4846 #include <linux/slab.h>
4847 #include <linux/init.h>
4849 -#include <asm/uaccess.h>
4851 #include <linux/ioport.h>
4852 -#include <asm/io.h>
4853 #include <linux/errno.h>
4854 #include <linux/i2c.h>
4855 #include <linux/i2c-algo-bit.h>
4856 +#include <asm/io.h>
4858 #define DEFAULT_BASE 0x378
4862 static int bit_elv_init(void)
4864 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
4867 - /* test for ELV adap. */
4868 - if (inb(base+1) & 0x80) { /* BUSY should be high */
4869 - DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
4872 - outb(0x0c,base+2); /* SLCT auf low */
4874 - if ( !(inb(base+1) && 0x10) ) {
4875 - outb(0x04,base+2);
4876 - DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
4880 - request_region(base,(base == 0x3bc)? 3 : 8,
4881 - "i2c (ELV adapter)");
4883 - bit_elv_setsda((void*)base,1);
4884 - bit_elv_setscl((void*)base,1);
4885 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
4886 + "i2c (ELV adapter)"))
4889 + if (inb(base+1) & 0x80) { /* BUSY should be high */
4890 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
4894 + outb(0x0c,base+2); /* SLCT auf low */
4896 + if (!(inb(base+1) && 0x10)) {
4897 + outb(0x04,base+2);
4898 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
4904 -static void __exit bit_elv_exit(void)
4906 - release_region( base , (base == 0x3bc)? 3 : 8 );
4909 -static int bit_elv_reg(struct i2c_client *client)
4914 -static int bit_elv_unreg(struct i2c_client *client)
4917 + bit_elv_setsda((void*)base,1);
4918 + bit_elv_setscl((void*)base,1);
4922 -static void bit_elv_inc_use(struct i2c_adapter *adap)
4925 - MOD_INC_USE_COUNT;
4929 -static void bit_elv_dec_use(struct i2c_adapter *adap)
4932 - MOD_DEC_USE_COUNT;
4935 + release_region(base , (base == 0x3bc) ? 3 : 8);
4939 /* ------------------------------------------------------------------------
4940 @@ -148,26 +118,23 @@
4941 * This is only done when more than one hardware adapter is supported.
4943 static struct i2c_algo_bit_data bit_elv_data = {
4949 - 80, 80, 100, /* waits, timeout */
4950 + .setsda = bit_elv_setsda,
4951 + .setscl = bit_elv_setscl,
4952 + .getsda = bit_elv_getsda,
4953 + .getscl = bit_elv_getscl,
4959 static struct i2c_adapter bit_elv_ops = {
4960 - "ELV Parallel port adaptor",
4968 + .owner = THIS_MODULE,
4969 + .name = "ELV Parallel port adaptor",
4970 + .id = I2C_HW_B_ELV,
4971 + .algo_data = &bit_elv_data,
4974 -int __init i2c_bitelv_init(void)
4975 +static int __init i2c_bitelv_init(void)
4977 printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4979 @@ -193,25 +160,19 @@
4983 +static void __exit i2c_bitelv_exit(void)
4985 + i2c_bit_del_bus(&bit_elv_ops);
4986 + release_region(base, (base == 0x3bc) ? 3 : 8);
4992 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4993 MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
4994 MODULE_LICENSE("GPL");
4996 MODULE_PARM(base, "i");
4998 -int init_module(void)
5000 - return i2c_bitelv_init();
5003 -void cleanup_module(void)
5005 - i2c_bit_del_bus(&bit_elv_ops);
5010 +module_init(i2c_bitelv_init);
5011 +module_exit(i2c_bitelv_exit);
5012 diff -urN linux-2.4.24.org/drivers/i2c/i2c-frodo.c linux-2.4.24/drivers/i2c/i2c-frodo.c
5013 --- linux-2.4.24.org/drivers/i2c/i2c-frodo.c 1970-01-01 01:00:00.000000000 +0100
5014 +++ linux-2.4.24/drivers/i2c/i2c-frodo.c 2004-02-04 22:36:36.692823246 +0100
5018 + * linux/drivers/i2c/i2c-frodo.c
5020 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
5022 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
5023 + * Development board (Frodo).
5025 + * This source code is free software; you can redistribute it and/or
5026 + * modify it under the terms of the GNU General Public License
5027 + * version 2 as published by the Free Software Foundation.
5030 +#include <linux/module.h>
5031 +#include <linux/kernel.h>
5032 +#include <linux/init.h>
5033 +#include <linux/delay.h>
5034 +#include <linux/i2c.h>
5035 +#include <linux/i2c-algo-bit.h>
5036 +#include <asm/hardware.h>
5039 +static void frodo_setsda (void *data,int state)
5042 + FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
5044 + FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
5047 +static void frodo_setscl (void *data,int state)
5050 + FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
5052 + FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
5055 +static int frodo_getsda (void *data)
5057 + return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
5060 +static int frodo_getscl (void *data)
5062 + return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
5065 +static struct i2c_algo_bit_data bit_frodo_data = {
5066 + .setsda = frodo_setsda,
5067 + .setscl = frodo_setscl,
5068 + .getsda = frodo_getsda,
5069 + .getscl = frodo_getscl,
5075 +static struct i2c_adapter frodo_ops = {
5076 + .owner = THIS_MODULE,
5077 + .name = "Frodo adapter driver",
5078 + .id = I2C_HW_B_FRODO,
5079 + .algo_data = &bit_frodo_data,
5082 +static int __init i2c_frodo_init (void)
5084 + return i2c_bit_add_bus(&frodo_ops);
5087 +static void __exit i2c_frodo_exit (void)
5089 + i2c_bit_del_bus(&frodo_ops);
5092 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
5093 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
5094 +MODULE_LICENSE ("GPL");
5096 +module_init (i2c_frodo_init);
5097 +module_exit (i2c_frodo_exit);
5099 diff -urN linux-2.4.24.org/drivers/i2c/i2c-pcf-epp.c linux-2.4.24/drivers/i2c/i2c-pcf-epp.c
5100 --- linux-2.4.24.org/drivers/i2c/i2c-pcf-epp.c 1970-01-01 01:00:00.000000000 +0100
5101 +++ linux-2.4.24/drivers/i2c/i2c-pcf-epp.c 2004-02-04 22:36:36.696822414 +0100
5103 +/* ------------------------------------------------------------------------- */
5104 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters */
5105 +/* ------------------------------------------------------------------------- */
5106 +/* Copyright (C) 1998-99 Hans Berglund
5108 + This program is free software; you can redistribute it and/or modify
5109 + it under the terms of the GNU General Public License as published by
5110 + the Free Software Foundation; either version 2 of the License, or
5111 + (at your option) any later version.
5113 + This program is distributed in the hope that it will be useful,
5114 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5115 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5116 + GNU General Public License for more details.
5118 + You should have received a copy of the GNU General Public License
5119 + along with this program; if not, write to the Free Software
5120 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5121 +/* ------------------------------------------------------------------------- */
5123 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
5125 +#include <linux/kernel.h>
5126 +#include <linux/ioport.h>
5127 +#include <linux/module.h>
5128 +#include <linux/delay.h>
5129 +#include <linux/slab.h>
5130 +#include <linux/init.h>
5131 +#include <linux/parport.h>
5132 +#include <linux/i2c.h>
5133 +#include <linux/i2c-algo-pcf.h>
5134 +#include <asm/irq.h>
5135 +#include <asm/io.h>
5138 +struct i2c_pcf_epp {
5145 +#define DEFAULT_BASE 0x378
5146 +#define DEFAULT_IRQ 7
5147 +#define DEFAULT_CLOCK 0x1c
5148 +#define DEFAULT_OWN 0x55
5150 +static int base = 0;
5151 +static int irq = 0;
5152 +static int clock = 0;
5153 +static int own = 0;
5154 +static int i2c_debug=0;
5155 +static struct i2c_pcf_epp gpe;
5156 +static wait_queue_head_t pcf_wait;
5157 +static int pcf_pending;
5158 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5160 +/* ----- global defines ----------------------------------------------- */
5161 +#define DEB(x) if (i2c_debug>=1) x
5162 +#define DEB2(x) if (i2c_debug>=2) x
5163 +#define DEB3(x) if (i2c_debug>=3) x
5164 +#define DEBE(x) x /* error messages */
5166 +/* --- Convenience defines for the EPP/SPP port: */
5167 +#define BASE ((struct i2c_pcf_epp *)(data))->pe_base
5168 +// #define DATA BASE /* SPP data port */
5169 +#define STAT (BASE+1) /* SPP status port */
5170 +#define CTRL (BASE+2) /* SPP control port */
5171 +#define EADD (BASE+3) /* EPP address port */
5172 +#define EDAT (BASE+4) /* EPP data port */
5174 +/* ----- local functions ---------------------------------------------- */
5176 +static void pcf_epp_setbyte(void *data, int ctl, int val)
5179 + if (gpe.pe_irq > 0) {
5180 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
5181 + val|I2C_PCF_ENI));
5182 + // set A0 pin HIGH
5183 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5184 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5185 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5187 + // EPP write data cycle
5188 + outb(val | I2C_PCF_ENI, EDAT);
5190 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
5191 + // set A0 pin HIGH
5192 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5196 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
5198 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5199 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5200 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5205 +static int pcf_epp_getbyte(void *data, int ctl)
5210 + // set A0 pin HIGH
5211 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5213 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
5216 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5218 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
5223 +static int pcf_epp_getown(void *data)
5225 + return (gpe.pe_own);
5229 +static int pcf_epp_getclock(void *data)
5231 + return (gpe.pe_clock);
5235 +static void pcf_epp_sleep(unsigned long timeout)
5237 + schedule_timeout( timeout * HZ);
5241 +static void pcf_epp_waitforpin(void) {
5244 + if (gpe.pe_irq > 0) {
5245 + spin_lock_irq(&irq_driver_lock);
5246 + if (pcf_pending == 0) {
5247 + interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
5252 + spin_unlock_irq(&irq_driver_lock);
5258 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
5260 + wake_up_interruptible(&pcf_wait);
5261 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
5265 +static int pcf_epp_init(void *data)
5267 + if (check_region(gpe.pe_base, 5) < 0 ) {
5269 + printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
5272 + request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
5275 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
5277 + if (gpe.pe_irq > 0) {
5278 + if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
5279 + printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
5282 + disable_irq(gpe.pe_irq);
5283 + enable_irq(gpe.pe_irq);
5285 + // EPP mode initialize
5286 + // enable interrupt from nINTR pin
5287 + outb(inb(CTRL)|0x14, CTRL);
5288 + // clear ERROR bit of STAT
5289 + outb(inb(STAT)|0x01, STAT);
5290 + outb(inb(STAT)&~0x01,STAT);
5295 +/* ------------------------------------------------------------------------
5296 + * Encapsulate the above functions in the correct operations structure.
5297 + * This is only done when more than one hardware adapter is supported.
5299 +static struct i2c_algo_pcf_data pcf_epp_data = {
5300 + .setpcf = pcf_epp_setbyte,
5301 + .getpcf = pcf_epp_getbyte,
5302 + .getown = pcf_epp_getown,
5303 + .getclock = pcf_epp_getclock,
5304 + .waitforpin = pcf_epp_waitforpin,
5310 +static struct i2c_adapter pcf_epp_ops = {
5311 + .owner = THIS_MODULE,
5312 + .name = "PCF8584 EPP adapter",
5313 + .id = I2C_HW_P_LP,
5314 + .algo_data = &pcf_epp_data,
5317 +static int __init i2c_pcfepp_init(void)
5319 + struct i2c_pcf_epp *pepp = &gpe;
5321 + printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5323 + pepp->pe_base = DEFAULT_BASE;
5325 + pepp->pe_base = base;
5328 + pepp->pe_irq = DEFAULT_IRQ;
5333 + pepp->pe_irq = irq;
5336 + pepp->pe_clock = DEFAULT_CLOCK;
5338 + pepp->pe_clock = clock;
5341 + pepp->pe_own = DEFAULT_OWN;
5343 + pepp->pe_own = own;
5345 + pcf_epp_data.data = (void *)pepp;
5346 + init_waitqueue_head(&pcf_wait);
5347 + if (pcf_epp_init(pepp) == 0) {
5349 + if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
5350 + printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
5351 + release_region(pepp->pe_base , 5);
5358 + printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
5362 +static void __exit pcf_epp_exit(void)
5364 + i2c_pcf_del_bus(&pcf_epp_ops);
5365 + if (gpe.pe_irq > 0) {
5366 + disable_irq(gpe.pe_irq);
5367 + free_irq(gpe.pe_irq, 0);
5369 + release_region(gpe.pe_base , 5);
5372 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
5373 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
5374 +MODULE_LICENSE("GPL");
5376 +MODULE_PARM(base, "i");
5377 +MODULE_PARM(irq, "i");
5378 +MODULE_PARM(clock, "i");
5379 +MODULE_PARM(own, "i");
5380 +MODULE_PARM(i2c_debug, "i");
5382 +module_init(i2c_pcfepp_init);
5383 +module_exit(pcf_epp_exit);
5384 diff -urN linux-2.4.24.org/drivers/i2c/i2c-philips-par.c linux-2.4.24/drivers/i2c/i2c-philips-par.c
5385 --- linux-2.4.24.org/drivers/i2c/i2c-philips-par.c 2004-02-04 22:33:47.661973491 +0100
5386 +++ linux-2.4.24/drivers/i2c/i2c-philips-par.c 2004-02-04 22:37:38.775910804 +0100
5388 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
5389 Frodo Looijaard <frodol@dds.nl> */
5394 #include <linux/kernel.h>
5395 #include <linux/ioport.h>
5397 #include <linux/init.h>
5398 #include <linux/stddef.h>
5399 #include <linux/parport.h>
5401 +#include <linux/slab.h>
5402 #include <linux/i2c.h>
5403 #include <linux/i2c-algo-bit.h>
5406 -#define __exit __init
5412 @@ -130,59 +126,34 @@
5413 PARPORT_STATUS_BUSY) ? 0 : 1;
5416 -static int bit_lp_reg(struct i2c_client *client)
5421 -static int bit_lp_unreg(struct i2c_client *client)
5426 -static void bit_lp_inc_use(struct i2c_adapter *adap)
5428 - MOD_INC_USE_COUNT;
5431 -static void bit_lp_dec_use(struct i2c_adapter *adap)
5433 - MOD_DEC_USE_COUNT;
5436 /* ------------------------------------------------------------------------
5437 * Encapsulate the above functions in the correct operations structure.
5438 * This is only done when more than one hardware adapter is supported.
5441 static struct i2c_algo_bit_data bit_lp_data = {
5447 - 80, 80, 100, /* waits, timeout */
5448 + .setsda = bit_lp_setsda,
5449 + .setscl = bit_lp_setscl,
5450 + .getsda = bit_lp_getsda,
5451 + .getscl = bit_lp_getscl,
5457 static struct i2c_algo_bit_data bit_lp_data2 = {
5463 - 80, 80, 100, /* waits, timeout */
5464 + .setsda = bit_lp_setsda2,
5465 + .setscl = bit_lp_setscl2,
5466 + .getsda = bit_lp_getsda2,
5472 static struct i2c_adapter bit_lp_ops = {
5473 - "Philips Parallel port adapter",
5482 + .owner = THIS_MODULE,
5483 + .name = "Philips Parallel port adapter",
5484 + .id = I2C_HW_B_LP,
5487 static void i2c_parport_attach (struct parport *port)
5490 if (!adapter->pdev) {
5491 printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
5496 @@ -211,7 +183,11 @@
5497 adapter->bit_lp_data.data = port;
5499 /* reset hardware to sane state */
5500 - parport_claim_or_block(adapter->pdev);
5501 + if (parport_claim_or_block(adapter->pdev) < 0 ) {
5502 + printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
5506 adapter->bit_lp_data.setsda(port, 1);
5507 adapter->bit_lp_data.setscl(port, 1);
5508 parport_release(adapter->pdev);
5513 -int __init i2c_bitlp_init(void)
5514 +static int __init i2c_bitlp_init(void)
5516 printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5522 -void __exit i2c_bitlp_exit(void)
5523 +static void __exit i2c_bitlp_exit(void)
5525 parport_unregister_driver(&i2c_driver);
5527 @@ -279,14 +255,5 @@
5529 MODULE_PARM(type, "i");
5532 -int init_module(void)
5534 - return i2c_bitlp_init();
5537 -void cleanup_module(void)
5542 +module_init(i2c_bitlp_init);
5543 +module_exit(i2c_bitlp_exit);
5544 diff -urN linux-2.4.24.org/drivers/i2c/i2c-pport.c linux-2.4.24/drivers/i2c/i2c-pport.c
5545 --- linux-2.4.24.org/drivers/i2c/i2c-pport.c 1970-01-01 01:00:00.000000000 +0100
5546 +++ linux-2.4.24/drivers/i2c/i2c-pport.c 2004-02-04 22:36:36.706820334 +0100
5548 +/* ------------------------------------------------------------------------- */
5549 +/* i2c-pport.c i2c-hw access for primitive i2c par. port adapter */
5550 +/* ------------------------------------------------------------------------- */
5551 +/* Copyright (C) 2001 Daniel Smolik
5553 + This program is free software; you can redistribute it and/or modify
5554 + it under the terms of the GNU General Public License as published by
5555 + the Free Software Foundation; either version 2 of the License, or
5556 + (at your option) any later version.
5558 + This program is distributed in the hope that it will be useful,
5559 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5560 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5561 + GNU General Public License for more details.
5563 + You should have received a copy of the GNU General Public License
5564 + along with this program; if not, write to the Free Software
5565 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5566 +/* ------------------------------------------------------------------------- */
5569 + See doc/i2c-pport for instructions on wiring to the
5570 + parallel port connector.
5572 + Cut & paste :-) based on Velleman K8000 driver by Simon G. Vogl
5576 +#include <linux/kernel.h>
5577 +#include <linux/module.h>
5578 +#include <linux/delay.h>
5579 +#include <linux/slab.h>
5580 +#include <linux/init.h>
5581 +#include <linux/ioport.h>
5582 +#include <linux/errno.h>
5583 +#include <linux/i2c.h>
5584 +#include <linux/i2c-algo-bit.h>
5585 +#include <asm/io.h>
5588 +#define DEFAULT_BASE 0x378
5590 +static unsigned char PortData = 0;
5592 +/* ----- global defines ----------------------------------------------- */
5593 +#define DEB(x) /* should be reasonable open, close &c. */
5594 +#define DEB2(x) /* low level debugging - very slow */
5595 +#define DEBE(x) x /* error messages */
5596 +#define DEBINIT(x) x /* detection status messages */
5598 +/* --- Convenience defines for the parallel port: */
5599 +#define BASE (unsigned int)(data)
5600 +#define DATA BASE /* Centronics data port */
5601 +#define STAT (BASE+1) /* Centronics status port */
5602 +#define CTRL (BASE+2) /* Centronics control port */
5604 +/* we will use SDA - Auto Linefeed(14) bit 1 POUT */
5605 +/* we will use SCL - Initialize printer(16) BUSY bit 2*/
5607 +#define SET_SCL | 0x04
5608 +#define CLR_SCL & 0xFB
5613 +#define SET_SDA & 0x04
5614 +#define CLR_SDA | 0x02
5617 +/* ----- local functions ---------------------------------------------- */
5620 +static void bit_pport_setscl(void *data, int state)
5624 + PortData = PortData SET_SCL;
5627 + PortData = PortData CLR_SCL;
5629 + outb(PortData, CTRL);
5632 +static void bit_pport_setsda(void *data, int state)
5636 + PortData = PortData SET_SDA;
5639 + PortData = PortData CLR_SDA;
5641 + outb(PortData, CTRL);
5644 +static int bit_pport_getscl(void *data)
5647 + return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
5650 +static int bit_pport_getsda(void *data)
5652 + return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
5655 +static int bit_pport_init(void)
5657 + if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
5660 + /* test for PPORT adap. */
5663 + PortData=inb(base+2);
5664 + PortData= (PortData SET_SDA) SET_SCL;
5665 + outb(PortData,base+2);
5667 + if (!(inb(base+2) | 0x06)) { /* SDA and SCL will be high */
5668 + DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
5672 + /*SCL high and SDA low*/
5673 + PortData = PortData SET_SCL CLR_SDA;
5674 + outb(PortData,base+2);
5675 + schedule_timeout(400);
5676 + if ( !(inb(base+2) | 0x4) ) {
5677 + //outb(0x04,base+2);
5678 + DEBINIT(printk("i2c-port.o: SDA was high.\n"));
5682 + bit_pport_setsda((void*)base,1);
5683 + bit_pport_setscl((void*)base,1);
5689 +/* ------------------------------------------------------------------------
5690 + * Encapsulate the above functions in the correct operations structure.
5691 + * This is only done when more than one hardware adapter is supported.
5693 +static struct i2c_algo_bit_data bit_pport_data = {
5694 + .setsda = bit_pport_setsda,
5695 + .setscl = bit_pport_setscl,
5696 + .getsda = bit_pport_getsda,
5697 + .getscl = bit_pport_getscl,
5703 +static struct i2c_adapter bit_pport_ops = {
5704 + .owner = THIS_MODULE,
5705 + .name = "Primitive Parallel port adaptor",
5706 + .id = I2C_HW_B_PPORT,
5707 + .algo_data = &bit_pport_data,
5710 +static int __init i2c_bitpport_init(void)
5712 + printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5715 + /* probe some values */
5716 + base=DEFAULT_BASE;
5717 + bit_pport_data.data=(void*)DEFAULT_BASE;
5718 + if (bit_pport_init()==0) {
5719 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
5725 + bit_pport_data.data=(void*)base;
5726 + if (bit_pport_init()==0) {
5727 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
5733 + printk("i2c-pport.o: found device at %#x.\n",base);
5737 +static void __exit i2c_bitpport_exit(void)
5739 + i2c_bit_del_bus(&bit_pport_ops);
5740 + release_region((base+2),1);
5745 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
5746 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
5747 +MODULE_LICENSE("GPL");
5749 +MODULE_PARM(base, "i");
5751 +module_init(i2c_bitpport_init);
5752 +module_exit(i2c_bitpport_exit);
5753 diff -urN linux-2.4.24.org/drivers/i2c/i2c-proc.c linux-2.4.24/drivers/i2c/i2c-proc.c
5754 --- linux-2.4.24.org/drivers/i2c/i2c-proc.c 2004-02-04 22:33:47.507005716 +0100
5755 +++ linux-2.4.24/drivers/i2c/i2c-proc.c 2004-02-04 22:36:36.711819295 +0100
5757 #include <linux/ctype.h>
5758 #include <linux/sysctl.h>
5759 #include <linux/proc_fs.h>
5760 +#include <linux/init.h>
5761 #include <linux/ioport.h>
5762 -#include <asm/uaccess.h>
5764 #include <linux/i2c.h>
5765 #include <linux/i2c-proc.h>
5766 +#include <asm/uaccess.h>
5768 -#include <linux/init.h>
5770 -#ifndef THIS_MODULE
5771 -#define THIS_MODULE NULL
5774 -static int i2c_create_name(char **name, const char *prefix,
5775 - struct i2c_adapter *adapter, int addr);
5776 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
5777 long *results, int magnitude);
5778 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
5779 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
5780 long *results, int magnitude);
5781 static int i2c_proc_chips(ctl_table * ctl, int write,
5782 struct file *filp, void *buffer,
5784 void *newval, size_t newlen,
5787 -int __init sensors_init(void);
5789 #define SENSORS_ENTRY_MAX 20
5790 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
5792 static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
5793 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
5795 -static ctl_table sysctl_table[] = {
5796 - {CTL_DEV, "dev", NULL, 0, 0555},
5798 - {DEV_SENSORS, "sensors", NULL, 0, 0555},
5800 - {0, NULL, NULL, 0, 0555},
5804 static ctl_table i2c_proc_dev_sensors[] = {
5805 {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips,
5809 static struct ctl_table_header *i2c_proc_header;
5810 -static int i2c_initialized;
5812 /* This returns a nice name for a new directory; for example lm78-isa-0310
5813 (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for
5814 a LM75 chip on the third i2c bus at address 0x4e).
5815 name is allocated first. */
5816 -int i2c_create_name(char **name, const char *prefix,
5817 - struct i2c_adapter *adapter, int addr)
5818 +static char *generate_name(struct i2c_client *client, const char *prefix)
5820 - char name_buffer[50];
5822 - if (i2c_is_isa_adapter(adapter))
5823 + struct i2c_adapter *adapter = client->adapter;
5824 + int addr = client->addr;
5825 + char name_buffer[50], *name;
5827 + if (i2c_is_isa_adapter(adapter)) {
5828 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
5830 - if ((id = i2c_adapter_id(adapter)) < 0)
5832 + } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
5833 + int id = i2c_adapter_id(adapter);
5835 + return ERR_PTR(-ENOENT);
5836 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
5837 + } else { /* dummy adapter, generate prefix */
5840 + sprintf(name_buffer, "%s-", prefix);
5841 + end = strlen(name_buffer);
5843 + for (i = 0; i < 32; i++) {
5844 + if (adapter->algo->name[i] == ' ')
5846 + name_buffer[end++] = tolower(adapter->algo->name[i]);
5849 + name_buffer[end] = 0;
5850 + sprintf(name_buffer + end, "-%04x", addr);
5852 - *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
5854 - printk (KERN_WARNING "i2c_create_name: not enough memory\n");
5857 - strcpy(*name, name_buffer);
5860 + name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
5862 + return ERR_PTR(-ENOMEM);
5863 + strcpy(name, name_buffer);
5867 /* This rather complex function must be called when you want to add an entry
5868 @@ -124,139 +118,91 @@
5869 ctl_template should be a template of the newly created directory. It is
5870 copied in memory. The extra2 field of each file is set to point to client.
5871 If any driver wants subdirectories within the newly created directory,
5872 - this function must be updated!
5873 - controlling_mod is the controlling module. It should usually be
5874 - THIS_MODULE when calling. Note that this symbol is not defined in
5875 - kernels before 2.3.13; define it to NULL in that case. We will not use it
5876 - for anything older than 2.3.27 anyway. */
5877 + this function must be updated! */
5878 int i2c_register_entry(struct i2c_client *client, const char *prefix,
5879 - ctl_table * ctl_template,
5880 - struct module *controlling_mod)
5881 + struct ctl_table *ctl_template)
5883 - int i, res, len, id;
5884 - ctl_table *new_table;
5886 - struct ctl_table_header *new_header;
5887 + struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
5888 + struct ctl_table_header *hdr;
5889 + struct ctl_table *tmp, *leaf;
5893 - if ((res = i2c_create_name(&name, prefix, client->adapter,
5894 - client->addr))) return res;
5895 + name = generate_name(client, prefix);
5897 + return PTR_ERR(name);
5899 - for (id = 0; id < SENSORS_ENTRY_MAX; id++)
5900 - if (!i2c_entries[id]) {
5903 - if (id == SENSORS_ENTRY_MAX) {
5906 + for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
5907 + if (!i2c_entries[id])
5913 + goto out_free_name;
5916 while (ctl_template[len].procname)
5919 - if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
5924 - memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
5925 - new_table[0].child = &new_table[2];
5926 - new_table[2].child = &new_table[4];
5927 - new_table[4].child = &new_table[6];
5928 - new_table[4].procname = name;
5929 - new_table[4].ctl_name = id;
5930 - memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
5931 - for (i = 6; i < len; i++)
5932 - new_table[i].extra2 = client;
5934 - if (!(new_header = register_sysctl_table(new_table, 0))) {
5940 - i2c_entries[id - 256] = new_header;
5942 - i2c_clients[id - 256] = client;
5944 - if (!new_header || !new_header->ctl_table ||
5945 - !new_header->ctl_table->child ||
5946 - !new_header->ctl_table->child->child ||
5947 - !new_header->ctl_table->child->child->de) {
5949 - ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
5953 - i2c_inodes[id - 256] =
5954 - new_header->ctl_table->child->child->de->low_ino;
5955 - new_header->ctl_table->child->child->de->owner = controlling_mod;
5958 + tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1),
5961 + goto out_free_name;
5962 + memset(tbl, 0, sizeof(*tbl));
5964 + /* The client sysctls */
5965 + leaf = (struct ctl_table *) (tbl + 1);
5966 + memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
5967 + for (tmp = leaf; tmp->ctl_name; tmp++)
5968 + tmp->extra2 = client;
5970 + tbl->sensors->ctl_name = id+256;
5971 + tbl->sensors->procname = name;
5972 + tbl->sensors->mode = 0555;
5973 + tbl->sensors->child = leaf;
5975 + tbl->dev->ctl_name = DEV_SENSORS;
5976 + tbl->dev->procname = "sensors";
5977 + tbl->dev->mode = 0555;
5978 + tbl->dev->child = tbl->sensors;
5980 + tbl->root->ctl_name = CTL_DEV;
5981 + tbl->root->procname = "dev";
5982 + tbl->root->mode = 0555;
5983 + tbl->root->child = tbl->dev;
5985 + hdr = register_sysctl_table(tbl->root, 0);
5987 + goto out_free_tbl;
5989 + i2c_entries[id] = hdr;
5990 + i2c_clients[id] = client;
5992 + return (id + 256); /* XXX(hch) why?? */
6001 void i2c_deregister_entry(int id)
6006 - if (i2c_entries[id]) {
6007 - table = i2c_entries[id]->ctl_table;
6008 - unregister_sysctl_table(i2c_entries[id]);
6009 - /* 2-step kfree needed to keep gcc happy about const points */
6010 - (const char *) temp = table[4].procname;
6013 - i2c_entries[id] = NULL;
6014 - i2c_clients[id] = NULL;
6018 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o
6019 - impossible if some process still uses it or some file in it */
6020 -void i2c_fill_inode(struct inode *inode, int fill)
6023 - MOD_INC_USE_COUNT;
6025 - MOD_DEC_USE_COUNT;
6028 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
6029 - the corresponding module impossible if some process still uses it or
6030 - some file in it */
6031 -void i2c_dir_fill_inode(struct inode *inode, int fill)
6034 - struct i2c_client *client;
6035 + if (i2c_entries[id]) {
6036 + struct ctl_table_header *hdr = i2c_entries[id];
6037 + struct ctl_table *tbl = hdr->ctl_table;
6041 - printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
6043 + unregister_sysctl_table(hdr);
6044 + kfree(tbl->child->child->procname);
6045 + kfree(tbl); /* actually the whole anonymous struct */
6047 -#endif /* def DEBUG */
6049 - for (i = 0; i < SENSORS_ENTRY_MAX; i++)
6050 - if (i2c_clients[i]
6051 - && (i2c_inodes[i] == inode->i_ino)) break;
6053 - if (i == SENSORS_ENTRY_MAX) {
6055 - ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
6059 -#endif /* def DEBUG */
6060 - client = i2c_clients[i];
6062 - client->driver->inc_use(client);
6064 - client->driver->dec_use(client);
6065 + i2c_entries[id] = NULL;
6066 + i2c_clients[id] = NULL;
6069 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6070 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6071 void *buffer, size_t * lenp)
6073 char BUF[SENSORS_PREFIX_MAX + 30];
6078 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6079 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6080 void *oldval, size_t * oldlenp, void *newval,
6081 size_t newlen, void **context)
6084 WARNING! This is tricky code. I have tested it, but there may still be
6085 hidden bugs in it, even leading to crashes and things!
6087 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6088 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6089 long *results, int magnitude)
6091 int maxels, min, mag;
6096 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
6097 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
6098 long *results, int magnitude)
6102 I2C_FUNC_SMBUS_QUICK)) return -1;
6104 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
6105 + /* XXX: WTF is going on here??? */
6106 if ((is_isa && check_region(addr, 1)) ||
6107 (!is_isa && i2c_check_addr(adapter, addr)))
6109 @@ -846,46 +793,33 @@
6113 -int __init sensors_init(void)
6114 +static int __init i2c_proc_init(void)
6116 printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
6117 - i2c_initialized = 0;
6120 - register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
6121 + register_sysctl_table(i2c_proc, 0))) {
6122 + printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
6125 i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
6126 - i2c_initialized++;
6130 +static void __exit i2c_proc_exit(void)
6132 + unregister_sysctl_table(i2c_proc_header);
6135 +EXPORT_SYMBOL(i2c_register_entry);
6136 EXPORT_SYMBOL(i2c_deregister_entry);
6137 -EXPORT_SYMBOL(i2c_detect);
6138 EXPORT_SYMBOL(i2c_proc_real);
6139 -EXPORT_SYMBOL(i2c_register_entry);
6140 EXPORT_SYMBOL(i2c_sysctl_real);
6143 +EXPORT_SYMBOL(i2c_detect);
6145 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
6146 MODULE_DESCRIPTION("i2c-proc driver");
6147 MODULE_LICENSE("GPL");
6149 -int i2c_cleanup(void)
6151 - if (i2c_initialized >= 1) {
6152 - unregister_sysctl_table(i2c_proc_header);
6153 - i2c_initialized--;
6158 -int init_module(void)
6160 - return sensors_init();
6163 -int cleanup_module(void)
6165 - return i2c_cleanup();
6167 -#endif /* MODULE */
6168 +module_init(i2c_proc_init);
6169 +module_exit(i2c_proc_exit);
6170 diff -urN linux-2.4.24.org/drivers/i2c/i2c-rpx.c linux-2.4.24/drivers/i2c/i2c-rpx.c
6171 --- linux-2.4.24.org/drivers/i2c/i2c-rpx.c 1970-01-01 01:00:00.000000000 +0100
6172 +++ linux-2.4.24/drivers/i2c/i2c-rpx.c 2004-02-04 22:36:36.715818463 +0100
6175 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
6176 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
6178 + * moved into proper i2c interface;
6179 + * Brad Parker (brad@heeltoe.com)
6181 + * RPX lite specific parts of the i2c interface
6182 + * Update: There actually isn't anything RPXLite-specific about this module.
6183 + * This should work for most any 8xx board. The console messages have been
6184 + * changed to eliminate RPXLite references.
6187 +#include <linux/kernel.h>
6188 +#include <linux/module.h>
6189 +#include <linux/init.h>
6190 +#include <linux/stddef.h>
6191 +#include <linux/i2c.h>
6192 +#include <linux/i2c-algo-8xx.h>
6193 +#include <asm/mpc8xx.h>
6194 +#include <asm/commproc.h>
6198 +rpx_iic_init(struct i2c_algo_8xx_data *data)
6200 + volatile cpm8xx_t *cp;
6201 + volatile immap_t *immap;
6203 + cp = cpmp; /* Get pointer to Communication Processor */
6204 + immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
6206 + data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
6208 + /* Check for and use a microcode relocation patch.
6210 + if ((data->reloc = data->iip->iic_rpbase))
6211 + data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
6213 + data->i2c = (i2c8xx_t *)&(immap->im_i2c);
6216 + /* Initialize Port B IIC pins.
6218 + cp->cp_pbpar |= 0x00000030;
6219 + cp->cp_pbdir |= 0x00000030;
6220 + cp->cp_pbodr |= 0x00000030;
6222 + /* Allocate space for two transmit and two receive buffer
6223 + * descriptors in the DP ram.
6225 + data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
6227 + /* ptr to i2c area */
6228 + data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
6231 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
6233 + /* install interrupt handler */
6234 + cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
6239 +static struct i2c_algo_8xx_data rpx_data = {
6240 + .setisr = rpx_install_isr
6243 +static struct i2c_adapter rpx_ops = {
6244 + .owner = THIS_MODULE,
6246 + .id = I2C_HW_MPC8XX_EPON,
6247 + .algo_data = &rpx_data,
6250 +static int __init i2c_rpx_init(void)
6252 + printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6254 + /* reset hardware to sane state */
6255 + rpx_iic_init(&rpx_data);
6257 + if (i2c_8xx_add_bus(&rpx_ops) < 0) {
6258 + printk("i2c-rpx: Unable to register with I2C\n");
6265 +static void __exit i2c_rpx_exit(void)
6267 + i2c_8xx_del_bus(&rpx_ops);
6270 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
6271 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
6273 +module_init(i2c_rpx_init);
6274 +module_exit(i2c_rpx_exit);
6275 diff -urN linux-2.4.24.org/drivers/i2c/i2c-velleman.c linux-2.4.24/drivers/i2c/i2c-velleman.c
6276 --- linux-2.4.24.org/drivers/i2c/i2c-velleman.c 2004-02-04 22:33:47.695966422 +0100
6277 +++ linux-2.4.24/drivers/i2c/i2c-velleman.c 2004-02-04 22:36:36.718817839 +0100
6279 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6280 /* ------------------------------------------------------------------------- */
6285 #include <linux/kernel.h>
6286 #include <linux/ioport.h>
6287 #include <linux/module.h>
6288 #include <linux/init.h>
6289 -#include <linux/string.h> /* for 2.0 kernels to get NULL */
6290 -#include <asm/errno.h> /* for 2.0 kernels to get ENODEV */
6291 -#include <asm/io.h>
6293 +#include <linux/errno.h>
6294 +#include <linux/delay.h>
6295 #include <linux/i2c.h>
6296 #include <linux/i2c-algo-bit.h>
6297 +#include <asm/io.h>
6298 +#include <asm/param.h> /* for HZ */
6300 /* ----- global defines ----------------------------------------------- */
6301 #define DEB(x) /* should be reasonable open, close &c. */
6304 static int bit_velle_init(void)
6306 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6307 - DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
6309 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
6310 + "i2c (Vellemann adapter)"))
6313 - request_region(base, (base == 0x3bc)? 3 : 8,
6314 - "i2c (Vellemann adapter)");
6315 - bit_velle_setsda((void*)base,1);
6316 - bit_velle_setscl((void*)base,1);
6321 -static void __exit bit_velle_exit(void)
6323 - release_region( base , (base == 0x3bc)? 3 : 8 );
6327 -static int bit_velle_reg(struct i2c_client *client)
6332 -static int bit_velle_unreg(struct i2c_client *client)
6334 + bit_velle_setsda((void*)base,1);
6335 + bit_velle_setscl((void*)base,1);
6339 -static void bit_velle_inc_use(struct i2c_adapter *adap)
6342 - MOD_INC_USE_COUNT;
6346 -static void bit_velle_dec_use(struct i2c_adapter *adap)
6349 - MOD_DEC_USE_COUNT;
6353 /* ------------------------------------------------------------------------
6354 * Encapsulate the above functions in the correct operations structure.
6355 * This is only done when more than one hardware adapter is supported.
6358 static struct i2c_algo_bit_data bit_velle_data = {
6364 - 10, 10, 100, /* waits, timeout */
6365 + .setsda = bit_velle_setsda,
6366 + .setscl = bit_velle_setscl,
6367 + .getsda = bit_velle_getsda,
6368 + .getscl = bit_velle_getscl,
6374 static struct i2c_adapter bit_velle_ops = {
6379 - bit_velle_inc_use,
6380 - bit_velle_dec_use,
6383 + .owner = THIS_MODULE,
6384 + .name = "Velleman K8000",
6385 + .id = I2C_HW_B_VELLE,
6386 + .algo_data = &bit_velle_data,
6389 -int __init i2c_bitvelle_init(void)
6390 +static int __init i2c_bitvelle_init(void)
6392 printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6394 @@ -184,24 +147,19 @@
6398 +static void __exit i2c_bitvelle_exit(void)
6400 + i2c_bit_del_bus(&bit_velle_ops);
6401 + release_region(base, (base == 0x3bc) ? 3 : 8);
6407 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
6408 MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
6409 MODULE_LICENSE("GPL");
6411 MODULE_PARM(base, "i");
6413 -int init_module(void)
6415 - return i2c_bitvelle_init();
6418 -void cleanup_module(void)
6420 - i2c_bit_del_bus(&bit_velle_ops);
6425 +module_init(i2c_bitvelle_init);
6426 +module_exit(i2c_bitvelle_exit);
6427 diff -urN linux-2.4.24.org/drivers/i2c/scx200_acb.c linux-2.4.24/drivers/i2c/scx200_acb.c
6428 --- linux-2.4.24.org/drivers/i2c/scx200_acb.c 2004-02-04 22:33:47.486010082 +0100
6429 +++ linux-2.4.24/drivers/i2c/scx200_acb.c 2004-02-04 22:36:36.724816591 +0100
6430 @@ -408,16 +408,6 @@
6434 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
6436 - MOD_INC_USE_COUNT;
6439 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
6441 - MOD_DEC_USE_COUNT;
6444 /* For now, we only handle combined mode (smbus) */
6445 static struct i2c_algorithm scx200_acb_algorithm = {
6446 name: "NatSemi SCx200 ACCESS.bus",
6448 sprintf(adapter->name, "SCx200 ACB%d", index);
6449 adapter->id = I2C_ALGO_SMBUS;
6450 adapter->algo = &scx200_acb_algorithm;
6451 - adapter->inc_use = scx200_acb_inc_use;
6452 - adapter->dec_use = scx200_acb_dec_use;
6453 adapter->client_register = scx200_acb_reg;
6454 adapter->client_unregister = scx200_acb_unreg;
6456 diff -urN linux-2.4.24.org/drivers/i2c/scx200_i2c.c linux-2.4.24/drivers/i2c/scx200_i2c.c
6457 --- linux-2.4.24.org/drivers/i2c/scx200_i2c.c 2004-02-04 22:33:47.451017359 +0100
6458 +++ linux-2.4.24/drivers/i2c/scx200_i2c.c 2004-02-04 22:36:36.728815760 +0100
6463 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
6465 - MOD_INC_USE_COUNT;
6468 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
6470 - MOD_DEC_USE_COUNT;
6473 /* ------------------------------------------------------------------------
6474 * Encapsulate the above functions in the correct operations structure.
6475 * This is only done when more than one hardware adapter is supported.
6477 .name = "NatSemi SCx200 I2C",
6478 .id = I2C_HW_B_VELLE,
6479 .algo_data = &scx200_i2c_data,
6480 - .inc_use = scx200_i2c_inc_use,
6481 - .dec_use = scx200_i2c_dec_use,
6482 .client_register = scx200_i2c_reg,
6483 .client_unregister = scx200_i2c_unreg,
6485 diff -urN linux-2.4.24.org/drivers/media/video/saa5249.c linux-2.4.24/drivers/media/video/saa5249.c
6486 --- linux-2.4.24.org/drivers/media/video/saa5249.c 2004-02-04 22:33:53.966662445 +0100
6487 +++ linux-2.4.24/drivers/media/video/saa5249.c 2004-02-04 22:36:37.042750465 +0100
6488 @@ -258,12 +258,12 @@
6490 static struct i2c_driver i2c_driver_videotext =
6492 - IF_NAME, /* name */
6493 - I2C_DRIVERID_SAA5249, /* in i2c.h */
6498 + .name = IF_NAME, /* name */
6499 + .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
6500 + .flags = I2C_DF_NOTIFY,
6501 + .attach_adapter = saa5249_probe,
6502 + .detach_client = saa5249_detach,
6503 + .command = saa5249_command
6506 static struct i2c_client client_template = {
6507 diff -urN linux-2.4.24.org/drivers/media/video/tuner-3036.c linux-2.4.24/drivers/media/video/tuner-3036.c
6508 --- linux-2.4.24.org/drivers/media/video/tuner-3036.c 2004-02-04 22:33:54.024650387 +0100
6509 +++ linux-2.4.24/drivers/media/video/tuner-3036.c 2004-02-04 22:36:37.049749010 +0100
6510 @@ -185,12 +185,12 @@
6511 static struct i2c_driver
6514 - "sab3036", /* name */
6515 - I2C_DRIVERID_SAB3036, /* ID */
6520 + .name = "sab3036", /* name */
6521 + .id = I2C_DRIVERID_SAB3036, /* ID */
6522 + .flags = I2C_DF_NOTIFY,
6523 + .attach_adapter = tuner_probe,
6524 + .detach_client = tuner_detach,
6525 + .command = tuner_command
6528 static struct i2c_client client_template =
6529 diff -urN linux-2.4.24.org/drivers/video/matrox/i2c-matroxfb.c linux-2.4.24/drivers/video/matrox/i2c-matroxfb.c
6530 --- linux-2.4.24.org/drivers/video/matrox/i2c-matroxfb.c 2004-02-04 22:33:29.409768997 +0100
6531 +++ linux-2.4.24/drivers/video/matrox/i2c-matroxfb.c 2004-02-04 22:36:37.057747346 +0100
6533 return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
6536 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
6537 - MOD_INC_USE_COUNT;
6540 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
6541 - MOD_DEC_USE_COUNT;
6544 static struct i2c_adapter matrox_i2c_adapter_template =
6546 .id = I2C_HW_B_G400,
6547 - .inc_use = matroxfb_dh_inc_use,
6548 - .dec_use = matroxfb_dh_dec_use,
6551 static struct i2c_algo_bit_data matrox_i2c_algo_template =
6552 diff -urN linux-2.4.24.org/drivers/video/matrox/matroxfb_maven.c linux-2.4.24/drivers/video/matrox/matroxfb_maven.c
6553 --- linux-2.4.24.org/drivers/video/matrox/matroxfb_maven.c 2004-02-04 22:33:29.237804756 +0100
6554 +++ linux-2.4.24/drivers/video/matrox/matroxfb_maven.c 2004-02-04 22:36:37.061746514 +0100
6555 @@ -1246,14 +1246,6 @@
6556 static unsigned short normal_i2c_range[] = { MAVEN_I2CID, MAVEN_I2CID, I2C_CLIENT_END };
6559 -static void maven_inc_use(struct i2c_client* clnt) {
6560 - MOD_INC_USE_COUNT;
6563 -static void maven_dec_use(struct i2c_client* clnt) {
6564 - MOD_DEC_USE_COUNT;
6567 static struct i2c_driver maven_driver;
6569 static int maven_detect_client(struct i2c_adapter* adapter, int address, unsigned short flags,
6570 @@ -1320,14 +1312,12 @@
6571 static int maven_driver_registered = 0;
6573 static struct i2c_driver maven_driver={
6575 - I2C_DRIVERID_MGATVO,
6577 - maven_attach_adapter,
6578 - maven_detach_client,
6583 + .id = I2C_DRIVERID_MGATVO,
6584 + .flags = I2C_DF_NOTIFY,
6585 + .attach_adapter = maven_attach_adapter,
6586 + .detach_client = maven_detach_client,
6587 + .command = maven_command,
6590 /* ************************** */
6591 diff -urN linux-2.4.24.org/include/linux/i2c-algo-8xx.h linux-2.4.24/include/linux/i2c-algo-8xx.h
6592 --- linux-2.4.24.org/include/linux/i2c-algo-8xx.h 1970-01-01 01:00:00.000000000 +0100
6593 +++ linux-2.4.24/include/linux/i2c-algo-8xx.h 2004-02-04 22:36:36.749811393 +0100
6595 +/* ------------------------------------------------------------------------- */
6596 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM */
6598 + This program is free software; you can redistribute it and/or modify
6599 + it under the terms of the GNU General Public License as published by
6600 + the Free Software Foundation; either version 2 of the License, or
6601 + (at your option) any later version.
6603 + This program is distributed in the hope that it will be useful,
6604 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6605 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6606 + GNU General Public License for more details.
6608 + You should have received a copy of the GNU General Public License
6609 + along with this program; if not, write to the Free Software
6610 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6611 +/* ------------------------------------------------------------------------- */
6615 +#ifndef _LINUX_I2C_ALGO_8XX_H
6616 +#define _LINUX_I2C_ALGO_8XX_H
6618 +#include "asm/commproc.h"
6620 +struct i2c_algo_8xx_data {
6623 + volatile i2c8xx_t *i2c;
6624 + volatile iic_t *iip;
6625 + volatile cpm8xx_t *cp;
6627 + int (*setisr) (int irq,
6628 + void (*func)(void *, void *),
6634 +int i2c_8xx_add_bus(struct i2c_adapter *);
6635 +int i2c_8xx_del_bus(struct i2c_adapter *);
6637 +#endif /* _LINUX_I2C_ALGO_8XX_H */
6638 diff -urN linux-2.4.24.org/include/linux/i2c-algo-bit.h linux-2.4.24/include/linux/i2c-algo-bit.h
6639 --- linux-2.4.24.org/include/linux/i2c-algo-bit.h 2004-02-04 22:30:56.871489160 +0100
6640 +++ linux-2.4.24/include/linux/i2c-algo-bit.h 2004-02-04 22:36:36.784804115 +0100
6642 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6643 Frodo Looijaard <frodol@dds.nl> */
6648 -#ifndef I2C_ALGO_BIT_H
6649 -#define I2C_ALGO_BIT_H 1
6651 -#include <linux/i2c.h>
6652 +#ifndef _LINUX_I2C_ALGO_BIT_H
6653 +#define _LINUX_I2C_ALGO_BIT_H
6655 /* --- Defines for bit-adapters --------------------------------------- */
6658 int (*getscl) (void *data);
6660 /* local settings */
6664 + int udelay; /* half-clock-cycle time in microsecs */
6665 + /* i.e. clock is (500 / udelay) KHz */
6666 + int mdelay; /* in millisecs, unused */
6667 + int timeout; /* in jiffies */
6670 #define I2C_BIT_ADAP_MAX 16
6672 int i2c_bit_add_bus(struct i2c_adapter *);
6673 int i2c_bit_del_bus(struct i2c_adapter *);
6675 -#endif /* I2C_ALGO_BIT_H */
6676 +#endif /* _LINUX_I2C_ALGO_BIT_H */
6677 diff -urN linux-2.4.24.org/include/linux/i2c-algo-ibm_ocp.h linux-2.4.24/include/linux/i2c-algo-ibm_ocp.h
6678 --- linux-2.4.24.org/include/linux/i2c-algo-ibm_ocp.h 1970-01-01 01:00:00.000000000 +0100
6679 +++ linux-2.4.24/include/linux/i2c-algo-ibm_ocp.h 2004-02-04 22:36:36.788803283 +0100
6681 +/* ------------------------------------------------------------------------- */
6682 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters */
6683 +/* ------------------------------------------------------------------------- */
6684 +/* Copyright (C) 1995-97 Simon G. Vogl
6685 + 1998-99 Hans Berglund
6687 + This program is free software; you can redistribute it and/or modify
6688 + it under the terms of the GNU General Public License as published by
6689 + the Free Software Foundation; either version 2 of the License, or
6690 + (at your option) any later version.
6692 + This program is distributed in the hope that it will be useful,
6693 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6694 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6695 + GNU General Public License for more details.
6697 + You should have received a copy of the GNU General Public License
6698 + along with this program; if not, write to the Free Software
6699 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6700 +/* ------------------------------------------------------------------------- */
6702 +/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6703 + Frodo Looijaard <frodol@dds.nl> */
6705 +/* Modifications by MontaVista Software, August 2000
6706 + Changes made to support the IIC peripheral on the IBM PPC 405 */
6708 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
6709 +#define _LINUX_I2C_ALGO_IBM_OCP_H
6711 +struct i2c_algo_iic_data {
6712 + struct iic_regs *data; /* private data for lolevel routines */
6713 + void (*setiic) (void *data, int ctl, int val);
6714 + int (*getiic) (void *data, int ctl);
6715 + int (*getown) (void *data);
6716 + int (*getclock) (void *data);
6717 + void (*waitforpin) (void *data);
6719 + /* local settings */
6726 +#define I2C_IIC_ADAP_MAX 16
6729 +int i2c_ocp_add_bus(struct i2c_adapter *);
6730 +int i2c_ocp_del_bus(struct i2c_adapter *);
6732 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
6733 diff -urN linux-2.4.24.org/include/linux/i2c-algo-pcf.h linux-2.4.24/include/linux/i2c-algo-pcf.h
6734 --- linux-2.4.24.org/include/linux/i2c-algo-pcf.h 2004-02-04 22:30:56.872488952 +0100
6735 +++ linux-2.4.24/include/linux/i2c-algo-pcf.h 2004-02-04 22:36:36.810798708 +0100
6737 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6738 Frodo Looijaard <frodol@dds.nl> */
6743 -#ifndef I2C_ALGO_PCF_H
6744 -#define I2C_ALGO_PCF_H 1
6745 +#ifndef _LINUX_I2C_ALGO_PCF_H
6746 +#define _LINUX_I2C_ALGO_PCF_H
6748 -/* --- Defines for pcf-adapters --------------------------------------- */
6749 -#include <linux/i2c.h>
6750 +#include <linux/i2c-pcf8584.h>
6752 struct i2c_algo_pcf_data {
6753 void *data; /* private data for lolevel routines */
6755 int i2c_pcf_add_bus(struct i2c_adapter *);
6756 int i2c_pcf_del_bus(struct i2c_adapter *);
6758 -#endif /* I2C_ALGO_PCF_H */
6759 +#endif /* _LINUX_I2C_ALGO_PCF_H */
6760 diff -urN linux-2.4.24.org/include/linux/i2c-dev.h linux-2.4.24/include/linux/i2c-dev.h
6761 --- linux-2.4.24.org/include/linux/i2c-dev.h 2004-02-04 22:30:49.848949493 +0100
6762 +++ linux-2.4.24/include/linux/i2c-dev.h 2004-02-04 22:36:36.831794341 +0100
6764 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6773 +#ifndef _LINUX_I2C_DEV_H
6774 +#define _LINUX_I2C_DEV_H
6776 #include <linux/types.h>
6777 -#include <linux/i2c.h>
6779 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
6780 +#define minor(d) MINOR(d)
6783 /* Some IOCTL commands are defined in <linux/i2c.h> */
6784 /* Note: 10-bit addresses are NOT supported! */
6786 __u32 nmsgs; /* number of i2c_msgs */
6791 -#include <sys/ioctl.h>
6793 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
6794 - int size, union i2c_smbus_data *data)
6796 - struct i2c_smbus_ioctl_data args;
6798 - args.read_write = read_write;
6799 - args.command = command;
6802 - return ioctl(file,I2C_SMBUS,&args);
6806 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
6808 - return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
6811 -static inline __s32 i2c_smbus_read_byte(int file)
6813 - union i2c_smbus_data data;
6814 - if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
6817 - return 0x0FF & data.byte;
6820 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
6822 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
6823 - I2C_SMBUS_BYTE,NULL);
6826 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
6828 - union i2c_smbus_data data;
6829 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6830 - I2C_SMBUS_BYTE_DATA,&data))
6833 - return 0x0FF & data.byte;
6836 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
6839 - union i2c_smbus_data data;
6840 - data.byte = value;
6841 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6842 - I2C_SMBUS_BYTE_DATA, &data);
6845 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
6847 - union i2c_smbus_data data;
6848 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6849 - I2C_SMBUS_WORD_DATA,&data))
6852 - return 0x0FFFF & data.word;
6855 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
6858 - union i2c_smbus_data data;
6859 - data.word = value;
6860 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6861 - I2C_SMBUS_WORD_DATA, &data);
6864 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
6866 - union i2c_smbus_data data;
6867 - data.word = value;
6868 - if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6869 - I2C_SMBUS_PROC_CALL,&data))
6872 - return 0x0FFFF & data.word;
6876 -/* Returns the number of read bytes */
6877 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
6880 - union i2c_smbus_data data;
6882 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
6883 - I2C_SMBUS_BLOCK_DATA,&data))
6886 - for (i = 1; i <= data.block[0]; i++)
6887 - values[i-1] = data.block[i];
6888 - return data.block[0];
6892 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
6893 - __u8 length, __u8 *values)
6895 - union i2c_smbus_data data;
6899 - for (i = 1; i <= length; i++)
6900 - data.block[i] = values[i-1];
6901 - data.block[0] = length;
6902 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6903 - I2C_SMBUS_BLOCK_DATA, &data);
6906 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
6907 - __u8 length, __u8 *values)
6909 - union i2c_smbus_data data;
6913 - for (i = 1; i <= length; i++)
6914 - data.block[i] = values[i-1];
6915 - data.block[0] = length;
6916 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
6917 - I2C_SMBUS_I2C_BLOCK_DATA, &data);
6920 -#endif /* ndef __KERNEL__ */
6923 +#endif /* _LINUX_I2C_DEV_H */
6924 diff -urN linux-2.4.24.org/include/linux/i2c-elektor.h linux-2.4.24/include/linux/i2c-elektor.h
6925 --- linux-2.4.24.org/include/linux/i2c-elektor.h 2004-02-04 22:30:56.931476685 +0100
6926 +++ linux-2.4.24/include/linux/i2c-elektor.h 2004-02-04 22:36:36.834793718 +0100
6928 -/* ------------------------------------------------------------------------- */
6929 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
6930 -/* ------------------------------------------------------------------------- */
6931 -/* Copyright (C) 1995-97 Simon G. Vogl
6932 - 1998-99 Hans Berglund
6934 - This program is free software; you can redistribute it and/or modify
6935 - it under the terms of the GNU General Public License as published by
6936 - the Free Software Foundation; either version 2 of the License, or
6937 - (at your option) any later version.
6939 - This program is distributed in the hope that it will be useful,
6940 - but WITHOUT ANY WARRANTY; without even the implied warranty of
6941 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6942 - GNU General Public License for more details.
6944 - You should have received a copy of the GNU General Public License
6945 - along with this program; if not, write to the Free Software
6946 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6947 -/* ------------------------------------------------------------------------- */
6949 -/* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and even
6950 - Frodo Looijaard <frodol@dds.nl> */
6954 -#ifndef I2C_PCF_ELEKTOR_H
6955 -#define I2C_PCF_ELEKTOR_H 1
6958 - * This struct contains the hw-dependent functions of PCF8584 adapters to
6959 - * manipulate the registers, and to init any hw-specific features.
6960 - * vdovikin: removed: this module in real supports only one device,
6961 - * due to missing arguments in some functions, called from the algo-pcf module.
6962 - * Sometimes it's need to be rewriten -
6963 - * but for now just remove this for simpler reading */
6966 -struct i2c_pcf_isa {
6974 -#endif /* PCF_ELEKTOR_H */
6975 diff -urN linux-2.4.24.org/include/linux/i2c.h linux-2.4.24/include/linux/i2c.h
6976 --- linux-2.4.24.org/include/linux/i2c.h 2004-02-04 22:30:49.830953235 +0100
6977 +++ linux-2.4.24/include/linux/i2c.h 2004-02-04 22:36:36.957768140 +0100
6979 /* With some changes from Kyƶsti MƤlkki <kmalkki@cc.hut.fi> and
6980 Frodo Looijaard <frodol@dds.nl> */
6987 +#ifndef _LINUX_I2C_H
6988 +#define _LINUX_I2C_H
6990 -#define I2C_DATE "20010830"
6991 -#define I2C_VERSION "2.6.1"
6992 +#define I2C_DATE "20040115"
6993 +#define I2C_VERSION "2.8.3"
6995 -#include <linux/i2c-id.h> /* id values of adapters et. al. */
6996 +#include <linux/module.h>
6997 #include <linux/types.h>
7005 -/* --- Includes and compatibility declarations ------------------------ */
7007 +#include <linux/errno.h>
7008 +#include <linux/sched.h>
7009 #include <asm/semaphore.h>
7010 -#include <linux/config.h>
7011 +#include <linux/i2c-id.h>
7013 +#include <linux/version.h>
7014 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
7015 +#define MODULE_LICENSE(x)
7018 /* --- General options ------------------------------------------------ */
7020 -#define I2C_ALGO_MAX 4 /* control memory consumption */
7021 -#define I2C_ADAP_MAX 16
7022 +#define I2C_ADAP_MAX 16 /* control memory consumption */
7023 #define I2C_DRIVER_MAX 16
7024 #define I2C_CLIENT_MAX 32
7025 -#define I2C_DUMMY_MAX 4
7028 struct i2c_algorithm;
7032 struct i2c_client_address_data;
7033 union i2c_smbus_data;
7037 * The master routines are the ones normally used to transmit data to devices
7038 * on a bus (or read from them). Apart from two basic transfer functions to
7040 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
7041 u8 command, u8 length,
7043 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
7044 + u8 command, u8 *values);
7045 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
7046 u8 command, u8 length,
7052 + struct module *owner;
7055 unsigned int flags; /* div., see below */
7056 @@ -148,18 +147,6 @@
7059 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
7061 - /* These two are mainly used for bookkeeping & dynamic unloading of
7062 - * kernel modules. inc_use tells the driver that a client is being
7063 - * used by another module & that it should increase its ref. counter.
7064 - * dec_use is the inverse operation.
7065 - * NB: Make sure you have no circular dependencies, or else you get a
7066 - * deadlock when trying to unload the modules.
7067 - * You should use the i2c_{inc,dec}_use_client functions instead of
7068 - * calling this function directly.
7070 - void (*inc_use)(struct i2c_client *client);
7071 - void (*dec_use)(struct i2c_client *client);
7076 * to name two of the most common.
7078 struct i2c_algorithm {
7079 + struct module *owner; /* future use --km */
7080 char name[32]; /* textual description */
7083 @@ -221,16 +209,13 @@
7084 * with the access algorithms necessary to access it.
7086 struct i2c_adapter {
7087 + struct module *owner;
7088 char name[32]; /* some useful name to identify the adapter */
7089 unsigned int id;/* == is algo->id | hwdep.struct->id, */
7090 /* for registered values see below */
7091 struct i2c_algorithm *algo;/* the algorithm to access the bus */
7094 - /* --- These may be NULL, but should increase the module use count */
7095 - void (*inc_use)(struct i2c_adapter *);
7096 - void (*dec_use)(struct i2c_adapter *);
7098 /* --- administration stuff. */
7099 int (*client_register)(struct i2c_client *);
7100 int (*client_unregister)(struct i2c_client *);
7101 @@ -241,11 +226,11 @@
7102 /* and can be set via the i2c_ioctl call */
7104 /* data fields that are valid for all devices */
7105 - struct semaphore lock;
7106 + struct semaphore bus;
7107 + struct semaphore list;
7108 unsigned int flags;/* flags specifying div. data */
7110 struct i2c_client *clients[I2C_CLIENT_MAX];
7116 #define I2C_CLIENT_ALLOW_USE 0x01 /* Client allows access */
7117 #define I2C_CLIENT_ALLOW_MULTIPLE_USE 0x02 /* Allow multiple access-locks */
7118 /* on an i2c_client */
7119 +#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
7120 +#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
7121 + /* Must equal I2C_M_TEN below */
7123 /* i2c_client_address_data is the struct for holding default client
7124 * addresses for a driver and for the parameters supplied on the
7125 @@ -302,12 +290,6 @@
7126 extern int i2c_attach_client(struct i2c_client *);
7127 extern int i2c_detach_client(struct i2c_client *);
7129 -/* Only call these if you grab a resource that makes unloading the
7130 - client and the adapter it is on completely impossible. Like when a
7131 - /proc directory is entered. */
7132 -extern void i2c_inc_use_client(struct i2c_client *);
7133 -extern void i2c_dec_use_client(struct i2c_client *);
7135 /* New function: This is to get an i2c_client-struct for controlling the
7136 client either by using i2c_control-function or having the
7137 client-module export functions that can be used with the i2c_client
7138 @@ -341,6 +323,15 @@
7139 struct i2c_client_address_data *address_data,
7140 i2c_client_found_addr_proc *found_proc);
7142 +static inline int i2c_client_command(struct i2c_client *client,
7143 + unsigned int cmd, void *arg)
7145 + if (client->driver && client->driver->command)
7146 + return client->driver->command(client, cmd, arg);
7151 /* An ioctl like call to set div. parameters of the adapter.
7153 extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
7155 /* Return 1 if adapter supports everything we need, 0 if not. */
7156 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
7158 -#endif /* __KERNEL__ */
7161 * I2C Message - used for pure i2c transaction, also from /dev interface
7163 @@ -370,15 +359,28 @@
7164 #define I2C_M_RD 0x01
7165 #define I2C_M_NOSTART 0x4000
7166 #define I2C_M_REV_DIR_ADDR 0x2000
7167 +#define I2C_M_IGNORE_NAK 0x1000
7168 +#define I2C_M_NO_RD_ACK 0x0800
7169 +#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
7170 +#define I2C_M_RECV_PEC 0x0200 /* receive one more than the returned
7171 + length byte for the PEC */
7172 __u16 len; /* msg length */
7173 __u8 *buf; /* pointer to msg data */
7178 /* To determine what functionality is present */
7180 #define I2C_FUNC_I2C 0x00000001
7181 #define I2C_FUNC_10BIT_ADDR 0x00000002
7182 -#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
7183 +#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
7184 +#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
7185 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */
7186 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */
7187 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */
7188 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
7189 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
7190 #define I2C_FUNC_SMBUS_QUICK 0x00010000
7191 #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
7192 #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
7193 @@ -389,8 +391,12 @@
7194 #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
7195 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
7196 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
7197 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* New I2C-like block */
7198 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
7199 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
7200 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
7201 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
7202 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
7203 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */
7204 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
7206 #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
7207 I2C_FUNC_SMBUS_WRITE_BYTE
7208 @@ -402,13 +408,28 @@
7209 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7210 #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
7211 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
7212 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
7213 + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
7214 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
7215 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
7216 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
7217 + I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
7219 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_DATA
7220 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC I2C_FUNC_SMBUS_WRITE_BYTE_DATA
7221 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA
7222 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC I2C_FUNC_SMBUS_WRITE_WORD_DATA
7223 +#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_BYTE_DATA
7224 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC I2C_FUNC_SMBUS_WORD_DATA
7226 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
7227 I2C_FUNC_SMBUS_BYTE | \
7228 I2C_FUNC_SMBUS_BYTE_DATA | \
7229 I2C_FUNC_SMBUS_WORD_DATA | \
7230 I2C_FUNC_SMBUS_PROC_CALL | \
7231 - I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7232 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
7233 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
7234 + I2C_FUNC_SMBUS_I2C_BLOCK
7237 * Data for SMBus Messages
7239 union i2c_smbus_data {
7242 - __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
7243 + __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
7244 /* one more for read length in block process call */
7245 + /* and one more for PEC */
7248 /* smbus_access read or write markers */
7249 @@ -435,6 +457,11 @@
7250 #define I2C_SMBUS_PROC_CALL 4
7251 #define I2C_SMBUS_BLOCK_DATA 5
7252 #define I2C_SMBUS_I2C_BLOCK_DATA 6
7253 +#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
7254 +#define I2C_SMBUS_BLOCK_DATA_PEC 8 /* SMBus 2.0 */
7255 +#define I2C_SMBUS_PROC_CALL_PEC 9 /* SMBus 2.0 */
7256 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC 10 /* SMBus 2.0 */
7257 +#define I2C_SMBUS_WORD_DATA_PEC 11 /* SMBus 2.0 */
7260 /* ----- commands for the ioctl like i2c_command call:
7263 #define I2C_FUNCS 0x0705 /* Get the adapter functionality */
7264 #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/
7265 +#define I2C_PEC 0x0708 /* != 0 for SMBus PEC */
7267 #define I2C_ACK_TEST 0x0710 /* See if a slave is at a specific address */
7269 @@ -475,16 +503,6 @@
7271 #define I2C_MAJOR 89 /* Device major number */
7276 -# define NULL ( (void *) 0 )
7280 -# include <asm/errno.h>
7283 /* These defines are used for probing i2c client addresses */
7284 /* Default fill of many variables */
7285 #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
7286 @@ -546,5 +564,11 @@
7287 #define i2c_is_isa_adapter(adapptr) \
7288 ((adapptr)->algo->id == I2C_ALGO_ISA)
7290 -#endif /* def __KERNEL__ */
7292 +/* Tiny delay function used by the i2c bus drivers */
7293 +static inline void i2c_delay(signed long timeout)
7295 + set_current_state(TASK_INTERRUPTIBLE);
7296 + schedule_timeout(timeout);
7299 +#endif /* _LINUX_I2C_H */
7300 diff -urN linux-2.4.24.org/include/linux/i2c-id.h linux-2.4.24/include/linux/i2c-id.h
7301 --- linux-2.4.24.org/include/linux/i2c-id.h 2004-02-04 22:30:48.969132451 +0100
7302 +++ linux-2.4.24/include/linux/i2c-id.h 2004-02-04 22:36:37.005758159 +0100
7304 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7305 /* ------------------------------------------------------------------------- */
7310 +#ifndef LINUX_I2C_ID_H
7311 +#define LINUX_I2C_ID_H
7316 * This file is part of the i2c-bus package and contains the identifier
7317 * values for drivers, adapters and other folk populating these serial
7319 #define I2C_DRIVERID_DRP3510 43 /* ADR decoder (Astra Radio) */
7320 #define I2C_DRIVERID_SP5055 44 /* Satellite tuner */
7321 #define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */
7322 +#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */
7323 +#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */
7324 #define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */
7325 -#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
7326 -#define I2C_DRIVERID_SAA7191 57 /* video decoder */
7327 -#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
7328 +#define I2C_DRIVERID_ZR36067 49 /* Zoran 36067 video encoder */
7329 +#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */
7330 +#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */
7331 +#define I2C_DRIVERID_STM41T00 52 /* real time clock */
7332 +#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
7333 +#define I2C_DRIVERID_ADV7170 54 /* video encoder */
7334 +#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */
7335 +#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
7336 +#define I2C_DRIVERID_SAA7191 57 /* video encoder */
7337 +#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
7338 +#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */
7339 +#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */
7340 +#define I2C_DRIVERID_OVCAMCHIP 61 /* OmniVision CMOS image sens. */
7341 +#define I2C_DRIVERID_TDA7313 62 /* TDA7313 audio processor */
7345 #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */
7346 #define I2C_DRIVERID_EXP1 0xF1
7349 #define I2C_DRIVERID_I2CDEV 900
7350 #define I2C_DRIVERID_I2CPROC 901
7351 +#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
7352 +#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */
7354 /* IDs -- Use DRIVERIDs 1000-1999 for sensors.
7355 These were originally in sensors.h in the lm_sensors package */
7356 @@ -131,6 +149,26 @@
7357 #define I2C_DRIVERID_ADM1024 1025
7358 #define I2C_DRIVERID_IT87 1026
7359 #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
7360 +#define I2C_DRIVERID_FSCPOS 1028
7361 +#define I2C_DRIVERID_FSCSCY 1029
7362 +#define I2C_DRIVERID_PCF8591 1030
7363 +#define I2C_DRIVERID_SMSC47M1 1031
7364 +#define I2C_DRIVERID_VT1211 1032
7365 +#define I2C_DRIVERID_LM92 1033
7366 +#define I2C_DRIVERID_VT8231 1034
7367 +#define I2C_DRIVERID_SMARTBATT 1035
7368 +#define I2C_DRIVERID_BMCSENSORS 1036
7369 +#define I2C_DRIVERID_FS451 1037
7370 +#define I2C_DRIVERID_W83627HF 1038
7371 +#define I2C_DRIVERID_LM85 1039
7372 +#define I2C_DRIVERID_LM83 1040
7373 +#define I2C_DRIVERID_SAA1064 1041
7374 +#define I2C_DRIVERID_LM90 1042
7375 +#define I2C_DRIVERID_ASB100 1043
7376 +#define I2C_DRIVERID_MAX6650 1044
7377 +#define I2C_DRIVERID_XEONTEMP 1045
7378 +#define I2C_DRIVERID_FSCHER 1046
7379 +#define I2C_DRIVERID_W83L785TS 1047
7382 * ---- Adapter types ----------------------------------------------------
7383 @@ -147,14 +185,21 @@
7384 #define I2C_ALGO_ISA 0x050000 /* lm_sensors ISA pseudo-adapter */
7385 #define I2C_ALGO_SAA7146 0x060000 /* SAA 7146 video decoder bus */
7386 #define I2C_ALGO_ACB 0x070000 /* ACCESS.bus algorithm */
7388 +#define I2C_ALGO_IIC 0x080000 /* ITE IIC bus */
7389 +#define I2C_ALGO_SAA7134 0x090000
7390 +#define I2C_ALGO_MPC824X 0x0a0000 /* Motorola 8240 / 8245 */
7391 +#define I2C_ALGO_IPMI 0x0b0000 /* IPMI dummy adapter */
7392 +#define I2C_ALGO_IPMB 0x0c0000 /* IPMB adapter */
7393 +#define I2C_ALGO_MPC107 0x0d0000
7394 #define I2C_ALGO_EC 0x100000 /* ACPI embedded controller */
7396 #define I2C_ALGO_MPC8XX 0x110000 /* MPC8xx PowerPC I2C algorithm */
7398 -#define I2C_ALGO_SIBYTE 0x120000 /* Broadcom SiByte SOCs */
7400 -#define I2C_ALGO_SGI 0x130000 /* SGI algorithm */
7401 +#define I2C_ALGO_OCP 0x120000 /* IBM or otherwise On-chip I2C algorithm */
7402 +#define I2C_ALGO_BITHS 0x130000 /* enhanced bit style adapters */
7403 +#define I2C_ALGO_OCP_IOP3XX 0x140000 /* XSCALE IOP3XX On-chip I2C alg */
7404 +#define I2C_ALGO_SIBYTE 0x150000 /* Broadcom SiByte SOCs */
7405 +#define I2C_ALGO_SGI 0x160000 /* SGI algorithm */
7406 +#define I2C_ALGO_USB 0x170000 /* USB algorithm */
7408 #define I2C_ALGO_EXP 0x800000 /* experimental */
7410 @@ -182,27 +227,45 @@
7411 #define I2C_HW_B_I810 0x0a /* Intel I810 */
7412 #define I2C_HW_B_VOO 0x0b /* 3dfx Voodoo 3 / Banshee */
7413 #define I2C_HW_B_PPORT 0x0c /* Primitive parallel port adapter */
7414 +#define I2C_HW_B_SAVG 0x0d /* Savage 4 */
7415 +#define I2C_HW_B_SCX200 0x0e /* Nat'l Semi SCx200 I2C */
7416 #define I2C_HW_B_RIVA 0x10 /* Riva based graphics cards */
7417 #define I2C_HW_B_IOC 0x11 /* IOC bit-wiggling */
7418 #define I2C_HW_B_TSUNA 0x12 /* DEC Tsunami chipset */
7419 +#define I2C_HW_B_FRODO 0x13 /* 2d3D, Inc. SA-1110 Development Board */
7420 +#define I2C_HW_B_OMAHA 0x14 /* Omaha I2C interface (ARM) */
7421 +#define I2C_HW_B_GUIDE 0x15 /* Guide bit-basher */
7422 +#define I2C_HW_B_IXP2000 0x16 /* GPIO on IXP2000 systems */
7423 +#define I2C_HW_B_IXP425 0x17 /* GPIO on IXP425 systems */
7424 +#define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */
7425 +#define I2C_HW_B_ZR36067 0x19 /* Zoran-36057/36067 based boards */
7426 +#define I2C_HW_B_PCILYNX 0x20 /* TI PCILynx I2C adapter */
7428 /* --- PCF 8584 based algorithms */
7429 #define I2C_HW_P_LP 0x00 /* Parallel port interface */
7430 #define I2C_HW_P_ISA 0x01 /* generic ISA Bus inteface card */
7431 #define I2C_HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */
7433 +/* --- USB based adapters */
7434 +#define I2C_HW_USB_USBVISION 0x00
7436 /* --- ACPI Embedded controller algorithms */
7437 #define I2C_HW_ACPI_EC 0x00
7439 +/* --- MPC824x PowerPC adapters */
7440 +#define I2C_HW_MPC824X 0x00 /* Motorola 8240 / 8245 */
7442 /* --- MPC8xx PowerPC adapters */
7443 #define I2C_HW_MPC8XX_EPON 0x00 /* Eponymous MPC8xx I2C adapter */
7445 -/* --- Broadcom SiByte adapters */
7446 -#define I2C_HW_SIBYTE 0x00
7447 +/* --- ITE based algorithms */
7448 +#define I2C_HW_I_IIC 0x00 /* controller on the ITE */
7450 +/* --- PowerPC on-chip adapters */
7451 +#define I2C_HW_OCP 0x00 /* IBM on-chip I2C adapter */
7453 -/* --- SGI adapters */
7454 -#define I2C_HW_SGI_VINO 0x00
7455 -#define I2C_HW_SGI_MACE 0x01
7456 +/* --- XSCALE on-chip adapters */
7457 +#define I2C_HW_IOP321 0x00
7459 /* --- SMBus only adapters */
7460 #define I2C_HW_SMBUS_PIIX4 0x00
7461 @@ -213,9 +276,27 @@
7462 #define I2C_HW_SMBUS_AMD756 0x05
7463 #define I2C_HW_SMBUS_SIS5595 0x06
7464 #define I2C_HW_SMBUS_ALI1535 0x07
7465 +#define I2C_HW_SMBUS_SIS630 0x08
7466 +#define I2C_HW_SMBUS_SIS645 0x09
7467 +#define I2C_HW_SMBUS_AMD8111 0x0a
7468 +#define I2C_HW_SMBUS_SCX200 0x0b
7469 +#define I2C_HW_SMBUS_NFORCE2 0x0c
7470 #define I2C_HW_SMBUS_W9968CF 0x0d
7471 +#define I2C_HW_SMBUS_OV511 0x0e /* OV511(+) USB 1.1 webcam ICs */
7472 +#define I2C_HW_SMBUS_OV518 0x0f /* OV518(+) USB 1.1 webcam ICs */
7473 +#define I2C_HW_SMBUS_OV519 0x10 /* OV519 USB 1.1 webcam IC */
7474 +#define I2C_HW_SMBUS_OVFX2 0x11 /* Cypress Ez-USB FX2 USB 2.0 */
7476 /* --- ISA pseudo-adapter */
7477 #define I2C_HW_ISA 0x00
7479 -#endif /* I2C_ID_H */
7480 +/* --- IPMI pseudo-adapter */
7481 +#define I2C_HW_IPMI 0x00
7483 +/* --- IPMB adapter */
7484 +#define I2C_HW_IPMB 0x00
7486 +/* --- MCP107 adapter */
7487 +#define I2C_HW_MPC107 0x00
7489 +#endif /* LINUX_I2C_ID_H */
7490 diff -urN linux-2.4.24.org/include/linux/i2c-pcf8584.h linux-2.4.24/include/linux/i2c-pcf8584.h
7491 --- linux-2.4.24.org/include/linux/i2c-pcf8584.h 1970-01-01 01:00:00.000000000 +0100
7492 +++ linux-2.4.24/include/linux/i2c-pcf8584.h 2004-02-04 22:36:37.010757119 +0100
7494 +/* -------------------------------------------------------------------- */
7495 +/* i2c-pcf8584.h: PCF 8584 global defines */
7496 +/* -------------------------------------------------------------------- */
7497 +/* Copyright (C) 1996 Simon G. Vogl
7498 + 1999 Hans Berglund
7500 + This program is free software; you can redistribute it and/or modify
7501 + it under the terms of the GNU General Public License as published by
7502 + the Free Software Foundation; either version 2 of the License, or
7503 + (at your option) any later version.
7505 + This program is distributed in the hope that it will be useful,
7506 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7507 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7508 + GNU General Public License for more details.
7510 + You should have received a copy of the GNU General Public License
7511 + along with this program; if not, write to the Free Software
7512 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7513 +/* -------------------------------------------------------------------- */
7515 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
7519 +#ifndef _LINUX_I2C_PCF8584_H
7520 +#define _LINUX_I2C_PCF8584_H
7522 +/* ----- Control register bits ---------------------------------------- */
7523 +#define I2C_PCF_PIN 0x80
7524 +#define I2C_PCF_ESO 0x40
7525 +#define I2C_PCF_ES1 0x20
7526 +#define I2C_PCF_ES2 0x10
7527 +#define I2C_PCF_ENI 0x08
7528 +#define I2C_PCF_STA 0x04
7529 +#define I2C_PCF_STO 0x02
7530 +#define I2C_PCF_ACK 0x01
7532 +#define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7533 +#define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
7534 +#define I2C_PCF_REPSTART ( I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7535 +#define I2C_PCF_IDLE (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ACK)
7537 +/* ----- Status register bits ----------------------------------------- */
7538 +/*#define I2C_PCF_PIN 0x80 as above*/
7540 +#define I2C_PCF_INI 0x40 /* 1 if not initialized */
7541 +#define I2C_PCF_STS 0x20
7542 +#define I2C_PCF_BER 0x10
7543 +#define I2C_PCF_AD0 0x08
7544 +#define I2C_PCF_LRB 0x08
7545 +#define I2C_PCF_AAS 0x04
7546 +#define I2C_PCF_LAB 0x02
7547 +#define I2C_PCF_BB 0x01
7549 +/* ----- Chip clock frequencies --------------------------------------- */
7550 +#define I2C_PCF_CLK3 0x00
7551 +#define I2C_PCF_CLK443 0x10
7552 +#define I2C_PCF_CLK6 0x14
7553 +#define I2C_PCF_CLK 0x18
7554 +#define I2C_PCF_CLK12 0x1c
7556 +/* ----- transmission frequencies ------------------------------------- */
7557 +#define I2C_PCF_TRNS90 0x00 /* 90 kHz */
7558 +#define I2C_PCF_TRNS45 0x01 /* 45 kHz */
7559 +#define I2C_PCF_TRNS11 0x02 /* 11 kHz */
7560 +#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */
7563 +/* ----- Access to internal registers according to ES1,ES2 ------------ */
7564 +/* they are mapped to the data port ( a0 = 0 ) */
7565 +/* available when ESO == 0 : */
7567 +#define I2C_PCF_OWNADR 0
7568 +#define I2C_PCF_INTREG I2C_PCF_ES2
7569 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7571 +#endif /* _LINUX_I2C_PCF8584_H */
7572 diff -urN linux-2.4.24.org/include/linux/i2c-proc.h linux-2.4.24/include/linux/i2c-proc.h
7573 --- linux-2.4.24.org/include/linux/i2c-proc.h 2004-02-04 22:30:58.421166905 +0100
7574 +++ linux-2.4.24/include/linux/i2c-proc.h 2004-02-04 22:36:37.038751297 +0100
7577 - sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7579 + i2c-proc.h - Part of the i2c package
7580 + was originally sensors.h - Part of lm_sensors, Linux kernel modules
7581 + for hardware monitoring
7582 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
7584 This program is free software; you can redistribute it and/or modify
7586 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7589 -#ifndef SENSORS_SENSORS_H
7590 -#define SENSORS_SENSORS_H
7591 +#ifndef _LINUX_I2C_PROC_H
7592 +#define _LINUX_I2C_PROC_H
7596 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
7597 -#include <linux/types.h>
7598 -#include <linux/fs.h>
7599 #include <linux/sysctl.h>
7601 /* The type of callback functions used in sensors_{proc,sysctl}_real */
7603 these functions must be updated! */
7604 extern int i2c_register_entry(struct i2c_client *client,
7606 - ctl_table * ctl_template,
7607 - struct module *controlling_mod);
7608 + ctl_table * ctl_template);
7610 extern void i2c_deregister_entry(int id);
7612 @@ -347,6 +342,31 @@
7616 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
7617 + enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
7618 + SENSORS_MODULE_PARM(force, \
7619 + "List of adapter,address pairs to boldly assume " \
7620 + "to be present"); \
7621 + SENSORS_MODULE_PARM_FORCE(chip1); \
7622 + SENSORS_MODULE_PARM_FORCE(chip2); \
7623 + SENSORS_MODULE_PARM_FORCE(chip3); \
7624 + SENSORS_MODULE_PARM_FORCE(chip4); \
7625 + SENSORS_MODULE_PARM_FORCE(chip5); \
7626 + SENSORS_MODULE_PARM_FORCE(chip6); \
7627 + SENSORS_MODULE_PARM_FORCE(chip7); \
7628 + SENSORS_MODULE_PARM_FORCE(chip8); \
7629 + static struct i2c_force_data forces[] = {{force,any_chip}, \
7630 + {force_ ## chip1,chip1}, \
7631 + {force_ ## chip2,chip2}, \
7632 + {force_ ## chip3,chip3}, \
7633 + {force_ ## chip4,chip4}, \
7634 + {force_ ## chip5,chip5}, \
7635 + {force_ ## chip6,chip6}, \
7636 + {force_ ## chip7,chip7}, \
7637 + {force_ ## chip8,chip8}, \
7641 typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
7642 int addr, unsigned short flags,
7646 /* This macro is used to scale user-input to sensible values in almost all
7648 -extern inline int SENSORS_LIMIT(long value, long low, long high)
7649 +static inline int SENSORS_LIMIT(long value, long low, long high)
7657 -#endif /* def __KERNEL__ */
7660 /* The maximum length of the prefix */
7661 #define SENSORS_PREFIX_MAX 20
7663 char name[SENSORS_PREFIX_MAX + 13];
7666 -#endif /* def SENSORS_SENSORS_H */
7667 +#endif /* def _LINUX_I2C_PROC_H */