1 diff -ruN linux-2.4.23-rc1-orig/drivers/acorn/char/i2c.c linux-2.4.23-rc1-i2c/drivers/acorn/char/i2c.c
2 --- linux-2.4.23-rc1-orig/drivers/acorn/char/i2c.c Wed Aug 27 18:11:45 2003
3 +++ linux-2.4.23-rc1-i2c/drivers/acorn/char/i2c.c Sat Nov 15 17:36:24 2003
7 static struct i2c_algo_bit_data ioc_data = {
15 + .setsda = ioc_setsda,
16 + .setscl = ioc_setscl,
17 + .getsda = ioc_getsda,
18 + .getscl = ioc_getscl,
24 static int ioc_client_reg(struct i2c_client *client)
28 static struct i2c_adapter ioc_ops = {
31 - algo_data: &ioc_data,
32 - client_register: ioc_client_reg,
33 - client_unregister: ioc_client_unreg
34 + .owner = THIS_MODULE,
37 + .algo_data = &ioc_data,
38 + .client_register = ioc_client_reg,
39 + .client_unregister = ioc_client_unreg,
42 static int __init i2c_ioc_init(void)
43 diff -ruN linux-2.4.23-rc1-orig/drivers/acorn/char/pcf8583.c linux-2.4.23-rc1-i2c/drivers/acorn/char/pcf8583.c
44 --- linux-2.4.23-rc1-orig/drivers/acorn/char/pcf8583.c Tue Jul 15 12:23:25 2003
45 +++ linux-2.4.23-rc1-i2c/drivers/acorn/char/pcf8583.c Sat Nov 15 17:36:24 2003
47 static unsigned short normal_addr[] = { 0x50, I2C_CLIENT_END };
49 static struct i2c_client_address_data addr_data = {
50 - normal_i2c: normal_addr,
51 - normal_i2c_range: ignore,
53 - probe_range: ignore,
55 - ignore_range: ignore,
57 + .normal_i2c = normal_addr,
58 + .normal_i2c_range = ignore,
60 + .probe_range = ignore,
62 + .ignore_range = ignore,
66 #define DAT(x) ((unsigned int)(x->data))
70 strcpy(c->name, "PCF8583");
71 + c->name = THIS_MODULE;
72 c->id = pcf8583_driver.id;
78 static struct i2c_driver pcf8583_driver = {
80 - id: I2C_DRIVERID_PCF8583,
81 - flags: I2C_DF_NOTIFY,
82 - attach_adapter: pcf8583_probe,
83 - detach_client: pcf8583_detach,
84 - command: pcf8583_command
85 + .owner = THIS_MODULE,
87 + .id = I2C_DRIVERID_PCF8583,
88 + .flags = I2C_DF_NOTIFY,
89 + .attach_adapter = pcf8583_probe,
90 + .detach_client = pcf8583_detach,
91 + .command = pcf8583_command,
94 static __init int pcf8583_init(void)
95 --- linux-2.4.23-rc1-orig/drivers/i2c/Config.in Wed Aug 27 18:11:46 2003
96 +++ linux-2.4.23-rc1-i2c/drivers/i2c/Config.in Sat Nov 15 20:36:59 2003
98 dep_tristate ' Philips style parallel port adapter' CONFIG_I2C_PHILIPSPAR $CONFIG_I2C_ALGOBIT $CONFIG_PARPORT
99 dep_tristate ' ELV adapter' CONFIG_I2C_ELV $CONFIG_I2C_ALGOBIT
100 dep_tristate ' Velleman K9000 adapter' CONFIG_I2C_VELLEMAN $CONFIG_I2C_ALGOBIT
101 - dep_tristate ' NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200 $CONFIG_I2C_ALGOBIT
102 + if [ "$CONFIG_ARCH_SA1100" = "y" ]; then
103 + dep_tristate 'SA1100 I2C Adapter' CONFIG_I2C_FRODO $CONFIG_I2C_ALGOBIT
105 + dep_tristate ' NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200_GPIO $CONFIG_I2C_ALGOBIT
106 if [ "$CONFIG_SCx200_I2C" != "n" ]; then
107 int ' GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
108 int ' GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
110 - dep_tristate ' NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
113 + dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
115 dep_tristate 'I2C PCF 8584 interfaces' CONFIG_I2C_ALGOPCF $CONFIG_I2C
116 if [ "$CONFIG_I2C_ALGOPCF" != "n" ]; then
117 dep_tristate ' Elektor ISA card' CONFIG_I2C_ELEKTOR $CONFIG_I2C_ALGOPCF
118 + dep_tristate ' PCF on EPP port' CONFIG_I2C_PCFEPP $CONFIG_I2C_ALGOPCF
121 if [ "$CONFIG_MIPS_ITE8172" = "y" ]; then
123 if [ "$CONFIG_8xx" = "y" ]; then
124 dep_tristate 'MPC8xx CPM I2C interface' CONFIG_I2C_ALGO8XX $CONFIG_I2C
125 if [ "$CONFIG_RPXLITE" = "y" -o "$CONFIG_RPXCLASSIC" = "y" ]; then
126 - dep_tristate ' Embedded Planet RPX Lite/Classic suppoort' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
127 + dep_tristate ' Embedded Planet RPX Lite/Classic support' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
130 - if [ "$CONFIG_405" = "y" ]; then
131 - dep_tristate 'PPC 405 I2C Algorithm' CONFIG_I2C_PPC405_ALGO $CONFIG_I2C
132 - if [ "$CONFIG_I2C_PPC405_ALGO" != "n" ]; then
133 - dep_tristate ' PPC 405 I2C Adapter' CONFIG_I2C_PPC405_ADAP $CONFIG_I2C_PPC405_ALGO
134 + if [ "$CONFIG_IBM_OCP" = "y" ]; then
135 + dep_tristate 'IBM on-chip I2C Algorithm' CONFIG_I2C_IBM_OCP_ALGO $CONFIG_I2C
136 + if [ "$CONFIG_I2C_IBM_OCP_ALGO" != "n" ]; then
137 + dep_tristate ' IBM on-chip I2C Adapter' CONFIG_I2C_IBM_OCP_ADAP $CONFIG_I2C_IBM_OCP_ALGO
142 # This is needed for automatic patch generation: sensors code ends here
144 dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C
145 - dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C
146 + dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C $CONFIG_SYSCTL
150 --- linux-2.4.23-rc1-orig/drivers/i2c/Makefile Wed Aug 27 18:11:46 2003
151 +++ linux-2.4.23-rc1-i2c/drivers/i2c/Makefile Sat Nov 15 20:37:44 2003
155 export-objs := i2c-core.o i2c-algo-bit.o i2c-algo-pcf.o \
156 - i2c-algo-ite.o i2c-proc.o i2c-algo-sibyte.o
157 + i2c-algo-ite.o i2c-proc.o i2c-algo-sibyte.o \
158 + i2c-algo-8xx.o i2c-algo-ibm_ocp.o
160 obj-$(CONFIG_I2C) += i2c-core.o
161 obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
163 obj-$(CONFIG_I2C_PHILIPSPAR) += i2c-philips-par.o
164 obj-$(CONFIG_I2C_ELV) += i2c-elv.o
165 obj-$(CONFIG_I2C_VELLEMAN) += i2c-velleman.o
166 +obj-$(CONFIG_I2C_FRODO) += i2c-frodo.o
167 obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o
168 obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
169 +obj-$(CONFIG_I2C_PCFEPP) += i2c-pcf-epp.o
170 obj-$(CONFIG_ITE_I2C_ALGO) += i2c-algo-ite.o
171 obj-$(CONFIG_ITE_I2C_ADAP) += i2c-adap-ite.o
172 +obj-$(CONFIG_I2C_ALGO8XX) += i2c-algo-8xx.o
173 +obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
174 +obj-$(CONFIG_I2C_IBM_OCP_ALGO) += i2c-algo-ibm_ocp.o
175 +obj-$(CONFIG_I2C_IBM_OCP_ADAP) += i2c-adap-ibm_ocp.o
176 obj-$(CONFIG_I2C_PROC) += i2c-proc.o
177 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
178 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
179 --- linux-old/Documentation/Configure.help Wed Aug 27 16:11:41 2003
180 +++ linux/Documentation/Configure.help Sun Dec 7 11:17:34 2003
181 @@ -18185,6 +18185,16 @@
182 <file:Documentation/modules.txt>.
183 The module will be called i2c-velleman.o.
185 +Basic I2C on Parallel Port adapter
187 + This supports directly connecting I2C devices to the parallel port.
188 + See <file:Documentation/i2c/i2c-pport> for more information.
190 + This driver is also available as a module. If you want to compile
191 + it as a module, say M here and read
192 + <file:Documentation/modules.txt>.
193 + The module will be called i2c-pport.o.
195 I2C PCF 8584 interfaces
197 This allows you to use a range of I2C adapters called PCF adapters.
198 @@ -18206,6 +18216,15 @@
199 <file:Documentation/modules.txt>.
200 The module will be called i2c-elektor.o.
202 +PCF on the EPP Parallel Port
204 + This supports the PCF8584 connected to the parallel port.
206 + This driver is also available as a module. If you want to compile
207 + it as a module, say M here and read
208 + <file:Documentation/modules.txt>.
209 + The module will be called i2c-pcf-epp.o.
213 This supports the use the ITE8172 I2C interface found on some MIPS
214 @@ -18238,6 +18257,51 @@
215 sensor. Currently the device is only supported on a SiByte I2C
216 adapter, and the driver prints status updates to the system log.
218 +Motorola 8xx I2C algorithm
220 + This is the algorithm that allows you to use Motorola 8xx I2C adapters.
222 + This driver is also available as a module. If you want to compile
223 + it as a module, say M here and read
224 + <file:Documentation/modules.txt>.
225 + The module will be called i2c-algo-8xx.o.
227 +Motorola 8xx I2C interface
229 + This supports the Motorola 8xx I2C device.
231 + This driver is also available as a module. If you want to compile
232 + it as a module, say M here and read
233 + <file:Documentation/modules.txt>.
234 + The module will be called i2c-rpx.o.
236 +IBM 405 I2C algorithm
237 +CONFIG_I2C_IBM_OCP_ALGO
238 + This is the algorithm that allows you to use IBM 405 I2C adapters.
240 + This driver is also available as a module. If you want to compile
241 + it as a module, say M here and read
242 + <file:Documentation/modules.txt>.
243 + The module will be called i2c-algo-ibm_ocp.o.
245 +IBM 405 I2C interface
246 +CONFIG_I2C_IBM_OCP_ADAP
247 + This supports the IBM 405 I2C device.
249 + This driver is also available as a module. If you want to compile
250 + it as a module, say M here and read
251 + <file:Documentation/modules.txt>.
252 + The module will be called i2c-adap-ibm_ocp.o.
254 +StrongARM SA-1110 interface
256 + This supports the StrongARM SA-1110 Development Board.
258 + This driver is also available as a module. If you want to compile
259 + it as a module, say M here and read
260 + <file:Documentation/modules.txt>.
261 + The module will be called i2c-frodo.o.
265 Say Y here to use i2c-* device files, usually found in the /dev
266 @@ -18258,6 +18322,15 @@
267 This code is also available as a module. If you want to compile
268 it as a module, say M here and read <file:Documentation/modules.txt>.
269 The module will be called i2c-proc.o.
271 +Powermac Keywest I2C interface
273 + This supports the use of the I2C interface in the combo-I/O
274 + chip on recent Apple machines. Say Y if you have such a machine.
276 + This driver is also available as a module. If you want to compile
277 + it as a module, say M here and read Documentation/modules.txt.
278 + The module will be called i2c-keywest.o.
282 --- linux-old/Documentation/i2c/dev-interface Thu Oct 11 15:05:47 2001
283 +++ linux/Documentation/i2c/dev-interface Sun Dec 7 11:17:34 2003
286 ioctl(file,I2C_TENBIT,long select)
287 Selects ten bit addresses if select not equals 0, selects normal 7 bit
288 - addresses if select equals 0.
289 + addresses if select equals 0. Default 0.
291 +ioctl(file,I2C_PEC,long select)
292 + Selects SMBus PEC (packet error checking) generation and verification
293 + if select not equals 0, disables if select equals 0. Default 0.
294 + Used only for SMBus transactions.
296 ioctl(file,I2C_FUNCS,unsigned long *funcs)
297 Gets the adapter functionality and puts it in *funcs.
298 --- linux-old/Documentation/i2c/i2c-pport Thu Jan 1 00:00:00 1970
299 +++ linux/Documentation/i2c/i2c-pport Sun Dec 7 11:17:34 2003
301 +Parallel Port Adapters
302 +----------------------
303 +If you are installing parallel port adapters it means you are probably messing
304 +around with wires and IC's and the like. If you have purchased a card that
305 +provides an external i2c/smbus this will require combined algorithm and
306 +adapter code in a single module.
307 +If you are doing it yourself by using the parallel port there
308 +are basically 2 options.
310 +1) Using the parallel port and using the i2c-pport adapter module and the
311 +i2c-algo-bit algorithm module together to enable you to wire up your parallel
312 +port to act as an i2c/smbus. This provides a bus that will enable most
313 +sensors to work but doesn't support the entire i2c/smbus capability.
315 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c
316 +adapter chip. You will need to build a bit of a circuit to do this. This
317 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf
318 +algorithm module. This support almost all of the i2c/smbus capabilities.
321 +i2c-pport Documentation
322 +-----------------------
323 +This is a primitive parallel port driver for the i2c bus, which exploits
324 +features of modern bidirectional parallel ports.
326 +Bidirectional ports have particular bits connected in following way:
331 + read \-----| /------- Out pin
339 +It means when output is set to 1 we can read the port. Therefore
340 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It
341 +is not necessary to add any external - additional parts, we can
342 +read and write the same port simultaneously.
343 + I only use register base+2 so it is possible to use all
344 +8 data bits of parallel port for other applications (I have
345 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
346 + Port. The only disadvantage is we can only support 5V chips.
352 +SDA - connect to pin 14 (Auto Linefeed)
353 +SCL - connect to pin 16 (Initialize Printer)
354 +GND - connect to pin 18-25
355 ++5V - use external supply (I use 5V from 3.5" floppy connector)
368 --- linux-old/Documentation/i2c/i2c-protocol Fri Jul 28 19:50:51 2000
369 +++ linux/Documentation/i2c/i2c-protocol Sun Dec 7 11:17:35 2003
371 We have found some I2C devices that needs the following modifications:
374 - In a combined transaction, no 'S Addr' is generated at some point.
375 - For example, setting I2C_M_NOSTART on the second partial message
376 + In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
377 + point. For example, setting I2C_M_NOSTART on the second partial message
378 generates something like:
379 - S Addr Rd [A] [Data] NA Wr [A] Data [A] P
380 + S Addr Rd [A] [Data] NA Data [A] P
381 If you set the I2C_M_NOSTART variable for the first partial message,
382 we do not generate Addr, but we do generate the startbit S. This will
383 probably confuse all other clients on your bus, so don't try this.
385 need to emit an Rd instead of a Wr, or vice versa, you set this
387 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
390 + Flags I2C_M_IGNORE_NAK
391 + Normally message is interrupted immediately if there is [NA] from the
392 + client. Setting this flag treats any [NA] as [A], and all of
394 + These messages may still fail to SCL lo->hi timeout.
396 + Flags I2C_M_NO_RD_ACK
397 + In a read message, master A/NA bit is skipped.
398 --- linux-old/Documentation/i2c/i2c-velleman Thu Jan 1 00:00:00 1970
399 +++ linux/Documentation/i2c/i2c-velleman Sun Dec 7 11:17:35 2003
403 +This is a driver for i2c-hw access for Velleman K9000 and other adapters.
408 + http://www.velleman.be/
410 +Velleman K8000 Howto:
411 + http://howto.htlw16.ac.at/k8000-howto.html
414 +K8000 and K8005 libraries
415 +-------------------------
416 +The project has lead to new libs for the Velleman K8000 and K8005..
417 +LIBK8000 v1.99.1 and LIBK8005 v0.21
419 +With these libs you can control the K8000 and K8005 with the original
420 +simple commands which are in the original Velleman software.
421 +Like SetIOchannel, ReadADchannel, SendStepCCWFull and many more.
422 +Via i2c kernel device /dev/velleman
424 +The libs can be found on http://groups.yahoo.com/group/k8000/files/linux/
426 +The Velleman K8000 interface card on http://www.velleman.be/kits/k8000.htm
427 +The Velleman K8005 steppermotorcard on http://www.velleman.be/kits/k8005.htm
428 --- linux-old/Documentation/i2c/smbus-protocol Fri Feb 16 23:53:08 2001
429 +++ linux/Documentation/i2c/smbus-protocol Sun Dec 7 11:17:35 2003
431 +SMBus Protocol Summary
432 +======================
433 +The following is a summary of the SMBus protocol. It applies to
434 +all revisions of the protocol (1.0, 1.1, and 2.0).
435 +Certain protocol features which are not supported by
436 +this package are briefly described at the end of this document.
438 Some adapters understand only the SMBus (System Management Bus) protocol,
439 which is a subset from the I2C protocol. Fortunately, many devices use
440 only the same subset, which makes it possible to put them on an SMBus.
442 I2C protocol). This makes it possible to use the device driver on both
443 SMBus adapters and I2C adapters (the SMBus command set is automatically
444 translated to I2C on I2C adapters, but plain I2C commands can not be
445 -handled at all on a pure SMBus adapter).
446 +handled at all on most pure SMBus adapters).
448 Below is a list of SMBus commands.
451 This is the reverse of Read Byte: it sends a single byte to a device.
452 See Read Byte for more information.
454 -S Addr Wr [A] Data NA P
455 +S Addr Wr [A] Data [A] P
463 -This command reads a block of upto 32 bytes from a device, from a
464 +This command reads a block of up to 32 bytes from a device, from a
465 designated register that is specified through the Comm byte. The amount
466 of data is specified by the device in the Count byte.
472 -The opposite of the Block Read command, this writes upto 32 bytes to
473 +The opposite of the Block Read command, this writes up to 32 bytes to
474 a device, to a designated register that is specified through the
475 Comm byte. The amount of data is specified in the Count byte.
477 S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
480 +SMBus Block Process Call
481 +========================
483 +SMBus Block Process Call was introduced in Revision 2.0 of the specification.
485 +This command selects a device register (through the Comm byte), sends
486 +1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.
488 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
489 + S Addr Rd [A] [Count] A [Data] ... NA P
495 +This command is sent from a SMBus device acting as a master to the
496 +SMBus host acting as a slave.
497 +It is the same form as Write Word, with the command code replaced by the
498 +alerting device's address.
500 +[S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
503 +Packet Error Checking (PEC)
504 +===========================
505 +Packet Error Checking was introduced in Revision 1.1 of the specification.
507 +PEC adds a CRC-8 error-checking byte to all transfers.
510 +Address Resolution Protocol (ARP)
511 +=================================
512 +The Address Resolution Protocol was introduced in Revision 2.0 of
513 +the specification. It is a higher-layer protocol which uses the
516 +ARP adds device enumeration and dynamic address assignment to
517 +the protocol. All ARP communications use slave address 0x61 and
518 +require PEC checksums.
521 +I2C Block Transactions
522 +======================
523 +The following I2C block transactions are supported by the
524 +SMBus layer and are described here for completeness.
525 +I2C block transactions do not limit the number of bytes transferred
526 +but the SMBus layer places a limit of 32 bytes.
532 +This command reads a block of bytes from a device, from a
533 +designated register that is specified through the Comm byte.
535 +S Addr Wr [A] Comm [A]
536 + S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
539 +I2C Block Read (2 Comm bytes)
540 +=============================
542 +This command reads a block of bytes from a device, from a
543 +designated register that is specified through the two Comm bytes.
545 +S Addr Wr [A] Comm1 [A] Comm2 [A]
546 + S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
552 +The opposite of the Block Read command, this writes bytes to
553 +a device, to a designated register that is specified through the
554 +Comm byte. Note that command lengths of 0, 2, or more bytes are
555 +supported as they are indistinguishable from data.
557 +S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
560 --- linux-old/Documentation/i2c/summary Thu Oct 11 15:05:47 2001
561 +++ linux/Documentation/i2c/summary Sun Dec 7 11:17:35 2003
565 I2C (pronounce: I squared C) is a protocol developed by Philips. It is a
566 -slow two-wire protocol (10-100 kHz), but it suffices for many types of
567 +slow two-wire protocol (10-400 kHz), but it suffices for many types of
570 SMBus (System Management Bus) is a subset of the I2C protocol. Many
575 -Note that not only stable drivers are patched into the kernel by 'mkpatch'.
576 +Note that only stable drivers are patched into the kernel by 'mkpatch'.
582 -i2c-core: The basic I2C code, including the /proc interface
583 -i2c-dev: The /dev interface
584 -i2c-proc: The /proc interface for device (client) drivers
585 +i2c-core: The basic I2C code, including the /proc/bus/i2c* interface
586 +i2c-dev: The /dev/i2c-* interface
587 +i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers
592 i2c-algo-8xx: An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
593 i2c-algo-bit: A bit-banging algorithm
594 i2c-algo-pcf: A PCF 8584 style algorithm
595 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
596 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
601 i2c-elektor: Elektor ISA card (uses i2c-algo-pcf)
602 i2c-elv: ELV parallel port adapter (uses i2c-algo-bit)
603 -i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
604 +i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
605 i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
606 -i2c-ppc405: IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
607 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
608 i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit)
609 i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
610 i2c-velleman: Velleman K9000 parallel port adapter (uses i2c-algo-bit)
611 --- linux-old/Documentation/i2c/writing-clients Thu Oct 11 15:05:47 2001
612 +++ linux/Documentation/i2c/writing-clients Sun Dec 7 11:17:36 2003
614 routines, a client structure specific information like the actual I2C
617 - struct i2c_driver foo_driver
619 - /* name */ "Foo version 2.3 and later driver",
620 - /* id */ I2C_DRIVERID_FOO,
621 - /* flags */ I2C_DF_NOTIFY,
622 - /* attach_adapter */ &foo_attach_adapter,
623 - /* detach_client */ &foo_detach_client,
624 - /* command */ &foo_command, /* May be NULL */
625 - /* inc_use */ &foo_inc_use, /* May be NULL */
626 - /* dec_use */ &foo_dec_use /* May be NULL */
627 + static struct i2c_driver foo_driver = {
628 + .owner = THIS_MODULE,
629 + .name = "Foo version 2.3 driver",
630 + .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */
631 + .flags = I2C_DF_NOTIFY,
632 + .attach_adapter = &foo_attach_adapter,
633 + .detach_client = &foo_detach_client,
634 + .command = &foo_command /* may be NULL */
637 The name can be chosen freely, and may be upto 40 characters long. Please
639 All other fields are for call-back functions which will be explained
646 -If your driver can also be compiled as a module, there are moments at
647 -which the module can not be removed from memory. For example, when you
648 -are doing a lengthy transaction, or when you create a /proc directory,
649 -and some process has entered that directory (this last case is the
650 -main reason why these call-backs were introduced).
652 -To increase or decrease the module usage count, you can use the
653 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
654 -which needs to get its usage count changed; that is why each driver
655 -module has to implement its own callback.
657 - void foo_inc_use (struct i2c_client *client)
664 - void foo_dec_use (struct i2c_client *client)
671 -Do not call these call-back functions directly; instead, use one of the
672 -following functions defined in i2c.h:
673 - void i2c_inc_use_client(struct i2c_client *);
674 - void i2c_dec_use_client(struct i2c_client *);
676 -You should *not* increase the module count just because a device is
677 -detected and a client created. This would make it impossible to remove
679 +There use to be two additional fields in this structure, inc_use et dec_use,
680 +for module usage count, but these fields were obsoleted and removed.
686 The detect client function is called by i2c_probe or i2c_detect.
687 The `kind' parameter contains 0 if this call is due to a `force'
688 -parameter, and 0 otherwise (for i2c_detect, it contains 0 if
689 +parameter, and -1 otherwise (for i2c_detect, it contains 0 if
690 this call is due to the generic `force' parameter, and the chip type
691 number if it is due to a specific `force' parameter).
694 /* Note that we reserve some space for foo_data too. If you don't
695 need it, remove it. We do it here to help to lessen memory
697 - if (! (new_client = kmalloc(sizeof(struct i2c_client)) +
698 + if (! (new_client = kmalloc(sizeof(struct i2c_client) +
699 sizeof(struct foo_data),
705 --- linux-old/drivers/i2c/i2c-adap-ibm_ocp.c Thu Jan 1 00:00:00 1970
706 +++ linux/drivers/i2c/i2c-adap-ibm_ocp.c Sun Dec 7 11:17:36 2003
709 + -------------------------------------------------------------------------
710 + i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
711 + -------------------------------------------------------------------------
713 + Ian DaSilva, MontaVista Software, Inc.
714 + idasilva@mvista.com or source@mvista.com
716 + Copyright 2000 MontaVista Software Inc.
718 + Changes made to support the IIC peripheral on the IBM PPC 405
721 + ----------------------------------------------------------------------------
722 + This file was highly leveraged from i2c-elektor.c, which was created
723 + by Simon G. Vogl and Hans Berglund:
726 + Copyright (C) 1995-97 Simon G. Vogl
727 + 1998-99 Hans Berglund
729 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
730 + Frodo Looijaard <frodol@dds.nl>
733 + This program is free software; you can redistribute it and/or modify
734 + it under the terms of the GNU General Public License as published by
735 + the Free Software Foundation; either version 2 of the License, or
736 + (at your option) any later version.
738 + This program is distributed in the hope that it will be useful,
739 + but WITHOUT ANY WARRANTY; without even the implied warranty of
740 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
741 + GNU General Public License for more details.
743 + You should have received a copy of the GNU General Public License
744 + along with this program; if not, write to the Free Software
745 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
746 + ----------------------------------------------------------------------------
748 + History: 01/20/12 - Armin
750 + ported up to 2.4.16+
752 + Version 02/03/25 - Armin
753 + converted to ocp format
754 + removed commented out or #if 0 code
756 + TODO: convert to ocp_register
762 +#include <linux/kernel.h>
763 +#include <linux/ioport.h>
764 +#include <linux/module.h>
765 +#include <linux/delay.h>
766 +#include <linux/slab.h>
767 +#include <linux/init.h>
768 +#include <linux/i2c.h>
769 +#include <linux/i2c-algo-ibm_ocp.h>
770 +#include <asm/irq.h>
772 +#include <asm/ocp.h>
775 + * This next section is configurable, and it is used to set the number
776 + * of i2c controllers in the system. The default number of instances is 1,
777 + * however, this should be changed to reflect your system's configuration.
781 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
783 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
784 +extern iic_t *IIC_ADDR[];
785 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
787 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
788 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
790 +static int i2c_debug=0;
791 +static wait_queue_head_t iic_wait[IIC_NUMS];
792 +static int iic_pending;
793 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
796 +/* ----- global defines ----------------------------------------------- */
797 +#define DEB(x) if (i2c_debug>=1) x
798 +#define DEB2(x) if (i2c_debug>=2) x
799 +#define DEB3(x) if (i2c_debug>=3) x
800 +#define DEBE(x) x /* error messages */
802 +/* ----- local functions ---------------------------------------------- */
805 +// Description: Write a byte to IIC hardware
807 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
809 + // writeb resolves to a write to the specified memory location
810 + // plus a call to eieio. eieio ensures that all instructions
811 + // preceding it are completed before any further stores are
813 + // Delays at this level (to protect writes) are not needed here.
819 +// Description: Read a byte from IIC hardware
821 +static int iic_ibmocp_getbyte(void *data, int ctl)
831 +// Description: Return our slave address. This is the address
832 +// put on the I2C bus when another master on the bus wants to address us
835 +static int iic_ibmocp_getown(void *data)
837 + return(((struct iic_ibm *)(data))->iic_own);
842 +// Description: Return the clock rate
844 +static int iic_ibmocp_getclock(void *data)
846 + return(((struct iic_ibm *)(data))->iic_clock);
852 +// Description: Put this process to sleep. We will wake up when the
853 +// IIC controller interrupts.
855 +static void iic_ibmocp_waitforpin(void *data) {
858 + struct iic_ibm *priv_data = data;
861 + // If interrupts are enabled (which they are), then put the process to
862 + // sleep. This process will be awakened by two events -- either the
863 + // the IIC peripheral interrupts or the timeout expires.
865 + if (priv_data->iic_irq > 0) {
866 + spin_lock_irq(&irq_driver_lock);
867 + if (iic_pending == 0) {
868 + interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
871 + spin_unlock_irq(&irq_driver_lock);
874 + // If interrupts are not enabled then delay for a reasonable amount
875 + // of time and return. We expect that by time we return to the calling
876 + // function that the IIC has finished our requested transaction and
877 + // the status bit reflects this.
879 + // udelay is probably not the best choice for this since it is
880 + // the equivalent of a busy wait
884 + //printk("iic_ibmocp_waitforpin: exitting\n");
889 +// Description: The registered interrupt handler
891 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs)
894 + struct iic_regs *iic;
895 + struct iic_ibm *priv_data = dev_id;
896 + iic = (struct iic_regs *) priv_data->iic_base;
898 + DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
899 + // Read status register
900 + ret = readb((int) &(iic->sts));
901 + DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
902 + // Clear status register. See IBM PPC 405 reference manual for details
903 + writeb(0x0a, (int) &(iic->sts));
904 + wake_up_interruptible(&(iic_wait[priv_data->index]));
909 +// Description: This function is very hardware dependent. First, we lock
910 +// the region of memory where out registers exist. Next, we request our
911 +// interrupt line and register its associated handler. Our IIC peripheral
912 +// uses interrupt number 2, as specified by the 405 reference manual.
914 +static int iic_hw_resrc_init(int instance)
917 + DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
918 + iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
920 + DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
922 + if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
924 + if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
925 + 0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
926 + printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
927 + iic_ibmocp_adaps[instance]->iic_irq);
928 + iic_ibmocp_adaps[instance]->iic_irq = 0;
930 + DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
938 +// Description: Release irq and memory
940 +static void iic_ibmocp_release(void)
944 + for(i=0; i<IIC_NUMS; i++) {
945 + struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
946 + if (priv_data->iic_irq > 0) {
947 + disable_irq(priv_data->iic_irq);
948 + free_irq(priv_data->iic_irq, 0);
950 + kfree(iic_ibmocp_data[i]);
951 + kfree(iic_ibmocp_ops[i]);
957 +// Description: Called when the module is loaded. This function starts the
958 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
959 +// algorithm layer and into to the core layer)
961 +static int __init iic_ibmocp_init(void)
965 + printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
967 + for(i=0; i<IIC_NUMS; i++) {
968 + iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
969 + if(iic_ibmocp_data[i] == NULL) {
972 + memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
976 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
979 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
982 + iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
983 + iic_ibmocp_adaps[i]->iic_own = IIC_OWN;
984 + iic_ibmocp_adaps[i]->index = i;
986 + DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
987 + DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
988 + DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
989 + DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
992 + iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i];
993 + iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
994 + iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
995 + iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
996 + iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
997 + iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
998 + iic_ibmocp_data[i]->udelay = 80;
999 + iic_ibmocp_data[i]->mdelay = 80;
1000 + iic_ibmocp_data[i]->timeout = HZ;
1002 + iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
1003 + if(iic_ibmocp_ops[i] == NULL) {
1006 + memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
1007 + strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
1008 + iic_ibmocp_ops[i]->owner = THIS_MODULE;
1009 + iic_ibmocp_ops[i]->id = I2C_HW_OCP;
1010 + iic_ibmocp_ops[i]->algo = NULL;
1011 + iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
1014 + init_waitqueue_head(&(iic_wait[i]));
1015 + if (iic_hw_resrc_init(i) == 0) {
1016 + if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
1021 + DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
1027 +static void __exit iic_ibmocp_exit(void)
1031 + for(i=0; i<IIC_NUMS; i++) {
1032 + i2c_ocp_del_bus(iic_ibmocp_ops[i]);
1034 + iic_ibmocp_release();
1038 +// If modules is NOT defined when this file is compiled, then the MODULE_*
1039 +// macros will resolve to nothing
1041 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
1042 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
1043 +MODULE_LICENSE("GPL");
1045 +MODULE_PARM(base, "i");
1046 +MODULE_PARM(irq, "i");
1047 +MODULE_PARM(clock, "i");
1048 +MODULE_PARM(own, "i");
1049 +MODULE_PARM(i2c_debug,"i");
1052 +module_init(iic_ibmocp_init);
1053 +module_exit(iic_ibmocp_exit);
1054 --- linux-old/drivers/i2c/i2c-algo-8xx.c Thu Jan 1 00:00:00 1970
1055 +++ linux/drivers/i2c/i2c-algo-8xx.c Sun Dec 7 11:17:36 2003
1058 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
1059 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
1061 + This program is free software; you can redistribute it and/or modify
1062 + it under the terms of the GNU General Public License as published by
1063 + the Free Software Foundation; either version 2 of the License, or
1064 + (at your option) any later version.
1066 + This program is distributed in the hope that it will be useful,
1067 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1068 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1069 + GNU General Public License for more details.
1071 + You should have received a copy of the GNU General Public License
1072 + along with this program; if not, write to the Free Software
1073 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1075 + * moved into proper i2c interface; separated out platform specific
1076 + * parts into i2c-rpx.c
1077 + * Brad Parker (brad@heeltoe.com)
1085 +#include <linux/kernel.h>
1086 +#include <linux/module.h>
1087 +#include <linux/delay.h>
1088 +#include <linux/slab.h>
1089 +#include <linux/init.h>
1090 +#include <linux/errno.h>
1091 +#include <linux/sched.h>
1092 +#include <linux/i2c.h>
1093 +#include <linux/i2c-algo-8xx.h>
1094 +#include <asm/mpc8xx.h>
1095 +#include <asm/commproc.h>
1098 +#define CPM_MAX_READ 513
1099 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
1100 +static wait_queue_head_t iic_wait;
1101 +static ushort r_tbase, r_rbase;
1106 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
1108 + volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
1109 + if (cpm_debug > 1)
1110 + printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
1112 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
1113 + /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
1114 + /* Someone with a buggy CPU needs to confirm that */
1115 + i2c->i2c_i2mod &= ~1;
1117 + /* Clear interrupt.
1119 + i2c->i2c_i2cer = 0xff;
1121 + /* Get 'me going again.
1123 + wake_up_interruptible(&iic_wait);
1127 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
1129 + volatile iic_t *iip = cpm->iip;
1130 + volatile i2c8xx_t *i2c = cpm->i2c;
1131 + unsigned char brg;
1132 + bd_t *bd = (bd_t *)__res;
1134 + if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
1136 + /* Initialize the parameter ram.
1137 + * We need to make sure many things are initialized to zero,
1138 + * especially in the case of a microcode patch.
1140 + iip->iic_rstate = 0;
1142 + iip->iic_rbptr = 0;
1144 + iip->iic_rxtmp = 0;
1145 + iip->iic_tstate = 0;
1147 + iip->iic_tbptr = 0;
1149 + iip->iic_txtmp = 0;
1151 + /* Set up the IIC parameters in the parameter ram.
1153 + iip->iic_tbase = r_tbase = cpm->dp_addr;
1154 + iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
1156 + iip->iic_tfcr = SMC_EB;
1157 + iip->iic_rfcr = SMC_EB;
1159 + /* Set maximum receive size.
1161 + iip->iic_mrblr = CPM_MAX_READ;
1163 + /* Initialize Tx/Rx parameters.
1165 + if (cpm->reloc == 0) {
1166 + volatile cpm8xx_t *cp = cpm->cp;
1169 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
1170 + while (cp->cp_cpcr & CPM_CR_FLG);
1172 + iip->iic_rbptr = iip->iic_rbase;
1173 + iip->iic_tbptr = iip->iic_tbase;
1174 + iip->iic_rstate = 0;
1175 + iip->iic_tstate = 0;
1178 + /* Select an arbitrary address. Just make sure it is unique.
1180 + i2c->i2c_i2add = 0xfe;
1182 + /* Make clock run at 60 KHz.
1184 + brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
1185 + i2c->i2c_i2brg = brg;
1187 + i2c->i2c_i2mod = 0x00;
1188 + i2c->i2c_i2com = 0x01; /* Master mode */
1190 + /* Disable interrupts.
1192 + i2c->i2c_i2cmr = 0;
1193 + i2c->i2c_i2cer = 0xff;
1195 + init_waitqueue_head(&iic_wait);
1197 + /* Install interrupt handler.
1200 + printk ("%s[%d] Install ISR for IRQ %d\n",
1201 + __func__,__LINE__, CPMVEC_I2C);
1203 + (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
1208 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
1210 + volatile i2c8xx_t *i2c = cpm->i2c;
1214 + i2c->i2c_i2mod &= ~1;
1215 + i2c->i2c_i2cmr = 0;
1216 + i2c->i2c_i2cer = 0xff;
1222 +cpm_reset_iic_params(volatile iic_t *iip)
1224 + iip->iic_tbase = r_tbase;
1225 + iip->iic_rbase = r_rbase;
1227 + iip->iic_tfcr = SMC_EB;
1228 + iip->iic_rfcr = SMC_EB;
1230 + iip->iic_mrblr = CPM_MAX_READ;
1232 + iip->iic_rstate = 0;
1234 + iip->iic_rbptr = iip->iic_rbase;
1236 + iip->iic_rxtmp = 0;
1237 + iip->iic_tstate = 0;
1239 + iip->iic_tbptr = iip->iic_tbase;
1241 + iip->iic_txtmp = 0;
1244 +#define BD_SC_NAK ((ushort)0x0004) /* NAK - did not respond */
1245 +#define BD_SC_OV ((ushort)0x0002) /* OV - receive overrun */
1246 +#define CPM_CR_CLOSE_RXBD ((ushort)0x0007)
1248 +static void force_close(struct i2c_algo_8xx_data *cpm)
1250 + volatile i2c8xx_t *i2c = cpm->i2c;
1251 + if (cpm->reloc == 0) { /* micro code disabled */
1252 + volatile cpm8xx_t *cp = cpm->cp;
1254 + if (cpm_debug) printk("force_close()\n");
1256 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
1259 + while (cp->cp_cpcr & CPM_CR_FLG);
1261 + i2c->i2c_i2cmr = 0x00; /* Disable all interrupts */
1262 + i2c->i2c_i2cer = 0xff;
1266 +/* Read from IIC...
1267 + * abyte = address byte, with r/w flag already set
1270 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
1272 + volatile iic_t *iip = cpm->iip;
1273 + volatile i2c8xx_t *i2c = cpm->i2c;
1274 + volatile cpm8xx_t *cp = cpm->cp;
1275 + volatile cbd_t *tbdf, *rbdf;
1277 + unsigned long flags, tmo;
1279 + if (count >= CPM_MAX_READ)
1282 + /* check for and use a microcode relocation patch */
1284 + cpm_reset_iic_params(iip);
1287 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1288 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1290 + /* To read, we need an empty buffer of the proper length.
1291 + * All that is used is the first byte for address, the remainder
1292 + * is just used for timing (and doesn't really have to exist).
1295 + tb = (u_char *)(((uint)tb + 15) & ~15);
1296 + tb[0] = abyte; /* Device address byte w/rw flag */
1298 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1300 + if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
1302 + tbdf->cbd_bufaddr = __pa(tb);
1303 + tbdf->cbd_datlen = count + 1;
1305 + BD_SC_READY | BD_SC_LAST |
1306 + BD_SC_WRAP | BD_IIC_START;
1308 + iip->iic_mrblr = count +1; /* prevent excessive read, +1
1309 + is needed otherwise will the
1310 + RXB interrupt come too early */
1312 + /* flush will invalidate too. */
1313 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1315 + rbdf->cbd_datlen = 0;
1316 + rbdf->cbd_bufaddr = __pa(buf);
1317 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
1319 + /* Chip bug, set enable here */
1320 + local_irq_save(flags);
1321 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1322 + i2c->i2c_i2cer = 0xff;
1323 + i2c->i2c_i2mod |= 1; /* Enable */
1324 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1326 + /* Wait for IIC transfer */
1327 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1328 + local_irq_restore(flags);
1329 + } else { /* busy wait for small transfers, its faster */
1330 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1331 + i2c->i2c_i2cer = 0xff;
1332 + i2c->i2c_i2mod |= 1; /* Enable */
1333 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1334 + tmo = jiffies + 1*HZ;
1335 + while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1338 + if (signal_pending(current) || !tmo){
1341 + printk("IIC read: timeout!\n");
1344 +#ifdef I2C_CHIP_ERRATA
1345 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1346 + Disabling I2C too early may cause too short stop condition */
1348 + i2c->i2c_i2mod &= ~1;
1351 + printk("tx sc %04x, rx sc %04x\n",
1352 + tbdf->cbd_sc, rbdf->cbd_sc);
1355 + if (tbdf->cbd_sc & BD_SC_READY) {
1356 + printk("IIC read; complete but tbuf ready\n");
1358 + printk("tx sc %04x, rx sc %04x\n",
1359 + tbdf->cbd_sc, rbdf->cbd_sc);
1362 + if (tbdf->cbd_sc & BD_SC_NAK) {
1364 + printk("IIC read; no ack\n");
1365 + return -EREMOTEIO;
1368 + if (rbdf->cbd_sc & BD_SC_EMPTY) {
1369 + /* force_close(cpm); */
1371 + printk("IIC read; complete but rbuf empty\n");
1372 + printk("tx sc %04x, rx sc %04x\n",
1373 + tbdf->cbd_sc, rbdf->cbd_sc);
1375 + return -EREMOTEIO;
1378 + if (rbdf->cbd_sc & BD_SC_OV) {
1380 + printk("IIC read; Overrun\n");
1381 + return -EREMOTEIO;;
1384 + if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
1386 + if (rbdf->cbd_datlen < count) {
1388 + printk("IIC read; short, wanted %d got %d\n",
1389 + count, rbdf->cbd_datlen);
1397 + * addr = address byte, with r/w flag already set
1400 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
1402 + volatile iic_t *iip = cpm->iip;
1403 + volatile i2c8xx_t *i2c = cpm->i2c;
1404 + volatile cpm8xx_t *cp = cpm->cp;
1405 + volatile cbd_t *tbdf;
1407 + unsigned long flags, tmo;
1409 + /* check for and use a microcode relocation patch */
1411 + cpm_reset_iic_params(iip);
1414 + tb = (u_char *)(((uint)tb + 15) & ~15);
1415 + *tb = abyte; /* Device address byte w/rw flag */
1417 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1418 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1420 + if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1422 + /* set up 2 descriptors */
1423 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1425 + tbdf[0].cbd_bufaddr = __pa(tb);
1426 + tbdf[0].cbd_datlen = 1;
1427 + tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1429 + tbdf[1].cbd_bufaddr = __pa(buf);
1430 + tbdf[1].cbd_datlen = count;
1431 + tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1434 + /* Chip bug, set enable here */
1435 + local_irq_save(flags);
1436 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1437 + i2c->i2c_i2cer = 0xff;
1438 + i2c->i2c_i2mod |= 1; /* Enable */
1439 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1441 + /* Wait for IIC transfer */
1442 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1443 + local_irq_restore(flags);
1444 + } else { /* busy wait for small transfers, its faster */
1445 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1446 + i2c->i2c_i2cer = 0xff;
1447 + i2c->i2c_i2mod |= 1; /* Enable */
1448 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1449 + tmo = jiffies + 1*HZ;
1450 + while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1453 + if (signal_pending(current) || !tmo){
1455 + if(cpm_debug && !tmo)
1456 + printk("IIC write: timeout!\n");
1460 +#if I2C_CHIP_ERRATA
1461 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1462 + Disabling I2C too early may cause too short stop condition */
1464 + i2c->i2c_i2mod &= ~1;
1467 + printk("tx0 sc %04x, tx1 sc %04x\n",
1468 + tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1471 + if (tbdf->cbd_sc & BD_SC_NAK) {
1473 + printk("IIC write; no ack\n");
1477 + if (tbdf->cbd_sc & BD_SC_READY) {
1479 + printk("IIC write; complete but tbuf ready\n");
1486 +/* See if an IIC address exists..
1487 + * addr = 7 bit address, unshifted
1490 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1492 + volatile iic_t *iip = cpm->iip;
1493 + volatile i2c8xx_t *i2c = cpm->i2c;
1494 + volatile cpm8xx_t *cp = cpm->cp;
1495 + volatile cbd_t *tbdf, *rbdf;
1497 + unsigned long flags, len, tmo;
1499 + if (cpm_debug > 1)
1500 + printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1502 + /* check for and use a microcode relocation patch */
1504 + cpm_reset_iic_params(iip);
1507 + if (cpm_debug && addr == 0) {
1508 + printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1509 + printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1512 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1513 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1516 + tb = (u_char *)(((uint)tb + 15) & ~15);
1518 + /* do a simple read */
1519 + tb[0] = (addr << 1) | 1; /* device address (+ read) */
1522 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1524 + tbdf->cbd_bufaddr = __pa(tb);
1525 + tbdf->cbd_datlen = len;
1527 + BD_SC_READY | BD_SC_LAST |
1528 + BD_SC_WRAP | BD_IIC_START;
1530 + rbdf->cbd_datlen = 0;
1531 + rbdf->cbd_bufaddr = __pa(tb+2);
1532 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1534 + local_irq_save(flags);
1535 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1536 + i2c->i2c_i2cer = 0xff;
1537 + i2c->i2c_i2mod |= 1; /* Enable */
1538 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1540 + if (cpm_debug > 1) printk("about to sleep\n");
1542 + /* wait for IIC transfer */
1543 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1544 + local_irq_restore(flags);
1546 +#ifdef I2C_CHIP_ERRATA
1547 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1548 + Disabling I2C too early may cause too short stop condition */
1550 + i2c->i2c_i2mod &= ~1;
1553 + if (signal_pending(current) || !tmo){
1555 + if(cpm_debug && !tmo)
1556 + printk("IIC tryaddress: timeout!\n");
1560 + if (cpm_debug > 1) printk("back from sleep\n");
1562 + if (tbdf->cbd_sc & BD_SC_NAK) {
1563 + if (cpm_debug > 1) printk("IIC try; no ack\n");
1567 + if (tbdf->cbd_sc & BD_SC_READY) {
1568 + printk("IIC try; complete but tbuf ready\n");
1574 +static int cpm_xfer(struct i2c_adapter *adap,
1575 + struct i2c_msg msgs[],
1578 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1579 + struct i2c_msg *pmsg;
1583 + for (i = 0; i < num; i++) {
1587 + printk("i2c-algo-8xx.o: "
1588 + "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1589 + i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1591 + addr = pmsg->addr << 1;
1592 + if (pmsg->flags & I2C_M_RD )
1594 + if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1597 + if (!(pmsg->flags & I2C_M_NOSTART)) {
1599 + if (pmsg->flags & I2C_M_RD ) {
1600 + /* read bytes into buffer*/
1601 + ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1603 + printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1604 + if (ret < pmsg->len ) {
1605 + return (ret<0)? ret : -EREMOTEIO;
1608 + /* write bytes from buffer */
1609 + ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1611 + printk("i2c-algo-8xx.o: wrote %d\n", ret);
1612 + if (ret < pmsg->len ) {
1613 + return (ret<0) ? ret : -EREMOTEIO;
1620 +static u32 cpm_func(struct i2c_adapter *adap)
1622 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1623 + I2C_FUNC_PROTOCOL_MANGLING;
1626 +/* -----exported algorithm data: ------------------------------------- */
1628 +static struct i2c_algorithm cpm_algo = {
1629 + .owner = THIS_MODULE,
1630 + .name = "MPC8xx CPM algorithm",
1631 + .id = I2C_ALGO_MPC8XX,
1632 + .master_xfer = cpm_xfer,
1633 + .functionality = cpm_func,
1637 + * registering functions to load algorithms at runtime
1639 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1642 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1645 + printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1648 + /* register new adapter to i2c module... */
1650 + adap->id |= cpm_algo.id;
1651 + adap->algo = &cpm_algo;
1653 + i2c_add_adapter(adap);
1654 + cpm_iic_init(cpm);
1658 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1660 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1662 + cpm_iic_shutdown(cpm);
1664 + return i2c_del_adapter(adap);
1667 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1668 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1670 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1671 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1672 +MODULE_LICENSE("GPL");
1673 --- linux-old/include/linux/i2c-algo-8xx.h Thu Jan 1 00:00:00 1970
1674 +++ linux/include/linux/i2c-algo-8xx.h Sun Dec 7 11:17:36 2003
1676 +/* ------------------------------------------------------------------------- */
1677 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM */
1679 + This program is free software; you can redistribute it and/or modify
1680 + it under the terms of the GNU General Public License as published by
1681 + the Free Software Foundation; either version 2 of the License, or
1682 + (at your option) any later version.
1684 + This program is distributed in the hope that it will be useful,
1685 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1686 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1687 + GNU General Public License for more details.
1689 + You should have received a copy of the GNU General Public License
1690 + along with this program; if not, write to the Free Software
1691 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1692 +/* ------------------------------------------------------------------------- */
1696 +#ifndef _LINUX_I2C_ALGO_8XX_H
1697 +#define _LINUX_I2C_ALGO_8XX_H
1699 +#include "asm/commproc.h"
1701 +struct i2c_algo_8xx_data {
1704 + volatile i2c8xx_t *i2c;
1705 + volatile iic_t *iip;
1706 + volatile cpm8xx_t *cp;
1708 + int (*setisr) (int irq,
1709 + void (*func)(void *, void *),
1715 +int i2c_8xx_add_bus(struct i2c_adapter *);
1716 +int i2c_8xx_del_bus(struct i2c_adapter *);
1718 +#endif /* _LINUX_I2C_ALGO_8XX_H */
1719 --- linux-old/drivers/i2c/i2c-algo-bit.c Wed Aug 27 16:11:46 2003
1720 +++ linux/drivers/i2c/i2c-algo-bit.c Sun Dec 7 11:17:37 2003
1722 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1723 /* ------------------------------------------------------------------------- */
1725 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
1726 - Frodo Looijaard <frodol@dds.nl> */
1727 +/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
1728 + <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
1733 #include <linux/kernel.h>
1734 #include <linux/module.h>
1735 #include <linux/delay.h>
1736 #include <linux/slab.h>
1737 -#include <linux/version.h>
1738 #include <linux/init.h>
1739 -#include <asm/uaccess.h>
1740 -#include <linux/ioport.h>
1741 #include <linux/errno.h>
1742 #include <linux/sched.h>
1744 #include <linux/i2c.h>
1745 #include <linux/i2c-algo-bit.h>
1748 /* ----- global defines ----------------------------------------------- */
1749 #define DEB(x) if (i2c_debug>=1) x;
1750 #define DEB2(x) if (i2c_debug>=2) x;
1752 #define DEBPROTO(x) if (i2c_debug>=9) { x; }
1753 /* debug the protocol by showing transferred bits */
1755 -/* debugging - slow down transfer to have a look at the data .. */
1756 -/* I use this with two leds&resistors, each one connected to sda,scl */
1757 -/* respectively. This makes sure that the algorithm works. Some chips */
1758 -/* might not like this, as they have an internal timeout of some mils */
1760 -#define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1761 - if (need_resched) schedule();
1765 /* ----- global variables --------------------------------------------- */
1771 /* module parameters:
1773 static int i2c_debug;
1774 static int bit_test; /* see if the line-setting functions work */
1775 -static int bit_scan; /* have a look at what's hanging 'round */
1777 /* --- setting states on the bus with the right timing: --------------- */
1782 udelay(adap->udelay);
1789 @@ -100,33 +80,35 @@
1791 static inline int sclhi(struct i2c_algo_bit_data *adap)
1793 - int start=jiffies;
1798 - udelay(adap->udelay);
1800 /* Not all adapters have scl sense line... */
1801 - if (adap->getscl == NULL )
1802 + if (adap->getscl == NULL ) {
1803 + udelay(adap->udelay);
1807 - while (! getscl(adap) ) {
1809 + while (! getscl(adap) ) {
1810 /* the hw knows how to read the clock line,
1811 * so we wait until it actually gets high.
1812 * This is safer as some chips may hold it low
1813 * while they are processing data internally.
1816 if (time_after_eq(jiffies, start+adap->timeout)) {
1819 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1820 if (current->need_resched)
1823 - DEBSTAT(printk("needed %ld jiffies\n", jiffies-start));
1830 + DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1831 + udelay(adap->udelay);
1836 /* scl, sda may not be high */
1837 DEBPROTO(printk(" Sr "));
1841 udelay(adap->udelay);
1844 @@ -179,14 +161,14 @@
1845 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1847 /* assert: scl is low */
1848 - DEB2(printk(" i2c_outb:%2.2X\n",c&0xff));
1849 for ( i=7 ; i>=0 ; i-- ) {
1850 sb = c & ( 1 << i );
1852 udelay(adap->udelay);
1853 - DEBPROTO(printk("%d",sb!=0));
1854 + DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1855 if (sclhi(adap)<0) { /* timed out */
1856 sdahi(adap); /* we don't want to block the net */
1857 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1860 /* do arbitration here:
1861 @@ -197,14 +179,15 @@
1864 if (sclhi(adap)<0){ /* timeout */
1865 - return -ETIMEDOUT;
1866 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1867 + return -ETIMEDOUT;
1869 /* read ack: SDA should be pulled down by slave */
1870 ack=getsda(adap); /* ack: sda is pulled low ->success. */
1871 - DEB2(printk(" i2c_outb: getsda() = 0x%2.2x\n", ~ack ));
1872 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1874 - DEBPROTO( printk("[%2.2x]",c&0xff) );
1875 - DEBPROTO(if (0==ack){ printk(" A ");} else printk(" NA ") );
1876 + DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1877 + DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1879 return 0==ack; /* return 1 if device acked */
1880 /* assert: scl is low (sda undef) */
1881 @@ -220,11 +203,10 @@
1882 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1884 /* assert: scl is low */
1885 - DEB2(printk("i2c_inb.\n"));
1889 if (sclhi(adap)<0) { /* timeout */
1890 + DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1897 /* assert: scl is low */
1898 - DEBPROTO(printk(" %2.2x", indata & 0xff));
1899 + DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1901 + DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1902 return (int) (indata & 0xff);
1905 @@ -243,71 +227,75 @@
1907 static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
1910 + if (adap->getscl==NULL)
1911 + printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, "
1912 + "SCL is not readable.\n");
1915 - if (adap->getscl==NULL) {
1916 - printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1920 - printk("i2c-algo-bit.o: Adapter: %s scl: %d sda: %d -- testing...\n",
1921 - name,getscl(adap),getsda(adap));
1922 + scl=(adap->getscl==NULL?1:getscl(adap));
1923 + printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
1924 if (!scl || !sda ) {
1925 - printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1926 + printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name);
1931 - printk("i2c-algo-bit.o:1 scl: %d sda: %d \n",getscl(adap),
1933 - if ( 0 != getsda(adap) ) {
1934 - printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1937 + scl=(adap->getscl==NULL?1:getscl(adap));
1938 + printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
1940 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n");
1943 - if ( 0 == getscl(adap) ) {
1944 - printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1947 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1948 + "while pulling SDA low!\n");
1953 - printk("i2c-algo-bit.o:2 scl: %d sda: %d \n",getscl(adap),
1955 - if ( 0 == getsda(adap) ) {
1956 - printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1959 + scl=(adap->getscl==NULL?1:getscl(adap));
1960 + printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
1962 + printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n");
1965 - if ( 0 == getscl(adap) ) {
1966 - printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1970 + printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1971 + "while pulling SDA high!\n");
1976 - printk("i2c-algo-bit.o:3 scl: %d sda: %d \n",getscl(adap),
1978 - if ( 0 != getscl(adap) ) {
1979 - printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1982 + scl=(adap->getscl==NULL?0:getscl(adap));
1983 + printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
1985 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n");
1988 - if ( 0 == getsda(adap) ) {
1989 - printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1992 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1993 + "while pulling SCL low!\n");
1998 - printk("i2c-algo-bit.o:4 scl: %d sda: %d \n",getscl(adap),
2000 - if ( 0 == getscl(adap) ) {
2001 - printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
2004 + scl=(adap->getscl==NULL?1:getscl(adap));
2005 + printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
2007 + printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n");
2010 - if ( 0 == getsda(adap) ) {
2011 - printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
2014 + printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
2015 + "while pulling SCL high!\n");
2018 - printk("i2c-algo-bit.o: %s passed test.\n",name);
2019 + printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
2023 @@ -341,30 +329,35 @@
2025 udelay(adap->udelay);
2027 - DEB2(if (i) printk("i2c-algo-bit.o: needed %d retries for %d\n",
2030 + printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
2031 + i+1, addr & 1 ? "read" : "write", addr>>1,
2032 + ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
2037 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
2038 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
2040 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2042 - const char *temp = buf;
2043 + const char *temp = msg->buf;
2044 + int count = msg->len;
2045 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
2051 - DEB2(printk("i2c-algo-bit.o: %s i2c_write: writing %2.2X\n",
2052 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
2053 i2c_adap->name, c&0xff));
2054 retval = i2c_outb(i2c_adap,c);
2056 + if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
2060 } else { /* arbitration or no acknowledge */
2061 - printk("i2c-algo-bit.o: %s i2c_write: error - bailout.\n",
2062 + printk(KERN_ERR "i2c-algo-bit.o: %s sendbytes: error - bailout.\n",
2065 return (retval<0)? retval : -EFAULT;
2066 @@ -378,12 +371,13 @@
2070 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
2071 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
2075 int rdcount=0; /* counts bytes read */
2076 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2077 + char *temp = msg->buf;
2078 + int count = msg->len;
2081 inval = i2c_inb(i2c_adap);
2085 } else { /* read timed out */
2086 - printk("i2c-algo-bit.o: i2c_read: i2c_inb timed out.\n");
2087 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n");
2093 if (sclhi(adap)<0) { /* timeout */
2095 - printk("i2c-algo-bit.o: i2c_read: Timeout at ack\n");
2096 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n");
2100 @@ -420,33 +414,36 @@
2101 * try_address) and transmits the address in the necessary format to handle
2102 * reads, writes as well as 10bit-addresses.
2104 - * 0 everything went okay, the chip ack'ed
2105 + * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
2106 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
2107 * -ETIMEDOUT, for example if the lines are stuck...)
2109 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
2110 - struct i2c_msg *msg, int retries)
2111 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
2113 unsigned short flags = msg->flags;
2114 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
2115 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2121 + retries = nak_ok ? 0 : i2c_adap->retries;
2123 if ( (flags & I2C_M_TEN) ) {
2124 /* a ten bit address */
2125 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2126 - DEB2(printk("addr0: %d\n",addr));
2127 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2128 /* try extended address code...*/
2129 ret = try_address(i2c_adap, addr, retries);
2131 - printk("died at extended address code.\n");
2132 + if ((ret != 1) && !nak_ok) {
2133 + printk(KERN_ERR "died at extended address code.\n");
2136 /* the remaining 8 bit address */
2137 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
2139 + if ((ret != 1) && !nak_ok) {
2140 /* the chip did not ack / xmission error occurred */
2141 - printk("died at 2nd address code.\n");
2142 + printk(KERN_ERR "died at 2nd address code.\n");
2145 if ( flags & I2C_M_RD ) {
2147 /* okay, now switch into reading mode */
2149 ret = try_address(i2c_adap, addr, retries);
2151 - printk("died at extended address code.\n");
2152 + if ((ret!=1) && !nak_ok) {
2153 + printk(KERN_ERR "died at extended address code.\n");
2157 @@ -466,10 +463,10 @@
2158 if (flags & I2C_M_REV_DIR_ADDR )
2160 ret = try_address(i2c_adap, addr, retries);
2162 + if ((ret!=1) && !nak_ok)
2170 @@ -480,32 +477,34 @@
2171 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2174 + unsigned short nak_ok;
2177 for (i=0;i<num;i++) {
2179 + nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
2180 if (!(pmsg->flags & I2C_M_NOSTART)) {
2184 - ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
2186 - DEB2(printk("i2c-algo-bit.o: NAK from device adr %#2x msg #%d\n"
2187 - ,msgs[i].addr,i));
2188 - return (ret<0) ? ret : -EREMOTEIO;
2189 + ret = bit_doAddress(i2c_adap, pmsg);
2190 + if ((ret != 0) && !nak_ok) {
2191 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n"
2192 + ,msgs[i].addr,i));
2193 + return (ret<0) ? ret : -EREMOTEIO;
2196 if (pmsg->flags & I2C_M_RD ) {
2197 /* read bytes into buffer*/
2198 - ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
2199 - DEB2(printk("i2c-algo-bit.o: read %d bytes.\n",ret));
2200 + ret = readbytes(i2c_adap, pmsg);
2201 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
2202 if (ret < pmsg->len ) {
2203 return (ret<0)? ret : -EREMOTEIO;
2206 /* write bytes from buffer */
2207 - ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
2208 - DEB2(printk("i2c-algo-bit.o: wrote %d bytes.\n",ret));
2209 + ret = sendbytes(i2c_adap, pmsg);
2210 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
2211 if (ret < pmsg->len ) {
2212 return (ret<0) ? ret : -EREMOTEIO;
2214 @@ -515,13 +514,7 @@
2218 -static int algo_control(struct i2c_adapter *adapter,
2219 - unsigned int cmd, unsigned long arg)
2224 -static u32 bit_func(struct i2c_adapter *adap)
2225 +static u32 bit_func(struct i2c_adapter *i2c_adap)
2227 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2228 I2C_FUNC_PROTOCOL_MANGLING;
2229 @@ -531,14 +524,11 @@
2230 /* -----exported algorithm data: ------------------------------------- */
2232 static struct i2c_algorithm i2c_bit_algo = {
2233 - "Bit-shift algorithm",
2237 - NULL, /* slave_xmit */
2238 - NULL, /* slave_recv */
2239 - algo_control, /* ioctl */
2240 - bit_func, /* functionality */
2241 + .owner = THIS_MODULE,
2242 + .name = "Bit-shift algorithm",
2243 + .id = I2C_ALGO_BIT,
2244 + .master_xfer = bit_xfer,
2245 + .functionality = bit_func,
2251 int i2c_bit_add_bus(struct i2c_adapter *adap)
2254 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
2261 - DEB2(printk("i2c-algo-bit.o: hw routines for %s registered.\n",
2262 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: hw routines for %s registered.\n",
2265 /* register new adapter to i2c module... */
2266 @@ -566,78 +555,26 @@
2267 adap->timeout = 100; /* default values, should */
2268 adap->retries = 3; /* be replaced by defines */
2273 - printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
2275 - for (i = 0x00; i < 0xff; i+=2) {
2276 - i2c_start(bit_adap);
2277 - ack = i2c_outb(adap,i);
2278 - i2c_stop(bit_adap);
2280 - printk("(%02x)",i>>1);
2288 - MOD_INC_USE_COUNT;
2290 i2c_add_adapter(adap);
2296 int i2c_bit_del_bus(struct i2c_adapter *adap)
2300 - if ((res = i2c_del_adapter(adap)) < 0)
2303 - DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
2306 - MOD_DEC_USE_COUNT;
2311 -int __init i2c_algo_bit_init (void)
2313 - printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
2315 + return i2c_del_adapter(adap);
2320 EXPORT_SYMBOL(i2c_bit_add_bus);
2321 EXPORT_SYMBOL(i2c_bit_del_bus);
2324 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
2325 MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
2326 MODULE_LICENSE("GPL");
2328 MODULE_PARM(bit_test, "i");
2329 -MODULE_PARM(bit_scan, "i");
2330 MODULE_PARM(i2c_debug,"i");
2332 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
2333 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
2334 MODULE_PARM_DESC(i2c_debug,
2335 - "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2337 -int init_module(void)
2339 - return i2c_algo_bit_init();
2342 -void cleanup_module(void)
2346 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2347 --- linux-old/include/linux/i2c-algo-bit.h Mon Dec 11 21:15:41 2000
2348 +++ linux/include/linux/i2c-algo-bit.h Sun Dec 7 11:17:37 2003
2350 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
2351 Frodo Looijaard <frodol@dds.nl> */
2356 -#ifndef I2C_ALGO_BIT_H
2357 -#define I2C_ALGO_BIT_H 1
2359 -#include <linux/i2c.h>
2360 +#ifndef _LINUX_I2C_ALGO_BIT_H
2361 +#define _LINUX_I2C_ALGO_BIT_H
2363 /* --- Defines for bit-adapters --------------------------------------- */
2366 int (*getscl) (void *data);
2368 /* local settings */
2372 + int udelay; /* half-clock-cycle time in microsecs */
2373 + /* i.e. clock is (500 / udelay) KHz */
2374 + int mdelay; /* in millisecs, unused */
2375 + int timeout; /* in jiffies */
2378 #define I2C_BIT_ADAP_MAX 16
2380 int i2c_bit_add_bus(struct i2c_adapter *);
2381 int i2c_bit_del_bus(struct i2c_adapter *);
2383 -#endif /* I2C_ALGO_BIT_H */
2384 +#endif /* _LINUX_I2C_ALGO_BIT_H */
2385 --- linux-old/drivers/i2c/i2c-algo-ibm_ocp.c Thu Jan 1 00:00:00 1970
2386 +++ linux/drivers/i2c/i2c-algo-ibm_ocp.c Sun Dec 7 11:17:38 2003
2389 + -------------------------------------------------------------------------
2390 + i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters
2391 + -------------------------------------------------------------------------
2393 + Ian DaSilva, MontaVista Software, Inc.
2394 + idasilva@mvista.com or source@mvista.com
2396 + Copyright 2000 MontaVista Software Inc.
2398 + Changes made to support the IIC peripheral on the IBM PPC 405
2401 + ---------------------------------------------------------------------------
2402 + This file was highly leveraged from i2c-algo-pcf.c, which was created
2403 + by Simon G. Vogl and Hans Berglund:
2406 + Copyright (C) 1995-1997 Simon G. Vogl
2407 + 1998-2000 Hans Berglund
2409 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
2410 + Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
2411 + <mbailey@littlefeet-inc.com>
2414 + This program is free software; you can redistribute it and/or modify
2415 + it under the terms of the GNU General Public License as published by
2416 + the Free Software Foundation; either version 2 of the License, or
2417 + (at your option) any later version.
2419 + This program is distributed in the hope that it will be useful,
2420 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2421 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2422 + GNU General Public License for more details.
2424 + You should have received a copy of the GNU General Public License
2425 + along with this program; if not, write to the Free Software
2426 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2427 + ---------------------------------------------------------------------------
2429 + History: 01/20/12 - Armin
2430 + akuster@mvista.com
2431 + ported up to 2.4.16+
2433 + Version 02/03/25 - Armin
2434 + converted to ocp format
2435 + removed commented out or #if 0 code
2436 + added Gérard Basler's fix to iic_combined_transaction() such that it
2437 + returns the number of successfully completed transfers .
2441 +#include <linux/kernel.h>
2442 +#include <linux/module.h>
2443 +#include <linux/delay.h>
2444 +#include <linux/slab.h>
2445 +#include <linux/init.h>
2446 +#include <linux/errno.h>
2447 +#include <linux/sched.h>
2448 +#include <linux/i2c.h>
2449 +#include <linux/i2c-algo-ibm_ocp.h>
2450 +#include <asm/ocp.h>
2453 +/* ----- global defines ----------------------------------------------- */
2454 +#define DEB(x) if (i2c_debug>=1) x
2455 +#define DEB2(x) if (i2c_debug>=2) x
2456 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
2457 +#define DEBPROTO(x) if (i2c_debug>=9) x;
2458 + /* debug the protocol by showing transferred bits */
2459 +#define DEF_TIMEOUT 5
2462 +/* ----- global variables --------------------------------------------- */
2465 +/* module parameters:
2467 +static int i2c_debug=0;
2469 +/* --- setting states on the bus with the right timing: --------------- */
2471 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
2472 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
2474 +#define IICO_I2C_SDAHIGH 0x0780
2475 +#define IICO_I2C_SDALOW 0x0781
2476 +#define IICO_I2C_SCLHIGH 0x0782
2477 +#define IICO_I2C_SCLLOW 0x0783
2478 +#define IICO_I2C_LINEREAD 0x0784
2480 +#define IIC_SINGLE_XFER 0
2481 +#define IIC_COMBINED_XFER 1
2483 +#define IIC_ERR_LOST_ARB -2
2484 +#define IIC_ERR_INCOMPLETE_XFR -3
2485 +#define IIC_ERR_NACK -1
2487 +/* --- other auxiliary functions -------------------------------------- */
2491 +// Description: Puts this process to sleep for a period equal to timeout
2493 +static inline void iic_sleep(unsigned long timeout)
2495 + schedule_timeout( timeout * HZ);
2500 +// Description: This performs the IBM PPC 405 IIC initialization sequence
2501 +// as described in the PPC405GP data book.
2503 +static int iic_init (struct i2c_algo_iic_data *adap)
2505 + struct iic_regs *iic;
2506 + struct iic_ibm *adap_priv_data = adap->data;
2507 + unsigned short retval;
2508 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2510 + /* Clear master low master address */
2511 + iic_outb(adap,iic->lmadr, 0);
2513 + /* Clear high master address */
2514 + iic_outb(adap,iic->hmadr, 0);
2516 + /* Clear low slave address */
2517 + iic_outb(adap,iic->lsadr, 0);
2519 + /* Clear high slave address */
2520 + iic_outb(adap,iic->hsadr, 0);
2522 + /* Clear status */
2523 + iic_outb(adap,iic->sts, 0x0a);
2525 + /* Clear extended status */
2526 + iic_outb(adap,iic->extsts, 0x8f);
2528 + /* Set clock division */
2529 + iic_outb(adap,iic->clkdiv, 0x04);
2531 + retval = iic_inb(adap, iic->clkdiv);
2532 + DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2534 + /* Enable interrupts on Requested Master Transfer Complete */
2535 + iic_outb(adap,iic->intmsk, 0x01);
2537 + /* Clear transfer count */
2538 + iic_outb(adap,iic->xfrcnt, 0x0);
2540 + /* Clear extended control and status */
2541 + iic_outb(adap,iic->xtcntlss, 0xf0);
2543 + /* Set mode control (flush master data buf, enable hold SCL, exit */
2544 + /* unknown state. */
2545 + iic_outb(adap,iic->mdcntl, 0x47);
2547 + /* Clear control register */
2548 + iic_outb(adap,iic->cntl, 0x0);
2550 + DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2556 +// Description: After we issue a transaction on the IIC bus, this function
2557 +// is called. It puts this process to sleep until we get an interrupt from
2558 +// from the controller telling us that the transaction we requested in complete.
2560 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status)
2563 + int timeout = DEF_TIMEOUT;
2565 + struct iic_regs *iic;
2566 + struct iic_ibm *adap_priv_data = adap->data;
2567 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2570 + *status = iic_inb(adap, iic->sts);
2573 + while (timeout-- && (*status & 0x01)) {
2574 + adap->waitforpin(adap->data);
2575 + *status = iic_inb(adap, iic->sts);
2578 + if (timeout <= 0) {
2579 + /* Issue stop signal on the bus, and force an interrupt */
2580 + retval = iic_inb(adap, iic->cntl);
2581 + iic_outb(adap, iic->cntl, retval | 0x80);
2582 + /* Clear status register */
2583 + iic_outb(adap, iic->sts, 0x0a);
2584 + /* Exit unknown bus state */
2585 + retval = iic_inb(adap, iic->mdcntl);
2586 + iic_outb(adap, iic->mdcntl, (retval | 0x02));
2588 + // Check the status of the controller. Does it still see a
2589 + // pending transfer, even though we've tried to stop any
2590 + // ongoing transaction?
2591 + retval = iic_inb(adap, iic->sts);
2592 + retval = retval & 0x01;
2594 + // The iic controller is hosed. It is not responding to any
2595 + // of our commands. We have already tried to force it into
2596 + // a known state, but it has not worked. Our only choice now
2597 + // is a soft reset, which will clear all registers, and force
2598 + // us to re-initialize the controller.
2600 + iic_outb(adap, iic->xtcntlss, 0x01);
2603 + /* Is the pending transfer bit in the sts reg finally cleared? */
2604 + retval = iic_inb(adap, iic->sts);
2605 + retval = retval & 0x01;
2607 + printk(KERN_CRIT "The IIC Controller is hosed. A processor reset is required\n");
2609 + // For some reason, even though the interrupt bit in this
2610 + // register was set during iic_init, it didn't take. We
2611 + // need to set it again. Don't ask me why....this is just what
2612 + // I saw when testing timeouts.
2613 + iic_outb(adap, iic->intmsk, 0x01);
2622 +//------------------------------------
2623 +// Utility functions
2628 +// Description: Look at the status register to see if there was an error
2629 +// in the requested transaction. If there is, look at the extended status
2630 +// register and determine the exact cause.
2632 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2635 + struct iic_regs *iic;
2636 + struct iic_ibm *adap_priv_data = adap->data;
2637 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2640 + ret = iic_inb(adap, iic->sts);
2643 + ret = iic_inb(adap, iic->extsts);
2645 + // Lost arbitration
2646 + *error_code = IIC_ERR_LOST_ARB;
2649 + // Incomplete transfer
2650 + *error_code = IIC_ERR_INCOMPLETE_XFR;
2653 + // Master transfer aborted by a NACK during the transfer of the
2655 + *error_code = IIC_ERR_NACK;
2664 +// Description: This function is called by the upper layers to do the
2665 +// grunt work for a master send transaction
2667 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2668 + int count, int xfer_flag)
2670 + struct iic_regs *iic;
2671 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2672 + struct iic_ibm *adap_priv_data = adap->data;
2673 + int wrcount, status, timeout;
2674 + int loops, remainder, i, j;
2675 + int ret, error_code;
2676 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2679 + if( count == 0 ) return 0;
2681 + loops = count / 4;
2682 + remainder = count % 4;
2684 + if((loops > 1) && (remainder == 0)) {
2685 + for(i=0; i<(loops-1); i++) {
2687 + // Write four bytes to master data buffer
2689 + for(j=0; j<4; j++) {
2690 + iic_outb(adap, iic->mdbuf,
2694 + // Issue command to IICO device to begin transmission
2696 + iic_outb(adap, iic->cntl, 0x35);
2698 + // Wait for transmission to complete. When it does,
2699 + //loop to the top of the for statement and write the
2700 + // next four bytes.
2702 + timeout = wait_for_pin(adap, &status);
2707 + //printk(KERN_ERR "Error: write timeout\n");
2710 + ret = analyze_status(adap, &error_code);
2712 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2713 + // Return the number of bytes transferred
2714 + ret = iic_inb(adap, iic->xfrcnt);
2716 + return (wrcount-4+ret);
2718 + else return error_code;
2722 + else if((loops >= 1) && (remainder > 0)){
2723 + //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2724 + for(i=0; i<loops; i++) {
2726 + // Write four bytes to master data buffer
2728 + for(j=0; j<4; j++) {
2729 + iic_outb(adap, iic->mdbuf,
2733 + // Issue command to IICO device to begin transmission
2735 + iic_outb(adap, iic->cntl, 0x35);
2737 + // Wait for transmission to complete. When it does,
2738 + //loop to the top of the for statement and write the
2739 + // next four bytes.
2741 + timeout = wait_for_pin(adap, &status);
2746 + //printk(KERN_ERR "Error: write timeout\n");
2749 + ret = analyze_status(adap, &error_code);
2751 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2752 + // Return the number of bytes transferred
2753 + ret = iic_inb(adap, iic->xfrcnt);
2755 + return (wrcount-4+ret);
2757 + else return error_code;
2762 + //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2763 + if(remainder == 0) remainder = 4;
2764 + // remainder = remainder - 1;
2766 + // Write the remaining bytes (less than or equal to 4)
2768 + for(i=0; i<remainder; i++) {
2769 + iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2770 + //printk(KERN_DEBUG "iic_sendbytes: data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2772 + //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2774 + if(xfer_flag == IIC_COMBINED_XFER) {
2775 + iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2778 + iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2780 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2781 + timeout = wait_for_pin(adap, &status);
2786 + //printk(KERN_ERR "Error: write timeout\n");
2789 + ret = analyze_status(adap, &error_code);
2791 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2792 + // Return the number of bytes transferred
2793 + ret = iic_inb(adap, iic->xfrcnt);
2795 + return (wrcount-4+ret);
2797 + else return error_code;
2799 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2805 +// Description: Called by the upper layers to do the grunt work for
2806 +// a master read transaction.
2808 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2810 + struct iic_regs *iic;
2811 + int rdcount=0, i, status, timeout;
2812 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2813 + struct iic_ibm *adap_priv_data = adap->data;
2814 + int loops, remainder, j;
2815 + int ret, error_code;
2816 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2818 + if(count == 0) return 0;
2819 + loops = count / 4;
2820 + remainder = count % 4;
2822 + //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2824 + if((loops > 1) && (remainder == 0)) {
2825 + //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2826 + for(i=0; i<(loops-1); i++) {
2828 + // Issue command to begin master read (4 bytes maximum)
2830 + //printk(KERN_DEBUG "--->Issued read command\n");
2831 + iic_outb(adap, iic->cntl, 0x37);
2833 + // Wait for transmission to complete. When it does,
2834 + // loop to the top of the for statement and write the
2835 + // next four bytes.
2837 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2838 + timeout = wait_for_pin(adap, &status);
2841 + //printk(KERN_ERR "Error: read timed out\n");
2844 + //printk(KERN_DEBUG "--->Got interrupt\n");
2846 + ret = analyze_status(adap, &error_code);
2848 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2851 + return error_code;
2854 + for(j=0; j<4; j++) {
2855 + // Wait for data to shuffle to top of data buffer
2856 + // This value needs to optimized.
2858 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2860 + //printk(KERN_DEBUG "--->Read one byte\n");
2865 + else if((loops >= 1) && (remainder > 0)){
2866 + //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2867 + for(i=0; i<loops; i++) {
2869 + // Issue command to begin master read (4 bytes maximum)
2871 + //printk(KERN_DEBUG "--->Issued read command\n");
2872 + iic_outb(adap, iic->cntl, 0x37);
2874 + // Wait for transmission to complete. When it does,
2875 + // loop to the top of the for statement and write the
2876 + // next four bytes.
2878 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2879 + timeout = wait_for_pin(adap, &status);
2882 + //printk(KERN_ERR "Error: read timed out\n");
2885 + //printk(KERN_DEBUG "--->Got interrupt\n");
2887 + ret = analyze_status(adap, &error_code);
2889 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2892 + return error_code;
2895 + for(j=0; j<4; j++) {
2896 + // Wait for data to shuffle to top of data buffer
2897 + // This value needs to optimized.
2899 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2901 + //printk(KERN_DEBUG "--->Read one byte\n");
2906 + //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2907 + if(remainder == 0) remainder = 4;
2908 + DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2910 + if(xfer_type == IIC_COMBINED_XFER) {
2911 + iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2914 + iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2916 + DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2917 + timeout = wait_for_pin(adap, &status);
2918 + DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2921 + //printk(KERN_ERR "Error: read timed out\n");
2925 + ret = analyze_status(adap, &error_code);
2927 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2930 + return error_code;
2933 + //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2934 + for(i=0; i<remainder; i++) {
2935 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2936 + // printk(KERN_DEBUG "iic_readbytes: Character read = %x\n", buf[rdcount]);
2945 +// Description: This function implements combined transactions. Combined
2946 +// transactions consist of combinations of reading and writing blocks of data.
2947 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2950 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
2953 + struct i2c_msg *pmsg;
2956 + DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2957 + for(i=0; i < num; i++) {
2959 + if(pmsg->flags & I2C_M_RD) {
2961 + // Last read or write segment needs to be terminated with a stop
2963 + DEB2(printk(KERN_DEBUG "This one is a read\n"));
2966 + DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2968 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2970 + if (ret != pmsg->len) {
2971 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2972 + "only read %d bytes.\n",ret));
2976 + DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2979 + else if(!(pmsg->flags & I2C_M_RD)) {
2981 + // Last read or write segment needs to be terminated with a stop
2983 + DEB2(printk(KERN_DEBUG "This one is a write\n"));
2986 + DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2988 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2990 + if (ret != pmsg->len) {
2991 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2992 + "only wrote %d bytes.\n",ret));
2996 + DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
3006 +// Description: Whenever we initiate a transaction, the first byte clocked
3007 +// onto the bus after the start condition is the address (7 bit) of the
3008 +// device we want to talk to. This function manipulates the address specified
3009 +// so that it makes sense to the hardware when written to the IIC peripheral.
3011 +// Note: 10 bit addresses are not supported in this driver, although they are
3012 +// supported by the hardware. This functionality needs to be implemented.
3014 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
3015 + struct i2c_msg *msg, int retries)
3017 + struct iic_regs *iic;
3018 + unsigned short flags = msg->flags;
3019 + unsigned char addr;
3020 + struct iic_ibm *adap_priv_data = adap->data;
3021 + iic = (struct iic_regs *) adap_priv_data->iic_base;
3024 +// The following segment for 10 bit addresses needs to be ported
3026 +/* Ten bit addresses not supported right now
3027 + if ( (flags & I2C_M_TEN) ) {
3028 + // a ten bit address
3029 + addr = 0xf0 | (( msg->addr >> 7) & 0x03);
3030 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
3031 + // try extended address code...
3032 + ret = try_address(adap, addr, retries);
3034 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
3035 + return -EREMOTEIO;
3037 + // the remaining 8 bit address
3038 + iic_outb(adap,msg->addr & 0x7f);
3039 + // Status check comes here
3041 + printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
3042 + return -EREMOTEIO;
3044 + if ( flags & I2C_M_RD ) {
3045 + i2c_repstart(adap);
3046 + // okay, now switch into reading mode
3048 + ret = try_address(adap, addr, retries);
3050 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
3051 + return -EREMOTEIO;
3054 + } else ----------> // normal 7 bit address
3056 +Ten bit addresses not supported yet */
3058 + addr = ( msg->addr << 1 );
3059 + if (flags & I2C_M_RD )
3061 + if (flags & I2C_M_REV_DIR_ADDR )
3064 + // Write to the low slave address
3066 + iic_outb(adap, iic->lmadr, addr);
3068 + // Write zero to the high slave register since we are
3069 + // only using 7 bit addresses
3071 + iic_outb(adap, iic->hmadr, 0);
3078 +// Description: Prepares the controller for a transaction (clearing status
3079 +// registers, data buffers, etc), and then calls either iic_readbytes or
3080 +// iic_sendbytes to do the actual transaction.
3082 +static int iic_xfer(struct i2c_adapter *i2c_adap,
3083 + struct i2c_msg msgs[],
3086 + struct iic_regs *iic;
3087 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
3088 + struct iic_ibm *adap_priv_data = adap->data;
3089 + struct i2c_msg *pmsg;
3092 + iic = (struct iic_regs *) adap_priv_data->iic_base;
3097 + // Clear status register
3099 + DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
3100 + iic_outb(adap, iic->sts, 0x0a);
3103 + // Wait for any pending transfers to complete
3105 + DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
3106 + while((ret = iic_inb(adap, iic->sts)) == 0x01) {
3111 + // Flush master data buf
3113 + DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));
3114 + ret = iic_inb(adap, iic->mdcntl);
3115 + iic_outb(adap, iic->mdcntl, ret | 0x40);
3118 + // Load slave address
3120 + DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
3121 + ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
3124 + // Check to see if the bus is busy
3126 + ret = iic_inb(adap, iic->extsts);
3127 + // Mask off the irrelevent bits
3129 + // When the bus is free, the BCS bits in the EXTSTS register are 0b100
3130 + if(ret != 0x40) return IIC_ERR_LOST_ARB;
3133 + // Combined transaction (read and write)
3136 + DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
3137 + ret = iic_combined_transaction(i2c_adap, msgs, num);
3142 + else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
3144 + // Tell device to begin reading data from the master data
3146 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
3147 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
3152 + else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
3154 + // Write data to master data buffers and tell our device
3155 + // to begin transmitting
3157 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
3158 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
3166 +// Description: Implements device specific ioctls. Higher level ioctls can
3167 +// be found in i2c-core.c and are typical of any i2c controller (specifying
3168 +// slave address, timeouts, etc). These ioctls take advantage of any hardware
3169 +// features built into the controller for which this algorithm-adapter set
3170 +// was written. These ioctls allow you to take control of the data and clock
3171 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
3172 +// similar to a GPIO pin.
3174 +static int algo_control(struct i2c_adapter *adapter,
3175 + unsigned int cmd, unsigned long arg)
3177 + struct iic_regs *iic;
3178 + struct i2c_algo_iic_data *adap = adapter->algo_data;
3179 + struct iic_ibm *adap_priv_data = adap->data;
3182 + iic = (struct iic_regs *) adap_priv_data->iic_base;
3184 + lines = iic_inb(adap, iic->directcntl);
3186 + if (cmd == IICO_I2C_SDAHIGH) {
3187 + lines = lines & 0x01;
3188 + if( lines ) lines = 0x04;
3190 + iic_outb(adap, iic->directcntl,(0x08|lines));
3192 + else if (cmd == IICO_I2C_SDALOW) {
3193 + lines = lines & 0x01;
3194 + if( lines ) lines = 0x04;
3196 + iic_outb(adap, iic->directcntl,(0x00|lines));
3198 + else if (cmd == IICO_I2C_SCLHIGH) {
3199 + lines = lines & 0x02;
3200 + if( lines ) lines = 0x08;
3202 + iic_outb(adap, iic->directcntl,(0x04|lines));
3204 + else if (cmd == IICO_I2C_SCLLOW) {
3205 + lines = lines & 0x02;
3206 + if( lines ) lines = 0x08;
3208 + iic_outb(adap, iic->directcntl,(0x00|lines));
3210 + else if (cmd == IICO_I2C_LINEREAD) {
3217 +static u32 iic_func(struct i2c_adapter *adap)
3219 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
3220 + I2C_FUNC_PROTOCOL_MANGLING;
3224 +/* -----exported algorithm data: ------------------------------------- */
3226 +static struct i2c_algorithm iic_algo = {
3227 + .owner = THIS_MODULE,
3228 + .name = "IBM on-chip IIC algorithm",
3229 + .id = I2C_ALGO_OCP,
3230 + .master_xfer = iic_xfer,
3231 + .algo_control = algo_control,
3232 + .functionality = iic_func,
3236 + * registering functions to load algorithms at runtime
3241 +// Description: Register bus structure
3243 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
3245 + struct i2c_algo_iic_data *iic_adap = adap->algo_data;
3247 + DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
3250 + /* register new adapter to i2c module... */
3252 + adap->id |= iic_algo.id;
3253 + adap->algo = &iic_algo;
3255 + adap->timeout = 100; /* default values, should */
3256 + adap->retries = 3; /* be replaced by defines */
3258 + iic_init(iic_adap);
3259 + i2c_add_adapter(adap);
3267 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
3269 + return i2c_del_adapter(adap);
3273 +EXPORT_SYMBOL(i2c_ocp_add_bus);
3274 +EXPORT_SYMBOL(i2c_ocp_del_bus);
3277 +// The MODULE_* macros resolve to nothing if MODULES is not defined
3278 +// when this file is compiled.
3280 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
3281 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
3282 +MODULE_LICENSE("GPL");
3284 +MODULE_PARM(i2c_debug,"i");
3286 +MODULE_PARM_DESC(i2c_debug,
3287 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
3289 --- linux-old/include/linux/i2c-algo-ibm_ocp.h Thu Jan 1 00:00:00 1970
3290 +++ linux/include/linux/i2c-algo-ibm_ocp.h Sun Dec 7 11:17:38 2003
3292 +/* ------------------------------------------------------------------------- */
3293 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters */
3294 +/* ------------------------------------------------------------------------- */
3295 +/* Copyright (C) 1995-97 Simon G. Vogl
3296 + 1998-99 Hans Berglund
3298 + This program is free software; you can redistribute it and/or modify
3299 + it under the terms of the GNU General Public License as published by
3300 + the Free Software Foundation; either version 2 of the License, or
3301 + (at your option) any later version.
3303 + This program is distributed in the hope that it will be useful,
3304 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3305 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3306 + GNU General Public License for more details.
3308 + You should have received a copy of the GNU General Public License
3309 + along with this program; if not, write to the Free Software
3310 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
3311 +/* ------------------------------------------------------------------------- */
3313 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3314 + Frodo Looijaard <frodol@dds.nl> */
3316 +/* Modifications by MontaVista Software, August 2000
3317 + Changes made to support the IIC peripheral on the IBM PPC 405 */
3319 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
3320 +#define _LINUX_I2C_ALGO_IBM_OCP_H
3322 +struct i2c_algo_iic_data {
3323 + struct iic_regs *data; /* private data for lolevel routines */
3324 + void (*setiic) (void *data, int ctl, int val);
3325 + int (*getiic) (void *data, int ctl);
3326 + int (*getown) (void *data);
3327 + int (*getclock) (void *data);
3328 + void (*waitforpin) (void *data);
3330 + /* local settings */
3337 +#define I2C_IIC_ADAP_MAX 16
3340 +int i2c_ocp_add_bus(struct i2c_adapter *);
3341 +int i2c_ocp_del_bus(struct i2c_adapter *);
3343 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
3344 --- linux-old/drivers/i2c/i2c-algo-pcf.c Thu Oct 11 15:05:47 2001
3345 +++ linux/drivers/i2c/i2c-algo-pcf.c Sun Dec 7 11:17:38 2003
3347 #include <linux/module.h>
3348 #include <linux/delay.h>
3349 #include <linux/slab.h>
3350 -#include <linux/version.h>
3351 #include <linux/init.h>
3352 -#include <asm/uaccess.h>
3353 -#include <linux/ioport.h>
3354 #include <linux/errno.h>
3355 -#include <linux/sched.h>
3357 #include <linux/i2c.h>
3358 #include <linux/i2c-algo-pcf.h>
3359 -#include "i2c-pcf8584.h"
3362 /* ----- global defines ----------------------------------------------- */
3363 #define DEB(x) if (i2c_debug>=1) x
3365 /* module parameters:
3367 static int i2c_debug=0;
3368 -static int pcf_scan=0; /* have a look at what's hanging 'round */
3370 /* --- setting states on the bus with the right timing: --------------- */
3376 - printk("Timeout waiting for Bus Busy\n");
3377 + printk(KERN_ERR "Timeout waiting for Bus Busy\n");
3380 return (timeout<=0);
3381 @@ -144,15 +138,14 @@
3385 - DEB3(printk("i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3386 + DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3388 /* S1=0x80: S0 selected, serial interface off */
3389 set_pcf(adap, 1, I2C_PCF_PIN);
3390 /* check to see S1 now used as R/W ctrl -
3391 PCF8584 does that when ESO is zero */
3392 - /* PCF also resets PIN bit */
3393 - if ((temp = get_pcf(adap, 1)) != (0)) {
3394 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3395 + if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
3396 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3397 return -ENXIO; /* definetly not PCF8584 */
3400 @@ -160,15 +153,15 @@
3401 i2c_outb(adap, get_own(adap));
3402 /* check it's realy writen */
3403 if ((temp = i2c_inb(adap)) != get_own(adap)) {
3404 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3405 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3409 /* S1=0xA0, next byte in S2 */
3410 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
3411 /* check to see S2 now selected */
3412 - if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
3413 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3414 + if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
3415 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3420 i2c_outb(adap, get_clock(adap));
3421 /* check it's realy writen, the only 5 lowest bits does matter */
3422 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
3423 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3424 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3428 @@ -185,11 +178,11 @@
3430 /* check to see PCF is realy idled and we can access status register */
3431 if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
3432 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3433 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3437 - printk("i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3438 + printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3444 udelay(adap->udelay);
3446 - DEB2(if (i) printk("i2c-algo-pcf.o: needed %d retries for %d\n",i,
3447 + DEB2(if (i) printk(KERN_DEBUG "i2c-algo-pcf.o: needed %d retries for %d\n",i,
3451 @@ -228,20 +221,20 @@
3452 int wrcount, status, timeout;
3454 for (wrcount=0; wrcount<count; ++wrcount) {
3455 - DEB2(printk("i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3456 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3457 i2c_adap->name, buf[wrcount]&0xff));
3458 i2c_outb(adap, buf[wrcount]);
3459 timeout = wait_for_pin(adap, &status);
3462 - printk("i2c-algo-pcf.o: %s i2c_write: "
3463 + printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3464 "error - timeout.\n", i2c_adap->name);
3465 return -EREMOTEIO; /* got a better one ?? */
3468 if (status & I2C_PCF_LRB) {
3470 - printk("i2c-algo-pcf.o: %s i2c_write: "
3471 + printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3472 "error - no ack.\n", i2c_adap->name);
3473 return -EREMOTEIO; /* got a better one ?? */
3475 @@ -269,14 +262,14 @@
3477 if (wait_for_pin(adap, &status)) {
3479 - printk("i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3480 + printk(KERN_ERR "i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3485 if ((status & I2C_PCF_LRB) && (i != count)) {
3487 - printk("i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3488 + printk(KERN_ERR "i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3492 @@ -312,18 +305,18 @@
3493 if ( (flags & I2C_M_TEN) ) {
3494 /* a ten bit address */
3495 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
3496 - DEB2(printk("addr0: %d\n",addr));
3497 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
3498 /* try extended address code...*/
3499 ret = try_address(adap, addr, retries);
3501 - printk("died at extended address code.\n");
3502 + printk(KERN_ERR "died at extended address code.\n");
3505 /* the remaining 8 bit address */
3506 i2c_outb(adap,msg->addr & 0x7f);
3507 /* Status check comes here */
3509 - printk("died at 2nd address code.\n");
3510 + printk(KERN_ERR "died at 2nd address code.\n");
3513 if ( flags & I2C_M_RD ) {
3516 ret = try_address(adap, addr, retries);
3518 - printk("died at extended address code.\n");
3519 + printk(KERN_ERR "died at extended address code.\n");
3524 /* Check for bus busy */
3525 timeout = wait_for_bb(adap);
3527 - DEB2(printk("i2c-algo-pcf.o: "
3528 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
3529 "Timeout waiting for BB in pcf_xfer\n");)
3533 for (i = 0;ret >= 0 && i < num; i++) {
3536 - DEB2(printk("i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3537 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3538 pmsg->flags & I2C_M_RD ? "read" : "write",
3539 pmsg->len, pmsg->addr, i + 1, num);)
3542 timeout = wait_for_pin(adap, &status);
3545 - DEB2(printk("i2c-algo-pcf.o: Timeout waiting "
3546 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
3547 "for PIN(1) in pcf_xfer\n");)
3548 return (-EREMOTEIO);
3550 @@ -392,12 +385,12 @@
3551 /* Check LRB (last rcvd bit - slave ack) */
3552 if (status & I2C_PCF_LRB) {
3554 - DEB2(printk("i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3555 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3556 return (-EREMOTEIO);
3560 - DEB3(printk("i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3561 + DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3562 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
3565 @@ -407,20 +400,20 @@
3568 if (ret != pmsg->len) {
3569 - DEB2(printk("i2c-algo-pcf.o: fail: "
3570 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3571 "only read %d bytes.\n",ret));
3573 - DEB2(printk("i2c-algo-pcf.o: read %d bytes.\n",ret));
3574 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
3576 } else { /* Write */
3577 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
3580 if (ret != pmsg->len) {
3581 - DEB2(printk("i2c-algo-pcf.o: fail: "
3582 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3583 "only wrote %d bytes.\n",ret));
3585 - DEB2(printk("i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3586 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3590 @@ -428,12 +421,6 @@
3594 -static int algo_control(struct i2c_adapter *adapter,
3595 - unsigned int cmd, unsigned long arg)
3600 static u32 pcf_func(struct i2c_adapter *adap)
3602 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
3603 @@ -443,14 +430,11 @@
3604 /* -----exported algorithm data: ------------------------------------- */
3606 static struct i2c_algorithm pcf_algo = {
3607 - "PCF8584 algorithm",
3611 - NULL, /* slave_xmit */
3612 - NULL, /* slave_recv */
3613 - algo_control, /* ioctl */
3614 - pcf_func, /* functionality */
3615 + .owner = THIS_MODULE,
3616 + .name = "PCF8584 algorithm",
3617 + .id = I2C_ALGO_PCF,
3618 + .master_xfer = pcf_xfer,
3619 + .functionality = pcf_func,
3623 @@ -458,10 +442,10 @@
3625 int i2c_pcf_add_bus(struct i2c_adapter *adap)
3629 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
3631 - DEB2(printk("i2c-algo-pcf.o: hw routines for %s registered.\n",
3632 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
3635 /* register new adapter to i2c module... */
3636 @@ -476,81 +460,23 @@
3641 - MOD_INC_USE_COUNT;
3644 i2c_add_adapter(adap);
3648 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
3650 - for (i = 0x00; i < 0xff; i+=2) {
3651 - if (wait_for_bb(pcf_adap)) {
3652 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
3656 - i2c_outb(pcf_adap, i);
3657 - i2c_start(pcf_adap);
3658 - if ((wait_for_pin(pcf_adap, &status) >= 0) &&
3659 - ((status & I2C_PCF_LRB) == 0)) {
3660 - printk("(%02x)",i>>1);
3664 - i2c_stop(pcf_adap);
3665 - udelay(pcf_adap->udelay);
3673 int i2c_pcf_del_bus(struct i2c_adapter *adap)
3676 - if ((res = i2c_del_adapter(adap)) < 0)
3678 - DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
3681 - MOD_DEC_USE_COUNT;
3686 -int __init i2c_algo_pcf_init (void)
3688 - printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
3690 + return i2c_del_adapter(adap);
3694 EXPORT_SYMBOL(i2c_pcf_add_bus);
3695 EXPORT_SYMBOL(i2c_pcf_del_bus);
3698 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
3699 MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
3700 MODULE_LICENSE("GPL");
3702 -MODULE_PARM(pcf_scan, "i");
3703 MODULE_PARM(i2c_debug,"i");
3705 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
3706 MODULE_PARM_DESC(i2c_debug,
3707 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
3710 -int init_module(void)
3712 - return i2c_algo_pcf_init();
3715 -void cleanup_module(void)
3719 --- linux-old/include/linux/i2c-algo-pcf.h Mon Dec 11 21:22:34 2000
3720 +++ linux/include/linux/i2c-algo-pcf.h Sun Dec 7 11:17:38 2003
3722 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3723 Frodo Looijaard <frodol@dds.nl> */
3728 -#ifndef I2C_ALGO_PCF_H
3729 -#define I2C_ALGO_PCF_H 1
3730 +#ifndef _LINUX_I2C_ALGO_PCF_H
3731 +#define _LINUX_I2C_ALGO_PCF_H
3733 -/* --- Defines for pcf-adapters --------------------------------------- */
3734 -#include <linux/i2c.h>
3735 +#include <linux/i2c-pcf8584.h>
3737 struct i2c_algo_pcf_data {
3738 void *data; /* private data for lolevel routines */
3740 int i2c_pcf_add_bus(struct i2c_adapter *);
3741 int i2c_pcf_del_bus(struct i2c_adapter *);
3743 -#endif /* I2C_ALGO_PCF_H */
3744 +#endif /* _LINUX_I2C_ALGO_PCF_H */
3745 --- linux-old/drivers/i2c/i2c-core.c Wed Aug 27 16:11:46 2003
3746 +++ linux/drivers/i2c/i2c-core.c Sun Dec 7 11:17:39 2003
3748 /* ------------------------------------------------------------------------- */
3750 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
3751 - All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
3752 + All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
3753 + SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */
3756 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
3758 #include <linux/module.h>
3759 #include <linux/kernel.h>
3760 #include <linux/errno.h>
3761 #include <linux/slab.h>
3762 #include <linux/proc_fs.h>
3763 -#include <linux/config.h>
3765 -#include <linux/i2c.h>
3767 -/* ----- compatibility stuff ----------------------------------------------- */
3769 -#include <linux/version.h>
3770 #include <linux/init.h>
3772 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
3773 -#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
3776 +#include <linux/i2c.h>
3777 #include <asm/uaccess.h>
3779 /* ----- global defines ---------------------------------------------------- */
3781 -/* exclusive access to the bus */
3782 -#define I2C_LOCK(adap) down(&adap->lock)
3783 -#define I2C_UNLOCK(adap) up(&adap->lock)
3785 -#define ADAP_LOCK() down(&adap_lock)
3786 -#define ADAP_UNLOCK() up(&adap_lock)
3788 -#define DRV_LOCK() down(&driver_lock)
3789 -#define DRV_UNLOCK() up(&driver_lock)
3791 #define DEB(x) if (i2c_debug>=1) x;
3792 #define DEB2(x) if (i2c_debug>=2) x;
3794 /* ----- global variables -------------------------------------------------- */
3796 -/**** lock for writing to global variables: the adapter & driver list */
3797 -struct semaphore adap_lock;
3798 -struct semaphore driver_lock;
3800 -/**** adapter list */
3801 +DECLARE_MUTEX(core_lists);
3802 static struct i2c_adapter *adapters[I2C_ADAP_MAX];
3803 -static int adap_count;
3805 -/**** drivers list */
3806 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
3807 -static int driver_count;
3809 /**** debug level */
3810 -static int i2c_debug=1;
3811 +static int i2c_debug;
3813 /* ---------------------------------------------------
3814 * /proc entry declarations
3818 #ifdef CONFIG_PROC_FS
3820 -static int i2cproc_init(void);
3821 -static int i2cproc_cleanup(void);
3823 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
3824 -static void monitor_bus_i2c(struct inode *inode, int fill);
3825 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3827 static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
3829 static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
3831 /* To implement the dynamic /proc/bus/i2c-? files, we need our own
3832 implementation of the read hook */
3833 static struct file_operations i2cproc_operations = {
3834 - read: i2cproc_bus_read,
3835 + .read = i2cproc_bus_read,
3838 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
3839 -static struct inode_operations i2cproc_inode_operations = {
3840 - &i2cproc_operations
3844 -static int i2cproc_initialized = 0;
3846 -#else /* undef CONFIG_PROC_FS */
3848 -#define i2cproc_init() 0
3849 -#define i2cproc_cleanup() 0
3850 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3851 +static void i2cproc_remove(int bus);
3853 #endif /* CONFIG_PROC_FS */
3857 int i2c_add_adapter(struct i2c_adapter *adap)
3863 + down(&core_lists);
3864 for (i = 0; i < I2C_ADAP_MAX; i++)
3865 if (NULL == adapters[i])
3867 @@ -140,81 +94,44 @@
3872 +#ifdef CONFIG_PROC_FS
3873 + res = i2cproc_register(adap, i);
3876 +#endif /* def CONFIG_PROC_FS */
3882 /* init data types */
3883 - init_MUTEX(&adap->lock);
3885 -#ifdef CONFIG_PROC_FS
3887 - if (i2cproc_initialized) {
3889 - struct proc_dir_entry *proc_entry;
3891 - sprintf(name,"i2c-%d", i);
3893 - proc_entry = create_proc_entry(name,0,proc_bus);
3894 - if (! proc_entry) {
3895 - printk("i2c-core.o: Could not create /proc/bus/%s\n",
3901 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,48))
3902 - proc_entry->proc_fops = &i2cproc_operations;
3904 - proc_entry->ops = &i2cproc_inode_operations;
3906 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
3907 - proc_entry->owner = THIS_MODULE;
3909 - proc_entry->fill_inode = &monitor_bus_i2c;
3910 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3911 - adap->inode = proc_entry->low_ino;
3914 -#endif /* def CONFIG_PROC_FS */
3915 + init_MUTEX(&adap->bus);
3916 + init_MUTEX(&adap->list);
3918 /* inform drivers of new adapters */
3920 for (j=0;j<I2C_DRIVER_MAX;j++)
3921 if (drivers[j]!=NULL &&
3922 (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
3923 /* We ignore the return code; if it fails, too bad */
3924 drivers[j]->attach_adapter(adap);
3927 - DEB(printk("i2c-core.o: adapter %s registered as adapter %d.\n",
3928 + DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3936 - adapters[i] = NULL;
3946 int i2c_del_adapter(struct i2c_adapter *adap)
3953 + down(&core_lists);
3954 for (i = 0; i < I2C_ADAP_MAX; i++)
3955 if (adap == adapters[i])
3957 if (I2C_ADAP_MAX == i) {
3958 - printk( "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3959 + printk( KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3963 @@ -225,17 +142,14 @@
3964 * *detach* it! Of course, each dummy driver should know about
3965 * this or hell will break loose...
3968 for (j = 0; j < I2C_DRIVER_MAX; j++)
3969 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3970 if ((res = drivers[j]->attach_adapter(adap))) {
3971 - printk("i2c-core.o: can't detach adapter %s "
3972 + printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3973 "while detaching driver %s: driver not "
3974 "detached!",adap->name,drivers[j]->name);
3981 /* detach any active clients. This must be done first, because
3982 * it can fail; in which case we give upp. */
3983 @@ -247,33 +161,22 @@
3984 * must be deleted, as this would cause invalid states.
3986 if ((res=client->driver->detach_client(client))) {
3987 - printk("i2c-core.o: adapter %s not "
3988 + printk(KERN_ERR "i2c-core.o: adapter %s not "
3989 "unregistered, because client at "
3990 "address %02x can't be detached. ",
3991 adap->name, client->addr);
3996 #ifdef CONFIG_PROC_FS
3997 - if (i2cproc_initialized) {
3999 - sprintf(name,"i2c-%d", i);
4000 - remove_proc_entry(name,proc_bus);
4002 + i2cproc_remove(i);
4003 #endif /* def CONFIG_PROC_FS */
4009 - DEB(printk("i2c-core.o: adapter unregistered: %s\n",adap->name));
4017 + DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
4024 int i2c_add_driver(struct i2c_driver *driver)
4029 + down(&core_lists);
4030 for (i = 0; i < I2C_DRIVER_MAX; i++)
4031 if (NULL == drivers[i])
4033 @@ -296,19 +200,12 @@
4034 " i2c-core.o: register_driver(%s) "
4035 "- enlarge I2C_DRIVER_MAX.\n",
4042 - drivers[i] = driver;
4045 - DRV_UNLOCK(); /* driver was successfully added */
4047 - DEB(printk("i2c-core.o: driver %s registered.\n",driver->name));
4048 + drivers[i] = driver;
4049 + DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
4053 /* now look for instances of driver on our adapters
4055 if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
4056 @@ -317,15 +214,15 @@
4058 driver->attach_adapter(adapters[i]);
4065 int i2c_del_driver(struct i2c_driver *driver)
4068 + int i,j,k,res = 0;
4071 + down(&core_lists);
4072 for (i = 0; i < I2C_DRIVER_MAX; i++)
4073 if (driver == drivers[i])
4075 @@ -333,24 +230,23 @@
4076 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
4083 /* Have a look at each adapter, if clients of this driver are still
4084 * attached. If so, detach them to be able to kill the driver
4087 - DEB2(printk("i2c-core.o: unregister_driver - looking for clients.\n"));
4088 + DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n"));
4089 /* removing clients does not depend on the notify flag, else
4090 * invalid operation might (will!) result, when using stale client
4093 - ADAP_LOCK(); /* should be moved inside the if statement... */
4094 for (k=0;k<I2C_ADAP_MAX;k++) {
4095 struct i2c_adapter *adap = adapters[k];
4096 if (adap == NULL) /* skip empty entries. */
4098 - DEB2(printk("i2c-core.o: examining adapter %s:\n",
4099 + DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
4101 if (driver->flags & I2C_DF_DUMMY) {
4102 /* DUMMY drivers do not register their clients, so we have to
4103 @@ -359,60 +255,69 @@
4104 * this or hell will break loose...
4106 if ((res = driver->attach_adapter(adap))) {
4107 - printk("i2c-core.o: while unregistering "
4108 + printk(KERN_WARNING "i2c-core.o: while unregistering "
4109 "dummy driver %s, adapter %s could "
4110 "not be detached properly; driver "
4111 "not unloaded!",driver->name,
4118 for (j=0;j<I2C_CLIENT_MAX;j++) {
4119 struct i2c_client *client = adap->clients[j];
4120 if (client != NULL &&
4121 client->driver == driver) {
4122 - DEB2(printk("i2c-core.o: "
4123 + DEB2(printk(KERN_DEBUG "i2c-core.o: "
4124 "detaching client %s:\n",
4127 detach_client(client)))
4129 - printk("i2c-core.o: while "
4130 + printk(KERN_ERR "i2c-core.o: while "
4131 "unregistering driver "
4132 "`%s', the client at "
4134 - "adapter `%s' could not"
4135 - "be detached; driver"
4136 + "adapter `%s' could not "
4137 + "be detached; driver "
4155 - DEB(printk("i2c-core.o: driver unregistered: %s\n",driver->name));
4157 + DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
4164 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4165 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
4168 for (i = 0; i < I2C_CLIENT_MAX ; i++)
4169 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
4175 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4179 + down(&adapter->list);
4180 + rval = __i2c_check_addr(adapter, addr);
4181 + up(&adapter->list);
4186 int i2c_attach_client(struct i2c_client *client)
4188 struct i2c_adapter *adapter = client->adapter;
4190 if (i2c_check_addr(client->adapter,client->addr))
4193 + down(&adapter->list);
4194 for (i = 0; i < I2C_CLIENT_MAX; i++)
4195 if (NULL == adapter->clients[i])
4197 @@ -428,18 +334,18 @@
4199 " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
4201 + up(&adapter->list);
4205 adapter->clients[i] = client;
4206 - adapter->client_count++;
4207 + up(&adapter->list);
4209 if (adapter->client_register)
4210 if (adapter->client_register(client))
4211 - printk("i2c-core.o: warning: client_register seems "
4212 + printk(KERN_DEBUG "i2c-core.o: warning: client_register seems "
4213 "to have failed for client %02x at adapter %s\n",
4214 client->addr,adapter->name);
4215 - DEB(printk("i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4216 + DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4217 client->name, adapter->name,i));
4219 if(client->flags & I2C_CLIENT_ALLOW_USE)
4220 @@ -454,54 +360,52 @@
4221 struct i2c_adapter *adapter = client->adapter;
4224 - for (i = 0; i < I2C_CLIENT_MAX; i++)
4225 - if (client == adapter->clients[i])
4227 - if (I2C_CLIENT_MAX == i) {
4228 - printk(KERN_WARNING " i2c-core.o: unregister_client "
4229 - "[%s] not found\n",
4234 if( (client->flags & I2C_CLIENT_ALLOW_USE) &&
4235 (client->usage_count>0))
4238 if (adapter->client_unregister != NULL)
4239 if ((res = adapter->client_unregister(client))) {
4240 - printk("i2c-core.o: client_unregister [%s] failed, "
4241 + printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, "
4242 "client not detached",client->name);
4246 + down(&adapter->list);
4247 + for (i = 0; i < I2C_CLIENT_MAX; i++)
4248 + if (client == adapter->clients[i])
4250 + if (I2C_CLIENT_MAX == i) {
4251 + printk(KERN_WARNING " i2c-core.o: unregister_client "
4252 + "[%s] not found\n",
4254 + up(&adapter->list);
4257 adapter->clients[i] = NULL;
4258 - adapter->client_count--;
4259 + up(&adapter->list);
4261 - DEB(printk("i2c-core.o: client [%s] unregistered.\n",client->name));
4262 + DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
4266 -void i2c_inc_use_client(struct i2c_client *client)
4267 +static void i2c_inc_use_client(struct i2c_client *client)
4270 - if (client->driver->inc_use != NULL)
4271 - client->driver->inc_use(client);
4273 - if (client->adapter->inc_use != NULL)
4274 - client->adapter->inc_use(client->adapter);
4275 + if(client->driver->owner)
4276 + __MOD_INC_USE_COUNT(client->driver->owner);
4277 + if(client->adapter->owner)
4278 + __MOD_INC_USE_COUNT(client->adapter->owner);
4281 -void i2c_dec_use_client(struct i2c_client *client)
4282 +static void i2c_dec_use_client(struct i2c_client *client)
4285 - if (client->driver->dec_use != NULL)
4286 - client->driver->dec_use(client);
4288 - if (client->adapter->dec_use != NULL)
4289 - client->adapter->dec_use(client->adapter);
4290 + if(client->driver->owner)
4291 + __MOD_DEC_USE_COUNT(client->driver->owner);
4292 + if(client->adapter->owner)
4293 + __MOD_DEC_USE_COUNT(client->adapter->owner);
4296 +#if 0 /* just forget about this for now --km */
4297 struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
4298 struct i2c_client *prev)
4300 @@ -568,18 +472,17 @@
4306 int i2c_use_client(struct i2c_client *client)
4308 - if(client->flags & I2C_CLIENT_ALLOW_USE) {
4309 - if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
4310 + if (client->flags & I2C_CLIENT_ALLOW_USE) {
4311 + if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
4312 + client->usage_count++;
4313 + else if (client->usage_count > 0)
4316 client->usage_count++;
4318 - if(client->usage_count > 0)
4321 - client->usage_count++;
4325 i2c_inc_use_client(client);
4326 @@ -611,25 +514,14 @@
4328 #ifdef CONFIG_PROC_FS
4330 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
4331 -/* Monitor access to /proc/bus/i2c*; make unloading i2c-proc impossible
4332 - if some process still uses it or some file in it */
4333 -void monitor_bus_i2c(struct inode *inode, int fill)
4336 - MOD_INC_USE_COUNT;
4338 - MOD_DEC_USE_COUNT;
4340 -#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */
4342 /* This function generates the output for /proc/bus/i2c */
4343 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
4344 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
4349 /* Note that it is safe to write a `little' beyond len. Yes, really. */
4350 + down(&core_lists);
4351 for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
4353 nr += sprintf(buf+nr, "i2c-%d\t", i);
4356 adapters[i]->algo->name);
4362 @@ -656,102 +549,125 @@
4363 struct inode * inode = file->f_dentry->d_inode;
4365 struct i2c_client *client;
4366 + struct i2c_adapter *adap;
4367 int i,j,k,order_nr,len=0;
4369 int order[I2C_CLIENT_MAX];
4370 +#define OUTPUT_LENGTH_PER_LINE 70
4374 len_total = file->f_pos + count;
4375 - /* Too bad if this gets longer (unlikely) */
4376 - if (len_total > 4000)
4378 - for (i = 0; i < I2C_ADAP_MAX; i++)
4379 - if (adapters[i]->inode == inode->i_ino) {
4380 - /* We need a bit of slack in the kernel buffer; this makes the
4382 - if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
4384 - /* Order will hold the indexes of the clients
4385 - sorted by address */
4387 - for (j = 0; j < I2C_CLIENT_MAX; j++) {
4388 - if ((client = adapters[i]->clients[j]) &&
4389 - (client->driver->id != I2C_DRIVERID_I2CDEV)) {
4392 - adapters[i]->clients[order[k-1]]->
4393 - addr > client->addr;
4395 - order[k] = order[k-1];
4402 - for (j = 0; (j < order_nr) && (len < len_total); j++) {
4403 - client = adapters[i]->clients[order[j]];
4404 - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4407 - client->driver->name);
4409 - len = len - file->f_pos;
4414 - if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4418 - file->f_pos += len;
4423 + if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
4424 + /* adjust to maximum file size */
4425 + len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
4427 + down(&core_lists);
4428 + /* adap = file->private_data; ?? --km */
4429 + for (i = 0; i < I2C_ADAP_MAX; i++) {
4430 + adap = adapters[i];
4431 + if (adap && (adap->inode == inode->i_ino))
4434 + if ( I2C_ADAP_MAX == i ) {
4439 + /* We need a bit of slack in the kernel buffer; this makes the
4441 + if (! (kbuf = kmalloc(len_total +
4442 + OUTPUT_LENGTH_PER_LINE,
4446 + /* Order will hold the indexes of the clients
4447 + sorted by address */
4449 + down(&adap->list);
4450 + for (j = 0; j < I2C_CLIENT_MAX; j++) {
4451 + if ((client = adap->clients[j]) &&
4452 + (client->driver->id != I2C_DRIVERID_I2CDEV)) {
4455 + adap->clients[order[k-1]]->
4456 + addr > client->addr;
4458 + order[k] = order[k-1];
4465 + for (j = 0; (j < order_nr) && (len < len_total); j++) {
4466 + client = adap->clients[order[j]];
4467 + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4470 + client->driver->name);
4475 + len = len - file->f_pos;
4480 + if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4484 + file->f_pos += len;
4489 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
4492 + struct proc_dir_entry *proc_entry;
4494 + sprintf(name,"i2c-%d", bus);
4495 + proc_entry = create_proc_entry(name,0,proc_bus);
4496 + if (! proc_entry) {
4497 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
4502 + proc_entry->proc_fops = &i2cproc_operations;
4503 + proc_entry->owner = adap->owner;
4504 + adap->inode = proc_entry->low_ino;
4508 -int i2cproc_init(void)
4509 +static void i2cproc_remove(int bus)
4512 + sprintf(name,"i2c-%d", bus);
4513 + remove_proc_entry(name, proc_bus);
4516 +static int __init i2cproc_init(void)
4518 struct proc_dir_entry *proc_bus_i2c;
4520 - i2cproc_initialized = 0;
4523 - printk("i2c-core.o: /proc/bus/ does not exist");
4524 - i2cproc_cleanup();
4527 proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
4528 if (!proc_bus_i2c) {
4529 - printk("i2c-core.o: Could not create /proc/bus/i2c");
4530 - i2cproc_cleanup();
4531 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
4535 proc_bus_i2c->read_proc = &read_bus_i2c;
4536 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
4537 proc_bus_i2c->owner = THIS_MODULE;
4539 - proc_bus_i2c->fill_inode = &monitor_bus_i2c;
4540 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
4541 - i2cproc_initialized += 2;
4545 -int i2cproc_cleanup(void)
4546 +static void __exit i2cproc_cleanup(void)
4549 - if (i2cproc_initialized >= 1) {
4550 - remove_proc_entry("i2c",proc_bus);
4551 - i2cproc_initialized -= 2;
4554 + remove_proc_entry("i2c",proc_bus);
4558 #endif /* def CONFIG_PROC_FS */
4560 /* ----------------------------------------------------
4561 @@ -764,16 +680,16 @@
4564 if (adap->algo->master_xfer) {
4565 - DEB2(printk("i2c-core.o: master_xfer: %s with %d msgs.\n",
4566 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
4571 ret = adap->algo->master_xfer(adap,msgs,num);
4577 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4578 + printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4582 @@ -791,19 +707,19 @@
4584 (const char *)msg.buf = buf;
4586 - DEB2(printk("i2c-core.o: master_send: writing %d bytes on %s.\n",
4587 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
4588 count,client->adapter->name));
4592 ret = adap->algo->master_xfer(adap,&msg,1);
4596 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4597 * transmitted, else error code.
4599 return (ret == 1 )? count : ret;
4601 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4602 + printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4603 client->adapter->id);
4606 @@ -821,14 +737,14 @@
4610 - DEB2(printk("i2c-core.o: master_recv: reading %d bytes on %s.\n",
4611 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
4612 count,client->adapter->name));
4616 ret = adap->algo->master_xfer(adap,&msg,1);
4620 - DEB2(printk("i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4621 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4622 ret, count, client->addr));
4624 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4627 return (ret == 1 )? count : ret;
4629 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4630 + printk(KERN_DEBUG "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4631 client->adapter->id);
4636 struct i2c_adapter *adap = client->adapter;
4638 - DEB2(printk("i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4639 + DEB2(printk(KERN_DEBUG "i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4642 adap->retries = arg;
4644 if (((adap_id == address_data->force[i]) ||
4645 (address_data->force[i] == ANY_I2C_BUS)) &&
4646 (addr == address_data->force[i+1])) {
4647 - DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4648 + DEB2(printk(KERN_DEBUG "i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4650 if ((err = found_proc(adapter,addr,0,0)))
4653 if (((adap_id == address_data->ignore[i]) ||
4654 ((address_data->ignore[i] == ANY_I2C_BUS))) &&
4655 (addr == address_data->ignore[i+1])) {
4656 - DEB2(printk("i2c-core.o: found ignore parameter for adapter %d, "
4657 + DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore parameter for adapter %d, "
4658 "addr %04x\n", adap_id ,addr));
4662 ((address_data->ignore_range[i]==ANY_I2C_BUS))) &&
4663 (addr >= address_data->ignore_range[i+1]) &&
4664 (addr <= address_data->ignore_range[i+2])) {
4665 - DEB2(printk("i2c-core.o: found ignore_range parameter for adapter %d, "
4666 + DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore_range parameter for adapter %d, "
4667 "addr %04x\n", adap_id,addr));
4672 if (addr == address_data->normal_i2c[i]) {
4674 - DEB2(printk("i2c-core.o: found normal i2c entry for adapter %d, "
4675 + DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, "
4676 "addr %02x", adap_id,addr));
4680 if ((addr >= address_data->normal_i2c_range[i]) &&
4681 (addr <= address_data->normal_i2c_range[i+1])) {
4683 - DEB2(printk("i2c-core.o: found normal i2c_range entry for adapter %d, "
4684 + DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c_range entry for adapter %d, "
4685 "addr %04x\n", adap_id,addr));
4689 ((address_data->probe[i] == ANY_I2C_BUS))) &&
4690 (addr == address_data->probe[i+1])) {
4692 - DEB2(printk("i2c-core.o: found probe parameter for adapter %d, "
4693 + DEB2(printk(KERN_DEBUG "i2c-core.o: found probe parameter for adapter %d, "
4694 "addr %04x\n", adap_id,addr));
4698 (addr >= address_data->probe_range[i+1]) &&
4699 (addr <= address_data->probe_range[i+2])) {
4701 - DEB2(printk("i2c-core.o: found probe_range parameter for adapter %d, "
4702 + DEB2(printk(KERN_DEBUG "i2c-core.o: found probe_range parameter for adapter %d, "
4703 "addr %04x\n", adap_id,addr));
4706 @@ -1004,6 +920,123 @@
4708 /* The SMBus parts */
4710 +#define POLY (0x1070U << 3)
4716 + for(i = 0; i < 8; i++) {
4717 + if (data & 0x8000)
4718 + data = data ^ POLY;
4721 + return (u8)(data >> 8);
4724 +/* CRC over count bytes in the first array plus the bytes in the rest
4725 + array if it is non-null. rest[0] is the (length of rest) - 1
4726 + and is included. */
4727 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
4731 + for(i = 0; i < count; i++)
4732 + crc = crc8((crc ^ first[i]) << 8);
4734 + for(i = 0; i <= rest[0]; i++)
4735 + crc = crc8((crc ^ rest[i]) << 8);
4739 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
4741 + return i2c_smbus_partial_pec(0, count, first, rest);
4744 +/* Returns new "size" (transaction type)
4745 + Note that we convert byte to byte_data and byte_data to word_data
4746 + rather than invent new xxx_PEC transactions. */
4747 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
4748 + union i2c_smbus_data *data)
4752 + buf[0] = addr << 1;
4755 + case I2C_SMBUS_BYTE:
4756 + data->byte = i2c_smbus_pec(2, buf, NULL);
4757 + size = I2C_SMBUS_BYTE_DATA;
4759 + case I2C_SMBUS_BYTE_DATA:
4760 + buf[2] = data->byte;
4761 + data->word = buf[2] ||
4762 + (i2c_smbus_pec(3, buf, NULL) << 8);
4763 + size = I2C_SMBUS_WORD_DATA;
4765 + case I2C_SMBUS_WORD_DATA:
4768 + case I2C_SMBUS_BLOCK_DATA:
4769 + data->block[data->block[0] + 1] =
4770 + i2c_smbus_pec(2, buf, data->block);
4771 + size = I2C_SMBUS_BLOCK_DATA_PEC;
4777 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
4778 + union i2c_smbus_data *data)
4780 + u8 buf[3], rpec, cpec;
4784 + case I2C_SMBUS_BYTE_DATA:
4785 + buf[0] = (addr << 1) | 1;
4786 + cpec = i2c_smbus_pec(2, buf, NULL);
4787 + rpec = data->byte;
4789 + case I2C_SMBUS_WORD_DATA:
4790 + buf[0] = (addr << 1) | 1;
4791 + buf[2] = data->word & 0xff;
4792 + cpec = i2c_smbus_pec(3, buf, NULL);
4793 + rpec = data->word >> 8;
4795 + case I2C_SMBUS_WORD_DATA_PEC:
4799 + case I2C_SMBUS_PROC_CALL_PEC:
4803 + case I2C_SMBUS_BLOCK_DATA_PEC:
4804 + buf[0] = (addr << 1);
4805 + buf[2] = (addr << 1) | 1;
4806 + cpec = i2c_smbus_pec(3, buf, data->block);
4807 + rpec = data->block[data->block[0] + 1];
4809 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4810 + buf[0] = (addr << 1) | 1;
4811 + rpec = i2c_smbus_partial_pec(partial, 1,
4812 + buf, data->block);
4813 + cpec = data->block[data->block[0] + 1];
4819 + if(rpec != cpec) {
4820 + DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
4827 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
4829 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4830 @@ -1022,8 +1055,9 @@
4832 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
4834 + union i2c_smbus_data data; /* only for PEC */
4835 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4836 - I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
4837 + I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
4840 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
4841 @@ -1101,8 +1135,8 @@
4843 union i2c_smbus_data data;
4847 + if (length > I2C_SMBUS_BLOCK_MAX)
4848 + length = I2C_SMBUS_BLOCK_MAX;
4849 for (i = 1; i <= length; i++)
4850 data.block[i] = values[i-1];
4851 data.block[0] = length;
4852 @@ -1111,13 +1145,50 @@
4853 I2C_SMBUS_BLOCK_DATA,&data);
4856 +/* Returns the number of read bytes */
4857 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
4858 + u8 command, u8 length, u8 *values)
4860 + union i2c_smbus_data data;
4862 + if (length > I2C_SMBUS_BLOCK_MAX - 1)
4864 + data.block[0] = length;
4865 + for (i = 1; i <= length; i++)
4866 + data.block[i] = values[i-1];
4867 + if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4868 + I2C_SMBUS_WRITE, command,
4869 + I2C_SMBUS_BLOCK_PROC_CALL, &data))
4871 + for (i = 1; i <= data.block[0]; i++)
4872 + values[i-1] = data.block[i];
4873 + return data.block[0];
4876 +/* Returns the number of read bytes */
4877 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
4878 + u8 command, u8 *values)
4880 + union i2c_smbus_data data;
4882 + if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4883 + I2C_SMBUS_READ,command,
4884 + I2C_SMBUS_I2C_BLOCK_DATA,&data))
4887 + for (i = 1; i <= data.block[0]; i++)
4888 + values[i-1] = data.block[i];
4889 + return data.block[0];
4893 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
4894 u8 command, u8 length, u8 *values)
4896 union i2c_smbus_data data;
4900 + if (length > I2C_SMBUS_I2C_BLOCK_MAX)
4901 + length = I2C_SMBUS_I2C_BLOCK_MAX;
4902 for (i = 1; i <= length; i++)
4903 data.block[i] = values[i-1];
4904 data.block[0] = length;
4905 @@ -1179,30 +1250,54 @@
4907 case I2C_SMBUS_PROC_CALL:
4908 num = 2; /* Special case */
4909 + read_write = I2C_SMBUS_READ;
4912 msgbuf0[1] = data->word & 0xff;
4913 msgbuf0[2] = (data->word >> 8) & 0xff;
4915 case I2C_SMBUS_BLOCK_DATA:
4916 + case I2C_SMBUS_BLOCK_DATA_PEC:
4917 if (read_write == I2C_SMBUS_READ) {
4918 - printk("i2c-core.o: Block read not supported under "
4919 - "I2C emulation!\n");
4921 + printk(KERN_ERR "i2c-core.o: Block read not supported "
4922 + "under I2C emulation!\n");
4925 msg[0].len = data->block[0] + 2;
4926 - if (msg[0].len > 34) {
4927 - printk("i2c-core.o: smbus_access called with "
4928 + if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
4929 + printk(KERN_ERR "i2c-core.o: smbus_access called with "
4930 "invalid block write size (%d)\n",
4935 + if(size == I2C_SMBUS_BLOCK_DATA_PEC)
4937 for (i = 1; i <= msg[0].len; i++)
4938 msgbuf0[i] = data->block[i-1];
4941 + case I2C_SMBUS_BLOCK_PROC_CALL:
4942 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4943 + printk(KERN_ERR "i2c-core.o: Block process call not supported "
4944 + "under I2C emulation!\n");
4946 + case I2C_SMBUS_I2C_BLOCK_DATA:
4947 + if (read_write == I2C_SMBUS_READ) {
4948 + msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
4950 + msg[0].len = data->block[0] + 1;
4951 + if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
4952 + printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
4953 + "invalid block write size (%d)\n",
4957 + for (i = 1; i <= data->block[0]; i++)
4958 + msgbuf0[i] = data->block[i];
4962 - printk("i2c-core.o: smbus_access called with invalid size (%d)\n",
4963 + printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
4967 @@ -1222,25 +1317,61 @@
4968 case I2C_SMBUS_PROC_CALL:
4969 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
4971 + case I2C_SMBUS_I2C_BLOCK_DATA:
4972 + /* fixed at 32 for now */
4973 + data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
4974 + for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
4975 + data->block[i+1] = msgbuf1[i];
4982 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
4983 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
4984 char read_write, u8 command, int size,
4985 union i2c_smbus_data * data)
4988 - flags = flags & I2C_M_TEN;
4989 - if (adapter->algo->smbus_xfer) {
4990 - I2C_LOCK(adapter);
4991 - res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4995 + flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4996 + if((flags & I2C_CLIENT_PEC) &&
4997 + !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4999 + if(read_write == I2C_SMBUS_READ &&
5000 + size == I2C_SMBUS_BLOCK_DATA)
5001 + size = I2C_SMBUS_BLOCK_DATA_PEC;
5002 + else if(size == I2C_SMBUS_PROC_CALL)
5003 + size = I2C_SMBUS_PROC_CALL_PEC;
5004 + else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
5005 + i2c_smbus_add_pec(addr, command,
5006 + I2C_SMBUS_BLOCK_DATA, data);
5007 + partial = data->block[data->block[0] + 1];
5008 + size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
5009 + } else if(read_write == I2C_SMBUS_WRITE &&
5010 + size != I2C_SMBUS_QUICK &&
5011 + size != I2C_SMBUS_I2C_BLOCK_DATA)
5012 + size = i2c_smbus_add_pec(addr, command, size, data);
5015 + if (adap->algo->smbus_xfer) {
5017 + res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
5019 - I2C_UNLOCK(adapter);
5022 - res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
5023 + res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
5026 + if(res >= 0 && swpec &&
5027 + size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
5028 + (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
5029 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
5030 + if(i2c_smbus_check_pec(addr, command, size, partial, data))
5036 @@ -1264,139 +1395,38 @@
5038 static int __init i2c_init(void)
5040 - printk(KERN_INFO "i2c-core.o: i2c core module\n");
5041 + printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5042 memset(adapters,0,sizeof(adapters));
5043 memset(drivers,0,sizeof(drivers));
5047 - init_MUTEX(&adap_lock);
5048 - init_MUTEX(&driver_lock);
5052 +#ifdef CONFIG_PROC_FS
5053 + return i2cproc_init();
5059 -#ifdef CONFIG_I2C_CHARDEV
5060 - extern int i2c_dev_init(void);
5062 -#ifdef CONFIG_I2C_ALGOBIT
5063 - extern int i2c_algo_bit_init(void);
5065 -#ifdef CONFIG_I2C_PHILIPSPAR
5066 - extern int i2c_bitlp_init(void);
5068 -#ifdef CONFIG_I2C_ELV
5069 - extern int i2c_bitelv_init(void);
5071 -#ifdef CONFIG_I2C_VELLEMAN
5072 - extern int i2c_bitvelle_init(void);
5074 -#ifdef CONFIG_I2C_BITVIA
5075 - extern int i2c_bitvia_init(void);
5078 -#ifdef CONFIG_I2C_ALGOPCF
5079 - extern int i2c_algo_pcf_init(void);
5081 -#ifdef CONFIG_I2C_ELEKTOR
5082 - extern int i2c_pcfisa_init(void);
5085 -#ifdef CONFIG_I2C_ALGO8XX
5086 - extern int i2c_algo_8xx_init(void);
5088 -#ifdef CONFIG_I2C_RPXLITE
5089 - extern int i2c_rpx_init(void);
5092 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5093 - extern int i2c_algo_sibyte_init(void);
5094 - extern int i2c_sibyte_init(void);
5096 -#ifdef CONFIG_I2C_MAX1617
5097 - extern int i2c_max1617_init(void);
5101 -#ifdef CONFIG_I2C_PROC
5102 - extern int sensors_init(void);
5103 +static void __exit i2c_exit(void)
5105 +#ifdef CONFIG_PROC_FS
5106 + i2cproc_cleanup();
5110 -/* This is needed for automatic patch generation: sensors code starts here */
5111 -/* This is needed for automatic patch generation: sensors code ends here */
5113 +/* leave this in for now simply to make patching easier so we don't have
5114 + to remove the call in drivers/char/mem.c */
5115 int __init i2c_init_all(void)
5117 - /* --------------------- global ----- */
5120 -#ifdef CONFIG_I2C_CHARDEV
5123 - /* --------------------- bit -------- */
5124 -#ifdef CONFIG_I2C_ALGOBIT
5125 - i2c_algo_bit_init();
5127 -#ifdef CONFIG_I2C_PHILIPSPAR
5130 -#ifdef CONFIG_I2C_ELV
5131 - i2c_bitelv_init();
5133 -#ifdef CONFIG_I2C_VELLEMAN
5134 - i2c_bitvelle_init();
5137 - /* --------------------- pcf -------- */
5138 -#ifdef CONFIG_I2C_ALGOPCF
5139 - i2c_algo_pcf_init();
5141 -#ifdef CONFIG_I2C_ELEKTOR
5142 - i2c_pcfisa_init();
5145 - /* --------------------- 8xx -------- */
5146 -#ifdef CONFIG_I2C_ALGO8XX
5147 - i2c_algo_8xx_init();
5149 -#ifdef CONFIG_I2C_RPXLITE
5153 - /* --------------------- SiByte -------- */
5154 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5155 - i2c_algo_sibyte_init();
5156 - i2c_sibyte_init();
5158 -#ifdef CONFIG_I2C_MAX1617
5159 - i2c_max1617_init();
5162 - /* -------------- proc interface ---- */
5163 -#ifdef CONFIG_I2C_PROC
5166 -/* This is needed for automatic patch generation: sensors code starts here */
5167 -/* This is needed for automatic patch generation: sensors code ends here */
5176 EXPORT_SYMBOL(i2c_add_adapter);
5177 EXPORT_SYMBOL(i2c_del_adapter);
5178 EXPORT_SYMBOL(i2c_add_driver);
5179 EXPORT_SYMBOL(i2c_del_driver);
5180 EXPORT_SYMBOL(i2c_attach_client);
5181 EXPORT_SYMBOL(i2c_detach_client);
5182 -EXPORT_SYMBOL(i2c_inc_use_client);
5183 -EXPORT_SYMBOL(i2c_dec_use_client);
5184 -EXPORT_SYMBOL(i2c_get_client);
5185 EXPORT_SYMBOL(i2c_use_client);
5186 EXPORT_SYMBOL(i2c_release_client);
5187 EXPORT_SYMBOL(i2c_check_addr);
5188 @@ -1420,24 +1450,18 @@
5189 EXPORT_SYMBOL(i2c_smbus_process_call);
5190 EXPORT_SYMBOL(i2c_smbus_read_block_data);
5191 EXPORT_SYMBOL(i2c_smbus_write_block_data);
5192 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
5193 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
5195 EXPORT_SYMBOL(i2c_get_functionality);
5196 EXPORT_SYMBOL(i2c_check_functionality);
5199 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5200 MODULE_DESCRIPTION("I2C-Bus main module");
5201 -MODULE_PARM(i2c_debug, "i");
5202 -MODULE_PARM_DESC(i2c_debug,"debug level");
5203 MODULE_LICENSE("GPL");
5205 -int init_module(void)
5207 - return i2c_init();
5209 +MODULE_PARM(i2c_debug, "i");
5210 +MODULE_PARM_DESC(i2c_debug,"debug level");
5212 -void cleanup_module(void)
5214 - i2cproc_cleanup();
5217 +module_init(i2c_init);
5218 +module_exit(i2c_exit);
5219 --- linux-old/drivers/i2c/i2c-dev.c Wed Aug 27 16:11:46 2003
5220 +++ linux/drivers/i2c/i2c-dev.c Sun Dec 7 11:17:40 2003
5222 /* The devfs code is contributed by Philipp Matthias Hahn
5223 <pmhahn@titan.lahn.de> */
5228 -#include <linux/config.h>
5229 #include <linux/kernel.h>
5230 #include <linux/module.h>
5231 #include <linux/fs.h>
5232 #include <linux/slab.h>
5233 -#include <linux/version.h>
5234 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5235 #include <linux/smp_lock.h>
5236 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5237 #ifdef CONFIG_DEVFS_FS
5238 #include <linux/devfs_fs_kernel.h>
5242 -/* If you want debugging uncomment: */
5243 -/* #define DEBUG */
5245 #include <linux/init.h>
5246 -#include <asm/uaccess.h>
5248 #include <linux/i2c.h>
5249 #include <linux/i2c-dev.h>
5250 +#include <asm/uaccess.h>
5252 +/* If you want debugging uncomment: */
5253 +/* #define DEBUG */
5256 -extern int init_module(void);
5257 -extern int cleanup_module(void);
5258 -#endif /* def MODULE */
5260 /* struct file_operations changed too often in the 2.1 series for nice code */
5262 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5263 -static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin);
5265 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5267 static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
5269 static int i2cdev_command(struct i2c_client *client, unsigned int cmd,
5277 - int __init i2c_dev_init(void);
5278 -static int i2cdev_cleanup(void);
5280 static struct file_operations i2cdev_fops = {
5281 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5282 - owner: THIS_MODULE,
5283 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5284 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5285 - llseek: i2cdev_lseek,
5287 - llseek: no_llseek,
5289 - read: i2cdev_read,
5290 - write: i2cdev_write,
5291 - ioctl: i2cdev_ioctl,
5292 - open: i2cdev_open,
5293 - release: i2cdev_release,
5294 + .owner = THIS_MODULE,
5295 + .llseek = no_llseek,
5296 + .read = i2cdev_read,
5297 + .write = i2cdev_write,
5298 + .ioctl = i2cdev_ioctl,
5299 + .open = i2cdev_open,
5300 + .release = i2cdev_release,
5303 #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
5304 @@ -111,42 +83,22 @@
5307 static struct i2c_driver i2cdev_driver = {
5308 - name: "i2c-dev dummy driver",
5309 - id: I2C_DRIVERID_I2CDEV,
5310 - flags: I2C_DF_DUMMY,
5311 - attach_adapter: i2cdev_attach_adapter,
5312 - detach_client: i2cdev_detach_client,
5313 - command: i2cdev_command,
5316 + .owner = THIS_MODULE, /* not really used */
5317 + .name = "i2c-dev dummy driver",
5318 + .id = I2C_DRIVERID_I2CDEV,
5319 + .flags = I2C_DF_DUMMY,
5320 + .attach_adapter = i2cdev_attach_adapter,
5321 + .detach_client = i2cdev_detach_client,
5322 + .command = i2cdev_command,
5325 static struct i2c_client i2cdev_client_template = {
5326 - name: "I2C /dev entry",
5330 -/* adapter: NULL, */
5331 - driver: &i2cdev_driver,
5333 + .name = "I2C /dev entry",
5336 + .driver = &i2cdev_driver,
5339 -static int i2cdev_initialized;
5341 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5342 -/* Note that the lseek function is called llseek in 2.1 kernels. But things
5343 - are complicated enough as is. */
5344 -loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin)
5347 - struct inode *inode = file->f_dentry->d_inode;
5348 - printk("i2c-dev.o: i2c-%d lseek to %ld bytes relative to %d.\n",
5349 - MINOR(inode->i_rdev),(long) offset,origin);
5355 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5358 @@ -159,16 +111,16 @@
5360 struct i2c_client *client = (struct i2c_client *)file->private_data;
5367 /* copy user space data to kernel space. */
5368 tmp = kmalloc(count,GFP_KERNEL);
5373 - printk("i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
5374 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
5379 struct inode *inode = file->f_dentry->d_inode;
5387 /* copy user space data to kernel space. */
5388 tmp = kmalloc(count,GFP_KERNEL);
5394 - printk("i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
5395 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
5398 ret = i2c_master_send(client,tmp,count);
5400 unsigned long funcs;
5403 - printk("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
5404 - MINOR(inode->i_rdev),cmd, arg);
5405 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
5406 + minor(inode->i_rdev),cmd, arg);
5410 @@ -244,6 +196,12 @@
5412 client->flags &= ~I2C_M_TEN;
5416 + client->flags |= I2C_CLIENT_PEC;
5418 + client->flags &= ~I2C_CLIENT_PEC;
5421 funcs = i2c_get_functionality(client->adapter);
5422 return (copy_to_user((unsigned long *)arg,&funcs,
5423 @@ -344,9 +302,10 @@
5424 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
5425 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
5426 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
5427 - (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
5428 + (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
5429 + (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
5431 - printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5432 + printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5437 if ((data_arg.read_write != I2C_SMBUS_READ) &&
5438 (data_arg.read_write != I2C_SMBUS_WRITE)) {
5440 - printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5441 + printk(KERN_DEBUG "i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5442 data_arg.read_write);
5447 if (data_arg.data == NULL) {
5449 - printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5450 + printk(KERN_DEBUG "i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5454 @@ -387,10 +346,11 @@
5455 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
5456 (data_arg.size == I2C_SMBUS_PROC_CALL))
5457 datasize = sizeof(data_arg.data->word);
5458 - else /* size == I2C_SMBUS_BLOCK_DATA */
5459 + else /* size == smbus block, i2c block, or block proc. call */
5460 datasize = sizeof(data_arg.data->block);
5462 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
5463 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
5464 (data_arg.read_write == I2C_SMBUS_WRITE)) {
5465 if (copy_from_user(&temp, data_arg.data, datasize))
5468 data_arg.read_write,
5469 data_arg.command,data_arg.size,&temp);
5470 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
5471 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
5472 (data_arg.read_write == I2C_SMBUS_READ))) {
5473 if (copy_to_user(data_arg.data, &temp, datasize))
5475 @@ -413,12 +374,12 @@
5477 int i2cdev_open (struct inode *inode, struct file *file)
5479 - unsigned int minor = MINOR(inode->i_rdev);
5480 + unsigned int minor = minor(inode->i_rdev);
5481 struct i2c_client *client;
5483 if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
5485 - printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5486 + printk(KERN_DEBUG "i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5490 @@ -429,39 +390,35 @@
5491 if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
5493 memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
5495 + /* registered with adapter, passed as client to user */
5496 client->adapter = i2cdev_adaps[minor];
5497 file->private_data = client;
5499 - if (i2cdev_adaps[minor]->inc_use)
5500 - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
5501 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5502 - MOD_INC_USE_COUNT;
5503 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5504 + if(client->adapter->owner)
5505 + __MOD_INC_USE_COUNT(client->adapter->owner);
5508 - printk("i2c-dev.o: opened i2c-%d\n",minor);
5509 + printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
5514 static int i2cdev_release (struct inode *inode, struct file *file)
5516 - unsigned int minor = MINOR(inode->i_rdev);
5517 - kfree(file->private_data);
5518 - file->private_data=NULL;
5520 - printk("i2c-dev.o: Closed: i2c-%d\n", minor);
5522 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5523 - MOD_DEC_USE_COUNT;
5524 -#else /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5526 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5527 - if (i2cdev_adaps[minor]->dec_use)
5528 - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
5529 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5531 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5532 + struct i2c_client *client;
5534 + unsigned int minor = minor(inode->i_rdev);
5537 + client = file->private_data;
5538 + file->private_data = NULL;
5539 + if(client->adapter->owner)
5540 + __MOD_DEC_USE_COUNT(client->adapter->owner);
5543 + printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
5548 @@ -471,11 +428,11 @@
5551 if ((i = i2c_adapter_id(adap)) < 0) {
5552 - printk("i2c-dev.o: Unknown adapter ?!?\n");
5553 + printk(KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n");
5556 if (i >= I2CDEV_ADAPS_MAX) {
5557 - printk("i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5558 + printk(KERN_DEBUG "i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5563 devfs_i2c[i] = devfs_register (devfs_handle, name,
5564 DEVFS_FL_DEFAULT, I2C_MAJOR, i,
5565 S_IFCHR | S_IRUSR | S_IWUSR,
5566 - &i2cdev_fops, NULL);
5567 + &i2cdev_fops, adap);
5569 - printk("i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5570 + printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5572 /* This is actually a detach_adapter call! */
5573 #ifdef CONFIG_DEVFS_FS
5576 i2cdev_adaps[i] = NULL;
5578 - printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5579 + printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5583 @@ -518,78 +475,43 @@
5587 - printk("i2c-dev.o: i2c /dev entries driver module\n");
5588 + printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5590 - i2cdev_initialized = 0;
5591 #ifdef CONFIG_DEVFS_FS
5592 if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
5594 if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
5596 - printk("i2c-dev.o: unable to get major %d for i2c bus\n",
5597 + printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
5601 #ifdef CONFIG_DEVFS_FS
5602 devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
5604 - i2cdev_initialized ++;
5606 if ((res = i2c_add_driver(&i2cdev_driver))) {
5607 - printk("i2c-dev.o: Driver registration failed, module not inserted.\n");
5609 + printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
5610 +#ifdef CONFIG_DEVFS_FS
5611 + devfs_unregister(devfs_handle);
5613 + unregister_chrdev(I2C_MAJOR,"i2c");
5616 - i2cdev_initialized ++;
5620 -int i2cdev_cleanup(void)
5621 +static void __exit i2c_dev_exit(void)
5625 - if (i2cdev_initialized >= 2) {
5626 - if ((res = i2c_del_driver(&i2cdev_driver))) {
5627 - printk("i2c-dev.o: Driver deregistration failed, "
5628 - "module not removed.\n");
5631 - i2cdev_initialized --;
5634 - if (i2cdev_initialized >= 1) {
5635 + i2c_del_driver(&i2cdev_driver);
5636 #ifdef CONFIG_DEVFS_FS
5637 - devfs_unregister(devfs_handle);
5638 - if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
5640 - if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
5641 + devfs_unregister(devfs_handle);
5643 - printk("i2c-dev.o: unable to release major %d for i2c bus\n",
5647 - i2cdev_initialized --;
5650 + unregister_chrdev(I2C_MAJOR,"i2c");
5657 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5658 MODULE_DESCRIPTION("I2C /dev entries driver");
5659 MODULE_LICENSE("GPL");
5661 -int init_module(void)
5663 - return i2c_dev_init();
5666 -int cleanup_module(void)
5668 - return i2cdev_cleanup();
5671 -#endif /* def MODULE */
5673 +module_init(i2c_dev_init);
5674 +module_exit(i2c_dev_exit);
5675 --- linux-old/include/linux/i2c-dev.h Tue Jul 15 10:23:54 2003
5676 +++ linux/include/linux/i2c-dev.h Sun Dec 7 11:17:40 2003
5678 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5687 +#ifndef _LINUX_I2C_DEV_H
5688 +#define _LINUX_I2C_DEV_H
5690 #include <linux/types.h>
5691 -#include <linux/i2c.h>
5693 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
5694 +#define minor(d) MINOR(d)
5697 /* Some IOCTL commands are defined in <linux/i2c.h> */
5698 /* Note: 10-bit addresses are NOT supported! */
5700 __u32 nmsgs; /* number of i2c_msgs */
5705 -#include <sys/ioctl.h>
5707 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
5708 - int size, union i2c_smbus_data *data)
5710 - struct i2c_smbus_ioctl_data args;
5712 - args.read_write = read_write;
5713 - args.command = command;
5716 - return ioctl(file,I2C_SMBUS,&args);
5720 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
5722 - return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
5725 -static inline __s32 i2c_smbus_read_byte(int file)
5727 - union i2c_smbus_data data;
5728 - if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
5731 - return 0x0FF & data.byte;
5734 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
5736 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
5737 - I2C_SMBUS_BYTE,NULL);
5740 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
5742 - union i2c_smbus_data data;
5743 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5744 - I2C_SMBUS_BYTE_DATA,&data))
5747 - return 0x0FF & data.byte;
5750 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
5753 - union i2c_smbus_data data;
5754 - data.byte = value;
5755 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5756 - I2C_SMBUS_BYTE_DATA, &data);
5759 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
5761 - union i2c_smbus_data data;
5762 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5763 - I2C_SMBUS_WORD_DATA,&data))
5766 - return 0x0FFFF & data.word;
5769 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
5772 - union i2c_smbus_data data;
5773 - data.word = value;
5774 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5775 - I2C_SMBUS_WORD_DATA, &data);
5778 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
5780 - union i2c_smbus_data data;
5781 - data.word = value;
5782 - if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5783 - I2C_SMBUS_PROC_CALL,&data))
5786 - return 0x0FFFF & data.word;
5790 -/* Returns the number of read bytes */
5791 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
5794 - union i2c_smbus_data data;
5796 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5797 - I2C_SMBUS_BLOCK_DATA,&data))
5800 - for (i = 1; i <= data.block[0]; i++)
5801 - values[i-1] = data.block[i];
5802 - return data.block[0];
5806 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
5807 - __u8 length, __u8 *values)
5809 - union i2c_smbus_data data;
5813 - for (i = 1; i <= length; i++)
5814 - data.block[i] = values[i-1];
5815 - data.block[0] = length;
5816 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5817 - I2C_SMBUS_BLOCK_DATA, &data);
5820 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
5821 - __u8 length, __u8 *values)
5823 - union i2c_smbus_data data;
5827 - for (i = 1; i <= length; i++)
5828 - data.block[i] = values[i-1];
5829 - data.block[0] = length;
5830 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5831 - I2C_SMBUS_I2C_BLOCK_DATA, &data);
5834 -#endif /* ndef __KERNEL__ */
5837 +#endif /* _LINUX_I2C_DEV_H */
5838 --- linux-old/drivers/i2c/i2c-elektor.c Thu Oct 11 15:05:47 2001
5839 +++ linux/drivers/i2c/i2c-elektor.c Sun Dec 7 11:17:40 2003
5841 #include <linux/module.h>
5842 #include <linux/delay.h>
5843 #include <linux/slab.h>
5844 -#include <linux/version.h>
5845 #include <linux/init.h>
5846 +#include <linux/interrupt.h>
5847 #include <linux/pci.h>
5848 -#include <asm/irq.h>
5849 -#include <asm/io.h>
5851 +#include <linux/wait.h>
5852 #include <linux/i2c.h>
5853 #include <linux/i2c-algo-pcf.h>
5854 -#include <linux/i2c-elektor.h>
5855 -#include "i2c-pcf8584.h"
5856 +#include <asm/io.h>
5857 +#include <asm/irq.h>
5859 #define DEFAULT_BASE 0x330
5861 -static int base = 0;
5862 -static int irq = 0;
5865 static int clock = 0x1c;
5866 static int own = 0x55;
5867 -static int mmapped = 0;
5868 -static int i2c_debug = 0;
5869 +static int mmapped;
5870 +static int i2c_debug;
5872 /* vdovikin: removed static struct i2c_pcf_isa gpi; code -
5873 this module in real supports only one device, due to missing arguments
5874 in some functions, called from the algo-pcf module. Sometimes it's
5875 need to be rewriten - but for now just remove this for simpler reading */
5877 -#if (LINUX_VERSION_CODE < 0x020301)
5878 -static struct wait_queue *pcf_wait = NULL;
5880 static wait_queue_head_t pcf_wait;
5882 static int pcf_pending;
5883 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5885 /* ----- global defines ----------------------------------------------- */
5886 #define DEB(x) if (i2c_debug>=1) x
5888 #define DEB3(x) if (i2c_debug>=3) x
5889 #define DEBE(x) x /* error messages */
5892 +/* compatibility */
5894 +#define isa_readb readb
5898 +#define isa_writeb writeb
5901 /* ----- local functions ---------------------------------------------- */
5903 static void pcf_isa_setbyte(void *data, int ctl, int val)
5905 int address = ctl ? (base + 1) : base;
5908 + /* enable irq if any specified for serial operation */
5909 + if (ctl && irq && (val & I2C_PCF_ESO)) {
5913 - DEB3(printk("i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5914 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5917 case 0: /* regular I/O */
5920 case 2: /* double mapped I/O needed for UP2000 board,
5921 I don't know why this... */
5922 - writeb(val, address);
5923 + isa_writeb(val, address);
5925 case 1: /* memory mapped I/O */
5926 - writeb(val, address);
5927 + isa_writeb(val, address);
5932 static int pcf_isa_getbyte(void *data, int ctl)
5934 int address = ctl ? (base + 1) : base;
5935 - int val = mmapped ? readb(address) : inb(address);
5936 + int val = mmapped ? isa_readb(address) : inb(address);
5938 - DEB3(printk("i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5939 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5943 @@ -120,12 +126,12 @@
5948 + spin_lock_irq(&irq_driver_lock);
5949 if (pcf_pending == 0) {
5950 interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
5954 + spin_unlock_irq(&irq_driver_lock);
5958 @@ -141,16 +147,16 @@
5959 static int pcf_isa_init(void)
5962 - if (check_region(base, 2) < 0 ) {
5963 - printk("i2c-elektor.o: requested I/O region (0x%X:2) is in use.\n", base);
5964 + if (!request_region(base, 2, "i2c (isa bus adapter)")) {
5966 + "i2c-elektor.o: requested I/O region (0x%X:2) "
5967 + "is in use.\n", base);
5970 - request_region(base, 2, "i2c (isa bus adapter)");
5974 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", 0) < 0) {
5975 - printk("i2c-elektor.o: Request irq%d failed\n", irq);
5976 + printk(KERN_ERR "i2c-elektor.o: Request irq%d failed\n", irq);
5980 @@ -159,70 +165,29 @@
5984 -static void __exit pcf_isa_exit(void)
5991 - release_region(base , 2);
5996 -static int pcf_isa_reg(struct i2c_client *client)
6002 -static int pcf_isa_unreg(struct i2c_client *client)
6007 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
6010 - MOD_INC_USE_COUNT;
6014 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
6017 - MOD_DEC_USE_COUNT;
6022 /* ------------------------------------------------------------------------
6023 * Encapsulate the above functions in the correct operations structure.
6024 * This is only done when more than one hardware adapter is supported.
6026 static struct i2c_algo_pcf_data pcf_isa_data = {
6032 - pcf_isa_waitforpin,
6033 - 10, 10, 100, /* waits, timeout */
6034 + .setpcf = pcf_isa_setbyte,
6035 + .getpcf = pcf_isa_getbyte,
6036 + .getown = pcf_isa_getown,
6037 + .getclock = pcf_isa_getclock,
6038 + .waitforpin = pcf_isa_waitforpin,
6044 static struct i2c_adapter pcf_isa_ops = {
6045 - "PCF8584 ISA adapter",
6053 + .owner = THIS_MODULE,
6054 + .name = "PCF8584 ISA adapter",
6055 + .id = I2C_HW_P_ELEK,
6056 + .algo_data = &pcf_isa_data,
6059 -int __init i2c_pcfisa_init(void)
6060 +static int __init i2c_pcfisa_init(void)
6063 /* check to see we have memory mapped PCF8584 connected to the
6065 /* yeap, we've found cypress, let's check config */
6066 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
6068 - DEB3(printk("i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
6069 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
6071 /* UP2000 board has this register set to 0xe1,
6072 but the most significant bit as seems can be
6074 8.25 MHz (PCI/4) clock
6075 (this can be read from cypress) */
6076 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
6077 - printk("i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
6078 + printk(KERN_INFO "i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
6082 @@ -269,35 +234,51 @@
6084 /* sanity checks for mmapped I/O */
6085 if (mmapped && base < 0xc8000) {
6086 - printk("i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
6087 + printk(KERN_ERR "i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
6091 - printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n");
6092 + printk(KERN_INFO "i2c-elektor.o: i2c pcf8584-isa adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6095 base = DEFAULT_BASE;
6098 -#if (LINUX_VERSION_CODE >= 0x020301)
6099 init_waitqueue_head(&pcf_wait);
6101 - if (pcf_isa_init() == 0) {
6102 - if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
6105 + if (pcf_isa_init())
6108 + if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
6111 - printk("i2c-elektor.o: found device at %#x.\n", base);
6112 + printk(KERN_ERR "i2c-elektor.o: found device at %#x.\n", base);
6123 + release_region(base , 2);
6129 +static void __exit i2c_pcfisa_exit(void)
6131 + i2c_pcf_del_bus(&pcf_isa_ops);
6139 + release_region(base , 2);
6143 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
6144 MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
6145 MODULE_LICENSE("GPL");
6146 @@ -309,15 +290,5 @@
6147 MODULE_PARM(mmapped, "i");
6148 MODULE_PARM(i2c_debug, "i");
6150 -int init_module(void)
6152 - return i2c_pcfisa_init();
6155 -void cleanup_module(void)
6157 - i2c_pcf_del_bus(&pcf_isa_ops);
6162 +module_init(i2c_pcfisa_init);
6163 +module_exit(i2c_pcfisa_exit);
6164 --- linux-old/include/linux/i2c-elektor.h Thu Oct 11 15:05:47 2001
6165 +++ linux/include/linux/i2c-elektor.h Sun Dec 7 11:17:40 2003
6167 -/* ------------------------------------------------------------------------- */
6168 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
6169 -/* ------------------------------------------------------------------------- */
6170 -/* Copyright (C) 1995-97 Simon G. Vogl
6171 - 1998-99 Hans Berglund
6173 - This program is free software; you can redistribute it and/or modify
6174 - it under the terms of the GNU General Public License as published by
6175 - the Free Software Foundation; either version 2 of the License, or
6176 - (at your option) any later version.
6178 - This program is distributed in the hope that it will be useful,
6179 - but WITHOUT ANY WARRANTY; without even the implied warranty of
6180 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6181 - GNU General Public License for more details.
6183 - You should have received a copy of the GNU General Public License
6184 - along with this program; if not, write to the Free Software
6185 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6186 -/* ------------------------------------------------------------------------- */
6188 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6189 - Frodo Looijaard <frodol@dds.nl> */
6193 -#ifndef I2C_PCF_ELEKTOR_H
6194 -#define I2C_PCF_ELEKTOR_H 1
6197 - * This struct contains the hw-dependent functions of PCF8584 adapters to
6198 - * manipulate the registers, and to init any hw-specific features.
6199 - * vdovikin: removed: this module in real supports only one device,
6200 - * due to missing arguments in some functions, called from the algo-pcf module.
6201 - * Sometimes it's need to be rewriten -
6202 - * but for now just remove this for simpler reading */
6205 -struct i2c_pcf_isa {
6213 -#endif /* PCF_ELEKTOR_H */
6214 --- linux-old/drivers/i2c/i2c-elv.c Thu Oct 11 15:05:47 2001
6215 +++ linux/drivers/i2c/i2c-elv.c Sun Dec 7 11:17:40 2003
6217 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6218 Frodo Looijaard <frodol@dds.nl> */
6223 #include <linux/kernel.h>
6224 #include <linux/module.h>
6225 #include <linux/delay.h>
6226 #include <linux/slab.h>
6227 -#include <linux/version.h>
6228 #include <linux/init.h>
6230 -#include <asm/uaccess.h>
6232 #include <linux/ioport.h>
6233 -#include <asm/io.h>
6234 #include <linux/errno.h>
6235 #include <linux/i2c.h>
6236 #include <linux/i2c-algo-bit.h>
6237 +#include <asm/io.h>
6239 #define DEFAULT_BASE 0x378
6243 static int bit_elv_init(void)
6245 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6248 - /* test for ELV adap. */
6249 - if (inb(base+1) & 0x80) { /* BUSY should be high */
6250 - DEBINIT(printk("i2c-elv.o: Busy was low.\n"));
6253 - outb(0x0c,base+2); /* SLCT auf low */
6255 - if ( !(inb(base+1) && 0x10) ) {
6256 - outb(0x04,base+2);
6257 - DEBINIT(printk("i2c-elv.o: Select was high.\n"));
6261 - request_region(base,(base == 0x3bc)? 3 : 8,
6262 - "i2c (ELV adapter)");
6264 - bit_elv_setsda((void*)base,1);
6265 - bit_elv_setscl((void*)base,1);
6266 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
6267 + "i2c (ELV adapter)"))
6270 + if (inb(base+1) & 0x80) { /* BUSY should be high */
6271 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
6275 + outb(0x0c,base+2); /* SLCT auf low */
6277 + if (!(inb(base+1) && 0x10)) {
6278 + outb(0x04,base+2);
6279 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
6285 -static void __exit bit_elv_exit(void)
6287 - release_region( base , (base == 0x3bc)? 3 : 8 );
6290 -static int bit_elv_reg(struct i2c_client *client)
6293 + bit_elv_setsda((void*)base,1);
6294 + bit_elv_setscl((void*)base,1);
6298 -static int bit_elv_unreg(struct i2c_client *client)
6303 -static void bit_elv_inc_use(struct i2c_adapter *adap)
6306 - MOD_INC_USE_COUNT;
6310 -static void bit_elv_dec_use(struct i2c_adapter *adap)
6313 - MOD_DEC_USE_COUNT;
6316 + release_region(base , (base == 0x3bc) ? 3 : 8);
6320 /* ------------------------------------------------------------------------
6321 @@ -149,28 +118,25 @@
6322 * This is only done when more than one hardware adapter is supported.
6324 static struct i2c_algo_bit_data bit_elv_data = {
6330 - 80, 80, 100, /* waits, timeout */
6331 + .setsda = bit_elv_setsda,
6332 + .setscl = bit_elv_setscl,
6333 + .getsda = bit_elv_getsda,
6334 + .getscl = bit_elv_getscl,
6340 static struct i2c_adapter bit_elv_ops = {
6341 - "ELV Parallel port adaptor",
6349 + .owner = THIS_MODULE,
6350 + .name = "ELV Parallel port adaptor",
6351 + .id = I2C_HW_B_ELV,
6352 + .algo_data = &bit_elv_data,
6355 -int __init i2c_bitelv_init(void)
6356 +static int __init i2c_bitelv_init(void)
6358 - printk("i2c-elv.o: i2c ELV parallel port adapter module\n");
6359 + printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6361 /* probe some values */
6363 @@ -190,30 +156,23 @@
6367 - printk("i2c-elv.o: found device at %#x.\n",base);
6368 + printk(KERN_DEBUG "i2c-elv.o: found device at %#x.\n",base);
6372 +static void __exit i2c_bitelv_exit(void)
6374 + i2c_bit_del_bus(&bit_elv_ops);
6375 + release_region(base , (base == 0x3bc) ? 3 : 8);
6381 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
6382 MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
6383 MODULE_LICENSE("GPL");
6386 MODULE_PARM(base, "i");
6388 -int init_module(void)
6390 - return i2c_bitelv_init();
6393 -void cleanup_module(void)
6395 - i2c_bit_del_bus(&bit_elv_ops);
6400 +module_init(i2c_bitelv_init);
6401 +module_exit(i2c_bitelv_exit);
6402 --- linux-old/drivers/i2c/i2c-frodo.c Thu Jan 1 00:00:00 1970
6403 +++ linux/drivers/i2c/i2c-frodo.c Sun Dec 7 11:17:40 2003
6407 + * linux/drivers/i2c/i2c-frodo.c
6409 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
6411 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
6412 + * Development board (Frodo).
6414 + * This source code is free software; you can redistribute it and/or
6415 + * modify it under the terms of the GNU General Public License
6416 + * version 2 as published by the Free Software Foundation.
6419 +#include <linux/module.h>
6420 +#include <linux/kernel.h>
6421 +#include <linux/init.h>
6422 +#include <linux/delay.h>
6423 +#include <linux/i2c.h>
6424 +#include <linux/i2c-algo-bit.h>
6425 +#include <asm/hardware.h>
6428 +static void frodo_setsda (void *data,int state)
6431 + FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
6433 + FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
6436 +static void frodo_setscl (void *data,int state)
6439 + FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
6441 + FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
6444 +static int frodo_getsda (void *data)
6446 + return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
6449 +static int frodo_getscl (void *data)
6451 + return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
6454 +static struct i2c_algo_bit_data bit_frodo_data = {
6455 + .setsda = frodo_setsda,
6456 + .setscl = frodo_setscl,
6457 + .getsda = frodo_getsda,
6458 + .getscl = frodo_getscl,
6464 +static struct i2c_adapter frodo_ops = {
6465 + .owner = THIS_MODULE,
6466 + .name = "Frodo adapter driver",
6467 + .id = I2C_HW_B_FRODO,
6468 + .algo_data = &bit_frodo_data,
6471 +static int __init i2c_frodo_init (void)
6473 + return i2c_bit_add_bus(&frodo_ops);
6476 +static void __exit i2c_frodo_exit (void)
6478 + i2c_bit_del_bus(&frodo_ops);
6481 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
6482 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
6483 +MODULE_LICENSE ("GPL");
6485 +module_init (i2c_frodo_init);
6486 +module_exit (i2c_frodo_exit);
6488 --- linux-old/include/linux/i2c-id.h Tue Jul 15 10:23:54 2003
6489 +++ linux/include/linux/i2c-id.h Sun Dec 7 11:17:40 2003
6491 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6492 /* ------------------------------------------------------------------------- */
6497 +#ifndef LINUX_I2C_ID_H
6498 +#define LINUX_I2C_ID_H
6503 * This file is part of the i2c-bus package and contains the identifier
6504 * values for drivers, adapters and other folk populating these serial
6506 #define I2C_DRIVERID_DRP3510 43 /* ADR decoder (Astra Radio) */
6507 #define I2C_DRIVERID_SP5055 44 /* Satellite tuner */
6508 #define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */
6509 -#define I2C_DRIVERID_ADV717X 48 /* video encoder */
6510 +#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */
6511 +#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */
6512 +#define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */
6513 +#define I2C_DRIVERID_ZR36067 49 /* Zoran 36067 video encoder */
6514 +#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */
6515 +#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */
6516 +#define I2C_DRIVERID_STM41T00 52 /* real time clock */
6517 +#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
6518 +#define I2C_DRIVERID_ADV7170 54 /* video encoder */
6519 +#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */
6520 +#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
6521 +#define I2C_DRIVERID_SAA7191 57 /* video encoder */
6522 +#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
6523 +#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */
6524 +#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */
6528 #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */
6529 #define I2C_DRIVERID_EXP1 0xF1
6532 #define I2C_DRIVERID_I2CDEV 900
6533 #define I2C_DRIVERID_I2CPROC 901
6534 +#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
6535 +#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */
6537 /* IDs -- Use DRIVERIDs 1000-1999 for sensors.
6538 These were originally in sensors.h in the lm_sensors package */
6539 @@ -128,6 +147,25 @@
6540 #define I2C_DRIVERID_ADM1024 1025
6541 #define I2C_DRIVERID_IT87 1026
6542 #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
6543 +#define I2C_DRIVERID_FSCPOS 1028
6544 +#define I2C_DRIVERID_FSCSCY 1029
6545 +#define I2C_DRIVERID_PCF8591 1030
6546 +#define I2C_DRIVERID_SMSC47M1 1031
6547 +#define I2C_DRIVERID_VT1211 1032
6548 +#define I2C_DRIVERID_LM92 1033
6549 +#define I2C_DRIVERID_VT8231 1034
6550 +#define I2C_DRIVERID_SMARTBATT 1035
6551 +#define I2C_DRIVERID_BMCSENSORS 1036
6552 +#define I2C_DRIVERID_FS451 1037
6553 +#define I2C_DRIVERID_W83627HF 1038
6554 +#define I2C_DRIVERID_LM85 1039
6555 +#define I2C_DRIVERID_LM83 1040
6556 +#define I2C_DRIVERID_SAA1064 1041
6557 +#define I2C_DRIVERID_LM90 1042
6558 +#define I2C_DRIVERID_ASB100 1043
6559 +#define I2C_DRIVERID_MAX6650 1044
6560 +#define I2C_DRIVERID_XEONTEMP 1045
6561 +#define I2C_DRIVERID_FSCHER 1046
6564 * ---- Adapter types ----------------------------------------------------
6565 @@ -144,10 +182,21 @@
6566 #define I2C_ALGO_ISA 0x050000 /* lm_sensors ISA pseudo-adapter */
6567 #define I2C_ALGO_SAA7146 0x060000 /* SAA 7146 video decoder bus */
6568 #define I2C_ALGO_ACB 0x070000 /* ACCESS.bus algorithm */
6570 +#define I2C_ALGO_IIC 0x080000 /* ITE IIC bus */
6571 +#define I2C_ALGO_SAA7134 0x090000
6572 +#define I2C_ALGO_MPC824X 0x0a0000 /* Motorola 8240 / 8245 */
6573 +#define I2C_ALGO_IPMI 0x0b0000 /* IPMI dummy adapter */
6574 +#define I2C_ALGO_IPMB 0x0c0000 /* IPMB adapter */
6575 +#define I2C_ALGO_MPC107 0x0d0000
6576 #define I2C_ALGO_EC 0x100000 /* ACPI embedded controller */
6578 #define I2C_ALGO_MPC8XX 0x110000 /* MPC8xx PowerPC I2C algorithm */
6579 +#define I2C_ALGO_OCP 0x120000 /* IBM or otherwise On-chip I2C algorithm */
6580 +#define I2C_ALGO_BITHS 0x130000 /* enhanced bit style adapters */
6581 +#define I2C_ALGO_OCP_IOP3XX 0x140000 /* XSCALE IOP3XX On-chip I2C alg */
6582 +#define I2C_ALGO_SIBYTE 0x150000 /* Broadcom SiByte SOCs */
6583 +#define I2C_ALGO_SGI 0x160000 /* SGI algorithm */
6584 +#define I2C_ALGO_USB 0x170000 /* USB algorithm */
6586 #define I2C_ALGO_EXP 0x800000 /* experimental */
6588 @@ -175,21 +224,46 @@
6589 #define I2C_HW_B_I810 0x0a /* Intel I810 */
6590 #define I2C_HW_B_VOO 0x0b /* 3dfx Voodoo 3 / Banshee */
6591 #define I2C_HW_B_PPORT 0x0c /* Primitive parallel port adapter */
6592 +#define I2C_HW_B_SAVG 0x0d /* Savage 4 */
6593 +#define I2C_HW_B_SCX200 0x0e /* Nat'l Semi SCx200 I2C */
6594 #define I2C_HW_B_RIVA 0x10 /* Riva based graphics cards */
6595 #define I2C_HW_B_IOC 0x11 /* IOC bit-wiggling */
6596 #define I2C_HW_B_TSUNA 0x12 /* DEC Tsunami chipset */
6597 +#define I2C_HW_B_FRODO 0x13 /* 2d3D, Inc. SA-1110 Development Board */
6598 +#define I2C_HW_B_OMAHA 0x14 /* Omaha I2C interface (ARM) */
6599 +#define I2C_HW_B_GUIDE 0x15 /* Guide bit-basher */
6600 +#define I2C_HW_B_IXP2000 0x16 /* GPIO on IXP2000 systems */
6601 +#define I2C_HW_B_IXP425 0x17 /* GPIO on IXP425 systems */
6602 +#define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */
6603 +#define I2C_HW_B_ZR36067 0x19 /* Zoran-36057/36067 based boards */
6604 +#define I2C_HW_B_PCILYNX 0x20 /* TI PCILynx I2C adapter */
6606 /* --- PCF 8584 based algorithms */
6607 #define I2C_HW_P_LP 0x00 /* Parallel port interface */
6608 #define I2C_HW_P_ISA 0x01 /* generic ISA Bus inteface card */
6609 #define I2C_HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */
6611 +/* --- USB based adapters */
6612 +#define I2C_HW_USB_USBVISION 0x00
6614 /* --- ACPI Embedded controller algorithms */
6615 #define I2C_HW_ACPI_EC 0x00
6617 +/* --- MPC824x PowerPC adapters */
6618 +#define I2C_HW_MPC824X 0x00 /* Motorola 8240 / 8245 */
6620 /* --- MPC8xx PowerPC adapters */
6621 #define I2C_HW_MPC8XX_EPON 0x00 /* Eponymous MPC8xx I2C adapter */
6623 +/* --- ITE based algorithms */
6624 +#define I2C_HW_I_IIC 0x00 /* controller on the ITE */
6626 +/* --- PowerPC on-chip adapters */
6627 +#define I2C_HW_OCP 0x00 /* IBM on-chip I2C adapter */
6629 +/* --- XSCALE on-chip adapters */
6630 +#define I2C_HW_IOP321 0x00
6632 /* --- SMBus only adapters */
6633 #define I2C_HW_SMBUS_PIIX4 0x00
6634 #define I2C_HW_SMBUS_ALI15X3 0x01
6635 @@ -199,8 +273,23 @@
6636 #define I2C_HW_SMBUS_SIS5595 0x06
6637 #define I2C_HW_SMBUS_ALI1535 0x07
6638 #define I2C_HW_SMBUS_W9968CF 0x08
6639 +#define I2C_HW_SMBUS_SIS630 0x09
6640 +#define I2C_HW_SMBUS_SIS645 0x0a
6641 +#define I2C_HW_SMBUS_AMD8111 0x0b
6642 +#define I2C_HW_SMBUS_SCX200 0x0c
6643 +#define I2C_HW_SMBUS_NFORCE2 0x0d
6646 /* --- ISA pseudo-adapter */
6647 #define I2C_HW_ISA 0x00
6649 -#endif /* I2C_ID_H */
6650 +/* --- IPMI pseudo-adapter */
6651 +#define I2C_HW_IPMI 0x00
6653 +/* --- IPMB adapter */
6654 +#define I2C_HW_IPMB 0x00
6656 +/* --- MCP107 adapter */
6657 +#define I2C_HW_MPC107 0x00
6659 +#endif /* LINUX_I2C_ID_H */
6660 --- linux-old/drivers/i2c/i2c-pcf-epp.c Thu Jan 1 00:00:00 1970
6661 +++ linux/drivers/i2c/i2c-pcf-epp.c Sun Dec 7 11:17:41 2003
6663 +/* ------------------------------------------------------------------------- */
6664 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters */
6665 +/* ------------------------------------------------------------------------- */
6666 +/* Copyright (C) 1998-99 Hans Berglund
6668 + This program is free software; you can redistribute it and/or modify
6669 + it under the terms of the GNU General Public License as published by
6670 + the Free Software Foundation; either version 2 of the License, or
6671 + (at your option) any later version.
6673 + This program is distributed in the hope that it will be useful,
6674 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6675 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6676 + GNU General Public License for more details.
6678 + You should have received a copy of the GNU General Public License
6679 + along with this program; if not, write to the Free Software
6680 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6681 +/* ------------------------------------------------------------------------- */
6683 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
6685 +#include <linux/kernel.h>
6686 +#include <linux/ioport.h>
6687 +#include <linux/module.h>
6688 +#include <linux/delay.h>
6689 +#include <linux/slab.h>
6690 +#include <linux/init.h>
6691 +#include <linux/parport.h>
6692 +#include <linux/i2c.h>
6693 +#include <linux/i2c-algo-pcf.h>
6694 +#include <asm/irq.h>
6695 +#include <asm/io.h>
6698 +struct i2c_pcf_epp {
6705 +#define DEFAULT_BASE 0x378
6706 +#define DEFAULT_IRQ 7
6707 +#define DEFAULT_CLOCK 0x1c
6708 +#define DEFAULT_OWN 0x55
6710 +static int base = 0;
6711 +static int irq = 0;
6712 +static int clock = 0;
6713 +static int own = 0;
6714 +static int i2c_debug=0;
6715 +static struct i2c_pcf_epp gpe;
6716 +static wait_queue_head_t pcf_wait;
6717 +static int pcf_pending;
6718 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
6720 +/* ----- global defines ----------------------------------------------- */
6721 +#define DEB(x) if (i2c_debug>=1) x
6722 +#define DEB2(x) if (i2c_debug>=2) x
6723 +#define DEB3(x) if (i2c_debug>=3) x
6724 +#define DEBE(x) x /* error messages */
6726 +/* --- Convenience defines for the EPP/SPP port: */
6727 +#define BASE ((struct i2c_pcf_epp *)(data))->pe_base
6728 +// #define DATA BASE /* SPP data port */
6729 +#define STAT (BASE+1) /* SPP status port */
6730 +#define CTRL (BASE+2) /* SPP control port */
6731 +#define EADD (BASE+3) /* EPP address port */
6732 +#define EDAT (BASE+4) /* EPP data port */
6734 +/* ----- local functions ---------------------------------------------- */
6736 +static void pcf_epp_setbyte(void *data, int ctl, int val)
6739 + if (gpe.pe_irq > 0) {
6740 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
6741 + val|I2C_PCF_ENI));
6742 + // set A0 pin HIGH
6743 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6744 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
6745 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
6747 + // EPP write data cycle
6748 + outb(val | I2C_PCF_ENI, EDAT);
6750 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
6751 + // set A0 pin HIGH
6752 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6756 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
6758 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6759 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
6760 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
6765 +static int pcf_epp_getbyte(void *data, int ctl)
6770 + // set A0 pin HIGH
6771 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6773 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
6776 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6778 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
6783 +static int pcf_epp_getown(void *data)
6785 + return (gpe.pe_own);
6789 +static int pcf_epp_getclock(void *data)
6791 + return (gpe.pe_clock);
6795 +static void pcf_epp_sleep(unsigned long timeout)
6797 + schedule_timeout( timeout * HZ);
6801 +static void pcf_epp_waitforpin(void) {
6804 + if (gpe.pe_irq > 0) {
6805 + spin_lock_irq(&irq_driver_lock);
6806 + if (pcf_pending == 0) {
6807 + interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
6812 + spin_unlock_irq(&irq_driver_lock);
6818 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
6820 + wake_up_interruptible(&pcf_wait);
6821 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
6825 +static int pcf_epp_init(void *data)
6827 + if (check_region(gpe.pe_base, 5) < 0 ) {
6829 + printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
6832 + request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
6835 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
6837 + if (gpe.pe_irq > 0) {
6838 + if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
6839 + printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
6842 + disable_irq(gpe.pe_irq);
6843 + enable_irq(gpe.pe_irq);
6845 + // EPP mode initialize
6846 + // enable interrupt from nINTR pin
6847 + outb(inb(CTRL)|0x14, CTRL);
6848 + // clear ERROR bit of STAT
6849 + outb(inb(STAT)|0x01, STAT);
6850 + outb(inb(STAT)&~0x01,STAT);
6855 +/* ------------------------------------------------------------------------
6856 + * Encapsulate the above functions in the correct operations structure.
6857 + * This is only done when more than one hardware adapter is supported.
6859 +static struct i2c_algo_pcf_data pcf_epp_data = {
6860 + .setpcf = pcf_epp_setbyte,
6861 + .getpcf = pcf_epp_getbyte,
6862 + .getown = pcf_epp_getown,
6863 + .getclock = pcf_epp_getclock,
6864 + .waitforpin = pcf_epp_waitforpin,
6870 +static struct i2c_adapter pcf_epp_ops = {
6871 + .owner = THIS_MODULE,
6872 + .name = "PCF8584 EPP adapter",
6873 + .id = I2C_HW_P_LP,
6874 + .algo_data = &pcf_epp_data,
6877 +static int __init i2c_pcfepp_init(void)
6879 + struct i2c_pcf_epp *pepp = &gpe;
6881 + printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6883 + pepp->pe_base = DEFAULT_BASE;
6885 + pepp->pe_base = base;
6888 + pepp->pe_irq = DEFAULT_IRQ;
6893 + pepp->pe_irq = irq;
6896 + pepp->pe_clock = DEFAULT_CLOCK;
6898 + pepp->pe_clock = clock;
6901 + pepp->pe_own = DEFAULT_OWN;
6903 + pepp->pe_own = own;
6905 + pcf_epp_data.data = (void *)pepp;
6906 + init_waitqueue_head(&pcf_wait);
6907 + if (pcf_epp_init(pepp) == 0) {
6909 + if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
6910 + printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
6911 + release_region(pepp->pe_base , 5);
6918 + printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
6922 +static void __exit pcf_epp_exit(void)
6924 + i2c_pcf_del_bus(&pcf_epp_ops);
6925 + if (gpe.pe_irq > 0) {
6926 + disable_irq(gpe.pe_irq);
6927 + free_irq(gpe.pe_irq, 0);
6929 + release_region(gpe.pe_base , 5);
6932 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
6933 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
6934 +MODULE_LICENSE("GPL");
6936 +MODULE_PARM(base, "i");
6937 +MODULE_PARM(irq, "i");
6938 +MODULE_PARM(clock, "i");
6939 +MODULE_PARM(own, "i");
6940 +MODULE_PARM(i2c_debug, "i");
6942 +module_init(i2c_pcfepp_init);
6943 +module_exit(pcf_epp_exit);
6944 --- linux-old/include/linux/i2c-pcf8584.h Thu Jan 1 00:00:00 1970
6945 +++ linux/include/linux/i2c-pcf8584.h Sun Dec 7 11:17:41 2003
6947 +/* -------------------------------------------------------------------- */
6948 +/* i2c-pcf8584.h: PCF 8584 global defines */
6949 +/* -------------------------------------------------------------------- */
6950 +/* Copyright (C) 1996 Simon G. Vogl
6951 + 1999 Hans Berglund
6953 + This program is free software; you can redistribute it and/or modify
6954 + it under the terms of the GNU General Public License as published by
6955 + the Free Software Foundation; either version 2 of the License, or
6956 + (at your option) any later version.
6958 + This program is distributed in the hope that it will be useful,
6959 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6960 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6961 + GNU General Public License for more details.
6963 + You should have received a copy of the GNU General Public License
6964 + along with this program; if not, write to the Free Software
6965 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6966 +/* -------------------------------------------------------------------- */
6968 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
6972 +#ifndef _LINUX_I2C_PCF8584_H
6973 +#define _LINUX_I2C_PCF8584_H
6975 +/* ----- Control register bits ---------------------------------------- */
6976 +#define I2C_PCF_PIN 0x80
6977 +#define I2C_PCF_ESO 0x40
6978 +#define I2C_PCF_ES1 0x20
6979 +#define I2C_PCF_ES2 0x10
6980 +#define I2C_PCF_ENI 0x08
6981 +#define I2C_PCF_STA 0x04
6982 +#define I2C_PCF_STO 0x02
6983 +#define I2C_PCF_ACK 0x01
6985 +#define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6986 +#define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
6987 +#define I2C_PCF_REPSTART ( I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6988 +#define I2C_PCF_IDLE (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ACK)
6990 +/* ----- Status register bits ----------------------------------------- */
6991 +/*#define I2C_PCF_PIN 0x80 as above*/
6993 +#define I2C_PCF_INI 0x40 /* 1 if not initialized */
6994 +#define I2C_PCF_STS 0x20
6995 +#define I2C_PCF_BER 0x10
6996 +#define I2C_PCF_AD0 0x08
6997 +#define I2C_PCF_LRB 0x08
6998 +#define I2C_PCF_AAS 0x04
6999 +#define I2C_PCF_LAB 0x02
7000 +#define I2C_PCF_BB 0x01
7002 +/* ----- Chip clock frequencies --------------------------------------- */
7003 +#define I2C_PCF_CLK3 0x00
7004 +#define I2C_PCF_CLK443 0x10
7005 +#define I2C_PCF_CLK6 0x14
7006 +#define I2C_PCF_CLK 0x18
7007 +#define I2C_PCF_CLK12 0x1c
7009 +/* ----- transmission frequencies ------------------------------------- */
7010 +#define I2C_PCF_TRNS90 0x00 /* 90 kHz */
7011 +#define I2C_PCF_TRNS45 0x01 /* 45 kHz */
7012 +#define I2C_PCF_TRNS11 0x02 /* 11 kHz */
7013 +#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */
7016 +/* ----- Access to internal registers according to ES1,ES2 ------------ */
7017 +/* they are mapped to the data port ( a0 = 0 ) */
7018 +/* available when ESO == 0 : */
7020 +#define I2C_PCF_OWNADR 0
7021 +#define I2C_PCF_INTREG I2C_PCF_ES2
7022 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7024 +#endif /* _LINUX_I2C_PCF8584_H */
7025 --- linux-old/drivers/i2c/i2c-philips-par.c Sun Sep 30 19:26:05 2001
7026 +++ linux/drivers/i2c/i2c-philips-par.c Sun Dec 7 11:17:41 2003
7028 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
7029 Frodo Looijaard <frodol@dds.nl> */
7034 #include <linux/kernel.h>
7035 #include <linux/ioport.h>
7037 #include <linux/init.h>
7038 #include <linux/stddef.h>
7039 #include <linux/parport.h>
7041 +#include <linux/slab.h>
7042 #include <linux/i2c.h>
7043 #include <linux/i2c-algo-bit.h>
7046 -#define __exit __init
7052 @@ -130,59 +126,34 @@
7053 PARPORT_STATUS_BUSY) ? 0 : 1;
7056 -static int bit_lp_reg(struct i2c_client *client)
7061 -static int bit_lp_unreg(struct i2c_client *client)
7066 -static void bit_lp_inc_use(struct i2c_adapter *adap)
7068 - MOD_INC_USE_COUNT;
7071 -static void bit_lp_dec_use(struct i2c_adapter *adap)
7073 - MOD_DEC_USE_COUNT;
7076 /* ------------------------------------------------------------------------
7077 * Encapsulate the above functions in the correct operations structure.
7078 * This is only done when more than one hardware adapter is supported.
7081 static struct i2c_algo_bit_data bit_lp_data = {
7087 - 80, 80, 100, /* waits, timeout */
7088 + .setsda = bit_lp_setsda,
7089 + .setscl = bit_lp_setscl,
7090 + .getsda = bit_lp_getsda,
7091 + .getscl = bit_lp_getscl,
7097 static struct i2c_algo_bit_data bit_lp_data2 = {
7103 - 80, 80, 100, /* waits, timeout */
7104 + .setsda = bit_lp_setsda2,
7105 + .setscl = bit_lp_setscl2,
7106 + .getsda = bit_lp_getsda2,
7112 static struct i2c_adapter bit_lp_ops = {
7113 - "Philips Parallel port adapter",
7122 + .owner = THIS_MODULE,
7123 + .name = "Philips Parallel port adapter",
7124 + .id = I2C_HW_B_LP,
7127 static void i2c_parport_attach (struct parport *port)
7128 @@ -190,18 +161,19 @@
7129 struct i2c_par *adapter = kmalloc(sizeof(struct i2c_par),
7132 - printk("i2c-philips-par: Unable to malloc.\n");
7133 + printk(KERN_ERR "i2c-philips-par: Unable to malloc.\n");
7137 - printk("i2c-philips-par.o: attaching to %s\n", port->name);
7138 + printk(KERN_DEBUG "i2c-philips-par.o: attaching to %s\n", port->name);
7140 adapter->pdev = parport_register_device(port, "i2c-philips-par",
7144 if (!adapter->pdev) {
7145 - printk("i2c-philips-par: Unable to register with parport.\n");
7146 + printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
7151 @@ -210,15 +182,19 @@
7152 adapter->bit_lp_data = type ? bit_lp_data2 : bit_lp_data;
7153 adapter->bit_lp_data.data = port;
7155 + if (parport_claim_or_block(adapter->pdev) < 0 ) {
7156 + printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
7160 /* reset hardware to sane state */
7161 - parport_claim_or_block(adapter->pdev);
7162 bit_lp_setsda(port, 1);
7163 bit_lp_setscl(port, 1);
7164 parport_release(adapter->pdev);
7166 if (i2c_bit_add_bus(&adapter->adapter) < 0)
7168 - printk("i2c-philips-par: Unable to register with I2C.\n");
7169 + printk(KERN_ERR "i2c-philips-par: Unable to register with I2C.\n");
7170 parport_unregister_device(adapter->pdev);
7172 return; /* No good */
7173 @@ -250,41 +226,25 @@
7177 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7178 static struct parport_driver i2c_driver = {
7186 int __init i2c_bitlp_init(void)
7188 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,4)
7189 - struct parport *port;
7191 - printk("i2c-philips-par.o: i2c Philips parallel port adapter module\n");
7192 + printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7194 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7195 parport_register_driver(&i2c_driver);
7197 - for (port = parport_enumerate(); port; port=port->next)
7198 - i2c_parport_attach(port);
7204 void __exit i2c_bitlp_exit(void)
7206 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7207 parport_unregister_driver(&i2c_driver);
7209 - struct parport *port;
7210 - for (port = parport_enumerate(); port; port=port->next)
7211 - i2c_parport_detach(port);
7216 @@ -295,14 +255,5 @@
7218 MODULE_PARM(type, "i");
7221 -int init_module(void)
7223 - return i2c_bitlp_init();
7226 -void cleanup_module(void)
7231 +module_init(i2c_bitlp_init);
7232 +module_exit(i2c_bitlp_exit);
7233 --- linux-old/drivers/i2c/i2c-pport.c Thu Jan 1 00:00:00 1970
7234 +++ linux/drivers/i2c/i2c-pport.c Sun Dec 7 11:17:41 2003
7236 +/* ------------------------------------------------------------------------- */
7237 +/* i2c-pport.c i2c-hw access for primitive i2c par. port adapter */
7238 +/* ------------------------------------------------------------------------- */
7239 +/* Copyright (C) 2001 Daniel Smolik
7241 + This program is free software; you can redistribute it and/or modify
7242 + it under the terms of the GNU General Public License as published by
7243 + the Free Software Foundation; either version 2 of the License, or
7244 + (at your option) any later version.
7246 + This program is distributed in the hope that it will be useful,
7247 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7248 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7249 + GNU General Public License for more details.
7251 + You should have received a copy of the GNU General Public License
7252 + along with this program; if not, write to the Free Software
7253 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7254 +/* ------------------------------------------------------------------------- */
7257 + See doc/i2c-pport for instructions on wiring to the
7258 + parallel port connector.
7260 + Cut & paste :-) based on Velleman K9000 driver by Simon G. Vogl
7264 +#include <linux/kernel.h>
7265 +#include <linux/module.h>
7266 +#include <linux/delay.h>
7267 +#include <linux/slab.h>
7268 +#include <linux/init.h>
7269 +#include <linux/ioport.h>
7270 +#include <linux/errno.h>
7271 +#include <linux/i2c.h>
7272 +#include <linux/i2c-algo-bit.h>
7273 +#include <asm/io.h>
7276 +#define DEFAULT_BASE 0x378
7278 +static unsigned char PortData = 0;
7280 +/* ----- global defines ----------------------------------------------- */
7281 +#define DEB(x) /* should be reasonable open, close &c. */
7282 +#define DEB2(x) /* low level debugging - very slow */
7283 +#define DEBE(x) x /* error messages */
7284 +#define DEBINIT(x) x /* detection status messages */
7286 +/* --- Convenience defines for the parallel port: */
7287 +#define BASE (unsigned int)(data)
7288 +#define DATA BASE /* Centronics data port */
7289 +#define STAT (BASE+1) /* Centronics status port */
7290 +#define CTRL (BASE+2) /* Centronics control port */
7292 +/* we will use SDA - Auto Linefeed(14) bit 1 POUT */
7293 +/* we will use SCL - Initialize printer(16) BUSY bit 2*/
7295 +#define SET_SCL | 0x04
7296 +#define CLR_SCL & 0xFB
7301 +#define SET_SDA & 0x04
7302 +#define CLR_SDA | 0x02
7305 +/* ----- local functions ---------------------------------------------- */
7308 +static void bit_pport_setscl(void *data, int state)
7312 + PortData = PortData SET_SCL;
7315 + PortData = PortData CLR_SCL;
7317 + outb(PortData, CTRL);
7320 +static void bit_pport_setsda(void *data, int state)
7324 + PortData = PortData SET_SDA;
7327 + PortData = PortData CLR_SDA;
7329 + outb(PortData, CTRL);
7332 +static int bit_pport_getscl(void *data)
7335 + return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
7338 +static int bit_pport_getsda(void *data)
7340 + return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
7343 +static int bit_pport_init(void)
7345 + if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
7348 + /* test for PPORT adap. */
7351 + PortData=inb(base+2);
7352 + PortData= (PortData SET_SDA) SET_SCL;
7353 + outb(PortData,base+2);
7355 + if (!(inb(base+2) | 0x06)) { /* SDA and SCL will be high */
7356 + DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
7360 + /*SCL high and SDA low*/
7361 + PortData = PortData SET_SCL CLR_SDA;
7362 + outb(PortData,base+2);
7363 + schedule_timeout(400);
7364 + if ( !(inb(base+2) | 0x4) ) {
7365 + //outb(0x04,base+2);
7366 + DEBINIT(printk("i2c-port.o: SDA was high.\n"));
7370 + bit_pport_setsda((void*)base,1);
7371 + bit_pport_setscl((void*)base,1);
7377 +/* ------------------------------------------------------------------------
7378 + * Encapsulate the above functions in the correct operations structure.
7379 + * This is only done when more than one hardware adapter is supported.
7381 +static struct i2c_algo_bit_data bit_pport_data = {
7382 + .setsda = bit_pport_setsda,
7383 + .setscl = bit_pport_setscl,
7384 + .getsda = bit_pport_getsda,
7385 + .getscl = bit_pport_getscl,
7391 +static struct i2c_adapter bit_pport_ops = {
7392 + .owner = THIS_MODULE,
7393 + .name = "Primitive Parallel port adaptor",
7394 + .id = I2C_HW_B_PPORT,
7395 + .algo_data = &bit_pport_data,
7398 +int __init i2c_bitpport_init(void)
7400 + printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7403 + /* probe some values */
7404 + base=DEFAULT_BASE;
7405 + bit_pport_data.data=(void*)DEFAULT_BASE;
7406 + if (bit_pport_init()==0) {
7407 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7413 + bit_pport_data.data=(void*)base;
7414 + if (bit_pport_init()==0) {
7415 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7421 + printk("i2c-pport.o: found device at %#x.\n",base);
7425 +static void __exit i2c_bitpport_exit(void)
7427 + i2c_bit_del_bus(&bit_pport_ops);
7428 + release_region((base+2),1);
7433 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
7434 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
7435 +MODULE_LICENSE("GPL");
7437 +MODULE_PARM(base, "i");
7439 +module_init(i2c_bitpport_init);
7440 +module_exit(i2c_bitpport_exit);
7441 --- linux-old/drivers/i2c/i2c-proc.c Tue Jul 15 10:23:49 2003
7442 +++ linux/drivers/i2c/i2c-proc.c Sun Dec 7 11:17:42 2003
7444 This driver puts entries in /proc/sys/dev/sensors for each I2C device
7447 -#include <linux/version.h>
7448 #include <linux/module.h>
7449 #include <linux/kernel.h>
7450 #include <linux/slab.h>
7451 #include <linux/ctype.h>
7452 #include <linux/sysctl.h>
7453 #include <linux/proc_fs.h>
7454 +#include <linux/init.h>
7455 #include <linux/ioport.h>
7456 -#include <asm/uaccess.h>
7458 #include <linux/i2c.h>
7459 #include <linux/i2c-proc.h>
7460 +#include <asm/uaccess.h>
7462 -#include <linux/init.h>
7464 -/* FIXME need i2c versioning */
7465 -#define LM_DATE "20010825"
7466 -#define LM_VERSION "2.6.1"
7468 -#ifndef THIS_MODULE
7469 -#define THIS_MODULE NULL
7472 -static int i2c_create_name(char **name, const char *prefix,
7473 - struct i2c_adapter *adapter, int addr);
7474 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7475 long *results, int magnitude);
7476 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7477 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7478 long *results, int magnitude);
7479 static int i2c_proc_chips(ctl_table * ctl, int write,
7480 struct file *filp, void *buffer,
7482 void *newval, size_t newlen,
7485 -int __init sensors_init(void);
7487 #define SENSORS_ENTRY_MAX 20
7488 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
7490 static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
7491 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
7492 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
7493 -static void i2c_fill_inode(struct inode *inode, int fill);
7494 -static void i2c_dir_fill_inode(struct inode *inode, int fill);
7495 -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */
7497 -static ctl_table sysctl_table[] = {
7498 - {CTL_DEV, "dev", NULL, 0, 0555},
7500 - {DEV_SENSORS, "sensors", NULL, 0, 0555},
7502 - {0, NULL, NULL, 0, 0555},
7506 static ctl_table i2c_proc_dev_sensors[] = {
7507 {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips,
7508 @@ -100,31 +71,45 @@
7511 static struct ctl_table_header *i2c_proc_header;
7512 -static int i2c_initialized;
7514 /* This returns a nice name for a new directory; for example lm78-isa-0310
7515 (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for
7516 a LM75 chip on the third i2c bus at address 0x4e).
7517 name is allocated first. */
7518 -int i2c_create_name(char **name, const char *prefix,
7519 - struct i2c_adapter *adapter, int addr)
7520 +static char *generate_name(struct i2c_client *client, const char *prefix)
7522 - char name_buffer[50];
7524 - if (i2c_is_isa_adapter(adapter))
7525 + struct i2c_adapter *adapter = client->adapter;
7526 + int addr = client->addr;
7527 + char name_buffer[50], *name;
7529 + if (i2c_is_isa_adapter(adapter)) {
7530 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
7532 - if ((id = i2c_adapter_id(adapter)) < 0)
7534 + } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
7535 + int id = i2c_adapter_id(adapter);
7537 + return ERR_PTR(-ENOENT);
7538 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
7539 + } else { /* dummy adapter, generate prefix */
7542 + sprintf(name_buffer, "%s-", prefix);
7543 + end = strlen(name_buffer);
7545 + for (i = 0; i < 32; i++) {
7546 + if (adapter->algo->name[i] == ' ')
7548 + name_buffer[end++] = tolower(adapter->algo->name[i]);
7551 + name_buffer[end] = 0;
7552 + sprintf(name_buffer + end, "-%04x", addr);
7554 - *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7556 - printk (KERN_WARNING "i2c_create_name: not enough memory\n");
7559 - strcpy(*name, name_buffer);
7562 + name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7564 + return ERR_PTR(-ENOMEM);
7565 + strcpy(name, name_buffer);
7569 /* This rather complex function must be called when you want to add an entry
7570 @@ -133,144 +118,91 @@
7571 ctl_template should be a template of the newly created directory. It is
7572 copied in memory. The extra2 field of each file is set to point to client.
7573 If any driver wants subdirectories within the newly created directory,
7574 - this function must be updated!
7575 - controlling_mod is the controlling module. It should usually be
7576 - THIS_MODULE when calling. Note that this symbol is not defined in
7577 - kernels before 2.3.13; define it to NULL in that case. We will not use it
7578 - for anything older than 2.3.27 anyway. */
7579 + this function must be updated! */
7580 int i2c_register_entry(struct i2c_client *client, const char *prefix,
7581 - ctl_table * ctl_template,
7582 - struct module *controlling_mod)
7583 + struct ctl_table *ctl_template)
7585 - int i, res, len, id;
7586 - ctl_table *new_table;
7588 - struct ctl_table_header *new_header;
7589 + struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
7590 + struct ctl_table_header *hdr;
7591 + struct ctl_table *tmp, *leaf;
7595 - if ((res = i2c_create_name(&name, prefix, client->adapter,
7596 - client->addr))) return res;
7597 + name = generate_name(client, prefix);
7599 + return PTR_ERR(name);
7601 - for (id = 0; id < SENSORS_ENTRY_MAX; id++)
7602 - if (!i2c_entries[id]) {
7605 - if (id == SENSORS_ENTRY_MAX) {
7608 + for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
7609 + if (!i2c_entries[id])
7615 + goto out_free_name;
7618 while (ctl_template[len].procname)
7621 - if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
7626 - memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
7627 - new_table[0].child = &new_table[2];
7628 - new_table[2].child = &new_table[4];
7629 - new_table[4].child = &new_table[6];
7630 - new_table[4].procname = name;
7631 - new_table[4].ctl_name = id;
7632 - memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
7633 - for (i = 6; i < len; i++)
7634 - new_table[i].extra2 = client;
7636 - if (!(new_header = register_sysctl_table(new_table, 0))) {
7642 - i2c_entries[id - 256] = new_header;
7644 - i2c_clients[id - 256] = client;
7646 - if (!new_header || !new_header->ctl_table ||
7647 - !new_header->ctl_table->child ||
7648 - !new_header->ctl_table->child->child ||
7649 - !new_header->ctl_table->child->child->de) {
7651 - ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
7655 - i2c_inodes[id - 256] =
7656 - new_header->ctl_table->child->child->de->low_ino;
7657 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
7658 - new_header->ctl_table->child->child->de->owner = controlling_mod;
7660 - new_header->ctl_table->child->child->de->fill_inode =
7661 - &i2c_dir_fill_inode;
7662 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
7665 + tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1),
7668 + goto out_free_name;
7669 + memset(tbl, 0, sizeof(*tbl));
7671 + /* The client sysctls */
7672 + leaf = (struct ctl_table *) (tbl + 1);
7673 + memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
7674 + for (tmp = leaf; tmp->ctl_name; tmp++)
7675 + tmp->extra2 = client;
7677 + tbl->sensors->ctl_name = id+256;
7678 + tbl->sensors->procname = name;
7679 + tbl->sensors->mode = 0555;
7680 + tbl->sensors->child = leaf;
7682 + tbl->dev->ctl_name = DEV_SENSORS;
7683 + tbl->dev->procname = "sensors";
7684 + tbl->dev->mode = 0555;
7685 + tbl->dev->child = tbl->sensors;
7687 + tbl->root->ctl_name = CTL_DEV;
7688 + tbl->root->procname = "dev";
7689 + tbl->root->mode = 0555;
7690 + tbl->root->child = tbl->dev;
7692 + hdr = register_sysctl_table(tbl->root, 0);
7694 + goto out_free_tbl;
7696 + i2c_entries[id] = hdr;
7697 + i2c_clients[id] = client;
7699 + return (id + 256); /* XXX(hch) why?? */
7708 void i2c_deregister_entry(int id)
7713 - if (i2c_entries[id]) {
7714 - table = i2c_entries[id]->ctl_table;
7715 - unregister_sysctl_table(i2c_entries[id]);
7716 - /* 2-step kfree needed to keep gcc happy about const points */
7717 - (const char *) temp = table[4].procname;
7720 - i2c_entries[id] = NULL;
7721 - i2c_clients[id] = NULL;
7725 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o
7726 - impossible if some process still uses it or some file in it */
7727 -void i2c_fill_inode(struct inode *inode, int fill)
7730 - MOD_INC_USE_COUNT;
7732 - MOD_DEC_USE_COUNT;
7735 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
7736 - the corresponding module impossible if some process still uses it or
7737 - some file in it */
7738 -void i2c_dir_fill_inode(struct inode *inode, int fill)
7741 - struct i2c_client *client;
7742 + if (i2c_entries[id]) {
7743 + struct ctl_table_header *hdr = i2c_entries[id];
7744 + struct ctl_table *tbl = hdr->ctl_table;
7748 - printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
7750 + unregister_sysctl_table(hdr);
7751 + kfree(tbl->child->child->procname);
7752 + kfree(tbl); /* actually the whole anonymous struct */
7754 -#endif /* def DEBUG */
7756 - for (i = 0; i < SENSORS_ENTRY_MAX; i++)
7757 - if (i2c_clients[i]
7758 - && (i2c_inodes[i] == inode->i_ino)) break;
7760 - if (i == SENSORS_ENTRY_MAX) {
7762 - ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
7766 -#endif /* def DEBUG */
7767 - client = i2c_clients[i];
7769 - client->driver->inc_use(client);
7771 - client->driver->dec_use(client);
7772 + i2c_entries[id] = NULL;
7773 + i2c_clients[id] = NULL;
7776 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7777 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7778 void *buffer, size_t * lenp)
7780 char BUF[SENSORS_PREFIX_MAX + 30];
7785 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7786 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7787 void *oldval, size_t * oldlenp, void *newval,
7788 size_t newlen, void **context)
7791 WARNING! This is tricky code. I have tested it, but there may still be
7792 hidden bugs in it, even leading to crashes and things!
7794 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7795 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7796 long *results, int magnitude)
7798 int maxels, min, mag;
7803 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7804 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7805 long *results, int magnitude)
7809 I2C_FUNC_SMBUS_QUICK)) return -1;
7811 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
7812 + /* XXX: WTF is going on here??? */
7813 if ((is_isa && check_region(addr, 1)) ||
7814 (!is_isa && i2c_check_addr(adapter, addr)))
7817 && (addr == this_force->force[j + 1])) {
7820 - ("i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7821 + (KERN_DEBUG "i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7826 && (addr == address_data->ignore[i + 1])) {
7829 - ("i2c-proc.o: found ignore parameter for adapter %d, "
7830 + (KERN_DEBUG "i2c-proc.o: found ignore parameter for adapter %d, "
7831 "addr %04x\n", adapter_id, addr);
7835 && (addr <= address_data->ignore_range[i + 2])) {
7838 - ("i2c-proc.o: found ignore_range parameter for adapter %d, "
7839 + (KERN_DEBUG "i2c-proc.o: found ignore_range parameter for adapter %d, "
7840 "addr %04x\n", adapter_id, addr);
7844 if (addr == address_data->normal_isa[i]) {
7847 - ("i2c-proc.o: found normal isa entry for adapter %d, "
7848 + (KERN_DEBUG "i2c-proc.o: found normal isa entry for adapter %d, "
7849 "addr %04x\n", adapter_id,
7856 - ("i2c-proc.o: found normal isa_range entry for adapter %d, "
7857 + (KERN_DEBUG "i2c-proc.o: found normal isa_range entry for adapter %d, "
7858 "addr %04x", adapter_id, addr);
7865 - ("i2c-proc.o: found normal i2c entry for adapter %d, "
7866 + (KERN_DEBUG "i2c-proc.o: found normal i2c entry for adapter %d, "
7867 "addr %02x", adapter_id, addr);
7874 - ("i2c-proc.o: found normal i2c_range entry for adapter %d, "
7875 + (KERN_DEBUG "i2c-proc.o: found normal i2c_range entry for adapter %d, "
7876 "addr %04x\n", adapter_id, addr);
7880 && (addr == address_data->probe[i + 1])) {
7883 - ("i2c-proc.o: found probe parameter for adapter %d, "
7884 + (KERN_DEBUG "i2c-proc.o: found probe parameter for adapter %d, "
7885 "addr %04x\n", adapter_id, addr);
7892 - ("i2c-proc.o: found probe_range parameter for adapter %d, "
7893 + (KERN_DEBUG "i2c-proc.o: found probe_range parameter for adapter %d, "
7894 "addr %04x\n", adapter_id, addr);
7897 @@ -860,51 +793,33 @@
7901 -int __init sensors_init(void)
7902 +static int __init i2c_proc_init(void)
7904 - printk("i2c-proc.o version %s (%s)\n", LM_VERSION, LM_DATE);
7905 - i2c_initialized = 0;
7906 + printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
7909 - register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
7910 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1))
7911 + register_sysctl_table(i2c_proc, 0))) {
7912 + printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
7915 i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
7917 - i2c_proc_header->ctl_table->child->de->fill_inode =
7919 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */
7920 - i2c_initialized++;
7924 +static void __exit i2c_proc_exit(void)
7926 + unregister_sysctl_table(i2c_proc_header);
7929 +EXPORT_SYMBOL(i2c_register_entry);
7930 EXPORT_SYMBOL(i2c_deregister_entry);
7931 -EXPORT_SYMBOL(i2c_detect);
7932 EXPORT_SYMBOL(i2c_proc_real);
7933 -EXPORT_SYMBOL(i2c_register_entry);
7934 EXPORT_SYMBOL(i2c_sysctl_real);
7937 +EXPORT_SYMBOL(i2c_detect);
7939 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
7940 MODULE_DESCRIPTION("i2c-proc driver");
7941 MODULE_LICENSE("GPL");
7943 -int i2c_cleanup(void)
7945 - if (i2c_initialized >= 1) {
7946 - unregister_sysctl_table(i2c_proc_header);
7947 - i2c_initialized--;
7952 -int init_module(void)
7954 - return sensors_init();
7957 -int cleanup_module(void)
7959 - return i2c_cleanup();
7961 -#endif /* MODULE */
7962 +module_init(i2c_proc_init);
7963 +module_exit(i2c_proc_exit);
7964 --- linux-old/include/linux/i2c-proc.h Thu Oct 11 15:05:47 2001
7965 +++ linux/include/linux/i2c-proc.h Sun Dec 7 11:17:42 2003
7968 - sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7970 + i2c-proc.h - Part of the i2c package
7971 + was originally sensors.h - Part of lm_sensors, Linux kernel modules
7972 + for hardware monitoring
7973 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
7975 This program is free software; you can redistribute it and/or modify
7977 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7980 -#ifndef SENSORS_SENSORS_H
7981 -#define SENSORS_SENSORS_H
7982 +#ifndef _LINUX_I2C_PROC_H
7983 +#define _LINUX_I2C_PROC_H
7987 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
7988 -#include <linux/types.h>
7989 -#include <linux/fs.h>
7990 #include <linux/sysctl.h>
7992 /* The type of callback functions used in sensors_{proc,sysctl}_real */
7994 these functions must be updated! */
7995 extern int i2c_register_entry(struct i2c_client *client,
7997 - ctl_table * ctl_template,
7998 - struct module *controlling_mod);
7999 + ctl_table * ctl_template);
8001 extern void i2c_deregister_entry(int id);
8003 @@ -347,6 +342,31 @@
8007 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
8008 + enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
8009 + SENSORS_MODULE_PARM(force, \
8010 + "List of adapter,address pairs to boldly assume " \
8011 + "to be present"); \
8012 + SENSORS_MODULE_PARM_FORCE(chip1); \
8013 + SENSORS_MODULE_PARM_FORCE(chip2); \
8014 + SENSORS_MODULE_PARM_FORCE(chip3); \
8015 + SENSORS_MODULE_PARM_FORCE(chip4); \
8016 + SENSORS_MODULE_PARM_FORCE(chip5); \
8017 + SENSORS_MODULE_PARM_FORCE(chip6); \
8018 + SENSORS_MODULE_PARM_FORCE(chip7); \
8019 + SENSORS_MODULE_PARM_FORCE(chip8); \
8020 + static struct i2c_force_data forces[] = {{force,any_chip}, \
8021 + {force_ ## chip1,chip1}, \
8022 + {force_ ## chip2,chip2}, \
8023 + {force_ ## chip3,chip3}, \
8024 + {force_ ## chip4,chip4}, \
8025 + {force_ ## chip5,chip5}, \
8026 + {force_ ## chip6,chip6}, \
8027 + {force_ ## chip7,chip7}, \
8028 + {force_ ## chip8,chip8}, \
8032 typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
8033 int addr, unsigned short flags,
8037 /* This macro is used to scale user-input to sensible values in almost all
8039 -extern inline int SENSORS_LIMIT(long value, long low, long high)
8040 +static inline int SENSORS_LIMIT(long value, long low, long high)
8048 -#endif /* def __KERNEL__ */
8051 /* The maximum length of the prefix */
8052 #define SENSORS_PREFIX_MAX 20
8054 char name[SENSORS_PREFIX_MAX + 13];
8057 -#endif /* def SENSORS_SENSORS_H */
8058 +#endif /* def _LINUX_I2C_PROC_H */
8060 --- linux-old/drivers/i2c/i2c-rpx.c Thu Jan 1 00:00:00 1970
8061 +++ linux/drivers/i2c/i2c-rpx.c Sun Dec 7 11:17:42 2003
8064 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
8065 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
8067 + * moved into proper i2c interface;
8068 + * Brad Parker (brad@heeltoe.com)
8070 + * RPX lite specific parts of the i2c interface
8071 + * Update: There actually isn't anything RPXLite-specific about this module.
8072 + * This should work for most any 8xx board. The console messages have been
8073 + * changed to eliminate RPXLite references.
8076 +#include <linux/kernel.h>
8077 +#include <linux/ioport.h>
8078 +#include <linux/module.h>
8079 +#include <linux/init.h>
8080 +#include <linux/stddef.h>
8081 +#include <linux/parport.h>
8082 +#include <linux/i2c.h>
8083 +#include <linux/i2c-algo-8xx.h>
8084 +#include <asm/mpc8xx.h>
8085 +#include <asm/commproc.h>
8089 +rpx_iic_init(struct i2c_algo_8xx_data *data)
8091 + volatile cpm8xx_t *cp;
8092 + volatile immap_t *immap;
8094 + cp = cpmp; /* Get pointer to Communication Processor */
8095 + immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
8097 + data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
8099 + /* Check for and use a microcode relocation patch.
8101 + if ((data->reloc = data->iip->iic_rpbase))
8102 + data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
8104 + data->i2c = (i2c8xx_t *)&(immap->im_i2c);
8107 + /* Initialize Port B IIC pins.
8109 + cp->cp_pbpar |= 0x00000030;
8110 + cp->cp_pbdir |= 0x00000030;
8111 + cp->cp_pbodr |= 0x00000030;
8113 + /* Allocate space for two transmit and two receive buffer
8114 + * descriptors in the DP ram.
8116 + data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
8118 + /* ptr to i2c area */
8119 + data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
8122 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
8124 + /* install interrupt handler */
8125 + cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
8130 +static struct i2c_algo_8xx_data rpx_data = {
8131 + .setisr = rpx_install_isr
8134 +static struct i2c_adapter rpx_ops = {
8135 + .owner = THIS_MODULE,
8137 + .id = I2C_HW_MPC8XX_EPON,
8138 + .algo_data = &rpx_data,
8141 +int __init i2c_rpx_init(void)
8143 + printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8145 + /* reset hardware to sane state */
8146 + rpx_iic_init(&rpx_data);
8148 + if (i2c_8xx_add_bus(&rpx_ops) < 0) {
8149 + printk("i2c-rpx: Unable to register with I2C\n");
8156 +void __exit i2c_rpx_exit(void)
8158 + i2c_8xx_del_bus(&rpx_ops);
8161 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
8162 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
8164 +module_init(i2c_rpx_init);
8165 +module_exit(i2c_rpx_exit);
8166 --- linux-old/drivers/i2c/i2c-velleman.c Thu Oct 11 15:05:47 2001
8167 +++ linux/drivers/i2c/i2c-velleman.c Sun Dec 7 11:17:42 2003
8169 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
8170 /* ------------------------------------------------------------------------- */
8175 #include <linux/kernel.h>
8176 #include <linux/ioport.h>
8177 #include <linux/module.h>
8178 #include <linux/init.h>
8179 -#include <linux/string.h> /* for 2.0 kernels to get NULL */
8180 -#include <asm/errno.h> /* for 2.0 kernels to get ENODEV */
8181 -#include <asm/io.h>
8183 +#include <linux/errno.h>
8184 +#include <linux/delay.h>
8185 #include <linux/i2c.h>
8186 #include <linux/i2c-algo-bit.h>
8187 +#include <asm/io.h>
8188 +#include <asm/param.h> /* for HZ */
8190 /* ----- global defines ----------------------------------------------- */
8191 #define DEB(x) /* should be reasonable open, close &c. */
8194 static int bit_velle_init(void)
8196 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
8197 - DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
8199 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
8200 + "i2c (Vellemann adapter)"))
8203 - request_region(base, (base == 0x3bc)? 3 : 8,
8204 - "i2c (Vellemann adapter)");
8205 - bit_velle_setsda((void*)base,1);
8206 - bit_velle_setscl((void*)base,1);
8211 -static void __exit bit_velle_exit(void)
8213 - release_region( base , (base == 0x3bc)? 3 : 8 );
8217 -static int bit_velle_reg(struct i2c_client *client)
8222 -static int bit_velle_unreg(struct i2c_client *client)
8224 + bit_velle_setsda((void*)base,1);
8225 + bit_velle_setscl((void*)base,1);
8229 -static void bit_velle_inc_use(struct i2c_adapter *adap)
8232 - MOD_INC_USE_COUNT;
8236 -static void bit_velle_dec_use(struct i2c_adapter *adap)
8239 - MOD_DEC_USE_COUNT;
8243 /* ------------------------------------------------------------------------
8244 * Encapsulate the above functions in the correct operations structure.
8245 * This is only done when more than one hardware adapter is supported.
8248 static struct i2c_algo_bit_data bit_velle_data = {
8254 - 10, 10, 100, /* waits, timeout */
8255 + .setsda = bit_velle_setsda,
8256 + .setscl = bit_velle_setscl,
8257 + .getsda = bit_velle_getsda,
8258 + .getscl = bit_velle_getscl,
8264 static struct i2c_adapter bit_velle_ops = {
8269 - bit_velle_inc_use,
8270 - bit_velle_dec_use,
8273 + .owner = THIS_MODULE,
8274 + .name = "Velleman K8000",
8275 + .id = I2C_HW_B_VELLE,
8276 + .algo_data = &bit_velle_data,
8279 -int __init i2c_bitvelle_init(void)
8280 +static int __init i2c_bitvelle_init(void)
8282 - printk("i2c-velleman.o: i2c Velleman K8000 adapter module\n");
8283 + printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8285 /* probe some values */
8287 @@ -180,28 +143,21 @@
8291 - printk("i2c-velleman.o: found device at %#x.\n",base);
8292 + printk(KERN_DEBUG "i2c-velleman.o: found device at %#x.\n",base);
8297 +static void __exit i2c_bitvelle_exit(void)
8299 + i2c_bit_del_bus(&bit_velle_ops);
8300 + release_region(base, (base == 0x3bc) ? 3 : 8);
8304 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
8305 MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
8306 MODULE_LICENSE("GPL");
8308 MODULE_PARM(base, "i");
8310 -int init_module(void)
8312 - return i2c_bitvelle_init();
8315 -void cleanup_module(void)
8317 - i2c_bit_del_bus(&bit_velle_ops);
8322 +module_init(i2c_bitvelle_init);
8323 +module_exit(i2c_bitvelle_exit);
8324 --- linux-old/include/linux/i2c.h Tue Jul 15 10:23:54 2003
8325 +++ linux/include/linux/i2c.h Sun Dec 7 11:17:43 2003
8327 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
8328 Frodo Looijaard <frodol@dds.nl> */
8335 +#ifndef _LINUX_I2C_H
8336 +#define _LINUX_I2C_H
8338 -#define I2C_DATE "20010830"
8339 -#define I2C_VERSION "2.6.1"
8340 +#define I2C_DATE "20031005"
8341 +#define I2C_VERSION "2.8.1"
8343 -#include <linux/i2c-id.h> /* id values of adapters et. al. */
8344 +#include <linux/module.h>
8345 #include <linux/types.h>
8353 -/* --- Includes and compatibility declarations ------------------------ */
8355 -#include <linux/version.h>
8356 -#ifndef KERNEL_VERSION
8357 -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
8360 -#include <asm/page.h> /* for 2.2.xx */
8361 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,25)
8362 +#include <linux/errno.h>
8363 #include <linux/sched.h>
8365 #include <asm/semaphore.h>
8366 +#include <linux/i2c-id.h>
8368 +#include <linux/version.h>
8369 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
8370 +#define MODULE_LICENSE(x)
8372 -#include <linux/config.h>
8374 /* --- General options ------------------------------------------------ */
8376 -#define I2C_ALGO_MAX 4 /* control memory consumption */
8377 -#define I2C_ADAP_MAX 16
8378 +#define I2C_ADAP_MAX 16 /* control memory consumption */
8379 #define I2C_DRIVER_MAX 16
8380 #define I2C_CLIENT_MAX 32
8381 -#define I2C_DUMMY_MAX 4
8384 struct i2c_algorithm;
8388 struct i2c_client_address_data;
8389 union i2c_smbus_data;
8393 * The master routines are the ones normally used to transmit data to devices
8394 * on a bus (or read from them). Apart from two basic transfer functions to
8396 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
8397 u8 command, u8 length,
8399 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
8400 + u8 command, u8 *values);
8401 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
8402 u8 command, u8 length,
8408 + struct module *owner;
8411 unsigned int flags; /* div., see below */
8412 @@ -158,18 +147,6 @@
8415 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
8417 - /* These two are mainly used for bookkeeping & dynamic unloading of
8418 - * kernel modules. inc_use tells the driver that a client is being
8419 - * used by another module & that it should increase its ref. counter.
8420 - * dec_use is the inverse operation.
8421 - * NB: Make sure you have no circular dependencies, or else you get a
8422 - * deadlock when trying to unload the modules.
8423 - * You should use the i2c_{inc,dec}_use_client functions instead of
8424 - * calling this function directly.
8426 - void (*inc_use)(struct i2c_client *client);
8427 - void (*dec_use)(struct i2c_client *client);
8432 * to name two of the most common.
8434 struct i2c_algorithm {
8435 + struct module *owner; /* future use --km */
8436 char name[32]; /* textual description */
8439 @@ -226,25 +204,18 @@
8440 u32 (*functionality) (struct i2c_adapter *);
8443 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8444 -struct proc_dir_entry;
8448 * i2c_adapter is the structure used to identify a physical i2c bus along
8449 * with the access algorithms necessary to access it.
8451 struct i2c_adapter {
8452 + struct module *owner;
8453 char name[32]; /* some useful name to identify the adapter */
8454 unsigned int id;/* == is algo->id | hwdep.struct->id, */
8455 /* for registered values see below */
8456 struct i2c_algorithm *algo;/* the algorithm to access the bus */
8459 - /* --- These may be NULL, but should increase the module use count */
8460 - void (*inc_use)(struct i2c_adapter *);
8461 - void (*dec_use)(struct i2c_adapter *);
8463 /* --- administration stuff. */
8464 int (*client_register)(struct i2c_client *);
8465 int (*client_unregister)(struct i2c_client *);
8466 @@ -255,11 +226,11 @@
8467 /* and can be set via the i2c_ioctl call */
8469 /* data fields that are valid for all devices */
8470 - struct semaphore lock;
8471 + struct semaphore bus;
8472 + struct semaphore list;
8473 unsigned int flags;/* flags specifying div. data */
8475 struct i2c_client *clients[I2C_CLIENT_MAX];
8481 #ifdef CONFIG_PROC_FS
8482 /* No need to set this when you initialize the adapter */
8484 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8485 - struct proc_dir_entry *proc_entry;
8487 #endif /* def CONFIG_PROC_FS */
8491 #define I2C_CLIENT_ALLOW_USE 0x01 /* Client allows access */
8492 #define I2C_CLIENT_ALLOW_MULTIPLE_USE 0x02 /* Allow multiple access-locks */
8493 /* on an i2c_client */
8494 +#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
8495 +#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
8496 + /* Must equal I2C_M_TEN below */
8498 /* i2c_client_address_data is the struct for holding default client
8499 * addresses for a driver and for the parameters supplied on the
8500 @@ -319,12 +290,6 @@
8501 extern int i2c_attach_client(struct i2c_client *);
8502 extern int i2c_detach_client(struct i2c_client *);
8504 -/* Only call these if you grab a resource that makes unloading the
8505 - client and the adapter it is on completely impossible. Like when a
8506 - /proc directory is entered. */
8507 -extern void i2c_inc_use_client(struct i2c_client *);
8508 -extern void i2c_dec_use_client(struct i2c_client *);
8510 /* New function: This is to get an i2c_client-struct for controlling the
8511 client either by using i2c_control-function or having the
8512 client-module export functions that can be used with the i2c_client
8513 @@ -358,6 +323,15 @@
8514 struct i2c_client_address_data *address_data,
8515 i2c_client_found_addr_proc *found_proc);
8517 +static inline int i2c_client_command(struct i2c_client *client,
8518 + unsigned int cmd, void *arg)
8520 + if (client->driver && client->driver->command)
8521 + return client->driver->command(client, cmd, arg);
8526 /* An ioctl like call to set div. parameters of the adapter.
8528 extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
8530 /* Return 1 if adapter supports everything we need, 0 if not. */
8531 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
8533 -#endif /* __KERNEL__ */
8536 * I2C Message - used for pure i2c transaction, also from /dev interface
8538 @@ -387,15 +359,25 @@
8539 #define I2C_M_RD 0x01
8540 #define I2C_M_NOSTART 0x4000
8541 #define I2C_M_REV_DIR_ADDR 0x2000
8542 +#define I2C_M_IGNORE_NAK 0x1000
8543 +#define I2C_M_NO_RD_ACK 0x0800
8544 __u16 len; /* msg length */
8545 __u8 *buf; /* pointer to msg data */
8550 /* To determine what functionality is present */
8552 #define I2C_FUNC_I2C 0x00000001
8553 #define I2C_FUNC_10BIT_ADDR 0x00000002
8554 -#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
8555 +#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
8556 +#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
8557 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */
8558 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */
8559 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */
8560 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
8561 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
8562 #define I2C_FUNC_SMBUS_QUICK 0x00010000
8563 #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
8564 #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
8565 @@ -406,8 +388,12 @@
8566 #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
8567 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
8568 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
8569 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* New I2C-like block */
8570 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
8571 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
8572 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
8573 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
8574 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
8575 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */
8576 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
8578 #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
8579 I2C_FUNC_SMBUS_WRITE_BYTE
8580 @@ -419,21 +405,40 @@
8581 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
8582 #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
8583 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
8584 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
8585 + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
8586 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
8587 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
8588 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
8589 + I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
8591 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_DATA
8592 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC I2C_FUNC_SMBUS_WRITE_BYTE_DATA
8593 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA
8594 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC I2C_FUNC_SMBUS_WRITE_WORD_DATA
8595 +#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_BYTE_DATA
8596 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC I2C_FUNC_SMBUS_WORD_DATA
8598 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
8599 I2C_FUNC_SMBUS_BYTE | \
8600 I2C_FUNC_SMBUS_BYTE_DATA | \
8601 I2C_FUNC_SMBUS_WORD_DATA | \
8602 I2C_FUNC_SMBUS_PROC_CALL | \
8603 - I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
8604 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
8605 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
8606 + I2C_FUNC_SMBUS_I2C_BLOCK
8609 * Data for SMBus Messages
8611 +#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
8612 +#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
8613 union i2c_smbus_data {
8616 - __u8 block[33]; /* block[0] is used for length */
8617 + __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
8618 + /* one more for read length in block process call */
8619 + /* and one more for PEC */
8622 /* smbus_access read or write markers */
8623 @@ -449,6 +454,11 @@
8624 #define I2C_SMBUS_PROC_CALL 4
8625 #define I2C_SMBUS_BLOCK_DATA 5
8626 #define I2C_SMBUS_I2C_BLOCK_DATA 6
8627 +#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
8628 +#define I2C_SMBUS_BLOCK_DATA_PEC 8 /* SMBus 2.0 */
8629 +#define I2C_SMBUS_PROC_CALL_PEC 9 /* SMBus 2.0 */
8630 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC 10 /* SMBus 2.0 */
8631 +#define I2C_SMBUS_WORD_DATA_PEC 11 /* SMBus 2.0 */
8634 /* ----- commands for the ioctl like i2c_command call:
8637 #define I2C_FUNCS 0x0705 /* Get the adapter functionality */
8638 #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/
8639 +#define I2C_PEC 0x0708 /* != 0 for SMBus PEC */
8641 #define I2C_ACK_TEST 0x0710 /* See if a slave is at a specific address */
8643 @@ -489,16 +500,6 @@
8645 #define I2C_MAJOR 89 /* Device major number */
8650 -# define NULL ( (void *) 0 )
8654 -# include <asm/errno.h>
8657 /* These defines are used for probing i2c client addresses */
8658 /* Default fill of many variables */
8659 #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
8660 @@ -560,5 +561,11 @@
8661 #define i2c_is_isa_adapter(adapptr) \
8662 ((adapptr)->algo->id == I2C_ALGO_ISA)
8664 -#endif /* def __KERNEL__ */
8666 +/* Tiny delay function used by the i2c bus drivers */
8667 +static inline void i2c_delay(signed long timeout)
8669 + set_current_state(TASK_INTERRUPTIBLE);
8670 + schedule_timeout(timeout);
8673 +#endif /* _LINUX_I2C_H */
8674 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-adap-ite.c Tue Jul 15 12:23:01 2003
8675 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-adap-ite.c Sat Nov 15 20:41:10 2003
8676 @@ -199,22 +199,6 @@
8680 -static void iic_ite_inc_use(struct i2c_adapter *adap)
8683 - MOD_INC_USE_COUNT;
8688 -static void iic_ite_dec_use(struct i2c_adapter *adap)
8691 - MOD_DEC_USE_COUNT;
8696 /* ------------------------------------------------------------------------
8697 * Encapsulate the above functions in the correct operations structure.
8698 * This is only done when more than one hardware adapter is supported.
8699 @@ -230,14 +214,13 @@
8702 static struct i2c_adapter iic_ite_ops = {
8703 - "ITE IIC adapter",
8711 + .owner = THIS_MODULE,
8712 + .name = "ITE IIC adapter",
8713 + .id = I2C_HW_I_IIC,
8715 + .algo_data = &iic_ite_data,
8716 + .client_register = iic_ite_reg,
8717 + .client_unregieter = iic_ite_unreg,
8720 /* Called when the module is loaded. This function starts the
8721 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-algo-ite.c Thu Oct 11 17:05:47 2001
8722 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-algo-ite.c Sat Nov 15 20:41:10 2003
8723 @@ -742,14 +742,12 @@
8724 /* -----exported algorithm data: ------------------------------------- */
8726 static struct i2c_algorithm iic_algo = {
8727 - "ITE IIC algorithm",
8729 - iic_xfer, /* master_xfer */
8730 - NULL, /* smbus_xfer */
8731 - NULL, /* slave_xmit */
8732 - NULL, /* slave_recv */
8733 - algo_control, /* ioctl */
8734 - iic_func, /* functionality */
8735 + .owner = THIS_MODULE,
8736 + .name = "ITE IIC algorithm",
8737 + .id = I2C_ALGO_IIC,
8738 + .master_xfer = iic_xfer,
8739 + .algo_control = algo_control,
8740 + .functionality = iic_func,
8744 @@ -780,10 +778,6 @@
8745 adap->retries = 3; /* be replaced by defines */
8749 - MOD_INC_USE_COUNT;
8752 i2c_add_adapter(adap);
8757 DEB2(printk("i2c-algo-ite: adapter unregistered: %s\n",adap->name));
8760 - MOD_DEC_USE_COUNT;
8765 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-algo-sibyte.c Wed Aug 27 18:11:46 2003
8766 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-algo-sibyte.c Sat Nov 15 20:41:10 2003
8767 @@ -136,14 +136,15 @@
8768 /* -----exported algorithm data: ------------------------------------- */
8770 static struct i2c_algorithm i2c_sibyte_algo = {
8771 - "SiByte algorithm",
8773 - NULL, /* master_xfer */
8774 - smbus_xfer, /* smbus_xfer */
8775 - NULL, /* slave_xmit */
8776 - NULL, /* slave_recv */
8777 - algo_control, /* ioctl */
8778 - bit_func, /* functionality */
8779 + .owner = THIS_MODULE,
8780 + .name = "SiByte algorithm",
8781 + .id = I2C_ALGO_SIBYTE,
8782 + .master_xfer = NULL,
8783 + .smbus_xfer = smbus_xfer,
8784 + .slave_xmit = NULL,
8785 + .slave_recv = NULL,
8786 + .algo_control = algo_control,
8787 + .functionality = bit_func,
8796 - MOD_INC_USE_COUNT;
8798 i2c_add_adapter(i2c_adap);
8802 if ((res = i2c_del_adapter(adap)) < 0)
8806 - MOD_DEC_USE_COUNT;
8811 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-keywest.c Tue Jul 15 12:23:26 2003
8812 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-keywest.c Sat Nov 15 20:41:10 2003
8813 @@ -412,25 +412,14 @@
8814 I2C_FUNC_SMBUS_BLOCK_DATA;
8818 -keywest_inc(struct i2c_adapter *adapter)
8820 - MOD_INC_USE_COUNT;
8824 -keywest_dec(struct i2c_adapter *adapter)
8826 - MOD_DEC_USE_COUNT;
8829 /* For now, we only handle combined mode (smbus) */
8830 static struct i2c_algorithm keywest_algorithm = {
8831 - name: "Keywest i2c",
8832 - id: I2C_ALGO_SMBUS,
8833 - smbus_xfer: keywest_smbus_xfer,
8834 - master_xfer: keywest_xfer,
8835 - functionality: keywest_func,
8836 + .owner = THIS_MODULE,
8837 + .name = "Keywest i2c",
8838 + .id = I2C_ALGO_SMBUS,
8839 + .smbus_xfer = keywest_smbus_xfer,
8840 + .master_xfer = keywest_xfer,
8841 + .functionality = keywest_func,
8845 @@ -527,14 +516,13 @@
8846 struct keywest_chan* chan = &iface->channels[i];
8849 + chan->adapter.owner = THIS_MODULE;
8850 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
8851 chan->iface = iface;
8853 chan->adapter.id = I2C_ALGO_SMBUS;
8854 chan->adapter.algo = &keywest_algorithm;
8855 chan->adapter.algo_data = NULL;
8856 - chan->adapter.inc_use = keywest_inc;
8857 - chan->adapter.dec_use = keywest_dec;
8858 chan->adapter.client_register = NULL;
8859 chan->adapter.client_unregister = NULL;
8860 chan->adapter.data = chan;
8861 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-max1617.c Wed Aug 27 18:11:46 2003
8862 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-max1617.c Sat Nov 15 20:41:10 2003
8864 static int max1617_probe(struct i2c_adapter *adap);
8865 static int max1617_detach(struct i2c_client *device);
8866 static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg);
8867 -static void max1617_inc_use(struct i2c_client *device);
8868 -static void max1617_dec_use(struct i2c_client *device);
8870 struct i2c_driver i2c_driver_max1617 = {
8872 - id: I2C_DRIVERID_MAX1617,
8873 - flags: I2C_DF_NOTIFY,
8874 - attach_adapter: max1617_probe,
8875 - detach_client: max1617_detach,
8876 - command: max1617_command,
8877 - inc_use: max1617_inc_use,
8878 - dec_use: max1617_dec_use
8879 + .owner = THIS_MODULE,
8881 + .id = I2C_DRIVERID_MAX1617,
8882 + .flags = I2C_DF_NOTIFY,
8883 + .attach_adapter = max1617_probe,
8884 + .detach_client = max1617_detach,
8885 + .command = max1617_command,
8888 static int max1617_read(struct i2c_client *client, unsigned char subaddr)
8889 @@ -184,20 +181,6 @@
8890 static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg)
8895 -static void max1617_inc_use(struct i2c_client *client)
8898 - MOD_INC_USE_COUNT;
8902 -static void max1617_dec_use(struct i2c_client *client)
8905 - MOD_DEC_USE_COUNT;
8909 void i2c_max1617_init(void)
8910 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-sibyte.c Wed Aug 27 18:11:46 2003
8911 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-sibyte.c Sat Nov 15 20:41:10 2003
8916 -static void sibyte_inc_use(struct i2c_adapter *adap)
8919 - MOD_INC_USE_COUNT;
8923 -static void sibyte_dec_use(struct i2c_adapter *adap)
8926 - MOD_DEC_USE_COUNT;
8930 static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
8931 { NULL, 0, (void *)(KSEG1+A_SMB_BASE(0)) },
8932 { NULL, 1, (void *)(KSEG1+A_SMB_BASE(1)) }
8935 static struct i2c_adapter sibyte_board_adapter[2] = {
8937 - name: "SiByte SMBus 0",
8938 - id: I2C_HW_SIBYTE,
8940 - algo_data: &sibyte_board_data[0],
8941 - inc_use: sibyte_inc_use,
8942 - dec_use: sibyte_dec_use,
8943 - client_register: sibyte_reg,
8944 - client_unregister: sibyte_unreg,
8948 - name: "SiByte SMBus 1",
8949 - id: I2C_HW_SIBYTE,
8951 - algo_data: &sibyte_board_data[1],
8952 - inc_use: sibyte_inc_use,
8953 - dec_use: sibyte_dec_use,
8954 - client_register: sibyte_reg,
8955 - client_unregister: sibyte_unreg,
8959 + .owner = THIS_MODULE,
8960 + .name = "SiByte SMBus 0",
8961 + .id = I2C_HW_SIBYTE,
8963 + .algo_data = &sibyte_board_data[0],
8964 + .client_register = sibyte_reg,
8965 + .client_unregister = sibyte_unreg,
8968 + .owner = THIS_MODULE,
8969 + .name = "SiByte SMBus 1",
8970 + .id = I2C_HW_SIBYTE,
8972 + .algo_data = &sibyte_board_data[1],
8973 + .client_register = sibyte_reg,
8974 + .client_unregister = sibyte_unreg,
8978 int __init i2c_sibyte_init(void)
8979 --- linux-2.4.23-rc1-orig/drivers/i2c/scx200_acb.c Tue Jul 15 12:23:49 2003
8980 +++ linux-2.4.23-rc1-i2c/drivers/i2c/scx200_acb.c Sat Nov 15 20:45:06 2003
8981 @@ -408,22 +408,13 @@
8985 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
8987 - MOD_INC_USE_COUNT;
8990 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
8992 - MOD_DEC_USE_COUNT;
8995 /* For now, we only handle combined mode (smbus) */
8996 static struct i2c_algorithm scx200_acb_algorithm = {
8997 - name: "NatSemi SCx200 ACCESS.bus",
8998 - id: I2C_ALGO_SMBUS,
8999 - smbus_xfer: scx200_acb_smbus_xfer,
9000 - functionality: scx200_acb_func,
9001 + .owner = THIS_MODULE,
9002 + .name = "NatSemi SCx200 ACCESS.bus",
9003 + .id = I2C_ALGO_SMBUS,
9004 + .smbus_xfer = scx200_acb_smbus_xfer,
9005 + .functionality = scx200_acb_func,
9008 struct scx200_acb_iface *scx200_acb_list;
9009 @@ -479,11 +470,10 @@
9010 memset(iface, 0, sizeof(*iface));
9011 adapter = &iface->adapter;
9012 adapter->data = iface;
9013 + adapter->owner = THIS_MODULE;
9014 sprintf(adapter->name, "SCx200 ACB%d", index);
9015 adapter->id = I2C_ALGO_SMBUS;
9016 adapter->algo = &scx200_acb_algorithm;
9017 - adapter->inc_use = scx200_acb_inc_use;
9018 - adapter->dec_use = scx200_acb_dec_use;
9019 adapter->client_register = scx200_acb_reg;
9020 adapter->client_unregister = scx200_acb_unreg;
9022 --- linux-2.4.23-rc1-orig/drivers/i2c/scx200_i2c.c Tue Jul 15 12:23:49 2003
9023 +++ linux-2.4.23-rc1-i2c/drivers/i2c/scx200_i2c.c Sat Nov 15 20:45:06 2003
9028 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
9030 - MOD_INC_USE_COUNT;
9033 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
9035 - MOD_DEC_USE_COUNT;
9038 /* ------------------------------------------------------------------------
9039 * Encapsulate the above functions in the correct operations structure.
9040 * This is only done when more than one hardware adapter is supported.
9041 @@ -101,11 +91,10 @@
9044 static struct i2c_adapter scx200_i2c_ops = {
9045 + .owner = THIS_MODULE,
9046 .name = "NatSemi SCx200 I2C",
9047 .id = I2C_HW_B_VELLE,
9048 .algo_data = &scx200_i2c_data,
9049 - .inc_use = scx200_i2c_inc_use,
9050 - .dec_use = scx200_i2c_dec_use,
9051 .client_register = scx200_i2c_reg,
9052 .client_unregister = scx200_i2c_unreg,
9054 diff -ruN linux-2.4.23-rc1-orig/drivers/ieee1394/pcilynx.c linux-2.4.23-rc1-i2c/drivers/ieee1394/pcilynx.c
9055 --- linux-2.4.23-rc1-orig/drivers/ieee1394/pcilynx.c Sat Nov 15 17:24:54 2003
9056 +++ linux-2.4.23-rc1-i2c/drivers/ieee1394/pcilynx.c Sat Nov 15 17:39:43 2003
9060 static struct i2c_adapter bit_ops = {
9061 - .id = 0xAA, //FIXME: probably we should get an id in i2c-id.h
9062 + .owner = THIS_MODULE,
9063 + .id = I2C_HW_B_PCILYNX,
9064 .client_register = bit_reg,
9065 .client_unregister = bit_unreg,
9066 .name = "PCILynx I2C",
9067 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/Makefile linux-2.4.23-rc1-i2c/drivers/media/video/Makefile
9068 --- linux-2.4.23-rc1-orig/drivers/media/video/Makefile Wed Aug 27 18:11:47 2003
9069 +++ linux-2.4.23-rc1-i2c/drivers/media/video/Makefile Sat Nov 15 18:46:46 2003
9072 obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
9073 obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o i2c-old.o
9074 -obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o i2c-old.o
9075 +obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
9076 obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
9077 obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o
9078 obj-$(CONFIG_VIDEO_W9966) += w9966.o
9080 obj-$(CONFIG_VIDEO_ZORAN_BUZ) += saa7111.o saa7185.o
9081 obj-$(CONFIG_VIDEO_ZORAN_DC10) += saa7110.o adv7175.o
9082 obj-$(CONFIG_VIDEO_ZORAN_LML33) += bt819.o bt856.o
9083 -obj-$(CONFIG_VIDEO_LML33) += bt856.o bt819.o
9084 obj-$(CONFIG_VIDEO_PMS) += pms.o
9085 obj-$(CONFIG_VIDEO_PLANB) += planb.o
9086 obj-$(CONFIG_VIDEO_VINO) += vino.o
9087 -obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
9088 +obj-$(CONFIG_VIDEO_STRADIS) += stradis.o i2c-old.o
9089 obj-$(CONFIG_VIDEO_CPIA) += cpia.o
9090 obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
9091 obj-$(CONFIG_VIDEO_CPIA_USB) += cpia_usb.o
9096 -zoran.o: zr36120.o zr36120_i2c.o zr36120_mem.o
9097 - $(LD) $(LD_RFLAG) -r -o $@ zr36120.o zr36120_i2c.o zr36120_mem.o
9098 +zoran.o: $(zoran-objs)
9099 + $(LD) $(LD_RFLAG) -r -o $@ $(zoran-objs)
9101 bttv.o: $(bttv-objs)
9102 $(LD) $(LD_RFLAG) -r -o $@ $(bttv-objs)
9103 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/bt832.c linux-2.4.23-rc1-i2c/drivers/media/video/bt832.c
9104 --- linux-2.4.23-rc1-orig/drivers/media/video/bt832.c Tue Jul 15 12:23:50 2003
9105 +++ linux-2.4.23-rc1-i2c/drivers/media/video/bt832.c Sat Nov 15 18:46:46 2003
9108 i2c_attach_client(&t->client);
9110 - MOD_INC_USE_COUNT;
9111 if(! bt832_init(&t->client)) {
9112 bt832_detach(&t->client);
9115 printk("bt832: detach.\n");
9116 i2c_detach_client(client);
9118 - MOD_DEC_USE_COUNT;
9124 /* ----------------------------------------------------------------------- */
9126 static struct i2c_driver driver = {
9127 + .owner = THIS_MODULE,
9128 .name = "i2c bt832 driver",
9129 - .id = -1, /* FIXME */
9130 + .id = I2C_DRIVERID_BT832,
9131 .flags = I2C_DF_NOTIFY,
9132 .attach_adapter = bt832_probe,
9133 .detach_client = bt832_detach,
9134 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/i2c-old.c linux-2.4.23-rc1-i2c/drivers/media/video/i2c-old.c
9135 --- linux-2.4.23-rc1-orig/drivers/media/video/i2c-old.c Sun Sep 30 21:26:06 2001
9136 +++ linux-2.4.23-rc1-i2c/drivers/media/video/i2c-old.c Sat Nov 15 18:46:46 2003
9138 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
9139 static int bus_count = 0, driver_count = 0;
9141 -#ifdef CONFIG_VIDEO_BUZ
9142 -extern int saa7111_init(void);
9143 -extern int saa7185_init(void);
9145 -#ifdef CONFIG_VIDEO_LML33
9146 -extern int bt819_init(void);
9147 -extern int bt856_init(void);
9152 printk(KERN_INFO "i2c: initialized%s\n",
9153 scan ? " (i2c bus scan enabled)" : "");
9154 /* anything to do here ? */
9155 -#ifdef CONFIG_VIDEO_BUZ
9159 -#ifdef CONFIG_VIDEO_LML33
9166 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/msp3400.c linux-2.4.23-rc1-i2c/drivers/media/video/msp3400.c
9167 --- linux-2.4.23-rc1-orig/drivers/media/video/msp3400.c Sat Nov 15 17:24:54 2003
9168 +++ linux-2.4.23-rc1-i2c/drivers/media/video/msp3400.c Sat Nov 15 18:46:46 2003
9169 @@ -1243,6 +1243,7 @@
9170 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
9172 static struct i2c_driver driver = {
9173 + .owner = THIS_MODULE,
9174 .name = "i2c msp3400 driver",
9175 .id = I2C_DRIVERID_MSP3400,
9176 .flags = I2C_DF_NOTIFY,
9177 @@ -1346,7 +1347,6 @@
9180 /* startup control thread */
9181 - MOD_INC_USE_COUNT;
9183 rc = kernel_thread(msp->simple ? msp3410d_thread : msp3400c_thread,
9185 @@ -1399,7 +1399,7 @@
9186 i2c_detach_client(client);
9189 - MOD_DEC_USE_COUNT;
9194 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa5249.c linux-2.4.23-rc1-i2c/drivers/media/video/saa5249.c
9195 --- linux-2.4.23-rc1-orig/drivers/media/video/saa5249.c Sun Sep 30 21:26:06 2001
9196 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa5249.c Sat Nov 15 18:46:46 2003
9200 i2c_attach_client(client);
9201 - MOD_INC_USE_COUNT;
9210 - MOD_DEC_USE_COUNT;
9215 @@ -256,23 +256,23 @@
9217 /* new I2C driver support */
9219 -static struct i2c_driver i2c_driver_videotext =
9221 - IF_NAME, /* name */
9222 - I2C_DRIVERID_SAA5249, /* in i2c.h */
9227 +static struct i2c_driver i2c_driver_videotext = {
9228 + .owner = THIS_MODULE,
9230 + .id = I2C_DRIVERID_SAA5249, /* in i2c-id.h */
9231 + .flags = I2C_DF_NOTIFY,
9232 + .attach_adapter = saa5249_probe,
9233 + .detach_client = saa5249_detach,
9234 + .command = saa5249_command,
9237 static struct i2c_client client_template = {
9243 - &i2c_driver_videotext
9244 + .name = "(unset)",
9249 + .driver = &i2c_driver_videotext,
9253 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa7110.c linux-2.4.23-rc1-i2c/drivers/media/video/saa7110.c
9254 --- linux-2.4.23-rc1-orig/drivers/media/video/saa7110.c Sat Nov 15 17:24:54 2003
9255 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa7110.c Sat Nov 15 18:59:29 2003
9258 "saa7110", /* name */
9260 - I2C_DRIVERID_VIDEODECODER, /* in i2c.h */
9261 + I2C_DRIVERID_VIDEODECODER, /* in i2c-old.h */
9262 I2C_SAA7110, I2C_SAA7110+1, /* Addr range */
9265 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa7146.h linux-2.4.23-rc1-i2c/drivers/media/video/saa7146.h
9266 --- linux-2.4.23-rc1-orig/drivers/media/video/saa7146.h Mon Dec 11 22:15:51 2000
9267 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa7146.h Sat Nov 15 18:46:46 2003
9269 #include <linux/types.h>
9270 #include <linux/wait.h>
9272 -#include <linux/i2c.h>
9273 -#include <linux/videodev.h>
9276 #define O_NONCAP O_TRUNC
9278 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/swarm_saa7114h.c linux-2.4.23-rc1-i2c/drivers/media/video/swarm_saa7114h.c
9279 --- linux-2.4.23-rc1-orig/drivers/media/video/swarm_saa7114h.c Wed Aug 27 18:11:47 2003
9280 +++ linux-2.4.23-rc1-i2c/drivers/media/video/swarm_saa7114h.c Sat Nov 15 18:46:46 2003
9281 @@ -201,11 +201,12 @@
9283 struct i2c_driver i2c_driver_saa7114h =
9285 - name: "saa7114h", /* name */
9286 - id: I2C_DRIVERID_SAA7114H, /* ID */
9287 - flags: I2C_DF_NOTIFY, /* XXXKW do I care? */
9288 - attach_adapter: saa7114h_probe,
9289 - detach_client: saa7114h_detach
9290 + .owner = THIS_MODULE,
9291 + .name = "saa7114h",
9292 + .id = I2C_DRIVERID_SAA7114H,
9293 + .flags = I2C_DF_NOTIFY,
9294 + .attach_adapter = saa7114h_probe,
9295 + .detach_client = saa7114h_detach,
9298 /* -----------------------------------------------------------------------
9299 @@ -1634,8 +1635,6 @@
9300 create_proc_decoder(vd->priv);
9303 - MOD_INC_USE_COUNT;
9308 @@ -1668,7 +1667,6 @@
9311 kfree(device->data);
9312 - MOD_DEC_USE_COUNT;
9314 #ifdef CONFIG_PROC_FS
9315 destroy_proc_decoder(((struct video_device *)device->data)->priv);
9316 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda7432.c linux-2.4.23-rc1-i2c/drivers/media/video/tda7432.c
9317 --- linux-2.4.23-rc1-orig/drivers/media/video/tda7432.c Sat Nov 15 17:24:54 2003
9318 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda7432.c Sat Nov 15 18:46:46 2003
9320 i2c_set_clientdata(client, t);
9322 do_tda7432_init(client);
9323 - MOD_INC_USE_COUNT;
9324 printk(KERN_INFO "tda7432: init\n");
9326 i2c_attach_client(client);
9328 i2c_detach_client(client);
9331 - MOD_DEC_USE_COUNT;
9339 static struct i2c_driver driver = {
9340 + .owner = THIS_MODULE,
9341 .name = "i2c tda7432 driver",
9342 .id = I2C_DRIVERID_TDA7432,
9343 .flags = I2C_DF_NOTIFY,
9344 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda9875.c linux-2.4.23-rc1-i2c/drivers/media/video/tda9875.c
9345 --- linux-2.4.23-rc1-orig/drivers/media/video/tda9875.c Sat Nov 15 17:24:54 2003
9346 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda9875.c Sat Nov 15 18:46:46 2003
9350 do_tda9875_init(client);
9351 - MOD_INC_USE_COUNT;
9352 printk(KERN_INFO "tda9875: init\n");
9354 i2c_attach_client(client);
9356 i2c_detach_client(client);
9359 - MOD_DEC_USE_COUNT;
9367 static struct i2c_driver driver = {
9368 + .owner = THIS_MODULE,
9369 .name = "i2c tda9875 driver",
9370 .id = I2C_DRIVERID_TDA9875,
9371 .flags = I2C_DF_NOTIFY,
9372 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda9887.c linux-2.4.23-rc1-i2c/drivers/media/video/tda9887.c
9373 --- linux-2.4.23-rc1-orig/drivers/media/video/tda9887.c Sat Nov 15 17:24:54 2003
9374 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda9887.c Sat Nov 15 18:46:46 2003
9376 i2c_set_clientdata(&t->client, t);
9377 i2c_attach_client(&t->client);
9379 - MOD_INC_USE_COUNT;
9385 i2c_detach_client(client);
9387 - MOD_DEC_USE_COUNT;
9393 /* ----------------------------------------------------------------------- */
9395 static struct i2c_driver driver = {
9396 + .owner = THIS_MODULE,
9397 .name = "i2c tda9887 driver",
9398 - .id = -1, /* FIXME */
9399 + .id = I2C_DRIVERID_TDA9887,
9400 .flags = I2C_DF_NOTIFY,
9401 .attach_adapter = tda9887_probe,
9402 .detach_client = tda9887_detach,
9403 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tuner-3036.c linux-2.4.23-rc1-i2c/drivers/media/video/tuner-3036.c
9404 --- linux-2.4.23-rc1-orig/drivers/media/video/tuner-3036.c Sun Sep 30 21:26:06 2001
9405 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tuner-3036.c Sat Nov 15 18:46:46 2003
9407 printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
9409 i2c_attach_client(client);
9410 - MOD_INC_USE_COUNT;
9412 if (i2c_master_send(client, buffer, 2) != 2)
9413 printk("tuner: i2c i/o error 1\n");
9416 tuner_detach(struct i2c_client *c)
9418 - MOD_DEC_USE_COUNT;
9422 @@ -183,24 +181,23 @@
9423 /* ----------------------------------------------------------------------- */
9425 static struct i2c_driver
9428 - "sab3036", /* name */
9429 - I2C_DRIVERID_SAB3036, /* ID */
9434 +i2c_driver_tuner = {
9435 + .owner = THIS_MODULE,
9436 + .name = "sab3036",
9437 + .id = I2C_DRIVERID_SAB3036,
9438 + .flags = I2C_DF_NOTIFY,
9439 + .attach_adapter = tuner_probe,
9440 + .detach_client = tuner_detach,
9441 + .command = tuner_command,
9444 -static struct i2c_client client_template =
9446 - "SAB3036", /* name */
9452 +static struct i2c_client client_template = {
9453 + .name = "SAB3036",
9458 + .driver = &i2c_driver_tuner,
9462 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tuner.c linux-2.4.23-rc1-i2c/drivers/media/video/tuner.c
9463 --- linux-2.4.23-rc1-orig/drivers/media/video/tuner.c Sat Nov 15 17:24:54 2003
9464 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tuner.c Sat Nov 15 18:46:46 2003
9466 /* ----------------------------------------------------------------------- */
9468 static struct i2c_driver driver = {
9469 + .owner = THIS_MODULE,
9470 .name = "i2c TV tuner driver",
9471 .id = I2C_DRIVERID_TUNER,
9472 .flags = I2C_DF_NOTIFY,
9473 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tvaudio.c linux-2.4.23-rc1-i2c/drivers/media/video/tvaudio.c
9474 --- linux-2.4.23-rc1-orig/drivers/media/video/tvaudio.c Sat Nov 15 17:24:54 2003
9475 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tvaudio.c Sat Nov 15 18:46:46 2003
9476 @@ -1463,7 +1463,6 @@
9477 chip->shadow.count = desc->registers+1;
9478 chip->prevmode = -1;
9480 - MOD_INC_USE_COUNT;
9481 i2c_attach_client(&chip->c);
9483 /* initialization */
9484 @@ -1538,7 +1537,7 @@
9486 i2c_detach_client(&chip->c);
9488 - MOD_DEC_USE_COUNT;
9493 @@ -1649,6 +1648,7 @@
9496 static struct i2c_driver driver = {
9497 + .owner = THIS_MODULE,
9498 .name = "generic i2c audio driver",
9499 .id = I2C_DRIVERID_TVAUDIO,
9500 .flags = I2C_DF_NOTIFY,
9501 diff -ruN linux-2.4.23-rc1-orig/drivers/pcmcia/sa1100_stork.c linux-2.4.23-rc1-i2c/drivers/pcmcia/sa1100_stork.c
9502 --- linux-2.4.23-rc1-orig/drivers/pcmcia/sa1100_stork.c Tue Jul 15 12:23:03 2003
9503 +++ linux-2.4.23-rc1-i2c/drivers/pcmcia/sa1100_stork.c Sat Nov 15 17:41:42 2003
9505 #include <linux/init.h>
9506 #include <linux/kernel.h>
9507 #include <linux/sched.h>
9508 -#include <linux/i2c.h>
9510 #include <asm/hardware.h>
9511 #include <asm/irq.h>
9512 diff -ruN linux-2.4.23-rc1-orig/drivers/sound/dmasound/dac3550a.c linux-2.4.23-rc1-i2c/drivers/sound/dmasound/dac3550a.c
9513 --- linux-2.4.23-rc1-orig/drivers/sound/dmasound/dac3550a.c Tue Jul 15 12:22:41 2003
9514 +++ linux-2.4.23-rc1-i2c/drivers/sound/dmasound/dac3550a.c Sat Nov 15 18:27:29 2003
9518 struct i2c_driver daca_driver = {
9519 - name: "DAC3550A driver V " DACA_VERSION,
9520 - id: I2C_DRIVERID_DACA,
9521 - flags: I2C_DF_NOTIFY,
9522 - attach_adapter: &daca_attach_adapter,
9523 - detach_client: &daca_detach_client,
9525 - inc_use: NULL, /* &daca_inc_use, */
9526 - dec_use: NULL /* &daca_dev_use */
9528 + .owner = THIS_MODULE,
9529 + .name = "DAC3550A driver V " DACA_VERSION,
9530 + .id = I2C_DRIVERID_DACA,
9531 + .flags = I2C_DF_NOTIFY,
9532 + .attach_adapter = &daca_attach_adapter,
9533 + .detach_client = &daca_detach_client,
9538 #define VOL_MAX ((1<<20) - 1)
9539 diff -ruN linux-2.4.23-rc1-orig/drivers/sound/dmasound/tas3001c.c linux-2.4.23-rc1-i2c/drivers/sound/dmasound/tas3001c.c
9540 --- linux-2.4.23-rc1-orig/drivers/sound/dmasound/tas3001c.c Tue Jul 15 12:22:41 2003
9541 +++ linux-2.4.23-rc1-i2c/drivers/sound/dmasound/tas3001c.c Sat Nov 15 18:27:29 2003
9545 struct i2c_driver tas_driver = {
9546 - name: "TAS3001C driver V 0.3",
9547 - id: I2C_DRIVERID_TAS,
9548 - flags: I2C_DF_NOTIFY,
9549 - attach_adapter: &tas_attach_adapter,
9550 - detach_client: &tas_detach_client,
9552 - inc_use: NULL, /* &tas_inc_use, */
9553 - dec_use: NULL /* &tas_dev_use */
9554 + .owner = THIS_MODULE,
9555 + .name = "TAS3001C driver V " TAS_VERSION,
9556 + .id = I2C_DRIVERID_TAS,
9557 + .flags = I2C_DF_NOTIFY,
9558 + .attach_adapter = &tas_attach_adapter,
9559 + .detach_client = &tas_detach_client,
9564 diff -ruN linux-2.4.23-rc1-orig/drivers/usb/w9968cf.c linux-2.4.23-rc1-i2c/drivers/usb/w9968cf.c
9565 --- linux-2.4.23-rc1-orig/drivers/usb/w9968cf.c Sat Nov 15 17:24:56 2003
9566 +++ linux-2.4.23-rc1-i2c/drivers/usb/w9968cf.c Sat Nov 15 21:48:40 2003
9568 static int w9968cf_i2c_detach_inform(struct i2c_client*);
9569 static int w9968cf_i2c_control(struct i2c_adapter*, unsigned int cmd,
9571 -static void w9968cf_i2c_inc_use(struct i2c_adapter*);
9572 -static void w9968cf_i2c_dec_use(struct i2c_adapter*);
9574 /* Memory management */
9575 static inline unsigned long kvirt_to_pa(unsigned long adr);
9576 @@ -1832,18 +1830,6 @@
9580 -static void w9968cf_i2c_inc_use(struct i2c_adapter* adap)
9582 - MOD_INC_USE_COUNT;
9586 -static void w9968cf_i2c_dec_use(struct i2c_adapter* adap)
9588 - MOD_DEC_USE_COUNT;
9592 static int w9968cf_i2c_init(struct w9968cf_device* cam)
9595 @@ -1857,9 +1843,8 @@
9598 static struct i2c_adapter adap = {
9599 + .owner = THIS_MODULE,
9600 .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF,
9601 - .inc_use = w9968cf_i2c_inc_use,
9602 - .dec_use = w9968cf_i2c_dec_use,
9603 .client_register = w9968cf_i2c_attach_inform,
9604 .client_unregister = w9968cf_i2c_detach_inform,
9606 diff -ruN linux-2.4.23-rc1-orig/drivers/video/matrox/i2c-matroxfb.c linux-2.4.23-rc1-i2c/drivers/video/matrox/i2c-matroxfb.c
9607 --- linux-2.4.23-rc1-orig/drivers/video/matrox/i2c-matroxfb.c Tue Jul 15 12:23:53 2003
9608 +++ linux-2.4.23-rc1-i2c/drivers/video/matrox/i2c-matroxfb.c Sat Nov 15 18:28:33 2003
9610 return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
9613 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
9614 - MOD_INC_USE_COUNT;
9617 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
9618 - MOD_DEC_USE_COUNT;
9621 -static struct i2c_adapter matrox_i2c_adapter_template =
9623 - .id = I2C_HW_B_G400,
9624 - .inc_use = matroxfb_dh_inc_use,
9625 - .dec_use = matroxfb_dh_dec_use,
9626 +static struct i2c_adapter matrox_i2c_adapter_template = {
9627 + .owner = THIS_MODULE,
9628 + .id = I2C_HW_B_G400,
9631 -static struct i2c_algo_bit_data matrox_i2c_algo_template =
9634 - matroxfb_gpio_setsda,
9635 - matroxfb_gpio_setscl,
9636 - matroxfb_gpio_getsda,
9637 - matroxfb_gpio_getscl,
9639 +static struct i2c_algo_bit_data matrox_i2c_algo_template = {
9641 + .setsda = matroxfb_gpio_setsda,
9642 + .setscl = matroxfb_gpio_setscl,
9643 + .getsda = matroxfb_gpio_getsda,
9644 + .getscl = matroxfb_gpio_getscl,
9650 static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
9651 diff -ruN linux-2.4.23-rc1-orig/drivers/video/matrox/matroxfb_maven.c linux-2.4.23-rc1-i2c/drivers/video/matrox/matroxfb_maven.c
9652 --- linux-2.4.23-rc1-orig/drivers/video/matrox/matroxfb_maven.c Tue Jul 15 12:23:53 2003
9653 +++ linux-2.4.23-rc1-i2c/drivers/video/matrox/matroxfb_maven.c Sat Nov 15 18:28:33 2003
9654 @@ -1246,14 +1246,6 @@
9655 static unsigned short normal_i2c_range[] = { MAVEN_I2CID, MAVEN_I2CID, I2C_CLIENT_END };
9658 -static void maven_inc_use(struct i2c_client* clnt) {
9659 - MOD_INC_USE_COUNT;
9662 -static void maven_dec_use(struct i2c_client* clnt) {
9663 - MOD_DEC_USE_COUNT;
9666 static struct i2c_driver maven_driver;
9668 static int maven_detect_client(struct i2c_adapter* adapter, int address, unsigned short flags,
9669 @@ -1319,15 +1311,14 @@
9671 static int maven_driver_registered = 0;
9673 -static struct i2c_driver maven_driver={
9675 - I2C_DRIVERID_MGATVO,
9677 - maven_attach_adapter,
9678 - maven_detach_client,
9682 +static struct i2c_driver maven_driver = {
9683 + .owner = THIS_MODULE,
9685 + .id = I2C_DRIVERID_MGATVO,
9686 + .flags = I2C_DF_NOTIFY,
9687 + .attach_adapter = maven_attach_adapter,
9688 + .detach_client = maven_detach_client,
9689 + .command = maven_command,
9692 /* ************************** */