1 --- linux-old/Documentation/Configure.help Mon Dec 13 16:57:33 2004
2 +++ linux/Documentation/Configure.help Mon Dec 13 19:26:23 2004
3 @@ -19347,6 +19347,16 @@
4 <file:Documentation/modules.txt>.
5 The module will be called i2c-velleman.o.
7 +Basic I2C on Parallel Port adapter
9 + This supports directly connecting I2C devices to the parallel port.
10 + See <file:Documentation/i2c/i2c-pport> for more information.
12 + This driver is also available as a module. If you want to compile
13 + it as a module, say M here and read
14 + <file:Documentation/modules.txt>.
15 + The module will be called i2c-pport.o.
17 I2C PCF 8584 interfaces
19 This allows you to use a range of I2C adapters called PCF adapters.
20 @@ -19368,6 +19378,15 @@
21 <file:Documentation/modules.txt>.
22 The module will be called i2c-elektor.o.
24 +PCF on the EPP Parallel Port
26 + This supports the PCF8584 connected to the parallel port.
28 + This driver is also available as a module. If you want to compile
29 + it as a module, say M here and read
30 + <file:Documentation/modules.txt>.
31 + The module will be called i2c-pcf-epp.o.
35 This supports the use the ITE8172 I2C interface found on some MIPS
36 @@ -19405,6 +19424,51 @@
37 Supports the SGI interfaces like the ones found on SGI Indy VINO
40 +Motorola 8xx I2C algorithm
42 + This is the algorithm that allows you to use Motorola 8xx I2C adapters.
44 + This driver is also available as a module. If you want to compile
45 + it as a module, say M here and read
46 + <file:Documentation/modules.txt>.
47 + The module will be called i2c-algo-8xx.o.
49 +Motorola 8xx I2C interface
51 + This supports the Motorola 8xx I2C device.
53 + This driver is also available as a module. If you want to compile
54 + it as a module, say M here and read
55 + <file:Documentation/modules.txt>.
56 + The module will be called i2c-rpx.o.
58 +IBM 405 I2C algorithm
59 +CONFIG_I2C_IBM_OCP_ALGO
60 + This is the algorithm that allows you to use IBM 405 I2C adapters.
62 + This driver is also available as a module. If you want to compile
63 + it as a module, say M here and read
64 + <file:Documentation/modules.txt>.
65 + The module will be called i2c-algo-ibm_ocp.o.
67 +IBM 405 I2C interface
68 +CONFIG_I2C_IBM_OCP_ADAP
69 + This supports the IBM 405 I2C device.
71 + This driver is also available as a module. If you want to compile
72 + it as a module, say M here and read
73 + <file:Documentation/modules.txt>.
74 + The module will be called i2c-adap-ibm_ocp.o.
76 +StrongARM SA-1110 interface
78 + This supports the StrongARM SA-1110 Development Board.
80 + This driver is also available as a module. If you want to compile
81 + it as a module, say M here and read
82 + <file:Documentation/modules.txt>.
83 + The module will be called i2c-frodo.o.
87 Say Y here to use i2c-* device files, usually found in the /dev
88 --- linux-old/Documentation/i2c/dev-interface Mon Dec 22 22:44:34 2003
89 +++ linux/Documentation/i2c/dev-interface Mon Dec 13 19:26:23 2004
91 Selects ten bit addresses if select not equals 0, selects normal 7 bit
92 addresses if select equals 0. Default 0.
94 +ioctl(file,I2C_PEC,long select)
95 + Selects SMBus PEC (packet error checking) generation and verification
96 + if select not equals 0, disables if select equals 0. Default 0.
97 + Used only for SMBus transactions.
99 ioctl(file,I2C_FUNCS,unsigned long *funcs)
100 Gets the adapter functionality and puts it in *funcs.
102 --- linux-old/Documentation/i2c/i2c-pport Thu Jan 1 00:00:00 1970
103 +++ linux/Documentation/i2c/i2c-pport Mon Dec 13 19:26:24 2004
105 +Parallel Port Adapters
106 +----------------------
107 +If you are installing parallel port adapters it means you are probably messing
108 +around with wires and IC's and the like. If you have purchased a card that
109 +provides an external i2c/smbus this will require combined algorithm and
110 +adapter code in a single module.
111 +If you are doing it yourself by using the parallel port there
112 +are basically 2 options.
114 +1) Using the parallel port and using the i2c-pport adapter module and the
115 +i2c-algo-bit algorithm module together to enable you to wire up your parallel
116 +port to act as an i2c/smbus. This provides a bus that will enable most
117 +sensors to work but doesn't support the entire i2c/smbus capability.
119 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c
120 +adapter chip. You will need to build a bit of a circuit to do this. This
121 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf
122 +algorithm module. This support almost all of the i2c/smbus capabilities.
125 +i2c-pport Documentation
126 +-----------------------
127 +This is a primitive parallel port driver for the i2c bus, which exploits
128 +features of modern bidirectional parallel ports.
130 +Bidirectional ports have particular bits connected in following way:
135 + read \-----| /------- Out pin
143 +It means when output is set to 1 we can read the port. Therefore
144 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It
145 +is not necessary to add any external - additional parts, we can
146 +read and write the same port simultaneously.
147 + I only use register base+2 so it is possible to use all
148 +8 data bits of parallel port for other applications (I have
149 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
150 + Port. The only disadvantage is we can only support 5V chips.
156 +SDA - connect to pin 14 (Auto Linefeed)
157 +SCL - connect to pin 16 (Initialize Printer)
158 +GND - connect to pin 18-25
159 ++5V - use external supply (I use 5V from 3.5" floppy connector)
172 --- linux-old/Documentation/i2c/i2c-protocol Mon Dec 22 22:44:34 2003
173 +++ linux/Documentation/i2c/i2c-protocol Mon Dec 13 19:26:24 2004
175 need to emit an Rd instead of a Wr, or vice versa, you set this
177 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
179 + Flags I2C_M_IGNORE_NAK
180 + Normally message is interrupted immediately if there is [NA] from the
181 + client. Setting this flag treats any [NA] as [A], and all of
183 + These messages may still fail to SCL lo->hi timeout.
185 + Flags I2C_M_NO_RD_ACK
186 + In a read message, master A/NA bit is skipped.
187 --- linux-old/Documentation/i2c/summary Tue Jan 20 15:10:28 2004
188 +++ linux/Documentation/i2c/summary Mon Dec 13 19:26:24 2004
190 i2c-algo-8xx: An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
191 i2c-algo-bit: A bit-banging algorithm
192 i2c-algo-pcf: A PCF 8584 style algorithm
193 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
194 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
199 i2c-elektor: Elektor ISA card (uses i2c-algo-pcf)
200 i2c-elv: ELV parallel port adapter (uses i2c-algo-bit)
201 -i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
202 +i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
203 i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
204 -i2c-ppc405: IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
205 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
206 i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit)
207 i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
208 i2c-velleman: Velleman K8000 parallel port adapter (uses i2c-algo-bit)
209 --- linux-old/Documentation/i2c/writing-clients Mon Dec 22 22:44:34 2003
210 +++ linux/Documentation/i2c/writing-clients Mon Dec 13 19:26:25 2004
212 routines, a client structure specific information like the actual I2C
215 - struct i2c_driver foo_driver
217 - /* name */ "Foo version 2.3 and later driver",
218 - /* id */ I2C_DRIVERID_FOO,
219 - /* flags */ I2C_DF_NOTIFY,
220 - /* attach_adapter */ &foo_attach_adapter,
221 - /* detach_client */ &foo_detach_client,
222 - /* command */ &foo_command, /* May be NULL */
223 - /* inc_use */ &foo_inc_use, /* May be NULL */
224 - /* dec_use */ &foo_dec_use /* May be NULL */
226 +static struct i2c_driver foo_driver = {
227 + .owner = THIS_MODULE,
228 + .name = "Foo version 2.3 driver",
229 + .id = I2C_DRIVERID_FOO, /* from i2c-id.h, optional */
230 + .flags = I2C_DF_NOTIFY,
231 + .attach_adapter = &foo_attach_adapter,
232 + .detach_client = &foo_detach_client,
233 + .command = &foo_command /* may be NULL */
236 The name can be chosen freely, and may be upto 40 characters long. Please
237 use something descriptive here.
239 -The id should be a unique ID. The range 0xf000 to 0xffff is reserved for
240 -local use, and you can use one of those until you start distributing the
241 -driver. Before you do that, contact the i2c authors to get your own ID(s).
242 +If used, the id should be a unique ID. The range 0xf000 to 0xffff is
243 +reserved for local use, and you can use one of those until you start
244 +distributing the driver, at which time you should contact the i2c authors
245 +to get your own ID(s). Note that most of the time you don't need an ID
246 +at all so you can just omit it.
248 Don't worry about the flags field; just put I2C_DF_NOTIFY into it. This
249 means that your driver will be notified when new adapters are found.
251 All other fields are for call-back functions which will be explained
258 -If your driver can also be compiled as a module, there are moments at
259 -which the module can not be removed from memory. For example, when you
260 -are doing a lengthy transaction, or when you create a /proc directory,
261 -and some process has entered that directory (this last case is the
262 -main reason why these call-backs were introduced).
264 -To increase or decrease the module usage count, you can use the
265 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
266 -which needs to get its usage count changed; that is why each driver
267 -module has to implement its own callback.
269 - void foo_inc_use (struct i2c_client *client)
276 - void foo_dec_use (struct i2c_client *client)
283 -Do not call these call-back functions directly; instead, use one of the
284 -following functions defined in i2c.h:
285 - void i2c_inc_use_client(struct i2c_client *);
286 - void i2c_dec_use_client(struct i2c_client *);
288 -You should *not* increase the module count just because a device is
289 -detected and a client created. This would make it impossible to remove
291 +There use to be two additional fields in this structure, inc_use et dec_use,
292 +for module usage count, but these fields were obsoleted and removed.
296 --- linux-old/drivers/i2c/i2c-adap-ibm_ocp.c Thu Jan 1 00:00:00 1970
297 +++ linux/drivers/i2c/i2c-adap-ibm_ocp.c Mon Dec 13 19:26:26 2004
300 + -------------------------------------------------------------------------
301 + i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
302 + -------------------------------------------------------------------------
304 + Ian DaSilva, MontaVista Software, Inc.
305 + idasilva@mvista.com or source@mvista.com
307 + Copyright 2000 MontaVista Software Inc.
309 + Changes made to support the IIC peripheral on the IBM PPC 405
312 + ----------------------------------------------------------------------------
313 + This file was highly leveraged from i2c-elektor.c, which was created
314 + by Simon G. Vogl and Hans Berglund:
317 + Copyright (C) 1995-97 Simon G. Vogl
318 + 1998-99 Hans Berglund
320 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
321 + Frodo Looijaard <frodol@dds.nl>
324 + This program is free software; you can redistribute it and/or modify
325 + it under the terms of the GNU General Public License as published by
326 + the Free Software Foundation; either version 2 of the License, or
327 + (at your option) any later version.
329 + This program is distributed in the hope that it will be useful,
330 + but WITHOUT ANY WARRANTY; without even the implied warranty of
331 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332 + GNU General Public License for more details.
334 + You should have received a copy of the GNU General Public License
335 + along with this program; if not, write to the Free Software
336 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
337 + ----------------------------------------------------------------------------
339 + History: 01/20/12 - Armin
341 + ported up to 2.4.16+
343 + Version 02/03/25 - Armin
344 + converted to ocp format
345 + removed commented out or #if 0 code
347 + TODO: convert to ocp_register
353 +#include <linux/kernel.h>
354 +#include <linux/ioport.h>
355 +#include <linux/module.h>
356 +#include <linux/delay.h>
357 +#include <linux/slab.h>
358 +#include <linux/init.h>
359 +#include <linux/i2c.h>
360 +#include <linux/i2c-algo-ibm_ocp.h>
361 +#include <asm/irq.h>
363 +#include <asm/ocp.h>
366 + * This next section is configurable, and it is used to set the number
367 + * of i2c controllers in the system. The default number of instances is 1,
368 + * however, this should be changed to reflect your system's configuration.
372 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
374 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
375 +extern iic_t *IIC_ADDR[];
376 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
378 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
379 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
381 +static int i2c_debug=0;
382 +static wait_queue_head_t iic_wait[IIC_NUMS];
383 +static int iic_pending;
384 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
387 +/* ----- global defines ----------------------------------------------- */
388 +#define DEB(x) if (i2c_debug>=1) x
389 +#define DEB2(x) if (i2c_debug>=2) x
390 +#define DEB3(x) if (i2c_debug>=3) x
391 +#define DEBE(x) x /* error messages */
393 +/* ----- local functions ---------------------------------------------- */
396 +// Description: Write a byte to IIC hardware
398 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
400 + // writeb resolves to a write to the specified memory location
401 + // plus a call to eieio. eieio ensures that all instructions
402 + // preceding it are completed before any further stores are
404 + // Delays at this level (to protect writes) are not needed here.
410 +// Description: Read a byte from IIC hardware
412 +static int iic_ibmocp_getbyte(void *data, int ctl)
422 +// Description: Return our slave address. This is the address
423 +// put on the I2C bus when another master on the bus wants to address us
426 +static int iic_ibmocp_getown(void *data)
428 + return(((struct iic_ibm *)(data))->iic_own);
433 +// Description: Return the clock rate
435 +static int iic_ibmocp_getclock(void *data)
437 + return(((struct iic_ibm *)(data))->iic_clock);
443 +// Description: Put this process to sleep. We will wake up when the
444 +// IIC controller interrupts.
446 +static void iic_ibmocp_waitforpin(void *data) {
449 + struct iic_ibm *priv_data = data;
452 + // If interrupts are enabled (which they are), then put the process to
453 + // sleep. This process will be awakened by two events -- either the
454 + // the IIC peripheral interrupts or the timeout expires.
456 + if (priv_data->iic_irq > 0) {
457 + spin_lock_irq(&irq_driver_lock);
458 + if (iic_pending == 0) {
459 + interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
462 + spin_unlock_irq(&irq_driver_lock);
465 + // If interrupts are not enabled then delay for a reasonable amount
466 + // of time and return. We expect that by time we return to the calling
467 + // function that the IIC has finished our requested transaction and
468 + // the status bit reflects this.
470 + // udelay is probably not the best choice for this since it is
471 + // the equivalent of a busy wait
475 + //printk("iic_ibmocp_waitforpin: exitting\n");
480 +// Description: The registered interrupt handler
482 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs)
485 + struct iic_regs *iic;
486 + struct iic_ibm *priv_data = dev_id;
487 + iic = (struct iic_regs *) priv_data->iic_base;
489 + DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
490 + // Read status register
491 + ret = readb((int) &(iic->sts));
492 + DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
493 + // Clear status register. See IBM PPC 405 reference manual for details
494 + writeb(0x0a, (int) &(iic->sts));
495 + wake_up_interruptible(&(iic_wait[priv_data->index]));
500 +// Description: This function is very hardware dependent. First, we lock
501 +// the region of memory where out registers exist. Next, we request our
502 +// interrupt line and register its associated handler. Our IIC peripheral
503 +// uses interrupt number 2, as specified by the 405 reference manual.
505 +static int iic_hw_resrc_init(int instance)
508 + DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
509 + iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
511 + DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
513 + if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
515 + if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
516 + 0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
517 + printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
518 + iic_ibmocp_adaps[instance]->iic_irq);
519 + iic_ibmocp_adaps[instance]->iic_irq = 0;
521 + DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
529 +// Description: Release irq and memory
531 +static void iic_ibmocp_release(void)
535 + for(i=0; i<IIC_NUMS; i++) {
536 + struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
537 + if (priv_data->iic_irq > 0) {
538 + disable_irq(priv_data->iic_irq);
539 + free_irq(priv_data->iic_irq, 0);
541 + kfree(iic_ibmocp_data[i]);
542 + kfree(iic_ibmocp_ops[i]);
548 +// Description: Called when the module is loaded. This function starts the
549 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
550 +// algorithm layer and into to the core layer)
552 +static int __init iic_ibmocp_init(void)
556 + printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
558 + for(i=0; i<IIC_NUMS; i++) {
559 + iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
560 + if(iic_ibmocp_data[i] == NULL) {
563 + memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
567 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
570 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
573 + iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
574 + iic_ibmocp_adaps[i]->iic_own = IIC_OWN;
575 + iic_ibmocp_adaps[i]->index = i;
577 + DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
578 + DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
579 + DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
580 + DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
583 + iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i];
584 + iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
585 + iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
586 + iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
587 + iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
588 + iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
589 + iic_ibmocp_data[i]->udelay = 80;
590 + iic_ibmocp_data[i]->mdelay = 80;
591 + iic_ibmocp_data[i]->timeout = HZ;
593 + iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
594 + if(iic_ibmocp_ops[i] == NULL) {
597 + memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
598 + strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
599 + iic_ibmocp_ops[i]->owner = THIS_MODULE;
600 + iic_ibmocp_ops[i]->id = I2C_HW_OCP;
601 + iic_ibmocp_ops[i]->algo = NULL;
602 + iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
605 + init_waitqueue_head(&(iic_wait[i]));
606 + if (iic_hw_resrc_init(i) == 0) {
607 + if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
612 + DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
618 +static void __exit iic_ibmocp_exit(void)
622 + for(i=0; i<IIC_NUMS; i++) {
623 + i2c_ocp_del_bus(iic_ibmocp_ops[i]);
625 + iic_ibmocp_release();
629 +// If modules is NOT defined when this file is compiled, then the MODULE_*
630 +// macros will resolve to nothing
632 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
633 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
634 +MODULE_LICENSE("GPL");
636 +MODULE_PARM(base, "i");
637 +MODULE_PARM(irq, "i");
638 +MODULE_PARM(clock, "i");
639 +MODULE_PARM(own, "i");
640 +MODULE_PARM(i2c_debug,"i");
643 +module_init(iic_ibmocp_init);
644 +module_exit(iic_ibmocp_exit);
645 --- linux-old/drivers/i2c/i2c-algo-8xx.c Thu Jan 1 00:00:00 1970
646 +++ linux/drivers/i2c/i2c-algo-8xx.c Mon Dec 13 19:26:27 2004
649 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
650 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
652 + This program is free software; you can redistribute it and/or modify
653 + it under the terms of the GNU General Public License as published by
654 + the Free Software Foundation; either version 2 of the License, or
655 + (at your option) any later version.
657 + This program is distributed in the hope that it will be useful,
658 + but WITHOUT ANY WARRANTY; without even the implied warranty of
659 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
660 + GNU General Public License for more details.
662 + You should have received a copy of the GNU General Public License
663 + along with this program; if not, write to the Free Software
664 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
666 + * moved into proper i2c interface; separated out platform specific
667 + * parts into i2c-rpx.c
668 + * Brad Parker (brad@heeltoe.com)
674 +/* $Id: i2c-algo-8xx.c,v 1.14 2003/07/25 07:56:42 khali Exp $ */
676 +#include <linux/kernel.h>
677 +#include <linux/module.h>
678 +#include <linux/delay.h>
679 +#include <linux/slab.h>
680 +#include <linux/init.h>
681 +#include <linux/errno.h>
682 +#include <linux/sched.h>
683 +#include <linux/i2c.h>
684 +#include <linux/i2c-algo-8xx.h>
685 +#include <asm/mpc8xx.h>
686 +#include <asm/commproc.h>
689 +#define CPM_MAX_READ 513
690 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
691 +static wait_queue_head_t iic_wait;
692 +static ushort r_tbase, r_rbase;
697 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
699 + volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
701 + printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
703 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
704 + /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
705 + /* Someone with a buggy CPU needs to confirm that */
706 + i2c->i2c_i2mod &= ~1;
708 + /* Clear interrupt.
710 + i2c->i2c_i2cer = 0xff;
712 + /* Get 'me going again.
714 + wake_up_interruptible(&iic_wait);
718 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
720 + volatile iic_t *iip = cpm->iip;
721 + volatile i2c8xx_t *i2c = cpm->i2c;
723 + bd_t *bd = (bd_t *)__res;
725 + if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
727 + /* Initialize the parameter ram.
728 + * We need to make sure many things are initialized to zero,
729 + * especially in the case of a microcode patch.
731 + iip->iic_rstate = 0;
733 + iip->iic_rbptr = 0;
735 + iip->iic_rxtmp = 0;
736 + iip->iic_tstate = 0;
738 + iip->iic_tbptr = 0;
740 + iip->iic_txtmp = 0;
742 + /* Set up the IIC parameters in the parameter ram.
744 + iip->iic_tbase = r_tbase = cpm->dp_addr;
745 + iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
747 + iip->iic_tfcr = SMC_EB;
748 + iip->iic_rfcr = SMC_EB;
750 + /* Set maximum receive size.
752 + iip->iic_mrblr = CPM_MAX_READ;
754 + /* Initialize Tx/Rx parameters.
756 + if (cpm->reloc == 0) {
757 + volatile cpm8xx_t *cp = cpm->cp;
760 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
761 + while (cp->cp_cpcr & CPM_CR_FLG);
763 + iip->iic_rbptr = iip->iic_rbase;
764 + iip->iic_tbptr = iip->iic_tbase;
765 + iip->iic_rstate = 0;
766 + iip->iic_tstate = 0;
769 + /* Select an arbitrary address. Just make sure it is unique.
771 + i2c->i2c_i2add = 0xfe;
773 + /* Make clock run at 60 KHz.
775 + brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
776 + i2c->i2c_i2brg = brg;
778 + i2c->i2c_i2mod = 0x00;
779 + i2c->i2c_i2com = 0x01; /* Master mode */
781 + /* Disable interrupts.
783 + i2c->i2c_i2cmr = 0;
784 + i2c->i2c_i2cer = 0xff;
786 + init_waitqueue_head(&iic_wait);
788 + /* Install interrupt handler.
791 + printk ("%s[%d] Install ISR for IRQ %d\n",
792 + __func__,__LINE__, CPMVEC_I2C);
794 + (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
799 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
801 + volatile i2c8xx_t *i2c = cpm->i2c;
805 + i2c->i2c_i2mod &= ~1;
806 + i2c->i2c_i2cmr = 0;
807 + i2c->i2c_i2cer = 0xff;
813 +cpm_reset_iic_params(volatile iic_t *iip)
815 + iip->iic_tbase = r_tbase;
816 + iip->iic_rbase = r_rbase;
818 + iip->iic_tfcr = SMC_EB;
819 + iip->iic_rfcr = SMC_EB;
821 + iip->iic_mrblr = CPM_MAX_READ;
823 + iip->iic_rstate = 0;
825 + iip->iic_rbptr = iip->iic_rbase;
827 + iip->iic_rxtmp = 0;
828 + iip->iic_tstate = 0;
830 + iip->iic_tbptr = iip->iic_tbase;
832 + iip->iic_txtmp = 0;
835 +#define BD_SC_NAK ((ushort)0x0004) /* NAK - did not respond */
836 +#define BD_SC_OV ((ushort)0x0002) /* OV - receive overrun */
837 +#define CPM_CR_CLOSE_RXBD ((ushort)0x0007)
839 +static void force_close(struct i2c_algo_8xx_data *cpm)
841 + volatile i2c8xx_t *i2c = cpm->i2c;
842 + if (cpm->reloc == 0) { /* micro code disabled */
843 + volatile cpm8xx_t *cp = cpm->cp;
845 + if (cpm_debug) printk("force_close()\n");
847 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
850 + while (cp->cp_cpcr & CPM_CR_FLG);
852 + i2c->i2c_i2cmr = 0x00; /* Disable all interrupts */
853 + i2c->i2c_i2cer = 0xff;
858 + * abyte = address byte, with r/w flag already set
861 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
863 + volatile iic_t *iip = cpm->iip;
864 + volatile i2c8xx_t *i2c = cpm->i2c;
865 + volatile cpm8xx_t *cp = cpm->cp;
866 + volatile cbd_t *tbdf, *rbdf;
868 + unsigned long flags, tmo;
870 + if (count >= CPM_MAX_READ)
873 + /* check for and use a microcode relocation patch */
875 + cpm_reset_iic_params(iip);
878 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
879 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
881 + /* To read, we need an empty buffer of the proper length.
882 + * All that is used is the first byte for address, the remainder
883 + * is just used for timing (and doesn't really have to exist).
886 + tb = (u_char *)(((uint)tb + 15) & ~15);
887 + tb[0] = abyte; /* Device address byte w/rw flag */
889 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
891 + if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
893 + tbdf->cbd_bufaddr = __pa(tb);
894 + tbdf->cbd_datlen = count + 1;
896 + BD_SC_READY | BD_SC_LAST |
897 + BD_SC_WRAP | BD_IIC_START;
899 + iip->iic_mrblr = count +1; /* prevent excessive read, +1
900 + is needed otherwise will the
901 + RXB interrupt come too early */
903 + /* flush will invalidate too. */
904 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
906 + rbdf->cbd_datlen = 0;
907 + rbdf->cbd_bufaddr = __pa(buf);
908 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
910 + /* Chip bug, set enable here */
911 + local_irq_save(flags);
912 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
913 + i2c->i2c_i2cer = 0xff;
914 + i2c->i2c_i2mod |= 1; /* Enable */
915 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
917 + /* Wait for IIC transfer */
918 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
919 + local_irq_restore(flags);
920 + } else { /* busy wait for small transfers, its faster */
921 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
922 + i2c->i2c_i2cer = 0xff;
923 + i2c->i2c_i2mod |= 1; /* Enable */
924 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
925 + tmo = jiffies + 1*HZ;
926 + while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
929 + if (signal_pending(current) || !tmo){
932 + printk("IIC read: timeout!\n");
935 +#ifdef I2C_CHIP_ERRATA
936 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
937 + Disabling I2C too early may cause too short stop condition */
939 + i2c->i2c_i2mod &= ~1;
942 + printk("tx sc %04x, rx sc %04x\n",
943 + tbdf->cbd_sc, rbdf->cbd_sc);
946 + if (tbdf->cbd_sc & BD_SC_READY) {
947 + printk("IIC read; complete but tbuf ready\n");
949 + printk("tx sc %04x, rx sc %04x\n",
950 + tbdf->cbd_sc, rbdf->cbd_sc);
953 + if (tbdf->cbd_sc & BD_SC_NAK) {
955 + printk("IIC read; no ack\n");
959 + if (rbdf->cbd_sc & BD_SC_EMPTY) {
960 + /* force_close(cpm); */
962 + printk("IIC read; complete but rbuf empty\n");
963 + printk("tx sc %04x, rx sc %04x\n",
964 + tbdf->cbd_sc, rbdf->cbd_sc);
969 + if (rbdf->cbd_sc & BD_SC_OV) {
971 + printk("IIC read; Overrun\n");
972 + return -EREMOTEIO;;
975 + if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
977 + if (rbdf->cbd_datlen < count) {
979 + printk("IIC read; short, wanted %d got %d\n",
980 + count, rbdf->cbd_datlen);
988 + * addr = address byte, with r/w flag already set
991 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
993 + volatile iic_t *iip = cpm->iip;
994 + volatile i2c8xx_t *i2c = cpm->i2c;
995 + volatile cpm8xx_t *cp = cpm->cp;
996 + volatile cbd_t *tbdf;
998 + unsigned long flags, tmo;
1000 + /* check for and use a microcode relocation patch */
1002 + cpm_reset_iic_params(iip);
1005 + tb = (u_char *)(((uint)tb + 15) & ~15);
1006 + *tb = abyte; /* Device address byte w/rw flag */
1008 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1009 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1011 + if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1013 + /* set up 2 descriptors */
1014 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1016 + tbdf[0].cbd_bufaddr = __pa(tb);
1017 + tbdf[0].cbd_datlen = 1;
1018 + tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1020 + tbdf[1].cbd_bufaddr = __pa(buf);
1021 + tbdf[1].cbd_datlen = count;
1022 + tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1025 + /* Chip bug, set enable here */
1026 + local_irq_save(flags);
1027 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1028 + i2c->i2c_i2cer = 0xff;
1029 + i2c->i2c_i2mod |= 1; /* Enable */
1030 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1032 + /* Wait for IIC transfer */
1033 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1034 + local_irq_restore(flags);
1035 + } else { /* busy wait for small transfers, its faster */
1036 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1037 + i2c->i2c_i2cer = 0xff;
1038 + i2c->i2c_i2mod |= 1; /* Enable */
1039 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1040 + tmo = jiffies + 1*HZ;
1041 + while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1044 + if (signal_pending(current) || !tmo){
1046 + if(cpm_debug && !tmo)
1047 + printk("IIC write: timeout!\n");
1051 +#if I2C_CHIP_ERRATA
1052 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1053 + Disabling I2C too early may cause too short stop condition */
1055 + i2c->i2c_i2mod &= ~1;
1058 + printk("tx0 sc %04x, tx1 sc %04x\n",
1059 + tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1062 + if (tbdf->cbd_sc & BD_SC_NAK) {
1064 + printk("IIC write; no ack\n");
1068 + if (tbdf->cbd_sc & BD_SC_READY) {
1070 + printk("IIC write; complete but tbuf ready\n");
1077 +/* See if an IIC address exists..
1078 + * addr = 7 bit address, unshifted
1081 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1083 + volatile iic_t *iip = cpm->iip;
1084 + volatile i2c8xx_t *i2c = cpm->i2c;
1085 + volatile cpm8xx_t *cp = cpm->cp;
1086 + volatile cbd_t *tbdf, *rbdf;
1088 + unsigned long flags, len, tmo;
1090 + if (cpm_debug > 1)
1091 + printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1093 + /* check for and use a microcode relocation patch */
1095 + cpm_reset_iic_params(iip);
1098 + if (cpm_debug && addr == 0) {
1099 + printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1100 + printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1103 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1104 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1107 + tb = (u_char *)(((uint)tb + 15) & ~15);
1109 + /* do a simple read */
1110 + tb[0] = (addr << 1) | 1; /* device address (+ read) */
1113 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1115 + tbdf->cbd_bufaddr = __pa(tb);
1116 + tbdf->cbd_datlen = len;
1118 + BD_SC_READY | BD_SC_LAST |
1119 + BD_SC_WRAP | BD_IIC_START;
1121 + rbdf->cbd_datlen = 0;
1122 + rbdf->cbd_bufaddr = __pa(tb+2);
1123 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1125 + local_irq_save(flags);
1126 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1127 + i2c->i2c_i2cer = 0xff;
1128 + i2c->i2c_i2mod |= 1; /* Enable */
1129 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1131 + if (cpm_debug > 1) printk("about to sleep\n");
1133 + /* wait for IIC transfer */
1134 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1135 + local_irq_restore(flags);
1137 +#ifdef I2C_CHIP_ERRATA
1138 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1139 + Disabling I2C too early may cause too short stop condition */
1141 + i2c->i2c_i2mod &= ~1;
1144 + if (signal_pending(current) || !tmo){
1146 + if(cpm_debug && !tmo)
1147 + printk("IIC tryaddress: timeout!\n");
1151 + if (cpm_debug > 1) printk("back from sleep\n");
1153 + if (tbdf->cbd_sc & BD_SC_NAK) {
1154 + if (cpm_debug > 1) printk("IIC try; no ack\n");
1158 + if (tbdf->cbd_sc & BD_SC_READY) {
1159 + printk("IIC try; complete but tbuf ready\n");
1165 +static int cpm_xfer(struct i2c_adapter *adap,
1166 + struct i2c_msg msgs[],
1169 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1170 + struct i2c_msg *pmsg;
1174 + for (i = 0; i < num; i++) {
1178 + printk("i2c-algo-8xx.o: "
1179 + "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1180 + i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1182 + addr = pmsg->addr << 1;
1183 + if (pmsg->flags & I2C_M_RD )
1185 + if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1188 + if (!(pmsg->flags & I2C_M_NOSTART)) {
1190 + if (pmsg->flags & I2C_M_RD ) {
1191 + /* read bytes into buffer*/
1192 + ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1194 + printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1195 + if (ret < pmsg->len ) {
1196 + return (ret<0)? ret : -EREMOTEIO;
1199 + /* write bytes from buffer */
1200 + ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1202 + printk("i2c-algo-8xx.o: wrote %d\n", ret);
1203 + if (ret < pmsg->len ) {
1204 + return (ret<0) ? ret : -EREMOTEIO;
1211 +static u32 cpm_func(struct i2c_adapter *adap)
1213 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1214 + I2C_FUNC_PROTOCOL_MANGLING;
1217 +/* -----exported algorithm data: ------------------------------------- */
1219 +static struct i2c_algorithm cpm_algo = {
1220 + .owner = THIS_MODULE,
1221 + .name = "MPC8xx CPM algorithm",
1222 + .id = I2C_ALGO_MPC8XX,
1223 + .master_xfer = cpm_xfer,
1224 + .functionality = cpm_func,
1228 + * registering functions to load algorithms at runtime
1230 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1233 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1236 + printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1239 + /* register new adapter to i2c module... */
1241 + adap->id |= cpm_algo.id;
1242 + adap->algo = &cpm_algo;
1244 + i2c_add_adapter(adap);
1245 + cpm_iic_init(cpm);
1249 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1251 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1253 + cpm_iic_shutdown(cpm);
1255 + return i2c_del_adapter(adap);
1258 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1259 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1261 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1262 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1263 +MODULE_LICENSE("GPL");
1264 --- linux-old/include/linux/i2c-algo-8xx.h Thu Jan 1 00:00:00 1970
1265 +++ linux/include/linux/i2c-algo-8xx.h Mon Dec 13 19:26:27 2004
1267 +/* ------------------------------------------------------------------------- */
1268 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM */
1270 + This program is free software; you can redistribute it and/or modify
1271 + it under the terms of the GNU General Public License as published by
1272 + the Free Software Foundation; either version 2 of the License, or
1273 + (at your option) any later version.
1275 + This program is distributed in the hope that it will be useful,
1276 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1277 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1278 + GNU General Public License for more details.
1280 + You should have received a copy of the GNU General Public License
1281 + along with this program; if not, write to the Free Software
1282 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1283 +/* ------------------------------------------------------------------------- */
1285 +/* $Id: i2c-algo-8xx.h,v 1.7 2003/08/01 20:56:38 khali Exp $ */
1287 +#ifndef _LINUX_I2C_ALGO_8XX_H
1288 +#define _LINUX_I2C_ALGO_8XX_H
1290 +#include "asm/commproc.h"
1292 +struct i2c_algo_8xx_data {
1295 + volatile i2c8xx_t *i2c;
1296 + volatile iic_t *iip;
1297 + volatile cpm8xx_t *cp;
1299 + int (*setisr) (int irq,
1300 + void (*func)(void *, void *),
1306 +int i2c_8xx_add_bus(struct i2c_adapter *);
1307 +int i2c_8xx_del_bus(struct i2c_adapter *);
1309 +#endif /* _LINUX_I2C_ALGO_8XX_H */
1310 --- linux-old/drivers/i2c/i2c-algo-bit.c Tue Jan 20 15:10:31 2004
1311 +++ linux/drivers/i2c/i2c-algo-bit.c Mon Dec 13 19:26:27 2004
1313 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1314 /* ------------------------------------------------------------------------- */
1316 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
1317 - Frodo Looijaard <frodol@dds.nl> */
1318 +/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
1319 + <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
1321 -/* $Id: i2c-algo-bit.c,v 1.30 2001/07/29 02:44:25 mds Exp $ */
1322 +/* $Id: i2c-algo-bit.c,v 1.50 2003/12/22 20:03:39 khali Exp $ */
1324 #include <linux/kernel.h>
1325 #include <linux/module.h>
1326 #include <linux/delay.h>
1327 #include <linux/slab.h>
1328 #include <linux/init.h>
1329 -#include <asm/uaccess.h>
1330 -#include <linux/ioport.h>
1331 #include <linux/errno.h>
1332 #include <linux/sched.h>
1334 #include <linux/i2c.h>
1335 #include <linux/i2c-algo-bit.h>
1338 /* ----- global defines ----------------------------------------------- */
1339 #define DEB(x) if (i2c_debug>=1) x;
1340 #define DEB2(x) if (i2c_debug>=2) x;
1342 #define DEBPROTO(x) if (i2c_debug>=9) { x; }
1343 /* debug the protocol by showing transferred bits */
1345 -/* debugging - slow down transfer to have a look at the data .. */
1346 -/* I use this with two leds&resistors, each one connected to sda,scl */
1347 -/* respectively. This makes sure that the algorithm works. Some chips */
1348 -/* might not like this, as they have an internal timeout of some mils */
1350 -#define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1351 - if (need_resched) schedule();
1355 /* ----- global variables --------------------------------------------- */
1361 /* module parameters:
1363 static int i2c_debug;
1364 static int bit_test; /* see if the line-setting functions work */
1365 -static int bit_scan; /* have a look at what's hanging 'round */
1367 /* --- setting states on the bus with the right timing: --------------- */
1372 udelay(adap->udelay);
1381 static inline int sclhi(struct i2c_algo_bit_data *adap)
1383 - int start=jiffies;
1388 - udelay(adap->udelay);
1390 /* Not all adapters have scl sense line... */
1391 - if (adap->getscl == NULL )
1392 + if (adap->getscl == NULL ) {
1393 + udelay(adap->udelay);
1397 - while (! getscl(adap) ) {
1399 + while (! getscl(adap) ) {
1400 /* the hw knows how to read the clock line,
1401 * so we wait until it actually gets high.
1402 * This is safer as some chips may hold it low
1403 * while they are processing data internally.
1406 if (time_after_eq(jiffies, start+adap->timeout)) {
1409 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1410 if (current->need_resched)
1416 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1420 + udelay(adap->udelay);
1425 /* scl, sda may not be high */
1426 DEBPROTO(printk(" Sr "));
1430 udelay(adap->udelay);
1434 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1436 /* assert: scl is low */
1437 - DEB2(printk(KERN_DEBUG " i2c_outb:%2.2X\n",c&0xff));
1438 for ( i=7 ; i>=0 ; i-- ) {
1439 sb = c & ( 1 << i );
1442 DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1443 if (sclhi(adap)<0) { /* timed out */
1444 sdahi(adap); /* we don't want to block the net */
1445 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1448 /* do arbitration here:
1449 @@ -196,11 +179,12 @@
1452 if (sclhi(adap)<0){ /* timeout */
1453 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1456 /* read ack: SDA should be pulled down by slave */
1457 ack=getsda(adap); /* ack: sda is pulled low ->success. */
1458 - DEB2(printk(KERN_DEBUG " i2c_outb: getsda() = 0x%2.2x\n", ~ack ));
1459 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1461 DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1462 DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1463 @@ -219,11 +203,10 @@
1464 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1466 /* assert: scl is low */
1467 - DEB2(printk(KERN_DEBUG "i2c_inb.\n"));
1471 if (sclhi(adap)<0) { /* timeout */
1472 + DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1479 /* assert: scl is low */
1480 + DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1482 DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1483 return (int) (indata & 0xff);
1485 @@ -242,71 +227,75 @@
1487 static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
1490 + if (adap->getscl==NULL)
1491 + printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, "
1492 + "SCL is not readable.\n");
1495 - if (adap->getscl==NULL) {
1496 - printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1500 - printk("i2c-algo-bit.o: Adapter: %s scl: %d sda: %d -- testing...\n",
1501 - name,getscl(adap),getsda(adap));
1502 + scl=(adap->getscl==NULL?1:getscl(adap));
1503 + printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
1504 if (!scl || !sda ) {
1505 - printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1506 + printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name);
1511 - printk("i2c-algo-bit.o:1 scl: %d sda: %d \n",getscl(adap),
1513 - if ( 0 != getsda(adap) ) {
1514 - printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1517 + scl=(adap->getscl==NULL?1:getscl(adap));
1518 + printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
1520 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n");
1523 - if ( 0 == getscl(adap) ) {
1524 - printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1527 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1528 + "while pulling SDA low!\n");
1533 - printk("i2c-algo-bit.o:2 scl: %d sda: %d \n",getscl(adap),
1535 - if ( 0 == getsda(adap) ) {
1536 - printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1539 + scl=(adap->getscl==NULL?1:getscl(adap));
1540 + printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
1542 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n");
1545 - if ( 0 == getscl(adap) ) {
1546 - printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1550 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1551 + "while pulling SDA high!\n");
1556 - printk("i2c-algo-bit.o:3 scl: %d sda: %d \n",getscl(adap),
1558 - if ( 0 != getscl(adap) ) {
1559 - printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1562 + scl=(adap->getscl==NULL?0:getscl(adap));
1563 + printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
1565 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n");
1568 - if ( 0 == getsda(adap) ) {
1569 - printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1572 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1573 + "while pulling SCL low!\n");
1578 - printk("i2c-algo-bit.o:4 scl: %d sda: %d \n",getscl(adap),
1580 - if ( 0 == getscl(adap) ) {
1581 - printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
1584 + scl=(adap->getscl==NULL?1:getscl(adap));
1585 + printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
1587 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n");
1590 - if ( 0 == getsda(adap) ) {
1591 - printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
1594 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1595 + "while pulling SCL high!\n");
1598 - printk("i2c-algo-bit.o: %s passed test.\n",name);
1599 + printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
1603 @@ -340,16 +329,21 @@
1605 udelay(adap->udelay);
1607 - DEB2(if (i) printk(KERN_DEBUG "i2c-algo-bit.o: needed %d retries for %d\n",
1610 + printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
1611 + i+1, addr & 1 ? "read" : "write", addr>>1,
1612 + ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
1617 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
1618 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1620 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1622 - const char *temp = buf;
1623 + const char *temp = msg->buf;
1624 + int count = msg->len;
1625 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1630 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
1631 i2c_adap->name, c&0xff));
1632 retval = i2c_outb(i2c_adap,c);
1634 + if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
1638 @@ -377,12 +371,18 @@
1642 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
1643 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1647 int rdcount=0; /* counts bytes read */
1648 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1649 + char *temp = msg->buf;
1650 + int count = msg->len;
1653 + /* Receive [Count] for I2C_SMBUS_BLOCK_DATA or I2C_SMBUS_BLOCK_PROC_CALL protocol */
1654 + if (msg->flags & I2C_M_RECV_LEN)
1658 inval = i2c_inb(i2c_adap);
1659 @@ -395,6 +395,20 @@
1665 + /* [Count] should be between 1 and 31 (I2C_SMBUS_BLOCK_MAX - 1). */
1666 + if (inval > 0 && inval < I2C_SMBUS_BLOCK_MAX) {
1667 + count = inval + 1; /* plus one for [Count] itself */
1669 + if (msg->flags & I2C_M_RECV_PEC)
1670 + count++; /* plus one for PEC */
1672 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: bad block count (%d).\n", inval);
1677 if ( count > 1 ) { /* send ack */
1679 DEBPROTO(printk(" Am "));
1680 @@ -419,31 +433,34 @@
1681 * try_address) and transmits the address in the necessary format to handle
1682 * reads, writes as well as 10bit-addresses.
1684 - * 0 everything went okay, the chip ack'ed
1685 + * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
1686 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
1687 * -ETIMEDOUT, for example if the lines are stuck...)
1689 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
1690 - struct i2c_msg *msg, int retries)
1691 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1693 unsigned short flags = msg->flags;
1694 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1695 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1701 + retries = nak_ok ? 0 : i2c_adap->retries;
1703 if ( (flags & I2C_M_TEN) ) {
1704 /* a ten bit address */
1705 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
1706 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
1707 /* try extended address code...*/
1708 ret = try_address(i2c_adap, addr, retries);
1710 + if ((ret != 1) && !nak_ok) {
1711 printk(KERN_ERR "died at extended address code.\n");
1714 /* the remaining 8 bit address */
1715 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
1717 + if ((ret != 1) && !nak_ok) {
1718 /* the chip did not ack / xmission error occurred */
1719 printk(KERN_ERR "died at 2nd address code.\n");
1722 /* okay, now switch into reading mode */
1724 ret = try_address(i2c_adap, addr, retries);
1726 + if ((ret!=1) && !nak_ok) {
1727 printk(KERN_ERR "died at extended address code.\n");
1730 @@ -465,10 +482,10 @@
1731 if (flags & I2C_M_REV_DIR_ADDR )
1733 ret = try_address(i2c_adap, addr, retries);
1735 + if ((ret!=1) && !nak_ok)
1743 @@ -479,16 +496,18 @@
1744 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1747 + unsigned short nak_ok;
1750 for (i=0;i<num;i++) {
1752 + nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
1753 if (!(pmsg->flags & I2C_M_NOSTART)) {
1757 - ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
1759 + ret = bit_doAddress(i2c_adap, pmsg);
1760 + if ((ret != 0) && !nak_ok) {
1761 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n",
1763 return (ret<0) ? ret : -EREMOTEIO;
1764 @@ -496,14 +515,14 @@
1766 if (pmsg->flags & I2C_M_RD ) {
1767 /* read bytes into buffer*/
1768 - ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
1769 + ret = readbytes(i2c_adap, pmsg);
1770 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
1771 if (ret < pmsg->len ) {
1772 return (ret<0)? ret : -EREMOTEIO;
1775 /* write bytes from buffer */
1776 - ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
1777 + ret = sendbytes(i2c_adap, pmsg);
1778 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
1779 if (ret < pmsg->len ) {
1780 return (ret<0) ? ret : -EREMOTEIO;
1781 @@ -514,30 +533,25 @@
1785 -static int algo_control(struct i2c_adapter *adapter,
1786 - unsigned int cmd, unsigned long arg)
1791 -static u32 bit_func(struct i2c_adapter *adap)
1792 +static u32 bit_func(struct i2c_adapter *i2c_adap)
1794 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1795 - I2C_FUNC_PROTOCOL_MANGLING;
1796 + I2C_FUNC_PROTOCOL_MANGLING |
1797 + I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
1798 + I2C_FUNC_SMBUS_READ_BLOCK_DATA |
1799 + I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC |
1800 + I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC;
1804 /* -----exported algorithm data: ------------------------------------- */
1806 static struct i2c_algorithm i2c_bit_algo = {
1807 - "Bit-shift algorithm",
1811 - NULL, /* slave_xmit */
1812 - NULL, /* slave_recv */
1813 - algo_control, /* ioctl */
1814 - bit_func, /* functionality */
1815 + .owner = THIS_MODULE,
1816 + .name = "Bit-shift algorithm",
1817 + .id = I2C_ALGO_BIT,
1818 + .master_xfer = bit_xfer,
1819 + .functionality = bit_func,
1825 int i2c_bit_add_bus(struct i2c_adapter *adap)
1828 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
1831 @@ -565,78 +578,26 @@
1832 adap->timeout = 100; /* default values, should */
1833 adap->retries = 3; /* be replaced by defines */
1838 - printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
1840 - for (i = 0x00; i < 0xff; i+=2) {
1841 - i2c_start(bit_adap);
1842 - ack = i2c_outb(adap,i);
1843 - i2c_stop(bit_adap);
1845 - printk("(%02x)",i>>1);
1853 - MOD_INC_USE_COUNT;
1855 i2c_add_adapter(adap);
1861 int i2c_bit_del_bus(struct i2c_adapter *adap)
1865 - if ((res = i2c_del_adapter(adap)) < 0)
1868 - DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
1871 - MOD_DEC_USE_COUNT;
1876 -int __init i2c_algo_bit_init (void)
1878 - printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
1880 + return i2c_del_adapter(adap);
1885 EXPORT_SYMBOL(i2c_bit_add_bus);
1886 EXPORT_SYMBOL(i2c_bit_del_bus);
1889 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1890 MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
1891 MODULE_LICENSE("GPL");
1893 MODULE_PARM(bit_test, "i");
1894 -MODULE_PARM(bit_scan, "i");
1895 MODULE_PARM(i2c_debug,"i");
1897 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
1898 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
1899 MODULE_PARM_DESC(i2c_debug,
1900 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
1902 -int init_module(void)
1904 - return i2c_algo_bit_init();
1907 -void cleanup_module(void)
1911 --- linux-old/include/linux/i2c-algo-bit.h Sat Feb 5 06:47:38 2000
1912 +++ linux/include/linux/i2c-algo-bit.h Mon Dec 13 19:26:28 2004
1914 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
1915 Frodo Looijaard <frodol@dds.nl> */
1917 -/* $Id: i2c-algo-bit.h,v 1.7 1999/12/21 23:45:58 frodo Exp $ */
1918 +/* $Id: i2c-algo-bit.h,v 1.11 2003/07/25 07:56:42 khali Exp $ */
1920 -#ifndef I2C_ALGO_BIT_H
1921 -#define I2C_ALGO_BIT_H 1
1923 -#include <linux/i2c.h>
1924 +#ifndef _LINUX_I2C_ALGO_BIT_H
1925 +#define _LINUX_I2C_ALGO_BIT_H
1927 /* --- Defines for bit-adapters --------------------------------------- */
1930 int (*getscl) (void *data);
1932 /* local settings */
1936 + int udelay; /* half-clock-cycle time in microsecs */
1937 + /* i.e. clock is (500 / udelay) KHz */
1938 + int mdelay; /* in millisecs, unused */
1939 + int timeout; /* in jiffies */
1942 #define I2C_BIT_ADAP_MAX 16
1944 int i2c_bit_add_bus(struct i2c_adapter *);
1945 int i2c_bit_del_bus(struct i2c_adapter *);
1947 -#endif /* I2C_ALGO_BIT_H */
1948 +#endif /* _LINUX_I2C_ALGO_BIT_H */
1949 --- linux-old/drivers/i2c/i2c-algo-ibm_ocp.c Thu Jan 1 00:00:00 1970
1950 +++ linux/drivers/i2c/i2c-algo-ibm_ocp.c Mon Dec 13 19:26:29 2004
1953 + -------------------------------------------------------------------------
1954 + i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters
1955 + -------------------------------------------------------------------------
1957 + Ian DaSilva, MontaVista Software, Inc.
1958 + idasilva@mvista.com or source@mvista.com
1960 + Copyright 2000 MontaVista Software Inc.
1962 + Changes made to support the IIC peripheral on the IBM PPC 405
1965 + ---------------------------------------------------------------------------
1966 + This file was highly leveraged from i2c-algo-pcf.c, which was created
1967 + by Simon G. Vogl and Hans Berglund:
1970 + Copyright (C) 1995-1997 Simon G. Vogl
1971 + 1998-2000 Hans Berglund
1973 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
1974 + Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
1975 + <mbailey@littlefeet-inc.com>
1978 + This program is free software; you can redistribute it and/or modify
1979 + it under the terms of the GNU General Public License as published by
1980 + the Free Software Foundation; either version 2 of the License, or
1981 + (at your option) any later version.
1983 + This program is distributed in the hope that it will be useful,
1984 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1985 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1986 + GNU General Public License for more details.
1988 + You should have received a copy of the GNU General Public License
1989 + along with this program; if not, write to the Free Software
1990 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1991 + ---------------------------------------------------------------------------
1993 + History: 01/20/12 - Armin
1994 + akuster@mvista.com
1995 + ported up to 2.4.16+
1997 + Version 02/03/25 - Armin
1998 + converted to ocp format
1999 + removed commented out or #if 0 code
2000 + added Gérard Basler's fix to iic_combined_transaction() such that it
2001 + returns the number of successfully completed transfers .
2005 +#include <linux/kernel.h>
2006 +#include <linux/module.h>
2007 +#include <linux/delay.h>
2008 +#include <linux/slab.h>
2009 +#include <linux/init.h>
2010 +#include <linux/errno.h>
2011 +#include <linux/sched.h>
2012 +#include <linux/i2c.h>
2013 +#include <linux/i2c-algo-ibm_ocp.h>
2014 +#include <asm/ocp.h>
2017 +/* ----- global defines ----------------------------------------------- */
2018 +#define DEB(x) if (i2c_debug>=1) x
2019 +#define DEB2(x) if (i2c_debug>=2) x
2020 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
2021 +#define DEBPROTO(x) if (i2c_debug>=9) x;
2022 + /* debug the protocol by showing transferred bits */
2023 +#define DEF_TIMEOUT 5
2026 +/* ----- global variables --------------------------------------------- */
2029 +/* module parameters:
2031 +static int i2c_debug=0;
2033 +/* --- setting states on the bus with the right timing: --------------- */
2035 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
2036 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
2038 +#define IICO_I2C_SDAHIGH 0x0780
2039 +#define IICO_I2C_SDALOW 0x0781
2040 +#define IICO_I2C_SCLHIGH 0x0782
2041 +#define IICO_I2C_SCLLOW 0x0783
2042 +#define IICO_I2C_LINEREAD 0x0784
2044 +#define IIC_SINGLE_XFER 0
2045 +#define IIC_COMBINED_XFER 1
2047 +#define IIC_ERR_LOST_ARB -2
2048 +#define IIC_ERR_INCOMPLETE_XFR -3
2049 +#define IIC_ERR_NACK -1
2051 +/* --- other auxiliary functions -------------------------------------- */
2055 +// Description: Puts this process to sleep for a period equal to timeout
2057 +static inline void iic_sleep(unsigned long timeout)
2059 + schedule_timeout( timeout * HZ);
2064 +// Description: This performs the IBM PPC 405 IIC initialization sequence
2065 +// as described in the PPC405GP data book.
2067 +static int iic_init (struct i2c_algo_iic_data *adap)
2069 + struct iic_regs *iic;
2070 + struct iic_ibm *adap_priv_data = adap->data;
2071 + unsigned short retval;
2072 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2074 + /* Clear master low master address */
2075 + iic_outb(adap,iic->lmadr, 0);
2077 + /* Clear high master address */
2078 + iic_outb(adap,iic->hmadr, 0);
2080 + /* Clear low slave address */
2081 + iic_outb(adap,iic->lsadr, 0);
2083 + /* Clear high slave address */
2084 + iic_outb(adap,iic->hsadr, 0);
2086 + /* Clear status */
2087 + iic_outb(adap,iic->sts, 0x0a);
2089 + /* Clear extended status */
2090 + iic_outb(adap,iic->extsts, 0x8f);
2092 + /* Set clock division */
2093 + iic_outb(adap,iic->clkdiv, 0x04);
2095 + retval = iic_inb(adap, iic->clkdiv);
2096 + DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2098 + /* Enable interrupts on Requested Master Transfer Complete */
2099 + iic_outb(adap,iic->intmsk, 0x01);
2101 + /* Clear transfer count */
2102 + iic_outb(adap,iic->xfrcnt, 0x0);
2104 + /* Clear extended control and status */
2105 + iic_outb(adap,iic->xtcntlss, 0xf0);
2107 + /* Set mode control (flush master data buf, enable hold SCL, exit */
2108 + /* unknown state. */
2109 + iic_outb(adap,iic->mdcntl, 0x47);
2111 + /* Clear control register */
2112 + iic_outb(adap,iic->cntl, 0x0);
2114 + DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2120 +// Description: After we issue a transaction on the IIC bus, this function
2121 +// is called. It puts this process to sleep until we get an interrupt from
2122 +// from the controller telling us that the transaction we requested in complete.
2124 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status)
2127 + int timeout = DEF_TIMEOUT;
2129 + struct iic_regs *iic;
2130 + struct iic_ibm *adap_priv_data = adap->data;
2131 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2134 + *status = iic_inb(adap, iic->sts);
2137 + while (timeout-- && (*status & 0x01)) {
2138 + adap->waitforpin(adap->data);
2139 + *status = iic_inb(adap, iic->sts);
2142 + if (timeout <= 0) {
2143 + /* Issue stop signal on the bus, and force an interrupt */
2144 + retval = iic_inb(adap, iic->cntl);
2145 + iic_outb(adap, iic->cntl, retval | 0x80);
2146 + /* Clear status register */
2147 + iic_outb(adap, iic->sts, 0x0a);
2148 + /* Exit unknown bus state */
2149 + retval = iic_inb(adap, iic->mdcntl);
2150 + iic_outb(adap, iic->mdcntl, (retval | 0x02));
2152 + // Check the status of the controller. Does it still see a
2153 + // pending transfer, even though we've tried to stop any
2154 + // ongoing transaction?
2155 + retval = iic_inb(adap, iic->sts);
2156 + retval = retval & 0x01;
2158 + // The iic controller is hosed. It is not responding to any
2159 + // of our commands. We have already tried to force it into
2160 + // a known state, but it has not worked. Our only choice now
2161 + // is a soft reset, which will clear all registers, and force
2162 + // us to re-initialize the controller.
2164 + iic_outb(adap, iic->xtcntlss, 0x01);
2167 + /* Is the pending transfer bit in the sts reg finally cleared? */
2168 + retval = iic_inb(adap, iic->sts);
2169 + retval = retval & 0x01;
2171 + printk(KERN_CRIT "The IIC Controller is hosed. A processor reset is required\n");
2173 + // For some reason, even though the interrupt bit in this
2174 + // register was set during iic_init, it didn't take. We
2175 + // need to set it again. Don't ask me why....this is just what
2176 + // I saw when testing timeouts.
2177 + iic_outb(adap, iic->intmsk, 0x01);
2186 +//------------------------------------
2187 +// Utility functions
2192 +// Description: Look at the status register to see if there was an error
2193 +// in the requested transaction. If there is, look at the extended status
2194 +// register and determine the exact cause.
2196 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2199 + struct iic_regs *iic;
2200 + struct iic_ibm *adap_priv_data = adap->data;
2201 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2204 + ret = iic_inb(adap, iic->sts);
2207 + ret = iic_inb(adap, iic->extsts);
2209 + // Lost arbitration
2210 + *error_code = IIC_ERR_LOST_ARB;
2213 + // Incomplete transfer
2214 + *error_code = IIC_ERR_INCOMPLETE_XFR;
2217 + // Master transfer aborted by a NACK during the transfer of the
2219 + *error_code = IIC_ERR_NACK;
2228 +// Description: This function is called by the upper layers to do the
2229 +// grunt work for a master send transaction
2231 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2232 + int count, int xfer_flag)
2234 + struct iic_regs *iic;
2235 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2236 + struct iic_ibm *adap_priv_data = adap->data;
2237 + int wrcount, status, timeout;
2238 + int loops, remainder, i, j;
2239 + int ret, error_code;
2240 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2243 + if( count == 0 ) return 0;
2245 + loops = count / 4;
2246 + remainder = count % 4;
2248 + if((loops > 1) && (remainder == 0)) {
2249 + for(i=0; i<(loops-1); i++) {
2251 + // Write four bytes to master data buffer
2253 + for(j=0; j<4; j++) {
2254 + iic_outb(adap, iic->mdbuf,
2258 + // Issue command to IICO device to begin transmission
2260 + iic_outb(adap, iic->cntl, 0x35);
2262 + // Wait for transmission to complete. When it does,
2263 + //loop to the top of the for statement and write the
2264 + // next four bytes.
2266 + timeout = wait_for_pin(adap, &status);
2271 + //printk(KERN_ERR "Error: write timeout\n");
2274 + ret = analyze_status(adap, &error_code);
2276 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2277 + // Return the number of bytes transferred
2278 + ret = iic_inb(adap, iic->xfrcnt);
2280 + return (wrcount-4+ret);
2282 + else return error_code;
2286 + else if((loops >= 1) && (remainder > 0)){
2287 + //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2288 + for(i=0; i<loops; i++) {
2290 + // Write four bytes to master data buffer
2292 + for(j=0; j<4; j++) {
2293 + iic_outb(adap, iic->mdbuf,
2297 + // Issue command to IICO device to begin transmission
2299 + iic_outb(adap, iic->cntl, 0x35);
2301 + // Wait for transmission to complete. When it does,
2302 + //loop to the top of the for statement and write the
2303 + // next four bytes.
2305 + timeout = wait_for_pin(adap, &status);
2310 + //printk(KERN_ERR "Error: write timeout\n");
2313 + ret = analyze_status(adap, &error_code);
2315 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2316 + // Return the number of bytes transferred
2317 + ret = iic_inb(adap, iic->xfrcnt);
2319 + return (wrcount-4+ret);
2321 + else return error_code;
2326 + //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2327 + if(remainder == 0) remainder = 4;
2328 + // remainder = remainder - 1;
2330 + // Write the remaining bytes (less than or equal to 4)
2332 + for(i=0; i<remainder; i++) {
2333 + iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2334 + //printk(KERN_DEBUG "iic_sendbytes: data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2336 + //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2338 + if(xfer_flag == IIC_COMBINED_XFER) {
2339 + iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2342 + iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2344 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2345 + timeout = wait_for_pin(adap, &status);
2350 + //printk(KERN_ERR "Error: write timeout\n");
2353 + ret = analyze_status(adap, &error_code);
2355 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2356 + // Return the number of bytes transferred
2357 + ret = iic_inb(adap, iic->xfrcnt);
2359 + return (wrcount-4+ret);
2361 + else return error_code;
2363 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2369 +// Description: Called by the upper layers to do the grunt work for
2370 +// a master read transaction.
2372 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2374 + struct iic_regs *iic;
2375 + int rdcount=0, i, status, timeout;
2376 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2377 + struct iic_ibm *adap_priv_data = adap->data;
2378 + int loops, remainder, j;
2379 + int ret, error_code;
2380 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2382 + if(count == 0) return 0;
2383 + loops = count / 4;
2384 + remainder = count % 4;
2386 + //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2388 + if((loops > 1) && (remainder == 0)) {
2389 + //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2390 + for(i=0; i<(loops-1); i++) {
2392 + // Issue command to begin master read (4 bytes maximum)
2394 + //printk(KERN_DEBUG "--->Issued read command\n");
2395 + iic_outb(adap, iic->cntl, 0x37);
2397 + // Wait for transmission to complete. When it does,
2398 + // loop to the top of the for statement and write the
2399 + // next four bytes.
2401 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2402 + timeout = wait_for_pin(adap, &status);
2405 + //printk(KERN_ERR "Error: read timed out\n");
2408 + //printk(KERN_DEBUG "--->Got interrupt\n");
2410 + ret = analyze_status(adap, &error_code);
2412 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2415 + return error_code;
2418 + for(j=0; j<4; j++) {
2419 + // Wait for data to shuffle to top of data buffer
2420 + // This value needs to optimized.
2422 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2424 + //printk(KERN_DEBUG "--->Read one byte\n");
2429 + else if((loops >= 1) && (remainder > 0)){
2430 + //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2431 + for(i=0; i<loops; i++) {
2433 + // Issue command to begin master read (4 bytes maximum)
2435 + //printk(KERN_DEBUG "--->Issued read command\n");
2436 + iic_outb(adap, iic->cntl, 0x37);
2438 + // Wait for transmission to complete. When it does,
2439 + // loop to the top of the for statement and write the
2440 + // next four bytes.
2442 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2443 + timeout = wait_for_pin(adap, &status);
2446 + //printk(KERN_ERR "Error: read timed out\n");
2449 + //printk(KERN_DEBUG "--->Got interrupt\n");
2451 + ret = analyze_status(adap, &error_code);
2453 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2456 + return error_code;
2459 + for(j=0; j<4; j++) {
2460 + // Wait for data to shuffle to top of data buffer
2461 + // This value needs to optimized.
2463 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2465 + //printk(KERN_DEBUG "--->Read one byte\n");
2470 + //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2471 + if(remainder == 0) remainder = 4;
2472 + DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2474 + if(xfer_type == IIC_COMBINED_XFER) {
2475 + iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2478 + iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2480 + DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2481 + timeout = wait_for_pin(adap, &status);
2482 + DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2485 + //printk(KERN_ERR "Error: read timed out\n");
2489 + ret = analyze_status(adap, &error_code);
2491 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2494 + return error_code;
2497 + //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2498 + for(i=0; i<remainder; i++) {
2499 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2500 + // printk(KERN_DEBUG "iic_readbytes: Character read = %x\n", buf[rdcount]);
2509 +// Description: This function implements combined transactions. Combined
2510 +// transactions consist of combinations of reading and writing blocks of data.
2511 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2514 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
2517 + struct i2c_msg *pmsg;
2520 + DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2521 + for(i=0; i < num; i++) {
2523 + if(pmsg->flags & I2C_M_RD) {
2525 + // Last read or write segment needs to be terminated with a stop
2527 + DEB2(printk(KERN_DEBUG "This one is a read\n"));
2530 + DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2532 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2534 + if (ret != pmsg->len) {
2535 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2536 + "only read %d bytes.\n",ret));
2540 + DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2543 + else if(!(pmsg->flags & I2C_M_RD)) {
2545 + // Last read or write segment needs to be terminated with a stop
2547 + DEB2(printk(KERN_DEBUG "This one is a write\n"));
2550 + DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2552 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2554 + if (ret != pmsg->len) {
2555 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2556 + "only wrote %d bytes.\n",ret));
2560 + DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2570 +// Description: Whenever we initiate a transaction, the first byte clocked
2571 +// onto the bus after the start condition is the address (7 bit) of the
2572 +// device we want to talk to. This function manipulates the address specified
2573 +// so that it makes sense to the hardware when written to the IIC peripheral.
2575 +// Note: 10 bit addresses are not supported in this driver, although they are
2576 +// supported by the hardware. This functionality needs to be implemented.
2578 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
2579 + struct i2c_msg *msg, int retries)
2581 + struct iic_regs *iic;
2582 + unsigned short flags = msg->flags;
2583 + unsigned char addr;
2584 + struct iic_ibm *adap_priv_data = adap->data;
2585 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2588 +// The following segment for 10 bit addresses needs to be ported
2590 +/* Ten bit addresses not supported right now
2591 + if ( (flags & I2C_M_TEN) ) {
2592 + // a ten bit address
2593 + addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2594 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2595 + // try extended address code...
2596 + ret = try_address(adap, addr, retries);
2598 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2599 + return -EREMOTEIO;
2601 + // the remaining 8 bit address
2602 + iic_outb(adap,msg->addr & 0x7f);
2603 + // Status check comes here
2605 + printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
2606 + return -EREMOTEIO;
2608 + if ( flags & I2C_M_RD ) {
2609 + i2c_repstart(adap);
2610 + // okay, now switch into reading mode
2612 + ret = try_address(adap, addr, retries);
2614 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2615 + return -EREMOTEIO;
2618 + } else ----------> // normal 7 bit address
2620 +Ten bit addresses not supported yet */
2622 + addr = ( msg->addr << 1 );
2623 + if (flags & I2C_M_RD )
2625 + if (flags & I2C_M_REV_DIR_ADDR )
2628 + // Write to the low slave address
2630 + iic_outb(adap, iic->lmadr, addr);
2632 + // Write zero to the high slave register since we are
2633 + // only using 7 bit addresses
2635 + iic_outb(adap, iic->hmadr, 0);
2642 +// Description: Prepares the controller for a transaction (clearing status
2643 +// registers, data buffers, etc), and then calls either iic_readbytes or
2644 +// iic_sendbytes to do the actual transaction.
2646 +static int iic_xfer(struct i2c_adapter *i2c_adap,
2647 + struct i2c_msg msgs[],
2650 + struct iic_regs *iic;
2651 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2652 + struct iic_ibm *adap_priv_data = adap->data;
2653 + struct i2c_msg *pmsg;
2656 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2661 + // Clear status register
2663 + DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
2664 + iic_outb(adap, iic->sts, 0x0a);
2667 + // Wait for any pending transfers to complete
2669 + DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
2670 + while((ret = iic_inb(adap, iic->sts)) == 0x01) {
2675 + // Flush master data buf
2677 + DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));
2678 + ret = iic_inb(adap, iic->mdcntl);
2679 + iic_outb(adap, iic->mdcntl, ret | 0x40);
2682 + // Load slave address
2684 + DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
2685 + ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
2688 + // Check to see if the bus is busy
2690 + ret = iic_inb(adap, iic->extsts);
2691 + // Mask off the irrelevent bits
2693 + // When the bus is free, the BCS bits in the EXTSTS register are 0b100
2694 + if(ret != 0x40) return IIC_ERR_LOST_ARB;
2697 + // Combined transaction (read and write)
2700 + DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
2701 + ret = iic_combined_transaction(i2c_adap, msgs, num);
2706 + else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
2708 + // Tell device to begin reading data from the master data
2710 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
2711 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2716 + else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
2718 + // Write data to master data buffers and tell our device
2719 + // to begin transmitting
2721 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
2722 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2730 +// Description: Implements device specific ioctls. Higher level ioctls can
2731 +// be found in i2c-core.c and are typical of any i2c controller (specifying
2732 +// slave address, timeouts, etc). These ioctls take advantage of any hardware
2733 +// features built into the controller for which this algorithm-adapter set
2734 +// was written. These ioctls allow you to take control of the data and clock
2735 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
2736 +// similar to a GPIO pin.
2738 +static int algo_control(struct i2c_adapter *adapter,
2739 + unsigned int cmd, unsigned long arg)
2741 + struct iic_regs *iic;
2742 + struct i2c_algo_iic_data *adap = adapter->algo_data;
2743 + struct iic_ibm *adap_priv_data = adap->data;
2746 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2748 + lines = iic_inb(adap, iic->directcntl);
2750 + if (cmd == IICO_I2C_SDAHIGH) {
2751 + lines = lines & 0x01;
2752 + if( lines ) lines = 0x04;
2754 + iic_outb(adap, iic->directcntl,(0x08|lines));
2756 + else if (cmd == IICO_I2C_SDALOW) {
2757 + lines = lines & 0x01;
2758 + if( lines ) lines = 0x04;
2760 + iic_outb(adap, iic->directcntl,(0x00|lines));
2762 + else if (cmd == IICO_I2C_SCLHIGH) {
2763 + lines = lines & 0x02;
2764 + if( lines ) lines = 0x08;
2766 + iic_outb(adap, iic->directcntl,(0x04|lines));
2768 + else if (cmd == IICO_I2C_SCLLOW) {
2769 + lines = lines & 0x02;
2770 + if( lines ) lines = 0x08;
2772 + iic_outb(adap, iic->directcntl,(0x00|lines));
2774 + else if (cmd == IICO_I2C_LINEREAD) {
2781 +static u32 iic_func(struct i2c_adapter *adap)
2783 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2784 + I2C_FUNC_PROTOCOL_MANGLING;
2788 +/* -----exported algorithm data: ------------------------------------- */
2790 +static struct i2c_algorithm iic_algo = {
2791 + .owner = THIS_MODULE,
2792 + .name = "IBM on-chip IIC algorithm",
2793 + .id = I2C_ALGO_OCP,
2794 + .master_xfer = iic_xfer,
2795 + .algo_control = algo_control,
2796 + .functionality = iic_func,
2800 + * registering functions to load algorithms at runtime
2805 +// Description: Register bus structure
2807 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
2809 + struct i2c_algo_iic_data *iic_adap = adap->algo_data;
2811 + DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
2814 + /* register new adapter to i2c module... */
2816 + adap->id |= iic_algo.id;
2817 + adap->algo = &iic_algo;
2819 + adap->timeout = 100; /* default values, should */
2820 + adap->retries = 3; /* be replaced by defines */
2822 + iic_init(iic_adap);
2823 + i2c_add_adapter(adap);
2831 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
2833 + return i2c_del_adapter(adap);
2837 +EXPORT_SYMBOL(i2c_ocp_add_bus);
2838 +EXPORT_SYMBOL(i2c_ocp_del_bus);
2841 +// The MODULE_* macros resolve to nothing if MODULES is not defined
2842 +// when this file is compiled.
2844 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
2845 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
2846 +MODULE_LICENSE("GPL");
2848 +MODULE_PARM(i2c_debug,"i");
2850 +MODULE_PARM_DESC(i2c_debug,
2851 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
2853 --- linux-old/include/linux/i2c-algo-ibm_ocp.h Thu Jan 1 00:00:00 1970
2854 +++ linux/include/linux/i2c-algo-ibm_ocp.h Mon Dec 13 19:26:29 2004
2856 +/* ------------------------------------------------------------------------- */
2857 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters */
2858 +/* ------------------------------------------------------------------------- */
2859 +/* Copyright (C) 1995-97 Simon G. Vogl
2860 + 1998-99 Hans Berglund
2862 + This program is free software; you can redistribute it and/or modify
2863 + it under the terms of the GNU General Public License as published by
2864 + the Free Software Foundation; either version 2 of the License, or
2865 + (at your option) any later version.
2867 + This program is distributed in the hope that it will be useful,
2868 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2869 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2870 + GNU General Public License for more details.
2872 + You should have received a copy of the GNU General Public License
2873 + along with this program; if not, write to the Free Software
2874 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
2875 +/* ------------------------------------------------------------------------- */
2877 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
2878 + Frodo Looijaard <frodol@dds.nl> */
2880 +/* Modifications by MontaVista Software, August 2000
2881 + Changes made to support the IIC peripheral on the IBM PPC 405 */
2883 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
2884 +#define _LINUX_I2C_ALGO_IBM_OCP_H
2886 +struct i2c_algo_iic_data {
2887 + struct iic_regs *data; /* private data for lolevel routines */
2888 + void (*setiic) (void *data, int ctl, int val);
2889 + int (*getiic) (void *data, int ctl);
2890 + int (*getown) (void *data);
2891 + int (*getclock) (void *data);
2892 + void (*waitforpin) (void *data);
2894 + /* local settings */
2901 +#define I2C_IIC_ADAP_MAX 16
2904 +int i2c_ocp_add_bus(struct i2c_adapter *);
2905 +int i2c_ocp_del_bus(struct i2c_adapter *);
2907 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
2908 --- linux-old/drivers/i2c/i2c-algo-pcf.c Tue Jan 20 15:10:31 2004
2909 +++ linux/drivers/i2c/i2c-algo-pcf.c Mon Dec 13 19:26:29 2004
2911 #include <linux/delay.h>
2912 #include <linux/slab.h>
2913 #include <linux/init.h>
2914 -#include <asm/uaccess.h>
2915 -#include <linux/ioport.h>
2916 #include <linux/errno.h>
2917 #include <linux/sched.h>
2919 #include <linux/i2c.h>
2920 #include <linux/i2c-algo-pcf.h>
2921 -#include "i2c-pcf8584.h"
2924 /* ----- global defines ----------------------------------------------- */
2925 #define DEB(x) if (i2c_debug>=1) x
2927 /* module parameters:
2929 static int i2c_debug=0;
2930 -static int pcf_scan=0; /* have a look at what's hanging 'round */
2932 /* --- setting states on the bus with the right timing: --------------- */
2935 set_pcf(adap, 1, I2C_PCF_PIN);
2936 /* check to see S1 now used as R/W ctrl -
2937 PCF8584 does that when ESO is zero */
2938 - /* PCF also resets PIN bit */
2939 - if ((temp = get_pcf(adap, 1)) != (0)) {
2940 + if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
2941 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
2942 return -ENXIO; /* definetly not PCF8584 */
2945 /* S1=0xA0, next byte in S2 */
2946 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
2947 /* check to see S2 now selected */
2948 - if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
2949 + if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
2950 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
2953 @@ -427,12 +422,6 @@
2957 -static int algo_control(struct i2c_adapter *adapter,
2958 - unsigned int cmd, unsigned long arg)
2963 static u32 pcf_func(struct i2c_adapter *adap)
2965 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2966 @@ -442,14 +431,11 @@
2967 /* -----exported algorithm data: ------------------------------------- */
2969 static struct i2c_algorithm pcf_algo = {
2970 - "PCF8584 algorithm",
2974 - NULL, /* slave_xmit */
2975 - NULL, /* slave_recv */
2976 - algo_control, /* ioctl */
2977 - pcf_func, /* functionality */
2978 + .owner = THIS_MODULE,
2979 + .name = "PCF8584 algorithm",
2980 + .id = I2C_ALGO_PCF,
2981 + .master_xfer = pcf_xfer,
2982 + .functionality = pcf_func,
2988 int i2c_pcf_add_bus(struct i2c_adapter *adap)
2992 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
2994 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
2995 @@ -475,81 +461,23 @@
3000 - MOD_INC_USE_COUNT;
3003 i2c_add_adapter(adap);
3007 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
3009 - for (i = 0x00; i < 0xff; i+=2) {
3010 - if (wait_for_bb(pcf_adap)) {
3011 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
3015 - i2c_outb(pcf_adap, i);
3016 - i2c_start(pcf_adap);
3017 - if ((wait_for_pin(pcf_adap, &status) >= 0) &&
3018 - ((status & I2C_PCF_LRB) == 0)) {
3019 - printk("(%02x)",i>>1);
3023 - i2c_stop(pcf_adap);
3024 - udelay(pcf_adap->udelay);
3032 int i2c_pcf_del_bus(struct i2c_adapter *adap)
3035 - if ((res = i2c_del_adapter(adap)) < 0)
3037 - DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
3040 - MOD_DEC_USE_COUNT;
3045 -int __init i2c_algo_pcf_init (void)
3047 - printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
3049 + return i2c_del_adapter(adap);
3053 EXPORT_SYMBOL(i2c_pcf_add_bus);
3054 EXPORT_SYMBOL(i2c_pcf_del_bus);
3057 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
3058 MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
3059 MODULE_LICENSE("GPL");
3061 -MODULE_PARM(pcf_scan, "i");
3062 MODULE_PARM(i2c_debug,"i");
3064 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
3065 MODULE_PARM_DESC(i2c_debug,
3066 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
3069 -int init_module(void)
3071 - return i2c_algo_pcf_init();
3074 -void cleanup_module(void)
3078 --- linux-old/include/linux/i2c-algo-pcf.h Thu Mar 23 02:26:01 2000
3079 +++ linux/include/linux/i2c-algo-pcf.h Mon Dec 13 19:26:30 2004
3081 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3082 Frodo Looijaard <frodol@dds.nl> */
3084 -/* $Id: i2c-algo-pcf.h,v 1.7 2000/02/27 23:02:45 frodo Exp $ */
3085 +/* $Id: i2c-algo-pcf.h,v 1.9 2003/07/25 07:56:42 khali Exp $ */
3087 -#ifndef I2C_ALGO_PCF_H
3088 -#define I2C_ALGO_PCF_H 1
3089 +#ifndef _LINUX_I2C_ALGO_PCF_H
3090 +#define _LINUX_I2C_ALGO_PCF_H
3092 -/* --- Defines for pcf-adapters --------------------------------------- */
3093 -#include <linux/i2c.h>
3094 +#include <linux/i2c-pcf8584.h>
3096 struct i2c_algo_pcf_data {
3097 void *data; /* private data for lolevel routines */
3099 int i2c_pcf_add_bus(struct i2c_adapter *);
3100 int i2c_pcf_del_bus(struct i2c_adapter *);
3102 -#endif /* I2C_ALGO_PCF_H */
3103 +#endif /* _LINUX_I2C_ALGO_PCF_H */
3104 --- linux-old/drivers/i2c/i2c-core.c Wed Jul 7 00:38:02 2004
3105 +++ linux/drivers/i2c/i2c-core.c Mon Dec 13 19:26:31 2004
3107 /* ------------------------------------------------------------------------- */
3109 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
3110 - All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
3111 + All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
3112 + SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */
3114 -/* $Id: i2c-core.c,v 1.64 2001/08/13 01:35:56 mds Exp $ */
3115 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
3117 #include <linux/module.h>
3118 #include <linux/kernel.h>
3119 #include <linux/errno.h>
3120 #include <linux/slab.h>
3121 #include <linux/proc_fs.h>
3122 -#include <linux/config.h>
3124 -#include <linux/i2c.h>
3126 -/* ----- compatibility stuff ----------------------------------------------- */
3128 #include <linux/init.h>
3130 +#include <linux/i2c.h>
3131 #include <asm/uaccess.h>
3133 /* ----- global defines ---------------------------------------------------- */
3135 -/* exclusive access to the bus */
3136 -#define I2C_LOCK(adap) down(&adap->lock)
3137 -#define I2C_UNLOCK(adap) up(&adap->lock)
3139 -#define ADAP_LOCK() down(&adap_lock)
3140 -#define ADAP_UNLOCK() up(&adap_lock)
3142 -#define DRV_LOCK() down(&driver_lock)
3143 -#define DRV_UNLOCK() up(&driver_lock)
3145 #define DEB(x) if (i2c_debug>=1) x;
3146 #define DEB2(x) if (i2c_debug>=2) x;
3148 /* ----- global variables -------------------------------------------------- */
3150 -/**** lock for writing to global variables: the adapter & driver list */
3151 -struct semaphore adap_lock;
3152 -struct semaphore driver_lock;
3154 -/**** adapter list */
3155 +DECLARE_MUTEX(core_lists);
3156 static struct i2c_adapter *adapters[I2C_ADAP_MAX];
3157 -static int adap_count;
3159 -/**** drivers list */
3160 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
3161 -static int driver_count;
3163 /**** debug level */
3164 -static int i2c_debug=1;
3165 +static int i2c_debug;
3167 /* ---------------------------------------------------
3168 * /proc entry declarations
3172 #ifdef CONFIG_PROC_FS
3174 -static int i2cproc_init(void);
3175 -static int i2cproc_cleanup(void);
3177 static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
3179 static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
3181 /* To implement the dynamic /proc/bus/i2c-? files, we need our own
3182 implementation of the read hook */
3183 static struct file_operations i2cproc_operations = {
3184 - read: i2cproc_bus_read,
3185 + .read = i2cproc_bus_read,
3188 -static int i2cproc_initialized = 0;
3190 -#else /* undef CONFIG_PROC_FS */
3192 -#define i2cproc_init() 0
3193 -#define i2cproc_cleanup() 0
3194 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3195 +static void i2cproc_remove(int bus);
3197 #endif /* CONFIG_PROC_FS */
3201 int i2c_add_adapter(struct i2c_adapter *adap)
3207 + down(&core_lists);
3208 for (i = 0; i < I2C_ADAP_MAX; i++)
3209 if (NULL == adapters[i])
3211 @@ -125,68 +94,39 @@
3216 +#ifdef CONFIG_PROC_FS
3217 + res = i2cproc_register(adap, i);
3220 +#endif /* def CONFIG_PROC_FS */
3226 /* init data types */
3227 - init_MUTEX(&adap->lock);
3229 -#ifdef CONFIG_PROC_FS
3231 - if (i2cproc_initialized) {
3233 - struct proc_dir_entry *proc_entry;
3235 - sprintf(name,"i2c-%d", i);
3237 - proc_entry = create_proc_entry(name,0,proc_bus);
3238 - if (! proc_entry) {
3239 - printk("i2c-core.o: Could not create /proc/bus/%s\n",
3245 - proc_entry->proc_fops = &i2cproc_operations;
3246 - proc_entry->owner = THIS_MODULE;
3247 - adap->inode = proc_entry->low_ino;
3250 -#endif /* def CONFIG_PROC_FS */
3251 + init_MUTEX(&adap->bus);
3252 + init_MUTEX(&adap->list);
3254 /* inform drivers of new adapters */
3256 for (j=0;j<I2C_DRIVER_MAX;j++)
3257 if (drivers[j]!=NULL &&
3258 (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
3259 /* We ignore the return code; if it fails, too bad */
3260 drivers[j]->attach_adapter(adap);
3263 DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3271 - adapters[i] = NULL;
3280 int i2c_del_adapter(struct i2c_adapter *adap)
3287 + down(&core_lists);
3288 for (i = 0; i < I2C_ADAP_MAX; i++)
3289 if (adap == adapters[i])
3291 @@ -202,20 +142,17 @@
3292 * *detach* it! Of course, each dummy driver should know about
3293 * this or hell will break loose...
3296 for (j = 0; j < I2C_DRIVER_MAX; j++)
3297 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3298 if ((res = drivers[j]->attach_adapter(adap))) {
3299 printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3300 "while detaching driver %s: driver not "
3301 "detached!",adap->name,drivers[j]->name);
3308 /* detach any active clients. This must be done first, because
3309 - * it can fail; in which case we give upp. */
3310 + * it can fail; in which case we give up. */
3311 for (j=0;j<I2C_CLIENT_MAX;j++) {
3312 struct i2c_client *client = adap->clients[j];
3314 @@ -231,26 +168,15 @@
3319 #ifdef CONFIG_PROC_FS
3320 - if (i2cproc_initialized) {
3322 - sprintf(name,"i2c-%d", i);
3323 - remove_proc_entry(name,proc_bus);
3325 + i2cproc_remove(i);
3326 #endif /* def CONFIG_PROC_FS */
3332 DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
3345 int i2c_add_driver(struct i2c_driver *driver)
3350 + down(&core_lists);
3351 for (i = 0; i < I2C_DRIVER_MAX; i++)
3352 if (NULL == drivers[i])
3354 @@ -273,19 +200,12 @@
3355 " i2c-core.o: register_driver(%s) "
3356 "- enlarge I2C_DRIVER_MAX.\n",
3363 drivers[i] = driver;
3366 - DRV_UNLOCK(); /* driver was successfully added */
3368 DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
3372 /* now look for instances of driver on our adapters
3374 if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
3375 @@ -294,15 +214,15 @@
3377 driver->attach_adapter(adapters[i]);
3384 int i2c_del_driver(struct i2c_driver *driver)
3387 + int i,j,k,res = 0;
3390 + down(&core_lists);
3391 for (i = 0; i < I2C_DRIVER_MAX; i++)
3392 if (driver == drivers[i])
3395 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
3402 /* Have a look at each adapter, if clients of this driver are still
3404 * invalid operation might (will!) result, when using stale client
3407 - ADAP_LOCK(); /* should be moved inside the if statement... */
3408 for (k=0;k<I2C_ADAP_MAX;k++) {
3409 struct i2c_adapter *adap = adapters[k];
3410 if (adap == NULL) /* skip empty entries. */
3412 "not be detached properly; driver "
3413 "not unloaded!",driver->name,
3420 for (j=0;j<I2C_CLIENT_MAX;j++) {
3421 @@ -359,37 +277,47 @@
3422 "unregistering driver "
3423 "`%s', the client at "
3425 - "adapter `%s' could not"
3426 - "be detached; driver"
3427 + "adapter `%s' could not "
3428 + "be detached; driver "
3446 DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
3454 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3455 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
3458 for (i = 0; i < I2C_CLIENT_MAX ; i++)
3459 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
3465 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
3469 + down(&adapter->list);
3470 + rval = __i2c_check_addr(adapter, addr);
3471 + up(&adapter->list);
3476 int i2c_attach_client(struct i2c_client *client)
3478 struct i2c_adapter *adapter = client->adapter;
3480 if (i2c_check_addr(client->adapter,client->addr))
3483 + down(&adapter->list);
3484 for (i = 0; i < I2C_CLIENT_MAX; i++)
3485 if (NULL == adapter->clients[i])
3487 @@ -405,11 +334,11 @@
3489 " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
3491 + up(&adapter->list);
3495 adapter->clients[i] = client;
3496 - adapter->client_count++;
3497 + up(&adapter->list);
3499 if (adapter->client_register)
3500 if (adapter->client_register(client))
3501 @@ -431,16 +360,6 @@
3502 struct i2c_adapter *adapter = client->adapter;
3505 - for (i = 0; i < I2C_CLIENT_MAX; i++)
3506 - if (client == adapter->clients[i])
3508 - if (I2C_CLIENT_MAX == i) {
3509 - printk(KERN_WARNING " i2c-core.o: unregister_client "
3510 - "[%s] not found\n",
3515 if( (client->flags & I2C_CLIENT_ALLOW_USE) &&
3516 (client->usage_count>0))
3518 @@ -452,33 +371,41 @@
3522 + down(&adapter->list);
3523 + for (i = 0; i < I2C_CLIENT_MAX; i++)
3524 + if (client == adapter->clients[i])
3526 + if (I2C_CLIENT_MAX == i) {
3527 + printk(KERN_WARNING " i2c-core.o: unregister_client "
3528 + "[%s] not found\n",
3530 + up(&adapter->list);
3533 adapter->clients[i] = NULL;
3534 - adapter->client_count--;
3535 + up(&adapter->list);
3537 DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
3541 -void i2c_inc_use_client(struct i2c_client *client)
3542 +static void i2c_inc_use_client(struct i2c_client *client)
3545 - if (client->driver->inc_use != NULL)
3546 - client->driver->inc_use(client);
3548 - if (client->adapter->inc_use != NULL)
3549 - client->adapter->inc_use(client->adapter);
3550 + if(client->driver->owner)
3551 + __MOD_INC_USE_COUNT(client->driver->owner);
3552 + if(client->adapter->owner)
3553 + __MOD_INC_USE_COUNT(client->adapter->owner);
3556 -void i2c_dec_use_client(struct i2c_client *client)
3557 +static void i2c_dec_use_client(struct i2c_client *client)
3560 - if (client->driver->dec_use != NULL)
3561 - client->driver->dec_use(client);
3563 - if (client->adapter->dec_use != NULL)
3564 - client->adapter->dec_use(client->adapter);
3565 + if(client->driver->owner)
3566 + __MOD_DEC_USE_COUNT(client->driver->owner);
3567 + if(client->adapter->owner)
3568 + __MOD_DEC_USE_COUNT(client->adapter->owner);
3571 +#if 0 /* just forget about this for now --km */
3572 struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
3573 struct i2c_client *prev)
3575 @@ -545,18 +472,17 @@
3581 int i2c_use_client(struct i2c_client *client)
3583 - if(client->flags & I2C_CLIENT_ALLOW_USE) {
3584 - if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
3585 + if (client->flags & I2C_CLIENT_ALLOW_USE) {
3586 + if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
3587 + client->usage_count++;
3588 + else if (client->usage_count > 0)
3591 client->usage_count++;
3593 - if(client->usage_count > 0)
3596 - client->usage_count++;
3600 i2c_inc_use_client(client);
3601 @@ -589,12 +515,13 @@
3602 #ifdef CONFIG_PROC_FS
3604 /* This function generates the output for /proc/bus/i2c */
3605 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
3606 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
3611 /* Note that it is safe to write a `little' beyond len. Yes, really. */
3612 + down(&core_lists);
3613 for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
3615 nr += sprintf(buf+nr, "i2c-%d\t", i);
3618 adapters[i]->algo->name);
3624 @@ -621,98 +549,125 @@
3625 struct inode * inode = file->f_dentry->d_inode;
3627 struct i2c_client *client;
3628 + struct i2c_adapter *adap;
3629 int i,j,k,order_nr,len=0;
3631 int order[I2C_CLIENT_MAX];
3632 +#define OUTPUT_LENGTH_PER_LINE 70
3636 len_total = file->f_pos + count;
3637 - /* Too bad if this gets longer (unlikely) */
3638 - if (len_total > 4000)
3640 - for (i = 0; i < I2C_ADAP_MAX; i++)
3641 - if (adapters[i]->inode == inode->i_ino) {
3642 - /* We need a bit of slack in the kernel buffer; this makes the
3644 - if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
3646 - /* Order will hold the indexes of the clients
3647 - sorted by address */
3649 - for (j = 0; j < I2C_CLIENT_MAX; j++) {
3650 - if ((client = adapters[i]->clients[j]) &&
3651 - (client->driver->id != I2C_DRIVERID_I2CDEV)) {
3654 - adapters[i]->clients[order[k-1]]->
3655 - addr > client->addr;
3657 - order[k] = order[k-1];
3664 - for (j = 0; (j < order_nr) && (len < len_total); j++) {
3665 - client = adapters[i]->clients[order[j]];
3666 - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3669 - client->driver->name);
3671 - len = len - file->f_pos;
3676 - if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3680 - file->f_pos += len;
3685 + if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
3686 + /* adjust to maximum file size */
3687 + len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
3689 + down(&core_lists);
3690 + /* adap = file->private_data; ?? --km */
3691 + for (i = 0; i < I2C_ADAP_MAX; i++) {
3692 + adap = adapters[i];
3693 + if (adap && (adap->inode == inode->i_ino))
3696 + if ( I2C_ADAP_MAX == i ) {
3701 + /* We need a bit of slack in the kernel buffer; this makes the
3703 + if (! (kbuf = kmalloc(len_total +
3704 + OUTPUT_LENGTH_PER_LINE,
3708 + /* Order will hold the indexes of the clients
3709 + sorted by address */
3711 + down(&adap->list);
3712 + for (j = 0; j < I2C_CLIENT_MAX; j++) {
3713 + if ((client = adap->clients[j]) &&
3714 + (client->driver->id != I2C_DRIVERID_I2CDEV)) {
3717 + adap->clients[order[k-1]]->
3718 + addr > client->addr;
3720 + order[k] = order[k-1];
3727 + for (j = 0; (j < order_nr) && (len < len_total); j++) {
3728 + client = adap->clients[order[j]];
3729 + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
3732 + client->driver->name);
3737 + len = len - file->f_pos;
3742 + if (copy_to_user (buf,kbuf+file->f_pos, len)) {
3746 + file->f_pos += len;
3751 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
3754 + struct proc_dir_entry *proc_entry;
3756 + sprintf(name,"i2c-%d", bus);
3757 + proc_entry = create_proc_entry(name,0,proc_bus);
3758 + if (! proc_entry) {
3759 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
3764 + proc_entry->proc_fops = &i2cproc_operations;
3765 + proc_entry->owner = adap->owner;
3766 + adap->inode = proc_entry->low_ino;
3770 -int i2cproc_init(void)
3771 +static void i2cproc_remove(int bus)
3774 + sprintf(name,"i2c-%d", bus);
3775 + remove_proc_entry(name, proc_bus);
3778 +static int __init i2cproc_init(void)
3780 struct proc_dir_entry *proc_bus_i2c;
3782 - i2cproc_initialized = 0;
3785 - printk("i2c-core.o: /proc/bus/ does not exist");
3786 - i2cproc_cleanup();
3789 proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
3790 if (!proc_bus_i2c) {
3791 printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
3792 - i2cproc_cleanup();
3796 proc_bus_i2c->read_proc = &read_bus_i2c;
3797 proc_bus_i2c->owner = THIS_MODULE;
3798 - i2cproc_initialized += 2;
3802 -int i2cproc_cleanup(void)
3803 +static void __exit i2cproc_cleanup(void)
3806 - if (i2cproc_initialized >= 1) {
3807 - remove_proc_entry("i2c",proc_bus);
3808 - i2cproc_initialized -= 2;
3811 + remove_proc_entry("i2c",proc_bus);
3815 #endif /* def CONFIG_PROC_FS */
3817 /* ----------------------------------------------------
3819 DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
3824 ret = adap->algo->master_xfer(adap,msgs,num);
3831 DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
3832 count,client->adapter->name));
3836 ret = adap->algo->master_xfer(adap,&msg,1);
3840 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
3841 * transmitted, else error code.
3843 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
3844 count,client->adapter->name));
3848 ret = adap->algo->master_xfer(adap,&msg,1);
3852 DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
3853 ret, count, client->addr));
3854 @@ -965,6 +920,123 @@
3856 /* The SMBus parts */
3858 +#define POLY (0x1070U << 3)
3864 + for(i = 0; i < 8; i++) {
3865 + if (data & 0x8000)
3866 + data = data ^ POLY;
3869 + return (u8)(data >> 8);
3872 +/* CRC over count bytes in the first array plus the bytes in the rest
3873 + array if it is non-null. rest[0] is the (length of rest) - 1
3874 + and is included. */
3875 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
3879 + for(i = 0; i < count; i++)
3880 + crc = crc8((crc ^ first[i]) << 8);
3882 + for(i = 0; i <= rest[0]; i++)
3883 + crc = crc8((crc ^ rest[i]) << 8);
3887 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
3889 + return i2c_smbus_partial_pec(0, count, first, rest);
3892 +/* Returns new "size" (transaction type)
3893 + Note that we convert byte to byte_data and byte_data to word_data
3894 + rather than invent new xxx_PEC transactions. */
3895 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
3896 + union i2c_smbus_data *data)
3900 + buf[0] = addr << 1;
3903 + case I2C_SMBUS_BYTE:
3904 + data->byte = i2c_smbus_pec(2, buf, NULL);
3905 + size = I2C_SMBUS_BYTE_DATA;
3907 + case I2C_SMBUS_BYTE_DATA:
3908 + buf[2] = data->byte;
3909 + data->word = buf[2] ||
3910 + (i2c_smbus_pec(3, buf, NULL) << 8);
3911 + size = I2C_SMBUS_WORD_DATA;
3913 + case I2C_SMBUS_WORD_DATA:
3916 + case I2C_SMBUS_BLOCK_DATA:
3917 + data->block[data->block[0] + 1] =
3918 + i2c_smbus_pec(2, buf, data->block);
3919 + size = I2C_SMBUS_BLOCK_DATA_PEC;
3925 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
3926 + union i2c_smbus_data *data)
3928 + u8 buf[3], rpec, cpec;
3932 + case I2C_SMBUS_BYTE_DATA:
3933 + buf[0] = (addr << 1) | 1;
3934 + cpec = i2c_smbus_pec(2, buf, NULL);
3935 + rpec = data->byte;
3937 + case I2C_SMBUS_WORD_DATA:
3938 + buf[0] = (addr << 1) | 1;
3939 + buf[2] = data->word & 0xff;
3940 + cpec = i2c_smbus_pec(3, buf, NULL);
3941 + rpec = data->word >> 8;
3943 + case I2C_SMBUS_WORD_DATA_PEC:
3947 + case I2C_SMBUS_PROC_CALL_PEC:
3951 + case I2C_SMBUS_BLOCK_DATA_PEC:
3952 + buf[0] = (addr << 1);
3953 + buf[2] = (addr << 1) | 1;
3954 + cpec = i2c_smbus_pec(3, buf, data->block);
3955 + rpec = data->block[data->block[0] + 1];
3957 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
3958 + buf[0] = (addr << 1) | 1;
3959 + rpec = i2c_smbus_partial_pec(partial, 1,
3960 + buf, data->block);
3961 + cpec = data->block[data->block[0] + 1];
3967 + if(rpec != cpec) {
3968 + DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
3975 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
3977 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3978 @@ -983,8 +1055,9 @@
3980 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
3982 + union i2c_smbus_data data; /* only for PEC */
3983 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
3984 - I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
3985 + I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
3988 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
3989 @@ -1072,6 +1145,43 @@
3990 I2C_SMBUS_BLOCK_DATA,&data);
3993 +/* Returns the number of read bytes */
3994 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
3995 + u8 command, u8 length, u8 *values)
3997 + union i2c_smbus_data data;
3999 + if (length > I2C_SMBUS_BLOCK_MAX - 1)
4001 + data.block[0] = length;
4002 + for (i = 1; i <= length; i++)
4003 + data.block[i] = values[i-1];
4004 + if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4005 + I2C_SMBUS_WRITE, command,
4006 + I2C_SMBUS_BLOCK_PROC_CALL, &data))
4008 + for (i = 1; i <= data.block[0]; i++)
4009 + values[i-1] = data.block[i];
4010 + return data.block[0];
4013 +/* Returns the number of read bytes */
4014 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
4015 + u8 command, u8 *values)
4017 + union i2c_smbus_data data;
4019 + if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4020 + I2C_SMBUS_READ,command,
4021 + I2C_SMBUS_I2C_BLOCK_DATA,&data))
4024 + for (i = 1; i <= data.block[0]; i++)
4025 + values[i-1] = data.block[i];
4026 + return data.block[0];
4030 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
4031 u8 command, u8 length, u8 *values)
4033 @@ -1098,13 +1208,13 @@
4034 need to use only one message; when reading, we need two. We initialize
4035 most things with sane defaults, to keep the code below somewhat
4037 - unsigned char msgbuf0[34];
4038 - unsigned char msgbuf1[34];
4039 + unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+2];
4040 + unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
4041 int num = read_write == I2C_SMBUS_READ?2:1;
4042 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
4043 { addr, flags | I2C_M_RD, 0, msgbuf1 }
4048 msgbuf0[0] = command;
4050 @@ -1140,16 +1250,30 @@
4052 case I2C_SMBUS_PROC_CALL:
4053 num = 2; /* Special case */
4054 + read_write = I2C_SMBUS_READ;
4057 msgbuf0[1] = data->word & 0xff;
4058 msgbuf0[2] = (data->word >> 8) & 0xff;
4060 case I2C_SMBUS_BLOCK_DATA:
4061 + case I2C_SMBUS_BLOCK_DATA_PEC:
4062 if (read_write == I2C_SMBUS_READ) {
4063 - printk(KERN_ERR "i2c-core.o: Block read not supported "
4064 - "under I2C emulation!\n");
4066 + /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_READ_BLOCK_DATA */
4067 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
4068 + printk(KERN_ERR "i2c-core.o: Block read not supported "
4069 + "under I2C emulation!\n");
4072 + /* set send message */
4074 + /* set recv message */
4075 + msg[1].flags |= I2C_M_RECV_LEN;
4076 + msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
4077 + if (size == I2C_SMBUS_BLOCK_DATA_PEC) {
4079 + msg[1].flags |= I2C_M_RECV_PEC;
4082 msg[0].len = data->block[0] + 2;
4083 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
4084 @@ -1158,10 +1282,57 @@
4088 + if(size == I2C_SMBUS_BLOCK_DATA_PEC)
4090 for (i = 1; i <= msg[0].len; i++)
4091 msgbuf0[i] = data->block[i-1];
4094 + case I2C_SMBUS_BLOCK_PROC_CALL:
4095 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4096 + /* I2C_FUNC_SMBUS_EMUL doesn't include I2C_FUNC_SMBUS_BLOCK_PROC_CALL */
4097 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_PROC_CALL)) {
4098 + printk(KERN_ERR "i2c-core.o: adapter doesn't support block process call!\n");
4102 + /* Another special case */
4104 + read_write = I2C_SMBUS_READ;
4106 + /* set send message */
4107 + msg[0].len = data->block[0] + 2;
4108 + if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
4109 + printk(KERN_ERR "i2c-core.o: smbus_access called with "
4110 + "invalid block write size (%d)\n", data->block[0]);
4113 + for (i = 1; i <= msg[0].len; i++)
4114 + msgbuf0[i] = data->block[i-1];
4116 + /* set recv message */
4117 + msg[1].flags |= I2C_M_RECV_LEN;
4118 + msg[1].len = I2C_SMBUS_BLOCK_MAX + 1;
4119 + if (size == I2C_SMBUS_BLOCK_PROC_CALL_PEC) {
4121 + msg[1].flags |= I2C_M_RECV_PEC;
4124 + case I2C_SMBUS_I2C_BLOCK_DATA:
4125 + if (read_write == I2C_SMBUS_READ) {
4126 + msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
4128 + msg[0].len = data->block[0] + 1;
4129 + if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
4130 + printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
4131 + "invalid block write size (%d)\n",
4135 + for (i = 1; i <= data->block[0]; i++)
4136 + msgbuf0[i] = data->block[i];
4140 printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
4142 @@ -1183,25 +1354,72 @@
4143 case I2C_SMBUS_PROC_CALL:
4144 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
4146 + case I2C_SMBUS_I2C_BLOCK_DATA:
4147 + /* fixed at 32 for now */
4148 + data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
4149 + for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
4150 + data->block[i+1] = msgbuf1[i];
4152 + case I2C_SMBUS_BLOCK_DATA:
4153 + case I2C_SMBUS_BLOCK_PROC_CALL:
4154 + case I2C_SMBUS_BLOCK_DATA_PEC:
4155 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4156 + len = msgbuf1[0] + 1;
4157 + if(size == I2C_SMBUS_BLOCK_DATA_PEC ||
4158 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)
4160 + for (i = 0; i < len; i++)
4161 + data->block[i] = msgbuf1[i];
4168 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
4169 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
4170 char read_write, u8 command, int size,
4171 union i2c_smbus_data * data)
4174 - flags = flags & I2C_M_TEN;
4175 - if (adapter->algo->smbus_xfer) {
4176 - I2C_LOCK(adapter);
4177 - res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4181 + flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4182 + if((flags & I2C_CLIENT_PEC) &&
4183 + !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4185 + if(read_write == I2C_SMBUS_READ &&
4186 + size == I2C_SMBUS_BLOCK_DATA)
4187 + size = I2C_SMBUS_BLOCK_DATA_PEC;
4188 + else if(size == I2C_SMBUS_PROC_CALL)
4189 + size = I2C_SMBUS_PROC_CALL_PEC;
4190 + else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
4191 + i2c_smbus_add_pec(addr, command,
4192 + I2C_SMBUS_BLOCK_DATA, data);
4193 + partial = data->block[data->block[0] + 1];
4194 + size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
4195 + } else if(read_write == I2C_SMBUS_WRITE &&
4196 + size != I2C_SMBUS_QUICK &&
4197 + size != I2C_SMBUS_I2C_BLOCK_DATA)
4198 + size = i2c_smbus_add_pec(addr, command, size, data);
4201 + if (adap->algo->smbus_xfer) {
4203 + res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
4205 - I2C_UNLOCK(adapter);
4208 - res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
4209 + res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
4212 + if(res >= 0 && swpec &&
4213 + size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
4214 + (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
4215 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
4216 + if(i2c_smbus_check_pec(addr, command, size, partial, data))
4222 @@ -1228,143 +1446,37 @@
4223 printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4224 memset(adapters,0,sizeof(adapters));
4225 memset(drivers,0,sizeof(drivers));
4229 - init_MUTEX(&adap_lock);
4230 - init_MUTEX(&driver_lock);
4234 +#ifdef CONFIG_PROC_FS
4235 + return i2cproc_init();
4241 -#ifdef CONFIG_I2C_CHARDEV
4242 - extern int i2c_dev_init(void);
4244 -#ifdef CONFIG_I2C_ALGOBIT
4245 - extern int i2c_algo_bit_init(void);
4247 -#ifdef CONFIG_I2C_PHILIPSPAR
4248 - extern int i2c_bitlp_init(void);
4250 -#ifdef CONFIG_I2C_ELV
4251 - extern int i2c_bitelv_init(void);
4253 -#ifdef CONFIG_I2C_VELLEMAN
4254 - extern int i2c_bitvelle_init(void);
4256 -#ifdef CONFIG_I2C_BITVIA
4257 - extern int i2c_bitvia_init(void);
4260 -#ifdef CONFIG_I2C_ALGOPCF
4261 - extern int i2c_algo_pcf_init(void);
4263 -#ifdef CONFIG_I2C_ELEKTOR
4264 - extern int i2c_pcfisa_init(void);
4267 -#ifdef CONFIG_I2C_ALGO8XX
4268 - extern int i2c_algo_8xx_init(void);
4270 -#ifdef CONFIG_I2C_RPXLITE
4271 - extern int i2c_rpx_init(void);
4274 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4275 - extern int i2c_algo_sibyte_init(void);
4276 - extern int i2c_sibyte_init(void);
4278 -#ifdef CONFIG_I2C_MAX1617
4279 - extern int i2c_max1617_init(void);
4281 -#ifdef CONFIG_I2C_ALGO_AU1550
4282 - extern int i2c_pb1550_init(void);
4286 -#ifdef CONFIG_I2C_PROC
4287 - extern int sensors_init(void);
4288 +static void __exit i2c_exit(void)
4290 +#ifdef CONFIG_PROC_FS
4291 + i2cproc_cleanup();
4295 -/* This is needed for automatic patch generation: sensors code starts here */
4296 -/* This is needed for automatic patch generation: sensors code ends here */
4298 +/* leave this in for now simply to make patching easier so we don't have
4299 + to remove the call in drivers/char/mem.c */
4300 int __init i2c_init_all(void)
4302 - /* --------------------- global ----- */
4305 -#ifdef CONFIG_I2C_CHARDEV
4308 - /* --------------------- bit -------- */
4309 -#ifdef CONFIG_I2C_ALGOBIT
4310 - i2c_algo_bit_init();
4312 -#ifdef CONFIG_I2C_PHILIPSPAR
4315 -#ifdef CONFIG_I2C_ELV
4316 - i2c_bitelv_init();
4318 -#ifdef CONFIG_I2C_VELLEMAN
4319 - i2c_bitvelle_init();
4322 - /* --------------------- pcf -------- */
4323 -#ifdef CONFIG_I2C_ALGOPCF
4324 - i2c_algo_pcf_init();
4326 -#ifdef CONFIG_I2C_ELEKTOR
4327 - i2c_pcfisa_init();
4330 - /* --------------------- 8xx -------- */
4331 -#ifdef CONFIG_I2C_ALGO8XX
4332 - i2c_algo_8xx_init();
4334 -#ifdef CONFIG_I2C_RPXLITE
4338 - /* --------------------- SiByte -------- */
4339 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4340 - i2c_algo_sibyte_init();
4341 - i2c_sibyte_init();
4343 -#ifdef CONFIG_I2C_MAX1617
4344 - i2c_max1617_init();
4347 -#ifdef CONFIG_I2C_ALGO_AU1550
4348 - i2c_pb1550_init();
4351 - /* -------------- proc interface ---- */
4352 -#ifdef CONFIG_I2C_PROC
4355 -/* This is needed for automatic patch generation: sensors code starts here */
4356 -/* This is needed for automatic patch generation: sensors code ends here */
4365 EXPORT_SYMBOL(i2c_add_adapter);
4366 EXPORT_SYMBOL(i2c_del_adapter);
4367 EXPORT_SYMBOL(i2c_add_driver);
4368 EXPORT_SYMBOL(i2c_del_driver);
4369 EXPORT_SYMBOL(i2c_attach_client);
4370 EXPORT_SYMBOL(i2c_detach_client);
4371 -EXPORT_SYMBOL(i2c_inc_use_client);
4372 -EXPORT_SYMBOL(i2c_dec_use_client);
4374 EXPORT_SYMBOL(i2c_get_client);
4376 EXPORT_SYMBOL(i2c_use_client);
4377 EXPORT_SYMBOL(i2c_release_client);
4378 EXPORT_SYMBOL(i2c_check_addr);
4379 @@ -1388,11 +1500,12 @@
4380 EXPORT_SYMBOL(i2c_smbus_process_call);
4381 EXPORT_SYMBOL(i2c_smbus_read_block_data);
4382 EXPORT_SYMBOL(i2c_smbus_write_block_data);
4383 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
4384 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
4386 EXPORT_SYMBOL(i2c_get_functionality);
4387 EXPORT_SYMBOL(i2c_check_functionality);
4390 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4391 MODULE_DESCRIPTION("I2C-Bus main module");
4392 MODULE_LICENSE("GPL");
4393 @@ -1400,13 +1513,5 @@
4394 MODULE_PARM(i2c_debug, "i");
4395 MODULE_PARM_DESC(i2c_debug,"debug level");
4397 -int init_module(void)
4399 - return i2c_init();
4402 -void cleanup_module(void)
4404 - i2cproc_cleanup();
4407 +module_init(i2c_init);
4408 +module_exit(i2c_exit);
4409 --- linux-old/drivers/i2c/i2c-dev.c Tue Jan 20 15:10:31 2004
4410 +++ linux/drivers/i2c/i2c-dev.c Mon Dec 13 19:26:32 2004
4412 /* The devfs code is contributed by Philipp Matthias Hahn
4413 <pmhahn@titan.lahn.de> */
4415 -/* $Id: i2c-dev.c,v 1.40 2001/08/25 01:28:01 mds Exp $ */
4416 +/* $Id: i2c-dev.c,v 1.57 2003/12/22 20:03:39 khali Exp $ */
4418 -#include <linux/config.h>
4419 #include <linux/kernel.h>
4420 #include <linux/module.h>
4421 #include <linux/fs.h>
4423 #ifdef CONFIG_DEVFS_FS
4424 #include <linux/devfs_fs_kernel.h>
4428 -/* If you want debugging uncomment: */
4429 -/* #define DEBUG */
4431 #include <linux/init.h>
4432 -#include <asm/uaccess.h>
4434 #include <linux/i2c.h>
4435 #include <linux/i2c-dev.h>
4436 +#include <asm/uaccess.h>
4438 +/* If you want debugging uncomment: */
4439 +/* #define DEBUG */
4442 -extern int init_module(void);
4443 -extern int cleanup_module(void);
4444 -#endif /* def MODULE */
4446 /* struct file_operations changed too often in the 2.1 series for nice code */
4449 static int i2cdev_command(struct i2c_client *client, unsigned int cmd,
4457 - int __init i2c_dev_init(void);
4458 -static int i2cdev_cleanup(void);
4460 static struct file_operations i2cdev_fops = {
4461 - owner: THIS_MODULE,
4462 - llseek: no_llseek,
4463 - read: i2cdev_read,
4464 - write: i2cdev_write,
4465 - ioctl: i2cdev_ioctl,
4466 - open: i2cdev_open,
4467 - release: i2cdev_release,
4468 + .owner = THIS_MODULE,
4469 + .llseek = no_llseek,
4470 + .read = i2cdev_read,
4471 + .write = i2cdev_write,
4472 + .ioctl = i2cdev_ioctl,
4473 + .open = i2cdev_open,
4474 + .release = i2cdev_release,
4477 #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
4481 static struct i2c_driver i2cdev_driver = {
4482 - name: "i2c-dev dummy driver",
4483 - id: I2C_DRIVERID_I2CDEV,
4484 - flags: I2C_DF_DUMMY,
4485 - attach_adapter: i2cdev_attach_adapter,
4486 - detach_client: i2cdev_detach_client,
4487 - command: i2cdev_command,
4490 + .owner = THIS_MODULE, /* not really used */
4491 + .name = "i2c-dev dummy driver",
4492 + .id = I2C_DRIVERID_I2CDEV,
4493 + .flags = I2C_DF_DUMMY,
4494 + .attach_adapter = i2cdev_attach_adapter,
4495 + .detach_client = i2cdev_detach_client,
4496 + .command = i2cdev_command,
4499 static struct i2c_client i2cdev_client_template = {
4500 - name: "I2C /dev entry",
4504 -/* adapter: NULL, */
4505 - driver: &i2cdev_driver,
4507 + .name = "I2C /dev entry",
4510 + .driver = &i2cdev_driver,
4513 -static int i2cdev_initialized;
4515 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
4522 - printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
4523 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
4531 - printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
4532 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
4535 ret = i2c_master_send(client,tmp,count);
4539 printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
4540 - MINOR(inode->i_rdev),cmd, arg);
4541 + minor(inode->i_rdev),cmd, arg);
4545 @@ -218,6 +196,12 @@
4547 client->flags &= ~I2C_M_TEN;
4551 + client->flags |= I2C_CLIENT_PEC;
4553 + client->flags &= ~I2C_CLIENT_PEC;
4556 funcs = i2c_get_functionality(client->adapter);
4557 return (copy_to_user((unsigned long *)arg,&funcs,
4559 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
4560 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
4561 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
4562 - (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
4563 + (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
4564 + (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
4566 printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
4568 @@ -361,10 +346,11 @@
4569 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
4570 (data_arg.size == I2C_SMBUS_PROC_CALL))
4571 datasize = sizeof(data_arg.data->word);
4572 - else /* size == I2C_SMBUS_BLOCK_DATA */
4573 + else /* size == smbus block, i2c block, or block proc. call */
4574 datasize = sizeof(data_arg.data->block);
4576 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
4577 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
4578 (data_arg.read_write == I2C_SMBUS_WRITE)) {
4579 if (copy_from_user(&temp, data_arg.data, datasize))
4582 data_arg.read_write,
4583 data_arg.command,data_arg.size,&temp);
4584 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
4585 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
4586 (data_arg.read_write == I2C_SMBUS_READ))) {
4587 if (copy_to_user(data_arg.data, &temp, datasize))
4591 int i2cdev_open (struct inode *inode, struct file *file)
4593 - unsigned int minor = MINOR(inode->i_rdev);
4594 + unsigned int minor = minor(inode->i_rdev);
4595 struct i2c_client *client;
4597 if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
4598 @@ -403,11 +390,13 @@
4599 if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
4601 memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
4603 + /* registered with adapter, passed as client to user */
4604 client->adapter = i2cdev_adaps[minor];
4605 file->private_data = client;
4607 - if (i2cdev_adaps[minor]->inc_use)
4608 - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
4609 + if(client->adapter->owner)
4610 + __MOD_INC_USE_COUNT(client->adapter->owner);
4613 printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
4614 @@ -417,16 +406,19 @@
4616 static int i2cdev_release (struct inode *inode, struct file *file)
4618 - unsigned int minor = MINOR(inode->i_rdev);
4619 - kfree(file->private_data);
4620 - file->private_data=NULL;
4621 + struct i2c_client *client;
4623 + unsigned int minor = minor(inode->i_rdev);
4626 + client = file->private_data;
4627 + file->private_data = NULL;
4628 + if(client->adapter->owner)
4629 + __MOD_DEC_USE_COUNT(client->adapter->owner);
4632 printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
4635 - if (i2cdev_adaps[minor]->dec_use)
4636 - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
4642 devfs_i2c[i] = devfs_register (devfs_handle, name,
4643 DEVFS_FL_DEFAULT, I2C_MAJOR, i,
4644 S_IFCHR | S_IRUSR | S_IWUSR,
4645 - &i2cdev_fops, NULL);
4646 + &i2cdev_fops, adap);
4648 printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
4650 @@ -479,13 +471,12 @@
4654 -int __init i2c_dev_init(void)
4655 +static int __init i2c_dev_init(void)
4659 printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4661 - i2cdev_initialized = 0;
4662 #ifdef CONFIG_DEVFS_FS
4663 if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
4665 @@ -498,63 +489,31 @@
4666 #ifdef CONFIG_DEVFS_FS
4667 devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
4669 - i2cdev_initialized ++;
4671 if ((res = i2c_add_driver(&i2cdev_driver))) {
4672 printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
4674 +#ifdef CONFIG_DEVFS_FS
4675 + devfs_unregister(devfs_handle);
4677 + unregister_chrdev(I2C_MAJOR,"i2c");
4680 - i2cdev_initialized ++;
4684 -int i2cdev_cleanup(void)
4685 +static void __exit i2c_dev_exit(void)
4689 - if (i2cdev_initialized >= 2) {
4690 - if ((res = i2c_del_driver(&i2cdev_driver))) {
4691 - printk("i2c-dev.o: Driver deregistration failed, "
4692 - "module not removed.\n");
4695 - i2cdev_initialized --;
4698 - if (i2cdev_initialized >= 1) {
4699 + i2c_del_driver(&i2cdev_driver);
4700 #ifdef CONFIG_DEVFS_FS
4701 - devfs_unregister(devfs_handle);
4702 - if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
4704 - if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
4705 + devfs_unregister(devfs_handle);
4707 - printk("i2c-dev.o: unable to release major %d for i2c bus\n",
4711 - i2cdev_initialized --;
4714 + unregister_chrdev(I2C_MAJOR,"i2c");
4721 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
4722 MODULE_DESCRIPTION("I2C /dev entries driver");
4723 MODULE_LICENSE("GPL");
4725 -int init_module(void)
4727 - return i2c_dev_init();
4730 -int cleanup_module(void)
4732 - return i2cdev_cleanup();
4735 -#endif /* def MODULE */
4737 +module_init(i2c_dev_init);
4738 +module_exit(i2c_dev_exit);
4739 --- linux-old/include/linux/i2c-dev.h Sat Jul 5 03:23:47 2003
4740 +++ linux/include/linux/i2c-dev.h Mon Dec 13 19:26:32 2004
4742 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4745 -/* $Id: i2c-dev.h,v 1.9 2001/08/15 03:04:58 mds Exp $ */
4749 +/* $Id: i2c-dev.h,v 1.14 2003/07/25 07:56:42 khali Exp $ */
4751 +#ifndef _LINUX_I2C_DEV_H
4752 +#define _LINUX_I2C_DEV_H
4754 #include <linux/types.h>
4755 -#include <linux/i2c.h>
4757 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
4758 +#define minor(d) MINOR(d)
4761 /* Some IOCTL commands are defined in <linux/i2c.h> */
4762 /* Note: 10-bit addresses are NOT supported! */
4764 __u32 nmsgs; /* number of i2c_msgs */
4769 -#include <sys/ioctl.h>
4771 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
4772 - int size, union i2c_smbus_data *data)
4774 - struct i2c_smbus_ioctl_data args;
4776 - args.read_write = read_write;
4777 - args.command = command;
4780 - return ioctl(file,I2C_SMBUS,&args);
4784 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
4786 - return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
4789 -static inline __s32 i2c_smbus_read_byte(int file)
4791 - union i2c_smbus_data data;
4792 - if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
4795 - return 0x0FF & data.byte;
4798 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
4800 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
4801 - I2C_SMBUS_BYTE,NULL);
4804 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
4806 - union i2c_smbus_data data;
4807 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
4808 - I2C_SMBUS_BYTE_DATA,&data))
4811 - return 0x0FF & data.byte;
4814 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
4817 - union i2c_smbus_data data;
4818 - data.byte = value;
4819 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
4820 - I2C_SMBUS_BYTE_DATA, &data);
4823 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
4825 - union i2c_smbus_data data;
4826 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
4827 - I2C_SMBUS_WORD_DATA,&data))
4830 - return 0x0FFFF & data.word;
4833 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
4836 - union i2c_smbus_data data;
4837 - data.word = value;
4838 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
4839 - I2C_SMBUS_WORD_DATA, &data);
4842 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
4844 - union i2c_smbus_data data;
4845 - data.word = value;
4846 - if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
4847 - I2C_SMBUS_PROC_CALL,&data))
4850 - return 0x0FFFF & data.word;
4854 -/* Returns the number of read bytes */
4855 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
4858 - union i2c_smbus_data data;
4860 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
4861 - I2C_SMBUS_BLOCK_DATA,&data))
4864 - for (i = 1; i <= data.block[0]; i++)
4865 - values[i-1] = data.block[i];
4866 - return data.block[0];
4870 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
4871 - __u8 length, __u8 *values)
4873 - union i2c_smbus_data data;
4877 - for (i = 1; i <= length; i++)
4878 - data.block[i] = values[i-1];
4879 - data.block[0] = length;
4880 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
4881 - I2C_SMBUS_BLOCK_DATA, &data);
4884 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
4885 - __u8 length, __u8 *values)
4887 - union i2c_smbus_data data;
4891 - for (i = 1; i <= length; i++)
4892 - data.block[i] = values[i-1];
4893 - data.block[0] = length;
4894 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
4895 - I2C_SMBUS_I2C_BLOCK_DATA, &data);
4898 -#endif /* ndef __KERNEL__ */
4901 +#endif /* _LINUX_I2C_DEV_H */
4902 --- linux-old/drivers/i2c/i2c-elektor.c Tue Jan 20 15:10:31 2004
4903 +++ linux/drivers/i2c/i2c-elektor.c Mon Dec 13 19:26:33 2004
4905 #include <linux/delay.h>
4906 #include <linux/slab.h>
4907 #include <linux/init.h>
4908 +#include <linux/interrupt.h>
4909 #include <linux/pci.h>
4910 -#include <asm/irq.h>
4911 -#include <asm/io.h>
4913 +#include <linux/wait.h>
4914 #include <linux/i2c.h>
4915 #include <linux/i2c-algo-pcf.h>
4916 -#include <linux/i2c-elektor.h>
4917 -#include "i2c-pcf8584.h"
4918 +#include <asm/io.h>
4919 +#include <asm/irq.h>
4921 #define DEFAULT_BASE 0x330
4923 -static int base = 0;
4924 -static int irq = 0;
4927 static int clock = 0x1c;
4928 static int own = 0x55;
4929 -static int mmapped = 0;
4930 -static int i2c_debug = 0;
4931 +static int mmapped;
4932 +static int i2c_debug;
4934 /* vdovikin: removed static struct i2c_pcf_isa gpi; code -
4935 this module in real supports only one device, due to missing arguments
4938 static wait_queue_head_t pcf_wait;
4939 static int pcf_pending;
4940 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
4942 /* ----- global defines ----------------------------------------------- */
4943 #define DEB(x) if (i2c_debug>=1) x
4945 #define DEB3(x) if (i2c_debug>=3) x
4946 #define DEBE(x) x /* error messages */
4949 +/* compatibility */
4951 +#define isa_readb readb
4955 +#define isa_writeb writeb
4958 /* ----- local functions ---------------------------------------------- */
4960 static void pcf_isa_setbyte(void *data, int ctl, int val)
4962 int address = ctl ? (base + 1) : base;
4965 + /* enable irq if any specified for serial operation */
4966 + if (ctl && irq && (val & I2C_PCF_ESO)) {
4972 case 2: /* double mapped I/O needed for UP2000 board,
4973 I don't know why this... */
4974 - writeb(val, address);
4975 + isa_writeb(val, address);
4977 case 1: /* memory mapped I/O */
4978 - writeb(val, address);
4979 + isa_writeb(val, address);
4984 static int pcf_isa_getbyte(void *data, int ctl)
4986 int address = ctl ? (base + 1) : base;
4987 - int val = mmapped ? readb(address) : inb(address);
4988 + int val = mmapped ? isa_readb(address) : inb(address);
4990 DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
4992 @@ -115,12 +126,12 @@
4997 + spin_lock_irq(&irq_driver_lock);
4998 if (pcf_pending == 0) {
4999 interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
5003 + spin_unlock_irq(&irq_driver_lock);
5007 @@ -136,13 +147,11 @@
5008 static int pcf_isa_init(void)
5011 - if (check_region(base, 2) < 0 ) {
5012 + if (!request_region(base, 2, "i2c (isa bus adapter)")) {
5014 "i2c-elektor.o: requested I/O region (0x%X:2) "
5015 "is in use.\n", base);
5018 - request_region(base, 2, "i2c (isa bus adapter)");
5022 @@ -156,70 +165,29 @@
5026 -static void __exit pcf_isa_exit(void)
5033 - release_region(base , 2);
5038 -static int pcf_isa_reg(struct i2c_client *client)
5044 -static int pcf_isa_unreg(struct i2c_client *client)
5049 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
5052 - MOD_INC_USE_COUNT;
5056 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
5059 - MOD_DEC_USE_COUNT;
5064 /* ------------------------------------------------------------------------
5065 * Encapsulate the above functions in the correct operations structure.
5066 * This is only done when more than one hardware adapter is supported.
5068 static struct i2c_algo_pcf_data pcf_isa_data = {
5074 - pcf_isa_waitforpin,
5075 - 10, 10, 100, /* waits, timeout */
5076 + .setpcf = pcf_isa_setbyte,
5077 + .getpcf = pcf_isa_getbyte,
5078 + .getown = pcf_isa_getown,
5079 + .getclock = pcf_isa_getclock,
5080 + .waitforpin = pcf_isa_waitforpin,
5086 static struct i2c_adapter pcf_isa_ops = {
5087 - "PCF8584 ISA adapter",
5095 + .owner = THIS_MODULE,
5096 + .name = "PCF8584 ISA adapter",
5097 + .id = I2C_HW_P_ELEK,
5098 + .algo_data = &pcf_isa_data,
5101 -int __init i2c_pcfisa_init(void)
5102 +static int __init i2c_pcfisa_init(void)
5105 /* check to see we have memory mapped PCF8584 connected to the
5106 @@ -277,22 +245,41 @@
5109 init_waitqueue_head(&pcf_wait);
5110 - if (pcf_isa_init() == 0) {
5111 - if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5114 + if (pcf_isa_init())
5117 + if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5120 printk(KERN_DEBUG "i2c-elektor.o: found device at %#x.\n", base);
5131 + release_region(base , 2);
5135 +static void __exit i2c_pcfisa_exit(void)
5137 + i2c_pcf_del_bus(&pcf_isa_ops);
5145 + release_region(base , 2);
5151 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
5152 MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
5153 MODULE_LICENSE("GPL");
5154 @@ -304,15 +291,5 @@
5155 MODULE_PARM(mmapped, "i");
5156 MODULE_PARM(i2c_debug, "i");
5158 -int init_module(void)
5160 - return i2c_pcfisa_init();
5163 -void cleanup_module(void)
5165 - i2c_pcf_del_bus(&pcf_isa_ops);
5170 +module_init(i2c_pcfisa_init);
5171 +module_exit(i2c_pcfisa_exit);
5172 --- linux-old/include/linux/i2c-elektor.h Tue Nov 6 00:55:29 2001
5173 +++ linux/include/linux/i2c-elektor.h Mon Dec 13 19:26:33 2004
5175 -/* ------------------------------------------------------------------------- */
5176 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
5177 -/* ------------------------------------------------------------------------- */
5178 -/* Copyright (C) 1995-97 Simon G. Vogl
5179 - 1998-99 Hans Berglund
5181 - This program is free software; you can redistribute it and/or modify
5182 - it under the terms of the GNU General Public License as published by
5183 - the Free Software Foundation; either version 2 of the License, or
5184 - (at your option) any later version.
5186 - This program is distributed in the hope that it will be useful,
5187 - but WITHOUT ANY WARRANTY; without even the implied warranty of
5188 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5189 - GNU General Public License for more details.
5191 - You should have received a copy of the GNU General Public License
5192 - along with this program; if not, write to the Free Software
5193 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5194 -/* ------------------------------------------------------------------------- */
5196 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
5197 - Frodo Looijaard <frodol@dds.nl> */
5199 -/* $Id: i2c-elektor.h,v 1.5 2001/06/05 01:46:33 mds Exp $ */
5201 -#ifndef I2C_PCF_ELEKTOR_H
5202 -#define I2C_PCF_ELEKTOR_H 1
5205 - * This struct contains the hw-dependent functions of PCF8584 adapters to
5206 - * manipulate the registers, and to init any hw-specific features.
5207 - * vdovikin: removed: this module in real supports only one device,
5208 - * due to missing arguments in some functions, called from the algo-pcf module.
5209 - * Sometimes it's need to be rewriten -
5210 - * but for now just remove this for simpler reading */
5213 -struct i2c_pcf_isa {
5221 -#endif /* PCF_ELEKTOR_H */
5222 --- linux-old/drivers/i2c/i2c-elv.c Tue Jan 20 15:10:31 2004
5223 +++ linux/drivers/i2c/i2c-elv.c Mon Dec 13 19:26:33 2004
5225 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
5226 Frodo Looijaard <frodol@dds.nl> */
5228 -/* $Id: i2c-elv.c,v 1.17 2001/07/29 02:44:25 mds Exp $ */
5229 +/* $Id: i2c-elv.c,v 1.29 2003/12/22 20:03:11 khali Exp $ */
5231 #include <linux/kernel.h>
5232 #include <linux/module.h>
5233 #include <linux/delay.h>
5234 #include <linux/slab.h>
5235 #include <linux/init.h>
5237 -#include <asm/uaccess.h>
5239 #include <linux/ioport.h>
5240 -#include <asm/io.h>
5241 #include <linux/errno.h>
5242 #include <linux/i2c.h>
5243 #include <linux/i2c-algo-bit.h>
5244 +#include <asm/io.h>
5246 #define DEFAULT_BASE 0x378
5250 static int bit_elv_init(void)
5252 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
5255 - /* test for ELV adap. */
5256 - if (inb(base+1) & 0x80) { /* BUSY should be high */
5257 - DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
5260 - outb(0x0c,base+2); /* SLCT auf low */
5262 - if ( !(inb(base+1) && 0x10) ) {
5263 - outb(0x04,base+2);
5264 - DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
5268 - request_region(base,(base == 0x3bc)? 3 : 8,
5269 - "i2c (ELV adapter)");
5271 - bit_elv_setsda((void*)base,1);
5272 - bit_elv_setscl((void*)base,1);
5273 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
5274 + "i2c (ELV adapter)"))
5277 + if (inb(base+1) & 0x80) { /* BUSY should be high */
5278 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
5282 + outb(0x0c,base+2); /* SLCT auf low */
5284 + if (!(inb(base+1) && 0x10)) {
5285 + outb(0x04,base+2);
5286 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
5292 -static void __exit bit_elv_exit(void)
5294 - release_region( base , (base == 0x3bc)? 3 : 8 );
5297 -static int bit_elv_reg(struct i2c_client *client)
5302 -static int bit_elv_unreg(struct i2c_client *client)
5305 + bit_elv_setsda((void*)base,1);
5306 + bit_elv_setscl((void*)base,1);
5310 -static void bit_elv_inc_use(struct i2c_adapter *adap)
5313 - MOD_INC_USE_COUNT;
5317 -static void bit_elv_dec_use(struct i2c_adapter *adap)
5320 - MOD_DEC_USE_COUNT;
5323 + release_region(base , (base == 0x3bc) ? 3 : 8);
5327 /* ------------------------------------------------------------------------
5328 @@ -148,26 +118,23 @@
5329 * This is only done when more than one hardware adapter is supported.
5331 static struct i2c_algo_bit_data bit_elv_data = {
5337 - 80, 80, 100, /* waits, timeout */
5338 + .setsda = bit_elv_setsda,
5339 + .setscl = bit_elv_setscl,
5340 + .getsda = bit_elv_getsda,
5341 + .getscl = bit_elv_getscl,
5347 static struct i2c_adapter bit_elv_ops = {
5348 - "ELV Parallel port adaptor",
5356 + .owner = THIS_MODULE,
5357 + .name = "ELV Parallel port adaptor",
5358 + .id = I2C_HW_B_ELV,
5359 + .algo_data = &bit_elv_data,
5362 -int __init i2c_bitelv_init(void)
5363 +static int __init i2c_bitelv_init(void)
5365 printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5367 @@ -193,25 +160,19 @@
5371 +static void __exit i2c_bitelv_exit(void)
5373 + i2c_bit_del_bus(&bit_elv_ops);
5374 + release_region(base, (base == 0x3bc) ? 3 : 8);
5380 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5381 MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
5382 MODULE_LICENSE("GPL");
5384 MODULE_PARM(base, "i");
5386 -int init_module(void)
5388 - return i2c_bitelv_init();
5391 -void cleanup_module(void)
5393 - i2c_bit_del_bus(&bit_elv_ops);
5398 +module_init(i2c_bitelv_init);
5399 +module_exit(i2c_bitelv_exit);
5400 --- linux-old/drivers/i2c/i2c-frodo.c Thu Jan 1 00:00:00 1970
5401 +++ linux/drivers/i2c/i2c-frodo.c Mon Dec 13 19:26:33 2004
5405 + * linux/drivers/i2c/i2c-frodo.c
5407 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
5409 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
5410 + * Development board (Frodo).
5412 + * This source code is free software; you can redistribute it and/or
5413 + * modify it under the terms of the GNU General Public License
5414 + * version 2 as published by the Free Software Foundation.
5417 +#include <linux/module.h>
5418 +#include <linux/kernel.h>
5419 +#include <linux/init.h>
5420 +#include <linux/delay.h>
5421 +#include <linux/i2c.h>
5422 +#include <linux/i2c-algo-bit.h>
5423 +#include <asm/hardware.h>
5426 +static void frodo_setsda (void *data,int state)
5429 + FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
5431 + FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
5434 +static void frodo_setscl (void *data,int state)
5437 + FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
5439 + FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
5442 +static int frodo_getsda (void *data)
5444 + return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
5447 +static int frodo_getscl (void *data)
5449 + return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
5452 +static struct i2c_algo_bit_data bit_frodo_data = {
5453 + .setsda = frodo_setsda,
5454 + .setscl = frodo_setscl,
5455 + .getsda = frodo_getsda,
5456 + .getscl = frodo_getscl,
5462 +static struct i2c_adapter frodo_ops = {
5463 + .owner = THIS_MODULE,
5464 + .name = "Frodo adapter driver",
5465 + .id = I2C_HW_B_FRODO,
5466 + .algo_data = &bit_frodo_data,
5469 +static int __init i2c_frodo_init (void)
5471 + return i2c_bit_add_bus(&frodo_ops);
5474 +static void __exit i2c_frodo_exit (void)
5476 + i2c_bit_del_bus(&frodo_ops);
5479 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
5480 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
5481 +MODULE_LICENSE ("GPL");
5483 +module_init (i2c_frodo_init);
5484 +module_exit (i2c_frodo_exit);
5486 --- linux-old/include/linux/i2c-id.h Wed Jul 7 00:38:02 2004
5487 +++ linux/include/linux/i2c-id.h Mon Dec 13 19:26:33 2004
5489 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5490 /* ------------------------------------------------------------------------- */
5492 -/* $Id: i2c-id.h,v 1.35 2001/08/12 17:22:20 mds Exp $ */
5493 +/* $Id: i2c-id.h,v 1.92 2004/07/27 18:15:06 mmh Exp $ */
5495 +#ifndef LINUX_I2C_ID_H
5496 +#define LINUX_I2C_ID_H
5501 * This file is part of the i2c-bus package and contains the identifier
5502 * values for drivers, adapters and other folk populating these serial
5504 #define I2C_DRIVERID_DRP3510 43 /* ADR decoder (Astra Radio) */
5505 #define I2C_DRIVERID_SP5055 44 /* Satellite tuner */
5506 #define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */
5507 +#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */
5508 +#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */
5509 #define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */
5510 -#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
5511 -#define I2C_DRIVERID_SAA7191 57 /* video decoder */
5512 -#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
5513 +#define I2C_DRIVERID_ZR36067 49 /* Zoran 36067 video encoder */
5514 +#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */
5515 +#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */
5516 +#define I2C_DRIVERID_STM41T00 52 /* real time clock */
5517 +#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
5518 +#define I2C_DRIVERID_ADV7170 54 /* video encoder */
5519 +#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */
5520 +#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
5521 +#define I2C_DRIVERID_SAA7191 57 /* video encoder */
5522 +#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
5523 +#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */
5524 +#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */
5525 +#define I2C_DRIVERID_OVCAMCHIP 61 /* OmniVision CMOS image sens. */
5526 +#define I2C_DRIVERID_TDA7313 62 /* TDA7313 audio processor */
5527 +#define I2C_DRIVERID_MAX6900 63 /* MAX6900 real-time clock */
5530 #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */
5531 #define I2C_DRIVERID_EXP1 0xF1
5534 #define I2C_DRIVERID_I2CDEV 900
5535 #define I2C_DRIVERID_I2CPROC 901
5536 +#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
5537 +#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */
5539 /* IDs -- Use DRIVERIDs 1000-1999 for sensors.
5540 These were originally in sensors.h in the lm_sensors package */
5541 @@ -131,6 +149,28 @@
5542 #define I2C_DRIVERID_ADM1024 1025
5543 #define I2C_DRIVERID_IT87 1026
5544 #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
5545 +#define I2C_DRIVERID_FSCPOS 1028
5546 +#define I2C_DRIVERID_FSCSCY 1029
5547 +#define I2C_DRIVERID_PCF8591 1030
5548 +#define I2C_DRIVERID_SMSC47M1 1031
5549 +#define I2C_DRIVERID_VT1211 1032
5550 +#define I2C_DRIVERID_LM92 1033
5551 +#define I2C_DRIVERID_VT8231 1034
5552 +#define I2C_DRIVERID_SMARTBATT 1035
5553 +#define I2C_DRIVERID_BMCSENSORS 1036
5554 +#define I2C_DRIVERID_FS451 1037
5555 +#define I2C_DRIVERID_W83627HF 1038
5556 +#define I2C_DRIVERID_LM85 1039
5557 +#define I2C_DRIVERID_LM83 1040
5558 +#define I2C_DRIVERID_SAA1064 1041
5559 +#define I2C_DRIVERID_LM90 1042
5560 +#define I2C_DRIVERID_ASB100 1043
5561 +#define I2C_DRIVERID_MAX6650 1044
5562 +#define I2C_DRIVERID_XEONTEMP 1045
5563 +#define I2C_DRIVERID_FSCHER 1046
5564 +#define I2C_DRIVERID_W83L785TS 1047
5565 +#define I2C_DRIVERID_ADM1026 1048
5566 +#define I2C_DRIVERID_LM93 1049
5569 * ---- Adapter types ----------------------------------------------------
5570 @@ -147,16 +187,21 @@
5571 #define I2C_ALGO_ISA 0x050000 /* lm_sensors ISA pseudo-adapter */
5572 #define I2C_ALGO_SAA7146 0x060000 /* SAA 7146 video decoder bus */
5573 #define I2C_ALGO_ACB 0x070000 /* ACCESS.bus algorithm */
5575 +#define I2C_ALGO_IIC 0x080000 /* ITE IIC bus */
5576 +#define I2C_ALGO_SAA7134 0x090000
5577 +#define I2C_ALGO_MPC824X 0x0a0000 /* Motorola 8240 / 8245 */
5578 +#define I2C_ALGO_IPMI 0x0b0000 /* IPMI dummy adapter */
5579 +#define I2C_ALGO_IPMB 0x0c0000 /* IPMB adapter */
5580 +#define I2C_ALGO_MPC107 0x0d0000
5581 #define I2C_ALGO_EC 0x100000 /* ACPI embedded controller */
5583 #define I2C_ALGO_MPC8XX 0x110000 /* MPC8xx PowerPC I2C algorithm */
5585 -#define I2C_ALGO_SIBYTE 0x120000 /* Broadcom SiByte SOCs */
5587 -#define I2C_ALGO_SGI 0x130000 /* SGI algorithm */
5589 -#define I2C_ALGO_AU1550 0x140000 /* Alchemy Au1550 PSC */
5590 +#define I2C_ALGO_OCP 0x120000 /* IBM or otherwise On-chip I2C algorithm */
5591 +#define I2C_ALGO_BITHS 0x130000 /* enhanced bit style adapters */
5592 +#define I2C_ALGO_OCP_IOP3XX 0x140000 /* XSCALE IOP3XX On-chip I2C alg */
5593 +#define I2C_ALGO_SIBYTE 0x150000 /* Broadcom SiByte SOCs */
5594 +#define I2C_ALGO_SGI 0x160000 /* SGI algorithm */
5595 +#define I2C_ALGO_USB 0x170000 /* USB algorithm */
5597 #define I2C_ALGO_EXP 0x800000 /* experimental */
5599 @@ -184,21 +229,46 @@
5600 #define I2C_HW_B_I810 0x0a /* Intel I810 */
5601 #define I2C_HW_B_VOO 0x0b /* 3dfx Voodoo 3 / Banshee */
5602 #define I2C_HW_B_PPORT 0x0c /* Primitive parallel port adapter */
5603 +#define I2C_HW_B_SAVG 0x0d /* Savage 4 */
5604 +#define I2C_HW_B_SCX200 0x0e /* Nat'l Semi SCx200 I2C */
5605 #define I2C_HW_B_RIVA 0x10 /* Riva based graphics cards */
5606 #define I2C_HW_B_IOC 0x11 /* IOC bit-wiggling */
5607 #define I2C_HW_B_TSUNA 0x12 /* DEC Tsunami chipset */
5608 +#define I2C_HW_B_FRODO 0x13 /* 2d3D, Inc. SA-1110 Development Board */
5609 +#define I2C_HW_B_OMAHA 0x14 /* Omaha I2C interface (ARM) */
5610 +#define I2C_HW_B_GUIDE 0x15 /* Guide bit-basher */
5611 +#define I2C_HW_B_IXP2000 0x16 /* GPIO on IXP2000 systems */
5612 +#define I2C_HW_B_IXP425 0x17 /* GPIO on IXP425 systems */
5613 +#define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */
5614 +#define I2C_HW_B_ZR36067 0x19 /* Zoran-36057/36067 based boards */
5615 +#define I2C_HW_B_PCILYNX 0x1a /* TI PCILynx I2C adapter */
5617 /* --- PCF 8584 based algorithms */
5618 #define I2C_HW_P_LP 0x00 /* Parallel port interface */
5619 #define I2C_HW_P_ISA 0x01 /* generic ISA Bus inteface card */
5620 #define I2C_HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */
5622 +/* --- USB based adapters */
5623 +#define I2C_HW_USB_USBVISION 0x00
5625 /* --- ACPI Embedded controller algorithms */
5626 #define I2C_HW_ACPI_EC 0x00
5628 +/* --- MPC824x PowerPC adapters */
5629 +#define I2C_HW_MPC824X 0x00 /* Motorola 8240 / 8245 */
5631 /* --- MPC8xx PowerPC adapters */
5632 #define I2C_HW_MPC8XX_EPON 0x00 /* Eponymous MPC8xx I2C adapter */
5634 +/* --- ITE based algorithms */
5635 +#define I2C_HW_I_IIC 0x00 /* controller on the ITE */
5637 +/* --- PowerPC on-chip adapters */
5638 +#define I2C_HW_OCP 0x00 /* IBM on-chip I2C adapter */
5640 +/* --- XSCALE on-chip adapters */
5641 +#define I2C_HW_IOP321 0x00
5643 /* --- Broadcom SiByte adapters */
5644 #define I2C_HW_SIBYTE 0x00
5647 #define I2C_HW_SGI_VINO 0x00
5648 #define I2C_HW_SGI_MACE 0x01
5650 -/* --- Au1550 PSC adapters */
5651 -#define I2C_HW_AU1550_PSC 0x00
5653 /* --- SMBus only adapters */
5654 #define I2C_HW_SMBUS_PIIX4 0x00
5655 #define I2C_HW_SMBUS_ALI15X3 0x01
5656 @@ -218,9 +285,27 @@
5657 #define I2C_HW_SMBUS_AMD756 0x05
5658 #define I2C_HW_SMBUS_SIS5595 0x06
5659 #define I2C_HW_SMBUS_ALI1535 0x07
5660 +#define I2C_HW_SMBUS_SIS630 0x08
5661 +#define I2C_HW_SMBUS_SIS645 0x09
5662 +#define I2C_HW_SMBUS_AMD8111 0x0a
5663 +#define I2C_HW_SMBUS_SCX200 0x0b
5664 +#define I2C_HW_SMBUS_NFORCE2 0x0c
5665 #define I2C_HW_SMBUS_W9968CF 0x0d
5666 +#define I2C_HW_SMBUS_OV511 0x0e /* OV511(+) USB 1.1 webcam ICs */
5667 +#define I2C_HW_SMBUS_OV518 0x0f /* OV518(+) USB 1.1 webcam ICs */
5668 +#define I2C_HW_SMBUS_OV519 0x10 /* OV519 USB 1.1 webcam IC */
5669 +#define I2C_HW_SMBUS_OVFX2 0x11 /* Cypress/OmniVision FX2 webcam */
5671 /* --- ISA pseudo-adapter */
5672 #define I2C_HW_ISA 0x00
5674 -#endif /* I2C_ID_H */
5675 +/* --- IPMI pseudo-adapter */
5676 +#define I2C_HW_IPMI 0x00
5678 +/* --- IPMB adapter */
5679 +#define I2C_HW_IPMB 0x00
5681 +/* --- MCP107 adapter */
5682 +#define I2C_HW_MPC107 0x00
5684 +#endif /* LINUX_I2C_ID_H */
5685 --- linux-old/drivers/i2c/i2c-pcf-epp.c Thu Jan 1 00:00:00 1970
5686 +++ linux/drivers/i2c/i2c-pcf-epp.c Mon Dec 13 19:26:34 2004
5688 +/* ------------------------------------------------------------------------- */
5689 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters */
5690 +/* ------------------------------------------------------------------------- */
5691 +/* Copyright (C) 1998-99 Hans Berglund
5693 + This program is free software; you can redistribute it and/or modify
5694 + it under the terms of the GNU General Public License as published by
5695 + the Free Software Foundation; either version 2 of the License, or
5696 + (at your option) any later version.
5698 + This program is distributed in the hope that it will be useful,
5699 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5700 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5701 + GNU General Public License for more details.
5703 + You should have received a copy of the GNU General Public License
5704 + along with this program; if not, write to the Free Software
5705 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5706 +/* ------------------------------------------------------------------------- */
5708 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
5710 +#include <linux/kernel.h>
5711 +#include <linux/ioport.h>
5712 +#include <linux/module.h>
5713 +#include <linux/delay.h>
5714 +#include <linux/slab.h>
5715 +#include <linux/init.h>
5716 +#include <linux/parport.h>
5717 +#include <linux/i2c.h>
5718 +#include <linux/i2c-algo-pcf.h>
5719 +#include <asm/irq.h>
5720 +#include <asm/io.h>
5723 +struct i2c_pcf_epp {
5730 +#define DEFAULT_BASE 0x378
5731 +#define DEFAULT_IRQ 7
5732 +#define DEFAULT_CLOCK 0x1c
5733 +#define DEFAULT_OWN 0x55
5735 +static int base = 0;
5736 +static int irq = 0;
5737 +static int clock = 0;
5738 +static int own = 0;
5739 +static int i2c_debug=0;
5740 +static struct i2c_pcf_epp gpe;
5741 +static wait_queue_head_t pcf_wait;
5742 +static int pcf_pending;
5743 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5745 +/* ----- global defines ----------------------------------------------- */
5746 +#define DEB(x) if (i2c_debug>=1) x
5747 +#define DEB2(x) if (i2c_debug>=2) x
5748 +#define DEB3(x) if (i2c_debug>=3) x
5749 +#define DEBE(x) x /* error messages */
5751 +/* --- Convenience defines for the EPP/SPP port: */
5752 +#define BASE ((struct i2c_pcf_epp *)(data))->pe_base
5753 +// #define DATA BASE /* SPP data port */
5754 +#define STAT (BASE+1) /* SPP status port */
5755 +#define CTRL (BASE+2) /* SPP control port */
5756 +#define EADD (BASE+3) /* EPP address port */
5757 +#define EDAT (BASE+4) /* EPP data port */
5759 +/* ----- local functions ---------------------------------------------- */
5761 +static void pcf_epp_setbyte(void *data, int ctl, int val)
5764 + if (gpe.pe_irq > 0) {
5765 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
5766 + val|I2C_PCF_ENI));
5767 + // set A0 pin HIGH
5768 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5769 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5770 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5772 + // EPP write data cycle
5773 + outb(val | I2C_PCF_ENI, EDAT);
5775 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
5776 + // set A0 pin HIGH
5777 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5781 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
5783 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5784 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
5785 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
5790 +static int pcf_epp_getbyte(void *data, int ctl)
5795 + // set A0 pin HIGH
5796 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
5798 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
5801 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
5803 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
5808 +static int pcf_epp_getown(void *data)
5810 + return (gpe.pe_own);
5814 +static int pcf_epp_getclock(void *data)
5816 + return (gpe.pe_clock);
5820 +static void pcf_epp_sleep(unsigned long timeout)
5822 + schedule_timeout( timeout * HZ);
5826 +static void pcf_epp_waitforpin(void) {
5829 + if (gpe.pe_irq > 0) {
5830 + spin_lock_irq(&irq_driver_lock);
5831 + if (pcf_pending == 0) {
5832 + interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
5837 + spin_unlock_irq(&irq_driver_lock);
5843 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
5845 + wake_up_interruptible(&pcf_wait);
5846 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
5850 +static int pcf_epp_init(void *data)
5852 + if (check_region(gpe.pe_base, 5) < 0 ) {
5854 + printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
5857 + request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
5860 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
5862 + if (gpe.pe_irq > 0) {
5863 + if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
5864 + printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
5867 + disable_irq(gpe.pe_irq);
5868 + enable_irq(gpe.pe_irq);
5870 + // EPP mode initialize
5871 + // enable interrupt from nINTR pin
5872 + outb(inb(CTRL)|0x14, CTRL);
5873 + // clear ERROR bit of STAT
5874 + outb(inb(STAT)|0x01, STAT);
5875 + outb(inb(STAT)&~0x01,STAT);
5880 +/* ------------------------------------------------------------------------
5881 + * Encapsulate the above functions in the correct operations structure.
5882 + * This is only done when more than one hardware adapter is supported.
5884 +static struct i2c_algo_pcf_data pcf_epp_data = {
5885 + .setpcf = pcf_epp_setbyte,
5886 + .getpcf = pcf_epp_getbyte,
5887 + .getown = pcf_epp_getown,
5888 + .getclock = pcf_epp_getclock,
5889 + .waitforpin = pcf_epp_waitforpin,
5895 +static struct i2c_adapter pcf_epp_ops = {
5896 + .owner = THIS_MODULE,
5897 + .name = "PCF8584 EPP adapter",
5898 + .id = I2C_HW_P_LP,
5899 + .algo_data = &pcf_epp_data,
5902 +static int __init i2c_pcfepp_init(void)
5904 + struct i2c_pcf_epp *pepp = &gpe;
5906 + printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5908 + pepp->pe_base = DEFAULT_BASE;
5910 + pepp->pe_base = base;
5913 + pepp->pe_irq = DEFAULT_IRQ;
5918 + pepp->pe_irq = irq;
5921 + pepp->pe_clock = DEFAULT_CLOCK;
5923 + pepp->pe_clock = clock;
5926 + pepp->pe_own = DEFAULT_OWN;
5928 + pepp->pe_own = own;
5930 + pcf_epp_data.data = (void *)pepp;
5931 + init_waitqueue_head(&pcf_wait);
5932 + if (pcf_epp_init(pepp) == 0) {
5934 + if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
5935 + printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
5936 + release_region(pepp->pe_base , 5);
5943 + printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
5947 +static void __exit pcf_epp_exit(void)
5949 + i2c_pcf_del_bus(&pcf_epp_ops);
5950 + if (gpe.pe_irq > 0) {
5951 + disable_irq(gpe.pe_irq);
5952 + free_irq(gpe.pe_irq, 0);
5954 + release_region(gpe.pe_base , 5);
5957 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
5958 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
5959 +MODULE_LICENSE("GPL");
5961 +MODULE_PARM(base, "i");
5962 +MODULE_PARM(irq, "i");
5963 +MODULE_PARM(clock, "i");
5964 +MODULE_PARM(own, "i");
5965 +MODULE_PARM(i2c_debug, "i");
5967 +module_init(i2c_pcfepp_init);
5968 +module_exit(pcf_epp_exit);
5969 --- linux-old/include/linux/i2c-pcf8584.h Thu Jan 1 00:00:00 1970
5970 +++ linux/include/linux/i2c-pcf8584.h Mon Dec 13 19:26:34 2004
5972 +/* -------------------------------------------------------------------- */
5973 +/* i2c-pcf8584.h: PCF 8584 global defines */
5974 +/* -------------------------------------------------------------------- */
5975 +/* Copyright (C) 1996 Simon G. Vogl
5976 + 1999 Hans Berglund
5978 + This program is free software; you can redistribute it and/or modify
5979 + it under the terms of the GNU General Public License as published by
5980 + the Free Software Foundation; either version 2 of the License, or
5981 + (at your option) any later version.
5983 + This program is distributed in the hope that it will be useful,
5984 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5985 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5986 + GNU General Public License for more details.
5988 + You should have received a copy of the GNU General Public License
5989 + along with this program; if not, write to the Free Software
5990 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
5991 +/* -------------------------------------------------------------------- */
5993 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
5995 +/* $Id: i2c-pcf8584.h,v 1.6 2003/07/25 07:56:42 khali Exp $ */
5997 +#ifndef _LINUX_I2C_PCF8584_H
5998 +#define _LINUX_I2C_PCF8584_H
6000 +/* ----- Control register bits ---------------------------------------- */
6001 +#define I2C_PCF_PIN 0x80
6002 +#define I2C_PCF_ESO 0x40
6003 +#define I2C_PCF_ES1 0x20
6004 +#define I2C_PCF_ES2 0x10
6005 +#define I2C_PCF_ENI 0x08
6006 +#define I2C_PCF_STA 0x04
6007 +#define I2C_PCF_STO 0x02
6008 +#define I2C_PCF_ACK 0x01
6010 +#define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6011 +#define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
6012 +#define I2C_PCF_REPSTART ( I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6013 +#define I2C_PCF_IDLE (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ACK)
6015 +/* ----- Status register bits ----------------------------------------- */
6016 +/*#define I2C_PCF_PIN 0x80 as above*/
6018 +#define I2C_PCF_INI 0x40 /* 1 if not initialized */
6019 +#define I2C_PCF_STS 0x20
6020 +#define I2C_PCF_BER 0x10
6021 +#define I2C_PCF_AD0 0x08
6022 +#define I2C_PCF_LRB 0x08
6023 +#define I2C_PCF_AAS 0x04
6024 +#define I2C_PCF_LAB 0x02
6025 +#define I2C_PCF_BB 0x01
6027 +/* ----- Chip clock frequencies --------------------------------------- */
6028 +#define I2C_PCF_CLK3 0x00
6029 +#define I2C_PCF_CLK443 0x10
6030 +#define I2C_PCF_CLK6 0x14
6031 +#define I2C_PCF_CLK 0x18
6032 +#define I2C_PCF_CLK12 0x1c
6034 +/* ----- transmission frequencies ------------------------------------- */
6035 +#define I2C_PCF_TRNS90 0x00 /* 90 kHz */
6036 +#define I2C_PCF_TRNS45 0x01 /* 45 kHz */
6037 +#define I2C_PCF_TRNS11 0x02 /* 11 kHz */
6038 +#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */
6041 +/* ----- Access to internal registers according to ES1,ES2 ------------ */
6042 +/* they are mapped to the data port ( a0 = 0 ) */
6043 +/* available when ESO == 0 : */
6045 +#define I2C_PCF_OWNADR 0
6046 +#define I2C_PCF_INTREG I2C_PCF_ES2
6047 +#define I2C_PCF_CLKREG I2C_PCF_ES1
6049 +#endif /* _LINUX_I2C_PCF8584_H */
6050 --- linux-old/drivers/i2c/i2c-philips-par.c Fri Feb 20 01:22:16 2004
6051 +++ linux/drivers/i2c/i2c-philips-par.c Mon Dec 13 19:26:34 2004
6053 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6054 Frodo Looijaard <frodol@dds.nl> */
6056 -/* $Id: i2c-philips-par.c,v 1.18 2000/07/06 19:21:49 frodo Exp $ */
6057 +/* $Id: i2c-philips-par.c,v 1.33 2004/01/23 20:22:53 khali Exp $ */
6059 #include <linux/kernel.h>
6060 #include <linux/ioport.h>
6062 #include <linux/init.h>
6063 #include <linux/stddef.h>
6064 #include <linux/parport.h>
6066 +#include <linux/slab.h>
6067 #include <linux/i2c.h>
6068 #include <linux/i2c-algo-bit.h>
6071 -#define __exit __init
6077 @@ -130,59 +126,34 @@
6078 PARPORT_STATUS_BUSY) ? 0 : 1;
6081 -static int bit_lp_reg(struct i2c_client *client)
6086 -static int bit_lp_unreg(struct i2c_client *client)
6091 -static void bit_lp_inc_use(struct i2c_adapter *adap)
6093 - MOD_INC_USE_COUNT;
6096 -static void bit_lp_dec_use(struct i2c_adapter *adap)
6098 - MOD_DEC_USE_COUNT;
6101 /* ------------------------------------------------------------------------
6102 * Encapsulate the above functions in the correct operations structure.
6103 * This is only done when more than one hardware adapter is supported.
6106 static struct i2c_algo_bit_data bit_lp_data = {
6112 - 80, 80, 100, /* waits, timeout */
6113 + .setsda = bit_lp_setsda,
6114 + .setscl = bit_lp_setscl,
6115 + .getsda = bit_lp_getsda,
6116 + .getscl = bit_lp_getscl,
6122 static struct i2c_algo_bit_data bit_lp_data2 = {
6128 - 80, 80, 100, /* waits, timeout */
6129 + .setsda = bit_lp_setsda2,
6130 + .setscl = bit_lp_setscl2,
6131 + .getsda = bit_lp_getsda2,
6137 static struct i2c_adapter bit_lp_ops = {
6138 - "Philips Parallel port adapter",
6147 + .owner = THIS_MODULE,
6148 + .name = "Philips Parallel port adapter",
6149 + .id = I2C_HW_B_LP,
6152 static void i2c_parport_attach (struct parport *port)
6155 if (!adapter->pdev) {
6156 printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
6161 @@ -210,8 +182,12 @@
6162 adapter->bit_lp_data = type ? bit_lp_data2 : bit_lp_data;
6163 adapter->bit_lp_data.data = port;
6165 + if (parport_claim_or_block(adapter->pdev) < 0 ) {
6166 + printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
6170 /* reset hardware to sane state */
6171 - parport_claim_or_block(adapter->pdev);
6172 adapter->bit_lp_data.setsda(port, 1);
6173 adapter->bit_lp_data.setscl(port, 1);
6174 parport_release(adapter->pdev);
6179 -int __init i2c_bitlp_init(void)
6180 +static int __init i2c_bitlp_init(void)
6182 printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6188 -void __exit i2c_bitlp_exit(void)
6189 +static void __exit i2c_bitlp_exit(void)
6191 parport_unregister_driver(&i2c_driver);
6193 @@ -279,14 +255,5 @@
6195 MODULE_PARM(type, "i");
6198 -int init_module(void)
6200 - return i2c_bitlp_init();
6203 -void cleanup_module(void)
6208 +module_init(i2c_bitlp_init);
6209 +module_exit(i2c_bitlp_exit);
6210 --- linux-old/drivers/i2c/i2c-pport.c Thu Jan 1 00:00:00 1970
6211 +++ linux/drivers/i2c/i2c-pport.c Mon Dec 13 19:26:34 2004
6213 +/* ------------------------------------------------------------------------- */
6214 +/* i2c-pport.c i2c-hw access for primitive i2c par. port adapter */
6215 +/* ------------------------------------------------------------------------- */
6216 +/* Copyright (C) 2001 Daniel Smolik
6218 + This program is free software; you can redistribute it and/or modify
6219 + it under the terms of the GNU General Public License as published by
6220 + the Free Software Foundation; either version 2 of the License, or
6221 + (at your option) any later version.
6223 + This program is distributed in the hope that it will be useful,
6224 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6225 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6226 + GNU General Public License for more details.
6228 + You should have received a copy of the GNU General Public License
6229 + along with this program; if not, write to the Free Software
6230 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6231 +/* ------------------------------------------------------------------------- */
6234 + See doc/i2c-pport for instructions on wiring to the
6235 + parallel port connector.
6237 + Cut & paste :-) based on Velleman K8000 driver by Simon G. Vogl
6239 + Note that SDA is hardware inverted.
6243 +#include <linux/kernel.h>
6244 +#include <linux/module.h>
6245 +#include <linux/delay.h>
6246 +#include <linux/slab.h>
6247 +#include <linux/init.h>
6248 +#include <linux/ioport.h>
6249 +#include <linux/errno.h>
6250 +#include <linux/i2c.h>
6251 +#include <linux/i2c-algo-bit.h>
6252 +#include <asm/io.h>
6255 +#define DEFAULT_BASE 0x378
6256 +static int base = DEFAULT_BASE;
6257 +static unsigned char PortData = 0;
6259 +/* ----- global defines ----------------------------------------------- */
6260 +#define DEB(x) /* should be reasonable open, close &c. */
6261 +#define DEB2(x) /* low level debugging - very slow */
6262 +#define DEBE(x) x /* error messages */
6263 +#define DEBINIT(x) x /* detection status messages */
6265 +/* --- Convenience defines for the parallel port: */
6266 +#define BASE (unsigned int)(data)
6267 +#define DATA BASE /* Centronics data port */
6268 +#define STAT (BASE+1) /* Centronics status port */
6269 +#define CTRL (BASE+2) /* Centronics control port */
6271 +/* we will use SDA - Auto Linefeed(14) POUT (ctrl bit 1) */
6272 +/* we will use SCL - Initialize printer(16) BUSY (ctrl bit 2) */
6274 +#define SET_SCL | 0x04
6275 +#define CLR_SCL & 0xFB
6277 +#define SET_SDA & 0xFD
6278 +#define CLR_SDA | 0x02
6281 +/* ----- local functions ---------------------------------------------- */
6284 +static void bit_pport_setscl(void *data, int state)
6287 + PortData = PortData SET_SCL;
6289 + PortData = PortData CLR_SCL;
6291 + outb(PortData, CTRL);
6294 +static void bit_pport_setsda(void *data, int state)
6297 + PortData = PortData SET_SDA;
6299 + PortData = PortData CLR_SDA;
6301 + outb(PortData, CTRL);
6304 +static int bit_pport_getscl(void *data)
6306 + return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
6309 +static int bit_pport_getsda(void *data)
6311 + return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
6314 +static int bit_pport_init(void)
6316 + if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
6320 + PortData = inb(base+2);
6321 + bit_pport_setsda((void*)base, 1);
6322 + bit_pport_setscl((void*)base, 1);
6328 +/* ------------------------------------------------------------------------
6329 + * Encapsulate the above functions in the correct operations structure.
6330 + * This is only done when more than one hardware adapter is supported.
6332 +static struct i2c_algo_bit_data bit_pport_data = {
6333 + .setsda = bit_pport_setsda,
6334 + .setscl = bit_pport_setscl,
6335 + .getsda = bit_pport_getsda,
6336 + .getscl = bit_pport_getscl,
6342 +static struct i2c_adapter bit_pport_ops = {
6343 + .owner = THIS_MODULE,
6344 + .name = "Primitive Parallel port adaptor",
6345 + .id = I2C_HW_B_PPORT,
6346 + .algo_data = &bit_pport_data,
6349 +static int __init i2c_bitpport_init(void)
6351 + printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6353 + bit_pport_data.data = (void*)base;
6354 + if (bit_pport_init() < 0)
6357 + if (i2c_bit_add_bus(&bit_pport_ops) < 0) {
6358 + release_region(base+2, 1);
6362 + printk("i2c-pport.o: found device at %#x.\n",base);
6366 +static void __exit i2c_bitpport_exit(void)
6368 + i2c_bit_del_bus(&bit_pport_ops);
6369 + release_region((base+2),1);
6374 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
6375 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
6376 +MODULE_LICENSE("GPL");
6378 +MODULE_PARM(base, "i");
6380 +module_init(i2c_bitpport_init);
6381 +module_exit(i2c_bitpport_exit);
6382 --- linux-old/drivers/i2c/i2c-proc.c Tue Jan 20 15:10:31 2004
6383 +++ linux/drivers/i2c/i2c-proc.c Mon Dec 13 19:26:35 2004
6385 This driver puts entries in /proc/sys/dev/sensors for each I2C device
6388 +#include <linux/config.h>
6389 #include <linux/module.h>
6390 #include <linux/kernel.h>
6391 #include <linux/slab.h>
6392 #include <linux/ctype.h>
6393 #include <linux/sysctl.h>
6394 #include <linux/proc_fs.h>
6395 +#include <linux/init.h>
6396 #include <linux/ioport.h>
6397 -#include <asm/uaccess.h>
6399 #include <linux/i2c.h>
6400 #include <linux/i2c-proc.h>
6401 +#include <asm/uaccess.h>
6403 -#include <linux/init.h>
6405 -#ifndef THIS_MODULE
6406 -#define THIS_MODULE NULL
6407 +#ifndef CONFIG_SYSCTL
6408 +#error Your kernel lacks sysctl support (CONFIG_SYSCTL)!
6411 -static int i2c_create_name(char **name, const char *prefix,
6412 - struct i2c_adapter *adapter, int addr);
6413 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6414 long *results, int magnitude);
6415 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
6416 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
6417 long *results, int magnitude);
6418 static int i2c_proc_chips(ctl_table * ctl, int write,
6419 struct file *filp, void *buffer,
6421 void *newval, size_t newlen,
6424 -int __init sensors_init(void);
6426 #define SENSORS_ENTRY_MAX 20
6427 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
6429 static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
6430 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
6432 -static ctl_table sysctl_table[] = {
6433 - {CTL_DEV, "dev", NULL, 0, 0555},
6435 - {DEV_SENSORS, "sensors", NULL, 0, 0555},
6437 - {0, NULL, NULL, 0, 0555},
6441 static ctl_table i2c_proc_dev_sensors[] = {
6442 {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips,
6446 static struct ctl_table_header *i2c_proc_header;
6447 -static int i2c_initialized;
6449 /* This returns a nice name for a new directory; for example lm78-isa-0310
6450 (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for
6451 a LM75 chip on the third i2c bus at address 0x4e).
6452 name is allocated first. */
6453 -int i2c_create_name(char **name, const char *prefix,
6454 - struct i2c_adapter *adapter, int addr)
6455 +static char *generate_name(struct i2c_client *client, const char *prefix)
6457 - char name_buffer[50];
6459 - if (i2c_is_isa_adapter(adapter))
6460 + struct i2c_adapter *adapter = client->adapter;
6461 + int addr = client->addr;
6462 + char name_buffer[50], *name;
6464 + if (i2c_is_isa_adapter(adapter)) {
6465 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
6467 - if ((id = i2c_adapter_id(adapter)) < 0)
6469 + } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
6470 + int id = i2c_adapter_id(adapter);
6472 + return ERR_PTR(-ENOENT);
6473 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
6474 + } else { /* dummy adapter, generate prefix */
6477 + sprintf(name_buffer, "%s-", prefix);
6478 + end = strlen(name_buffer);
6480 + for (i = 0; i < 32; i++) {
6481 + if (adapter->algo->name[i] == ' ')
6483 + name_buffer[end++] = tolower(adapter->algo->name[i]);
6486 + name_buffer[end] = 0;
6487 + sprintf(name_buffer + end, "-%04x", addr);
6489 - *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
6491 - printk (KERN_WARNING "i2c_create_name: not enough memory\n");
6494 - strcpy(*name, name_buffer);
6497 + name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
6499 + return ERR_PTR(-ENOMEM);
6500 + strcpy(name, name_buffer);
6504 /* This rather complex function must be called when you want to add an entry
6505 @@ -124,139 +123,91 @@
6506 ctl_template should be a template of the newly created directory. It is
6507 copied in memory. The extra2 field of each file is set to point to client.
6508 If any driver wants subdirectories within the newly created directory,
6509 - this function must be updated!
6510 - controlling_mod is the controlling module. It should usually be
6511 - THIS_MODULE when calling. Note that this symbol is not defined in
6512 - kernels before 2.3.13; define it to NULL in that case. We will not use it
6513 - for anything older than 2.3.27 anyway. */
6514 + this function must be updated! */
6515 int i2c_register_entry(struct i2c_client *client, const char *prefix,
6516 - ctl_table * ctl_template,
6517 - struct module *controlling_mod)
6518 + struct ctl_table *ctl_template)
6520 - int i, res, len, id;
6521 - ctl_table *new_table;
6523 - struct ctl_table_header *new_header;
6525 - if ((res = i2c_create_name(&name, prefix, client->adapter,
6526 - client->addr))) return res;
6527 + struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
6528 + struct ctl_table_header *hdr;
6529 + struct ctl_table *tmp, *leaf;
6533 - for (id = 0; id < SENSORS_ENTRY_MAX; id++)
6534 - if (!i2c_entries[id]) {
6537 - if (id == SENSORS_ENTRY_MAX) {
6542 + name = generate_name(client, prefix);
6544 + return PTR_ERR(name);
6547 - while (ctl_template[len].procname)
6550 - if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
6555 - memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
6556 - new_table[0].child = &new_table[2];
6557 - new_table[2].child = &new_table[4];
6558 - new_table[4].child = &new_table[6];
6559 - new_table[4].procname = name;
6560 - new_table[4].ctl_name = id;
6561 - memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
6562 - for (i = 6; i < len; i++)
6563 - new_table[i].extra2 = client;
6565 - if (!(new_header = register_sysctl_table(new_table, 0))) {
6569 + for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
6570 + if (!i2c_entries[id])
6574 - i2c_entries[id - 256] = new_header;
6575 + goto out_free_name;
6577 - i2c_clients[id - 256] = client;
6579 - if (!new_header || !new_header->ctl_table ||
6580 - !new_header->ctl_table->child ||
6581 - !new_header->ctl_table->child->child ||
6582 - !new_header->ctl_table->child->child->de) {
6584 - ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
6588 - i2c_inodes[id - 256] =
6589 - new_header->ctl_table->child->child->de->low_ino;
6590 - new_header->ctl_table->child->child->de->owner = controlling_mod;
6594 + while (ctl_template[len].ctl_name)
6596 + tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1),
6599 + goto out_free_name;
6600 + memset(tbl, 0, sizeof(*tbl));
6602 + /* The client sysctls */
6603 + leaf = (struct ctl_table *) (tbl + 1);
6604 + memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
6605 + for (tmp = leaf; tmp->ctl_name; tmp++)
6606 + tmp->extra2 = client;
6608 + tbl->sensors->ctl_name = id+256;
6609 + tbl->sensors->procname = name;
6610 + tbl->sensors->mode = 0555;
6611 + tbl->sensors->child = leaf;
6613 + tbl->dev->ctl_name = DEV_SENSORS;
6614 + tbl->dev->procname = "sensors";
6615 + tbl->dev->mode = 0555;
6616 + tbl->dev->child = tbl->sensors;
6618 + tbl->root->ctl_name = CTL_DEV;
6619 + tbl->root->procname = "dev";
6620 + tbl->root->mode = 0555;
6621 + tbl->root->child = tbl->dev;
6623 + hdr = register_sysctl_table(tbl->root, 0);
6625 + goto out_free_tbl;
6627 + i2c_entries[id] = hdr;
6628 + i2c_clients[id] = client;
6630 + return (id + 256); /* XXX(hch) why?? */
6639 void i2c_deregister_entry(int id)
6644 - if (i2c_entries[id]) {
6645 - table = i2c_entries[id]->ctl_table;
6646 - unregister_sysctl_table(i2c_entries[id]);
6647 - /* 2-step kfree needed to keep gcc happy about const points */
6648 - (const char *) temp = table[4].procname;
6651 - i2c_entries[id] = NULL;
6652 - i2c_clients[id] = NULL;
6656 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o
6657 - impossible if some process still uses it or some file in it */
6658 -void i2c_fill_inode(struct inode *inode, int fill)
6661 - MOD_INC_USE_COUNT;
6663 - MOD_DEC_USE_COUNT;
6666 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
6667 - the corresponding module impossible if some process still uses it or
6668 - some file in it */
6669 -void i2c_dir_fill_inode(struct inode *inode, int fill)
6672 - struct i2c_client *client;
6673 + if (i2c_entries[id]) {
6674 + struct ctl_table_header *hdr = i2c_entries[id];
6675 + struct ctl_table *tbl = hdr->ctl_table;
6679 - printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
6681 + unregister_sysctl_table(hdr);
6682 + kfree(tbl->child->child->procname);
6683 + kfree(tbl); /* actually the whole anonymous struct */
6685 -#endif /* def DEBUG */
6687 - for (i = 0; i < SENSORS_ENTRY_MAX; i++)
6688 - if (i2c_clients[i]
6689 - && (i2c_inodes[i] == inode->i_ino)) break;
6691 - if (i == SENSORS_ENTRY_MAX) {
6693 - ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
6697 -#endif /* def DEBUG */
6698 - client = i2c_clients[i];
6700 - client->driver->inc_use(client);
6702 - client->driver->dec_use(client);
6703 + i2c_entries[id] = NULL;
6704 + i2c_clients[id] = NULL;
6707 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6708 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
6709 void *buffer, size_t * lenp)
6711 char BUF[SENSORS_PREFIX_MAX + 30];
6716 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6717 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
6718 void *oldval, size_t * oldlenp, void *newval,
6719 size_t newlen, void **context)
6722 WARNING! This is tricky code. I have tested it, but there may still be
6723 hidden bugs in it, even leading to crashes and things!
6725 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6726 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
6727 long *results, int magnitude)
6729 int maxels, min, mag;
6734 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
6735 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
6736 long *results, int magnitude)
6740 I2C_FUNC_SMBUS_QUICK)) return -1;
6742 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
6743 + /* XXX: WTF is going on here??? */
6744 if ((is_isa && check_region(addr, 1)) ||
6745 (!is_isa && i2c_check_addr(adapter, addr)))
6747 @@ -846,46 +798,33 @@
6751 -int __init sensors_init(void)
6752 +static int __init i2c_proc_init(void)
6754 printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
6755 - i2c_initialized = 0;
6758 - register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
6759 + register_sysctl_table(i2c_proc, 0))) {
6760 + printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
6763 i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
6764 - i2c_initialized++;
6768 +static void __exit i2c_proc_exit(void)
6770 + unregister_sysctl_table(i2c_proc_header);
6773 +EXPORT_SYMBOL(i2c_register_entry);
6774 EXPORT_SYMBOL(i2c_deregister_entry);
6775 -EXPORT_SYMBOL(i2c_detect);
6776 EXPORT_SYMBOL(i2c_proc_real);
6777 -EXPORT_SYMBOL(i2c_register_entry);
6778 EXPORT_SYMBOL(i2c_sysctl_real);
6781 +EXPORT_SYMBOL(i2c_detect);
6783 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
6784 MODULE_DESCRIPTION("i2c-proc driver");
6785 MODULE_LICENSE("GPL");
6787 -int i2c_cleanup(void)
6789 - if (i2c_initialized >= 1) {
6790 - unregister_sysctl_table(i2c_proc_header);
6791 - i2c_initialized--;
6796 -int init_module(void)
6798 - return sensors_init();
6801 -int cleanup_module(void)
6803 - return i2c_cleanup();
6805 -#endif /* MODULE */
6806 +module_init(i2c_proc_init);
6807 +module_exit(i2c_proc_exit);
6808 --- linux-old/include/linux/i2c-proc.h Tue Nov 6 00:55:29 2001
6809 +++ linux/include/linux/i2c-proc.h Mon Dec 13 19:26:36 2004
6812 - sensors.h - Part of lm_sensors, Linux kernel modules for hardware
6814 + i2c-proc.h - Part of the i2c package
6815 + was originally sensors.h - Part of lm_sensors, Linux kernel modules
6816 + for hardware monitoring
6817 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
6819 This program is free software; you can redistribute it and/or modify
6821 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6824 -#ifndef SENSORS_SENSORS_H
6825 -#define SENSORS_SENSORS_H
6826 +#ifndef _LINUX_I2C_PROC_H
6827 +#define _LINUX_I2C_PROC_H
6831 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
6832 -#include <linux/types.h>
6833 -#include <linux/fs.h>
6834 #include <linux/sysctl.h>
6836 /* The type of callback functions used in sensors_{proc,sysctl}_real */
6838 these functions must be updated! */
6839 extern int i2c_register_entry(struct i2c_client *client,
6841 - ctl_table * ctl_template,
6842 - struct module *controlling_mod);
6843 + ctl_table * ctl_template);
6845 extern void i2c_deregister_entry(int id);
6847 @@ -347,6 +342,31 @@
6851 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
6852 + enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
6853 + SENSORS_MODULE_PARM(force, \
6854 + "List of adapter,address pairs to boldly assume " \
6855 + "to be present"); \
6856 + SENSORS_MODULE_PARM_FORCE(chip1); \
6857 + SENSORS_MODULE_PARM_FORCE(chip2); \
6858 + SENSORS_MODULE_PARM_FORCE(chip3); \
6859 + SENSORS_MODULE_PARM_FORCE(chip4); \
6860 + SENSORS_MODULE_PARM_FORCE(chip5); \
6861 + SENSORS_MODULE_PARM_FORCE(chip6); \
6862 + SENSORS_MODULE_PARM_FORCE(chip7); \
6863 + SENSORS_MODULE_PARM_FORCE(chip8); \
6864 + static struct i2c_force_data forces[] = {{force,any_chip}, \
6865 + {force_ ## chip1,chip1}, \
6866 + {force_ ## chip2,chip2}, \
6867 + {force_ ## chip3,chip3}, \
6868 + {force_ ## chip4,chip4}, \
6869 + {force_ ## chip5,chip5}, \
6870 + {force_ ## chip6,chip6}, \
6871 + {force_ ## chip7,chip7}, \
6872 + {force_ ## chip8,chip8}, \
6876 typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
6877 int addr, unsigned short flags,
6881 /* This macro is used to scale user-input to sensible values in almost all
6883 -extern inline int SENSORS_LIMIT(long value, long low, long high)
6884 +static inline int SENSORS_LIMIT(long value, long low, long high)
6892 -#endif /* def __KERNEL__ */
6895 /* The maximum length of the prefix */
6896 #define SENSORS_PREFIX_MAX 20
6898 char name[SENSORS_PREFIX_MAX + 13];
6901 -#endif /* def SENSORS_SENSORS_H */
6902 +#endif /* def _LINUX_I2C_PROC_H */
6904 --- linux-old/drivers/i2c/i2c-rpx.c Thu Jan 1 00:00:00 1970
6905 +++ linux/drivers/i2c/i2c-rpx.c Mon Dec 13 19:26:36 2004
6908 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
6909 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
6911 + * moved into proper i2c interface;
6912 + * Brad Parker (brad@heeltoe.com)
6914 + * RPX lite specific parts of the i2c interface
6915 + * Update: There actually isn't anything RPXLite-specific about this module.
6916 + * This should work for most any 8xx board. The console messages have been
6917 + * changed to eliminate RPXLite references.
6920 +#include <linux/kernel.h>
6921 +#include <linux/module.h>
6922 +#include <linux/init.h>
6923 +#include <linux/stddef.h>
6924 +#include <linux/i2c.h>
6925 +#include <linux/i2c-algo-8xx.h>
6926 +#include <asm/mpc8xx.h>
6927 +#include <asm/commproc.h>
6931 +rpx_iic_init(struct i2c_algo_8xx_data *data)
6933 + volatile cpm8xx_t *cp;
6934 + volatile immap_t *immap;
6936 + cp = cpmp; /* Get pointer to Communication Processor */
6937 + immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
6939 + data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
6941 + /* Check for and use a microcode relocation patch.
6943 + if ((data->reloc = data->iip->iic_rpbase))
6944 + data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
6946 + data->i2c = (i2c8xx_t *)&(immap->im_i2c);
6949 + /* Initialize Port B IIC pins.
6951 + cp->cp_pbpar |= 0x00000030;
6952 + cp->cp_pbdir |= 0x00000030;
6953 + cp->cp_pbodr |= 0x00000030;
6955 + /* Allocate space for two transmit and two receive buffer
6956 + * descriptors in the DP ram.
6958 + data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
6960 + /* ptr to i2c area */
6961 + data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
6964 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
6966 + /* install interrupt handler */
6967 + cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
6972 +static struct i2c_algo_8xx_data rpx_data = {
6973 + .setisr = rpx_install_isr
6976 +static struct i2c_adapter rpx_ops = {
6977 + .owner = THIS_MODULE,
6979 + .id = I2C_HW_MPC8XX_EPON,
6980 + .algo_data = &rpx_data,
6983 +static int __init i2c_rpx_init(void)
6985 + printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6987 + /* reset hardware to sane state */
6988 + rpx_iic_init(&rpx_data);
6990 + if (i2c_8xx_add_bus(&rpx_ops) < 0) {
6991 + printk("i2c-rpx: Unable to register with I2C\n");
6998 +static void __exit i2c_rpx_exit(void)
7000 + i2c_8xx_del_bus(&rpx_ops);
7003 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
7004 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
7006 +module_init(i2c_rpx_init);
7007 +module_exit(i2c_rpx_exit);
7008 --- linux-old/drivers/i2c/i2c-velleman.c Tue Jan 20 15:10:31 2004
7009 +++ linux/drivers/i2c/i2c-velleman.c Mon Dec 13 19:26:36 2004
7011 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7012 /* ------------------------------------------------------------------------- */
7014 -/* $Id: i2c-velleman.c,v 1.19 2000/01/24 02:06:33 mds Exp $ */
7015 +/* $Id: i2c-velleman.c,v 1.33 2003/12/24 17:49:44 khali Exp $ */
7017 #include <linux/kernel.h>
7018 #include <linux/ioport.h>
7019 #include <linux/module.h>
7020 #include <linux/init.h>
7021 -#include <linux/string.h> /* for 2.0 kernels to get NULL */
7022 -#include <asm/errno.h> /* for 2.0 kernels to get ENODEV */
7023 -#include <asm/io.h>
7025 +#include <linux/errno.h>
7026 +#include <linux/delay.h>
7027 #include <linux/i2c.h>
7028 #include <linux/i2c-algo-bit.h>
7029 +#include <asm/io.h>
7030 +#include <asm/param.h> /* for HZ */
7032 /* ----- global defines ----------------------------------------------- */
7033 #define DEB(x) /* should be reasonable open, close &c. */
7036 static int bit_velle_init(void)
7038 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
7039 - DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
7041 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
7042 + "i2c (Vellemann adapter)"))
7045 - request_region(base, (base == 0x3bc)? 3 : 8,
7046 - "i2c (Vellemann adapter)");
7047 - bit_velle_setsda((void*)base,1);
7048 - bit_velle_setscl((void*)base,1);
7053 -static void __exit bit_velle_exit(void)
7055 - release_region( base , (base == 0x3bc)? 3 : 8 );
7059 -static int bit_velle_reg(struct i2c_client *client)
7064 -static int bit_velle_unreg(struct i2c_client *client)
7066 + bit_velle_setsda((void*)base,1);
7067 + bit_velle_setscl((void*)base,1);
7071 -static void bit_velle_inc_use(struct i2c_adapter *adap)
7074 - MOD_INC_USE_COUNT;
7078 -static void bit_velle_dec_use(struct i2c_adapter *adap)
7081 - MOD_DEC_USE_COUNT;
7085 /* ------------------------------------------------------------------------
7086 * Encapsulate the above functions in the correct operations structure.
7087 * This is only done when more than one hardware adapter is supported.
7090 static struct i2c_algo_bit_data bit_velle_data = {
7096 - 10, 10, 100, /* waits, timeout */
7097 + .setsda = bit_velle_setsda,
7098 + .setscl = bit_velle_setscl,
7099 + .getsda = bit_velle_getsda,
7100 + .getscl = bit_velle_getscl,
7106 static struct i2c_adapter bit_velle_ops = {
7111 - bit_velle_inc_use,
7112 - bit_velle_dec_use,
7115 + .owner = THIS_MODULE,
7116 + .name = "Velleman K8000",
7117 + .id = I2C_HW_B_VELLE,
7118 + .algo_data = &bit_velle_data,
7121 -int __init i2c_bitvelle_init(void)
7122 +static int __init i2c_bitvelle_init(void)
7124 printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7126 @@ -184,24 +147,19 @@
7130 +static void __exit i2c_bitvelle_exit(void)
7132 + i2c_bit_del_bus(&bit_velle_ops);
7133 + release_region(base, (base == 0x3bc) ? 3 : 8);
7139 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
7140 MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
7141 MODULE_LICENSE("GPL");
7143 MODULE_PARM(base, "i");
7145 -int init_module(void)
7147 - return i2c_bitvelle_init();
7150 -void cleanup_module(void)
7152 - i2c_bit_del_bus(&bit_velle_ops);
7157 +module_init(i2c_bitvelle_init);
7158 +module_exit(i2c_bitvelle_exit);
7159 --- linux-old/include/linux/i2c.h Tue Jan 20 15:10:34 2004
7160 +++ linux/include/linux/i2c.h Mon Dec 13 19:26:37 2004
7162 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
7163 Frodo Looijaard <frodol@dds.nl> */
7165 -/* $Id: i2c.h,v 1.46 2001/08/31 00:04:07 phil Exp $ */
7166 +/* $Id: i2c.h,v 1.80 2004/10/07 23:47:17 phil Exp $ */
7170 +#ifndef _LINUX_I2C_H
7171 +#define _LINUX_I2C_H
7173 -#define I2C_DATE "20010830"
7174 -#define I2C_VERSION "2.6.1"
7175 +#define I2C_DATE "20041007"
7176 +#define I2C_VERSION "2.8.8"
7178 -#include <linux/i2c-id.h> /* id values of adapters et. al. */
7179 +#include <linux/module.h>
7180 #include <linux/types.h>
7188 -/* --- Includes and compatibility declarations ------------------------ */
7190 +#include <linux/errno.h>
7191 +#include <linux/sched.h>
7192 #include <asm/semaphore.h>
7193 -#include <linux/config.h>
7194 +#include <linux/i2c-id.h>
7196 +#include <linux/version.h>
7197 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
7198 +#define MODULE_LICENSE(x)
7201 /* --- General options ------------------------------------------------ */
7203 -#define I2C_ALGO_MAX 4 /* control memory consumption */
7204 -#define I2C_ADAP_MAX 16
7205 +#define I2C_ADAP_MAX 16 /* control memory consumption */
7206 #define I2C_DRIVER_MAX 16
7207 #define I2C_CLIENT_MAX 32
7208 -#define I2C_DUMMY_MAX 4
7211 struct i2c_algorithm;
7215 struct i2c_client_address_data;
7216 union i2c_smbus_data;
7220 * The master routines are the ones normally used to transmit data to devices
7221 * on a bus (or read from them). Apart from two basic transfer functions to
7223 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
7224 u8 command, u8 length,
7226 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
7227 + u8 command, u8 *values);
7228 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
7229 u8 command, u8 length,
7235 + struct module *owner;
7238 unsigned int flags; /* div., see below */
7239 @@ -148,18 +147,6 @@
7242 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
7244 - /* These two are mainly used for bookkeeping & dynamic unloading of
7245 - * kernel modules. inc_use tells the driver that a client is being
7246 - * used by another module & that it should increase its ref. counter.
7247 - * dec_use is the inverse operation.
7248 - * NB: Make sure you have no circular dependencies, or else you get a
7249 - * deadlock when trying to unload the modules.
7250 - * You should use the i2c_{inc,dec}_use_client functions instead of
7251 - * calling this function directly.
7253 - void (*inc_use)(struct i2c_client *client);
7254 - void (*dec_use)(struct i2c_client *client);
7259 * to name two of the most common.
7261 struct i2c_algorithm {
7262 + struct module *owner; /* future use --km */
7263 char name[32]; /* textual description */
7266 @@ -221,16 +209,13 @@
7267 * with the access algorithms necessary to access it.
7269 struct i2c_adapter {
7270 + struct module *owner;
7271 char name[32]; /* some useful name to identify the adapter */
7272 unsigned int id;/* == is algo->id | hwdep.struct->id, */
7273 /* for registered values see below */
7274 struct i2c_algorithm *algo;/* the algorithm to access the bus */
7277 - /* --- These may be NULL, but should increase the module use count */
7278 - void (*inc_use)(struct i2c_adapter *);
7279 - void (*dec_use)(struct i2c_adapter *);
7281 /* --- administration stuff. */
7282 int (*client_register)(struct i2c_client *);
7283 int (*client_unregister)(struct i2c_client *);
7284 @@ -241,11 +226,11 @@
7285 /* and can be set via the i2c_ioctl call */
7287 /* data fields that are valid for all devices */
7288 - struct semaphore lock;
7289 + struct semaphore bus;
7290 + struct semaphore list;
7291 unsigned int flags;/* flags specifying div. data */
7293 struct i2c_client *clients[I2C_CLIENT_MAX];
7299 #define I2C_CLIENT_ALLOW_USE 0x01 /* Client allows access */
7300 #define I2C_CLIENT_ALLOW_MULTIPLE_USE 0x02 /* Allow multiple access-locks */
7301 /* on an i2c_client */
7302 +#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
7303 +#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
7304 + /* Must equal I2C_M_TEN below */
7306 /* i2c_client_address_data is the struct for holding default client
7307 * addresses for a driver and for the parameters supplied on the
7308 @@ -302,12 +290,6 @@
7309 extern int i2c_attach_client(struct i2c_client *);
7310 extern int i2c_detach_client(struct i2c_client *);
7312 -/* Only call these if you grab a resource that makes unloading the
7313 - client and the adapter it is on completely impossible. Like when a
7314 - /proc directory is entered. */
7315 -extern void i2c_inc_use_client(struct i2c_client *);
7316 -extern void i2c_dec_use_client(struct i2c_client *);
7318 /* New function: This is to get an i2c_client-struct for controlling the
7319 client either by using i2c_control-function or having the
7320 client-module export functions that can be used with the i2c_client
7321 @@ -341,6 +323,15 @@
7322 struct i2c_client_address_data *address_data,
7323 i2c_client_found_addr_proc *found_proc);
7325 +static inline int i2c_client_command(struct i2c_client *client,
7326 + unsigned int cmd, void *arg)
7328 + if (client->driver && client->driver->command)
7329 + return client->driver->command(client, cmd, arg);
7334 /* An ioctl like call to set div. parameters of the adapter.
7336 extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
7338 /* Return 1 if adapter supports everything we need, 0 if not. */
7339 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
7341 -#endif /* __KERNEL__ */
7344 * I2C Message - used for pure i2c transaction, also from /dev interface
7346 @@ -370,15 +359,28 @@
7347 #define I2C_M_RD 0x01
7348 #define I2C_M_NOSTART 0x4000
7349 #define I2C_M_REV_DIR_ADDR 0x2000
7350 +#define I2C_M_IGNORE_NAK 0x1000
7351 +#define I2C_M_NO_RD_ACK 0x0800
7352 +#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
7353 +#define I2C_M_RECV_PEC 0x0200 /* receive one more than the returned
7354 + length byte for the PEC */
7355 __u16 len; /* msg length */
7356 __u8 *buf; /* pointer to msg data */
7361 /* To determine what functionality is present */
7363 #define I2C_FUNC_I2C 0x00000001
7364 #define I2C_FUNC_10BIT_ADDR 0x00000002
7365 -#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
7366 +#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
7367 +#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
7368 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */
7369 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */
7370 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */
7371 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
7372 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
7373 #define I2C_FUNC_SMBUS_QUICK 0x00010000
7374 #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
7375 #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
7376 @@ -389,8 +391,12 @@
7377 #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
7378 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
7379 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
7380 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* New I2C-like block */
7381 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
7382 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
7383 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
7384 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
7385 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
7386 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */
7387 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
7389 #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
7390 I2C_FUNC_SMBUS_WRITE_BYTE
7391 @@ -402,13 +408,28 @@
7392 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7393 #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
7394 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
7395 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
7396 + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
7397 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
7398 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
7399 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
7400 + I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
7402 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_DATA
7403 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC I2C_FUNC_SMBUS_WRITE_BYTE_DATA
7404 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA
7405 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC I2C_FUNC_SMBUS_WRITE_WORD_DATA
7406 +#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_BYTE_DATA
7407 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC I2C_FUNC_SMBUS_WORD_DATA
7409 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
7410 I2C_FUNC_SMBUS_BYTE | \
7411 I2C_FUNC_SMBUS_BYTE_DATA | \
7412 I2C_FUNC_SMBUS_WORD_DATA | \
7413 I2C_FUNC_SMBUS_PROC_CALL | \
7414 - I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
7415 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
7416 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
7417 + I2C_FUNC_SMBUS_I2C_BLOCK
7420 * Data for SMBus Messages
7422 union i2c_smbus_data {
7425 - __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
7426 + __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
7427 /* one more for read length in block process call */
7428 + /* and one more for PEC */
7431 /* smbus_access read or write markers */
7432 @@ -435,6 +457,11 @@
7433 #define I2C_SMBUS_PROC_CALL 4
7434 #define I2C_SMBUS_BLOCK_DATA 5
7435 #define I2C_SMBUS_I2C_BLOCK_DATA 6
7436 +#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
7437 +#define I2C_SMBUS_BLOCK_DATA_PEC 8 /* SMBus 2.0 */
7438 +#define I2C_SMBUS_PROC_CALL_PEC 9 /* SMBus 2.0 */
7439 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC 10 /* SMBus 2.0 */
7440 +#define I2C_SMBUS_WORD_DATA_PEC 11 /* SMBus 2.0 */
7443 /* ----- commands for the ioctl like i2c_command call:
7446 #define I2C_FUNCS 0x0705 /* Get the adapter functionality */
7447 #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/
7448 +#define I2C_PEC 0x0708 /* != 0 for SMBus PEC */
7450 #define I2C_ACK_TEST 0x0710 /* See if a slave is at a specific address */
7452 @@ -475,16 +503,6 @@
7454 #define I2C_MAJOR 89 /* Device major number */
7459 -# define NULL ( (void *) 0 )
7463 -# include <asm/errno.h>
7466 /* These defines are used for probing i2c client addresses */
7467 /* Default fill of many variables */
7468 #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
7469 @@ -546,5 +564,11 @@
7470 #define i2c_is_isa_adapter(adapptr) \
7471 ((adapptr)->algo->id == I2C_ALGO_ISA)
7473 -#endif /* def __KERNEL__ */
7475 +/* Tiny delay function used by the i2c bus drivers */
7476 +static inline void i2c_delay(signed long timeout)
7478 + set_current_state(TASK_INTERRUPTIBLE);
7479 + schedule_timeout(timeout);
7482 +#endif /* _LINUX_I2C_H */