]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.23-i2c-2.8.1.patch
- added description of djurban's branch
[packages/kernel.git] / linux-2.4.23-i2c-2.8.1.patch
1 diff -ruN linux-2.4.23-rc1-orig/drivers/acorn/char/i2c.c linux-2.4.23-rc1-i2c/drivers/acorn/char/i2c.c
2 --- linux-2.4.23-rc1-orig/drivers/acorn/char/i2c.c      Wed Aug 27 18:11:45 2003
3 +++ linux-2.4.23-rc1-i2c/drivers/acorn/char/i2c.c       Sat Nov 15 17:36:24 2003
4 @@ -264,13 +264,13 @@
5  }
6  
7  static struct i2c_algo_bit_data ioc_data = {
8 -       setsda:         ioc_setsda,
9 -       setscl:         ioc_setscl,
10 -       getsda:         ioc_getsda,
11 -       getscl:         ioc_getscl,
12 -       udelay:          80,
13 -       mdelay:          80,
14 -       timeout:        100
15 +       .setsda         = ioc_setsda,
16 +       .setscl         = ioc_setscl,
17 +       .getsda         = ioc_getsda,
18 +       .getscl         = ioc_getscl,
19 +       .udelay         = 80,
20 +       .mdelay         = 80,
21 +       .timeout        = 100,
22  };
23  
24  static int ioc_client_reg(struct i2c_client *client)
25 @@ -303,11 +303,12 @@
26  }
27  
28  static struct i2c_adapter ioc_ops = {
29 -       name:                   "IOC/IOMD",
30 -       id:                     I2C_HW_B_IOC,
31 -       algo_data:              &ioc_data,
32 -       client_register:        ioc_client_reg,
33 -       client_unregister:      ioc_client_unreg
34 +       .owner                  = THIS_MODULE,
35 +       .name                   = "IOC/IOMD",
36 +       .id                     = I2C_HW_B_IOC,
37 +       .algo_data              = &ioc_data,
38 +       .client_register        = ioc_client_reg,
39 +       .client_unregister      = ioc_client_unreg,
40  };
41  
42  static int __init i2c_ioc_init(void)
43 diff -ruN linux-2.4.23-rc1-orig/drivers/acorn/char/pcf8583.c linux-2.4.23-rc1-i2c/drivers/acorn/char/pcf8583.c
44 --- linux-2.4.23-rc1-orig/drivers/acorn/char/pcf8583.c  Tue Jul 15 12:23:25 2003
45 +++ linux-2.4.23-rc1-i2c/drivers/acorn/char/pcf8583.c   Sat Nov 15 17:36:24 2003
46 @@ -23,13 +23,13 @@
47  static unsigned short normal_addr[] = { 0x50, I2C_CLIENT_END };
48  
49  static struct i2c_client_address_data addr_data = {
50 -       normal_i2c:             normal_addr,
51 -       normal_i2c_range:       ignore,
52 -       probe:                  ignore,
53 -       probe_range:            ignore,
54 -       ignore:                 ignore,
55 -       ignore_range:           ignore,
56 -       force:                  ignore,
57 +       .normal_i2c             = normal_addr,
58 +       .normal_i2c_range       = ignore,
59 +       .probe                  = ignore,
60 +       .probe_range            = ignore,
61 +       .ignore                 = ignore,
62 +       .ignore_range           = ignore,
63 +       .force                  = ignore,
64  };
65  
66  #define DAT(x) ((unsigned int)(x->data))
67 @@ -50,6 +50,7 @@
68                 return -ENOMEM;
69  
70         strcpy(c->name, "PCF8583");
71 +       c->name         = THIS_MODULE;
72         c->id           = pcf8583_driver.id;
73         c->flags        = 0;
74         c->addr         = addr;
75 @@ -225,12 +226,13 @@
76  }
77  
78  static struct i2c_driver pcf8583_driver = {
79 -       name:           "PCF8583",
80 -       id:             I2C_DRIVERID_PCF8583,
81 -       flags:          I2C_DF_NOTIFY,
82 -       attach_adapter: pcf8583_probe,
83 -       detach_client:  pcf8583_detach,
84 -       command:        pcf8583_command
85 +       .owner          = THIS_MODULE,
86 +       .name           = "PCF8583",
87 +       .id             = I2C_DRIVERID_PCF8583,
88 +       .flags          = I2C_DF_NOTIFY,
89 +       .attach_adapter = pcf8583_probe,
90 +       .detach_client  = pcf8583_detach,
91 +       .command        = pcf8583_command,
92  };
93  
94  static __init int pcf8583_init(void)
95 --- linux-2.4.23-rc1-orig/drivers/i2c/Config.in Wed Aug 27 18:11:46 2003
96 +++ linux-2.4.23-rc1-i2c/drivers/i2c/Config.in  Sat Nov 15 20:36:59 2003
97 @@ -13,17 +13,22 @@
98        dep_tristate '  Philips style parallel port adapter' CONFIG_I2C_PHILIPSPAR $CONFIG_I2C_ALGOBIT $CONFIG_PARPORT
99        dep_tristate '  ELV adapter' CONFIG_I2C_ELV $CONFIG_I2C_ALGOBIT
100        dep_tristate '  Velleman K9000 adapter' CONFIG_I2C_VELLEMAN $CONFIG_I2C_ALGOBIT
101 -      dep_tristate '  NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200 $CONFIG_I2C_ALGOBIT
102 +      if [ "$CONFIG_ARCH_SA1100" = "y" ]; then
103 +         dep_tristate 'SA1100 I2C Adapter' CONFIG_I2C_FRODO $CONFIG_I2C_ALGOBIT
104 +      fi
105 +      dep_tristate '  NatSemi SCx200 I2C using GPIO pins' CONFIG_SCx200_I2C $CONFIG_SCx200_GPIO $CONFIG_I2C_ALGOBIT
106        if [ "$CONFIG_SCx200_I2C" != "n" ]; then
107           int  '    GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
108           int  '    GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
109        fi
110 -      dep_tristate '  NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
111     fi
112  
113 +   dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
114 +
115     dep_tristate 'I2C PCF 8584 interfaces' CONFIG_I2C_ALGOPCF $CONFIG_I2C
116     if [ "$CONFIG_I2C_ALGOPCF" != "n" ]; then
117        dep_tristate '  Elektor ISA card' CONFIG_I2C_ELEKTOR $CONFIG_I2C_ALGOPCF
118 +      dep_tristate '  PCF on EPP port' CONFIG_I2C_PCFEPP $CONFIG_I2C_ALGOPCF
119     fi
120  
121     if [ "$CONFIG_MIPS_ITE8172" = "y" ]; then
122 @@ -35,13 +40,13 @@
123     if [ "$CONFIG_8xx" = "y" ]; then
124        dep_tristate 'MPC8xx CPM I2C interface' CONFIG_I2C_ALGO8XX $CONFIG_I2C
125        if [ "$CONFIG_RPXLITE" = "y" -o "$CONFIG_RPXCLASSIC" = "y" ]; then
126 -         dep_tristate '  Embedded Planet RPX Lite/Classic suppoort' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
127 +         dep_tristate '  Embedded Planet RPX Lite/Classic support' CONFIG_I2C_RPXLITE $CONFIG_I2C_ALGO8XX
128        fi
129     fi
130 -   if [ "$CONFIG_405" = "y" ]; then
131 -      dep_tristate 'PPC 405 I2C Algorithm' CONFIG_I2C_PPC405_ALGO $CONFIG_I2C
132 -      if [ "$CONFIG_I2C_PPC405_ALGO" != "n" ]; then
133 -         dep_tristate '  PPC 405 I2C Adapter' CONFIG_I2C_PPC405_ADAP $CONFIG_I2C_PPC405_ALGO
134 +   if [ "$CONFIG_IBM_OCP" = "y" ]; then
135 +      dep_tristate 'IBM on-chip I2C Algorithm' CONFIG_I2C_IBM_OCP_ALGO $CONFIG_I2C
136 +      if [ "$CONFIG_I2C_IBM_OCP_ALGO" != "n" ]; then
137 +         dep_tristate '  IBM on-chip I2C Adapter' CONFIG_I2C_IBM_OCP_ADAP $CONFIG_I2C_IBM_OCP_ALGO
138        fi
139     fi
140  
141 @@ -58,7 +63,7 @@
142  # This is needed for automatic patch generation: sensors code ends here
143  
144     dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C
145 -   dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C
146 +   dep_tristate 'I2C /proc interface (required for hardware sensors)' CONFIG_I2C_PROC $CONFIG_I2C $CONFIG_SYSCTL
147  
148  fi
149  endmenu
150 --- linux-2.4.23-rc1-orig/drivers/i2c/Makefile  Wed Aug 27 18:11:46 2003
151 +++ linux-2.4.23-rc1-i2c/drivers/i2c/Makefile   Sat Nov 15 20:37:44 2003
152 @@ -5,7 +5,8 @@
153  O_TARGET := i2c.o
154  
155  export-objs    := i2c-core.o i2c-algo-bit.o i2c-algo-pcf.o \
156 -                  i2c-algo-ite.o i2c-proc.o i2c-algo-sibyte.o
157 +                  i2c-algo-ite.o i2c-proc.o i2c-algo-sibyte.o \
158 +                  i2c-algo-8xx.o i2c-algo-ibm_ocp.o
159  
160  obj-$(CONFIG_I2C)              += i2c-core.o
161  obj-$(CONFIG_I2C_CHARDEV)      += i2c-dev.o
162 @@ -13,10 +14,16 @@
163  obj-$(CONFIG_I2C_PHILIPSPAR)   += i2c-philips-par.o
164  obj-$(CONFIG_I2C_ELV)          += i2c-elv.o
165  obj-$(CONFIG_I2C_VELLEMAN)     += i2c-velleman.o
166 +obj-$(CONFIG_I2C_FRODO)                += i2c-frodo.o
167  obj-$(CONFIG_I2C_ALGOPCF)      += i2c-algo-pcf.o
168  obj-$(CONFIG_I2C_ELEKTOR)      += i2c-elektor.o
169 +obj-$(CONFIG_I2C_PCFEPP)       += i2c-pcf-epp.o
170  obj-$(CONFIG_ITE_I2C_ALGO)     += i2c-algo-ite.o
171  obj-$(CONFIG_ITE_I2C_ADAP)     += i2c-adap-ite.o
172 +obj-$(CONFIG_I2C_ALGO8XX)      += i2c-algo-8xx.o
173 +obj-$(CONFIG_I2C_RPXLITE)      += i2c-rpx.o
174 +obj-$(CONFIG_I2C_IBM_OCP_ALGO) += i2c-algo-ibm_ocp.o
175 +obj-$(CONFIG_I2C_IBM_OCP_ADAP) += i2c-adap-ibm_ocp.o
176  obj-$(CONFIG_I2C_PROC)         += i2c-proc.o
177  obj-$(CONFIG_SCx200_I2C)       += scx200_i2c.o
178  obj-$(CONFIG_SCx200_ACB)       += scx200_acb.o
179 --- linux-old/Documentation/Configure.help      Wed Aug 27 16:11:41 2003
180 +++ linux/Documentation/Configure.help  Sun Dec  7 11:17:34 2003
181 @@ -18185,6 +18185,16 @@
182    <file:Documentation/modules.txt>.
183    The module will be called i2c-velleman.o.
184  
185 +Basic I2C on Parallel Port adapter
186 +CONFIG_I2C_PPORT
187 +  This supports directly connecting I2C devices to the parallel port.
188 +  See <file:Documentation/i2c/i2c-pport> for more information.
189 +
190 +  This driver is also available as a module.  If you want to compile
191 +  it as a module, say M here and read
192 +  <file:Documentation/modules.txt>.
193 +  The module will be called i2c-pport.o.
194 +
195  I2C PCF 8584 interfaces
196  CONFIG_I2C_ALGOPCF
197    This allows you to use a range of I2C adapters called PCF adapters.
198 @@ -18206,6 +18216,15 @@
199    <file:Documentation/modules.txt>.
200    The module will be called i2c-elektor.o.
201  
202 +PCF on the EPP Parallel Port
203 +CONFIG_I2C_PCFEPP
204 +  This supports the PCF8584 connected to the parallel port.
205 +
206 +  This driver is also available as a module.  If you want to compile
207 +  it as a module, say M here and read
208 +  <file:Documentation/modules.txt>.
209 +  The module will be called i2c-pcf-epp.o.
210 +
211  ITE I2C Algorithm
212  CONFIG_ITE_I2C_ALGO
213    This supports the use the ITE8172 I2C interface found on some MIPS
214 @@ -18238,6 +18257,51 @@
215    sensor.  Currently the device is only supported on a SiByte I2C
216    adapter, and the driver prints status updates to the system log.
217  
218 +Motorola 8xx I2C algorithm
219 +CONFIG_I2C_ALGO8XX
220 +  This is the algorithm that allows you to use Motorola 8xx I2C adapters.
221 +
222 +  This driver is also available as a module.  If you want to compile
223 +  it as a module, say M here and read
224 +  <file:Documentation/modules.txt>.
225 +  The module will be called i2c-algo-8xx.o.
226 +
227 +Motorola 8xx I2C interface
228 +CONFIG_I2C_RPXLITE
229 +  This supports the Motorola 8xx I2C device.
230 +
231 +  This driver is also available as a module.  If you want to compile
232 +  it as a module, say M here and read
233 +  <file:Documentation/modules.txt>.
234 +  The module will be called i2c-rpx.o.
235 +
236 +IBM 405 I2C algorithm
237 +CONFIG_I2C_IBM_OCP_ALGO
238 +  This is the algorithm that allows you to use IBM 405 I2C adapters.
239 +
240 +  This driver is also available as a module.  If you want to compile
241 +  it as a module, say M here and read
242 +  <file:Documentation/modules.txt>.
243 +  The module will be called i2c-algo-ibm_ocp.o.
244 +
245 +IBM 405 I2C interface
246 +CONFIG_I2C_IBM_OCP_ADAP
247 +  This supports the IBM 405 I2C device.
248 +
249 +  This driver is also available as a module.  If you want to compile
250 +  it as a module, say M here and read
251 +  <file:Documentation/modules.txt>.
252 +  The module will be called i2c-adap-ibm_ocp.o.
253 +
254 +StrongARM SA-1110 interface
255 +CONFIG_I2C_FRODO
256 +  This supports the StrongARM SA-1110 Development Board.
257 +
258 +  This driver is also available as a module.  If you want to compile
259 +  it as a module, say M here and read
260 +  <file:Documentation/modules.txt>.
261 +  The module will be called i2c-frodo.o.
262 +
263  I2C device interface
264  CONFIG_I2C_CHARDEV
265    Say Y here to use i2c-* device files, usually found in the /dev
266 @@ -18258,6 +18322,15 @@
267    This code is also available as a module. If you want to compile
268    it as a module, say M here and read <file:Documentation/modules.txt>.
269    The module will be called i2c-proc.o.
270 +
271 +Powermac Keywest I2C interface
272 +CONFIG_I2C_KEYWEST
273 +  This supports the use of the I2C interface in the combo-I/O
274 +  chip on recent Apple machines.  Say Y if you have such a machine.
275 +
276 +  This driver is also available as a module.  If you want to compile
277 +  it as a module, say M here and read Documentation/modules.txt.
278 +  The module will be called i2c-keywest.o.
279  
280  Bus Mouse Support
281  CONFIG_BUSMOUSE
282 --- linux-old/Documentation/i2c/dev-interface   Thu Oct 11 15:05:47 2001
283 +++ linux/Documentation/i2c/dev-interface       Sun Dec  7 11:17:34 2003
284 @@ -87,7 +87,12 @@
285  
286  ioctl(file,I2C_TENBIT,long select)
287    Selects ten bit addresses if select not equals 0, selects normal 7 bit
288 -  addresses if select equals 0.
289 +  addresses if select equals 0. Default 0.
290 +
291 +ioctl(file,I2C_PEC,long select)
292 +  Selects SMBus PEC (packet error checking) generation and verification
293 +  if select not equals 0, disables if select equals 0. Default 0.
294 +  Used only for SMBus transactions.
295  
296  ioctl(file,I2C_FUNCS,unsigned long *funcs)
297    Gets the adapter functionality and puts it in *funcs.
298 --- linux-old/Documentation/i2c/i2c-pport       Thu Jan  1 00:00:00 1970
299 +++ linux/Documentation/i2c/i2c-pport   Sun Dec  7 11:17:34 2003
300 @@ -0,0 +1,67 @@
301 +Parallel Port Adapters
302 +----------------------
303 +If you are installing parallel port adapters it means you are probably messing 
304 +around with wires and IC's and the like. If you have purchased a card that 
305 +provides an external i2c/smbus this will require combined algorithm and 
306 +adapter code in a single module.
307 +If you are doing it yourself by using the parallel port there 
308 +are basically 2 options.
309 +
310 +1) Using the parallel port and using the i2c-pport adapter module and the 
311 +i2c-algo-bit algorithm module together to enable you to wire up your parallel 
312 +port to act as an i2c/smbus. This provides a bus that will enable most 
313 +sensors to work but doesn't support the entire i2c/smbus capability.
314 +
315 +2) Using the parallel port to interface to a Philips PCF8584 parallel to i2c 
316 +adapter chip. You will need to build a bit of a circuit to do this. This 
317 +configuration needs the i2c-pcf-epp adapter module and the i2c-algo-pcf 
318 +algorithm module. This support almost all of the i2c/smbus capabilities.
319 +
320 +
321 +i2c-pport Documentation
322 +-----------------------
323 +This is a primitive parallel port driver for the i2c bus, which exploits 
324 +features of modern bidirectional parallel ports. 
325 +
326 +Bidirectional ports have particular bits connected in following way:
327 +   
328 +                        |
329 +            /-----|     R
330 +         --o|     |-----|
331 +      read  \-----|     /------- Out pin
332 +                      |/
333 +                   - -|\
334 +                write   V
335 +                        |
336 +                       ---  
337 +
338 +
339 +It means when output is set to 1 we can read the port. Therefore 
340 +we can use 2 pins of parallel port as SDA and SCL for i2c bus. It 
341 +is not necessary to add any external - additional parts, we can 
342 +read and write the same port simultaneously.
343 +       I only use register base+2 so it is possible to use all 
344 +8 data bits of parallel port for other applications (I have 
345 +connected EEPROM and LCD display). I do not use bit Enable Bi-directional
346 + Port. The only disadvantage is we can only support 5V chips.
347 +
348 +Layout:
349 +
350 +Cannon 25 pin
351 +
352 +SDA - connect to pin 14 (Auto Linefeed)
353 +SCL - connect to pin 16 (Initialize Printer)
354 +GND - connect to pin 18-25
355 ++5V - use external supply (I use 5V from 3.5" floppy connector)
356 +      
357 +no pullups  requied
358 +
359 +Module parameters:
360 +
361 +base = 0xXXX
362 +XXX - 278 or 378
363 +
364 +That's all.
365 +
366 +Daniel Smolik
367 +marvin@sitour.cz
368 --- linux-old/Documentation/i2c/i2c-protocol    Fri Jul 28 19:50:51 2000
369 +++ linux/Documentation/i2c/i2c-protocol        Sun Dec  7 11:17:35 2003
370 @@ -52,10 +52,10 @@
371  We have found some I2C devices that needs the following modifications:
372  
373    Flag I2C_M_NOSTART: 
374 -    In a combined transaction, no 'S Addr' is generated at some point.
375 -    For example, setting I2C_M_NOSTART on the second partial message
376 +    In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some
377 +    point. For example, setting I2C_M_NOSTART on the second partial message
378      generates something like:
379 -      S Addr Rd [A] [Data] NA Wr [A] Data [A] P
380 +      S Addr Rd [A] [Data] NA Data [A] P
381      If you set the I2C_M_NOSTART variable for the first partial message,
382      we do not generate Addr, but we do generate the startbit S. This will
383      probably confuse all other clients on your bus, so don't try this.
384 @@ -65,4 +65,12 @@
385      need to emit an Rd instead of a Wr, or vice versa, you set this
386      flag. For example:
387        S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P
388 -                      
389 +
390 +  Flags I2C_M_IGNORE_NAK
391 +    Normally message is interrupted immediately if there is [NA] from the
392 +    client. Setting this flag treats any [NA] as [A], and all of
393 +    message is sent.
394 +    These messages may still fail to SCL lo->hi timeout.
395 +
396 +  Flags I2C_M_NO_RD_ACK
397 +    In a read message, master A/NA bit is skipped.
398 --- linux-old/Documentation/i2c/i2c-velleman    Thu Jan  1 00:00:00 1970
399 +++ linux/Documentation/i2c/i2c-velleman        Sun Dec  7 11:17:35 2003
400 @@ -0,0 +1,27 @@
401 +i2c-velleman driver
402 +-------------------
403 +This is a driver for i2c-hw access for Velleman K9000 and other adapters.
404 +
405 +Useful links
406 +------------
407 +Velleman:
408 +       http://www.velleman.be/
409 +
410 +Velleman K8000 Howto:
411 +       http://howto.htlw16.ac.at/k8000-howto.html
412 +
413 +
414 +K8000 and K8005 libraries
415 +-------------------------
416 +The project has lead to new libs for the Velleman K8000 and K8005..
417 +LIBK8000 v1.99.1 and LIBK8005 v0.21
418 +
419 +With these libs you can control the K8000 and K8005 with the original
420 +simple commands which are in the original Velleman software.
421 +Like SetIOchannel, ReadADchannel, SendStepCCWFull and many more.
422 +Via i2c kernel device /dev/velleman
423 +
424 +The libs can be found on http://groups.yahoo.com/group/k8000/files/linux/
425 +
426 +The Velleman K8000 interface card on http://www.velleman.be/kits/k8000.htm
427 +The Velleman K8005 steppermotorcard on http://www.velleman.be/kits/k8005.htm
428 --- linux-old/Documentation/i2c/smbus-protocol  Fri Feb 16 23:53:08 2001
429 +++ linux/Documentation/i2c/smbus-protocol      Sun Dec  7 11:17:35 2003
430 @@ -1,3 +1,10 @@
431 +SMBus Protocol Summary
432 +======================
433 +The following is a summary of the SMBus protocol. It applies to
434 +all revisions of the protocol (1.0, 1.1, and 2.0).
435 +Certain protocol features which are not supported by
436 +this package are briefly described at the end of this document.
437 +
438  Some adapters understand only the SMBus (System Management Bus) protocol,
439  which is a subset from the I2C protocol. Fortunately, many devices use
440  only the same subset, which makes it possible to put them on an SMBus.
441 @@ -6,7 +13,7 @@
442  I2C protocol). This makes it possible to use the device driver on both
443  SMBus adapters and I2C adapters (the SMBus command set is automatically
444  translated to I2C on I2C adapters, but plain I2C commands can not be
445 -handled at all on a pure SMBus adapter).
446 +handled at all on most pure SMBus adapters).
447  
448  Below is a list of SMBus commands.
449  
450 @@ -54,7 +61,7 @@
451  This is the reverse of Read Byte: it sends a single byte to a device.
452  See Read Byte for more information.
453  
454 -S Addr Wr [A] Data NA P
455 +S Addr Wr [A] Data [A] P
456  
457  
458  SMBus Read Byte Data
459 @@ -109,7 +116,7 @@
460  SMBus Block Read
461  ================
462  
463 -This command reads a block of upto 32 bytes from a device, from a 
464 +This command reads a block of up to 32 bytes from a device, from a 
465  designated register that is specified through the Comm byte. The amount
466  of data is specified by the device in the Count byte.
467  
468 @@ -120,8 +127,90 @@
469  SMBus Block Write
470  =================
471  
472 -The opposite of the Block Read command, this writes upto 32 bytes to 
473 +The opposite of the Block Read command, this writes up to 32 bytes to 
474  a device, to a designated register that is specified through the
475  Comm byte. The amount of data is specified in the Count byte.
476  
477  S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
478 +
479 +
480 +SMBus Block Process Call
481 +========================
482 +
483 +SMBus Block Process Call was introduced in Revision 2.0 of the specification.
484 +
485 +This command selects a device register (through the Comm byte), sends
486 +1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.
487 +
488 +S Addr Wr [A] Comm [A] Count [A] Data [A] ...
489 +                             S Addr Rd [A] [Count] A [Data] ... NA P
490 +
491 +
492 +SMBus Host Notify
493 +=================
494 +
495 +This command is sent from a SMBus device acting as a master to the
496 +SMBus host acting as a slave.
497 +It is the same form as Write Word, with the command code replaced by the
498 +alerting device's address.
499 +
500 +[S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P]
501 +
502 +
503 +Packet Error Checking (PEC)
504 +===========================
505 +Packet Error Checking was introduced in Revision 1.1 of the specification.
506 +
507 +PEC adds a CRC-8 error-checking byte to all transfers.
508 +
509 +
510 +Address Resolution Protocol (ARP)
511 +=================================
512 +The Address Resolution Protocol was introduced in Revision 2.0 of
513 +the specification. It is a higher-layer protocol which uses the
514 +messages above.
515 +
516 +ARP adds device enumeration and dynamic address assignment to
517 +the protocol. All ARP communications use slave address 0x61 and
518 +require PEC checksums.
519 +
520 +
521 +I2C Block Transactions
522 +======================
523 +The following I2C block transactions are supported by the
524 +SMBus layer and are described here for completeness.
525 +I2C block transactions do not limit the number of bytes transferred
526 +but the SMBus layer places a limit of 32 bytes.
527 +
528 +
529 +I2C Block Read
530 +==============
531 +
532 +This command reads a block of bytes from a device, from a 
533 +designated register that is specified through the Comm byte.
534 +
535 +S Addr Wr [A] Comm [A] 
536 +           S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
537 +
538 +
539 +I2C Block Read (2 Comm bytes)
540 +=============================
541 +
542 +This command reads a block of bytes from a device, from a 
543 +designated register that is specified through the two Comm bytes.
544 +
545 +S Addr Wr [A] Comm1 [A] Comm2 [A] 
546 +           S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
547 +
548 +
549 +I2C Block Write
550 +===============
551 +
552 +The opposite of the Block Read command, this writes bytes to 
553 +a device, to a designated register that is specified through the
554 +Comm byte. Note that command lengths of 0, 2, or more bytes are
555 +supported as they are indistinguishable from data.
556 +
557 +S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
558 +
559 +
560 --- linux-old/Documentation/i2c/summary Thu Oct 11 15:05:47 2001
561 +++ linux/Documentation/i2c/summary     Sun Dec  7 11:17:35 2003
562 @@ -4,7 +4,7 @@
563  =============
564  
565  I2C (pronounce: I squared C) is a protocol developed by Philips. It is a 
566 -slow two-wire protocol (10-100 kHz), but it suffices for many types of 
567 +slow two-wire protocol (10-400 kHz), but it suffices for many types of 
568  devices.
569  
570  SMBus (System Management Bus) is a subset of the I2C protocol. Many
571 @@ -43,15 +43,15 @@
572  
573  Included Bus Drivers
574  ====================
575 -Note that not only stable drivers are patched into the kernel by 'mkpatch'.
576 +Note that only stable drivers are patched into the kernel by 'mkpatch'.
577  
578  
579  Base modules
580  ------------
581  
582 -i2c-core: The basic I2C code, including the /proc interface
583 -i2c-dev:  The /dev interface
584 -i2c-proc: The /proc interface for device (client) drivers
585 +i2c-core: The basic I2C code, including the /proc/bus/i2c* interface
586 +i2c-dev:  The /dev/i2c-* interface
587 +i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers
588  
589  Algorithm drivers
590  -----------------
591 @@ -59,16 +59,16 @@
592  i2c-algo-8xx:    An algorithm for CPM's I2C device in Motorola 8xx processors (NOT BUILT BY DEFAULT)
593  i2c-algo-bit:    A bit-banging algorithm
594  i2c-algo-pcf:    A PCF 8584 style algorithm
595 -i2c-algo-ppc405: An algorithm for the I2C device in IBM 405xx processors (NOT BUILT BY DEFAULT)
596 +i2c-algo-ibm_ocp: An algorithm for the I2C device in IBM 4xx processors (NOT BUILT BY DEFAULT)
597  
598  Adapter drivers
599  ---------------
600  
601  i2c-elektor:     Elektor ISA card (uses i2c-algo-pcf)
602  i2c-elv:         ELV parallel port adapter (uses i2c-algo-bit)
603 -i2c-pcf-epp:     PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (BROKEN - missing i2c-pcf-epp.h)
604 +i2c-pcf-epp:     PCF8584 on a EPP parallel port (uses i2c-algo-pcf) (NOT mkpatched)
605  i2c-philips-par: Philips style parallel port adapter (uses i2c-algo-bit)
606 -i2c-ppc405:      IBM 405xx processor I2C device (uses i2c-algo-ppc405) (NOT BUILT BY DEFAULT)
607 +i2c-adap-ibm_ocp: IBM 4xx processor I2C device (uses i2c-algo-ibm_ocp) (NOT BUILT BY DEFAULT)
608  i2c-pport:       Primitive parallel port adapter (uses i2c-algo-bit)
609  i2c-rpx:         RPX board Motorola 8xx I2C device (uses i2c-algo-8xx) (NOT BUILT BY DEFAULT)
610  i2c-velleman:    Velleman K9000 parallel port adapter (uses i2c-algo-bit)
611 --- linux-old/Documentation/i2c/writing-clients Thu Oct 11 15:05:47 2001
612 +++ linux/Documentation/i2c/writing-clients     Sun Dec  7 11:17:36 2003
613 @@ -24,16 +24,14 @@
614  routines, a client structure specific information like the actual I2C
615  address.
616  
617 -  struct i2c_driver foo_driver
618 -  {  
619 -    /* name           */  "Foo version 2.3 and later driver",
620 -    /* id             */  I2C_DRIVERID_FOO,
621 -    /* flags          */  I2C_DF_NOTIFY,
622 -    /* attach_adapter */  &foo_attach_adapter,
623 -    /* detach_client  */  &foo_detach_client,
624 -    /* command        */  &foo_command,   /* May be NULL */
625 -    /* inc_use        */  &foo_inc_use,   /* May be NULL */
626 -    /* dec_use        */  &foo_dec_use    /* May be NULL */
627 +  static struct i2c_driver foo_driver = {
628 +    .owner          = THIS_MODULE,
629 +    .name           = "Foo version 2.3 driver",
630 +    .id             = I2C_DRIVERID_FOO, /* usually from i2c-id.h */
631 +    .flags          = I2C_DF_NOTIFY,
632 +    .attach_adapter = &foo_attach_adapter,
633 +    .detach_client  = &foo_detach_client,
634 +    .command        = &foo_command /* may be NULL */
635    }
636   
637  The name can be chosen freely, and may be upto 40 characters long. Please
638 @@ -50,43 +48,8 @@
639  All other fields are for call-back functions which will be explained 
640  below.
641  
642 -
643 -Module usage count
644 -==================
645 -
646 -If your driver can also be compiled as a module, there are moments at 
647 -which the module can not be removed from memory. For example, when you
648 -are doing a lengthy transaction, or when you create a /proc directory,
649 -and some process has entered that directory (this last case is the
650 -main reason why these call-backs were introduced).
651 -
652 -To increase or decrease the module usage count, you can use the
653 -MOD_{INC,DEC}_USE_COUNT macros. They must be called from the module
654 -which needs to get its usage count changed; that is why each driver
655 -module has to implement its own callback.
656 -
657 -  void foo_inc_use (struct i2c_client *client)
658 -  {
659 -  #ifdef MODULE
660 -    MOD_INC_USE_COUNT;
661 -  #endif
662 -  }
663 -
664 -  void foo_dec_use (struct i2c_client *client)
665 -  {
666 -  #ifdef MODULE
667 -    MOD_DEC_USE_COUNT;
668 -  #endif
669 -  }
670 -
671 -Do not call these call-back functions directly; instead, use one of the
672 -following functions defined in i2c.h:
673 -  void i2c_inc_use_client(struct i2c_client *);
674 -  void i2c_dec_use_client(struct i2c_client *);
675 -
676 -You should *not* increase the module count just because a device is
677 -detected and a client created. This would make it impossible to remove
678 -an adapter driver! 
679 +There use to be two additional fields in this structure, inc_use et dec_use,
680 +for module usage count, but these fields were obsoleted and removed.
681  
682  
683  Extra client data
684 @@ -365,7 +328,7 @@
685  
686  The detect client function is called by i2c_probe or i2c_detect.
687  The `kind' parameter contains 0 if this call is due to a `force'
688 -parameter, and 0 otherwise (for i2c_detect, it contains 0 if
689 +parameter, and -1 otherwise (for i2c_detect, it contains 0 if
690  this call is due to the generic `force' parameter, and the chip type
691  number if it is due to a specific `force' parameter).
692  
693 @@ -448,9 +411,9 @@
694      /* Note that we reserve some space for foo_data too. If you don't
695         need it, remove it. We do it here to help to lessen memory
696         fragmentation. */
697 -    if (! (new_client = kmalloc(sizeof(struct i2c_client)) + 
698 +    if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
699                                  sizeof(struct foo_data),
700 -                                GFP_KERNEL)) {
701 +                                GFP_KERNEL))) {
702        err = -ENOMEM;
703        goto ERROR0;
704      }
705 --- linux-old/drivers/i2c/i2c-adap-ibm_ocp.c    Thu Jan  1 00:00:00 1970
706 +++ linux/drivers/i2c/i2c-adap-ibm_ocp.c        Sun Dec  7 11:17:36 2003
707 @@ -0,0 +1,346 @@
708 +/*
709 +   -------------------------------------------------------------------------
710 +   i2c-adap-ibm_ocp.c i2c-hw access for the IIC peripheral on the IBM PPC 405
711 +   -------------------------------------------------------------------------
712 +  
713 +   Ian DaSilva, MontaVista Software, Inc.
714 +   idasilva@mvista.com or source@mvista.com
715 +
716 +   Copyright 2000 MontaVista Software Inc.
717 +
718 +   Changes made to support the IIC peripheral on the IBM PPC 405 
719 +
720 +
721 +   ----------------------------------------------------------------------------
722 +   This file was highly leveraged from i2c-elektor.c, which was created
723 +   by Simon G. Vogl and Hans Berglund:
724 +
725
726 +     Copyright (C) 1995-97 Simon G. Vogl
727 +                   1998-99 Hans Berglund
728 +
729 +   With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
730 +   Frodo Looijaard <frodol@dds.nl>
731 +
732 +
733 +    This program is free software; you can redistribute it and/or modify
734 +    it under the terms of the GNU General Public License as published by
735 +    the Free Software Foundation; either version 2 of the License, or
736 +    (at your option) any later version.
737 +
738 +    This program is distributed in the hope that it will be useful,
739 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
740 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
741 +    GNU General Public License for more details.
742 +
743 +    You should have received a copy of the GNU General Public License
744 +    along with this program; if not, write to the Free Software
745 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
746 +   ----------------------------------------------------------------------------
747 +
748 +   History: 01/20/12 - Armin
749 +       akuster@mvista.com
750 +       ported up to 2.4.16+    
751 +
752 +   Version 02/03/25 - Armin
753 +       converted to ocp format
754 +       removed commented out or #if 0 code
755 +
756 +   TODO: convert to ocp_register
757 +         add PM hooks
758 +
759 +*/
760 +
761 +
762 +#include <linux/kernel.h>
763 +#include <linux/ioport.h>
764 +#include <linux/module.h>
765 +#include <linux/delay.h>
766 +#include <linux/slab.h>
767 +#include <linux/init.h>
768 +#include <linux/i2c.h>
769 +#include <linux/i2c-algo-ibm_ocp.h>
770 +#include <asm/irq.h>
771 +#include <asm/io.h>
772 +#include <asm/ocp.h>
773 +
774 +/*
775 + * This next section is configurable, and it is used to set the number
776 + * of i2c controllers in the system.  The default number of instances is 1,
777 + * however, this should be changed to reflect your system's configuration.
778 + */ 
779 +
780 +/*
781 + * The STB03xxx, with a PPC405 core, has two i2c controllers.
782 + */
783 +//(sizeof(IIC_ADDR)/sizeof(struct iic_regs))
784 +extern iic_t *IIC_ADDR[];
785 +static struct iic_ibm iic_ibmocp_adaps[IIC_NUMS][5];
786 +
787 +static struct i2c_algo_iic_data *iic_ibmocp_data[IIC_NUMS];
788 +static struct i2c_adapter *iic_ibmocp_ops[IIC_NUMS];
789 +
790 +static int i2c_debug=0;
791 +static wait_queue_head_t iic_wait[IIC_NUMS];
792 +static int iic_pending;
793 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
794 +
795 +
796 +/* ----- global defines -----------------------------------------------        */
797 +#define DEB(x) if (i2c_debug>=1) x
798 +#define DEB2(x) if (i2c_debug>=2) x
799 +#define DEB3(x) if (i2c_debug>=3) x
800 +#define DEBE(x)        x       /* error messages                               */
801 +
802 +/* ----- local functions ----------------------------------------------        */
803 +
804 +//
805 +// Description: Write a byte to IIC hardware
806 +//
807 +static void iic_ibmocp_setbyte(void *data, int ctl, int val)
808 +{
809 +   // writeb resolves to a write to the specified memory location
810 +   // plus a call to eieio.  eieio ensures that all instructions
811 +   // preceding it are completed before any further stores are
812 +   // completed.
813 +   // Delays at this level (to protect writes) are not needed here.
814 +   writeb(val, ctl);
815 +}
816 +
817 +
818 +//
819 +// Description: Read a byte from IIC hardware
820 +//
821 +static int iic_ibmocp_getbyte(void *data, int ctl)
822 +{
823 +   int val;
824 +
825 +   val = readb(ctl);
826 +   return (val);
827 +}
828 +
829 +
830 +//
831 +// Description: Return our slave address.  This is the address
832 +// put on the I2C bus when another master on the bus wants to address us
833 +// as a slave
834 +//
835 +static int iic_ibmocp_getown(void *data)
836 +{
837 +   return(((struct iic_ibm *)(data))->iic_own);
838 +}
839 +
840 +
841 +//
842 +// Description: Return the clock rate
843 +//
844 +static int iic_ibmocp_getclock(void *data)
845 +{
846 +   return(((struct iic_ibm *)(data))->iic_clock);
847 +}
848 +
849 +
850 +
851 +//
852 +// Description:  Put this process to sleep.  We will wake up when the
853 +// IIC controller interrupts.
854 +//
855 +static void iic_ibmocp_waitforpin(void *data) {
856 +
857 +   int timeout = 2;
858 +   struct iic_ibm *priv_data = data;
859 +
860 +   //
861 +   // If interrupts are enabled (which they are), then put the process to
862 +   // sleep.  This process will be awakened by two events -- either the
863 +   // the IIC peripheral interrupts or the timeout expires. 
864 +   //
865 +   if (priv_data->iic_irq > 0) {
866 +      spin_lock_irq(&irq_driver_lock);
867 +      if (iic_pending == 0) {
868 +        interruptible_sleep_on_timeout(&(iic_wait[priv_data->index]), timeout*HZ );
869 +      } else
870 +        iic_pending = 0;
871 +      spin_unlock_irq(&irq_driver_lock);
872 +   } else {
873 +      //
874 +      // If interrupts are not enabled then delay for a reasonable amount
875 +      // of time and return.  We expect that by time we return to the calling
876 +      // function that the IIC has finished our requested transaction and
877 +      // the status bit reflects this.
878 +      //
879 +      // udelay is probably not the best choice for this since it is
880 +      // the equivalent of a busy wait
881 +      //
882 +      udelay(100);
883 +   }
884 +   //printk("iic_ibmocp_waitforpin: exitting\n");
885 +}
886 +
887 +
888 +//
889 +// Description: The registered interrupt handler
890 +//
891 +static void iic_ibmocp_handler(int this_irq, void *dev_id, struct pt_regs *regs) 
892 +{
893 +   int ret;
894 +   struct iic_regs *iic;
895 +   struct iic_ibm *priv_data = dev_id;
896 +   iic = (struct iic_regs *) priv_data->iic_base;
897 +   iic_pending = 1;
898 +   DEB2(printk("iic_ibmocp_handler: in interrupt handler\n"));
899 +   // Read status register
900 +   ret = readb((int) &(iic->sts));
901 +   DEB2(printk("iic_ibmocp_handler: status = %x\n", ret));
902 +   // Clear status register.  See IBM PPC 405 reference manual for details
903 +   writeb(0x0a, (int) &(iic->sts));
904 +   wake_up_interruptible(&(iic_wait[priv_data->index]));
905 +}
906 +
907 +
908 +//
909 +// Description: This function is very hardware dependent.  First, we lock
910 +// the region of memory where out registers exist.  Next, we request our
911 +// interrupt line and register its associated handler.  Our IIC peripheral
912 +// uses interrupt number 2, as specified by the 405 reference manual.
913 +//
914 +static int iic_hw_resrc_init(int instance)
915 +{
916 +
917 +   DEB(printk("iic_hw_resrc_init: Physical Base address: 0x%x\n", (u32) IIC_ADDR[instance] ));
918 +   iic_ibmocp_adaps[instance]->iic_base = (u32)ioremap((unsigned long)IIC_ADDR[instance],PAGE_SIZE);
919 +
920 +   DEB(printk("iic_hw_resrc_init: ioremapped base address: 0x%x\n", iic_ibmocp_adaps[instance]->iic_base));
921 +
922 +   if (iic_ibmocp_adaps[instance]->iic_irq > 0) {
923 +       
924 +      if (request_irq(iic_ibmocp_adaps[instance]->iic_irq, iic_ibmocp_handler,
925 +       0, "IBM OCP IIC", iic_ibmocp_adaps[instance]) < 0) {
926 +         printk(KERN_ERR "iic_hw_resrc_init: Request irq%d failed\n",
927 +          iic_ibmocp_adaps[instance]->iic_irq);
928 +        iic_ibmocp_adaps[instance]->iic_irq = 0;
929 +      } else {
930 +         DEB3(printk("iic_hw_resrc_init: Enabled interrupt\n"));
931 +      }
932 +   }
933 +   return 0;
934 +}
935 +
936 +
937 +//
938 +// Description: Release irq and memory
939 +//
940 +static void iic_ibmocp_release(void)
941 +{
942 +   int i;
943 +
944 +   for(i=0; i<IIC_NUMS; i++) {
945 +      struct iic_ibm *priv_data = (struct iic_ibm *)iic_ibmocp_data[i]->data;
946 +      if (priv_data->iic_irq > 0) {
947 +         disable_irq(priv_data->iic_irq);
948 +         free_irq(priv_data->iic_irq, 0);
949 +      }
950 +      kfree(iic_ibmocp_data[i]);
951 +      kfree(iic_ibmocp_ops[i]);
952 +   }
953 +}
954 +
955 +
956 +//
957 +// Description: Called when the module is loaded.  This function starts the
958 +// cascade of calls up through the heirarchy of i2c modules (i.e. up to the
959 +//  algorithm layer and into to the core layer)
960 +//
961 +static int __init iic_ibmocp_init(void) 
962 +{
963 +   int i;
964 +
965 +   printk(KERN_INFO "iic_ibmocp_init: IBM on-chip iic adapter module\n");
966
967 +   for(i=0; i<IIC_NUMS; i++) {
968 +      iic_ibmocp_data[i] = kmalloc(sizeof(struct i2c_algo_iic_data),GFP_KERNEL);
969 +      if(iic_ibmocp_data[i] == NULL) {
970 +         return -ENOMEM;
971 +      }
972 +      memset(iic_ibmocp_data[i], 0, sizeof(struct i2c_algo_iic_data));
973 +      
974 +      switch (i) {
975 +             case 0:
976 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(0);
977 +             break;
978 +             case 1:
979 +              iic_ibmocp_adaps[i]->iic_irq = IIC_IRQ(1);
980 +             break;
981 +      }
982 +      iic_ibmocp_adaps[i]->iic_clock = IIC_CLOCK;
983 +      iic_ibmocp_adaps[i]->iic_own = IIC_OWN; 
984 +      iic_ibmocp_adaps[i]->index = i;
985
986 +      DEB(printk("irq %x\n", iic_ibmocp_adaps[i]->iic_irq));
987 +      DEB(printk("clock %x\n", iic_ibmocp_adaps[i]->iic_clock));
988 +      DEB(printk("own %x\n", iic_ibmocp_adaps[i]->iic_own));
989 +      DEB(printk("index %x\n", iic_ibmocp_adaps[i]->index));
990 +
991 +
992 +      iic_ibmocp_data[i]->data = (struct iic_regs *)iic_ibmocp_adaps[i]; 
993 +      iic_ibmocp_data[i]->setiic = iic_ibmocp_setbyte;
994 +      iic_ibmocp_data[i]->getiic = iic_ibmocp_getbyte;
995 +      iic_ibmocp_data[i]->getown = iic_ibmocp_getown;
996 +      iic_ibmocp_data[i]->getclock = iic_ibmocp_getclock;
997 +      iic_ibmocp_data[i]->waitforpin = iic_ibmocp_waitforpin;
998 +      iic_ibmocp_data[i]->udelay = 80;
999 +      iic_ibmocp_data[i]->mdelay = 80;
1000 +      iic_ibmocp_data[i]->timeout = HZ;
1001 +      
1002 +            iic_ibmocp_ops[i] = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
1003 +      if(iic_ibmocp_ops[i] == NULL) {
1004 +         return -ENOMEM;
1005 +      }
1006 +      memset(iic_ibmocp_ops[i], 0, sizeof(struct i2c_adapter));
1007 +      strcpy(iic_ibmocp_ops[i]->name, "IBM OCP IIC adapter");
1008 +      iic_ibmocp_ops[i]->owner = THIS_MODULE;
1009 +      iic_ibmocp_ops[i]->id = I2C_HW_OCP;
1010 +      iic_ibmocp_ops[i]->algo = NULL;
1011 +      iic_ibmocp_ops[i]->algo_data = iic_ibmocp_data[i];
1012 +       
1013 +      
1014 +      init_waitqueue_head(&(iic_wait[i]));
1015 +      if (iic_hw_resrc_init(i) == 0) {
1016 +         if (i2c_ocp_add_bus(iic_ibmocp_ops[i]) < 0)
1017 +         return -ENODEV;
1018 +      } else {
1019 +         return -ENODEV;
1020 +      }
1021 +      DEB(printk(KERN_INFO "iic_ibmocp_init: found device at %#x.\n\n", iic_ibmocp_adaps[i]->iic_base));
1022 +   }
1023 +   return 0;
1024 +}
1025 +
1026 +
1027 +static void __exit iic_ibmocp_exit(void)
1028 +{
1029 +   int i;
1030 +
1031 +   for(i=0; i<IIC_NUMS; i++) {
1032 +      i2c_ocp_del_bus(iic_ibmocp_ops[i]);
1033 +   }
1034 +   iic_ibmocp_release();
1035 +}
1036 +
1037 +//
1038 +// If modules is NOT defined when this file is compiled, then the MODULE_*
1039 +// macros will resolve to nothing
1040 +//
1041 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
1042 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PPC 405 IIC bus adapter");
1043 +MODULE_LICENSE("GPL");
1044 +
1045 +MODULE_PARM(base, "i");
1046 +MODULE_PARM(irq, "i");
1047 +MODULE_PARM(clock, "i");
1048 +MODULE_PARM(own, "i");
1049 +MODULE_PARM(i2c_debug,"i");
1050 +
1051 +
1052 +module_init(iic_ibmocp_init);
1053 +module_exit(iic_ibmocp_exit); 
1054 --- linux-old/drivers/i2c/i2c-algo-8xx.c        Thu Jan  1 00:00:00 1970
1055 +++ linux/drivers/i2c/i2c-algo-8xx.c    Sun Dec  7 11:17:36 2003
1056 @@ -0,0 +1,616 @@
1057 +/*
1058 + * i2c-algo-8xx.c i2x driver algorithms for MPC8XX CPM
1059 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
1060 + *
1061 +    This program is free software; you can redistribute it and/or modify
1062 +    it under the terms of the GNU General Public License as published by
1063 +    the Free Software Foundation; either version 2 of the License, or
1064 +    (at your option) any later version.
1065 +
1066 +    This program is distributed in the hope that it will be useful,
1067 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
1068 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1069 +    GNU General Public License for more details.
1070 +
1071 +    You should have received a copy of the GNU General Public License
1072 +    along with this program; if not, write to the Free Software
1073 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1074 + *
1075 + * moved into proper i2c interface; separated out platform specific 
1076 + * parts into i2c-rpx.c
1077 + * Brad Parker (brad@heeltoe.com)
1078 + */
1079 +
1080 +// XXX todo
1081 +// timeout sleep?
1082 +
1083 +/* $Id$ */
1084 +
1085 +#include <linux/kernel.h>
1086 +#include <linux/module.h>
1087 +#include <linux/delay.h>
1088 +#include <linux/slab.h>
1089 +#include <linux/init.h>
1090 +#include <linux/errno.h>
1091 +#include <linux/sched.h>
1092 +#include <linux/i2c.h>
1093 +#include <linux/i2c-algo-8xx.h>
1094 +#include <asm/mpc8xx.h>
1095 +#include <asm/commproc.h>
1096 +
1097 +
1098 +#define CPM_MAX_READ   513
1099 +/* #define I2C_CHIP_ERRATA */ /* Try uncomment this if you have an older CPU(earlier than rev D4) */
1100 +static wait_queue_head_t iic_wait;
1101 +static ushort r_tbase, r_rbase;
1102 +
1103 +int cpm_debug = 0;
1104 +
1105 +static  void
1106 +cpm_iic_interrupt(void *dev_id, struct pt_regs *regs)
1107 +{
1108 +       volatile i2c8xx_t *i2c = (i2c8xx_t *)dev_id;
1109 +       if (cpm_debug > 1)
1110 +               printk("cpm_iic_interrupt(dev_id=%p)\n", dev_id);
1111 +#if 0
1112 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs */
1113 +        /* This should probably be removed and replaced by I2C_CHIP_ERRATA stuff */
1114 +        /* Someone with a buggy CPU needs to confirm that */
1115 +       i2c->i2c_i2mod &= ~1;
1116 +#endif
1117 +       /* Clear interrupt.
1118 +       */
1119 +       i2c->i2c_i2cer = 0xff;
1120 +
1121 +       /* Get 'me going again.
1122 +       */
1123 +       wake_up_interruptible(&iic_wait);
1124 +}
1125 +
1126 +static void
1127 +cpm_iic_init(struct i2c_algo_8xx_data *cpm)
1128 +{
1129 +       volatile iic_t          *iip = cpm->iip;
1130 +       volatile i2c8xx_t       *i2c = cpm->i2c;
1131 +       unsigned char brg;
1132 +       bd_t *bd = (bd_t *)__res;
1133 +
1134 +       if (cpm_debug) printk(KERN_DEBUG "cpm_iic_init()\n");
1135 +
1136 +       /* Initialize the parameter ram.
1137 +        * We need to make sure many things are initialized to zero,
1138 +        * especially in the case of a microcode patch.
1139 +        */
1140 +       iip->iic_rstate = 0;
1141 +       iip->iic_rdp = 0;
1142 +       iip->iic_rbptr = 0;
1143 +       iip->iic_rbc = 0;
1144 +       iip->iic_rxtmp = 0;
1145 +       iip->iic_tstate = 0;
1146 +       iip->iic_tdp = 0;
1147 +       iip->iic_tbptr = 0;
1148 +       iip->iic_tbc = 0;
1149 +       iip->iic_txtmp = 0;
1150 +
1151 +       /* Set up the IIC parameters in the parameter ram.
1152 +       */
1153 +       iip->iic_tbase = r_tbase = cpm->dp_addr;
1154 +       iip->iic_rbase = r_rbase = cpm->dp_addr + sizeof(cbd_t)*2;
1155 +
1156 +       iip->iic_tfcr = SMC_EB;
1157 +       iip->iic_rfcr = SMC_EB;
1158 +
1159 +       /* Set maximum receive size.
1160 +       */
1161 +       iip->iic_mrblr = CPM_MAX_READ;
1162 +
1163 +       /* Initialize Tx/Rx parameters.
1164 +       */
1165 +       if (cpm->reloc == 0) {
1166 +               volatile cpm8xx_t *cp = cpm->cp;
1167 +
1168 +               cp->cp_cpcr =
1169 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_INIT_TRX) | CPM_CR_FLG;
1170 +               while (cp->cp_cpcr & CPM_CR_FLG);
1171 +       } else {
1172 +               iip->iic_rbptr = iip->iic_rbase;
1173 +               iip->iic_tbptr = iip->iic_tbase;
1174 +               iip->iic_rstate = 0;
1175 +               iip->iic_tstate = 0;
1176 +       }
1177 +
1178 +       /* Select an arbitrary address.  Just make sure it is unique.
1179 +       */
1180 +       i2c->i2c_i2add = 0xfe;
1181 +
1182 +       /* Make clock run at 60 KHz.
1183 +       */
1184 +       brg = (unsigned char) (bd->bi_intfreq/(32*2*60000) -3);
1185 +       i2c->i2c_i2brg = brg;
1186 +
1187 +       i2c->i2c_i2mod = 0x00; 
1188 +       i2c->i2c_i2com = 0x01; /* Master mode */
1189 +
1190 +       /* Disable interrupts.
1191 +       */
1192 +       i2c->i2c_i2cmr = 0;
1193 +       i2c->i2c_i2cer = 0xff;
1194 +
1195 +       init_waitqueue_head(&iic_wait);
1196 +
1197 +       /* Install interrupt handler.
1198 +       */
1199 +       if (cpm_debug) {
1200 +               printk ("%s[%d] Install ISR for IRQ %d\n",
1201 +                       __func__,__LINE__, CPMVEC_I2C);
1202 +       }
1203 +       (*cpm->setisr)(CPMVEC_I2C, cpm_iic_interrupt, (void *)i2c);
1204 +}
1205 +
1206 +
1207 +static int
1208 +cpm_iic_shutdown(struct i2c_algo_8xx_data *cpm)
1209 +{
1210 +       volatile i2c8xx_t *i2c = cpm->i2c;
1211 +
1212 +       /* Shut down IIC.
1213 +       */
1214 +       i2c->i2c_i2mod &= ~1;
1215 +       i2c->i2c_i2cmr = 0;
1216 +       i2c->i2c_i2cer = 0xff;
1217 +
1218 +       return(0);
1219 +}
1220 +
1221 +static void 
1222 +cpm_reset_iic_params(volatile iic_t *iip)
1223 +{
1224 +       iip->iic_tbase = r_tbase;
1225 +       iip->iic_rbase = r_rbase;
1226 +
1227 +       iip->iic_tfcr = SMC_EB;
1228 +       iip->iic_rfcr = SMC_EB;
1229 +
1230 +       iip->iic_mrblr = CPM_MAX_READ;
1231 +
1232 +       iip->iic_rstate = 0;
1233 +       iip->iic_rdp = 0;
1234 +       iip->iic_rbptr = iip->iic_rbase;
1235 +       iip->iic_rbc = 0;
1236 +       iip->iic_rxtmp = 0;
1237 +       iip->iic_tstate = 0;
1238 +       iip->iic_tdp = 0;
1239 +       iip->iic_tbptr = iip->iic_tbase;
1240 +       iip->iic_tbc = 0;
1241 +       iip->iic_txtmp = 0;
1242 +}
1243 +
1244 +#define BD_SC_NAK              ((ushort)0x0004) /* NAK - did not respond */
1245 +#define BD_SC_OV               ((ushort)0x0002) /* OV - receive overrun */
1246 +#define CPM_CR_CLOSE_RXBD      ((ushort)0x0007)
1247 +
1248 +static void force_close(struct i2c_algo_8xx_data *cpm)
1249 +{
1250 +       volatile i2c8xx_t *i2c = cpm->i2c;
1251 +       if (cpm->reloc == 0) { /* micro code disabled */
1252 +               volatile cpm8xx_t *cp = cpm->cp;
1253 +
1254 +               if (cpm_debug) printk("force_close()\n");
1255 +               cp->cp_cpcr =
1256 +                       mk_cr_cmd(CPM_CR_CH_I2C, CPM_CR_CLOSE_RXBD) |
1257 +                       CPM_CR_FLG;
1258 +
1259 +               while (cp->cp_cpcr & CPM_CR_FLG);
1260 +       }
1261 +       i2c->i2c_i2cmr = 0x00;  /* Disable all interrupts */
1262 +       i2c->i2c_i2cer = 0xff; 
1263 +}
1264 +
1265 +
1266 +/* Read from IIC...
1267 + * abyte = address byte, with r/w flag already set
1268 + */
1269 +static int
1270 +cpm_iic_read(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf, int count)
1271 +{
1272 +       volatile iic_t *iip = cpm->iip;
1273 +       volatile i2c8xx_t *i2c = cpm->i2c;
1274 +       volatile cpm8xx_t *cp = cpm->cp;
1275 +       volatile cbd_t  *tbdf, *rbdf;
1276 +       u_char *tb;
1277 +       unsigned long flags, tmo;
1278 +
1279 +       if (count >= CPM_MAX_READ)
1280 +               return -EINVAL;
1281 +
1282 +       /* check for and use a microcode relocation patch */
1283 +       if (cpm->reloc) {
1284 +               cpm_reset_iic_params(iip);
1285 +       }
1286 +
1287 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1288 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1289 +
1290 +       /* To read, we need an empty buffer of the proper length.
1291 +        * All that is used is the first byte for address, the remainder
1292 +        * is just used for timing (and doesn't really have to exist).
1293 +        */
1294 +       tb = cpm->temp;
1295 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1296 +       tb[0] = abyte;          /* Device address byte w/rw flag */
1297 +
1298 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1299 +
1300 +       if (cpm_debug) printk("cpm_iic_read(abyte=0x%x)\n", abyte);
1301 +
1302 +       tbdf->cbd_bufaddr = __pa(tb);
1303 +       tbdf->cbd_datlen = count + 1;
1304 +       tbdf->cbd_sc =
1305 +               BD_SC_READY | BD_SC_LAST |
1306 +               BD_SC_WRAP | BD_IIC_START;
1307 +
1308 +       iip->iic_mrblr = count +1; /* prevent excessive read, +1
1309 +                                     is needed otherwise will the
1310 +                                     RXB interrupt come too early */
1311 +
1312 +       /* flush will invalidate too. */
1313 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1314 +
1315 +       rbdf->cbd_datlen = 0;
1316 +       rbdf->cbd_bufaddr = __pa(buf);
1317 +       rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP| BD_SC_INTRPT;
1318 +       if(count > 16){
1319 +               /* Chip bug, set enable here */
1320 +               local_irq_save(flags);
1321 +               i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
1322 +               i2c->i2c_i2cer = 0xff;
1323 +               i2c->i2c_i2mod |= 1;    /* Enable */
1324 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1325 +
1326 +               /* Wait for IIC transfer */
1327 +               tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1328 +               local_irq_restore(flags);
1329 +       } else { /* busy wait for small transfers, its faster */
1330 +               i2c->i2c_i2cmr = 0x00;  /* Disable I2C interupts */
1331 +               i2c->i2c_i2cer = 0xff;
1332 +               i2c->i2c_i2mod |= 1;    /* Enable */
1333 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1334 +               tmo = jiffies + 1*HZ; 
1335 +               while(!(i2c->i2c_i2cer & 0x11 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1336 +       }               
1337 +
1338 +       if (signal_pending(current) || !tmo){
1339 +               force_close(cpm);
1340 +               if(cpm_debug) 
1341 +                       printk("IIC read: timeout!\n");
1342 +               return -EIO;
1343 +       }
1344 +#ifdef I2C_CHIP_ERRATA
1345 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1346 +        Disabling I2C too early may cause too short stop condition */
1347 +       udelay(4);
1348 +       i2c->i2c_i2mod &= ~1;
1349 +#endif
1350 +       if (cpm_debug) {
1351 +               printk("tx sc %04x, rx sc %04x\n",
1352 +                      tbdf->cbd_sc, rbdf->cbd_sc);
1353 +       }
1354 +
1355 +       if (tbdf->cbd_sc & BD_SC_READY) {
1356 +               printk("IIC read; complete but tbuf ready\n");
1357 +               force_close(cpm);
1358 +               printk("tx sc %04x, rx sc %04x\n",
1359 +                      tbdf->cbd_sc, rbdf->cbd_sc);
1360 +       }
1361 +
1362 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1363 +               if (cpm_debug)
1364 +                       printk("IIC read; no ack\n");
1365 +               return -EREMOTEIO;
1366 +       }
1367 +
1368 +       if (rbdf->cbd_sc & BD_SC_EMPTY) {
1369 +               /* force_close(cpm); */
1370 +               if (cpm_debug){
1371 +                       printk("IIC read; complete but rbuf empty\n");
1372 +                       printk("tx sc %04x, rx sc %04x\n",
1373 +                              tbdf->cbd_sc, rbdf->cbd_sc);
1374 +               }
1375 +               return -EREMOTEIO;
1376 +       }
1377 +
1378 +       if (rbdf->cbd_sc & BD_SC_OV) {
1379 +               if (cpm_debug)
1380 +                       printk("IIC read; Overrun\n");
1381 +               return -EREMOTEIO;;
1382 +       }
1383 +
1384 +       if (cpm_debug) printk("read %d bytes\n", rbdf->cbd_datlen);
1385 +
1386 +       if (rbdf->cbd_datlen < count) {
1387 +               if (cpm_debug)
1388 +                       printk("IIC read; short, wanted %d got %d\n",
1389 +                              count, rbdf->cbd_datlen);
1390 +               return 0;
1391 +       }
1392 +
1393 +       return count;
1394 +}
1395 +
1396 +/* Write to IIC...
1397 + * addr = address byte, with r/w flag already set
1398 + */
1399 +static int
1400 +cpm_iic_write(struct i2c_algo_8xx_data *cpm, u_char abyte, char *buf,int count)
1401 +{
1402 +       volatile iic_t *iip = cpm->iip;
1403 +       volatile i2c8xx_t *i2c = cpm->i2c;
1404 +       volatile cpm8xx_t *cp = cpm->cp;
1405 +       volatile cbd_t  *tbdf;
1406 +       u_char *tb;
1407 +       unsigned long flags, tmo;
1408 +
1409 +       /* check for and use a microcode relocation patch */
1410 +       if (cpm->reloc) {
1411 +               cpm_reset_iic_params(iip);
1412 +       }
1413 +       tb = cpm->temp;
1414 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1415 +       *tb = abyte;            /* Device address byte w/rw flag */
1416 +
1417 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+1));
1418 +       flush_dcache_range((unsigned long) buf, (unsigned long) (buf+count));
1419 +
1420 +       if (cpm_debug) printk("cpm_iic_write(abyte=0x%x)\n", abyte);
1421 +
1422 +       /* set up 2 descriptors */
1423 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1424 +
1425 +       tbdf[0].cbd_bufaddr = __pa(tb);
1426 +       tbdf[0].cbd_datlen = 1;
1427 +       tbdf[0].cbd_sc = BD_SC_READY | BD_IIC_START;
1428 +
1429 +       tbdf[1].cbd_bufaddr = __pa(buf);
1430 +       tbdf[1].cbd_datlen = count;
1431 +       tbdf[1].cbd_sc = BD_SC_READY | BD_SC_INTRPT | BD_SC_LAST | BD_SC_WRAP;
1432 +
1433 +       if(count > 16){
1434 +               /* Chip bug, set enable here */
1435 +               local_irq_save(flags);
1436 +               i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
1437 +               i2c->i2c_i2cer = 0xff;
1438 +               i2c->i2c_i2mod |= 1;    /* Enable */
1439 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1440 +               
1441 +               /* Wait for IIC transfer */
1442 +               tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1443 +               local_irq_restore(flags);
1444 +       } else {  /* busy wait for small transfers, its faster */
1445 +               i2c->i2c_i2cmr = 0x00;  /* Disable I2C interupts */
1446 +               i2c->i2c_i2cer = 0xff;
1447 +               i2c->i2c_i2mod |= 1;    /* Enable */
1448 +               i2c->i2c_i2com |= 0x80; /* Begin transmission */
1449 +               tmo = jiffies + 1*HZ; 
1450 +               while(!(i2c->i2c_i2cer & 0x12 || time_after(jiffies, tmo))); /* Busy wait, with a timeout */
1451 +       }               
1452 +
1453 +       if (signal_pending(current) || !tmo){
1454 +               force_close(cpm);
1455 +               if(cpm_debug && !tmo) 
1456 +                       printk("IIC write: timeout!\n");
1457 +               return -EIO;
1458 +       }
1459 +       
1460 +#if I2C_CHIP_ERRATA
1461 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1462 +        Disabling I2C too early may cause too short stop condition */
1463 +       udelay(4);
1464 +       i2c->i2c_i2mod &= ~1;
1465 +#endif
1466 +       if (cpm_debug) {
1467 +               printk("tx0 sc %04x, tx1 sc %04x\n",
1468 +                      tbdf[0].cbd_sc, tbdf[1].cbd_sc);
1469 +       }
1470 +
1471 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1472 +               if (cpm_debug) 
1473 +                       printk("IIC write; no ack\n");
1474 +               return 0;
1475 +       }
1476 +         
1477 +       if (tbdf->cbd_sc & BD_SC_READY) {
1478 +               if (cpm_debug)
1479 +                       printk("IIC write; complete but tbuf ready\n");
1480 +               return 0;
1481 +       }
1482 +
1483 +       return count;
1484 +}
1485 +
1486 +/* See if an IIC address exists..
1487 + * addr = 7 bit address, unshifted
1488 + */
1489 +static int
1490 +cpm_iic_tryaddress(struct i2c_algo_8xx_data *cpm, int addr)
1491 +{
1492 +       volatile iic_t *iip = cpm->iip;
1493 +       volatile i2c8xx_t *i2c = cpm->i2c;
1494 +       volatile cpm8xx_t *cp = cpm->cp;
1495 +       volatile cbd_t *tbdf, *rbdf;
1496 +       u_char *tb;
1497 +       unsigned long flags, len, tmo;
1498 +
1499 +       if (cpm_debug > 1)
1500 +               printk("cpm_iic_tryaddress(cpm=%p,addr=%d)\n", cpm, addr);
1501 +
1502 +       /* check for and use a microcode relocation patch */
1503 +       if (cpm->reloc) {
1504 +               cpm_reset_iic_params(iip);
1505 +       }
1506 +
1507 +       if (cpm_debug && addr == 0) {
1508 +               printk("iip %p, dp_addr 0x%x\n", cpm->iip, cpm->dp_addr);
1509 +               printk("iic_tbase %d, r_tbase %d\n", iip->iic_tbase, r_tbase);
1510 +       }
1511 +
1512 +       tbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_tbase];
1513 +       rbdf = (cbd_t *)&cp->cp_dpmem[iip->iic_rbase];
1514 +
1515 +       tb = cpm->temp;
1516 +       tb = (u_char *)(((uint)tb + 15) & ~15);
1517 +
1518 +       /* do a simple read */
1519 +       tb[0] = (addr << 1) | 1;        /* device address (+ read) */
1520 +       len = 2;
1521 +
1522 +       flush_dcache_range((unsigned long) tb, (unsigned long) (tb+2));
1523 +
1524 +       tbdf->cbd_bufaddr = __pa(tb);
1525 +       tbdf->cbd_datlen = len;
1526 +       tbdf->cbd_sc =
1527 +               BD_SC_READY | BD_SC_LAST |
1528 +               BD_SC_WRAP | BD_IIC_START;
1529 +
1530 +       rbdf->cbd_datlen = 0;
1531 +       rbdf->cbd_bufaddr = __pa(tb+2);
1532 +       rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP | BD_SC_INTRPT;
1533 +
1534 +       local_irq_save(flags);
1535 +       i2c->i2c_i2cmr = 0x13;  /* Enable some interupts */
1536 +       i2c->i2c_i2cer = 0xff;
1537 +       i2c->i2c_i2mod |= 1;    /* Enable */
1538 +       i2c->i2c_i2com |= 0x80; /* Begin transmission */
1539 +
1540 +       if (cpm_debug > 1) printk("about to sleep\n");
1541 +
1542 +       /* wait for IIC transfer */
1543 +       tmo = interruptible_sleep_on_timeout(&iic_wait,1*HZ);
1544 +       local_irq_restore(flags);
1545 +
1546 +#ifdef I2C_CHIP_ERRATA
1547 +       /* Chip errata, clear enable. This is not needed on rev D4 CPUs.
1548 +        Disabling I2C too early may cause too short stop condition */
1549 +       udelay(4);
1550 +       i2c->i2c_i2mod &= ~1;
1551 +#endif
1552 +
1553 +       if (signal_pending(current) || !tmo){
1554 +               force_close(cpm);
1555 +               if(cpm_debug && !tmo) 
1556 +                       printk("IIC tryaddress: timeout!\n");
1557 +               return -EIO;
1558 +       }
1559 +
1560 +       if (cpm_debug > 1) printk("back from sleep\n");
1561 +
1562 +       if (tbdf->cbd_sc & BD_SC_NAK) {
1563 +               if (cpm_debug > 1) printk("IIC try; no ack\n");
1564 +               return 0;
1565 +       }
1566 +         
1567 +       if (tbdf->cbd_sc & BD_SC_READY) {
1568 +               printk("IIC try; complete but tbuf ready\n");
1569 +       }
1570 +       
1571 +       return 1;
1572 +}
1573 +
1574 +static int cpm_xfer(struct i2c_adapter *adap,
1575 +                   struct i2c_msg msgs[], 
1576 +                   int num)
1577 +{
1578 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1579 +       struct i2c_msg *pmsg;
1580 +       int i, ret;
1581 +       u_char addr;
1582 +    
1583 +       for (i = 0; i < num; i++) {
1584 +               pmsg = &msgs[i];
1585 +
1586 +               if (cpm_debug)
1587 +                       printk("i2c-algo-8xx.o: "
1588 +                              "#%d addr=0x%x flags=0x%x len=%d\n buf=%lx\n",
1589 +                              i, pmsg->addr, pmsg->flags, pmsg->len, (unsigned long)pmsg->buf);
1590 +
1591 +               addr = pmsg->addr << 1;
1592 +               if (pmsg->flags & I2C_M_RD )
1593 +                       addr |= 1;
1594 +               if (pmsg->flags & I2C_M_REV_DIR_ADDR )
1595 +                       addr ^= 1;
1596 +    
1597 +               if (!(pmsg->flags & I2C_M_NOSTART)) {
1598 +               }
1599 +               if (pmsg->flags & I2C_M_RD ) {
1600 +                       /* read bytes into buffer*/
1601 +                       ret = cpm_iic_read(cpm, addr, pmsg->buf, pmsg->len);
1602 +                       if (cpm_debug)
1603 +                               printk("i2c-algo-8xx.o: read %d bytes\n", ret);
1604 +                       if (ret < pmsg->len ) {
1605 +                               return (ret<0)? ret : -EREMOTEIO;
1606 +                       }
1607 +               } else {
1608 +                       /* write bytes from buffer */
1609 +                       ret = cpm_iic_write(cpm, addr, pmsg->buf, pmsg->len);
1610 +                       if (cpm_debug)
1611 +                               printk("i2c-algo-8xx.o: wrote %d\n", ret);
1612 +                       if (ret < pmsg->len ) {
1613 +                               return (ret<0) ? ret : -EREMOTEIO;
1614 +                       }
1615 +               }
1616 +       }
1617 +       return (num);
1618 +}
1619 +
1620 +static u32 cpm_func(struct i2c_adapter *adap)
1621 +{
1622 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
1623 +              I2C_FUNC_PROTOCOL_MANGLING; 
1624 +}
1625 +
1626 +/* -----exported algorithm data: ------------------------------------- */
1627 +
1628 +static struct i2c_algorithm cpm_algo = {
1629 +       .owner          = THIS_MODULE,
1630 +       .name           = "MPC8xx CPM algorithm",
1631 +       .id             = I2C_ALGO_MPC8XX,
1632 +       .master_xfer    = cpm_xfer,
1633 +       .functionality  = cpm_func,
1634 +};
1635 +
1636 +/* 
1637 + * registering functions to load algorithms at runtime 
1638 + */
1639 +int i2c_8xx_add_bus(struct i2c_adapter *adap)
1640 +{
1641 +       int i;
1642 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1643 +
1644 +       if (cpm_debug)
1645 +               printk("i2c-algo-8xx.o: hw routines for %s registered.\n",
1646 +                      adap->name);
1647 +
1648 +       /* register new adapter to i2c module... */
1649 +
1650 +       adap->id |= cpm_algo.id;
1651 +       adap->algo = &cpm_algo;
1652 +
1653 +       i2c_add_adapter(adap);
1654 +       cpm_iic_init(cpm);
1655 +}
1656 +
1657 +
1658 +int i2c_8xx_del_bus(struct i2c_adapter *adap)
1659 +{
1660 +       struct i2c_algo_8xx_data *cpm = adap->algo_data;
1661 +
1662 +       cpm_iic_shutdown(cpm);
1663 +
1664 +       return i2c_del_adapter(adap);
1665 +}
1666 +
1667 +EXPORT_SYMBOL(i2c_8xx_add_bus);
1668 +EXPORT_SYMBOL(i2c_8xx_del_bus);
1669 +
1670 +MODULE_AUTHOR("Brad Parker <brad@heeltoe.com>");
1671 +MODULE_DESCRIPTION("I2C-Bus MPC8XX algorithm");
1672 +MODULE_LICENSE("GPL");
1673 --- linux-old/include/linux/i2c-algo-8xx.h      Thu Jan  1 00:00:00 1970
1674 +++ linux/include/linux/i2c-algo-8xx.h  Sun Dec  7 11:17:36 2003
1675 @@ -0,0 +1,43 @@
1676 +/* ------------------------------------------------------------------------- */
1677 +/* i2c-algo-8xx.h i2c driver algorithms for MPX8XX CPM                      */
1678 +/*
1679 +    This program is free software; you can redistribute it and/or modify
1680 +    it under the terms of the GNU General Public License as published by
1681 +    the Free Software Foundation; either version 2 of the License, or
1682 +    (at your option) any later version.
1683 +
1684 +    This program is distributed in the hope that it will be useful,
1685 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
1686 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1687 +    GNU General Public License for more details.
1688 +
1689 +    You should have received a copy of the GNU General Public License
1690 +    along with this program; if not, write to the Free Software
1691 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
1692 +/* ------------------------------------------------------------------------- */
1693 +
1694 +/* $Id$ */
1695 +
1696 +#ifndef _LINUX_I2C_ALGO_8XX_H
1697 +#define _LINUX_I2C_ALGO_8XX_H
1698 +
1699 +#include "asm/commproc.h"
1700 +
1701 +struct i2c_algo_8xx_data {
1702 +       uint dp_addr;
1703 +       int reloc;
1704 +       volatile i2c8xx_t *i2c;
1705 +       volatile iic_t  *iip;
1706 +       volatile cpm8xx_t *cp;
1707 +
1708 +       int     (*setisr) (int irq,
1709 +                          void (*func)(void *, void *),
1710 +                          void *data);
1711 +
1712 +       u_char  temp[513];
1713 +};
1714 +
1715 +int i2c_8xx_add_bus(struct i2c_adapter *);
1716 +int i2c_8xx_del_bus(struct i2c_adapter *);
1717 +
1718 +#endif /* _LINUX_I2C_ALGO_8XX_H */
1719 --- linux-old/drivers/i2c/i2c-algo-bit.c        Wed Aug 27 16:11:46 2003
1720 +++ linux/drivers/i2c/i2c-algo-bit.c    Sun Dec  7 11:17:37 2003
1721 @@ -18,25 +18,22 @@
1722      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
1723  /* ------------------------------------------------------------------------- */
1724  
1725 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
1726 -   Frodo Looijaard <frodol@dds.nl> */
1727 +/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
1728 +   <kmalkki@cc.hut.fi> and Jean Delvare <khali@linux-fr.org> */
1729  
1730 -/* $Id$ */
1731 +/* $Id$ */
1732  
1733  #include <linux/kernel.h>
1734  #include <linux/module.h>
1735  #include <linux/delay.h>
1736  #include <linux/slab.h>
1737 -#include <linux/version.h>
1738  #include <linux/init.h>
1739 -#include <asm/uaccess.h>
1740 -#include <linux/ioport.h>
1741  #include <linux/errno.h>
1742  #include <linux/sched.h>
1743 -
1744  #include <linux/i2c.h>
1745  #include <linux/i2c-algo-bit.h>
1746  
1747 +
1748  /* ----- global defines ----------------------------------------------- */
1749  #define DEB(x) if (i2c_debug>=1) x;
1750  #define DEB2(x) if (i2c_debug>=2) x;
1751 @@ -44,27 +41,13 @@
1752  #define DEBPROTO(x) if (i2c_debug>=9) { x; }
1753         /* debug the protocol by showing transferred bits */
1754  
1755 -/* debugging - slow down transfer to have a look at the data ..        */
1756 -/* I use this with two leds&resistors, each one connected to sda,scl   */
1757 -/* respectively. This makes sure that the algorithm works. Some chips   */
1758 -/* might not like this, as they have an internal timeout of some mils  */
1759 -/*
1760 -#define SLO_IO      jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\
1761 -                        if (need_resched) schedule();
1762 -*/
1763 -
1764  
1765  /* ----- global variables ---------------------------------------------        */
1766  
1767 -#ifdef SLO_IO
1768 -       int jif;
1769 -#endif
1770 -
1771  /* module parameters:
1772   */
1773  static int i2c_debug;
1774  static int bit_test;   /* see if the line-setting functions work       */
1775 -static int bit_scan;   /* have a look at what's hanging 'round         */
1776  
1777  /* --- setting states on the bus with the right timing: ---------------        */
1778  
1779 @@ -89,9 +72,6 @@
1780  {
1781         setscl(adap,0);
1782         udelay(adap->udelay);
1783 -#ifdef SLO_IO
1784 -       SLO_IO
1785 -#endif
1786  }
1787  
1788  /*
1789 @@ -100,33 +80,35 @@
1790   */
1791  static inline int sclhi(struct i2c_algo_bit_data *adap)
1792  {
1793 -       int start=jiffies;
1794 +       int start;
1795  
1796         setscl(adap,1);
1797  
1798 -       udelay(adap->udelay);
1799 -
1800         /* Not all adapters have scl sense line... */
1801 -       if (adap->getscl == NULL )
1802 +       if (adap->getscl == NULL ) {
1803 +               udelay(adap->udelay);
1804                 return 0;
1805 +       }
1806  
1807 -       while (! getscl(adap) ) {       
1808 +       start=jiffies;
1809 +       while (! getscl(adap) ) {       
1810                 /* the hw knows how to read the clock line,
1811                  * so we wait until it actually gets high.
1812                  * This is safer as some chips may hold it low
1813                  * while they are processing data internally. 
1814                  */
1815 -               setscl(adap,1);
1816                 if (time_after_eq(jiffies, start+adap->timeout)) {
1817                         return -ETIMEDOUT;
1818                 }
1819 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1820                 if (current->need_resched)
1821                         schedule();
1822 -       }
1823 -       DEBSTAT(printk("needed %ld jiffies\n", jiffies-start));
1824 -#ifdef SLO_IO
1825 -       SLO_IO
1826 +#else
1827 +               cond_resched();
1828  #endif
1829 +       }
1830 +       DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start));
1831 +       udelay(adap->udelay);
1832         return 0;
1833  } 
1834  
1835 @@ -145,7 +127,7 @@
1836         /* scl, sda may not be high */
1837         DEBPROTO(printk(" Sr "));
1838         setsda(adap,1);
1839 -       setscl(adap,1);
1840 +       sclhi(adap);
1841         udelay(adap->udelay);
1842         
1843         sdalo(adap);
1844 @@ -179,14 +161,14 @@
1845         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1846  
1847         /* assert: scl is low */
1848 -       DEB2(printk(" i2c_outb:%2.2X\n",c&0xff));
1849         for ( i=7 ; i>=0 ; i-- ) {
1850                 sb = c & ( 1 << i );
1851                 setsda(adap,sb);
1852                 udelay(adap->udelay);
1853 -               DEBPROTO(printk("%d",sb!=0));
1854 +               DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
1855                 if (sclhi(adap)<0) { /* timed out */
1856                         sdahi(adap); /* we don't want to block the net */
1857 +                       DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i));
1858                         return -ETIMEDOUT;
1859                 };
1860                 /* do arbitration here: 
1861 @@ -197,14 +179,15 @@
1862         }
1863         sdahi(adap);
1864         if (sclhi(adap)<0){ /* timeout */
1865 -               return -ETIMEDOUT;
1866 +           DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff));
1867 +           return -ETIMEDOUT;
1868         };
1869         /* read ack: SDA should be pulled down by slave */
1870         ack=getsda(adap);       /* ack: sda is pulled low ->success.     */
1871 -       DEB2(printk(" i2c_outb: getsda() =  0x%2.2x\n", ~ack ));
1872 +       DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack));
1873  
1874 -       DEBPROTO( printk("[%2.2x]",c&0xff) );
1875 -       DEBPROTO(if (0==ack){ printk(" A ");} else printk(" NA ") );
1876 +       DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
1877 +       DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
1878         scllo(adap);
1879         return 0==ack;          /* return 1 if device acked      */
1880         /* assert: scl is low (sda undef) */
1881 @@ -220,11 +203,10 @@
1882         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
1883  
1884         /* assert: scl is low */
1885 -       DEB2(printk("i2c_inb.\n"));
1886 -
1887         sdahi(adap);
1888         for (i=0;i<8;i++) {
1889                 if (sclhi(adap)<0) { /* timeout */
1890 +                       DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i));
1891                         return -ETIMEDOUT;
1892                 };
1893                 indata *= 2;
1894 @@ -233,7 +215,9 @@
1895                 scllo(adap);
1896         }
1897         /* assert: scl is low */
1898 -       DEBPROTO(printk(" %2.2x", indata & 0xff));
1899 +       DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff));
1900 +
1901 +       DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
1902         return (int) (indata & 0xff);
1903  }
1904  
1905 @@ -243,71 +227,75 @@
1906   */
1907  static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
1908         int scl,sda;
1909 +
1910 +       if (adap->getscl==NULL)
1911 +               printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, "
1912 +                       "SCL is not readable.\n");
1913 +
1914         sda=getsda(adap);
1915 -       if (adap->getscl==NULL) {
1916 -               printk("i2c-algo-bit.o: Warning: Adapter can't read from clock line - skipping test.\n");
1917 -               return 0;               
1918 -       }
1919 -       scl=getscl(adap);
1920 -       printk("i2c-algo-bit.o: Adapter: %s scl: %d  sda: %d -- testing...\n",
1921 -              name,getscl(adap),getsda(adap));
1922 +       scl=(adap->getscl==NULL?1:getscl(adap));
1923 +       printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
1924         if (!scl || !sda ) {
1925 -               printk("i2c-algo-bit.o: %s seems to be busy.\n",name);
1926 +               printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name);
1927                 goto bailout;
1928         }
1929 +
1930         sdalo(adap);
1931 -       printk("i2c-algo-bit.o:1 scl: %d  sda: %d \n",getscl(adap),
1932 -              getsda(adap));
1933 -       if ( 0 != getsda(adap) ) {
1934 -               printk("i2c-algo-bit.o: %s SDA stuck high!\n",name);
1935 -               sdahi(adap);
1936 +       sda=getsda(adap);
1937 +       scl=(adap->getscl==NULL?1:getscl(adap));
1938 +       printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
1939 +       if ( 0 != sda ) {
1940 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n");
1941                 goto bailout;
1942         }
1943 -       if ( 0 == getscl(adap) ) {
1944 -               printk("i2c-algo-bit.o: %s SCL unexpected low while pulling SDA low!\n",
1945 -                       name);
1946 +       if ( 0 == scl ) {
1947 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1948 +                       "while pulling SDA low!\n");
1949                 goto bailout;
1950         }               
1951 +
1952         sdahi(adap);
1953 -       printk("i2c-algo-bit.o:2 scl: %d  sda: %d \n",getscl(adap),
1954 -              getsda(adap));
1955 -       if ( 0 == getsda(adap) ) {
1956 -               printk("i2c-algo-bit.o: %s SDA stuck low!\n",name);
1957 -               sdahi(adap);
1958 +       sda=getsda(adap);
1959 +       scl=(adap->getscl==NULL?1:getscl(adap));
1960 +       printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
1961 +       if ( 0 == sda ) {
1962 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n");
1963                 goto bailout;
1964         }
1965 -       if ( 0 == getscl(adap) ) {
1966 -               printk("i2c-algo-bit.o: %s SCL unexpected low while SDA high!\n",
1967 -                      name);
1968 -       goto bailout;
1969 +       if ( 0 == scl ) {
1970 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low "
1971 +                       "while pulling SDA high!\n");
1972 +               goto bailout;
1973         }
1974 +
1975         scllo(adap);
1976 -       printk("i2c-algo-bit.o:3 scl: %d  sda: %d \n",getscl(adap),
1977 -              getsda(adap));
1978 -       if ( 0 != getscl(adap) ) {
1979 -               printk("i2c-algo-bit.o: %s SCL stuck high!\n",name);
1980 -               sclhi(adap);
1981 +       sda=getsda(adap);
1982 +       scl=(adap->getscl==NULL?0:getscl(adap));
1983 +       printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
1984 +       if ( 0 != scl ) {
1985 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n");
1986                 goto bailout;
1987         }
1988 -       if ( 0 == getsda(adap) ) {
1989 -               printk("i2c-algo-bit.o: %s SDA unexpected low while pulling SCL low!\n",
1990 -                       name);
1991 +       if ( 0 == sda ) {
1992 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
1993 +                       "while pulling SCL low!\n");
1994                 goto bailout;
1995         }
1996 +       
1997         sclhi(adap);
1998 -       printk("i2c-algo-bit.o:4 scl: %d  sda: %d \n",getscl(adap),
1999 -              getsda(adap));
2000 -       if ( 0 == getscl(adap) ) {
2001 -               printk("i2c-algo-bit.o: %s SCL stuck low!\n",name);
2002 -               sclhi(adap);
2003 +       sda=getsda(adap);
2004 +       scl=(adap->getscl==NULL?1:getscl(adap));
2005 +       printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
2006 +       if ( 0 == scl ) {
2007 +               printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n");
2008                 goto bailout;
2009         }
2010 -       if ( 0 == getsda(adap) ) {
2011 -               printk("i2c-algo-bit.o: %s SDA unexpected low while SCL high!\n",
2012 -                       name);
2013 +       if ( 0 == sda ) {
2014 +               printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low "
2015 +                       "while pulling SCL high!\n");
2016                 goto bailout;
2017         }
2018 -       printk("i2c-algo-bit.o: %s passed test.\n",name);
2019 +       printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name);
2020         return 0;
2021  bailout:
2022         sdahi(adap);
2023 @@ -341,30 +329,35 @@
2024                 i2c_start(adap);
2025                 udelay(adap->udelay);
2026         }
2027 -       DEB2(if (i) printk("i2c-algo-bit.o: needed %d retries for %d\n",
2028 -                          i,addr));
2029 +       DEB2(if (i)
2030 +            printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n",
2031 +                   i+1, addr & 1 ? "read" : "write", addr>>1,
2032 +                   ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" )
2033 +           );
2034         return ret;
2035  }
2036  
2037 -static int sendbytes(struct i2c_adapter *i2c_adap,const char *buf, int count)
2038 +static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
2039  {
2040         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2041         char c;
2042 -       const char *temp = buf;
2043 +       const char *temp = msg->buf;
2044 +       int count = msg->len;
2045 +       unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 
2046         int retval;
2047         int wrcount=0;
2048  
2049         while (count > 0) {
2050                 c = *temp;
2051 -               DEB2(printk("i2c-algo-bit.o: %s i2c_write: writing %2.2X\n",
2052 +               DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n",
2053                             i2c_adap->name, c&0xff));
2054                 retval = i2c_outb(i2c_adap,c);
2055 -               if (retval>0) {
2056 +               if ((retval>0) || (nak_ok && (retval==0)))  { /* ok or ignored NAK */
2057                         count--; 
2058                         temp++;
2059                         wrcount++;
2060                 } else { /* arbitration or no acknowledge */
2061 -                       printk("i2c-algo-bit.o: %s i2c_write: error - bailout.\n",
2062 +                       printk(KERN_ERR "i2c-algo-bit.o: %s sendbytes: error - bailout.\n",
2063                                i2c_adap->name);
2064                         i2c_stop(adap);
2065                         return (retval<0)? retval : -EFAULT;
2066 @@ -378,12 +371,13 @@
2067         return wrcount;
2068  }
2069  
2070 -static inline int readbytes(struct i2c_adapter *i2c_adap,char *buf,int count)
2071 +static inline int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
2072  {
2073 -       char *temp = buf;
2074         int inval;
2075         int rdcount=0;          /* counts bytes read */
2076         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2077 +       char *temp = msg->buf;
2078 +       int count = msg->len;
2079  
2080         while (count > 0) {
2081                 inval = i2c_inb(i2c_adap);
2082 @@ -392,7 +386,7 @@
2083                         *temp = inval;
2084                         rdcount++;
2085                 } else {   /* read timed out */
2086 -                       printk("i2c-algo-bit.o: i2c_read: i2c_inb timed out.\n");
2087 +                       printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n");
2088                         break;
2089                 }
2090  
2091 @@ -405,7 +399,7 @@
2092                 }
2093                 if (sclhi(adap)<0) {    /* timeout */
2094                         sdahi(adap);
2095 -                       printk("i2c-algo-bit.o: i2c_read: Timeout at ack\n");
2096 +                       printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n");
2097                         return -ETIMEDOUT;
2098                 };
2099                 scllo(adap);
2100 @@ -420,33 +414,36 @@
2101   * try_address) and transmits the address in the necessary format to handle
2102   * reads, writes as well as 10bit-addresses.
2103   * returns:
2104 - *  0 everything went okay, the chip ack'ed
2105 + *  0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
2106   * -x an error occurred (like: -EREMOTEIO if the device did not answer, or
2107   *     -ETIMEDOUT, for example if the lines are stuck...) 
2108   */
2109 -static inline int bit_doAddress(struct i2c_adapter *i2c_adap,
2110 -                                struct i2c_msg *msg, int retries) 
2111 +static inline int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 
2112  {
2113         unsigned short flags = msg->flags;
2114 +       unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
2115         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2116  
2117         unsigned char addr;
2118 -       int ret;
2119 +       int ret, retries;
2120 +
2121 +       retries = nak_ok ? 0 : i2c_adap->retries;
2122 +       
2123         if ( (flags & I2C_M_TEN)  ) { 
2124                 /* a ten bit address */
2125                 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
2126 -               DEB2(printk("addr0: %d\n",addr));
2127 +               DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
2128                 /* try extended address code...*/
2129                 ret = try_address(i2c_adap, addr, retries);
2130 -               if (ret!=1) {
2131 -                       printk("died at extended address code.\n");
2132 +               if ((ret != 1) && !nak_ok)  {
2133 +                       printk(KERN_ERR "died at extended address code.\n");
2134                         return -EREMOTEIO;
2135                 }
2136                 /* the remaining 8 bit address */
2137                 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
2138 -               if (ret != 1) {
2139 +               if ((ret != 1) && !nak_ok) {
2140                         /* the chip did not ack / xmission error occurred */
2141 -                       printk("died at 2nd address code.\n");
2142 +                       printk(KERN_ERR "died at 2nd address code.\n");
2143                         return -EREMOTEIO;
2144                 }
2145                 if ( flags & I2C_M_RD ) {
2146 @@ -454,8 +451,8 @@
2147                         /* okay, now switch into reading mode */
2148                         addr |= 0x01;
2149                         ret = try_address(i2c_adap, addr, retries);
2150 -                       if (ret!=1) {
2151 -                               printk("died at extended address code.\n");
2152 +                       if ((ret!=1) && !nak_ok) {
2153 +                               printk(KERN_ERR "died at extended address code.\n");
2154                                 return -EREMOTEIO;
2155                         }
2156                 }
2157 @@ -466,10 +463,10 @@
2158                 if (flags & I2C_M_REV_DIR_ADDR )
2159                         addr ^= 1;
2160                 ret = try_address(i2c_adap, addr, retries);
2161 -               if (ret!=1) {
2162 +               if ((ret!=1) && !nak_ok)
2163                         return -EREMOTEIO;
2164 -               }
2165         }
2166 +
2167         return 0;
2168  }
2169  
2170 @@ -480,32 +477,34 @@
2171         struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
2172         
2173         int i,ret;
2174 +       unsigned short nak_ok;
2175  
2176         i2c_start(adap);
2177         for (i=0;i<num;i++) {
2178                 pmsg = &msgs[i];
2179 +               nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 
2180                 if (!(pmsg->flags & I2C_M_NOSTART)) {
2181                         if (i) {
2182                                 i2c_repstart(adap);
2183                         }
2184 -                       ret = bit_doAddress(i2c_adap,pmsg,i2c_adap->retries);
2185 -                       if (ret != 0) {
2186 -                               DEB2(printk("i2c-algo-bit.o: NAK from device adr %#2x msg #%d\n"
2187 -                                      ,msgs[i].addr,i));
2188 -                               return (ret<0) ? ret : -EREMOTEIO;
2189 +                       ret = bit_doAddress(i2c_adap, pmsg);
2190 +                       if ((ret != 0) && !nak_ok) {
2191 +                           DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n"
2192 +                                       ,msgs[i].addr,i));
2193 +                           return (ret<0) ? ret : -EREMOTEIO;
2194                         }
2195                 }
2196                 if (pmsg->flags & I2C_M_RD ) {
2197                         /* read bytes into buffer*/
2198 -                       ret = readbytes(i2c_adap,pmsg->buf,pmsg->len);
2199 -                       DEB2(printk("i2c-algo-bit.o: read %d bytes.\n",ret));
2200 +                       ret = readbytes(i2c_adap, pmsg);
2201 +                       DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret));
2202                         if (ret < pmsg->len ) {
2203                                 return (ret<0)? ret : -EREMOTEIO;
2204                         }
2205                 } else {
2206                         /* write bytes from buffer */
2207 -                       ret = sendbytes(i2c_adap,pmsg->buf,pmsg->len);
2208 -                       DEB2(printk("i2c-algo-bit.o: wrote %d bytes.\n",ret));
2209 +                       ret = sendbytes(i2c_adap, pmsg);
2210 +                       DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret));
2211                         if (ret < pmsg->len ) {
2212                                 return (ret<0) ? ret : -EREMOTEIO;
2213                         }
2214 @@ -515,13 +514,7 @@
2215         return num;
2216  }
2217  
2218 -static int algo_control(struct i2c_adapter *adapter, 
2219 -       unsigned int cmd, unsigned long arg)
2220 -{
2221 -       return 0;
2222 -}
2223 -
2224 -static u32 bit_func(struct i2c_adapter *adap)
2225 +static u32 bit_func(struct i2c_adapter *i2c_adap)
2226  {
2227         return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
2228                I2C_FUNC_PROTOCOL_MANGLING;
2229 @@ -531,14 +524,11 @@
2230  /* -----exported algorithm data: ------------------------------------- */
2231  
2232  static struct i2c_algorithm i2c_bit_algo = {
2233 -       "Bit-shift algorithm",
2234 -       I2C_ALGO_BIT,
2235 -       bit_xfer,
2236 -       NULL,
2237 -       NULL,                           /* slave_xmit           */
2238 -       NULL,                           /* slave_recv           */
2239 -       algo_control,                   /* ioctl                */
2240 -       bit_func,                       /* functionality        */
2241 +       .owner          = THIS_MODULE,
2242 +       .name           = "Bit-shift algorithm",
2243 +       .id             = I2C_ALGO_BIT,
2244 +       .master_xfer    = bit_xfer,
2245 +       .functionality  = bit_func,
2246  };
2247  
2248  /* 
2249 @@ -546,7 +536,6 @@
2250   */
2251  int i2c_bit_add_bus(struct i2c_adapter *adap)
2252  {
2253 -       int i;
2254         struct i2c_algo_bit_data *bit_adap = adap->algo_data;
2255  
2256         if (bit_test) {
2257 @@ -555,7 +544,7 @@
2258                         return -ENODEV;
2259         }
2260  
2261 -       DEB2(printk("i2c-algo-bit.o: hw routines for %s registered.\n",
2262 +       DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: hw routines for %s registered.\n",
2263                     adap->name));
2264  
2265         /* register new adapter to i2c module... */
2266 @@ -566,78 +555,26 @@
2267         adap->timeout = 100;    /* default values, should       */
2268         adap->retries = 3;      /* be replaced by defines       */
2269  
2270 -       /* scan bus */
2271 -       if (bit_scan) {
2272 -               int ack;
2273 -               printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n",
2274 -                      adap->name);
2275 -               for (i = 0x00; i < 0xff; i+=2) {
2276 -                       i2c_start(bit_adap);
2277 -                       ack = i2c_outb(adap,i);
2278 -                       i2c_stop(bit_adap);
2279 -                       if (ack>0) {
2280 -                               printk("(%02x)",i>>1); 
2281 -                       } else 
2282 -                               printk("."); 
2283 -               }
2284 -               printk("\n");
2285 -       }
2286 -
2287 -#ifdef MODULE
2288 -       MOD_INC_USE_COUNT;
2289 -#endif
2290         i2c_add_adapter(adap);
2291 -
2292         return 0;
2293  }
2294  
2295  
2296  int i2c_bit_del_bus(struct i2c_adapter *adap)
2297  {
2298 -       int res;
2299 -
2300 -       if ((res = i2c_del_adapter(adap)) < 0)
2301 -               return res;
2302 -
2303 -       DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name));
2304 -
2305 -#ifdef MODULE
2306 -       MOD_DEC_USE_COUNT;
2307 -#endif
2308 -       return 0;
2309 -}
2310 -
2311 -int __init i2c_algo_bit_init (void)
2312 -{
2313 -       printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n");
2314 -       return 0;
2315 +       return i2c_del_adapter(adap);
2316  }
2317  
2318 -
2319 -
2320  EXPORT_SYMBOL(i2c_bit_add_bus);
2321  EXPORT_SYMBOL(i2c_bit_del_bus);
2322  
2323 -#ifdef MODULE
2324  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
2325  MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
2326  MODULE_LICENSE("GPL");
2327  
2328  MODULE_PARM(bit_test, "i");
2329 -MODULE_PARM(bit_scan, "i");
2330  MODULE_PARM(i2c_debug,"i");
2331  
2332  MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
2333 -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
2334  MODULE_PARM_DESC(i2c_debug,
2335 -            "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2336 -
2337 -int init_module(void) 
2338 -{
2339 -       return i2c_algo_bit_init();
2340 -}
2341 -
2342 -void cleanup_module(void) 
2343 -{
2344 -}
2345 -#endif
2346 +                "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
2347 --- linux-old/include/linux/i2c-algo-bit.h      Mon Dec 11 21:15:41 2000
2348 +++ linux/include/linux/i2c-algo-bit.h  Sun Dec  7 11:17:37 2003
2349 @@ -21,12 +21,10 @@
2350  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
2351     Frodo Looijaard <frodol@dds.nl> */
2352  
2353 -/* $Id$ */
2354 +/* $Id$ */
2355  
2356 -#ifndef I2C_ALGO_BIT_H
2357 -#define I2C_ALGO_BIT_H 1
2358 -
2359 -#include <linux/i2c.h>
2360 +#ifndef _LINUX_I2C_ALGO_BIT_H
2361 +#define _LINUX_I2C_ALGO_BIT_H
2362  
2363  /* --- Defines for bit-adapters ---------------------------------------        */
2364  /*
2365 @@ -42,9 +40,10 @@
2366         int  (*getscl) (void *data);
2367  
2368         /* local settings */
2369 -       int udelay;
2370 -       int mdelay;
2371 -       int timeout;
2372 +       int udelay;             /* half-clock-cycle time in microsecs */
2373 +                               /* i.e. clock is (500 / udelay) KHz */
2374 +       int mdelay;             /* in millisecs, unused */
2375 +       int timeout;            /* in jiffies */
2376  };
2377  
2378  #define I2C_BIT_ADAP_MAX       16
2379 @@ -52,4 +51,4 @@
2380  int i2c_bit_add_bus(struct i2c_adapter *);
2381  int i2c_bit_del_bus(struct i2c_adapter *);
2382  
2383 -#endif /* I2C_ALGO_BIT_H */
2384 +#endif /* _LINUX_I2C_ALGO_BIT_H */
2385 --- linux-old/drivers/i2c/i2c-algo-ibm_ocp.c    Thu Jan  1 00:00:00 1970
2386 +++ linux/drivers/i2c/i2c-algo-ibm_ocp.c        Sun Dec  7 11:17:38 2003
2387 @@ -0,0 +1,901 @@
2388 +/*
2389 +   -------------------------------------------------------------------------
2390 +   i2c-algo-ibm_ocp.c i2c driver algorithms for IBM PPC 405 adapters       
2391 +   -------------------------------------------------------------------------
2392 +      
2393 +   Ian DaSilva, MontaVista Software, Inc.
2394 +   idasilva@mvista.com or source@mvista.com
2395 +
2396 +   Copyright 2000 MontaVista Software Inc.
2397 +
2398 +   Changes made to support the IIC peripheral on the IBM PPC 405
2399 +
2400 +
2401 +   ---------------------------------------------------------------------------
2402 +   This file was highly leveraged from i2c-algo-pcf.c, which was created
2403 +   by Simon G. Vogl and Hans Berglund:
2404 +
2405 +
2406 +     Copyright (C) 1995-1997 Simon G. Vogl
2407 +                   1998-2000 Hans Berglund
2408 +
2409 +   With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and 
2410 +   Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
2411 +   <mbailey@littlefeet-inc.com>
2412 +
2413 +
2414 +    This program is free software; you can redistribute it and/or modify
2415 +    it under the terms of the GNU General Public License as published by
2416 +    the Free Software Foundation; either version 2 of the License, or
2417 +    (at your option) any later version.
2418 +
2419 +    This program is distributed in the hope that it will be useful,
2420 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
2421 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2422 +    GNU General Public License for more details.
2423 +
2424 +    You should have received a copy of the GNU General Public License
2425 +    along with this program; if not, write to the Free Software
2426 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2427 +   ---------------------------------------------------------------------------
2428 +
2429 +   History: 01/20/12 - Armin
2430 +       akuster@mvista.com
2431 +       ported up to 2.4.16+    
2432 +
2433 +   Version 02/03/25 - Armin
2434 +       converted to ocp format
2435 +       removed commented out or #if 0 code
2436 +       added Gérard Basler's fix to iic_combined_transaction() such that it 
2437 +       returns the number of successfully completed transfers .
2438 +*/
2439 +
2440 +
2441 +#include <linux/kernel.h>
2442 +#include <linux/module.h>
2443 +#include <linux/delay.h>
2444 +#include <linux/slab.h>
2445 +#include <linux/init.h>
2446 +#include <linux/errno.h>
2447 +#include <linux/sched.h>
2448 +#include <linux/i2c.h>
2449 +#include <linux/i2c-algo-ibm_ocp.h>
2450 +#include <asm/ocp.h>
2451 +
2452 +
2453 +/* ----- global defines ----------------------------------------------- */
2454 +#define DEB(x) if (i2c_debug>=1) x
2455 +#define DEB2(x) if (i2c_debug>=2) x
2456 +#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
2457 +#define DEBPROTO(x) if (i2c_debug>=9) x;
2458 +       /* debug the protocol by showing transferred bits */
2459 +#define DEF_TIMEOUT 5
2460 +
2461 +
2462 +/* ----- global variables ---------------------------------------------        */
2463 +
2464 +
2465 +/* module parameters:
2466 + */
2467 +static int i2c_debug=0;
2468 +
2469 +/* --- setting states on the bus with the right timing: ---------------        */
2470 +
2471 +#define iic_outb(adap, reg, val) adap->setiic(adap->data, (int) &(reg), val)
2472 +#define iic_inb(adap, reg) adap->getiic(adap->data, (int) &(reg))
2473 +
2474 +#define IICO_I2C_SDAHIGH       0x0780
2475 +#define IICO_I2C_SDALOW                0x0781
2476 +#define IICO_I2C_SCLHIGH       0x0782
2477 +#define IICO_I2C_SCLLOW                0x0783
2478 +#define IICO_I2C_LINEREAD      0x0784
2479 +
2480 +#define IIC_SINGLE_XFER                0
2481 +#define IIC_COMBINED_XFER      1
2482 +
2483 +#define IIC_ERR_LOST_ARB        -2
2484 +#define IIC_ERR_INCOMPLETE_XFR  -3
2485 +#define IIC_ERR_NACK            -1
2486 +
2487 +/* --- other auxiliary functions --------------------------------------        */
2488 +
2489 +
2490 +//
2491 +// Description: Puts this process to sleep for a period equal to timeout 
2492 +//
2493 +static inline void iic_sleep(unsigned long timeout)
2494 +{
2495 +       schedule_timeout( timeout * HZ);
2496 +}
2497 +
2498 +
2499 +//
2500 +// Description: This performs the IBM PPC 405 IIC initialization sequence
2501 +// as described in the PPC405GP data book.
2502 +//
2503 +static int iic_init (struct i2c_algo_iic_data *adap)
2504 +{
2505 +       struct iic_regs *iic;   
2506 +       struct iic_ibm *adap_priv_data = adap->data;
2507 +       unsigned short  retval;
2508 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2509 +
2510 +        /* Clear master low master address */
2511 +        iic_outb(adap,iic->lmadr, 0);
2512 +
2513 +        /* Clear high master address */
2514 +        iic_outb(adap,iic->hmadr, 0);
2515 +
2516 +        /* Clear low slave address */
2517 +        iic_outb(adap,iic->lsadr, 0);
2518 +
2519 +        /* Clear high slave address */
2520 +        iic_outb(adap,iic->hsadr, 0);
2521 +
2522 +        /* Clear status */
2523 +        iic_outb(adap,iic->sts, 0x0a);
2524 +
2525 +        /* Clear extended status */
2526 +        iic_outb(adap,iic->extsts, 0x8f);
2527 +
2528 +        /* Set clock division */
2529 +        iic_outb(adap,iic->clkdiv, 0x04);
2530 +
2531 +       retval = iic_inb(adap, iic->clkdiv);
2532 +       DEB(printk("iic_init: CLKDIV register = %x\n", retval));
2533 +
2534 +        /* Enable interrupts on Requested Master Transfer Complete */
2535 +        iic_outb(adap,iic->intmsk, 0x01);
2536 +
2537 +        /* Clear transfer count */
2538 +        iic_outb(adap,iic->xfrcnt, 0x0);
2539 +
2540 +        /* Clear extended control and status */
2541 +        iic_outb(adap,iic->xtcntlss, 0xf0);
2542 +
2543 +        /* Set mode control (flush master data buf, enable hold SCL, exit */
2544 +        /* unknown state.                                                 */
2545 +        iic_outb(adap,iic->mdcntl, 0x47);
2546 +
2547 +        /* Clear control register */
2548 +        iic_outb(adap,iic->cntl, 0x0);
2549 +
2550 +        DEB2(printk(KERN_DEBUG "iic_init: Initialized IIC on PPC 405\n"));
2551 +        return 0;
2552 +}
2553 +
2554 +
2555 +//
2556 +// Description: After we issue a transaction on the IIC bus, this function
2557 +// is called.  It puts this process to sleep until we get an interrupt from
2558 +// from the controller telling us that the transaction we requested in complete.
2559 +//
2560 +static int wait_for_pin(struct i2c_algo_iic_data *adap, int *status) 
2561 +{
2562 +
2563 +       int timeout = DEF_TIMEOUT;
2564 +       int retval;
2565 +       struct iic_regs *iic;
2566 +       struct iic_ibm *adap_priv_data = adap->data;
2567 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2568 +
2569 +
2570 +       *status = iic_inb(adap, iic->sts);
2571 +#ifndef STUB_I2C
2572 +
2573 +       while (timeout-- && (*status & 0x01)) {
2574 +          adap->waitforpin(adap->data);
2575 +          *status = iic_inb(adap, iic->sts);
2576 +       }
2577 +#endif
2578 +       if (timeout <= 0) {
2579 +          /* Issue stop signal on the bus, and force an interrupt */
2580 +           retval = iic_inb(adap, iic->cntl);
2581 +           iic_outb(adap, iic->cntl, retval | 0x80);
2582 +           /* Clear status register */
2583 +          iic_outb(adap, iic->sts, 0x0a);
2584 +          /* Exit unknown bus state */
2585 +          retval = iic_inb(adap, iic->mdcntl);
2586 +          iic_outb(adap, iic->mdcntl, (retval | 0x02));
2587 +
2588 +          // Check the status of the controller.  Does it still see a
2589 +          // pending transfer, even though we've tried to stop any
2590 +          // ongoing transaction?
2591 +           retval = iic_inb(adap, iic->sts);
2592 +           retval = retval & 0x01;
2593 +           if(retval) {
2594 +             // The iic controller is hosed.  It is not responding to any
2595 +             // of our commands.  We have already tried to force it into
2596 +             // a known state, but it has not worked.  Our only choice now
2597 +             // is a soft reset, which will clear all registers, and force
2598 +             // us to re-initialize the controller.
2599 +             /* Soft reset */
2600 +              iic_outb(adap, iic->xtcntlss, 0x01);
2601 +              udelay(500);
2602 +              iic_init(adap);
2603 +             /* Is the pending transfer bit in the sts reg finally cleared? */
2604 +              retval = iic_inb(adap, iic->sts);
2605 +              retval = retval & 0x01;
2606 +              if(retval) {
2607 +                 printk(KERN_CRIT "The IIC Controller is hosed.  A processor reset is required\n");
2608 +              }
2609 +             // For some reason, even though the interrupt bit in this
2610 +             // register was set during iic_init, it didn't take.  We
2611 +             // need to set it again.  Don't ask me why....this is just what
2612 +             // I saw when testing timeouts.
2613 +              iic_outb(adap, iic->intmsk, 0x01);
2614 +           }
2615 +          return(-1);
2616 +       }
2617 +       else
2618 +          return(0);
2619 +}
2620 +
2621 +
2622 +//------------------------------------
2623 +// Utility functions
2624 +//
2625 +
2626 +
2627 +//
2628 +// Description: Look at the status register to see if there was an error
2629 +// in the requested transaction.  If there is, look at the extended status
2630 +// register and determine the exact cause.
2631 +//
2632 +int analyze_status(struct i2c_algo_iic_data *adap, int *error_code)
2633 +{
2634 +   int ret;
2635 +   struct iic_regs *iic;
2636 +   struct iic_ibm *adap_priv_data = adap->data;
2637 +   iic = (struct iic_regs *) adap_priv_data->iic_base;
2638 +
2639 +       
2640 +   ret = iic_inb(adap, iic->sts);
2641 +   if(ret & 0x04) {
2642 +      // Error occurred
2643 +      ret = iic_inb(adap, iic->extsts);
2644 +      if(ret & 0x04) {
2645 +         // Lost arbitration
2646 +         *error_code =  IIC_ERR_LOST_ARB;
2647 +      }
2648 +      if(ret & 0x02) {
2649 +         // Incomplete transfer
2650 +         *error_code = IIC_ERR_INCOMPLETE_XFR;
2651 +      }
2652 +      if(ret & 0x01) {
2653 +         // Master transfer aborted by a NACK during the transfer of the 
2654 +        // address byte
2655 +         *error_code = IIC_ERR_NACK;
2656 +      }
2657 +      return -1;
2658 +   }
2659 +   return 0;
2660 +}
2661 +
2662 +
2663 +//
2664 +// Description: This function is called by the upper layers to do the
2665 +// grunt work for a master send transaction
2666 +//
2667 +static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
2668 +                         int count, int xfer_flag)
2669 +{
2670 +       struct iic_regs *iic;
2671 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2672 +       struct iic_ibm *adap_priv_data = adap->data;
2673 +       int wrcount, status, timeout;
2674 +       int loops, remainder, i, j;
2675 +       int ret, error_code;
2676 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2677 +
2678
2679 +       if( count == 0 ) return 0;
2680 +       wrcount = 0;
2681 +       loops =  count / 4;
2682 +       remainder = count % 4;
2683 +
2684 +       if((loops > 1) && (remainder == 0)) {
2685 +          for(i=0; i<(loops-1); i++) {
2686 +                     //
2687 +             // Write four bytes to master data buffer
2688 +             //
2689 +             for(j=0; j<4; j++) {
2690 +                iic_outb(adap, iic->mdbuf, 
2691 +                buf[wrcount++]);
2692 +             }
2693 +             //
2694 +             // Issue command to IICO device to begin transmission
2695 +             //
2696 +             iic_outb(adap, iic->cntl, 0x35);
2697 +             //
2698 +             // Wait for transmission to complete.  When it does, 
2699 +             //loop to the top of the for statement and write the 
2700 +             // next four bytes.
2701 +             //
2702 +             timeout = wait_for_pin(adap, &status);
2703 +             if(timeout < 0) {
2704 +                //
2705 +                // Error handling
2706 +                //
2707 +                 //printk(KERN_ERR "Error: write timeout\n");
2708 +                 return wrcount;
2709 +             }
2710 +             ret = analyze_status(adap, &error_code);
2711 +             if(ret < 0) {
2712 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2713 +                    // Return the number of bytes transferred
2714 +                    ret = iic_inb(adap, iic->xfrcnt);
2715 +                    ret = ret & 0x07;
2716 +                    return (wrcount-4+ret);
2717 +                 }
2718 +                 else return error_code;
2719 +              }
2720 +           }
2721 +       }
2722 +       else if((loops >= 1) && (remainder > 0)){
2723 +          //printk(KERN_DEBUG "iic_sendbytes: (loops >= 1)\n");
2724 +          for(i=0; i<loops; i++) {
2725 +              //
2726 +              // Write four bytes to master data buffer
2727 +              //
2728 +              for(j=0; j<4; j++) {
2729 +                 iic_outb(adap, iic->mdbuf,
2730 +                 buf[wrcount++]);
2731 +              }
2732 +              //
2733 +              // Issue command to IICO device to begin transmission
2734 +              //
2735 +              iic_outb(adap, iic->cntl, 0x35);
2736 +              //
2737 +              // Wait for transmission to complete.  When it does,
2738 +              //loop to the top of the for statement and write the
2739 +              // next four bytes.
2740 +              //
2741 +              timeout = wait_for_pin(adap, &status);
2742 +              if(timeout < 0) {
2743 +                 //
2744 +                 // Error handling
2745 +                 //
2746 +                 //printk(KERN_ERR "Error: write timeout\n");
2747 +                 return wrcount;
2748 +              }
2749 +              ret = analyze_status(adap, &error_code);
2750 +              if(ret < 0) {
2751 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2752 +                    // Return the number of bytes transferred
2753 +                    ret = iic_inb(adap, iic->xfrcnt);
2754 +                    ret = ret & 0x07;
2755 +                    return (wrcount-4+ret);
2756 +                 }
2757 +                 else return error_code;
2758 +              }
2759 +           }
2760 +        }
2761 +
2762 +       //printk(KERN_DEBUG "iic_sendbytes: expedite write\n");
2763 +       if(remainder == 0) remainder = 4;
2764 +       // remainder = remainder - 1;
2765 +       //
2766 +       // Write the remaining bytes (less than or equal to 4)
2767 +       //
2768 +       for(i=0; i<remainder; i++) {
2769 +          iic_outb(adap, iic->mdbuf, buf[wrcount++]);
2770 +          //printk(KERN_DEBUG "iic_sendbytes:  data transferred = %x, wrcount = %d\n", buf[wrcount-1], (wrcount-1));
2771 +       }
2772 +        //printk(KERN_DEBUG "iic_sendbytes: Issuing write\n");
2773 +
2774 +        if(xfer_flag == IIC_COMBINED_XFER) {
2775 +           iic_outb(adap, iic->cntl, (0x09 | ((remainder-1) << 4)));
2776 +        }
2777 +       else {
2778 +           iic_outb(adap, iic->cntl, (0x01 | ((remainder-1) << 4)));
2779 +        }
2780 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Waiting for interrupt\n"));
2781 +       timeout = wait_for_pin(adap, &status);
2782 +        if(timeout < 0) {
2783 +                  //
2784 +           // Error handling
2785 +           //
2786 +           //printk(KERN_ERR "Error: write timeout\n");
2787 +           return wrcount;
2788 +        }
2789 +        ret = analyze_status(adap, &error_code);
2790 +        if(ret < 0) {
2791 +           if(error_code == IIC_ERR_INCOMPLETE_XFR) {
2792 +              // Return the number of bytes transferred
2793 +              ret = iic_inb(adap, iic->xfrcnt);
2794 +              ret = ret & 0x07;
2795 +              return (wrcount-4+ret);
2796 +           }
2797 +           else return error_code;
2798 +        }
2799 +       DEB2(printk(KERN_DEBUG "iic_sendbytes: Got interrupt\n"));
2800 +       return wrcount;
2801 +}
2802 +
2803 +
2804 +//
2805 +// Description: Called by the upper layers to do the grunt work for
2806 +// a master read transaction.
2807 +//
2808 +static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count, int xfer_type)
2809 +{
2810 +       struct iic_regs *iic;
2811 +       int rdcount=0, i, status, timeout;
2812 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
2813 +       struct iic_ibm *adap_priv_data = adap->data;
2814 +       int loops, remainder, j;
2815 +        int ret, error_code;
2816 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
2817 +
2818 +       if(count == 0) return 0;
2819 +       loops = count / 4;
2820 +       remainder = count % 4;
2821 +
2822 +       //printk(KERN_DEBUG "iic_readbytes: loops = %d, remainder = %d\n", loops, remainder);
2823 +
2824 +       if((loops > 1) && (remainder == 0)) {
2825 +       //printk(KERN_DEBUG "iic_readbytes: (loops > 1) && (remainder == 0)\n");
2826 +          for(i=0; i<(loops-1); i++) {
2827 +             //
2828 +              // Issue command to begin master read (4 bytes maximum)
2829 +              //
2830 +             //printk(KERN_DEBUG "--->Issued read command\n");
2831 +             iic_outb(adap, iic->cntl, 0x37);
2832 +             //
2833 +              // Wait for transmission to complete.  When it does,
2834 +              // loop to the top of the for statement and write the
2835 +              // next four bytes.
2836 +              //
2837 +             //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2838 +              timeout = wait_for_pin(adap, &status);
2839 +              if(timeout < 0) {
2840 +                // Error Handler
2841 +                //printk(KERN_ERR "Error: read timed out\n");
2842 +                 return rdcount;
2843 +             }
2844 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2845 +
2846 +              ret = analyze_status(adap, &error_code);
2847 +             if(ret < 0) {
2848 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2849 +                    return rdcount;
2850 +                 else
2851 +                    return error_code;
2852 +              }
2853 +
2854 +             for(j=0; j<4; j++) {
2855 +                 // Wait for data to shuffle to top of data buffer
2856 +                 // This value needs to optimized.
2857 +                udelay(1);
2858 +                buf[rdcount] = iic_inb(adap, iic->mdbuf);
2859 +                rdcount++;
2860 +                //printk(KERN_DEBUG "--->Read one byte\n");
2861 +              }
2862 +           }
2863 +       }
2864 +
2865 +       else if((loops >= 1) && (remainder > 0)){
2866 +       //printk(KERN_DEBUG "iic_readbytes: (loops >=1) && (remainder > 0)\n");
2867 +          for(i=0; i<loops; i++) {
2868 +              //
2869 +              // Issue command to begin master read (4 bytes maximum)
2870 +              //
2871 +              //printk(KERN_DEBUG "--->Issued read command\n");
2872 +              iic_outb(adap, iic->cntl, 0x37);
2873 +              //
2874 +              // Wait for transmission to complete.  When it does,
2875 +              // loop to the top of the for statement and write the
2876 +              // next four bytes.
2877 +              //
2878 +              //printk(KERN_DEBUG "--->Waiting for interrupt\n");
2879 +              timeout = wait_for_pin(adap, &status);
2880 +              if(timeout < 0) {
2881 +                 // Error Handler
2882 +                 //printk(KERN_ERR "Error: read timed out\n");
2883 +                 return rdcount;
2884 +              }
2885 +              //printk(KERN_DEBUG "--->Got interrupt\n");
2886 +
2887 +              ret = analyze_status(adap, &error_code);
2888 +              if(ret < 0) {
2889 +                 if(error_code == IIC_ERR_INCOMPLETE_XFR)
2890 +                    return rdcount;
2891 +                 else
2892 +                    return error_code;
2893 +              }
2894 +
2895 +              for(j=0; j<4; j++) {
2896 +                 // Wait for data to shuffle to top of data buffer
2897 +                 // This value needs to optimized.
2898 +                 udelay(1);
2899 +                 buf[rdcount] = iic_inb(adap, iic->mdbuf);
2900 +                 rdcount++;
2901 +                 //printk(KERN_DEBUG "--->Read one byte\n");
2902 +              }
2903 +           }
2904 +        }
2905 +
2906 +       //printk(KERN_DEBUG "iic_readbytes: expedite read\n");
2907 +       if(remainder == 0) remainder = 4;
2908 +       DEB2(printk(KERN_DEBUG "iic_readbytes: writing %x to IICO_CNTL\n", (0x03 | ((remainder-1) << 4))));
2909 +
2910 +       if(xfer_type == IIC_COMBINED_XFER) {
2911 +          iic_outb(adap, iic->cntl, (0x0b | ((remainder-1) << 4)));
2912 +        }
2913 +        else {
2914 +          iic_outb(adap, iic->cntl, (0x03 | ((remainder-1) << 4)));
2915 +        }
2916 +       DEB2(printk(KERN_DEBUG "iic_readbytes: Wait for pin\n"));
2917 +        timeout = wait_for_pin(adap, &status);
2918 +       DEB2(printk(KERN_DEBUG "iic_readbytes: Got the interrupt\n"));
2919 +        if(timeout < 0) {
2920 +           // Error Handler
2921 +          //printk(KERN_ERR "Error: read timed out\n");
2922 +           return rdcount;
2923 +        }
2924 +
2925 +        ret = analyze_status(adap, &error_code);
2926 +        if(ret < 0) {
2927 +           if(error_code == IIC_ERR_INCOMPLETE_XFR)
2928 +              return rdcount;
2929 +           else
2930 +              return error_code;
2931 +        }
2932 +
2933 +       //printk(KERN_DEBUG "iic_readbyte: Begin reading data buffer\n");
2934 +       for(i=0; i<remainder; i++) {
2935 +          buf[rdcount] = iic_inb(adap, iic->mdbuf);
2936 +          // printk(KERN_DEBUG "iic_readbytes:  Character read = %x\n", buf[rdcount]);
2937 +           rdcount++;
2938 +       }
2939 +
2940 +       return rdcount;
2941 +}
2942 +
2943 +
2944 +//
2945 +// Description:  This function implements combined transactions.  Combined
2946 +// transactions consist of combinations of reading and writing blocks of data.
2947 +// Each transfer (i.e. a read or a write) is separated by a repeated start
2948 +// condition.
2949 +//
2950 +static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 
2951 +{
2952 +   int i;
2953 +   struct i2c_msg *pmsg;
2954 +   int ret;
2955 +
2956 +   DEB2(printk(KERN_DEBUG "Beginning combined transaction\n"));
2957 +       for(i=0; i < num; i++) {
2958 +               pmsg = &msgs[i];
2959 +               if(pmsg->flags & I2C_M_RD) {
2960 +
2961 +                       // Last read or write segment needs to be terminated with a stop
2962 +                       if(i < num-1) {
2963 +                               DEB2(printk(KERN_DEBUG "This one is a read\n"));
2964 +                       }
2965 +                       else {
2966 +                               DEB2(printk(KERN_DEBUG "Doing the last read\n"));
2967 +                       }
2968 +                       ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2969 +
2970 +                       if (ret != pmsg->len) {
2971 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2972 +                                                       "only read %d bytes.\n",ret));
2973 +                               return i;
2974 +                       }
2975 +                       else {
2976 +                               DEB2(printk("i2c-algo-ppc405.o: read %d bytes.\n",ret));
2977 +                       }
2978 +               }
2979 +               else if(!(pmsg->flags & I2C_M_RD)) {
2980 +
2981 +                       // Last read or write segment needs to be terminated with a stop
2982 +                       if(i < num-1) {
2983 +                               DEB2(printk(KERN_DEBUG "This one is a write\n"));
2984 +                       }
2985 +                       else {
2986 +                               DEB2(printk(KERN_DEBUG "Doing the last write\n"));
2987 +                       }
2988 +                       ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, (i < num-1) ? IIC_COMBINED_XFER : IIC_SINGLE_XFER);
2989 +
2990 +                       if (ret != pmsg->len) {
2991 +                               DEB2(printk("i2c-algo-ppc405.o: fail: "
2992 +                                                       "only wrote %d bytes.\n",ret));
2993 +                               return i;
2994 +                       }
2995 +                       else {
2996 +                               DEB2(printk("i2c-algo-ppc405.o: wrote %d bytes.\n",ret));
2997 +                       }
2998 +               }
2999 +       }
3000
3001 +       return num;
3002 +}
3003 +
3004 +
3005 +//
3006 +// Description: Whenever we initiate a transaction, the first byte clocked
3007 +// onto the bus after the start condition is the address (7 bit) of the
3008 +// device we want to talk to.  This function manipulates the address specified
3009 +// so that it makes sense to the hardware when written to the IIC peripheral.
3010 +//
3011 +// Note: 10 bit addresses are not supported in this driver, although they are
3012 +// supported by the hardware.  This functionality needs to be implemented.
3013 +//
3014 +static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
3015 +                                struct i2c_msg *msg, int retries) 
3016 +{
3017 +       struct iic_regs *iic;
3018 +       unsigned short flags = msg->flags;
3019 +       unsigned char addr;
3020 +       struct iic_ibm *adap_priv_data = adap->data;
3021 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
3022 +
3023 +//
3024 +// The following segment for 10 bit addresses needs to be ported
3025 +//
3026 +/* Ten bit addresses not supported right now
3027 +       if ( (flags & I2C_M_TEN)  ) { 
3028 +               // a ten bit address
3029 +               addr = 0xf0 | (( msg->addr >> 7) & 0x03);
3030 +               DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
3031 +               // try extended address code...
3032 +               ret = try_address(adap, addr, retries);
3033 +               if (ret!=1) {
3034 +                       printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
3035 +                       return -EREMOTEIO;
3036 +               }
3037 +               // the remaining 8 bit address
3038 +               iic_outb(adap,msg->addr & 0x7f);
3039 +               // Status check comes here
3040 +               if (ret != 1) {
3041 +                       printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n");
3042 +                       return -EREMOTEIO;
3043 +               }
3044 +               if ( flags & I2C_M_RD ) {
3045 +                       i2c_repstart(adap);
3046 +                       // okay, now switch into reading mode
3047 +                       addr |= 0x01;
3048 +                       ret = try_address(adap, addr, retries);
3049 +                       if (ret!=1) {
3050 +                               printk(KERN_ERR "iic_doAddress: died at extended address code.\n");
3051 +                               return -EREMOTEIO;
3052 +                       }
3053 +               }
3054 +       } else ----------> // normal 7 bit address
3055 +
3056 +Ten bit addresses not supported yet */
3057 +
3058 +       addr = ( msg->addr << 1 );
3059 +       if (flags & I2C_M_RD )
3060 +               addr |= 1;
3061 +       if (flags & I2C_M_REV_DIR_ADDR )
3062 +               addr ^= 1;
3063 +       //
3064 +       // Write to the low slave address
3065 +       //
3066 +       iic_outb(adap, iic->lmadr, addr);
3067 +       //
3068 +       // Write zero to the high slave register since we are
3069 +       // only using 7 bit addresses
3070 +       //
3071 +       iic_outb(adap, iic->hmadr, 0);
3072 +
3073 +       return 0;
3074 +}
3075 +
3076 +
3077 +//
3078 +// Description: Prepares the controller for a transaction (clearing status
3079 +// registers, data buffers, etc), and then calls either iic_readbytes or
3080 +// iic_sendbytes to do the actual transaction.
3081 +//
3082 +static int iic_xfer(struct i2c_adapter *i2c_adap,
3083 +                   struct i2c_msg msgs[], 
3084 +                   int num)
3085 +{
3086 +       struct iic_regs *iic;
3087 +       struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
3088 +       struct iic_ibm *adap_priv_data = adap->data;
3089 +       struct i2c_msg *pmsg;
3090 +       int i = 0;
3091 +       int ret;
3092 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
3093 +
3094 +       pmsg = &msgs[i];
3095 +
3096 +       //
3097 +       // Clear status register
3098 +       //
3099 +       DEB2(printk(KERN_DEBUG "iic_xfer: iic_xfer: Clearing status register\n"));
3100 +       iic_outb(adap, iic->sts, 0x0a);
3101 +
3102 +       //
3103 +       // Wait for any pending transfers to complete
3104 +       //
3105 +       DEB2(printk(KERN_DEBUG "iic_xfer: Waiting for any pending transfers to complete\n"));
3106 +       while((ret = iic_inb(adap, iic->sts)) == 0x01) {
3107 +               ;
3108 +       }
3109 +
3110 +       //
3111 +       // Flush master data buf
3112 +       //
3113 +       DEB2(printk(KERN_DEBUG "iic_xfer: Clearing master data buffer\n"));             
3114 +       ret = iic_inb(adap, iic->mdcntl);
3115 +       iic_outb(adap, iic->mdcntl, ret | 0x40);
3116 +
3117 +       //
3118 +       // Load slave address
3119 +       //
3120 +       DEB2(printk(KERN_DEBUG "iic_xfer: Loading slave address\n"));
3121 +       ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
3122 +
3123 +        //
3124 +        // Check to see if the bus is busy
3125 +        //
3126 +        ret = iic_inb(adap, iic->extsts);
3127 +        // Mask off the irrelevent bits
3128 +        ret = ret & 0x70;
3129 +        // When the bus is free, the BCS bits in the EXTSTS register are 0b100
3130 +        if(ret != 0x40) return IIC_ERR_LOST_ARB;
3131 +
3132 +       //
3133 +       // Combined transaction (read and write)
3134 +       //
3135 +       if(num > 1) {
3136 +           DEB2(printk(KERN_DEBUG "iic_xfer: Call combined transaction\n"));
3137 +           ret = iic_combined_transaction(i2c_adap, msgs, num);
3138 +        }
3139 +       //
3140 +       // Read only
3141 +       //
3142 +       else if((num == 1) && (pmsg->flags & I2C_M_RD)) {
3143 +          //
3144 +          // Tell device to begin reading data from the  master data 
3145 +          //
3146 +          DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's read\n"));
3147 +          ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
3148 +       } 
3149 +        //
3150 +       // Write only
3151 +       //
3152 +       else if((num == 1 ) && (!(pmsg->flags & I2C_M_RD))) {
3153 +          //
3154 +          // Write data to master data buffers and tell our device
3155 +          // to begin transmitting
3156 +          //
3157 +          DEB2(printk(KERN_DEBUG "iic_xfer: Call adapter's write\n"));
3158 +          ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
3159 +       }       
3160 +
3161 +       return ret;   
3162 +}
3163 +
3164 +
3165 +//
3166 +// Description: Implements device specific ioctls.  Higher level ioctls can
3167 +// be found in i2c-core.c and are typical of any i2c controller (specifying
3168 +// slave address, timeouts, etc).  These ioctls take advantage of any hardware
3169 +// features built into the controller for which this algorithm-adapter set
3170 +// was written.  These ioctls allow you to take control of the data and clock
3171 +// lines on the IBM PPC 405 IIC controller and set the either high or low,
3172 +// similar to a GPIO pin.
3173 +//
3174 +static int algo_control(struct i2c_adapter *adapter, 
3175 +       unsigned int cmd, unsigned long arg)
3176 +{
3177 +       struct iic_regs *iic;
3178 +       struct i2c_algo_iic_data *adap = adapter->algo_data;
3179 +       struct iic_ibm *adap_priv_data = adap->data;
3180 +       int ret=0;
3181 +       int lines;
3182 +       iic = (struct iic_regs *) adap_priv_data->iic_base;
3183 +
3184 +       lines = iic_inb(adap, iic->directcntl);
3185 +
3186 +       if (cmd == IICO_I2C_SDAHIGH) {
3187 +             lines = lines & 0x01;
3188 +             if( lines ) lines = 0x04;
3189 +             else lines = 0;
3190 +             iic_outb(adap, iic->directcntl,(0x08|lines));
3191 +       }
3192 +       else if (cmd == IICO_I2C_SDALOW) {
3193 +             lines = lines & 0x01;
3194 +             if( lines ) lines = 0x04;
3195 +              else lines = 0;
3196 +              iic_outb(adap, iic->directcntl,(0x00|lines));
3197 +       }
3198 +       else if (cmd == IICO_I2C_SCLHIGH) {
3199 +              lines = lines & 0x02;
3200 +              if( lines ) lines = 0x08;
3201 +              else lines = 0;
3202 +              iic_outb(adap, iic->directcntl,(0x04|lines));
3203 +       }
3204 +       else if (cmd == IICO_I2C_SCLLOW) {
3205 +              lines = lines & 0x02;
3206 +             if( lines ) lines = 0x08;
3207 +              else lines = 0;
3208 +              iic_outb(adap, iic->directcntl,(0x00|lines));
3209 +       }
3210 +       else if (cmd == IICO_I2C_LINEREAD) {
3211 +             ret = lines;
3212 +       }
3213 +       return ret;
3214 +}
3215 +
3216 +
3217 +static u32 iic_func(struct i2c_adapter *adap)
3218 +{
3219 +       return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
3220 +              I2C_FUNC_PROTOCOL_MANGLING; 
3221 +}
3222 +
3223 +
3224 +/* -----exported algorithm data: ------------------------------------- */
3225 +
3226 +static struct i2c_algorithm iic_algo = {
3227 +       .owner          = THIS_MODULE,
3228 +       .name           = "IBM on-chip IIC algorithm",
3229 +       .id             = I2C_ALGO_OCP,
3230 +       .master_xfer    = iic_xfer,
3231 +       .algo_control   = algo_control,
3232 +       .functionality  = iic_func,
3233 +};
3234 +
3235 +/* 
3236 + * registering functions to load algorithms at runtime 
3237 + */
3238 +
3239 +
3240 +//
3241 +// Description: Register bus structure
3242 +//
3243 +int i2c_ocp_add_bus(struct i2c_adapter *adap)
3244 +{
3245 +       struct i2c_algo_iic_data *iic_adap = adap->algo_data;
3246 +
3247 +       DEB2(printk(KERN_DEBUG "i2c-algo-iic.o: hw routines for %s registered.\n",
3248 +                   adap->name));
3249 +
3250 +       /* register new adapter to i2c module... */
3251 +
3252 +       adap->id |= iic_algo.id;
3253 +       adap->algo = &iic_algo;
3254 +
3255 +       adap->timeout = 100;    /* default values, should       */
3256 +       adap->retries = 3;              /* be replaced by defines       */
3257 +
3258 +       iic_init(iic_adap);
3259 +       i2c_add_adapter(adap);
3260 +       return 0;
3261 +}
3262 +
3263 +
3264 +//
3265 +// Done
3266 +//
3267 +int i2c_ocp_del_bus(struct i2c_adapter *adap)
3268 +{
3269 +       return i2c_del_adapter(adap);
3270 +}
3271 +
3272 +
3273 +EXPORT_SYMBOL(i2c_ocp_add_bus);
3274 +EXPORT_SYMBOL(i2c_ocp_del_bus);
3275 +
3276 +//
3277 +// The MODULE_* macros resolve to nothing if MODULES is not defined
3278 +// when this file is compiled.
3279 +//
3280 +MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
3281 +MODULE_DESCRIPTION("PPC 405 iic algorithm");
3282 +MODULE_LICENSE("GPL");
3283 +
3284 +MODULE_PARM(i2c_debug,"i");
3285 +
3286 +MODULE_PARM_DESC(i2c_debug,
3287 +        "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
3288 +
3289 --- linux-old/include/linux/i2c-algo-ibm_ocp.h  Thu Jan  1 00:00:00 1970
3290 +++ linux/include/linux/i2c-algo-ibm_ocp.h      Sun Dec  7 11:17:38 2003
3291 @@ -0,0 +1,52 @@
3292 +/* ------------------------------------------------------------------------- */
3293 +/* i2c-algo-ibm_ocp.h i2c driver algorithms for IBM PPC 405 IIC adapters         */
3294 +/* ------------------------------------------------------------------------- */
3295 +/*   Copyright (C) 1995-97 Simon G. Vogl
3296 +                   1998-99 Hans Berglund
3297 +
3298 +    This program is free software; you can redistribute it and/or modify
3299 +    it under the terms of the GNU General Public License as published by
3300 +    the Free Software Foundation; either version 2 of the License, or
3301 +    (at your option) any later version.
3302 +
3303 +    This program is distributed in the hope that it will be useful,
3304 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
3305 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3306 +    GNU General Public License for more details.
3307 +
3308 +    You should have received a copy of the GNU General Public License
3309 +    along with this program; if not, write to the Free Software
3310 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
3311 +/* ------------------------------------------------------------------------- */
3312 +
3313 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3314 +   Frodo Looijaard <frodol@dds.nl> */
3315 +
3316 +/* Modifications by MontaVista Software, August 2000
3317 +   Changes made to support the IIC peripheral on the IBM PPC 405 */
3318 +
3319 +#ifndef _LINUX_I2C_ALGO_IBM_OCP_H
3320 +#define _LINUX_I2C_ALGO_IBM_OCP_H
3321 +
3322 +struct i2c_algo_iic_data {
3323 +       struct iic_regs *data;          /* private data for lolevel routines    */
3324 +       void (*setiic) (void *data, int ctl, int val);
3325 +       int  (*getiic) (void *data, int ctl);
3326 +       int  (*getown) (void *data);
3327 +       int  (*getclock) (void *data);
3328 +       void (*waitforpin) (void *data);     
3329 +
3330 +       /* local settings */
3331 +       int udelay;
3332 +       int mdelay;
3333 +       int timeout;
3334 +};
3335 +
3336 +
3337 +#define I2C_IIC_ADAP_MAX       16
3338 +
3339 +
3340 +int i2c_ocp_add_bus(struct i2c_adapter *);
3341 +int i2c_ocp_del_bus(struct i2c_adapter *);
3342 +
3343 +#endif /* _LINUX_I2C_ALGO_IBM_OCP_H */
3344 --- linux-old/drivers/i2c/i2c-algo-pcf.c        Thu Oct 11 15:05:47 2001
3345 +++ linux/drivers/i2c/i2c-algo-pcf.c    Sun Dec  7 11:17:38 2003
3346 @@ -31,16 +31,11 @@
3347  #include <linux/module.h>
3348  #include <linux/delay.h>
3349  #include <linux/slab.h>
3350 -#include <linux/version.h>
3351  #include <linux/init.h>
3352 -#include <asm/uaccess.h>
3353 -#include <linux/ioport.h>
3354  #include <linux/errno.h>
3355 -#include <linux/sched.h>
3356 -
3357  #include <linux/i2c.h>
3358  #include <linux/i2c-algo-pcf.h>
3359 -#include "i2c-pcf8584.h"
3360 +
3361  
3362  /* ----- global defines ----------------------------------------------- */
3363  #define DEB(x) if (i2c_debug>=1) x
3364 @@ -53,7 +48,6 @@
3365  /* module parameters:
3366   */
3367  static int i2c_debug=0;
3368 -static int pcf_scan=0; /* have a look at what's hanging 'round         */
3369  
3370  /* --- setting states on the bus with the right timing: ---------------        */
3371  
3372 @@ -99,7 +93,7 @@
3373         }
3374  #endif
3375         if (timeout <= 0) {
3376 -               printk("Timeout waiting for Bus Busy\n");
3377 +               printk(KERN_ERR "Timeout waiting for Bus Busy\n");
3378         }
3379         
3380         return (timeout<=0);
3381 @@ -144,15 +138,14 @@
3382  {
3383         unsigned char temp;
3384  
3385 -       DEB3(printk("i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3386 +       DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));
3387  
3388         /* S1=0x80: S0 selected, serial interface off */
3389         set_pcf(adap, 1, I2C_PCF_PIN);
3390         /* check to see S1 now used as R/W ctrl -
3391            PCF8584 does that when ESO is zero */
3392 -       /* PCF also resets PIN bit */
3393 -       if ((temp = get_pcf(adap, 1)) != (0)) {
3394 -               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3395 +       if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
3396 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
3397                 return -ENXIO; /* definetly not PCF8584 */
3398         }
3399  
3400 @@ -160,15 +153,15 @@
3401         i2c_outb(adap, get_own(adap));
3402         /* check it's realy writen */
3403         if ((temp = i2c_inb(adap)) != get_own(adap)) {
3404 -               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3405 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
3406                 return -ENXIO;
3407         }
3408  
3409         /* S1=0xA0, next byte in S2                                     */
3410         set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
3411         /* check to see S2 now selected */
3412 -       if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
3413 -               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3414 +       if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
3415 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
3416                 return -ENXIO;
3417         }
3418  
3419 @@ -176,7 +169,7 @@
3420         i2c_outb(adap, get_clock(adap));
3421         /* check it's realy writen, the only 5 lowest bits does matter */
3422         if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
3423 -               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3424 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
3425                 return -ENXIO;
3426         }
3427  
3428 @@ -185,11 +178,11 @@
3429  
3430         /* check to see PCF is realy idled and we can access status register */
3431         if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
3432 -               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3433 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
3434                 return -ENXIO;
3435         }
3436         
3437 -       printk("i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3438 +       printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
3439  
3440         return 0;
3441  }
3442 @@ -215,7 +208,7 @@
3443                 i2c_stop(adap);
3444                 udelay(adap->udelay);
3445         }
3446 -       DEB2(if (i) printk("i2c-algo-pcf.o: needed %d retries for %d\n",i,
3447 +       DEB2(if (i) printk(KERN_DEBUG "i2c-algo-pcf.o: needed %d retries for %d\n",i,
3448                            addr));
3449         return ret;
3450  }
3451 @@ -228,20 +221,20 @@
3452         int wrcount, status, timeout;
3453      
3454         for (wrcount=0; wrcount<count; ++wrcount) {
3455 -               DEB2(printk("i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3456 +               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: %s i2c_write: writing %2.2X\n",
3457                       i2c_adap->name, buf[wrcount]&0xff));
3458                 i2c_outb(adap, buf[wrcount]);
3459                 timeout = wait_for_pin(adap, &status);
3460                 if (timeout) {
3461                         i2c_stop(adap);
3462 -                       printk("i2c-algo-pcf.o: %s i2c_write: "
3463 +                       printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3464                                "error - timeout.\n", i2c_adap->name);
3465                         return -EREMOTEIO; /* got a better one ?? */
3466                 }
3467  #ifndef STUB_I2C
3468                 if (status & I2C_PCF_LRB) {
3469                         i2c_stop(adap);
3470 -                       printk("i2c-algo-pcf.o: %s i2c_write: "
3471 +                       printk(KERN_ERR "i2c-algo-pcf.o: %s i2c_write: "
3472                                "error - no ack.\n", i2c_adap->name);
3473                         return -EREMOTEIO; /* got a better one ?? */
3474                 }
3475 @@ -269,14 +262,14 @@
3476  
3477                 if (wait_for_pin(adap, &status)) {
3478                         i2c_stop(adap);
3479 -                       printk("i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3480 +                       printk(KERN_ERR "i2c-algo-pcf.o: pcf_readbytes timed out.\n");
3481                         return (-1);
3482                 }
3483  
3484  #ifndef STUB_I2C
3485                 if ((status & I2C_PCF_LRB) && (i != count)) {
3486                         i2c_stop(adap);
3487 -                       printk("i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3488 +                       printk(KERN_ERR "i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
3489                         return (-1);
3490                 }
3491  #endif
3492 @@ -312,18 +305,18 @@
3493         if ( (flags & I2C_M_TEN)  ) { 
3494                 /* a ten bit address */
3495                 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
3496 -               DEB2(printk("addr0: %d\n",addr));
3497 +               DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
3498                 /* try extended address code...*/
3499                 ret = try_address(adap, addr, retries);
3500                 if (ret!=1) {
3501 -                       printk("died at extended address code.\n");
3502 +                       printk(KERN_ERR "died at extended address code.\n");
3503                         return -EREMOTEIO;
3504                 }
3505                 /* the remaining 8 bit address */
3506                 i2c_outb(adap,msg->addr & 0x7f);
3507  /* Status check comes here */
3508                 if (ret != 1) {
3509 -                       printk("died at 2nd address code.\n");
3510 +                       printk(KERN_ERR "died at 2nd address code.\n");
3511                         return -EREMOTEIO;
3512                 }
3513                 if ( flags & I2C_M_RD ) {
3514 @@ -332,7 +325,7 @@
3515                         addr |= 0x01;
3516                         ret = try_address(adap, addr, retries);
3517                         if (ret!=1) {
3518 -                               printk("died at extended address code.\n");
3519 +                               printk(KERN_ERR "died at extended address code.\n");
3520                                 return -EREMOTEIO;
3521                         }
3522                 }
3523 @@ -360,7 +353,7 @@
3524         /* Check for bus busy */
3525         timeout = wait_for_bb(adap);
3526         if (timeout) {
3527 -               DEB2(printk("i2c-algo-pcf.o: "
3528 +               DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
3529                             "Timeout waiting for BB in pcf_xfer\n");)
3530                 return -EIO;
3531         }
3532 @@ -368,7 +361,7 @@
3533         for (i = 0;ret >= 0 && i < num; i++) {
3534                 pmsg = &msgs[i];
3535  
3536 -               DEB2(printk("i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3537 +               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
3538                      pmsg->flags & I2C_M_RD ? "read" : "write",
3539                       pmsg->len, pmsg->addr, i + 1, num);)
3540      
3541 @@ -383,7 +376,7 @@
3542                 timeout = wait_for_pin(adap, &status);
3543                 if (timeout) {
3544                         i2c_stop(adap);
3545 -                       DEB2(printk("i2c-algo-pcf.o: Timeout waiting "
3546 +                       DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
3547                                     "for PIN(1) in pcf_xfer\n");)
3548                         return (-EREMOTEIO);
3549                 }
3550 @@ -392,12 +385,12 @@
3551                 /* Check LRB (last rcvd bit - slave ack) */
3552                 if (status & I2C_PCF_LRB) {
3553                         i2c_stop(adap);
3554 -                       DEB2(printk("i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3555 +                       DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
3556                         return (-EREMOTEIO);
3557                 }
3558  #endif
3559      
3560 -               DEB3(printk("i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3561 +               DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
3562                             i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
3563      
3564                 /* Read */
3565 @@ -407,20 +400,20 @@
3566                                              (i + 1 == num));
3567          
3568                         if (ret != pmsg->len) {
3569 -                               DEB2(printk("i2c-algo-pcf.o: fail: "
3570 +                               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3571                                             "only read %d bytes.\n",ret));
3572                         } else {
3573 -                               DEB2(printk("i2c-algo-pcf.o: read %d bytes.\n",ret));
3574 +                               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
3575                         }
3576                 } else { /* Write */
3577                         ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
3578                                              (i + 1 == num));
3579          
3580                         if (ret != pmsg->len) {
3581 -                               DEB2(printk("i2c-algo-pcf.o: fail: "
3582 +                               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
3583                                             "only wrote %d bytes.\n",ret));
3584                         } else {
3585 -                               DEB2(printk("i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3586 +                               DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
3587                         }
3588                 }
3589         }
3590 @@ -428,12 +421,6 @@
3591         return (i);
3592  }
3593  
3594 -static int algo_control(struct i2c_adapter *adapter, 
3595 -       unsigned int cmd, unsigned long arg)
3596 -{
3597 -       return 0;
3598 -}
3599 -
3600  static u32 pcf_func(struct i2c_adapter *adap)
3601  {
3602         return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | 
3603 @@ -443,14 +430,11 @@
3604  /* -----exported algorithm data: ------------------------------------- */
3605  
3606  static struct i2c_algorithm pcf_algo = {
3607 -       "PCF8584 algorithm",
3608 -       I2C_ALGO_PCF,
3609 -       pcf_xfer,
3610 -       NULL,
3611 -       NULL,                           /* slave_xmit           */
3612 -       NULL,                           /* slave_recv           */
3613 -       algo_control,                   /* ioctl                */
3614 -       pcf_func,                       /* functionality        */
3615 +       .owner          = THIS_MODULE,
3616 +       .name           = "PCF8584 algorithm",
3617 +       .id             = I2C_ALGO_PCF,
3618 +       .master_xfer    = pcf_xfer,
3619 +       .functionality  = pcf_func,
3620  };
3621  
3622  /* 
3623 @@ -458,10 +442,10 @@
3624   */
3625  int i2c_pcf_add_bus(struct i2c_adapter *adap)
3626  {
3627 -       int i, status;
3628 +       int i;
3629         struct i2c_algo_pcf_data *pcf_adap = adap->algo_data;
3630  
3631 -       DEB2(printk("i2c-algo-pcf.o: hw routines for %s registered.\n",
3632 +       DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n",
3633                     adap->name));
3634  
3635         /* register new adapter to i2c module... */
3636 @@ -476,81 +460,23 @@
3637                 return i;
3638         }
3639  
3640 -#ifdef MODULE
3641 -       MOD_INC_USE_COUNT;
3642 -#endif
3643 -
3644         i2c_add_adapter(adap);
3645 -
3646 -       /* scan bus */
3647 -       if (pcf_scan) {
3648 -               printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n",
3649 -                      adap->name);
3650 -               for (i = 0x00; i < 0xff; i+=2) {
3651 -                       if (wait_for_bb(pcf_adap)) {
3652 -                       printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n",
3653 -                          adap->name);
3654 -                           break;
3655 -                       }
3656 -                       i2c_outb(pcf_adap, i);
3657 -                       i2c_start(pcf_adap);
3658 -                       if ((wait_for_pin(pcf_adap, &status) >= 0) && 
3659 -                           ((status & I2C_PCF_LRB) == 0)) { 
3660 -                               printk("(%02x)",i>>1); 
3661 -                       } else {
3662 -                               printk("."); 
3663 -                       }
3664 -                       i2c_stop(pcf_adap);
3665 -                       udelay(pcf_adap->udelay);
3666 -               }
3667 -               printk("\n");
3668 -       }
3669         return 0;
3670  }
3671  
3672  
3673  int i2c_pcf_del_bus(struct i2c_adapter *adap)
3674  {
3675 -       int res;
3676 -       if ((res = i2c_del_adapter(adap)) < 0)
3677 -               return res;
3678 -       DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name));
3679 -
3680 -#ifdef MODULE
3681 -       MOD_DEC_USE_COUNT;
3682 -#endif
3683 -       return 0;
3684 -}
3685 -
3686 -int __init i2c_algo_pcf_init (void)
3687 -{
3688 -       printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n");
3689 -       return 0;
3690 +       return i2c_del_adapter(adap);
3691  }
3692  
3693 -
3694  EXPORT_SYMBOL(i2c_pcf_add_bus);
3695  EXPORT_SYMBOL(i2c_pcf_del_bus);
3696  
3697 -#ifdef MODULE
3698  MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
3699  MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
3700  MODULE_LICENSE("GPL");
3701  
3702 -MODULE_PARM(pcf_scan, "i");
3703  MODULE_PARM(i2c_debug,"i");
3704 -
3705 -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus");
3706  MODULE_PARM_DESC(i2c_debug,
3707          "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");
3708 -
3709 -
3710 -int init_module(void) 
3711 -{
3712 -       return i2c_algo_pcf_init();
3713 -}
3714 -
3715 -void cleanup_module(void) 
3716 -{
3717 -}
3718 -#endif
3719 --- linux-old/include/linux/i2c-algo-pcf.h      Mon Dec 11 21:22:34 2000
3720 +++ linux/include/linux/i2c-algo-pcf.h  Sun Dec  7 11:17:38 2003
3721 @@ -22,13 +22,12 @@
3722  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
3723     Frodo Looijaard <frodol@dds.nl> */
3724  
3725 -/* $Id$ */
3726 +/* $Id$ */
3727  
3728 -#ifndef I2C_ALGO_PCF_H
3729 -#define I2C_ALGO_PCF_H 1
3730 +#ifndef _LINUX_I2C_ALGO_PCF_H
3731 +#define _LINUX_I2C_ALGO_PCF_H
3732  
3733 -/* --- Defines for pcf-adapters ---------------------------------------        */
3734 -#include <linux/i2c.h>
3735 +#include <linux/i2c-pcf8584.h>
3736  
3737  struct i2c_algo_pcf_data {
3738         void *data;             /* private data for lolevel routines    */
3739 @@ -49,4 +48,4 @@
3740  int i2c_pcf_add_bus(struct i2c_adapter *);
3741  int i2c_pcf_del_bus(struct i2c_adapter *);
3742  
3743 -#endif /* I2C_ALGO_PCF_H */
3744 +#endif /* _LINUX_I2C_ALGO_PCF_H */
3745 --- linux-old/drivers/i2c/i2c-core.c    Wed Aug 27 16:11:46 2003
3746 +++ linux/drivers/i2c/i2c-core.c        Sun Dec  7 11:17:39 2003
3747 @@ -18,61 +18,33 @@
3748  /* ------------------------------------------------------------------------- */
3749  
3750  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
3751 -   All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */
3752 +   All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
3753 +   SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com>                */
3754  
3755 -/* $Id$ */
3756 +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */
3757  
3758  #include <linux/module.h>
3759  #include <linux/kernel.h>
3760  #include <linux/errno.h>
3761  #include <linux/slab.h>
3762  #include <linux/proc_fs.h>
3763 -#include <linux/config.h>
3764 -
3765 -#include <linux/i2c.h>
3766 -
3767 -/* ----- compatibility stuff ----------------------------------------------- */
3768 -
3769 -#include <linux/version.h>
3770  #include <linux/init.h>
3771 -
3772 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
3773 -#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
3774 -#endif
3775 -
3776 +#include <linux/i2c.h>
3777  #include <asm/uaccess.h>
3778  
3779  /* ----- global defines ---------------------------------------------------- */
3780  
3781 -/* exclusive access to the bus */
3782 -#define I2C_LOCK(adap) down(&adap->lock)
3783 -#define I2C_UNLOCK(adap) up(&adap->lock) 
3784 -
3785 -#define ADAP_LOCK()    down(&adap_lock)
3786 -#define ADAP_UNLOCK()  up(&adap_lock)
3787 -
3788 -#define DRV_LOCK()     down(&driver_lock)
3789 -#define DRV_UNLOCK()   up(&driver_lock)
3790 -
3791  #define DEB(x) if (i2c_debug>=1) x;
3792  #define DEB2(x) if (i2c_debug>=2) x;
3793  
3794  /* ----- global variables -------------------------------------------------- */
3795  
3796 -/**** lock for writing to global variables: the adapter & driver list */
3797 -struct semaphore adap_lock;
3798 -struct semaphore driver_lock;
3799 -
3800 -/**** adapter list */
3801 +DECLARE_MUTEX(core_lists);
3802  static struct i2c_adapter *adapters[I2C_ADAP_MAX];
3803 -static int adap_count;
3804 -
3805 -/**** drivers list */
3806  static struct i2c_driver *drivers[I2C_DRIVER_MAX];
3807 -static int driver_count;
3808  
3809  /**** debug level */
3810 -static int i2c_debug=1;
3811 +static int i2c_debug;
3812  
3813  /* ---------------------------------------------------
3814   * /proc entry declarations
3815 @@ -80,14 +52,6 @@
3816   */
3817  
3818  #ifdef CONFIG_PROC_FS
3819 -
3820 -static int i2cproc_init(void);
3821 -static int i2cproc_cleanup(void);
3822 -
3823 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
3824 -static void monitor_bus_i2c(struct inode *inode, int fill);
3825 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3826 -
3827  static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, 
3828                                  loff_t *ppos);
3829  static int read_bus_i2c(char *buf, char **start, off_t offset, int len,
3830 @@ -96,21 +60,11 @@
3831  /* To implement the dynamic /proc/bus/i2c-? files, we need our own 
3832     implementation of the read hook */
3833  static struct file_operations i2cproc_operations = {
3834 -       read:           i2cproc_bus_read,
3835 +       .read           = i2cproc_bus_read,
3836  };
3837  
3838 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
3839 -static struct inode_operations i2cproc_inode_operations = {
3840 -       &i2cproc_operations
3841 -};
3842 -#endif
3843 -
3844 -static int i2cproc_initialized = 0;
3845 -
3846 -#else /* undef CONFIG_PROC_FS */
3847 -
3848 -#define i2cproc_init() 0
3849 -#define i2cproc_cleanup() 0
3850 +static int i2cproc_register(struct i2c_adapter *adap, int bus);
3851 +static void i2cproc_remove(int bus);
3852  
3853  #endif /* CONFIG_PROC_FS */
3854  
3855 @@ -127,9 +81,9 @@
3856   */
3857  int i2c_add_adapter(struct i2c_adapter *adap)
3858  {
3859 -       int i,j,res;
3860 +       int i,j,res = 0;
3861  
3862 -       ADAP_LOCK();
3863 +       down(&core_lists);
3864         for (i = 0; i < I2C_ADAP_MAX; i++)
3865                 if (NULL == adapters[i])
3866                         break;
3867 @@ -140,81 +94,44 @@
3868                 res = -ENOMEM;
3869                 goto ERROR0;
3870         }
3871 +       
3872 +#ifdef CONFIG_PROC_FS
3873 +       res = i2cproc_register(adap, i);
3874 +       if (res<0)
3875 +           goto ERROR0;
3876 +#endif /* def CONFIG_PROC_FS */
3877  
3878         adapters[i] = adap;
3879 -       adap_count++;
3880 -       ADAP_UNLOCK();
3881         
3882         /* init data types */
3883 -       init_MUTEX(&adap->lock);
3884 -
3885 -#ifdef CONFIG_PROC_FS
3886 -
3887 -       if (i2cproc_initialized) {
3888 -               char name[8];
3889 -               struct proc_dir_entry *proc_entry;
3890 -
3891 -               sprintf(name,"i2c-%d", i);
3892 -
3893 -               proc_entry = create_proc_entry(name,0,proc_bus);
3894 -               if (! proc_entry) {
3895 -                       printk("i2c-core.o: Could not create /proc/bus/%s\n",
3896 -                              name);
3897 -                       res = -ENOENT;
3898 -                       goto ERROR1;
3899 -               }
3900 -
3901 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,48))
3902 -               proc_entry->proc_fops = &i2cproc_operations;
3903 -#else
3904 -               proc_entry->ops = &i2cproc_inode_operations;
3905 -#endif
3906 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
3907 -               proc_entry->owner = THIS_MODULE;
3908 -#else
3909 -               proc_entry->fill_inode = &monitor_bus_i2c;
3910 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */
3911 -               adap->inode = proc_entry->low_ino;
3912 -       }
3913 -
3914 -#endif /* def CONFIG_PROC_FS */
3915 +       init_MUTEX(&adap->bus);
3916 +       init_MUTEX(&adap->list);
3917  
3918         /* inform drivers of new adapters */
3919 -       DRV_LOCK();     
3920         for (j=0;j<I2C_DRIVER_MAX;j++)
3921                 if (drivers[j]!=NULL && 
3922                     (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY)))
3923                         /* We ignore the return code; if it fails, too bad */
3924                         drivers[j]->attach_adapter(adap);
3925 -       DRV_UNLOCK();
3926         
3927 -       DEB(printk("i2c-core.o: adapter %s registered as adapter %d.\n",
3928 +       DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n",
3929                    adap->name,i));
3930 -
3931 -       return 0;       
3932 -
3933 -
3934 -ERROR1:
3935 -       ADAP_LOCK();
3936 -       adapters[i] = NULL;
3937 -       adap_count--;
3938 -ERROR0:
3939 -       ADAP_UNLOCK();
3940 + ERROR0:
3941 +       up(&core_lists);
3942         return res;
3943  }
3944  
3945  
3946  int i2c_del_adapter(struct i2c_adapter *adap)
3947  {
3948 -       int i,j,res;
3949 -
3950 -       ADAP_LOCK();
3951 +       int i,j, res=0;
3952  
3953 +       down(&core_lists);
3954         for (i = 0; i < I2C_ADAP_MAX; i++)
3955                 if (adap == adapters[i])
3956                         break;
3957         if (I2C_ADAP_MAX == i) {
3958 -               printk( "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3959 +               printk( KERN_WARNING "i2c-core.o: unregister_adapter adap [%s] not found.\n",
3960                         adap->name);
3961                 res = -ENODEV;
3962                 goto ERROR0;
3963 @@ -225,17 +142,14 @@
3964          * *detach* it! Of course, each dummy driver should know about
3965          * this or hell will break loose...
3966          */
3967 -       DRV_LOCK();
3968         for (j = 0; j < I2C_DRIVER_MAX; j++) 
3969                 if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY))
3970                         if ((res = drivers[j]->attach_adapter(adap))) {
3971 -                               printk("i2c-core.o: can't detach adapter %s "
3972 +                               printk(KERN_WARNING "i2c-core.o: can't detach adapter %s "
3973                                        "while detaching driver %s: driver not "
3974                                        "detached!",adap->name,drivers[j]->name);
3975 -                               goto ERROR1;    
3976 +                               goto ERROR0;
3977                         }
3978 -       DRV_UNLOCK();
3979 -
3980  
3981         /* detach any active clients. This must be done first, because
3982          * it can fail; in which case we give upp. */
3983 @@ -247,33 +161,22 @@
3984                      * must be deleted, as this would cause invalid states.
3985                      */
3986                         if ((res=client->driver->detach_client(client))) {
3987 -                               printk("i2c-core.o: adapter %s not "
3988 +                               printk(KERN_ERR "i2c-core.o: adapter %s not "
3989                                         "unregistered, because client at "
3990                                         "address %02x can't be detached. ",
3991                                         adap->name, client->addr);
3992                                 goto ERROR0;
3993                         }
3994         }
3995 +
3996  #ifdef CONFIG_PROC_FS
3997 -       if (i2cproc_initialized) {
3998 -               char name[8];
3999 -               sprintf(name,"i2c-%d", i);
4000 -               remove_proc_entry(name,proc_bus);
4001 -       }
4002 +       i2cproc_remove(i);
4003  #endif /* def CONFIG_PROC_FS */
4004  
4005         adapters[i] = NULL;
4006 -       adap_count--;
4007 -       
4008 -       ADAP_UNLOCK();  
4009 -       DEB(printk("i2c-core.o: adapter unregistered: %s\n",adap->name));
4010 -       return 0;
4011 -
4012 -ERROR0:
4013 -       ADAP_UNLOCK();
4014 -       return res;
4015 -ERROR1:
4016 -       DRV_UNLOCK();
4017 +               DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
4018 + ERROR0:
4019 +       up(&core_lists);
4020         return res;
4021  }
4022  
4023 @@ -287,7 +190,8 @@
4024  int i2c_add_driver(struct i2c_driver *driver)
4025  {
4026         int i;
4027 -       DRV_LOCK();
4028 +
4029 +       down(&core_lists);
4030         for (i = 0; i < I2C_DRIVER_MAX; i++)
4031                 if (NULL == drivers[i])
4032                         break;
4033 @@ -296,19 +200,12 @@
4034                        " i2c-core.o: register_driver(%s) "
4035                        "- enlarge I2C_DRIVER_MAX.\n",
4036                         driver->name);
4037 -               DRV_UNLOCK();
4038 +               up(&core_lists);
4039                 return -ENOMEM;
4040         }
4041 -
4042 -       drivers[i] = driver;
4043 -       driver_count++;
4044 -       
4045 -       DRV_UNLOCK();   /* driver was successfully added */
4046 -       
4047 -       DEB(printk("i2c-core.o: driver %s registered.\n",driver->name));
4048 +       drivers[i] = driver;    
4049 +       DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
4050         
4051 -       ADAP_LOCK();
4052 -
4053         /* now look for instances of driver on our adapters
4054          */
4055         if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
4056 @@ -317,15 +214,15 @@
4057                                 /* Ignore errors */
4058                                 driver->attach_adapter(adapters[i]);
4059         }
4060 -       ADAP_UNLOCK();
4061 +       up(&core_lists);
4062         return 0;
4063  }
4064  
4065  int i2c_del_driver(struct i2c_driver *driver)
4066  {
4067 -       int i,j,k,res;
4068 +       int i,j,k,res = 0;
4069  
4070 -       DRV_LOCK();
4071 +       down(&core_lists);
4072         for (i = 0; i < I2C_DRIVER_MAX; i++)
4073                 if (driver == drivers[i])
4074                         break;
4075 @@ -333,24 +230,23 @@
4076                 printk(KERN_WARNING " i2c-core.o: unregister_driver: "
4077                                     "[%s] not found\n",
4078                         driver->name);
4079 -               DRV_UNLOCK();
4080 +               up(&core_lists);
4081                 return -ENODEV;
4082         }
4083         /* Have a look at each adapter, if clients of this driver are still
4084          * attached. If so, detach them to be able to kill the driver 
4085          * afterwards.
4086          */
4087 -       DEB2(printk("i2c-core.o: unregister_driver - looking for clients.\n"));
4088 +       DEB2(printk(KERN_DEBUG "i2c-core.o: unregister_driver - looking for clients.\n"));
4089         /* removing clients does not depend on the notify flag, else 
4090          * invalid operation might (will!) result, when using stale client
4091          * pointers.
4092          */
4093 -       ADAP_LOCK(); /* should be moved inside the if statement... */
4094         for (k=0;k<I2C_ADAP_MAX;k++) {
4095                 struct i2c_adapter *adap = adapters[k];
4096                 if (adap == NULL) /* skip empty entries. */
4097                         continue;
4098 -               DEB2(printk("i2c-core.o: examining adapter %s:\n",
4099 +               DEB2(printk(KERN_DEBUG "i2c-core.o: examining adapter %s:\n",
4100                             adap->name));
4101                 if (driver->flags & I2C_DF_DUMMY) {
4102                 /* DUMMY drivers do not register their clients, so we have to
4103 @@ -359,60 +255,69 @@
4104                  * this or hell will break loose...  
4105                  */
4106                         if ((res = driver->attach_adapter(adap))) {
4107 -                               printk("i2c-core.o: while unregistering "
4108 +                               printk(KERN_WARNING "i2c-core.o: while unregistering "
4109                                        "dummy driver %s, adapter %s could "
4110                                        "not be detached properly; driver "
4111                                        "not unloaded!",driver->name,
4112                                        adap->name);
4113 -                               ADAP_UNLOCK();
4114 -                               return res;
4115 +                               goto ERROR0;
4116                         }
4117                 } else {
4118                         for (j=0;j<I2C_CLIENT_MAX;j++) { 
4119                                 struct i2c_client *client = adap->clients[j];
4120                                 if (client != NULL && 
4121                                     client->driver == driver) {
4122 -                                       DEB2(printk("i2c-core.o: "
4123 +                                       DEB2(printk(KERN_DEBUG "i2c-core.o: "
4124                                                     "detaching client %s:\n",
4125                                                     client->name));
4126                                         if ((res = driver->
4127                                                         detach_client(client)))
4128                                         {
4129 -                                               printk("i2c-core.o: while "
4130 +                                               printk(KERN_ERR "i2c-core.o: while "
4131                                                        "unregistering driver "
4132                                                        "`%s', the client at "
4133                                                        "address %02x of "
4134 -                                                      "adapter `%s' could not"
4135 -                                                      "be detached; driver"
4136 +                                                      "adapter `%s' could not "
4137 +                                                      "be detached; driver "
4138                                                        "not unloaded!",
4139                                                        driver->name,
4140                                                        client->addr,
4141                                                        adap->name);
4142 -                                               ADAP_UNLOCK();
4143 -                                               return res;
4144 +                                               goto ERROR0;
4145                                         }
4146                                 }
4147                         }
4148                 }
4149         }
4150 -       ADAP_UNLOCK();
4151         drivers[i] = NULL;
4152 -       driver_count--;
4153 -       DRV_UNLOCK();
4154 -       
4155 -       DEB(printk("i2c-core.o: driver unregistered: %s\n",driver->name));
4156 -       return 0;
4157 +       DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
4158 +
4159 + ERROR0:
4160 +       up(&core_lists);
4161 +       return res;
4162  }
4163  
4164 -int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4165 +static int __i2c_check_addr (struct i2c_adapter *adapter, int addr)
4166  {
4167         int i;
4168         for (i = 0; i < I2C_CLIENT_MAX ; i++) 
4169                 if (adapter->clients[i] && (adapter->clients[i]->addr == addr))
4170                         return -EBUSY;
4171 +
4172         return 0;
4173  }
4174  
4175 +int i2c_check_addr (struct i2c_adapter *adapter, int addr)
4176 +{
4177 +       int rval;
4178 +
4179 +       down(&adapter->list);
4180 +       rval = __i2c_check_addr(adapter, addr);
4181 +       up(&adapter->list);
4182 +
4183 +       return rval;
4184 +}
4185 +
4186  int i2c_attach_client(struct i2c_client *client)
4187  {
4188         struct i2c_adapter *adapter = client->adapter;
4189 @@ -421,6 +326,7 @@
4190         if (i2c_check_addr(client->adapter,client->addr))
4191                 return -EBUSY;
4192  
4193 +       down(&adapter->list);
4194         for (i = 0; i < I2C_CLIENT_MAX; i++)
4195                 if (NULL == adapter->clients[i])
4196                         break;
4197 @@ -428,18 +334,18 @@
4198                 printk(KERN_WARNING 
4199                        " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
4200                         client->name);
4201 +               up(&adapter->list);
4202                 return -ENOMEM;
4203         }
4204 -
4205         adapter->clients[i] = client;
4206 -       adapter->client_count++;
4207 +       up(&adapter->list);
4208         
4209         if (adapter->client_register) 
4210                 if (adapter->client_register(client)) 
4211 -                       printk("i2c-core.o: warning: client_register seems "
4212 +                       printk(KERN_DEBUG "i2c-core.o: warning: client_register seems "
4213                                "to have failed for client %02x at adapter %s\n",
4214                                client->addr,adapter->name);
4215 -       DEB(printk("i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4216 +       DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n",
4217                 client->name, adapter->name,i));
4218  
4219         if(client->flags & I2C_CLIENT_ALLOW_USE)
4220 @@ -454,54 +360,52 @@
4221         struct i2c_adapter *adapter = client->adapter;
4222         int i,res;
4223  
4224 -       for (i = 0; i < I2C_CLIENT_MAX; i++)
4225 -               if (client == adapter->clients[i])
4226 -                       break;
4227 -       if (I2C_CLIENT_MAX == i) {
4228 -               printk(KERN_WARNING " i2c-core.o: unregister_client "
4229 -                                   "[%s] not found\n",
4230 -                       client->name);
4231 -               return -ENODEV;
4232 -       }
4233 -       
4234         if( (client->flags & I2C_CLIENT_ALLOW_USE) && 
4235             (client->usage_count>0))
4236                 return -EBUSY;
4237         
4238         if (adapter->client_unregister != NULL) 
4239                 if ((res = adapter->client_unregister(client))) {
4240 -                       printk("i2c-core.o: client_unregister [%s] failed, "
4241 +                       printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, "
4242                                "client not detached",client->name);
4243                         return res;
4244                 }
4245  
4246 +       down(&adapter->list);
4247 +       for (i = 0; i < I2C_CLIENT_MAX; i++)
4248 +               if (client == adapter->clients[i])
4249 +                       break;
4250 +       if (I2C_CLIENT_MAX == i) {
4251 +               printk(KERN_WARNING " i2c-core.o: unregister_client "
4252 +                                   "[%s] not found\n",
4253 +                       client->name);
4254 +               up(&adapter->list);
4255 +               return -ENODEV;
4256 +       }
4257         adapter->clients[i] = NULL;
4258 -       adapter->client_count--;
4259 +       up(&adapter->list);
4260  
4261 -       DEB(printk("i2c-core.o: client [%s] unregistered.\n",client->name));
4262 +       DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name));
4263         return 0;
4264  }
4265  
4266 -void i2c_inc_use_client(struct i2c_client *client)
4267 +static void i2c_inc_use_client(struct i2c_client *client)
4268  {
4269 -
4270 -       if (client->driver->inc_use != NULL)
4271 -               client->driver->inc_use(client);
4272 -
4273 -       if (client->adapter->inc_use != NULL)
4274 -               client->adapter->inc_use(client->adapter);
4275 +       if(client->driver->owner)
4276 +               __MOD_INC_USE_COUNT(client->driver->owner);
4277 +       if(client->adapter->owner)
4278 +               __MOD_INC_USE_COUNT(client->adapter->owner);
4279  }
4280  
4281 -void i2c_dec_use_client(struct i2c_client *client)
4282 +static void i2c_dec_use_client(struct i2c_client *client)
4283  {
4284 -       
4285 -       if (client->driver->dec_use != NULL)
4286 -               client->driver->dec_use(client);
4287 -
4288 -       if (client->adapter->dec_use != NULL)
4289 -               client->adapter->dec_use(client->adapter);
4290 +       if(client->driver->owner)
4291 +               __MOD_DEC_USE_COUNT(client->driver->owner);
4292 +       if(client->adapter->owner)
4293 +               __MOD_DEC_USE_COUNT(client->adapter->owner);
4294  }
4295  
4296 +#if 0 /* just forget about this for now --km */
4297  struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
4298                                         struct i2c_client *prev)
4299  {
4300 @@ -568,18 +472,17 @@
4301  
4302         return 0;
4303  }
4304 +#endif
4305  
4306  int i2c_use_client(struct i2c_client *client)
4307  {
4308 -       if(client->flags & I2C_CLIENT_ALLOW_USE) {
4309 -               if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE) 
4310 +       if (client->flags & I2C_CLIENT_ALLOW_USE) {
4311 +               if (client->flags & I2C_CLIENT_ALLOW_MULTIPLE_USE)
4312 +                       client->usage_count++;
4313 +               else if (client->usage_count > 0) 
4314 +                       return -EBUSY;
4315 +               else 
4316                         client->usage_count++;
4317 -               else {
4318 -                       if(client->usage_count > 0) 
4319 -                               return -EBUSY;
4320 -                        else 
4321 -                               client->usage_count++;
4322 -               }
4323         }
4324  
4325         i2c_inc_use_client(client);
4326 @@ -611,25 +514,14 @@
4327  
4328  #ifdef CONFIG_PROC_FS
4329  
4330 -#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27))
4331 -/* Monitor access to /proc/bus/i2c*; make unloading i2c-proc impossible
4332 -   if some process still uses it or some file in it */
4333 -void monitor_bus_i2c(struct inode *inode, int fill)
4334 -{
4335 -       if (fill)
4336 -               MOD_INC_USE_COUNT;
4337 -       else
4338 -               MOD_DEC_USE_COUNT;
4339 -}
4340 -#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */
4341 -
4342  /* This function generates the output for /proc/bus/i2c */
4343 -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 
4344 +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, 
4345                   void *private)
4346  {
4347         int i;
4348         int nr = 0;
4349         /* Note that it is safe to write a `little' beyond len. Yes, really. */
4350 +       down(&core_lists);
4351         for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++)
4352                 if (adapters[i]) {
4353                         nr += sprintf(buf+nr, "i2c-%d\t", i);
4354 @@ -646,6 +538,7 @@
4355                                       adapters[i]->name,
4356                                       adapters[i]->algo->name);
4357                 }
4358 +       up(&core_lists);
4359         return nr;
4360  }
4361  
4362 @@ -656,102 +549,125 @@
4363         struct inode * inode = file->f_dentry->d_inode;
4364         char *kbuf;
4365         struct i2c_client *client;
4366 +       struct i2c_adapter *adap;
4367         int i,j,k,order_nr,len=0;
4368         size_t len_total;
4369         int order[I2C_CLIENT_MAX];
4370 +#define OUTPUT_LENGTH_PER_LINE 70
4371  
4372 -       if (count > 4000)
4373 -               return -EINVAL; 
4374         len_total = file->f_pos + count;
4375 -       /* Too bad if this gets longer (unlikely) */
4376 -       if (len_total > 4000)
4377 -               len_total = 4000;
4378 -       for (i = 0; i < I2C_ADAP_MAX; i++)
4379 -               if (adapters[i]->inode == inode->i_ino) {
4380 -               /* We need a bit of slack in the kernel buffer; this makes the
4381 -                  sprintf safe. */
4382 -                       if (! (kbuf = kmalloc(count + 80,GFP_KERNEL)))
4383 -                               return -ENOMEM;
4384 -                       /* Order will hold the indexes of the clients
4385 -                          sorted by address */
4386 -                       order_nr=0;
4387 -                       for (j = 0; j < I2C_CLIENT_MAX; j++) {
4388 -                               if ((client = adapters[i]->clients[j]) && 
4389 -                                   (client->driver->id != I2C_DRIVERID_I2CDEV))  {
4390 -                                       for(k = order_nr; 
4391 -                                           (k > 0) && 
4392 -                                           adapters[i]->clients[order[k-1]]->
4393 -                                                    addr > client->addr; 
4394 -                                           k--)
4395 -                                               order[k] = order[k-1];
4396 -                                       order[k] = j;
4397 -                                       order_nr++;
4398 -                               }
4399 -                       }
4400 -
4401 -
4402 -                       for (j = 0; (j < order_nr) && (len < len_total); j++) {
4403 -                               client = adapters[i]->clients[order[j]];
4404 -                               len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4405 -                                             client->addr,
4406 -                                             client->name,
4407 -                                             client->driver->name);
4408 -                       }
4409 -                       len = len - file->f_pos;
4410 -                       if (len > count)
4411 -                               len = count;
4412 -                       if (len < 0) 
4413 -                               len = 0;
4414 -                       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4415 -                               kfree(kbuf);
4416 -                               return -EFAULT;
4417 -                       }
4418 -                       file->f_pos += len;
4419 -                       kfree(kbuf);
4420 -                       return len;
4421 -               }
4422 -       return -ENOENT;
4423 +       if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) )
4424 +               /* adjust to maximum file size */
4425 +               len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE);
4426 +
4427 +       down(&core_lists);
4428 +       /* adap = file->private_data; ?? --km */
4429 +       for (i = 0; i < I2C_ADAP_MAX; i++) {
4430 +           adap = adapters[i];
4431 +           if (adap && (adap->inode == inode->i_ino))
4432 +               break;
4433 +       }
4434 +       if ( I2C_ADAP_MAX == i ) {
4435 +           up(&core_lists);
4436 +           return -ENOENT;
4437 +       }
4438 +
4439 +       /* We need a bit of slack in the kernel buffer; this makes the
4440 +          sprintf safe. */
4441 +       if (! (kbuf = kmalloc(len_total +
4442 +                             OUTPUT_LENGTH_PER_LINE,
4443 +                             GFP_KERNEL)))
4444 +           return -ENOMEM;
4445 +
4446 +       /* Order will hold the indexes of the clients
4447 +          sorted by address */
4448 +       order_nr=0;
4449 +       down(&adap->list);
4450 +       for (j = 0; j < I2C_CLIENT_MAX; j++) {
4451 +           if ((client = adap->clients[j]) && 
4452 +               (client->driver->id != I2C_DRIVERID_I2CDEV))  {
4453 +               for(k = order_nr; 
4454 +                   (k > 0) && 
4455 +                       adap->clients[order[k-1]]->
4456 +                       addr > client->addr; 
4457 +                   k--)
4458 +                   order[k] = order[k-1];
4459 +               order[k] = j;
4460 +               order_nr++;
4461 +           }
4462 +       }
4463 +
4464 +
4465 +       for (j = 0; (j < order_nr) && (len < len_total); j++) {
4466 +           client = adap->clients[order[j]];
4467 +           len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n",
4468 +                          client->addr,
4469 +                          client->name,
4470 +                          client->driver->name);
4471 +       }
4472 +       up(&adap->list);
4473 +       up(&core_lists);
4474 +       
4475 +       len = len - file->f_pos;
4476 +       if (len > count)
4477 +           len = count;
4478 +       if (len < 0) 
4479 +           len = 0;
4480 +       if (copy_to_user (buf,kbuf+file->f_pos, len)) {
4481 +           kfree(kbuf);
4482 +           return -EFAULT;
4483 +       }
4484 +       file->f_pos += len;
4485 +       kfree(kbuf);
4486 +       return len;
4487 +}
4488 +
4489 +static int i2cproc_register(struct i2c_adapter *adap, int bus)
4490 +{
4491 +       char name[8];
4492 +       struct proc_dir_entry *proc_entry;
4493 +
4494 +       sprintf(name,"i2c-%d", bus);
4495 +       proc_entry = create_proc_entry(name,0,proc_bus);
4496 +       if (! proc_entry) {
4497 +               printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n",
4498 +                      name);
4499 +               return -ENOENT;
4500 +       }
4501 +           
4502 +       proc_entry->proc_fops = &i2cproc_operations;
4503 +       proc_entry->owner = adap->owner;
4504 +       adap->inode = proc_entry->low_ino;
4505 +       return 0;
4506  }
4507  
4508 -int i2cproc_init(void)
4509 +static void i2cproc_remove(int bus)
4510  {
4511 +       char name[8];
4512 +       sprintf(name,"i2c-%d", bus);
4513 +       remove_proc_entry(name, proc_bus);
4514 +}
4515  
4516 +static int __init i2cproc_init(void)
4517 +{
4518         struct proc_dir_entry *proc_bus_i2c;
4519  
4520 -       i2cproc_initialized = 0;
4521 -
4522 -       if (! proc_bus) {
4523 -               printk("i2c-core.o: /proc/bus/ does not exist");
4524 -               i2cproc_cleanup();
4525 -               return -ENOENT;
4526 -       } 
4527         proc_bus_i2c = create_proc_entry("i2c",0,proc_bus);
4528         if (!proc_bus_i2c) {
4529 -               printk("i2c-core.o: Could not create /proc/bus/i2c");
4530 -               i2cproc_cleanup();
4531 +               printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c");
4532                 return -ENOENT;
4533         }
4534 +
4535         proc_bus_i2c->read_proc = &read_bus_i2c;
4536 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
4537         proc_bus_i2c->owner = THIS_MODULE;
4538 -#else
4539 -       proc_bus_i2c->fill_inode = &monitor_bus_i2c;
4540 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
4541 -       i2cproc_initialized += 2;
4542         return 0;
4543  }
4544  
4545 -int i2cproc_cleanup(void)
4546 +static void __exit i2cproc_cleanup(void)
4547  {
4548 -
4549 -       if (i2cproc_initialized >= 1) {
4550 -               remove_proc_entry("i2c",proc_bus);
4551 -               i2cproc_initialized -= 2;
4552 -       }
4553 -       return 0;
4554 +       remove_proc_entry("i2c",proc_bus);
4555  }
4556  
4557 -
4558  #endif /* def CONFIG_PROC_FS */
4559  
4560  /* ----------------------------------------------------
4561 @@ -764,16 +680,16 @@
4562         int ret;
4563  
4564         if (adap->algo->master_xfer) {
4565 -               DEB2(printk("i2c-core.o: master_xfer: %s with %d msgs.\n",
4566 +               DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n",
4567                             adap->name,num));
4568  
4569 -               I2C_LOCK(adap);
4570 +               down(&adap->bus);
4571                 ret = adap->algo->master_xfer(adap,msgs,num);
4572 -               I2C_UNLOCK(adap);
4573 +               up(&adap->bus);
4574  
4575                 return ret;
4576         } else {
4577 -               printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4578 +               printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4579                        adap->id);
4580                 return -ENOSYS;
4581         }
4582 @@ -791,19 +707,19 @@
4583                 msg.len = count;
4584                 (const char *)msg.buf = buf;
4585         
4586 -               DEB2(printk("i2c-core.o: master_send: writing %d bytes on %s.\n",
4587 +               DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n",
4588                         count,client->adapter->name));
4589         
4590 -               I2C_LOCK(adap);
4591 +               down(&adap->bus);
4592                 ret = adap->algo->master_xfer(adap,&msg,1);
4593 -               I2C_UNLOCK(adap);
4594 +               up(&adap->bus);
4595  
4596                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4597                  * transmitted, else error code.
4598                  */
4599                 return (ret == 1 )? count : ret;
4600         } else {
4601 -               printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4602 +               printk(KERN_ERR "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4603                        client->adapter->id);
4604                 return -ENOSYS;
4605         }
4606 @@ -821,14 +737,14 @@
4607                 msg.len = count;
4608                 msg.buf = buf;
4609  
4610 -               DEB2(printk("i2c-core.o: master_recv: reading %d bytes on %s.\n",
4611 +               DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n",
4612                         count,client->adapter->name));
4613         
4614 -               I2C_LOCK(adap);
4615 +               down(&adap->bus);
4616                 ret = adap->algo->master_xfer(adap,&msg,1);
4617 -               I2C_UNLOCK(adap);
4618 +               up(&adap->bus);
4619         
4620 -               DEB2(printk("i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4621 +               DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n",
4622                         ret, count, client->addr));
4623         
4624                 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
4625 @@ -836,7 +752,7 @@
4626                 */
4627                 return (ret == 1 )? count : ret;
4628         } else {
4629 -               printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4630 +               printk(KERN_DEBUG "i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n",
4631                        client->adapter->id);
4632                 return -ENOSYS;
4633         }
4634 @@ -849,7 +765,7 @@
4635         int ret = 0;
4636         struct i2c_adapter *adap = client->adapter;
4637  
4638 -       DEB2(printk("i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4639 +       DEB2(printk(KERN_DEBUG "i2c-core.o: i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd, arg));
4640         switch ( cmd ) {
4641                 case I2C_RETRIES:
4642                         adap->retries = arg;
4643 @@ -894,7 +810,7 @@
4644                         if (((adap_id == address_data->force[i]) || 
4645                              (address_data->force[i] == ANY_I2C_BUS)) &&
4646                              (addr == address_data->force[i+1])) {
4647 -                               DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4648 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found force parameter for adapter %d, addr %04x\n",
4649                                             adap_id,addr));
4650                                 if ((err = found_proc(adapter,addr,0,0)))
4651                                         return err;
4652 @@ -912,7 +828,7 @@
4653                         if (((adap_id == address_data->ignore[i]) || 
4654                             ((address_data->ignore[i] == ANY_I2C_BUS))) &&
4655                             (addr == address_data->ignore[i+1])) {
4656 -                               DEB2(printk("i2c-core.o: found ignore parameter for adapter %d, "
4657 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore parameter for adapter %d, "
4658                                      "addr %04x\n", adap_id ,addr));
4659                                 found = 1;
4660                         }
4661 @@ -924,7 +840,7 @@
4662                             ((address_data->ignore_range[i]==ANY_I2C_BUS))) &&
4663                             (addr >= address_data->ignore_range[i+1]) &&
4664                             (addr <= address_data->ignore_range[i+2])) {
4665 -                               DEB2(printk("i2c-core.o: found ignore_range parameter for adapter %d, "
4666 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found ignore_range parameter for adapter %d, "
4667                                             "addr %04x\n", adap_id,addr));
4668                                 found = 1;
4669                         }
4670 @@ -939,7 +855,7 @@
4671                      i += 1) {
4672                         if (addr == address_data->normal_i2c[i]) {
4673                                 found = 1;
4674 -                               DEB2(printk("i2c-core.o: found normal i2c entry for adapter %d, "
4675 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c entry for adapter %d, "
4676                                             "addr %02x", adap_id,addr));
4677                         }
4678                 }
4679 @@ -950,7 +866,7 @@
4680                         if ((addr >= address_data->normal_i2c_range[i]) &&
4681                             (addr <= address_data->normal_i2c_range[i+1])) {
4682                                 found = 1;
4683 -                               DEB2(printk("i2c-core.o: found normal i2c_range entry for adapter %d, "
4684 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found normal i2c_range entry for adapter %d, "
4685                                             "addr %04x\n", adap_id,addr));
4686                         }
4687                 }
4688 @@ -962,7 +878,7 @@
4689                             ((address_data->probe[i] == ANY_I2C_BUS))) &&
4690                             (addr == address_data->probe[i+1])) {
4691                                 found = 1;
4692 -                               DEB2(printk("i2c-core.o: found probe parameter for adapter %d, "
4693 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found probe parameter for adapter %d, "
4694                                             "addr %04x\n", adap_id,addr));
4695                         }
4696                 }
4697 @@ -974,7 +890,7 @@
4698                            (addr >= address_data->probe_range[i+1]) &&
4699                            (addr <= address_data->probe_range[i+2])) {
4700                                 found = 1;
4701 -                               DEB2(printk("i2c-core.o: found probe_range parameter for adapter %d, "
4702 +                               DEB2(printk(KERN_DEBUG "i2c-core.o: found probe_range parameter for adapter %d, "
4703                                             "addr %04x\n", adap_id,addr));
4704                         }
4705                 }
4706 @@ -1004,6 +920,123 @@
4707  
4708  /* The SMBus parts */
4709  
4710 +#define POLY    (0x1070U << 3) 
4711 +static u8
4712 +crc8(u16 data)
4713 +{
4714 +       int i;
4715 +  
4716 +       for(i = 0; i < 8; i++) {
4717 +               if (data & 0x8000) 
4718 +                       data = data ^ POLY;
4719 +               data = data << 1;
4720 +       }
4721 +       return (u8)(data >> 8);
4722 +}
4723 +
4724 +/* CRC over count bytes in the first array plus the bytes in the rest
4725 +   array if it is non-null. rest[0] is the (length of rest) - 1
4726 +   and is included. */
4727 +u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
4728 +{
4729 +       int i;
4730 +
4731 +       for(i = 0; i < count; i++)
4732 +               crc = crc8((crc ^ first[i]) << 8);
4733 +       if(rest != NULL)
4734 +               for(i = 0; i <= rest[0]; i++)
4735 +                       crc = crc8((crc ^ rest[i]) << 8);
4736 +       return crc;
4737 +}
4738 +
4739 +u8 i2c_smbus_pec(int count, u8 *first, u8 *rest)
4740 +{
4741 +       return i2c_smbus_partial_pec(0, count, first, rest);
4742 +}
4743 +
4744 +/* Returns new "size" (transaction type)
4745 +   Note that we convert byte to byte_data and byte_data to word_data
4746 +   rather than invent new xxx_PEC transactions. */
4747 +int i2c_smbus_add_pec(u16 addr, u8 command, int size,
4748 +                      union i2c_smbus_data *data)
4749 +{
4750 +       u8 buf[3];
4751 +
4752 +       buf[0] = addr << 1;
4753 +       buf[1] = command;
4754 +       switch(size) {
4755 +               case I2C_SMBUS_BYTE:
4756 +                       data->byte = i2c_smbus_pec(2, buf, NULL);
4757 +                       size = I2C_SMBUS_BYTE_DATA;
4758 +                       break;
4759 +               case I2C_SMBUS_BYTE_DATA:
4760 +                       buf[2] = data->byte;
4761 +                       data->word = buf[2] ||
4762 +                                   (i2c_smbus_pec(3, buf, NULL) << 8);
4763 +                       size = I2C_SMBUS_WORD_DATA;
4764 +                       break;
4765 +               case I2C_SMBUS_WORD_DATA:
4766 +                       /* unsupported */
4767 +                       break;
4768 +               case I2C_SMBUS_BLOCK_DATA:
4769 +                       data->block[data->block[0] + 1] =
4770 +                                    i2c_smbus_pec(2, buf, data->block);
4771 +                       size = I2C_SMBUS_BLOCK_DATA_PEC;
4772 +                       break;
4773 +       }
4774 +       return size;    
4775 +}
4776 +
4777 +int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial,
4778 +                        union i2c_smbus_data *data)
4779 +{
4780 +       u8 buf[3], rpec, cpec;
4781 +
4782 +       buf[1] = command;
4783 +       switch(size) {
4784 +               case I2C_SMBUS_BYTE_DATA:
4785 +                       buf[0] = (addr << 1) | 1;
4786 +                       cpec = i2c_smbus_pec(2, buf, NULL);
4787 +                       rpec = data->byte;
4788 +                       break;
4789 +               case I2C_SMBUS_WORD_DATA:
4790 +                       buf[0] = (addr << 1) | 1;
4791 +                       buf[2] = data->word & 0xff;
4792 +                       cpec = i2c_smbus_pec(3, buf, NULL);
4793 +                       rpec = data->word >> 8;
4794 +                       break;
4795 +               case I2C_SMBUS_WORD_DATA_PEC:
4796 +                       /* unsupported */
4797 +                       cpec = rpec = 0;
4798 +                       break;
4799 +               case I2C_SMBUS_PROC_CALL_PEC:
4800 +                       /* unsupported */
4801 +                       cpec = rpec = 0;
4802 +                       break;
4803 +               case I2C_SMBUS_BLOCK_DATA_PEC:
4804 +                       buf[0] = (addr << 1);
4805 +                       buf[2] = (addr << 1) | 1;
4806 +                       cpec = i2c_smbus_pec(3, buf, data->block);
4807 +                       rpec = data->block[data->block[0] + 1];
4808 +                       break;
4809 +               case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4810 +                       buf[0] = (addr << 1) | 1;
4811 +                       rpec = i2c_smbus_partial_pec(partial, 1,
4812 +                                                    buf, data->block);
4813 +                       cpec = data->block[data->block[0] + 1];
4814 +                       break;
4815 +               default:
4816 +                       cpec = rpec = 0;
4817 +                       break;
4818 +       }
4819 +       if(rpec != cpec) {
4820 +               DEB(printk(KERN_DEBUG "i2c-core.o: Bad PEC 0x%02x vs. 0x%02x\n",
4821 +                          rpec, cpec));
4822 +               return -1;
4823 +       }
4824 +       return 0;       
4825 +}
4826 +
4827  extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value)
4828  {
4829         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4830 @@ -1022,8 +1055,9 @@
4831  
4832  extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value)
4833  {
4834 +       union i2c_smbus_data data;      /* only for PEC */
4835         return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4836 -                             I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL);
4837 +                             I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data);
4838  }
4839  
4840  extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command)
4841 @@ -1101,8 +1135,8 @@
4842  {
4843         union i2c_smbus_data data;
4844         int i;
4845 -       if (length > 32)
4846 -               length = 32;
4847 +       if (length > I2C_SMBUS_BLOCK_MAX)
4848 +               length = I2C_SMBUS_BLOCK_MAX;
4849         for (i = 1; i <= length; i++)
4850                 data.block[i] = values[i-1];
4851         data.block[0] = length;
4852 @@ -1111,13 +1145,50 @@
4853                               I2C_SMBUS_BLOCK_DATA,&data);
4854  }
4855  
4856 +/* Returns the number of read bytes */
4857 +extern s32 i2c_smbus_block_process_call(struct i2c_client * client,
4858 +                                        u8 command, u8 length, u8 *values)
4859 +{
4860 +       union i2c_smbus_data data;
4861 +       int i;
4862 +       if (length > I2C_SMBUS_BLOCK_MAX - 1)
4863 +               return -1;
4864 +       data.block[0] = length;
4865 +       for (i = 1; i <= length; i++)
4866 +               data.block[i] = values[i-1];
4867 +       if(i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4868 +                         I2C_SMBUS_WRITE, command,
4869 +                         I2C_SMBUS_BLOCK_PROC_CALL, &data))
4870 +               return -1;
4871 +       for (i = 1; i <= data.block[0]; i++)
4872 +               values[i-1] = data.block[i];
4873 +       return data.block[0];
4874 +}
4875 +
4876 +/* Returns the number of read bytes */
4877 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
4878 +                                         u8 command, u8 *values)
4879 +{
4880 +       union i2c_smbus_data data;
4881 +       int i;
4882 +       if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
4883 +                             I2C_SMBUS_READ,command,
4884 +                             I2C_SMBUS_I2C_BLOCK_DATA,&data))
4885 +               return -1;
4886 +       else {
4887 +               for (i = 1; i <= data.block[0]; i++)
4888 +                       values[i-1] = data.block[i];
4889 +               return data.block[0];
4890 +       }
4891 +}
4892 +
4893  extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
4894                                            u8 command, u8 length, u8 *values)
4895  {
4896         union i2c_smbus_data data;
4897         int i;
4898 -       if (length > 32)
4899 -               length = 32;
4900 +       if (length > I2C_SMBUS_I2C_BLOCK_MAX)
4901 +               length = I2C_SMBUS_I2C_BLOCK_MAX;
4902         for (i = 1; i <= length; i++)
4903                 data.block[i] = values[i-1];
4904         data.block[0] = length;
4905 @@ -1179,30 +1250,54 @@
4906                 break;
4907         case I2C_SMBUS_PROC_CALL:
4908                 num = 2; /* Special case */
4909 +               read_write = I2C_SMBUS_READ;
4910                 msg[0].len = 3;
4911                 msg[1].len = 2;
4912                 msgbuf0[1] = data->word & 0xff;
4913                 msgbuf0[2] = (data->word >> 8) & 0xff;
4914                 break;
4915         case I2C_SMBUS_BLOCK_DATA:
4916 +       case I2C_SMBUS_BLOCK_DATA_PEC:
4917                 if (read_write == I2C_SMBUS_READ) {
4918 -                       printk("i2c-core.o: Block read not supported under "
4919 -                              "I2C emulation!\n");
4920 -               return -1;
4921 +                       printk(KERN_ERR "i2c-core.o: Block read not supported "
4922 +                              "under I2C emulation!\n");
4923 +                       return -1;
4924                 } else {
4925                         msg[0].len = data->block[0] + 2;
4926 -                       if (msg[0].len > 34) {
4927 -                               printk("i2c-core.o: smbus_access called with "
4928 +                       if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
4929 +                               printk(KERN_ERR "i2c-core.o: smbus_access called with "
4930                                        "invalid block write size (%d)\n",
4931 -                                      msg[0].len);
4932 +                                      data->block[0]);
4933                                 return -1;
4934                         }
4935 +                       if(size == I2C_SMBUS_BLOCK_DATA_PEC)
4936 +                               (msg[0].len)++;
4937                         for (i = 1; i <= msg[0].len; i++)
4938                                 msgbuf0[i] = data->block[i-1];
4939                 }
4940                 break;
4941 +       case I2C_SMBUS_BLOCK_PROC_CALL:
4942 +       case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
4943 +               printk(KERN_ERR "i2c-core.o: Block process call not supported "
4944 +                      "under I2C emulation!\n");
4945 +               return -1;
4946 +       case I2C_SMBUS_I2C_BLOCK_DATA:
4947 +               if (read_write == I2C_SMBUS_READ) {
4948 +                       msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX;
4949 +               } else {
4950 +                       msg[0].len = data->block[0] + 1;
4951 +                       if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) {
4952 +                               printk("i2c-core.o: i2c_smbus_xfer_emulated called with "
4953 +                                      "invalid block write size (%d)\n",
4954 +                                      data->block[0]);
4955 +                               return -1;
4956 +                       }
4957 +                       for (i = 1; i <= data->block[0]; i++)
4958 +                               msgbuf0[i] = data->block[i];
4959 +               }
4960 +               break;
4961         default:
4962 -               printk("i2c-core.o: smbus_access called with invalid size (%d)\n",
4963 +               printk(KERN_ERR "i2c-core.o: smbus_access called with invalid size (%d)\n",
4964                        size);
4965                 return -1;
4966         }
4967 @@ -1222,25 +1317,61 @@
4968                         case I2C_SMBUS_PROC_CALL:
4969                                 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
4970                                 break;
4971 +                       case I2C_SMBUS_I2C_BLOCK_DATA:
4972 +                               /* fixed at 32 for now */
4973 +                               data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX;
4974 +                               for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++)
4975 +                                       data->block[i+1] = msgbuf1[i];
4976 +                               break;
4977                 }
4978         return 0;
4979  }
4980  
4981  
4982 -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
4983 +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
4984                     char read_write, u8 command, int size, 
4985                     union i2c_smbus_data * data)
4986  {
4987         s32 res;
4988 -       flags = flags & I2C_M_TEN;
4989 -       if (adapter->algo->smbus_xfer) {
4990 -               I2C_LOCK(adapter);
4991 -               res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
4992 +       int swpec = 0;
4993 +       u8 partial = 0;
4994 +
4995 +       flags &= I2C_M_TEN | I2C_CLIENT_PEC;
4996 +       if((flags & I2C_CLIENT_PEC) &&
4997 +          !(i2c_check_functionality(adap, I2C_FUNC_SMBUS_HWPEC_CALC))) {
4998 +               swpec = 1;
4999 +               if(read_write == I2C_SMBUS_READ &&
5000 +                  size == I2C_SMBUS_BLOCK_DATA)
5001 +                       size = I2C_SMBUS_BLOCK_DATA_PEC;
5002 +               else if(size == I2C_SMBUS_PROC_CALL)
5003 +                       size = I2C_SMBUS_PROC_CALL_PEC;
5004 +               else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
5005 +                       i2c_smbus_add_pec(addr, command,
5006 +                                         I2C_SMBUS_BLOCK_DATA, data);
5007 +                       partial = data->block[data->block[0] + 1];
5008 +                       size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
5009 +               } else if(read_write == I2C_SMBUS_WRITE &&
5010 +                         size != I2C_SMBUS_QUICK &&
5011 +                         size != I2C_SMBUS_I2C_BLOCK_DATA)
5012 +                       size = i2c_smbus_add_pec(addr, command, size, data);
5013 +       }
5014 +
5015 +       if (adap->algo->smbus_xfer) {
5016 +               down(&adap->bus);
5017 +               res = adap->algo->smbus_xfer(adap,addr,flags,read_write,
5018                                                 command,size,data);
5019 -               I2C_UNLOCK(adapter);
5020 +               up(&adap->bus);
5021         } else
5022 -               res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
5023 +               res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write,
5024                                               command,size,data);
5025 +
5026 +       if(res >= 0 && swpec &&
5027 +          size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
5028 +          (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
5029 +           size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
5030 +               if(i2c_smbus_check_pec(addr, command, size, partial, data))
5031 +                       return -1;
5032 +       }
5033         return res;
5034  }
5035  
5036 @@ -1264,139 +1395,38 @@
5037  
5038  static int __init i2c_init(void)
5039  {
5040 -       printk(KERN_INFO "i2c-core.o: i2c core module\n");
5041 +       printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5042         memset(adapters,0,sizeof(adapters));
5043         memset(drivers,0,sizeof(drivers));
5044 -       adap_count=0;
5045 -       driver_count=0;
5046  
5047 -       init_MUTEX(&adap_lock);
5048 -       init_MUTEX(&driver_lock);
5049 -       
5050 -       i2cproc_init();
5051 -       
5052 +#ifdef CONFIG_PROC_FS
5053 +       return i2cproc_init();
5054 +#else
5055         return 0;
5056 -}
5057 -
5058 -#ifndef MODULE
5059 -#ifdef CONFIG_I2C_CHARDEV
5060 -       extern int i2c_dev_init(void);
5061 -#endif
5062 -#ifdef CONFIG_I2C_ALGOBIT
5063 -       extern int i2c_algo_bit_init(void);
5064 -#endif
5065 -#ifdef CONFIG_I2C_PHILIPSPAR
5066 -       extern int i2c_bitlp_init(void);
5067 -#endif
5068 -#ifdef CONFIG_I2C_ELV
5069 -       extern int i2c_bitelv_init(void);
5070 -#endif
5071 -#ifdef CONFIG_I2C_VELLEMAN
5072 -       extern int i2c_bitvelle_init(void);
5073 -#endif
5074 -#ifdef CONFIG_I2C_BITVIA
5075 -       extern int i2c_bitvia_init(void);
5076 -#endif
5077 -
5078 -#ifdef CONFIG_I2C_ALGOPCF
5079 -       extern int i2c_algo_pcf_init(void);     
5080 -#endif
5081 -#ifdef CONFIG_I2C_ELEKTOR
5082 -       extern int i2c_pcfisa_init(void);
5083 -#endif
5084 -
5085 -#ifdef CONFIG_I2C_ALGO8XX
5086 -       extern int i2c_algo_8xx_init(void);
5087 -#endif
5088 -#ifdef CONFIG_I2C_RPXLITE
5089 -       extern int i2c_rpx_init(void);
5090  #endif
5091  
5092 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5093 -       extern int i2c_algo_sibyte_init(void);
5094 -       extern int i2c_sibyte_init(void);
5095 -#endif
5096 -#ifdef CONFIG_I2C_MAX1617
5097 -       extern int i2c_max1617_init(void);
5098 -#endif
5099 +}
5100  
5101 -#ifdef CONFIG_I2C_PROC
5102 -       extern int sensors_init(void);
5103 +static void __exit i2c_exit(void) 
5104 +{
5105 +#ifdef CONFIG_PROC_FS
5106 +       i2cproc_cleanup();
5107  #endif
5108 +}
5109  
5110 -/* This is needed for automatic patch generation: sensors code starts here */
5111 -/* This is needed for automatic patch generation: sensors code ends here   */
5112 -
5113 +/* leave this in for now simply to make patching easier so we don't have
5114 +   to remove the call in drivers/char/mem.c */
5115  int __init i2c_init_all(void)
5116  {
5117 -       /* --------------------- global ----- */
5118 -       i2c_init();
5119 -
5120 -#ifdef CONFIG_I2C_CHARDEV
5121 -       i2c_dev_init();
5122 -#endif
5123 -       /* --------------------- bit -------- */
5124 -#ifdef CONFIG_I2C_ALGOBIT
5125 -       i2c_algo_bit_init();
5126 -#endif
5127 -#ifdef CONFIG_I2C_PHILIPSPAR
5128 -       i2c_bitlp_init();
5129 -#endif
5130 -#ifdef CONFIG_I2C_ELV
5131 -       i2c_bitelv_init();
5132 -#endif
5133 -#ifdef CONFIG_I2C_VELLEMAN
5134 -       i2c_bitvelle_init();
5135 -#endif
5136 -
5137 -       /* --------------------- pcf -------- */
5138 -#ifdef CONFIG_I2C_ALGOPCF
5139 -       i2c_algo_pcf_init();    
5140 -#endif
5141 -#ifdef CONFIG_I2C_ELEKTOR
5142 -       i2c_pcfisa_init();
5143 -#endif
5144 -
5145 -       /* --------------------- 8xx -------- */
5146 -#ifdef CONFIG_I2C_ALGO8XX
5147 -       i2c_algo_8xx_init();
5148 -#endif
5149 -#ifdef CONFIG_I2C_RPXLITE
5150 -       i2c_rpx_init();
5151 -#endif
5152 -
5153 -       /* --------------------- SiByte -------- */
5154 -#ifdef CONFIG_I2C_ALGO_SIBYTE
5155 -       i2c_algo_sibyte_init();
5156 -       i2c_sibyte_init();
5157 -#endif
5158 -#ifdef CONFIG_I2C_MAX1617
5159 -       i2c_max1617_init();
5160 -#endif
5161 -
5162 -       /* -------------- proc interface ---- */
5163 -#ifdef CONFIG_I2C_PROC
5164 -       sensors_init();
5165 -#endif
5166 -/* This is needed for automatic patch generation: sensors code starts here */
5167 -/* This is needed for automatic patch generation: sensors code ends here */
5168 -
5169         return 0;
5170  }
5171  
5172 -#endif
5173 -
5174 -
5175 -
5176  EXPORT_SYMBOL(i2c_add_adapter);
5177  EXPORT_SYMBOL(i2c_del_adapter);
5178  EXPORT_SYMBOL(i2c_add_driver);
5179  EXPORT_SYMBOL(i2c_del_driver);
5180  EXPORT_SYMBOL(i2c_attach_client);
5181  EXPORT_SYMBOL(i2c_detach_client);
5182 -EXPORT_SYMBOL(i2c_inc_use_client);
5183 -EXPORT_SYMBOL(i2c_dec_use_client);
5184 -EXPORT_SYMBOL(i2c_get_client);
5185  EXPORT_SYMBOL(i2c_use_client);
5186  EXPORT_SYMBOL(i2c_release_client);
5187  EXPORT_SYMBOL(i2c_check_addr);
5188 @@ -1420,24 +1450,18 @@
5189  EXPORT_SYMBOL(i2c_smbus_process_call);
5190  EXPORT_SYMBOL(i2c_smbus_read_block_data);
5191  EXPORT_SYMBOL(i2c_smbus_write_block_data);
5192 +EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
5193 +EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
5194  
5195  EXPORT_SYMBOL(i2c_get_functionality);
5196  EXPORT_SYMBOL(i2c_check_functionality);
5197  
5198 -#ifdef MODULE
5199  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5200  MODULE_DESCRIPTION("I2C-Bus main module");
5201 -MODULE_PARM(i2c_debug, "i");
5202 -MODULE_PARM_DESC(i2c_debug,"debug level");
5203  MODULE_LICENSE("GPL");
5204  
5205 -int init_module(void) 
5206 -{
5207 -       return i2c_init();
5208 -}
5209 +MODULE_PARM(i2c_debug, "i");
5210 +MODULE_PARM_DESC(i2c_debug,"debug level");
5211  
5212 -void cleanup_module(void) 
5213 -{
5214 -       i2cproc_cleanup();
5215 -}
5216 -#endif
5217 +module_init(i2c_init);
5218 +module_exit(i2c_exit);
5219 --- linux-old/drivers/i2c/i2c-dev.c     Wed Aug 27 16:11:46 2003
5220 +++ linux/drivers/i2c/i2c-dev.c Sun Dec  7 11:17:40 2003
5221 @@ -28,41 +28,27 @@
5222  /* The devfs code is contributed by Philipp Matthias Hahn 
5223     <pmhahn@titan.lahn.de> */
5224  
5225 -/* $Id$ */
5226 +/* $Id$ */
5227  
5228 -#include <linux/config.h>
5229  #include <linux/kernel.h>
5230  #include <linux/module.h>
5231  #include <linux/fs.h>
5232  #include <linux/slab.h>
5233 -#include <linux/version.h>
5234 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5235  #include <linux/smp_lock.h>
5236 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5237  #ifdef CONFIG_DEVFS_FS
5238  #include <linux/devfs_fs_kernel.h>
5239  #endif
5240 -
5241 -
5242 -/* If you want debugging uncomment: */
5243 -/* #define DEBUG */
5244 -
5245  #include <linux/init.h>
5246 -#include <asm/uaccess.h>
5247 -
5248  #include <linux/i2c.h>
5249  #include <linux/i2c-dev.h>
5250 +#include <asm/uaccess.h>
5251 +
5252 +/* If you want debugging uncomment: */
5253 +/* #define DEBUG */
5254  
5255 -#ifdef MODULE
5256 -extern int init_module(void);
5257 -extern int cleanup_module(void);
5258 -#endif /* def MODULE */
5259  
5260  /* struct file_operations changed too often in the 2.1 series for nice code */
5261  
5262 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5263 -static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin);
5264 -#endif
5265  static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, 
5266                              loff_t *offset);
5267  static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count, 
5268 @@ -79,28 +65,14 @@
5269  static int i2cdev_command(struct i2c_client *client, unsigned int cmd,
5270                             void *arg);
5271  
5272 -#ifdef MODULE
5273 -static
5274 -#else
5275 -extern
5276 -#endif
5277 -       int __init i2c_dev_init(void);
5278 -static int i2cdev_cleanup(void);
5279 -
5280  static struct file_operations i2cdev_fops = {
5281 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5282 -       owner:          THIS_MODULE,
5283 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5284 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5285 -       llseek:         i2cdev_lseek,
5286 -#else
5287 -       llseek:         no_llseek,
5288 -#endif
5289 -       read:           i2cdev_read,
5290 -       write:          i2cdev_write,
5291 -       ioctl:          i2cdev_ioctl,
5292 -       open:           i2cdev_open,
5293 -       release:        i2cdev_release,
5294 +       .owner          = THIS_MODULE,
5295 +       .llseek         = no_llseek,
5296 +       .read           = i2cdev_read,
5297 +       .write          = i2cdev_write,
5298 +       .ioctl          = i2cdev_ioctl,
5299 +       .open           = i2cdev_open,
5300 +       .release        = i2cdev_release,
5301  };
5302  
5303  #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX
5304 @@ -111,42 +83,22 @@
5305  #endif
5306  
5307  static struct i2c_driver i2cdev_driver = {
5308 -       name:           "i2c-dev dummy driver",
5309 -       id:             I2C_DRIVERID_I2CDEV,
5310 -       flags:          I2C_DF_DUMMY,
5311 -       attach_adapter: i2cdev_attach_adapter,
5312 -       detach_client:  i2cdev_detach_client,
5313 -       command:        i2cdev_command,
5314 -/*     inc_use:        NULL,
5315 -       dec_use:        NULL, */
5316 +       .owner          = THIS_MODULE, /* not really used */
5317 +       .name           = "i2c-dev dummy driver",
5318 +       .id             = I2C_DRIVERID_I2CDEV,
5319 +       .flags          = I2C_DF_DUMMY,
5320 +       .attach_adapter = i2cdev_attach_adapter,
5321 +       .detach_client  = i2cdev_detach_client,
5322 +       .command        = i2cdev_command,
5323  };
5324  
5325  static struct i2c_client i2cdev_client_template = {
5326 -       name:           "I2C /dev entry",
5327 -       id:             1,
5328 -       flags:          0,
5329 -       addr:           -1,
5330 -/*     adapter:        NULL, */
5331 -       driver:         &i2cdev_driver,
5332 -/*     data:           NULL */
5333 +       .name           = "I2C /dev entry",
5334 +       .id             = 1,
5335 +       .addr           = -1,
5336 +       .driver         = &i2cdev_driver,
5337  };
5338  
5339 -static int i2cdev_initialized;
5340 -
5341 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9)
5342 -/* Note that the lseek function is called llseek in 2.1 kernels. But things
5343 -   are complicated enough as is. */
5344 -loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin)
5345 -{
5346 -#ifdef DEBUG
5347 -       struct inode *inode = file->f_dentry->d_inode;
5348 -       printk("i2c-dev.o: i2c-%d lseek to %ld bytes relative to %d.\n",
5349 -              MINOR(inode->i_rdev),(long) offset,origin);
5350 -#endif /* DEBUG */
5351 -       return -ESPIPE;
5352 -}
5353 -#endif
5354 -
5355  static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
5356                              loff_t *offset)
5357  {
5358 @@ -159,16 +111,16 @@
5359  
5360         struct i2c_client *client = (struct i2c_client *)file->private_data;
5361  
5362 -       if(count > 8192)
5363 +       if (count > 8192)
5364                 count = 8192;
5365 -               
5366 +
5367         /* copy user space data to kernel space. */
5368         tmp = kmalloc(count,GFP_KERNEL);
5369         if (tmp==NULL)
5370                 return -ENOMEM;
5371  
5372  #ifdef DEBUG
5373 -       printk("i2c-dev.o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),
5374 +       printk(KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n",minor(inode->i_rdev),
5375                count);
5376  #endif
5377  
5378 @@ -190,9 +142,9 @@
5379         struct inode *inode = file->f_dentry->d_inode;
5380  #endif /* DEBUG */
5381  
5382 -       if(count > 8192)
5383 +       if (count > 8192)
5384                 count = 8192;
5385 -               
5386 +
5387         /* copy user space data to kernel space. */
5388         tmp = kmalloc(count,GFP_KERNEL);
5389         if (tmp==NULL)
5390 @@ -203,7 +155,7 @@
5391         }
5392  
5393  #ifdef DEBUG
5394 -       printk("i2c-dev.o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),
5395 +       printk(KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n",minor(inode->i_rdev),
5396                count);
5397  #endif
5398         ret = i2c_master_send(client,tmp,count);
5399 @@ -224,8 +176,8 @@
5400         unsigned long funcs;
5401  
5402  #ifdef DEBUG
5403 -       printk("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", 
5404 -              MINOR(inode->i_rdev),cmd, arg);
5405 +       printk(KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", 
5406 +              minor(inode->i_rdev),cmd, arg);
5407  #endif /* DEBUG */
5408  
5409         switch ( cmd ) {
5410 @@ -244,6 +196,12 @@
5411                 else
5412                         client->flags &= ~I2C_M_TEN;
5413                 return 0;
5414 +       case I2C_PEC:
5415 +               if (arg)
5416 +                       client->flags |= I2C_CLIENT_PEC;
5417 +               else
5418 +                       client->flags &= ~I2C_CLIENT_PEC;
5419 +               return 0;
5420         case I2C_FUNCS:
5421                 funcs = i2c_get_functionality(client->adapter);
5422                 return (copy_to_user((unsigned long *)arg,&funcs,
5423 @@ -344,9 +302,10 @@
5424                     (data_arg.size != I2C_SMBUS_WORD_DATA) &&
5425                     (data_arg.size != I2C_SMBUS_PROC_CALL) &&
5426                     (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
5427 -                   (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {
5428 +                   (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
5429 +                   (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
5430  #ifdef DEBUG
5431 -                       printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5432 +                       printk(KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n",
5433                                data_arg.size);
5434  #endif
5435                         return -EINVAL;
5436 @@ -356,7 +315,7 @@
5437                 if ((data_arg.read_write != I2C_SMBUS_READ) && 
5438                     (data_arg.read_write != I2C_SMBUS_WRITE)) {
5439  #ifdef DEBUG
5440 -                       printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5441 +                       printk(KERN_DEBUG "i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n",
5442                                data_arg.read_write);
5443  #endif
5444                         return -EINVAL;
5445 @@ -376,7 +335,7 @@
5446  
5447                 if (data_arg.data == NULL) {
5448  #ifdef DEBUG
5449 -                       printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5450 +                       printk(KERN_DEBUG "i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n");
5451  #endif
5452                         return -EINVAL;
5453                 }
5454 @@ -387,10 +346,11 @@
5455                 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || 
5456                          (data_arg.size == I2C_SMBUS_PROC_CALL))
5457                         datasize = sizeof(data_arg.data->word);
5458 -               else /* size == I2C_SMBUS_BLOCK_DATA */
5459 +               else /* size == smbus block, i2c block, or block proc. call */
5460                         datasize = sizeof(data_arg.data->block);
5461  
5462                 if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 
5463 +                   (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 
5464                     (data_arg.read_write == I2C_SMBUS_WRITE)) {
5465                         if (copy_from_user(&temp, data_arg.data, datasize))
5466                                 return -EFAULT;
5467 @@ -399,6 +359,7 @@
5468                       data_arg.read_write,
5469                       data_arg.command,data_arg.size,&temp);
5470                 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || 
5471 +                             (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 
5472                               (data_arg.read_write == I2C_SMBUS_READ))) {
5473                         if (copy_to_user(data_arg.data, &temp, datasize))
5474                                 return -EFAULT;
5475 @@ -413,12 +374,12 @@
5476  
5477  int i2cdev_open (struct inode *inode, struct file *file)
5478  {
5479 -       unsigned int minor = MINOR(inode->i_rdev);
5480 +       unsigned int minor = minor(inode->i_rdev);
5481         struct i2c_client *client;
5482  
5483         if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) {
5484  #ifdef DEBUG
5485 -               printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5486 +               printk(KERN_DEBUG "i2c-dev.o: Trying to open unattached adapter i2c-%d\n",
5487                        minor);
5488  #endif
5489                 return -ENODEV;
5490 @@ -429,39 +390,35 @@
5491         if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL)))
5492                 return -ENOMEM;
5493         memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client));
5494 +
5495 +       /* registered with adapter, passed as client to user */
5496         client->adapter = i2cdev_adaps[minor];
5497         file->private_data = client;
5498  
5499 -       if (i2cdev_adaps[minor]->inc_use)
5500 -               i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]);
5501 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5502 -       MOD_INC_USE_COUNT;
5503 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5504 +       if(client->adapter->owner)
5505 +               __MOD_INC_USE_COUNT(client->adapter->owner);
5506  
5507  #ifdef DEBUG
5508 -       printk("i2c-dev.o: opened i2c-%d\n",minor);
5509 +       printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor);
5510  #endif
5511         return 0;
5512  }
5513  
5514  static int i2cdev_release (struct inode *inode, struct file *file)
5515  {
5516 -       unsigned int minor = MINOR(inode->i_rdev);
5517 -       kfree(file->private_data);
5518 -       file->private_data=NULL;
5519 -#ifdef DEBUG
5520 -       printk("i2c-dev.o: Closed: i2c-%d\n", minor);
5521 -#endif
5522 -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0)
5523 -       MOD_DEC_USE_COUNT;
5524 -#else /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5525 -       lock_kernel();
5526 -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */
5527 -       if (i2cdev_adaps[minor]->dec_use)
5528 -               i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]);
5529 -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
5530 -       unlock_kernel();
5531 -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
5532 +       struct i2c_client *client;
5533 +#ifdef DEBUG
5534 +       unsigned int minor = minor(inode->i_rdev);
5535 +#endif
5536 +
5537 +       client = file->private_data;
5538 +       file->private_data = NULL;
5539 +       if(client->adapter->owner)
5540 +               __MOD_DEC_USE_COUNT(client->adapter->owner);
5541 +       kfree(client);
5542 +#ifdef DEBUG
5543 +       printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor);
5544 +#endif
5545         return 0;
5546  }
5547  
5548 @@ -471,11 +428,11 @@
5549         char name[8];
5550  
5551         if ((i = i2c_adapter_id(adap)) < 0) {
5552 -               printk("i2c-dev.o: Unknown adapter ?!?\n");
5553 +               printk(KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n");
5554                 return -ENODEV;
5555         }
5556         if (i >= I2CDEV_ADAPS_MAX) {
5557 -               printk("i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5558 +               printk(KERN_DEBUG "i2c-dev.o: Adapter number too large?!? (%d)\n",i);
5559                 return -ENODEV;
5560         }
5561  
5562 @@ -486,9 +443,9 @@
5563                 devfs_i2c[i] = devfs_register (devfs_handle, name,
5564                         DEVFS_FL_DEFAULT, I2C_MAJOR, i,
5565                         S_IFCHR | S_IRUSR | S_IWUSR,
5566 -                       &i2cdev_fops, NULL);
5567 +                       &i2cdev_fops, adap);
5568  #endif
5569 -               printk("i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5570 +               printk(KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i);
5571         } else {
5572                 /* This is actually a detach_adapter call! */
5573  #ifdef CONFIG_DEVFS_FS
5574 @@ -496,7 +453,7 @@
5575  #endif
5576                 i2cdev_adaps[i] = NULL;
5577  #ifdef DEBUG
5578 -               printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5579 +               printk(KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n",adap->name);
5580  #endif
5581         }
5582  
5583 @@ -518,78 +475,43 @@
5584  {
5585         int res;
5586  
5587 -       printk("i2c-dev.o: i2c /dev entries driver module\n");
5588 +       printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);
5589  
5590 -       i2cdev_initialized = 0;
5591  #ifdef CONFIG_DEVFS_FS
5592         if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
5593  #else
5594         if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
5595  #endif
5596 -               printk("i2c-dev.o: unable to get major %d for i2c bus\n",
5597 +               printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
5598                        I2C_MAJOR);
5599                 return -EIO;
5600         }
5601  #ifdef CONFIG_DEVFS_FS
5602         devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
5603  #endif
5604 -       i2cdev_initialized ++;
5605 -
5606         if ((res = i2c_add_driver(&i2cdev_driver))) {
5607 -               printk("i2c-dev.o: Driver registration failed, module not inserted.\n");
5608 -               i2cdev_cleanup();
5609 +               printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
5610 +#ifdef CONFIG_DEVFS_FS
5611 +               devfs_unregister(devfs_handle);
5612 +#endif
5613 +               unregister_chrdev(I2C_MAJOR,"i2c");
5614                 return res;
5615         }
5616 -       i2cdev_initialized ++;
5617         return 0;
5618  }
5619  
5620 -int i2cdev_cleanup(void)
5621 +static void __exit i2c_dev_exit(void)
5622  {
5623 -       int res;
5624 -
5625 -       if (i2cdev_initialized >= 2) {
5626 -               if ((res = i2c_del_driver(&i2cdev_driver))) {
5627 -                       printk("i2c-dev.o: Driver deregistration failed, "
5628 -                              "module not removed.\n");
5629 -                       return res;
5630 -               }
5631 -       i2cdev_initialized --;
5632 -       }
5633 -
5634 -       if (i2cdev_initialized >= 1) {
5635 +       i2c_del_driver(&i2cdev_driver);
5636  #ifdef CONFIG_DEVFS_FS
5637 -               devfs_unregister(devfs_handle);
5638 -               if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
5639 -#else
5640 -               if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
5641 +       devfs_unregister(devfs_handle);
5642  #endif
5643 -                       printk("i2c-dev.o: unable to release major %d for i2c bus\n",
5644 -                              I2C_MAJOR);
5645 -                       return res;
5646 -               }
5647 -               i2cdev_initialized --;
5648 -       }
5649 -       return 0;
5650 +       unregister_chrdev(I2C_MAJOR,"i2c");
5651  }
5652  
5653 -EXPORT_NO_SYMBOLS;
5654 -
5655 -#ifdef MODULE
5656 -
5657  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
5658  MODULE_DESCRIPTION("I2C /dev entries driver");
5659  MODULE_LICENSE("GPL");
5660  
5661 -int init_module(void)
5662 -{
5663 -       return i2c_dev_init();
5664 -}
5665 -
5666 -int cleanup_module(void)
5667 -{
5668 -       return i2cdev_cleanup();
5669 -}
5670 -
5671 -#endif /* def MODULE */
5672 -
5673 +module_init(i2c_dev_init);
5674 +module_exit(i2c_dev_exit);
5675 --- linux-old/include/linux/i2c-dev.h   Tue Jul 15 10:23:54 2003
5676 +++ linux/include/linux/i2c-dev.h       Sun Dec  7 11:17:40 2003
5677 @@ -19,14 +19,16 @@
5678      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5679  */
5680  
5681 -/* $Id$ */
5682 -
5683 -#ifndef I2C_DEV_H
5684 -#define I2C_DEV_H
5685 +/* $Id$ */
5686  
5687 +#ifndef _LINUX_I2C_DEV_H
5688 +#define _LINUX_I2C_DEV_H
5689  
5690  #include <linux/types.h>
5691 -#include <linux/i2c.h>
5692 +
5693 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
5694 +#define minor(d) MINOR(d)
5695 +#endif
5696  
5697  /* Some IOCTL commands are defined in <linux/i2c.h> */
5698  /* Note: 10-bit addresses are NOT supported! */
5699 @@ -45,137 +47,4 @@
5700         __u32 nmsgs;            /* number of i2c_msgs */
5701  };
5702  
5703 -#ifndef __KERNEL__
5704 -
5705 -#include <sys/ioctl.h>
5706 -
5707 -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, 
5708 -                                     int size, union i2c_smbus_data *data)
5709 -{
5710 -       struct i2c_smbus_ioctl_data args;
5711 -
5712 -       args.read_write = read_write;
5713 -       args.command = command;
5714 -       args.size = size;
5715 -       args.data = data;
5716 -       return ioctl(file,I2C_SMBUS,&args);
5717 -}
5718 -
5719 -
5720 -static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
5721 -{
5722 -       return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
5723 -}
5724 -       
5725 -static inline __s32 i2c_smbus_read_byte(int file)
5726 -{
5727 -       union i2c_smbus_data data;
5728 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
5729 -               return -1;
5730 -       else
5731 -               return 0x0FF & data.byte;
5732 -}
5733 -
5734 -static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
5735 -{
5736 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
5737 -                               I2C_SMBUS_BYTE,NULL);
5738 -}
5739 -
5740 -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
5741 -{
5742 -       union i2c_smbus_data data;
5743 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5744 -                            I2C_SMBUS_BYTE_DATA,&data))
5745 -               return -1;
5746 -       else
5747 -               return 0x0FF & data.byte;
5748 -}
5749 -
5750 -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, 
5751 -                                              __u8 value)
5752 -{
5753 -       union i2c_smbus_data data;
5754 -       data.byte = value;
5755 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5756 -                               I2C_SMBUS_BYTE_DATA, &data);
5757 -}
5758 -
5759 -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
5760 -{
5761 -       union i2c_smbus_data data;
5762 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5763 -                            I2C_SMBUS_WORD_DATA,&data))
5764 -               return -1;
5765 -       else
5766 -               return 0x0FFFF & data.word;
5767 -}
5768 -
5769 -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, 
5770 -                                              __u16 value)
5771 -{
5772 -       union i2c_smbus_data data;
5773 -       data.word = value;
5774 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5775 -                               I2C_SMBUS_WORD_DATA, &data);
5776 -}
5777 -
5778 -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
5779 -{
5780 -       union i2c_smbus_data data;
5781 -       data.word = value;
5782 -       if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5783 -                            I2C_SMBUS_PROC_CALL,&data))
5784 -               return -1;
5785 -       else
5786 -               return 0x0FFFF & data.word;
5787 -}
5788 -
5789 -
5790 -/* Returns the number of read bytes */
5791 -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command, 
5792 -                                              __u8 *values)
5793 -{
5794 -       union i2c_smbus_data data;
5795 -       int i;
5796 -       if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
5797 -                            I2C_SMBUS_BLOCK_DATA,&data))
5798 -               return -1;
5799 -       else {
5800 -               for (i = 1; i <= data.block[0]; i++)
5801 -                       values[i-1] = data.block[i];
5802 -                       return data.block[0];
5803 -       }
5804 -}
5805 -
5806 -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, 
5807 -                                               __u8 length, __u8 *values)
5808 -{
5809 -       union i2c_smbus_data data;
5810 -       int i;
5811 -       if (length > 32)
5812 -               length = 32;
5813 -       for (i = 1; i <= length; i++)
5814 -               data.block[i] = values[i-1];
5815 -       data.block[0] = length;
5816 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5817 -                               I2C_SMBUS_BLOCK_DATA, &data);
5818 -}
5819 -
5820 -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
5821 -                                               __u8 length, __u8 *values)
5822 -{
5823 -       union i2c_smbus_data data;
5824 -       int i;
5825 -       if (length > 32)
5826 -               length = 32;
5827 -       for (i = 1; i <= length; i++)
5828 -               data.block[i] = values[i-1];
5829 -       data.block[0] = length;
5830 -       return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
5831 -                               I2C_SMBUS_I2C_BLOCK_DATA, &data);
5832 -}
5833 -
5834 -#endif /* ndef __KERNEL__ */
5835 -
5836 -#endif
5837 +#endif /* _LINUX_I2C_DEV_H */
5838 --- linux-old/drivers/i2c/i2c-elektor.c Thu Oct 11 15:05:47 2001
5839 +++ linux/drivers/i2c/i2c-elektor.c     Sun Dec  7 11:17:40 2003
5840 @@ -30,37 +30,32 @@
5841  #include <linux/module.h>
5842  #include <linux/delay.h>
5843  #include <linux/slab.h>
5844 -#include <linux/version.h>
5845  #include <linux/init.h>
5846 +#include <linux/interrupt.h>
5847  #include <linux/pci.h>
5848 -#include <asm/irq.h>
5849 -#include <asm/io.h>
5850 -
5851 +#include <linux/wait.h>
5852  #include <linux/i2c.h>
5853  #include <linux/i2c-algo-pcf.h>
5854 -#include <linux/i2c-elektor.h>
5855 -#include "i2c-pcf8584.h"
5856 +#include <asm/io.h>
5857 +#include <asm/irq.h>
5858  
5859  #define DEFAULT_BASE 0x330
5860  
5861 -static int base   = 0;
5862 -static int irq    = 0;
5863 +static int base;
5864 +static int irq;
5865  static int clock  = 0x1c;
5866  static int own    = 0x55;
5867 -static int mmapped = 0;
5868 -static int i2c_debug = 0;
5869 +static int mmapped;
5870 +static int i2c_debug;
5871  
5872  /* vdovikin: removed static struct i2c_pcf_isa gpi; code - 
5873    this module in real supports only one device, due to missing arguments
5874    in some functions, called from the algo-pcf module. Sometimes it's
5875    need to be rewriten - but for now just remove this for simpler reading */
5876  
5877 -#if (LINUX_VERSION_CODE < 0x020301)
5878 -static struct wait_queue *pcf_wait = NULL;
5879 -#else
5880  static wait_queue_head_t pcf_wait;
5881 -#endif
5882  static int pcf_pending;
5883 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
5884  
5885  /* ----- global defines -----------------------------------------------        */
5886  #define DEB(x) if (i2c_debug>=1) x
5887 @@ -68,17 +63,28 @@
5888  #define DEB3(x) if (i2c_debug>=3) x
5889  #define DEBE(x)        x       /* error messages                               */
5890  
5891 +
5892 +/* compatibility */
5893 +#ifndef isa_readb
5894 +#define isa_readb readb
5895 +#endif
5896 +
5897 +#ifndef isa_writeb
5898 +#define isa_writeb writeb
5899 +#endif
5900 +
5901  /* ----- local functions ----------------------------------------------        */
5902  
5903  static void pcf_isa_setbyte(void *data, int ctl, int val)
5904  {
5905         int address = ctl ? (base + 1) : base;
5906  
5907 -       if (ctl && irq) {
5908 +       /* enable irq if any specified for serial operation */
5909 +       if (ctl && irq && (val & I2C_PCF_ESO)) {
5910                 val |= I2C_PCF_ENI;
5911         }
5912  
5913 -       DEB3(printk("i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5914 +       DEB3(printk(KERN_DEBUG "i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
5915  
5916         switch (mmapped) {
5917         case 0: /* regular I/O */
5918 @@ -86,10 +92,10 @@
5919                 break;
5920         case 2: /* double mapped I/O needed for UP2000 board,
5921                     I don't know why this... */
5922 -               writeb(val, address);
5923 +               isa_writeb(val, address);
5924                 /* fall */
5925         case 1: /* memory mapped I/O */
5926 -               writeb(val, address);
5927 +               isa_writeb(val, address);
5928                 break;
5929         }
5930  }
5931 @@ -97,9 +103,9 @@
5932  static int pcf_isa_getbyte(void *data, int ctl)
5933  {
5934         int address = ctl ? (base + 1) : base;
5935 -       int val = mmapped ? readb(address) : inb(address);
5936 +       int val = mmapped ? isa_readb(address) : inb(address);
5937  
5938 -       DEB3(printk("i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5939 +       DEB3(printk(KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
5940  
5941         return (val);
5942  }
5943 @@ -120,12 +126,12 @@
5944         int timeout = 2;
5945  
5946         if (irq > 0) {
5947 -               cli();
5948 +               spin_lock_irq(&irq_driver_lock);
5949                 if (pcf_pending == 0) {
5950                         interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
5951                 } else
5952                         pcf_pending = 0;
5953 -               sti();
5954 +               spin_unlock_irq(&irq_driver_lock);
5955         } else {
5956                 udelay(100);
5957         }
5958 @@ -141,16 +147,16 @@
5959  static int pcf_isa_init(void)
5960  {
5961         if (!mmapped) {
5962 -               if (check_region(base, 2) < 0 ) {
5963 -                       printk("i2c-elektor.o: requested I/O region (0x%X:2) is in use.\n", base);
5964 +               if (!request_region(base, 2, "i2c (isa bus adapter)")) {
5965 +                       printk(KERN_ERR
5966 +                              "i2c-elektor.o: requested I/O region (0x%X:2) "
5967 +                              "is in use.\n", base);
5968                         return -ENODEV;
5969 -               } else {
5970 -                       request_region(base, 2, "i2c (isa bus adapter)");
5971                 }
5972         }
5973         if (irq > 0) {
5974                 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", 0) < 0) {
5975 -                       printk("i2c-elektor.o: Request irq%d failed\n", irq);
5976 +                       printk(KERN_ERR "i2c-elektor.o: Request irq%d failed\n", irq);
5977                         irq = 0;
5978                 } else
5979                         enable_irq(irq);
5980 @@ -159,70 +165,29 @@
5981  }
5982  
5983  
5984 -static void __exit pcf_isa_exit(void)
5985 -{
5986 -       if (irq > 0) {
5987 -               disable_irq(irq);
5988 -               free_irq(irq, 0);
5989 -       }
5990 -       if (!mmapped) {
5991 -               release_region(base , 2);
5992 -       }
5993 -}
5994 -
5995 -
5996 -static int pcf_isa_reg(struct i2c_client *client)
5997 -{
5998 -       return 0;
5999 -}
6000 -
6001 -
6002 -static int pcf_isa_unreg(struct i2c_client *client)
6003 -{
6004 -       return 0;
6005 -}
6006 -
6007 -static void pcf_isa_inc_use(struct i2c_adapter *adap)
6008 -{
6009 -#ifdef MODULE
6010 -       MOD_INC_USE_COUNT;
6011 -#endif
6012 -}
6013 -
6014 -static void pcf_isa_dec_use(struct i2c_adapter *adap)
6015 -{
6016 -#ifdef MODULE
6017 -       MOD_DEC_USE_COUNT;
6018 -#endif
6019 -}
6020 -
6021 -
6022  /* ------------------------------------------------------------------------
6023   * Encapsulate the above functions in the correct operations structure.
6024   * This is only done when more than one hardware adapter is supported.
6025   */
6026  static struct i2c_algo_pcf_data pcf_isa_data = {
6027 -       NULL,
6028 -       pcf_isa_setbyte,
6029 -       pcf_isa_getbyte,
6030 -       pcf_isa_getown,
6031 -       pcf_isa_getclock,
6032 -       pcf_isa_waitforpin,
6033 -       10, 10, 100,            /*      waits, timeout */
6034 +       .setpcf     = pcf_isa_setbyte,
6035 +       .getpcf     = pcf_isa_getbyte,
6036 +       .getown     = pcf_isa_getown,
6037 +       .getclock   = pcf_isa_getclock,
6038 +       .waitforpin = pcf_isa_waitforpin,
6039 +       .udelay     = 10,
6040 +       .mdelay     = 10,
6041 +       .timeout    = HZ,
6042  };
6043  
6044  static struct i2c_adapter pcf_isa_ops = {
6045 -       "PCF8584 ISA adapter",
6046 -       I2C_HW_P_ELEK,
6047 -       NULL,
6048 -       &pcf_isa_data,
6049 -       pcf_isa_inc_use,
6050 -       pcf_isa_dec_use,
6051 -       pcf_isa_reg,
6052 -       pcf_isa_unreg,
6053 +       .owner             = THIS_MODULE,
6054 +       .name              = "PCF8584 ISA adapter",
6055 +       .id                = I2C_HW_P_ELEK,
6056 +       .algo_data         = &pcf_isa_data,
6057  };
6058  
6059 -int __init i2c_pcfisa_init(void) 
6060 +static int __init i2c_pcfisa_init(void) 
6061  {
6062  #ifdef __alpha__
6063         /* check to see we have memory mapped PCF8584 connected to the 
6064 @@ -238,7 +203,7 @@
6065                         /* yeap, we've found cypress, let's check config */
6066                         if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
6067                                 
6068 -                               DEB3(printk("i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
6069 +                               DEB3(printk(KERN_DEBUG "i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
6070  
6071                                 /* UP2000 board has this register set to 0xe1,
6072                                     but the most significant bit as seems can be 
6073 @@ -260,7 +225,7 @@
6074                                            8.25 MHz (PCI/4) clock
6075                                            (this can be read from cypress) */
6076                                         clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
6077 -                                       printk("i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
6078 +                                       printk(KERN_INFO "i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
6079                                 }
6080                         }
6081                 }
6082 @@ -269,35 +234,51 @@
6083  
6084         /* sanity checks for mmapped I/O */
6085         if (mmapped && base < 0xc8000) {
6086 -               printk("i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
6087 +               printk(KERN_ERR "i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
6088                 return -ENODEV;
6089         }
6090  
6091 -       printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n");
6092 +       printk(KERN_INFO "i2c-elektor.o: i2c pcf8584-isa adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6093  
6094         if (base == 0) {
6095                 base = DEFAULT_BASE;
6096         }
6097  
6098 -#if (LINUX_VERSION_CODE >= 0x020301)
6099         init_waitqueue_head(&pcf_wait);
6100 -#endif
6101 -       if (pcf_isa_init() == 0) {
6102 -               if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
6103 -                       return -ENODEV;
6104 -       } else {
6105 +       if (pcf_isa_init())
6106                 return -ENODEV;
6107 -       }
6108 +       if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
6109 +               goto fail;
6110         
6111 -       printk("i2c-elektor.o: found device at %#x.\n", base);
6112 +       printk(KERN_ERR "i2c-elektor.o: found device at %#x.\n", base);
6113  
6114         return 0;
6115 +
6116 + fail:
6117 +       if (irq > 0) {
6118 +               disable_irq(irq);
6119 +               free_irq(irq, 0);
6120 +       }
6121 +
6122 +       if (!mmapped)
6123 +               release_region(base , 2);
6124 +       return -ENODEV;
6125  }
6126  
6127  
6128 -EXPORT_NO_SYMBOLS;
6129 +static void __exit i2c_pcfisa_exit(void)
6130 +{
6131 +       i2c_pcf_del_bus(&pcf_isa_ops);
6132 +
6133 +       if (irq > 0) {
6134 +               disable_irq(irq);
6135 +               free_irq(irq, 0);
6136 +       }
6137 +
6138 +       if (!mmapped)
6139 +               release_region(base , 2);
6140 +}
6141  
6142 -#ifdef MODULE
6143  MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
6144  MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
6145  MODULE_LICENSE("GPL");
6146 @@ -309,15 +290,5 @@
6147  MODULE_PARM(mmapped, "i");
6148  MODULE_PARM(i2c_debug, "i");
6149  
6150 -int init_module(void) 
6151 -{
6152 -       return i2c_pcfisa_init();
6153 -}
6154 -
6155 -void cleanup_module(void) 
6156 -{
6157 -       i2c_pcf_del_bus(&pcf_isa_ops);
6158 -       pcf_isa_exit();
6159 -}
6160 -
6161 -#endif
6162 +module_init(i2c_pcfisa_init);
6163 +module_exit(i2c_pcfisa_exit);
6164 --- linux-old/include/linux/i2c-elektor.h       Thu Oct 11 15:05:47 2001
6165 +++ linux/include/linux/i2c-elektor.h   Sun Dec  7 11:17:40 2003
6166 @@ -1,47 +0,0 @@
6167 -/* ------------------------------------------------------------------------- */
6168 -/* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes             */
6169 -/* ------------------------------------------------------------------------- */
6170 -/*   Copyright (C) 1995-97 Simon G. Vogl
6171 -                   1998-99 Hans Berglund
6172 -
6173 -    This program is free software; you can redistribute it and/or modify
6174 -    it under the terms of the GNU General Public License as published by
6175 -    the Free Software Foundation; either version 2 of the License, or
6176 -    (at your option) any later version.
6177 -
6178 -    This program is distributed in the hope that it will be useful,
6179 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
6180 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6181 -    GNU General Public License for more details.
6182 -
6183 -    You should have received a copy of the GNU General Public License
6184 -    along with this program; if not, write to the Free Software
6185 -    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
6186 -/* ------------------------------------------------------------------------- */
6187 -
6188 -/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6189 -   Frodo Looijaard <frodol@dds.nl> */
6190 -
6191 -/* $Id$ */
6192 -
6193 -#ifndef I2C_PCF_ELEKTOR_H
6194 -#define I2C_PCF_ELEKTOR_H 1
6195 -
6196 -/*
6197 - * This struct contains the hw-dependent functions of PCF8584 adapters to
6198 - * manipulate the registers, and to init any hw-specific features.
6199 - * vdovikin: removed: this module in real supports only one device,
6200 - * due to missing arguments in some functions, called from the algo-pcf module.
6201 - * Sometimes it's need to be rewriten -
6202 - * but for now just remove this for simpler reading */
6203 -
6204 -/*
6205 -struct i2c_pcf_isa {
6206 -       int pi_base;
6207 -       int pi_irq;
6208 -       int pi_clock;
6209 -       int pi_own;
6210 -};
6211 -*/
6212 -
6213 -#endif /* PCF_ELEKTOR_H */
6214 --- linux-old/drivers/i2c/i2c-elv.c     Thu Oct 11 15:05:47 2001
6215 +++ linux/drivers/i2c/i2c-elv.c Sun Dec  7 11:17:40 2003
6216 @@ -21,22 +21,18 @@
6217  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
6218     Frodo Looijaard <frodol@dds.nl> */
6219  
6220 -/* $Id$ */
6221 +/* $Id$ */
6222  
6223  #include <linux/kernel.h>
6224  #include <linux/module.h>
6225  #include <linux/delay.h>
6226  #include <linux/slab.h>
6227 -#include <linux/version.h>
6228  #include <linux/init.h>
6229 -
6230 -#include <asm/uaccess.h>
6231 -
6232  #include <linux/ioport.h>
6233 -#include <asm/io.h>
6234  #include <linux/errno.h>
6235  #include <linux/i2c.h>
6236  #include <linux/i2c-algo-bit.h>
6237 +#include <asm/io.h>
6238  
6239  #define DEFAULT_BASE 0x378
6240  static int base=0;
6241 @@ -90,58 +86,31 @@
6242  
6243  static int bit_elv_init(void)
6244  {
6245 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
6246 -               return -ENODEV; 
6247 -       } else {
6248 -                                               /* test for ELV adap.   */
6249 -               if (inb(base+1) & 0x80) {       /* BUSY should be high  */
6250 -                       DEBINIT(printk("i2c-elv.o: Busy was low.\n"));
6251 -                       return -ENODEV;
6252 -               } else {
6253 -                       outb(0x0c,base+2);      /* SLCT auf low         */
6254 -                       udelay(400);
6255 -                       if ( !(inb(base+1) && 0x10) ) {
6256 -                               outb(0x04,base+2);
6257 -                               DEBINIT(printk("i2c-elv.o: Select was high.\n"));
6258 -                               return -ENODEV;
6259 -                       }
6260 -               }
6261 -               request_region(base,(base == 0x3bc)? 3 : 8,
6262 -                       "i2c (ELV adapter)");
6263 -               PortData = 0;
6264 -               bit_elv_setsda((void*)base,1);
6265 -               bit_elv_setscl((void*)base,1);
6266 +       if (!request_region(base, (base == 0x3bc) ? 3 : 8,
6267 +                               "i2c (ELV adapter)"))
6268 +               return -ENODEV;
6269 +
6270 +       if (inb(base+1) & 0x80) {       /* BUSY should be high  */
6271 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Busy was low.\n"));
6272 +               goto fail;
6273 +       } 
6274 +
6275 +       outb(0x0c,base+2);      /* SLCT auf low         */
6276 +       udelay(400);
6277 +       if (!(inb(base+1) && 0x10)) {
6278 +               outb(0x04,base+2);
6279 +               DEBINIT(printk(KERN_DEBUG "i2c-elv.o: Select was high.\n"));
6280 +               goto fail;
6281         }
6282 -       return 0;
6283 -}
6284 -
6285 -static void __exit bit_elv_exit(void)
6286 -{
6287 -       release_region( base , (base == 0x3bc)? 3 : 8 );
6288 -}
6289  
6290 -static int bit_elv_reg(struct i2c_client *client)
6291 -{
6292 +       PortData = 0;
6293 +       bit_elv_setsda((void*)base,1);
6294 +       bit_elv_setscl((void*)base,1);
6295         return 0;
6296 -}
6297  
6298 -static int bit_elv_unreg(struct i2c_client *client)
6299 -{
6300 -       return 0;
6301 -}
6302 -
6303 -static void bit_elv_inc_use(struct i2c_adapter *adap)
6304 -{
6305 -#ifdef MODULE
6306 -       MOD_INC_USE_COUNT;
6307 -#endif
6308 -}
6309 -
6310 -static void bit_elv_dec_use(struct i2c_adapter *adap)
6311 -{
6312 -#ifdef MODULE
6313 -       MOD_DEC_USE_COUNT;
6314 -#endif
6315 +fail:
6316 +       release_region(base , (base == 0x3bc) ? 3 : 8);
6317 +       return -ENODEV;
6318  }
6319  
6320  /* ------------------------------------------------------------------------
6321 @@ -149,28 +118,25 @@
6322   * This is only done when more than one hardware adapter is supported.
6323   */
6324  static struct i2c_algo_bit_data bit_elv_data = {
6325 -       NULL,
6326 -       bit_elv_setsda,
6327 -       bit_elv_setscl,
6328 -       bit_elv_getsda,
6329 -       bit_elv_getscl,
6330 -       80, 80, 100,            /*      waits, timeout */
6331 +       .setsda         = bit_elv_setsda,
6332 +       .setscl         = bit_elv_setscl,
6333 +       .getsda         = bit_elv_getsda,
6334 +       .getscl         = bit_elv_getscl,
6335 +       .udelay         = 80,
6336 +       .mdelay         = 80,
6337 +       .timeout        = HZ
6338  };
6339  
6340  static struct i2c_adapter bit_elv_ops = {
6341 -       "ELV Parallel port adaptor",
6342 -       I2C_HW_B_ELV,
6343 -       NULL,
6344 -       &bit_elv_data,
6345 -       bit_elv_inc_use,
6346 -       bit_elv_dec_use,
6347 -       bit_elv_reg,
6348 -       bit_elv_unreg,  
6349 +       .owner          = THIS_MODULE,
6350 +       .name           = "ELV Parallel port adaptor",
6351 +       .id             = I2C_HW_B_ELV,
6352 +       .algo_data      = &bit_elv_data,
6353  };
6354  
6355 -int __init i2c_bitelv_init(void)
6356 +static int __init i2c_bitelv_init(void)
6357  {
6358 -       printk("i2c-elv.o: i2c ELV parallel port adapter module\n");
6359 +       printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6360         if (base==0) {
6361                 /* probe some values */
6362                 base=DEFAULT_BASE;
6363 @@ -190,30 +156,23 @@
6364                         return -ENODEV;
6365                 }
6366         }
6367 -       printk("i2c-elv.o: found device at %#x.\n",base);
6368 +       printk(KERN_DEBUG "i2c-elv.o: found device at %#x.\n",base);
6369         return 0;
6370  }
6371  
6372 +static void __exit i2c_bitelv_exit(void)
6373 +{
6374 +       i2c_bit_del_bus(&bit_elv_ops);
6375 +       release_region(base , (base == 0x3bc) ? 3 : 8);
6376 +}
6377  
6378  EXPORT_NO_SYMBOLS;
6379  
6380 -#ifdef MODULE
6381  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
6382  MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
6383  MODULE_LICENSE("GPL");
6384  
6385 -
6386  MODULE_PARM(base, "i");
6387  
6388 -int init_module(void)
6389 -{
6390 -       return i2c_bitelv_init();
6391 -}
6392 -
6393 -void cleanup_module(void)
6394 -{
6395 -       i2c_bit_del_bus(&bit_elv_ops);
6396 -       bit_elv_exit();
6397 -}
6398 -
6399 -#endif
6400 +module_init(i2c_bitelv_init);
6401 +module_exit(i2c_bitelv_exit);
6402 --- linux-old/drivers/i2c/i2c-frodo.c   Thu Jan  1 00:00:00 1970
6403 +++ linux/drivers/i2c/i2c-frodo.c       Sun Dec  7 11:17:40 2003
6404 @@ -0,0 +1,83 @@
6405 +
6406 +/*
6407 + * linux/drivers/i2c/i2c-frodo.c
6408 + *
6409 + * Author: Abraham van der Merwe <abraham@2d3d.co.za>
6410 + *
6411 + * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
6412 + * Development board (Frodo).
6413 + *
6414 + * This source code is free software; you can redistribute it and/or
6415 + * modify it under the terms of the GNU General Public License
6416 + * version 2 as published by the Free Software Foundation.
6417 + */
6418 +
6419 +#include <linux/module.h>
6420 +#include <linux/kernel.h>
6421 +#include <linux/init.h>
6422 +#include <linux/delay.h>
6423 +#include <linux/i2c.h>
6424 +#include <linux/i2c-algo-bit.h>
6425 +#include <asm/hardware.h>
6426 +
6427 +
6428 +static void frodo_setsda (void *data,int state)
6429 +{
6430 +       if (state)
6431 +               FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
6432 +       else
6433 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
6434 +}
6435 +
6436 +static void frodo_setscl (void *data,int state)
6437 +{
6438 +       if (state)
6439 +               FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
6440 +       else
6441 +               FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
6442 +}
6443 +
6444 +static int frodo_getsda (void *data)
6445 +{
6446 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
6447 +}
6448 +
6449 +static int frodo_getscl (void *data)
6450 +{
6451 +       return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
6452 +}
6453 +
6454 +static struct i2c_algo_bit_data bit_frodo_data = {
6455 +       .setsda         = frodo_setsda,
6456 +       .setscl         = frodo_setscl,
6457 +       .getsda         = frodo_getsda,
6458 +       .getscl         = frodo_getscl,
6459 +       .udelay         = 80,
6460 +       .mdelay         = 80,
6461 +       .timeout        = HZ
6462 +};
6463 +
6464 +static struct i2c_adapter frodo_ops = {
6465 +       .owner                  = THIS_MODULE,
6466 +       .name                   = "Frodo adapter driver",
6467 +       .id                     = I2C_HW_B_FRODO,
6468 +       .algo_data              = &bit_frodo_data,
6469 +};
6470 +
6471 +static int __init i2c_frodo_init (void)
6472 +{
6473 +       return i2c_bit_add_bus(&frodo_ops);
6474 +}
6475 +
6476 +static void __exit i2c_frodo_exit (void)
6477 +{
6478 +       i2c_bit_del_bus(&frodo_ops);
6479 +}
6480 +
6481 +MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
6482 +MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
6483 +MODULE_LICENSE ("GPL");
6484 +
6485 +module_init (i2c_frodo_init);
6486 +module_exit (i2c_frodo_exit);
6487 +
6488 --- linux-old/include/linux/i2c-id.h    Tue Jul 15 10:23:54 2003
6489 +++ linux/include/linux/i2c-id.h        Sun Dec  7 11:17:40 2003
6490 @@ -20,10 +20,11 @@
6491      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
6492  /* ------------------------------------------------------------------------- */
6493  
6494 -/* $Id$ */
6495 +/* $Id$ */
6496 +
6497 +#ifndef LINUX_I2C_ID_H
6498 +#define LINUX_I2C_ID_H
6499  
6500 -#ifndef I2C_ID_H
6501 -#define I2C_ID_H
6502  /*
6503   * This file is part of the i2c-bus package and contains the identifier
6504   * values for drivers, adapters and other folk populating these serial
6505 @@ -90,7 +91,23 @@
6506  #define I2C_DRIVERID_DRP3510   43     /* ADR decoder (Astra Radio)     */
6507  #define I2C_DRIVERID_SP5055    44     /* Satellite tuner               */
6508  #define I2C_DRIVERID_STV0030   45     /* Multipurpose switch           */
6509 -#define I2C_DRIVERID_ADV717X   48     /* video encoder                 */
6510 +#define I2C_DRIVERID_SAA7108   46     /* video decoder, image scaler   */
6511 +#define I2C_DRIVERID_DS1307    47     /* DS1307 real time clock        */
6512 +#define I2C_DRIVERID_ADV7175   48     /* ADV 7175/7176 video encoder   */
6513 +#define I2C_DRIVERID_ZR36067   49     /* Zoran 36067 video encoder     */
6514 +#define I2C_DRIVERID_ZR36120   50     /* Zoran 36120 video encoder     */
6515 +#define I2C_DRIVERID_24LC32A   51      /* Microchip 24LC32A 32k EEPROM */
6516 +#define I2C_DRIVERID_STM41T00  52      /* real time clock              */
6517 +#define I2C_DRIVERID_UDA1342   53      /* UDA1342 audio codec          */
6518 +#define I2C_DRIVERID_ADV7170   54      /* video encoder                */
6519 +#define I2C_DRIVERID_RADEON    55      /* I2C bus on Radeon boards     */
6520 +#define I2C_DRIVERID_MAX1617   56      /* temp sensor                  */
6521 +#define I2C_DRIVERID_SAA7191   57      /* video encoder                */
6522 +#define I2C_DRIVERID_INDYCAM   58      /* SGI IndyCam                  */
6523 +#define I2C_DRIVERID_BT832     59      /* CMOS camera video processor  */
6524 +#define I2C_DRIVERID_TDA9887   60      /* TDA988x IF-PLL demodulator   */
6525 +
6526 +
6527  
6528  #define I2C_DRIVERID_EXP0      0xF0    /* experimental use id's        */
6529  #define I2C_DRIVERID_EXP1      0xF1
6530 @@ -99,6 +116,8 @@
6531  
6532  #define I2C_DRIVERID_I2CDEV    900
6533  #define I2C_DRIVERID_I2CPROC   901
6534 +#define I2C_DRIVERID_ARP        902    /* SMBus ARP Client              */
6535 +#define I2C_DRIVERID_ALERT      903    /* SMBus Alert Responder Client  */
6536  
6537  /* IDs --   Use DRIVERIDs 1000-1999 for sensors. 
6538     These were originally in sensors.h in the lm_sensors package */
6539 @@ -128,6 +147,25 @@
6540  #define I2C_DRIVERID_ADM1024 1025
6541  #define I2C_DRIVERID_IT87 1026
6542  #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
6543 +#define I2C_DRIVERID_FSCPOS 1028
6544 +#define I2C_DRIVERID_FSCSCY 1029
6545 +#define I2C_DRIVERID_PCF8591 1030
6546 +#define I2C_DRIVERID_SMSC47M1 1031
6547 +#define I2C_DRIVERID_VT1211 1032
6548 +#define I2C_DRIVERID_LM92 1033
6549 +#define I2C_DRIVERID_VT8231 1034
6550 +#define I2C_DRIVERID_SMARTBATT 1035
6551 +#define I2C_DRIVERID_BMCSENSORS 1036
6552 +#define I2C_DRIVERID_FS451 1037
6553 +#define I2C_DRIVERID_W83627HF 1038
6554 +#define I2C_DRIVERID_LM85 1039
6555 +#define I2C_DRIVERID_LM83 1040
6556 +#define I2C_DRIVERID_SAA1064 1041
6557 +#define I2C_DRIVERID_LM90 1042
6558 +#define I2C_DRIVERID_ASB100 1043
6559 +#define I2C_DRIVERID_MAX6650 1044
6560 +#define I2C_DRIVERID_XEONTEMP 1045
6561 +#define I2C_DRIVERID_FSCHER 1046
6562  
6563  /*
6564   * ---- Adapter types ----------------------------------------------------
6565 @@ -144,10 +182,21 @@
6566  #define I2C_ALGO_ISA   0x050000        /* lm_sensors ISA pseudo-adapter */
6567  #define I2C_ALGO_SAA7146 0x060000      /* SAA 7146 video decoder bus   */
6568  #define I2C_ALGO_ACB   0x070000        /* ACCESS.bus algorithm         */
6569 -
6570 +#define I2C_ALGO_IIC    0x080000       /* ITE IIC bus */
6571 +#define I2C_ALGO_SAA7134 0x090000
6572 +#define I2C_ALGO_MPC824X 0x0a0000      /* Motorola 8240 / 8245         */
6573 +#define I2C_ALGO_IPMI  0x0b0000        /* IPMI dummy adapter */
6574 +#define I2C_ALGO_IPMB  0x0c0000        /* IPMB adapter */
6575 +#define I2C_ALGO_MPC107 0x0d0000
6576  #define I2C_ALGO_EC     0x100000        /* ACPI embedded controller     */
6577  
6578  #define I2C_ALGO_MPC8XX 0x110000       /* MPC8xx PowerPC I2C algorithm */
6579 +#define I2C_ALGO_OCP    0x120000       /* IBM or otherwise On-chip I2C algorithm */
6580 +#define I2C_ALGO_BITHS 0x130000        /* enhanced bit style adapters  */
6581 +#define I2C_ALGO_OCP_IOP3XX  0x140000  /* XSCALE IOP3XX On-chip I2C alg */
6582 +#define I2C_ALGO_SIBYTE        0x150000        /* Broadcom SiByte SOCs         */
6583 +#define I2C_ALGO_SGI   0x160000        /* SGI algorithm                */
6584 +#define I2C_ALGO_USB   0x170000        /* USB algorithm                */
6585  
6586  #define I2C_ALGO_EXP   0x800000        /* experimental                 */
6587  
6588 @@ -175,21 +224,46 @@
6589  #define I2C_HW_B_I810  0x0a    /* Intel I810                           */
6590  #define I2C_HW_B_VOO   0x0b    /* 3dfx Voodoo 3 / Banshee              */
6591  #define I2C_HW_B_PPORT  0x0c   /* Primitive parallel port adapter      */
6592 +#define I2C_HW_B_SAVG  0x0d    /* Savage 4                             */
6593 +#define I2C_HW_B_SCX200        0x0e    /* Nat'l Semi SCx200 I2C                */
6594  #define I2C_HW_B_RIVA  0x10    /* Riva based graphics cards            */
6595  #define I2C_HW_B_IOC   0x11    /* IOC bit-wiggling                     */
6596  #define I2C_HW_B_TSUNA  0x12   /* DEC Tsunami chipset                  */
6597 +#define I2C_HW_B_FRODO  0x13    /* 2d3D, Inc. SA-1110 Development Board */
6598 +#define I2C_HW_B_OMAHA  0x14    /* Omaha I2C interface (ARM)           */
6599 +#define I2C_HW_B_GUIDE  0x15    /* Guide bit-basher                    */
6600 +#define I2C_HW_B_IXP2000 0x16  /* GPIO on IXP2000 systems              */
6601 +#define I2C_HW_B_IXP425 0x17   /* GPIO on IXP425 systems               */
6602 +#define I2C_HW_B_S3VIA 0x18    /* S3Via ProSavage adapter              */
6603 +#define I2C_HW_B_ZR36067 0x19  /* Zoran-36057/36067 based boards       */
6604 +#define I2C_HW_B_PCILYNX 0x20  /* TI PCILynx I2C adapter               */
6605  
6606  /* --- PCF 8584 based algorithms                                       */
6607  #define I2C_HW_P_LP    0x00    /* Parallel port interface              */
6608  #define I2C_HW_P_ISA   0x01    /* generic ISA Bus inteface card        */
6609  #define I2C_HW_P_ELEK  0x02    /* Elektor ISA Bus inteface card        */
6610  
6611 +/* --- USB based adapters                                              */
6612 +#define I2C_HW_USB_USBVISION   0x00
6613 +
6614  /* --- ACPI Embedded controller algorithms                              */
6615  #define I2C_HW_ACPI_EC          0x00
6616  
6617 +/* --- MPC824x PowerPC adapters                                                */
6618 +#define I2C_HW_MPC824X 0x00    /* Motorola 8240 / 8245                 */
6619 +
6620  /* --- MPC8xx PowerPC adapters                                         */
6621  #define I2C_HW_MPC8XX_EPON 0x00        /* Eponymous MPC8xx I2C adapter         */
6622  
6623 +/* --- ITE based algorithms                                            */
6624 +#define I2C_HW_I_IIC   0x00    /* controller on the ITE */
6625 +
6626 +/* --- PowerPC on-chip adapters                                                */
6627 +#define I2C_HW_OCP 0x00        /* IBM on-chip I2C adapter      */
6628 +
6629 +/* --- XSCALE on-chip adapters                          */
6630 +#define I2C_HW_IOP321 0x00
6631 +
6632  /* --- SMBus only adapters                                             */
6633  #define I2C_HW_SMBUS_PIIX4     0x00
6634  #define I2C_HW_SMBUS_ALI15X3   0x01
6635 @@ -199,8 +273,23 @@
6636  #define I2C_HW_SMBUS_SIS5595   0x06
6637  #define I2C_HW_SMBUS_ALI1535   0x07
6638  #define I2C_HW_SMBUS_W9968CF   0x08
6639 +#define I2C_HW_SMBUS_SIS630    0x09
6640 +#define I2C_HW_SMBUS_SIS645    0x0a
6641 +#define I2C_HW_SMBUS_AMD8111   0x0b
6642 +#define I2C_HW_SMBUS_SCX200    0x0c
6643 +#define I2C_HW_SMBUS_NFORCE2   0x0d
6644 +
6645  
6646  /* --- ISA pseudo-adapter                                              */
6647  #define I2C_HW_ISA 0x00
6648  
6649 -#endif /* I2C_ID_H */
6650 +/* --- IPMI pseudo-adapter                                             */
6651 +#define I2C_HW_IPMI 0x00
6652 +
6653 +/* --- IPMB adapter                                            */
6654 +#define I2C_HW_IPMB 0x00
6655 +
6656 +/* --- MCP107 adapter */
6657 +#define I2C_HW_MPC107 0x00
6658 +
6659 +#endif /* LINUX_I2C_ID_H */
6660 --- linux-old/drivers/i2c/i2c-pcf-epp.c Thu Jan  1 00:00:00 1970
6661 +++ linux/drivers/i2c/i2c-pcf-epp.c     Sun Dec  7 11:17:41 2003
6662 @@ -0,0 +1,281 @@
6663 +/* ------------------------------------------------------------------------- */
6664 +/* i2c-pcf-epp.c i2c-hw access for PCF8584 style EPP parallel port adapters  */
6665 +/* ------------------------------------------------------------------------- */
6666 +/*   Copyright (C) 1998-99 Hans Berglund
6667 +
6668 +    This program is free software; you can redistribute it and/or modify
6669 +    it under the terms of the GNU General Public License as published by
6670 +    the Free Software Foundation; either version 2 of the License, or
6671 +    (at your option) any later version.
6672 +
6673 +    This program is distributed in the hope that it will be useful,
6674 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
6675 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6676 +    GNU General Public License for more details.
6677 +
6678 +    You should have received a copy of the GNU General Public License
6679 +    along with this program; if not, write to the Free Software
6680 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
6681 +/* ------------------------------------------------------------------------- */
6682 +
6683 +/* With some changes from Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp> */
6684 +
6685 +#include <linux/kernel.h>
6686 +#include <linux/ioport.h>
6687 +#include <linux/module.h>
6688 +#include <linux/delay.h>
6689 +#include <linux/slab.h>
6690 +#include <linux/init.h>
6691 +#include <linux/parport.h>
6692 +#include <linux/i2c.h>
6693 +#include <linux/i2c-algo-pcf.h>
6694 +#include <asm/irq.h>
6695 +#include <asm/io.h>
6696 +
6697 +
6698 +struct  i2c_pcf_epp {
6699 +  int pe_base;
6700 +  int pe_irq;
6701 +  int pe_clock;
6702 +  int pe_own;
6703 +} ;
6704 +
6705 +#define DEFAULT_BASE 0x378
6706 +#define DEFAULT_IRQ      7
6707 +#define DEFAULT_CLOCK 0x1c
6708 +#define DEFAULT_OWN   0x55
6709 +
6710 +static int base  = 0;
6711 +static int irq   = 0;
6712 +static int clock = 0;
6713 +static int own   = 0;
6714 +static int i2c_debug=0;
6715 +static struct i2c_pcf_epp gpe;
6716 +static wait_queue_head_t pcf_wait;
6717 +static int pcf_pending;
6718 +static spinlock_t irq_driver_lock = SPIN_LOCK_UNLOCKED;
6719 +
6720 +/* ----- global defines -----------------------------------------------        */
6721 +#define DEB(x) if (i2c_debug>=1) x
6722 +#define DEB2(x) if (i2c_debug>=2) x
6723 +#define DEB3(x) if (i2c_debug>=3) x
6724 +#define DEBE(x)        x       /* error messages                               */
6725 +
6726 +/* --- Convenience defines for the EPP/SPP port:                       */
6727 +#define BASE   ((struct i2c_pcf_epp *)(data))->pe_base
6728 +// #define DATA        BASE                    /* SPP data port */
6729 +#define STAT   (BASE+1)                /* SPP status port */
6730 +#define CTRL   (BASE+2)                /* SPP control port */
6731 +#define EADD   (BASE+3)                /* EPP address port */
6732 +#define EDAT   (BASE+4)                /* EPP data port */
6733 +
6734 +/* ----- local functions ----------------------------------------------        */
6735 +
6736 +static void pcf_epp_setbyte(void *data, int ctl, int val)
6737 +{
6738 +  if (ctl) {
6739 +    if (gpe.pe_irq > 0) {
6740 +      DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n",
6741 +                 val|I2C_PCF_ENI));
6742 +      // set A0 pin HIGH
6743 +      outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6744 +      // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: CTRL port = 0x%x\n", inb(CTRL)));
6745 +      // DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: STAT port = 0x%x\n", inb(STAT)));
6746 +      
6747 +      // EPP write data cycle
6748 +      outb(val | I2C_PCF_ENI, EDAT);
6749 +    } else {
6750 +      DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write control 0x%x\n", val));
6751 +      // set A0 pin HIGH
6752 +      outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6753 +      outb(val, CTRL);
6754 +    }
6755 +  } else {
6756 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Write data 0x%x\n", val));
6757 +    // set A0 pin LO
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 +    outb(val, EDAT);
6762 +  }
6763 +}
6764 +
6765 +static int pcf_epp_getbyte(void *data, int ctl)
6766 +{
6767 +  int val;
6768 +
6769 +  if (ctl) {
6770 +    // set A0 pin HIGH
6771 +    outb(inb(CTRL) | PARPORT_CONTROL_INIT, CTRL);
6772 +    val = inb(EDAT);
6773 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read control 0x%x\n", val));
6774 +  } else {
6775 +    // set A0 pin LOW
6776 +    outb(inb(CTRL) & ~PARPORT_CONTROL_INIT, CTRL);
6777 +    val = inb(EDAT);
6778 +    DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: Read data 0x%x\n", val));
6779 +  }
6780 +  return (val);
6781 +}
6782 +
6783 +static int pcf_epp_getown(void *data)
6784 +{
6785 +  return (gpe.pe_own);
6786 +}
6787 +
6788 +
6789 +static int pcf_epp_getclock(void *data)
6790 +{
6791 +  return (gpe.pe_clock);
6792 +}
6793 +
6794 +#if 0
6795 +static void pcf_epp_sleep(unsigned long timeout)
6796 +{
6797 +  schedule_timeout( timeout * HZ);
6798 +}
6799 +#endif
6800 +
6801 +static void pcf_epp_waitforpin(void) {
6802 +  int timeout = 10;
6803 +
6804 +  if (gpe.pe_irq > 0) {
6805 +    spin_lock_irq(&irq_driver_lock);
6806 +    if (pcf_pending == 0) {
6807 +      interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ);
6808 +      //udelay(100);
6809 +    } else {
6810 +      pcf_pending = 0;
6811 +    }
6812 +    spin_unlock_irq(&irq_driver_lock);
6813 +  } else {
6814 +    udelay(100);
6815 +  }
6816 +}
6817 +
6818 +static void pcf_epp_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
6819 +  pcf_pending = 1;
6820 +  wake_up_interruptible(&pcf_wait);
6821 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: in interrupt handler.\n"));
6822 +}
6823 +
6824 +
6825 +static int pcf_epp_init(void *data)
6826 +{
6827 +  if (check_region(gpe.pe_base, 5) < 0 ) {
6828 +    
6829 +    printk(KERN_WARNING "Could not request port region with base 0x%x\n", gpe.pe_base);
6830 +    return -ENODEV;
6831 +  } else {
6832 +    request_region(gpe.pe_base, 5, "i2c (EPP parallel port adapter)");
6833 +  }
6834 +
6835 +  DEB3(printk(KERN_DEBUG "i2c-pcf-epp.o: init status port = 0x%x\n", inb(0x379)));
6836 +  
6837 +  if (gpe.pe_irq > 0) {
6838 +    if (request_irq(gpe.pe_irq, pcf_epp_handler, 0, "PCF8584", 0) < 0) {
6839 +      printk(KERN_NOTICE "i2c-pcf-epp.o: Request irq%d failed\n", gpe.pe_irq);
6840 +      gpe.pe_irq = 0;
6841 +    } else
6842 +      disable_irq(gpe.pe_irq);
6843 +      enable_irq(gpe.pe_irq);
6844 +  }
6845 +  // EPP mode initialize
6846 +  // enable interrupt from nINTR pin
6847 +  outb(inb(CTRL)|0x14, CTRL);
6848 +  // clear ERROR bit of STAT
6849 +  outb(inb(STAT)|0x01, STAT);
6850 +  outb(inb(STAT)&~0x01,STAT);
6851 +  
6852 +  return 0;
6853 +}
6854 +
6855 +/* ------------------------------------------------------------------------
6856 + * Encapsulate the above functions in the correct operations structure.
6857 + * This is only done when more than one hardware adapter is supported.
6858 + */
6859 +static struct i2c_algo_pcf_data pcf_epp_data = {
6860 +       .setpcf     = pcf_epp_setbyte,
6861 +       .getpcf     = pcf_epp_getbyte,
6862 +       .getown     = pcf_epp_getown,
6863 +       .getclock   = pcf_epp_getclock,
6864 +       .waitforpin = pcf_epp_waitforpin,
6865 +       .udelay     = 80,
6866 +       .mdelay     = 80,
6867 +       .timeout    = HZ,
6868 +};
6869 +
6870 +static struct i2c_adapter pcf_epp_ops = {
6871 +       .owner          = THIS_MODULE,
6872 +       .name           = "PCF8584 EPP adapter",
6873 +       .id             = I2C_HW_P_LP,
6874 +       .algo_data      = &pcf_epp_data,
6875 +};
6876 +
6877 +static int __init i2c_pcfepp_init(void) 
6878 +{
6879 +  struct i2c_pcf_epp *pepp = &gpe;
6880 +
6881 +  printk(KERN_DEBUG "i2c-pcf-epp.o: i2c pcf8584-epp adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
6882 +  if (base == 0)
6883 +    pepp->pe_base = DEFAULT_BASE;
6884 +  else
6885 +    pepp->pe_base = base;
6886 +
6887 +  if (irq == 0)
6888 +    pepp->pe_irq = DEFAULT_IRQ;
6889 +  else if (irq<0) {
6890 +    // switch off irq
6891 +    pepp->pe_irq=0;
6892 +  } else {
6893 +    pepp->pe_irq = irq;
6894 +  }
6895 +  if (clock == 0)
6896 +    pepp->pe_clock = DEFAULT_CLOCK;
6897 +  else
6898 +    pepp->pe_clock = clock;
6899 +
6900 +  if (own == 0)
6901 +    pepp->pe_own = DEFAULT_OWN;
6902 +  else
6903 +    pepp->pe_own = own;
6904 +
6905 +  pcf_epp_data.data = (void *)pepp;
6906 +  init_waitqueue_head(&pcf_wait);
6907 +  if (pcf_epp_init(pepp) == 0) {
6908 +    int ret;
6909 +    if ( (ret = i2c_pcf_add_bus(&pcf_epp_ops)) < 0) {
6910 +      printk(KERN_WARNING "i2c_pcf_add_bus caused an error: %d\n",ret);
6911 +      release_region(pepp->pe_base , 5);
6912 +      return ret;
6913 +    }
6914 +  } else {
6915 +    
6916 +    return -ENODEV;
6917 +  }
6918 +  printk(KERN_DEBUG "i2c-pcf-epp.o: found device at %#x.\n", pepp->pe_base);
6919 +  return 0;
6920 +}
6921 +
6922 +static void __exit pcf_epp_exit(void)
6923 +{
6924 +  i2c_pcf_del_bus(&pcf_epp_ops);
6925 +  if (gpe.pe_irq > 0) {
6926 +    disable_irq(gpe.pe_irq);
6927 +    free_irq(gpe.pe_irq, 0);
6928 +  }
6929 +  release_region(gpe.pe_base , 5);
6930 +}
6931 +
6932 +MODULE_AUTHOR("Hans Berglund <hb@spacetec.no> \n modified by Ryosuke Tajima <rosk@jsk.t.u-tokyo.ac.jp>");
6933 +MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 EPP parallel port adapter");
6934 +MODULE_LICENSE("GPL");
6935 +
6936 +MODULE_PARM(base, "i");
6937 +MODULE_PARM(irq, "i");
6938 +MODULE_PARM(clock, "i");
6939 +MODULE_PARM(own, "i");
6940 +MODULE_PARM(i2c_debug, "i");
6941 +
6942 +module_init(i2c_pcfepp_init);
6943 +module_exit(pcf_epp_exit);
6944 --- linux-old/include/linux/i2c-pcf8584.h       Thu Jan  1 00:00:00 1970
6945 +++ linux/include/linux/i2c-pcf8584.h   Sun Dec  7 11:17:41 2003
6946 @@ -0,0 +1,78 @@
6947 +/* -------------------------------------------------------------------- */
6948 +/* i2c-pcf8584.h: PCF 8584 global defines                              */
6949 +/* -------------------------------------------------------------------- */
6950 +/*   Copyright (C) 1996 Simon G. Vogl
6951 +                   1999 Hans Berglund
6952 +
6953 +    This program is free software; you can redistribute it and/or modify
6954 +    it under the terms of the GNU General Public License as published by
6955 +    the Free Software Foundation; either version 2 of the License, or
6956 +    (at your option) any later version.
6957 +
6958 +    This program is distributed in the hope that it will be useful,
6959 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
6960 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6961 +    GNU General Public License for more details.
6962 +
6963 +    You should have received a copy of the GNU General Public License
6964 +    along with this program; if not, write to the Free Software
6965 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.          */
6966 +/* --------------------------------------------------------------------        */
6967 +
6968 +/* With some changes from Frodo Looijaard <frodol@dds.nl> */
6969 +
6970 +/* $Id$ */
6971 +
6972 +#ifndef _LINUX_I2C_PCF8584_H
6973 +#define _LINUX_I2C_PCF8584_H
6974 +
6975 +/* ----- Control register bits ----------------------------------------        */
6976 +#define I2C_PCF_PIN    0x80
6977 +#define I2C_PCF_ESO    0x40
6978 +#define I2C_PCF_ES1    0x20
6979 +#define I2C_PCF_ES2    0x10
6980 +#define I2C_PCF_ENI    0x08
6981 +#define I2C_PCF_STA    0x04
6982 +#define I2C_PCF_STO    0x02
6983 +#define I2C_PCF_ACK    0x01
6984 +
6985 +#define I2C_PCF_START    (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6986 +#define I2C_PCF_STOP     (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
6987 +#define I2C_PCF_REPSTART (              I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
6988 +#define I2C_PCF_IDLE     (I2C_PCF_PIN | I2C_PCF_ESO               | I2C_PCF_ACK)
6989 +
6990 +/* ----- Status register bits -----------------------------------------        */
6991 +/*#define I2C_PCF_PIN  0x80    as above*/
6992 +
6993 +#define I2C_PCF_INI 0x40   /* 1 if not initialized */
6994 +#define I2C_PCF_STS 0x20
6995 +#define I2C_PCF_BER 0x10
6996 +#define I2C_PCF_AD0 0x08
6997 +#define I2C_PCF_LRB 0x08
6998 +#define I2C_PCF_AAS 0x04
6999 +#define I2C_PCF_LAB 0x02
7000 +#define I2C_PCF_BB  0x01
7001 +
7002 +/* ----- Chip clock frequencies ---------------------------------------        */
7003 +#define I2C_PCF_CLK3   0x00
7004 +#define I2C_PCF_CLK443 0x10
7005 +#define I2C_PCF_CLK6   0x14
7006 +#define I2C_PCF_CLK    0x18
7007 +#define I2C_PCF_CLK12  0x1c
7008 +
7009 +/* ----- transmission frequencies -------------------------------------        */
7010 +#define I2C_PCF_TRNS90 0x00    /*  90 kHz */
7011 +#define I2C_PCF_TRNS45 0x01    /*  45 kHz */
7012 +#define I2C_PCF_TRNS11 0x02    /*  11 kHz */
7013 +#define I2C_PCF_TRNS15 0x03    /* 1.5 kHz */
7014 +
7015 +
7016 +/* ----- Access to internal registers according to ES1,ES2 ------------        */
7017 +/* they are mapped to the data port ( a0 = 0 )                                 */
7018 +/* available when ESO == 0 :                                           */
7019 +
7020 +#define I2C_PCF_OWNADR 0
7021 +#define I2C_PCF_INTREG I2C_PCF_ES2
7022 +#define I2C_PCF_CLKREG I2C_PCF_ES1
7023 +
7024 +#endif /* _LINUX_I2C_PCF8584_H */
7025 --- linux-old/drivers/i2c/i2c-philips-par.c     Sun Sep 30 19:26:05 2001
7026 +++ linux/drivers/i2c/i2c-philips-par.c Sun Dec  7 11:17:41 2003
7027 @@ -21,7 +21,7 @@
7028  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
7029     Frodo Looijaard <frodol@dds.nl> */
7030  
7031 -/* $Id$ */
7032 +/* $Id$ */
7033  
7034  #include <linux/kernel.h>
7035  #include <linux/ioport.h>
7036 @@ -29,14 +29,10 @@
7037  #include <linux/init.h>
7038  #include <linux/stddef.h>
7039  #include <linux/parport.h>
7040 -
7041 +#include <linux/slab.h>
7042  #include <linux/i2c.h>
7043  #include <linux/i2c-algo-bit.h>
7044  
7045 -#ifndef __exit
7046 -#define __exit __init
7047 -#endif
7048 -
7049  static int type;
7050  
7051  struct i2c_par
7052 @@ -130,59 +126,34 @@
7053                                      PARPORT_STATUS_BUSY) ? 0 : 1;
7054  }
7055  
7056 -static int bit_lp_reg(struct i2c_client *client)
7057 -{
7058 -       return 0;
7059 -}
7060 -
7061 -static int bit_lp_unreg(struct i2c_client *client)
7062 -{
7063 -       return 0;
7064 -}
7065 -
7066 -static void bit_lp_inc_use(struct i2c_adapter *adap)
7067 -{
7068 -       MOD_INC_USE_COUNT;
7069 -}
7070 -
7071 -static void bit_lp_dec_use(struct i2c_adapter *adap)
7072 -{
7073 -       MOD_DEC_USE_COUNT;
7074 -}
7075 -
7076  /* ------------------------------------------------------------------------
7077   * Encapsulate the above functions in the correct operations structure.
7078   * This is only done when more than one hardware adapter is supported.
7079   */
7080   
7081  static struct i2c_algo_bit_data bit_lp_data = {
7082 -       NULL,
7083 -       bit_lp_setsda,
7084 -       bit_lp_setscl,
7085 -       bit_lp_getsda,
7086 -       bit_lp_getscl,
7087 -       80, 80, 100,            /*      waits, timeout */
7088 +       .setsda         = bit_lp_setsda,
7089 +       .setscl         = bit_lp_setscl,
7090 +       .getsda         = bit_lp_getsda,
7091 +       .getscl         = bit_lp_getscl,
7092 +       .udelay         = 80,
7093 +       .mdelay         = 80,
7094 +       .timeout        = HZ
7095  }; 
7096  
7097  static struct i2c_algo_bit_data bit_lp_data2 = {
7098 -       NULL,
7099 -       bit_lp_setsda2,
7100 -       bit_lp_setscl2,
7101 -       bit_lp_getsda2,
7102 -       NULL,
7103 -       80, 80, 100,            /*      waits, timeout */
7104 +       .setsda         = bit_lp_setsda2,
7105 +       .setscl         = bit_lp_setscl2,
7106 +       .getsda         = bit_lp_getsda2,
7107 +       .udelay         = 80,
7108 +       .mdelay         = 80,
7109 +       .timeout        = HZ
7110  }; 
7111  
7112  static struct i2c_adapter bit_lp_ops = {
7113 -       "Philips Parallel port adapter",
7114 -       I2C_HW_B_LP,
7115 -       NULL,
7116 -       NULL,
7117 -       bit_lp_inc_use,
7118 -       bit_lp_dec_use,
7119 -       bit_lp_reg,
7120 -
7121 -       bit_lp_unreg,
7122 +       .owner          = THIS_MODULE,
7123 +       .name           = "Philips Parallel port adapter",
7124 +       .id             = I2C_HW_B_LP,
7125  };
7126  
7127  static void i2c_parport_attach (struct parport *port)
7128 @@ -190,18 +161,19 @@
7129         struct i2c_par *adapter = kmalloc(sizeof(struct i2c_par),
7130                                           GFP_KERNEL);
7131         if (!adapter) {
7132 -               printk("i2c-philips-par: Unable to malloc.\n");
7133 +               printk(KERN_ERR "i2c-philips-par: Unable to malloc.\n");
7134                 return;
7135         }
7136  
7137 -       printk("i2c-philips-par.o: attaching to %s\n", port->name);
7138 +       printk(KERN_DEBUG "i2c-philips-par.o: attaching to %s\n", port->name);
7139  
7140         adapter->pdev = parport_register_device(port, "i2c-philips-par",
7141                                                 NULL, NULL, NULL, 
7142                                                 PARPORT_FLAG_EXCL,
7143                                                 NULL);
7144         if (!adapter->pdev) {
7145 -               printk("i2c-philips-par: Unable to register with parport.\n");
7146 +               printk(KERN_ERR "i2c-philips-par: Unable to register with parport.\n");
7147 +               kfree(adapter);
7148                 return;
7149         }
7150  
7151 @@ -210,15 +182,19 @@
7152         adapter->bit_lp_data = type ? bit_lp_data2 : bit_lp_data;
7153         adapter->bit_lp_data.data = port;
7154  
7155 +       if (parport_claim_or_block(adapter->pdev) < 0 ) {
7156 +               printk(KERN_ERR "i2c-philips-par: Could not claim parallel port.\n");
7157 +               kfree(adapter);
7158 +               return;
7159 +       }
7160         /* reset hardware to sane state */
7161 -       parport_claim_or_block(adapter->pdev);
7162         bit_lp_setsda(port, 1);
7163         bit_lp_setscl(port, 1);
7164         parport_release(adapter->pdev);
7165  
7166         if (i2c_bit_add_bus(&adapter->adapter) < 0)
7167         {
7168 -               printk("i2c-philips-par: Unable to register with I2C.\n");
7169 +               printk(KERN_ERR "i2c-philips-par: Unable to register with I2C.\n");
7170                 parport_unregister_device(adapter->pdev);
7171                 kfree(adapter);
7172                 return;         /* No good */
7173 @@ -250,41 +226,25 @@
7174  }
7175  
7176  
7177 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7178  static struct parport_driver i2c_driver = {
7179         "i2c-philips-par",
7180         i2c_parport_attach,
7181         i2c_parport_detach,
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  }
7203  
7204  void __exit i2c_bitlp_exit(void)
7205  {
7206 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4)
7207         parport_unregister_driver(&i2c_driver);
7208 -#else
7209 -       struct parport *port;
7210 -       for (port = parport_enumerate(); port; port=port->next)
7211 -               i2c_parport_detach(port);
7212 -#endif
7213  }
7214  
7215  EXPORT_NO_SYMBOLS;
7216 @@ -295,14 +255,5 @@
7217  
7218  MODULE_PARM(type, "i");
7219  
7220 -#ifdef MODULE
7221 -int init_module(void)
7222 -{
7223 -       return i2c_bitlp_init();
7224 -}
7225 -
7226 -void cleanup_module(void)
7227 -{
7228 -       i2c_bitlp_exit();
7229 -}
7230 -#endif
7231 +module_init(i2c_bitlp_init);
7232 +module_exit(i2c_bitlp_exit);
7233 --- linux-old/drivers/i2c/i2c-pport.c   Thu Jan  1 00:00:00 1970
7234 +++ linux/drivers/i2c/i2c-pport.c       Sun Dec  7 11:17:41 2003
7235 @@ -0,0 +1,205 @@
7236 +/* ------------------------------------------------------------------------- */
7237 +/* i2c-pport.c i2c-hw access  for primitive i2c par. port adapter           */
7238 +/* ------------------------------------------------------------------------- */
7239 +/*   Copyright (C) 2001    Daniel Smolik
7240 +
7241 +    This program is free software; you can redistribute it and/or modify
7242 +    it under the terms of the GNU General Public License as published by
7243 +    the Free Software Foundation; either version 2 of the License, or
7244 +    (at your option) any later version.
7245 +
7246 +    This program is distributed in the hope that it will be useful,
7247 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
7248 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7249 +    GNU General Public License for more details.
7250 +
7251 +    You should have received a copy of the GNU General Public License
7252 +    along with this program; if not, write to the Free Software
7253 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
7254 +/* ------------------------------------------------------------------------- */
7255 +
7256 +/*
7257 +       See doc/i2c-pport for instructions on wiring to the
7258 +       parallel port connector.
7259 +
7260 +       Cut & paste :-)  based on Velleman K9000 driver by Simon G. Vogl
7261 +*/
7262 +
7263 +
7264 +#include <linux/kernel.h>
7265 +#include <linux/module.h>
7266 +#include <linux/delay.h>
7267 +#include <linux/slab.h>
7268 +#include <linux/init.h>
7269 +#include <linux/ioport.h>
7270 +#include <linux/errno.h>
7271 +#include <linux/i2c.h>
7272 +#include <linux/i2c-algo-bit.h>
7273 +#include <asm/io.h>
7274 +
7275 +
7276 +#define DEFAULT_BASE 0x378
7277 +static int base=0;
7278 +static unsigned char PortData = 0;
7279 +
7280 +/* ----- global defines -----------------------------------------------        */
7281 +#define DEB(x)         /* should be reasonable open, close &c.         */
7282 +#define DEB2(x)        /* low level debugging - very slow              */
7283 +#define DEBE(x)        x       /* error messages                               */
7284 +#define DEBINIT(x) x   /* detection status messages                    */
7285 +
7286 +/* --- Convenience defines for the parallel port:                      */
7287 +#define BASE   (unsigned int)(data)
7288 +#define DATA   BASE                    /* Centronics data port         */
7289 +#define STAT   (BASE+1)                /* Centronics status port       */
7290 +#define CTRL   (BASE+2)                /* Centronics control port      */
7291 +
7292 +/* we will use SDA  - Auto Linefeed(14)   bit 1  POUT   */
7293 +/* we will use SCL - Initialize printer(16)    BUSY bit 2*/
7294 +
7295 +#define  SET_SCL    | 0x04
7296 +#define  CLR_SCL    & 0xFB
7297 +
7298 +
7299 +
7300 +
7301 +#define  SET_SDA    & 0x04
7302 +#define  CLR_SDA    | 0x02
7303 +
7304 +
7305 +/* ----- local functions ----------------------------------------------        */
7306 +
7307 +
7308 +static void bit_pport_setscl(void *data, int state)
7309 +{
7310 +       if (state) {
7311 +               //high
7312 +               PortData = PortData SET_SCL;
7313 +       } else {
7314 +               //low
7315 +               PortData = PortData CLR_SCL; 
7316 +       }
7317 +       outb(PortData, CTRL);
7318 +}
7319 +
7320 +static void bit_pport_setsda(void *data, int state)
7321 +{
7322 +       if (state) {
7323 +               
7324 +               PortData = PortData SET_SDA;
7325 +       } else {
7326 +
7327 +               PortData = PortData CLR_SDA;
7328 +       }
7329 +       outb(PortData, CTRL);
7330 +} 
7331 +
7332 +static int bit_pport_getscl(void *data)
7333 +{
7334 +
7335 +       return ( 4 == ( (inb_p(CTRL)) & 0x04 ) );
7336 +}
7337 +
7338 +static int bit_pport_getsda(void *data)
7339 +{
7340 +       return ( 0 == ( (inb_p(CTRL)) & 0x02 ) );
7341 +}
7342 +
7343 +static int bit_pport_init(void)
7344 +{
7345 +       if (!request_region((base+2),1, "i2c (PPORT adapter)")) {
7346 +               return -ENODEV; 
7347 +       } else {
7348 +               /* test for PPORT adap.         */
7349 +       
7350 +
7351 +               PortData=inb(base+2);
7352 +               PortData= (PortData SET_SDA) SET_SCL;
7353 +               outb(PortData,base+2);                          
7354 +
7355 +               if (!(inb(base+2) | 0x06)) {    /* SDA and SCL will be high     */
7356 +                       DEBINIT(printk("i2c-pport.o: SDA and SCL was low.\n"));
7357 +                       return -ENODEV;
7358 +               } else {
7359 +               
7360 +                       /*SCL high and SDA low*/
7361 +                       PortData = PortData SET_SCL CLR_SDA;
7362 +                       outb(PortData,base+2);  
7363 +                       schedule_timeout(400);
7364 +                       if ( !(inb(base+2) | 0x4) ) {
7365 +                               //outb(0x04,base+2);
7366 +                               DEBINIT(printk("i2c-port.o: SDA was high.\n"));
7367 +                               return -ENODEV;
7368 +                       }
7369 +               }
7370 +               bit_pport_setsda((void*)base,1);
7371 +               bit_pport_setscl((void*)base,1);
7372 +       }
7373 +       return 0;
7374 +}
7375 +
7376 +
7377 +/* ------------------------------------------------------------------------
7378 + * Encapsulate the above functions in the correct operations structure.
7379 + * This is only done when more than one hardware adapter is supported.
7380 + */
7381 +static struct i2c_algo_bit_data bit_pport_data = {
7382 +       .setsda         = bit_pport_setsda,
7383 +       .setscl         = bit_pport_setscl,
7384 +       .getsda         = bit_pport_getsda,
7385 +       .getscl         = bit_pport_getscl,
7386 +       .udelay         = 40,
7387 +       .mdelay         = 80,
7388 +       .timeout        = HZ
7389 +};
7390 +
7391 +static struct i2c_adapter bit_pport_ops = {
7392 +       .owner          = THIS_MODULE,
7393 +       .name           = "Primitive Parallel port adaptor",
7394 +       .id             = I2C_HW_B_PPORT,
7395 +       .algo_data      = &bit_pport_data,
7396 +};
7397 +
7398 +int __init i2c_bitpport_init(void)
7399 +{
7400 +       printk("i2c-pport.o: i2c Primitive parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
7401 +
7402 +       if (base==0) {
7403 +               /* probe some values */
7404 +               base=DEFAULT_BASE;
7405 +               bit_pport_data.data=(void*)DEFAULT_BASE;
7406 +               if (bit_pport_init()==0) {
7407 +                       if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7408 +                               return -ENODEV;
7409 +               } else {
7410 +                       return -ENODEV;
7411 +               }
7412 +       } else {
7413 +               bit_pport_data.data=(void*)base;
7414 +               if (bit_pport_init()==0) {
7415 +                       if(i2c_bit_add_bus(&bit_pport_ops) < 0)
7416 +                               return -ENODEV;
7417 +               } else {
7418 +                       return -ENODEV;
7419 +               }
7420 +       }
7421 +       printk("i2c-pport.o: found device at %#x.\n",base);
7422 +       return 0;
7423 +}
7424 +
7425 +static void __exit i2c_bitpport_exit(void)
7426 +{
7427 +       i2c_bit_del_bus(&bit_pport_ops);
7428 +       release_region((base+2),1);
7429 +}
7430 +
7431 +EXPORT_NO_SYMBOLS;
7432 +
7433 +MODULE_AUTHOR("Daniel Smolik <marvin@sitour.cz>");
7434 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Primitive parallel port adapter");
7435 +MODULE_LICENSE("GPL");
7436 +
7437 +MODULE_PARM(base, "i");
7438 +
7439 +module_init(i2c_bitpport_init);
7440 +module_exit(i2c_bitpport_exit);
7441 --- linux-old/drivers/i2c/i2c-proc.c    Tue Jul 15 10:23:49 2003
7442 +++ linux/drivers/i2c/i2c-proc.c        Sun Dec  7 11:17:42 2003
7443 @@ -23,34 +23,21 @@
7444      This driver puts entries in /proc/sys/dev/sensors for each I2C device
7445  */
7446  
7447 -#include <linux/version.h>
7448  #include <linux/module.h>
7449  #include <linux/kernel.h>
7450  #include <linux/slab.h>
7451  #include <linux/ctype.h>
7452  #include <linux/sysctl.h>
7453  #include <linux/proc_fs.h>
7454 +#include <linux/init.h>
7455  #include <linux/ioport.h>
7456 -#include <asm/uaccess.h>
7457 -
7458  #include <linux/i2c.h>
7459  #include <linux/i2c-proc.h>
7460 +#include <asm/uaccess.h>
7461  
7462 -#include <linux/init.h>
7463 -
7464 -/* FIXME need i2c versioning */
7465 -#define LM_DATE "20010825"
7466 -#define LM_VERSION "2.6.1"
7467 -
7468 -#ifndef THIS_MODULE
7469 -#define THIS_MODULE NULL
7470 -#endif
7471 -
7472 -static int i2c_create_name(char **name, const char *prefix,
7473 -                              struct i2c_adapter *adapter, int addr);
7474  static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7475                                long *results, int magnitude);
7476 -static int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7477 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7478                                long *results, int magnitude);
7479  static int i2c_proc_chips(ctl_table * ctl, int write,
7480                               struct file *filp, void *buffer,
7481 @@ -60,26 +47,10 @@
7482                                 void *newval, size_t newlen,
7483                                 void **context);
7484  
7485 -int __init sensors_init(void);
7486 -
7487  #define SENSORS_ENTRY_MAX 20
7488  static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX];
7489  
7490  static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX];
7491 -static unsigned short i2c_inodes[SENSORS_ENTRY_MAX];
7492 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)
7493 -static void i2c_fill_inode(struct inode *inode, int fill);
7494 -static void i2c_dir_fill_inode(struct inode *inode, int fill);
7495 -#endif                 /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */
7496 -
7497 -static ctl_table sysctl_table[] = {
7498 -       {CTL_DEV, "dev", NULL, 0, 0555},
7499 -       {0},
7500 -       {DEV_SENSORS, "sensors", NULL, 0, 0555},
7501 -       {0},
7502 -       {0, NULL, NULL, 0, 0555},
7503 -       {0}
7504 -};
7505  
7506  static ctl_table i2c_proc_dev_sensors[] = {
7507         {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips,
7508 @@ -100,31 +71,45 @@
7509  
7510  
7511  static struct ctl_table_header *i2c_proc_header;
7512 -static int i2c_initialized;
7513  
7514  /* This returns a nice name for a new directory; for example lm78-isa-0310
7515     (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for
7516     a LM75 chip on the third i2c bus at address 0x4e).  
7517     name is allocated first. */
7518 -int i2c_create_name(char **name, const char *prefix,
7519 -                       struct i2c_adapter *adapter, int addr)
7520 +static char *generate_name(struct i2c_client *client, const char *prefix)
7521  {
7522 -       char name_buffer[50];
7523 -       int id;
7524 -       if (i2c_is_isa_adapter(adapter))
7525 +       struct i2c_adapter *adapter = client->adapter;
7526 +       int addr = client->addr;
7527 +       char name_buffer[50], *name;
7528 +
7529 +       if (i2c_is_isa_adapter(adapter)) {
7530                 sprintf(name_buffer, "%s-isa-%04x", prefix, addr);
7531 -       else {
7532 -               if ((id = i2c_adapter_id(adapter)) < 0)
7533 -                       return -ENOENT;
7534 +       } else if (adapter->algo->smbus_xfer || adapter->algo->master_xfer) {
7535 +               int id = i2c_adapter_id(adapter);
7536 +               if (id < 0)
7537 +                       return ERR_PTR(-ENOENT);
7538                 sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr);
7539 +       } else {        /* dummy adapter, generate prefix */
7540 +               int end, i;
7541 +
7542 +               sprintf(name_buffer, "%s-", prefix);
7543 +               end = strlen(name_buffer);
7544 +
7545 +               for (i = 0; i < 32; i++) {
7546 +                       if (adapter->algo->name[i] == ' ')
7547 +                               break;
7548 +                       name_buffer[end++] = tolower(adapter->algo->name[i]);
7549 +               }
7550 +
7551 +               name_buffer[end] = 0;
7552 +               sprintf(name_buffer + end, "-%04x", addr);
7553         }
7554 -       *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7555 -       if (!*name) {
7556 -               printk (KERN_WARNING "i2c_create_name: not enough memory\n");
7557 -               return -ENOMEM;
7558 -       }
7559 -       strcpy(*name, name_buffer);
7560 -       return 0;
7561 +
7562 +       name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL);
7563 +       if (!name)
7564 +               return ERR_PTR(-ENOMEM);
7565 +       strcpy(name, name_buffer);
7566 +       return name;
7567  }
7568  
7569  /* This rather complex function must be called when you want to add an entry
7570 @@ -133,144 +118,91 @@
7571     ctl_template should be a template of the newly created directory. It is
7572     copied in memory. The extra2 field of each file is set to point to client.
7573     If any driver wants subdirectories within the newly created directory,
7574 -   this function must be updated! 
7575 -   controlling_mod is the controlling module. It should usually be
7576 -   THIS_MODULE when calling. Note that this symbol is not defined in
7577 -   kernels before 2.3.13; define it to NULL in that case. We will not use it
7578 -   for anything older than 2.3.27 anyway. */
7579 +   this function must be updated!  */
7580  int i2c_register_entry(struct i2c_client *client, const char *prefix,
7581 -                          ctl_table * ctl_template,
7582 -                          struct module *controlling_mod)
7583 +                      struct ctl_table *ctl_template)
7584  {
7585 -       int i, res, len, id;
7586 -       ctl_table *new_table;
7587 -       char *name;
7588 -       struct ctl_table_header *new_header;
7589 +       struct { struct ctl_table root[2], dev[2], sensors[2]; } *tbl;
7590 +       struct ctl_table_header *hdr;
7591 +       struct ctl_table *tmp, *leaf;
7592 +       const char *name;
7593 +       int id, len = 0;
7594  
7595 -       if ((res = i2c_create_name(&name, prefix, client->adapter,
7596 -                                      client->addr))) return res;
7597 +       name = generate_name(client, prefix);
7598 +       if (IS_ERR(name))
7599 +               return PTR_ERR(name);
7600  
7601 -       for (id = 0; id < SENSORS_ENTRY_MAX; id++)
7602 -               if (!i2c_entries[id]) {
7603 -                       break;
7604 -               }
7605 -       if (id == SENSORS_ENTRY_MAX) {
7606 -               kfree(name);
7607 -               return -ENOMEM;
7608 +       for (id = 0; id < SENSORS_ENTRY_MAX; id++) {
7609 +               if (!i2c_entries[id])
7610 +                       goto free_slot;
7611         }
7612 -       id += 256;
7613  
7614 -       len = 0;
7615 +       goto out_free_name;
7616 +
7617 + free_slot:
7618         while (ctl_template[len].procname)
7619                 len++;
7620 -       len += 7;
7621 -       if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) {
7622 -               kfree(name);
7623 -               return -ENOMEM;
7624 -       }
7625 -
7626 -       memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table));
7627 -       new_table[0].child = &new_table[2];
7628 -       new_table[2].child = &new_table[4];
7629 -       new_table[4].child = &new_table[6];
7630 -       new_table[4].procname = name;
7631 -       new_table[4].ctl_name = id;
7632 -       memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table));
7633 -       for (i = 6; i < len; i++)
7634 -               new_table[i].extra2 = client;
7635 -
7636 -       if (!(new_header = register_sysctl_table(new_table, 0))) {
7637 -               kfree(new_table);
7638 -               kfree(name);
7639 -               return -ENOMEM;
7640 -       }
7641 -
7642 -       i2c_entries[id - 256] = new_header;
7643 -
7644 -       i2c_clients[id - 256] = client;
7645 -#ifdef DEBUG
7646 -       if (!new_header || !new_header->ctl_table ||
7647 -           !new_header->ctl_table->child ||
7648 -           !new_header->ctl_table->child->child ||
7649 -           !new_header->ctl_table->child->child->de) {
7650 -               printk
7651 -                   ("i2c-proc.o: NULL pointer when trying to install fill_inode fix!\n");
7652 -               return id;
7653 -       }
7654 -#endif                         /* DEBUG */
7655 -       i2c_inodes[id - 256] =
7656 -           new_header->ctl_table->child->child->de->low_ino;
7657 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27))
7658 -       new_header->ctl_table->child->child->de->owner = controlling_mod;
7659 -#else
7660 -       new_header->ctl_table->child->child->de->fill_inode =
7661 -           &i2c_dir_fill_inode;
7662 -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */
7663 -
7664 -       return id;
7665 +       tbl = kmalloc(sizeof(*tbl) + sizeof(ctl_table) * (len + 1), 
7666 +                                 GFP_KERNEL);
7667 +       if (!tbl)
7668 +               goto out_free_name;
7669 +       memset(tbl, 0, sizeof(*tbl));
7670 +
7671 +       /* The client sysctls */
7672 +       leaf = (struct ctl_table *) (tbl + 1);
7673 +       memcpy(leaf, ctl_template, sizeof(ctl_table) * (len+1));
7674 +       for (tmp = leaf; tmp->ctl_name; tmp++)
7675 +               tmp->extra2 = client;
7676 +
7677 +       tbl->sensors->ctl_name = id+256;
7678 +       tbl->sensors->procname = name;
7679 +       tbl->sensors->mode = 0555;
7680 +       tbl->sensors->child = leaf;
7681 +
7682 +       tbl->dev->ctl_name = DEV_SENSORS;
7683 +       tbl->dev->procname = "sensors";
7684 +       tbl->dev->mode = 0555;
7685 +       tbl->dev->child = tbl->sensors;
7686 +
7687 +       tbl->root->ctl_name = CTL_DEV;
7688 +       tbl->root->procname = "dev";
7689 +       tbl->root->mode = 0555;
7690 +       tbl->root->child = tbl->dev;
7691 +
7692 +       hdr = register_sysctl_table(tbl->root, 0);
7693 +       if (!hdr)
7694 +               goto out_free_tbl;
7695 +
7696 +       i2c_entries[id] = hdr;
7697 +       i2c_clients[id] = client;
7698 +
7699 +       return (id + 256);      /* XXX(hch) why?? */
7700 +
7701 + out_free_tbl:
7702 +       kfree(tbl);
7703 + out_free_name:
7704 +       kfree(name);
7705 +       return -ENOMEM;
7706  }
7707  
7708  void i2c_deregister_entry(int id)
7709  {
7710 -       ctl_table *table;
7711 -       char *temp;
7712         id -= 256;
7713 -       if (i2c_entries[id]) {
7714 -               table = i2c_entries[id]->ctl_table;
7715 -               unregister_sysctl_table(i2c_entries[id]);
7716 -               /* 2-step kfree needed to keep gcc happy about const points */
7717 -               (const char *) temp = table[4].procname;
7718 -               kfree(temp);
7719 -               kfree(table);
7720 -               i2c_entries[id] = NULL;
7721 -               i2c_clients[id] = NULL;
7722 -       }
7723 -}
7724  
7725 -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o 
7726 -   impossible if some process still uses it or some file in it */
7727 -void i2c_fill_inode(struct inode *inode, int fill)
7728 -{
7729 -       if (fill)
7730 -               MOD_INC_USE_COUNT;
7731 -       else
7732 -               MOD_DEC_USE_COUNT;
7733 -}
7734 -
7735 -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading
7736 -   the corresponding module impossible if some process still uses it or
7737 -   some file in it */
7738 -void i2c_dir_fill_inode(struct inode *inode, int fill)
7739 -{
7740 -       int i;
7741 -       struct i2c_client *client;
7742 +       if (i2c_entries[id]) {
7743 +               struct ctl_table_header *hdr = i2c_entries[id];
7744 +               struct ctl_table *tbl = hdr->ctl_table;
7745  
7746 -#ifdef DEBUG
7747 -       if (!inode) {
7748 -               printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n");
7749 -               return;
7750 +               unregister_sysctl_table(hdr);
7751 +               kfree(tbl->child->child->procname);
7752 +               kfree(tbl); /* actually the whole anonymous struct */
7753         }
7754 -#endif                         /* def DEBUG */
7755  
7756 -       for (i = 0; i < SENSORS_ENTRY_MAX; i++)
7757 -               if (i2c_clients[i]
7758 -                   && (i2c_inodes[i] == inode->i_ino)) break;
7759 -#ifdef DEBUG
7760 -       if (i == SENSORS_ENTRY_MAX) {
7761 -               printk
7762 -                   ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n",
7763 -                    inode->i_ino);
7764 -               return;
7765 -       }
7766 -#endif                         /* def DEBUG */
7767 -       client = i2c_clients[i];
7768 -       if (fill)
7769 -               client->driver->inc_use(client);
7770 -       else
7771 -               client->driver->dec_use(client);
7772 +       i2c_entries[id] = NULL;
7773 +       i2c_clients[id] = NULL;
7774  }
7775  
7776 -int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7777 +static int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp,
7778                        void *buffer, size_t * lenp)
7779  {
7780         char BUF[SENSORS_PREFIX_MAX + 30];
7781 @@ -308,7 +240,7 @@
7782         return 0;
7783  }
7784  
7785 -int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7786 +static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
7787                          void *oldval, size_t * oldlenp, void *newval,
7788                          size_t newlen, void **context)
7789  {
7790 @@ -470,7 +402,7 @@
7791     WARNING! This is tricky code. I have tested it, but there may still be
7792              hidden bugs in it, even leading to crashes and things!
7793  */
7794 -int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7795 +static int i2c_parse_reals(int *nrels, void *buffer, int bufsize,
7796                          long *results, int magnitude)
7797  {
7798         int maxels, min, mag;
7799 @@ -571,7 +503,7 @@
7800         return 0;
7801  }
7802  
7803 -int i2c_write_reals(int nrels, void *buffer, int *bufsize,
7804 +static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
7805                          long *results, int magnitude)
7806  {
7807  #define BUFLEN 20
7808 @@ -660,6 +592,7 @@
7809                                         I2C_FUNC_SMBUS_QUICK)) return -1;
7810  
7811         for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
7812 +               /* XXX: WTF is going on here??? */
7813                 if ((is_isa && check_region(addr, 1)) ||
7814                     (!is_isa && i2c_check_addr(adapter, addr)))
7815                         continue;
7816 @@ -684,7 +617,7 @@
7817                                     && (addr == this_force->force[j + 1])) {
7818  #ifdef DEBUG
7819                                         printk
7820 -                                           ("i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7821 +                                           (KERN_DEBUG "i2c-proc.o: found force parameter for adapter %d, addr %04x\n",
7822                                              adapter_id, addr);
7823  #endif
7824                                         if (
7825 @@ -714,7 +647,7 @@
7826                             && (addr == address_data->ignore[i + 1])) {
7827  #ifdef DEBUG
7828                                 printk
7829 -                                   ("i2c-proc.o: found ignore parameter for adapter %d, "
7830 +                                   (KERN_DEBUG "i2c-proc.o: found ignore parameter for adapter %d, "
7831                                      "addr %04x\n", adapter_id, addr);
7832  #endif
7833                                 found = 1;
7834 @@ -734,7 +667,7 @@
7835                             && (addr <= address_data->ignore_range[i + 2])) {
7836  #ifdef DEBUG
7837                                 printk
7838 -                                   ("i2c-proc.o: found ignore_range parameter for adapter %d, "
7839 +                                   (KERN_DEBUG "i2c-proc.o: found ignore_range parameter for adapter %d, "
7840                                      "addr %04x\n", adapter_id, addr);
7841  #endif
7842                                 found = 1;
7843 @@ -753,7 +686,7 @@
7844                                 if (addr == address_data->normal_isa[i]) {
7845  #ifdef DEBUG
7846                                         printk
7847 -                                           ("i2c-proc.o: found normal isa entry for adapter %d, "
7848 +                                           (KERN_DEBUG "i2c-proc.o: found normal isa entry for adapter %d, "
7849                                              "addr %04x\n", adapter_id,
7850                                              addr);
7851  #endif
7852 @@ -775,7 +708,7 @@
7853                                      0)) {
7854  #ifdef DEBUG
7855                                         printk
7856 -                                           ("i2c-proc.o: found normal isa_range entry for adapter %d, "
7857 +                                           (KERN_DEBUG "i2c-proc.o: found normal isa_range entry for adapter %d, "
7858                                              "addr %04x", adapter_id, addr);
7859  #endif
7860                                         found = 1;
7861 @@ -789,7 +722,7 @@
7862                                         found = 1;
7863  #ifdef DEBUG
7864                                         printk
7865 -                                           ("i2c-proc.o: found normal i2c entry for adapter %d, "
7866 +                                           (KERN_DEBUG "i2c-proc.o: found normal i2c entry for adapter %d, "
7867                                              "addr %02x", adapter_id, addr);
7868  #endif
7869                                 }
7870 @@ -805,7 +738,7 @@
7871                                 {
7872  #ifdef DEBUG
7873                                         printk
7874 -                                           ("i2c-proc.o: found normal i2c_range entry for adapter %d, "
7875 +                                           (KERN_DEBUG "i2c-proc.o: found normal i2c_range entry for adapter %d, "
7876                                              "addr %04x\n", adapter_id, addr);
7877  #endif
7878                                         found = 1;
7879 @@ -822,7 +755,7 @@
7880                             && (addr == address_data->probe[i + 1])) {
7881  #ifdef DEBUG
7882                                 printk
7883 -                                   ("i2c-proc.o: found probe parameter for adapter %d, "
7884 +                                   (KERN_DEBUG "i2c-proc.o: found probe parameter for adapter %d, "
7885                                      "addr %04x\n", adapter_id, addr);
7886  #endif
7887                                 found = 1;
7888 @@ -841,7 +774,7 @@
7889                                 found = 1;
7890  #ifdef DEBUG
7891                                 printk
7892 -                                   ("i2c-proc.o: found probe_range parameter for adapter %d, "
7893 +                                   (KERN_DEBUG "i2c-proc.o: found probe_range parameter for adapter %d, "
7894                                      "addr %04x\n", adapter_id, addr);
7895  #endif
7896                         }
7897 @@ -860,51 +793,33 @@
7898         return 0;
7899  }
7900  
7901 -int __init sensors_init(void)
7902 +static int __init i2c_proc_init(void)
7903  {
7904 -       printk("i2c-proc.o version %s (%s)\n", LM_VERSION, LM_DATE);
7905 -       i2c_initialized = 0;
7906 +       printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
7907         if (!
7908             (i2c_proc_header =
7909 -            register_sysctl_table(i2c_proc, 0))) return -ENOMEM;
7910 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1))
7911 +            register_sysctl_table(i2c_proc, 0))) {
7912 +               printk(KERN_ERR "i2c-proc.o: error: sysctl interface not supported by kernel!\n");
7913 +               return -EPERM;
7914 +       }
7915         i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE;
7916 -#else
7917 -       i2c_proc_header->ctl_table->child->de->fill_inode =
7918 -           &i2c_fill_inode;
7919 -#endif                 /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */
7920 -       i2c_initialized++;
7921         return 0;
7922  }
7923  
7924 +static void __exit i2c_proc_exit(void)
7925 +{
7926 +       unregister_sysctl_table(i2c_proc_header);
7927 +}
7928 +
7929 +EXPORT_SYMBOL(i2c_register_entry);
7930  EXPORT_SYMBOL(i2c_deregister_entry);
7931 -EXPORT_SYMBOL(i2c_detect);
7932  EXPORT_SYMBOL(i2c_proc_real);
7933 -EXPORT_SYMBOL(i2c_register_entry);
7934  EXPORT_SYMBOL(i2c_sysctl_real);
7935 -
7936 -#ifdef MODULE
7937 +EXPORT_SYMBOL(i2c_detect);
7938  
7939  MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
7940  MODULE_DESCRIPTION("i2c-proc driver");
7941  MODULE_LICENSE("GPL");
7942  
7943 -int i2c_cleanup(void)
7944 -{
7945 -       if (i2c_initialized >= 1) {
7946 -               unregister_sysctl_table(i2c_proc_header);
7947 -               i2c_initialized--;
7948 -       }
7949 -       return 0;
7950 -}
7951 -
7952 -int init_module(void)
7953 -{
7954 -       return sensors_init();
7955 -}
7956 -
7957 -int cleanup_module(void)
7958 -{
7959 -       return i2c_cleanup();
7960 -}
7961 -#endif                         /* MODULE */
7962 +module_init(i2c_proc_init);
7963 +module_exit(i2c_proc_exit);
7964 --- linux-old/include/linux/i2c-proc.h  Thu Oct 11 15:05:47 2001
7965 +++ linux/include/linux/i2c-proc.h      Sun Dec  7 11:17:42 2003
7966 @@ -1,6 +1,7 @@
7967  /*
7968 -    sensors.h - Part of lm_sensors, Linux kernel modules for hardware
7969 -                monitoring
7970 +    i2c-proc.h - Part of the i2c package
7971 +    was originally sensors.h - Part of lm_sensors, Linux kernel modules
7972 +                               for hardware monitoring
7973      Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
7974  
7975      This program is free software; you can redistribute it and/or modify
7976 @@ -18,14 +19,9 @@
7977      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7978  */
7979  
7980 -#ifndef SENSORS_SENSORS_H
7981 -#define SENSORS_SENSORS_H
7982 +#ifndef _LINUX_I2C_PROC_H
7983 +#define _LINUX_I2C_PROC_H
7984  
7985 -#ifdef __KERNEL__
7986 -
7987 -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */
7988 -#include <linux/types.h>
7989 -#include <linux/fs.h>
7990  #include <linux/sysctl.h>
7991  
7992  /* The type of callback functions used in sensors_{proc,sysctl}_real */
7993 @@ -73,8 +69,7 @@
7994     these functions must be updated! */
7995  extern int i2c_register_entry(struct i2c_client *client,
7996                                   const char *prefix,
7997 -                                 ctl_table * ctl_template,
7998 -                                 struct module *controlling_mod);
7999 +                                 ctl_table * ctl_template);
8000  
8001  extern void i2c_deregister_entry(int id);
8002  
8003 @@ -347,6 +342,31 @@
8004                                                   {NULL}}; \
8005    SENSORS_INSMOD
8006  
8007 +#define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
8008 +  enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
8009 +  SENSORS_MODULE_PARM(force, \
8010 +                      "List of adapter,address pairs to boldly assume " \
8011 +                      "to be present"); \
8012 +  SENSORS_MODULE_PARM_FORCE(chip1); \
8013 +  SENSORS_MODULE_PARM_FORCE(chip2); \
8014 +  SENSORS_MODULE_PARM_FORCE(chip3); \
8015 +  SENSORS_MODULE_PARM_FORCE(chip4); \
8016 +  SENSORS_MODULE_PARM_FORCE(chip5); \
8017 +  SENSORS_MODULE_PARM_FORCE(chip6); \
8018 +  SENSORS_MODULE_PARM_FORCE(chip7); \
8019 +  SENSORS_MODULE_PARM_FORCE(chip8); \
8020 +  static struct i2c_force_data forces[] = {{force,any_chip}, \
8021 +                                                 {force_ ## chip1,chip1}, \
8022 +                                                 {force_ ## chip2,chip2}, \
8023 +                                                 {force_ ## chip3,chip3}, \
8024 +                                                 {force_ ## chip4,chip4}, \
8025 +                                                 {force_ ## chip5,chip5}, \
8026 +                                                 {force_ ## chip6,chip6}, \
8027 +                                                 {force_ ## chip7,chip7}, \
8028 +                                                 {force_ ## chip8,chip8}, \
8029 +                                                 {NULL}}; \
8030 +  SENSORS_INSMOD
8031 +
8032  typedef int i2c_found_addr_proc(struct i2c_adapter *adapter,
8033                                     int addr, unsigned short flags,
8034                                     int kind);
8035 @@ -362,7 +382,7 @@
8036  
8037  /* This macro is used to scale user-input to sensible values in almost all
8038     chip drivers. */
8039 -extern inline int SENSORS_LIMIT(long value, long low, long high)
8040 +static inline int SENSORS_LIMIT(long value, long low, long high)
8041  {
8042         if (value < low)
8043                 return low;
8044 @@ -372,8 +392,6 @@
8045                 return value;
8046  }
8047  
8048 -#endif                         /* def __KERNEL__ */
8049 -
8050  
8051  /* The maximum length of the prefix */
8052  #define SENSORS_PREFIX_MAX 20
8053 @@ -392,5 +410,5 @@
8054         char name[SENSORS_PREFIX_MAX + 13];
8055  };
8056  
8057 -#endif                         /* def SENSORS_SENSORS_H */
8058 +#endif                         /* def _LINUX_I2C_PROC_H */
8059  
8060 --- linux-old/drivers/i2c/i2c-rpx.c     Thu Jan  1 00:00:00 1970
8061 +++ linux/drivers/i2c/i2c-rpx.c Sun Dec  7 11:17:42 2003
8062 @@ -0,0 +1,103 @@
8063 +/*
8064 + * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
8065 + * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
8066 + *
8067 + * moved into proper i2c interface;
8068 + * Brad Parker (brad@heeltoe.com)
8069 + *
8070 + * RPX lite specific parts of the i2c interface
8071 + * Update:  There actually isn't anything RPXLite-specific about this module.
8072 + * This should work for most any 8xx board.  The console messages have been 
8073 + * changed to eliminate RPXLite references.
8074 + */
8075 +
8076 +#include <linux/kernel.h>
8077 +#include <linux/ioport.h>
8078 +#include <linux/module.h>
8079 +#include <linux/init.h>
8080 +#include <linux/stddef.h>
8081 +#include <linux/parport.h>
8082 +#include <linux/i2c.h>
8083 +#include <linux/i2c-algo-8xx.h>
8084 +#include <asm/mpc8xx.h>
8085 +#include <asm/commproc.h>
8086 +
8087 +
8088 +static void
8089 +rpx_iic_init(struct i2c_algo_8xx_data *data)
8090 +{
8091 +       volatile cpm8xx_t *cp;
8092 +       volatile immap_t *immap;
8093 +
8094 +       cp = cpmp;      /* Get pointer to Communication Processor */
8095 +       immap = (immap_t *)IMAP_ADDR;   /* and to internal registers */
8096 +
8097 +       data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
8098 +
8099 +       /* Check for and use a microcode relocation patch.
8100 +       */
8101 +       if ((data->reloc = data->iip->iic_rpbase))
8102 +               data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
8103 +               
8104 +       data->i2c = (i2c8xx_t *)&(immap->im_i2c);
8105 +       data->cp = cp;
8106 +
8107 +       /* Initialize Port B IIC pins.
8108 +       */
8109 +       cp->cp_pbpar |= 0x00000030;
8110 +       cp->cp_pbdir |= 0x00000030;
8111 +       cp->cp_pbodr |= 0x00000030;
8112 +
8113 +       /* Allocate space for two transmit and two receive buffer
8114 +        * descriptors in the DP ram.
8115 +        */
8116 +       data->dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 4);
8117 +
8118 +       /* ptr to i2c area */
8119 +       data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
8120 +}
8121 +
8122 +static int rpx_install_isr(int irq, void (*func)(void *, void *), void *data)
8123 +{
8124 +       /* install interrupt handler */
8125 +       cpm_install_handler(irq, (void (*)(void *, struct pt_regs *)) func, data);
8126 +
8127 +       return 0;
8128 +}
8129 +
8130 +static struct i2c_algo_8xx_data rpx_data = {
8131 +       .setisr = rpx_install_isr
8132 +};
8133 +
8134 +static struct i2c_adapter rpx_ops = {
8135 +       .owner          = THIS_MODULE,
8136 +       .name           = "m8xx",
8137 +       .id             = I2C_HW_MPC8XX_EPON,
8138 +       .algo_data      = &rpx_data,
8139 +};
8140 +
8141 +int __init i2c_rpx_init(void)
8142 +{
8143 +       printk("i2c-rpx.o: i2c MPC8xx module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8144 +
8145 +       /* reset hardware to sane state */
8146 +       rpx_iic_init(&rpx_data);
8147 +
8148 +       if (i2c_8xx_add_bus(&rpx_ops) < 0) {
8149 +               printk("i2c-rpx: Unable to register with I2C\n");
8150 +               return -ENODEV;
8151 +       }
8152 +
8153 +       return 0;
8154 +}
8155 +
8156 +void __exit i2c_rpx_exit(void)
8157 +{
8158 +       i2c_8xx_del_bus(&rpx_ops);
8159 +}
8160 +
8161 +MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
8162 +MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
8163 +
8164 +module_init(i2c_rpx_init);
8165 +module_exit(i2c_rpx_exit);
8166 --- linux-old/drivers/i2c/i2c-velleman.c        Thu Oct 11 15:05:47 2001
8167 +++ linux/drivers/i2c/i2c-velleman.c    Sun Dec  7 11:17:42 2003
8168 @@ -18,18 +18,18 @@
8169      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
8170  /* ------------------------------------------------------------------------- */
8171  
8172 -/* $Id$ */
8173 +/* $Id$ */
8174  
8175  #include <linux/kernel.h>
8176  #include <linux/ioport.h>
8177  #include <linux/module.h>
8178  #include <linux/init.h>
8179 -#include <linux/string.h>  /* for 2.0 kernels to get NULL   */
8180 -#include <asm/errno.h>     /* for 2.0 kernels to get ENODEV */
8181 -#include <asm/io.h>
8182 -
8183 +#include <linux/errno.h>
8184 +#include <linux/delay.h>
8185  #include <linux/i2c.h>
8186  #include <linux/i2c-algo-bit.h>
8187 +#include <asm/io.h>
8188 +#include <asm/param.h> /* for HZ */
8189  
8190  /* ----- global defines -----------------------------------------------        */
8191  #define DEB(x)         /* should be reasonable open, close &c.         */
8192 @@ -90,77 +90,40 @@
8193  
8194  static int bit_velle_init(void)
8195  {
8196 -       if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
8197 -               DEBE(printk("i2c-velleman.o: Port %#x already in use.\n",
8198 -                    base));
8199 +       if (!request_region(base, (base == 0x3bc) ? 3 : 8, 
8200 +                       "i2c (Vellemann adapter)"))
8201                 return -ENODEV;
8202 -       } else {
8203 -               request_region(base, (base == 0x3bc)? 3 : 8, 
8204 -                       "i2c (Vellemann adapter)");
8205 -               bit_velle_setsda((void*)base,1);
8206 -               bit_velle_setscl((void*)base,1);
8207 -       }
8208 -       return 0;
8209 -}
8210 -
8211 -static void __exit bit_velle_exit(void)
8212 -{      
8213 -       release_region( base , (base == 0x3bc)? 3 : 8 );
8214 -}
8215 -
8216 -
8217 -static int bit_velle_reg(struct i2c_client *client)
8218 -{
8219 -       return 0;
8220 -}
8221  
8222 -static int bit_velle_unreg(struct i2c_client *client)
8223 -{
8224 +       bit_velle_setsda((void*)base,1);
8225 +       bit_velle_setscl((void*)base,1);
8226         return 0;
8227  }
8228  
8229 -static void bit_velle_inc_use(struct i2c_adapter *adap)
8230 -{
8231 -#ifdef MODULE
8232 -       MOD_INC_USE_COUNT;
8233 -#endif
8234 -}
8235 -
8236 -static void bit_velle_dec_use(struct i2c_adapter *adap)
8237 -{
8238 -#ifdef MODULE
8239 -       MOD_DEC_USE_COUNT;
8240 -#endif
8241 -}
8242 -
8243  /* ------------------------------------------------------------------------
8244   * Encapsulate the above functions in the correct operations structure.
8245   * This is only done when more than one hardware adapter is supported.
8246   */
8247  
8248  static struct i2c_algo_bit_data bit_velle_data = {
8249 -       NULL,
8250 -       bit_velle_setsda,
8251 -       bit_velle_setscl,
8252 -       bit_velle_getsda,
8253 -       bit_velle_getscl,
8254 -       10, 10, 100,            /*      waits, timeout */
8255 +       .setsda         = bit_velle_setsda,
8256 +       .setscl         = bit_velle_setscl,
8257 +       .getsda         = bit_velle_getsda,
8258 +       .getscl         = bit_velle_getscl,
8259 +       .udelay         = 10,
8260 +       .mdelay         = 10,
8261 +       .timeout        = HZ
8262  };
8263  
8264  static struct i2c_adapter bit_velle_ops = {
8265 -       "Velleman K8000",
8266 -       I2C_HW_B_VELLE,
8267 -       NULL,
8268 -       &bit_velle_data,
8269 -       bit_velle_inc_use,
8270 -       bit_velle_dec_use,
8271 -       bit_velle_reg,
8272 -       bit_velle_unreg,
8273 +       .owner          = THIS_MODULE,
8274 +       .name           = "Velleman K8000",
8275 +       .id             = I2C_HW_B_VELLE,
8276 +       .algo_data      = &bit_velle_data,
8277  };
8278  
8279 -int __init  i2c_bitvelle_init(void)
8280 +static int __init i2c_bitvelle_init(void)
8281  {
8282 -       printk("i2c-velleman.o: i2c Velleman K8000 adapter module\n");
8283 +       printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
8284         if (base==0) {
8285                 /* probe some values */
8286                 base=DEFAULT_BASE;
8287 @@ -180,28 +143,21 @@
8288                         return -ENODEV;
8289                 }
8290         }
8291 -       printk("i2c-velleman.o: found device at %#x.\n",base);
8292 +       printk(KERN_DEBUG "i2c-velleman.o: found device at %#x.\n",base);
8293         return 0;
8294  }
8295  
8296 -EXPORT_NO_SYMBOLS;
8297 +static void __exit i2c_bitvelle_exit(void)
8298 +{      
8299 +       i2c_bit_del_bus(&bit_velle_ops);
8300 +       release_region(base, (base == 0x3bc) ? 3 : 8);
8301 +}
8302  
8303 -#ifdef MODULE
8304  MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
8305  MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
8306  MODULE_LICENSE("GPL");
8307  
8308  MODULE_PARM(base, "i");
8309  
8310 -int init_module(void) 
8311 -{
8312 -       return i2c_bitvelle_init();
8313 -}
8314 -
8315 -void cleanup_module(void) 
8316 -{
8317 -       i2c_bit_del_bus(&bit_velle_ops);
8318 -       bit_velle_exit();
8319 -}
8320 -
8321 -#endif
8322 +module_init(i2c_bitvelle_init);
8323 +module_exit(i2c_bitvelle_exit);
8324 --- linux-old/include/linux/i2c.h       Tue Jul 15 10:23:54 2003
8325 +++ linux/include/linux/i2c.h   Sun Dec  7 11:17:43 2003
8326 @@ -23,46 +23,33 @@
8327  /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
8328     Frodo Looijaard <frodol@dds.nl> */
8329  
8330 -/* $Id$ */
8331 +/* $Id$ */
8332  
8333 -#ifndef I2C_H
8334 -#define I2C_H
8335 +#ifndef _LINUX_I2C_H
8336 +#define _LINUX_I2C_H
8337  
8338 -#define I2C_DATE "20010830"
8339 -#define I2C_VERSION "2.6.1"
8340 +#define I2C_DATE "20031005"
8341 +#define I2C_VERSION "2.8.1"
8342  
8343 -#include <linux/i2c-id.h>      /* id values of adapters et. al.        */
8344 +#include <linux/module.h>
8345  #include <linux/types.h>
8346 -
8347 -
8348 -struct i2c_msg;
8349 -
8350 -
8351 -#ifdef __KERNEL__
8352 -
8353 -/* --- Includes and compatibility declarations ------------------------ */
8354 -
8355 -#include <linux/version.h>
8356 -#ifndef KERNEL_VERSION
8357 -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
8358 -#endif
8359 -
8360 -#include <asm/page.h>                  /* for 2.2.xx                   */
8361 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,25)
8362 +#include <linux/errno.h>
8363  #include <linux/sched.h>
8364 -#else
8365  #include <asm/semaphore.h>
8366 +#include <linux/i2c-id.h>
8367 +
8368 +#include <linux/version.h>
8369 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
8370 +#define MODULE_LICENSE(x)
8371  #endif
8372 -#include <linux/config.h>
8373  
8374  /* --- General options ------------------------------------------------        */
8375  
8376 -#define I2C_ALGO_MAX   4               /* control memory consumption   */
8377 -#define I2C_ADAP_MAX   16
8378 +#define I2C_ADAP_MAX   16              /* control memory consumption   */
8379  #define I2C_DRIVER_MAX 16
8380  #define I2C_CLIENT_MAX 32
8381 -#define I2C_DUMMY_MAX 4
8382  
8383 +struct i2c_msg;
8384  struct i2c_algorithm;
8385  struct i2c_adapter;
8386  struct i2c_client;
8387 @@ -70,7 +57,6 @@
8388  struct i2c_client_address_data;
8389  union i2c_smbus_data;
8390  
8391 -
8392  /*
8393   * The master routines are the ones normally used to transmit data to devices
8394   * on a bus (or read from them). Apart from two basic transfer functions to 
8395 @@ -123,6 +109,8 @@
8396  extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
8397                                        u8 command, u8 length,
8398                                        u8 *values);
8399 +extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
8400 +                                         u8 command, u8 *values);
8401  extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
8402                                            u8 command, u8 length,
8403                                            u8 *values);
8404 @@ -135,6 +123,7 @@
8405   */
8406  
8407  struct i2c_driver {
8408 +       struct module *owner;
8409         char name[32];
8410         int id;
8411         unsigned int flags;             /* div., see below              */
8412 @@ -158,18 +147,6 @@
8413          * with the device.
8414          */
8415         int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
8416 -       
8417 -       /* These two are mainly used for bookkeeping & dynamic unloading of 
8418 -        * kernel modules. inc_use tells the driver that a client is being  
8419 -        * used by another module & that it should increase its ref. counter.
8420 -        * dec_use is the inverse operation.
8421 -        * NB: Make sure you have no circular dependencies, or else you get a 
8422 -        * deadlock when trying to unload the modules.
8423 -       * You should use the i2c_{inc,dec}_use_client functions instead of
8424 -       * calling this function directly.
8425 -        */
8426 -       void (*inc_use)(struct i2c_client *client);
8427 -       void (*dec_use)(struct i2c_client *client);
8428  };
8429  
8430  /*
8431 @@ -202,6 +179,7 @@
8432   * to name two of the most common.
8433   */
8434  struct i2c_algorithm {
8435 +       struct module *owner;                   /* future use --km      */
8436         char name[32];                          /* textual description  */
8437         unsigned int id;
8438  
8439 @@ -226,25 +204,18 @@
8440         u32 (*functionality) (struct i2c_adapter *);
8441  };
8442  
8443 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8444 -struct proc_dir_entry;
8445 -#endif
8446 -
8447  /*
8448   * i2c_adapter is the structure used to identify a physical i2c bus along
8449   * with the access algorithms necessary to access it.
8450   */
8451  struct i2c_adapter {
8452 +       struct module *owner;
8453         char name[32];  /* some useful name to identify the adapter     */
8454         unsigned int id;/* == is algo->id | hwdep.struct->id,           */
8455                         /* for registered values see below              */
8456         struct i2c_algorithm *algo;/* the algorithm to access the bus   */
8457         void *algo_data;
8458  
8459 -       /* --- These may be NULL, but should increase the module use count */
8460 -       void (*inc_use)(struct i2c_adapter *);
8461 -       void (*dec_use)(struct i2c_adapter *);
8462 -
8463         /* --- administration stuff. */
8464         int (*client_register)(struct i2c_client *);
8465         int (*client_unregister)(struct i2c_client *);
8466 @@ -255,11 +226,11 @@
8467                         /* and can be set via the i2c_ioctl call        */
8468  
8469                         /* data fields that are valid for all devices   */
8470 -       struct semaphore lock;  
8471 +       struct semaphore bus;
8472 +       struct semaphore list;  
8473         unsigned int flags;/* flags specifying div. data                */
8474  
8475         struct i2c_client *clients[I2C_CLIENT_MAX];
8476 -       int client_count;
8477  
8478         int timeout;
8479         int retries;
8480 @@ -267,9 +238,6 @@
8481  #ifdef CONFIG_PROC_FS 
8482         /* No need to set this when you initialize the adapter          */
8483         int inode;
8484 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)
8485 -       struct proc_dir_entry *proc_entry;
8486 -#endif
8487  #endif /* def CONFIG_PROC_FS */
8488  };
8489  
8490 @@ -281,6 +249,9 @@
8491  #define I2C_CLIENT_ALLOW_USE           0x01    /* Client allows access */
8492  #define I2C_CLIENT_ALLOW_MULTIPLE_USE  0x02    /* Allow multiple access-locks */
8493                                                 /* on an i2c_client */
8494 +#define I2C_CLIENT_PEC  0x04                   /* Use Packet Error Checking */
8495 +#define I2C_CLIENT_TEN 0x10                    /* we have a ten bit chip address       */
8496 +                                               /* Must equal I2C_M_TEN below */
8497  
8498  /* i2c_client_address_data is the struct for holding default client
8499   * addresses for a driver and for the parameters supplied on the
8500 @@ -319,12 +290,6 @@
8501  extern int i2c_attach_client(struct i2c_client *);
8502  extern int i2c_detach_client(struct i2c_client *);
8503  
8504 -/* Only call these if you grab a resource that makes unloading the
8505 -   client and the adapter it is on completely impossible. Like when a
8506 -   /proc directory is entered. */
8507 -extern void i2c_inc_use_client(struct i2c_client *);
8508 -extern void i2c_dec_use_client(struct i2c_client *);
8509 -
8510  /* New function: This is to get an i2c_client-struct for controlling the 
8511     client either by using i2c_control-function or having the 
8512     client-module export functions that can be used with the i2c_client
8513 @@ -358,6 +323,15 @@
8514                 struct i2c_client_address_data *address_data,
8515                 i2c_client_found_addr_proc *found_proc);
8516  
8517 +static inline int i2c_client_command(struct i2c_client *client,
8518 +                                    unsigned int cmd, void *arg)
8519 +{
8520 +       if (client->driver && client->driver->command)
8521 +               return client->driver->command(client, cmd, arg);
8522 +       else
8523 +               return -EINVAL;
8524 +}
8525 +
8526  /* An ioctl like call to set div. parameters of the adapter.
8527   */
8528  extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
8529 @@ -375,8 +349,6 @@
8530  /* Return 1 if adapter supports everything we need, 0 if not. */
8531  extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
8532  
8533 -#endif /* __KERNEL__ */
8534 -
8535  /*
8536   * I2C Message - used for pure i2c transaction, also from /dev interface
8537   */
8538 @@ -387,15 +359,25 @@
8539  #define I2C_M_RD       0x01
8540  #define I2C_M_NOSTART  0x4000
8541  #define I2C_M_REV_DIR_ADDR     0x2000
8542 +#define I2C_M_IGNORE_NAK       0x1000
8543 +#define I2C_M_NO_RD_ACK                0x0800
8544         __u16 len;              /* msg length                           */
8545         __u8 *buf;              /* pointer to msg data                  */
8546 +       int err;
8547 +       short done;
8548  };
8549  
8550  /* To determine what functionality is present */
8551  
8552  #define I2C_FUNC_I2C                   0x00000001
8553  #define I2C_FUNC_10BIT_ADDR            0x00000002
8554 -#define I2C_FUNC_PROTOCOL_MANGLING     0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART} */
8555 +#define I2C_FUNC_PROTOCOL_MANGLING     0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
8556 +#define I2C_FUNC_SMBUS_HWPEC_CALC      0x00000008 /* SMBus 2.0 */
8557 +#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
8558 +#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
8559 +#define I2C_FUNC_SMBUS_PROC_CALL_PEC   0x00002000 /* SMBus 2.0 */
8560 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
8561 +#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
8562  #define I2C_FUNC_SMBUS_QUICK           0x00010000 
8563  #define I2C_FUNC_SMBUS_READ_BYTE       0x00020000 
8564  #define I2C_FUNC_SMBUS_WRITE_BYTE      0x00040000 
8565 @@ -406,8 +388,12 @@
8566  #define I2C_FUNC_SMBUS_PROC_CALL       0x00800000 
8567  #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000 
8568  #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 
8569 -#define I2C_FUNC_SMBUS_READ_I2C_BLOCK  0x04000000 /* New I2C-like block */
8570 -#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* transfer */
8571 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK  0x04000000 /* I2C-like block xfer  */
8572 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
8573 +#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2         0x10000000 /* I2C-like block xfer  */
8574 +#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
8575 +#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
8576 +#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
8577  
8578  #define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
8579                              I2C_FUNC_SMBUS_WRITE_BYTE
8580 @@ -419,21 +405,40 @@
8581                                    I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
8582  #define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
8583                                    I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
8584 +#define I2C_FUNC_SMBUS_I2C_BLOCK_2 I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
8585 +                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2
8586 +#define I2C_FUNC_SMBUS_BLOCK_DATA_PEC I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
8587 +                                      I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC
8588 +#define I2C_FUNC_SMBUS_WORD_DATA_PEC  I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
8589 +                                      I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC
8590 +
8591 +#define I2C_FUNC_SMBUS_READ_BYTE_PEC           I2C_FUNC_SMBUS_READ_BYTE_DATA
8592 +#define I2C_FUNC_SMBUS_WRITE_BYTE_PEC          I2C_FUNC_SMBUS_WRITE_BYTE_DATA
8593 +#define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC      I2C_FUNC_SMBUS_READ_WORD_DATA
8594 +#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC     I2C_FUNC_SMBUS_WRITE_WORD_DATA
8595 +#define I2C_FUNC_SMBUS_BYTE_PEC                        I2C_FUNC_SMBUS_BYTE_DATA
8596 +#define I2C_FUNC_SMBUS_BYTE_DATA_PEC           I2C_FUNC_SMBUS_WORD_DATA
8597  
8598  #define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
8599                              I2C_FUNC_SMBUS_BYTE | \
8600                              I2C_FUNC_SMBUS_BYTE_DATA | \
8601                              I2C_FUNC_SMBUS_WORD_DATA | \
8602                              I2C_FUNC_SMBUS_PROC_CALL | \
8603 -                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
8604 +                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
8605 +                            I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
8606 +                            I2C_FUNC_SMBUS_I2C_BLOCK
8607  
8608  /* 
8609   * Data for SMBus Messages 
8610   */
8611 +#define I2C_SMBUS_BLOCK_MAX    32      /* As specified in SMBus standard */    
8612 +#define I2C_SMBUS_I2C_BLOCK_MAX        32      /* Not specified but we use same structure */
8613  union i2c_smbus_data {
8614         __u8 byte;
8615         __u16 word;
8616 -       __u8 block[33]; /* block[0] is used for length */
8617 +       __u8 block[I2C_SMBUS_BLOCK_MAX + 3]; /* block[0] is used for length */
8618 +                          /* one more for read length in block process call */
8619 +                                                   /* and one more for PEC */
8620  };
8621  
8622  /* smbus_access read or write markers */
8623 @@ -449,6 +454,11 @@
8624  #define I2C_SMBUS_PROC_CALL        4
8625  #define I2C_SMBUS_BLOCK_DATA       5
8626  #define I2C_SMBUS_I2C_BLOCK_DATA    6
8627 +#define I2C_SMBUS_BLOCK_PROC_CALL   7          /* SMBus 2.0 */
8628 +#define I2C_SMBUS_BLOCK_DATA_PEC    8          /* SMBus 2.0 */
8629 +#define I2C_SMBUS_PROC_CALL_PEC     9          /* SMBus 2.0 */
8630 +#define I2C_SMBUS_BLOCK_PROC_CALL_PEC  10      /* SMBus 2.0 */
8631 +#define I2C_SMBUS_WORD_DATA_PEC           11           /* SMBus 2.0 */
8632  
8633  
8634  /* ----- commands for the ioctl like i2c_command call:
8635 @@ -474,6 +484,7 @@
8636  
8637  #define I2C_FUNCS      0x0705  /* Get the adapter functionality */
8638  #define I2C_RDWR       0x0707  /* Combined R/W transfer (one stop only)*/
8639 +#define I2C_PEC                0x0708  /* != 0 for SMBus PEC                   */
8640  #if 0
8641  #define I2C_ACK_TEST   0x0710  /* See if a slave is at a specific address */
8642  #endif
8643 @@ -489,16 +500,6 @@
8644  
8645  #define I2C_MAJOR      89              /* Device major number          */
8646  
8647 -#ifdef __KERNEL__
8648 -
8649 -#  ifndef NULL
8650 -#    define NULL ( (void *) 0 )
8651 -#  endif
8652 -
8653 -#  ifndef ENODEV
8654 -#    include <asm/errno.h>
8655 -#  endif
8656 -
8657  /* These defines are used for probing i2c client addresses */
8658  /* Default fill of many variables */
8659  #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
8660 @@ -560,5 +561,11 @@
8661  #define i2c_is_isa_adapter(adapptr) \
8662          ((adapptr)->algo->id == I2C_ALGO_ISA)
8663  
8664 -#endif /* def __KERNEL__ */
8665 -#endif /* I2C_H */
8666 +/* Tiny delay function used by the i2c bus drivers */
8667 +static inline void i2c_delay(signed long timeout)
8668 +{
8669 +       set_current_state(TASK_INTERRUPTIBLE);
8670 +       schedule_timeout(timeout);
8671 +}
8672 +
8673 +#endif /* _LINUX_I2C_H */
8674 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-adap-ite.c    Tue Jul 15 12:23:01 2003
8675 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-adap-ite.c     Sat Nov 15 20:41:10 2003
8676 @@ -199,22 +199,6 @@
8677  }
8678  
8679  
8680 -static void iic_ite_inc_use(struct i2c_adapter *adap)
8681 -{
8682 -#ifdef MODULE
8683 -       MOD_INC_USE_COUNT;
8684 -#endif
8685 -}
8686 -
8687 -
8688 -static void iic_ite_dec_use(struct i2c_adapter *adap)
8689 -{
8690 -#ifdef MODULE
8691 -       MOD_DEC_USE_COUNT;
8692 -#endif
8693 -}
8694 -
8695 -
8696  /* ------------------------------------------------------------------------
8697   * Encapsulate the above functions in the correct operations structure.
8698   * This is only done when more than one hardware adapter is supported.
8699 @@ -230,14 +214,13 @@
8700  };
8701  
8702  static struct i2c_adapter iic_ite_ops = {
8703 -       "ITE IIC adapter",
8704 -       I2C_HW_I_IIC,
8705 -       NULL,
8706 -       &iic_ite_data,
8707 -       iic_ite_inc_use,
8708 -       iic_ite_dec_use,
8709 -       iic_ite_reg,
8710 -       iic_ite_unreg,
8711 +       .owner             = THIS_MODULE,
8712 +       .name              = "ITE IIC adapter",
8713 +       .id                = I2C_HW_I_IIC,
8714 +       .algo              = NULL,
8715 +       .algo_data         = &iic_ite_data,
8716 +       .client_register   = iic_ite_reg,
8717 +       .client_unregieter = iic_ite_unreg,
8718  };
8719  
8720  /* Called when the module is loaded.  This function starts the
8721 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-algo-ite.c    Thu Oct 11 17:05:47 2001
8722 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-algo-ite.c     Sat Nov 15 20:41:10 2003
8723 @@ -742,14 +742,12 @@
8724  /* -----exported algorithm data: ------------------------------------- */
8725  
8726  static struct i2c_algorithm iic_algo = {
8727 -       "ITE IIC algorithm",
8728 -       I2C_ALGO_IIC,
8729 -       iic_xfer,               /* master_xfer  */
8730 -       NULL,                           /* smbus_xfer   */
8731 -       NULL,                           /* slave_xmit           */
8732 -       NULL,                           /* slave_recv           */
8733 -       algo_control,                   /* ioctl                */
8734 -       iic_func,                       /* functionality        */
8735 +       .owner          = THIS_MODULE,
8736 +       .name           = "ITE IIC algorithm",
8737 +       .id             = I2C_ALGO_IIC,
8738 +       .master_xfer    = iic_xfer,
8739 +       .algo_control   = algo_control,
8740 +       .functionality  = iic_func,
8741  };
8742  
8743  
8744 @@ -780,10 +778,6 @@
8745         adap->retries = 3;              /* be replaced by defines       */
8746         adap->flags = 0;
8747  
8748 -#ifdef MODULE
8749 -       MOD_INC_USE_COUNT;
8750 -#endif
8751 -
8752         i2c_add_adapter(adap);
8753         iic_init(iic_adap);
8754  
8755 @@ -816,9 +810,6 @@
8756                 return res;
8757         DEB2(printk("i2c-algo-ite: adapter unregistered: %s\n",adap->name));
8758  
8759 -#ifdef MODULE
8760 -       MOD_DEC_USE_COUNT;
8761 -#endif
8762         return 0;
8763  }
8764  
8765 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-algo-sibyte.c Wed Aug 27 18:11:46 2003
8766 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-algo-sibyte.c  Sat Nov 15 20:41:10 2003
8767 @@ -136,14 +136,15 @@
8768  /* -----exported algorithm data: ------------------------------------- */
8769  
8770  static struct i2c_algorithm i2c_sibyte_algo = {
8771 -       "SiByte algorithm",
8772 -       I2C_ALGO_SIBYTE,
8773 -       NULL,                           /* master_xfer          */
8774 -       smbus_xfer,                     /* smbus_xfer           */
8775 -       NULL,                           /* slave_xmit           */
8776 -       NULL,                           /* slave_recv           */
8777 -       algo_control,                   /* ioctl                */
8778 -       bit_func,                       /* functionality        */
8779 +       .owner                  = THIS_MODULE,
8780 +       .name                   = "SiByte algorithm",
8781 +       .id                     = I2C_ALGO_SIBYTE,
8782 +       .master_xfer            = NULL,
8783 +       .smbus_xfer             = smbus_xfer,
8784 +       .slave_xmit             = NULL,
8785 +       .slave_recv             = NULL,
8786 +       .algo_control           = algo_control,
8787 +       .functionality          = bit_func,
8788  };
8789  
8790  /* 
8791 @@ -181,9 +182,6 @@
8792                 printk("\n");
8793         }
8794  
8795 -#ifdef MODULE
8796 -       MOD_INC_USE_COUNT;
8797 -#endif
8798         i2c_add_adapter(i2c_adap);
8799  
8800         return 0;
8801 @@ -197,9 +195,6 @@
8802         if ((res = i2c_del_adapter(adap)) < 0)
8803                 return res;
8804  
8805 -#ifdef MODULE
8806 -       MOD_DEC_USE_COUNT;
8807 -#endif
8808         return 0;
8809  }
8810  
8811 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-keywest.c     Tue Jul 15 12:23:26 2003
8812 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-keywest.c      Sat Nov 15 20:41:10 2003
8813 @@ -412,25 +412,14 @@
8814                I2C_FUNC_SMBUS_BLOCK_DATA;
8815  }
8816  
8817 -static void
8818 -keywest_inc(struct i2c_adapter *adapter)
8819 -{
8820 -       MOD_INC_USE_COUNT;
8821 -}
8822 -
8823 -static void
8824 -keywest_dec(struct i2c_adapter *adapter)
8825 -{
8826 -       MOD_DEC_USE_COUNT;
8827 -}
8828 -
8829  /* For now, we only handle combined mode (smbus) */
8830  static struct i2c_algorithm keywest_algorithm = {
8831 -       name:           "Keywest i2c",
8832 -       id:             I2C_ALGO_SMBUS,
8833 -       smbus_xfer:     keywest_smbus_xfer,
8834 -       master_xfer:    keywest_xfer,
8835 -       functionality:  keywest_func,
8836 +       .owner          = THIS_MODULE,
8837 +       .name           = "Keywest i2c",
8838 +       .id             = I2C_ALGO_SMBUS,
8839 +       .smbus_xfer     = keywest_smbus_xfer,
8840 +       .master_xfer    = keywest_xfer,
8841 +       .functionality  = keywest_func,
8842  };
8843  
8844  
8845 @@ -527,14 +516,13 @@
8846                 struct keywest_chan* chan = &iface->channels[i];
8847                 u8 addr;
8848                 
8849 +               chan->adapter.owner = THIS_MODULE;
8850                 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
8851                 chan->iface = iface;
8852                 chan->chan_no = i;
8853                 chan->adapter.id = I2C_ALGO_SMBUS;
8854                 chan->adapter.algo = &keywest_algorithm;
8855                 chan->adapter.algo_data = NULL;
8856 -               chan->adapter.inc_use = keywest_inc;
8857 -               chan->adapter.dec_use = keywest_dec;
8858                 chan->adapter.client_register = NULL;
8859                 chan->adapter.client_unregister = NULL;
8860                 chan->adapter.data = chan;
8861 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-max1617.c     Wed Aug 27 18:11:46 2003
8862 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-max1617.c      Sat Nov 15 20:41:10 2003
8863 @@ -67,18 +67,15 @@
8864  static int max1617_probe(struct i2c_adapter *adap);
8865  static int max1617_detach(struct i2c_client *device);
8866  static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg);
8867 -static void max1617_inc_use(struct i2c_client *device);
8868 -static void max1617_dec_use(struct i2c_client *device);
8869  
8870  struct i2c_driver i2c_driver_max1617 = {
8871 -       name:           IF_NAME,
8872 -       id:             I2C_DRIVERID_MAX1617,
8873 -       flags:          I2C_DF_NOTIFY,
8874 -       attach_adapter: max1617_probe,
8875 -       detach_client:  max1617_detach,
8876 -       command:        max1617_command,
8877 -       inc_use:        max1617_inc_use,
8878 -       dec_use:        max1617_dec_use
8879 +       .owner                  = THIS_MODULE,
8880 +       .name                   = IF_NAME,
8881 +       .id                     = I2C_DRIVERID_MAX1617,
8882 +       .flags                  = I2C_DF_NOTIFY,
8883 +       .attach_adapter         = max1617_probe,
8884 +       .detach_client          = max1617_detach,
8885 +       .command                = max1617_command,
8886  };
8887  \
8888  static int max1617_read(struct i2c_client *client, unsigned char subaddr)
8889 @@ -184,20 +181,6 @@
8890  static int max1617_command(struct i2c_client *device, unsigned int cmd, void *arg)
8891  {
8892          return 0;
8893 -}
8894 -
8895 -static void max1617_inc_use(struct i2c_client *client)
8896 -{
8897 -#ifdef MODULE
8898 -       MOD_INC_USE_COUNT;
8899 -#endif
8900 -}
8901 -
8902 -static void max1617_dec_use(struct i2c_client *client)
8903 -{
8904 -#ifdef MODULE
8905 -       MOD_DEC_USE_COUNT;
8906 -#endif
8907  }
8908  
8909  void i2c_max1617_init(void)
8910 --- linux-2.4.23-rc1-orig/drivers/i2c/i2c-sibyte.c      Wed Aug 27 18:11:46 2003
8911 +++ linux-2.4.23-rc1-i2c/drivers/i2c/i2c-sibyte.c       Sat Nov 15 20:41:10 2003
8912 @@ -38,48 +38,30 @@
8913         return 0;
8914  }
8915  
8916 -static void sibyte_inc_use(struct i2c_adapter *adap)
8917 -{
8918 -#ifdef MODULE
8919 -       MOD_INC_USE_COUNT;
8920 -#endif
8921 -}
8922 -
8923 -static void sibyte_dec_use(struct i2c_adapter *adap)
8924 -{
8925 -#ifdef MODULE
8926 -       MOD_DEC_USE_COUNT;
8927 -#endif
8928 -}
8929 -
8930  static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
8931          { NULL, 0, (void *)(KSEG1+A_SMB_BASE(0)) },
8932          { NULL, 1, (void *)(KSEG1+A_SMB_BASE(1)) }
8933  };
8934  
8935  static struct i2c_adapter sibyte_board_adapter[2] = {
8936 -        {
8937 -                name:              "SiByte SMBus 0",
8938 -                id:                I2C_HW_SIBYTE,
8939 -                algo:              NULL,
8940 -                algo_data:         &sibyte_board_data[0],
8941 -                inc_use:           sibyte_inc_use,
8942 -                dec_use:           sibyte_dec_use,
8943 -                client_register:   sibyte_reg,
8944 -                client_unregister: sibyte_unreg,
8945 -               client_count:      0
8946 -        } , 
8947 -        {
8948 -                name:              "SiByte SMBus 1",
8949 -                id:                I2C_HW_SIBYTE,
8950 -                algo:              NULL,
8951 -                algo_data:         &sibyte_board_data[1],
8952 -                inc_use:           sibyte_inc_use,
8953 -                dec_use:           sibyte_dec_use,
8954 -                client_register:   sibyte_reg,
8955 -                client_unregister: sibyte_unreg,
8956 -               client_count:      0
8957 -        }
8958 +       {
8959 +               .owner                  = THIS_MODULE,
8960 +               .name                   = "SiByte SMBus 0",
8961 +               .id                     = I2C_HW_SIBYTE,
8962 +               .algo                   = NULL,
8963 +               .algo_data              = &sibyte_board_data[0],
8964 +               .client_register        = sibyte_reg,
8965 +               .client_unregister      = sibyte_unreg,
8966 +       } , 
8967 +       {
8968 +               .owner                  = THIS_MODULE,
8969 +               .name                   = "SiByte SMBus 1",
8970 +               .id                     = I2C_HW_SIBYTE,
8971 +               .algo                   = NULL,
8972 +               .algo_data              = &sibyte_board_data[1],
8973 +               .client_register        = sibyte_reg,
8974 +               .client_unregister      = sibyte_unreg,
8975 +       }
8976  };
8977  
8978  int __init i2c_sibyte_init(void)
8979 --- linux-2.4.23-rc1-orig/drivers/i2c/scx200_acb.c      Tue Jul 15 12:23:49 2003
8980 +++ linux-2.4.23-rc1-i2c/drivers/i2c/scx200_acb.c       Sat Nov 15 20:45:06 2003
8981 @@ -408,22 +408,13 @@
8982         return 0;
8983  }
8984  
8985 -static void scx200_acb_inc_use(struct i2c_adapter *adapter)
8986 -{
8987 -       MOD_INC_USE_COUNT;
8988 -}
8989 -
8990 -static void scx200_acb_dec_use(struct i2c_adapter *adapter)
8991 -{
8992 -       MOD_DEC_USE_COUNT;
8993 -}
8994 -
8995  /* For now, we only handle combined mode (smbus) */
8996  static struct i2c_algorithm scx200_acb_algorithm = {
8997 -       name:           "NatSemi SCx200 ACCESS.bus",
8998 -       id:             I2C_ALGO_SMBUS,
8999 -       smbus_xfer:     scx200_acb_smbus_xfer,
9000 -       functionality:  scx200_acb_func,
9001 +       .owner          = THIS_MODULE,
9002 +       .name           = "NatSemi SCx200 ACCESS.bus",
9003 +       .id             = I2C_ALGO_SMBUS,
9004 +       .smbus_xfer     = scx200_acb_smbus_xfer,
9005 +       .functionality  = scx200_acb_func,
9006  };
9007  
9008  struct scx200_acb_iface *scx200_acb_list;
9009 @@ -479,11 +470,10 @@
9010         memset(iface, 0, sizeof(*iface));
9011         adapter = &iface->adapter;
9012         adapter->data = iface;
9013 +       adapter->owner = THIS_MODULE;
9014         sprintf(adapter->name, "SCx200 ACB%d", index);
9015         adapter->id = I2C_ALGO_SMBUS;
9016         adapter->algo = &scx200_acb_algorithm;
9017 -       adapter->inc_use = scx200_acb_inc_use;
9018 -       adapter->dec_use = scx200_acb_dec_use;
9019         adapter->client_register = scx200_acb_reg;
9020         adapter->client_unregister = scx200_acb_unreg;
9021  
9022 --- linux-2.4.23-rc1-orig/drivers/i2c/scx200_i2c.c      Tue Jul 15 12:23:49 2003
9023 +++ linux-2.4.23-rc1-i2c/drivers/i2c/scx200_i2c.c       Sat Nov 15 20:45:06 2003
9024 @@ -76,16 +76,6 @@
9025         return 0;
9026  }
9027  
9028 -static void scx200_i2c_inc_use(struct i2c_adapter *adap)
9029 -{
9030 -       MOD_INC_USE_COUNT;
9031 -}
9032 -
9033 -static void scx200_i2c_dec_use(struct i2c_adapter *adap)
9034 -{
9035 -       MOD_DEC_USE_COUNT;
9036 -}
9037 -
9038  /* ------------------------------------------------------------------------
9039   * Encapsulate the above functions in the correct operations structure.
9040   * This is only done when more than one hardware adapter is supported.
9041 @@ -101,11 +91,10 @@
9042  };
9043  
9044  static struct i2c_adapter scx200_i2c_ops = {
9045 +       .owner             = THIS_MODULE,
9046         .name              = "NatSemi SCx200 I2C",
9047         .id                = I2C_HW_B_VELLE,
9048         .algo_data         = &scx200_i2c_data,
9049 -       .inc_use           = scx200_i2c_inc_use,
9050 -       .dec_use           = scx200_i2c_dec_use,
9051         .client_register   = scx200_i2c_reg,
9052         .client_unregister = scx200_i2c_unreg,
9053  };
9054 diff -ruN linux-2.4.23-rc1-orig/drivers/ieee1394/pcilynx.c linux-2.4.23-rc1-i2c/drivers/ieee1394/pcilynx.c
9055 --- linux-2.4.23-rc1-orig/drivers/ieee1394/pcilynx.c    Sat Nov 15 17:24:54 2003
9056 +++ linux-2.4.23-rc1-i2c/drivers/ieee1394/pcilynx.c     Sat Nov 15 17:39:43 2003
9057 @@ -139,7 +139,8 @@
9058  }; 
9059  
9060  static struct i2c_adapter bit_ops = {
9061 -       .id                     = 0xAA, //FIXME: probably we should get an id in i2c-id.h
9062 +       .owner                  = THIS_MODULE,
9063 +       .id                     = I2C_HW_B_PCILYNX,
9064         .client_register        = bit_reg,
9065         .client_unregister      = bit_unreg,
9066         .name                   = "PCILynx I2C",
9067 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/Makefile linux-2.4.23-rc1-i2c/drivers/media/video/Makefile
9068 --- linux-2.4.23-rc1-orig/drivers/media/video/Makefile  Wed Aug 27 18:11:47 2003
9069 +++ linux-2.4.23-rc1-i2c/drivers/media/video/Makefile   Sat Nov 15 18:46:46 2003
9070 @@ -40,7 +40,7 @@
9071  
9072  obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
9073  obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o i2c-old.o
9074 -obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o i2c-old.o
9075 +obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
9076  obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
9077  obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o
9078  obj-$(CONFIG_VIDEO_W9966) += w9966.o
9079 @@ -48,11 +48,10 @@
9080  obj-$(CONFIG_VIDEO_ZORAN_BUZ) += saa7111.o saa7185.o
9081  obj-$(CONFIG_VIDEO_ZORAN_DC10) += saa7110.o adv7175.o
9082  obj-$(CONFIG_VIDEO_ZORAN_LML33) += bt819.o bt856.o
9083 -obj-$(CONFIG_VIDEO_LML33) += bt856.o bt819.o
9084  obj-$(CONFIG_VIDEO_PMS) += pms.o
9085  obj-$(CONFIG_VIDEO_PLANB) += planb.o
9086  obj-$(CONFIG_VIDEO_VINO) += vino.o
9087 -obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
9088 +obj-$(CONFIG_VIDEO_STRADIS) += stradis.o i2c-old.o
9089  obj-$(CONFIG_VIDEO_CPIA) += cpia.o
9090  obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
9091  obj-$(CONFIG_VIDEO_CPIA_USB) += cpia_usb.o
9092 @@ -81,8 +80,8 @@
9093  
9094  fastdep:
9095  
9096 -zoran.o: zr36120.o zr36120_i2c.o zr36120_mem.o
9097 -       $(LD) $(LD_RFLAG) -r -o $@ zr36120.o zr36120_i2c.o zr36120_mem.o
9098 +zoran.o: $(zoran-objs)
9099 +       $(LD) $(LD_RFLAG) -r -o $@ $(zoran-objs)
9100  
9101  bttv.o: $(bttv-objs)
9102         $(LD) $(LD_RFLAG) -r -o $@ $(bttv-objs)
9103 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/bt832.c linux-2.4.23-rc1-i2c/drivers/media/video/bt832.c
9104 --- linux-2.4.23-rc1-orig/drivers/media/video/bt832.c   Tue Jul 15 12:23:50 2003
9105 +++ linux-2.4.23-rc1-i2c/drivers/media/video/bt832.c    Sat Nov 15 18:46:46 2003
9106 @@ -187,7 +187,6 @@
9107          t->client.data = t;
9108          i2c_attach_client(&t->client);
9109  
9110 -       MOD_INC_USE_COUNT;
9111         if(! bt832_init(&t->client)) {
9112                 bt832_detach(&t->client);
9113                 return -1;
9114 @@ -226,7 +225,7 @@
9115         printk("bt832: detach.\n");
9116         i2c_detach_client(client);
9117         kfree(t);
9118 -       MOD_DEC_USE_COUNT;
9119 +
9120         return 0;
9121  }
9122  
9123 @@ -257,8 +256,9 @@
9124  /* ----------------------------------------------------------------------- */
9125  
9126  static struct i2c_driver driver = {
9127 +        .owner          = THIS_MODULE,
9128          .name           = "i2c bt832 driver",
9129 -        .id             = -1, /* FIXME */
9130 +        .id             = I2C_DRIVERID_BT832,
9131          .flags          = I2C_DF_NOTIFY,
9132          .attach_adapter = bt832_probe,
9133          .detach_client  = bt832_detach,
9134 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/i2c-old.c linux-2.4.23-rc1-i2c/drivers/media/video/i2c-old.c
9135 --- linux-2.4.23-rc1-orig/drivers/media/video/i2c-old.c Sun Sep 30 21:26:06 2001
9136 +++ linux-2.4.23-rc1-i2c/drivers/media/video/i2c-old.c  Sat Nov 15 18:46:46 2003
9137 @@ -36,28 +36,11 @@
9138  static struct i2c_driver *drivers[I2C_DRIVER_MAX];
9139  static int bus_count = 0, driver_count = 0;
9140  
9141 -#ifdef CONFIG_VIDEO_BUZ
9142 -extern int saa7111_init(void);
9143 -extern int saa7185_init(void);
9144 -#endif
9145 -#ifdef CONFIG_VIDEO_LML33
9146 -extern int bt819_init(void);
9147 -extern int bt856_init(void);
9148 -#endif
9149 -
9150  int i2c_init(void)
9151  {
9152         printk(KERN_INFO "i2c: initialized%s\n",
9153                 scan ? " (i2c bus scan enabled)" : "");
9154         /* anything to do here ? */
9155 -#ifdef CONFIG_VIDEO_BUZ
9156 -       saa7111_init();
9157 -       saa7185_init();
9158 -#endif
9159 -#ifdef CONFIG_VIDEO_LML33
9160 -       bt819_init();
9161 -       bt856_init();
9162 -#endif
9163         return 0;
9164  }
9165  
9166 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/msp3400.c linux-2.4.23-rc1-i2c/drivers/media/video/msp3400.c
9167 --- linux-2.4.23-rc1-orig/drivers/media/video/msp3400.c Sat Nov 15 17:24:54 2003
9168 +++ linux-2.4.23-rc1-i2c/drivers/media/video/msp3400.c  Sat Nov 15 18:46:46 2003
9169 @@ -1243,6 +1243,7 @@
9170  static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
9171  
9172  static struct i2c_driver driver = {
9173 +        .owner          = THIS_MODULE,
9174          .name           = "i2c msp3400 driver",
9175          .id             = I2C_DRIVERID_MSP3400,
9176          .flags          = I2C_DF_NOTIFY,
9177 @@ -1346,7 +1347,6 @@
9178         printk("\n");
9179  
9180         /* startup control thread */
9181 -       MOD_INC_USE_COUNT;
9182         msp->notify = &sem;
9183         rc = kernel_thread(msp->simple ? msp3410d_thread : msp3400c_thread,
9184                            (void *)c, 0);
9185 @@ -1399,7 +1399,7 @@
9186         i2c_detach_client(client);
9187         kfree(msp);
9188         kfree(client);
9189 -       MOD_DEC_USE_COUNT;
9190 +
9191         return 0;
9192  }
9193  
9194 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa5249.c linux-2.4.23-rc1-i2c/drivers/media/video/saa5249.c
9195 --- linux-2.4.23-rc1-orig/drivers/media/video/saa5249.c Sun Sep 30 21:26:06 2001
9196 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa5249.c  Sat Nov 15 18:46:46 2003
9197 @@ -217,7 +217,7 @@
9198         }
9199         t->client = client;
9200         i2c_attach_client(client);
9201 -       MOD_INC_USE_COUNT;
9202 +
9203         return 0;
9204  }
9205  
9206 @@ -244,7 +244,7 @@
9207         kfree(vd->priv);
9208         kfree(vd);
9209         kfree(client);
9210 -       MOD_DEC_USE_COUNT;
9211 +
9212         return 0;
9213  }
9214  
9215 @@ -256,23 +256,23 @@
9216  
9217  /* new I2C driver support */
9218  
9219 -static struct i2c_driver i2c_driver_videotext = 
9220 -{
9221 -       IF_NAME,                /* name */
9222 -       I2C_DRIVERID_SAA5249, /* in i2c.h */
9223 -       I2C_DF_NOTIFY,
9224 -       saa5249_probe,
9225 -       saa5249_detach,
9226 -       saa5249_command
9227 +static struct i2c_driver i2c_driver_videotext = {
9228 +       .owner          = THIS_MODULE,
9229 +       .name           = IF_NAME,
9230 +       .id             = I2C_DRIVERID_SAA5249, /* in i2c-id.h */
9231 +       .flags          = I2C_DF_NOTIFY,
9232 +       .attach_adapter = saa5249_probe,
9233 +       .detach_client  = saa5249_detach,
9234 +       .command        = saa5249_command,
9235  };
9236  
9237  static struct i2c_client client_template = {
9238 -       "(unset)",
9239 -       -1,
9240 -       0,
9241 -       0,
9242 -       NULL,
9243 -       &i2c_driver_videotext
9244 +       .name           = "(unset)",
9245 +       .id             = -1,
9246 +       .flags          = 0,
9247 +       .addr           = 0,
9248 +       .adapter        = NULL,
9249 +       .driver         = &i2c_driver_videotext,
9250  };
9251  
9252  /*
9253 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa7110.c linux-2.4.23-rc1-i2c/drivers/media/video/saa7110.c
9254 --- linux-2.4.23-rc1-orig/drivers/media/video/saa7110.c Sat Nov 15 17:24:54 2003
9255 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa7110.c  Sat Nov 15 18:59:29 2003
9256 @@ -404,7 +404,7 @@
9257  {
9258         "saa7110",                      /* name */
9259  
9260 -       I2C_DRIVERID_VIDEODECODER,      /* in i2c.h */
9261 +       I2C_DRIVERID_VIDEODECODER,      /* in i2c-old.h */
9262         I2C_SAA7110, I2C_SAA7110+1,     /* Addr range */
9263  
9264         saa7110_attach,
9265 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/saa7146.h linux-2.4.23-rc1-i2c/drivers/media/video/saa7146.h
9266 --- linux-2.4.23-rc1-orig/drivers/media/video/saa7146.h Mon Dec 11 22:15:51 2000
9267 +++ linux-2.4.23-rc1-i2c/drivers/media/video/saa7146.h  Sat Nov 15 18:46:46 2003
9268 @@ -25,9 +25,6 @@
9269  #include <linux/types.h>
9270  #include <linux/wait.h>
9271  
9272 -#include <linux/i2c.h>
9273 -#include <linux/videodev.h>
9274 -
9275  #ifndef O_NONCAP  
9276  #define O_NONCAP       O_TRUNC
9277  #endif
9278 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/swarm_saa7114h.c linux-2.4.23-rc1-i2c/drivers/media/video/swarm_saa7114h.c
9279 --- linux-2.4.23-rc1-orig/drivers/media/video/swarm_saa7114h.c  Wed Aug 27 18:11:47 2003
9280 +++ linux-2.4.23-rc1-i2c/drivers/media/video/swarm_saa7114h.c   Sat Nov 15 18:46:46 2003
9281 @@ -201,11 +201,12 @@
9282  
9283  struct i2c_driver i2c_driver_saa7114h =
9284  {
9285 -       name:           "saa7114h",             /* name */
9286 -       id:             I2C_DRIVERID_SAA7114H,  /* ID */
9287 -       flags:          I2C_DF_NOTIFY,          /* XXXKW do I care? */
9288 -       attach_adapter: saa7114h_probe,
9289 -       detach_client:  saa7114h_detach
9290 +       .owner          = THIS_MODULE,
9291 +       .name           = "saa7114h",
9292 +       .id             = I2C_DRIVERID_SAA7114H,
9293 +       .flags          = I2C_DF_NOTIFY,
9294 +       .attach_adapter = saa7114h_probe,
9295 +       .detach_client  = saa7114h_detach,
9296  };
9297  
9298  /* -----------------------------------------------------------------------
9299 @@ -1634,8 +1635,6 @@
9300         create_proc_decoder(vd->priv);
9301  #endif
9302  
9303 -       MOD_INC_USE_COUNT;
9304 -
9305         return 0;
9306  }
9307  
9308 @@ -1668,7 +1667,6 @@
9309  {
9310  #if 0
9311         kfree(device->data);
9312 -       MOD_DEC_USE_COUNT;
9313  #endif
9314  #ifdef CONFIG_PROC_FS
9315         destroy_proc_decoder(((struct video_device *)device->data)->priv);
9316 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda7432.c linux-2.4.23-rc1-i2c/drivers/media/video/tda7432.c
9317 --- linux-2.4.23-rc1-orig/drivers/media/video/tda7432.c Sat Nov 15 17:24:54 2003
9318 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda7432.c  Sat Nov 15 18:46:46 2003
9319 @@ -332,7 +332,6 @@
9320         i2c_set_clientdata(client, t);
9321         
9322         do_tda7432_init(client);
9323 -       MOD_INC_USE_COUNT;
9324         printk(KERN_INFO "tda7432: init\n");
9325  
9326         i2c_attach_client(client);
9327 @@ -359,7 +358,7 @@
9328         i2c_detach_client(client);
9329         
9330         kfree(t);
9331 -       MOD_DEC_USE_COUNT;
9332 +
9333         return 0;
9334  }
9335  
9336 @@ -520,6 +519,7 @@
9337  }
9338  
9339  static struct i2c_driver driver = {
9340 +       .owner           = THIS_MODULE,
9341          .name            = "i2c tda7432 driver",
9342         .id              = I2C_DRIVERID_TDA7432,
9343          .flags           = I2C_DF_NOTIFY,
9344 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda9875.c linux-2.4.23-rc1-i2c/drivers/media/video/tda9875.c
9345 --- linux-2.4.23-rc1-orig/drivers/media/video/tda9875.c Sat Nov 15 17:24:54 2003
9346 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda9875.c  Sat Nov 15 18:46:46 2003
9347 @@ -266,7 +266,6 @@
9348         }
9349         
9350         do_tda9875_init(client);
9351 -       MOD_INC_USE_COUNT;
9352         printk(KERN_INFO "tda9875: init\n");
9353  
9354         i2c_attach_client(client);
9355 @@ -293,7 +292,7 @@
9356         i2c_detach_client(client);
9357         
9358         kfree(t);
9359 -       MOD_DEC_USE_COUNT;
9360 +
9361         return 0;
9362  }
9363  
9364 @@ -391,6 +390,7 @@
9365  
9366  
9367  static struct i2c_driver driver = {
9368 +        .owner          = THIS_MODULE,
9369          .name           = "i2c tda9875 driver",
9370          .id             = I2C_DRIVERID_TDA9875,
9371          .flags          = I2C_DF_NOTIFY,
9372 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tda9887.c linux-2.4.23-rc1-i2c/drivers/media/video/tda9887.c
9373 --- linux-2.4.23-rc1-orig/drivers/media/video/tda9887.c Sat Nov 15 17:24:54 2003
9374 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tda9887.c  Sat Nov 15 18:46:46 2003
9375 @@ -363,7 +363,6 @@
9376          i2c_set_clientdata(&t->client, t);
9377          i2c_attach_client(&t->client);
9378          
9379 -       MOD_INC_USE_COUNT;
9380         return 0;
9381  }
9382  
9383 @@ -390,7 +389,7 @@
9384  
9385         i2c_detach_client(client);
9386         kfree(t);
9387 -       MOD_DEC_USE_COUNT;
9388 +
9389         return 0;
9390  }
9391  
9392 @@ -443,8 +442,9 @@
9393  /* ----------------------------------------------------------------------- */
9394  
9395  static struct i2c_driver driver = {
9396 +        .owner          = THIS_MODULE,
9397          .name           = "i2c tda9887 driver",
9398 -        .id             = -1, /* FIXME */
9399 +        .id             = I2C_DRIVERID_TDA9887,
9400          .flags          = I2C_DF_NOTIFY,
9401          .attach_adapter = tda9887_probe,
9402          .detach_client  = tda9887_detach,
9403 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tuner-3036.c linux-2.4.23-rc1-i2c/drivers/media/video/tuner-3036.c
9404 --- linux-2.4.23-rc1-orig/drivers/media/video/tuner-3036.c      Sun Sep 30 21:26:06 2001
9405 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tuner-3036.c       Sat Nov 15 18:46:46 2003
9406 @@ -136,7 +136,6 @@
9407         printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
9408  
9409          i2c_attach_client(client);
9410 -       MOD_INC_USE_COUNT;
9411  
9412         if (i2c_master_send(client, buffer, 2) != 2)
9413                 printk("tuner: i2c i/o error 1\n");
9414 @@ -150,7 +149,6 @@
9415  static int 
9416  tuner_detach(struct i2c_client *c)
9417  {
9418 -       MOD_DEC_USE_COUNT;
9419         return 0;
9420  }
9421  
9422 @@ -183,24 +181,23 @@
9423  /* ----------------------------------------------------------------------- */
9424  
9425  static struct i2c_driver 
9426 -i2c_driver_tuner = 
9427 -{
9428 -       "sab3036",              /* name       */
9429 -       I2C_DRIVERID_SAB3036,   /* ID         */
9430 -        I2C_DF_NOTIFY,
9431 -       tuner_probe,
9432 -       tuner_detach,
9433 -       tuner_command
9434 +i2c_driver_tuner = {
9435 +       .owner          = THIS_MODULE,
9436 +       .name           = "sab3036",
9437 +       .id             = I2C_DRIVERID_SAB3036,
9438 +       .flags          = I2C_DF_NOTIFY,
9439 +       .attach_adapter = tuner_probe,
9440 +       .detach_client  = tuner_detach,
9441 +       .command        = tuner_command,
9442  };
9443  
9444 -static struct i2c_client client_template =
9445 -{
9446 -        "SAB3036",             /* name       */
9447 -        -1,
9448 -        0,
9449 -        0,
9450 -        NULL,
9451 -        &i2c_driver_tuner
9452 +static struct i2c_client client_template = {
9453 +       .name           = "SAB3036",
9454 +       .id             = -1,
9455 +       .flags          = 0,
9456 +       .addr           = 0,
9457 +       .adapter        = NULL,
9458 +       .driver         = &i2c_driver_tuner,
9459  };
9460  
9461  EXPORT_NO_SYMBOLS;
9462 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tuner.c linux-2.4.23-rc1-i2c/drivers/media/video/tuner.c
9463 --- linux-2.4.23-rc1-orig/drivers/media/video/tuner.c   Sat Nov 15 17:24:54 2003
9464 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tuner.c    Sat Nov 15 18:46:46 2003
9465 @@ -971,6 +971,7 @@
9466  /* ----------------------------------------------------------------------- */
9467  
9468  static struct i2c_driver driver = {
9469 +        .owner          = THIS_MODULE,
9470          .name           = "i2c TV tuner driver",
9471          .id             = I2C_DRIVERID_TUNER,
9472          .flags          = I2C_DF_NOTIFY,
9473 diff -ruN linux-2.4.23-rc1-orig/drivers/media/video/tvaudio.c linux-2.4.23-rc1-i2c/drivers/media/video/tvaudio.c
9474 --- linux-2.4.23-rc1-orig/drivers/media/video/tvaudio.c Sat Nov 15 17:24:54 2003
9475 +++ linux-2.4.23-rc1-i2c/drivers/media/video/tvaudio.c  Sat Nov 15 18:46:46 2003
9476 @@ -1463,7 +1463,6 @@
9477         chip->shadow.count = desc->registers+1;
9478          chip->prevmode = -1;
9479         /* register */
9480 -       MOD_INC_USE_COUNT;
9481         i2c_attach_client(&chip->c);
9482  
9483         /* initialization  */
9484 @@ -1538,7 +1537,7 @@
9485         
9486         i2c_detach_client(&chip->c);
9487         kfree(chip);
9488 -       MOD_DEC_USE_COUNT;
9489 +
9490         return 0;
9491  }
9492  
9493 @@ -1649,6 +1648,7 @@
9494  
9495  
9496  static struct i2c_driver driver = {
9497 +        .owner           = THIS_MODULE,
9498          .name            = "generic i2c audio driver",
9499          .id              = I2C_DRIVERID_TVAUDIO,
9500          .flags           = I2C_DF_NOTIFY,
9501 diff -ruN linux-2.4.23-rc1-orig/drivers/pcmcia/sa1100_stork.c linux-2.4.23-rc1-i2c/drivers/pcmcia/sa1100_stork.c
9502 --- linux-2.4.23-rc1-orig/drivers/pcmcia/sa1100_stork.c Tue Jul 15 12:23:03 2003
9503 +++ linux-2.4.23-rc1-i2c/drivers/pcmcia/sa1100_stork.c  Sat Nov 15 17:41:42 2003
9504 @@ -24,7 +24,6 @@
9505  #include <linux/init.h>
9506  #include <linux/kernel.h>
9507  #include <linux/sched.h>
9508 -#include <linux/i2c.h>
9509  
9510  #include <asm/hardware.h>
9511  #include <asm/irq.h>
9512 diff -ruN linux-2.4.23-rc1-orig/drivers/sound/dmasound/dac3550a.c linux-2.4.23-rc1-i2c/drivers/sound/dmasound/dac3550a.c
9513 --- linux-2.4.23-rc1-orig/drivers/sound/dmasound/dac3550a.c     Tue Jul 15 12:22:41 2003
9514 +++ linux-2.4.23-rc1-i2c/drivers/sound/dmasound/dac3550a.c      Sat Nov 15 18:27:29 2003
9515 @@ -52,15 +52,14 @@
9516  };
9517  
9518  struct i2c_driver daca_driver = {  
9519 -       name:           "DAC3550A driver  V " DACA_VERSION,
9520 -       id:             I2C_DRIVERID_DACA,
9521 -       flags:          I2C_DF_NOTIFY,
9522 -       attach_adapter: &daca_attach_adapter,
9523 -       detach_client:  &daca_detach_client,
9524 -       command:        NULL,
9525 -       inc_use:        NULL, /* &daca_inc_use, */
9526 -       dec_use:        NULL  /* &daca_dev_use  */
9527 -  };
9528 +       .owner          = THIS_MODULE,
9529 +       .name           = "DAC3550A driver  V " DACA_VERSION,
9530 +       .id             = I2C_DRIVERID_DACA,
9531 +       .flags          = I2C_DF_NOTIFY,
9532 +       .attach_adapter = &daca_attach_adapter,
9533 +       .detach_client  = &daca_detach_client,
9534 +       .command        = NULL,
9535 +};
9536  
9537  
9538  #define VOL_MAX ((1<<20) - 1)
9539 diff -ruN linux-2.4.23-rc1-orig/drivers/sound/dmasound/tas3001c.c linux-2.4.23-rc1-i2c/drivers/sound/dmasound/tas3001c.c
9540 --- linux-2.4.23-rc1-orig/drivers/sound/dmasound/tas3001c.c     Tue Jul 15 12:22:41 2003
9541 +++ linux-2.4.23-rc1-i2c/drivers/sound/dmasound/tas3001c.c      Sat Nov 15 18:27:29 2003
9542 @@ -90,14 +90,13 @@
9543  };
9544  
9545  struct i2c_driver tas_driver = {  
9546 -       name:           "TAS3001C driver  V 0.3",
9547 -       id:             I2C_DRIVERID_TAS,
9548 -       flags:          I2C_DF_NOTIFY,
9549 -       attach_adapter: &tas_attach_adapter,
9550 -       detach_client:  &tas_detach_client,
9551 -       command:        NULL,
9552 -       inc_use:        NULL, /* &tas_inc_use, */
9553 -       dec_use:        NULL  /* &tas_dev_use  */
9554 +       .owner          = THIS_MODULE,
9555 +       .name           = "TAS3001C driver  V " TAS_VERSION,
9556 +       .id             = I2C_DRIVERID_TAS,
9557 +       .flags          = I2C_DF_NOTIFY,
9558 +       .attach_adapter = &tas_attach_adapter,
9559 +       .detach_client  = &tas_detach_client,
9560 +       .command        = NULL,
9561  };
9562  
9563  int
9564 diff -ruN linux-2.4.23-rc1-orig/drivers/usb/w9968cf.c linux-2.4.23-rc1-i2c/drivers/usb/w9968cf.c
9565 --- linux-2.4.23-rc1-orig/drivers/usb/w9968cf.c Sat Nov 15 17:24:56 2003
9566 +++ linux-2.4.23-rc1-i2c/drivers/usb/w9968cf.c  Sat Nov 15 21:48:40 2003
9567 @@ -441,8 +441,6 @@
9568  static int w9968cf_i2c_detach_inform(struct i2c_client*);
9569  static int w9968cf_i2c_control(struct i2c_adapter*, unsigned int cmd,
9570                                 unsigned long arg);
9571 -static void w9968cf_i2c_inc_use(struct i2c_adapter*);
9572 -static void w9968cf_i2c_dec_use(struct i2c_adapter*);
9573  
9574  /* Memory management */
9575  static inline unsigned long kvirt_to_pa(unsigned long adr);
9576 @@ -1832,18 +1830,6 @@
9577  }
9578  
9579  
9580 -static void w9968cf_i2c_inc_use(struct i2c_adapter* adap)
9581 -{
9582 -       MOD_INC_USE_COUNT;
9583 -}
9584 -
9585 -
9586 -static void w9968cf_i2c_dec_use(struct i2c_adapter* adap)
9587 -{
9588 -       MOD_DEC_USE_COUNT;
9589 -}
9590 -
9591 -
9592  static int w9968cf_i2c_init(struct w9968cf_device* cam)
9593  {
9594         int rc = 0;
9595 @@ -1857,9 +1843,8 @@
9596         };
9597  
9598         static struct i2c_adapter adap = {
9599 +               .owner =             THIS_MODULE,
9600                 .id =                I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF,
9601 -               .inc_use =           w9968cf_i2c_inc_use,
9602 -               .dec_use =           w9968cf_i2c_dec_use,
9603                 .client_register =   w9968cf_i2c_attach_inform,
9604                 .client_unregister = w9968cf_i2c_detach_inform,
9605                 .algo =              &algo,
9606 diff -ruN linux-2.4.23-rc1-orig/drivers/video/matrox/i2c-matroxfb.c linux-2.4.23-rc1-i2c/drivers/video/matrox/i2c-matroxfb.c
9607 --- linux-2.4.23-rc1-orig/drivers/video/matrox/i2c-matroxfb.c   Tue Jul 15 12:23:53 2003
9608 +++ linux-2.4.23-rc1-i2c/drivers/video/matrox/i2c-matroxfb.c    Sat Nov 15 18:28:33 2003
9609 @@ -87,29 +87,20 @@
9610         return (matroxfb_read_gpio(b->minfo) & b->mask.clock) ? 1 : 0;
9611  }
9612  
9613 -static void matroxfb_dh_inc_use(struct i2c_adapter* dummy) {
9614 -       MOD_INC_USE_COUNT;
9615 -}
9616 -
9617 -static void matroxfb_dh_dec_use(struct i2c_adapter* dummy) {
9618 -       MOD_DEC_USE_COUNT;
9619 -}
9620 -
9621 -static struct i2c_adapter matrox_i2c_adapter_template =
9622 -{
9623 -       .id =           I2C_HW_B_G400,
9624 -       .inc_use =      matroxfb_dh_inc_use,
9625 -       .dec_use =      matroxfb_dh_dec_use,
9626 +static struct i2c_adapter matrox_i2c_adapter_template = {
9627 +       .owner          = THIS_MODULE,
9628 +       .id             = I2C_HW_B_G400,
9629  };
9630  
9631 -static struct i2c_algo_bit_data matrox_i2c_algo_template =
9632 -{
9633 -       NULL,
9634 -       matroxfb_gpio_setsda,
9635 -       matroxfb_gpio_setscl,
9636 -       matroxfb_gpio_getsda,
9637 -       matroxfb_gpio_getscl,
9638 -       10, 10, 100,
9639 +static struct i2c_algo_bit_data matrox_i2c_algo_template = {
9640 +       .data           = NULL,
9641 +       .setsda         = matroxfb_gpio_setsda,
9642 +       .setscl         = matroxfb_gpio_setscl,
9643 +       .getsda         = matroxfb_gpio_getsda,
9644 +       .getscl         = matroxfb_gpio_getscl,
9645 +       .udelay         = 10,
9646 +       .mdelay         = 10,
9647 +       .timeout        = 100,
9648  };
9649  
9650  static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo, 
9651 diff -ruN linux-2.4.23-rc1-orig/drivers/video/matrox/matroxfb_maven.c linux-2.4.23-rc1-i2c/drivers/video/matrox/matroxfb_maven.c
9652 --- linux-2.4.23-rc1-orig/drivers/video/matrox/matroxfb_maven.c Tue Jul 15 12:23:53 2003
9653 +++ linux-2.4.23-rc1-i2c/drivers/video/matrox/matroxfb_maven.c  Sat Nov 15 18:28:33 2003
9654 @@ -1246,14 +1246,6 @@
9655  static unsigned short normal_i2c_range[] = { MAVEN_I2CID, MAVEN_I2CID, I2C_CLIENT_END };
9656  I2C_CLIENT_INSMOD;
9657  
9658 -static void maven_inc_use(struct i2c_client* clnt) {
9659 -       MOD_INC_USE_COUNT;
9660 -}
9661 -
9662 -static void maven_dec_use(struct i2c_client* clnt) {
9663 -       MOD_DEC_USE_COUNT;
9664 -}
9665 -
9666  static struct i2c_driver maven_driver;
9667  
9668  static int maven_detect_client(struct i2c_adapter* adapter, int address, unsigned short flags,
9669 @@ -1319,15 +1311,14 @@
9670  
9671  static int maven_driver_registered = 0;
9672  
9673 -static struct i2c_driver maven_driver={
9674 -       "maven",
9675 -       I2C_DRIVERID_MGATVO,
9676 -       I2C_DF_NOTIFY,
9677 -       maven_attach_adapter,
9678 -       maven_detach_client,
9679 -       maven_command,
9680 -       maven_inc_use,
9681 -       maven_dec_use
9682 +static struct i2c_driver maven_driver = {
9683 +       .owner          = THIS_MODULE,
9684 +       .name           = "maven",
9685 +       .id             = I2C_DRIVERID_MGATVO,
9686 +       .flags          = I2C_DF_NOTIFY,
9687 +       .attach_adapter = maven_attach_adapter,
9688 +       .detach_client  = maven_detach_client,
9689 +       .command        = maven_command,
9690  };
9691  
9692  /* ************************** */
This page took 0.836622 seconds and 3 git commands to generate.