]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.22-i2c-2.8.0.patch
- obsolete
[packages/kernel.git] / linux-2.4.22-i2c-2.8.0.patch
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
4 @@ -303,11 +303,12 @@
5  }
6  
7  static struct i2c_adapter ioc_ops = {
8 -       name:                   "IOC/IOMD",
9 -       id:                     I2C_HW_B_IOC,
10 -       algo_data:              &ioc_data,
11 -       client_register:        ioc_client_reg,
12 -       client_unregister:      ioc_client_unreg
13 +       .owner             = THIS_MODULE,
14 +       .name              = "IOC/IOMD",
15 +       .id                = I2C_HW_B_IOC,
16 +       .algo_data         = &ioc_data,
17 +       .client_register   = ioc_client_reg,
18 +       .client_unregister = ioc_client_unreg
19  };
20  
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
25 @@ -225,12 +225,13 @@
26  }
27  
28  static struct i2c_driver pcf8583_driver = {
29 -       name:           "PCF8583",
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,
36 +       .name           = "PCF8583",
37 +       .id             = I2C_DRIVERID_PCF8583,
38 +       .flags          = I2C_DF_NOTIFY,
39 +       .attach_adapter = pcf8583_probe,
40 +       .detach_client  = pcf8583_detach,
41 +       .command        = pcf8583_command
42  };
43  
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
47 @@ -13,17 +13,23 @@
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
55 +      fi
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
60        fi
61 -      dep_tristate '  NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
62     fi
63  
64 +   dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
65 +
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
70     fi
71  
72     if [ "$CONFIG_MIPS_ITE8172" = "y" ]; then
73 @@ -35,13 +41,13 @@
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
79        fi
80     fi
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
89        fi
90     fi
91  
92 @@ -49,16 +55,11 @@
93        dep_tristate 'Keywest I2C interface in Apple Core99 machines' CONFIG_I2C_KEYWEST $CONFIG_I2C
94     fi
95  
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
99 -   fi
100 -
101  # This is needed for automatic patch generation: sensors code starts here
102  # This is needed for automatic patch generation: sensors code ends here
103  
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
107  
108  fi
109  endmenu
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
112 @@ -5,7 +5,8 @@
113  O_TARGET := i2c.o
114  
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 \
118 +                  i2c-algo-ibm_ocp.o
119  
120  obj-$(CONFIG_I2C)              += i2c-core.o
121  obj-$(CONFIG_I2C_CHARDEV)      += i2c-dev.o
122 @@ -13,16 +14,21 @@
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
143  
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
148 @@ -88,5 +88,10 @@
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.
153 +
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.
158  
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
164 @@ -0,0 +1,67 @@
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.
173 +
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.
178 +
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.
183 +
184 +
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. 
189 +
190 +Bidirectional ports have particular bits connected in following way:
191 +   
192 +                        |
193 +            /-----|     R
194 +         --o|     |-----|
195 +      read  \-----|     /------- Out pin
196 +                      |/
197 +                   - -|\
198 +                write   V
199 +                        |
200 +                       ---  
201 +
202 +
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.
211 +
212 +Layout:
213 +
214 +Cannon 25 pin
215 +
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)
220 +      
221 +no pullups  requied
222 +
223 +Module parameters:
224 +
225 +base = 0xXXX
226 +XXX - 278 or 378
227 +
228 +That's all.
229 +
230 +Daniel Smolik
231 +marvin@sitour.cz
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
234 @@ -53,8 +53,8 @@
235  
236    Flag I2C_M_NOSTART: 
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
246 @@ -66,3 +66,11 @@
247      flag. For example:
248        S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
249 -                      
250 +
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
254 +    message is sent.
255 +    These messages may still fail to SCL lo->hi timeout.
256 +
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
261 @@ -0,0 +1,27 @@
262 +i2c-velleman driver
263 +-------------------
264 +This is a driver for i2c-hw access for Velleman K9000 and other adapters.
265 +
266 +Useful links
267 +------------
268 +Velleman:
269 +       http://www.velleman.be/
270 +
271 +Velleman K8000 Howto:
272 +       http://howto.htlw16.ac.at/k8000-howto.html
273 +
274 +
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
279 +
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
284 +
285 +The libs can be found on http://groups.yahoo.com/group/k8000/files/linux/
286 +
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
293 @@ -1,2 +1,9 @@
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.
300 +
301  Some adapters understand only the SMBus (System Management Bus) protocol,
302  which is a subset from the I2C protocol. Fortunately, many devices use
303 @@ -7,5 +14,5 @@
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).
308  
309  Below is a list of SMBus commands.
310 @@ -55,5 +62,5 @@
311  See Read Byte for more information.
312  
313 -S Addr Wr [A] Data NA P
314 +S Addr Wr [A] Data [A] P
315  
316  
317 @@ -110,5 +117,5 @@
318  ================
319  
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.
324 @@ -121,7 +128,89 @@
325  =================
326  
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.
331  
332  S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
333 +
334 +
335 +SMBus Block Process Call
336 +========================
337 +
338 +SMBus Block Process Call was introduced in Revision 2.0 of the specification.
339 +
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.
342 +
343 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
344 +                             S Addr Rd [A] [Count] A [Data] ... NA P
345 +
346 +
347 +SMBus Host Notify
348 +=================
349 +
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.
354 +
355 +[S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
356 +
357 +
358 +Packet Error Checking (PEC)
359 +===========================
360 +Packet Error Checking was introduced in Revision 1.1 of the specification.
361 +
362 +PEC adds a CRC-8 error-checking byte to all transfers.
363 +
364 +
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
369 +messages above.
370 +
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.
374 +
375 +
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.
382 +
383 +
384 +I2C Block Read
385 +==============
386 +
387 +This command reads a block of bytes from a device, from a 
388 +designated register that is specified through the Comm byte.
389 +
390 +S Addr Wr [A] Comm [A] 
391 +           S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
392 +
393 +
394 +I2C Block Read (2 Comm bytes)
395 +=============================
396 +
397 +This command reads a block of bytes from a device, from a 
398 +designated register that is specified through the two Comm bytes.
399 +
400 +S Addr Wr [A] Comm1 [A] Comm2 [A] 
401 +           S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
402 +
403 +
404 +I2C Block Write
405 +===============
406 +
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.
411 +
412 +S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
413 +
414 +
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
417 @@ -5,5 +5,5 @@
418  
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 
422  devices.
423  
424 @@ -44,5 +44,5 @@
425  Included Bus Drivers
426  ====================
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'.
429  
430  
431 @@ -50,7 +50,7 @@
432  ------------
433  
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
440  
441  Algorithm drivers
442 @@ -60,5 +60,5 @@
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)
447  
448  Adapter drivers
449 @@ -67,7 +67,7 @@
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
463 @@ -25,14 +25,12 @@
464  address.
465  
466 -  struct i2c_driver foo_driver
467 -  {  
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 */
484    }
485   
486 @@ -51,41 +49,6 @@
487  below.
488  
489 -
490 -Module usage count
491 -==================
492 -
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).
498 -
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.
503 -
504 -  void foo_inc_use (struct i2c_client *client)
505 -  {
506 -  #ifdef MODULE
507 -    MOD_INC_USE_COUNT;
508 -  #endif
509 -  }
510 -
511 -  void foo_dec_use (struct i2c_client *client)
512 -  {
513 -  #ifdef MODULE
514 -    MOD_DEC_USE_COUNT;
515 -  #endif
516 -  }
517 -
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 *);
522 -
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
525 -an adapter driver! 
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.
528  
529  
530 @@ -366,5 +329,5 @@
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).
537 @@ -449,7 +412,7 @@
538         need it, remove it. We do it here to help to lessen memory
539         fragmentation. */
540 -    if (! (new_client = kmalloc(sizeof(struct i2c_client)) + 
541 +    if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
542                                  sizeof(struct foo_data),
543 -                                GFP_KERNEL)) {
544 +                                GFP_KERNEL))) {
545        err = -ENOMEM;
546        goto ERROR0;
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
549 @@ -0,0 +1,346 @@
550 +/*
551 +   -------------------------------------------------------------------------
552 +   i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
553 +   -------------------------------------------------------------------------
554 +  
555 +   Ian DaSilva, MontaVista Software, Inc.
556 +   idasilva@mvista.com or source@mvista.com
557 +
558 +   Copyright 2000 MontaVista Software Inc.
559 +
560 +   Changes made to support the IIC peripheral on the IBM PPC 405 
561 +
562 +
563 +   ----------------------------------------------------------------------------
564 +   This file was highly leveraged from i2c-elektor.c, which was created
565 +   by Simon G. Vogl and Hans Berglund:
566 +
567
568 +     Copyright (C) 1995-97 Simon G. Vogl
569 +                   1998-99 Hans Berglund
570 +
571 +   With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
572 +   Frodo Looijaard <frodol@dds.nl>
573 +
574 +
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.
579 +
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.
584 +
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 +   ----------------------------------------------------------------------------
589 +
590 +   History: 01/20/12 - Armin
591 +       akuster@mvista.com
592 +       ported up to 2.4.16+    
593 +
594 +   Version 02/03/25 - Armin
595 +       converted to ocp format
596 +       removed commented out or #if 0 code
597 +
598 +   TODO: convert to ocp_register
599 +         add PM hooks
600 +
601 +*/
602 +
603 +
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>
613 +#include <asm/io.h>
614 +#include <asm/ocp.h>
615 +
616 +/*
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.
620 + */ 
621 +
622 +/*
623 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
624 + */
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];
628 +
629 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
630 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
631 +
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;
636 +
637 +
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                               */
643 +
644 +/* ----- local functions ----------------------------------------------        */
645 +
646 +//
647 +// Description: Write a byte to IIC hardware
648 +//
649 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
650 +{
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
654 +   // completed.
655 +   // Delays at this level (to protect writes) are not needed here.
656 +   writeb(val, ctl);
657 +}
658 +
659 +
660 +//
661 +// Description: Read a byte from IIC hardware
662 +//
663 +static int iic_ibmocp_getbyte(void *data, int ctl)
664 +{
665 +   int val;
666 +
667 +   val = readb(ctl);
668 +   return (val);
669 +}
670 +
671 +
672 +//
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
675 +// as a slave
676 +//
677 +static int iic_ibmocp_getown(void *data)
678 +{
679 +   return(((struct iic_ibm *)(data))->iic_own);
680 +}
681 +
682 +
683 +//
684 +// Description: Return the clock rate
685 +//
686 +static int iic_ibmocp_getclock(void *data)
687 +{
688 +   return(((struct iic_ibm *)(data))->iic_clock);
689 +}
690 +
691 +
692 +
693 +//
694 +// Description:  Put this process to sleep.  We will wake up when the
695 +// IIC controller interrupts.
696 +//
697 +static void iic_ibmocp_waitforpin(void *data) {
698 +
699 +   int timeout = 2;
700 +   struct iic_ibm *priv_data = data;
701 +
702 +   //
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. 
706 +   //
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 );
711 +      } else
712 +        iic_pending = 0;
713 +      spin_unlock_irq(&irq_driver_lock);
714 +   } else {
715 +      //
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.
720 +      //
721 +      // udelay is probably not the best choice for this since it is
722 +      // the equivalent of a busy wait
723 +      //
724 +      udelay(100);
725 +   }
726 +   //printk("iic_ibmocp_waitforpin: exitting\n");
727 +}
728 +
729 +
730 +//
731 +// Description: The registered interrupt handler
732 +//
733 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs) 
734 +{
735 +   int ret;
736 +   struct iic_regs *iic;
737 +   struct iic_ibm *priv_data = dev_id;
738 +   iic = (struct iic_regs *) priv_data->iic_base;
739 +   iic_pending = 1;
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]));
747 +}
748 +
749 +
750 +//
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.
755 +//
756 +static int iic_hw_resrc_init(int instance)
757 +{
758 +
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);
761 +
762 +   DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
763 +
764 +   if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
765 +       
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;
771 +      } else {
772 +         DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
773 +      }
774 +   }
775 +   return 0;
776 +}
777 +
778 +
779 +//
780 +// Description: Release irq and memory
781 +//
782 +static void iic_ibmocp_release(void)
783 +{
784 +   int i;
785 +
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);
791 +      }
792 +      kfree(iic_ibmocp_data[i]);
793 +      kfree(iic_ibmocp_ops[i]);
794 +   }
795 +}
796 +
797 +
798 +//
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)
802 +//
803 +static int __init iic_ibmocp_init(void) 
804 +{
805 +   int i;
806 +
807 +   printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
808
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) {
812 +         return -ENOMEM;
813 +      }
814 +      memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
815 +      
816 +      switch (i) {
817 +             case 0:
818 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
819 +             break;
820 +             case 1:
821 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
822 +             break;
823 +      }
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;
827
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));
832 +
833 +
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;
843 +      
844 +            iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
845 +      if(iic_ibmocp_ops[i] == NULL) {
846 +         return -ENOMEM;
847 +      }
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];
854 +       
855 +      
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)
859 +         return -ENODEV;
860 +      } else {
861 +         return -ENODEV;
862 +      }
863 +      DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
864 +   }
865 +   return 0;
866 +}
867 +
868 +
869 +static void __exit iic_ibmocp_exit(void)
870 +{
871 +   int i;
872 +
873 +   for(i=0; i<IIC_NUMS; i++) {
874 +      i2c_ocp_del_bus(iic_ibmocp_ops[i]);
875 +   }
876 +   iic_ibmocp_release();
877 +}
878 +
879 +//
880 +// If modules is NOT defined when this file is compiled, then the MODULE_*
881 +// macros will resolve to nothing
882 +//
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");
886 +
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");
892 +
893 +
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
898 @@ -0,0 +1,616 @@
899 +/*
900 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
901 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
902 + *
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.
907 +
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.
912 +
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.
916 + *
917 + * moved into proper i2c interface; separated out platform specific 
918 + * parts into i2c-rpx.c
919 + * Brad Parker (brad@heeltoe.com)
920 + */
921 +
922 +// XXX todo
923 +// timeout sleep?
924 +
925 +/* $Id$ */
926 +
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>
938 +
939 +
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;
944 +
945 +int cpm_debug = 0;
946 +
947 +static  void
948 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
949 +{
950 +       volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
951 +       if (cpm_debug > 1)
952 +               printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
953 +#if 0
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;
958 +#endif
959 +       /* Clear interrupt.
960 +       */
961 +       i2c->i2c_i2cer = 0xff;
962 +
963 +       /* Get 'me going again.
964 +       */
965 +       wake_up_interruptible(&iic_wait);
966 +}
967 +
968 +static void
969 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
970 +{
971 +       volatile iic_t          *iip = cpm->iip;
972 +       volatile i2c8xx_t       *i2c = cpm->i2c;
973 +       unsigned char brg;
974 +       bd_t *bd = (bd_t *)__res;
975 +
976 +       if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
977 +
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.
981 +        */
982 +       iip->iic_rstate = 0;
983 +       iip->iic_rdp = 0;
984 +       iip->iic_rbptr = 0;
985 +       iip->iic_rbc = 0;
986 +       iip->iic_rxtmp = 0;
987 +       iip->iic_tstate = 0;
988 +       iip->iic_tdp = 0;
989 +       iip->iic_tbptr = 0;
990 +       iip->iic_tbc = 0;
991 +       iip->iic_txtmp = 0;
992 +
993 +       /* Set up the IIC parameters in the parameter ram.
994 +       */
995 +       iip->iic_tbase = r_tbase = cpm->dp_addr;
996 +       iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
997 +
998 +       iip->iic_tfcr = SMC_EB;
999 +       iip->iic_rfcr = SMC_EB;
1000 +
1001 +       /* Set maximum receive size.
1002 +       */
1003 +       iip->iic_mrblr = CPM_MAX_READ;
1004 +
1005 +       /* Initialize Tx/Rx parameters.
1006 +       */
1007 +       if (cpm->reloc == 0) {
1008 +               volatile cpm8xx_t *cp = cpm->cp;
1009 +
1010 +               cp->cp_cpcr =
1011 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
1012 +               while (cp->cp_cpcr & CPM_CR_FLG);
1013 +       } else {
1014 +               iip->iic_rbptr = iip->iic_rbase;
1015 +               iip->iic_tbptr = iip->iic_tbase;
1016 +               iip->iic_rstate = 0;
1017 +               iip->iic_tstate = 0;
1018 +       }
1019 +
1020 +       /* Select an arbitrary address.  Just make sure it is unique.
1021 +       */
1022 +       i2c->i2c_i2add = 0xfe;
1023 +
1024 +       /* Make clock run at 60 KHz.
1025 +       */
1026 +       brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
1027 +       i2c->i2c_i2brg = brg;
1028 +
1029 +       i2c->i2c_i2mod = 0x00; 
1030 +       i2c->i2c_i2com = 0x01; /* Master mode */
1031 +
1032 +       /* Disable interrupts.
1033 +       */
1034 +       i2c->i2c_i2cmr = 0;
1035 +       i2c->i2c_i2cer = 0xff;
1036 +
1037 +       init_waitqueue_head(&iic_wait);
1038 +
1039 +       /* Install interrupt handler.
1040 +       */
1041 +       if (cpm_debug) {
1042 +               printk ("%s[%d] Install ISR for IRQ %d\n",
1043 +                       __func__,__LINE__, CPMVEC_I2C);
1044 +       }
1045 +       (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
1046 +}
1047 +
1048 +
1049 +static int
1050 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
1051 +{
1052 +       volatile i2c8xx_t *i2c = cpm->i2c;
1053 +
1054 +       /* Shut down IIC.
1055 +       */
1056 +       i2c->i2c_i2mod &= ~1;
1057 +       i2c->i2c_i2cmr = 0;
1058 +       i2c->i2c_i2cer = 0xff;
1059 +
1060 +       return(0);
1061 +}
1062 +
1063 +static void 
1064 +cpm_reset_iic_params(volatile iic_t *iip)
1065 +{
1066 +       iip->iic_tbase = r_tbase;
1067 +       iip->iic_rbase = r_rbase;
1068 +
1069 +       iip->iic_tfcr = SMC_EB;
1070 +       iip->iic_rfcr = SMC_EB;
1071 +
1072 +       iip->iic_mrblr = CPM_MAX_READ;
1073 +
1074 +       iip->iic_rstate = 0;
1075 +       iip->iic_rdp = 0;
1076 +       iip->iic_rbptr = iip->iic_rbase;
1077 +       iip->iic_rbc = 0;
1078 +       iip->iic_rxtmp = 0;
1079 +       iip->iic_tstate = 0;
1080 +       iip->iic_tdp = 0;
1081 +       iip->iic_tbptr = iip->iic_tbase;
1082 +       iip->iic_tbc = 0;
1083 +       iip->iic_txtmp = 0;
1084 +}
1085 +
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)
1089 +
1090 +static void force_close(struct i2c_algo_8xx_data *cpm)
1091 +{
1092 +       volatile i2c8xx_t *i2c = cpm->i2c;
1093 +       if (cpm->reloc == 0) { /* micro code disabled */
1094 +               volatile cpm8xx_t *cp = cpm->cp;
1095 +
1096 +               if (cpm_debug) printk("force_close()\n");
1097 +               cp->cp_cpcr =
1098 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
1099 +                       CPM_CR_FLG;
1100 +
1101 +               while (cp->cp_cpcr & CPM_CR_FLG);
1102 +       }
1103 +       i2c->i2c_i2cmr = 0x00;  /* Disable all interrupts */
1104 +       i2c->i2c_i2cer = 0xff; 
1105 +}
1106 +
1107 +
1108 +/* Read from IIC...
1109 + * abyte = address byte, with r/w flag already set
1110 + */
1111 +static int
1112 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
1113 +{
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;
1118 +       u_char *tb;
1119 +       unsigned long flags, tmo;
1120 +
1121 +       if (count >= CPM_MAX_READ)
1122 +               return -EINVAL;
1123 +
1124 +       /* check for and use a microcode relocation patch */
1125 +       if (cpm->reloc) {
1126 +               cpm_reset_iic_params(iip);
1127 +       }
1128 +
1129 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1130 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1131 +
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).
1135 +        */
1136 +       tb = cpm->temp;
1137 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1138 +       tb[0] = abyte;          /* Device address byte w/rw flag */
1139 +
1140 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1141 +
1142 +       if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
1143 +
1144 +       tbdf->cbd_bufaddr = __pa(tb);
1145 +       tbdf->cbd_datlen = count + 1;
1146 +       tbdf->cbd_sc =
1147 +               BD_SC_READY | BD_SC_LAST |
1148 +               BD_SC_WRAP | BD_IIC_START;
1149 +
1150 +       iip->iic_mrblr = count +1; /* prevent excessive read, +1
1151 +                                     is needed otherwise will the
1152 +                                     RXB interrupt come too early */
1153 +
1154 +       /* flush will invalidate too. */
1155 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1156 +
1157 +       rbdf->cbd_datlen = 0;
1158 +       rbdf->cbd_bufaddr = __pa(buf);
1159 +       rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
1160 +       if(count > 16){
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 */
1167 +
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 */
1178 +       }               
1179 +
1180 +       if (signal_pending(current) || !tmo){
1181 +               force_close(cpm);
1182 +               if(cpm_debug) 
1183 +                       printk("IIC read: timeout!\n");
1184 +               return -EIO;
1185 +       }
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 */
1189 +       udelay(4);
1190 +       i2c->i2c_i2mod &= ~1;
1191 +#endif
1192 +       if (cpm_debug) {
1193 +               printk("tx sc %04x, rx sc %04x\n",
1194 +                      tbdf->cbd_sc, rbdf->cbd_sc);
1195 +       }
1196 +
1197 +       if (tbdf->cbd_sc & BD_SC_READY) {
1198 +               printk("IIC read; complete but tbuf ready\n");
1199 +               force_close(cpm);
1200 +               printk("tx sc %04x, rx sc %04x\n",
1201 +                      tbdf->cbd_sc, rbdf->cbd_sc);
1202 +       }
1203 +
1204 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1205 +               if (cpm_debug)
1206 +                       printk("IIC read; no ack\n");
1207 +               return -EREMOTEIO;
1208 +       }
1209 +
1210 +       if (rbdf->cbd_sc & BD_SC_EMPTY) {
1211 +               /* force_close(cpm); */
1212 +               if (cpm_debug){
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);
1216 +               }
1217 +               return -EREMOTEIO;
1218 +       }
1219 +
1220 +       if (rbdf->cbd_sc & BD_SC_OV) {
1221 +               if (cpm_debug)
1222 +                       printk("IIC read; Overrun\n");
1223 +               return -EREMOTEIO;;
1224 +       }
1225 +
1226 +       if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
1227 +
1228 +       if (rbdf->cbd_datlen < count) {
1229 +               if (cpm_debug)
1230 +                       printk("IIC read; short, wanted %d got %d\n",
1231 +                              count, rbdf->cbd_datlen);
1232 +               return 0;
1233 +       }
1234 +
1235 +       return count;
1236 +}
1237 +
1238 +/* Write to IIC...
1239 + * addr = address byte, with r/w flag already set
1240 + */
1241 +static int
1242 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
1243 +{
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;
1248 +       u_char *tb;
1249 +       unsigned long flags, tmo;
1250 +
1251 +       /* check for and use a microcode relocation patch */
1252 +       if (cpm->reloc) {
1253 +               cpm_reset_iic_params(iip);
1254 +       }
1255 +       tb = cpm->temp;
1256 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1257 +       *tb = abyte;            /* Device address byte w/rw flag */
1258 +
1259 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1260 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1261 +
1262 +       if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1263 +
1264 +       /* set up 2 descriptors */
1265 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1266 +
1267 +       tbdf[0].cbd_bufaddr = __pa(tb);
1268 +       tbdf[0].cbd_datlen = 1;
1269 +       tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1270 +
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;
1274 +
1275 +       if(count > 16){
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 */
1282 +               
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 */
1293 +       }               
1294 +
1295 +       if (signal_pending(current) || !tmo){
1296 +               force_close(cpm);
1297 +               if(cpm_debug && !tmo) 
1298 +                       printk("IIC write: timeout!\n");
1299 +               return -EIO;
1300 +       }
1301 +       
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 */
1305 +       udelay(4);
1306 +       i2c->i2c_i2mod &= ~1;
1307 +#endif
1308 +       if (cpm_debug) {
1309 +               printk("tx0 sc %04x, tx1 sc %04x\n",
1310 +                      tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1311 +       }
1312 +
1313 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1314 +               if (cpm_debug) 
1315 +                       printk("IIC write; no ack\n");
1316 +               return 0;
1317 +       }
1318 +         
1319 +       if (tbdf->cbd_sc & BD_SC_READY) {
1320 +               if (cpm_debug)
1321 +                       printk("IIC write; complete but tbuf ready\n");
1322 +               return 0;
1323 +       }
1324 +
1325 +       return count;
1326 +}
1327 +
1328 +/* See if an IIC address exists..
1329 + * addr = 7 bit address, unshifted
1330 + */
1331 +static int
1332 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1333 +{
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;
1338 +       u_char *tb;
1339 +       unsigned long flags, len, tmo;
1340 +
1341 +       if (cpm_debug > 1)
1342 +               printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1343 +
1344 +       /* check for and use a microcode relocation patch */
1345 +       if (cpm->reloc) {
1346 +               cpm_reset_iic_params(iip);
1347 +       }
1348 +
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);
1352 +       }
1353 +
1354 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1355 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1356 +
1357 +       tb = cpm->temp;
1358 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1359 +
1360 +       /* do a simple read */
1361 +       tb[0] = (addr << 1) | 1;        /* device address (+ read) */
1362 +       len = 2;
1363 +
1364 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1365 +
1366 +       tbdf->cbd_bufaddr = __pa(tb);
1367 +       tbdf->cbd_datlen = len;
1368 +       tbdf->cbd_sc =
1369 +               BD_SC_READY | BD_SC_LAST |
1370 +               BD_SC_WRAP | BD_IIC_START;
1371 +
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;
1375 +
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 */
1381 +
1382 +       if (cpm_debug > 1) printk("about to sleep\n");
1383 +
1384 +       /* wait for IIC transfer */
1385 +       tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1386 +       local_irq_restore(flags);
1387 +
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 */
1391 +       udelay(4);
1392 +       i2c->i2c_i2mod &= ~1;
1393 +#endif
1394 +
1395 +       if (signal_pending(current) || !tmo){
1396 +               force_close(cpm);
1397 +               if(cpm_debug && !tmo) 
1398 +                       printk("IIC tryaddress: timeout!\n");
1399 +               return -EIO;
1400 +       }
1401 +
1402 +       if (cpm_debug > 1) printk("back from sleep\n");
1403 +
1404 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1405 +               if (cpm_debug > 1) printk("IIC try; no ack\n");
1406 +               return 0;
1407 +       }
1408 +         
1409 +       if (tbdf->cbd_sc & BD_SC_READY) {
1410 +               printk("IIC try; complete but tbuf ready\n");
1411 +       }
1412 +       
1413 +       return 1;
1414 +}
1415 +
1416 +static int cpm_xfer(struct i2c_adapter *adap,
1417 +                   struct i2c_msg msgs[], 
1418 +                   int num)
1419 +{
1420 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1421 +       struct i2c_msg *pmsg;
1422 +       int i, ret;
1423 +       u_char addr;
1424 +    
1425 +       for (i = 0; i < num; i++) {
1426 +               pmsg = &msgs[i];
1427 +
1428 +               if (cpm_debug)
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);
1432 +
1433 +               addr = pmsg->addr << 1;
1434 +               if (pmsg->flags & I2C_M_RD )
1435 +                       addr |= 1;
1436 +               if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1437 +                       addr ^= 1;
1438 +    
1439 +               if (!(pmsg->flags & I2C_M_NOSTART)) {
1440 +               }
1441 +               if (pmsg->flags & I2C_M_RD ) {
1442 +                       /* read bytes into buffer*/
1443 +                       ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1444 +                       if (cpm_debug)
1445 +                               printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1446 +                       if (ret < pmsg->len ) {
1447 +                               return (ret<0)? ret : -EREMOTEIO;
1448 +                       }
1449 +               } else {
1450 +                       /* write bytes from buffer */
1451 +                       ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1452 +                       if (cpm_debug)
1453 +                               printk("i2c-algo-8xx.o: wrote %d\n", ret);
1454 +                       if (ret < pmsg->len ) {
1455 +                               return (ret<0) ? ret : -EREMOTEIO;
1456 +                       }
1457 +               }
1458 +       }
1459 +       return (num);
1460 +}
1461 +
1462 +static u32 cpm_func(struct i2c_adapter *adap)
1463 +{
1464 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
1465 +              I2C_FUNC_PROTOCOL_MANGLING; 
1466 +}
1467 +
1468 +/* -----exported algorithm data: ------------------------------------- */
1469 +
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,
1476 +};
1477 +
1478 +/* 
1479 + * registering functions to load algorithms at runtime 
1480 + */
1481 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1482 +{
1483 +       int i;
1484 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1485 +
1486 +       if (cpm_debug)
1487 +               printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1488 +                      adap->name);
1489 +
1490 +       /* register new adapter to i2c module... */
1491 +
1492 +       adap->id |= cpm_algo.id;
1493 +       adap->algo = &cpm_algo;
1494 +
1495 +       i2c_add_adapter(adap);
1496 +       cpm_iic_init(cpm);
1497 +}
1498 +
1499 +
1500 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1501 +{
1502 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1503 +
1504 +       cpm_iic_shutdown(cpm);
1505 +
1506 +       return i2c_del_adapter(adap);
1507 +}
1508 +
1509 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1510 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1511 +
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
1517 @@ -0,0 +1,43 @@
1518 +/* ------------------------------------------------------------------------- */
1519 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM                      */
1520 +/*
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.
1525 +
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.
1530 +
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 +/* ------------------------------------------------------------------------- */
1535 +
1536 +/* $Id$ */
1537 +
1538 +#ifndef _LINUX_I2C_ALGO_8XX_H
1539 +#define _LINUX_I2C_ALGO_8XX_H
1540 +
1541 +#include "asm/commproc.h"
1542 +
1543 +struct i2c_algo_8xx_data {
1544 +       uint dp_addr;
1545 +       int reloc;
1546 +       volatile i2c8xx_t *i2c;
1547 +       volatile iic_t  *iip;
1548 +       volatile cpm8xx_t *cp;
1549 +
1550 +       int     (*setisr) (int irq,
1551 +                          void (*func)(void *, void *),
1552 +                          void *data);
1553 +
1554 +       u_char  temp[513];
1555 +};
1556 +
1557 +int i2c_8xx_add_bus(struct i2c_adapter *);
1558 +int i2c_8xx_del_bus(struct i2c_adapter *);
1559 +
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
1563 @@ -22,5 +22,5 @@
1564     Frodo Looijaard <frodol@dds.nl> */
1565  
1566 -/* $Id$ */
1567 +/* $Id$ */
1568  
1569  #include <linux/kernel.h>
1570 @@ -28,14 +28,11 @@
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>
1579 -
1580  #include <linux/i2c.h>
1581  #include <linux/i2c-algo-bit.h>
1582  
1583 +
1584  /* ----- global defines ----------------------------------------------- */
1585  #define DEB(x) if (i2c_debug>=1) x;
1586 @@ -45,25 +42,11 @@
1587         /* debug the protocol by showing transferred bits */
1588  
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  */
1593 -/*
1594 -#define SLO_IO      jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1595 -                        if (need_resched) schedule();
1596 -*/
1597 -
1598  
1599  /* ----- global variables ---------------------------------------------        */
1600  
1601 -#ifdef SLO_IO
1602 -       int jif;
1603 -#endif
1604 -
1605  /* module parameters:
1606   */
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         */
1610  
1611  /* --- setting states on the bus with the right timing: ---------------        */
1612 @@ -90,7 +73,4 @@
1613         setscl(adap,0);
1614         udelay(adap->udelay);
1615 -#ifdef SLO_IO
1616 -       SLO_IO
1617 -#endif
1618  }
1619  
1620 @@ -101,15 +81,14 @@
1621  static inline int sclhi(struct i2c_algo_bit_data *adap)
1622  {
1623 -       int start=jiffies;
1624 +       int start;
1625  
1626         setscl(adap,1);
1627  
1628 -       udelay(adap->udelay);
1629 -
1630         /* Not all adapters have scl sense line... */
1631         if (adap->getscl == NULL )
1632                 return 0;
1633  
1634 -       while (! getscl(adap) ) {       
1635 +       start=jiffies;
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. 
1641                  */
1642 -               setscl(adap,1);
1643                 if (time_after_eq(jiffies, start+adap->timeout)) {
1644                         return -ETIMEDOUT;
1645                 }
1646 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1647                 if (current->need_resched)
1648                         schedule();
1649 -       }
1650 -       DEBSTAT(printk("needed %ld jiffies\n", jiffies-start));
1651 -#ifdef SLO_IO
1652 -       SLO_IO
1653 +#else
1654 +               cond_resched();
1655  #endif
1656 +       }
1657 +       DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1658 +       udelay(adap->udelay);
1659         return 0;
1660  } 
1661 @@ -146,5 +126,5 @@
1662         DEBPROTO(printk(" Sr "));
1663         setsda(adap,1);
1664 -       setscl(adap,1);
1665 +       sclhi(adap);
1666         udelay(adap->udelay);
1667         
1668 @@ -180,12 +160,12 @@
1669  
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 );
1674                 setsda(adap,sb);
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));
1681                         return -ETIMEDOUT;
1682                 };
1683 @@ -198,12 +178,13 @@
1684         sdahi(adap);
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;
1689         };
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));
1694  
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 ") );
1699         scllo(adap);
1700         return 0==ack;          /* return 1 if device acked      */
1701 @@ -221,9 +202,8 @@
1702  
1703         /* assert: scl is low */
1704 -       DEB2(printk("i2c_inb.\n"));
1705 -
1706         sdahi(adap);
1707         for (i=0;i<8;i++) {
1708                 if (sclhi(adap)<0) { /* timeout */
1709 +                       DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1710                         return -ETIMEDOUT;
1711                 };
1712 @@ -234,5 +214,7 @@
1713         }
1714         /* assert: scl is low */
1715 -       DEBPROTO(printk(" %2.2x", indata & 0xff));
1716 +       DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1717 +
1718 +       DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1719         return (int) (indata & 0xff);
1720  }
1721 @@ -246,67 +228,67 @@
1722         sda=getsda(adap);
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");
1726                 return 0;               
1727         }
1728         scl=getscl(adap);
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);
1735                 goto bailout;
1736         }
1737         sdalo(adap);
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),
1740                getsda(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);
1744                 sdahi(adap);
1745                 goto bailout;
1746         }
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",
1750                         name);
1751                 goto bailout;
1752         }               
1753         sdahi(adap);
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),
1756                getsda(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);
1760                 sdahi(adap);
1761                 goto bailout;
1762         }
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",
1766                        name);
1767         goto bailout;
1768         }
1769         scllo(adap);
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),
1772                getsda(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);
1776                 sclhi(adap);
1777                 goto bailout;
1778         }
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",
1782                         name);
1783                 goto bailout;
1784         }
1785         sclhi(adap);
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),
1788                getsda(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);
1792                 sclhi(adap);
1793                 goto bailout;
1794         }
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",
1798                         name);
1799                 goto bailout;
1800         }
1801 -       printk("i2c-algo-bit.o: %s passed test.\n",name);
1802 +       printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
1803         return 0;
1804  bailout:
1805 @@ -342,14 +324,19 @@
1806                 udelay(adap->udelay);
1807         }
1808 -       DEB2(if (i) printk("i2c-algo-bit.o: needed %d retries for %d\n",
1809 -                          i,addr));
1810 +       DEB2(if (i)
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?" )
1814 +           );
1815         return ret;
1816  }
1817  
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)
1820  {
1821         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1822         char c;
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; 
1827         int retval;
1828         int wrcount=0;
1829 @@ -357,13 +344,13 @@
1830         while (count > 0) {
1831                 c = *temp;
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);
1836 -               if (retval>0) {
1837 +               if ((retval>0) || (nak_ok && (retval==0)))  { /* ok or ignored NAK */
1838                         count--; 
1839                         temp++;
1840                         wrcount++;
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",
1844                                i2c_adap->name);
1845                         i2c_stop(adap);
1846 @@ -379,10 +366,11 @@
1847  }
1848  
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)
1851  {
1852 -       char *temp = buf;
1853         int inval;
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;
1858  
1859         while (count > 0) {
1860 @@ -393,5 +381,5 @@
1861                         rdcount++;
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");
1865                         break;
1866                 }
1867 @@ -406,5 +394,5 @@
1868                 if (sclhi(adap)<0) {    /* timeout */
1869                         sdahi(adap);
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");
1872                         return -ETIMEDOUT;
1873                 };
1874 @@ -421,31 +409,34 @@
1875   * reads, writes as well as 10bit-addresses.
1876   * returns:
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...) 
1881   */
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) 
1885  {
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;
1889  
1890         unsigned char addr;
1891 -       int ret;
1892 +       int ret, retries;
1893 +
1894 +       retries = nak_ok ? 0 : i2c_adap->retries;
1895 +       
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);
1903 -               if (ret!=1) {
1904 -                       printk("died at extended address code.\n");
1905 +               if ((ret != 1) && !nak_ok)  {
1906 +                       printk(KERN_ERR "died at extended address code.\n");
1907                         return -EREMOTEIO;
1908                 }
1909                 /* the remaining 8 bit address */
1910                 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
1911 -               if (ret != 1) {
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");
1916                         return -EREMOTEIO;
1917                 }
1918 @@ -455,6 +446,6 @@
1919                         addr |= 0x01;
1920                         ret = try_address(i2c_adap, addr, retries);
1921 -                       if (ret!=1) {
1922 -                               printk("died at extended address code.\n");
1923 +                       if ((ret!=1) && !nak_ok) {
1924 +                               printk(KERN_ERR "died at extended address code.\n");
1925                                 return -EREMOTEIO;
1926                         }
1927 @@ -467,8 +458,8 @@
1928                         addr ^= 1;
1929                 ret = try_address(i2c_adap, addr, retries);
1930 -               if (ret!=1) {
1931 +               if ((ret!=1) && !nak_ok)
1932                         return -EREMOTEIO;
1933 -               }
1934         }
1935 +
1936         return 0;
1937  }
1938 @@ -481,23 +472,25 @@
1939         
1940         int i,ret;
1941 +       unsigned short nak_ok;
1942  
1943         i2c_start(adap);
1944         for (i=0;i<num;i++) {
1945                 pmsg = &msgs[i];
1946 +               nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 
1947                 if (!(pmsg->flags & I2C_M_NOSTART)) {
1948                         if (i) {
1949                                 i2c_repstart(adap);
1950                         }
1951 -                       ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
1952 -                       if (ret != 0) {
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;
1961                         }
1962                 }
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;
1971 @@ -505,6 +498,6 @@
1972                 } else {
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 @@
1981  }
1982  
1983 -static int algo_control(struct i2c_adapter *adapter, 
1984 -       unsigned int cmd, unsigned long arg)
1985 -{
1986 -       return 0;
1987 -}
1988 -
1989 -static u32 bit_func(struct i2c_adapter *adap)
1990 +static u32 bit_func(struct i2c_adapter *i2c_adap)
1991  {
1992         return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
1993 @@ -532,12 +519,9 @@
1994  
1995  static struct i2c_algorithm i2c_bit_algo = {
1996 -       "Bit-shift algorithm",
1997 -       I2C_ALGO_BIT,
1998 -       bit_xfer,
1999 -       NULL,
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,
2009  };
2010  
2011 @@ -547,5 +531,4 @@
2012  int i2c_bit_add_bus(struct i2c_adapter *adap)
2013  {
2014 -       int i;
2015         struct i2c_algo_bit_data *bit_adap = adap->algo_data;
2016  
2017 @@ -556,5 +539,5 @@
2018         }
2019  
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",
2022                     adap->name));
2023  
2024 @@ -567,26 +550,5 @@
2025         adap->retries = 3;      /* be replaced by defines       */
2026  
2027 -       /* scan bus */
2028 -       if (bit_scan) {
2029 -               int ack;
2030 -               printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
2031 -                      adap->name);
2032 -               for (i = 0x00; i < 0xff; i+=2) {
2033 -                       i2c_start(bit_adap);
2034 -                       ack = i2c_outb(adap,i);
2035 -                       i2c_stop(bit_adap);
2036 -                       if (ack>0) {
2037 -                               printk("(%02x)",i>>1); 
2038 -                       } else 
2039 -                               printk("."); 
2040 -               }
2041 -               printk("\n");
2042 -       }
2043 -
2044 -#ifdef MODULE
2045 -       MOD_INC_USE_COUNT;
2046 -#endif
2047         i2c_add_adapter(adap);
2048 -
2049         return 0;
2050  }
2051 @@ -595,29 +557,10 @@
2052  int i2c_bit_del_bus(struct i2c_adapter *adap)
2053  {
2054 -       int res;
2055 -
2056 -       if ((res = i2c_del_adapter(adap)) < 0)
2057 -               return res;
2058 -
2059 -       DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
2060 -
2061 -#ifdef MODULE
2062 -       MOD_DEC_USE_COUNT;
2063 -#endif
2064 -       return 0;
2065 -}
2066 -
2067 -int __init i2c_algo_bit_init (void)
2068 -{
2069 -       printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
2070 -       return 0;
2071 +       return i2c_del_adapter(adap);
2072  }
2073  
2074 -
2075 -
2076  EXPORT_SYMBOL(i2c_bit_add_bus);
2077  EXPORT_SYMBOL(i2c_bit_del_bus);
2078  
2079 -#ifdef MODULE
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 @@
2083  
2084  MODULE_PARM(bit_test, "i");
2085 -MODULE_PARM(bit_scan, "i");
2086  MODULE_PARM(i2c_debug,"i");
2087  
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");
2092 -
2093 -int init_module(void) 
2094 -{
2095 -       return i2c_algo_bit_init();
2096 -}
2097 -
2098 -void cleanup_module(void) 
2099 -{
2100 -}
2101 -#endif
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
2105 @@ -22,10 +22,8 @@
2106     Frodo Looijaard <frodol@dds.nl> */
2107  
2108 -/* $Id$ */
2109 +/* $Id$ */
2110  
2111 -#ifndef I2C_ALGO_BIT_H
2112 -#define I2C_ALGO_BIT_H 1
2113 -
2114 -#include <linux/i2c.h>
2115 +#ifndef _LINUX_I2C_ALGO_BIT_H
2116 +#define _LINUX_I2C_ALGO_BIT_H
2117  
2118  /* --- Defines for bit-adapters ---------------------------------------        */
2119 @@ -43,7 +41,8 @@
2120  
2121         /* local settings */
2122 -       int udelay;
2123 -       int mdelay;
2124 -       int timeout;
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 */
2129  };
2130  
2131 @@ -53,3 +52,3 @@
2132  int i2c_bit_del_bus(struct i2c_adapter *);
2133  
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
2138 @@ -0,0 +1,901 @@
2139 +/*
2140 +   -------------------------------------------------------------------------
2141 +   i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters       
2142 +   -------------------------------------------------------------------------
2143 +      
2144 +   Ian DaSilva, MontaVista Software, Inc.
2145 +   idasilva@mvista.com or source@mvista.com
2146 +
2147 +   Copyright 2000 MontaVista Software Inc.
2148 +
2149 +   Changes made to support the IIC peripheral on the IBM PPC 405
2150 +
2151 +
2152 +   ---------------------------------------------------------------------------
2153 +   This file was highly leveraged from i2c-algo-pcf.c, which was created
2154 +   by Simon G. Vogl and Hans Berglund:
2155 +
2156 +
2157 +     Copyright (C) 1995-1997 Simon G. Vogl
2158 +                   1998-2000 Hans Berglund
2159 +
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>
2163 +
2164 +
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.
2169 +
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.
2174 +
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 +   ---------------------------------------------------------------------------
2179 +
2180 +   History: 01/20/12 - Armin
2181 +       akuster@mvista.com
2182 +       ported up to 2.4.16+    
2183 +
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 .
2189 +*/
2190 +
2191 +
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>
2202 +
2203 +
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
2211 +
2212 +
2213 +/* ----- global variables ---------------------------------------------        */
2214 +
2215 +
2216 +/* module parameters:
2217 + */
2218 +static int i2c_debug=0;
2219 +
2220 +/* --- setting states on the bus with the right timing: ---------------        */
2221 +
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))
2224 +
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
2230 +
2231 +#define IIC_SINGLE_XFER                0
2232 +#define IIC_COMBINED_XFER      1
2233 +
2234 +#define IIC_ERR_LOST_ARB        -2
2235 +#define IIC_ERR_INCOMPLETE_XFR  -3
2236 +#define IIC_ERR_NACK            -1
2237 +
2238 +/* --- other auxiliary functions --------------------------------------        */
2239 +
2240 +
2241 +//
2242 +// Description: Puts this process to sleep for a period equal to timeout 
2243 +//
2244 +static inline void iic_sleep(unsigned long timeout)
2245 +{
2246 +       schedule_timeout( timeout * HZ);
2247 +}
2248 +
2249 +
2250 +//
2251 +// Description: This performs the IBM PPC 405 IIC initialization sequence
2252 +// as described in the PPC405GP data book.
2253 +//
2254 +static int iic_init (struct i2c_algo_iic_data *adap)
2255 +{
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;
2260 +
2261 +        /* Clear master low master address */
2262 +        iic_outb(adap,iic->lmadr, 0);
2263 +
2264 +        /* Clear high master address */
2265 +        iic_outb(adap,iic->hmadr, 0);
2266 +
2267 +        /* Clear low slave address */
2268 +        iic_outb(adap,iic->lsadr, 0);
2269 +
2270 +        /* Clear high slave address */
2271 +        iic_outb(adap,iic->hsadr, 0);
2272 +
2273 +        /* Clear status */
2274 +        iic_outb(adap,iic->sts, 0x0a);
2275 +
2276 +        /* Clear extended status */
2277 +        iic_outb(adap,iic->extsts, 0x8f);
2278 +
2279 +        /* Set clock division */
2280 +        iic_outb(adap,iic->clkdiv, 0x04);
2281 +
2282 +       retval = iic_inb(adap, iic->clkdiv);
2283 +       DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2284 +
2285 +        /* Enable interrupts on Requested Master Transfer Complete */
2286 +        iic_outb(adap,iic->intmsk, 0x01);
2287 +
2288 +        /* Clear transfer count */
2289 +        iic_outb(adap,iic->xfrcnt, 0x0);
2290 +
2291 +        /* Clear extended control and status */
2292 +        iic_outb(adap,iic->xtcntlss, 0xf0);
2293 +
2294 +        /* Set mode control (flush master data buf, enable hold SCL, exit */
2295 +        /* unknown state.                                                 */
2296 +        iic_outb(adap,iic->mdcntl, 0x47);
2297 +
2298 +        /* Clear control register */
2299 +        iic_outb(adap,iic->cntl, 0x0);
2300 +
2301 +        DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2302 +        return 0;
2303 +}
2304 +
2305 +
2306 +//
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.
2310 +//
2311 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status) 
2312 +{
2313 +
2314 +       int timeout = DEF_TIMEOUT;
2315 +       int retval;
2316 +       struct iic_regs *iic;
2317 +       struct iic_ibm *adap_priv_data = adap->data;
2318 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2319 +
2320 +
2321 +       *status = iic_inb(adap, iic->sts);
2322 +#ifndef STUB_I2C
2323 +
2324 +       while (timeout-- && (*status & 0x01)) {
2325 +          adap->waitforpin(adap->data);
2326 +          *status = iic_inb(adap, iic->sts);
2327 +       }
2328 +#endif
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));
2338 +
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;
2344 +           if(retval) {
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.
2350 +             /* Soft reset */
2351 +              iic_outb(adap, iic->xtcntlss, 0x01);
2352 +              udelay(500);
2353 +              iic_init(adap);
2354 +             /* Is the pending transfer bit in the sts reg finally cleared? */
2355 +              retval = iic_inb(adap, iic->sts);
2356 +              retval = retval & 0x01;
2357 +              if(retval) {
2358 +                 printk(KERN_CRIT "The IIC Controller is hosed.  A processor reset is required\n");
2359 +              }
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);
2365 +           }
2366 +          return(-1);
2367 +       }
2368 +       else
2369 +          return(0);
2370 +}
2371 +
2372 +
2373 +//------------------------------------
2374 +// Utility functions
2375 +//
2376 +
2377 +
2378 +//
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.
2382 +//
2383 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2384 +{
2385 +   int ret;
2386 +   struct iic_regs *iic;
2387 +   struct iic_ibm *adap_priv_data = adap->data;
2388 +   iic = (struct iic_regs *) adap_priv_data->iic_base;
2389 +
2390 +       
2391 +   ret = iic_inb(adap, iic->sts);
2392 +   if(ret & 0x04) {
2393 +      // Error occurred
2394 +      ret = iic_inb(adap, iic->extsts);
2395 +      if(ret & 0x04) {
2396 +         // Lost arbitration
2397 +         *error_code =  IIC_ERR_LOST_ARB;
2398 +      }
2399 +      if(ret & 0x02) {
2400 +         // Incomplete transfer
2401 +         *error_code = IIC_ERR_INCOMPLETE_XFR;
2402 +      }
2403 +      if(ret & 0x01) {
2404 +         // Master transfer aborted by a NACK during the transfer of the 
2405 +        // address byte
2406 +         *error_code = IIC_ERR_NACK;
2407 +      }
2408 +      return -1;
2409 +   }
2410 +   return 0;
2411 +}
2412 +
2413 +
2414 +//
2415 +// Description: This function is called by the upper layers to do the
2416 +// grunt work for a master send transaction
2417 +//
2418 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2419 +                         int count, int xfer_flag)
2420 +{
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;
2428 +
2429
2430 +       if( count == 0 ) return 0;
2431 +       wrcount = 0;
2432 +       loops =  count / 4;
2433 +       remainder = count % 4;
2434 +
2435 +       if((loops > 1) && (remainder == 0)) {
2436 +          for(i=0; i<(loops-1); i++) {
2437 +                     //
2438 +             // Write four bytes to master data buffer
2439 +             //
2440 +             for(j=0; j<4; j++) {
2441 +                iic_outb(adap, iic->mdbuf, 
2442 +                buf[wrcount++]);
2443 +             }
2444 +             //
2445 +             // Issue command to IICO device to begin transmission
2446 +             //
2447 +             iic_outb(adap, iic->cntl, 0x35);
2448 +             //
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.
2452 +             //
2453 +             timeout = wait_for_pin(adap, &status);
2454 +             if(timeout < 0) {
2455 +                //
2456 +                // Error handling
2457 +                //
2458 +                 //printk(KERN_ERR "Error: write timeout\n");
2459 +                 return wrcount;
2460 +             }
2461 +             ret = analyze_status(adap, &error_code);
2462 +             if(ret < 0) {
2463 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2464 +                    // Return the number of bytes transferred
2465 +                    ret = iic_inb(adap, iic->xfrcnt);
2466 +                    ret = ret & 0x07;
2467 +                    return (wrcount-4+ret);
2468 +                 }
2469 +                 else return error_code;
2470 +              }
2471 +           }
2472 +       }
2473 +       else if((loops >= 1) && (remainder > 0)){
2474 +          //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2475 +          for(i=0; i<loops; i++) {
2476 +              //
2477 +              // Write four bytes to master data buffer
2478 +              //
2479 +              for(j=0; j<4; j++) {
2480 +                 iic_outb(adap, iic->mdbuf,
2481 +                 buf[wrcount++]);
2482 +              }
2483 +              //
2484 +              // Issue command to IICO device to begin transmission
2485 +              //
2486 +              iic_outb(adap, iic->cntl, 0x35);
2487 +              //
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.
2491 +              //
2492 +              timeout = wait_for_pin(adap, &status);
2493 +              if(timeout < 0) {
2494 +                 //
2495 +                 // Error handling
2496 +                 //
2497 +                 //printk(KERN_ERR "Error: write timeout\n");
2498 +                 return wrcount;
2499 +              }
2500 +              ret = analyze_status(adap, &error_code);
2501 +              if(ret < 0) {
2502 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2503 +                    // Return the number of bytes transferred
2504 +                    ret = iic_inb(adap, iic->xfrcnt);
2505 +                    ret = ret & 0x07;
2506 +                    return (wrcount-4+ret);
2507 +                 }
2508 +                 else return error_code;
2509 +              }
2510 +           }
2511 +        }
2512 +
2513 +       //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2514 +       if(remainder == 0) remainder = 4;
2515 +       // remainder = remainder - 1;
2516 +       //
2517 +       // Write the remaining bytes (less than or equal to 4)
2518 +       //
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));
2522 +       }
2523 +        //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2524 +
2525 +        if(xfer_flag == IIC_COMBINED_XFER) {
2526 +           iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2527 +        }
2528 +       else {
2529 +           iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2530 +        }
2531 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2532 +       timeout = wait_for_pin(adap, &status);
2533 +        if(timeout < 0) {
2534 +                  //
2535 +           // Error handling
2536 +           //
2537 +           //printk(KERN_ERR "Error: write timeout\n");
2538 +           return wrcount;
2539 +        }
2540 +        ret = analyze_status(adap, &error_code);
2541 +        if(ret < 0) {
2542 +           if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2543 +              // Return the number of bytes transferred
2544 +              ret = iic_inb(adap, iic->xfrcnt);
2545 +              ret = ret & 0x07;
2546 +              return (wrcount-4+ret);
2547 +           }
2548 +           else return error_code;
2549 +        }
2550 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2551 +       return wrcount;
2552 +}
2553 +
2554 +
2555 +//
2556 +// Description: Called by the upper layers to do the grunt work for
2557 +// a master read transaction.
2558 +//
2559 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2560 +{
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;
2568 +
2569 +       if(count == 0) return 0;
2570 +       loops = count / 4;
2571 +       remainder = count % 4;
2572 +
2573 +       //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2574 +
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++) {
2578 +             //
2579 +              // Issue command to begin master read (4 bytes maximum)
2580 +              //
2581 +             //printk(KERN_DEBUG "--->Issued read command\n");
2582 +             iic_outb(adap, iic->cntl, 0x37);
2583 +             //
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.
2587 +              //
2588 +             //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2589 +              timeout = wait_for_pin(adap, &status);
2590 +              if(timeout < 0) {
2591 +                // Error Handler
2592 +                //printk(KERN_ERR "Error: read timed out\n");
2593 +                 return rdcount;
2594 +             }
2595 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2596 +
2597 +              ret = analyze_status(adap, &error_code);
2598 +             if(ret < 0) {
2599 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2600 +                    return rdcount;
2601 +                 else
2602 +                    return error_code;
2603 +              }
2604 +
2605 +             for(j=0; j<4; j++) {
2606 +                 // Wait for data to shuffle to top of data buffer
2607 +                 // This value needs to optimized.
2608 +                udelay(1);
2609 +                buf[rdcount] = iic_inb(adap, iic->mdbuf);
2610 +                rdcount++;
2611 +                //printk(KERN_DEBUG "--->Read one byte\n");
2612 +              }
2613 +           }
2614 +       }
2615 +
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++) {
2619 +              //
2620 +              // Issue command to begin master read (4 bytes maximum)
2621 +              //
2622 +              //printk(KERN_DEBUG "--->Issued read command\n");
2623 +              iic_outb(adap, iic->cntl, 0x37);
2624 +              //
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.
2628 +              //
2629 +              //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2630 +              timeout = wait_for_pin(adap, &status);
2631 +              if(timeout < 0) {
2632 +                 // Error Handler
2633 +                 //printk(KERN_ERR "Error: read timed out\n");
2634 +                 return rdcount;
2635 +              }
2636 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2637 +
2638 +              ret = analyze_status(adap, &error_code);
2639 +              if(ret < 0) {
2640 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2641 +                    return rdcount;
2642 +                 else
2643 +                    return error_code;
2644 +              }
2645 +
2646 +              for(j=0; j<4; j++) {
2647 +                 // Wait for data to shuffle to top of data buffer
2648 +                 // This value needs to optimized.
2649 +                 udelay(1);
2650 +                 buf[rdcount] = iic_inb(adap, iic->mdbuf);
2651 +                 rdcount++;
2652 +                 //printk(KERN_DEBUG "--->Read one byte\n");
2653 +              }
2654 +           }
2655 +        }
2656 +
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))));
2660 +
2661 +       if(xfer_type == IIC_COMBINED_XFER) {
2662 +          iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2663 +        }
2664 +        else {
2665 +          iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2666 +        }
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"));
2670 +        if(timeout < 0) {
2671 +           // Error Handler
2672 +          //printk(KERN_ERR "Error: read timed out\n");
2673 +           return rdcount;
2674 +        }
2675 +
2676 +        ret = analyze_status(adap, &error_code);
2677 +        if(ret < 0) {
2678 +           if(error_code == IIC_ERR_INCOMPLETE_XFR)
2679 +              return rdcount;
2680 +           else
2681 +              return error_code;
2682 +        }
2683 +
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]);
2688 +           rdcount++;
2689 +       }
2690 +
2691 +       return rdcount;
2692 +}
2693 +
2694 +
2695 +//
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
2699 +// condition.
2700 +//
2701 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 
2702 +{
2703 +   int i;
2704 +   struct i2c_msg *pmsg;
2705 +   int ret;
2706 +
2707 +   DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2708 +       for(i=0; i < num; i++) {
2709 +               pmsg = &msgs[i];
2710 +               if(pmsg->flags & I2C_M_RD) {
2711 +
2712 +                       // Last read or write segment needs to be terminated with a stop
2713 +                       if(i < num-1) {
2714 +                               DEB2(printk(KERN_DEBUG "This one is a read\n"));
2715 +                       }
2716 +                       else {
2717 +                               DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2718 +                       }
2719 +                       ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2720 +
2721 +                       if (ret != pmsg->len) {
2722 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2723 +                                                       "only read %d bytes.\n",ret));
2724 +                               return i;
2725 +                       }
2726 +                       else {
2727 +                               DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2728 +                       }
2729 +               }
2730 +               else if(!(pmsg->flags & I2C_M_RD)) {
2731 +
2732 +                       // Last read or write segment needs to be terminated with a stop
2733 +                       if(i < num-1) {
2734 +                               DEB2(printk(KERN_DEBUG "This one is a write\n"));
2735 +                       }
2736 +                       else {
2737 +                               DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2738 +                       }
2739 +                       ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2740 +
2741 +                       if (ret != pmsg->len) {
2742 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2743 +                                                       "only wrote %d bytes.\n",ret));
2744 +                               return i;
2745 +                       }
2746 +                       else {
2747 +                               DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2748 +                       }
2749 +               }
2750 +       }
2751
2752 +       return num;
2753 +}
2754 +
2755 +
2756 +//
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.
2761 +//
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.
2764 +//
2765 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
2766 +                                struct i2c_msg *msg, int retries) 
2767 +{
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;
2773 +
2774 +//
2775 +// The following segment for 10 bit addresses needs to be ported
2776 +//
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);
2784 +               if (ret!=1) {
2785 +                       printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2786 +                       return -EREMOTEIO;
2787 +               }
2788 +               // the remaining 8 bit address
2789 +               iic_outb(adap,msg->addr & 0x7f);
2790 +               // Status check comes here
2791 +               if (ret != 1) {
2792 +                       printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
2793 +                       return -EREMOTEIO;
2794 +               }
2795 +               if ( flags & I2C_M_RD ) {
2796 +                       i2c_repstart(adap);
2797 +                       // okay, now switch into reading mode
2798 +                       addr |= 0x01;
2799 +                       ret = try_address(adap, addr, retries);
2800 +                       if (ret!=1) {
2801 +                               printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
2802 +                               return -EREMOTEIO;
2803 +                       }
2804 +               }
2805 +       } else ----------> // normal 7 bit address
2806 +
2807 +Ten bit addresses not supported yet */
2808 +
2809 +       addr = ( msg->addr << 1 );
2810 +       if (flags & I2C_M_RD )
2811 +               addr |= 1;
2812 +       if (flags & I2C_M_REV_DIR_ADDR )
2813 +               addr ^= 1;
2814 +       //
2815 +       // Write to the low slave address
2816 +       //
2817 +       iic_outb(adap, iic->lmadr, addr);
2818 +       //
2819 +       // Write zero to the high slave register since we are
2820 +       // only using 7 bit addresses
2821 +       //
2822 +       iic_outb(adap, iic->hmadr, 0);
2823 +
2824 +       return 0;
2825 +}
2826 +
2827 +
2828 +//
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.
2832 +//
2833 +static int iic_xfer(struct i2c_adapter *i2c_adap,
2834 +                   struct i2c_msg msgs[], 
2835 +                   int num)
2836 +{
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;
2841 +       int i = 0;
2842 +       int ret;
2843 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2844 +
2845 +       pmsg = &msgs[i];
2846 +
2847 +       //
2848 +       // Clear status register
2849 +       //
2850 +       DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
2851 +       iic_outb(adap, iic->sts, 0x0a);
2852 +
2853 +       //
2854 +       // Wait for any pending transfers to complete
2855 +       //
2856 +       DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
2857 +       while((ret = iic_inb(adap, iic->sts)) == 0x01) {
2858 +               ;
2859 +       }
2860 +
2861 +       //
2862 +       // Flush master data buf
2863 +       //
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);
2867 +
2868 +       //
2869 +       // Load slave address
2870 +       //
2871 +       DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
2872 +       ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
2873 +
2874 +        //
2875 +        // Check to see if the bus is busy
2876 +        //
2877 +        ret = iic_inb(adap, iic->extsts);
2878 +        // Mask off the irrelevent bits
2879 +        ret = ret & 0x70;
2880 +        // When the bus is free, the BCS bits in the EXTSTS register are 0b100
2881 +        if(ret != 0x40) return IIC_ERR_LOST_ARB;
2882 +
2883 +       //
2884 +       // Combined transaction (read and write)
2885 +       //
2886 +       if(num > 1) {
2887 +           DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
2888 +           ret = iic_combined_transaction(i2c_adap, msgs, num);
2889 +        }
2890 +       //
2891 +       // Read only
2892 +       //
2893 +       else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
2894 +          //
2895 +          // Tell device to begin reading data from the  master data 
2896 +          //
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);
2899 +       } 
2900 +        //
2901 +       // Write only
2902 +       //
2903 +       else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
2904 +          //
2905 +          // Write data to master data buffers and tell our device
2906 +          // to begin transmitting
2907 +          //
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);
2910 +       }       
2911 +
2912 +       return ret;   
2913 +}
2914 +
2915 +
2916 +//
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.
2924 +//
2925 +static int algo_control(struct i2c_adapter *adapter, 
2926 +       unsigned int cmd, unsigned long arg)
2927 +{
2928 +       struct iic_regs *iic;
2929 +       struct i2c_algo_iic_data *adap = adapter->algo_data;
2930 +       struct iic_ibm *adap_priv_data = adap->data;
2931 +       int ret=0;
2932 +       int lines;
2933 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2934 +
2935 +       lines = iic_inb(adap, iic->directcntl);
2936 +
2937 +       if (cmd == IICO_I2C_SDAHIGH) {
2938 +             lines = lines & 0x01;
2939 +             if( lines ) lines = 0x04;
2940 +             else lines = 0;
2941 +             iic_outb(adap, iic->directcntl,(0x08|lines));
2942 +       }
2943 +       else if (cmd == IICO_I2C_SDALOW) {
2944 +             lines = lines & 0x01;
2945 +             if( lines ) lines = 0x04;
2946 +              else lines = 0;
2947 +              iic_outb(adap, iic->directcntl,(0x00|lines));
2948 +       }
2949 +       else if (cmd == IICO_I2C_SCLHIGH) {
2950 +              lines = lines & 0x02;
2951 +              if( lines ) lines = 0x08;
2952 +              else lines = 0;
2953 +              iic_outb(adap, iic->directcntl,(0x04|lines));
2954 +       }
2955 +       else if (cmd == IICO_I2C_SCLLOW) {
2956 +              lines = lines & 0x02;
2957 +             if( lines ) lines = 0x08;
2958 +              else lines = 0;
2959 +              iic_outb(adap, iic->directcntl,(0x00|lines));
2960 +       }
2961 +       else if (cmd == IICO_I2C_LINEREAD) {
2962 +             ret = lines;
2963 +       }
2964 +       return ret;
2965 +}
2966 +
2967 +
2968 +static u32 iic_func(struct i2c_adapter *adap)
2969 +{
2970 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
2971 +              I2C_FUNC_PROTOCOL_MANGLING; 
2972 +}
2973 +
2974 +
2975 +/* -----exported algorithm data: ------------------------------------- */
2976 +
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,
2984 +};
2985 +
2986 +/* 
2987 + * registering functions to load algorithms at runtime 
2988 + */
2989 +
2990 +
2991 +//
2992 +// Description: Register bus structure
2993 +//
2994 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
2995 +{
2996 +       struct i2c_algo_iic_data *iic_adap = adap->algo_data;
2997 +
2998 +       DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
2999 +                   adap->name));
3000 +
3001 +       /* register new adapter to i2c module... */
3002 +
3003 +       adap->id |= iic_algo.id;
3004 +       adap->algo = &iic_algo;
3005 +
3006 +       adap->timeout = 100;    /* default values, should       */
3007 +       adap->retries = 3;              /* be replaced by defines       */
3008 +
3009 +       iic_init(iic_adap);
3010 +       i2c_add_adapter(adap);
3011 +       return 0;
3012 +}
3013 +
3014 +
3015 +//
3016 +// Done
3017 +//
3018 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
3019 +{
3020 +       return i2c_del_adapter(adap);
3021 +}
3022 +
3023 +
3024 +EXPORT_SYMBOL(i2c_ocp_add_bus);
3025 +EXPORT_SYMBOL(i2c_ocp_del_bus);
3026 +
3027 +//
3028 +// The MODULE_* macros resolve to nothing if MODULES is not defined
3029 +// when this file is compiled.
3030 +//
3031 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
3032 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
3033 +MODULE_LICENSE("GPL");
3034 +
3035 +MODULE_PARM(i2c_debug,"i");
3036 +
3037 +MODULE_PARM_DESC(i2c_debug,
3038 +        "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
3039 +
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
3042 @@ -0,0 +1,52 @@
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
3048 +
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.
3053 +
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.
3058 +
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 +/* ------------------------------------------------------------------------- */
3063 +
3064 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3065 +   Frodo Looijaard <frodol@dds.nl> */
3066 +
3067 +/* Modifications by MontaVista Software, August 2000
3068 +   Changes made to support the IIC peripheral on the IBM PPC 405 */
3069 +
3070 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
3071 +#define _LINUX_I2C_ALGO_IBM_OCP_H
3072 +
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);     
3080 +
3081 +       /* local settings */
3082 +       int udelay;
3083 +       int mdelay;
3084 +       int timeout;
3085 +};
3086 +
3087 +
3088 +#define I2C_IIC_ADAP_MAX       16
3089 +
3090 +
3091 +int i2c_ocp_add_bus(struct i2c_adapter *);
3092 +int i2c_ocp_del_bus(struct i2c_adapter *);
3093 +
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
3097 @@ -32,14 +32,9 @@
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>
3106 -
3107  #include <linux/i2c.h>
3108  #include <linux/i2c-algo-pcf.h>
3109 -#include "i2c-pcf8584.h"
3110 +
3111  
3112  /* ----- global defines ----------------------------------------------- */
3113 @@ -54,5 +49,4 @@
3114   */
3115  static int i2c_debug=0;
3116 -static int pcf_scan=0; /* have a look at what's hanging 'round         */
3117  
3118  /* --- setting states on the bus with the right timing: ---------------        */
3119 @@ -100,5 +94,5 @@
3120  #endif
3121         if (timeout <= 0) {
3122 -               printk("Timeout waiting for Bus Busy\n");
3123 +               printk(KERN_ERR "Timeout waiting for Bus Busy\n");
3124         }
3125         
3126 @@ -145,5 +139,5 @@
3127         unsigned char temp;
3128  
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)));
3131  
3132         /* S1=0x80: S0 selected, serial interface off */
3133 @@ -151,7 +145,6 @@
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 */
3142         }
3143 @@ -161,5 +154,5 @@
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));
3148                 return -ENXIO;
3149         }
3150 @@ -168,6 +161,6 @@
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));
3157                 return -ENXIO;
3158         }
3159 @@ -177,5 +170,5 @@
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));
3164                 return -ENXIO;
3165         }
3166 @@ -186,9 +179,9 @@
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));
3171                 return -ENXIO;
3172         }
3173         
3174 -       printk("i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3175 +       printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3176  
3177         return 0;
3178 @@ -216,5 +209,5 @@
3179                 udelay(adap->udelay);
3180         }
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,
3183                            addr));
3184         return ret;
3185 @@ -229,5 +222,5 @@
3186      
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]);
3192 @@ -235,5 +228,5 @@
3193                 if (timeout) {
3194                         i2c_stop(adap);
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 ?? */
3199 @@ -242,5 +235,5 @@
3200                 if (status & I2C_PCF_LRB) {
3201                         i2c_stop(adap);
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 ?? */
3206 @@ -270,5 +263,5 @@
3207                 if (wait_for_pin(adap, &status)) {
3208                         i2c_stop(adap);
3209 -                       printk("i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3210 +                       printk(KERN_ERR "i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3211                         return (-1);
3212                 }
3213 @@ -277,5 +270,5 @@
3214                 if ((status & I2C_PCF_LRB) && (i != count)) {
3215                         i2c_stop(adap);
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");
3218                         return (-1);
3219                 }
3220 @@ -313,9 +306,9 @@
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);
3227                 if (ret!=1) {
3228 -                       printk("died at extended address code.\n");
3229 +                       printk(KERN_ERR "died at extended address code.\n");
3230                         return -EREMOTEIO;
3231                 }
3232 @@ -324,5 +317,5 @@
3233  /* Status check comes here */
3234                 if (ret != 1) {
3235 -                       printk("died at 2nd address code.\n");
3236 +                       printk(KERN_ERR "died at 2nd address code.\n");
3237                         return -EREMOTEIO;
3238                 }
3239 @@ -333,5 +326,5 @@
3240                         ret = try_address(adap, addr, retries);
3241                         if (ret!=1) {
3242 -                               printk("died at extended address code.\n");
3243 +                               printk(KERN_ERR "died at extended address code.\n");
3244                                 return -EREMOTEIO;
3245                         }
3246 @@ -361,5 +354,5 @@
3247         timeout = wait_for_bb(adap);
3248         if (timeout) {
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");)
3252                 return -EIO;
3253 @@ -369,5 +362,5 @@
3254                 pmsg = &msgs[i];
3255  
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);)
3260 @@ -384,5 +377,5 @@
3261                 if (timeout) {
3262                         i2c_stop(adap);
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) {
3269                         i2c_stop(adap);
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);
3273                 }
3274  #endif
3275      
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);)
3279      
3280 @@ -408,8 +401,8 @@
3281          
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));
3286                         } else {
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));
3289                         }
3290                 } else { /* Write */
3291 @@ -418,8 +411,8 @@
3292          
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));
3297                         } else {
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));
3300                         }
3301                 }
3302 @@ -429,10 +422,4 @@
3303  }
3304  
3305 -static int algo_control(struct i2c_adapter *adapter, 
3306 -       unsigned int cmd, unsigned long arg)
3307 -{
3308 -       return 0;
3309 -}
3310 -
3311  static u32 pcf_func(struct i2c_adapter *adap)
3312  {
3313 @@ -444,12 +431,9 @@
3314  
3315  static struct i2c_algorithm pcf_algo = {
3316 -       "PCF8584 algorithm",
3317 -       I2C_ALGO_PCF,
3318 -       pcf_xfer,
3319 -       NULL,
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,
3329  };
3330  
3331 @@ -459,8 +443,8 @@
3332  int i2c_pcf_add_bus(struct i2c_adapter *adap)
3333  {
3334 -       int i, status;
3335 +       int i;
3336         struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
3337  
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",
3340                     adap->name));
3341  
3342 @@ -477,33 +461,5 @@
3343         }
3344  
3345 -#ifdef MODULE
3346 -       MOD_INC_USE_COUNT;
3347 -#endif
3348 -
3349         i2c_add_adapter(adap);
3350 -
3351 -       /* scan bus */
3352 -       if (pcf_scan) {
3353 -               printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
3354 -                      adap->name);
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",
3358 -                          adap->name);
3359 -                           break;
3360 -                       }
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); 
3366 -                       } else {
3367 -                               printk("."); 
3368 -                       }
3369 -                       i2c_stop(pcf_adap);
3370 -                       udelay(pcf_adap->udelay);
3371 -               }
3372 -               printk("\n");
3373 -       }
3374         return 0;
3375  }
3376 @@ -512,45 +468,15 @@
3377  int i2c_pcf_del_bus(struct i2c_adapter *adap)
3378  {
3379 -       int res;
3380 -       if ((res = i2c_del_adapter(adap)) < 0)
3381 -               return res;
3382 -       DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
3383 -
3384 -#ifdef MODULE
3385 -       MOD_DEC_USE_COUNT;
3386 -#endif
3387 -       return 0;
3388 -}
3389 -
3390 -int __init i2c_algo_pcf_init (void)
3391 -{
3392 -       printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
3393 -       return 0;
3394 +       return i2c_del_adapter(adap);
3395  }
3396  
3397 -
3398  EXPORT_SYMBOL(i2c_pcf_add_bus);
3399  EXPORT_SYMBOL(i2c_pcf_del_bus);
3400  
3401 -#ifdef MODULE
3402  MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
3403  MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
3404  MODULE_LICENSE("GPL");
3405  
3406 -MODULE_PARM(pcf_scan, "i");
3407  MODULE_PARM(i2c_debug,"i");
3408 -
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");
3412 -
3413 -
3414 -int init_module(void) 
3415 -{
3416 -       return i2c_algo_pcf_init();
3417 -}
3418 -
3419 -void cleanup_module(void) 
3420 -{
3421 -}
3422 -#endif
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
3425 @@ -23,11 +23,10 @@
3426     Frodo Looijaard <frodol@dds.nl> */
3427  
3428 -/* $Id$ */
3429 +/* $Id$ */
3430  
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
3435  
3436 -/* --- Defines for pcf-adapters ---------------------------------------        */
3437 -#include <linux/i2c.h>
3438 +#include <linux/i2c-pcf8584.h>
3439  
3440  struct i2c_algo_pcf_data {
3441 @@ -50,3 +49,3 @@
3442  int i2c_pcf_del_bus(struct i2c_adapter *);
3443  
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
3448 @@ -1,231 +0,0 @@
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
3454 -
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.
3459 -
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.
3464 -
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 -/* ------------------------------------------------------------------------- */
3469 -
3470 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3471 -   Frodo Looijaard <frodol@dds.nl>.  */
3472 -
3473 -/* Ported for SiByte SOCs by Broadcom Corporation.  */
3474 -
3475 -#include <linux/config.h>
3476 -#include <linux/kernel.h>
3477 -#include <linux/module.h>
3478 -#include <linux/init.h>
3479 -
3480 -#include <asm/sibyte/64bit.h>
3481 -#include <asm/sibyte/sb1250_regs.h>
3482 -#include <asm/sibyte/sb1250_smbus.h>
3483 -
3484 -#include <linux/i2c.h>
3485 -#include <linux/i2c-algo-sibyte.h>
3486 -
3487 -/* ----- global defines ----------------------------------------------- */
3488 -#define SMB_CSR(a,r) ((long)(a->reg_base + r))
3489 -
3490 -/* ----- global variables ---------------------------------------------        */
3491 -
3492 -/* module parameters:
3493 - */
3494 -static int bit_scan=0; /* have a look at what's hanging 'round         */
3495 -
3496 -
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)
3500 -{
3501 -       struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
3502 -        int data_bytes = 0;
3503 -        int error;
3504 -
3505 -        while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
3506 -                ;
3507 -
3508 -        switch (size) {
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));
3512 -                break;
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));
3517 -                        data_bytes = 1;
3518 -                } else {
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));
3522 -                }
3523 -                break;
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));
3529 -                        data_bytes = 1;
3530 -                } else {
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));
3534 -                }
3535 -                break;
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));
3541 -                        data_bytes = 2;
3542 -                } else {
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));
3547 -                }
3548 -                break;
3549 -        default:
3550 -                return -1;      /* XXXKW better error code? */
3551 -        }
3552 -
3553 -        while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
3554 -                ;
3555 -
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? */
3561 -        }
3562 -
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;
3567 -
3568 -        return 0;
3569 -}
3570 -
3571 -static int algo_control(struct i2c_adapter *adapter, 
3572 -       unsigned int cmd, unsigned long arg)
3573 -{
3574 -       return 0;
3575 -}
3576 -
3577 -static u32 bit_func(struct i2c_adapter *adap)
3578 -{
3579 -       return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
3580 -                I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
3581 -}
3582 -
3583 -
3584 -/* -----exported algorithm data: ------------------------------------- */
3585 -
3586 -static struct i2c_algorithm i2c_sibyte_algo = {
3587 -       "SiByte algorithm",
3588 -       I2C_ALGO_SIBYTE,
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        */
3595 -};
3596 -
3597 -/* 
3598 - * registering functions to load algorithms at runtime 
3599 - */
3600 -int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
3601 -{
3602 -       int i;
3603 -       struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
3604 -
3605 -       /* register new adapter to i2c module... */
3606 -
3607 -       i2c_adap->id |= i2c_sibyte_algo.id;
3608 -       i2c_adap->algo = &i2c_sibyte_algo;
3609 -        
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));
3613 -
3614 -       /* scan bus */
3615 -       if (bit_scan) {
3616 -                union i2c_smbus_data data;
3617 -                int rc;
3618 -               printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
3619 -                      i2c_adap->name);
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);
3624 -                       if (!rc) {
3625 -                               printk("(%02x)",i); 
3626 -                       } else 
3627 -                               printk("."); 
3628 -               }
3629 -               printk("\n");
3630 -       }
3631 -
3632 -#ifdef MODULE
3633 -       MOD_INC_USE_COUNT;
3634 -#endif
3635 -       i2c_add_adapter(i2c_adap);
3636 -
3637 -       return 0;
3638 -}
3639 -
3640 -
3641 -int i2c_sibyte_del_bus(struct i2c_adapter *adap)
3642 -{
3643 -       int res;
3644 -
3645 -       if ((res = i2c_del_adapter(adap)) < 0)
3646 -               return res;
3647 -
3648 -#ifdef MODULE
3649 -       MOD_DEC_USE_COUNT;
3650 -#endif
3651 -       return 0;
3652 -}
3653 -
3654 -int __init i2c_algo_sibyte_init (void)
3655 -{
3656 -       printk("i2c-algo-sibyte.o: i2c SiByte algorithm module\n");
3657 -       return 0;
3658 -}
3659 -
3660 -
3661 -EXPORT_SYMBOL(i2c_sibyte_add_bus);
3662 -EXPORT_SYMBOL(i2c_sibyte_del_bus);
3663 -
3664 -#ifdef MODULE
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");
3670 -
3671 -int init_module(void) 
3672 -{
3673 -       return i2c_algo_sibyte_init();
3674 -}
3675 -
3676 -void cleanup_module(void) 
3677 -{
3678 -}
3679 -#endif
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
3682 @@ -1,33 +0,0 @@
3683 -/*
3684 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
3685 - *
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.
3690 - *
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.
3695 - *
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.
3699 - */
3700 -
3701 -#ifndef I2C_ALGO_SIBYTE_H
3702 -#define I2C_ALGO_SIBYTE_H 1
3703 -
3704 -#include <linux/i2c.h>
3705 -
3706 -struct i2c_algo_sibyte_data {
3707 -       void *data;             /* private data */
3708 -        int   bus;             /* which bus */
3709 -        void *reg_base;                /* CSR base */
3710 -};
3711 -
3712 -int i2c_sibyte_add_bus(struct i2c_adapter *, int speed);
3713 -int i2c_sibyte_del_bus(struct i2c_adapter *);
3714 -
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
3718 @@ -19,7 +19,8 @@
3719  
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>                */
3724  
3725 -/* $Id$ */
3726 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
3727  
3728  #include <linux/module.h>
3729 @@ -28,31 +29,10 @@
3730  #include <linux/slab.h>
3731  #include <linux/proc_fs.h>
3732 -#include <linux/config.h>
3733 -
3734 -#include <linux/i2c.h>
3735 -
3736 -/* ----- compatibility stuff ----------------------------------------------- */
3737 -
3738 -#include <linux/version.h>
3739  #include <linux/init.h>
3740 -
3741 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
3742 -#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
3743 -#endif
3744 -
3745 +#include <linux/i2c.h>
3746  #include <asm/uaccess.h>
3747  
3748  /* ----- global defines ---------------------------------------------------- */
3749  
3750 -/* exclusive access to the bus */
3751 -#define I2C_LOCK(adap) down(&adap->lock)
3752 -#define I2C_UNLOCK(adap) up(&adap->lock) 
3753 -
3754 -#define ADAP_LOCK()    down(&adap_lock)
3755 -#define ADAP_UNLOCK()  up(&adap_lock)
3756 -
3757 -#define DRV_LOCK()     down(&driver_lock)
3758 -#define DRV_UNLOCK()   up(&driver_lock)
3759 -
3760  #define DEB(x) if (i2c_debug>=1) x;
3761  #define DEB2(x) if (i2c_debug>=2) x;
3762 @@ -60,18 +40,10 @@
3763  /* ----- global variables -------------------------------------------------- */
3764  
3765 -/**** lock for writing to global variables: the adapter & driver list */
3766 -struct semaphore adap_lock;
3767 -struct semaphore driver_lock;
3768 -
3769 -/**** adapter list */
3770 +DECLARE_MUTEX(core_lists);
3771  static struct i2c_adapter *adapters[I2C_ADAP_MAX];
3772 -static int adap_count;
3773 -
3774 -/**** drivers list */
3775  static struct i2c_driver *drivers[I2C_DRIVER_MAX];
3776 -static int driver_count;
3777  
3778  /**** debug level */
3779 -static int i2c_debug=1;
3780 +static int i2c_debug;
3781  
3782  /* ---------------------------------------------------
3783 @@ -81,12 +53,4 @@
3784  
3785  #ifdef CONFIG_PROC_FS
3786 -
3787 -static int i2cproc_init(void);
3788 -static int i2cproc_cleanup(void);
3789 -
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)) */
3793 -
3794  static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, 
3795                                  loff_t *ppos);
3796 @@ -97,19 +61,9 @@
3797     implementation of the read hook */
3798  static struct file_operations i2cproc_operations = {
3799 -       read:           i2cproc_bus_read,
3800 +       .read           = i2cproc_bus_read,
3801  };
3802  
3803 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
3804 -static struct inode_operations i2cproc_inode_operations = {
3805 -       &i2cproc_operations
3806 -};
3807 -#endif
3808 -
3809 -static int i2cproc_initialized = 0;
3810 -
3811 -#else /* undef CONFIG_PROC_FS */
3812 -
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);
3817  
3818  #endif /* CONFIG_PROC_FS */
3819 @@ -128,7 +82,7 @@
3820  int i2c_add_adapter(struct i2c_adapter *adap)
3821  {
3822 -       int i,j,res;
3823 +       int i,j,res = 0;
3824  
3825 -       ADAP_LOCK();
3826 +       down(&core_lists);
3827         for (i = 0; i < I2C_ADAP_MAX; i++)
3828                 if (NULL == adapters[i])
3829 @@ -141,45 +95,18 @@
3830                 goto ERROR0;
3831         }
3832 +       
3833 +#ifdef CONFIG_PROC_FS
3834 +       res = i2cproc_register(adap, i);
3835 +       if (res<0)
3836 +           goto ERROR0;
3837 +#endif /* def CONFIG_PROC_FS */
3838  
3839         adapters[i] = adap;
3840 -       adap_count++;
3841 -       ADAP_UNLOCK();
3842         
3843         /* init data types */
3844 -       init_MUTEX(&adap->lock);
3845 -
3846 -#ifdef CONFIG_PROC_FS
3847 -
3848 -       if (i2cproc_initialized) {
3849 -               char name[8];
3850 -               struct proc_dir_entry *proc_entry;
3851 -
3852 -               sprintf(name,"i2c-%d", i);
3853 -
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",
3857 -                              name);
3858 -                       res = -ENOENT;
3859 -                       goto ERROR1;
3860 -               }
3861 -
3862 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,48))
3863 -               proc_entry->proc_fops = &i2cproc_operations;
3864 -#else
3865 -               proc_entry->ops = &i2cproc_inode_operations;
3866 -#endif
3867 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
3868 -               proc_entry->owner = THIS_MODULE;
3869 -#else
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;
3873 -       }
3874 -
3875 -#endif /* def CONFIG_PROC_FS */
3876 +       init_MUTEX(&adap->bus);
3877 +       init_MUTEX(&adap->list);
3878  
3879         /* inform drivers of new adapters */
3880 -       DRV_LOCK();     
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);
3886 -       DRV_UNLOCK();
3887         
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",
3890                    adap->name,i));
3891 -
3892 -       return 0;       
3893 -
3894 -
3895 -ERROR1:
3896 -       ADAP_LOCK();
3897 -       adapters[i] = NULL;
3898 -       adap_count--;
3899 -ERROR0:
3900 -       ADAP_UNLOCK();
3901 + ERROR0:
3902 +       up(&core_lists);
3903         return res;
3904  }
3905 @@ -207,13 +125,12 @@
3906  int i2c_del_adapter(struct i2c_adapter *adap)
3907  {
3908 -       int i,j,res;
3909 -
3910 -       ADAP_LOCK();
3911 +       int i,j, res=0;
3912  
3913 +       down(&core_lists);
3914         for (i = 0; i < I2C_ADAP_MAX; i++)
3915                 if (adap == adapters[i])
3916                         break;
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",
3920                         adap->name);
3921                 res = -ENODEV;
3922 @@ -226,15 +143,12 @@
3923          * this or hell will break loose...
3924          */
3925 -       DRV_LOCK();
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);
3933 -                               goto ERROR1;    
3934 +                               goto ERROR0;
3935                         }
3936 -       DRV_UNLOCK();
3937 -
3938  
3939         /* detach any active clients. This must be done first, because
3940 @@ -248,5 +162,5 @@
3941                      */
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 @@
3948                         }
3949         }
3950 +
3951  #ifdef CONFIG_PROC_FS
3952 -       if (i2cproc_initialized) {
3953 -               char name[8];
3954 -               sprintf(name,"i2c-%d", i);
3955 -               remove_proc_entry(name,proc_bus);
3956 -       }
3957 +       i2cproc_remove(i);
3958  #endif /* def CONFIG_PROC_FS */
3959  
3960         adapters[i] = NULL;
3961 -       adap_count--;
3962 -       
3963 -       ADAP_UNLOCK();  
3964 -       DEB(printk("i2c-core.o: adapter unregistered: %s\n",adap->name));
3965 -       return 0;
3966 -
3967 -ERROR0:
3968 -       ADAP_UNLOCK();
3969 -       return res;
3970 -ERROR1:
3971 -       DRV_UNLOCK();
3972 +               DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
3973 + ERROR0:
3974 +       up(&core_lists);
3975         return res;
3976  }
3977 @@ -288,5 +191,6 @@
3978  {
3979         int i;
3980 -       DRV_LOCK();
3981 +
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",
3987                         driver->name);
3988 -               DRV_UNLOCK();
3989 +               up(&core_lists);
3990                 return -ENOMEM;
3991         }
3992 -
3993 -       drivers[i] = driver;
3994 -       driver_count++;
3995 -       
3996 -       DRV_UNLOCK();   /* driver was successfully added */
3997 -       
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));
4001         
4002 -       ADAP_LOCK();
4003 -
4004         /* now look for instances of driver on our adapters
4005          */
4006 @@ -318,5 +215,5 @@
4007                                 driver->attach_adapter(adapters[i]);
4008         }
4009 -       ADAP_UNLOCK();
4010 +       up(&core_lists);
4011         return 0;
4012  }
4013 @@ -324,7 +221,7 @@
4014  int i2c_del_driver(struct i2c_driver *driver)
4015  {
4016 -       int i,j,k,res;
4017 +       int i,j,k,res = 0;
4018  
4019 -       DRV_LOCK();
4020 +       down(&core_lists);
4021         for (i = 0; i < I2C_DRIVER_MAX; i++)
4022                 if (driver == drivers[i])
4023 @@ -334,5 +231,5 @@
4024                                     "[%s] not found\n",
4025                         driver->name);
4026 -               DRV_UNLOCK();
4027 +               up(&core_lists);
4028                 return -ENODEV;
4029         }
4030 @@ -341,15 +238,14 @@
4031          * afterwards.
4032          */
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
4037          * pointers.
4038          */
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. */
4043                         continue;
4044 -               DEB2(printk("i2c-core.o: examining adapter %s:\n",
4045 +               DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
4046                             adap->name));
4047                 if (driver->flags & I2C_DF_DUMMY) {
4048 @@ -360,11 +256,10 @@
4049                  */
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,
4056                                        adap->name);
4057 -                               ADAP_UNLOCK();
4058 -                               return res;
4059 +                               goto ERROR0;
4060                         }
4061                 } else {
4062 @@ -373,5 +268,5 @@
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",
4068                                                     client->name));
4069 @@ -379,16 +274,15 @@
4070                                                         detach_client(client)))
4071                                         {
4072 -                                               printk("i2c-core.o: while "
4073 +                                               printk(KERN_ERR "i2c-core.o: while "
4074                                                        "unregistering driver "
4075                                                        "`%s', the client at "
4076                                                        "address %02x of "
4077 -                                                      "adapter `%s' could not"
4078 -                                                      "be detached; driver"
4079 +                                                      "adapter `%s' could not "
4080 +                                                      "be detached; driver "
4081                                                        "not unloaded!",
4082                                                        driver->name,
4083                                                        client->addr,
4084                                                        adap->name);
4085 -                                               ADAP_UNLOCK();
4086 -                                               return res;
4087 +                                               goto ERROR0;
4088                                         }
4089                                 }
4090 @@ -396,14 +290,13 @@
4091                 }
4092         }
4093 -       ADAP_UNLOCK();
4094         drivers[i] = NULL;
4095 -       driver_count--;
4096 -       DRV_UNLOCK();
4097 -       
4098 -       DEB(printk("i2c-core.o: driver unregistered: %s\n",driver->name));
4099 -       return 0;
4100 +       DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
4101 +
4102 + ERROR0:
4103 +       up(&core_lists);
4104 +       return res;
4105  }
4106  
4107 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4108 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
4109  {
4110         int i;
4111 @@ -411,7 +304,19 @@
4112                 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
4113                         return -EBUSY;
4114 +
4115         return 0;
4116  }
4117  
4118 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4119 +{
4120 +       int rval;
4121 +
4122 +       down(&adapter->list);
4123 +       rval = __i2c_check_addr(adapter, addr);
4124 +       up(&adapter->list);
4125 +
4126 +       return rval;
4127 +}
4128 +
4129  int i2c_attach_client(struct i2c_client *client)
4130  {
4131 @@ -422,4 +327,5 @@
4132                 return -EBUSY;
4133  
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",
4139                         client->name);
4140 +               up(&adapter->list);
4141                 return -ENOMEM;
4142         }
4143 -
4144         adapter->clients[i] = client;
4145 -       adapter->client_count++;
4146 +       up(&adapter->list);
4147         
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));
4157  
4158 @@ -455,14 +361,4 @@
4159         int i,res;
4160  
4161 -       for (i = 0; i < I2C_CLIENT_MAX; i++)
4162 -               if (client == adapter->clients[i])
4163 -                       break;
4164 -       if (I2C_CLIENT_MAX == i) {
4165 -               printk(KERN_WARNING " i2c-core.o: unregister_client "
4166 -                                   "[%s] not found\n",
4167 -                       client->name);
4168 -               return -ENODEV;
4169 -       }
4170 -       
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);
4179                         return res;
4180                 }
4181  
4182 +       down(&adapter->list);
4183 +       for (i = 0; i < I2C_CLIENT_MAX; i++)
4184 +               if (client == adapter->clients[i])
4185 +                       break;
4186 +       if (I2C_CLIENT_MAX == i) {
4187 +               printk(KERN_WARNING " i2c-core.o: unregister_client "
4188 +                                   "[%s] not found\n",
4189 +                       client->name);
4190 +               up(&adapter->list);
4191 +               return -ENODEV;
4192 +       }
4193         adapter->clients[i] = NULL;
4194 -       adapter->client_count--;
4195 +       up(&adapter->list);
4196  
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));
4199         return 0;
4200  }
4201  
4202 -void i2c_inc_use_client(struct i2c_client *client)
4203 +static void i2c_inc_use_client(struct i2c_client *client)
4204  {
4205 -
4206 -       if (client->driver->inc_use != NULL)
4207 -               client->driver->inc_use(client);
4208 -
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);
4215  }
4216  
4217 -void i2c_dec_use_client(struct i2c_client *client)
4218 +static void i2c_dec_use_client(struct i2c_client *client)
4219  {
4220 -       
4221 -       if (client->driver->dec_use != NULL)
4222 -               client->driver->dec_use(client);
4223 -
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);
4230  }
4231  
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 @@
4236         return 0;
4237  }
4238 +#endif
4239  
4240  int i2c_use_client(struct i2c_client *client)
4241  {
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) 
4248 +                       return -EBUSY;
4249 +               else 
4250                         client->usage_count++;
4251 -               else {
4252 -                       if(client->usage_count > 0) 
4253 -                               return -EBUSY;
4254 -                        else 
4255 -                               client->usage_count++;
4256 -               }
4257         }
4258  
4259 @@ -612,18 +515,6 @@
4260  #ifdef CONFIG_PROC_FS
4261  
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)
4266 -{
4267 -       if (fill)
4268 -               MOD_INC_USE_COUNT;
4269 -       else
4270 -               MOD_DEC_USE_COUNT;
4271 -}
4272 -#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */
4273 -
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, 
4277                   void *private)
4278  {
4279 @@ -631,4 +522,5 @@
4280         int nr = 0;
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++)
4284                 if (adapters[i]) {
4285 @@ -647,4 +539,5 @@
4286                                       adapters[i]->algo->name);
4287                 }
4288 +       up(&core_lists);
4289         return nr;
4290  }
4291 @@ -657,100 +550,123 @@
4292         char *kbuf;
4293         struct i2c_client *client;
4294 +       struct i2c_adapter *adap;
4295         int i,j,k,order_nr,len=0;
4296         size_t len_total;
4297         int order[I2C_CLIENT_MAX];
4298 +#define OUTPUT_LENGTH_PER_LINE 70
4299  
4300 -       if (count > 4000)
4301 -               return -EINVAL; 
4302         len_total = file->f_pos + count;
4303 -       /* Too bad if this gets longer (unlikely) */
4304 -       if (len_total > 4000)
4305 -               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
4309 -                  sprintf safe. */
4310 -                       if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
4311 -                               return -ENOMEM;
4312 -                       /* Order will hold the indexes of the clients
4313 -                          sorted by address */
4314 -                       order_nr=0;
4315 -                       for (j = 0; j < I2C_CLIENT_MAX; j++) {
4316 -                               if ((client = adapters[i]->clients[j]) && 
4317 -                                   (client->driver->id != I2C_DRIVERID_I2CDEV))  {
4318 -                                       for(k = order_nr; 
4319 -                                           (k > 0) && 
4320 -                                           adapters[i]->clients[order[k-1]]->
4321 -                                                    addr > client->addr; 
4322 -                                           k--)
4323 -                                               order[k] = order[k-1];
4324 -                                       order[k] = j;
4325 -                                       order_nr++;
4326 -                               }
4327 -                       }
4328 -
4329 -
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",
4333 -                                             client->addr,
4334 -                                             client->name,
4335 -                                             client->driver->name);
4336 -                       }
4337 -                       len = len - file->f_pos;
4338 -                       if (len > count)
4339 -                               len = count;
4340 -                       if (len < 0) 
4341 -                               len = 0;
4342 -                       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4343 -                               kfree(kbuf);
4344 -                               return -EFAULT;
4345 -                       }
4346 -                       file->f_pos += len;
4347 -                       kfree(kbuf);
4348 -                       return len;
4349 -               }
4350 -       return -ENOENT;
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);
4354 +
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))
4360 +               break;
4361 +       }
4362 +       if ( I2C_ADAP_MAX == i ) {
4363 +           up(&core_lists);
4364 +           return -ENOENT;
4365 +       }
4366 +
4367 +       /* We need a bit of slack in the kernel buffer; this makes the
4368 +          sprintf safe. */
4369 +       if (! (kbuf = kmalloc(len_total +
4370 +                             OUTPUT_LENGTH_PER_LINE,
4371 +                             GFP_KERNEL)))
4372 +           return -ENOMEM;
4373 +
4374 +       /* Order will hold the indexes of the clients
4375 +          sorted by address */
4376 +       order_nr=0;
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))  {
4381 +               for(k = order_nr; 
4382 +                   (k > 0) && 
4383 +                       adap->clients[order[k-1]]->
4384 +                       addr > client->addr; 
4385 +                   k--)
4386 +                   order[k] = order[k-1];
4387 +               order[k] = j;
4388 +               order_nr++;
4389 +           }
4390 +       }
4391 +
4392 +
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",
4396 +                          client->addr,
4397 +                          client->name,
4398 +                          client->driver->name);
4399 +       }
4400 +       up(&adap->list);
4401 +       up(&core_lists);
4402 +       
4403 +       len = len - file->f_pos;
4404 +       if (len > count)
4405 +           len = count;
4406 +       if (len < 0) 
4407 +           len = 0;
4408 +       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4409 +           kfree(kbuf);
4410 +           return -EFAULT;
4411 +       }
4412 +       file->f_pos += len;
4413 +       kfree(kbuf);
4414 +       return len;
4415 +}
4416 +
4417 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
4418 +{
4419 +       char name[8];
4420 +       struct proc_dir_entry *proc_entry;
4421 +
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",
4426 +                      name);
4427 +               return -ENOENT;
4428 +       }
4429 +           
4430 +       proc_entry->proc_fops = &i2cproc_operations;
4431 +       proc_entry->owner = adap->owner;
4432 +       adap->inode = proc_entry->low_ino;
4433 +       return 0;
4434  }
4435  
4436 -int i2cproc_init(void)
4437 +static void i2cproc_remove(int bus)
4438  {
4439 +       char name[8];
4440 +       sprintf(name,"i2c-%d", bus);
4441 +       remove_proc_entry(name, proc_bus);
4442 +}
4443  
4444 +static int __init i2cproc_init(void)
4445 +{
4446         struct proc_dir_entry *proc_bus_i2c;
4447  
4448 -       i2cproc_initialized = 0;
4449 -
4450 -       if (! proc_bus) {
4451 -               printk("i2c-core.o: /proc/bus/ does not exist");
4452 -               i2cproc_cleanup();
4453 -               return -ENOENT;
4454 -       } 
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");
4460                 return -ENOENT;
4461         }
4462 +
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;
4466 -#else
4467 -       proc_bus_i2c->fill_inode = &monitor_bus_i2c;
4468 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
4469 -       i2cproc_initialized += 2;
4470         return 0;
4471  }
4472  
4473 -int i2cproc_cleanup(void)
4474 +static void __exit i2cproc_cleanup(void)
4475  {
4476 -
4477 -       if (i2cproc_initialized >= 1) {
4478 -               remove_proc_entry("i2c",proc_bus);
4479 -               i2cproc_initialized -= 2;
4480 -       }
4481 -       return 0;
4482 +       remove_proc_entry("i2c",proc_bus);
4483  }
4484  
4485 -
4486  #endif /* def CONFIG_PROC_FS */
4487  
4488 @@ -765,14 +681,14 @@
4489  
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",
4493                             adap->name,num));
4494  
4495 -               I2C_LOCK(adap);
4496 +               down(&adap->bus);
4497                 ret = adap->algo->master_xfer(adap,msgs,num);
4498 -               I2C_UNLOCK(adap);
4499 +               up(&adap->bus);
4500  
4501                 return ret;
4502         } else {
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",
4505                        adap->id);
4506                 return -ENOSYS;
4507 @@ -792,10 +708,10 @@
4508                 (const char *)msg.buf = buf;
4509         
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));
4513         
4514 -               I2C_LOCK(adap);
4515 +               down(&adap->bus);
4516                 ret = adap->algo->master_xfer(adap,&msg,1);
4517 -               I2C_UNLOCK(adap);
4518 +               up(&adap->bus);
4519  
4520                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4521 @@ -804,5 +720,5 @@
4522                 return (ret == 1 )? count : ret;
4523         } else {
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);
4527                 return -ENOSYS;
4528 @@ -822,12 +738,12 @@
4529                 msg.buf = buf;
4530  
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));
4534         
4535 -               I2C_LOCK(adap);
4536 +               down(&adap->bus);
4537                 ret = adap->algo->master_xfer(adap,&msg,1);
4538 -               I2C_UNLOCK(adap);
4539 +               up(&adap->bus);
4540         
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));
4544         
4545 @@ -837,5 +753,5 @@
4546                 return (ret == 1 )? count : ret;
4547         } else {
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);
4551                 return -ENOSYS;
4552 @@ -850,5 +766,5 @@
4553         struct i2c_adapter *adap = client->adapter;
4554  
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));
4557         switch ( cmd ) {
4558                 case I2C_RETRIES:
4559 @@ -895,5 +811,5 @@
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",
4564                                             adap_id,addr));
4565                                 if ((err = found_proc(adapter,addr,0,0)))
4566 @@ -913,5 +829,5 @@
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));
4572                                 found = 1;
4573 @@ -925,5 +841,5 @@
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));
4579                                 found = 1;
4580 @@ -940,5 +856,5 @@
4581                         if (addr == address_data->normal_i2c[i]) {
4582                                 found = 1;
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));
4586                         }
4587 @@ -951,5 +867,5 @@
4588                             (addr <= address_data->normal_i2c_range[i+1])) {
4589                                 found = 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));
4593                         }
4594 @@ -963,5 +879,5 @@
4595                             (addr == address_data->probe[i+1])) {
4596                                 found = 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));
4600                         }
4601 @@ -975,5 +891,5 @@
4602                            (addr <= address_data->probe_range[i+2])) {
4603                                 found = 1;
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));
4607                         }
4608 @@ -1005,4 +921,121 @@
4609  /* The SMBus parts */
4610  
4611 +#define POLY    (0x1070U << 3) 
4612 +static u8
4613 +crc8(u16 data)
4614 +{
4615 +       int i;
4616 +  
4617 +       for(i = 0; i < 8; i++) {
4618 +               if (data & 0x8000) 
4619 +                       data = data ^ POLY;
4620 +               data = data << 1;
4621 +       }
4622 +       return (u8)(data >> 8);
4623 +}
4624 +
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)
4629 +{
4630 +       int i;
4631 +
4632 +       for(i = 0; i < count; i++)
4633 +               crc = crc8((crc ^ first[i]) << 8);
4634 +       if(rest != NULL)
4635 +               for(i = 0; i <= rest[0]; i++)
4636 +                       crc = crc8((crc ^ rest[i]) << 8);
4637 +       return crc;
4638 +}
4639 +
4640 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
4641 +{
4642 +       return i2c_smbus_partial_pec(0, count, first, rest);
4643 +}
4644 +
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)
4650 +{
4651 +       u8 buf[3];
4652 +
4653 +       buf[0] = addr << 1;
4654 +       buf[1] = command;
4655 +       switch(size) {
4656 +               case I2C_SMBUS_BYTE:
4657 +                       data->byte = i2c_smbus_pec(2, buf, NULL);
4658 +                       size = I2C_SMBUS_BYTE_DATA;
4659 +                       break;
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;
4665 +                       break;
4666 +               case I2C_SMBUS_WORD_DATA:
4667 +                       /* unsupported */
4668 +                       break;
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;
4673 +                       break;
4674 +       }
4675 +       return size;    
4676 +}
4677 +
4678 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
4679 +                        union i2c_smbus_data *data)
4680 +{
4681 +       u8 buf[3], rpec, cpec;
4682 +
4683 +       buf[1] = command;
4684 +       switch(size) {
4685 +               case I2C_SMBUS_BYTE_DATA:
4686 +                       buf[0] = (addr << 1) | 1;
4687 +                       cpec = i2c_smbus_pec(2, buf, NULL);
4688 +                       rpec = data->byte;
4689 +                       break;
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;
4695 +                       break;
4696 +               case I2C_SMBUS_WORD_DATA_PEC:
4697 +                       /* unsupported */
4698 +                       cpec = rpec = 0;
4699 +                       break;
4700 +               case I2C_SMBUS_PROC_CALL_PEC:
4701 +                       /* unsupported */
4702 +                       cpec = rpec = 0;
4703 +                       break;
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];
4709 +                       break;
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];
4715 +                       break;
4716 +               default:
4717 +                       cpec = rpec = 0;
4718 +                       break;
4719 +       }
4720 +       if(rpec != cpec) {
4721 +               DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
4722 +                          rpec, cpec));
4723 +               return -1;
4724 +       }
4725 +       return 0;       
4726 +}
4727 +
4728  extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
4729  {
4730 @@ -1023,6 +1056,7 @@
4731  extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
4732  {
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);
4737  }
4738  
4739 @@ -1102,6 +1136,6 @@
4740         union i2c_smbus_data data;
4741         int i;
4742 -       if (length > 32)
4743 -               length = 32;
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 @@
4749  }
4750  
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)
4754 +{
4755 +       union i2c_smbus_data data;
4756 +       int i;
4757 +       if (length > I2C_SMBUS_BLOCK_MAX - 1)
4758 +               return -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))
4765 +               return -1;
4766 +       for (i = 1; i <= data.block[0]; i++)
4767 +               values[i-1] = data.block[i];
4768 +       return data.block[0];
4769 +}
4770 +
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)
4774 +{
4775 +       union i2c_smbus_data data;
4776 +       int i;
4777 +       if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4778 +                             I2C_SMBUS_READ,command,
4779 +                             I2C_SMBUS_I2C_BLOCK_DATA,&data))
4780 +               return -1;
4781 +       else {
4782 +               for (i = 1; i <= data.block[0]; i++)
4783 +                       values[i-1] = data.block[i];
4784 +               return data.block[0];
4785 +       }
4786 +}
4787 +
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;
4792         int i;
4793 -       if (length > 32)
4794 -               length = 32;
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;
4803                 msg[0].len = 3;
4804                 msg[1].len = 2;
4805 @@ -1186,22 +1258,45 @@
4806                 break;
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");
4812 -               return -1;
4813 +                       printk(KERN_ERR "i2c-core.o: Block read not supported "
4814 +                              "under I2C emulation!\n");
4815 +                       return -1;
4816                 } else {
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",
4823 -                                      msg[0].len);
4824 +                                      data->block[0]);
4825                                 return -1;
4826                         }
4827 +                       if(size == I2C_SMBUS_BLOCK_DATA_PEC)
4828 +                               (msg[0].len)++;
4829                         for (i = 1; i <= msg[0].len; i++)
4830                                 msgbuf0[i] = data->block[i-1];
4831                 }
4832                 break;
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");
4837 +               return -1;
4838 +       case I2C_SMBUS_I2C_BLOCK_DATA:
4839 +               if (read_write == I2C_SMBUS_READ) {
4840 +                       msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
4841 +               } else {
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",
4846 +                                      data->block[0]);
4847 +                               return -1;
4848 +                       }
4849 +                       for (i = 1; i <= data->block[0]; i++)
4850 +                               msgbuf0[i] = data->block[i];
4851 +               }
4852 +               break;
4853         default:
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",
4856                        size);
4857                 return -1;
4858 @@ -1223,4 +1318,10 @@
4859                                 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
4860                                 break;
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];
4866 +                               break;
4867                 }
4868         return 0;
4869 @@ -1228,18 +1329,48 @@
4870  
4871  
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)
4876  {
4877         s32 res;
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,
4882 +       int swpec = 0;
4883 +       u8 partial = 0;
4884 +
4885 +       flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4886 +       if((flags & I2C_CLIENT_PEC) &&
4887 +          !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4888 +               swpec = 1;
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);
4903 +       }
4904 +
4905 +       if (adap->algo->smbus_xfer) {
4906 +               down(&adap->bus);
4907 +               res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
4908                                                 command,size,data);
4909 -               I2C_UNLOCK(adapter);
4910 +               up(&adap->bus);
4911         } else
4912 -               res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
4913 +               res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
4914                                               command,size,data);
4915 +
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))
4921 +                       return -1;
4922 +       }
4923         return res;
4924  }
4925 @@ -1265,128 +1396,30 @@
4926  static int __init i2c_init(void)
4927  {
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));
4932 -       adap_count=0;
4933 -       driver_count=0;
4934  
4935 -       init_MUTEX(&adap_lock);
4936 -       init_MUTEX(&driver_lock);
4937 -       
4938 -       i2cproc_init();
4939 -       
4940 +#ifdef CONFIG_PROC_FS
4941 +       return i2cproc_init();
4942 +#else
4943         return 0;
4944 -}
4945 -
4946 -#ifndef MODULE
4947 -#ifdef CONFIG_I2C_CHARDEV
4948 -       extern int i2c_dev_init(void);
4949 -#endif
4950 -#ifdef CONFIG_I2C_ALGOBIT
4951 -       extern int i2c_algo_bit_init(void);
4952 -#endif
4953 -#ifdef CONFIG_I2C_PHILIPSPAR
4954 -       extern int i2c_bitlp_init(void);
4955 -#endif
4956 -#ifdef CONFIG_I2C_ELV
4957 -       extern int i2c_bitelv_init(void);
4958 -#endif
4959 -#ifdef CONFIG_I2C_VELLEMAN
4960 -       extern int i2c_bitvelle_init(void);
4961 -#endif
4962 -#ifdef CONFIG_I2C_BITVIA
4963 -       extern int i2c_bitvia_init(void);
4964 -#endif
4965 -
4966 -#ifdef CONFIG_I2C_ALGOPCF
4967 -       extern int i2c_algo_pcf_init(void);     
4968 -#endif
4969 -#ifdef CONFIG_I2C_ELEKTOR
4970 -       extern int i2c_pcfisa_init(void);
4971 -#endif
4972 -
4973 -#ifdef CONFIG_I2C_ALGO8XX
4974 -       extern int i2c_algo_8xx_init(void);
4975 -#endif
4976 -#ifdef CONFIG_I2C_RPXLITE
4977 -       extern int i2c_rpx_init(void);
4978  #endif
4979  
4980 -#ifdef CONFIG_I2C_ALGO_SIBYTE
4981 -       extern int i2c_algo_sibyte_init(void);
4982 -       extern int i2c_sibyte_init(void);
4983 -#endif
4984 -#ifdef CONFIG_I2C_MAX1617
4985 -       extern int i2c_max1617_init(void);
4986 -#endif
4987 +}
4988  
4989 -#ifdef CONFIG_I2C_PROC
4990 -       extern int sensors_init(void);
4991 +static void __exit i2c_exit(void) 
4992 +{
4993 +#ifdef CONFIG_PROC_FS
4994 +       i2cproc_cleanup();
4995  #endif
4996 +}
4997  
4998 -/* This is needed for automatic patch generation: sensors code starts here */
4999 -/* This is needed for automatic patch generation: sensors code ends here   */
5000 -
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)
5004  {
5005 -       /* --------------------- global ----- */
5006 -       i2c_init();
5007 -
5008 -#ifdef CONFIG_I2C_CHARDEV
5009 -       i2c_dev_init();
5010 -#endif
5011 -       /* --------------------- bit -------- */
5012 -#ifdef CONFIG_I2C_ALGOBIT
5013 -       i2c_algo_bit_init();
5014 -#endif
5015 -#ifdef CONFIG_I2C_PHILIPSPAR
5016 -       i2c_bitlp_init();
5017 -#endif
5018 -#ifdef CONFIG_I2C_ELV
5019 -       i2c_bitelv_init();
5020 -#endif
5021 -#ifdef CONFIG_I2C_VELLEMAN
5022 -       i2c_bitvelle_init();
5023 -#endif
5024 -
5025 -       /* --------------------- pcf -------- */
5026 -#ifdef CONFIG_I2C_ALGOPCF
5027 -       i2c_algo_pcf_init();    
5028 -#endif
5029 -#ifdef CONFIG_I2C_ELEKTOR
5030 -       i2c_pcfisa_init();
5031 -#endif
5032 -
5033 -       /* --------------------- 8xx -------- */
5034 -#ifdef CONFIG_I2C_ALGO8XX
5035 -       i2c_algo_8xx_init();
5036 -#endif
5037 -#ifdef CONFIG_I2C_RPXLITE
5038 -       i2c_rpx_init();
5039 -#endif
5040 -
5041 -       /* --------------------- SiByte -------- */
5042 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5043 -       i2c_algo_sibyte_init();
5044 -       i2c_sibyte_init();
5045 -#endif
5046 -#ifdef CONFIG_I2C_MAX1617
5047 -       i2c_max1617_init();
5048 -#endif
5049 -
5050 -       /* -------------- proc interface ---- */
5051 -#ifdef CONFIG_I2C_PROC
5052 -       sensors_init();
5053 -#endif
5054 -/* This is needed for automatic patch generation: sensors code starts here */
5055 -/* This is needed for automatic patch generation: sensors code ends here */
5056 -
5057         return 0;
5058  }
5059  
5060 -#endif
5061 -
5062 -
5063 -
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);
5079  
5080  EXPORT_SYMBOL(i2c_get_functionality);
5081  EXPORT_SYMBOL(i2c_check_functionality);
5082  
5083 -#ifdef MODULE
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");
5089  
5090 -int init_module(void) 
5091 -{
5092 -       return i2c_init();
5093 -}
5094 +MODULE_PARM(i2c_debug, "i");
5095 +MODULE_PARM_DESC(i2c_debug,"debug level");
5096  
5097 -void cleanup_module(void) 
5098 -{
5099 -       i2cproc_cleanup();
5100 -}
5101 -#endif
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
5106 @@ -29,39 +29,25 @@
5107     <pmhahn@titan.lahn.de> */
5108  
5109 -/* $Id$ */
5110 +/* $Id$ */
5111  
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>
5123  #endif
5124 -
5125 -
5126 -/* If you want debugging uncomment: */
5127 -/* #define DEBUG */
5128 -
5129  #include <linux/init.h>
5130 -#include <asm/uaccess.h>
5131 -
5132  #include <linux/i2c.h>
5133  #include <linux/i2c-dev.h>
5134 +#include <asm/uaccess.h>
5135 +
5136 +/* If you want debugging uncomment: */
5137 +/* #define DEBUG */
5138  
5139 -#ifdef MODULE
5140 -extern int init_module(void);
5141 -extern int cleanup_module(void);
5142 -#endif /* def MODULE */
5143  
5144  /* struct file_operations changed too often in the 2.1 series for nice code */
5145  
5146 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5147 -static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin);
5148 -#endif
5149  static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, 
5150                              loff_t *offset);
5151 @@ -80,26 +66,12 @@
5152                             void *arg);
5153  
5154 -#ifdef MODULE
5155 -static
5156 -#else
5157 -extern
5158 -#endif
5159 -       int __init i2c_dev_init(void);
5160 -static int i2cdev_cleanup(void);
5161 -
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,
5168 -#else
5169 -       llseek:         no_llseek,
5170 -#endif
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,
5183  };
5184  
5185 @@ -112,40 +84,20 @@
5186  
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,
5194 -/*     inc_use:        NULL,
5195 -       dec_use:        NULL, */
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,
5203  };
5204  
5205  static struct i2c_client i2cdev_client_template = {
5206 -       name:           "I2C /dev entry",
5207 -       id:             1,
5208 -       flags:          0,
5209 -       addr:           -1,
5210 -/*     adapter:        NULL, */
5211 -       driver:         &i2cdev_driver,
5212 -/*     data:           NULL */
5213 +       .name           = "I2C /dev entry",
5214 +       .id             = 1,
5215 +       .addr           = -1,
5216 +       .driver         = &i2cdev_driver,
5217  };
5218  
5219 -static int i2cdev_initialized;
5220 -
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)
5225 -{
5226 -#ifdef DEBUG
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);
5230 -#endif /* DEBUG */
5231 -       return -ESPIPE;
5232 -}
5233 -#endif
5234 -
5235  static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5236                              loff_t *offset)
5237 @@ -160,7 +112,7 @@
5238         struct i2c_client *client = (struct i2c_client *)file->private_data;
5239  
5240 -       if(count > 8192)
5241 +       if (count > 8192)
5242                 count = 8192;
5243 -               
5244 +
5245         /* copy user space data to kernel space. */
5246         tmp = kmalloc(count,GFP_KERNEL);
5247 @@ -169,5 +121,5 @@
5248  
5249  #ifdef DEBUG
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),
5252                count);
5253  #endif
5254 @@ -191,7 +143,7 @@
5255  #endif /* DEBUG */
5256  
5257 -       if(count > 8192)
5258 +       if (count > 8192)
5259                 count = 8192;
5260 -               
5261 +
5262         /* copy user space data to kernel space. */
5263         tmp = kmalloc(count,GFP_KERNEL);
5264 @@ -204,5 +156,5 @@
5265  
5266  #ifdef DEBUG
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),
5269                count);
5270  #endif
5271 @@ -225,6 +177,6 @@
5272  
5273  #ifdef DEBUG
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);
5278  #endif /* DEBUG */
5279  
5280 @@ -245,4 +197,10 @@
5281                         client->flags &= ~I2C_M_TEN;
5282                 return 0;
5283 +       case I2C_PEC:
5284 +               if (arg)
5285 +                       client->flags |= I2C_CLIENT_PEC;
5286 +               else
5287 +                       client->flags &= ~I2C_CLIENT_PEC;
5288 +               return 0;
5289         case I2C_FUNCS:
5290                 funcs = i2c_get_functionality(client->adapter);
5291 @@ -260,5 +218,5 @@
5292                 if (rdwr_arg.nmsgs > 42)
5293                         return -EINVAL;
5294 -               
5295 +               
5296                 rdwr_pa = (struct i2c_msg *)
5297                         kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), 
5298 @@ -345,7 +303,8 @@
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)) {
5304  #ifdef DEBUG
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",
5307                                data_arg.size);
5308  #endif
5309 @@ -357,5 +316,5 @@
5310                     (data_arg.read_write != I2C_SMBUS_WRITE)) {
5311  #ifdef DEBUG
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);
5315  #endif
5316 @@ -377,5 +336,5 @@
5317                 if (data_arg.data == NULL) {
5318  #ifdef DEBUG
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");
5321  #endif
5322                         return -EINVAL;
5323 @@ -388,8 +347,9 @@
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);
5329  
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))
5334 @@ -400,4 +360,5 @@
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)
5342  {
5343 -       unsigned int minor = MINOR(inode->i_rdev);
5344 +       unsigned int minor = minor(inode->i_rdev);
5345         struct i2c_client *client;
5346  
5347         if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
5348  #ifdef DEBUG
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",
5351                        minor);
5352  #endif
5353 @@ -430,15 +391,14 @@
5354                 return -ENOMEM;
5355         memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
5356 +
5357 +       /* registered with adapter, passed as client to user */
5358         client->adapter = i2cdev_adaps[minor];
5359         file->private_data = client;
5360  
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);
5368  
5369  #ifdef DEBUG
5370 -       printk("i2c-dev.o: opened i2c-%d\n",minor);
5371 +       printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
5372  #endif
5373         return 0;
5374 @@ -447,20 +407,17 @@
5375  static int i2cdev_release (struct inode *inode, struct file *file)
5376  {
5377 -       unsigned int minor = MINOR(inode->i_rdev);
5378 -       kfree(file->private_data);
5379 -       file->private_data=NULL;
5380 -#ifdef DEBUG
5381 -       printk("i2c-dev.o: Closed: i2c-%d\n", minor);
5382 -#endif
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) */
5386 -       lock_kernel();
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)
5391 -       unlock_kernel();
5392 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5393 +       struct i2c_client *client;
5394 +#ifdef DEBUG
5395 +       unsigned int minor = minor(inode->i_rdev);
5396 +#endif
5397 +
5398 +       client = file->private_data;
5399 +       file->private_data = NULL;
5400 +       if(client->adapter->owner)
5401 +               __MOD_DEC_USE_COUNT(client->adapter->owner);
5402 +       kfree(client);
5403 +#ifdef DEBUG
5404 +       printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
5405 +#endif
5406         return 0;
5407  }
5408 @@ -472,9 +429,9 @@
5409  
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");
5413                 return -ENODEV;
5414         }
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);
5418                 return -ENODEV;
5419         }
5420 @@ -487,7 +444,7 @@
5421                         DEVFS_FL_DEFAULT, I2C_MAJOR, i,
5422                         S_IFCHR | S_IRUSR | S_IWUSR,
5423 -                       &i2cdev_fops, NULL);
5424 +                       &i2cdev_fops, adap);
5425  #endif
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);
5428         } else {
5429                 /* This is actually a detach_adapter call! */
5430 @@ -497,5 +454,5 @@
5431                 i2cdev_adaps[i] = NULL;
5432  #ifdef DEBUG
5433 -               printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5434 +               printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5435  #endif
5436         }
5437 @@ -519,7 +476,6 @@
5438         int res;
5439  
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);
5442  
5443 -       i2cdev_initialized = 0;
5444  #ifdef CONFIG_DEVFS_FS
5445         if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
5446 @@ -527,5 +483,5 @@
5447         if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
5448  #endif
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",
5451                        I2C_MAJOR);
5452                 return -EIO;
5453 @@ -534,62 +490,28 @@
5454         devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
5455  #endif
5456 -       i2cdev_initialized ++;
5457 -
5458         if ((res = i2c_add_driver(&i2cdev_driver))) {
5459 -               printk("i2c-dev.o: Driver registration failed, module not inserted.\n");
5460 -               i2cdev_cleanup();
5461 +               printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
5462 +#ifdef CONFIG_DEVFS_FS
5463 +               devfs_unregister(devfs_handle);
5464 +#endif
5465 +               unregister_chrdev(I2C_MAJOR,"i2c");
5466                 return res;
5467         }
5468 -       i2cdev_initialized ++;
5469         return 0;
5470  }
5471  
5472 -int i2cdev_cleanup(void)
5473 +static void __exit i2c_dev_exit(void)
5474  {
5475 -       int res;
5476 -
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");
5481 -                       return res;
5482 -               }
5483 -       i2cdev_initialized --;
5484 -       }
5485 -
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"))) {
5491 -#else
5492 -               if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
5493 +       devfs_unregister(devfs_handle);
5494  #endif
5495 -                       printk("i2c-dev.o: unable to release major %d for i2c bus\n",
5496 -                              I2C_MAJOR);
5497 -                       return res;
5498 -               }
5499 -               i2cdev_initialized --;
5500 -       }
5501 -       return 0;
5502 +       unregister_chrdev(I2C_MAJOR,"i2c");
5503  }
5504  
5505 -EXPORT_NO_SYMBOLS;
5506 -
5507 -#ifdef MODULE
5508 -
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");
5512  
5513 -int init_module(void)
5514 -{
5515 -       return i2c_dev_init();
5516 -}
5517 -
5518 -int cleanup_module(void)
5519 -{
5520 -       return i2cdev_cleanup();
5521 -}
5522 -
5523 -#endif /* def MODULE */
5524 -
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
5529 @@ -20,12 +20,14 @@
5530  */
5531  
5532 -/* $Id$ */
5533 -
5534 -#ifndef I2C_DEV_H
5535 -#define I2C_DEV_H
5536 +/* $Id$ */
5537  
5538 +#ifndef _LINUX_I2C_DEV_H
5539 +#define _LINUX_I2C_DEV_H
5540  
5541  #include <linux/types.h>
5542 -#include <linux/i2c.h>
5543 +
5544 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
5545 +#define minor(d) MINOR(d)
5546 +#endif
5547  
5548  /* Some IOCTL commands are defined in <linux/i2c.h> */
5549 @@ -46,136 +48,3 @@
5550  };
5551  
5552 -#ifndef __KERNEL__
5553 -
5554 -#include <sys/ioctl.h>
5555 -
5556 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, 
5557 -                                     int size, union i2c_smbus_data *data)
5558 -{
5559 -       struct i2c_smbus_ioctl_data args;
5560 -
5561 -       args.read_write = read_write;
5562 -       args.command = command;
5563 -       args.size = size;
5564 -       args.data = data;
5565 -       return ioctl(file,I2C_SMBUS,&args);
5566 -}
5567 -
5568 -
5569 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
5570 -{
5571 -       return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
5572 -}
5573 -       
5574 -static inline __s32 i2c_smbus_read_byte(int file)
5575 -{
5576 -       union i2c_smbus_data data;
5577 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
5578 -               return -1;
5579 -       else
5580 -               return 0x0FF & data.byte;
5581 -}
5582 -
5583 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
5584 -{
5585 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
5586 -                               I2C_SMBUS_BYTE,NULL);
5587 -}
5588 -
5589 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
5590 -{
5591 -       union i2c_smbus_data data;
5592 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5593 -                            I2C_SMBUS_BYTE_DATA,&data))
5594 -               return -1;
5595 -       else
5596 -               return 0x0FF & data.byte;
5597 -}
5598 -
5599 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, 
5600 -                                              __u8 value)
5601 -{
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);
5606 -}
5607 -
5608 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
5609 -{
5610 -       union i2c_smbus_data data;
5611 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5612 -                            I2C_SMBUS_WORD_DATA,&data))
5613 -               return -1;
5614 -       else
5615 -               return 0x0FFFF & data.word;
5616 -}
5617 -
5618 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, 
5619 -                                              __u16 value)
5620 -{
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);
5625 -}
5626 -
5627 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
5628 -{
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))
5633 -               return -1;
5634 -       else
5635 -               return 0x0FFFF & data.word;
5636 -}
5637 -
5638 -
5639 -/* Returns the number of read bytes */
5640 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command, 
5641 -                                              __u8 *values)
5642 -{
5643 -       union i2c_smbus_data data;
5644 -       int i;
5645 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5646 -                            I2C_SMBUS_BLOCK_DATA,&data))
5647 -               return -1;
5648 -       else {
5649 -               for (i = 1; i <= data.block[0]; i++)
5650 -                       values[i-1] = data.block[i];
5651 -                       return data.block[0];
5652 -       }
5653 -}
5654 -
5655 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, 
5656 -                                               __u8 length, __u8 *values)
5657 -{
5658 -       union i2c_smbus_data data;
5659 -       int i;
5660 -       if (length > 32)
5661 -               length = 32;
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);
5667 -}
5668 -
5669 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
5670 -                                               __u8 length, __u8 *values)
5671 -{
5672 -       union i2c_smbus_data data;
5673 -       int i;
5674 -       if (length > 32)
5675 -               length = 32;
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);
5681 -}
5682 -
5683 -#endif /* ndef __KERNEL__ */
5684 -
5685 -#endif
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
5689 @@ -31,23 +31,21 @@
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>
5698 -
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>
5706  
5707  #define DEFAULT_BASE 0x330
5708  
5709 -static int base   = 0;
5710 -static int irq    = 0;
5711 +static int base;
5712 +static int irq;
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;
5719  
5720  /* vdovikin: removed static struct i2c_pcf_isa gpi; code - 
5721 @@ -56,10 +54,7 @@
5722    need to be rewriten - but for now just remove this for simpler reading */
5723  
5724 -#if (LINUX_VERSION_CODE < 0x020301)
5725 -static struct wait_queue *pcf_wait = NULL;
5726 -#else
5727  static wait_queue_head_t pcf_wait;
5728 -#endif
5729  static int pcf_pending;
5730 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5731  
5732  /* ----- global defines -----------------------------------------------        */
5733 @@ -69,4 +64,14 @@
5734  #define DEBE(x)        x       /* error messages                               */
5735  
5736 +
5737 +/* compatibility */
5738 +#ifndef isa_readb
5739 +#define isa_readb readb
5740 +#endif
5741 +
5742 +#ifndef isa_writeb
5743 +#define isa_writeb writeb
5744 +#endif
5745 +
5746  /* ----- local functions ----------------------------------------------        */
5747  
5748 @@ -75,9 +80,10 @@
5749         int address = ctl ? (base + 1) : base;
5750  
5751 -       if (ctl && irq) {
5752 +       /* enable irq if any specified for serial operation */
5753 +       if (ctl && irq && (val & I2C_PCF_ESO)) {
5754                 val |= I2C_PCF_ENI;
5755         }
5756  
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));
5759  
5760         switch (mmapped) {
5761 @@ -87,8 +93,8 @@
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);
5766                 /* fall */
5767         case 1: /* memory mapped I/O */
5768 -               writeb(val, address);
5769 +               isa_writeb(val, address);
5770                 break;
5771         }
5772 @@ -98,7 +104,7 @@
5773  {
5774         int address = ctl ? (base + 1) : base;
5775 -       int val = mmapped ? readb(address) : inb(address);
5776 +       int val = mmapped ? isa_readb(address) : inb(address);
5777  
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));
5780  
5781         return (val);
5782 @@ -121,10 +127,10 @@
5783  
5784         if (irq > 0) {
5785 -               cli();
5786 +               spin_lock_irq(&irq_driver_lock);
5787                 if (pcf_pending == 0) {
5788                         interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
5789                 } else
5790                         pcf_pending = 0;
5791 -               sti();
5792 +               spin_unlock_irq(&irq_driver_lock);
5793         } else {
5794                 udelay(100);
5795 @@ -142,14 +148,14 @@
5796  {
5797         if (!mmapped) {
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)")) {
5801 +                       printk(KERN_ERR
5802 +                              "i2c-elektor.o: requested I/O region (0x%X:2) "
5803 +                              "is in use.\n", base);
5804                         return -ENODEV;
5805 -               } else {
5806 -                       request_region(base, 2, "i2c (isa bus adapter)");
5807                 }
5808         }
5809         if (irq > 0) {
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);
5813                         irq = 0;
5814                 } else
5815 @@ -160,42 +166,4 @@
5816  
5817  
5818 -static void __exit pcf_isa_exit(void)
5819 -{
5820 -       if (irq > 0) {
5821 -               disable_irq(irq);
5822 -               free_irq(irq, 0);
5823 -       }
5824 -       if (!mmapped) {
5825 -               release_region(base , 2);
5826 -       }
5827 -}
5828 -
5829 -
5830 -static int pcf_isa_reg(struct i2c_client *client)
5831 -{
5832 -       return 0;
5833 -}
5834 -
5835 -
5836 -static int pcf_isa_unreg(struct i2c_client *client)
5837 -{
5838 -       return 0;
5839 -}
5840 -
5841 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
5842 -{
5843 -#ifdef MODULE
5844 -       MOD_INC_USE_COUNT;
5845 -#endif
5846 -}
5847 -
5848 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
5849 -{
5850 -#ifdef MODULE
5851 -       MOD_DEC_USE_COUNT;
5852 -#endif
5853 -}
5854 -
5855 -
5856  /* ------------------------------------------------------------------------
5857   * Encapsulate the above functions in the correct operations structure.
5858 @@ -203,25 +171,22 @@
5859   */
5860  static struct i2c_algo_pcf_data pcf_isa_data = {
5861 -       NULL,
5862 -       pcf_isa_setbyte,
5863 -       pcf_isa_getbyte,
5864 -       pcf_isa_getown,
5865 -       pcf_isa_getclock,
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,
5873 +       .udelay     = 10,
5874 +       .mdelay     = 10,
5875 +       .timeout    = HZ,
5876  };
5877  
5878  static struct i2c_adapter pcf_isa_ops = {
5879 -       "PCF8584 ISA adapter",
5880 -       I2C_HW_P_ELEK,
5881 -       NULL,
5882 -       &pcf_isa_data,
5883 -       pcf_isa_inc_use,
5884 -       pcf_isa_dec_use,
5885 -       pcf_isa_reg,
5886 -       pcf_isa_unreg,
5887 +       .owner             = THIS_MODULE,
5888 +       .name              = "PCF8584 ISA adapter",
5889 +       .id                = I2C_HW_P_ELEK,
5890 +       .algo_data         = &pcf_isa_data,
5891  };
5892  
5893 -int __init i2c_pcfisa_init(void) 
5894 +static int __init i2c_pcfisa_init(void) 
5895  {
5896  #ifdef __alpha__
5897 @@ -239,5 +204,5 @@
5898                         if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
5899                                 
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));
5902  
5903                                 /* UP2000 board has this register set to 0xe1,
5904 @@ -261,5 +226,5 @@
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");
5909                                 }
5910                         }
5911 @@ -270,9 +235,9 @@
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);
5916                 return -ENODEV;
5917         }
5918  
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);
5921  
5922         if (base == 0) {
5923 @@ -280,23 +245,39 @@
5924         }
5925  
5926 -#if (LINUX_VERSION_CODE >= 0x020301)
5927         init_waitqueue_head(&pcf_wait);
5928 -#endif
5929 -       if (pcf_isa_init() == 0) {
5930 -               if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5931 -                       return -ENODEV;
5932 -       } else {
5933 +       if (pcf_isa_init())
5934                 return -ENODEV;
5935 -       }
5936 +       if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
5937 +               goto fail;
5938         
5939 -       printk("i2c-elektor.o: found device at %#x.\n", base);
5940 +       printk(KERN_ERR "i2c-elektor.o: found device at %#x.\n", base);
5941  
5942         return 0;
5943 +
5944 + fail:
5945 +       if (irq > 0) {
5946 +               disable_irq(irq);
5947 +               free_irq(irq, 0);
5948 +       }
5949 +
5950 +       if (!mmapped)
5951 +               release_region(base , 2);
5952 +       return -ENODEV;
5953  }
5954  
5955  
5956 -EXPORT_NO_SYMBOLS;
5957 +static void i2c_pcfisa_exit(void)
5958 +{
5959 +       i2c_pcf_del_bus(&pcf_isa_ops);
5960 +
5961 +       if (irq > 0) {
5962 +               disable_irq(irq);
5963 +               free_irq(irq, 0);
5964 +       }
5965 +
5966 +       if (!mmapped)
5967 +               release_region(base , 2);
5968 +}
5969  
5970 -#ifdef MODULE
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");
5975  
5976 -int init_module(void) 
5977 -{
5978 -       return i2c_pcfisa_init();
5979 -}
5980 -
5981 -void cleanup_module(void) 
5982 -{
5983 -       i2c_pcf_del_bus(&pcf_isa_ops);
5984 -       pcf_isa_exit();
5985 -}
5986 -
5987 -#endif
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
5992 @@ -1,47 +0,0 @@
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
5998 -
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.
6003 -
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.
6008 -
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 -/* ------------------------------------------------------------------------- */
6013 -
6014 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6015 -   Frodo Looijaard <frodol@dds.nl> */
6016 -
6017 -/* $Id$ */
6018 -
6019 -#ifndef I2C_PCF_ELEKTOR_H
6020 -#define I2C_PCF_ELEKTOR_H 1
6021 -
6022 -/*
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 */
6029 -
6030 -/*
6031 -struct i2c_pcf_isa {
6032 -       int pi_base;
6033 -       int pi_irq;
6034 -       int pi_clock;
6035 -       int pi_own;
6036 -};
6037 -*/
6038 -
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
6042 @@ -22,5 +22,5 @@
6043     Frodo Looijaard <frodol@dds.nl> */
6044  
6045 -/* $Id$ */
6046 +/* $Id$ */
6047  
6048  #include <linux/kernel.h>
6049 @@ -28,14 +28,10 @@
6050  #include <linux/delay.h>
6051  #include <linux/slab.h>
6052 -#include <linux/version.h>
6053  #include <linux/init.h>
6054 -
6055 -#include <asm/uaccess.h>
6056 -
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>
6063  
6064  #define DEFAULT_BASE 0x378
6065 @@ -91,56 +87,29 @@
6066  static int bit_elv_init(void)
6067  {
6068 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6069 -               return -ENODEV; 
6070 -       } else {
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"));
6074 -                       return -ENODEV;
6075 -               } else {
6076 -                       outb(0x0c,base+2);      /* SLCT auf low         */
6077 -                       udelay(400);
6078 -                       if ( !(inb(base+1) && 0x10) ) {
6079 -                               outb(0x04,base+2);
6080 -                               DEBINIT(printk("i2c-elv.o: Select was high.\n"));
6081 -                               return -ENODEV;
6082 -                       }
6083 -               }
6084 -               request_region(base,(base == 0x3bc)? 3 : 8,
6085 -                       "i2c (ELV adapter)");
6086 -               PortData = 0;
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)"))
6091 +               return -ENODEV;
6092 +
6093 +       if (inb(base+1) & 0x80) {       /* BUSY should be high  */
6094 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
6095 +               goto fail;
6096 +       } 
6097 +
6098 +       outb(0x0c,base+2);      /* SLCT auf low         */
6099 +       udelay(400);
6100 +       if (!(inb(base+1) && 0x10)) {
6101 +               outb(0x04,base+2);
6102 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
6103 +               goto fail;
6104         }
6105 -       return 0;
6106 -}
6107 -
6108 -static void __exit bit_elv_exit(void)
6109 -{
6110 -       release_region( base , (base == 0x3bc)? 3 : 8 );
6111 -}
6112  
6113 -static int bit_elv_reg(struct i2c_client *client)
6114 -{
6115 +       PortData = 0;
6116 +       bit_elv_setsda((void*)base,1);
6117 +       bit_elv_setscl((void*)base,1);
6118         return 0;
6119 -}
6120  
6121 -static int bit_elv_unreg(struct i2c_client *client)
6122 -{
6123 -       return 0;
6124 -}
6125 -
6126 -static void bit_elv_inc_use(struct i2c_adapter *adap)
6127 -{
6128 -#ifdef MODULE
6129 -       MOD_INC_USE_COUNT;
6130 -#endif
6131 -}
6132 -
6133 -static void bit_elv_dec_use(struct i2c_adapter *adap)
6134 -{
6135 -#ifdef MODULE
6136 -       MOD_DEC_USE_COUNT;
6137 -#endif
6138 +fail:
6139 +       release_region(base , (base == 0x3bc) ? 3 : 8);
6140 +       return -ENODEV;
6141  }
6142  
6143 @@ -150,26 +119,23 @@
6144   */
6145  static struct i2c_algo_bit_data bit_elv_data = {
6146 -       NULL,
6147 -       bit_elv_setsda,
6148 -       bit_elv_setscl,
6149 -       bit_elv_getsda,
6150 -       bit_elv_getscl,
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,
6156 +       .udelay         = 80,
6157 +       .mdelay         = 80,
6158 +       .timeout        = HZ
6159  };
6160  
6161  static struct i2c_adapter bit_elv_ops = {
6162 -       "ELV Parallel port adaptor",
6163 -       I2C_HW_B_ELV,
6164 -       NULL,
6165 -       &bit_elv_data,
6166 -       bit_elv_inc_use,
6167 -       bit_elv_dec_use,
6168 -       bit_elv_reg,
6169 -       bit_elv_unreg,  
6170 +       .owner          = THIS_MODULE,
6171 +       .name           = "ELV Parallel port adaptor",
6172 +       .id             = I2C_HW_B_ELV,
6173 +       .algo_data      = &bit_elv_data,
6174  };
6175  
6176 -int __init i2c_bitelv_init(void)
6177 +static int __init i2c_bitelv_init(void)
6178  {
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);
6181         if (base==0) {
6182                 /* probe some values */
6183 @@ -191,29 +157,22 @@
6184                 }
6185         }
6186 -       printk("i2c-elv.o: found device at %#x.\n",base);
6187 +       printk(KERN_DEBUG "i2c-elv.o: found device at %#x.\n",base);
6188         return 0;
6189  }
6190  
6191 +static void __exit i2c_bitelv_exit(void)
6192 +{
6193 +       i2c_bit_del_bus(&bit_elv_ops);
6194 +       release_region(base , (base == 0x3bc) ? 3 : 8);
6195 +}
6196  
6197  EXPORT_NO_SYMBOLS;
6198  
6199 -#ifdef MODULE
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");
6203  
6204 -
6205  MODULE_PARM(base, "i");
6206  
6207 -int init_module(void)
6208 -{
6209 -       return i2c_bitelv_init();
6210 -}
6211 -
6212 -void cleanup_module(void)
6213 -{
6214 -       i2c_bit_del_bus(&bit_elv_ops);
6215 -       bit_elv_exit();
6216 -}
6217 -
6218 -#endif
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
6223 @@ -0,0 +1,83 @@
6224 +
6225 +/*
6226 + * linux/drivers/i2c/i2c-frodo.c
6227 + *
6228 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
6229 + *
6230 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
6231 + * Development board (Frodo).
6232 + *
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.
6236 + */
6237 +
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>
6245 +
6246 +
6247 +static void frodo_setsda (void *data,int state)
6248 +{
6249 +       if (state)
6250 +               FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
6251 +       else
6252 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
6253 +}
6254 +
6255 +static void frodo_setscl (void *data,int state)
6256 +{
6257 +       if (state)
6258 +               FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
6259 +       else
6260 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
6261 +}
6262 +
6263 +static int frodo_getsda (void *data)
6264 +{
6265 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
6266 +}
6267 +
6268 +static int frodo_getscl (void *data)
6269 +{
6270 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
6271 +}
6272 +
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,
6278 +       .udelay         = 80,
6279 +       .mdelay         = 80,
6280 +       .timeout        = HZ
6281 +};
6282 +
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,
6288 +};
6289 +
6290 +static int __init i2c_frodo_init (void)
6291 +{
6292 +       return i2c_bit_add_bus(&frodo_ops);
6293 +}
6294 +
6295 +static void __exit i2c_frodo_exit (void)
6296 +{
6297 +       i2c_bit_del_bus(&frodo_ops);
6298 +}
6299 +
6300 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
6301 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
6302 +MODULE_LICENSE ("GPL");
6303 +
6304 +module_init (i2c_frodo_init);
6305 +module_exit (i2c_frodo_exit);
6306 +
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
6309 @@ -21,8 +21,9 @@
6310  /* ------------------------------------------------------------------------- */
6311  
6312 -/* $Id$ */
6313 +/* $Id$ */
6314 +
6315 +#ifndef LINUX_I2C_ID_H
6316 +#define LINUX_I2C_ID_H
6317  
6318 -#ifndef I2C_ID_H
6319 -#define I2C_ID_H
6320  /*
6321   * This file is part of the i2c-bus package and contains the identifier
6322 @@ -91,5 +92,16 @@
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     */
6336 +
6337 +
6338  
6339  #define I2C_DRIVERID_EXP0      0xF0    /* experimental use id's        */
6340 @@ -100,4 +112,6 @@
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  */
6345  
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
6368  
6369  /*
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         */
6373 -
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     */
6381  
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 */
6386  
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              */
6402  
6403  /* --- PCF 8584 based algorithms                                       */
6404 @@ -188,7 +236,19 @@
6405  #define I2C_HW_ACPI_EC          0x00
6406  
6407 +/* --- MPC824x PowerPC adapters                                                */
6408 +#define I2C_HW_MPC824X 0x00    /* Motorola 8240 / 8245                 */
6409 +
6410  /* --- MPC8xx PowerPC adapters                                         */
6411  #define I2C_HW_MPC8XX_EPON 0x00        /* Eponymous MPC8xx I2C adapter         */
6412  
6413 +/* --- ITE based algorithms                                            */
6414 +#define I2C_HW_I_IIC   0x00    /* controller on the ITE */
6415 +
6416 +/* --- PowerPC on-chip adapters                                                */
6417 +#define I2C_HW_OCP 0x00        /* IBM on-chip I2C adapter      */
6418 +
6419 +/* --- XSCALE on-chip adapters                          */
6420 +#define I2C_HW_IOP321 0x00
6421 +
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
6432  
6433  /* --- ISA pseudo-adapter                                              */
6434  #define I2C_HW_ISA 0x00
6435  
6436 -#endif /* I2C_ID_H */
6437 +/* --- IPMI pseudo-adapter                                             */
6438 +#define I2C_HW_IPMI 0x00
6439 +
6440 +/* --- IPMB adapter                                            */
6441 +#define I2C_HW_IPMB 0x00
6442 +
6443 +/* --- MCP107 adapter */
6444 +#define I2C_HW_MPC107 0x00
6445 +
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
6449 @@ -1,225 +0,0 @@
6450 -/*
6451 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
6452 - *
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.
6457 - *
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.
6462 - * 
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.
6466 - */
6467 -
6468 -/*
6469 - * SMBus/I2C device driver for the MAX1617 temperature sensor
6470 - */
6471 -
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>
6478 -
6479 -#include <linux/i2c.h>
6480 -#include <linux/i2c-algo-sibyte.h>
6481 -
6482 -#define IF_NAME "max1617"
6483 -
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
6489 -
6490 -static int max1617_verbose = 0;
6491 -static int max1617_polling = 1;
6492 -
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 };
6501 -
6502 -static struct i2c_client_address_data addr_data = {
6503 -        normal_i2c, normal_i2c_range,
6504 -        probe, probe_range,
6505 -        ignore, ignore_range,
6506 -        force
6507 -};
6508 -
6509 -struct max1617_info {
6510 -        struct i2c_client *client;
6511 -        struct timer_list  timer;
6512 -        int                local;
6513 -        int                remote;
6514 -};
6515 -
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);
6521 -
6522 -struct i2c_driver i2c_driver_max1617 = {
6523 -       name:           IF_NAME,
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
6531 -};
6532 -\
6533 -static int max1617_read(struct i2c_client *client, unsigned char subaddr)
6534 -{
6535 -        return i2c_smbus_read_byte_data(client, subaddr);
6536 -}
6537 -
6538 -/* poll the device, check for temperature/status changes */
6539 -static void max1617_update(unsigned long arg)
6540 -{
6541 -        struct max1617_info *m = (struct max1617_info *)arg;
6542 -        int status, remote, local;
6543 -        char statstr[50];
6544 -
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");
6550 -        } else {
6551 -                statstr[0] = 0;
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 ");
6558 -
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);
6562 -                }
6563 -                m->local = local;
6564 -                m->remote = remote;
6565 -                mod_timer(&m->timer, jiffies + (HZ * MAX1617_POLL_PERIOD));
6566 -        }
6567 -}
6568 -
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)
6571 -{
6572 -        struct max1617_info *m;
6573 -        struct i2c_client   *client;
6574 -        int err;
6575 -
6576 -        client = kmalloc(sizeof(*client), GFP_KERNEL);
6577 -        if (client == NULL)
6578 -                return -ENOMEM;
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) {
6584 -                kfree(client);
6585 -                return err;
6586 -        }
6587 -
6588 -        m = kmalloc(sizeof(*m), GFP_KERNEL);
6589 -        if (m == NULL) {
6590 -                i2c_detach_client(client);
6591 -                kfree(client);
6592 -                return -ENOMEM;
6593 -        }
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);
6602 -        }
6603 -        client->data = m;
6604 -        return 0;
6605 -}
6606 -
6607 -/* initiate probing on a particular bus */
6608 -static int max1617_probe(struct i2c_adapter *adap)
6609 -{
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);
6613 -        else
6614 -                return 0;
6615 -}
6616 -
6617 -static int max1617_detach(struct i2c_client *device)
6618 -{
6619 -        struct max1617_info *m = (struct max1617_info *)device->data;
6620 -       int rc = 0;
6621 -
6622 -       if ((rc = i2c_detach_client(device)) != 0) {
6623 -               printk(IF_NAME "detach failed: %d\n", rc);
6624 -       } else {
6625 -               kfree(device);
6626 -               if (max1617_polling)
6627 -                       del_timer(&m->timer);
6628 -               kfree(m);
6629 -       }
6630 -       return rc;
6631 -}
6632 -
6633 -static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg)
6634 -{
6635 -        return 0;
6636 -}
6637 -
6638 -static void max1617_inc_use(struct i2c_client *client)
6639 -{
6640 -#ifdef MODULE
6641 -       MOD_INC_USE_COUNT;
6642 -#endif
6643 -}
6644 -
6645 -static void max1617_dec_use(struct i2c_client *client)
6646 -{
6647 -#ifdef MODULE
6648 -       MOD_DEC_USE_COUNT;
6649 -#endif
6650 -}
6651 -
6652 -void i2c_max1617_init(void)
6653 -{
6654 -        i2c_add_driver(&i2c_driver_max1617);
6655 -}
6656 -
6657 -EXPORT_NO_SYMBOLS;
6658 -
6659 -#ifdef MODULE
6660 -MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
6661 -MODULE_DESCRIPTION("Max 1617 temperature sensor for SiByte SOC boards");
6662 -MODULE_LICENSE("GPL");
6663 -
6664 -int init_module(void)
6665 -{
6666 -       i2c_max1617_init();
6667 -       return 0;
6668 -}
6669 -
6670 -void cleanup_module(void)
6671 -{
6672 -        i2c_del_driver(&i2c_driver_max1617);
6673 -}
6674 -#endif
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
6677 @@ -0,0 +1,281 @@
6678 +/* ------------------------------------------------------------------------- */
6679 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters  */
6680 +/* ------------------------------------------------------------------------- */
6681 +/*   Copyright (C) 1998-99 Hans Berglund
6682 +
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.
6687 +
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.
6692 +
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 +/* ------------------------------------------------------------------------- */
6697 +
6698 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
6699 +
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>
6711 +
6712 +
6713 +struct  i2c_pcf_epp {
6714 +  int pe_base;
6715 +  int pe_irq;
6716 +  int pe_clock;
6717 +  int pe_own;
6718 +} ;
6719 +
6720 +#define DEFAULT_BASE 0x378
6721 +#define DEFAULT_IRQ      7
6722 +#define DEFAULT_CLOCK 0x1c
6723 +#define DEFAULT_OWN   0x55
6724 +
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;
6734 +
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                               */
6740 +
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 */
6748 +
6749 +/* ----- local functions ----------------------------------------------        */
6750 +
6751 +static void pcf_epp_setbyte(void *data, int ctl, int val)
6752 +{
6753 +  if (ctl) {
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)));
6761 +      
6762 +      // EPP write data cycle
6763 +      outb(val | I2C_PCF_ENI, EDAT);
6764 +    } else {
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);
6768 +      outb(val, CTRL);
6769 +    }
6770 +  } else {
6771 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
6772 +    // set A0 pin LO
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)));
6776 +    outb(val, EDAT);
6777 +  }
6778 +}
6779 +
6780 +static int pcf_epp_getbyte(void *data, int ctl)
6781 +{
6782 +  int val;
6783 +
6784 +  if (ctl) {
6785 +    // set A0 pin HIGH
6786 +    outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6787 +    val = inb(EDAT);
6788 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
6789 +  } else {
6790 +    // set A0 pin LOW
6791 +    outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6792 +    val = inb(EDAT);
6793 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
6794 +  }
6795 +  return (val);
6796 +}
6797 +
6798 +static int pcf_epp_getown(void *data)
6799 +{
6800 +  return (gpe.pe_own);
6801 +}
6802 +
6803 +
6804 +static int pcf_epp_getclock(void *data)
6805 +{
6806 +  return (gpe.pe_clock);
6807 +}
6808 +
6809 +#if 0
6810 +static void pcf_epp_sleep(unsigned long timeout)
6811 +{
6812 +  schedule_timeout( timeout * HZ);
6813 +}
6814 +#endif
6815 +
6816 +static void pcf_epp_waitforpin(void) {
6817 +  int timeout = 10;
6818 +
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);
6823 +      //udelay(100);
6824 +    } else {
6825 +      pcf_pending = 0;
6826 +    }
6827 +    spin_unlock_irq(&irq_driver_lock);
6828 +  } else {
6829 +    udelay(100);
6830 +  }
6831 +}
6832 +
6833 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
6834 +  pcf_pending = 1;
6835 +  wake_up_interruptible(&pcf_wait);
6836 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
6837 +}
6838 +
6839 +
6840 +static int pcf_epp_init(void *data)
6841 +{
6842 +  if (check_region(gpe.pe_base, 5) < 0 ) {
6843 +    
6844 +    printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
6845 +    return -ENODEV;
6846 +  } else {
6847 +    request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
6848 +  }
6849 +
6850 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
6851 +  
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);
6855 +      gpe.pe_irq = 0;
6856 +    } else
6857 +      disable_irq(gpe.pe_irq);
6858 +      enable_irq(gpe.pe_irq);
6859 +  }
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);
6866 +  
6867 +  return 0;
6868 +}
6869 +
6870 +/* ------------------------------------------------------------------------
6871 + * Encapsulate the above functions in the correct operations structure.
6872 + * This is only done when more than one hardware adapter is supported.
6873 + */
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,
6880 +       .udelay     = 80,
6881 +       .mdelay     = 80,
6882 +       .timeout    = HZ,
6883 +};
6884 +
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,
6890 +};
6891 +
6892 +static int __init i2c_pcfepp_init(void) 
6893 +{
6894 +  struct i2c_pcf_epp *pepp = &gpe;
6895 +
6896 +  printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6897 +  if (base == 0)
6898 +    pepp->pe_base = DEFAULT_BASE;
6899 +  else
6900 +    pepp->pe_base = base;
6901 +
6902 +  if (irq == 0)
6903 +    pepp->pe_irq = DEFAULT_IRQ;
6904 +  else if (irq<0) {
6905 +    // switch off irq
6906 +    pepp->pe_irq=0;
6907 +  } else {
6908 +    pepp->pe_irq = irq;
6909 +  }
6910 +  if (clock == 0)
6911 +    pepp->pe_clock = DEFAULT_CLOCK;
6912 +  else
6913 +    pepp->pe_clock = clock;
6914 +
6915 +  if (own == 0)
6916 +    pepp->pe_own = DEFAULT_OWN;
6917 +  else
6918 +    pepp->pe_own = own;
6919 +
6920 +  pcf_epp_data.data = (void *)pepp;
6921 +  init_waitqueue_head(&pcf_wait);
6922 +  if (pcf_epp_init(pepp) == 0) {
6923 +    int ret;
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);
6927 +      return ret;
6928 +    }
6929 +  } else {
6930 +    
6931 +    return -ENODEV;
6932 +  }
6933 +  printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
6934 +  return 0;
6935 +}
6936 +
6937 +static void __exit pcf_epp_exit(void)
6938 +{
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);
6943 +  }
6944 +  release_region(gpe.pe_base , 5);
6945 +}
6946 +
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");
6950 +
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");
6956 +
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
6961 @@ -0,0 +1,78 @@
6962 +/* -------------------------------------------------------------------- */
6963 +/* i2c-pcf8584.h: PCF 8584 global defines                              */
6964 +/* -------------------------------------------------------------------- */
6965 +/*   Copyright (C) 1996 Simon G. Vogl
6966 +                   1999 Hans Berglund
6967 +
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.
6972 +
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.
6977 +
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 +/* --------------------------------------------------------------------        */
6982 +
6983 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
6984 +
6985 +/* $Id$ */
6986 +
6987 +#ifndef _LINUX_I2C_PCF8584_H
6988 +#define _LINUX_I2C_PCF8584_H
6989 +
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
6999 +
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)
7004 +
7005 +/* ----- Status register bits -----------------------------------------        */
7006 +/*#define I2C_PCF_PIN  0x80    as above*/
7007 +
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
7016 +
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
7023 +
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 */
7029 +
7030 +
7031 +/* ----- Access to internal registers according to ES1,ES2 ------------        */
7032 +/* they are mapped to the data port ( a0 = 0 )                                 */
7033 +/* available when ESO == 0 :                                           */
7034 +
7035 +#define I2C_PCF_OWNADR 0
7036 +#define I2C_PCF_INTREG I2C_PCF_ES2
7037 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7038 +
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
7042 @@ -22,5 +22,5 @@
7043     Frodo Looijaard <frodol@dds.nl> */
7044  
7045 -/* $Id$ */
7046 +/* $Id$ */
7047  
7048  #include <linux/kernel.h>
7049 @@ -30,12 +30,8 @@
7050  #include <linux/stddef.h>
7051  #include <linux/parport.h>
7052 -
7053 +#include <linux/slab.h>
7054  #include <linux/i2c.h>
7055  #include <linux/i2c-algo-bit.h>
7056  
7057 -#ifndef __exit
7058 -#define __exit __init
7059 -#endif
7060 -
7061  static int type;
7062  
7063 @@ -131,24 +127,4 @@
7064  }
7065  
7066 -static int bit_lp_reg(struct i2c_client *client)
7067 -{
7068 -       return 0;
7069 -}
7070 -
7071 -static int bit_lp_unreg(struct i2c_client *client)
7072 -{
7073 -       return 0;
7074 -}
7075 -
7076 -static void bit_lp_inc_use(struct i2c_adapter *adap)
7077 -{
7078 -       MOD_INC_USE_COUNT;
7079 -}
7080 -
7081 -static void bit_lp_dec_use(struct i2c_adapter *adap)
7082 -{
7083 -       MOD_DEC_USE_COUNT;
7084 -}
7085 -
7086  /* ------------------------------------------------------------------------
7087   * Encapsulate the above functions in the correct operations structure.
7088 @@ -157,31 +133,26 @@
7089   
7090  static struct i2c_algo_bit_data bit_lp_data = {
7091 -       NULL,
7092 -       bit_lp_setsda,
7093 -       bit_lp_setscl,
7094 -       bit_lp_getsda,
7095 -       bit_lp_getscl,
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,
7101 +       .udelay         = 80,
7102 +       .mdelay         = 80,
7103 +       .timeout        = HZ
7104  }; 
7105  
7106  static struct i2c_algo_bit_data bit_lp_data2 = {
7107 -       NULL,
7108 -       bit_lp_setsda2,
7109 -       bit_lp_setscl2,
7110 -       bit_lp_getsda2,
7111 -       NULL,
7112 -       80, 80, 100,            /*      waits, timeout */
7113 +       .setsda         = bit_lp_setsda2,
7114 +       .setscl         = bit_lp_setscl2,
7115 +       .getsda         = bit_lp_getsda2,
7116 +       .udelay         = 80,
7117 +       .mdelay         = 80,
7118 +       .timeout        = HZ
7119  }; 
7120  
7121  static struct i2c_adapter bit_lp_ops = {
7122 -       "Philips Parallel port adapter",
7123 -       I2C_HW_B_LP,
7124 -       NULL,
7125 -       NULL,
7126 -       bit_lp_inc_use,
7127 -       bit_lp_dec_use,
7128 -       bit_lp_reg,
7129 -
7130 -       bit_lp_unreg,
7131 +       .owner          = THIS_MODULE,
7132 +       .name           = "Philips Parallel port adapter",
7133 +       .id             = I2C_HW_B_LP,
7134  };
7135  
7136 @@ -191,9 +162,9 @@
7137                                           GFP_KERNEL);
7138         if (!adapter) {
7139 -               printk("i2c-philips-par: Unable to malloc.\n");
7140 +               printk(KERN_ERR "i2c-philips-par: Unable to malloc.\n");
7141                 return;
7142         }
7143  
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);
7146  
7147         adapter->pdev = parport_register_device(port, "i2c-philips-par",
7148 @@ -202,5 +173,6 @@
7149                                                 NULL);
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");
7153 +               kfree(adapter);
7154                 return;
7155         }
7156 @@ -211,6 +183,10 @@
7157         adapter->bit_lp_data.data = port;
7158  
7159 +       if (parport_claim_or_block(adapter->pdev) < 0 ) {
7160 +               printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
7161 +               kfree(adapter);
7162 +               return;
7163 +       }
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);
7168 @@ -219,5 +195,5 @@
7169         if (i2c_bit_add_bus(&adapter->adapter) < 0)
7170         {
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);
7174                 kfree(adapter);
7175 @@ -251,5 +227,4 @@
7176  
7177  
7178 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7179  static struct parport_driver i2c_driver = {
7180         "i2c-philips-par",
7181 @@ -258,19 +233,10 @@
7182         NULL
7183  };
7184 -#endif
7185  
7186  int __init i2c_bitlp_init(void)
7187  {
7188 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,4)
7189 -       struct parport *port;
7190 -#endif
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);
7193  
7194 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7195         parport_register_driver(&i2c_driver);
7196 -#else
7197 -       for (port = parport_enumerate(); port; port=port->next)
7198 -               i2c_parport_attach(port);
7199 -#endif
7200         
7201         return 0;
7202 @@ -279,11 +245,5 @@
7203  void __exit i2c_bitlp_exit(void)
7204  {
7205 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7206         parport_unregister_driver(&i2c_driver);
7207 -#else
7208 -       struct parport *port;
7209 -       for (port = parport_enumerate(); port; port=port->next)
7210 -               i2c_parport_detach(port);
7211 -#endif
7212  }
7213  
7214 @@ -296,13 +256,4 @@
7215  MODULE_PARM(type, "i");
7216  
7217 -#ifdef MODULE
7218 -int init_module(void)
7219 -{
7220 -       return i2c_bitlp_init();
7221 -}
7222 -
7223 -void cleanup_module(void)
7224 -{
7225 -       i2c_bitlp_exit();
7226 -}
7227 -#endif
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
7232 @@ -0,0 +1,205 @@
7233 +/* ------------------------------------------------------------------------- */
7234 +/* i2c-pport.c i2c-hw access  for primitive i2c par. port adapter           */
7235 +/* ------------------------------------------------------------------------- */
7236 +/*   Copyright (C) 2001    Daniel Smolik
7237 +
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.
7242 +
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.
7247 +
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 +/* ------------------------------------------------------------------------- */
7252 +
7253 +/*
7254 +       See doc/i2c-pport for instructions on wiring to the
7255 +       parallel port connector.
7256 +
7257 +       Cut & paste :-)  based on Velleman K9000 driver by Simon G. Vogl
7258 +*/
7259 +
7260 +
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>
7271 +
7272 +
7273 +#define DEFAULT_BASE 0x378
7274 +static int base=0;
7275 +static unsigned char PortData = 0;
7276 +
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                    */
7282 +
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      */
7288 +
7289 +/* we will use SDA  - Auto Linefeed(14)   bit 1  POUT   */
7290 +/* we will use SCL - Initialize printer(16)    BUSY bit 2*/
7291 +
7292 +#define  SET_SCL    | 0x04
7293 +#define  CLR_SCL    & 0xFB
7294 +
7295 +
7296 +
7297 +
7298 +#define  SET_SDA    & 0x04
7299 +#define  CLR_SDA    | 0x02
7300 +
7301 +
7302 +/* ----- local functions ----------------------------------------------        */
7303 +
7304 +
7305 +static void bit_pport_setscl(void *data, int state)
7306 +{
7307 +       if (state) {
7308 +               //high
7309 +               PortData = PortData SET_SCL;
7310 +       } else {
7311 +               //low
7312 +               PortData = PortData CLR_SCL; 
7313 +       }
7314 +       outb(PortData, CTRL);
7315 +}
7316 +
7317 +static void bit_pport_setsda(void *data, int state)
7318 +{
7319 +       if (state) {
7320 +               
7321 +               PortData = PortData SET_SDA;
7322 +       } else {
7323 +
7324 +               PortData = PortData CLR_SDA;
7325 +       }
7326 +       outb(PortData, CTRL);
7327 +} 
7328 +
7329 +static int bit_pport_getscl(void *data)
7330 +{
7331 +
7332 +       return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
7333 +}
7334 +
7335 +static int bit_pport_getsda(void *data)
7336 +{
7337 +       return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
7338 +}
7339 +
7340 +static int bit_pport_init(void)
7341 +{
7342 +       if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
7343 +               return -ENODEV; 
7344 +       } else {
7345 +               /* test for PPORT adap.         */
7346 +       
7347 +
7348 +               PortData=inb(base+2);
7349 +               PortData= (PortData SET_SDA) SET_SCL;
7350 +               outb(PortData,base+2);                          
7351 +
7352 +               if (!(inb(base+2) | 0x06)) {    /* SDA and SCL will be high     */
7353 +                       DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
7354 +                       return -ENODEV;
7355 +               } else {
7356 +               
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"));
7364 +                               return -ENODEV;
7365 +                       }
7366 +               }
7367 +               bit_pport_setsda((void*)base,1);
7368 +               bit_pport_setscl((void*)base,1);
7369 +       }
7370 +       return 0;
7371 +}
7372 +
7373 +
7374 +/* ------------------------------------------------------------------------
7375 + * Encapsulate the above functions in the correct operations structure.
7376 + * This is only done when more than one hardware adapter is supported.
7377 + */
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,
7383 +       .udelay         = 40,
7384 +       .mdelay         = 80,
7385 +       .timeout        = HZ
7386 +};
7387 +
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,
7393 +};
7394 +
7395 +int __init i2c_bitpport_init(void)
7396 +{
7397 +       printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7398 +
7399 +       if (base==0) {
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)
7405 +                               return -ENODEV;
7406 +               } else {
7407 +                       return -ENODEV;
7408 +               }
7409 +       } else {
7410 +               bit_pport_data.data=(void*)base;
7411 +               if (bit_pport_init()==0) {
7412 +                       if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7413 +                               return -ENODEV;
7414 +               } else {
7415 +                       return -ENODEV;
7416 +               }
7417 +       }
7418 +       printk("i2c-pport.o: found device at %#x.\n",base);
7419 +       return 0;
7420 +}
7421 +
7422 +static void __exit i2c_bitpport_exit(void)
7423 +{
7424 +       i2c_bit_del_bus(&bit_pport_ops);
7425 +       release_region((base+2),1);
7426 +}
7427 +
7428 +EXPORT_NO_SYMBOLS;
7429 +
7430 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
7431 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
7432 +MODULE_LICENSE("GPL");
7433 +
7434 +MODULE_PARM(base, "i");
7435 +
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
7440 @@ -24,5 +24,4 @@
7441  */
7442  
7443 -#include <linux/version.h>
7444  #include <linux/module.h>
7445  #include <linux/kernel.h>
7446 @@ -31,25 +30,13 @@
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>
7452 -
7453  #include <linux/i2c.h>
7454  #include <linux/i2c-proc.h>
7455 +#include <asm/uaccess.h>
7456  
7457 -#include <linux/init.h>
7458 -
7459 -/* FIXME need i2c versioning */
7460 -#define LM_DATE "20010825"
7461 -#define LM_VERSION "2.6.1"
7462 -
7463 -#ifndef THIS_MODULE
7464 -#define THIS_MODULE NULL
7465 -#endif
7466 -
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,
7475 @@ -61,24 +48,8 @@
7476                                 void **context);
7477  
7478 -int __init sensors_init(void);
7479 -
7480  #define SENSORS_ENTRY_MAX 20
7481  static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
7482  
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) */
7489 -
7490 -static ctl_table sysctl_table[] = {
7491 -       {CTL_DEV, "dev", NULL, 0, 0555},
7492 -       {0},
7493 -       {DEV_SENSORS, "sensors", NULL, 0, 0555},
7494 -       {0},
7495 -       {0, NULL, NULL, 0, 0555},
7496 -       {0}
7497 -};
7498  
7499  static ctl_table i2c_proc_dev_sensors[] = {
7500 @@ -101,5 +72,4 @@
7501  
7502  static struct ctl_table_header *i2c_proc_header;
7503 -static int i2c_initialized;
7504  
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)
7512  {
7513 -       char name_buffer[50];
7514 -       int id;
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;
7519 +
7520 +       if (i2c_is_isa_adapter(adapter)) {
7521                 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
7522 -       else {
7523 -               if ((id = i2c_adapter_id(adapter)) < 0)
7524 -                       return -ENOENT;
7525 +       } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
7526 +               int id = i2c_adapter_id(adapter);
7527 +               if (id < 0)
7528 +                       return ERR_PTR(-ENOENT);
7529                 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
7530 +       } else {        /* dummy adapter, generate prefix */
7531 +               int end, i;
7532 +
7533 +               sprintf(name_buffer, "%s-", prefix);
7534 +               end = strlen(name_buffer);
7535 +
7536 +               for (i = 0; i < 32; i++) {
7537 +                       if (adapter->algo->name[i] == ' ')
7538 +                               break;
7539 +                       name_buffer[end++] = tolower(adapter->algo->name[i]);
7540 +               }
7541 +
7542 +               name_buffer[end] = 0;
7543 +               sprintf(name_buffer + end, "-%04x", addr);
7544         }
7545 -       *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7546 -       if (!*name) {
7547 -               printk (KERN_WARNING "i2c_create_name: not enough memory\n");
7548 -               return -ENOMEM;
7549 -       }
7550 -       strcpy(*name, name_buffer);
7551 -       return 0;
7552 +
7553 +       name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7554 +       if (!name)
7555 +               return ERR_PTR(-ENOMEM);
7556 +       strcpy(name, name_buffer);
7557 +       return name;
7558  }
7559  
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)
7573  {
7574 -       int i, res, len, id;
7575 -       ctl_table *new_table;
7576 -       char *name;
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;
7581 +       const char *name;
7582 +       int id, len = 0;
7583  
7584 -       if ((res = i2c_create_name(&name, prefix, client->adapter,
7585 -                                      client->addr))) return res;
7586 +       name = generate_name(client, prefix);
7587 +       if (IS_ERR(name))
7588 +               return PTR_ERR(name);
7589  
7590 -       for (id = 0; id < SENSORS_ENTRY_MAX; id++)
7591 -               if (!i2c_entries[id]) {
7592 -                       break;
7593 -               }
7594 -       if (id == SENSORS_ENTRY_MAX) {
7595 -               kfree(name);
7596 -               return -ENOMEM;
7597 +       for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
7598 +               if (!i2c_entries[id])
7599 +                       goto free_slot;
7600         }
7601 -       id += 256;
7602  
7603 -       len = 0;
7604 +       goto out_free_name;
7605 +
7606 + free_slot:
7607         while (ctl_template[len].procname)
7608                 len++;
7609 -       len += 7;
7610 -       if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
7611 -               kfree(name);
7612 -               return -ENOMEM;
7613 -       }
7614 -
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;
7624 -
7625 -       if (!(new_header = register_sysctl_table(new_table, 0))) {
7626 -               kfree(new_table);
7627 -               kfree(name);
7628 -               return -ENOMEM;
7629 -       }
7630 -
7631 -       i2c_entries[id - 256] = new_header;
7632 -
7633 -       i2c_clients[id - 256] = client;
7634 -#ifdef DEBUG
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) {
7639 -               printk
7640 -                   ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
7641 -               return id;
7642 -       }
7643 -#endif                         /* DEBUG */
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;
7648 -#else
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)) */
7652 -
7653 -       return id;
7654 +       tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1), 
7655 +                                 GFP_KERNEL);
7656 +       if (!tbl)
7657 +               goto out_free_name;
7658 +       memset(tbl, 0, sizeof(*tbl));
7659 +
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;
7665 +
7666 +       tbl->sensors->ctl_name = id+256;
7667 +       tbl->sensors->procname = name;
7668 +       tbl->sensors->mode = 0555;
7669 +       tbl->sensors->child = leaf;
7670 +
7671 +       tbl->dev->ctl_name = DEV_SENSORS;
7672 +       tbl->dev->procname = "sensors";
7673 +       tbl->dev->mode = 0555;
7674 +       tbl->dev->child = tbl->sensors;
7675 +
7676 +       tbl->root->ctl_name = CTL_DEV;
7677 +       tbl->root->procname = "dev";
7678 +       tbl->root->mode = 0555;
7679 +       tbl->root->child = tbl->dev;
7680 +
7681 +       hdr = register_sysctl_table(tbl->root, 0);
7682 +       if (!hdr)
7683 +               goto out_free_tbl;
7684 +
7685 +       i2c_entries[id] = hdr;
7686 +       i2c_clients[id] = client;
7687 +
7688 +       return (id + 256);      /* XXX(hch) why?? */
7689 +
7690 + out_free_tbl:
7691 +       kfree(tbl);
7692 + out_free_name:
7693 +       kfree(name);
7694 +       return -ENOMEM;
7695  }
7696  
7697  void i2c_deregister_entry(int id)
7698  {
7699 -       ctl_table *table;
7700 -       char *temp;
7701         id -= 256;
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;
7707 -               kfree(temp);
7708 -               kfree(table);
7709 -               i2c_entries[id] = NULL;
7710 -               i2c_clients[id] = NULL;
7711 -       }
7712 -}
7713  
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)
7717 -{
7718 -       if (fill)
7719 -               MOD_INC_USE_COUNT;
7720 -       else
7721 -               MOD_DEC_USE_COUNT;
7722 -}
7723 -
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)
7728 -{
7729 -       int i;
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;
7734  
7735 -#ifdef DEBUG
7736 -       if (!inode) {
7737 -               printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
7738 -               return;
7739 +               unregister_sysctl_table(hdr);
7740 +               kfree(tbl->child->child->procname);
7741 +               kfree(tbl); /* actually the whole anonymous struct */
7742         }
7743 -#endif                         /* def DEBUG */
7744  
7745 -       for (i = 0; i < SENSORS_ENTRY_MAX; i++)
7746 -               if (i2c_clients[i]
7747 -                   && (i2c_inodes[i] == inode->i_ino)) break;
7748 -#ifdef DEBUG
7749 -       if (i == SENSORS_ENTRY_MAX) {
7750 -               printk
7751 -                   ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
7752 -                    inode->i_ino);
7753 -               return;
7754 -       }
7755 -#endif                         /* def DEBUG */
7756 -       client = i2c_clients[i];
7757 -       if (fill)
7758 -               client->driver->inc_use(client);
7759 -       else
7760 -               client->driver->dec_use(client);
7761 +       i2c_entries[id] = NULL;
7762 +       i2c_clients[id] = NULL;
7763  }
7764  
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)
7768  {
7769 @@ -309,5 +241,5 @@
7770  }
7771  
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)
7776 @@ -471,5 +403,5 @@
7777              hidden bugs in it, even leading to crashes and things!
7778  */
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)
7782  {
7783 @@ -572,5 +504,5 @@
7784  }
7785  
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)
7789  {
7790 @@ -661,4 +593,5 @@
7791  
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)))
7796 @@ -685,5 +618,5 @@
7797  #ifdef DEBUG
7798                                         printk
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",
7801                                              adapter_id, addr);
7802  #endif
7803 @@ -715,5 +648,5 @@
7804  #ifdef DEBUG
7805                                 printk
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);
7809  #endif
7810 @@ -735,5 +668,5 @@
7811  #ifdef DEBUG
7812                                 printk
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);
7816  #endif
7817 @@ -754,5 +687,5 @@
7818  #ifdef DEBUG
7819                                         printk
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,
7823                                              addr);
7824 @@ -776,5 +709,5 @@
7825  #ifdef DEBUG
7826                                         printk
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);
7830  #endif
7831 @@ -790,5 +723,5 @@
7832  #ifdef DEBUG
7833                                         printk
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);
7837  #endif
7838 @@ -806,5 +739,5 @@
7839  #ifdef DEBUG
7840                                         printk
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);
7844  #endif
7845 @@ -823,5 +756,5 @@
7846  #ifdef DEBUG
7847                                 printk
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);
7851  #endif
7852 @@ -842,5 +775,5 @@
7853  #ifdef DEBUG
7854                                 printk
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);
7858  #endif
7859 @@ -861,28 +794,27 @@
7860  }
7861  
7862 -int __init sensors_init(void)
7863 +static int __init i2c_proc_init(void)
7864  {
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);
7868         if (!
7869             (i2c_proc_header =
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");
7874 +               return -EPERM;
7875 +       }
7876         i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
7877 -#else
7878 -       i2c_proc_header->ctl_table->child->de->fill_inode =
7879 -           &i2c_fill_inode;
7880 -#endif                 /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */
7881 -       i2c_initialized++;
7882         return 0;
7883  }
7884  
7885 +static void __exit i2c_proc_exit(void)
7886 +{
7887 +       unregister_sysctl_table(i2c_proc_header);
7888 +}
7889 +
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);
7896 -
7897 -#ifdef MODULE
7898 +EXPORT_SYMBOL(i2c_detect);
7899  
7900  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
7901 @@ -890,21 +822,4 @@
7902  MODULE_LICENSE("GPL");
7903  
7904 -int i2c_cleanup(void)
7905 -{
7906 -       if (i2c_initialized >= 1) {
7907 -               unregister_sysctl_table(i2c_proc_header);
7908 -               i2c_initialized--;
7909 -       }
7910 -       return 0;
7911 -}
7912 -
7913 -int init_module(void)
7914 -{
7915 -       return sensors_init();
7916 -}
7917 -
7918 -int cleanup_module(void)
7919 -{
7920 -       return i2c_cleanup();
7921 -}
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
7927 @@ -1,5 +1,6 @@
7928  /*
7929 -    sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7930 -                monitoring
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>
7935  
7936 @@ -19,12 +20,7 @@
7937  */
7938  
7939 -#ifndef SENSORS_SENSORS_H
7940 -#define SENSORS_SENSORS_H
7941 +#ifndef _LINUX_I2C_PROC_H
7942 +#define _LINUX_I2C_PROC_H
7943  
7944 -#ifdef __KERNEL__
7945 -
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>
7950  
7951 @@ -74,6 +70,5 @@
7952  extern int i2c_register_entry(struct i2c_client *client,
7953                                   const char *prefix,
7954 -                                 ctl_table * ctl_template,
7955 -                                 struct module *controlling_mod);
7956 +                                 ctl_table * ctl_template);
7957  
7958  extern void i2c_deregister_entry(int id);
7959 @@ -348,4 +343,29 @@
7960    SENSORS_INSMOD
7961  
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}, \
7984 +                                                 {NULL}}; \
7985 +  SENSORS_INSMOD
7986 +
7987  typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
7988                                     int addr, unsigned short flags,
7989 @@ -363,5 +383,5 @@
7990  /* This macro is used to scale user-input to sensible values in almost all
7991     chip drivers. */
7992 -extern inline int SENSORS_LIMIT(long value, long low, long high)
7993 +static inline int SENSORS_LIMIT(long value, long low, long high)
7994  {
7995         if (value < low)
7996 @@ -373,6 +393,4 @@
7997  }
7998  
7999 -#endif                         /* def __KERNEL__ */
8000 -
8001  
8002  /* The maximum length of the prefix */
8003 @@ -393,4 +411,4 @@
8004  };
8005  
8006 -#endif                         /* def SENSORS_SENSORS_H */
8007 +#endif                         /* def _LINUX_I2C_PROC_H */
8008  
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
8011 @@ -0,0 +1,103 @@
8012 +/*
8013 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
8014 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
8015 + *
8016 + * moved into proper i2c interface;
8017 + * Brad Parker (brad@heeltoe.com)
8018 + *
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.
8023 + */
8024 +
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>
8035 +
8036 +
8037 +static void
8038 +rpx_iic_init(struct i2c_algo_8xx_data *data)
8039 +{
8040 +       volatile cpm8xx_t *cp;
8041 +       volatile immap_t *immap;
8042 +
8043 +       cp = cpmp;      /* Get pointer to Communication Processor */
8044 +       immap = (immap_t *)IMAP_ADDR;   /* and to internal registers */
8045 +
8046 +       data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
8047 +
8048 +       /* Check for and use a microcode relocation patch.
8049 +       */
8050 +       if ((data->reloc = data->iip->iic_rpbase))
8051 +               data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
8052 +               
8053 +       data->i2c = (i2c8xx_t *)&(immap->im_i2c);
8054 +       data->cp = cp;
8055 +
8056 +       /* Initialize Port B IIC pins.
8057 +       */
8058 +       cp->cp_pbpar |= 0x00000030;
8059 +       cp->cp_pbdir |= 0x00000030;
8060 +       cp->cp_pbodr |= 0x00000030;
8061 +
8062 +       /* Allocate space for two transmit and two receive buffer
8063 +        * descriptors in the DP ram.
8064 +        */
8065 +       data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
8066 +
8067 +       /* ptr to i2c area */
8068 +       data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
8069 +}
8070 +
8071 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
8072 +{
8073 +       /* install interrupt handler */
8074 +       cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
8075 +
8076 +       return 0;
8077 +}
8078 +
8079 +static struct i2c_algo_8xx_data rpx_data = {
8080 +       .setisr = rpx_install_isr
8081 +};
8082 +
8083 +static struct i2c_adapter rpx_ops = {
8084 +       .owner          = THIS_MODULE,
8085 +       .name           = "m8xx",
8086 +       .id             = I2C_HW_MPC8XX_EPON,
8087 +       .algo_data      = &rpx_data,
8088 +};
8089 +
8090 +int __init i2c_rpx_init(void)
8091 +{
8092 +       printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8093 +
8094 +       /* reset hardware to sane state */
8095 +       rpx_iic_init(&rpx_data);
8096 +
8097 +       if (i2c_8xx_add_bus(&rpx_ops) < 0) {
8098 +               printk("i2c-rpx: Unable to register with I2C\n");
8099 +               return -ENODEV;
8100 +       }
8101 +
8102 +       return 0;
8103 +}
8104 +
8105 +void __exit i2c_rpx_exit(void)
8106 +{
8107 +       i2c_8xx_del_bus(&rpx_ops);
8108 +}
8109 +
8110 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
8111 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
8112 +
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
8117 @@ -1,114 +0,0 @@
8118 -/*
8119 - * Copyright (C) 2001,2002,2003 Broadcom Corporation
8120 - *
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.
8125 - *
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.
8130 - * 
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.
8134 - */
8135 -
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>
8141 -
8142 -#include <asm/sibyte/sb1250_regs.h>
8143 -#include <asm/sibyte/sb1250_smbus.h>
8144 -
8145 -#include <linux/i2c.h>
8146 -#include <linux/i2c-algo-sibyte.h>
8147 -
8148 -static int sibyte_reg(struct i2c_client *client)
8149 -{
8150 -       return 0;
8151 -}
8152 -
8153 -static int sibyte_unreg(struct i2c_client *client)
8154 -{
8155 -       return 0;
8156 -}
8157 -
8158 -static void sibyte_inc_use(struct i2c_adapter *adap)
8159 -{
8160 -#ifdef MODULE
8161 -       MOD_INC_USE_COUNT;
8162 -#endif
8163 -}
8164 -
8165 -static void sibyte_dec_use(struct i2c_adapter *adap)
8166 -{
8167 -#ifdef MODULE
8168 -       MOD_DEC_USE_COUNT;
8169 -#endif
8170 -}
8171 -
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)) }
8175 -};
8176 -
8177 -static struct i2c_adapter sibyte_board_adapter[2] = {
8178 -        {
8179 -                name:              "SiByte SMBus 0",
8180 -                id:                I2C_HW_SIBYTE,
8181 -                algo:              NULL,
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,
8187 -               client_count:      0
8188 -        } , 
8189 -        {
8190 -                name:              "SiByte SMBus 1",
8191 -                id:                I2C_HW_SIBYTE,
8192 -                algo:              NULL,
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,
8198 -               client_count:      0
8199 -        }
8200 -};
8201 -
8202 -int __init i2c_sibyte_init(void)
8203 -{
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)
8206 -                return -ENODEV;
8207 -        if (i2c_sibyte_add_bus(&sibyte_board_adapter[1], K_SMB_FREQ_400KHZ) < 0)
8208 -                return -ENODEV;
8209 -       return 0;
8210 -}
8211 -
8212 -
8213 -EXPORT_NO_SYMBOLS;
8214 -
8215 -#ifdef MODULE
8216 -MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
8217 -MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards");
8218 -MODULE_LICENSE("GPL");
8219 -
8220 -int init_module(void)
8221 -{
8222 -       return i2c_sibyte_init();
8223 -}
8224 -
8225 -void cleanup_module(void)
8226 -{
8227 -       i2c_sibyte_del_bus(&sibyte_board_adapter[0]);
8228 -       i2c_sibyte_del_bus(&sibyte_board_adapter[1]);
8229 -}
8230 -
8231 -#endif
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
8234 @@ -19,5 +19,5 @@
8235  /* ------------------------------------------------------------------------- */
8236  
8237 -/* $Id$ */
8238 +/* $Id$ */
8239  
8240  #include <linux/kernel.h>
8241 @@ -25,10 +25,10 @@
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>
8247 -
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 */
8254  
8255  /* ----- global defines -----------------------------------------------        */
8256 @@ -91,47 +91,13 @@
8257  static int bit_velle_init(void)
8258  {
8259 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
8260 -               DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
8261 -                    base));
8262 +       if (!request_region(base, (base == 0x3bc) ? 3 : 8, 
8263 +                       "i2c (Vellemann adapter)"))
8264                 return -ENODEV;
8265 -       } else {
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);
8270 -       }
8271 -       return 0;
8272 -}
8273 -
8274 -static void __exit bit_velle_exit(void)
8275 -{      
8276 -       release_region( base , (base == 0x3bc)? 3 : 8 );
8277 -}
8278 -
8279 -
8280 -static int bit_velle_reg(struct i2c_client *client)
8281 -{
8282 -       return 0;
8283 -}
8284  
8285 -static int bit_velle_unreg(struct i2c_client *client)
8286 -{
8287 +       bit_velle_setsda((void*)base,1);
8288 +       bit_velle_setscl((void*)base,1);
8289         return 0;
8290  }
8291  
8292 -static void bit_velle_inc_use(struct i2c_adapter *adap)
8293 -{
8294 -#ifdef MODULE
8295 -       MOD_INC_USE_COUNT;
8296 -#endif
8297 -}
8298 -
8299 -static void bit_velle_dec_use(struct i2c_adapter *adap)
8300 -{
8301 -#ifdef MODULE
8302 -       MOD_DEC_USE_COUNT;
8303 -#endif
8304 -}
8305 -
8306  /* ------------------------------------------------------------------------
8307   * Encapsulate the above functions in the correct operations structure.
8308 @@ -140,26 +106,23 @@
8309  
8310  static struct i2c_algo_bit_data bit_velle_data = {
8311 -       NULL,
8312 -       bit_velle_setsda,
8313 -       bit_velle_setscl,
8314 -       bit_velle_getsda,
8315 -       bit_velle_getscl,
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,
8321 +       .udelay         = 10,
8322 +       .mdelay         = 10,
8323 +       .timeout        = HZ
8324  };
8325  
8326  static struct i2c_adapter bit_velle_ops = {
8327 -       "Velleman K8000",
8328 -       I2C_HW_B_VELLE,
8329 -       NULL,
8330 -       &bit_velle_data,
8331 -       bit_velle_inc_use,
8332 -       bit_velle_dec_use,
8333 -       bit_velle_reg,
8334 -       bit_velle_unreg,
8335 +       .owner          = THIS_MODULE,
8336 +       .name           = "Velleman K8000",
8337 +       .id             = I2C_HW_B_VELLE,
8338 +       .algo_data      = &bit_velle_data,
8339  };
8340  
8341 -int __init  i2c_bitvelle_init(void)
8342 +static int __init i2c_bitvelle_init(void)
8343  {
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);
8346         if (base==0) {
8347                 /* probe some values */
8348 @@ -181,11 +144,14 @@
8349                 }
8350         }
8351 -       printk("i2c-velleman.o: found device at %#x.\n",base);
8352 +       printk(KERN_DEBUG "i2c-velleman.o: found device at %#x.\n",base);
8353         return 0;
8354  }
8355  
8356 -EXPORT_NO_SYMBOLS;
8357 +static void __exit i2c_bitvelle_exit(void)
8358 +{      
8359 +       i2c_bit_del_bus(&bit_velle_ops);
8360 +       release_region(base, (base == 0x3bc) ? 3 : 8);
8361 +}
8362  
8363 -#ifdef MODULE
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");
8368  
8369 -int init_module(void) 
8370 -{
8371 -       return i2c_bitvelle_init();
8372 -}
8373 -
8374 -void cleanup_module(void) 
8375 -{
8376 -       i2c_bit_del_bus(&bit_velle_ops);
8377 -       bit_velle_exit();
8378 -}
8379 -
8380 -#endif
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
8385 @@ -24,44 +24,31 @@
8386     Frodo Looijaard <frodol@dds.nl> */
8387  
8388 -/* $Id$ */
8389 +/* $Id$ */
8390  
8391 -#ifndef I2C_H
8392 -#define I2C_H
8393 +#ifndef _LINUX_I2C_H
8394 +#define _LINUX_I2C_H
8395  
8396 -#define I2C_DATE "20010830"
8397 -#define I2C_VERSION "2.6.1"
8398 +#define I2C_DATE "20030714"
8399 +#define I2C_VERSION "2.8.0"
8400  
8401 -#include <linux/i2c-id.h>      /* id values of adapters et. al.        */
8402 +#include <linux/module.h>
8403  #include <linux/types.h>
8404 -
8405 -
8406 -struct i2c_msg;
8407 -
8408 -
8409 -#ifdef __KERNEL__
8410 -
8411 -/* --- Includes and compatibility declarations ------------------------ */
8412 -
8413 -#include <linux/version.h>
8414 -#ifndef KERNEL_VERSION
8415 -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
8416 -#endif
8417 -
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>
8422 -#else
8423  #include <asm/semaphore.h>
8424 +#include <linux/i2c-id.h>
8425 +
8426 +#include <linux/version.h>
8427 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
8428 +#define MODULE_LICENSE(x)
8429  #endif
8430 -#include <linux/config.h>
8431  
8432  /* --- General options ------------------------------------------------        */
8433  
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
8440  
8441 +struct i2c_msg;
8442  struct i2c_algorithm;
8443  struct i2c_adapter;
8444 @@ -71,5 +58,4 @@
8445  union i2c_smbus_data;
8446  
8447 -
8448  /*
8449   * The master routines are the ones normally used to transmit data to devices
8450 @@ -124,4 +110,6 @@
8451                                        u8 command, u8 length,
8452                                        u8 *values);
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,
8457 @@ -136,4 +124,5 @@
8458  
8459  struct i2c_driver {
8460 +       struct module *owner;
8461         char name[32];
8462         int id;
8463 @@ -159,16 +148,4 @@
8464          */
8465         int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
8466 -       
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.
8475 -        */
8476 -       void (*inc_use)(struct i2c_client *client);
8477 -       void (*dec_use)(struct i2c_client *client);
8478  };
8479  
8480 @@ -203,4 +180,5 @@
8481   */
8482  struct i2c_algorithm {
8483 +       struct module *owner;                   /* future use --km      */
8484         char name[32];                          /* textual description  */
8485         unsigned int id;
8486 @@ -227,8 +205,4 @@
8487  };
8488  
8489 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8490 -struct proc_dir_entry;
8491 -#endif
8492 -
8493  /*
8494   * i2c_adapter is the structure used to identify a physical i2c bus along
8495 @@ -236,4 +210,5 @@
8496   */
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,           */
8501 @@ -242,8 +217,4 @@
8502         void *algo_data;
8503  
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 *);
8507 -
8508         /* --- administration stuff. */
8509         int (*client_register)(struct i2c_client *);
8510 @@ -256,9 +227,9 @@
8511  
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                */
8517  
8518         struct i2c_client *clients[I2C_CLIENT_MAX];
8519 -       int client_count;
8520  
8521         int timeout;
8522 @@ -268,7 +239,4 @@
8523         /* No need to set this when you initialize the adapter          */
8524         int inode;
8525 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8526 -       struct proc_dir_entry *proc_entry;
8527 -#endif
8528  #endif /* def CONFIG_PROC_FS */
8529  };
8530 @@ -282,4 +250,7 @@
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 */
8536  
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 *);
8540  
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 *);
8546 -
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);
8551  
8552 +static inline int i2c_client_command(struct i2c_client *client,
8553 +                                    unsigned int cmd, void *arg)
8554 +{
8555 +       if (client->driver && client->driver->command)
8556 +               return client->driver->command(client, cmd, arg);
8557 +       else
8558 +               return -EINVAL;
8559 +}
8560 +
8561  /* An ioctl like call to set div. parameters of the adapter.
8562   */
8563 @@ -376,6 +350,4 @@
8564  extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
8565  
8566 -#endif /* __KERNEL__ */
8567 -
8568  /*
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                  */
8577 +       int err;
8578 +       short done;
8579  };
8580  
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 */
8605  
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
8616 +
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
8623  
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
8632  
8633  /* 
8634   * Data for SMBus Messages 
8635   */
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 {
8639         __u8 byte;
8640         __u16 word;
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 */
8645  };
8646  
8647 @@ -450,4 +455,9 @@
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 */
8655  
8656  
8657 @@ -475,4 +485,5 @@
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                   */
8661  #if 0
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          */
8665  
8666 -#ifdef __KERNEL__
8667 -
8668 -#  ifndef NULL
8669 -#    define NULL ( (void *) 0 )
8670 -#  endif
8671 -
8672 -#  ifndef ENODEV
8673 -#    include <asm/errno.h>
8674 -#  endif
8675 -
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)
8680  
8681 -#endif /* def __KERNEL__ */
8682 -#endif /* I2C_H */
8683 +/* Tiny delay function used by the i2c bus drivers */
8684 +static inline void i2c_delay(signed long timeout)
8685 +{
8686 +       set_current_state(TASK_INTERRUPTIBLE);
8687 +       schedule_timeout(timeout);
8688 +}
8689 +
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>.
8695  
8696 +UltraSPARC-III bootbus i2c controller driver
8697 +CONFIG_BBC_I2C
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.
8704 +
8705 +ITE I2C Algorithm
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.
8710 +
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.
8715 +
8716 +ITE I2C Adapter
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.
8721 +
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.
8726 +
8727 +SiByte I2C Algorithm
8728 +CONFIG_I2C_ALGO_SIBYTE
8729 +  Supports the SiByte SOC on-chip I2C interfaces (2 channels).
8730 +
8731 +MAX1617 Temperature Sensor
8732 +CONFIG_I2C_MAX1617
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.
8736 +
8737  I2C support
8738  CONFIG_I2C
8739 @@ -18133,13 +18174,4 @@
8740    The module will be called i2c-core.o.
8741  
8742 -UltraSPARC-III bootbus i2c controller driver
8743 -CONFIG_BBC_I2C
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.
8750 -
8751  I2C bit-banging interfaces
8752  CONFIG_I2C_ALGOBIT
8753 @@ -18186,4 +18218,14 @@
8754    The module will be called i2c-velleman.o.
8755  
8756 +Basic I2C on Parallel Port adapter
8757 +CONFIG_I2C_PPORT
8758 +  This supports directly connecting I2C devices to the parallel port.
8759 +  See <file:Documentation/i2c/i2c-pport> for more information.
8760 +
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.
8765 +
8766  I2C PCF 8584 interfaces
8767  CONFIG_I2C_ALGOPCF
8768 @@ -18207,35 +18249,57 @@
8769    The module will be called i2c-elektor.o.
8770  
8771 -ITE I2C Algorithm
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
8777 +CONFIG_I2C_PCFEPP
8778 +  This supports the PCF8584 connected to the parallel port.
8779  
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.
8787  
8788 -ITE I2C Adapter
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
8794 +CONFIG_I2C_ALGO8XX
8795 +  This is the algorithm that allows you to use Motorola 8xx I2C adapters.
8796  
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.
8803  
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
8808 +CONFIG_I2C_RPXLITE
8809 +  This supports the Motorola 8xx I2C device.
8810  
8811 -MAX1617 Temperature Sensor
8812 -CONFIG_I2C_MAX1617
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.
8820 +
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.
8824 +
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.
8829 +
8830 +IBM 405 I2C interface
8831 +CONFIG_I2C_IBM_OCP_ADAP
8832 +  This supports the IBM 405 I2C device.
8833 +
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.
8838 +
8839 +StrongARM SA-1110 interface
8840 +CONFIG_I2C_FRODO
8841 +  This supports the StrongARM SA-1110 Development Board.
8842 +
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.
8847  
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 @@
8852  }
8853  
8854  
8855 -static void iic_ite_inc_use(struct i2c_adapter *adap)
8856 -{
8857 -#ifdef MODULE
8858 -       MOD_INC_USE_COUNT;
8859 -#endif
8860 -}
8861 -
8862 -
8863 -static void iic_ite_dec_use(struct i2c_adapter *adap)
8864 -{
8865 -#ifdef MODULE
8866 -       MOD_DEC_USE_COUNT;
8867 -#endif
8868 -}
8869 -
8870 -
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 @@
8875  };
8876  
8877  static struct i2c_adapter iic_ite_ops = {
8878 -       "ITE IIC adapter",
8879 -       I2C_HW_I_IIC,
8880 -       NULL,
8881 -       &iic_ite_data,
8882 -       iic_ite_inc_use,
8883 -       iic_ite_dec_use,
8884 -       iic_ite_reg,
8885 -       iic_ite_unreg,
8886 +       .owner             = THIS_MODULE,
8887 +       .name              = "ITE IIC adapter",
8888 +       .id                = I2C_HW_I_IIC,
8889 +       .algo              = NULL,
8890 +       .algo_data         = &iic_ite_data,
8891 +       .client_register   = iic_ite_reg,
8892 +       .client_unregieter = iic_ite_unreg,
8893  };
8894  
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: ------------------------------------- */
8900  
8901  static struct i2c_algorithm iic_algo = {
8902 -       "ITE IIC algorithm",
8903 -       I2C_ALGO_IIC,
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,
8916  };
8917  
8918  
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;
8923  }
8924  
8925 -static void
8926 -keywest_inc(struct i2c_adapter *adapter)
8927 -{
8928 -       MOD_INC_USE_COUNT;
8929 -}
8930 -
8931 -static void
8932 -keywest_dec(struct i2c_adapter *adapter)
8933 -{
8934 -       MOD_DEC_USE_COUNT;
8935 -}
8936 -
8937  /* For now, we only handle combined mode (smbus) */
8938  static struct i2c_algorithm keywest_algorithm = {
8939 +       owner:          THIS_MODULE,
8940         name:           "Keywest i2c",
8941         id:             I2C_ALGO_SMBUS,
8942         smbus_xfer:     keywest_smbus_xfer,
8943 @@ -527,14 +516,13 @@
8944                 struct keywest_chan* chan = &iface->channels[i];
8945                 u8 addr;
8946                 
8947 +               chan->adapter.owner = THIS_MODULE;
8948                 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
8949                 chan->iface = iface;
8950                 chan->chan_no = i;
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 @@
8962         return 0;
8963  }
8964  
8965 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
8966 -{
8967 -       MOD_INC_USE_COUNT;
8968 -}
8969 -
8970 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
8971 -{
8972 -       MOD_DEC_USE_COUNT;
8973 -}
8974 -
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;
8990  
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
8993 @@ -76,16 +76,6 @@
8994         return 0;
8995  }
8996  
8997 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
8998 -{
8999 -       MOD_INC_USE_COUNT;
9000 -}
9001 -
9002 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
9003 -{
9004 -       MOD_DEC_USE_COUNT;
9005 -}
9006 -
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 @@
9011  };
9012  
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,
9022  };
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
9026 @@ -139,6 +139,7 @@
9027  }; 
9028  
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
9037 @@ -40,7 +40,7 @@
9038  
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
9046 @@ -48,11 +48,10 @@
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
9059 @@ -81,8 +80,8 @@
9060  
9061  fastdep:
9062  
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)
9067  
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
9073 @@ -257,6 +257,7 @@
9074  /* ----------------------------------------------------------------------- */
9075  
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
9084 @@ -36,28 +36,11 @@
9085  static struct i2c_driver *drivers[I2C_DRIVER_MAX];
9086  static int bus_count = 0, driver_count = 0;
9087  
9088 -#ifdef CONFIG_VIDEO_BUZ
9089 -extern int saa7111_init(void);
9090 -extern int saa7185_init(void);
9091 -#endif
9092 -#ifdef CONFIG_VIDEO_LML33
9093 -extern int bt819_init(void);
9094 -extern int bt856_init(void);
9095 -#endif
9096 -
9097  int i2c_init(void)
9098  {
9099         printk(KERN_INFO "i2c: initialized%s\n",
9100                 scan ? " (i2c bus scan enabled)" : "");
9101         /* anything to do here ? */
9102 -#ifdef CONFIG_VIDEO_BUZ
9103 -       saa7111_init();
9104 -       saa7185_init();
9105 -#endif
9106 -#ifdef CONFIG_VIDEO_LML33
9107 -       bt819_init();
9108 -       bt856_init();
9109 -#endif
9110         return 0;
9111  }
9112  
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);
9118  
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 @@
9128  
9129  static struct i2c_driver i2c_driver_videotext = 
9130  {
9131 -       IF_NAME,                /* name */
9132 -       I2C_DRIVERID_SAA5249, /* in i2c.h */
9133 -       I2C_DF_NOTIFY,
9134 -       saa5249_probe,
9135 -       saa5249_detach,
9136 -       saa5249_command
9137 +       .owner          = THIS_MODULE,
9138 +       .name           = IF_NAME,
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
9144  };
9145  
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
9150 @@ -25,9 +25,6 @@
9151  #include <linux/types.h>
9152  #include <linux/wait.h>
9153  
9154 -#include <linux/i2c.h>
9155 -#include <linux/videodev.h>
9156 -
9157  #ifndef O_NONCAP  
9158  #define O_NONCAP       O_TRUNC
9159  #endif
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 @@
9164  
9165  struct i2c_driver i2c_driver_saa7114h =
9166  {
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
9178  };
9179  
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
9184 @@ -515,6 +515,7 @@
9185  }
9186  
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
9195 @@ -386,6 +386,7 @@
9196  
9197  
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
9206 @@ -438,6 +438,7 @@
9207  /* ----------------------------------------------------------------------- */
9208  
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 
9219  i2c_driver_tuner = 
9220  {
9221 -       "sab3036",              /* name       */
9222 -       I2C_DRIVERID_SAB3036,   /* ID         */
9223 -        I2C_DF_NOTIFY,
9224 -       tuner_probe,
9225 -       tuner_detach,
9226 -       tuner_command
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
9234  };
9235  
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
9240 @@ -963,6 +963,7 @@
9241  /* ----------------------------------------------------------------------- */
9242  
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 @@
9252  
9253  
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
9262 @@ -24,7 +24,6 @@
9263  #include <linux/init.h>
9264  #include <linux/kernel.h>
9265  #include <linux/sched.h>
9266 -#include <linux/i2c.h>
9267  
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
9273 @@ -52,14 +52,13 @@
9274  };
9275  
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,
9282 -       command:        NULL,
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,
9291 +       .command        = NULL
9292    };
9293  
9294  
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
9298 @@ -90,14 +90,13 @@
9299  };
9300  
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,
9307 -       command:        NULL,
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,
9316 +       .command        = NULL
9317  };
9318  
9319  int
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
9323 @@ -87,19 +87,10 @@
9324         return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
9325  }
9326  
9327 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
9328 -       MOD_INC_USE_COUNT;
9329 -}
9330 -
9331 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
9332 -       MOD_DEC_USE_COUNT;
9333 -}
9334 -
9335  static struct i2c_adapter matrox_i2c_adapter_template =
9336  {
9337 +       .owner =        THIS_MODULE,
9338         .id =           I2C_HW_B_G400,
9339 -       .inc_use =      matroxfb_dh_inc_use,
9340 -       .dec_use =      matroxfb_dh_dec_use,
9341  };
9342  
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 };
9349  I2C_CLIENT_INSMOD;
9350  
9351 -static void maven_inc_use(struct i2c_client* clnt) {
9352 -       MOD_INC_USE_COUNT;
9353 -}
9354 -
9355 -static void maven_dec_use(struct i2c_client* clnt) {
9356 -       MOD_DEC_USE_COUNT;
9357 -}
9358 -
9359  static struct i2c_driver maven_driver;
9360  
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;
9364  
9365  static struct i2c_driver maven_driver={
9366 -       "maven",
9367 -       I2C_DRIVERID_MGATVO,
9368 -       I2C_DF_NOTIFY,
9369 -       maven_attach_adapter,
9370 -       maven_detach_client,
9371 -       maven_command,
9372 -       maven_inc_use,
9373 -       maven_dec_use
9374 +       .owner          = THIS_MODULE,
9375 +       .name           = "maven",
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
9381  };
9382  
9383  /* ************************** */
This page took 0.81348 seconds and 3 git commands to generate.