1 diff -ruN linux-2.4.22-orig/drivers/acorn/char/i2c.c linux-2.4.22-i2c/drivers/acorn/char/i2c.c
2 --- linux-2.4.22-orig/drivers/acorn/char/i2c.c Wed Aug 27 18:11:45 2003
3 +++ linux-2.4.22-i2c/drivers/acorn/char/i2c.c Thu Aug 28 18:13:23 2003
7 static struct i2c_adapter ioc_ops = {
10 - algo_data: &ioc_data,
11 - client_register: ioc_client_reg,
12 - client_unregister: ioc_client_unreg
13 + .owner = THIS_MODULE,
16 + .algo_data = &ioc_data,
17 + .client_register = ioc_client_reg,
18 + .client_unregister = ioc_client_unreg
21 static int __init i2c_ioc_init(void)
22 diff -ruN linux-2.4.22-orig/drivers/acorn/char/pcf8583.c linux-2.4.22-i2c/drivers/acorn/char/pcf8583.c
23 --- linux-2.4.22-orig/drivers/acorn/char/pcf8583.c Tue Jul 15 12:23:25 2003
24 +++ linux-2.4.22-i2c/drivers/acorn/char/pcf8583.c Thu Aug 28 18:13:23 2003
28 static struct i2c_driver pcf8583_driver = {
30 - id: I2C_DRIVERID_PCF8583,
31 - flags: I2C_DF_NOTIFY,
32 - attach_adapter: pcf8583_probe,
33 - detach_client: pcf8583_detach,
34 - command: pcf8583_command
35 + .owner = THIS_MODULE,
37 + .id = I2C_DRIVERID_PCF8583,
38 + .flags = I2C_DF_NOTIFY,
39 + .attach_adapter = pcf8583_probe,
40 + .detach_client = pcf8583_detach,
41 + .command = pcf8583_command
44 static __init int pcf8583_init(void)
45 --- linux-2.4.22-orig/drivers/i2c/Config.in Wed Aug 27 18:11:46 2003
46 +++ linux-2.4.22-i2c/drivers/i2c/Config.in Sun Sep 7 17:07:13 2003
48 dep_tristate ' Philips style parallel port adapter' CONFIG_I2C_PHILIPSPAR $CONFIG_I2C_ALGOBIT $CONFIG_PARPORT
49 dep_tristate ' ELV adapter' CONFIG_I2C_ELV $CONFIG_I2C_ALGOBIT
50 dep_tristate ' Velleman K9000 adapter' CONFIG_I2C_VELLEMAN $CONFIG_I2C_ALGOBIT
51 - dep_tristate ' NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200 $CONFIG_I2C_ALGOBIT
52 + dep_tristate ' Basic I2C on Parallel Port' CONFIG_I2C_PPORT $CONFIG_I2C_ALGOBIT
53 + if [ "$CONFIG_ARCH_SA1100" = "y" ]; then
54 + dep_tristate 'SA1100 I2C Adapter' CONFIG_I2C_FRODO $CONFIG_I2C_ALGOBIT
56 + dep_tristate ' NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200_GPIO $CONFIG_I2C_ALGOBIT
57 if [ "$CONFIG_SCx200_I2C" != "n" ]; then
58 int ' GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
59 int ' GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
61 - dep_tristate ' NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
64 + dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
66 dep_tristate 'I2C PCF 8584 interfaces' CONFIG_I2C_ALGOPCF $CONFIG_I2C
67 if [ "$CONFIG_I2C_ALGOPCF" != "n" ]; then
68 dep_tristate ' Elektor ISA card' CONFIG_I2C_ELEKTOR $CONFIG_I2C_ALGOPCF
69 + dep_tristate ' PCF on EPP port' CONFIG_I2C_PCFEPP $CONFIG_I2C_ALGOPCF
72 if [ "$CONFIG_MIPS_ITE8172" = "y" ]; then
74 if [ "$CONFIG_8xx" = "y" ]; then
75 dep_tristate 'MPC8xx CPM I2C interface' CONFIG_I2C_ALGO8XX $CONFIG_I2C
76 if [ "$CONFIG_RPXLITE" = "y" -o "$CONFIG_RPXCLASSIC" = "y" ]; then
77 - dep_tristate ' Embedded Planet RPX Lite/Classic suppoort' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
78 + dep_tristate ' Embedded Planet RPX Lite/Classic support' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
81 - if [ "$CONFIG_405" = "y" ]; then
82 - dep_tristate 'PPC 405 I2C Algorithm' CONFIG_I2C_PPC405_ALGO $CONFIG_I2C
83 - if [ "$CONFIG_I2C_PPC405_ALGO" != "n" ]; then
84 - dep_tristate ' PPC 405 I2C Adapter' CONFIG_I2C_PPC405_ADAP $CONFIG_I2C_PPC405_ALGO
85 + if [ "$CONFIG_IBM_OCP" = "y" ]; then
86 + dep_tristate 'IBM on-chip I2C Algorithm' CONFIG_I2C_IBM_OCP_ALGO $CONFIG_I2C
87 + if [ "$CONFIG_I2C_IBM_OCP_ALGO" != "n" ]; then
88 + dep_tristate ' IBM on-chip I2C Adapter' CONFIG_I2C_IBM_OCP_ADAP $CONFIG_I2C_IBM_OCP_ALGO
93 dep_tristate 'Keywest I2C interface in Apple Core99 machines' CONFIG_I2C_KEYWEST $CONFIG_I2C
96 - if [ "$CONFIG_SIBYTE_SB1xxx_SOC" = "y" ]; then
97 - dep_tristate 'SiByte SMBus interface' CONFIG_I2C_ALGO_SIBYTE $CONFIG_I2C
98 - dep_tristate ' MAX1617 Temperature Sensor' CONFIG_I2C_MAX1617 $CONFIG_I2C_ALGO_SIBYTE
101 # This is needed for automatic patch generation: sensors code starts here
102 # This is needed for automatic patch generation: sensors code ends here
104 dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C
105 - dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C
106 + dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C $CONFIG_SYSCTL
110 --- linux-2.4.22-orig/drivers/i2c/Makefile Wed Aug 27 18:11:46 2003
111 +++ linux-2.4.22-i2c/drivers/i2c/Makefile Sun Aug 31 14:46:51 2003
115 export-objs := i2c-core.o i2c-algo-bit.o i2c-algo-pcf.o \
116 - i2c-algo-ite.o i2c-proc.o i2c-algo-sibyte.o
117 + i2c-algo-ite.o i2c-proc.o i2c-algo-8xx.o \
120 obj-$(CONFIG_I2C) += i2c-core.o
121 obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
123 obj-$(CONFIG_I2C_PHILIPSPAR) += i2c-philips-par.o
124 obj-$(CONFIG_I2C_ELV) += i2c-elv.o
125 obj-$(CONFIG_I2C_VELLEMAN) += i2c-velleman.o
126 +obj-$(CONFIG_I2C_PPORT) += i2c-pport.o
127 +obj-$(CONFIG_I2C_FRODO) += i2c-frodo.o
128 obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o
129 obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
130 +obj-$(CONFIG_I2C_PCFEPP) += i2c-pcf-epp.o
131 obj-$(CONFIG_ITE_I2C_ALGO) += i2c-algo-ite.o
132 obj-$(CONFIG_ITE_I2C_ADAP) += i2c-adap-ite.o
133 +obj-$(CONFIG_I2C_ALGO8XX) += i2c-algo-8xx.o
134 +obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
135 +obj-$(CONFIG_I2C_IBM_OCP_ALGO) += i2c-algo-ibm_ocp.o
136 +obj-$(CONFIG_I2C_IBM_OCP_ADAP) += i2c-adap-ibm_ocp.o
137 obj-$(CONFIG_I2C_PROC) += i2c-proc.o
138 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
139 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
140 obj-$(CONFIG_I2C_KEYWEST) += i2c-keywest.o
141 -obj-$(CONFIG_I2C_ALGO_SIBYTE) += i2c-algo-sibyte.o i2c-sibyte.o
142 -obj-$(CONFIG_I2C_MAX1617) += i2c-max1617.o
144 # This is needed for automatic patch generation: sensors code starts here
145 # This is needed for automatic patch generation: sensors code ends here
146 --- linux-old/Documentation/i2c/dev-interface Sun Aug 31 14:51:49 CEST 2003
147 +++ linux/Documentation/i2c/dev-interface Sun Aug 31 14:51:49 CEST 2003
149 ioctl(file,I2C_TENBIT,long select)
150 Selects ten bit addresses if select not equals 0, selects normal 7 bit
151 - addresses if select equals 0.
152 + addresses if select equals 0. Default 0.
154 +ioctl(file,I2C_PEC,long select)
155 + Selects SMBus PEC (packet error checking) generation and verification
156 + if select not equals 0, disables if select equals 0. Default 0.
157 + Used only for SMBus transactions.
159 ioctl(file,I2C_FUNCS,unsigned long *funcs)
160 --- linux-old/Documentation/i2c/functionality Sun Aug 31 14:51:49 CEST 2003
161 +++ linux/Documentation/i2c/functionality Sun Aug 31 14:51:49 CEST 2003
162 --- linux-old/Documentation/i2c/i2c-pport Sun Aug 31 14:51:49 CEST 2003
163 +++ linux/Documentation/i2c/i2c-pport Sun Aug 31 14:51:49 CEST 2003
165 +Parallel Port Adapters
166 +----------------------
167 +If you are installing parallel port adapters it means you are probably messing
168 +around with wires and IC's and the like. If you have purchased a card that
169 +provides an external i2c/smbus this will require combined algorithm and
170 +adapter code in a single module.
171 +If you are doing it yourself by using the parallel port there
172 +are basically 2 options.
174 +1) Using the parallel port and using the i2c-pport adapter module and the
175 +i2c-algo-bit algorithm module together to enable you to wire up your parallel
176 +port to act as an i2c/smbus. This provides a bus that will enable most
177 +sensors to work but doesn't support the entire i2c/smbus capability.
179 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c
180 +adapter chip. You will need to build a bit of a circuit to do this. This
181 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf
182 +algorithm module. This support almost all of the i2c/smbus capabilities.
185 +i2c-pport Documentation
186 +-----------------------
187 +This is a primitive parallel port driver for the i2c bus, which exploits
188 +features of modern bidirectional parallel ports.
190 +Bidirectional ports have particular bits connected in following way:
195 + read \-----| /------- Out pin
203 +It means when output is set to 1 we can read the port. Therefore
204 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It
205 +is not necessary to add any external - additional parts, we can
206 +read and write the same port simultaneously.
207 + I only use register base+2 so it is possible to use all
208 +8 data bits of parallel port for other applications (I have
209 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
210 + Port. The only disadvantage is we can only support 5V chips.
216 +SDA - connect to pin 14 (Auto Linefeed)
217 +SCL - connect to pin 16 (Initialize Printer)
218 +GND - connect to pin 18-25
219 ++5V - use external supply (I use 5V from 3.5" floppy connector)
232 --- linux-old/Documentation/i2c/i2c-protocol Sun Aug 31 14:51:49 CEST 2003
233 +++ linux/Documentation/i2c/i2c-protocol Sun Aug 31 14:51:49 CEST 2003
237 - In a combined transaction, no 'S Addr' is generated at some point.
238 - For example, setting I2C_M_NOSTART on the second partial message
239 + In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
240 + point. For example, setting I2C_M_NOSTART on the second partial message
241 generates something like:
242 - S Addr Rd [A] [Data] NA Wr [A] Data [A] P
243 + S Addr Rd [A] [Data] NA Data [A] P
244 If you set the I2C_M_NOSTART variable for the first partial message,
245 we do not generate Addr, but we do generate the startbit S. This will
248 S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
251 + Flags I2C_M_IGNORE_NAK
252 + Normally message is interrupted immediately if there is [NA] from the
253 + client. Setting this flag treats any [NA] as [A], and all of
255 + These messages may still fail to SCL lo->hi timeout.
257 + Flags I2C_M_NO_RD_ACK
258 + In a read message, master A/NA bit is skipped.
259 --- linux-old/Documentation/i2c/i2c-velleman Sun Aug 31 14:51:49 CEST 2003
260 +++ linux/Documentation/i2c/i2c-velleman Sun Aug 31 14:51:49 CEST 2003
264 +This is a driver for i2c-hw access for Velleman K9000 and other adapters.
269 + http://www.velleman.be/
271 +Velleman K8000 Howto:
272 + http://howto.htlw16.ac.at/k8000-howto.html
275 +K8000 and K8005 libraries
276 +-------------------------
277 +The project has lead to new libs for the Velleman K8000 and K8005..
278 +LIBK8000 v1.99.1 and LIBK8005 v0.21
280 +With these libs you can control the K8000 and K8005 with the original
281 +simple commands which are in the original Velleman software.
282 +Like SetIOchannel, ReadADchannel, SendStepCCWFull and many more.
283 +Via i2c kernel device /dev/velleman
285 +The libs can be found on http://groups.yahoo.com/group/k8000/files/linux/
287 +The Velleman K8000 interface card on http://www.velleman.be/kits/k8000.htm
288 +The Velleman K8005 steppermotorcard on http://www.velleman.be/kits/k8005.htm
289 --- linux-old/Documentation/i2c/proc-interface Sun Aug 31 14:51:49 CEST 2003
290 +++ linux/Documentation/i2c/proc-interface Sun Aug 31 14:51:49 CEST 2003
291 --- linux-old/Documentation/i2c/smbus-protocol Sun Aug 31 14:51:50 CEST 2003
292 +++ linux/Documentation/i2c/smbus-protocol Sun Aug 31 14:51:50 CEST 2003
294 +SMBus Protocol Summary
295 +======================
296 +The following is a summary of the SMBus protocol. It applies to
297 +all revisions of the protocol (1.0, 1.1, and 2.0).
298 +Certain protocol features which are not supported by
299 +this package are briefly described at the end of this document.
301 Some adapters understand only the SMBus (System Management Bus) protocol,
302 which is a subset from the I2C protocol. Fortunately, many devices use
304 SMBus adapters and I2C adapters (the SMBus command set is automatically
305 translated to I2C on I2C adapters, but plain I2C commands can not be
306 -handled at all on a pure SMBus adapter).
307 +handled at all on most pure SMBus adapters).
309 Below is a list of SMBus commands.
311 See Read Byte for more information.
313 -S Addr Wr [A] Data NA P
314 +S Addr Wr [A] Data [A] P
320 -This command reads a block of upto 32 bytes from a device, from a
321 +This command reads a block of up to 32 bytes from a device, from a
322 designated register that is specified through the Comm byte. The amount
323 of data is specified by the device in the Count byte.
327 -The opposite of the Block Read command, this writes upto 32 bytes to
328 +The opposite of the Block Read command, this writes up to 32 bytes to
329 a device, to a designated register that is specified through the
330 Comm byte. The amount of data is specified in the Count byte.
332 S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
335 +SMBus Block Process Call
336 +========================
338 +SMBus Block Process Call was introduced in Revision 2.0 of the specification.
340 +This command selects a device register (through the Comm byte), sends
341 +1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.
343 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
344 + S Addr Rd [A] [Count] A [Data] ... NA P
350 +This command is sent from a SMBus device acting as a master to the
351 +SMBus host acting as a slave.
352 +It is the same form as Write Word, with the command code replaced by the
353 +alerting device's address.
355 +[S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
358 +Packet Error Checking (PEC)
359 +===========================
360 +Packet Error Checking was introduced in Revision 1.1 of the specification.
362 +PEC adds a CRC-8 error-checking byte to all transfers.
365 +Address Resolution Protocol (ARP)
366 +=================================
367 +The Address Resolution Protocol was introduced in Revision 2.0 of
368 +the specification. It is a higher-layer protocol which uses the
371 +ARP adds device enumeration and dynamic address assignment to
372 +the protocol. All ARP communications use slave address 0x61 and
373 +require PEC checksums.
376 +I2C Block Transactions
377 +======================
378 +The following I2C block transactions are supported by the
379 +SMBus layer and are described here for completeness.
380 +I2C block transactions do not limit the number of bytes transferred
381 +but the SMBus layer places a limit of 32 bytes.
387 +This command reads a block of bytes from a device, from a
388 +designated register that is specified through the Comm byte.
390 +S Addr Wr [A] Comm [A]
391 + S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
394 +I2C Block Read (2 Comm bytes)
395 +=============================
397 +This command reads a block of bytes from a device, from a
398 +designated register that is specified through the two Comm bytes.
400 +S Addr Wr [A] Comm1 [A] Comm2 [A]
401 + S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
407 +The opposite of the Block Read command, this writes bytes to
408 +a device, to a designated register that is specified through the
409 +Comm byte. Note that command lengths of 0, 2, or more bytes are
410 +supported as they are indistinguishable from data.
412 +S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
415 --- linux-old/Documentation/i2c/summary Sun Aug 31 14:51:50 CEST 2003
416 +++ linux/Documentation/i2c/summary Sun Aug 31 14:51:50 CEST 2003
419 I2C (pronounce: I squared C) is a protocol developed by Philips. It is a
420 -slow two-wire protocol (10-100 kHz), but it suffices for many types of
421 +slow two-wire protocol (10-400 kHz), but it suffices for many types of
427 -Note that not only stable drivers are patched into the kernel by 'mkpatch'.
428 +Note that only stable drivers are patched into the kernel by 'mkpatch'.
434 -i2c-core: The basic I2C code, including the /proc interface
435 -i2c-dev: The /dev interface
436 -i2c-proc: The /proc interface for device (client) drivers
437 +i2c-core: The basic I2C code, including the /proc/bus/i2c* interface
438 +i2c-dev: The /dev/i2c-* interface
439 +i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers
443 i2c-algo-bit: A bit-banging algorithm
444 i2c-algo-pcf: A PCF 8584 style algorithm
445 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
446 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
450 i2c-elektor: Elektor ISA card (uses i2c-algo-pcf)
451 i2c-elv: ELV parallel port adapter (uses i2c-algo-bit)
452 -i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
453 +i2c-pcf-epp: PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
454 i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
455 -i2c-ppc405: IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
456 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
457 i2c-pport: Primitive parallel port adapter (uses i2c-algo-bit)
458 i2c-rpx: RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
459 --- linux-old/Documentation/i2c/ten-bit-addresses Sun Aug 31 14:51:50 CEST 2003
460 +++ linux/Documentation/i2c/ten-bit-addresses Sun Aug 31 14:51:50 CEST 2003
461 --- linux-old/Documentation/i2c/writing-clients Sun Aug 31 14:51:50 CEST 2003
462 +++ linux/Documentation/i2c/writing-clients Sun Aug 31 14:51:50 CEST 2003
466 - struct i2c_driver foo_driver
468 - /* name */ "Foo version 2.3 and later driver",
469 - /* id */ I2C_DRIVERID_FOO,
470 - /* flags */ I2C_DF_NOTIFY,
471 - /* attach_adapter */ &foo_attach_adapter,
472 - /* detach_client */ &foo_detach_client,
473 - /* command */ &foo_command, /* May be NULL */
474 - /* inc_use */ &foo_inc_use, /* May be NULL */
475 - /* dec_use */ &foo_dec_use /* May be NULL */
476 + static struct i2c_driver foo_driver = {
477 + .owner = THIS_MODULE,
478 + .name = "Foo version 2.3 driver",
479 + .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */
480 + .flags = I2C_DF_NOTIFY,
481 + .attach_adapter = &foo_attach_adapter,
482 + .detach_client = &foo_detach_client,
483 + .command = &foo_command /* may be NULL */
493 -If your driver can also be compiled as a module, there are moments at
494 -which the module can not be removed from memory. For example, when you
495 -are doing a lengthy transaction, or when you create a /proc directory,
496 -and some process has entered that directory (this last case is the
497 -main reason why these call-backs were introduced).
499 -To increase or decrease the module usage count, you can use the
500 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
501 -which needs to get its usage count changed; that is why each driver
502 -module has to implement its own callback.
504 - void foo_inc_use (struct i2c_client *client)
511 - void foo_dec_use (struct i2c_client *client)
518 -Do not call these call-back functions directly; instead, use one of the
519 -following functions defined in i2c.h:
520 - void i2c_inc_use_client(struct i2c_client *);
521 - void i2c_dec_use_client(struct i2c_client *);
523 -You should *not* increase the module count just because a device is
524 -detected and a client created. This would make it impossible to remove
526 +There use to be two additional fields in this structure, inc_use et dec_use,
527 +for module usage count, but these fields were obsoleted and removed.
531 The detect client function is called by i2c_probe or i2c_detect.
532 The `kind' parameter contains 0 if this call is due to a `force'
533 -parameter, and 0 otherwise (for i2c_detect, it contains 0 if
534 +parameter, and -1 otherwise (for i2c_detect, it contains 0 if
535 this call is due to the generic `force' parameter, and the chip type
536 number if it is due to a specific `force' parameter).
538 need it, remove it. We do it here to help to lessen memory
540 - if (! (new_client = kmalloc(sizeof(struct i2c_client)) +
541 + if (! (new_client = kmalloc(sizeof(struct i2c_client) +
542 sizeof(struct foo_data),
547 --- linux-old/drivers/i2c/i2c-adap-ibm_ocp.c Sun Aug 31 14:51:51 CEST 2003
548 +++ linux/drivers/i2c/i2c-adap-ibm_ocp.c Sun Aug 31 14:51:51 CEST 2003
551 + -------------------------------------------------------------------------
552 + i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
553 + -------------------------------------------------------------------------
555 + Ian DaSilva, MontaVista Software, Inc.
556 + idasilva@mvista.com or source@mvista.com
558 + Copyright 2000 MontaVista Software Inc.
560 + Changes made to support the IIC peripheral on the IBM PPC 405
563 + ----------------------------------------------------------------------------
564 + This file was highly leveraged from i2c-elektor.c, which was created
565 + by Simon G. Vogl and Hans Berglund:
568 + Copyright (C) 1995-97 Simon G. Vogl
569 + 1998-99 Hans Berglund
571 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
572 + Frodo Looijaard <frodol@dds.nl>
575 + This program is free software; you can redistribute it and/or modify
576 + it under the terms of the GNU General Public License as published by
577 + the Free Software Foundation; either version 2 of the License, or
578 + (at your option) any later version.
580 + This program is distributed in the hope that it will be useful,
581 + but WITHOUT ANY WARRANTY; without even the implied warranty of
582 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
583 + GNU General Public License for more details.
585 + You should have received a copy of the GNU General Public License
586 + along with this program; if not, write to the Free Software
587 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
588 + ----------------------------------------------------------------------------
590 + History: 01/20/12 - Armin
592 + ported up to 2.4.16+
594 + Version 02/03/25 - Armin
595 + converted to ocp format
596 + removed commented out or #if 0 code
598 + TODO: convert to ocp_register
604 +#include <linux/kernel.h>
605 +#include <linux/ioport.h>
606 +#include <linux/module.h>
607 +#include <linux/delay.h>
608 +#include <linux/slab.h>
609 +#include <linux/init.h>
610 +#include <linux/i2c.h>
611 +#include <linux/i2c-algo-ibm_ocp.h>
612 +#include <asm/irq.h>
614 +#include <asm/ocp.h>
617 + * This next section is configurable, and it is used to set the number
618 + * of i2c controllers in the system. The default number of instances is 1,
619 + * however, this should be changed to reflect your system's configuration.
623 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
625 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
626 +extern iic_t *IIC_ADDR[];
627 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
629 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
630 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
632 +static int i2c_debug=0;
633 +static wait_queue_head_t iic_wait[IIC_NUMS];
634 +static int iic_pending;
635 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
638 +/* ----- global defines ----------------------------------------------- */
639 +#define DEB(x) if (i2c_debug>=1) x
640 +#define DEB2(x) if (i2c_debug>=2) x
641 +#define DEB3(x) if (i2c_debug>=3) x
642 +#define DEBE(x) x /* error messages */
644 +/* ----- local functions ---------------------------------------------- */
647 +// Description: Write a byte to IIC hardware
649 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
651 + // writeb resolves to a write to the specified memory location
652 + // plus a call to eieio. eieio ensures that all instructions
653 + // preceding it are completed before any further stores are
655 + // Delays at this level (to protect writes) are not needed here.
661 +// Description: Read a byte from IIC hardware
663 +static int iic_ibmocp_getbyte(void *data, int ctl)
673 +// Description: Return our slave address. This is the address
674 +// put on the I2C bus when another master on the bus wants to address us
677 +static int iic_ibmocp_getown(void *data)
679 + return(((struct iic_ibm *)(data))->iic_own);
684 +// Description: Return the clock rate
686 +static int iic_ibmocp_getclock(void *data)
688 + return(((struct iic_ibm *)(data))->iic_clock);
694 +// Description: Put this process to sleep. We will wake up when the
695 +// IIC controller interrupts.
697 +static void iic_ibmocp_waitforpin(void *data) {
700 + struct iic_ibm *priv_data = data;
703 + // If interrupts are enabled (which they are), then put the process to
704 + // sleep. This process will be awakened by two events -- either the
705 + // the IIC peripheral interrupts or the timeout expires.
707 + if (priv_data->iic_irq > 0) {
708 + spin_lock_irq(&irq_driver_lock);
709 + if (iic_pending == 0) {
710 + interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
713 + spin_unlock_irq(&irq_driver_lock);
716 + // If interrupts are not enabled then delay for a reasonable amount
717 + // of time and return. We expect that by time we return to the calling
718 + // function that the IIC has finished our requested transaction and
719 + // the status bit reflects this.
721 + // udelay is probably not the best choice for this since it is
722 + // the equivalent of a busy wait
726 + //printk("iic_ibmocp_waitforpin: exitting\n");
731 +// Description: The registered interrupt handler
733 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs)
736 + struct iic_regs *iic;
737 + struct iic_ibm *priv_data = dev_id;
738 + iic = (struct iic_regs *) priv_data->iic_base;
740 + DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
741 + // Read status register
742 + ret = readb((int) &(iic->sts));
743 + DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
744 + // Clear status register. See IBM PPC 405 reference manual for details
745 + writeb(0x0a, (int) &(iic->sts));
746 + wake_up_interruptible(&(iic_wait[priv_data->index]));
751 +// Description: This function is very hardware dependent. First, we lock
752 +// the region of memory where out registers exist. Next, we request our
753 +// interrupt line and register its associated handler. Our IIC peripheral
754 +// uses interrupt number 2, as specified by the 405 reference manual.
756 +static int iic_hw_resrc_init(int instance)
759 + DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
760 + iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
762 + DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
764 + if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
766 + if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
767 + 0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
768 + printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
769 + iic_ibmocp_adaps[instance]->iic_irq);
770 + iic_ibmocp_adaps[instance]->iic_irq = 0;
772 + DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
780 +// Description: Release irq and memory
782 +static void iic_ibmocp_release(void)
786 + for(i=0; i<IIC_NUMS; i++) {
787 + struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
788 + if (priv_data->iic_irq > 0) {
789 + disable_irq(priv_data->iic_irq);
790 + free_irq(priv_data->iic_irq, 0);
792 + kfree(iic_ibmocp_data[i]);
793 + kfree(iic_ibmocp_ops[i]);
799 +// Description: Called when the module is loaded. This function starts the
800 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
801 +// algorithm layer and into to the core layer)
803 +static int __init iic_ibmocp_init(void)
807 + printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
809 + for(i=0; i<IIC_NUMS; i++) {
810 + iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
811 + if(iic_ibmocp_data[i] == NULL) {
814 + memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
818 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
821 + iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
824 + iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
825 + iic_ibmocp_adaps[i]->iic_own = IIC_OWN;
826 + iic_ibmocp_adaps[i]->index = i;
828 + DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
829 + DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
830 + DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
831 + DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
834 + iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i];
835 + iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
836 + iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
837 + iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
838 + iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
839 + iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
840 + iic_ibmocp_data[i]->udelay = 80;
841 + iic_ibmocp_data[i]->mdelay = 80;
842 + iic_ibmocp_data[i]->timeout = HZ;
844 + iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
845 + if(iic_ibmocp_ops[i] == NULL) {
848 + memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
849 + strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
850 + iic_ibmocp_ops[i]->owner = THIS_MODULE;
851 + iic_ibmocp_ops[i]->id = I2C_HW_OCP;
852 + iic_ibmocp_ops[i]->algo = NULL;
853 + iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
856 + init_waitqueue_head(&(iic_wait[i]));
857 + if (iic_hw_resrc_init(i) == 0) {
858 + if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
863 + DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
869 +static void __exit iic_ibmocp_exit(void)
873 + for(i=0; i<IIC_NUMS; i++) {
874 + i2c_ocp_del_bus(iic_ibmocp_ops[i]);
876 + iic_ibmocp_release();
880 +// If modules is NOT defined when this file is compiled, then the MODULE_*
881 +// macros will resolve to nothing
883 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
884 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
885 +MODULE_LICENSE("GPL");
887 +MODULE_PARM(base, "i");
888 +MODULE_PARM(irq, "i");
889 +MODULE_PARM(clock, "i");
890 +MODULE_PARM(own, "i");
891 +MODULE_PARM(i2c_debug,"i");
894 +module_init(iic_ibmocp_init);
895 +module_exit(iic_ibmocp_exit);
896 --- linux-old/drivers/i2c/i2c-algo-8xx.c Sun Aug 31 14:51:51 CEST 2003
897 +++ linux/drivers/i2c/i2c-algo-8xx.c Sun Aug 31 14:51:51 CEST 2003
900 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
901 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
903 + This program is free software; you can redistribute it and/or modify
904 + it under the terms of the GNU General Public License as published by
905 + the Free Software Foundation; either version 2 of the License, or
906 + (at your option) any later version.
908 + This program is distributed in the hope that it will be useful,
909 + but WITHOUT ANY WARRANTY; without even the implied warranty of
910 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
911 + GNU General Public License for more details.
913 + You should have received a copy of the GNU General Public License
914 + along with this program; if not, write to the Free Software
915 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
917 + * moved into proper i2c interface; separated out platform specific
918 + * parts into i2c-rpx.c
919 + * Brad Parker (brad@heeltoe.com)
927 +#include <linux/kernel.h>
928 +#include <linux/module.h>
929 +#include <linux/delay.h>
930 +#include <linux/slab.h>
931 +#include <linux/init.h>
932 +#include <linux/errno.h>
933 +#include <linux/sched.h>
934 +#include <linux/i2c.h>
935 +#include <linux/i2c-algo-8xx.h>
936 +#include <asm/mpc8xx.h>
937 +#include <asm/commproc.h>
940 +#define CPM_MAX_READ 513
941 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
942 +static wait_queue_head_t iic_wait;
943 +static ushort r_tbase, r_rbase;
948 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
950 + volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
952 + printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
954 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
955 + /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
956 + /* Someone with a buggy CPU needs to confirm that */
957 + i2c->i2c_i2mod &= ~1;
959 + /* Clear interrupt.
961 + i2c->i2c_i2cer = 0xff;
963 + /* Get 'me going again.
965 + wake_up_interruptible(&iic_wait);
969 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
971 + volatile iic_t *iip = cpm->iip;
972 + volatile i2c8xx_t *i2c = cpm->i2c;
974 + bd_t *bd = (bd_t *)__res;
976 + if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
978 + /* Initialize the parameter ram.
979 + * We need to make sure many things are initialized to zero,
980 + * especially in the case of a microcode patch.
982 + iip->iic_rstate = 0;
984 + iip->iic_rbptr = 0;
986 + iip->iic_rxtmp = 0;
987 + iip->iic_tstate = 0;
989 + iip->iic_tbptr = 0;
991 + iip->iic_txtmp = 0;
993 + /* Set up the IIC parameters in the parameter ram.
995 + iip->iic_tbase = r_tbase = cpm->dp_addr;
996 + iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
998 + iip->iic_tfcr = SMC_EB;
999 + iip->iic_rfcr = SMC_EB;
1001 + /* Set maximum receive size.
1003 + iip->iic_mrblr = CPM_MAX_READ;
1005 + /* Initialize Tx/Rx parameters.
1007 + if (cpm->reloc == 0) {
1008 + volatile cpm8xx_t *cp = cpm->cp;
1011 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
1012 + while (cp->cp_cpcr & CPM_CR_FLG);
1014 + iip->iic_rbptr = iip->iic_rbase;
1015 + iip->iic_tbptr = iip->iic_tbase;
1016 + iip->iic_rstate = 0;
1017 + iip->iic_tstate = 0;
1020 + /* Select an arbitrary address. Just make sure it is unique.
1022 + i2c->i2c_i2add = 0xfe;
1024 + /* Make clock run at 60 KHz.
1026 + brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
1027 + i2c->i2c_i2brg = brg;
1029 + i2c->i2c_i2mod = 0x00;
1030 + i2c->i2c_i2com = 0x01; /* Master mode */
1032 + /* Disable interrupts.
1034 + i2c->i2c_i2cmr = 0;
1035 + i2c->i2c_i2cer = 0xff;
1037 + init_waitqueue_head(&iic_wait);
1039 + /* Install interrupt handler.
1042 + printk ("%s[%d] Install ISR for IRQ %d\n",
1043 + __func__,__LINE__, CPMVEC_I2C);
1045 + (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
1050 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
1052 + volatile i2c8xx_t *i2c = cpm->i2c;
1056 + i2c->i2c_i2mod &= ~1;
1057 + i2c->i2c_i2cmr = 0;
1058 + i2c->i2c_i2cer = 0xff;
1064 +cpm_reset_iic_params(volatile iic_t *iip)
1066 + iip->iic_tbase = r_tbase;
1067 + iip->iic_rbase = r_rbase;
1069 + iip->iic_tfcr = SMC_EB;
1070 + iip->iic_rfcr = SMC_EB;
1072 + iip->iic_mrblr = CPM_MAX_READ;
1074 + iip->iic_rstate = 0;
1076 + iip->iic_rbptr = iip->iic_rbase;
1078 + iip->iic_rxtmp = 0;
1079 + iip->iic_tstate = 0;
1081 + iip->iic_tbptr = iip->iic_tbase;
1083 + iip->iic_txtmp = 0;
1086 +#define BD_SC_NAK ((ushort)0x0004) /* NAK - did not respond */
1087 +#define BD_SC_OV ((ushort)0x0002) /* OV - receive overrun */
1088 +#define CPM_CR_CLOSE_RXBD ((ushort)0x0007)
1090 +static void force_close(struct i2c_algo_8xx_data *cpm)
1092 + volatile i2c8xx_t *i2c = cpm->i2c;
1093 + if (cpm->reloc == 0) { /* micro code disabled */
1094 + volatile cpm8xx_t *cp = cpm->cp;
1096 + if (cpm_debug) printk("force_close()\n");
1098 + mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
1101 + while (cp->cp_cpcr & CPM_CR_FLG);
1103 + i2c->i2c_i2cmr = 0x00; /* Disable all interrupts */
1104 + i2c->i2c_i2cer = 0xff;
1108 +/* Read from IIC...
1109 + * abyte = address byte, with r/w flag already set
1112 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
1114 + volatile iic_t *iip = cpm->iip;
1115 + volatile i2c8xx_t *i2c = cpm->i2c;
1116 + volatile cpm8xx_t *cp = cpm->cp;
1117 + volatile cbd_t *tbdf, *rbdf;
1119 + unsigned long flags, tmo;
1121 + if (count >= CPM_MAX_READ)
1124 + /* check for and use a microcode relocation patch */
1126 + cpm_reset_iic_params(iip);
1129 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1130 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1132 + /* To read, we need an empty buffer of the proper length.
1133 + * All that is used is the first byte for address, the remainder
1134 + * is just used for timing (and doesn't really have to exist).
1137 + tb = (u_char *)(((uint)tb + 15) & ~15);
1138 + tb[0] = abyte; /* Device address byte w/rw flag */
1140 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1142 + if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
1144 + tbdf->cbd_bufaddr = __pa(tb);
1145 + tbdf->cbd_datlen = count + 1;
1147 + BD_SC_READY | BD_SC_LAST |
1148 + BD_SC_WRAP | BD_IIC_START;
1150 + iip->iic_mrblr = count +1; /* prevent excessive read, +1
1151 + is needed otherwise will the
1152 + RXB interrupt come too early */
1154 + /* flush will invalidate too. */
1155 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1157 + rbdf->cbd_datlen = 0;
1158 + rbdf->cbd_bufaddr = __pa(buf);
1159 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
1161 + /* Chip bug, set enable here */
1162 + local_irq_save(flags);
1163 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1164 + i2c->i2c_i2cer = 0xff;
1165 + i2c->i2c_i2mod |= 1; /* Enable */
1166 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1168 + /* Wait for IIC transfer */
1169 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1170 + local_irq_restore(flags);
1171 + } else { /* busy wait for small transfers, its faster */
1172 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1173 + i2c->i2c_i2cer = 0xff;
1174 + i2c->i2c_i2mod |= 1; /* Enable */
1175 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1176 + tmo = jiffies + 1*HZ;
1177 + while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1180 + if (signal_pending(current) || !tmo){
1183 + printk("IIC read: timeout!\n");
1186 +#ifdef I2C_CHIP_ERRATA
1187 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1188 + Disabling I2C too early may cause too short stop condition */
1190 + i2c->i2c_i2mod &= ~1;
1193 + printk("tx sc %04x, rx sc %04x\n",
1194 + tbdf->cbd_sc, rbdf->cbd_sc);
1197 + if (tbdf->cbd_sc & BD_SC_READY) {
1198 + printk("IIC read; complete but tbuf ready\n");
1200 + printk("tx sc %04x, rx sc %04x\n",
1201 + tbdf->cbd_sc, rbdf->cbd_sc);
1204 + if (tbdf->cbd_sc & BD_SC_NAK) {
1206 + printk("IIC read; no ack\n");
1207 + return -EREMOTEIO;
1210 + if (rbdf->cbd_sc & BD_SC_EMPTY) {
1211 + /* force_close(cpm); */
1213 + printk("IIC read; complete but rbuf empty\n");
1214 + printk("tx sc %04x, rx sc %04x\n",
1215 + tbdf->cbd_sc, rbdf->cbd_sc);
1217 + return -EREMOTEIO;
1220 + if (rbdf->cbd_sc & BD_SC_OV) {
1222 + printk("IIC read; Overrun\n");
1223 + return -EREMOTEIO;;
1226 + if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
1228 + if (rbdf->cbd_datlen < count) {
1230 + printk("IIC read; short, wanted %d got %d\n",
1231 + count, rbdf->cbd_datlen);
1239 + * addr = address byte, with r/w flag already set
1242 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
1244 + volatile iic_t *iip = cpm->iip;
1245 + volatile i2c8xx_t *i2c = cpm->i2c;
1246 + volatile cpm8xx_t *cp = cpm->cp;
1247 + volatile cbd_t *tbdf;
1249 + unsigned long flags, tmo;
1251 + /* check for and use a microcode relocation patch */
1253 + cpm_reset_iic_params(iip);
1256 + tb = (u_char *)(((uint)tb + 15) & ~15);
1257 + *tb = abyte; /* Device address byte w/rw flag */
1259 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1260 + flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1262 + if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1264 + /* set up 2 descriptors */
1265 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1267 + tbdf[0].cbd_bufaddr = __pa(tb);
1268 + tbdf[0].cbd_datlen = 1;
1269 + tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1271 + tbdf[1].cbd_bufaddr = __pa(buf);
1272 + tbdf[1].cbd_datlen = count;
1273 + tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1276 + /* Chip bug, set enable here */
1277 + local_irq_save(flags);
1278 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1279 + i2c->i2c_i2cer = 0xff;
1280 + i2c->i2c_i2mod |= 1; /* Enable */
1281 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1283 + /* Wait for IIC transfer */
1284 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1285 + local_irq_restore(flags);
1286 + } else { /* busy wait for small transfers, its faster */
1287 + i2c->i2c_i2cmr = 0x00; /* Disable I2C interupts */
1288 + i2c->i2c_i2cer = 0xff;
1289 + i2c->i2c_i2mod |= 1; /* Enable */
1290 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1291 + tmo = jiffies + 1*HZ;
1292 + while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1295 + if (signal_pending(current) || !tmo){
1297 + if(cpm_debug && !tmo)
1298 + printk("IIC write: timeout!\n");
1302 +#if I2C_CHIP_ERRATA
1303 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1304 + Disabling I2C too early may cause too short stop condition */
1306 + i2c->i2c_i2mod &= ~1;
1309 + printk("tx0 sc %04x, tx1 sc %04x\n",
1310 + tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1313 + if (tbdf->cbd_sc & BD_SC_NAK) {
1315 + printk("IIC write; no ack\n");
1319 + if (tbdf->cbd_sc & BD_SC_READY) {
1321 + printk("IIC write; complete but tbuf ready\n");
1328 +/* See if an IIC address exists..
1329 + * addr = 7 bit address, unshifted
1332 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1334 + volatile iic_t *iip = cpm->iip;
1335 + volatile i2c8xx_t *i2c = cpm->i2c;
1336 + volatile cpm8xx_t *cp = cpm->cp;
1337 + volatile cbd_t *tbdf, *rbdf;
1339 + unsigned long flags, len, tmo;
1341 + if (cpm_debug > 1)
1342 + printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1344 + /* check for and use a microcode relocation patch */
1346 + cpm_reset_iic_params(iip);
1349 + if (cpm_debug && addr == 0) {
1350 + printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1351 + printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1354 + tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1355 + rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1358 + tb = (u_char *)(((uint)tb + 15) & ~15);
1360 + /* do a simple read */
1361 + tb[0] = (addr << 1) | 1; /* device address (+ read) */
1364 + flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1366 + tbdf->cbd_bufaddr = __pa(tb);
1367 + tbdf->cbd_datlen = len;
1369 + BD_SC_READY | BD_SC_LAST |
1370 + BD_SC_WRAP | BD_IIC_START;
1372 + rbdf->cbd_datlen = 0;
1373 + rbdf->cbd_bufaddr = __pa(tb+2);
1374 + rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1376 + local_irq_save(flags);
1377 + i2c->i2c_i2cmr = 0x13; /* Enable some interupts */
1378 + i2c->i2c_i2cer = 0xff;
1379 + i2c->i2c_i2mod |= 1; /* Enable */
1380 + i2c->i2c_i2com |= 0x80; /* Begin transmission */
1382 + if (cpm_debug > 1) printk("about to sleep\n");
1384 + /* wait for IIC transfer */
1385 + tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1386 + local_irq_restore(flags);
1388 +#ifdef I2C_CHIP_ERRATA
1389 + /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1390 + Disabling I2C too early may cause too short stop condition */
1392 + i2c->i2c_i2mod &= ~1;
1395 + if (signal_pending(current) || !tmo){
1397 + if(cpm_debug && !tmo)
1398 + printk("IIC tryaddress: timeout!\n");
1402 + if (cpm_debug > 1) printk("back from sleep\n");
1404 + if (tbdf->cbd_sc & BD_SC_NAK) {
1405 + if (cpm_debug > 1) printk("IIC try; no ack\n");
1409 + if (tbdf->cbd_sc & BD_SC_READY) {
1410 + printk("IIC try; complete but tbuf ready\n");
1416 +static int cpm_xfer(struct i2c_adapter *adap,
1417 + struct i2c_msg msgs[],
1420 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1421 + struct i2c_msg *pmsg;
1425 + for (i = 0; i < num; i++) {
1429 + printk("i2c-algo-8xx.o: "
1430 + "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1431 + i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1433 + addr = pmsg->addr << 1;
1434 + if (pmsg->flags & I2C_M_RD )
1436 + if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1439 + if (!(pmsg->flags & I2C_M_NOSTART)) {
1441 + if (pmsg->flags & I2C_M_RD ) {
1442 + /* read bytes into buffer*/
1443 + ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1445 + printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1446 + if (ret < pmsg->len ) {
1447 + return (ret<0)? ret : -EREMOTEIO;
1450 + /* write bytes from buffer */
1451 + ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1453 + printk("i2c-algo-8xx.o: wrote %d\n", ret);
1454 + if (ret < pmsg->len ) {
1455 + return (ret<0) ? ret : -EREMOTEIO;
1462 +static u32 cpm_func(struct i2c_adapter *adap)
1464 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1465 + I2C_FUNC_PROTOCOL_MANGLING;
1468 +/* -----exported algorithm data: ------------------------------------- */
1470 +static struct i2c_algorithm cpm_algo = {
1471 + .owner = THIS_MODULE,
1472 + .name = "MPC8xx CPM algorithm",
1473 + .id = I2C_ALGO_MPC8XX,
1474 + .master_xfer = cpm_xfer,
1475 + .functionality = cpm_func,
1479 + * registering functions to load algorithms at runtime
1481 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1484 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1487 + printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1490 + /* register new adapter to i2c module... */
1492 + adap->id |= cpm_algo.id;
1493 + adap->algo = &cpm_algo;
1495 + i2c_add_adapter(adap);
1496 + cpm_iic_init(cpm);
1500 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1502 + struct i2c_algo_8xx_data *cpm = adap->algo_data;
1504 + cpm_iic_shutdown(cpm);
1506 + return i2c_del_adapter(adap);
1509 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1510 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1512 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1513 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1514 +MODULE_LICENSE("GPL");
1515 --- linux-old/include/linux/i2c-algo-8xx.h Sun Aug 31 14:51:51 CEST 2003
1516 +++ linux/include/linux/i2c-algo-8xx.h Sun Aug 31 14:51:51 CEST 2003
1518 +/* ------------------------------------------------------------------------- */
1519 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM */
1521 + This program is free software; you can redistribute it and/or modify
1522 + it under the terms of the GNU General Public License as published by
1523 + the Free Software Foundation; either version 2 of the License, or
1524 + (at your option) any later version.
1526 + This program is distributed in the hope that it will be useful,
1527 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1528 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1529 + GNU General Public License for more details.
1531 + You should have received a copy of the GNU General Public License
1532 + along with this program; if not, write to the Free Software
1533 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
1534 +/* ------------------------------------------------------------------------- */
1538 +#ifndef _LINUX_I2C_ALGO_8XX_H
1539 +#define _LINUX_I2C_ALGO_8XX_H
1541 +#include "asm/commproc.h"
1543 +struct i2c_algo_8xx_data {
1546 + volatile i2c8xx_t *i2c;
1547 + volatile iic_t *iip;
1548 + volatile cpm8xx_t *cp;
1550 + int (*setisr) (int irq,
1551 + void (*func)(void *, void *),
1557 +int i2c_8xx_add_bus(struct i2c_adapter *);
1558 +int i2c_8xx_del_bus(struct i2c_adapter *);
1560 +#endif /* _LINUX_I2C_ALGO_8XX_H */
1561 --- linux-old/drivers/i2c/i2c-algo-bit.c Sun Aug 31 14:51:52 CEST 2003
1562 +++ linux/drivers/i2c/i2c-algo-bit.c Sun Aug 31 14:51:52 CEST 2003
1564 Frodo Looijaard <frodol@dds.nl> */
1569 #include <linux/kernel.h>
1571 #include <linux/delay.h>
1572 #include <linux/slab.h>
1573 -#include <linux/version.h>
1574 #include <linux/init.h>
1575 -#include <asm/uaccess.h>
1576 -#include <linux/ioport.h>
1577 #include <linux/errno.h>
1578 #include <linux/sched.h>
1580 #include <linux/i2c.h>
1581 #include <linux/i2c-algo-bit.h>
1584 /* ----- global defines ----------------------------------------------- */
1585 #define DEB(x) if (i2c_debug>=1) x;
1587 /* debug the protocol by showing transferred bits */
1589 -/* debugging - slow down transfer to have a look at the data .. */
1590 -/* I use this with two leds&resistors, each one connected to sda,scl */
1591 -/* respectively. This makes sure that the algorithm works. Some chips */
1592 -/* might not like this, as they have an internal timeout of some mils */
1594 -#define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1595 - if (need_resched) schedule();
1599 /* ----- global variables --------------------------------------------- */
1605 /* module parameters:
1607 static int i2c_debug;
1608 static int bit_test; /* see if the line-setting functions work */
1609 -static int bit_scan; /* have a look at what's hanging 'round */
1611 /* --- setting states on the bus with the right timing: --------------- */
1614 udelay(adap->udelay);
1620 @@ -101,15 +81,14 @@
1621 static inline int sclhi(struct i2c_algo_bit_data *adap)
1623 - int start=jiffies;
1628 - udelay(adap->udelay);
1630 /* Not all adapters have scl sense line... */
1631 if (adap->getscl == NULL )
1634 - while (! getscl(adap) ) {
1636 + while (! getscl(adap) ) {
1637 /* the hw knows how to read the clock line,
1638 * so we wait until it actually gets high.
1639 @@ -117,15 +96,16 @@
1640 * while they are processing data internally.
1643 if (time_after_eq(jiffies, start+adap->timeout)) {
1646 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1647 if (current->need_resched)
1650 - DEBSTAT(printk("needed %ld jiffies\n", jiffies-start));
1657 + DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1658 + udelay(adap->udelay);
1662 DEBPROTO(printk(" Sr "));
1666 udelay(adap->udelay);
1668 @@ -180,12 +160,12 @@
1670 /* assert: scl is low */
1671 - DEB2(printk(" i2c_outb:%2.2X\n",c&0xff));
1672 for ( i=7 ; i>=0 ; i-- ) {
1673 sb = c & ( 1 << i );
1675 udelay(adap->udelay);
1676 - DEBPROTO(printk("%d",sb!=0));
1677 + DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1678 if (sclhi(adap)<0) { /* timed out */
1679 sdahi(adap); /* we don't want to block the net */
1680 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1683 @@ -198,12 +178,13 @@
1685 if (sclhi(adap)<0){ /* timeout */
1686 - return -ETIMEDOUT;
1687 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1688 + return -ETIMEDOUT;
1690 /* read ack: SDA should be pulled down by slave */
1691 ack=getsda(adap); /* ack: sda is pulled low ->success. */
1692 - DEB2(printk(" i2c_outb: getsda() = 0x%2.2x\n", ~ack ));
1693 + DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1695 - DEBPROTO( printk("[%2.2x]",c&0xff) );
1696 - DEBPROTO(if (0==ack){ printk(" A ");} else printk(" NA ") );
1697 + DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1698 + DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1700 return 0==ack; /* return 1 if device acked */
1703 /* assert: scl is low */
1704 - DEB2(printk("i2c_inb.\n"));
1708 if (sclhi(adap)<0) { /* timeout */
1709 + DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1714 /* assert: scl is low */
1715 - DEBPROTO(printk(" %2.2x", indata & 0xff));
1716 + DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1718 + DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1719 return (int) (indata & 0xff);
1721 @@ -246,67 +228,67 @@
1723 if (adap->getscl==NULL) {
1724 - printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1725 + printk(KERN_WARNING "i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1729 - printk("i2c-algo-bit.o: Adapter: %s scl: %d sda: %d -- testing...\n",
1730 + printk(KERN_INFO "i2c-algo-bit.o: Adapter: %s scl: %d sda: %d -- testing...\n",
1731 name,getscl(adap),getsda(adap));
1732 if (!scl || !sda ) {
1733 - printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1734 + printk(KERN_INFO " i2c-algo-bit.o: %s seems to be busy.\n",name);
1738 - printk("i2c-algo-bit.o:1 scl: %d sda: %d \n",getscl(adap),
1739 + printk(KERN_DEBUG "i2c-algo-bit.o:1 scl: %d sda: %d \n",getscl(adap),
1741 if ( 0 != getsda(adap) ) {
1742 - printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1743 + printk(KERN_WARNING "i2c-algo-bit.o: %s SDA stuck high!\n",name);
1747 if ( 0 == getscl(adap) ) {
1748 - printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1749 + printk(KERN_WARNING "i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1754 - printk("i2c-algo-bit.o:2 scl: %d sda: %d \n",getscl(adap),
1755 + printk(KERN_DEBUG "i2c-algo-bit.o:2 scl: %d sda: %d \n",getscl(adap),
1757 if ( 0 == getsda(adap) ) {
1758 - printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1759 + printk(KERN_WARNING "i2c-algo-bit.o: %s SDA stuck low!\n",name);
1763 if ( 0 == getscl(adap) ) {
1764 - printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1765 + printk(KERN_WARNING "i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1770 - printk("i2c-algo-bit.o:3 scl: %d sda: %d \n",getscl(adap),
1771 + printk(KERN_DEBUG "i2c-algo-bit.o:3 scl: %d sda: %d \n",getscl(adap),
1773 if ( 0 != getscl(adap) ) {
1774 - printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1775 + printk(KERN_WARNING "i2c-algo-bit.o: %s SCL stuck high!\n",name);
1779 if ( 0 == getsda(adap) ) {
1780 - printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1781 + printk(KERN_WARNING "i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1786 - printk("i2c-algo-bit.o:4 scl: %d sda: %d \n",getscl(adap),
1787 + printk(KERN_DEBUG "i2c-algo-bit.o:4 scl: %d sda: %d \n",getscl(adap),
1789 if ( 0 == getscl(adap) ) {
1790 - printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
1791 + printk(KERN_WARNING "i2c-algo-bit.o: %s SCL stuck low!\n",name);
1795 if ( 0 == getsda(adap) ) {
1796 - printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
1797 + printk(KERN_WARNING "i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
1801 - printk("i2c-algo-bit.o: %s passed test.\n",name);
1802 + printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
1805 @@ -342,14 +324,19 @@
1806 udelay(adap->udelay);
1808 - DEB2(if (i) printk("i2c-algo-bit.o: needed %d retries for %d\n",
1811 + printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
1812 + i+1, addr & 1 ? "read" : "write", addr>>1,
1813 + ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
1818 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
1819 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1821 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1823 - const char *temp = buf;
1824 + const char *temp = msg->buf;
1825 + int count = msg->len;
1826 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1829 @@ -357,13 +344,13 @@
1832 - DEB2(printk("i2c-algo-bit.o: %s i2c_write: writing %2.2X\n",
1833 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
1834 i2c_adap->name, c&0xff));
1835 retval = i2c_outb(i2c_adap,c);
1837 + if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
1841 } else { /* arbitration or no acknowledge */
1842 - printk("i2c-algo-bit.o: %s i2c_write: error - bailout.\n",
1843 + printk(KERN_ERR "i2c-algo-bit.o: %s sendbytes: error - bailout.\n",
1846 @@ -379,10 +366,11 @@
1849 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
1850 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1854 int rdcount=0; /* counts bytes read */
1855 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1856 + char *temp = msg->buf;
1857 + int count = msg->len;
1862 } else { /* read timed out */
1863 - printk("i2c-algo-bit.o: i2c_read: i2c_inb timed out.\n");
1864 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n");
1868 if (sclhi(adap)<0) { /* timeout */
1870 - printk("i2c-algo-bit.o: i2c_read: Timeout at ack\n");
1871 + printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n");
1874 @@ -421,31 +409,34 @@
1875 * reads, writes as well as 10bit-addresses.
1877 - * 0 everything went okay, the chip ack'ed
1878 + * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
1879 * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
1880 * -ETIMEDOUT, for example if the lines are stuck...)
1882 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
1883 - struct i2c_msg *msg, int retries)
1884 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
1886 unsigned short flags = msg->flags;
1887 + unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
1888 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1894 + retries = nak_ok ? 0 : i2c_adap->retries;
1896 if ( (flags & I2C_M_TEN) ) {
1897 /* a ten bit address */
1898 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
1899 - DEB2(printk("addr0: %d\n",addr));
1900 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
1901 /* try extended address code...*/
1902 ret = try_address(i2c_adap, addr, retries);
1904 - printk("died at extended address code.\n");
1905 + if ((ret != 1) && !nak_ok) {
1906 + printk(KERN_ERR "died at extended address code.\n");
1909 /* the remaining 8 bit address */
1910 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
1912 + if ((ret != 1) && !nak_ok) {
1913 /* the chip did not ack / xmission error occurred */
1914 - printk("died at 2nd address code.\n");
1915 + printk(KERN_ERR "died at 2nd address code.\n");
1920 ret = try_address(i2c_adap, addr, retries);
1922 - printk("died at extended address code.\n");
1923 + if ((ret!=1) && !nak_ok) {
1924 + printk(KERN_ERR "died at extended address code.\n");
1929 ret = try_address(i2c_adap, addr, retries);
1931 + if ((ret!=1) && !nak_ok)
1938 @@ -481,23 +472,25 @@
1941 + unsigned short nak_ok;
1944 for (i=0;i<num;i++) {
1946 + nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
1947 if (!(pmsg->flags & I2C_M_NOSTART)) {
1951 - ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
1953 - DEB2(printk("i2c-algo-bit.o: NAK from device adr %#2x msg #%d\n"
1954 - ,msgs[i].addr,i));
1955 - return (ret<0) ? ret : -EREMOTEIO;
1956 + ret = bit_doAddress(i2c_adap, pmsg);
1957 + if ((ret != 0) && !nak_ok) {
1958 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n"
1959 + ,msgs[i].addr,i));
1960 + return (ret<0) ? ret : -EREMOTEIO;
1963 if (pmsg->flags & I2C_M_RD ) {
1964 /* read bytes into buffer*/
1965 - ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
1966 - DEB2(printk("i2c-algo-bit.o: read %d bytes.\n",ret));
1967 + ret = readbytes(i2c_adap, pmsg);
1968 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
1969 if (ret < pmsg->len ) {
1970 return (ret<0)? ret : -EREMOTEIO;
1973 /* write bytes from buffer */
1974 - ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
1975 - DEB2(printk("i2c-algo-bit.o: wrote %d bytes.\n",ret));
1976 + ret = sendbytes(i2c_adap, pmsg);
1977 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
1978 if (ret < pmsg->len ) {
1979 return (ret<0) ? ret : -EREMOTEIO;
1980 @@ -516,11 +509,5 @@
1983 -static int algo_control(struct i2c_adapter *adapter,
1984 - unsigned int cmd, unsigned long arg)
1989 -static u32 bit_func(struct i2c_adapter *adap)
1990 +static u32 bit_func(struct i2c_adapter *i2c_adap)
1992 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
1993 @@ -532,12 +519,9 @@
1995 static struct i2c_algorithm i2c_bit_algo = {
1996 - "Bit-shift algorithm",
2000 - NULL, /* slave_xmit */
2001 - NULL, /* slave_recv */
2002 - algo_control, /* ioctl */
2003 - bit_func, /* functionality */
2004 + .owner = THIS_MODULE,
2005 + .name = "Bit-shift algorithm",
2006 + .id = I2C_ALGO_BIT,
2007 + .master_xfer = bit_xfer,
2008 + .functionality = bit_func,
2012 int i2c_bit_add_bus(struct i2c_adapter *adap)
2015 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
2020 - DEB2(printk("i2c-algo-bit.o: hw routines for %s registered.\n",
2021 + DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: hw routines for %s registered.\n",
2024 @@ -567,26 +550,5 @@
2025 adap->retries = 3; /* be replaced by defines */
2030 - printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
2032 - for (i = 0x00; i < 0xff; i+=2) {
2033 - i2c_start(bit_adap);
2034 - ack = i2c_outb(adap,i);
2035 - i2c_stop(bit_adap);
2037 - printk("(%02x)",i>>1);
2045 - MOD_INC_USE_COUNT;
2047 i2c_add_adapter(adap);
2051 @@ -595,29 +557,10 @@
2052 int i2c_bit_del_bus(struct i2c_adapter *adap)
2056 - if ((res = i2c_del_adapter(adap)) < 0)
2059 - DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
2062 - MOD_DEC_USE_COUNT;
2067 -int __init i2c_algo_bit_init (void)
2069 - printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
2071 + return i2c_del_adapter(adap);
2076 EXPORT_SYMBOL(i2c_bit_add_bus);
2077 EXPORT_SYMBOL(i2c_bit_del_bus);
2080 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
2081 MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
2082 @@ -625,19 +568,7 @@
2084 MODULE_PARM(bit_test, "i");
2085 -MODULE_PARM(bit_scan, "i");
2086 MODULE_PARM(i2c_debug,"i");
2088 MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
2089 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
2090 MODULE_PARM_DESC(i2c_debug,
2091 - "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2093 -int init_module(void)
2095 - return i2c_algo_bit_init();
2098 -void cleanup_module(void)
2102 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2103 --- linux-old/include/linux/i2c-algo-bit.h Sun Aug 31 14:51:52 CEST 2003
2104 +++ linux/include/linux/i2c-algo-bit.h Sun Aug 31 14:51:52 CEST 2003
2106 Frodo Looijaard <frodol@dds.nl> */
2111 -#ifndef I2C_ALGO_BIT_H
2112 -#define I2C_ALGO_BIT_H 1
2114 -#include <linux/i2c.h>
2115 +#ifndef _LINUX_I2C_ALGO_BIT_H
2116 +#define _LINUX_I2C_ALGO_BIT_H
2118 /* --- Defines for bit-adapters --------------------------------------- */
2121 /* local settings */
2125 + int udelay; /* half-clock-cycle time in microsecs */
2126 + /* i.e. clock is (500 / udelay) KHz */
2127 + int mdelay; /* in millisecs, unused */
2128 + int timeout; /* in jiffies */
2132 int i2c_bit_del_bus(struct i2c_adapter *);
2134 -#endif /* I2C_ALGO_BIT_H */
2135 +#endif /* _LINUX_I2C_ALGO_BIT_H */
2136 --- linux-old/drivers/i2c/i2c-algo-ibm_ocp.c Sun Aug 31 14:51:52 CEST 2003
2137 +++ linux/drivers/i2c/i2c-algo-ibm_ocp.c Sun Aug 31 14:51:52 CEST 2003
2140 + -------------------------------------------------------------------------
2141 + i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters
2142 + -------------------------------------------------------------------------
2144 + Ian DaSilva, MontaVista Software, Inc.
2145 + idasilva@mvista.com or source@mvista.com
2147 + Copyright 2000 MontaVista Software Inc.
2149 + Changes made to support the IIC peripheral on the IBM PPC 405
2152 + ---------------------------------------------------------------------------
2153 + This file was highly leveraged from i2c-algo-pcf.c, which was created
2154 + by Simon G. Vogl and Hans Berglund:
2157 + Copyright (C) 1995-1997 Simon G. Vogl
2158 + 1998-2000 Hans Berglund
2160 + With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
2161 + Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
2162 + <mbailey@littlefeet-inc.com>
2165 + This program is free software; you can redistribute it and/or modify
2166 + it under the terms of the GNU General Public License as published by
2167 + the Free Software Foundation; either version 2 of the License, or
2168 + (at your option) any later version.
2170 + This program is distributed in the hope that it will be useful,
2171 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2172 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2173 + GNU General Public License for more details.
2175 + You should have received a copy of the GNU General Public License
2176 + along with this program; if not, write to the Free Software
2177 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2178 + ---------------------------------------------------------------------------
2180 + History: 01/20/12 - Armin
2181 + akuster@mvista.com
2182 + ported up to 2.4.16+
2184 + Version 02/03/25 - Armin
2185 + converted to ocp format
2186 + removed commented out or #if 0 code
2187 + added Gérard Basler's fix to iic_combined_transaction() such that it
2188 + returns the number of successfully completed transfers .
2192 +#include <linux/kernel.h>
2193 +#include <linux/module.h>
2194 +#include <linux/delay.h>
2195 +#include <linux/slab.h>
2196 +#include <linux/init.h>
2197 +#include <linux/errno.h>
2198 +#include <linux/sched.h>
2199 +#include <linux/i2c.h>
2200 +#include <linux/i2c-algo-ibm_ocp.h>
2201 +#include <asm/ocp.h>
2204 +/* ----- global defines ----------------------------------------------- */
2205 +#define DEB(x) if (i2c_debug>=1) x
2206 +#define DEB2(x) if (i2c_debug>=2) x
2207 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
2208 +#define DEBPROTO(x) if (i2c_debug>=9) x;
2209 + /* debug the protocol by showing transferred bits */
2210 +#define DEF_TIMEOUT 5
2213 +/* ----- global variables --------------------------------------------- */
2216 +/* module parameters:
2218 +static int i2c_debug=0;
2220 +/* --- setting states on the bus with the right timing: --------------- */
2222 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
2223 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
2225 +#define IICO_I2C_SDAHIGH 0x0780
2226 +#define IICO_I2C_SDALOW 0x0781
2227 +#define IICO_I2C_SCLHIGH 0x0782
2228 +#define IICO_I2C_SCLLOW 0x0783
2229 +#define IICO_I2C_LINEREAD 0x0784
2231 +#define IIC_SINGLE_XFER 0
2232 +#define IIC_COMBINED_XFER 1
2234 +#define IIC_ERR_LOST_ARB -2
2235 +#define IIC_ERR_INCOMPLETE_XFR -3
2236 +#define IIC_ERR_NACK -1
2238 +/* --- other auxiliary functions -------------------------------------- */
2242 +// Description: Puts this process to sleep for a period equal to timeout
2244 +static inline void iic_sleep(unsigned long timeout)
2246 + schedule_timeout( timeout * HZ);
2251 +// Description: This performs the IBM PPC 405 IIC initialization sequence
2252 +// as described in the PPC405GP data book.
2254 +static int iic_init (struct i2c_algo_iic_data *adap)
2256 + struct iic_regs *iic;
2257 + struct iic_ibm *adap_priv_data = adap->data;
2258 + unsigned short retval;
2259 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2261 + /* Clear master low master address */
2262 + iic_outb(adap,iic->lmadr, 0);
2264 + /* Clear high master address */
2265 + iic_outb(adap,iic->hmadr, 0);
2267 + /* Clear low slave address */
2268 + iic_outb(adap,iic->lsadr, 0);
2270 + /* Clear high slave address */
2271 + iic_outb(adap,iic->hsadr, 0);
2273 + /* Clear status */
2274 + iic_outb(adap,iic->sts, 0x0a);
2276 + /* Clear extended status */
2277 + iic_outb(adap,iic->extsts, 0x8f);
2279 + /* Set clock division */
2280 + iic_outb(adap,iic->clkdiv, 0x04);
2282 + retval = iic_inb(adap, iic->clkdiv);
2283 + DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2285 + /* Enable interrupts on Requested Master Transfer Complete */
2286 + iic_outb(adap,iic->intmsk, 0x01);
2288 + /* Clear transfer count */
2289 + iic_outb(adap,iic->xfrcnt, 0x0);
2291 + /* Clear extended control and status */
2292 + iic_outb(adap,iic->xtcntlss, 0xf0);
2294 + /* Set mode control (flush master data buf, enable hold SCL, exit */
2295 + /* unknown state. */
2296 + iic_outb(adap,iic->mdcntl, 0x47);
2298 + /* Clear control register */
2299 + iic_outb(adap,iic->cntl, 0x0);
2301 + DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2307 +// Description: After we issue a transaction on the IIC bus, this function
2308 +// is called. It puts this process to sleep until we get an interrupt from
2309 +// from the controller telling us that the transaction we requested in complete.
2311 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status)
2314 + int timeout = DEF_TIMEOUT;
2316 + struct iic_regs *iic;
2317 + struct iic_ibm *adap_priv_data = adap->data;
2318 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2321 + *status = iic_inb(adap, iic->sts);
2324 + while (timeout-- && (*status & 0x01)) {
2325 + adap->waitforpin(adap->data);
2326 + *status = iic_inb(adap, iic->sts);
2329 + if (timeout <= 0) {
2330 + /* Issue stop signal on the bus, and force an interrupt */
2331 + retval = iic_inb(adap, iic->cntl);
2332 + iic_outb(adap, iic->cntl, retval | 0x80);
2333 + /* Clear status register */
2334 + iic_outb(adap, iic->sts, 0x0a);
2335 + /* Exit unknown bus state */
2336 + retval = iic_inb(adap, iic->mdcntl);
2337 + iic_outb(adap, iic->mdcntl, (retval | 0x02));
2339 + // Check the status of the controller. Does it still see a
2340 + // pending transfer, even though we've tried to stop any
2341 + // ongoing transaction?
2342 + retval = iic_inb(adap, iic->sts);
2343 + retval = retval & 0x01;
2345 + // The iic controller is hosed. It is not responding to any
2346 + // of our commands. We have already tried to force it into
2347 + // a known state, but it has not worked. Our only choice now
2348 + // is a soft reset, which will clear all registers, and force
2349 + // us to re-initialize the controller.
2351 + iic_outb(adap, iic->xtcntlss, 0x01);
2354 + /* Is the pending transfer bit in the sts reg finally cleared? */
2355 + retval = iic_inb(adap, iic->sts);
2356 + retval = retval & 0x01;
2358 + printk(KERN_CRIT "The IIC Controller is hosed. A processor reset is required\n");
2360 + // For some reason, even though the interrupt bit in this
2361 + // register was set during iic_init, it didn't take. We
2362 + // need to set it again. Don't ask me why....this is just what
2363 + // I saw when testing timeouts.
2364 + iic_outb(adap, iic->intmsk, 0x01);
2373 +//------------------------------------
2374 +// Utility functions
2379 +// Description: Look at the status register to see if there was an error
2380 +// in the requested transaction. If there is, look at the extended status
2381 +// register and determine the exact cause.
2383 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2386 + struct iic_regs *iic;
2387 + struct iic_ibm *adap_priv_data = adap->data;
2388 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2391 + ret = iic_inb(adap, iic->sts);
2394 + ret = iic_inb(adap, iic->extsts);
2396 + // Lost arbitration
2397 + *error_code = IIC_ERR_LOST_ARB;
2400 + // Incomplete transfer
2401 + *error_code = IIC_ERR_INCOMPLETE_XFR;
2404 + // Master transfer aborted by a NACK during the transfer of the
2406 + *error_code = IIC_ERR_NACK;
2415 +// Description: This function is called by the upper layers to do the
2416 +// grunt work for a master send transaction
2418 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2419 + int count, int xfer_flag)
2421 + struct iic_regs *iic;
2422 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2423 + struct iic_ibm *adap_priv_data = adap->data;
2424 + int wrcount, status, timeout;
2425 + int loops, remainder, i, j;
2426 + int ret, error_code;
2427 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2430 + if( count == 0 ) return 0;
2432 + loops = count / 4;
2433 + remainder = count % 4;
2435 + if((loops > 1) && (remainder == 0)) {
2436 + for(i=0; i<(loops-1); i++) {
2438 + // Write four bytes to master data buffer
2440 + for(j=0; j<4; j++) {
2441 + iic_outb(adap, iic->mdbuf,
2445 + // Issue command to IICO device to begin transmission
2447 + iic_outb(adap, iic->cntl, 0x35);
2449 + // Wait for transmission to complete. When it does,
2450 + //loop to the top of the for statement and write the
2451 + // next four bytes.
2453 + timeout = wait_for_pin(adap, &status);
2458 + //printk(KERN_ERR "Error: write timeout\n");
2461 + ret = analyze_status(adap, &error_code);
2463 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2464 + // Return the number of bytes transferred
2465 + ret = iic_inb(adap, iic->xfrcnt);
2467 + return (wrcount-4+ret);
2469 + else return error_code;
2473 + else if((loops >= 1) && (remainder > 0)){
2474 + //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2475 + for(i=0; i<loops; i++) {
2477 + // Write four bytes to master data buffer
2479 + for(j=0; j<4; j++) {
2480 + iic_outb(adap, iic->mdbuf,
2484 + // Issue command to IICO device to begin transmission
2486 + iic_outb(adap, iic->cntl, 0x35);
2488 + // Wait for transmission to complete. When it does,
2489 + //loop to the top of the for statement and write the
2490 + // next four bytes.
2492 + timeout = wait_for_pin(adap, &status);
2497 + //printk(KERN_ERR "Error: write timeout\n");
2500 + ret = analyze_status(adap, &error_code);
2502 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2503 + // Return the number of bytes transferred
2504 + ret = iic_inb(adap, iic->xfrcnt);
2506 + return (wrcount-4+ret);
2508 + else return error_code;
2513 + //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2514 + if(remainder == 0) remainder = 4;
2515 + // remainder = remainder - 1;
2517 + // Write the remaining bytes (less than or equal to 4)
2519 + for(i=0; i<remainder; i++) {
2520 + iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2521 + //printk(KERN_DEBUG "iic_sendbytes: data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2523 + //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2525 + if(xfer_flag == IIC_COMBINED_XFER) {
2526 + iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2529 + iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2531 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2532 + timeout = wait_for_pin(adap, &status);
2537 + //printk(KERN_ERR "Error: write timeout\n");
2540 + ret = analyze_status(adap, &error_code);
2542 + if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2543 + // Return the number of bytes transferred
2544 + ret = iic_inb(adap, iic->xfrcnt);
2546 + return (wrcount-4+ret);
2548 + else return error_code;
2550 + DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2556 +// Description: Called by the upper layers to do the grunt work for
2557 +// a master read transaction.
2559 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2561 + struct iic_regs *iic;
2562 + int rdcount=0, i, status, timeout;
2563 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2564 + struct iic_ibm *adap_priv_data = adap->data;
2565 + int loops, remainder, j;
2566 + int ret, error_code;
2567 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2569 + if(count == 0) return 0;
2570 + loops = count / 4;
2571 + remainder = count % 4;
2573 + //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2575 + if((loops > 1) && (remainder == 0)) {
2576 + //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2577 + for(i=0; i<(loops-1); i++) {
2579 + // Issue command to begin master read (4 bytes maximum)
2581 + //printk(KERN_DEBUG "--->Issued read command\n");
2582 + iic_outb(adap, iic->cntl, 0x37);
2584 + // Wait for transmission to complete. When it does,
2585 + // loop to the top of the for statement and write the
2586 + // next four bytes.
2588 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2589 + timeout = wait_for_pin(adap, &status);
2592 + //printk(KERN_ERR "Error: read timed out\n");
2595 + //printk(KERN_DEBUG "--->Got interrupt\n");
2597 + ret = analyze_status(adap, &error_code);
2599 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2602 + return error_code;
2605 + for(j=0; j<4; j++) {
2606 + // Wait for data to shuffle to top of data buffer
2607 + // This value needs to optimized.
2609 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2611 + //printk(KERN_DEBUG "--->Read one byte\n");
2616 + else if((loops >= 1) && (remainder > 0)){
2617 + //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2618 + for(i=0; i<loops; i++) {
2620 + // Issue command to begin master read (4 bytes maximum)
2622 + //printk(KERN_DEBUG "--->Issued read command\n");
2623 + iic_outb(adap, iic->cntl, 0x37);
2625 + // Wait for transmission to complete. When it does,
2626 + // loop to the top of the for statement and write the
2627 + // next four bytes.
2629 + //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2630 + timeout = wait_for_pin(adap, &status);
2633 + //printk(KERN_ERR "Error: read timed out\n");
2636 + //printk(KERN_DEBUG "--->Got interrupt\n");
2638 + ret = analyze_status(adap, &error_code);
2640 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2643 + return error_code;
2646 + for(j=0; j<4; j++) {
2647 + // Wait for data to shuffle to top of data buffer
2648 + // This value needs to optimized.
2650 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2652 + //printk(KERN_DEBUG "--->Read one byte\n");
2657 + //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2658 + if(remainder == 0) remainder = 4;
2659 + DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2661 + if(xfer_type == IIC_COMBINED_XFER) {
2662 + iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2665 + iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2667 + DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2668 + timeout = wait_for_pin(adap, &status);
2669 + DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2672 + //printk(KERN_ERR "Error: read timed out\n");
2676 + ret = analyze_status(adap, &error_code);
2678 + if(error_code == IIC_ERR_INCOMPLETE_XFR)
2681 + return error_code;
2684 + //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2685 + for(i=0; i<remainder; i++) {
2686 + buf[rdcount] = iic_inb(adap, iic->mdbuf);
2687 + // printk(KERN_DEBUG "iic_readbytes: Character read = %x\n", buf[rdcount]);
2696 +// Description: This function implements combined transactions. Combined
2697 +// transactions consist of combinations of reading and writing blocks of data.
2698 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2701 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
2704 + struct i2c_msg *pmsg;
2707 + DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2708 + for(i=0; i < num; i++) {
2710 + if(pmsg->flags & I2C_M_RD) {
2712 + // Last read or write segment needs to be terminated with a stop
2714 + DEB2(printk(KERN_DEBUG "This one is a read\n"));
2717 + DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2719 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2721 + if (ret != pmsg->len) {
2722 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2723 + "only read %d bytes.\n",ret));
2727 + DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2730 + else if(!(pmsg->flags & I2C_M_RD)) {
2732 + // Last read or write segment needs to be terminated with a stop
2734 + DEB2(printk(KERN_DEBUG "This one is a write\n"));
2737 + DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2739 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2741 + if (ret != pmsg->len) {
2742 + DEB2(printk("i2c-algo-ppc405.o: fail: "
2743 + "only wrote %d bytes.\n",ret));
2747 + DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2757 +// Description: Whenever we initiate a transaction, the first byte clocked
2758 +// onto the bus after the start condition is the address (7 bit) of the
2759 +// device we want to talk to. This function manipulates the address specified
2760 +// so that it makes sense to the hardware when written to the IIC peripheral.
2762 +// Note: 10 bit addresses are not supported in this driver, although they are
2763 +// supported by the hardware. This functionality needs to be implemented.
2765 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
2766 + struct i2c_msg *msg, int retries)
2768 + struct iic_regs *iic;
2769 + unsigned short flags = msg->flags;
2770 + unsigned char addr;
2771 + struct iic_ibm *adap_priv_data = adap->data;
2772 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2775 +// The following segment for 10 bit addresses needs to be ported
2777 +/* Ten bit addresses not supported right now
2778 + if ( (flags & I2C_M_TEN) ) {
2779 + // a ten bit address
2780 + addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2781 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2782 + // try extended address code...
2783 + ret = try_address(adap, addr, retries);
2785 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2786 + return -EREMOTEIO;
2788 + // the remaining 8 bit address
2789 + iic_outb(adap,msg->addr & 0x7f);
2790 + // Status check comes here
2792 + printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
2793 + return -EREMOTEIO;
2795 + if ( flags & I2C_M_RD ) {
2796 + i2c_repstart(adap);
2797 + // okay, now switch into reading mode
2799 + ret = try_address(adap, addr, retries);
2801 + printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2802 + return -EREMOTEIO;
2805 + } else ----------> // normal 7 bit address
2807 +Ten bit addresses not supported yet */
2809 + addr = ( msg->addr << 1 );
2810 + if (flags & I2C_M_RD )
2812 + if (flags & I2C_M_REV_DIR_ADDR )
2815 + // Write to the low slave address
2817 + iic_outb(adap, iic->lmadr, addr);
2819 + // Write zero to the high slave register since we are
2820 + // only using 7 bit addresses
2822 + iic_outb(adap, iic->hmadr, 0);
2829 +// Description: Prepares the controller for a transaction (clearing status
2830 +// registers, data buffers, etc), and then calls either iic_readbytes or
2831 +// iic_sendbytes to do the actual transaction.
2833 +static int iic_xfer(struct i2c_adapter *i2c_adap,
2834 + struct i2c_msg msgs[],
2837 + struct iic_regs *iic;
2838 + struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2839 + struct iic_ibm *adap_priv_data = adap->data;
2840 + struct i2c_msg *pmsg;
2843 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2848 + // Clear status register
2850 + DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
2851 + iic_outb(adap, iic->sts, 0x0a);
2854 + // Wait for any pending transfers to complete
2856 + DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
2857 + while((ret = iic_inb(adap, iic->sts)) == 0x01) {
2862 + // Flush master data buf
2864 + DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));
2865 + ret = iic_inb(adap, iic->mdcntl);
2866 + iic_outb(adap, iic->mdcntl, ret | 0x40);
2869 + // Load slave address
2871 + DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
2872 + ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
2875 + // Check to see if the bus is busy
2877 + ret = iic_inb(adap, iic->extsts);
2878 + // Mask off the irrelevent bits
2880 + // When the bus is free, the BCS bits in the EXTSTS register are 0b100
2881 + if(ret != 0x40) return IIC_ERR_LOST_ARB;
2884 + // Combined transaction (read and write)
2887 + DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
2888 + ret = iic_combined_transaction(i2c_adap, msgs, num);
2893 + else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
2895 + // Tell device to begin reading data from the master data
2897 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
2898 + ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2903 + else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
2905 + // Write data to master data buffers and tell our device
2906 + // to begin transmitting
2908 + DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
2909 + ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
2917 +// Description: Implements device specific ioctls. Higher level ioctls can
2918 +// be found in i2c-core.c and are typical of any i2c controller (specifying
2919 +// slave address, timeouts, etc). These ioctls take advantage of any hardware
2920 +// features built into the controller for which this algorithm-adapter set
2921 +// was written. These ioctls allow you to take control of the data and clock
2922 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
2923 +// similar to a GPIO pin.
2925 +static int algo_control(struct i2c_adapter *adapter,
2926 + unsigned int cmd, unsigned long arg)
2928 + struct iic_regs *iic;
2929 + struct i2c_algo_iic_data *adap = adapter->algo_data;
2930 + struct iic_ibm *adap_priv_data = adap->data;
2933 + iic = (struct iic_regs *) adap_priv_data->iic_base;
2935 + lines = iic_inb(adap, iic->directcntl);
2937 + if (cmd == IICO_I2C_SDAHIGH) {
2938 + lines = lines & 0x01;
2939 + if( lines ) lines = 0x04;
2941 + iic_outb(adap, iic->directcntl,(0x08|lines));
2943 + else if (cmd == IICO_I2C_SDALOW) {
2944 + lines = lines & 0x01;
2945 + if( lines ) lines = 0x04;
2947 + iic_outb(adap, iic->directcntl,(0x00|lines));
2949 + else if (cmd == IICO_I2C_SCLHIGH) {
2950 + lines = lines & 0x02;
2951 + if( lines ) lines = 0x08;
2953 + iic_outb(adap, iic->directcntl,(0x04|lines));
2955 + else if (cmd == IICO_I2C_SCLLOW) {
2956 + lines = lines & 0x02;
2957 + if( lines ) lines = 0x08;
2959 + iic_outb(adap, iic->directcntl,(0x00|lines));
2961 + else if (cmd == IICO_I2C_LINEREAD) {
2968 +static u32 iic_func(struct i2c_adapter *adap)
2970 + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
2971 + I2C_FUNC_PROTOCOL_MANGLING;
2975 +/* -----exported algorithm data: ------------------------------------- */
2977 +static struct i2c_algorithm iic_algo = {
2978 + .owner = THIS_MODULE,
2979 + .name = "IBM on-chip IIC algorithm",
2980 + .id = I2C_ALGO_OCP,
2981 + .master_xfer = iic_xfer,
2982 + .algo_control = algo_control,
2983 + .functionality = iic_func,
2987 + * registering functions to load algorithms at runtime
2992 +// Description: Register bus structure
2994 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
2996 + struct i2c_algo_iic_data *iic_adap = adap->algo_data;
2998 + DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
3001 + /* register new adapter to i2c module... */
3003 + adap->id |= iic_algo.id;
3004 + adap->algo = &iic_algo;
3006 + adap->timeout = 100; /* default values, should */
3007 + adap->retries = 3; /* be replaced by defines */
3009 + iic_init(iic_adap);
3010 + i2c_add_adapter(adap);
3018 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
3020 + return i2c_del_adapter(adap);
3024 +EXPORT_SYMBOL(i2c_ocp_add_bus);
3025 +EXPORT_SYMBOL(i2c_ocp_del_bus);
3028 +// The MODULE_* macros resolve to nothing if MODULES is not defined
3029 +// when this file is compiled.
3031 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
3032 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
3033 +MODULE_LICENSE("GPL");
3035 +MODULE_PARM(i2c_debug,"i");
3037 +MODULE_PARM_DESC(i2c_debug,
3038 + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
3040 --- linux-old/include/linux/i2c-algo-ibm_ocp.h Sun Aug 31 14:51:52 CEST 2003
3041 +++ linux/include/linux/i2c-algo-ibm_ocp.h Sun Aug 31 14:51:52 CEST 2003
3043 +/* ------------------------------------------------------------------------- */
3044 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters */
3045 +/* ------------------------------------------------------------------------- */
3046 +/* Copyright (C) 1995-97 Simon G. Vogl
3047 + 1998-99 Hans Berglund
3049 + This program is free software; you can redistribute it and/or modify
3050 + it under the terms of the GNU General Public License as published by
3051 + the Free Software Foundation; either version 2 of the License, or
3052 + (at your option) any later version.
3054 + This program is distributed in the hope that it will be useful,
3055 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3056 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3057 + GNU General Public License for more details.
3059 + You should have received a copy of the GNU General Public License
3060 + along with this program; if not, write to the Free Software
3061 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
3062 +/* ------------------------------------------------------------------------- */
3064 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3065 + Frodo Looijaard <frodol@dds.nl> */
3067 +/* Modifications by MontaVista Software, August 2000
3068 + Changes made to support the IIC peripheral on the IBM PPC 405 */
3070 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
3071 +#define _LINUX_I2C_ALGO_IBM_OCP_H
3073 +struct i2c_algo_iic_data {
3074 + struct iic_regs *data; /* private data for lolevel routines */
3075 + void (*setiic) (void *data, int ctl, int val);
3076 + int (*getiic) (void *data, int ctl);
3077 + int (*getown) (void *data);
3078 + int (*getclock) (void *data);
3079 + void (*waitforpin) (void *data);
3081 + /* local settings */
3088 +#define I2C_IIC_ADAP_MAX 16
3091 +int i2c_ocp_add_bus(struct i2c_adapter *);
3092 +int i2c_ocp_del_bus(struct i2c_adapter *);
3094 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
3095 --- linux-old/drivers/i2c/i2c-algo-pcf.c Sun Aug 31 14:51:53 CEST 2003
3096 +++ linux/drivers/i2c/i2c-algo-pcf.c Sun Aug 31 14:51:53 CEST 2003
3098 #include <linux/delay.h>
3099 #include <linux/slab.h>
3100 -#include <linux/version.h>
3101 #include <linux/init.h>
3102 -#include <asm/uaccess.h>
3103 -#include <linux/ioport.h>
3104 #include <linux/errno.h>
3105 -#include <linux/sched.h>
3107 #include <linux/i2c.h>
3108 #include <linux/i2c-algo-pcf.h>
3109 -#include "i2c-pcf8584.h"
3112 /* ----- global defines ----------------------------------------------- */
3115 static int i2c_debug=0;
3116 -static int pcf_scan=0; /* have a look at what's hanging 'round */
3118 /* --- setting states on the bus with the right timing: --------------- */
3122 - printk("Timeout waiting for Bus Busy\n");
3123 + printk(KERN_ERR "Timeout waiting for Bus Busy\n");
3129 - DEB3(printk("i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3130 + DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3132 /* S1=0x80: S0 selected, serial interface off */
3134 /* check to see S1 now used as R/W ctrl -
3135 PCF8584 does that when ESO is zero */
3136 - /* PCF also resets PIN bit */
3137 - if ((temp = get_pcf(adap, 1)) != (0)) {
3138 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3139 + if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
3140 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3141 return -ENXIO; /* definetly not PCF8584 */
3144 /* check it's realy writen */
3145 if ((temp = i2c_inb(adap)) != get_own(adap)) {
3146 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3147 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3151 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
3152 /* check to see S2 now selected */
3153 - if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
3154 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3155 + if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
3156 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3160 /* check it's realy writen, the only 5 lowest bits does matter */
3161 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
3162 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3163 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3167 /* check to see PCF is realy idled and we can access status register */
3168 if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
3169 - DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3170 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3174 - printk("i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3175 + printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3179 udelay(adap->udelay);
3181 - DEB2(if (i) printk("i2c-algo-pcf.o: needed %d retries for %d\n",i,
3182 + DEB2(if (i) printk(KERN_DEBUG "i2c-algo-pcf.o: needed %d retries for %d\n",i,
3187 for (wrcount=0; wrcount<count; ++wrcount) {
3188 - DEB2(printk("i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3189 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3190 i2c_adap->name, buf[wrcount]&0xff));
3191 i2c_outb(adap, buf[wrcount]);
3195 - printk("i2c-algo-pcf.o: %s i2c_write: "
3196 + printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3197 "error - timeout.\n", i2c_adap->name);
3198 return -EREMOTEIO; /* got a better one ?? */
3200 if (status & I2C_PCF_LRB) {
3202 - printk("i2c-algo-pcf.o: %s i2c_write: "
3203 + printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3204 "error - no ack.\n", i2c_adap->name);
3205 return -EREMOTEIO; /* got a better one ?? */
3207 if (wait_for_pin(adap, &status)) {
3209 - printk("i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3210 + printk(KERN_ERR "i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3214 if ((status & I2C_PCF_LRB) && (i != count)) {
3216 - printk("i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3217 + printk(KERN_ERR "i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3221 /* a ten bit address */
3222 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
3223 - DEB2(printk("addr0: %d\n",addr));
3224 + DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
3225 /* try extended address code...*/
3226 ret = try_address(adap, addr, retries);
3228 - printk("died at extended address code.\n");
3229 + printk(KERN_ERR "died at extended address code.\n");
3233 /* Status check comes here */
3235 - printk("died at 2nd address code.\n");
3236 + printk(KERN_ERR "died at 2nd address code.\n");
3240 ret = try_address(adap, addr, retries);
3242 - printk("died at extended address code.\n");
3243 + printk(KERN_ERR "died at extended address code.\n");
3247 timeout = wait_for_bb(adap);
3249 - DEB2(printk("i2c-algo-pcf.o: "
3250 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
3251 "Timeout waiting for BB in pcf_xfer\n");)
3256 - DEB2(printk("i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3257 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3258 pmsg->flags & I2C_M_RD ? "read" : "write",
3259 pmsg->len, pmsg->addr, i + 1, num);)
3263 - DEB2(printk("i2c-algo-pcf.o: Timeout waiting "
3264 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
3265 "for PIN(1) in pcf_xfer\n");)
3266 return (-EREMOTEIO);
3267 @@ -393,10 +386,10 @@
3268 if (status & I2C_PCF_LRB) {
3270 - DEB2(printk("i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3271 + DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3272 return (-EREMOTEIO);
3276 - DEB3(printk("i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3277 + DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3278 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
3282 if (ret != pmsg->len) {
3283 - DEB2(printk("i2c-algo-pcf.o: fail: "
3284 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3285 "only read %d bytes.\n",ret));
3287 - DEB2(printk("i2c-algo-pcf.o: read %d bytes.\n",ret));
3288 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
3290 } else { /* Write */
3293 if (ret != pmsg->len) {
3294 - DEB2(printk("i2c-algo-pcf.o: fail: "
3295 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3296 "only wrote %d bytes.\n",ret));
3298 - DEB2(printk("i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3299 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3302 @@ -429,10 +422,4 @@
3305 -static int algo_control(struct i2c_adapter *adapter,
3306 - unsigned int cmd, unsigned long arg)
3311 static u32 pcf_func(struct i2c_adapter *adap)
3313 @@ -444,12 +431,9 @@
3315 static struct i2c_algorithm pcf_algo = {
3316 - "PCF8584 algorithm",
3320 - NULL, /* slave_xmit */
3321 - NULL, /* slave_recv */
3322 - algo_control, /* ioctl */
3323 - pcf_func, /* functionality */
3324 + .owner = THIS_MODULE,
3325 + .name = "PCF8584 algorithm",
3326 + .id = I2C_ALGO_PCF,
3327 + .master_xfer = pcf_xfer,
3328 + .functionality = pcf_func,
3332 int i2c_pcf_add_bus(struct i2c_adapter *adap)
3336 struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
3338 - DEB2(printk("i2c-algo-pcf.o: hw routines for %s registered.\n",
3339 + DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
3342 @@ -477,33 +461,5 @@
3346 - MOD_INC_USE_COUNT;
3349 i2c_add_adapter(adap);
3353 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
3355 - for (i = 0x00; i < 0xff; i+=2) {
3356 - if (wait_for_bb(pcf_adap)) {
3357 - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
3361 - i2c_outb(pcf_adap, i);
3362 - i2c_start(pcf_adap);
3363 - if ((wait_for_pin(pcf_adap, &status) >= 0) &&
3364 - ((status & I2C_PCF_LRB) == 0)) {
3365 - printk("(%02x)",i>>1);
3369 - i2c_stop(pcf_adap);
3370 - udelay(pcf_adap->udelay);
3376 @@ -512,45 +468,15 @@
3377 int i2c_pcf_del_bus(struct i2c_adapter *adap)
3380 - if ((res = i2c_del_adapter(adap)) < 0)
3382 - DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
3385 - MOD_DEC_USE_COUNT;
3390 -int __init i2c_algo_pcf_init (void)
3392 - printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
3394 + return i2c_del_adapter(adap);
3398 EXPORT_SYMBOL(i2c_pcf_add_bus);
3399 EXPORT_SYMBOL(i2c_pcf_del_bus);
3402 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
3403 MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
3404 MODULE_LICENSE("GPL");
3406 -MODULE_PARM(pcf_scan, "i");
3407 MODULE_PARM(i2c_debug,"i");
3409 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
3410 MODULE_PARM_DESC(i2c_debug,
3411 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
3414 -int init_module(void)
3416 - return i2c_algo_pcf_init();
3419 -void cleanup_module(void)
3423 --- linux-old/include/linux/i2c-algo-pcf.h Sun Aug 31 14:51:53 CEST 2003
3424 +++ linux/include/linux/i2c-algo-pcf.h Sun Aug 31 14:51:53 CEST 2003
3426 Frodo Looijaard <frodol@dds.nl> */
3431 -#ifndef I2C_ALGO_PCF_H
3432 -#define I2C_ALGO_PCF_H 1
3433 +#ifndef _LINUX_I2C_ALGO_PCF_H
3434 +#define _LINUX_I2C_ALGO_PCF_H
3436 -/* --- Defines for pcf-adapters --------------------------------------- */
3437 -#include <linux/i2c.h>
3438 +#include <linux/i2c-pcf8584.h>
3440 struct i2c_algo_pcf_data {
3442 int i2c_pcf_del_bus(struct i2c_adapter *);
3444 -#endif /* I2C_ALGO_PCF_H */
3445 +#endif /* _LINUX_I2C_ALGO_PCF_H */
3446 --- linux-old/drivers/i2c/i2c-algo-sibyte.c Sun Aug 31 14:51:53 CEST 2003
3447 +++ linux/drivers/i2c/i2c-algo-sibyte.c Sun Aug 31 14:51:53 CEST 2003
3449 -/* ------------------------------------------------------------------------- */
3450 -/* i2c-algo-sibyte.c i2c driver algorithms for bit-shift adapters */
3451 -/* ------------------------------------------------------------------------- */
3452 -/* Copyright (C) 2001,2002,2003 Broadcom Corporation
3453 - Copyright (C) 1995-2000 Simon G. Vogl
3455 - This program is free software; you can redistribute it and/or modify
3456 - it under the terms of the GNU General Public License as published by
3457 - the Free Software Foundation; either version 2 of the License, or
3458 - (at your option) any later version.
3460 - This program is distributed in the hope that it will be useful,
3461 - but WITHOUT ANY WARRANTY; without even the implied warranty of
3462 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3463 - GNU General Public License for more details.
3465 - You should have received a copy of the GNU General Public License
3466 - along with this program; if not, write to the Free Software
3467 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
3468 -/* ------------------------------------------------------------------------- */
3470 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3471 - Frodo Looijaard <frodol@dds.nl>. */
3473 -/* Ported for SiByte SOCs by Broadcom Corporation. */
3475 -#include <linux/config.h>
3476 -#include <linux/kernel.h>
3477 -#include <linux/module.h>
3478 -#include <linux/init.h>
3480 -#include <asm/sibyte/64bit.h>
3481 -#include <asm/sibyte/sb1250_regs.h>
3482 -#include <asm/sibyte/sb1250_smbus.h>
3484 -#include <linux/i2c.h>
3485 -#include <linux/i2c-algo-sibyte.h>
3487 -/* ----- global defines ----------------------------------------------- */
3488 -#define SMB_CSR(a,r) ((long)(a->reg_base + r))
3490 -/* ----- global variables --------------------------------------------- */
3492 -/* module parameters:
3494 -static int bit_scan=0; /* have a look at what's hanging 'round */
3497 -static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
3498 - unsigned short flags, char read_write,
3499 - u8 command, int size, union i2c_smbus_data * data)
3501 - struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
3502 - int data_bytes = 0;
3505 - while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
3509 - case I2C_SMBUS_QUICK:
3510 - csr_out32((V_SMB_ADDR(addr) | (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
3511 - V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
3513 - case I2C_SMBUS_BYTE:
3514 - if (read_write == I2C_SMBUS_READ) {
3515 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
3516 - SMB_CSR(adap, R_SMB_START));
3519 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
3520 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
3521 - SMB_CSR(adap, R_SMB_START));
3524 - case I2C_SMBUS_BYTE_DATA:
3525 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
3526 - if (read_write == I2C_SMBUS_READ) {
3527 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
3528 - SMB_CSR(adap, R_SMB_START));
3531 - csr_out32(V_SMB_LB(data->byte), SMB_CSR(adap, R_SMB_DATA));
3532 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
3533 - SMB_CSR(adap, R_SMB_START));
3536 - case I2C_SMBUS_WORD_DATA:
3537 - csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
3538 - if (read_write == I2C_SMBUS_READ) {
3539 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
3540 - SMB_CSR(adap, R_SMB_START));
3543 - csr_out32(V_SMB_LB(data->word & 0xff), SMB_CSR(adap, R_SMB_DATA));
3544 - csr_out32(V_SMB_MB(data->word >> 8), SMB_CSR(adap, R_SMB_DATA));
3545 - csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
3546 - SMB_CSR(adap, R_SMB_START));
3550 - return -1; /* XXXKW better error code? */
3553 - while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
3556 - error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
3557 - if (error & M_SMB_ERROR) {
3558 - /* Clear error bit by writing a 1 */
3559 - csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
3560 - return -1; /* XXXKW better error code? */
3563 - if (data_bytes == 1)
3564 - data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
3565 - if (data_bytes == 2)
3566 - data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
3571 -static int algo_control(struct i2c_adapter *adapter,
3572 - unsigned int cmd, unsigned long arg)
3577 -static u32 bit_func(struct i2c_adapter *adap)
3579 - return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
3580 - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
3584 -/* -----exported algorithm data: ------------------------------------- */
3586 -static struct i2c_algorithm i2c_sibyte_algo = {
3587 - "SiByte algorithm",
3589 - NULL, /* master_xfer */
3590 - smbus_xfer, /* smbus_xfer */
3591 - NULL, /* slave_xmit */
3592 - NULL, /* slave_recv */
3593 - algo_control, /* ioctl */
3594 - bit_func, /* functionality */
3598 - * registering functions to load algorithms at runtime
3600 -int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
3603 - struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
3605 - /* register new adapter to i2c module... */
3607 - i2c_adap->id |= i2c_sibyte_algo.id;
3608 - i2c_adap->algo = &i2c_sibyte_algo;
3610 - /* Set the frequency to 100 kHz */
3611 - csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
3612 - csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
3616 - union i2c_smbus_data data;
3618 - printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
3620 - for (i = 0x00; i < 0x7f; i++) {
3621 - /* XXXKW is this a realistic probe? */
3622 - rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
3623 - I2C_SMBUS_BYTE_DATA, &data);
3625 - printk("(%02x)",i);
3633 - MOD_INC_USE_COUNT;
3635 - i2c_add_adapter(i2c_adap);
3641 -int i2c_sibyte_del_bus(struct i2c_adapter *adap)
3645 - if ((res = i2c_del_adapter(adap)) < 0)
3649 - MOD_DEC_USE_COUNT;
3654 -int __init i2c_algo_sibyte_init (void)
3656 - printk("i2c-algo-sibyte.o: i2c SiByte algorithm module\n");
3661 -EXPORT_SYMBOL(i2c_sibyte_add_bus);
3662 -EXPORT_SYMBOL(i2c_sibyte_del_bus);
3665 -MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
3666 -MODULE_DESCRIPTION("SiByte I2C-Bus algorithm");
3667 -MODULE_PARM(bit_scan, "i");
3668 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
3669 -MODULE_LICENSE("GPL");
3671 -int init_module(void)
3673 - return i2c_algo_sibyte_init();
3676 -void cleanup_module(void)
3680 --- linux-old/include/linux/i2c-algo-sibyte.h Sun Aug 31 14:51:53 CEST 2003
3681 +++ linux/include/linux/i2c-algo-sibyte.h Sun Aug 31 14:51:53 CEST 2003
3684 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
3686 - * This program is free software; you can redistribute it and/or
3687 - * modify it under the terms of the GNU General Public License
3688 - * as published by the Free Software Foundation; either version 2
3689 - * of the License, or (at your option) any later version.
3691 - * This program is distributed in the hope that it will be useful,
3692 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
3693 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3694 - * GNU General Public License for more details.
3696 - * You should have received a copy of the GNU General Public License
3697 - * along with this program; if not, write to the Free Software
3698 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3701 -#ifndef I2C_ALGO_SIBYTE_H
3702 -#define I2C_ALGO_SIBYTE_H 1
3704 -#include <linux/i2c.h>
3706 -struct i2c_algo_sibyte_data {
3707 - void *data; /* private data */
3708 - int bus; /* which bus */
3709 - void *reg_base; /* CSR base */
3712 -int i2c_sibyte_add_bus(struct i2c_adapter *, int speed);
3713 -int i2c_sibyte_del_bus(struct i2c_adapter *);
3715 -#endif /* I2C_ALGO_SIBYTE_H */
3716 --- linux-old/drivers/i2c/i2c-core.c Sun Aug 31 14:51:54 CEST 2003
3717 +++ linux/drivers/i2c/i2c-core.c Sun Aug 31 14:51:54 CEST 2003
3720 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
3721 - All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
3722 + All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
3723 + SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */
3726 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
3728 #include <linux/module.h>
3730 #include <linux/slab.h>
3731 #include <linux/proc_fs.h>
3732 -#include <linux/config.h>
3734 -#include <linux/i2c.h>
3736 -/* ----- compatibility stuff ----------------------------------------------- */
3738 -#include <linux/version.h>
3739 #include <linux/init.h>
3741 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
3742 -#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
3745 +#include <linux/i2c.h>
3746 #include <asm/uaccess.h>
3748 /* ----- global defines ---------------------------------------------------- */
3750 -/* exclusive access to the bus */
3751 -#define I2C_LOCK(adap) down(&adap->lock)
3752 -#define I2C_UNLOCK(adap) up(&adap->lock)
3754 -#define ADAP_LOCK() down(&adap_lock)
3755 -#define ADAP_UNLOCK() up(&adap_lock)
3757 -#define DRV_LOCK() down(&driver_lock)
3758 -#define DRV_UNLOCK() up(&driver_lock)
3760 #define DEB(x) if (i2c_debug>=1) x;
3761 #define DEB2(x) if (i2c_debug>=2) x;
3763 /* ----- global variables -------------------------------------------------- */
3765 -/**** lock for writing to global variables: the adapter & driver list */
3766 -struct semaphore adap_lock;
3767 -struct semaphore driver_lock;
3769 -/**** adapter list */
3770 +DECLARE_MUTEX(core_lists);
3771 static struct i2c_adapter *adapters[I2C_ADAP_MAX];
3772 -static int adap_count;
3774 -/**** drivers list */
3775 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
3776 -static int driver_count;
3778 /**** debug level */
3779 -static int i2c_debug=1;
3780 +static int i2c_debug;
3782 /* ---------------------------------------------------
3785 #ifdef CONFIG_PROC_FS
3787 -static int i2cproc_init(void);
3788 -static int i2cproc_cleanup(void);
3790 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
3791 -static void monitor_bus_i2c(struct inode *inode, int fill);
3792 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3794 static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count,
3797 implementation of the read hook */
3798 static struct file_operations i2cproc_operations = {
3799 - read: i2cproc_bus_read,
3800 + .read = i2cproc_bus_read,
3803 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
3804 -static struct inode_operations i2cproc_inode_operations = {
3805 - &i2cproc_operations
3809 -static int i2cproc_initialized = 0;
3811 -#else /* undef CONFIG_PROC_FS */
3813 -#define i2cproc_init() 0
3814 -#define i2cproc_cleanup() 0
3815 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3816 +static void i2cproc_remove(int bus);
3818 #endif /* CONFIG_PROC_FS */
3820 int i2c_add_adapter(struct i2c_adapter *adap)
3826 + down(&core_lists);
3827 for (i = 0; i < I2C_ADAP_MAX; i++)
3828 if (NULL == adapters[i])
3829 @@ -141,45 +95,18 @@
3833 +#ifdef CONFIG_PROC_FS
3834 + res = i2cproc_register(adap, i);
3837 +#endif /* def CONFIG_PROC_FS */
3843 /* init data types */
3844 - init_MUTEX(&adap->lock);
3846 -#ifdef CONFIG_PROC_FS
3848 - if (i2cproc_initialized) {
3850 - struct proc_dir_entry *proc_entry;
3852 - sprintf(name,"i2c-%d", i);
3854 - proc_entry = create_proc_entry(name,0,proc_bus);
3855 - if (! proc_entry) {
3856 - printk("i2c-core.o: Could not create /proc/bus/%s\n",
3862 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,48))
3863 - proc_entry->proc_fops = &i2cproc_operations;
3865 - proc_entry->ops = &i2cproc_inode_operations;
3867 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
3868 - proc_entry->owner = THIS_MODULE;
3870 - proc_entry->fill_inode = &monitor_bus_i2c;
3871 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3872 - adap->inode = proc_entry->low_ino;
3875 -#endif /* def CONFIG_PROC_FS */
3876 + init_MUTEX(&adap->bus);
3877 + init_MUTEX(&adap->list);
3879 /* inform drivers of new adapters */
3881 for (j=0;j<I2C_DRIVER_MAX;j++)
3882 if (drivers[j]!=NULL &&
3883 @@ -187,18 +114,9 @@
3884 /* We ignore the return code; if it fails, too bad */
3885 drivers[j]->attach_adapter(adap);
3888 - DEB(printk("i2c-core.o: adapter %s registered as adapter %d.\n",
3889 + DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3897 - adapters[i] = NULL;
3905 @@ -207,13 +125,12 @@
3906 int i2c_del_adapter(struct i2c_adapter *adap)
3913 + down(&core_lists);
3914 for (i = 0; i < I2C_ADAP_MAX; i++)
3915 if (adap == adapters[i])
3917 if (I2C_ADAP_MAX == i) {
3918 - printk( "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3919 + printk( KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3922 @@ -226,15 +143,12 @@
3923 * this or hell will break loose...
3926 for (j = 0; j < I2C_DRIVER_MAX; j++)
3927 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3928 if ((res = drivers[j]->attach_adapter(adap))) {
3929 - printk("i2c-core.o: can't detach adapter %s "
3930 + printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3931 "while detaching driver %s: driver not "
3932 "detached!",adap->name,drivers[j]->name);
3939 /* detach any active clients. This must be done first, because
3942 if ((res=client->driver->detach_client(client))) {
3943 - printk("i2c-core.o: adapter %s not "
3944 + printk(KERN_ERR "i2c-core.o: adapter %s not "
3945 "unregistered, because client at "
3946 "address %02x can't be detached. ",
3947 @@ -255,24 +169,13 @@
3951 #ifdef CONFIG_PROC_FS
3952 - if (i2cproc_initialized) {
3954 - sprintf(name,"i2c-%d", i);
3955 - remove_proc_entry(name,proc_bus);
3957 + i2cproc_remove(i);
3958 #endif /* def CONFIG_PROC_FS */
3964 - DEB(printk("i2c-core.o: adapter unregistered: %s\n",adap->name));
3972 + DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
3982 + down(&core_lists);
3983 for (i = 0; i < I2C_DRIVER_MAX; i++)
3984 if (NULL == drivers[i])
3985 @@ -297,17 +201,10 @@
3986 "- enlarge I2C_DRIVER_MAX.\n",
3993 - drivers[i] = driver;
3996 - DRV_UNLOCK(); /* driver was successfully added */
3998 - DEB(printk("i2c-core.o: driver %s registered.\n",driver->name));
3999 + drivers[i] = driver;
4000 + DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
4004 /* now look for instances of driver on our adapters
4007 driver->attach_adapter(adapters[i]);
4014 int i2c_del_driver(struct i2c_driver *driver)
4017 + int i,j,k,res = 0;
4020 + down(&core_lists);
4021 for (i = 0; i < I2C_DRIVER_MAX; i++)
4022 if (driver == drivers[i])
4030 @@ -341,15 +238,14 @@
4033 - DEB2(printk("i2c-core.o: unregister_driver - looking for clients.\n"));
4034 + DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n"));
4035 /* removing clients does not depend on the notify flag, else
4036 * invalid operation might (will!) result, when using stale client
4039 - ADAP_LOCK(); /* should be moved inside the if statement... */
4040 for (k=0;k<I2C_ADAP_MAX;k++) {
4041 struct i2c_adapter *adap = adapters[k];
4042 if (adap == NULL) /* skip empty entries. */
4044 - DEB2(printk("i2c-core.o: examining adapter %s:\n",
4045 + DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
4047 if (driver->flags & I2C_DF_DUMMY) {
4048 @@ -360,11 +256,10 @@
4050 if ((res = driver->attach_adapter(adap))) {
4051 - printk("i2c-core.o: while unregistering "
4052 + printk(KERN_WARNING "i2c-core.o: while unregistering "
4053 "dummy driver %s, adapter %s could "
4054 "not be detached properly; driver "
4055 "not unloaded!",driver->name,
4063 if (client != NULL &&
4064 client->driver == driver) {
4065 - DEB2(printk("i2c-core.o: "
4066 + DEB2(printk(KERN_DEBUG "i2c-core.o: "
4067 "detaching client %s:\n",
4069 @@ -379,16 +274,15 @@
4070 detach_client(client)))
4072 - printk("i2c-core.o: while "
4073 + printk(KERN_ERR "i2c-core.o: while "
4074 "unregistering driver "
4075 "`%s', the client at "
4077 - "adapter `%s' could not"
4078 - "be detached; driver"
4079 + "adapter `%s' could not "
4080 + "be detached; driver "
4090 @@ -396,14 +290,13 @@
4098 - DEB(printk("i2c-core.o: driver unregistered: %s\n",driver->name));
4100 + DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
4107 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4108 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
4111 @@ -411,7 +304,19 @@
4112 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
4118 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4122 + down(&adapter->list);
4123 + rval = __i2c_check_addr(adapter, addr);
4124 + up(&adapter->list);
4129 int i2c_attach_client(struct i2c_client *client)
4134 + down(&adapter->list);
4135 for (i = 0; i < I2C_CLIENT_MAX; i++)
4136 if (NULL == adapter->clients[i])
4137 @@ -429,16 +335,16 @@
4138 " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
4140 + up(&adapter->list);
4144 adapter->clients[i] = client;
4145 - adapter->client_count++;
4146 + up(&adapter->list);
4148 if (adapter->client_register)
4149 if (adapter->client_register(client))
4150 - printk("i2c-core.o: warning: client_register seems "
4151 + printk(KERN_DEBUG "i2c-core.o: warning: client_register seems "
4152 "to have failed for client %02x at adapter %s\n",
4153 client->addr,adapter->name);
4154 - DEB(printk("i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4155 + DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4156 client->name, adapter->name,i));
4158 @@ -455,14 +361,4 @@
4161 - for (i = 0; i < I2C_CLIENT_MAX; i++)
4162 - if (client == adapter->clients[i])
4164 - if (I2C_CLIENT_MAX == i) {
4165 - printk(KERN_WARNING " i2c-core.o: unregister_client "
4166 - "[%s] not found\n",
4171 if( (client->flags & I2C_CLIENT_ALLOW_USE) &&
4172 (client->usage_count>0))
4173 @@ -471,36 +367,44 @@
4174 if (adapter->client_unregister != NULL)
4175 if ((res = adapter->client_unregister(client))) {
4176 - printk("i2c-core.o: client_unregister [%s] failed, "
4177 + printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, "
4178 "client not detached",client->name);
4182 + down(&adapter->list);
4183 + for (i = 0; i < I2C_CLIENT_MAX; i++)
4184 + if (client == adapter->clients[i])
4186 + if (I2C_CLIENT_MAX == i) {
4187 + printk(KERN_WARNING " i2c-core.o: unregister_client "
4188 + "[%s] not found\n",
4190 + up(&adapter->list);
4193 adapter->clients[i] = NULL;
4194 - adapter->client_count--;
4195 + up(&adapter->list);
4197 - DEB(printk("i2c-core.o: client [%s] unregistered.\n",client->name));
4198 + DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
4202 -void i2c_inc_use_client(struct i2c_client *client)
4203 +static void i2c_inc_use_client(struct i2c_client *client)
4206 - if (client->driver->inc_use != NULL)
4207 - client->driver->inc_use(client);
4209 - if (client->adapter->inc_use != NULL)
4210 - client->adapter->inc_use(client->adapter);
4211 + if(client->driver->owner)
4212 + __MOD_INC_USE_COUNT(client->driver->owner);
4213 + if(client->adapter->owner)
4214 + __MOD_INC_USE_COUNT(client->adapter->owner);
4217 -void i2c_dec_use_client(struct i2c_client *client)
4218 +static void i2c_dec_use_client(struct i2c_client *client)
4221 - if (client->driver->dec_use != NULL)
4222 - client->driver->dec_use(client);
4224 - if (client->adapter->dec_use != NULL)
4225 - client->adapter->dec_use(client->adapter);
4226 + if(client->driver->owner)
4227 + __MOD_DEC_USE_COUNT(client->driver->owner);
4228 + if(client->adapter->owner)
4229 + __MOD_DEC_USE_COUNT(client->adapter->owner);
4232 +#if 0 /* just forget about this for now --km */
4233 struct i2c_client *i2c_get_client(int driver_id, int adapter_id,
4234 struct i2c_client *prev)
4235 @@ -569,16 +473,15 @@
4240 int i2c_use_client(struct i2c_client *client)
4242 - if(client->flags & I2C_CLIENT_ALLOW_USE) {
4243 - if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
4244 + if (client->flags & I2C_CLIENT_ALLOW_USE) {
4245 + if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
4246 + client->usage_count++;
4247 + else if (client->usage_count > 0)
4250 client->usage_count++;
4252 - if(client->usage_count > 0)
4255 - client->usage_count++;
4259 @@ -612,18 +515,6 @@
4260 #ifdef CONFIG_PROC_FS
4262 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
4263 -/* Monitor access to /proc/bus/i2c*; make unloading i2c-proc impossible
4264 - if some process still uses it or some file in it */
4265 -void monitor_bus_i2c(struct inode *inode, int fill)
4268 - MOD_INC_USE_COUNT;
4270 - MOD_DEC_USE_COUNT;
4272 -#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */
4274 /* This function generates the output for /proc/bus/i2c */
4275 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
4276 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof,
4281 /* Note that it is safe to write a `little' beyond len. Yes, really. */
4282 + down(&core_lists);
4283 for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
4286 adapters[i]->algo->name);
4291 @@ -657,100 +550,123 @@
4293 struct i2c_client *client;
4294 + struct i2c_adapter *adap;
4295 int i,j,k,order_nr,len=0;
4297 int order[I2C_CLIENT_MAX];
4298 +#define OUTPUT_LENGTH_PER_LINE 70
4302 len_total = file->f_pos + count;
4303 - /* Too bad if this gets longer (unlikely) */
4304 - if (len_total > 4000)
4306 - for (i = 0; i < I2C_ADAP_MAX; i++)
4307 - if (adapters[i]->inode == inode->i_ino) {
4308 - /* We need a bit of slack in the kernel buffer; this makes the
4310 - if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
4312 - /* Order will hold the indexes of the clients
4313 - sorted by address */
4315 - for (j = 0; j < I2C_CLIENT_MAX; j++) {
4316 - if ((client = adapters[i]->clients[j]) &&
4317 - (client->driver->id != I2C_DRIVERID_I2CDEV)) {
4320 - adapters[i]->clients[order[k-1]]->
4321 - addr > client->addr;
4323 - order[k] = order[k-1];
4330 - for (j = 0; (j < order_nr) && (len < len_total); j++) {
4331 - client = adapters[i]->clients[order[j]];
4332 - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4335 - client->driver->name);
4337 - len = len - file->f_pos;
4342 - if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4346 - file->f_pos += len;
4351 + if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
4352 + /* adjust to maximum file size */
4353 + len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
4355 + down(&core_lists);
4356 + /* adap = file->private_data; ?? --km */
4357 + for (i = 0; i < I2C_ADAP_MAX; i++) {
4358 + adap = adapters[i];
4359 + if (adap && (adap->inode == inode->i_ino))
4362 + if ( I2C_ADAP_MAX == i ) {
4367 + /* We need a bit of slack in the kernel buffer; this makes the
4369 + if (! (kbuf = kmalloc(len_total +
4370 + OUTPUT_LENGTH_PER_LINE,
4374 + /* Order will hold the indexes of the clients
4375 + sorted by address */
4377 + down(&adap->list);
4378 + for (j = 0; j < I2C_CLIENT_MAX; j++) {
4379 + if ((client = adap->clients[j]) &&
4380 + (client->driver->id != I2C_DRIVERID_I2CDEV)) {
4383 + adap->clients[order[k-1]]->
4384 + addr > client->addr;
4386 + order[k] = order[k-1];
4393 + for (j = 0; (j < order_nr) && (len < len_total); j++) {
4394 + client = adap->clients[order[j]];
4395 + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4398 + client->driver->name);
4403 + len = len - file->f_pos;
4408 + if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4412 + file->f_pos += len;
4417 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
4420 + struct proc_dir_entry *proc_entry;
4422 + sprintf(name,"i2c-%d", bus);
4423 + proc_entry = create_proc_entry(name,0,proc_bus);
4424 + if (! proc_entry) {
4425 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
4430 + proc_entry->proc_fops = &i2cproc_operations;
4431 + proc_entry->owner = adap->owner;
4432 + adap->inode = proc_entry->low_ino;
4436 -int i2cproc_init(void)
4437 +static void i2cproc_remove(int bus)
4440 + sprintf(name,"i2c-%d", bus);
4441 + remove_proc_entry(name, proc_bus);
4444 +static int __init i2cproc_init(void)
4446 struct proc_dir_entry *proc_bus_i2c;
4448 - i2cproc_initialized = 0;
4451 - printk("i2c-core.o: /proc/bus/ does not exist");
4452 - i2cproc_cleanup();
4455 proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
4456 if (!proc_bus_i2c) {
4457 - printk("i2c-core.o: Could not create /proc/bus/i2c");
4458 - i2cproc_cleanup();
4459 + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
4463 proc_bus_i2c->read_proc = &read_bus_i2c;
4464 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
4465 proc_bus_i2c->owner = THIS_MODULE;
4467 - proc_bus_i2c->fill_inode = &monitor_bus_i2c;
4468 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
4469 - i2cproc_initialized += 2;
4473 -int i2cproc_cleanup(void)
4474 +static void __exit i2cproc_cleanup(void)
4477 - if (i2cproc_initialized >= 1) {
4478 - remove_proc_entry("i2c",proc_bus);
4479 - i2cproc_initialized -= 2;
4482 + remove_proc_entry("i2c",proc_bus);
4486 #endif /* def CONFIG_PROC_FS */
4488 @@ -765,14 +681,14 @@
4490 if (adap->algo->master_xfer) {
4491 - DEB2(printk("i2c-core.o: master_xfer: %s with %d msgs.\n",
4492 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
4497 ret = adap->algo->master_xfer(adap,msgs,num);
4503 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4504 + printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4507 @@ -792,10 +708,10 @@
4508 (const char *)msg.buf = buf;
4510 - DEB2(printk("i2c-core.o: master_send: writing %d bytes on %s.\n",
4511 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
4512 count,client->adapter->name));
4516 ret = adap->algo->master_xfer(adap,&msg,1);
4520 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4522 return (ret == 1 )? count : ret;
4524 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4525 + printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4526 client->adapter->id);
4528 @@ -822,12 +738,12 @@
4531 - DEB2(printk("i2c-core.o: master_recv: reading %d bytes on %s.\n",
4532 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
4533 count,client->adapter->name));
4537 ret = adap->algo->master_xfer(adap,&msg,1);
4541 - DEB2(printk("i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4542 + DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4543 ret, count, client->addr));
4546 return (ret == 1 )? count : ret;
4548 - printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4549 + printk(KERN_DEBUG "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4550 client->adapter->id);
4553 struct i2c_adapter *adap = client->adapter;
4555 - DEB2(printk("i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4556 + DEB2(printk(KERN_DEBUG "i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4560 (address_data->force[i] == ANY_I2C_BUS)) &&
4561 (addr == address_data->force[i+1])) {
4562 - DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4563 + DEB2(printk(KERN_DEBUG "i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4565 if ((err = found_proc(adapter,addr,0,0)))
4567 ((address_data->ignore[i] == ANY_I2C_BUS))) &&
4568 (addr == address_data->ignore[i+1])) {
4569 - DEB2(printk("i2c-core.o: found ignore parameter for adapter %d, "
4570 + DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore parameter for adapter %d, "
4571 "addr %04x\n", adap_id ,addr));
4574 (addr >= address_data->ignore_range[i+1]) &&
4575 (addr <= address_data->ignore_range[i+2])) {
4576 - DEB2(printk("i2c-core.o: found ignore_range parameter for adapter %d, "
4577 + DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore_range parameter for adapter %d, "
4578 "addr %04x\n", adap_id,addr));
4581 if (addr == address_data->normal_i2c[i]) {
4583 - DEB2(printk("i2c-core.o: found normal i2c entry for adapter %d, "
4584 + DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, "
4585 "addr %02x", adap_id,addr));
4588 (addr <= address_data->normal_i2c_range[i+1])) {
4590 - DEB2(printk("i2c-core.o: found normal i2c_range entry for adapter %d, "
4591 + DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c_range entry for adapter %d, "
4592 "addr %04x\n", adap_id,addr));
4595 (addr == address_data->probe[i+1])) {
4597 - DEB2(printk("i2c-core.o: found probe parameter for adapter %d, "
4598 + DEB2(printk(KERN_DEBUG "i2c-core.o: found probe parameter for adapter %d, "
4599 "addr %04x\n", adap_id,addr));
4602 (addr <= address_data->probe_range[i+2])) {
4604 - DEB2(printk("i2c-core.o: found probe_range parameter for adapter %d, "
4605 + DEB2(printk(KERN_DEBUG "i2c-core.o: found probe_range parameter for adapter %d, "
4606 "addr %04x\n", adap_id,addr));
4608 @@ -1005,4 +921,121 @@
4609 /* The SMBus parts */
4611 +#define POLY (0x1070U << 3)
4617 + for(i = 0; i < 8; i++) {
4618 + if (data & 0x8000)
4619 + data = data ^ POLY;
4622 + return (u8)(data >> 8);
4625 +/* CRC over count bytes in the first array plus the bytes in the rest
4626 + array if it is non-null. rest[0] is the (length of rest) - 1
4627 + and is included. */
4628 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
4632 + for(i = 0; i < count; i++)
4633 + crc = crc8((crc ^ first[i]) << 8);
4635 + for(i = 0; i <= rest[0]; i++)
4636 + crc = crc8((crc ^ rest[i]) << 8);
4640 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
4642 + return i2c_smbus_partial_pec(0, count, first, rest);
4645 +/* Returns new "size" (transaction type)
4646 + Note that we convert byte to byte_data and byte_data to word_data
4647 + rather than invent new xxx_PEC transactions. */
4648 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
4649 + union i2c_smbus_data *data)
4653 + buf[0] = addr << 1;
4656 + case I2C_SMBUS_BYTE:
4657 + data->byte = i2c_smbus_pec(2, buf, NULL);
4658 + size = I2C_SMBUS_BYTE_DATA;
4660 + case I2C_SMBUS_BYTE_DATA:
4661 + buf[2] = data->byte;
4662 + data->word = buf[2] ||
4663 + (i2c_smbus_pec(3, buf, NULL) << 8);
4664 + size = I2C_SMBUS_WORD_DATA;
4666 + case I2C_SMBUS_WORD_DATA:
4669 + case I2C_SMBUS_BLOCK_DATA:
4670 + data->block[data->block[0] + 1] =
4671 + i2c_smbus_pec(2, buf, data->block);
4672 + size = I2C_SMBUS_BLOCK_DATA_PEC;
4678 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
4679 + union i2c_smbus_data *data)
4681 + u8 buf[3], rpec, cpec;
4685 + case I2C_SMBUS_BYTE_DATA:
4686 + buf[0] = (addr << 1) | 1;
4687 + cpec = i2c_smbus_pec(2, buf, NULL);
4688 + rpec = data->byte;
4690 + case I2C_SMBUS_WORD_DATA:
4691 + buf[0] = (addr << 1) | 1;
4692 + buf[2] = data->word & 0xff;
4693 + cpec = i2c_smbus_pec(3, buf, NULL);
4694 + rpec = data->word >> 8;
4696 + case I2C_SMBUS_WORD_DATA_PEC:
4700 + case I2C_SMBUS_PROC_CALL_PEC:
4704 + case I2C_SMBUS_BLOCK_DATA_PEC:
4705 + buf[0] = (addr << 1);
4706 + buf[2] = (addr << 1) | 1;
4707 + cpec = i2c_smbus_pec(3, buf, data->block);
4708 + rpec = data->block[data->block[0] + 1];
4710 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4711 + buf[0] = (addr << 1) | 1;
4712 + rpec = i2c_smbus_partial_pec(partial, 1,
4713 + buf, data->block);
4714 + cpec = data->block[data->block[0] + 1];
4720 + if(rpec != cpec) {
4721 + DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
4728 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
4730 @@ -1023,6 +1056,7 @@
4731 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
4733 + union i2c_smbus_data data; /* only for PEC */
4734 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4735 - I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
4736 + I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
4739 @@ -1102,6 +1136,6 @@
4740 union i2c_smbus_data data;
4744 + if (length > I2C_SMBUS_BLOCK_MAX)
4745 + length = I2C_SMBUS_BLOCK_MAX;
4746 for (i = 1; i <= length; i++)
4747 data.block[i] = values[i-1];
4748 @@ -1112,4 +1146,41 @@
4751 +/* Returns the number of read bytes */
4752 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
4753 + u8 command, u8 length, u8 *values)
4755 + union i2c_smbus_data data;
4757 + if (length > I2C_SMBUS_BLOCK_MAX - 1)
4759 + data.block[0] = length;
4760 + for (i = 1; i <= length; i++)
4761 + data.block[i] = values[i-1];
4762 + if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4763 + I2C_SMBUS_WRITE, command,
4764 + I2C_SMBUS_BLOCK_PROC_CALL, &data))
4766 + for (i = 1; i <= data.block[0]; i++)
4767 + values[i-1] = data.block[i];
4768 + return data.block[0];
4771 +/* Returns the number of read bytes */
4772 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
4773 + u8 command, u8 *values)
4775 + union i2c_smbus_data data;
4777 + if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4778 + I2C_SMBUS_READ,command,
4779 + I2C_SMBUS_I2C_BLOCK_DATA,&data))
4782 + for (i = 1; i <= data.block[0]; i++)
4783 + values[i-1] = data.block[i];
4784 + return data.block[0];
4788 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
4789 u8 command, u8 length, u8 *values)
4790 @@ -1117,6 +1188,6 @@
4791 union i2c_smbus_data data;
4795 + if (length > I2C_SMBUS_I2C_BLOCK_MAX)
4796 + length = I2C_SMBUS_I2C_BLOCK_MAX;
4797 for (i = 1; i <= length; i++)
4798 data.block[i] = values[i-1];
4799 @@ -1180,4 +1251,5 @@
4800 case I2C_SMBUS_PROC_CALL:
4801 num = 2; /* Special case */
4802 + read_write = I2C_SMBUS_READ;
4805 @@ -1186,22 +1258,45 @@
4807 case I2C_SMBUS_BLOCK_DATA:
4808 + case I2C_SMBUS_BLOCK_DATA_PEC:
4809 if (read_write == I2C_SMBUS_READ) {
4810 - printk("i2c-core.o: Block read not supported under "
4811 - "I2C emulation!\n");
4813 + printk(KERN_ERR "i2c-core.o: Block read not supported "
4814 + "under I2C emulation!\n");
4817 msg[0].len = data->block[0] + 2;
4818 - if (msg[0].len > 34) {
4819 - printk("i2c-core.o: smbus_access called with "
4820 + if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
4821 + printk(KERN_ERR "i2c-core.o: smbus_access called with "
4822 "invalid block write size (%d)\n",
4827 + if(size == I2C_SMBUS_BLOCK_DATA_PEC)
4829 for (i = 1; i <= msg[0].len; i++)
4830 msgbuf0[i] = data->block[i-1];
4833 + case I2C_SMBUS_BLOCK_PROC_CALL:
4834 + case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4835 + printk(KERN_ERR "i2c-core.o: Block process call not supported "
4836 + "under I2C emulation!\n");
4838 + case I2C_SMBUS_I2C_BLOCK_DATA:
4839 + if (read_write == I2C_SMBUS_READ) {
4840 + msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
4842 + msg[0].len = data->block[0] + 1;
4843 + if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
4844 + printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
4845 + "invalid block write size (%d)\n",
4849 + for (i = 1; i <= data->block[0]; i++)
4850 + msgbuf0[i] = data->block[i];
4854 - printk("i2c-core.o: smbus_access called with invalid size (%d)\n",
4855 + printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
4858 @@ -1223,4 +1318,10 @@
4859 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
4861 + case I2C_SMBUS_I2C_BLOCK_DATA:
4862 + /* fixed at 32 for now */
4863 + data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
4864 + for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
4865 + data->block[i+1] = msgbuf1[i];
4869 @@ -1228,18 +1329,48 @@
4872 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
4873 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
4874 char read_write, u8 command, int size,
4875 union i2c_smbus_data * data)
4878 - flags = flags & I2C_M_TEN;
4879 - if (adapter->algo->smbus_xfer) {
4880 - I2C_LOCK(adapter);
4881 - res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4885 + flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4886 + if((flags & I2C_CLIENT_PEC) &&
4887 + !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4889 + if(read_write == I2C_SMBUS_READ &&
4890 + size == I2C_SMBUS_BLOCK_DATA)
4891 + size = I2C_SMBUS_BLOCK_DATA_PEC;
4892 + else if(size == I2C_SMBUS_PROC_CALL)
4893 + size = I2C_SMBUS_PROC_CALL_PEC;
4894 + else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
4895 + i2c_smbus_add_pec(addr, command,
4896 + I2C_SMBUS_BLOCK_DATA, data);
4897 + partial = data->block[data->block[0] + 1];
4898 + size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
4899 + } else if(read_write == I2C_SMBUS_WRITE &&
4900 + size != I2C_SMBUS_QUICK &&
4901 + size != I2C_SMBUS_I2C_BLOCK_DATA)
4902 + size = i2c_smbus_add_pec(addr, command, size, data);
4905 + if (adap->algo->smbus_xfer) {
4907 + res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
4909 - I2C_UNLOCK(adapter);
4912 - res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
4913 + res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
4916 + if(res >= 0 && swpec &&
4917 + size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
4918 + (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
4919 + size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
4920 + if(i2c_smbus_check_pec(addr, command, size, partial, data))
4925 @@ -1265,128 +1396,30 @@
4926 static int __init i2c_init(void)
4928 - printk(KERN_INFO "i2c-core.o: i2c core module\n");
4929 + printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
4930 memset(adapters,0,sizeof(adapters));
4931 memset(drivers,0,sizeof(drivers));
4935 - init_MUTEX(&adap_lock);
4936 - init_MUTEX(&driver_lock);
4940 +#ifdef CONFIG_PROC_FS
4941 + return i2cproc_init();
4947 -#ifdef CONFIG_I2C_CHARDEV
4948 - extern int i2c_dev_init(void);
4950 -#ifdef CONFIG_I2C_ALGOBIT
4951 - extern int i2c_algo_bit_init(void);
4953 -#ifdef CONFIG_I2C_PHILIPSPAR
4954 - extern int i2c_bitlp_init(void);
4956 -#ifdef CONFIG_I2C_ELV
4957 - extern int i2c_bitelv_init(void);
4959 -#ifdef CONFIG_I2C_VELLEMAN
4960 - extern int i2c_bitvelle_init(void);
4962 -#ifdef CONFIG_I2C_BITVIA
4963 - extern int i2c_bitvia_init(void);
4966 -#ifdef CONFIG_I2C_ALGOPCF
4967 - extern int i2c_algo_pcf_init(void);
4969 -#ifdef CONFIG_I2C_ELEKTOR
4970 - extern int i2c_pcfisa_init(void);
4973 -#ifdef CONFIG_I2C_ALGO8XX
4974 - extern int i2c_algo_8xx_init(void);
4976 -#ifdef CONFIG_I2C_RPXLITE
4977 - extern int i2c_rpx_init(void);
4980 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4981 - extern int i2c_algo_sibyte_init(void);
4982 - extern int i2c_sibyte_init(void);
4984 -#ifdef CONFIG_I2C_MAX1617
4985 - extern int i2c_max1617_init(void);
4989 -#ifdef CONFIG_I2C_PROC
4990 - extern int sensors_init(void);
4991 +static void __exit i2c_exit(void)
4993 +#ifdef CONFIG_PROC_FS
4994 + i2cproc_cleanup();
4998 -/* This is needed for automatic patch generation: sensors code starts here */
4999 -/* This is needed for automatic patch generation: sensors code ends here */
5001 +/* leave this in for now simply to make patching easier so we don't have
5002 + to remove the call in drivers/char/mem.c */
5003 int __init i2c_init_all(void)
5005 - /* --------------------- global ----- */
5008 -#ifdef CONFIG_I2C_CHARDEV
5011 - /* --------------------- bit -------- */
5012 -#ifdef CONFIG_I2C_ALGOBIT
5013 - i2c_algo_bit_init();
5015 -#ifdef CONFIG_I2C_PHILIPSPAR
5018 -#ifdef CONFIG_I2C_ELV
5019 - i2c_bitelv_init();
5021 -#ifdef CONFIG_I2C_VELLEMAN
5022 - i2c_bitvelle_init();
5025 - /* --------------------- pcf -------- */
5026 -#ifdef CONFIG_I2C_ALGOPCF
5027 - i2c_algo_pcf_init();
5029 -#ifdef CONFIG_I2C_ELEKTOR
5030 - i2c_pcfisa_init();
5033 - /* --------------------- 8xx -------- */
5034 -#ifdef CONFIG_I2C_ALGO8XX
5035 - i2c_algo_8xx_init();
5037 -#ifdef CONFIG_I2C_RPXLITE
5041 - /* --------------------- SiByte -------- */
5042 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5043 - i2c_algo_sibyte_init();
5044 - i2c_sibyte_init();
5046 -#ifdef CONFIG_I2C_MAX1617
5047 - i2c_max1617_init();
5050 - /* -------------- proc interface ---- */
5051 -#ifdef CONFIG_I2C_PROC
5054 -/* This is needed for automatic patch generation: sensors code starts here */
5055 -/* This is needed for automatic patch generation: sensors code ends here */
5064 EXPORT_SYMBOL(i2c_add_adapter);
5065 EXPORT_SYMBOL(i2c_del_adapter);
5066 @@ -1395,7 +1428,4 @@
5067 EXPORT_SYMBOL(i2c_attach_client);
5068 EXPORT_SYMBOL(i2c_detach_client);
5069 -EXPORT_SYMBOL(i2c_inc_use_client);
5070 -EXPORT_SYMBOL(i2c_dec_use_client);
5071 -EXPORT_SYMBOL(i2c_get_client);
5072 EXPORT_SYMBOL(i2c_use_client);
5073 EXPORT_SYMBOL(i2c_release_client);
5074 @@ -1421,23 +1451,17 @@
5075 EXPORT_SYMBOL(i2c_smbus_read_block_data);
5076 EXPORT_SYMBOL(i2c_smbus_write_block_data);
5077 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
5078 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
5080 EXPORT_SYMBOL(i2c_get_functionality);
5081 EXPORT_SYMBOL(i2c_check_functionality);
5084 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5085 MODULE_DESCRIPTION("I2C-Bus main module");
5086 -MODULE_PARM(i2c_debug, "i");
5087 -MODULE_PARM_DESC(i2c_debug,"debug level");
5088 MODULE_LICENSE("GPL");
5090 -int init_module(void)
5092 - return i2c_init();
5094 +MODULE_PARM(i2c_debug, "i");
5095 +MODULE_PARM_DESC(i2c_debug,"debug level");
5097 -void cleanup_module(void)
5099 - i2cproc_cleanup();
5102 +module_init(i2c_init);
5103 +module_exit(i2c_exit);
5104 --- linux-old/drivers/i2c/i2c-dev.c Sun Aug 31 14:51:55 CEST 2003
5105 +++ linux/drivers/i2c/i2c-dev.c Sun Aug 31 14:51:55 CEST 2003
5107 <pmhahn@titan.lahn.de> */
5112 -#include <linux/config.h>
5113 #include <linux/kernel.h>
5114 #include <linux/module.h>
5115 #include <linux/fs.h>
5116 #include <linux/slab.h>
5117 -#include <linux/version.h>
5118 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5119 #include <linux/smp_lock.h>
5120 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5121 #ifdef CONFIG_DEVFS_FS
5122 #include <linux/devfs_fs_kernel.h>
5126 -/* If you want debugging uncomment: */
5127 -/* #define DEBUG */
5129 #include <linux/init.h>
5130 -#include <asm/uaccess.h>
5132 #include <linux/i2c.h>
5133 #include <linux/i2c-dev.h>
5134 +#include <asm/uaccess.h>
5136 +/* If you want debugging uncomment: */
5137 +/* #define DEBUG */
5140 -extern int init_module(void);
5141 -extern int cleanup_module(void);
5142 -#endif /* def MODULE */
5144 /* struct file_operations changed too often in the 2.1 series for nice code */
5146 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5147 -static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin);
5149 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5159 - int __init i2c_dev_init(void);
5160 -static int i2cdev_cleanup(void);
5162 static struct file_operations i2cdev_fops = {
5163 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5164 - owner: THIS_MODULE,
5165 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5166 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5167 - llseek: i2cdev_lseek,
5169 - llseek: no_llseek,
5171 - read: i2cdev_read,
5172 - write: i2cdev_write,
5173 - ioctl: i2cdev_ioctl,
5174 - open: i2cdev_open,
5175 - release: i2cdev_release,
5176 + .owner = THIS_MODULE,
5177 + .llseek = no_llseek,
5178 + .read = i2cdev_read,
5179 + .write = i2cdev_write,
5180 + .ioctl = i2cdev_ioctl,
5181 + .open = i2cdev_open,
5182 + .release = i2cdev_release,
5185 @@ -112,40 +84,20 @@
5187 static struct i2c_driver i2cdev_driver = {
5188 - name: "i2c-dev dummy driver",
5189 - id: I2C_DRIVERID_I2CDEV,
5190 - flags: I2C_DF_DUMMY,
5191 - attach_adapter: i2cdev_attach_adapter,
5192 - detach_client: i2cdev_detach_client,
5193 - command: i2cdev_command,
5196 + .owner = THIS_MODULE, /* not really used */
5197 + .name = "i2c-dev dummy driver",
5198 + .id = I2C_DRIVERID_I2CDEV,
5199 + .flags = I2C_DF_DUMMY,
5200 + .attach_adapter = i2cdev_attach_adapter,
5201 + .detach_client = i2cdev_detach_client,
5202 + .command = i2cdev_command,
5205 static struct i2c_client i2cdev_client_template = {
5206 - name: "I2C /dev entry",
5210 -/* adapter: NULL, */
5211 - driver: &i2cdev_driver,
5213 + .name = "I2C /dev entry",
5216 + .driver = &i2cdev_driver,
5219 -static int i2cdev_initialized;
5221 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5222 -/* Note that the lseek function is called llseek in 2.1 kernels. But things
5223 - are complicated enough as is. */
5224 -loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin)
5227 - struct inode *inode = file->f_dentry->d_inode;
5228 - printk("i2c-dev.o: i2c-%d lseek to %ld bytes relative to %d.\n",
5229 - MINOR(inode->i_rdev),(long) offset,origin);
5235 static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5238 struct i2c_client *client = (struct i2c_client *)file->private_data;
5245 /* copy user space data to kernel space. */
5246 tmp = kmalloc(count,GFP_KERNEL);
5250 - printk("i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
5251 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
5262 /* copy user space data to kernel space. */
5263 tmp = kmalloc(count,GFP_KERNEL);
5267 - printk("i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
5268 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
5274 - printk("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
5275 - MINOR(inode->i_rdev),cmd, arg);
5276 + printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n",
5277 + minor(inode->i_rdev),cmd, arg);
5280 @@ -245,4 +197,10 @@
5281 client->flags &= ~I2C_M_TEN;
5285 + client->flags |= I2C_CLIENT_PEC;
5287 + client->flags &= ~I2C_CLIENT_PEC;
5290 funcs = i2c_get_functionality(client->adapter);
5292 if (rdwr_arg.nmsgs > 42)
5296 rdwr_pa = (struct i2c_msg *)
5297 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
5299 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
5300 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
5301 - (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
5302 + (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
5303 + (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
5305 - printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5306 + printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5310 (data_arg.read_write != I2C_SMBUS_WRITE)) {
5312 - printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5313 + printk(KERN_DEBUG "i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5314 data_arg.read_write);
5317 if (data_arg.data == NULL) {
5319 - printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5320 + printk(KERN_DEBUG "i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5324 (data_arg.size == I2C_SMBUS_PROC_CALL))
5325 datasize = sizeof(data_arg.data->word);
5326 - else /* size == I2C_SMBUS_BLOCK_DATA */
5327 + else /* size == smbus block, i2c block, or block proc. call */
5328 datasize = sizeof(data_arg.data->block);
5330 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
5331 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
5332 (data_arg.read_write == I2C_SMBUS_WRITE)) {
5333 if (copy_from_user(&temp, data_arg.data, datasize))
5335 data_arg.command,data_arg.size,&temp);
5336 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
5337 + (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
5338 (data_arg.read_write == I2C_SMBUS_READ))) {
5339 if (copy_to_user(data_arg.data, &temp, datasize))
5340 @@ -414,10 +375,10 @@
5341 int i2cdev_open (struct inode *inode, struct file *file)
5343 - unsigned int minor = MINOR(inode->i_rdev);
5344 + unsigned int minor = minor(inode->i_rdev);
5345 struct i2c_client *client;
5347 if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
5349 - printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5350 + printk(KERN_DEBUG "i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5353 @@ -430,15 +391,14 @@
5355 memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
5357 + /* registered with adapter, passed as client to user */
5358 client->adapter = i2cdev_adaps[minor];
5359 file->private_data = client;
5361 - if (i2cdev_adaps[minor]->inc_use)
5362 - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
5363 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5364 - MOD_INC_USE_COUNT;
5365 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5366 + if(client->adapter->owner)
5367 + __MOD_INC_USE_COUNT(client->adapter->owner);
5370 - printk("i2c-dev.o: opened i2c-%d\n",minor);
5371 + printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
5374 @@ -447,20 +407,17 @@
5375 static int i2cdev_release (struct inode *inode, struct file *file)
5377 - unsigned int minor = MINOR(inode->i_rdev);
5378 - kfree(file->private_data);
5379 - file->private_data=NULL;
5381 - printk("i2c-dev.o: Closed: i2c-%d\n", minor);
5383 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5384 - MOD_DEC_USE_COUNT;
5385 -#else /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5387 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5388 - if (i2cdev_adaps[minor]->dec_use)
5389 - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
5390 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5392 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5393 + struct i2c_client *client;
5395 + unsigned int minor = minor(inode->i_rdev);
5398 + client = file->private_data;
5399 + file->private_data = NULL;
5400 + if(client->adapter->owner)
5401 + __MOD_DEC_USE_COUNT(client->adapter->owner);
5404 + printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
5410 if ((i = i2c_adapter_id(adap)) < 0) {
5411 - printk("i2c-dev.o: Unknown adapter ?!?\n");
5412 + printk(KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n");
5415 if (i >= I2CDEV_ADAPS_MAX) {
5416 - printk("i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5417 + printk(KERN_DEBUG "i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5421 DEVFS_FL_DEFAULT, I2C_MAJOR, i,
5422 S_IFCHR | S_IRUSR | S_IWUSR,
5423 - &i2cdev_fops, NULL);
5424 + &i2cdev_fops, adap);
5426 - printk("i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5427 + printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5429 /* This is actually a detach_adapter call! */
5431 i2cdev_adaps[i] = NULL;
5433 - printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5434 + printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5440 - printk("i2c-dev.o: i2c /dev entries driver module\n");
5441 + printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5443 - i2cdev_initialized = 0;
5444 #ifdef CONFIG_DEVFS_FS
5445 if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
5447 if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
5449 - printk("i2c-dev.o: unable to get major %d for i2c bus\n",
5450 + printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
5453 @@ -534,62 +490,28 @@
5454 devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
5456 - i2cdev_initialized ++;
5458 if ((res = i2c_add_driver(&i2cdev_driver))) {
5459 - printk("i2c-dev.o: Driver registration failed, module not inserted.\n");
5461 + printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
5462 +#ifdef CONFIG_DEVFS_FS
5463 + devfs_unregister(devfs_handle);
5465 + unregister_chrdev(I2C_MAJOR,"i2c");
5468 - i2cdev_initialized ++;
5472 -int i2cdev_cleanup(void)
5473 +static void __exit i2c_dev_exit(void)
5477 - if (i2cdev_initialized >= 2) {
5478 - if ((res = i2c_del_driver(&i2cdev_driver))) {
5479 - printk("i2c-dev.o: Driver deregistration failed, "
5480 - "module not removed.\n");
5483 - i2cdev_initialized --;
5486 - if (i2cdev_initialized >= 1) {
5487 + i2c_del_driver(&i2cdev_driver);
5488 #ifdef CONFIG_DEVFS_FS
5489 - devfs_unregister(devfs_handle);
5490 - if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
5492 - if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
5493 + devfs_unregister(devfs_handle);
5495 - printk("i2c-dev.o: unable to release major %d for i2c bus\n",
5499 - i2cdev_initialized --;
5502 + unregister_chrdev(I2C_MAJOR,"i2c");
5509 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5510 MODULE_DESCRIPTION("I2C /dev entries driver");
5511 MODULE_LICENSE("GPL");
5513 -int init_module(void)
5515 - return i2c_dev_init();
5518 -int cleanup_module(void)
5520 - return i2cdev_cleanup();
5523 -#endif /* def MODULE */
5525 +module_init(i2c_dev_init);
5526 +module_exit(i2c_dev_exit);
5527 --- linux-old/include/linux/i2c-dev.h Sun Aug 31 14:51:55 CEST 2003
5528 +++ linux/include/linux/i2c-dev.h Sun Aug 31 14:51:55 CEST 2003
5538 +#ifndef _LINUX_I2C_DEV_H
5539 +#define _LINUX_I2C_DEV_H
5541 #include <linux/types.h>
5542 -#include <linux/i2c.h>
5544 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
5545 +#define minor(d) MINOR(d)
5548 /* Some IOCTL commands are defined in <linux/i2c.h> */
5554 -#include <sys/ioctl.h>
5556 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
5557 - int size, union i2c_smbus_data *data)
5559 - struct i2c_smbus_ioctl_data args;
5561 - args.read_write = read_write;
5562 - args.command = command;
5565 - return ioctl(file,I2C_SMBUS,&args);
5569 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
5571 - return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
5574 -static inline __s32 i2c_smbus_read_byte(int file)
5576 - union i2c_smbus_data data;
5577 - if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
5580 - return 0x0FF & data.byte;
5583 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
5585 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
5586 - I2C_SMBUS_BYTE,NULL);
5589 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
5591 - union i2c_smbus_data data;
5592 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5593 - I2C_SMBUS_BYTE_DATA,&data))
5596 - return 0x0FF & data.byte;
5599 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
5602 - union i2c_smbus_data data;
5603 - data.byte = value;
5604 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5605 - I2C_SMBUS_BYTE_DATA, &data);
5608 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
5610 - union i2c_smbus_data data;
5611 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5612 - I2C_SMBUS_WORD_DATA,&data))
5615 - return 0x0FFFF & data.word;
5618 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
5621 - union i2c_smbus_data data;
5622 - data.word = value;
5623 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5624 - I2C_SMBUS_WORD_DATA, &data);
5627 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
5629 - union i2c_smbus_data data;
5630 - data.word = value;
5631 - if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5632 - I2C_SMBUS_PROC_CALL,&data))
5635 - return 0x0FFFF & data.word;
5639 -/* Returns the number of read bytes */
5640 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
5643 - union i2c_smbus_data data;
5645 - if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5646 - I2C_SMBUS_BLOCK_DATA,&data))
5649 - for (i = 1; i <= data.block[0]; i++)
5650 - values[i-1] = data.block[i];
5651 - return data.block[0];
5655 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
5656 - __u8 length, __u8 *values)
5658 - union i2c_smbus_data data;
5662 - for (i = 1; i <= length; i++)
5663 - data.block[i] = values[i-1];
5664 - data.block[0] = length;
5665 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5666 - I2C_SMBUS_BLOCK_DATA, &data);
5669 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
5670 - __u8 length, __u8 *values)
5672 - union i2c_smbus_data data;
5676 - for (i = 1; i <= length; i++)
5677 - data.block[i] = values[i-1];
5678 - data.block[0] = length;
5679 - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5680 - I2C_SMBUS_I2C_BLOCK_DATA, &data);
5683 -#endif /* ndef __KERNEL__ */
5686 +#endif /* _LINUX_I2C_DEV_H */
5687 --- linux-old/drivers/i2c/i2c-elektor.c Sun Aug 31 14:51:55 CEST 2003
5688 +++ linux/drivers/i2c/i2c-elektor.c Sun Aug 31 14:51:55 CEST 2003
5690 #include <linux/delay.h>
5691 #include <linux/slab.h>
5692 -#include <linux/version.h>
5693 #include <linux/init.h>
5694 +#include <linux/interrupt.h>
5695 #include <linux/pci.h>
5696 -#include <asm/irq.h>
5697 -#include <asm/io.h>
5699 +#include <linux/wait.h>
5700 #include <linux/i2c.h>
5701 #include <linux/i2c-algo-pcf.h>
5702 -#include <linux/i2c-elektor.h>
5703 -#include "i2c-pcf8584.h"
5704 +#include <asm/io.h>
5705 +#include <asm/irq.h>
5707 #define DEFAULT_BASE 0x330
5709 -static int base = 0;
5710 -static int irq = 0;
5713 static int clock = 0x1c;
5714 static int own = 0x55;
5715 -static int mmapped = 0;
5716 -static int i2c_debug = 0;
5717 +static int mmapped;
5718 +static int i2c_debug;
5720 /* vdovikin: removed static struct i2c_pcf_isa gpi; code -
5722 need to be rewriten - but for now just remove this for simpler reading */
5724 -#if (LINUX_VERSION_CODE < 0x020301)
5725 -static struct wait_queue *pcf_wait = NULL;
5727 static wait_queue_head_t pcf_wait;
5729 static int pcf_pending;
5730 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5732 /* ----- global defines ----------------------------------------------- */
5734 #define DEBE(x) x /* error messages */
5737 +/* compatibility */
5739 +#define isa_readb readb
5743 +#define isa_writeb writeb
5746 /* ----- local functions ---------------------------------------------- */
5749 int address = ctl ? (base + 1) : base;
5752 + /* enable irq if any specified for serial operation */
5753 + if (ctl && irq && (val & I2C_PCF_ESO)) {
5757 - DEB3(printk("i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5758 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5762 case 2: /* double mapped I/O needed for UP2000 board,
5763 I don't know why this... */
5764 - writeb(val, address);
5765 + isa_writeb(val, address);
5767 case 1: /* memory mapped I/O */
5768 - writeb(val, address);
5769 + isa_writeb(val, address);
5774 int address = ctl ? (base + 1) : base;
5775 - int val = mmapped ? readb(address) : inb(address);
5776 + int val = mmapped ? isa_readb(address) : inb(address);
5778 - DEB3(printk("i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5779 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5782 @@ -121,10 +127,10 @@
5786 + spin_lock_irq(&irq_driver_lock);
5787 if (pcf_pending == 0) {
5788 interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
5792 + spin_unlock_irq(&irq_driver_lock);
5795 @@ -142,14 +148,14 @@
5798 - if (check_region(base, 2) < 0 ) {
5799 - printk("i2c-elektor.o: requested I/O region (0x%X:2) is in use.\n", base);
5800 + if (!request_region(base, 2, "i2c (isa bus adapter)")) {
5802 + "i2c-elektor.o: requested I/O region (0x%X:2) "
5803 + "is in use.\n", base);
5806 - request_region(base, 2, "i2c (isa bus adapter)");
5810 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", 0) < 0) {
5811 - printk("i2c-elektor.o: Request irq%d failed\n", irq);
5812 + printk(KERN_ERR "i2c-elektor.o: Request irq%d failed\n", irq);
5815 @@ -160,42 +166,4 @@
5818 -static void __exit pcf_isa_exit(void)
5825 - release_region(base , 2);
5830 -static int pcf_isa_reg(struct i2c_client *client)
5836 -static int pcf_isa_unreg(struct i2c_client *client)
5841 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
5844 - MOD_INC_USE_COUNT;
5848 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
5851 - MOD_DEC_USE_COUNT;
5856 /* ------------------------------------------------------------------------
5857 * Encapsulate the above functions in the correct operations structure.
5858 @@ -203,25 +171,22 @@
5860 static struct i2c_algo_pcf_data pcf_isa_data = {
5866 - pcf_isa_waitforpin,
5867 - 10, 10, 100, /* waits, timeout */
5868 + .setpcf = pcf_isa_setbyte,
5869 + .getpcf = pcf_isa_getbyte,
5870 + .getown = pcf_isa_getown,
5871 + .getclock = pcf_isa_getclock,
5872 + .waitforpin = pcf_isa_waitforpin,
5878 static struct i2c_adapter pcf_isa_ops = {
5879 - "PCF8584 ISA adapter",
5887 + .owner = THIS_MODULE,
5888 + .name = "PCF8584 ISA adapter",
5889 + .id = I2C_HW_P_ELEK,
5890 + .algo_data = &pcf_isa_data,
5893 -int __init i2c_pcfisa_init(void)
5894 +static int __init i2c_pcfisa_init(void)
5898 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
5900 - DEB3(printk("i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
5901 + DEB3(printk(KERN_DEBUG "i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
5903 /* UP2000 board has this register set to 0xe1,
5905 (this can be read from cypress) */
5906 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
5907 - printk("i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
5908 + printk(KERN_INFO "i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
5912 /* sanity checks for mmapped I/O */
5913 if (mmapped && base < 0xc8000) {
5914 - printk("i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
5915 + printk(KERN_ERR "i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
5919 - printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n");
5920 + printk(KERN_INFO "i2c-elektor.o: i2c pcf8584-isa adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5923 @@ -280,23 +245,39 @@
5926 -#if (LINUX_VERSION_CODE >= 0x020301)
5927 init_waitqueue_head(&pcf_wait);
5929 - if (pcf_isa_init() == 0) {
5930 - if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5933 + if (pcf_isa_init())
5936 + if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5939 - printk("i2c-elektor.o: found device at %#x.\n", base);
5940 + printk(KERN_ERR "i2c-elektor.o: found device at %#x.\n", base);
5951 + release_region(base , 2);
5957 +static void i2c_pcfisa_exit(void)
5959 + i2c_pcf_del_bus(&pcf_isa_ops);
5967 + release_region(base , 2);
5971 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
5972 MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
5973 @@ -310,14 +291,4 @@
5974 MODULE_PARM(i2c_debug, "i");
5976 -int init_module(void)
5978 - return i2c_pcfisa_init();
5981 -void cleanup_module(void)
5983 - i2c_pcf_del_bus(&pcf_isa_ops);
5988 +module_init(i2c_pcfisa_init);
5989 +module_exit(i2c_pcfisa_exit);
5990 --- linux-old/include/linux/i2c-elektor.h Sun Aug 31 14:51:55 CEST 2003
5991 +++ linux/include/linux/i2c-elektor.h Sun Aug 31 14:51:55 CEST 2003
5993 -/* ------------------------------------------------------------------------- */
5994 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
5995 -/* ------------------------------------------------------------------------- */
5996 -/* Copyright (C) 1995-97 Simon G. Vogl
5997 - 1998-99 Hans Berglund
5999 - This program is free software; you can redistribute it and/or modify
6000 - it under the terms of the GNU General Public License as published by
6001 - the Free Software Foundation; either version 2 of the License, or
6002 - (at your option) any later version.
6004 - This program is distributed in the hope that it will be useful,
6005 - but WITHOUT ANY WARRANTY; without even the implied warranty of
6006 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6007 - GNU General Public License for more details.
6009 - You should have received a copy of the GNU General Public License
6010 - along with this program; if not, write to the Free Software
6011 - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6012 -/* ------------------------------------------------------------------------- */
6014 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6015 - Frodo Looijaard <frodol@dds.nl> */
6019 -#ifndef I2C_PCF_ELEKTOR_H
6020 -#define I2C_PCF_ELEKTOR_H 1
6023 - * This struct contains the hw-dependent functions of PCF8584 adapters to
6024 - * manipulate the registers, and to init any hw-specific features.
6025 - * vdovikin: removed: this module in real supports only one device,
6026 - * due to missing arguments in some functions, called from the algo-pcf module.
6027 - * Sometimes it's need to be rewriten -
6028 - * but for now just remove this for simpler reading */
6031 -struct i2c_pcf_isa {
6039 -#endif /* PCF_ELEKTOR_H */
6040 --- linux-old/drivers/i2c/i2c-elv.c Sun Aug 31 14:51:55 CEST 2003
6041 +++ linux/drivers/i2c/i2c-elv.c Sun Aug 31 14:51:55 CEST 2003
6043 Frodo Looijaard <frodol@dds.nl> */
6048 #include <linux/kernel.h>
6050 #include <linux/delay.h>
6051 #include <linux/slab.h>
6052 -#include <linux/version.h>
6053 #include <linux/init.h>
6055 -#include <asm/uaccess.h>
6057 #include <linux/ioport.h>
6058 -#include <asm/io.h>
6059 #include <linux/errno.h>
6060 #include <linux/i2c.h>
6061 #include <linux/i2c-algo-bit.h>
6062 +#include <asm/io.h>
6064 #define DEFAULT_BASE 0x378
6066 static int bit_elv_init(void)
6068 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6071 - /* test for ELV adap. */
6072 - if (inb(base+1) & 0x80) { /* BUSY should be high */
6073 - DEBINIT(printk("i2c-elv.o: Busy was low.\n"));
6076 - outb(0x0c,base+2); /* SLCT auf low */
6078 - if ( !(inb(base+1) && 0x10) ) {
6079 - outb(0x04,base+2);
6080 - DEBINIT(printk("i2c-elv.o: Select was high.\n"));
6084 - request_region(base,(base == 0x3bc)? 3 : 8,
6085 - "i2c (ELV adapter)");
6087 - bit_elv_setsda((void*)base,1);
6088 - bit_elv_setscl((void*)base,1);
6089 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
6090 + "i2c (ELV adapter)"))
6093 + if (inb(base+1) & 0x80) { /* BUSY should be high */
6094 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
6098 + outb(0x0c,base+2); /* SLCT auf low */
6100 + if (!(inb(base+1) && 0x10)) {
6101 + outb(0x04,base+2);
6102 + DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
6108 -static void __exit bit_elv_exit(void)
6110 - release_region( base , (base == 0x3bc)? 3 : 8 );
6113 -static int bit_elv_reg(struct i2c_client *client)
6116 + bit_elv_setsda((void*)base,1);
6117 + bit_elv_setscl((void*)base,1);
6121 -static int bit_elv_unreg(struct i2c_client *client)
6126 -static void bit_elv_inc_use(struct i2c_adapter *adap)
6129 - MOD_INC_USE_COUNT;
6133 -static void bit_elv_dec_use(struct i2c_adapter *adap)
6136 - MOD_DEC_USE_COUNT;
6139 + release_region(base , (base == 0x3bc) ? 3 : 8);
6143 @@ -150,26 +119,23 @@
6145 static struct i2c_algo_bit_data bit_elv_data = {
6151 - 80, 80, 100, /* waits, timeout */
6152 + .setsda = bit_elv_setsda,
6153 + .setscl = bit_elv_setscl,
6154 + .getsda = bit_elv_getsda,
6155 + .getscl = bit_elv_getscl,
6161 static struct i2c_adapter bit_elv_ops = {
6162 - "ELV Parallel port adaptor",
6170 + .owner = THIS_MODULE,
6171 + .name = "ELV Parallel port adaptor",
6172 + .id = I2C_HW_B_ELV,
6173 + .algo_data = &bit_elv_data,
6176 -int __init i2c_bitelv_init(void)
6177 +static int __init i2c_bitelv_init(void)
6179 - printk("i2c-elv.o: i2c ELV parallel port adapter module\n");
6180 + printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6182 /* probe some values */
6183 @@ -191,29 +157,22 @@
6186 - printk("i2c-elv.o: found device at %#x.\n",base);
6187 + printk(KERN_DEBUG "i2c-elv.o: found device at %#x.\n",base);
6191 +static void __exit i2c_bitelv_exit(void)
6193 + i2c_bit_del_bus(&bit_elv_ops);
6194 + release_region(base , (base == 0x3bc) ? 3 : 8);
6200 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
6201 MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
6202 MODULE_LICENSE("GPL");
6205 MODULE_PARM(base, "i");
6207 -int init_module(void)
6209 - return i2c_bitelv_init();
6212 -void cleanup_module(void)
6214 - i2c_bit_del_bus(&bit_elv_ops);
6219 +module_init(i2c_bitelv_init);
6220 +module_exit(i2c_bitelv_exit);
6221 --- linux-old/drivers/i2c/i2c-frodo.c Sun Aug 31 14:51:55 CEST 2003
6222 +++ linux/drivers/i2c/i2c-frodo.c Sun Aug 31 14:51:55 CEST 2003
6226 + * linux/drivers/i2c/i2c-frodo.c
6228 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
6230 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
6231 + * Development board (Frodo).
6233 + * This source code is free software; you can redistribute it and/or
6234 + * modify it under the terms of the GNU General Public License
6235 + * version 2 as published by the Free Software Foundation.
6238 +#include <linux/module.h>
6239 +#include <linux/kernel.h>
6240 +#include <linux/init.h>
6241 +#include <linux/delay.h>
6242 +#include <linux/i2c.h>
6243 +#include <linux/i2c-algo-bit.h>
6244 +#include <asm/hardware.h>
6247 +static void frodo_setsda (void *data,int state)
6250 + FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
6252 + FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
6255 +static void frodo_setscl (void *data,int state)
6258 + FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
6260 + FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
6263 +static int frodo_getsda (void *data)
6265 + return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
6268 +static int frodo_getscl (void *data)
6270 + return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
6273 +static struct i2c_algo_bit_data bit_frodo_data = {
6274 + .setsda = frodo_setsda,
6275 + .setscl = frodo_setscl,
6276 + .getsda = frodo_getsda,
6277 + .getscl = frodo_getscl,
6283 +static struct i2c_adapter frodo_ops = {
6284 + .owner = THIS_MODULE,
6285 + .name = "Frodo adapter driver",
6286 + .id = I2C_HW_B_FRODO,
6287 + .algo_data = &bit_frodo_data,
6290 +static int __init i2c_frodo_init (void)
6292 + return i2c_bit_add_bus(&frodo_ops);
6295 +static void __exit i2c_frodo_exit (void)
6297 + i2c_bit_del_bus(&frodo_ops);
6300 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
6301 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
6302 +MODULE_LICENSE ("GPL");
6304 +module_init (i2c_frodo_init);
6305 +module_exit (i2c_frodo_exit);
6307 --- linux-old/include/linux/i2c-id.h Sun Aug 31 14:51:55 CEST 2003
6308 +++ linux/include/linux/i2c-id.h Sun Aug 31 14:51:55 CEST 2003
6310 /* ------------------------------------------------------------------------- */
6315 +#ifndef LINUX_I2C_ID_H
6316 +#define LINUX_I2C_ID_H
6321 * This file is part of the i2c-bus package and contains the identifier
6323 #define I2C_DRIVERID_SP5055 44 /* Satellite tuner */
6324 #define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */
6325 -#define I2C_DRIVERID_ADV717X 48 /* video encoder */
6326 +#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */
6327 +#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */
6328 +#define I2C_DRIVERID_ADV717x 48 /* ADV 7175/7176 video encoder */
6329 +#define I2C_DRIVERID_ZR36067 49 /* Zoran 36067 video encoder */
6330 +#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */
6331 +#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */
6332 +#define I2C_DRIVERID_STM41T00 52 /* real time clock */
6333 +#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
6334 +#define I2C_DRIVERID_ADV7170 54 /* video encoder */
6335 +#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */
6339 #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */
6341 #define I2C_DRIVERID_I2CDEV 900
6342 #define I2C_DRIVERID_I2CPROC 901
6343 +#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
6344 +#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */
6346 /* IDs -- Use DRIVERIDs 1000-1999 for sensors.
6347 @@ -129,4 +143,22 @@
6348 #define I2C_DRIVERID_IT87 1026
6349 #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
6350 +#define I2C_DRIVERID_FSCPOS 1028
6351 +#define I2C_DRIVERID_FSCSCY 1029
6352 +#define I2C_DRIVERID_PCF8591 1030
6353 +#define I2C_DRIVERID_SMSC47M1 1031
6354 +#define I2C_DRIVERID_VT1211 1032
6355 +#define I2C_DRIVERID_LM92 1033
6356 +#define I2C_DRIVERID_VT8231 1034
6357 +#define I2C_DRIVERID_SMARTBATT 1035
6358 +#define I2C_DRIVERID_BMCSENSORS 1036
6359 +#define I2C_DRIVERID_FS451 1037
6360 +#define I2C_DRIVERID_W83627HF 1038
6361 +#define I2C_DRIVERID_LM85 1039
6362 +#define I2C_DRIVERID_LM83 1040
6363 +#define I2C_DRIVERID_SAA1064 1041
6364 +#define I2C_DRIVERID_LM90 1042
6365 +#define I2C_DRIVERID_ASB100 1043
6366 +#define I2C_DRIVERID_MAX6650 1044
6367 +#define I2C_DRIVERID_XEONTEMP 1045
6370 @@ -145,8 +177,16 @@
6371 #define I2C_ALGO_SAA7146 0x060000 /* SAA 7146 video decoder bus */
6372 #define I2C_ALGO_ACB 0x070000 /* ACCESS.bus algorithm */
6374 +#define I2C_ALGO_IIC 0x080000 /* ITE IIC bus */
6375 +#define I2C_ALGO_SAA7134 0x090000
6376 +#define I2C_ALGO_MPC824X 0x0a0000 /* Motorola 8240 / 8245 */
6377 +#define I2C_ALGO_IPMI 0x0b0000 /* IPMI dummy adapter */
6378 +#define I2C_ALGO_IPMB 0x0c0000 /* IPMB adapter */
6379 +#define I2C_ALGO_MPC107 0x0d0000
6380 #define I2C_ALGO_EC 0x100000 /* ACPI embedded controller */
6382 #define I2C_ALGO_MPC8XX 0x110000 /* MPC8xx PowerPC I2C algorithm */
6383 +#define I2C_ALGO_OCP 0x120000 /* IBM or otherwise On-chip I2C algorithm */
6384 +#define I2C_ALGO_BITHS 0x130000 /* enhanced bit style adapters */
6385 +#define I2C_ALGO_OCP_IOP3XX 0x140000 /* XSCALE IOP3XX On-chip I2C alg */
6387 #define I2C_ALGO_EXP 0x800000 /* experimental */
6388 @@ -176,7 +216,15 @@
6389 #define I2C_HW_B_VOO 0x0b /* 3dfx Voodoo 3 / Banshee */
6390 #define I2C_HW_B_PPORT 0x0c /* Primitive parallel port adapter */
6391 +#define I2C_HW_B_SAVG 0x0d /* Savage 4 */
6392 +#define I2C_HW_B_SCX200 0x0e /* Nat'l Semi SCx200 I2C */
6393 #define I2C_HW_B_RIVA 0x10 /* Riva based graphics cards */
6394 #define I2C_HW_B_IOC 0x11 /* IOC bit-wiggling */
6395 #define I2C_HW_B_TSUNA 0x12 /* DEC Tsunami chipset */
6396 +#define I2C_HW_B_FRODO 0x13 /* 2d3D, Inc. SA-1110 Development Board */
6397 +#define I2C_HW_B_OMAHA 0x14 /* Omaha I2C interface (ARM) */
6398 +#define I2C_HW_B_GUIDE 0x15 /* Guide bit-basher */
6399 +#define I2C_HW_B_IXP2000 0x16 /* GPIO on IXP2000 systems */
6400 +#define I2C_HW_B_IXP425 0x17 /* GPIO on IXP425 systems */
6401 +#define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */
6403 /* --- PCF 8584 based algorithms */
6404 @@ -188,7 +236,19 @@
6405 #define I2C_HW_ACPI_EC 0x00
6407 +/* --- MPC824x PowerPC adapters */
6408 +#define I2C_HW_MPC824X 0x00 /* Motorola 8240 / 8245 */
6410 /* --- MPC8xx PowerPC adapters */
6411 #define I2C_HW_MPC8XX_EPON 0x00 /* Eponymous MPC8xx I2C adapter */
6413 +/* --- ITE based algorithms */
6414 +#define I2C_HW_I_IIC 0x00 /* controller on the ITE */
6416 +/* --- PowerPC on-chip adapters */
6417 +#define I2C_HW_OCP 0x00 /* IBM on-chip I2C adapter */
6419 +/* --- XSCALE on-chip adapters */
6420 +#define I2C_HW_IOP321 0x00
6422 /* --- SMBus only adapters */
6423 #define I2C_HW_SMBUS_PIIX4 0x00
6424 @@ -200,7 +260,21 @@
6425 #define I2C_HW_SMBUS_SIS5595 0x06
6426 #define I2C_HW_SMBUS_ALI1535 0x07
6427 +#define I2C_HW_SMBUS_SIS630 0x08
6428 +#define I2C_HW_SMBUS_SIS645 0x09
6429 +#define I2C_HW_SMBUS_AMD8111 0x0a
6430 +#define I2C_HW_SMBUS_SCX200 0x0b
6431 +#define I2C_HW_SMBUS_NFORCE2 0x0c
6433 /* --- ISA pseudo-adapter */
6434 #define I2C_HW_ISA 0x00
6436 -#endif /* I2C_ID_H */
6437 +/* --- IPMI pseudo-adapter */
6438 +#define I2C_HW_IPMI 0x00
6440 +/* --- IPMB adapter */
6441 +#define I2C_HW_IPMB 0x00
6443 +/* --- MCP107 adapter */
6444 +#define I2C_HW_MPC107 0x00
6446 +#endif /* LINUX_I2C_ID_H */
6447 --- linux-old/drivers/i2c/i2c-max1617.c Sun Aug 31 14:51:56 CEST 2003
6448 +++ linux/drivers/i2c/i2c-max1617.c Sun Aug 31 14:51:56 CEST 2003
6451 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
6453 - * This program is free software; you can redistribute it and/or
6454 - * modify it under the terms of the GNU General Public License
6455 - * as published by the Free Software Foundation; either version 2
6456 - * of the License, or (at your option) any later version.
6458 - * This program is distributed in the hope that it will be useful,
6459 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
6460 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6461 - * GNU General Public License for more details.
6463 - * You should have received a copy of the GNU General Public License
6464 - * along with this program; if not, write to the Free Software
6465 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
6469 - * SMBus/I2C device driver for the MAX1617 temperature sensor
6472 -#include <linux/config.h>
6473 -#include <linux/kernel.h>
6474 -#include <linux/module.h>
6475 -#include <linux/slab.h>
6476 -#include <linux/timer.h>
6477 -#include <linux/errno.h>
6479 -#include <linux/i2c.h>
6480 -#include <linux/i2c-algo-sibyte.h>
6482 -#define IF_NAME "max1617"
6484 -#define MAX1617_SMBUS_DEV 0x2A
6485 -#define MAX1617_LOCAL 0
6486 -#define MAX1617_REMOTE 1
6487 -#define MAX1617_STATUS 2
6488 -#define MAX1617_POLL_PERIOD 10
6490 -static int max1617_verbose = 0;
6491 -static int max1617_polling = 1;
6493 -/* Addresses to scan */
6494 -static unsigned short normal_i2c[] = {MAX1617_SMBUS_DEV, I2C_CLIENT_END};
6495 -static unsigned short normal_i2c_range[] = {I2C_CLIENT_END};
6496 -static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
6497 -static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
6498 -static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
6499 -static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
6500 -static unsigned short force[2] = { I2C_CLIENT_END, I2C_CLIENT_END };
6502 -static struct i2c_client_address_data addr_data = {
6503 - normal_i2c, normal_i2c_range,
6504 - probe, probe_range,
6505 - ignore, ignore_range,
6509 -struct max1617_info {
6510 - struct i2c_client *client;
6511 - struct timer_list timer;
6516 -static int max1617_probe(struct i2c_adapter *adap);
6517 -static int max1617_detach(struct i2c_client *device);
6518 -static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg);
6519 -static void max1617_inc_use(struct i2c_client *device);
6520 -static void max1617_dec_use(struct i2c_client *device);
6522 -struct i2c_driver i2c_driver_max1617 = {
6524 - id: I2C_DRIVERID_MAX1617,
6525 - flags: I2C_DF_NOTIFY,
6526 - attach_adapter: max1617_probe,
6527 - detach_client: max1617_detach,
6528 - command: max1617_command,
6529 - inc_use: max1617_inc_use,
6530 - dec_use: max1617_dec_use
6533 -static int max1617_read(struct i2c_client *client, unsigned char subaddr)
6535 - return i2c_smbus_read_byte_data(client, subaddr);
6538 -/* poll the device, check for temperature/status changes */
6539 -static void max1617_update(unsigned long arg)
6541 - struct max1617_info *m = (struct max1617_info *)arg;
6542 - int status, remote, local;
6545 - status = max1617_read(m->client, MAX1617_STATUS);
6546 - remote = max1617_read(m->client, MAX1617_REMOTE);
6547 - local = max1617_read(m->client, MAX1617_LOCAL);
6548 - if (status < 0 || remote < 0 || local < 0) {
6549 - printk(KERN_ERR IF_NAME ": sensor device did not respond.\n");
6552 - if (status & 0x80) strcat(statstr,"Busy ");
6553 - if (status & 0x40) strcat(statstr,"HiTempLcl ");
6554 - if (status & 0x20) strcat(statstr,"LoTempLcl ");
6555 - if (status & 0x10) strcat(statstr,"HiTempRem ");
6556 - if (status & 0x08) strcat(statstr,"LoTempRem ");
6557 - if (status & 0x04) strcat(statstr,"Fault ");
6559 - if (max1617_verbose || (local != m->local) || (remote != m->remote)) {
6560 - printk(KERN_DEBUG IF_NAME ": Temperature - CPU: %dC Board: %dC Status:%02X [ %s]\n",
6561 - remote, local, status, statstr);
6564 - m->remote = remote;
6565 - mod_timer(&m->timer, jiffies + (HZ * MAX1617_POLL_PERIOD));
6569 -/* attach to an instance of the device that was probed on a bus */
6570 -static int max1617_attach(struct i2c_adapter *adap, int addr, unsigned short flags, int kind)
6572 - struct max1617_info *m;
6573 - struct i2c_client *client;
6576 - client = kmalloc(sizeof(*client), GFP_KERNEL);
6577 - if (client == NULL)
6579 - client->adapter = adap;
6580 - client->addr = addr;
6581 - client->driver = &i2c_driver_max1617;
6582 - sprintf(client->name, "%s-%x", IF_NAME, addr);
6583 - if ((err = i2c_attach_client(client)) < 0) {
6588 - m = kmalloc(sizeof(*m), GFP_KERNEL);
6590 - i2c_detach_client(client);
6594 - m->client = client;
6595 - m->remote = m->local = 0;
6596 - init_timer(&m->timer);
6597 - m->timer.data = (unsigned long)m;
6598 - m->timer.function = max1617_update;
6599 - if (max1617_polling) {
6600 - m->timer.expires = jiffies + (HZ * MAX1617_POLL_PERIOD);
6601 - add_timer(&m->timer);
6607 -/* initiate probing on a particular bus */
6608 -static int max1617_probe(struct i2c_adapter *adap)
6610 - /* Look for this device on the given adapter (bus) */
6611 - if (adap->id == (I2C_ALGO_SIBYTE | I2C_HW_SIBYTE))
6612 - return i2c_probe(adap, &addr_data, &max1617_attach);
6617 -static int max1617_detach(struct i2c_client *device)
6619 - struct max1617_info *m = (struct max1617_info *)device->data;
6622 - if ((rc = i2c_detach_client(device)) != 0) {
6623 - printk(IF_NAME "detach failed: %d\n", rc);
6626 - if (max1617_polling)
6627 - del_timer(&m->timer);
6633 -static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg)
6638 -static void max1617_inc_use(struct i2c_client *client)
6641 - MOD_INC_USE_COUNT;
6645 -static void max1617_dec_use(struct i2c_client *client)
6648 - MOD_DEC_USE_COUNT;
6652 -void i2c_max1617_init(void)
6654 - i2c_add_driver(&i2c_driver_max1617);
6660 -MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
6661 -MODULE_DESCRIPTION("Max 1617 temperature sensor for SiByte SOC boards");
6662 -MODULE_LICENSE("GPL");
6664 -int init_module(void)
6666 - i2c_max1617_init();
6670 -void cleanup_module(void)
6672 - i2c_del_driver(&i2c_driver_max1617);
6675 --- linux-old/drivers/i2c/i2c-pcf-epp.c Sun Aug 31 14:51:56 CEST 2003
6676 +++ linux/drivers/i2c/i2c-pcf-epp.c Sun Aug 31 14:51:56 CEST 2003
6678 +/* ------------------------------------------------------------------------- */
6679 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters */
6680 +/* ------------------------------------------------------------------------- */
6681 +/* Copyright (C) 1998-99 Hans Berglund
6683 + This program is free software; you can redistribute it and/or modify
6684 + it under the terms of the GNU General Public License as published by
6685 + the Free Software Foundation; either version 2 of the License, or
6686 + (at your option) any later version.
6688 + This program is distributed in the hope that it will be useful,
6689 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6690 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6691 + GNU General Public License for more details.
6693 + You should have received a copy of the GNU General Public License
6694 + along with this program; if not, write to the Free Software
6695 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6696 +/* ------------------------------------------------------------------------- */
6698 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
6700 +#include <linux/kernel.h>
6701 +#include <linux/ioport.h>
6702 +#include <linux/module.h>
6703 +#include <linux/delay.h>
6704 +#include <linux/slab.h>
6705 +#include <linux/init.h>
6706 +#include <linux/parport.h>
6707 +#include <linux/i2c.h>
6708 +#include <linux/i2c-algo-pcf.h>
6709 +#include <asm/irq.h>
6710 +#include <asm/io.h>
6713 +struct i2c_pcf_epp {
6720 +#define DEFAULT_BASE 0x378
6721 +#define DEFAULT_IRQ 7
6722 +#define DEFAULT_CLOCK 0x1c
6723 +#define DEFAULT_OWN 0x55
6725 +static int base = 0;
6726 +static int irq = 0;
6727 +static int clock = 0;
6728 +static int own = 0;
6729 +static int i2c_debug=0;
6730 +static struct i2c_pcf_epp gpe;
6731 +static wait_queue_head_t pcf_wait;
6732 +static int pcf_pending;
6733 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
6735 +/* ----- global defines ----------------------------------------------- */
6736 +#define DEB(x) if (i2c_debug>=1) x
6737 +#define DEB2(x) if (i2c_debug>=2) x
6738 +#define DEB3(x) if (i2c_debug>=3) x
6739 +#define DEBE(x) x /* error messages */
6741 +/* --- Convenience defines for the EPP/SPP port: */
6742 +#define BASE ((struct i2c_pcf_epp *)(data))->pe_base
6743 +// #define DATA BASE /* SPP data port */
6744 +#define STAT (BASE+1) /* SPP status port */
6745 +#define CTRL (BASE+2) /* SPP control port */
6746 +#define EADD (BASE+3) /* EPP address port */
6747 +#define EDAT (BASE+4) /* EPP data port */
6749 +/* ----- local functions ---------------------------------------------- */
6751 +static void pcf_epp_setbyte(void *data, int ctl, int val)
6754 + if (gpe.pe_irq > 0) {
6755 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
6756 + val|I2C_PCF_ENI));
6757 + // set A0 pin HIGH
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)));
6762 + // EPP write data cycle
6763 + outb(val | I2C_PCF_ENI, EDAT);
6765 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
6766 + // set A0 pin HIGH
6767 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6771 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
6773 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6774 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
6775 + // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
6780 +static int pcf_epp_getbyte(void *data, int ctl)
6785 + // set A0 pin HIGH
6786 + outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6788 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
6791 + outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6793 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
6798 +static int pcf_epp_getown(void *data)
6800 + return (gpe.pe_own);
6804 +static int pcf_epp_getclock(void *data)
6806 + return (gpe.pe_clock);
6810 +static void pcf_epp_sleep(unsigned long timeout)
6812 + schedule_timeout( timeout * HZ);
6816 +static void pcf_epp_waitforpin(void) {
6819 + if (gpe.pe_irq > 0) {
6820 + spin_lock_irq(&irq_driver_lock);
6821 + if (pcf_pending == 0) {
6822 + interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
6827 + spin_unlock_irq(&irq_driver_lock);
6833 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
6835 + wake_up_interruptible(&pcf_wait);
6836 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
6840 +static int pcf_epp_init(void *data)
6842 + if (check_region(gpe.pe_base, 5) < 0 ) {
6844 + printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
6847 + request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
6850 + DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
6852 + if (gpe.pe_irq > 0) {
6853 + if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
6854 + printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
6857 + disable_irq(gpe.pe_irq);
6858 + enable_irq(gpe.pe_irq);
6860 + // EPP mode initialize
6861 + // enable interrupt from nINTR pin
6862 + outb(inb(CTRL)|0x14, CTRL);
6863 + // clear ERROR bit of STAT
6864 + outb(inb(STAT)|0x01, STAT);
6865 + outb(inb(STAT)&~0x01,STAT);
6870 +/* ------------------------------------------------------------------------
6871 + * Encapsulate the above functions in the correct operations structure.
6872 + * This is only done when more than one hardware adapter is supported.
6874 +static struct i2c_algo_pcf_data pcf_epp_data = {
6875 + .setpcf = pcf_epp_setbyte,
6876 + .getpcf = pcf_epp_getbyte,
6877 + .getown = pcf_epp_getown,
6878 + .getclock = pcf_epp_getclock,
6879 + .waitforpin = pcf_epp_waitforpin,
6885 +static struct i2c_adapter pcf_epp_ops = {
6886 + .owner = THIS_MODULE,
6887 + .name = "PCF8584 EPP adapter",
6888 + .id = I2C_HW_P_LP,
6889 + .algo_data = &pcf_epp_data,
6892 +static int __init i2c_pcfepp_init(void)
6894 + struct i2c_pcf_epp *pepp = &gpe;
6896 + printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6898 + pepp->pe_base = DEFAULT_BASE;
6900 + pepp->pe_base = base;
6903 + pepp->pe_irq = DEFAULT_IRQ;
6908 + pepp->pe_irq = irq;
6911 + pepp->pe_clock = DEFAULT_CLOCK;
6913 + pepp->pe_clock = clock;
6916 + pepp->pe_own = DEFAULT_OWN;
6918 + pepp->pe_own = own;
6920 + pcf_epp_data.data = (void *)pepp;
6921 + init_waitqueue_head(&pcf_wait);
6922 + if (pcf_epp_init(pepp) == 0) {
6924 + if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
6925 + printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
6926 + release_region(pepp->pe_base , 5);
6933 + printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
6937 +static void __exit pcf_epp_exit(void)
6939 + i2c_pcf_del_bus(&pcf_epp_ops);
6940 + if (gpe.pe_irq > 0) {
6941 + disable_irq(gpe.pe_irq);
6942 + free_irq(gpe.pe_irq, 0);
6944 + release_region(gpe.pe_base , 5);
6947 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
6948 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
6949 +MODULE_LICENSE("GPL");
6951 +MODULE_PARM(base, "i");
6952 +MODULE_PARM(irq, "i");
6953 +MODULE_PARM(clock, "i");
6954 +MODULE_PARM(own, "i");
6955 +MODULE_PARM(i2c_debug, "i");
6957 +module_init(i2c_pcfepp_init);
6958 +module_exit(pcf_epp_exit);
6959 --- linux-old/include/linux/i2c-pcf8584.h Sun Aug 31 14:51:56 CEST 2003
6960 +++ linux/include/linux/i2c-pcf8584.h Sun Aug 31 14:51:56 CEST 2003
6962 +/* -------------------------------------------------------------------- */
6963 +/* i2c-pcf8584.h: PCF 8584 global defines */
6964 +/* -------------------------------------------------------------------- */
6965 +/* Copyright (C) 1996 Simon G. Vogl
6966 + 1999 Hans Berglund
6968 + This program is free software; you can redistribute it and/or modify
6969 + it under the terms of the GNU General Public License as published by
6970 + the Free Software Foundation; either version 2 of the License, or
6971 + (at your option) any later version.
6973 + This program is distributed in the hope that it will be useful,
6974 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6975 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6976 + GNU General Public License for more details.
6978 + You should have received a copy of the GNU General Public License
6979 + along with this program; if not, write to the Free Software
6980 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6981 +/* -------------------------------------------------------------------- */
6983 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
6987 +#ifndef _LINUX_I2C_PCF8584_H
6988 +#define _LINUX_I2C_PCF8584_H
6990 +/* ----- Control register bits ---------------------------------------- */
6991 +#define I2C_PCF_PIN 0x80
6992 +#define I2C_PCF_ESO 0x40
6993 +#define I2C_PCF_ES1 0x20
6994 +#define I2C_PCF_ES2 0x10
6995 +#define I2C_PCF_ENI 0x08
6996 +#define I2C_PCF_STA 0x04
6997 +#define I2C_PCF_STO 0x02
6998 +#define I2C_PCF_ACK 0x01
7000 +#define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7001 +#define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
7002 +#define I2C_PCF_REPSTART ( I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
7003 +#define I2C_PCF_IDLE (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_ACK)
7005 +/* ----- Status register bits ----------------------------------------- */
7006 +/*#define I2C_PCF_PIN 0x80 as above*/
7008 +#define I2C_PCF_INI 0x40 /* 1 if not initialized */
7009 +#define I2C_PCF_STS 0x20
7010 +#define I2C_PCF_BER 0x10
7011 +#define I2C_PCF_AD0 0x08
7012 +#define I2C_PCF_LRB 0x08
7013 +#define I2C_PCF_AAS 0x04
7014 +#define I2C_PCF_LAB 0x02
7015 +#define I2C_PCF_BB 0x01
7017 +/* ----- Chip clock frequencies --------------------------------------- */
7018 +#define I2C_PCF_CLK3 0x00
7019 +#define I2C_PCF_CLK443 0x10
7020 +#define I2C_PCF_CLK6 0x14
7021 +#define I2C_PCF_CLK 0x18
7022 +#define I2C_PCF_CLK12 0x1c
7024 +/* ----- transmission frequencies ------------------------------------- */
7025 +#define I2C_PCF_TRNS90 0x00 /* 90 kHz */
7026 +#define I2C_PCF_TRNS45 0x01 /* 45 kHz */
7027 +#define I2C_PCF_TRNS11 0x02 /* 11 kHz */
7028 +#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */
7031 +/* ----- Access to internal registers according to ES1,ES2 ------------ */
7032 +/* they are mapped to the data port ( a0 = 0 ) */
7033 +/* available when ESO == 0 : */
7035 +#define I2C_PCF_OWNADR 0
7036 +#define I2C_PCF_INTREG I2C_PCF_ES2
7037 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7039 +#endif /* _LINUX_I2C_PCF8584_H */
7040 --- linux-old/drivers/i2c/i2c-philips-par.c Sun Aug 31 14:51:56 CEST 2003
7041 +++ linux/drivers/i2c/i2c-philips-par.c Sun Aug 31 14:51:56 CEST 2003
7043 Frodo Looijaard <frodol@dds.nl> */
7048 #include <linux/kernel.h>
7050 #include <linux/stddef.h>
7051 #include <linux/parport.h>
7053 +#include <linux/slab.h>
7054 #include <linux/i2c.h>
7055 #include <linux/i2c-algo-bit.h>
7058 -#define __exit __init
7063 @@ -131,24 +127,4 @@
7066 -static int bit_lp_reg(struct i2c_client *client)
7071 -static int bit_lp_unreg(struct i2c_client *client)
7076 -static void bit_lp_inc_use(struct i2c_adapter *adap)
7078 - MOD_INC_USE_COUNT;
7081 -static void bit_lp_dec_use(struct i2c_adapter *adap)
7083 - MOD_DEC_USE_COUNT;
7086 /* ------------------------------------------------------------------------
7087 * Encapsulate the above functions in the correct operations structure.
7088 @@ -157,31 +133,26 @@
7090 static struct i2c_algo_bit_data bit_lp_data = {
7096 - 80, 80, 100, /* waits, timeout */
7097 + .setsda = bit_lp_setsda,
7098 + .setscl = bit_lp_setscl,
7099 + .getsda = bit_lp_getsda,
7100 + .getscl = bit_lp_getscl,
7106 static struct i2c_algo_bit_data bit_lp_data2 = {
7112 - 80, 80, 100, /* waits, timeout */
7113 + .setsda = bit_lp_setsda2,
7114 + .setscl = bit_lp_setscl2,
7115 + .getsda = bit_lp_getsda2,
7121 static struct i2c_adapter bit_lp_ops = {
7122 - "Philips Parallel port adapter",
7131 + .owner = THIS_MODULE,
7132 + .name = "Philips Parallel port adapter",
7133 + .id = I2C_HW_B_LP,
7139 - printk("i2c-philips-par: Unable to malloc.\n");
7140 + printk(KERN_ERR "i2c-philips-par: Unable to malloc.\n");
7144 - printk("i2c-philips-par.o: attaching to %s\n", port->name);
7145 + printk(KERN_DEBUG "i2c-philips-par.o: attaching to %s\n", port->name);
7147 adapter->pdev = parport_register_device(port, "i2c-philips-par",
7150 if (!adapter->pdev) {
7151 - printk("i2c-philips-par: Unable to register with parport.\n");
7152 + printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
7156 @@ -211,6 +183,10 @@
7157 adapter->bit_lp_data.data = port;
7159 + if (parport_claim_or_block(adapter->pdev) < 0 ) {
7160 + printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
7164 /* reset hardware to sane state */
7165 - parport_claim_or_block(adapter->pdev);
7166 bit_lp_setsda(port, 1);
7167 bit_lp_setscl(port, 1);
7169 if (i2c_bit_add_bus(&adapter->adapter) < 0)
7171 - printk("i2c-philips-par: Unable to register with I2C.\n");
7172 + printk(KERN_ERR "i2c-philips-par: Unable to register with I2C.\n");
7173 parport_unregister_device(adapter->pdev);
7178 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7179 static struct parport_driver i2c_driver = {
7181 @@ -258,19 +233,10 @@
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);
7202 @@ -279,11 +245,5 @@
7203 void __exit i2c_bitlp_exit(void)
7205 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7206 parport_unregister_driver(&i2c_driver);
7208 - struct parport *port;
7209 - for (port = parport_enumerate(); port; port=port->next)
7210 - i2c_parport_detach(port);
7214 @@ -296,13 +256,4 @@
7215 MODULE_PARM(type, "i");
7218 -int init_module(void)
7220 - return i2c_bitlp_init();
7223 -void cleanup_module(void)
7228 +module_init(i2c_bitlp_init);
7229 +module_exit(i2c_bitlp_exit);
7230 --- linux-old/drivers/i2c/i2c-pport.c Sun Aug 31 14:51:56 CEST 2003
7231 +++ linux/drivers/i2c/i2c-pport.c Sun Aug 31 14:51:56 CEST 2003
7233 +/* ------------------------------------------------------------------------- */
7234 +/* i2c-pport.c i2c-hw access for primitive i2c par. port adapter */
7235 +/* ------------------------------------------------------------------------- */
7236 +/* Copyright (C) 2001 Daniel Smolik
7238 + This program is free software; you can redistribute it and/or modify
7239 + it under the terms of the GNU General Public License as published by
7240 + the Free Software Foundation; either version 2 of the License, or
7241 + (at your option) any later version.
7243 + This program is distributed in the hope that it will be useful,
7244 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7245 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7246 + GNU General Public License for more details.
7248 + You should have received a copy of the GNU General Public License
7249 + along with this program; if not, write to the Free Software
7250 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7251 +/* ------------------------------------------------------------------------- */
7254 + See doc/i2c-pport for instructions on wiring to the
7255 + parallel port connector.
7257 + Cut & paste :-) based on Velleman K9000 driver by Simon G. Vogl
7261 +#include <linux/kernel.h>
7262 +#include <linux/module.h>
7263 +#include <linux/delay.h>
7264 +#include <linux/slab.h>
7265 +#include <linux/init.h>
7266 +#include <linux/ioport.h>
7267 +#include <linux/errno.h>
7268 +#include <linux/i2c.h>
7269 +#include <linux/i2c-algo-bit.h>
7270 +#include <asm/io.h>
7273 +#define DEFAULT_BASE 0x378
7275 +static unsigned char PortData = 0;
7277 +/* ----- global defines ----------------------------------------------- */
7278 +#define DEB(x) /* should be reasonable open, close &c. */
7279 +#define DEB2(x) /* low level debugging - very slow */
7280 +#define DEBE(x) x /* error messages */
7281 +#define DEBINIT(x) x /* detection status messages */
7283 +/* --- Convenience defines for the parallel port: */
7284 +#define BASE (unsigned int)(data)
7285 +#define DATA BASE /* Centronics data port */
7286 +#define STAT (BASE+1) /* Centronics status port */
7287 +#define CTRL (BASE+2) /* Centronics control port */
7289 +/* we will use SDA - Auto Linefeed(14) bit 1 POUT */
7290 +/* we will use SCL - Initialize printer(16) BUSY bit 2*/
7292 +#define SET_SCL | 0x04
7293 +#define CLR_SCL & 0xFB
7298 +#define SET_SDA & 0x04
7299 +#define CLR_SDA | 0x02
7302 +/* ----- local functions ---------------------------------------------- */
7305 +static void bit_pport_setscl(void *data, int state)
7309 + PortData = PortData SET_SCL;
7312 + PortData = PortData CLR_SCL;
7314 + outb(PortData, CTRL);
7317 +static void bit_pport_setsda(void *data, int state)
7321 + PortData = PortData SET_SDA;
7324 + PortData = PortData CLR_SDA;
7326 + outb(PortData, CTRL);
7329 +static int bit_pport_getscl(void *data)
7332 + return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
7335 +static int bit_pport_getsda(void *data)
7337 + return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
7340 +static int bit_pport_init(void)
7342 + if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
7345 + /* test for PPORT adap. */
7348 + PortData=inb(base+2);
7349 + PortData= (PortData SET_SDA) SET_SCL;
7350 + outb(PortData,base+2);
7352 + if (!(inb(base+2) | 0x06)) { /* SDA and SCL will be high */
7353 + DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
7357 + /*SCL high and SDA low*/
7358 + PortData = PortData SET_SCL CLR_SDA;
7359 + outb(PortData,base+2);
7360 + schedule_timeout(400);
7361 + if ( !(inb(base+2) | 0x4) ) {
7362 + //outb(0x04,base+2);
7363 + DEBINIT(printk("i2c-port.o: SDA was high.\n"));
7367 + bit_pport_setsda((void*)base,1);
7368 + bit_pport_setscl((void*)base,1);
7374 +/* ------------------------------------------------------------------------
7375 + * Encapsulate the above functions in the correct operations structure.
7376 + * This is only done when more than one hardware adapter is supported.
7378 +static struct i2c_algo_bit_data bit_pport_data = {
7379 + .setsda = bit_pport_setsda,
7380 + .setscl = bit_pport_setscl,
7381 + .getsda = bit_pport_getsda,
7382 + .getscl = bit_pport_getscl,
7388 +static struct i2c_adapter bit_pport_ops = {
7389 + .owner = THIS_MODULE,
7390 + .name = "Primitive Parallel port adaptor",
7391 + .id = I2C_HW_B_PPORT,
7392 + .algo_data = &bit_pport_data,
7395 +int __init i2c_bitpport_init(void)
7397 + printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7400 + /* probe some values */
7401 + base=DEFAULT_BASE;
7402 + bit_pport_data.data=(void*)DEFAULT_BASE;
7403 + if (bit_pport_init()==0) {
7404 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7410 + bit_pport_data.data=(void*)base;
7411 + if (bit_pport_init()==0) {
7412 + if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7418 + printk("i2c-pport.o: found device at %#x.\n",base);
7422 +static void __exit i2c_bitpport_exit(void)
7424 + i2c_bit_del_bus(&bit_pport_ops);
7425 + release_region((base+2),1);
7430 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
7431 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
7432 +MODULE_LICENSE("GPL");
7434 +MODULE_PARM(base, "i");
7436 +module_init(i2c_bitpport_init);
7437 +module_exit(i2c_bitpport_exit);
7438 --- linux-old/drivers/i2c/i2c-proc.c Sun Aug 31 14:51:57 CEST 2003
7439 +++ linux/drivers/i2c/i2c-proc.c Sun Aug 31 14:51:57 CEST 2003
7443 -#include <linux/version.h>
7444 #include <linux/module.h>
7445 #include <linux/kernel.h>
7447 #include <linux/sysctl.h>
7448 #include <linux/proc_fs.h>
7449 +#include <linux/init.h>
7450 #include <linux/ioport.h>
7451 -#include <asm/uaccess.h>
7453 #include <linux/i2c.h>
7454 #include <linux/i2c-proc.h>
7455 +#include <asm/uaccess.h>
7457 -#include <linux/init.h>
7459 -/* FIXME need i2c versioning */
7460 -#define LM_DATE "20010825"
7461 -#define LM_VERSION "2.6.1"
7463 -#ifndef THIS_MODULE
7464 -#define THIS_MODULE NULL
7467 -static int i2c_create_name(char **name, const char *prefix,
7468 - struct i2c_adapter *adapter, int addr);
7469 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7470 long *results, int magnitude);
7471 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7472 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7473 long *results, int magnitude);
7474 static int i2c_proc_chips(ctl_table * ctl, int write,
7478 -int __init sensors_init(void);
7480 #define SENSORS_ENTRY_MAX 20
7481 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
7483 static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
7484 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
7485 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
7486 -static void i2c_fill_inode(struct inode *inode, int fill);
7487 -static void i2c_dir_fill_inode(struct inode *inode, int fill);
7488 -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */
7490 -static ctl_table sysctl_table[] = {
7491 - {CTL_DEV, "dev", NULL, 0, 0555},
7493 - {DEV_SENSORS, "sensors", NULL, 0, 0555},
7495 - {0, NULL, NULL, 0, 0555},
7499 static ctl_table i2c_proc_dev_sensors[] = {
7502 static struct ctl_table_header *i2c_proc_header;
7503 -static int i2c_initialized;
7505 /* This returns a nice name for a new directory; for example lm78-isa-0310
7506 @@ -107,23 +77,38 @@
7507 a LM75 chip on the third i2c bus at address 0x4e).
7508 name is allocated first. */
7509 -int i2c_create_name(char **name, const char *prefix,
7510 - struct i2c_adapter *adapter, int addr)
7511 +static char *generate_name(struct i2c_client *client, const char *prefix)
7513 - char name_buffer[50];
7515 - if (i2c_is_isa_adapter(adapter))
7516 + struct i2c_adapter *adapter = client->adapter;
7517 + int addr = client->addr;
7518 + char name_buffer[50], *name;
7520 + if (i2c_is_isa_adapter(adapter)) {
7521 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
7523 - if ((id = i2c_adapter_id(adapter)) < 0)
7525 + } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
7526 + int id = i2c_adapter_id(adapter);
7528 + return ERR_PTR(-ENOENT);
7529 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
7530 + } else { /* dummy adapter, generate prefix */
7533 + sprintf(name_buffer, "%s-", prefix);
7534 + end = strlen(name_buffer);
7536 + for (i = 0; i < 32; i++) {
7537 + if (adapter->algo->name[i] == ' ')
7539 + name_buffer[end++] = tolower(adapter->algo->name[i]);
7542 + name_buffer[end] = 0;
7543 + sprintf(name_buffer + end, "-%04x", addr);
7545 - *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7547 - printk (KERN_WARNING "i2c_create_name: not enough memory\n");
7550 - strcpy(*name, name_buffer);
7553 + name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7555 + return ERR_PTR(-ENOMEM);
7556 + strcpy(name, name_buffer);
7560 @@ -134,142 +119,89 @@
7561 copied in memory. The extra2 field of each file is set to point to client.
7562 If any driver wants subdirectories within the newly created directory,
7563 - this function must be updated!
7564 - controlling_mod is the controlling module. It should usually be
7565 - THIS_MODULE when calling. Note that this symbol is not defined in
7566 - kernels before 2.3.13; define it to NULL in that case. We will not use it
7567 - for anything older than 2.3.27 anyway. */
7568 + this function must be updated! */
7569 int i2c_register_entry(struct i2c_client *client, const char *prefix,
7570 - ctl_table * ctl_template,
7571 - struct module *controlling_mod)
7572 + struct ctl_table *ctl_template)
7574 - int i, res, len, id;
7575 - ctl_table *new_table;
7577 - struct ctl_table_header *new_header;
7578 + struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
7579 + struct ctl_table_header *hdr;
7580 + struct ctl_table *tmp, *leaf;
7584 - if ((res = i2c_create_name(&name, prefix, client->adapter,
7585 - client->addr))) return res;
7586 + name = generate_name(client, prefix);
7588 + return PTR_ERR(name);
7590 - for (id = 0; id < SENSORS_ENTRY_MAX; id++)
7591 - if (!i2c_entries[id]) {
7594 - if (id == SENSORS_ENTRY_MAX) {
7597 + for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
7598 + if (!i2c_entries[id])
7604 + goto out_free_name;
7607 while (ctl_template[len].procname)
7610 - if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
7615 - memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
7616 - new_table[0].child = &new_table[2];
7617 - new_table[2].child = &new_table[4];
7618 - new_table[4].child = &new_table[6];
7619 - new_table[4].procname = name;
7620 - new_table[4].ctl_name = id;
7621 - memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
7622 - for (i = 6; i < len; i++)
7623 - new_table[i].extra2 = client;
7625 - if (!(new_header = register_sysctl_table(new_table, 0))) {
7631 - i2c_entries[id - 256] = new_header;
7633 - i2c_clients[id - 256] = client;
7635 - if (!new_header || !new_header->ctl_table ||
7636 - !new_header->ctl_table->child ||
7637 - !new_header->ctl_table->child->child ||
7638 - !new_header->ctl_table->child->child->de) {
7640 - ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
7644 - i2c_inodes[id - 256] =
7645 - new_header->ctl_table->child->child->de->low_ino;
7646 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
7647 - new_header->ctl_table->child->child->de->owner = controlling_mod;
7649 - new_header->ctl_table->child->child->de->fill_inode =
7650 - &i2c_dir_fill_inode;
7651 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
7654 + tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1),
7657 + goto out_free_name;
7658 + memset(tbl, 0, sizeof(*tbl));
7660 + /* The client sysctls */
7661 + leaf = (struct ctl_table *) (tbl + 1);
7662 + memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
7663 + for (tmp = leaf; tmp->ctl_name; tmp++)
7664 + tmp->extra2 = client;
7666 + tbl->sensors->ctl_name = id+256;
7667 + tbl->sensors->procname = name;
7668 + tbl->sensors->mode = 0555;
7669 + tbl->sensors->child = leaf;
7671 + tbl->dev->ctl_name = DEV_SENSORS;
7672 + tbl->dev->procname = "sensors";
7673 + tbl->dev->mode = 0555;
7674 + tbl->dev->child = tbl->sensors;
7676 + tbl->root->ctl_name = CTL_DEV;
7677 + tbl->root->procname = "dev";
7678 + tbl->root->mode = 0555;
7679 + tbl->root->child = tbl->dev;
7681 + hdr = register_sysctl_table(tbl->root, 0);
7683 + goto out_free_tbl;
7685 + i2c_entries[id] = hdr;
7686 + i2c_clients[id] = client;
7688 + return (id + 256); /* XXX(hch) why?? */
7697 void i2c_deregister_entry(int id)
7702 - if (i2c_entries[id]) {
7703 - table = i2c_entries[id]->ctl_table;
7704 - unregister_sysctl_table(i2c_entries[id]);
7705 - /* 2-step kfree needed to keep gcc happy about const points */
7706 - (const char *) temp = table[4].procname;
7709 - i2c_entries[id] = NULL;
7710 - i2c_clients[id] = NULL;
7714 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o
7715 - impossible if some process still uses it or some file in it */
7716 -void i2c_fill_inode(struct inode *inode, int fill)
7719 - MOD_INC_USE_COUNT;
7721 - MOD_DEC_USE_COUNT;
7724 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
7725 - the corresponding module impossible if some process still uses it or
7726 - some file in it */
7727 -void i2c_dir_fill_inode(struct inode *inode, int fill)
7730 - struct i2c_client *client;
7731 + if (i2c_entries[id]) {
7732 + struct ctl_table_header *hdr = i2c_entries[id];
7733 + struct ctl_table *tbl = hdr->ctl_table;
7737 - printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
7739 + unregister_sysctl_table(hdr);
7740 + kfree(tbl->child->child->procname);
7741 + kfree(tbl); /* actually the whole anonymous struct */
7743 -#endif /* def DEBUG */
7745 - for (i = 0; i < SENSORS_ENTRY_MAX; i++)
7746 - if (i2c_clients[i]
7747 - && (i2c_inodes[i] == inode->i_ino)) break;
7749 - if (i == SENSORS_ENTRY_MAX) {
7751 - ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
7755 -#endif /* def DEBUG */
7756 - client = i2c_clients[i];
7758 - client->driver->inc_use(client);
7760 - client->driver->dec_use(client);
7761 + i2c_entries[id] = NULL;
7762 + i2c_clients[id] = NULL;
7765 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7766 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7767 void *buffer, size_t * lenp)
7772 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7773 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7774 void *oldval, size_t * oldlenp, void *newval,
7775 size_t newlen, void **context)
7777 hidden bugs in it, even leading to crashes and things!
7779 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7780 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7781 long *results, int magnitude)
7786 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7787 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7788 long *results, int magnitude)
7792 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
7793 + /* XXX: WTF is going on here??? */
7794 if ((is_isa && check_region(addr, 1)) ||
7795 (!is_isa && i2c_check_addr(adapter, addr)))
7799 - ("i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7800 + (KERN_DEBUG "i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7806 - ("i2c-proc.o: found ignore parameter for adapter %d, "
7807 + (KERN_DEBUG "i2c-proc.o: found ignore parameter for adapter %d, "
7808 "addr %04x\n", adapter_id, addr);
7813 - ("i2c-proc.o: found ignore_range parameter for adapter %d, "
7814 + (KERN_DEBUG "i2c-proc.o: found ignore_range parameter for adapter %d, "
7815 "addr %04x\n", adapter_id, addr);
7820 - ("i2c-proc.o: found normal isa entry for adapter %d, "
7821 + (KERN_DEBUG "i2c-proc.o: found normal isa entry for adapter %d, "
7822 "addr %04x\n", adapter_id,
7827 - ("i2c-proc.o: found normal isa_range entry for adapter %d, "
7828 + (KERN_DEBUG "i2c-proc.o: found normal isa_range entry for adapter %d, "
7829 "addr %04x", adapter_id, addr);
7834 - ("i2c-proc.o: found normal i2c entry for adapter %d, "
7835 + (KERN_DEBUG "i2c-proc.o: found normal i2c entry for adapter %d, "
7836 "addr %02x", adapter_id, addr);
7841 - ("i2c-proc.o: found normal i2c_range entry for adapter %d, "
7842 + (KERN_DEBUG "i2c-proc.o: found normal i2c_range entry for adapter %d, "
7843 "addr %04x\n", adapter_id, addr);
7848 - ("i2c-proc.o: found probe parameter for adapter %d, "
7849 + (KERN_DEBUG "i2c-proc.o: found probe parameter for adapter %d, "
7850 "addr %04x\n", adapter_id, addr);
7855 - ("i2c-proc.o: found probe_range parameter for adapter %d, "
7856 + (KERN_DEBUG "i2c-proc.o: found probe_range parameter for adapter %d, "
7857 "addr %04x\n", adapter_id, addr);
7859 @@ -861,28 +794,27 @@
7862 -int __init sensors_init(void)
7863 +static int __init i2c_proc_init(void)
7865 - printk("i2c-proc.o version %s (%s)\n", LM_VERSION, LM_DATE);
7866 - i2c_initialized = 0;
7867 + printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
7870 - register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
7871 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1))
7872 + register_sysctl_table(i2c_proc, 0))) {
7873 + printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
7876 i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
7878 - i2c_proc_header->ctl_table->child->de->fill_inode =
7880 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */
7881 - i2c_initialized++;
7885 +static void __exit i2c_proc_exit(void)
7887 + unregister_sysctl_table(i2c_proc_header);
7890 +EXPORT_SYMBOL(i2c_register_entry);
7891 EXPORT_SYMBOL(i2c_deregister_entry);
7892 -EXPORT_SYMBOL(i2c_detect);
7893 EXPORT_SYMBOL(i2c_proc_real);
7894 -EXPORT_SYMBOL(i2c_register_entry);
7895 EXPORT_SYMBOL(i2c_sysctl_real);
7898 +EXPORT_SYMBOL(i2c_detect);
7900 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
7901 @@ -890,21 +822,4 @@
7902 MODULE_LICENSE("GPL");
7904 -int i2c_cleanup(void)
7906 - if (i2c_initialized >= 1) {
7907 - unregister_sysctl_table(i2c_proc_header);
7908 - i2c_initialized--;
7913 -int init_module(void)
7915 - return sensors_init();
7918 -int cleanup_module(void)
7920 - return i2c_cleanup();
7922 -#endif /* MODULE */
7923 +module_init(i2c_proc_init);
7924 +module_exit(i2c_proc_exit);
7925 --- linux-old/include/linux/i2c-proc.h Sun Aug 31 14:51:57 CEST 2003
7926 +++ linux/include/linux/i2c-proc.h Sun Aug 31 14:51:57 CEST 2003
7929 - sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7931 + i2c-proc.h - Part of the i2c package
7932 + was originally sensors.h - Part of lm_sensors, Linux kernel modules
7933 + for hardware monitoring
7934 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
7939 -#ifndef SENSORS_SENSORS_H
7940 -#define SENSORS_SENSORS_H
7941 +#ifndef _LINUX_I2C_PROC_H
7942 +#define _LINUX_I2C_PROC_H
7946 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
7947 -#include <linux/types.h>
7948 -#include <linux/fs.h>
7949 #include <linux/sysctl.h>
7952 extern int i2c_register_entry(struct i2c_client *client,
7954 - ctl_table * ctl_template,
7955 - struct module *controlling_mod);
7956 + ctl_table * ctl_template);
7958 extern void i2c_deregister_entry(int id);
7959 @@ -348,4 +343,29 @@
7962 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
7963 + enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
7964 + SENSORS_MODULE_PARM(force, \
7965 + "List of adapter,address pairs to boldly assume " \
7966 + "to be present"); \
7967 + SENSORS_MODULE_PARM_FORCE(chip1); \
7968 + SENSORS_MODULE_PARM_FORCE(chip2); \
7969 + SENSORS_MODULE_PARM_FORCE(chip3); \
7970 + SENSORS_MODULE_PARM_FORCE(chip4); \
7971 + SENSORS_MODULE_PARM_FORCE(chip5); \
7972 + SENSORS_MODULE_PARM_FORCE(chip6); \
7973 + SENSORS_MODULE_PARM_FORCE(chip7); \
7974 + SENSORS_MODULE_PARM_FORCE(chip8); \
7975 + static struct i2c_force_data forces[] = {{force,any_chip}, \
7976 + {force_ ## chip1,chip1}, \
7977 + {force_ ## chip2,chip2}, \
7978 + {force_ ## chip3,chip3}, \
7979 + {force_ ## chip4,chip4}, \
7980 + {force_ ## chip5,chip5}, \
7981 + {force_ ## chip6,chip6}, \
7982 + {force_ ## chip7,chip7}, \
7983 + {force_ ## chip8,chip8}, \
7987 typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
7988 int addr, unsigned short flags,
7990 /* This macro is used to scale user-input to sensible values in almost all
7992 -extern inline int SENSORS_LIMIT(long value, long low, long high)
7993 +static inline int SENSORS_LIMIT(long value, long low, long high)
7999 -#endif /* def __KERNEL__ */
8002 /* The maximum length of the prefix */
8006 -#endif /* def SENSORS_SENSORS_H */
8007 +#endif /* def _LINUX_I2C_PROC_H */
8009 --- linux-old/drivers/i2c/i2c-rpx.c Sun Aug 31 14:51:57 CEST 2003
8010 +++ linux/drivers/i2c/i2c-rpx.c Sun Aug 31 14:51:57 CEST 2003
8013 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
8014 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
8016 + * moved into proper i2c interface;
8017 + * Brad Parker (brad@heeltoe.com)
8019 + * RPX lite specific parts of the i2c interface
8020 + * Update: There actually isn't anything RPXLite-specific about this module.
8021 + * This should work for most any 8xx board. The console messages have been
8022 + * changed to eliminate RPXLite references.
8025 +#include <linux/kernel.h>
8026 +#include <linux/ioport.h>
8027 +#include <linux/module.h>
8028 +#include <linux/init.h>
8029 +#include <linux/stddef.h>
8030 +#include <linux/parport.h>
8031 +#include <linux/i2c.h>
8032 +#include <linux/i2c-algo-8xx.h>
8033 +#include <asm/mpc8xx.h>
8034 +#include <asm/commproc.h>
8038 +rpx_iic_init(struct i2c_algo_8xx_data *data)
8040 + volatile cpm8xx_t *cp;
8041 + volatile immap_t *immap;
8043 + cp = cpmp; /* Get pointer to Communication Processor */
8044 + immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
8046 + data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
8048 + /* Check for and use a microcode relocation patch.
8050 + if ((data->reloc = data->iip->iic_rpbase))
8051 + data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
8053 + data->i2c = (i2c8xx_t *)&(immap->im_i2c);
8056 + /* Initialize Port B IIC pins.
8058 + cp->cp_pbpar |= 0x00000030;
8059 + cp->cp_pbdir |= 0x00000030;
8060 + cp->cp_pbodr |= 0x00000030;
8062 + /* Allocate space for two transmit and two receive buffer
8063 + * descriptors in the DP ram.
8065 + data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
8067 + /* ptr to i2c area */
8068 + data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
8071 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
8073 + /* install interrupt handler */
8074 + cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
8079 +static struct i2c_algo_8xx_data rpx_data = {
8080 + .setisr = rpx_install_isr
8083 +static struct i2c_adapter rpx_ops = {
8084 + .owner = THIS_MODULE,
8086 + .id = I2C_HW_MPC8XX_EPON,
8087 + .algo_data = &rpx_data,
8090 +int __init i2c_rpx_init(void)
8092 + printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8094 + /* reset hardware to sane state */
8095 + rpx_iic_init(&rpx_data);
8097 + if (i2c_8xx_add_bus(&rpx_ops) < 0) {
8098 + printk("i2c-rpx: Unable to register with I2C\n");
8105 +void __exit i2c_rpx_exit(void)
8107 + i2c_8xx_del_bus(&rpx_ops);
8110 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
8111 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
8113 +module_init(i2c_rpx_init);
8114 +module_exit(i2c_rpx_exit);
8115 --- linux-old/drivers/i2c/i2c-sibyte.c Sun Aug 31 14:51:57 CEST 2003
8116 +++ linux/drivers/i2c/i2c-sibyte.c Sun Aug 31 14:51:57 CEST 2003
8119 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
8121 - * This program is free software; you can redistribute it and/or
8122 - * modify it under the terms of the GNU General Public License
8123 - * as published by the Free Software Foundation; either version 2
8124 - * of the License, or (at your option) any later version.
8126 - * This program is distributed in the hope that it will be useful,
8127 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8128 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8129 - * GNU General Public License for more details.
8131 - * You should have received a copy of the GNU General Public License
8132 - * along with this program; if not, write to the Free Software
8133 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8136 -#include <linux/config.h>
8137 -#include <linux/kernel.h>
8138 -#include <linux/module.h>
8139 -#include <linux/init.h>
8140 -#include <linux/errno.h>
8142 -#include <asm/sibyte/sb1250_regs.h>
8143 -#include <asm/sibyte/sb1250_smbus.h>
8145 -#include <linux/i2c.h>
8146 -#include <linux/i2c-algo-sibyte.h>
8148 -static int sibyte_reg(struct i2c_client *client)
8153 -static int sibyte_unreg(struct i2c_client *client)
8158 -static void sibyte_inc_use(struct i2c_adapter *adap)
8161 - MOD_INC_USE_COUNT;
8165 -static void sibyte_dec_use(struct i2c_adapter *adap)
8168 - MOD_DEC_USE_COUNT;
8172 -static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
8173 - { NULL, 0, (void *)(KSEG1+A_SMB_BASE(0)) },
8174 - { NULL, 1, (void *)(KSEG1+A_SMB_BASE(1)) }
8177 -static struct i2c_adapter sibyte_board_adapter[2] = {
8179 - name: "SiByte SMBus 0",
8180 - id: I2C_HW_SIBYTE,
8182 - algo_data: &sibyte_board_data[0],
8183 - inc_use: sibyte_inc_use,
8184 - dec_use: sibyte_dec_use,
8185 - client_register: sibyte_reg,
8186 - client_unregister: sibyte_unreg,
8190 - name: "SiByte SMBus 1",
8191 - id: I2C_HW_SIBYTE,
8193 - algo_data: &sibyte_board_data[1],
8194 - inc_use: sibyte_inc_use,
8195 - dec_use: sibyte_dec_use,
8196 - client_register: sibyte_reg,
8197 - client_unregister: sibyte_unreg,
8202 -int __init i2c_sibyte_init(void)
8204 - printk("i2c-swarm.o: i2c SMBus adapter module for SiByte board\n");
8205 - if (i2c_sibyte_add_bus(&sibyte_board_adapter[0], K_SMB_FREQ_100KHZ) < 0)
8207 - if (i2c_sibyte_add_bus(&sibyte_board_adapter[1], K_SMB_FREQ_400KHZ) < 0)
8216 -MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
8217 -MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards");
8218 -MODULE_LICENSE("GPL");
8220 -int init_module(void)
8222 - return i2c_sibyte_init();
8225 -void cleanup_module(void)
8227 - i2c_sibyte_del_bus(&sibyte_board_adapter[0]);
8228 - i2c_sibyte_del_bus(&sibyte_board_adapter[1]);
8232 --- linux-old/drivers/i2c/i2c-velleman.c Sun Aug 31 14:51:58 CEST 2003
8233 +++ linux/drivers/i2c/i2c-velleman.c Sun Aug 31 14:51:58 CEST 2003
8235 /* ------------------------------------------------------------------------- */
8240 #include <linux/kernel.h>
8242 #include <linux/module.h>
8243 #include <linux/init.h>
8244 -#include <linux/string.h> /* for 2.0 kernels to get NULL */
8245 -#include <asm/errno.h> /* for 2.0 kernels to get ENODEV */
8246 -#include <asm/io.h>
8248 +#include <linux/errno.h>
8249 +#include <linux/delay.h>
8250 #include <linux/i2c.h>
8251 #include <linux/i2c-algo-bit.h>
8252 +#include <asm/io.h>
8253 +#include <asm/param.h> /* for HZ */
8255 /* ----- global defines ----------------------------------------------- */
8257 static int bit_velle_init(void)
8259 - if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
8260 - DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
8262 + if (!request_region(base, (base == 0x3bc) ? 3 : 8,
8263 + "i2c (Vellemann adapter)"))
8266 - request_region(base, (base == 0x3bc)? 3 : 8,
8267 - "i2c (Vellemann adapter)");
8268 - bit_velle_setsda((void*)base,1);
8269 - bit_velle_setscl((void*)base,1);
8274 -static void __exit bit_velle_exit(void)
8276 - release_region( base , (base == 0x3bc)? 3 : 8 );
8280 -static int bit_velle_reg(struct i2c_client *client)
8285 -static int bit_velle_unreg(struct i2c_client *client)
8287 + bit_velle_setsda((void*)base,1);
8288 + bit_velle_setscl((void*)base,1);
8292 -static void bit_velle_inc_use(struct i2c_adapter *adap)
8295 - MOD_INC_USE_COUNT;
8299 -static void bit_velle_dec_use(struct i2c_adapter *adap)
8302 - MOD_DEC_USE_COUNT;
8306 /* ------------------------------------------------------------------------
8307 * Encapsulate the above functions in the correct operations structure.
8308 @@ -140,26 +106,23 @@
8310 static struct i2c_algo_bit_data bit_velle_data = {
8316 - 10, 10, 100, /* waits, timeout */
8317 + .setsda = bit_velle_setsda,
8318 + .setscl = bit_velle_setscl,
8319 + .getsda = bit_velle_getsda,
8320 + .getscl = bit_velle_getscl,
8326 static struct i2c_adapter bit_velle_ops = {
8331 - bit_velle_inc_use,
8332 - bit_velle_dec_use,
8335 + .owner = THIS_MODULE,
8336 + .name = "Velleman K8000",
8337 + .id = I2C_HW_B_VELLE,
8338 + .algo_data = &bit_velle_data,
8341 -int __init i2c_bitvelle_init(void)
8342 +static int __init i2c_bitvelle_init(void)
8344 - printk("i2c-velleman.o: i2c Velleman K8000 adapter module\n");
8345 + printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8347 /* probe some values */
8348 @@ -181,11 +144,14 @@
8351 - printk("i2c-velleman.o: found device at %#x.\n",base);
8352 + printk(KERN_DEBUG "i2c-velleman.o: found device at %#x.\n",base);
8357 +static void __exit i2c_bitvelle_exit(void)
8359 + i2c_bit_del_bus(&bit_velle_ops);
8360 + release_region(base, (base == 0x3bc) ? 3 : 8);
8364 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
8365 MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
8366 @@ -194,14 +160,4 @@
8367 MODULE_PARM(base, "i");
8369 -int init_module(void)
8371 - return i2c_bitvelle_init();
8374 -void cleanup_module(void)
8376 - i2c_bit_del_bus(&bit_velle_ops);
8381 +module_init(i2c_bitvelle_init);
8382 +module_exit(i2c_bitvelle_exit);
8383 --- linux-old/include/linux/i2c.h Sun Aug 31 14:51:58 CEST 2003
8384 +++ linux/include/linux/i2c.h Sun Aug 31 14:51:58 CEST 2003
8386 Frodo Looijaard <frodol@dds.nl> */
8393 +#ifndef _LINUX_I2C_H
8394 +#define _LINUX_I2C_H
8396 -#define I2C_DATE "20010830"
8397 -#define I2C_VERSION "2.6.1"
8398 +#define I2C_DATE "20030714"
8399 +#define I2C_VERSION "2.8.0"
8401 -#include <linux/i2c-id.h> /* id values of adapters et. al. */
8402 +#include <linux/module.h>
8403 #include <linux/types.h>
8411 -/* --- Includes and compatibility declarations ------------------------ */
8413 -#include <linux/version.h>
8414 -#ifndef KERNEL_VERSION
8415 -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
8418 -#include <asm/page.h> /* for 2.2.xx */
8419 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,25)
8420 +#include <linux/errno.h>
8421 #include <linux/sched.h>
8423 #include <asm/semaphore.h>
8424 +#include <linux/i2c-id.h>
8426 +#include <linux/version.h>
8427 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
8428 +#define MODULE_LICENSE(x)
8430 -#include <linux/config.h>
8432 /* --- General options ------------------------------------------------ */
8434 -#define I2C_ALGO_MAX 4 /* control memory consumption */
8435 -#define I2C_ADAP_MAX 16
8436 +#define I2C_ADAP_MAX 16 /* control memory consumption */
8437 #define I2C_DRIVER_MAX 16
8438 #define I2C_CLIENT_MAX 32
8439 -#define I2C_DUMMY_MAX 4
8442 struct i2c_algorithm;
8445 union i2c_smbus_data;
8449 * The master routines are the ones normally used to transmit data to devices
8451 u8 command, u8 length,
8453 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
8454 + u8 command, u8 *values);
8455 extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
8456 u8 command, u8 length,
8460 + struct module *owner;
8463 @@ -159,16 +148,4 @@
8465 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
8467 - /* These two are mainly used for bookkeeping & dynamic unloading of
8468 - * kernel modules. inc_use tells the driver that a client is being
8469 - * used by another module & that it should increase its ref. counter.
8470 - * dec_use is the inverse operation.
8471 - * NB: Make sure you have no circular dependencies, or else you get a
8472 - * deadlock when trying to unload the modules.
8473 - * You should use the i2c_{inc,dec}_use_client functions instead of
8474 - * calling this function directly.
8476 - void (*inc_use)(struct i2c_client *client);
8477 - void (*dec_use)(struct i2c_client *client);
8482 struct i2c_algorithm {
8483 + struct module *owner; /* future use --km */
8484 char name[32]; /* textual description */
8489 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8490 -struct proc_dir_entry;
8494 * i2c_adapter is the structure used to identify a physical i2c bus along
8497 struct i2c_adapter {
8498 + struct module *owner;
8499 char name[32]; /* some useful name to identify the adapter */
8500 unsigned int id;/* == is algo->id | hwdep.struct->id, */
8504 - /* --- These may be NULL, but should increase the module use count */
8505 - void (*inc_use)(struct i2c_adapter *);
8506 - void (*dec_use)(struct i2c_adapter *);
8508 /* --- administration stuff. */
8509 int (*client_register)(struct i2c_client *);
8512 /* data fields that are valid for all devices */
8513 - struct semaphore lock;
8514 + struct semaphore bus;
8515 + struct semaphore list;
8516 unsigned int flags;/* flags specifying div. data */
8518 struct i2c_client *clients[I2C_CLIENT_MAX];
8523 /* No need to set this when you initialize the adapter */
8525 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8526 - struct proc_dir_entry *proc_entry;
8528 #endif /* def CONFIG_PROC_FS */
8531 #define I2C_CLIENT_ALLOW_MULTIPLE_USE 0x02 /* Allow multiple access-locks */
8532 /* on an i2c_client */
8533 +#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
8534 +#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */
8535 + /* Must equal I2C_M_TEN below */
8537 /* i2c_client_address_data is the struct for holding default client
8538 @@ -320,10 +291,4 @@
8539 extern int i2c_detach_client(struct i2c_client *);
8541 -/* Only call these if you grab a resource that makes unloading the
8542 - client and the adapter it is on completely impossible. Like when a
8543 - /proc directory is entered. */
8544 -extern void i2c_inc_use_client(struct i2c_client *);
8545 -extern void i2c_dec_use_client(struct i2c_client *);
8547 /* New function: This is to get an i2c_client-struct for controlling the
8548 client either by using i2c_control-function or having the
8549 @@ -359,4 +324,13 @@
8550 i2c_client_found_addr_proc *found_proc);
8552 +static inline int i2c_client_command(struct i2c_client *client,
8553 + unsigned int cmd, void *arg)
8555 + if (client->driver && client->driver->command)
8556 + return client->driver->command(client, cmd, arg);
8561 /* An ioctl like call to set div. parameters of the adapter.
8564 extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
8566 -#endif /* __KERNEL__ */
8569 * I2C Message - used for pure i2c transaction, also from /dev interface
8570 @@ -388,6 +360,10 @@
8571 #define I2C_M_NOSTART 0x4000
8572 #define I2C_M_REV_DIR_ADDR 0x2000
8573 +#define I2C_M_IGNORE_NAK 0x1000
8574 +#define I2C_M_NO_RD_ACK 0x0800
8575 __u16 len; /* msg length */
8576 __u8 *buf; /* pointer to msg data */
8581 @@ -396,5 +372,11 @@
8582 #define I2C_FUNC_I2C 0x00000001
8583 #define I2C_FUNC_10BIT_ADDR 0x00000002
8584 -#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
8585 +#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
8586 +#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
8587 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */
8588 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */
8589 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */
8590 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
8591 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
8592 #define I2C_FUNC_SMBUS_QUICK 0x00010000
8593 #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
8594 @@ -407,6 +389,10 @@
8595 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
8596 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
8597 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* New I2C-like block */
8598 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
8599 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
8600 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
8601 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
8602 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
8603 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */
8604 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
8606 #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
8607 @@ -420,4 +406,17 @@
8608 #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
8609 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
8610 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
8611 + I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
8612 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
8613 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
8614 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
8615 + I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
8617 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_DATA
8618 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC I2C_FUNC_SMBUS_WRITE_BYTE_DATA
8619 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA
8620 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC I2C_FUNC_SMBUS_WRITE_WORD_DATA
8621 +#define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_BYTE_DATA
8622 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC I2C_FUNC_SMBUS_WORD_DATA
8624 #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
8625 @@ -426,13 +425,19 @@
8626 I2C_FUNC_SMBUS_WORD_DATA | \
8627 I2C_FUNC_SMBUS_PROC_CALL | \
8628 - I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
8629 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
8630 + I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
8631 + I2C_FUNC_SMBUS_I2C_BLOCK
8634 * Data for SMBus Messages
8636 +#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
8637 +#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
8638 union i2c_smbus_data {
8641 - __u8 block[33]; /* block[0] is used for length */
8642 + __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
8643 + /* one more for read length in block process call */
8644 + /* and one more for PEC */
8648 #define I2C_SMBUS_BLOCK_DATA 5
8649 #define I2C_SMBUS_I2C_BLOCK_DATA 6
8650 +#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
8651 +#define I2C_SMBUS_BLOCK_DATA_PEC 8 /* SMBus 2.0 */
8652 +#define I2C_SMBUS_PROC_CALL_PEC 9 /* SMBus 2.0 */
8653 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC 10 /* SMBus 2.0 */
8654 +#define I2C_SMBUS_WORD_DATA_PEC 11 /* SMBus 2.0 */
8658 #define I2C_FUNCS 0x0705 /* Get the adapter functionality */
8659 #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/
8660 +#define I2C_PEC 0x0708 /* != 0 for SMBus PEC */
8662 #define I2C_ACK_TEST 0x0710 /* See if a slave is at a specific address */
8663 @@ -490,14 +501,4 @@
8664 #define I2C_MAJOR 89 /* Device major number */
8669 -# define NULL ( (void *) 0 )
8673 -# include <asm/errno.h>
8676 /* These defines are used for probing i2c client addresses */
8677 /* Default fill of many variables */
8678 @@ -561,4 +562,10 @@
8679 ((adapptr)->algo->id == I2C_ALGO_ISA)
8681 -#endif /* def __KERNEL__ */
8683 +/* Tiny delay function used by the i2c bus drivers */
8684 +static inline void i2c_delay(signed long timeout)
8686 + set_current_state(TASK_INTERRUPTIBLE);
8687 + schedule_timeout(timeout);
8690 +#endif /* _LINUX_I2C_H */
8691 --- linux-old/Documentation/Configure.help Sun Aug 31 14:51:59 CEST 2003
8692 +++ linux/Documentation/Configure.help Sun Aug 31 14:51:59 CEST 2003
8693 @@ -18109,4 +18109,45 @@
8694 board at <http://www.mvista.com/allies/semiconductor/ite.html>.
8696 +UltraSPARC-III bootbus i2c controller driver
8698 + The BBC devices on the UltraSPARC III have two I2C controllers. The
8699 + first I2C controller connects mainly to configuration PROMs (NVRAM,
8700 + CPU configuration, DIMM types, etc.). The second I2C controller
8701 + connects to environmental control devices such as fans and
8702 + temperature sensors. The second controller also connects to the
8703 + smartcard reader, if present. Say Y to enable support for these.
8706 +CONFIG_ITE_I2C_ALGO
8707 + This supports the use the ITE8172 I2C interface found on some MIPS
8708 + systems. Say Y if you have one of these. You should also say Y for
8709 + the ITE I2C peripheral driver support below.
8711 + This support is also available as a module. If you want to compile
8712 + it as a modules, say M here and read
8713 + <file:Documentation/modules.txt>.
8714 + The module will be called i2c-algo-ite.o.
8717 +CONFIG_ITE_I2C_ADAP
8718 + This supports the ITE8172 I2C peripheral found on some MIPS
8719 + systems. Say Y if you have one of these. You should also say Y for
8720 + the ITE I2C driver algorithm support above.
8722 + This support is also available as a module. If you want to compile
8723 + it as a module, say M here and read
8724 + <file:Documentation/modules.txt>.
8725 + The module will be called i2c-adap-ite.o.
8727 +SiByte I2C Algorithm
8728 +CONFIG_I2C_ALGO_SIBYTE
8729 + Supports the SiByte SOC on-chip I2C interfaces (2 channels).
8731 +MAX1617 Temperature Sensor
8733 + This builds a simple polling driver for the Maxim 1617 temperature
8734 + sensor. Currently the device is only supported on a SiByte I2C
8735 + adapter, and the driver prints status updates to the system log.
8739 @@ -18133,13 +18174,4 @@
8740 The module will be called i2c-core.o.
8742 -UltraSPARC-III bootbus i2c controller driver
8744 - The BBC devices on the UltraSPARC III have two I2C controllers. The
8745 - first I2C controller connects mainly to configuration PROMs (NVRAM,
8746 - CPU configuration, DIMM types, etc.). The second I2C controller
8747 - connects to environmental control devices such as fans and
8748 - temperature sensors. The second controller also connects to the
8749 - smartcard reader, if present. Say Y to enable support for these.
8751 I2C bit-banging interfaces
8753 @@ -18186,4 +18218,14 @@
8754 The module will be called i2c-velleman.o.
8756 +Basic I2C on Parallel Port adapter
8758 + This supports directly connecting I2C devices to the parallel port.
8759 + See <file:Documentation/i2c/i2c-pport> for more information.
8761 + This driver is also available as a module. If you want to compile
8762 + it as a module, say M here and read
8763 + <file:Documentation/modules.txt>.
8764 + The module will be called i2c-pport.o.
8766 I2C PCF 8584 interfaces
8768 @@ -18207,35 +18249,57 @@
8769 The module will be called i2c-elektor.o.
8772 -CONFIG_ITE_I2C_ALGO
8773 - This supports the use the ITE8172 I2C interface found on some MIPS
8774 - systems. Say Y if you have one of these. You should also say Y for
8775 - the ITE I2C peripheral driver support below.
8776 +PCF on the EPP Parallel Port
8778 + This supports the PCF8584 connected to the parallel port.
8780 - This support is also available as a module. If you want to compile
8781 - it as a modules, say M here and read
8782 + This driver is also available as a module. If you want to compile
8783 + it as a module, say M here and read
8784 <file:Documentation/modules.txt>.
8785 - The module will be called i2c-algo-ite.o.
8786 + The module will be called i2c-pcf-epp.o.
8789 -CONFIG_ITE_I2C_ADAP
8790 - This supports the ITE8172 I2C peripheral found on some MIPS
8791 - systems. Say Y if you have one of these. You should also say Y for
8792 - the ITE I2C driver algorithm support above.
8793 +Motorola 8xx I2C algorithm
8795 + This is the algorithm that allows you to use Motorola 8xx I2C adapters.
8797 - This support is also available as a module. If you want to compile
8798 + This driver is also available as a module. If you want to compile
8799 it as a module, say M here and read
8800 <file:Documentation/modules.txt>.
8801 - The module will be called i2c-adap-ite.o.
8802 + The module will be called i2c-algo-8xx.o.
8804 -SiByte I2C Algorithm
8805 -CONFIG_I2C_ALGO_SIBYTE
8806 - Supports the SiByte SOC on-chip I2C interfaces (2 channels).
8807 +Motorola 8xx I2C interface
8809 + This supports the Motorola 8xx I2C device.
8811 -MAX1617 Temperature Sensor
8813 - This builds a simple polling driver for the Maxim 1617 temperature
8814 - sensor. Currently the device is only supported on a SiByte I2C
8815 - adapter, and the driver prints status updates to the system log.
8816 + This driver is also available as a module. If you want to compile
8817 + it as a module, say M here and read
8818 + <file:Documentation/modules.txt>.
8819 + The module will be called i2c-rpx.o.
8821 +IBM 405 I2C algorithm
8822 +CONFIG_I2C_IBM_OCP_ALGO
8823 + This is the algorithm that allows you to use IBM 405 I2C adapters.
8825 + This driver is also available as a module. If you want to compile
8826 + it as a module, say M here and read
8827 + <file:Documentation/modules.txt>.
8828 + The module will be called i2c-algo-ibm_ocp.o.
8830 +IBM 405 I2C interface
8831 +CONFIG_I2C_IBM_OCP_ADAP
8832 + This supports the IBM 405 I2C device.
8834 + This driver is also available as a module. If you want to compile
8835 + it as a module, say M here and read
8836 + <file:Documentation/modules.txt>.
8837 + The module will be called i2c-adap-ibm_ocp.o.
8839 +StrongARM SA-1110 interface
8841 + This supports the StrongARM SA-1110 Development Board.
8843 + This driver is also available as a module. If you want to compile
8844 + it as a module, say M here and read
8845 + <file:Documentation/modules.txt>.
8846 + The module will be called i2c-frodo.o.
8848 I2C device interface
8849 --- linux-2.4.22-orig/drivers/i2c/i2c-adap-ite.c Tue Jul 15 12:23:01 2003
8850 +++ linux-2.4.22-i2c/drivers/i2c/i2c-adap-ite.c Thu Aug 28 18:24:16 2003
8851 @@ -199,22 +199,6 @@
8855 -static void iic_ite_inc_use(struct i2c_adapter *adap)
8858 - MOD_INC_USE_COUNT;
8863 -static void iic_ite_dec_use(struct i2c_adapter *adap)
8866 - MOD_DEC_USE_COUNT;
8871 /* ------------------------------------------------------------------------
8872 * Encapsulate the above functions in the correct operations structure.
8873 * This is only done when more than one hardware adapter is supported.
8874 @@ -230,14 +214,13 @@
8877 static struct i2c_adapter iic_ite_ops = {
8878 - "ITE IIC adapter",
8886 + .owner = THIS_MODULE,
8887 + .name = "ITE IIC adapter",
8888 + .id = I2C_HW_I_IIC,
8890 + .algo_data = &iic_ite_data,
8891 + .client_register = iic_ite_reg,
8892 + .client_unregieter = iic_ite_unreg,
8895 /* Called when the module is loaded. This function starts the
8896 --- linux-2.4.22-orig/drivers/i2c/i2c-algo-ite.c Thu Oct 11 17:05:47 2001
8897 +++ linux-2.4.22-i2c/drivers/i2c/i2c-algo-ite.c Thu Aug 28 18:39:48 2003
8898 @@ -742,14 +742,12 @@
8899 /* -----exported algorithm data: ------------------------------------- */
8901 static struct i2c_algorithm iic_algo = {
8902 - "ITE IIC algorithm",
8904 - iic_xfer, /* master_xfer */
8905 - NULL, /* smbus_xfer */
8906 - NULL, /* slave_xmit */
8907 - NULL, /* slave_recv */
8908 - algo_control, /* ioctl */
8909 - iic_func, /* functionality */
8910 + .owner = THIS_MODULE,
8911 + .name = "ITE IIC algorithm",
8912 + .id = I2C_ALGO_IIC,
8913 + .master_xfer = iic_xfer,
8914 + .algo_control = algo_control,
8915 + .functionality = iic_func,
8919 --- linux-2.4.22-orig/drivers/i2c/i2c-keywest.c Tue Jul 15 12:23:26 2003
8920 +++ linux-2.4.22-i2c/drivers/i2c/i2c-keywest.c Sun Sep 14 10:33:10 2003
8921 @@ -412,20 +412,9 @@
8922 I2C_FUNC_SMBUS_BLOCK_DATA;
8926 -keywest_inc(struct i2c_adapter *adapter)
8928 - MOD_INC_USE_COUNT;
8932 -keywest_dec(struct i2c_adapter *adapter)
8934 - MOD_DEC_USE_COUNT;
8937 /* For now, we only handle combined mode (smbus) */
8938 static struct i2c_algorithm keywest_algorithm = {
8939 + owner: THIS_MODULE,
8940 name: "Keywest i2c",
8942 smbus_xfer: keywest_smbus_xfer,
8943 @@ -527,14 +516,13 @@
8944 struct keywest_chan* chan = &iface->channels[i];
8947 + chan->adapter.owner = THIS_MODULE;
8948 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
8949 chan->iface = iface;
8951 chan->adapter.id = I2C_ALGO_SMBUS;
8952 chan->adapter.algo = &keywest_algorithm;
8953 chan->adapter.algo_data = NULL;
8954 - chan->adapter.inc_use = keywest_inc;
8955 - chan->adapter.dec_use = keywest_dec;
8956 chan->adapter.client_register = NULL;
8957 chan->adapter.client_unregister = NULL;
8958 chan->adapter.data = chan;
8959 --- linux-2.4.22-orig/drivers/i2c/scx200_acb.c Tue Jul 15 12:23:49 2003
8960 +++ linux-2.4.22-i2c/drivers/i2c/scx200_acb.c Sun Aug 31 12:04:13 2003
8961 @@ -408,16 +408,6 @@
8965 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
8967 - MOD_INC_USE_COUNT;
8970 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
8972 - MOD_DEC_USE_COUNT;
8975 /* For now, we only handle combined mode (smbus) */
8976 static struct i2c_algorithm scx200_acb_algorithm = {
8977 name: "NatSemi SCx200 ACCESS.bus",
8978 @@ -479,11 +469,10 @@
8979 memset(iface, 0, sizeof(*iface));
8980 adapter = &iface->adapter;
8981 adapter->data = iface;
8982 + adapter->owner = THIS_MODULE;
8983 sprintf(adapter->name, "SCx200 ACB%d", index);
8984 adapter->id = I2C_ALGO_SMBUS;
8985 adapter->algo = &scx200_acb_algorithm;
8986 - adapter->inc_use = scx200_acb_inc_use;
8987 - adapter->dec_use = scx200_acb_dec_use;
8988 adapter->client_register = scx200_acb_reg;
8989 adapter->client_unregister = scx200_acb_unreg;
8991 --- linux-2.4.22-orig/drivers/i2c/scx200_i2c.c Tue Jul 15 12:23:49 2003
8992 +++ linux-2.4.22-i2c/drivers/i2c/scx200_i2c.c Sun Aug 31 12:04:18 2003
8997 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
8999 - MOD_INC_USE_COUNT;
9002 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
9004 - MOD_DEC_USE_COUNT;
9007 /* ------------------------------------------------------------------------
9008 * Encapsulate the above functions in the correct operations structure.
9009 * This is only done when more than one hardware adapter is supported.
9010 @@ -101,11 +91,10 @@
9013 static struct i2c_adapter scx200_i2c_ops = {
9014 + .owner = THIS_MODULE,
9015 .name = "NatSemi SCx200 I2C",
9016 .id = I2C_HW_B_VELLE,
9017 .algo_data = &scx200_i2c_data,
9018 - .inc_use = scx200_i2c_inc_use,
9019 - .dec_use = scx200_i2c_dec_use,
9020 .client_register = scx200_i2c_reg,
9021 .client_unregister = scx200_i2c_unreg,
9023 diff -ru linux-2.4.22-orig/drivers/ieee1394/pcilynx.c linux-2.4.22-i2c/drivers/ieee1394/pcilynx.c
9024 --- linux-2.4.22-orig/drivers/ieee1394/pcilynx.c Wed Aug 27 18:11:47 2003
9025 +++ linux-2.4.22-i2c/drivers/ieee1394/pcilynx.c Sun Aug 31 12:04:23 2003
9029 static struct i2c_adapter bit_ops = {
9030 + .owner = THIS_MODULE,
9031 .id = 0xAA, //FIXME: probably we should get an id in i2c-id.h
9032 .client_register = bit_reg,
9033 .client_unregister = bit_unreg,
9034 diff -ru linux-2.4.22-orig/drivers/media/video/Makefile linux-2.4.22-i2c/drivers/media/video/Makefile
9035 --- linux-2.4.22-orig/drivers/media/video/Makefile Wed Aug 27 18:11:47 2003
9036 +++ linux-2.4.22-i2c/drivers/media/video/Makefile Sun Aug 31 12:29:43 2003
9039 obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
9040 obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o i2c-old.o
9041 -obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o i2c-old.o
9042 +obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
9043 obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
9044 obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o
9045 obj-$(CONFIG_VIDEO_W9966) += w9966.o
9047 obj-$(CONFIG_VIDEO_ZORAN_BUZ) += saa7111.o saa7185.o
9048 obj-$(CONFIG_VIDEO_ZORAN_DC10) += saa7110.o adv7175.o
9049 obj-$(CONFIG_VIDEO_ZORAN_LML33) += bt819.o bt856.o
9050 -obj-$(CONFIG_VIDEO_LML33) += bt856.o bt819.o
9051 obj-$(CONFIG_VIDEO_PMS) += pms.o
9052 obj-$(CONFIG_VIDEO_PLANB) += planb.o
9053 obj-$(CONFIG_VIDEO_VINO) += vino.o
9054 -obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
9055 +obj-$(CONFIG_VIDEO_STRADIS) += stradis.o i2c-old.o
9056 obj-$(CONFIG_VIDEO_CPIA) += cpia.o
9057 obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
9058 obj-$(CONFIG_VIDEO_CPIA_USB) += cpia_usb.o
9063 -zoran.o: zr36120.o zr36120_i2c.o zr36120_mem.o
9064 - $(LD) $(LD_RFLAG) -r -o $@ zr36120.o zr36120_i2c.o zr36120_mem.o
9065 +zoran.o: $(zoran-objs)
9066 + $(LD) $(LD_RFLAG) -r -o $@ $(zoran-objs)
9068 bttv.o: $(bttv-objs)
9069 $(LD) $(LD_RFLAG) -r -o $@ $(bttv-objs)
9070 diff -ru linux-2.4.22-orig/drivers/media/video/bt832.c linux-2.4.22-i2c/drivers/media/video/bt832.c
9071 --- linux-2.4.22-orig/drivers/media/video/bt832.c Tue Jul 15 12:23:50 2003
9072 +++ linux-2.4.22-i2c/drivers/media/video/bt832.c Sun Aug 31 12:29:43 2003
9074 /* ----------------------------------------------------------------------- */
9076 static struct i2c_driver driver = {
9077 + .owner = THIS_MODULE,
9078 .name = "i2c bt832 driver",
9079 .id = -1, /* FIXME */
9080 .flags = I2C_DF_NOTIFY,
9081 diff -ru linux-2.4.22-orig/drivers/media/video/i2c-old.c linux-2.4.22-i2c/drivers/media/video/i2c-old.c
9082 --- linux-2.4.22-orig/drivers/media/video/i2c-old.c Sun Sep 30 21:26:06 2001
9083 +++ linux-2.4.22-i2c/drivers/media/video/i2c-old.c Sun Aug 31 12:29:43 2003
9085 static struct i2c_driver *drivers[I2C_DRIVER_MAX];
9086 static int bus_count = 0, driver_count = 0;
9088 -#ifdef CONFIG_VIDEO_BUZ
9089 -extern int saa7111_init(void);
9090 -extern int saa7185_init(void);
9092 -#ifdef CONFIG_VIDEO_LML33
9093 -extern int bt819_init(void);
9094 -extern int bt856_init(void);
9099 printk(KERN_INFO "i2c: initialized%s\n",
9100 scan ? " (i2c bus scan enabled)" : "");
9101 /* anything to do here ? */
9102 -#ifdef CONFIG_VIDEO_BUZ
9106 -#ifdef CONFIG_VIDEO_LML33
9113 diff -ru linux-2.4.22-orig/drivers/media/video/msp3400.c linux-2.4.22-i2c/drivers/media/video/msp3400.c
9114 --- linux-2.4.22-orig/drivers/media/video/msp3400.c Wed Aug 27 18:11:47 2003
9115 +++ linux-2.4.22-i2c/drivers/media/video/msp3400.c Sun Aug 31 12:29:43 2003
9116 @@ -1243,6 +1243,7 @@
9117 static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
9119 static struct i2c_driver driver = {
9120 + .owner = THIS_MODULE,
9121 .name = "i2c msp3400 driver",
9122 .id = I2C_DRIVERID_MSP3400,
9123 .flags = I2C_DF_NOTIFY,
9124 diff -ru linux-2.4.22-orig/drivers/media/video/saa5249.c linux-2.4.22-i2c/drivers/media/video/saa5249.c
9125 --- linux-2.4.22-orig/drivers/media/video/saa5249.c Sun Sep 30 21:26:06 2001
9126 +++ linux-2.4.22-i2c/drivers/media/video/saa5249.c Sun Aug 31 12:29:43 2003
9127 @@ -258,12 +258,13 @@
9129 static struct i2c_driver i2c_driver_videotext =
9131 - IF_NAME, /* name */
9132 - I2C_DRIVERID_SAA5249, /* in i2c.h */
9137 + .owner = THIS_MODULE,
9139 + .id = I2C_DRIVERID_SAA5249, /* in i2c-id.h */
9140 + .flags = I2C_DF_NOTIFY,
9141 + .attach_adapter = saa5249_probe,
9142 + .detach_client = saa5249_detach,
9143 + .command = saa5249_command
9146 static struct i2c_client client_template = {
9147 diff -ru linux-2.4.22-orig/drivers/media/video/saa7146.h linux-2.4.22-i2c/drivers/media/video/saa7146.h
9148 --- linux-2.4.22-orig/drivers/media/video/saa7146.h Mon Dec 11 22:15:51 2000
9149 +++ linux-2.4.22-i2c/drivers/media/video/saa7146.h Sun Aug 31 12:29:43 2003
9151 #include <linux/types.h>
9152 #include <linux/wait.h>
9154 -#include <linux/i2c.h>
9155 -#include <linux/videodev.h>
9158 #define O_NONCAP O_TRUNC
9160 diff -ru linux-2.4.22-orig/drivers/media/video/swarm_saa7114h.c linux-2.4.22-i2c/drivers/media/video/swarm_saa7114h.c
9161 --- linux-2.4.22-orig/drivers/media/video/swarm_saa7114h.c Wed Aug 27 18:11:47 2003
9162 +++ linux-2.4.22-i2c/drivers/media/video/swarm_saa7114h.c Sun Aug 31 12:42:00 2003
9163 @@ -201,11 +201,12 @@
9165 struct i2c_driver i2c_driver_saa7114h =
9167 - name: "saa7114h", /* name */
9168 - id: I2C_DRIVERID_SAA7114H, /* ID */
9169 - flags: I2C_DF_NOTIFY, /* XXXKW do I care? */
9170 - attach_adapter: saa7114h_probe,
9171 - detach_client: saa7114h_detach
9172 + .owner = THIS_MODULE,
9173 + .name = "saa7114h",
9174 + .id = I2C_DRIVERID_SAA7114H,
9175 + .flags = I2C_DF_NOTIFY,
9176 + .attach_adapter = saa7114h_probe,
9177 + .detach_client = saa7114h_detach
9180 /* -----------------------------------------------------------------------
9181 diff -ru linux-2.4.22-orig/drivers/media/video/tda7432.c linux-2.4.22-i2c/drivers/media/video/tda7432.c
9182 --- linux-2.4.22-orig/drivers/media/video/tda7432.c Wed Aug 27 18:11:47 2003
9183 +++ linux-2.4.22-i2c/drivers/media/video/tda7432.c Sun Aug 31 12:29:43 2003
9187 static struct i2c_driver driver = {
9188 + .owner = THIS_MODULE,
9189 .name = "i2c tda7432 driver",
9190 .id = I2C_DRIVERID_TDA7432,
9191 .flags = I2C_DF_NOTIFY,
9192 diff -ru linux-2.4.22-orig/drivers/media/video/tda9875.c linux-2.4.22-i2c/drivers/media/video/tda9875.c
9193 --- linux-2.4.22-orig/drivers/media/video/tda9875.c Wed Aug 27 18:11:47 2003
9194 +++ linux-2.4.22-i2c/drivers/media/video/tda9875.c Sun Aug 31 12:29:43 2003
9198 static struct i2c_driver driver = {
9199 + .owner = THIS_MODULE,
9200 .name = "i2c tda9875 driver",
9201 .id = I2C_DRIVERID_TDA9875,
9202 .flags = I2C_DF_NOTIFY,
9203 diff -ru linux-2.4.22-orig/drivers/media/video/tda9887.c linux-2.4.22-i2c/drivers/media/video/tda9887.c
9204 --- linux-2.4.22-orig/drivers/media/video/tda9887.c Wed Aug 27 18:11:47 2003
9205 +++ linux-2.4.22-i2c/drivers/media/video/tda9887.c Sun Aug 31 12:29:43 2003
9207 /* ----------------------------------------------------------------------- */
9209 static struct i2c_driver driver = {
9210 + .owner = THIS_MODULE,
9211 .name = "i2c tda9887 driver",
9212 .id = -1, /* FIXME */
9213 .flags = I2C_DF_NOTIFY,
9214 diff -ru linux-2.4.22-orig/drivers/media/video/tuner-3036.c linux-2.4.22-i2c/drivers/media/video/tuner-3036.c
9215 --- linux-2.4.22-orig/drivers/media/video/tuner-3036.c Sun Sep 30 21:26:06 2001
9216 +++ linux-2.4.22-i2c/drivers/media/video/tuner-3036.c Sun Aug 31 12:29:43 2003
9217 @@ -185,12 +185,13 @@
9218 static struct i2c_driver
9221 - "sab3036", /* name */
9222 - I2C_DRIVERID_SAB3036, /* ID */
9227 + .owner = THIS_MODULE,
9228 + .name = "sab3036",
9229 + .id = I2C_DRIVERID_SAB3036,
9230 + .flags = I2C_DF_NOTIFY,
9231 + .attach_adapter = tuner_probe,
9232 + .detach_client = tuner_detach,
9233 + .command = tuner_command
9236 static struct i2c_client client_template =
9237 diff -ru linux-2.4.22-orig/drivers/media/video/tuner.c linux-2.4.22-i2c/drivers/media/video/tuner.c
9238 --- linux-2.4.22-orig/drivers/media/video/tuner.c Wed Aug 27 18:11:47 2003
9239 +++ linux-2.4.22-i2c/drivers/media/video/tuner.c Sun Aug 31 12:29:43 2003
9241 /* ----------------------------------------------------------------------- */
9243 static struct i2c_driver driver = {
9244 + .owner = THIS_MODULE,
9245 .name = "i2c TV tuner driver",
9246 .id = I2C_DRIVERID_TUNER,
9247 .flags = I2C_DF_NOTIFY,
9248 diff -ru linux-2.4.22-orig/drivers/media/video/tvaudio.c linux-2.4.22-i2c/drivers/media/video/tvaudio.c
9249 --- linux-2.4.22-orig/drivers/media/video/tvaudio.c Wed Aug 27 18:11:47 2003
9250 +++ linux-2.4.22-i2c/drivers/media/video/tvaudio.c Sun Aug 31 12:29:43 2003
9251 @@ -1644,6 +1644,7 @@
9254 static struct i2c_driver driver = {
9255 + .owner = THIS_MODULE,
9256 .name = "generic i2c audio driver",
9257 .id = I2C_DRIVERID_TVAUDIO,
9258 .flags = I2C_DF_NOTIFY,
9259 diff -ru linux-2.4.22-orig/drivers/pcmcia/sa1100_stork.c linux-2.4.22-i2c/drivers/pcmcia/sa1100_stork.c
9260 --- linux-2.4.22-orig/drivers/pcmcia/sa1100_stork.c Tue Jul 15 12:23:03 2003
9261 +++ linux-2.4.22-i2c/drivers/pcmcia/sa1100_stork.c Sun Aug 31 12:32:31 2003
9263 #include <linux/init.h>
9264 #include <linux/kernel.h>
9265 #include <linux/sched.h>
9266 -#include <linux/i2c.h>
9268 #include <asm/hardware.h>
9269 #include <asm/irq.h>
9270 diff -ru linux-2.4.22-orig/drivers/sound/dmasound/dac3550a.c linux-2.4.22-i2c/drivers/sound/dmasound/dac3550a.c
9271 --- linux-2.4.22-orig/drivers/sound/dmasound/dac3550a.c Tue Jul 15 12:22:41 2003
9272 +++ linux-2.4.22-i2c/drivers/sound/dmasound/dac3550a.c Sun Aug 31 12:32:41 2003
9276 struct i2c_driver daca_driver = {
9277 - name: "DAC3550A driver V " DACA_VERSION,
9278 - id: I2C_DRIVERID_DACA,
9279 - flags: I2C_DF_NOTIFY,
9280 - attach_adapter: &daca_attach_adapter,
9281 - detach_client: &daca_detach_client,
9283 - inc_use: NULL, /* &daca_inc_use, */
9284 - dec_use: NULL /* &daca_dev_use */
9285 + .owner = THIS_MODULE,
9286 + .name = "DAC3550A driver V " DACA_VERSION,
9287 + .id = I2C_DRIVERID_DACA,
9288 + .flags = I2C_DF_NOTIFY,
9289 + .attach_adapter = &daca_attach_adapter,
9290 + .detach_client = &daca_detach_client,
9295 diff -ru linux-2.4.22-orig/drivers/sound/dmasound/tas3001c.c linux-2.4.22-i2c/drivers/sound/dmasound/tas3001c.c
9296 --- linux-2.4.22-orig/drivers/sound/dmasound/tas3001c.c Tue Jul 15 12:22:41 2003
9297 +++ linux-2.4.22-i2c/drivers/sound/dmasound/tas3001c.c Sun Aug 31 12:32:41 2003
9301 struct i2c_driver tas_driver = {
9302 - name: "TAS3001C driver V 0.3",
9303 - id: I2C_DRIVERID_TAS,
9304 - flags: I2C_DF_NOTIFY,
9305 - attach_adapter: &tas_attach_adapter,
9306 - detach_client: &tas_detach_client,
9308 - inc_use: NULL, /* &tas_inc_use, */
9309 - dec_use: NULL /* &tas_dev_use */
9310 + .owner = THIS_MODULE,
9311 + .name = "TAS3001C driver V 0.3",
9312 + .id = I2C_DRIVERID_TAS,
9313 + .flags = I2C_DF_NOTIFY,
9314 + .attach_adapter = &tas_attach_adapter,
9315 + .detach_client = &tas_detach_client,
9320 diff -ru linux-2.4.22-orig/drivers/video/matrox/i2c-matroxfb.c linux-2.4.22-i2c/drivers/video/matrox/i2c-matroxfb.c
9321 --- linux-2.4.22-orig/drivers/video/matrox/i2c-matroxfb.c Tue Jul 15 12:23:53 2003
9322 +++ linux-2.4.22-i2c/drivers/video/matrox/i2c-matroxfb.c Sun Aug 31 12:32:51 2003
9324 return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
9327 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
9328 - MOD_INC_USE_COUNT;
9331 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
9332 - MOD_DEC_USE_COUNT;
9335 static struct i2c_adapter matrox_i2c_adapter_template =
9337 + .owner = THIS_MODULE,
9338 .id = I2C_HW_B_G400,
9339 - .inc_use = matroxfb_dh_inc_use,
9340 - .dec_use = matroxfb_dh_dec_use,
9343 static struct i2c_algo_bit_data matrox_i2c_algo_template =
9344 diff -ru linux-2.4.22-orig/drivers/video/matrox/matroxfb_maven.c linux-2.4.22-i2c/drivers/video/matrox/matroxfb_maven.c
9345 --- linux-2.4.22-orig/drivers/video/matrox/matroxfb_maven.c Tue Jul 15 12:23:53 2003
9346 +++ linux-2.4.22-i2c/drivers/video/matrox/matroxfb_maven.c Sun Aug 31 12:32:51 2003
9347 @@ -1246,14 +1246,6 @@
9348 static unsigned short normal_i2c_range[] = { MAVEN_I2CID, MAVEN_I2CID, I2C_CLIENT_END };
9351 -static void maven_inc_use(struct i2c_client* clnt) {
9352 - MOD_INC_USE_COUNT;
9355 -static void maven_dec_use(struct i2c_client* clnt) {
9356 - MOD_DEC_USE_COUNT;
9359 static struct i2c_driver maven_driver;
9361 static int maven_detect_client(struct i2c_adapter* adapter, int address, unsigned short flags,
9362 @@ -1320,14 +1312,13 @@
9363 static int maven_driver_registered = 0;
9365 static struct i2c_driver maven_driver={
9367 - I2C_DRIVERID_MGATVO,
9369 - maven_attach_adapter,
9370 - maven_detach_client,
9374 + .owner = THIS_MODULE,
9376 + .id = I2C_DRIVERID_MGATVO,
9377 + .flags = I2C_DF_NOTIFY,
9378 + .attach_adapter = maven_attach_adapter,
9379 + .detach_client = maven_detach_client,
9380 + .command = maven_command
9383 /* ************************** */