aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt38
-rw-r--r--Documentation/i2c/busses/i2c-nforce22
-rw-r--r--Documentation/i2c/porting-clients18
-rw-r--r--Documentation/i2c/summary29
-rw-r--r--Documentation/i2c/writing-clients415
-rw-r--r--Documentation/usb/usb-serial.txt2
-rw-r--r--MAINTAINERS23
-rw-r--r--arch/i386/kernel/cpu/cpufreq/longhaul.c21
-rw-r--r--arch/i386/kernel/cpu/cpufreq/p4-clockmod.c31
-rw-r--r--arch/i386/kernel/cpu/cpufreq/powernow-k8.c6
-rw-r--r--arch/i386/kernel/cpu/cpufreq/powernow-k8.h2
-rw-r--r--arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c10
-rw-r--r--arch/m68k/Kconfig3
-rw-r--r--arch/m68k/Makefile2
-rw-r--r--arch/m68k/amiga/config.c1091
-rw-r--r--arch/m68k/atari/Makefile1
-rw-r--r--arch/m68k/atari/atakeyb.c730
-rw-r--r--arch/m68k/atari/config.c998
-rw-r--r--arch/m68k/atari/debug.c482
-rw-r--r--arch/m68k/kernel/entry.S2
-rw-r--r--arch/m68k/kernel/head.S2
-rw-r--r--arch/m68k/kernel/setup.c368
-rw-r--r--arch/m68k/lib/checksum.c3
-rw-r--r--arch/m68k/mac/baboon.c32
-rw-r--r--arch/m68k/mac/config.c167
-rw-r--r--arch/m68k/mac/debug.c331
-rw-r--r--arch/m68k/mac/oss.c18
-rw-r--r--arch/m68k/mac/psc.c21
-rw-r--r--arch/m68k/mac/via.c284
-rw-r--r--arch/m68k/q40/config.c272
-rw-r--r--arch/m68k/sun3/sun3ints.c2
-rw-r--r--arch/m68k/sun3x/prom.c132
-rw-r--r--arch/powerpc/platforms/powermac/cpufreq_32.c1
-rw-r--r--arch/s390/crypto/aes_s390.c15
-rw-r--r--arch/s390/kernel/kprobes.c3
-rw-r--r--arch/s390/kernel/setup.c111
-rw-r--r--arch/s390/mm/fault.c40
-rw-r--r--arch/x86_64/kernel/cpufreq/Kconfig19
-rw-r--r--crypto/Kconfig13
-rw-r--r--crypto/Makefile2
-rw-r--r--crypto/ablkcipher.c83
-rw-r--r--crypto/algapi.c169
-rw-r--r--crypto/blkcipher.c72
-rw-r--r--crypto/cbc.c11
-rw-r--r--crypto/cryptd.c375
-rw-r--r--crypto/cryptomgr.c66
-rw-r--r--crypto/ecb.c11
-rw-r--r--crypto/hash.c2
-rw-r--r--crypto/hmac.c11
-rw-r--r--crypto/lrw.c11
-rw-r--r--crypto/pcbc.c11
-rw-r--r--crypto/tcrypt.c121
-rw-r--r--crypto/xcbc.c12
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/processor_perflib.c46
-rw-r--r--drivers/char/agp/ali-agp.c2
-rw-r--r--drivers/char/agp/generic.c22
-rw-r--r--drivers/char/agp/intel-agp.c8
-rw-r--r--drivers/char/agp/nvidia-agp.c9
-rw-r--r--drivers/char/agp/sgi-agp.c5
-rw-r--r--drivers/char/agp/sis-agp.c278
-rw-r--r--drivers/char/agp/sworks-agp.c23
-rw-r--r--drivers/cpufreq/Kconfig61
-rw-r--r--drivers/cpufreq/cpufreq.c47
-rw-r--r--drivers/crypto/Kconfig16
-rw-r--r--drivers/crypto/Makefile1
-rw-r--r--drivers/crypto/padlock.c58
-rw-r--r--drivers/i2c/Kconfig18
-rw-r--r--drivers/i2c/Makefile1
-rw-r--r--drivers/i2c/algos/Kconfig8
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c286
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c9
-rw-r--r--drivers/i2c/busses/Kconfig151
-rw-r--r--drivers/i2c/busses/Makefile4
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c644
-rw-r--r--drivers/i2c/busses/i2c-elektor.c51
-rw-r--r--drivers/i2c/busses/i2c-gpio.c215
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c43
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c6
-rw-r--r--drivers/i2c/busses/i2c-omap.c3
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c144
-rw-r--r--drivers/i2c/busses/i2c-parport.c25
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c35
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c15
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c96
-rw-r--r--drivers/i2c/busses/i2c-simtec.c186
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-tiny-usb.c277
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
-rw-r--r--drivers/i2c/chips/Kconfig21
-rw-r--r--drivers/i2c/i2c-boardinfo.c90
-rw-r--r--drivers/i2c/i2c-core.c662
-rw-r--r--drivers/i2c/i2c-core.h31
-rw-r--r--drivers/input/keyboard/Kconfig11
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/atakbd.c134
-rw-r--r--drivers/input/keyboard/hilkbd.c2
-rw-r--r--drivers/input/mouse/Kconfig11
-rw-r--r--drivers/input/mouse/Makefile1
-rw-r--r--drivers/input/mouse/atarimouse.c160
-rw-r--r--drivers/macintosh/therm_windtunnel.c3
-rw-r--r--drivers/macintosh/via-cuda.c58
-rw-r--r--drivers/macintosh/via-macii.c582
-rw-r--r--drivers/macintosh/via-pmu68k.c3
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c3
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-i2c.c2
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c4
-rw-r--r--drivers/media/video/cx2341x.c1
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h1
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c1
-rw-r--r--drivers/net/7990.c6
-rw-r--r--drivers/net/Kconfig6
-rw-r--r--drivers/net/Space.c4
-rw-r--r--drivers/net/a2065.c8
-rw-r--r--drivers/net/ariadne.c1
-rw-r--r--drivers/net/jazzsonic.c27
-rw-r--r--drivers/net/mac8390.c245
-rw-r--r--drivers/net/mac89x0.c88
-rw-r--r--drivers/net/macmace.c591
-rw-r--r--drivers/net/macsonic.c65
-rw-r--r--drivers/net/sonic.c32
-rw-r--r--drivers/net/sun3_82586.c5
-rw-r--r--drivers/ps3/ps3av.c108
-rw-r--r--drivers/ps3/ps3av_cmd.c20
-rw-r--r--drivers/s390/block/dasd.c45
-rw-r--r--drivers/s390/block/dasd_eckd.c81
-rw-r--r--drivers/s390/block/dasd_fba.c2
-rw-r--r--drivers/s390/block/dasd_int.h2
-rw-r--r--drivers/s390/char/tape.h1
-rw-r--r--drivers/s390/char/tape_3590.c29
-rw-r--r--drivers/s390/char/tape_3590.h4
-rw-r--r--drivers/s390/char/tape_core.c3
-rw-r--r--drivers/s390/cio/qdio.c240
-rw-r--r--drivers/s390/cio/qdio.h52
-rw-r--r--drivers/s390/net/qeth.h3
-rw-r--r--drivers/s390/net/qeth_main.c77
-rw-r--r--drivers/s390/net/qeth_mpc.h1
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/atari_NCR5380.c4398
-rw-r--r--drivers/scsi/atari_scsi.c377
-rw-r--r--drivers/scsi/atari_scsi.h174
-rw-r--r--drivers/video/Kconfig5
-rw-r--r--drivers/video/Makefile3
-rw-r--r--drivers/video/atafb.c2801
-rw-r--r--drivers/video/atafb.h36
-rw-r--r--drivers/video/atafb_iplan2p2.c293
-rw-r--r--drivers/video/atafb_iplan2p4.c308
-rw-r--r--drivers/video/atafb_iplan2p8.c345
-rw-r--r--drivers/video/atafb_mfb.c112
-rw-r--r--drivers/video/atafb_utils.h400
-rw-r--r--drivers/video/intelfb/intelfb_i2c.c3
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c2
-rw-r--r--drivers/video/ps3fb.c116
-rw-r--r--drivers/zorro/proc.c5
-rw-r--r--drivers/zorro/zorro-sysfs.c3
-rw-r--r--drivers/zorro/zorro.c3
-rw-r--r--include/asm-i386/agp.h6
-rw-r--r--include/asm-m68k/adb.h75
-rw-r--r--include/asm-m68k/atarikb.h6
-rw-r--r--include/asm-powerpc/ps3av.h22
-rw-r--r--include/asm-s390/ccwdev.h6
-rw-r--r--include/asm-s390/elf.h7
-rw-r--r--include/asm-s390/kdebug.h18
-rw-r--r--include/asm-s390/kprobes.h16
-rw-r--r--include/asm-s390/lowcore.h10
-rw-r--r--include/asm-x86_64/agp.h6
-rw-r--r--include/crypto/algapi.h84
-rw-r--r--include/linux/cpufreq.h1
-rw-r--r--include/linux/crypto.h236
-rw-r--r--include/linux/highmem.h10
-rw-r--r--include/linux/i2c-algo-bit.h7
-rw-r--r--include/linux/i2c-gpio.h38
-rw-r--r--include/linux/i2c-id.h3
-rw-r--r--include/linux/i2c.h123
-rw-r--r--include/linux/input.h1
-rw-r--r--include/linux/interrupt.h6
-rw-r--r--include/linux/nubus.h126
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/media/ovcamchip.h1
-rw-r--r--include/media/tuner.h1
-rw-r--r--sound/oss/dmasound/tas_ioctl.h1
191 files changed, 14716 insertions, 8527 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 144058cf849a..5f96cb33743e 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -183,18 +183,10 @@ Who: Jean Delvare <khali@linux-fr.org>
183 183
184--------------------------- 184---------------------------
185 185
186What: i2c_adapter.dev 186What: i2c_adapter.list
187 i2c_adapter.list
188When: July 2007 187When: July 2007
189Why: Superfluous, given i2c_adapter.class_dev: 188Why: Superfluous, this list duplicates the one maintained by the driver
190 * The "dev" was a stand-in for the physical device node that legacy 189 core.
191 drivers would not have; but now it's almost always present. Any
192 remaining legacy drivers must upgrade (they now trigger warnings).
193 * The "list" duplicates class device children.
194 The delay in removing this is so upgraded lm_sensors and libsensors
195 can get deployed. (Removal causes minor changes in the sysfs layout,
196 notably the location of the adapter type name and parenting the i2c
197 client hardware directly from their controller.)
198Who: Jean Delvare <khali@linux-fr.org>, 190Who: Jean Delvare <khali@linux-fr.org>,
199 David Brownell <dbrownell@users.sourceforge.net> 191 David Brownell <dbrownell@users.sourceforge.net>
200 192
@@ -307,3 +299,27 @@ Why: Code was merged, then submitter immediately disappeared leaving
307Who: David S. Miller <davem@davemloft.net> 299Who: David S. Miller <davem@davemloft.net>
308 300
309--------------------------- 301---------------------------
302
303What: read_dev_chars(), read_conf_data{,_lpm}() (s390 common I/O layer)
304When: December 2007
305Why: These functions are a leftover from 2.4 times. They have several
306 problems:
307 - Duplication of checks that are done in the device driver's
308 interrupt handler
309 - common I/O layer can't do device specific error recovery
310 - device driver can't be notified for conditions happening during
311 execution of the function
312 Device drivers should issue the read device characteristics and read
313 configuration data ccws and do the appropriate error handling
314 themselves.
315Who: Cornelia Huck <cornelia.huck@de.ibm.com>
316
317---------------------------
318
319What: i2c-ixp2000, i2c-ixp4xx and scx200_i2c drivers
320When: September 2007
321Why: Obsolete. The new i2c-gpio driver replaces all hardware-specific
322 I2C-over-GPIO drivers.
323Who: Jean Delvare <khali@linux-fr.org>
324
325---------------------------
diff --git a/Documentation/i2c/busses/i2c-nforce2 b/Documentation/i2c/busses/i2c-nforce2
index 7f61fbc03f7f..fae3495bcbaf 100644
--- a/Documentation/i2c/busses/i2c-nforce2
+++ b/Documentation/i2c/busses/i2c-nforce2
@@ -9,6 +9,8 @@ Supported adapters:
9 * nForce4 MCP-04 10de:0034 9 * nForce4 MCP-04 10de:0034
10 * nForce4 MCP51 10de:0264 10 * nForce4 MCP51 10de:0264
11 * nForce4 MCP55 10de:0368 11 * nForce4 MCP55 10de:0368
12 * nForce4 MCP61 10de:03EB
13 * nForce4 MCP65 10de:0446
12 14
13Datasheet: not publicly available, but seems to be similar to the 15Datasheet: not publicly available, but seems to be similar to the
14 AMD-8111 SMBus 2.0 adapter. 16 AMD-8111 SMBus 2.0 adapter.
diff --git a/Documentation/i2c/porting-clients b/Documentation/i2c/porting-clients
index ca272b263a92..7bf82c08f6ca 100644
--- a/Documentation/i2c/porting-clients
+++ b/Documentation/i2c/porting-clients
@@ -1,4 +1,4 @@
1Revision 6, 2005-11-20 1Revision 7, 2007-04-19
2Jean Delvare <khali@linux-fr.org> 2Jean Delvare <khali@linux-fr.org>
3Greg KH <greg@kroah.com> 3Greg KH <greg@kroah.com>
4 4
@@ -20,6 +20,10 @@ yours for best results.
20 20
21Technical changes: 21Technical changes:
22 22
23* [Driver type] Any driver that was relying on i2c-isa has to be
24 converted to a proper isa, platform or pci driver. This is not
25 covered by this guide.
26
23* [Includes] Get rid of "version.h" and <linux/i2c-proc.h>. 27* [Includes] Get rid of "version.h" and <linux/i2c-proc.h>.
24 Includes typically look like that: 28 Includes typically look like that:
25 #include <linux/module.h> 29 #include <linux/module.h>
@@ -27,12 +31,10 @@ Technical changes:
27 #include <linux/slab.h> 31 #include <linux/slab.h>
28 #include <linux/jiffies.h> 32 #include <linux/jiffies.h>
29 #include <linux/i2c.h> 33 #include <linux/i2c.h>
30 #include <linux/i2c-isa.h> /* for ISA drivers */
31 #include <linux/hwmon.h> /* for hardware monitoring drivers */ 34 #include <linux/hwmon.h> /* for hardware monitoring drivers */
32 #include <linux/hwmon-sysfs.h> 35 #include <linux/hwmon-sysfs.h>
33 #include <linux/hwmon-vid.h> /* if you need VRM support */ 36 #include <linux/hwmon-vid.h> /* if you need VRM support */
34 #include <linux/err.h> /* for class registration */ 37 #include <linux/err.h> /* for class registration */
35 #include <asm/io.h> /* if you have I/O operations */
36 Please respect this inclusion order. Some extra headers may be 38 Please respect this inclusion order. Some extra headers may be
37 required for a given driver (e.g. "lm75.h"). 39 required for a given driver (e.g. "lm75.h").
38 40
@@ -69,20 +71,16 @@ Technical changes:
69 sensors mailing list <lm-sensors@lm-sensors.org> by providing a 71 sensors mailing list <lm-sensors@lm-sensors.org> by providing a
70 patch to the Documentation/hwmon/sysfs-interface file. 72 patch to the Documentation/hwmon/sysfs-interface file.
71 73
72* [Attach] For I2C drivers, the attach function should make sure 74* [Attach] The attach function should make sure that the adapter's
73 that the adapter's class has I2C_CLASS_HWMON (or whatever class is 75 class has I2C_CLASS_HWMON (or whatever class is suitable for your
74 suitable for your driver), using the following construct: 76 driver), using the following construct:
75 if (!(adapter->class & I2C_CLASS_HWMON)) 77 if (!(adapter->class & I2C_CLASS_HWMON))
76 return 0; 78 return 0;
77 ISA-only drivers of course don't need this.
78 Call i2c_probe() instead of i2c_detect(). 79 Call i2c_probe() instead of i2c_detect().
79 80
80* [Detect] As mentioned earlier, the flags parameter is gone. 81* [Detect] As mentioned earlier, the flags parameter is gone.
81 The type_name and client_name strings are replaced by a single 82 The type_name and client_name strings are replaced by a single
82 name string, which will be filled with a lowercase, short string. 83 name string, which will be filled with a lowercase, short string.
83 In i2c-only drivers, drop the i2c_is_isa_adapter check, it's
84 useless. Same for isa-only drivers, as the test would always be
85 true. Only hybrid drivers (which are quite rare) still need it.
86 The labels used for error paths are reduced to the number needed. 84 The labels used for error paths are reduced to the number needed.
87 It is advised that the labels are given descriptive names such as 85 It is advised that the labels are given descriptive names such as
88 exit and exit_free. Don't forget to properly set err before 86 exit and exit_free. Don't forget to properly set err before
diff --git a/Documentation/i2c/summary b/Documentation/i2c/summary
index 41dde8776791..aea60bf7e8f0 100644
--- a/Documentation/i2c/summary
+++ b/Documentation/i2c/summary
@@ -4,17 +4,23 @@ I2C and SMBus
4============= 4=============
5 5
6I2C (pronounce: I squared C) is a protocol developed by Philips. It is a 6I2C (pronounce: I squared C) is a protocol developed by Philips. It is a
7slow two-wire protocol (10-400 kHz), but it suffices for many types of 7slow two-wire protocol (variable speed, up to 400 kHz), with a high speed
8devices. 8extension (3.4 MHz). It provides an inexpensive bus for connecting many
9types of devices with infrequent or low bandwidth communications needs.
10I2C is widely used with embedded systems. Some systems use variants that
11don't meet branding requirements, and so are not advertised as being I2C.
9 12
10SMBus (System Management Bus) is a subset of the I2C protocol. Many 13SMBus (System Management Bus) is based on the I2C protocol, and is mostly
11modern mainboards have a System Management Bus. There are a lot of 14a subset of I2C protocols and signaling. Many I2C devices will work on an
12devices which can be connected to a SMBus; the most notable are modern 15SMBus, but some SMBus protocols add semantics beyond what is required to
13memory chips with EEPROM memories and chips for hardware monitoring. 16achieve I2C branding. Modern PC mainboards rely on SMBus. The most common
17devices connected through SMBus are RAM modules configured using I2C EEPROMs,
18and hardware monitoring chips.
14 19
15Because the SMBus is just a special case of the generalized I2C bus, we 20Because the SMBus is mostly a subset of the generalized I2C bus, we can
16can simulate the SMBus protocol on plain I2C busses. The reverse is 21use its protocols on many I2C systems. However, there are systems that don't
17regretfully impossible. 22meet both SMBus and I2C electrical constraints; and others which can't
23implement all the common SMBus protocol semantics or messages.
18 24
19 25
20Terminology 26Terminology
@@ -29,6 +35,7 @@ When we talk about I2C, we use the following terms:
29An Algorithm driver contains general code that can be used for a whole class 35An Algorithm driver contains general code that can be used for a whole class
30of I2C adapters. Each specific adapter driver depends on one algorithm 36of I2C adapters. Each specific adapter driver depends on one algorithm
31driver. 37driver.
38
32A Driver driver (yes, this sounds ridiculous, sorry) contains the general 39A Driver driver (yes, this sounds ridiculous, sorry) contains the general
33code to access some type of device. Each detected device gets its own 40code to access some type of device. Each detected device gets its own
34data in the Client structure. Usually, Driver and Client are more closely 41data in the Client structure. Usually, Driver and Client are more closely
@@ -40,6 +47,10 @@ a separate Adapter and Algorithm driver), and drivers for your I2C devices
40in this package. See the lm_sensors project http://www.lm-sensors.nu 47in this package. See the lm_sensors project http://www.lm-sensors.nu
41for device drivers. 48for device drivers.
42 49
50At this time, Linux only operates I2C (or SMBus) in master mode; you can't
51use these APIs to make a Linux system behave as a slave/device, either to
52speak a custom protocol or to emulate some other device.
53
43 54
44Included Bus Drivers 55Included Bus Drivers
45==================== 56====================
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index fbcff96f4ca1..3d8d36b0ad12 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -1,5 +1,5 @@
1This is a small guide for those who want to write kernel drivers for I2C 1This is a small guide for those who want to write kernel drivers for I2C
2or SMBus devices. 2or SMBus devices, using Linux as the protocol host/master (not slave).
3 3
4To set up a driver, you need to do several things. Some are optional, and 4To set up a driver, you need to do several things. Some are optional, and
5some things can be done slightly or completely different. Use this as a 5some things can be done slightly or completely different. Use this as a
@@ -29,8 +29,16 @@ static struct i2c_driver foo_driver = {
29 .driver = { 29 .driver = {
30 .name = "foo", 30 .name = "foo",
31 }, 31 },
32
33 /* iff driver uses driver model ("new style") binding model: */
34 .probe = foo_probe,
35 .remove = foo_remove,
36
37 /* else, driver uses "legacy" binding model: */
32 .attach_adapter = foo_attach_adapter, 38 .attach_adapter = foo_attach_adapter,
33 .detach_client = foo_detach_client, 39 .detach_client = foo_detach_client,
40
41 /* these may be used regardless of the driver binding model */
34 .shutdown = foo_shutdown, /* optional */ 42 .shutdown = foo_shutdown, /* optional */
35 .suspend = foo_suspend, /* optional */ 43 .suspend = foo_suspend, /* optional */
36 .resume = foo_resume, /* optional */ 44 .resume = foo_resume, /* optional */
@@ -40,7 +48,8 @@ static struct i2c_driver foo_driver = {
40The name field is the driver name, and must not contain spaces. It 48The name field is the driver name, and must not contain spaces. It
41should match the module name (if the driver can be compiled as a module), 49should match the module name (if the driver can be compiled as a module),
42although you can use MODULE_ALIAS (passing "foo" in this example) to add 50although you can use MODULE_ALIAS (passing "foo" in this example) to add
43another name for the module. 51another name for the module. If the driver name doesn't match the module
52name, the module won't be automatically loaded (hotplug/coldplug).
44 53
45All other fields are for call-back functions which will be explained 54All other fields are for call-back functions which will be explained
46below. 55below.
@@ -65,16 +74,13 @@ An example structure is below.
65 74
66 struct foo_data { 75 struct foo_data {
67 struct i2c_client client; 76 struct i2c_client client;
68 struct semaphore lock; /* For ISA access in `sensors' drivers. */
69 int sysctl_id; /* To keep the /proc directory entry for
70 `sensors' drivers. */
71 enum chips type; /* To keep the chips type for `sensors' drivers. */ 77 enum chips type; /* To keep the chips type for `sensors' drivers. */
72 78
73 /* Because the i2c bus is slow, it is often useful to cache the read 79 /* Because the i2c bus is slow, it is often useful to cache the read
74 information of a chip for some time (for example, 1 or 2 seconds). 80 information of a chip for some time (for example, 1 or 2 seconds).
75 It depends of course on the device whether this is really worthwhile 81 It depends of course on the device whether this is really worthwhile
76 or even sensible. */ 82 or even sensible. */
77 struct semaphore update_lock; /* When we are reading lots of information, 83 struct mutex update_lock; /* When we are reading lots of information,
78 another process should not update the 84 another process should not update the
79 below information */ 85 below information */
80 char valid; /* != 0 if the following fields are valid. */ 86 char valid; /* != 0 if the following fields are valid. */
@@ -95,8 +101,7 @@ some obscure clients). But we need generic reading and writing routines.
95I have found it useful to define foo_read and foo_write function for this. 101I have found it useful to define foo_read and foo_write function for this.
96For some cases, it will be easier to call the i2c functions directly, 102For some cases, it will be easier to call the i2c functions directly,
97but many chips have some kind of register-value idea that can easily 103but many chips have some kind of register-value idea that can easily
98be encapsulated. Also, some chips have both ISA and I2C interfaces, and 104be encapsulated.
99it useful to abstract from this (only for `sensors' drivers).
100 105
101The below functions are simple examples, and should not be copied 106The below functions are simple examples, and should not be copied
102literally. 107literally.
@@ -119,28 +124,101 @@ literally.
119 return i2c_smbus_write_word_data(client,reg,value); 124 return i2c_smbus_write_word_data(client,reg,value);
120 } 125 }
121 126
122For sensors code, you may have to cope with ISA registers too. Something
123like the below often works. Note the locking!
124
125 int foo_read_value(struct i2c_client *client, u8 reg)
126 {
127 int res;
128 if (i2c_is_isa_client(client)) {
129 down(&(((struct foo_data *) (client->data)) -> lock));
130 outb_p(reg,client->addr + FOO_ADDR_REG_OFFSET);
131 res = inb_p(client->addr + FOO_DATA_REG_OFFSET);
132 up(&(((struct foo_data *) (client->data)) -> lock));
133 return res;
134 } else
135 return i2c_smbus_read_byte_data(client,reg);
136 }
137
138Writing is done the same way.
139
140 127
141Probing and attaching 128Probing and attaching
142===================== 129=====================
143 130
131The Linux I2C stack was originally written to support access to hardware
132monitoring chips on PC motherboards, and thus it embeds some assumptions
133that are more appropriate to SMBus (and PCs) than to I2C. One of these
134assumptions is that most adapters and devices drivers support the SMBUS_QUICK
135protocol to probe device presence. Another is that devices and their drivers
136can be sufficiently configured using only such probe primitives.
137
138As Linux and its I2C stack became more widely used in embedded systems
139and complex components such as DVB adapters, those assumptions became more
140problematic. Drivers for I2C devices that issue interrupts need more (and
141different) configuration information, as do drivers handling chip variants
142that can't be distinguished by protocol probing, or which need some board
143specific information to operate correctly.
144
145Accordingly, the I2C stack now has two models for associating I2C devices
146with their drivers: the original "legacy" model, and a newer one that's
147fully compatible with the Linux 2.6 driver model. These models do not mix,
148since the "legacy" model requires drivers to create "i2c_client" device
149objects after SMBus style probing, while the Linux driver model expects
150drivers to be given such device objects in their probe() routines.
151
152
153Standard Driver Model Binding ("New Style")
154-------------------------------------------
155
156System infrastructure, typically board-specific initialization code or
157boot firmware, reports what I2C devices exist. For example, there may be
158a table, in the kernel or from the boot loader, identifying I2C devices
159and linking them to board-specific configuration information about IRQs
160and other wiring artifacts, chip type, and so on. That could be used to
161create i2c_client objects for each I2C device.
162
163I2C device drivers using this binding model work just like any other
164kind of driver in Linux: they provide a probe() method to bind to
165those devices, and a remove() method to unbind.
166
167 static int foo_probe(struct i2c_client *client);
168 static int foo_remove(struct i2c_client *client);
169
170Remember that the i2c_driver does not create those client handles. The
171handle may be used during foo_probe(). If foo_probe() reports success
172(zero not a negative status code) it may save the handle and use it until
173foo_remove() returns. That binding model is used by most Linux drivers.
174
175Drivers match devices when i2c_client.driver_name and the driver name are
176the same; this approach is used in several other busses that don't have
177device typing support in the hardware. The driver and module name should
178match, so hotplug/coldplug mechanisms will modprobe the driver.
179
180
181Device Creation (Standard driver model)
182---------------------------------------
183
184If you know for a fact that an I2C device is connected to a given I2C bus,
185you can instantiate that device by simply filling an i2c_board_info
186structure with the device address and driver name, and calling
187i2c_new_device(). This will create the device, then the driver core will
188take care of finding the right driver and will call its probe() method.
189If a driver supports different device types, you can specify the type you
190want using the type field. You can also specify an IRQ and platform data
191if needed.
192
193Sometimes you know that a device is connected to a given I2C bus, but you
194don't know the exact address it uses. This happens on TV adapters for
195example, where the same driver supports dozens of slightly different
196models, and I2C device addresses change from one model to the next. In
197that case, you can use the i2c_new_probed_device() variant, which is
198similar to i2c_new_device(), except that it takes an additional list of
199possible I2C addresses to probe. A device is created for the first
200responsive address in the list. If you expect more than one device to be
201present in the address range, simply call i2c_new_probed_device() that
202many times.
203
204The call to i2c_new_device() or i2c_new_probed_device() typically happens
205in the I2C bus driver. You may want to save the returned i2c_client
206reference for later use.
207
208
209Device Deletion (Standard driver model)
210---------------------------------------
211
212Each I2C device which has been created using i2c_new_device() or
213i2c_new_probed_device() can be unregistered by calling
214i2c_unregister_device(). If you don't call it explicitly, it will be
215called automatically before the underlying I2C bus itself is removed, as a
216device can't survive its parent in the device driver model.
217
218
219Legacy Driver Binding Model
220---------------------------
221
144Most i2c devices can be present on several i2c addresses; for some this 222Most i2c devices can be present on several i2c addresses; for some this
145is determined in hardware (by soldering some chip pins to Vcc or Ground), 223is determined in hardware (by soldering some chip pins to Vcc or Ground),
146for others this can be changed in software (by writing to specific client 224for others this can be changed in software (by writing to specific client
@@ -157,13 +235,9 @@ detection algorithm.
157You do not have to use this parameter interface; but don't try to use 235You do not have to use this parameter interface; but don't try to use
158function i2c_probe() if you don't. 236function i2c_probe() if you don't.
159 237
160NOTE: If you want to write a `sensors' driver, the interface is slightly
161 different! See below.
162
163 238
164 239Probing classes (Legacy model)
165Probing classes 240------------------------------
166---------------
167 241
168All parameters are given as lists of unsigned 16-bit integers. Lists are 242All parameters are given as lists of unsigned 16-bit integers. Lists are
169terminated by I2C_CLIENT_END. 243terminated by I2C_CLIENT_END.
@@ -210,8 +284,8 @@ Note that you *have* to call the defined variable `normal_i2c',
210without any prefix! 284without any prefix!
211 285
212 286
213Attaching to an adapter 287Attaching to an adapter (Legacy model)
214----------------------- 288--------------------------------------
215 289
216Whenever a new adapter is inserted, or for all adapters if the driver is 290Whenever a new adapter is inserted, or for all adapters if the driver is
217being registered, the callback attach_adapter() is called. Now is the 291being registered, the callback attach_adapter() is called. Now is the
@@ -237,17 +311,13 @@ them (unless a `force' parameter was used). In addition, addresses that
237are already in use (by some other registered client) are skipped. 311are already in use (by some other registered client) are skipped.
238 312
239 313
240The detect client function 314The detect client function (Legacy model)
241-------------------------- 315-----------------------------------------
242 316
243The detect client function is called by i2c_probe. The `kind' parameter 317The detect client function is called by i2c_probe. The `kind' parameter
244contains -1 for a probed detection, 0 for a forced detection, or a positive 318contains -1 for a probed detection, 0 for a forced detection, or a positive
245number for a forced detection with a chip type forced. 319number for a forced detection with a chip type forced.
246 320
247Below, some things are only needed if this is a `sensors' driver. Those
248parts are between /* SENSORS ONLY START */ and /* SENSORS ONLY END */
249markers.
250
251Returning an error different from -ENODEV in a detect function will cause 321Returning an error different from -ENODEV in a detect function will cause
252the detection to stop: other addresses and adapters won't be scanned. 322the detection to stop: other addresses and adapters won't be scanned.
253This should only be done on fatal or internal errors, such as a memory 323This should only be done on fatal or internal errors, such as a memory
@@ -256,64 +326,20 @@ shortage or i2c_attach_client failing.
256For now, you can ignore the `flags' parameter. It is there for future use. 326For now, you can ignore the `flags' parameter. It is there for future use.
257 327
258 int foo_detect_client(struct i2c_adapter *adapter, int address, 328 int foo_detect_client(struct i2c_adapter *adapter, int address,
259 unsigned short flags, int kind) 329 int kind)
260 { 330 {
261 int err = 0; 331 int err = 0;
262 int i; 332 int i;
263 struct i2c_client *new_client; 333 struct i2c_client *client;
264 struct foo_data *data; 334 struct foo_data *data;
265 const char *client_name = ""; /* For non-`sensors' drivers, put the real 335 const char *name = "";
266 name here! */
267 336
268 /* Let's see whether this adapter can support what we need. 337 /* Let's see whether this adapter can support what we need.
269 Please substitute the things you need here! 338 Please substitute the things you need here! */
270 For `sensors' drivers, add `! is_isa &&' to the if statement */
271 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA | 339 if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WORD_DATA |
272 I2C_FUNC_SMBUS_WRITE_BYTE)) 340 I2C_FUNC_SMBUS_WRITE_BYTE))
273 goto ERROR0; 341 goto ERROR0;
274 342
275 /* SENSORS ONLY START */
276 const char *type_name = "";
277 int is_isa = i2c_is_isa_adapter(adapter);
278
279 /* Do this only if the chip can additionally be found on the ISA bus
280 (hybrid chip). */
281
282 if (is_isa) {
283
284 /* Discard immediately if this ISA range is already used */
285 /* FIXME: never use check_region(), only request_region() */
286 if (check_region(address,FOO_EXTENT))
287 goto ERROR0;
288
289 /* Probe whether there is anything on this address.
290 Some example code is below, but you will have to adapt this
291 for your own driver */
292
293 if (kind < 0) /* Only if no force parameter was used */ {
294 /* We may need long timeouts at least for some chips. */
295 #define REALLY_SLOW_IO
296 i = inb_p(address + 1);
297 if (inb_p(address + 2) != i)
298 goto ERROR0;
299 if (inb_p(address + 3) != i)
300 goto ERROR0;
301 if (inb_p(address + 7) != i)
302 goto ERROR0;
303 #undef REALLY_SLOW_IO
304
305 /* Let's just hope nothing breaks here */
306 i = inb_p(address + 5) & 0x7f;
307 outb_p(~i & 0x7f,address+5);
308 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
309 outb_p(i,address+5);
310 return 0;
311 }
312 }
313 }
314
315 /* SENSORS ONLY END */
316
317 /* OK. For now, we presume we have a valid client. We now create the 343 /* OK. For now, we presume we have a valid client. We now create the
318 client structure, even though we cannot fill it completely yet. 344 client structure, even though we cannot fill it completely yet.
319 But it allows us to access several i2c functions safely */ 345 But it allows us to access several i2c functions safely */
@@ -323,13 +349,12 @@ For now, you can ignore the `flags' parameter. It is there for future use.
323 goto ERROR0; 349 goto ERROR0;
324 } 350 }
325 351
326 new_client = &data->client; 352 client = &data->client;
327 i2c_set_clientdata(new_client, data); 353 i2c_set_clientdata(client, data);
328 354
329 new_client->addr = address; 355 client->addr = address;
330 new_client->adapter = adapter; 356 client->adapter = adapter;
331 new_client->driver = &foo_driver; 357 client->driver = &foo_driver;
332 new_client->flags = 0;
333 358
334 /* Now, we do the remaining detection. If no `force' parameter is used. */ 359 /* Now, we do the remaining detection. If no `force' parameter is used. */
335 360
@@ -337,19 +362,17 @@ For now, you can ignore the `flags' parameter. It is there for future use.
337 parameter was used. */ 362 parameter was used. */
338 if (kind < 0) { 363 if (kind < 0) {
339 /* The below is of course bogus */ 364 /* The below is of course bogus */
340 if (foo_read(new_client,FOO_REG_GENERIC) != FOO_GENERIC_VALUE) 365 if (foo_read(client, FOO_REG_GENERIC) != FOO_GENERIC_VALUE)
341 goto ERROR1; 366 goto ERROR1;
342 } 367 }
343 368
344 /* SENSORS ONLY START */
345
346 /* Next, specific detection. This is especially important for `sensors' 369 /* Next, specific detection. This is especially important for `sensors'
347 devices. */ 370 devices. */
348 371
349 /* Determine the chip type. Not needed if a `force_CHIPTYPE' parameter 372 /* Determine the chip type. Not needed if a `force_CHIPTYPE' parameter
350 was used. */ 373 was used. */
351 if (kind <= 0) { 374 if (kind <= 0) {
352 i = foo_read(new_client,FOO_REG_CHIPTYPE); 375 i = foo_read(client, FOO_REG_CHIPTYPE);
353 if (i == FOO_TYPE_1) 376 if (i == FOO_TYPE_1)
354 kind = chip1; /* As defined in the enum */ 377 kind = chip1; /* As defined in the enum */
355 else if (i == FOO_TYPE_2) 378 else if (i == FOO_TYPE_2)
@@ -363,63 +386,31 @@ For now, you can ignore the `flags' parameter. It is there for future use.
363 386
364 /* Now set the type and chip names */ 387 /* Now set the type and chip names */
365 if (kind == chip1) { 388 if (kind == chip1) {
366 type_name = "chip1"; /* For /proc entry */ 389 name = "chip1";
367 client_name = "CHIP 1";
368 } else if (kind == chip2) { 390 } else if (kind == chip2) {
369 type_name = "chip2"; /* For /proc entry */ 391 name = "chip2";
370 client_name = "CHIP 2";
371 } 392 }
372 393
373 /* Reserve the ISA region */
374 if (is_isa)
375 request_region(address,FOO_EXTENT,type_name);
376
377 /* SENSORS ONLY END */
378
379 /* Fill in the remaining client fields. */ 394 /* Fill in the remaining client fields. */
380 strcpy(new_client->name,client_name); 395 strlcpy(client->name, name, I2C_NAME_SIZE);
381
382 /* SENSORS ONLY BEGIN */
383 data->type = kind; 396 data->type = kind;
384 /* SENSORS ONLY END */ 397 mutex_init(&data->update_lock); /* Only if you use this field */
385
386 data->valid = 0; /* Only if you use this field */
387 init_MUTEX(&data->update_lock); /* Only if you use this field */
388 398
389 /* Any other initializations in data must be done here too. */ 399 /* Any other initializations in data must be done here too. */
390 400
391 /* Tell the i2c layer a new client has arrived */
392 if ((err = i2c_attach_client(new_client)))
393 goto ERROR3;
394
395 /* SENSORS ONLY BEGIN */
396 /* Register a new directory entry with module sensors. See below for
397 the `template' structure. */
398 if ((i = i2c_register_entry(new_client, type_name,
399 foo_dir_table_template,THIS_MODULE)) < 0) {
400 err = i;
401 goto ERROR4;
402 }
403 data->sysctl_id = i;
404
405 /* SENSORS ONLY END */
406
407 /* This function can write default values to the client registers, if 401 /* This function can write default values to the client registers, if
408 needed. */ 402 needed. */
409 foo_init_client(new_client); 403 foo_init_client(client);
404
405 /* Tell the i2c layer a new client has arrived */
406 if ((err = i2c_attach_client(client)))
407 goto ERROR1;
408
410 return 0; 409 return 0;
411 410
412 /* OK, this is not exactly good programming practice, usually. But it is 411 /* OK, this is not exactly good programming practice, usually. But it is
413 very code-efficient in this case. */ 412 very code-efficient in this case. */
414 413
415 ERROR4:
416 i2c_detach_client(new_client);
417 ERROR3:
418 ERROR2:
419 /* SENSORS ONLY START */
420 if (is_isa)
421 release_region(address,FOO_EXTENT);
422 /* SENSORS ONLY END */
423 ERROR1: 414 ERROR1:
424 kfree(data); 415 kfree(data);
425 ERROR0: 416 ERROR0:
@@ -427,8 +418,8 @@ For now, you can ignore the `flags' parameter. It is there for future use.
427 } 418 }
428 419
429 420
430Removing the client 421Removing the client (Legacy model)
431=================== 422==================================
432 423
433The detach_client call back function is called when a client should be 424The detach_client call back function is called when a client should be
434removed. It may actually fail, but only when panicking. This code is 425removed. It may actually fail, but only when panicking. This code is
@@ -436,22 +427,12 @@ much simpler than the attachment code, fortunately!
436 427
437 int foo_detach_client(struct i2c_client *client) 428 int foo_detach_client(struct i2c_client *client)
438 { 429 {
439 int err,i; 430 int err;
440
441 /* SENSORS ONLY START */
442 /* Deregister with the `i2c-proc' module. */
443 i2c_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id);
444 /* SENSORS ONLY END */
445 431
446 /* Try to detach the client from i2c space */ 432 /* Try to detach the client from i2c space */
447 if ((err = i2c_detach_client(client))) 433 if ((err = i2c_detach_client(client)))
448 return err; 434 return err;
449 435
450 /* HYBRID SENSORS CHIP ONLY START */
451 if i2c_is_isa_client(client)
452 release_region(client->addr,LM78_EXTENT);
453 /* HYBRID SENSORS CHIP ONLY END */
454
455 kfree(i2c_get_clientdata(client)); 436 kfree(i2c_get_clientdata(client));
456 return 0; 437 return 0;
457 } 438 }
@@ -464,45 +445,34 @@ When the kernel is booted, or when your foo driver module is inserted,
464you have to do some initializing. Fortunately, just attaching (registering) 445you have to do some initializing. Fortunately, just attaching (registering)
465the driver module is usually enough. 446the driver module is usually enough.
466 447
467 /* Keep track of how far we got in the initialization process. If several
468 things have to initialized, and we fail halfway, only those things
469 have to be cleaned up! */
470 static int __initdata foo_initialized = 0;
471
472 static int __init foo_init(void) 448 static int __init foo_init(void)
473 { 449 {
474 int res; 450 int res;
475 printk("foo version %s (%s)\n",FOO_VERSION,FOO_DATE);
476 451
477 if ((res = i2c_add_driver(&foo_driver))) { 452 if ((res = i2c_add_driver(&foo_driver))) {
478 printk("foo: Driver registration failed, module not inserted.\n"); 453 printk("foo: Driver registration failed, module not inserted.\n");
479 foo_cleanup();
480 return res; 454 return res;
481 } 455 }
482 foo_initialized ++;
483 return 0; 456 return 0;
484 } 457 }
485 458
486 void foo_cleanup(void) 459 static void __exit foo_cleanup(void)
487 { 460 {
488 if (foo_initialized == 1) { 461 i2c_del_driver(&foo_driver);
489 if ((res = i2c_del_driver(&foo_driver))) {
490 printk("foo: Driver registration failed, module not removed.\n");
491 return;
492 }
493 foo_initialized --;
494 }
495 } 462 }
496 463
497 /* Substitute your own name and email address */ 464 /* Substitute your own name and email address */
498 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>" 465 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"
499 MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices"); 466 MODULE_DESCRIPTION("Driver for Barf Inc. Foo I2C devices");
500 467
468 /* a few non-GPL license types are also allowed */
469 MODULE_LICENSE("GPL");
470
501 module_init(foo_init); 471 module_init(foo_init);
502 module_exit(foo_cleanup); 472 module_exit(foo_cleanup);
503 473
504Note that some functions are marked by `__init', and some data structures 474Note that some functions are marked by `__init', and some data structures
505by `__init_data'. Hose functions and structures can be removed after 475by `__initdata'. These functions and structures can be removed after
506kernel booting (or module loading) is completed. 476kernel booting (or module loading) is completed.
507 477
508 478
@@ -632,110 +602,7 @@ General purpose routines
632Below all general purpose routines are listed, that were not mentioned 602Below all general purpose routines are listed, that were not mentioned
633before. 603before.
634 604
635 /* This call returns a unique low identifier for each registered adapter, 605 /* This call returns a unique low identifier for each registered adapter.
636 * or -1 if the adapter was not registered.
637 */ 606 */
638 extern int i2c_adapter_id(struct i2c_adapter *adap); 607 extern int i2c_adapter_id(struct i2c_adapter *adap);
639 608
640
641The sensors sysctl/proc interface
642=================================
643
644This section only applies if you write `sensors' drivers.
645
646Each sensors driver creates a directory in /proc/sys/dev/sensors for each
647registered client. The directory is called something like foo-i2c-4-65.
648The sensors module helps you to do this as easily as possible.
649
650The template
651------------
652
653You will need to define a ctl_table template. This template will automatically
654be copied to a newly allocated structure and filled in where necessary when
655you call sensors_register_entry.
656
657First, I will give an example definition.
658 static ctl_table foo_dir_table_template[] = {
659 { FOO_SYSCTL_FUNC1, "func1", NULL, 0, 0644, NULL, &i2c_proc_real,
660 &i2c_sysctl_real,NULL,&foo_func },
661 { FOO_SYSCTL_FUNC2, "func2", NULL, 0, 0644, NULL, &i2c_proc_real,
662 &i2c_sysctl_real,NULL,&foo_func },
663 { FOO_SYSCTL_DATA, "data", NULL, 0, 0644, NULL, &i2c_proc_real,
664 &i2c_sysctl_real,NULL,&foo_data },
665 { 0 }
666 };
667
668In the above example, three entries are defined. They can either be
669accessed through the /proc interface, in the /proc/sys/dev/sensors/*
670directories, as files named func1, func2 and data, or alternatively
671through the sysctl interface, in the appropriate table, with identifiers
672FOO_SYSCTL_FUNC1, FOO_SYSCTL_FUNC2 and FOO_SYSCTL_DATA.
673
674The third, sixth and ninth parameters should always be NULL, and the
675fourth should always be 0. The fifth is the mode of the /proc file;
6760644 is safe, as the file will be owned by root:root.
677
678The seventh and eighth parameters should be &i2c_proc_real and
679&i2c_sysctl_real if you want to export lists of reals (scaled
680integers). You can also use your own function for them, as usual.
681Finally, the last parameter is the call-back to gather the data
682(see below) if you use the *_proc_real functions.
683
684
685Gathering the data
686------------------
687
688The call back functions (foo_func and foo_data in the above example)
689can be called in several ways; the operation parameter determines
690what should be done:
691
692 * If operation == SENSORS_PROC_REAL_INFO, you must return the
693 magnitude (scaling) in nrels_mag;
694 * If operation == SENSORS_PROC_REAL_READ, you must read information
695 from the chip and return it in results. The number of integers
696 to display should be put in nrels_mag;
697 * If operation == SENSORS_PROC_REAL_WRITE, you must write the
698 supplied information to the chip. nrels_mag will contain the number
699 of integers, results the integers themselves.
700
701The *_proc_real functions will display the elements as reals for the
702/proc interface. If you set the magnitude to 2, and supply 345 for
703SENSORS_PROC_REAL_READ, it would display 3.45; and if the user would
704write 45.6 to the /proc file, it would be returned as 4560 for
705SENSORS_PROC_REAL_WRITE. A magnitude may even be negative!
706
707An example function:
708
709 /* FOO_FROM_REG and FOO_TO_REG translate between scaled values and
710 register values. Note the use of the read cache. */
711 void foo_in(struct i2c_client *client, int operation, int ctl_name,
712 int *nrels_mag, long *results)
713 {
714 struct foo_data *data = client->data;
715 int nr = ctl_name - FOO_SYSCTL_FUNC1; /* reduce to 0 upwards */
716
717 if (operation == SENSORS_PROC_REAL_INFO)
718 *nrels_mag = 2;
719 else if (operation == SENSORS_PROC_REAL_READ) {
720 /* Update the readings cache (if necessary) */
721 foo_update_client(client);
722 /* Get the readings from the cache */
723 results[0] = FOO_FROM_REG(data->foo_func_base[nr]);
724 results[1] = FOO_FROM_REG(data->foo_func_more[nr]);
725 results[2] = FOO_FROM_REG(data->foo_func_readonly[nr]);
726 *nrels_mag = 2;
727 } else if (operation == SENSORS_PROC_REAL_WRITE) {
728 if (*nrels_mag >= 1) {
729 /* Update the cache */
730 data->foo_base[nr] = FOO_TO_REG(results[0]);
731 /* Update the chip */
732 foo_write_value(client,FOO_REG_FUNC_BASE(nr),data->foo_base[nr]);
733 }
734 if (*nrels_mag >= 2) {
735 /* Update the cache */
736 data->foo_more[nr] = FOO_TO_REG(results[1]);
737 /* Update the chip */
738 foo_write_value(client,FOO_REG_FUNC_MORE(nr),data->foo_more[nr]);
739 }
740 }
741 }
diff --git a/Documentation/usb/usb-serial.txt b/Documentation/usb/usb-serial.txt
index d61f6e7865de..b18e86a22506 100644
--- a/Documentation/usb/usb-serial.txt
+++ b/Documentation/usb/usb-serial.txt
@@ -42,7 +42,7 @@ ConnectTech WhiteHEAT 4 port converter
42 http://www.connecttech.com 42 http://www.connecttech.com
43 43
44 For any questions or problems with this driver, please contact 44 For any questions or problems with this driver, please contact
45 Stuart MacDonald at stuartm@connecttech.com 45 Connect Tech's Support Department at support@connecttech.com
46 46
47 47
48HandSpring Visor, Palm USB, and Clié USB driver 48HandSpring Visor, Palm USB, and Clié USB driver
diff --git a/MAINTAINERS b/MAINTAINERS
index af1c7926c153..1e8c37054ea2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -733,6 +733,13 @@ M: tigran@aivazian.fsnet.co.uk
733L: linux-kernel@vger.kernel.org 733L: linux-kernel@vger.kernel.org
734S: Maintained 734S: Maintained
735 735
736BLACKFIN I2C TWI DRIVER
737P: Sonic Zhang
738M: sonic.zhang@analog.com
739L: uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
740W: http://blackfin.uclinux.org/
741S: Supported
742
736BLOCK LAYER 743BLOCK LAYER
737P: Jens Axboe 744P: Jens Axboe
738M: axboe@kernel.dk 745M: axboe@kernel.dk
@@ -1459,6 +1466,11 @@ L: linux-scsi@vger.kernel.org
1459W: http://www.icp-vortex.com/ 1466W: http://www.icp-vortex.com/
1460S: Supported 1467S: Supported
1461 1468
1469GENERIC GPIO I2C DRIVER
1470P: Haavard Skinnemoen
1471M: hskinnemoen@atmel.com
1472S: Supported
1473
1462GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS 1474GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
1463P: Krzysztof Halasa 1475P: Krzysztof Halasa
1464M: khc@pm.waw.pl 1476M: khc@pm.waw.pl
@@ -1631,6 +1643,13 @@ L: i2c@lm-sensors.org
1631T: quilt http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/ 1643T: quilt http://khali.linux-fr.org/devel/linux-2.6/jdelvare-i2c/
1632S: Maintained 1644S: Maintained
1633 1645
1646I2C-TINY-USB DRIVER
1647P: Till Harbaum
1648M: till@harbaum.org
1649L: i2c@lm-sensors.org
1650T: http://www.harbaum.org/till/i2c_tiny_usb
1651S: Maintained
1652
1634i386 BOOT CODE 1653i386 BOOT CODE
1635P: Riley H. Williams 1654P: Riley H. Williams
1636M: Riley@Williams.Name 1655M: Riley@Williams.Name
@@ -3627,8 +3646,8 @@ W: http://www.kroah.com/linux/
3627S: Maintained 3646S: Maintained
3628 3647
3629USB SERIAL WHITEHEAT DRIVER 3648USB SERIAL WHITEHEAT DRIVER
3630P: Stuart MacDonald 3649P: Support Department
3631M: stuartm@connecttech.com 3650M: support@connecttech.com
3632L: linux-usb-users@lists.sourceforge.net 3651L: linux-usb-users@lists.sourceforge.net
3633L: linux-usb-devel@lists.sourceforge.net 3652L: linux-usb-devel@lists.sourceforge.net
3634W: http://www.connecttech.com 3653W: http://www.connecttech.com
diff --git a/arch/i386/kernel/cpu/cpufreq/longhaul.c b/arch/i386/kernel/cpu/cpufreq/longhaul.c
index 2b030d6ccbf7..a3df9c039bd4 100644
--- a/arch/i386/kernel/cpu/cpufreq/longhaul.c
+++ b/arch/i386/kernel/cpu/cpufreq/longhaul.c
@@ -590,20 +590,23 @@ static acpi_status longhaul_walk_callback(acpi_handle obj_handle,
590static int enable_arbiter_disable(void) 590static int enable_arbiter_disable(void)
591{ 591{
592 struct pci_dev *dev; 592 struct pci_dev *dev;
593 int status;
593 int reg; 594 int reg;
594 u8 pci_cmd; 595 u8 pci_cmd;
595 596
597 status = 1;
596 /* Find PLE133 host bridge */ 598 /* Find PLE133 host bridge */
597 reg = 0x78; 599 reg = 0x78;
598 dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, NULL); 600 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0,
601 NULL);
599 /* Find CLE266 host bridge */ 602 /* Find CLE266 host bridge */
600 if (dev == NULL) { 603 if (dev == NULL) {
601 reg = 0x76; 604 reg = 0x76;
602 dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_862X_0, NULL); 605 dev = pci_get_device(PCI_VENDOR_ID_VIA,
606 PCI_DEVICE_ID_VIA_862X_0, NULL);
603 /* Find CN400 V-Link host bridge */ 607 /* Find CN400 V-Link host bridge */
604 if (dev == NULL) 608 if (dev == NULL)
605 dev = pci_find_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); 609 dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL);
606
607 } 610 }
608 if (dev != NULL) { 611 if (dev != NULL) {
609 /* Enable access to port 0x22 */ 612 /* Enable access to port 0x22 */
@@ -615,10 +618,11 @@ static int enable_arbiter_disable(void)
615 if (!(pci_cmd & 1<<7)) { 618 if (!(pci_cmd & 1<<7)) {
616 printk(KERN_ERR PFX 619 printk(KERN_ERR PFX
617 "Can't enable access to port 0x22.\n"); 620 "Can't enable access to port 0x22.\n");
618 return 0; 621 status = 0;
619 } 622 }
620 } 623 }
621 return 1; 624 pci_dev_put(dev);
625 return status;
622 } 626 }
623 return 0; 627 return 0;
624} 628}
@@ -629,7 +633,7 @@ static int longhaul_setup_vt8235(void)
629 u8 pci_cmd; 633 u8 pci_cmd;
630 634
631 /* Find VT8235 southbridge */ 635 /* Find VT8235 southbridge */
632 dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); 636 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL);
633 if (dev != NULL) { 637 if (dev != NULL) {
634 /* Set transition time to max */ 638 /* Set transition time to max */
635 pci_read_config_byte(dev, 0xec, &pci_cmd); 639 pci_read_config_byte(dev, 0xec, &pci_cmd);
@@ -641,6 +645,7 @@ static int longhaul_setup_vt8235(void)
641 pci_read_config_byte(dev, 0xe5, &pci_cmd); 645 pci_read_config_byte(dev, 0xe5, &pci_cmd);
642 pci_cmd |= 1 << 7; 646 pci_cmd |= 1 << 7;
643 pci_write_config_byte(dev, 0xe5, pci_cmd); 647 pci_write_config_byte(dev, 0xe5, pci_cmd);
648 pci_dev_put(dev);
644 return 1; 649 return 1;
645 } 650 }
646 return 0; 651 return 0;
@@ -678,7 +683,7 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
678 sizeof(samuel2_eblcr)); 683 sizeof(samuel2_eblcr));
679 break; 684 break;
680 case 1 ... 15: 685 case 1 ... 15:
681 longhaul_version = TYPE_LONGHAUL_V2; 686 longhaul_version = TYPE_LONGHAUL_V1;
682 if (c->x86_mask < 8) { 687 if (c->x86_mask < 8) {
683 cpu_model = CPU_SAMUEL2; 688 cpu_model = CPU_SAMUEL2;
684 cpuname = "C3 'Samuel 2' [C5B]"; 689 cpuname = "C3 'Samuel 2' [C5B]";
diff --git a/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c b/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
index 4786fedca6eb..4c76b511e194 100644
--- a/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
+++ b/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
@@ -27,7 +27,6 @@
27#include <linux/cpufreq.h> 27#include <linux/cpufreq.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/cpumask.h> 29#include <linux/cpumask.h>
30#include <linux/sched.h> /* current / set_cpus_allowed() */
31 30
32#include <asm/processor.h> 31#include <asm/processor.h>
33#include <asm/msr.h> 32#include <asm/msr.h>
@@ -62,7 +61,7 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
62 if (!cpu_online(cpu) || (newstate > DC_DISABLE) || (newstate == DC_RESV)) 61 if (!cpu_online(cpu) || (newstate > DC_DISABLE) || (newstate == DC_RESV))
63 return -EINVAL; 62 return -EINVAL;
64 63
65 rdmsr(MSR_IA32_THERM_STATUS, l, h); 64 rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h);
66 65
67 if (l & 0x01) 66 if (l & 0x01)
68 dprintk("CPU#%d currently thermal throttled\n", cpu); 67 dprintk("CPU#%d currently thermal throttled\n", cpu);
@@ -70,10 +69,10 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
70 if (has_N44_O17_errata[cpu] && (newstate == DC_25PT || newstate == DC_DFLT)) 69 if (has_N44_O17_errata[cpu] && (newstate == DC_25PT || newstate == DC_DFLT))
71 newstate = DC_38PT; 70 newstate = DC_38PT;
72 71
73 rdmsr(MSR_IA32_THERM_CONTROL, l, h); 72 rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h);
74 if (newstate == DC_DISABLE) { 73 if (newstate == DC_DISABLE) {
75 dprintk("CPU#%d disabling modulation\n", cpu); 74 dprintk("CPU#%d disabling modulation\n", cpu);
76 wrmsr(MSR_IA32_THERM_CONTROL, l & ~(1<<4), h); 75 wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l & ~(1<<4), h);
77 } else { 76 } else {
78 dprintk("CPU#%d setting duty cycle to %d%%\n", 77 dprintk("CPU#%d setting duty cycle to %d%%\n",
79 cpu, ((125 * newstate) / 10)); 78 cpu, ((125 * newstate) / 10));
@@ -84,7 +83,7 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
84 */ 83 */
85 l = (l & ~14); 84 l = (l & ~14);
86 l = l | (1<<4) | ((newstate & 0x7)<<1); 85 l = l | (1<<4) | ((newstate & 0x7)<<1);
87 wrmsr(MSR_IA32_THERM_CONTROL, l, h); 86 wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l, h);
88 } 87 }
89 88
90 return 0; 89 return 0;
@@ -111,7 +110,6 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
111{ 110{
112 unsigned int newstate = DC_RESV; 111 unsigned int newstate = DC_RESV;
113 struct cpufreq_freqs freqs; 112 struct cpufreq_freqs freqs;
114 cpumask_t cpus_allowed;
115 int i; 113 int i;
116 114
117 if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], target_freq, relation, &newstate)) 115 if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], target_freq, relation, &newstate))
@@ -132,17 +130,8 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
132 /* run on each logical CPU, see section 13.15.3 of IA32 Intel Architecture Software 130 /* run on each logical CPU, see section 13.15.3 of IA32 Intel Architecture Software
133 * Developer's Manual, Volume 3 131 * Developer's Manual, Volume 3
134 */ 132 */
135 cpus_allowed = current->cpus_allowed; 133 for_each_cpu_mask(i, policy->cpus)
136
137 for_each_cpu_mask(i, policy->cpus) {
138 cpumask_t this_cpu = cpumask_of_cpu(i);
139
140 set_cpus_allowed(current, this_cpu);
141 BUG_ON(smp_processor_id() != i);
142
143 cpufreq_p4_setdc(i, p4clockmod_table[newstate].index); 134 cpufreq_p4_setdc(i, p4clockmod_table[newstate].index);
144 }
145 set_cpus_allowed(current, cpus_allowed);
146 135
147 /* notifiers */ 136 /* notifiers */
148 for_each_cpu_mask(i, policy->cpus) { 137 for_each_cpu_mask(i, policy->cpus) {
@@ -256,17 +245,9 @@ static int cpufreq_p4_cpu_exit(struct cpufreq_policy *policy)
256 245
257static unsigned int cpufreq_p4_get(unsigned int cpu) 246static unsigned int cpufreq_p4_get(unsigned int cpu)
258{ 247{
259 cpumask_t cpus_allowed;
260 u32 l, h; 248 u32 l, h;
261 249
262 cpus_allowed = current->cpus_allowed; 250 rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h);
263
264 set_cpus_allowed(current, cpumask_of_cpu(cpu));
265 BUG_ON(smp_processor_id() != cpu);
266
267 rdmsr(MSR_IA32_THERM_CONTROL, l, h);
268
269 set_cpus_allowed(current, cpus_allowed);
270 251
271 if (l & 0x10) { 252 if (l & 0x10) {
272 l = l >> 1; 253 l = l >> 1;
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
index fe3b67005ebb..7cf3d207b6b3 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
@@ -661,7 +661,8 @@ static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst,
661 661
662 dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); 662 dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid);
663 data->powernow_table = powernow_table; 663 data->powernow_table = powernow_table;
664 print_basics(data); 664 if (first_cpu(cpu_core_map[data->cpu]) == data->cpu)
665 print_basics(data);
665 666
666 for (j = 0; j < data->numps; j++) 667 for (j = 0; j < data->numps; j++)
667 if ((pst[j].fid==data->currfid) && (pst[j].vid==data->currvid)) 668 if ((pst[j].fid==data->currfid) && (pst[j].vid==data->currvid))
@@ -814,7 +815,8 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
814 815
815 /* fill in data */ 816 /* fill in data */
816 data->numps = data->acpi_data.state_count; 817 data->numps = data->acpi_data.state_count;
817 print_basics(data); 818 if (first_cpu(cpu_core_map[data->cpu]) == data->cpu)
819 print_basics(data);
818 powernow_k8_acpi_pst_values(data, 0); 820 powernow_k8_acpi_pst_values(data, 0);
819 821
820 /* notify BIOS that we exist */ 822 /* notify BIOS that we exist */
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h
index 0fb2a3001ba5..95be5013c984 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h
+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h
@@ -215,8 +215,10 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
215 215
216static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); 216static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
217 217
218#ifdef CONFIG_X86_POWERNOW_K8_ACPI
218static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); 219static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
219static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); 220static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
221#endif
220 222
221#ifdef CONFIG_SMP 223#ifdef CONFIG_SMP
222static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) 224static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
index f43b987f952b..35489fd68852 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
@@ -720,6 +720,7 @@ static int centrino_target (struct cpufreq_policy *policy,
720 cpu_set(j, set_mask); 720 cpu_set(j, set_mask);
721 721
722 set_cpus_allowed(current, set_mask); 722 set_cpus_allowed(current, set_mask);
723 preempt_disable();
723 if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) { 724 if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) {
724 dprintk("couldn't limit to CPUs in this domain\n"); 725 dprintk("couldn't limit to CPUs in this domain\n");
725 retval = -EAGAIN; 726 retval = -EAGAIN;
@@ -727,6 +728,7 @@ static int centrino_target (struct cpufreq_policy *policy,
727 /* We haven't started the transition yet. */ 728 /* We haven't started the transition yet. */
728 goto migrate_end; 729 goto migrate_end;
729 } 730 }
731 preempt_enable();
730 break; 732 break;
731 } 733 }
732 734
@@ -761,10 +763,13 @@ static int centrino_target (struct cpufreq_policy *policy,
761 } 763 }
762 764
763 wrmsr(MSR_IA32_PERF_CTL, oldmsr, h); 765 wrmsr(MSR_IA32_PERF_CTL, oldmsr, h);
764 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) 766 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
767 preempt_enable();
765 break; 768 break;
769 }
766 770
767 cpu_set(j, covered_cpus); 771 cpu_set(j, covered_cpus);
772 preempt_enable();
768 } 773 }
769 774
770 for_each_cpu_mask(k, online_policy_cpus) { 775 for_each_cpu_mask(k, online_policy_cpus) {
@@ -796,8 +801,11 @@ static int centrino_target (struct cpufreq_policy *policy,
796 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 801 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
797 } 802 }
798 } 803 }
804 set_cpus_allowed(current, saved_mask);
805 return 0;
799 806
800migrate_end: 807migrate_end:
808 preempt_enable();
801 set_cpus_allowed(current, saved_mask); 809 set_cpus_allowed(current, saved_mask);
802 return 0; 810 return 0;
803} 811}
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index a8e1e604dfa8..b8536c7c0877 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -409,6 +409,9 @@ config STRAM_PROC
409 help 409 help
410 Say Y here to report ST-RAM usage statistics in /proc/stram. 410 Say Y here to report ST-RAM usage statistics in /proc/stram.
411 411
412config ATARI_KBD_CORE
413 bool
414
412config HEARTBEAT 415config HEARTBEAT
413 bool "Use power LED as a heartbeat" if AMIGA || APOLLO || ATARI || MAC ||Q40 416 bool "Use power LED as a heartbeat" if AMIGA || APOLLO || ATARI || MAC ||Q40
414 default y if !AMIGA && !APOLLO && !ATARI && !MAC && !Q40 && HP300 417 default y if !AMIGA && !APOLLO && !ATARI && !MAC && !Q40 && HP300
diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile
index 34d826d10f1b..c20831a7e1a9 100644
--- a/arch/m68k/Makefile
+++ b/arch/m68k/Makefile
@@ -21,7 +21,7 @@ AS += -m68020
21LDFLAGS := -m m68kelf 21LDFLAGS := -m m68kelf
22ifneq ($(COMPILE_ARCH),$(ARCH)) 22ifneq ($(COMPILE_ARCH),$(ARCH))
23 # prefix for cross-compiling binaries 23 # prefix for cross-compiling binaries
24 CROSS_COMPILE = m68k-linux- 24 CROSS_COMPILE = m68k-linux-gnu-
25endif 25endif
26 26
27ifdef CONFIG_SUN3 27ifdef CONFIG_SUN3
diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 3204f412cad8..35748531327d 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -22,9 +22,7 @@
22#include <linux/vt_kern.h> 22#include <linux/vt_kern.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#ifdef CONFIG_ZORRO
26#include <linux/zorro.h> 25#include <linux/zorro.h>
27#endif
28 26
29#include <asm/bootinfo.h> 27#include <asm/bootinfo.h>
30#include <asm/setup.h> 28#include <asm/setup.h>
@@ -62,55 +60,51 @@ static char s_cdtv[] __initdata = "CDTV";
62static char s_cd32[] __initdata = "CD32"; 60static char s_cd32[] __initdata = "CD32";
63static char s_draco[] __initdata = "Draco"; 61static char s_draco[] __initdata = "Draco";
64static char *amiga_models[] __initdata = { 62static char *amiga_models[] __initdata = {
65 [AMI_500-AMI_500] = s_a500, 63 [AMI_500-AMI_500] = s_a500,
66 [AMI_500PLUS-AMI_500] = s_a500p, 64 [AMI_500PLUS-AMI_500] = s_a500p,
67 [AMI_600-AMI_500] = s_a600, 65 [AMI_600-AMI_500] = s_a600,
68 [AMI_1000-AMI_500] = s_a1000, 66 [AMI_1000-AMI_500] = s_a1000,
69 [AMI_1200-AMI_500] = s_a1200, 67 [AMI_1200-AMI_500] = s_a1200,
70 [AMI_2000-AMI_500] = s_a2000, 68 [AMI_2000-AMI_500] = s_a2000,
71 [AMI_2500-AMI_500] = s_a2500, 69 [AMI_2500-AMI_500] = s_a2500,
72 [AMI_3000-AMI_500] = s_a3000, 70 [AMI_3000-AMI_500] = s_a3000,
73 [AMI_3000T-AMI_500] = s_a3000t, 71 [AMI_3000T-AMI_500] = s_a3000t,
74 [AMI_3000PLUS-AMI_500] = s_a3000p, 72 [AMI_3000PLUS-AMI_500] = s_a3000p,
75 [AMI_4000-AMI_500] = s_a4000, 73 [AMI_4000-AMI_500] = s_a4000,
76 [AMI_4000T-AMI_500] = s_a4000t, 74 [AMI_4000T-AMI_500] = s_a4000t,
77 [AMI_CDTV-AMI_500] = s_cdtv, 75 [AMI_CDTV-AMI_500] = s_cdtv,
78 [AMI_CD32-AMI_500] = s_cd32, 76 [AMI_CD32-AMI_500] = s_cd32,
79 [AMI_DRACO-AMI_500] = s_draco, 77 [AMI_DRACO-AMI_500] = s_draco,
80}; 78};
81 79
82static char amiga_model_name[13] = "Amiga "; 80static char amiga_model_name[13] = "Amiga ";
83 81
84extern char m68k_debug_device[];
85
86static void amiga_sched_init(irq_handler_t handler); 82static void amiga_sched_init(irq_handler_t handler);
87/* amiga specific irq functions */ 83/* amiga specific irq functions */
88extern void amiga_init_IRQ (void); 84extern void amiga_init_IRQ(void);
89static void amiga_get_model(char *model); 85static void amiga_get_model(char *model);
90static int amiga_get_hardware_list(char *buffer); 86static int amiga_get_hardware_list(char *buffer);
91/* amiga specific timer functions */ 87/* amiga specific timer functions */
92static unsigned long amiga_gettimeoffset (void); 88static unsigned long amiga_gettimeoffset(void);
93static int a3000_hwclk (int, struct rtc_time *); 89static int a3000_hwclk(int, struct rtc_time *);
94static int a2000_hwclk (int, struct rtc_time *); 90static int a2000_hwclk(int, struct rtc_time *);
95static int amiga_set_clock_mmss (unsigned long); 91static int amiga_set_clock_mmss(unsigned long);
96static unsigned int amiga_get_ss (void); 92static unsigned int amiga_get_ss(void);
97extern void amiga_mksound( unsigned int count, unsigned int ticks ); 93extern void amiga_mksound(unsigned int count, unsigned int ticks);
98static void amiga_reset (void); 94static void amiga_reset(void);
99extern void amiga_init_sound(void); 95extern void amiga_init_sound(void);
100static void amiga_savekmsg_init(void);
101static void amiga_mem_console_write(struct console *co, const char *b, 96static void amiga_mem_console_write(struct console *co, const char *b,
102 unsigned int count); 97 unsigned int count);
103void amiga_serial_console_write(struct console *co, const char *s, 98void amiga_serial_console_write(struct console *co, const char *s,
104 unsigned int count); 99 unsigned int count);
105static void amiga_debug_init(void);
106#ifdef CONFIG_HEARTBEAT 100#ifdef CONFIG_HEARTBEAT
107static void amiga_heartbeat(int on); 101static void amiga_heartbeat(int on);
108#endif 102#endif
109 103
110static struct console amiga_console_driver = { 104static struct console amiga_console_driver = {
111 .name = "debug", 105 .name = "debug",
112 .flags = CON_PRINTBUFFER, 106 .flags = CON_PRINTBUFFER,
113 .index = -1, 107 .index = -1,
114}; 108};
115 109
116 110
@@ -119,24 +113,24 @@ static struct console amiga_console_driver = {
119 */ 113 */
120 114
121static struct { 115static struct {
122 struct resource _ciab, _ciaa, _custom, _kickstart; 116 struct resource _ciab, _ciaa, _custom, _kickstart;
123} mb_resources = { 117} mb_resources = {
124 ._ciab = { 118 ._ciab = {
125 .name = "CIA B", .start = 0x00bfd000, .end = 0x00bfdfff 119 .name = "CIA B", .start = 0x00bfd000, .end = 0x00bfdfff
126 }, 120 },
127 ._ciaa = { 121 ._ciaa = {
128 .name = "CIA A", .start = 0x00bfe000, .end = 0x00bfefff 122 .name = "CIA A", .start = 0x00bfe000, .end = 0x00bfefff
129 }, 123 },
130 ._custom = { 124 ._custom = {
131 .name = "Custom I/O", .start = 0x00dff000, .end = 0x00dfffff 125 .name = "Custom I/O", .start = 0x00dff000, .end = 0x00dfffff
132 }, 126 },
133 ._kickstart = { 127 ._kickstart = {
134 .name = "Kickstart ROM", .start = 0x00f80000, .end = 0x00ffffff 128 .name = "Kickstart ROM", .start = 0x00f80000, .end = 0x00ffffff
135 } 129 }
136}; 130};
137 131
138static struct resource rtc_resource = { 132static struct resource rtc_resource = {
139 .start = 0x00dc0000, .end = 0x00dcffff 133 .start = 0x00dc0000, .end = 0x00dcffff
140}; 134};
141 135
142static struct resource ram_resource[NUM_MEMINFO]; 136static struct resource ram_resource[NUM_MEMINFO];
@@ -148,57 +142,57 @@ static struct resource ram_resource[NUM_MEMINFO];
148 142
149int amiga_parse_bootinfo(const struct bi_record *record) 143int amiga_parse_bootinfo(const struct bi_record *record)
150{ 144{
151 int unknown = 0; 145 int unknown = 0;
152 const unsigned long *data = record->data; 146 const unsigned long *data = record->data;
153 147
154 switch (record->tag) { 148 switch (record->tag) {
155 case BI_AMIGA_MODEL: 149 case BI_AMIGA_MODEL:
156 amiga_model = *data; 150 amiga_model = *data;
157 break; 151 break;
158 152
159 case BI_AMIGA_ECLOCK: 153 case BI_AMIGA_ECLOCK:
160 amiga_eclock = *data; 154 amiga_eclock = *data;
161 break; 155 break;
162 156
163 case BI_AMIGA_CHIPSET: 157 case BI_AMIGA_CHIPSET:
164 amiga_chipset = *data; 158 amiga_chipset = *data;
165 break; 159 break;
166 160
167 case BI_AMIGA_CHIP_SIZE: 161 case BI_AMIGA_CHIP_SIZE:
168 amiga_chip_size = *(const int *)data; 162 amiga_chip_size = *(const int *)data;
169 break; 163 break;
170 164
171 case BI_AMIGA_VBLANK: 165 case BI_AMIGA_VBLANK:
172 amiga_vblank = *(const unsigned char *)data; 166 amiga_vblank = *(const unsigned char *)data;
173 break; 167 break;
174 168
175 case BI_AMIGA_PSFREQ: 169 case BI_AMIGA_PSFREQ:
176 amiga_psfreq = *(const unsigned char *)data; 170 amiga_psfreq = *(const unsigned char *)data;
177 break; 171 break;
178 172
179 case BI_AMIGA_AUTOCON: 173 case BI_AMIGA_AUTOCON:
180#ifdef CONFIG_ZORRO 174#ifdef CONFIG_ZORRO
181 if (zorro_num_autocon < ZORRO_NUM_AUTO) { 175 if (zorro_num_autocon < ZORRO_NUM_AUTO) {
182 const struct ConfigDev *cd = (struct ConfigDev *)data; 176 const struct ConfigDev *cd = (struct ConfigDev *)data;
183 struct zorro_dev *dev = &zorro_autocon[zorro_num_autocon++]; 177 struct zorro_dev *dev = &zorro_autocon[zorro_num_autocon++];
184 dev->rom = cd->cd_Rom; 178 dev->rom = cd->cd_Rom;
185 dev->slotaddr = cd->cd_SlotAddr; 179 dev->slotaddr = cd->cd_SlotAddr;
186 dev->slotsize = cd->cd_SlotSize; 180 dev->slotsize = cd->cd_SlotSize;
187 dev->resource.start = (unsigned long)cd->cd_BoardAddr; 181 dev->resource.start = (unsigned long)cd->cd_BoardAddr;
188 dev->resource.end = dev->resource.start+cd->cd_BoardSize-1; 182 dev->resource.end = dev->resource.start + cd->cd_BoardSize - 1;
189 } else 183 } else
190 printk("amiga_parse_bootinfo: too many AutoConfig devices\n"); 184 printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
191#endif /* CONFIG_ZORRO */ 185#endif /* CONFIG_ZORRO */
192 break; 186 break;
193 187
194 case BI_AMIGA_SERPER: 188 case BI_AMIGA_SERPER:
195 /* serial port period: ignored here */ 189 /* serial port period: ignored here */
196 break; 190 break;
197 191
198 default: 192 default:
199 unknown = 1; 193 unknown = 1;
200 } 194 }
201 return(unknown); 195 return unknown;
202} 196}
203 197
204 /* 198 /*
@@ -207,159 +201,159 @@ int amiga_parse_bootinfo(const struct bi_record *record)
207 201
208static void __init amiga_identify(void) 202static void __init amiga_identify(void)
209{ 203{
210 /* Fill in some default values, if necessary */ 204 /* Fill in some default values, if necessary */
211 if (amiga_eclock == 0) 205 if (amiga_eclock == 0)
212 amiga_eclock = 709379; 206 amiga_eclock = 709379;
213
214 memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));
215
216 printk("Amiga hardware found: ");
217 if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
218 printk("[%s] ", amiga_models[amiga_model-AMI_500]);
219 strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
220 }
221
222 switch(amiga_model) {
223 case AMI_UNKNOWN:
224 goto Generic;
225
226 case AMI_600:
227 case AMI_1200:
228 AMIGAHW_SET(A1200_IDE);
229 AMIGAHW_SET(PCMCIA);
230 case AMI_500:
231 case AMI_500PLUS:
232 case AMI_1000:
233 case AMI_2000:
234 case AMI_2500:
235 AMIGAHW_SET(A2000_CLK); /* Is this correct for all models? */
236 goto Generic;
237
238 case AMI_3000:
239 case AMI_3000T:
240 AMIGAHW_SET(AMBER_FF);
241 AMIGAHW_SET(MAGIC_REKICK);
242 /* fall through */
243 case AMI_3000PLUS:
244 AMIGAHW_SET(A3000_SCSI);
245 AMIGAHW_SET(A3000_CLK);
246 AMIGAHW_SET(ZORRO3);
247 goto Generic;
248
249 case AMI_4000T:
250 AMIGAHW_SET(A4000_SCSI);
251 /* fall through */
252 case AMI_4000:
253 AMIGAHW_SET(A4000_IDE);
254 AMIGAHW_SET(A3000_CLK);
255 AMIGAHW_SET(ZORRO3);
256 goto Generic;
257
258 case AMI_CDTV:
259 case AMI_CD32:
260 AMIGAHW_SET(CD_ROM);
261 AMIGAHW_SET(A2000_CLK); /* Is this correct? */
262 goto Generic;
263
264 Generic:
265 AMIGAHW_SET(AMI_VIDEO);
266 AMIGAHW_SET(AMI_BLITTER);
267 AMIGAHW_SET(AMI_AUDIO);
268 AMIGAHW_SET(AMI_FLOPPY);
269 AMIGAHW_SET(AMI_KEYBOARD);
270 AMIGAHW_SET(AMI_MOUSE);
271 AMIGAHW_SET(AMI_SERIAL);
272 AMIGAHW_SET(AMI_PARALLEL);
273 AMIGAHW_SET(CHIP_RAM);
274 AMIGAHW_SET(PAULA);
275
276 switch(amiga_chipset) {
277 case CS_OCS:
278 case CS_ECS:
279 case CS_AGA:
280 switch (amiga_custom.deniseid & 0xf) {
281 case 0x0c:
282 AMIGAHW_SET(DENISE_HR);
283 break;
284 case 0x08:
285 AMIGAHW_SET(LISA);
286 break;
287 }
288 break;
289 default:
290 AMIGAHW_SET(DENISE);
291 break;
292 }
293 switch ((amiga_custom.vposr>>8) & 0x7f) {
294 case 0x00:
295 AMIGAHW_SET(AGNUS_PAL);
296 break;
297 case 0x10:
298 AMIGAHW_SET(AGNUS_NTSC);
299 break;
300 case 0x20:
301 case 0x21:
302 AMIGAHW_SET(AGNUS_HR_PAL);
303 break;
304 case 0x30:
305 case 0x31:
306 AMIGAHW_SET(AGNUS_HR_NTSC);
307 break;
308 case 0x22:
309 case 0x23:
310 AMIGAHW_SET(ALICE_PAL);
311 break;
312 case 0x32:
313 case 0x33:
314 AMIGAHW_SET(ALICE_NTSC);
315 break;
316 }
317 AMIGAHW_SET(ZORRO);
318 break;
319
320 case AMI_DRACO:
321 panic("No support for Draco yet");
322
323 default:
324 panic("Unknown Amiga Model");
325 }
326 207
327#define AMIGAHW_ANNOUNCE(name, str) \ 208 memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));
328 if (AMIGAHW_PRESENT(name)) \ 209
329 printk(str) 210 printk("Amiga hardware found: ");
330 211 if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
331 AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO "); 212 printk("[%s] ", amiga_models[amiga_model-AMI_500]);
332 AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER "); 213 strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
333 AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF "); 214 }
334 AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO "); 215
335 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY "); 216 switch (amiga_model) {
336 AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI "); 217 case AMI_UNKNOWN:
337 AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI "); 218 goto Generic;
338 AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE "); 219
339 AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE "); 220 case AMI_600:
340 AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM "); 221 case AMI_1200:
341 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD "); 222 AMIGAHW_SET(A1200_IDE);
342 AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE "); 223 AMIGAHW_SET(PCMCIA);
343 AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL "); 224 case AMI_500:
344 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL "); 225 case AMI_500PLUS:
345 AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK "); 226 case AMI_1000:
346 AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK "); 227 case AMI_2000:
347 AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM "); 228 case AMI_2500:
348 AMIGAHW_ANNOUNCE(PAULA, "PAULA "); 229 AMIGAHW_SET(A2000_CLK); /* Is this correct for all models? */
349 AMIGAHW_ANNOUNCE(DENISE, "DENISE "); 230 goto Generic;
350 AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR "); 231
351 AMIGAHW_ANNOUNCE(LISA, "LISA "); 232 case AMI_3000:
352 AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL "); 233 case AMI_3000T:
353 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC "); 234 AMIGAHW_SET(AMBER_FF);
354 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL "); 235 AMIGAHW_SET(MAGIC_REKICK);
355 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC "); 236 /* fall through */
356 AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL "); 237 case AMI_3000PLUS:
357 AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC "); 238 AMIGAHW_SET(A3000_SCSI);
358 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK "); 239 AMIGAHW_SET(A3000_CLK);
359 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA "); 240 AMIGAHW_SET(ZORRO3);
360 if (AMIGAHW_PRESENT(ZORRO)) 241 goto Generic;
361 printk("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : ""); 242
362 printk("\n"); 243 case AMI_4000T:
244 AMIGAHW_SET(A4000_SCSI);
245 /* fall through */
246 case AMI_4000:
247 AMIGAHW_SET(A4000_IDE);
248 AMIGAHW_SET(A3000_CLK);
249 AMIGAHW_SET(ZORRO3);
250 goto Generic;
251
252 case AMI_CDTV:
253 case AMI_CD32:
254 AMIGAHW_SET(CD_ROM);
255 AMIGAHW_SET(A2000_CLK); /* Is this correct? */
256 goto Generic;
257
258 Generic:
259 AMIGAHW_SET(AMI_VIDEO);
260 AMIGAHW_SET(AMI_BLITTER);
261 AMIGAHW_SET(AMI_AUDIO);
262 AMIGAHW_SET(AMI_FLOPPY);
263 AMIGAHW_SET(AMI_KEYBOARD);
264 AMIGAHW_SET(AMI_MOUSE);
265 AMIGAHW_SET(AMI_SERIAL);
266 AMIGAHW_SET(AMI_PARALLEL);
267 AMIGAHW_SET(CHIP_RAM);
268 AMIGAHW_SET(PAULA);
269
270 switch (amiga_chipset) {
271 case CS_OCS:
272 case CS_ECS:
273 case CS_AGA:
274 switch (amiga_custom.deniseid & 0xf) {
275 case 0x0c:
276 AMIGAHW_SET(DENISE_HR);
277 break;
278 case 0x08:
279 AMIGAHW_SET(LISA);
280 break;
281 }
282 break;
283 default:
284 AMIGAHW_SET(DENISE);
285 break;
286 }
287 switch ((amiga_custom.vposr>>8) & 0x7f) {
288 case 0x00:
289 AMIGAHW_SET(AGNUS_PAL);
290 break;
291 case 0x10:
292 AMIGAHW_SET(AGNUS_NTSC);
293 break;
294 case 0x20:
295 case 0x21:
296 AMIGAHW_SET(AGNUS_HR_PAL);
297 break;
298 case 0x30:
299 case 0x31:
300 AMIGAHW_SET(AGNUS_HR_NTSC);
301 break;
302 case 0x22:
303 case 0x23:
304 AMIGAHW_SET(ALICE_PAL);
305 break;
306 case 0x32:
307 case 0x33:
308 AMIGAHW_SET(ALICE_NTSC);
309 break;
310 }
311 AMIGAHW_SET(ZORRO);
312 break;
313
314 case AMI_DRACO:
315 panic("No support for Draco yet");
316
317 default:
318 panic("Unknown Amiga Model");
319 }
320
321#define AMIGAHW_ANNOUNCE(name, str) \
322 if (AMIGAHW_PRESENT(name)) \
323 printk(str)
324
325 AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO ");
326 AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER ");
327 AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF ");
328 AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO ");
329 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY ");
330 AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI ");
331 AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI ");
332 AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE ");
333 AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE ");
334 AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM ");
335 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD ");
336 AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE ");
337 AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL ");
338 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL ");
339 AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK ");
340 AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK ");
341 AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM ");
342 AMIGAHW_ANNOUNCE(PAULA, "PAULA ");
343 AMIGAHW_ANNOUNCE(DENISE, "DENISE ");
344 AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR ");
345 AMIGAHW_ANNOUNCE(LISA, "LISA ");
346 AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL ");
347 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC ");
348 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL ");
349 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC ");
350 AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL ");
351 AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC ");
352 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK ");
353 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA ");
354 if (AMIGAHW_PRESENT(ZORRO))
355 printk("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : "");
356 printk("\n");
363 357
364#undef AMIGAHW_ANNOUNCE 358#undef AMIGAHW_ANNOUNCE
365} 359}
@@ -370,119 +364,105 @@ static void __init amiga_identify(void)
370 364
371void __init config_amiga(void) 365void __init config_amiga(void)
372{ 366{
373 int i; 367 int i;
374 368
375 amiga_debug_init(); 369 amiga_identify();
376 amiga_identify(); 370
377 371 /* Yuk, we don't have PCI memory */
378 /* Yuk, we don't have PCI memory */ 372 iomem_resource.name = "Memory";
379 iomem_resource.name = "Memory"; 373 for (i = 0; i < 4; i++)
380 for (i = 0; i < 4; i++) 374 request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);
381 request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]); 375
382 376 mach_sched_init = amiga_sched_init;
383 mach_sched_init = amiga_sched_init; 377 mach_init_IRQ = amiga_init_IRQ;
384 mach_init_IRQ = amiga_init_IRQ; 378 mach_get_model = amiga_get_model;
385 mach_get_model = amiga_get_model; 379 mach_get_hardware_list = amiga_get_hardware_list;
386 mach_get_hardware_list = amiga_get_hardware_list; 380 mach_gettimeoffset = amiga_gettimeoffset;
387 mach_gettimeoffset = amiga_gettimeoffset; 381 if (AMIGAHW_PRESENT(A3000_CLK)) {
388 if (AMIGAHW_PRESENT(A3000_CLK)){ 382 mach_hwclk = a3000_hwclk;
389 mach_hwclk = a3000_hwclk; 383 rtc_resource.name = "A3000 RTC";
390 rtc_resource.name = "A3000 RTC"; 384 request_resource(&iomem_resource, &rtc_resource);
391 request_resource(&iomem_resource, &rtc_resource); 385 } else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
392 } 386 mach_hwclk = a2000_hwclk;
393 else{ /* if (AMIGAHW_PRESENT(A2000_CLK)) */ 387 rtc_resource.name = "A2000 RTC";
394 mach_hwclk = a2000_hwclk; 388 request_resource(&iomem_resource, &rtc_resource);
395 rtc_resource.name = "A2000 RTC"; 389 }
396 request_resource(&iomem_resource, &rtc_resource); 390
397 } 391 /*
398 392 * default MAX_DMA=0xffffffff on all machines. If we don't do so, the SCSI
399 mach_max_dma_address = 0xffffffff; /* 393 * code will not be able to allocate any mem for transfers, unless we are
400 * default MAX_DMA=0xffffffff 394 * dealing with a Z2 mem only system. /Jes
401 * on all machines. If we don't 395 */
402 * do so, the SCSI code will not 396 mach_max_dma_address = 0xffffffff;
403 * be able to allocate any mem 397
404 * for transfers, unless we are 398 mach_set_clock_mmss = amiga_set_clock_mmss;
405 * dealing with a Z2 mem only 399 mach_get_ss = amiga_get_ss;
406 * system. /Jes 400 mach_reset = amiga_reset;
407 */
408
409 mach_set_clock_mmss = amiga_set_clock_mmss;
410 mach_get_ss = amiga_get_ss;
411 mach_reset = amiga_reset;
412#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE) 401#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
413 mach_beep = amiga_mksound; 402 mach_beep = amiga_mksound;
414#endif 403#endif
415 404
416#ifdef CONFIG_HEARTBEAT 405#ifdef CONFIG_HEARTBEAT
417 mach_heartbeat = amiga_heartbeat; 406 mach_heartbeat = amiga_heartbeat;
418#endif 407#endif
419 408
420 /* Fill in the clock values (based on the 700 kHz E-Clock) */ 409 /* Fill in the clock values (based on the 700 kHz E-Clock) */
421 amiga_masterclock = 40*amiga_eclock; /* 28 MHz */ 410 amiga_masterclock = 40*amiga_eclock; /* 28 MHz */
422 amiga_colorclock = 5*amiga_eclock; /* 3.5 MHz */ 411 amiga_colorclock = 5*amiga_eclock; /* 3.5 MHz */
423 412
424 /* clear all DMA bits */ 413 /* clear all DMA bits */
425 amiga_custom.dmacon = DMAF_ALL; 414 amiga_custom.dmacon = DMAF_ALL;
426 /* ensure that the DMA master bit is set */ 415 /* ensure that the DMA master bit is set */
427 amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER; 416 amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
428 417
429 /* don't use Z2 RAM as system memory on Z3 capable machines */ 418 /* don't use Z2 RAM as system memory on Z3 capable machines */
430 if (AMIGAHW_PRESENT(ZORRO3)) { 419 if (AMIGAHW_PRESENT(ZORRO3)) {
431 int i, j; 420 int i, j;
432 u32 disabled_z2mem = 0; 421 u32 disabled_z2mem = 0;
433 for (i = 0; i < m68k_num_memory; i++) 422
434 if (m68k_memory[i].addr < 16*1024*1024) { 423 for (i = 0; i < m68k_num_memory; i++) {
435 if (i == 0) { 424 if (m68k_memory[i].addr < 16*1024*1024) {
436 /* don't cut off the branch we're sitting on */ 425 if (i == 0) {
437 printk("Warning: kernel runs in Zorro II memory\n"); 426 /* don't cut off the branch we're sitting on */
438 continue; 427 printk("Warning: kernel runs in Zorro II memory\n");
428 continue;
429 }
430 disabled_z2mem += m68k_memory[i].size;
431 m68k_num_memory--;
432 for (j = i; j < m68k_num_memory; j++)
433 m68k_memory[j] = m68k_memory[j+1];
434 i--;
435 }
436 }
437 if (disabled_z2mem)
438 printk("%dK of Zorro II memory will not be used as system memory\n",
439 disabled_z2mem>>10);
439 } 440 }
440 disabled_z2mem += m68k_memory[i].size; 441
441 m68k_num_memory--; 442 /* request all RAM */
442 for (j = i; j < m68k_num_memory; j++) 443 for (i = 0; i < m68k_num_memory; i++) {
443 m68k_memory[j] = m68k_memory[j+1]; 444 ram_resource[i].name =
444 i--; 445 (m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" :
445 } 446 (m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" :
446 if (disabled_z2mem) 447 "16-bit Slow RAM";
447 printk("%dK of Zorro II memory will not be used as system memory\n", 448 ram_resource[i].start = m68k_memory[i].addr;
448 disabled_z2mem>>10); 449 ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1;
449 } 450 request_resource(&iomem_resource, &ram_resource[i]);
450 451 }
451 /* request all RAM */ 452
452 for (i = 0; i < m68k_num_memory; i++) { 453 /* initialize chipram allocator */
453 ram_resource[i].name = 454 amiga_chip_init();
454 (m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" : 455
455 (m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" : 456 /* our beloved beeper */
456 "16-bit Slow RAM"; 457 if (AMIGAHW_PRESENT(AMI_AUDIO))
457 ram_resource[i].start = m68k_memory[i].addr; 458 amiga_init_sound();
458 ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1; 459
459 request_resource(&iomem_resource, &ram_resource[i]); 460 /*
460 } 461 * if it is an A3000, set the magic bit that forces
461 462 * a hard rekick
462 /* initialize chipram allocator */ 463 */
463 amiga_chip_init (); 464 if (AMIGAHW_PRESENT(MAGIC_REKICK))
464 465 *(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
465 /* debugging using chipram */
466 if (!strcmp( m68k_debug_device, "mem" )){
467 if (!AMIGAHW_PRESENT(CHIP_RAM))
468 printk("Warning: no chipram present for debugging\n");
469 else {
470 amiga_savekmsg_init();
471 amiga_console_driver.write = amiga_mem_console_write;
472 register_console(&amiga_console_driver);
473 }
474 }
475
476 /* our beloved beeper */
477 if (AMIGAHW_PRESENT(AMI_AUDIO))
478 amiga_init_sound();
479
480 /*
481 * if it is an A3000, set the magic bit that forces
482 * a hard rekick
483 */
484 if (AMIGAHW_PRESENT(MAGIC_REKICK))
485 *(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
486} 466}
487 467
488static unsigned short jiffy_ticks; 468static unsigned short jiffy_ticks;
@@ -490,12 +470,12 @@ static unsigned short jiffy_ticks;
490static void __init amiga_sched_init(irq_handler_t timer_routine) 470static void __init amiga_sched_init(irq_handler_t timer_routine)
491{ 471{
492 static struct resource sched_res = { 472 static struct resource sched_res = {
493 .name = "timer", .start = 0x00bfd400, .end = 0x00bfd5ff, 473 .name = "timer", .start = 0x00bfd400, .end = 0x00bfd5ff,
494 }; 474 };
495 jiffy_ticks = (amiga_eclock+HZ/2)/HZ; 475 jiffy_ticks = (amiga_eclock+HZ/2)/HZ;
496 476
497 if (request_resource(&mb_resources._ciab, &sched_res)) 477 if (request_resource(&mb_resources._ciab, &sched_res))
498 printk("Cannot allocate ciab.ta{lo,hi}\n"); 478 printk("Cannot allocate ciab.ta{lo,hi}\n");
499 ciab.cra &= 0xC0; /* turn off timer A, continuous mode, from Eclk */ 479 ciab.cra &= 0xC0; /* turn off timer A, continuous mode, from Eclk */
500 ciab.talo = jiffy_ticks % 256; 480 ciab.talo = jiffy_ticks % 256;
501 ciab.tahi = jiffy_ticks / 256; 481 ciab.tahi = jiffy_ticks / 256;
@@ -513,7 +493,7 @@ static void __init amiga_sched_init(irq_handler_t timer_routine)
513#define TICK_SIZE 10000 493#define TICK_SIZE 10000
514 494
515/* This is always executed with interrupts disabled. */ 495/* This is always executed with interrupts disabled. */
516static unsigned long amiga_gettimeoffset (void) 496static unsigned long amiga_gettimeoffset(void)
517{ 497{
518 unsigned short hi, lo, hi2; 498 unsigned short hi, lo, hi2;
519 unsigned long ticks, offset = 0; 499 unsigned long ticks, offset = 0;
@@ -585,15 +565,15 @@ static int a2000_hwclk(int op, struct rtc_time *t)
585 565
586 tod_2000.cntrl1 = TOD2000_CNTRL1_HOLD; 566 tod_2000.cntrl1 = TOD2000_CNTRL1_HOLD;
587 567
588 while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt--) 568 while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt--) {
589 { 569 tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;
590 tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD; 570 udelay(70);
591 udelay(70); 571 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
592 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
593 } 572 }
594 573
595 if (!cnt) 574 if (!cnt)
596 printk(KERN_INFO "hwclk: timed out waiting for RTC (0x%x)\n", tod_2000.cntrl1); 575 printk(KERN_INFO "hwclk: timed out waiting for RTC (0x%x)\n",
576 tod_2000.cntrl1);
597 577
598 if (!op) { /* read */ 578 if (!op) { /* read */
599 t->tm_sec = tod_2000.second1 * 10 + tod_2000.second2; 579 t->tm_sec = tod_2000.second1 * 10 + tod_2000.second2;
@@ -606,7 +586,7 @@ static int a2000_hwclk(int op, struct rtc_time *t)
606 if (t->tm_year <= 69) 586 if (t->tm_year <= 69)
607 t->tm_year += 100; 587 t->tm_year += 100;
608 588
609 if (!(tod_2000.cntrl3 & TOD2000_CNTRL3_24HMODE)){ 589 if (!(tod_2000.cntrl3 & TOD2000_CNTRL3_24HMODE)) {
610 if (!(tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour == 12) 590 if (!(tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour == 12)
611 t->tm_hour = 0; 591 t->tm_hour = 0;
612 else if ((tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour != 12) 592 else if ((tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour != 12)
@@ -642,7 +622,7 @@ static int a2000_hwclk(int op, struct rtc_time *t)
642 return 0; 622 return 0;
643} 623}
644 624
645static int amiga_set_clock_mmss (unsigned long nowtime) 625static int amiga_set_clock_mmss(unsigned long nowtime)
646{ 626{
647 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60; 627 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
648 628
@@ -660,8 +640,7 @@ static int amiga_set_clock_mmss (unsigned long nowtime)
660 640
661 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD; 641 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
662 642
663 while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt--) 643 while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt--) {
664 {
665 tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD; 644 tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;
666 udelay(70); 645 udelay(70);
667 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD; 646 tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
@@ -681,7 +660,7 @@ static int amiga_set_clock_mmss (unsigned long nowtime)
681 return 0; 660 return 0;
682} 661}
683 662
684static unsigned int amiga_get_ss( void ) 663static unsigned int amiga_get_ss(void)
685{ 664{
686 unsigned int s; 665 unsigned int s;
687 666
@@ -695,71 +674,72 @@ static unsigned int amiga_get_ss( void )
695 return s; 674 return s;
696} 675}
697 676
698static NORET_TYPE void amiga_reset( void ) 677static NORET_TYPE void amiga_reset(void)
699 ATTRIB_NORET; 678 ATTRIB_NORET;
700 679
701static void amiga_reset (void) 680static void amiga_reset(void)
702{ 681{
703 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040); 682 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
704 unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label); 683 unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label);
705 684
706 local_irq_disable(); 685 local_irq_disable();
707 if (CPU_IS_040_OR_060) 686 if (CPU_IS_040_OR_060)
708 /* Setup transparent translation registers for mapping 687 /* Setup transparent translation registers for mapping
709 * of 16 MB kernel segment before disabling translation 688 * of 16 MB kernel segment before disabling translation
710 */ 689 */
711 __asm__ __volatile__ 690 asm volatile ("\n"
712 ("movel %0,%/d0\n\t" 691 " move.l %0,%%d0\n"
713 "andl #0xff000000,%/d0\n\t" 692 " and.l #0xff000000,%%d0\n"
714 "orw #0xe020,%/d0\n\t" /* map 16 MB, enable, cacheable */ 693 " or.w #0xe020,%%d0\n" /* map 16 MB, enable, cacheable */
715 ".chip 68040\n\t" 694 " .chip 68040\n"
716 "movec %%d0,%%itt0\n\t" 695 " movec %%d0,%%itt0\n"
717 "movec %%d0,%%dtt0\n\t" 696 " movec %%d0,%%dtt0\n"
718 ".chip 68k\n\t" 697 " .chip 68k\n"
719 "jmp %0@\n\t" 698 " jmp %0@\n"
720 : /* no outputs */ 699 : /* no outputs */
721 : "a" (jmp_addr040)); 700 : "a" (jmp_addr040)
722 else 701 : "d0");
723 /* for 680[23]0, just disable translation and jump to the physical 702 else
724 * address of the label 703 /* for 680[23]0, just disable translation and jump to the physical
725 */ 704 * address of the label
726 __asm__ __volatile__ 705 */
727 ("pmove %/tc,%@\n\t" 706 asm volatile ("\n"
728 "bclr #7,%@\n\t" 707 " pmove %%tc,%@\n"
729 "pmove %@,%/tc\n\t" 708 " bclr #7,%@\n"
730 "jmp %0@\n\t" 709 " pmove %@,%%tc\n"
731 : /* no outputs */ 710 " jmp %0@\n"
732 : "a" (jmp_addr)); 711 : /* no outputs */
733 jmp_addr_label040: 712 : "a" (jmp_addr));
734 /* disable translation on '040 now */ 713jmp_addr_label040:
735 __asm__ __volatile__ 714 /* disable translation on '040 now */
736 ("moveq #0,%/d0\n\t" 715 asm volatile ("\n"
737 ".chip 68040\n\t" 716 " moveq #0,%%d0\n"
738 "movec %%d0,%%tc\n\t" /* disable MMU */ 717 " .chip 68040\n"
739 ".chip 68k\n\t" 718 " movec %%d0,%%tc\n" /* disable MMU */
740 : /* no outputs */ 719 " .chip 68k\n"
741 : /* no inputs */ 720 : /* no outputs */
742 : "d0"); 721 : /* no inputs */
743 722 : "d0");
744 jmp_addr_label: 723
745 /* pickup reset address from AmigaOS ROM, reset devices and jump 724 jmp_addr_label:
746 * to reset address 725 /* pickup reset address from AmigaOS ROM, reset devices and jump
747 */ 726 * to reset address
748 __asm__ __volatile__ 727 */
749 ("movew #0x2700,%/sr\n\t" 728 asm volatile ("\n"
750 "leal 0x01000000,%/a0\n\t" 729 " move.w #0x2700,%sr\n"
751 "subl %/a0@(-0x14),%/a0\n\t" 730 " lea 0x01000000,%a0\n"
752 "movel %/a0@(4),%/a0\n\t" 731 " sub.l %a0@(-0x14),%a0\n"
753 "subql #2,%/a0\n\t" 732 " move.l %a0@(4),%a0\n"
754 "bra 1f\n\t" 733 " subq.l #2,%a0\n"
755 /* align on a longword boundary */ 734 " jra 1f\n"
756 __ALIGN_STR "\n" 735 /* align on a longword boundary */
757 "1:\n\t" 736 " " __ALIGN_STR "\n"
758 "reset\n\t" 737 "1:\n"
759 "jmp %/a0@" : /* Just that gcc scans it for % escapes */ ); 738 " reset\n"
760 739 " jmp %a0@");
761 for (;;); 740
762 741 for (;;)
742 ;
763} 743}
764 744
765 745
@@ -773,11 +753,11 @@ static void amiga_reset (void)
773#define SAVEKMSG_MAGIC2 0x4B4D5347 /* 'KMSG' */ 753#define SAVEKMSG_MAGIC2 0x4B4D5347 /* 'KMSG' */
774 754
775struct savekmsg { 755struct savekmsg {
776 unsigned long magic1; /* SAVEKMSG_MAGIC1 */ 756 unsigned long magic1; /* SAVEKMSG_MAGIC1 */
777 unsigned long magic2; /* SAVEKMSG_MAGIC2 */ 757 unsigned long magic2; /* SAVEKMSG_MAGIC2 */
778 unsigned long magicptr; /* address of magic1 */ 758 unsigned long magicptr; /* address of magic1 */
779 unsigned long size; 759 unsigned long size;
780 char data[0]; 760 char data[0];
781}; 761};
782 762
783static struct savekmsg *savekmsg; 763static struct savekmsg *savekmsg;
@@ -785,113 +765,132 @@ static struct savekmsg *savekmsg;
785static void amiga_mem_console_write(struct console *co, const char *s, 765static void amiga_mem_console_write(struct console *co, const char *s,
786 unsigned int count) 766 unsigned int count)
787{ 767{
788 if (savekmsg->size+count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) { 768 if (savekmsg->size + count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
789 memcpy(savekmsg->data+savekmsg->size, s, count); 769 memcpy(savekmsg->data + savekmsg->size, s, count);
790 savekmsg->size += count; 770 savekmsg->size += count;
791 } 771 }
792} 772}
793 773
794static void amiga_savekmsg_init(void) 774static int __init amiga_savekmsg_setup(char *arg)
795{ 775{
796 static struct resource debug_res = { .name = "Debug" }; 776 static struct resource debug_res = { .name = "Debug" };
777
778 if (!MACH_IS_AMIGA || strcmp(arg, "mem"))
779 goto done;
780
781 if (!AMIGAHW_PRESENT(CHIP_RAM)) {
782 printk("Warning: no chipram present for debugging\n");
783 goto done;
784 }
797 785
798 savekmsg = amiga_chip_alloc_res(SAVEKMSG_MAXMEM, &debug_res); 786 savekmsg = amiga_chip_alloc_res(SAVEKMSG_MAXMEM, &debug_res);
799 savekmsg->magic1 = SAVEKMSG_MAGIC1; 787 savekmsg->magic1 = SAVEKMSG_MAGIC1;
800 savekmsg->magic2 = SAVEKMSG_MAGIC2; 788 savekmsg->magic2 = SAVEKMSG_MAGIC2;
801 savekmsg->magicptr = ZTWO_PADDR(savekmsg); 789 savekmsg->magicptr = ZTWO_PADDR(savekmsg);
802 savekmsg->size = 0; 790 savekmsg->size = 0;
791
792 amiga_console_driver.write = amiga_mem_console_write;
793 register_console(&amiga_console_driver);
794
795done:
796 return 0;
803} 797}
804 798
799early_param("debug", amiga_savekmsg_setup);
800
805static void amiga_serial_putc(char c) 801static void amiga_serial_putc(char c)
806{ 802{
807 amiga_custom.serdat = (unsigned char)c | 0x100; 803 amiga_custom.serdat = (unsigned char)c | 0x100;
808 while (!(amiga_custom.serdatr & 0x2000)) 804 while (!(amiga_custom.serdatr & 0x2000))
809 ; 805 ;
810} 806}
811 807
812void amiga_serial_console_write(struct console *co, const char *s, 808void amiga_serial_console_write(struct console *co, const char *s,
813 unsigned int count) 809 unsigned int count)
814{ 810{
815 while (count--) { 811 while (count--) {
816 if (*s == '\n') 812 if (*s == '\n')
817 amiga_serial_putc('\r'); 813 amiga_serial_putc('\r');
818 amiga_serial_putc(*s++); 814 amiga_serial_putc(*s++);
819 } 815 }
820} 816}
821 817
822#ifdef CONFIG_SERIAL_CONSOLE 818#ifdef CONFIG_SERIAL_CONSOLE
823void amiga_serial_puts(const char *s) 819void amiga_serial_puts(const char *s)
824{ 820{
825 amiga_serial_console_write(NULL, s, strlen(s)); 821 amiga_serial_console_write(NULL, s, strlen(s));
826} 822}
827 823
828int amiga_serial_console_wait_key(struct console *co) 824int amiga_serial_console_wait_key(struct console *co)
829{ 825{
830 int ch; 826 int ch;
831 827
832 while (!(amiga_custom.intreqr & IF_RBF)) 828 while (!(amiga_custom.intreqr & IF_RBF))
833 barrier(); 829 barrier();
834 ch = amiga_custom.serdatr & 0xff; 830 ch = amiga_custom.serdatr & 0xff;
835 /* clear the interrupt, so that another character can be read */ 831 /* clear the interrupt, so that another character can be read */
836 amiga_custom.intreq = IF_RBF; 832 amiga_custom.intreq = IF_RBF;
837 return ch; 833 return ch;
838} 834}
839 835
840void amiga_serial_gets(struct console *co, char *s, int len) 836void amiga_serial_gets(struct console *co, char *s, int len)
841{ 837{
842 int ch, cnt = 0; 838 int ch, cnt = 0;
843 839
844 while (1) { 840 while (1) {
845 ch = amiga_serial_console_wait_key(co); 841 ch = amiga_serial_console_wait_key(co);
846 842
847 /* Check for backspace. */ 843 /* Check for backspace. */
848 if (ch == 8 || ch == 127) { 844 if (ch == 8 || ch == 127) {
849 if (cnt == 0) { 845 if (cnt == 0) {
850 amiga_serial_putc('\007'); 846 amiga_serial_putc('\007');
851 continue; 847 continue;
852 } 848 }
853 cnt--; 849 cnt--;
854 amiga_serial_puts("\010 \010"); 850 amiga_serial_puts("\010 \010");
855 continue; 851 continue;
856 } 852 }
857 853
858 /* Check for enter. */ 854 /* Check for enter. */
859 if (ch == 10 || ch == 13) 855 if (ch == 10 || ch == 13)
860 break; 856 break;
861 857
862 /* See if line is too long. */ 858 /* See if line is too long. */
863 if (cnt >= len + 1) { 859 if (cnt >= len + 1) {
864 amiga_serial_putc(7); 860 amiga_serial_putc(7);
865 cnt--; 861 cnt--;
866 continue; 862 continue;
867 } 863 }
868 864
869 /* Store and echo character. */ 865 /* Store and echo character. */
870 s[cnt++] = ch; 866 s[cnt++] = ch;
871 amiga_serial_putc(ch); 867 amiga_serial_putc(ch);
872 } 868 }
873 /* Print enter. */ 869 /* Print enter. */
874 amiga_serial_puts("\r\n"); 870 amiga_serial_puts("\r\n");
875 s[cnt] = 0; 871 s[cnt] = 0;
876} 872}
877#endif 873#endif
878 874
879static void __init amiga_debug_init(void) 875static int __init amiga_debug_setup(char *arg)
880{ 876{
881 if (!strcmp( m68k_debug_device, "ser" )) { 877 if (MACH_IS_AMIGA && !strcmp(arg, "ser")) {
882 /* no initialization required (?) */ 878 /* no initialization required (?) */
883 amiga_console_driver.write = amiga_serial_console_write; 879 amiga_console_driver.write = amiga_serial_console_write;
884 register_console(&amiga_console_driver); 880 register_console(&amiga_console_driver);
885 } 881 }
882 return 0;
886} 883}
887 884
885early_param("debug", amiga_debug_setup);
886
888#ifdef CONFIG_HEARTBEAT 887#ifdef CONFIG_HEARTBEAT
889static void amiga_heartbeat(int on) 888static void amiga_heartbeat(int on)
890{ 889{
891 if (on) 890 if (on)
892 ciaa.pra &= ~2; 891 ciaa.pra &= ~2;
893 else 892 else
894 ciaa.pra |= 2; 893 ciaa.pra |= 2;
895} 894}
896#endif 895#endif
897 896
@@ -901,81 +900,81 @@ static void amiga_heartbeat(int on)
901 900
902static void amiga_get_model(char *model) 901static void amiga_get_model(char *model)
903{ 902{
904 strcpy(model, amiga_model_name); 903 strcpy(model, amiga_model_name);
905} 904}
906 905
907 906
908static int amiga_get_hardware_list(char *buffer) 907static int amiga_get_hardware_list(char *buffer)
909{ 908{
910 int len = 0; 909 int len = 0;
911 910
912 if (AMIGAHW_PRESENT(CHIP_RAM)) 911 if (AMIGAHW_PRESENT(CHIP_RAM))
913 len += sprintf(buffer+len, "Chip RAM:\t%ldK\n", amiga_chip_size>>10); 912 len += sprintf(buffer+len, "Chip RAM:\t%ldK\n", amiga_chip_size>>10);
914 len += sprintf(buffer+len, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n", 913 len += sprintf(buffer+len, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n",
915 amiga_psfreq, amiga_eclock); 914 amiga_psfreq, amiga_eclock);
916 if (AMIGAHW_PRESENT(AMI_VIDEO)) { 915 if (AMIGAHW_PRESENT(AMI_VIDEO)) {
917 char *type; 916 char *type;
918 switch(amiga_chipset) { 917 switch (amiga_chipset) {
919 case CS_OCS: 918 case CS_OCS:
920 type = "OCS"; 919 type = "OCS";
921 break; 920 break;
922 case CS_ECS: 921 case CS_ECS:
923 type = "ECS"; 922 type = "ECS";
924 break; 923 break;
925 case CS_AGA: 924 case CS_AGA:
926 type = "AGA"; 925 type = "AGA";
927 break; 926 break;
928 default: 927 default:
929 type = "Old or Unknown"; 928 type = "Old or Unknown";
930 break; 929 break;
930 }
931 len += sprintf(buffer+len, "Graphics:\t%s\n", type);
931 } 932 }
932 len += sprintf(buffer+len, "Graphics:\t%s\n", type);
933 }
934 933
935#define AMIGAHW_ANNOUNCE(name, str) \ 934#define AMIGAHW_ANNOUNCE(name, str) \
936 if (AMIGAHW_PRESENT(name)) \ 935 if (AMIGAHW_PRESENT(name)) \
937 len += sprintf (buffer+len, "\t%s\n", str) 936 len += sprintf (buffer+len, "\t%s\n", str)
938 937
939 len += sprintf (buffer + len, "Detected hardware:\n"); 938 len += sprintf (buffer + len, "Detected hardware:\n");
940 939
941 AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video"); 940 AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video");
942 AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter"); 941 AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter");
943 AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer"); 942 AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer");
944 AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio"); 943 AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio");
945 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller"); 944 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller");
946 AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)"); 945 AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)");
947 AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)"); 946 AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)");
948 AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)"); 947 AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)");
949 AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)"); 948 AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)");
950 AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive"); 949 AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive");
951 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard"); 950 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard");
952 AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port"); 951 AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port");
953 AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port"); 952 AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port");
954 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port"); 953 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port");
955 AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)"); 954 AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)");
956 AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)"); 955 AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)");
957 AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM"); 956 AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM");
958 AMIGAHW_ANNOUNCE(PAULA, "Paula 8364"); 957 AMIGAHW_ANNOUNCE(PAULA, "Paula 8364");
959 AMIGAHW_ANNOUNCE(DENISE, "Denise 8362"); 958 AMIGAHW_ANNOUNCE(DENISE, "Denise 8362");
960 AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373"); 959 AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373");
961 AMIGAHW_ANNOUNCE(LISA, "Lisa 8375"); 960 AMIGAHW_ANNOUNCE(LISA, "Lisa 8375");
962 AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371"); 961 AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371");
963 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370"); 962 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370");
964 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372"); 963 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372");
965 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372"); 964 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372");
966 AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374"); 965 AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374");
967 AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374"); 966 AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374");
968 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick"); 967 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
969 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot"); 968 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
970#ifdef CONFIG_ZORRO 969#ifdef CONFIG_ZORRO
971 if (AMIGAHW_PRESENT(ZORRO)) 970 if (AMIGAHW_PRESENT(ZORRO))
972 len += sprintf(buffer+len, "\tZorro II%s AutoConfig: %d Expansion " 971 len += sprintf(buffer+len, "\tZorro II%s AutoConfig: %d Expansion "
973 "Device%s\n", 972 "Device%s\n",
974 AMIGAHW_PRESENT(ZORRO3) ? "I" : "", 973 AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
975 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); 974 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
976#endif /* CONFIG_ZORRO */ 975#endif /* CONFIG_ZORRO */
977 976
978#undef AMIGAHW_ANNOUNCE 977#undef AMIGAHW_ANNOUNCE
979 978
980 return(len); 979 return len;
981} 980}
diff --git a/arch/m68k/atari/Makefile b/arch/m68k/atari/Makefile
index 8cb6236b39db..2cb86191f0aa 100644
--- a/arch/m68k/atari/Makefile
+++ b/arch/m68k/atari/Makefile
@@ -8,3 +8,4 @@ obj-y := config.o time.o debug.o ataints.o stdma.o \
8ifeq ($(CONFIG_PCI),y) 8ifeq ($(CONFIG_PCI),y)
9obj-$(CONFIG_HADES) += hades-pci.o 9obj-$(CONFIG_HADES) += hades-pci.o
10endif 10endif
11obj-$(CONFIG_ATARI_KBD_CORE) += atakeyb.o
diff --git a/arch/m68k/atari/atakeyb.c b/arch/m68k/atari/atakeyb.c
new file mode 100644
index 000000000000..1c29603b16b3
--- /dev/null
+++ b/arch/m68k/atari/atakeyb.c
@@ -0,0 +1,730 @@
1/*
2 * linux/atari/atakeyb.c
3 *
4 * Atari Keyboard driver for 680x0 Linux
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
10
11/*
12 * Atari support by Robert de Vries
13 * enhanced by Bjoern Brauel and Roman Hodek
14 */
15
16#include <linux/sched.h>
17#include <linux/kernel.h>
18#include <linux/interrupt.h>
19#include <linux/errno.h>
20#include <linux/keyboard.h>
21#include <linux/delay.h>
22#include <linux/timer.h>
23#include <linux/kd.h>
24#include <linux/random.h>
25#include <linux/init.h>
26#include <linux/kbd_kern.h>
27
28#include <asm/atariints.h>
29#include <asm/atarihw.h>
30#include <asm/atarikb.h>
31#include <asm/atari_joystick.h>
32#include <asm/irq.h>
33
34static void atakeyb_rep(unsigned long ignore);
35extern unsigned int keymap_count;
36
37/* Hook for MIDI serial driver */
38void (*atari_MIDI_interrupt_hook) (void);
39/* Hook for mouse driver */
40void (*atari_mouse_interrupt_hook) (char *);
41/* Hook for keyboard inputdev driver */
42void (*atari_input_keyboard_interrupt_hook) (unsigned char, char);
43/* Hook for mouse inputdev driver */
44void (*atari_input_mouse_interrupt_hook) (char *);
45
46/* variables for IKBD self test: */
47
48/* state: 0: off; >0: in progress; >1: 0xf1 received */
49static volatile int ikbd_self_test;
50/* timestamp when last received a char */
51static volatile unsigned long self_test_last_rcv;
52/* bitmap of keys reported as broken */
53static unsigned long broken_keys[128/(sizeof(unsigned long)*8)] = { 0, };
54
55#define BREAK_MASK (0x80)
56
57/*
58 * ++roman: The following changes were applied manually:
59 *
60 * - The Alt (= Meta) key works in combination with Shift and
61 * Control, e.g. Alt+Shift+a sends Meta-A (0xc1), Alt+Control+A sends
62 * Meta-Ctrl-A (0x81) ...
63 *
64 * - The parentheses on the keypad send '(' and ')' with all
65 * modifiers (as would do e.g. keypad '+'), but they cannot be used as
66 * application keys (i.e. sending Esc O c).
67 *
68 * - HELP and UNDO are mapped to be F21 and F24, resp, that send the
69 * codes "\E[M" and "\E[P". (This is better than the old mapping to
70 * F11 and F12, because these codes are on Shift+F1/2 anyway.) This
71 * way, applications that allow their own keyboard mappings
72 * (e.g. tcsh, X Windows) can be configured to use them in the way
73 * the label suggests (providing help or undoing).
74 *
75 * - Console switching is done with Alt+Fx (consoles 1..10) and
76 * Shift+Alt+Fx (consoles 11..20).
77 *
78 * - The misc. special function implemented in the kernel are mapped
79 * to the following key combinations:
80 *
81 * ClrHome -> Home/Find
82 * Shift + ClrHome -> End/Select
83 * Shift + Up -> Page Up
84 * Shift + Down -> Page Down
85 * Alt + Help -> show system status
86 * Shift + Help -> show memory info
87 * Ctrl + Help -> show registers
88 * Ctrl + Alt + Del -> Reboot
89 * Alt + Undo -> switch to last console
90 * Shift + Undo -> send interrupt
91 * Alt + Insert -> stop/start output (same as ^S/^Q)
92 * Alt + Up -> Scroll back console (if implemented)
93 * Alt + Down -> Scroll forward console (if implemented)
94 * Alt + CapsLock -> NumLock
95 *
96 * ++Andreas:
97 *
98 * - Help mapped to K_HELP
99 * - Undo mapped to K_UNDO (= K_F246)
100 * - Keypad Left/Right Parenthesis mapped to new K_PPAREN[LR]
101 */
102
103static u_short ataplain_map[NR_KEYS] __initdata = {
104 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
105 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf008, 0xf009,
106 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
107 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
108 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
109 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
110 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf200,
111 0xf703, 0xf020, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
112 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf200, 0xf200, 0xf114,
113 0xf603, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
114 0xf600, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf200, 0xf200,
115 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
116 0xf200, 0xf1ff, 0xf11b, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
117 0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
118 0xf300, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
119 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
120};
121
122typedef enum kb_state_t {
123 KEYBOARD, AMOUSE, RMOUSE, JOYSTICK, CLOCK, RESYNC
124} KB_STATE_T;
125
126#define IS_SYNC_CODE(sc) ((sc) >= 0x04 && (sc) <= 0xfb)
127
128typedef struct keyboard_state {
129 unsigned char buf[6];
130 int len;
131 KB_STATE_T state;
132} KEYBOARD_STATE;
133
134KEYBOARD_STATE kb_state;
135
136#define DEFAULT_KEYB_REP_DELAY (HZ/4)
137#define DEFAULT_KEYB_REP_RATE (HZ/25)
138
139/* These could be settable by some ioctl() in future... */
140static unsigned int key_repeat_delay = DEFAULT_KEYB_REP_DELAY;
141static unsigned int key_repeat_rate = DEFAULT_KEYB_REP_RATE;
142
143static unsigned char rep_scancode;
144static struct timer_list atakeyb_rep_timer = {
145 .function = atakeyb_rep,
146};
147
148static void atakeyb_rep(unsigned long ignore)
149{
150 /* Disable keyboard for the time we call handle_scancode(), else a race
151 * in the keyboard tty queue may happen */
152 atari_disable_irq(IRQ_MFP_ACIA);
153 del_timer(&atakeyb_rep_timer);
154
155 /* A keyboard int may have come in before we disabled the irq, so
156 * double-check whether rep_scancode is still != 0 */
157 if (rep_scancode) {
158 init_timer(&atakeyb_rep_timer);
159 atakeyb_rep_timer.expires = jiffies + key_repeat_rate;
160 add_timer(&atakeyb_rep_timer);
161
162 //handle_scancode(rep_scancode, 1);
163 if (atari_input_keyboard_interrupt_hook)
164 atari_input_keyboard_interrupt_hook(rep_scancode, 1);
165 }
166
167 atari_enable_irq(IRQ_MFP_ACIA);
168}
169
170
171/* ++roman: If a keyboard overrun happened, we can't tell in general how much
172 * bytes have been lost and in which state of the packet structure we are now.
173 * This usually causes keyboards bytes to be interpreted as mouse movements
174 * and vice versa, which is very annoying. It seems better to throw away some
175 * bytes (that are usually mouse bytes) than to misinterpret them. Therefor I
176 * introduced the RESYNC state for IKBD data. In this state, the bytes up to
177 * one that really looks like a key event (0x04..0xf2) or the start of a mouse
178 * packet (0xf8..0xfb) are thrown away, but at most 2 bytes. This at least
179 * speeds up the resynchronization of the event structure, even if maybe a
180 * mouse movement is lost. However, nothing is perfect. For bytes 0x01..0x03,
181 * it's really hard to decide whether they're mouse or keyboard bytes. Since
182 * overruns usually occur when moving the Atari mouse rapidly, they're seen as
183 * mouse bytes here. If this is wrong, only a make code of the keyboard gets
184 * lost, which isn't too bad. Loosing a break code would be disastrous,
185 * because then the keyboard repeat strikes...
186 */
187
188static irqreturn_t atari_keyboard_interrupt(int irq, void *dummy)
189{
190 u_char acia_stat;
191 int scancode;
192 int break_flag;
193
194repeat:
195 if (acia.mid_ctrl & ACIA_IRQ)
196 if (atari_MIDI_interrupt_hook)
197 atari_MIDI_interrupt_hook();
198 acia_stat = acia.key_ctrl;
199 /* check out if the interrupt came from this ACIA */
200 if (!((acia_stat | acia.mid_ctrl) & ACIA_IRQ))
201 return IRQ_HANDLED;
202
203 if (acia_stat & ACIA_OVRN) {
204 /* a very fast typist or a slow system, give a warning */
205 /* ...happens often if interrupts were disabled for too long */
206 printk(KERN_DEBUG "Keyboard overrun\n");
207 scancode = acia.key_data;
208 /* Turn off autorepeating in case a break code has been lost */
209 del_timer(&atakeyb_rep_timer);
210 rep_scancode = 0;
211 if (ikbd_self_test)
212 /* During self test, don't do resyncing, just process the code */
213 goto interpret_scancode;
214 else if (IS_SYNC_CODE(scancode)) {
215 /* This code seem already to be the start of a new packet or a
216 * single scancode */
217 kb_state.state = KEYBOARD;
218 goto interpret_scancode;
219 } else {
220 /* Go to RESYNC state and skip this byte */
221 kb_state.state = RESYNC;
222 kb_state.len = 1; /* skip max. 1 another byte */
223 goto repeat;
224 }
225 }
226
227 if (acia_stat & ACIA_RDRF) {
228 /* received a character */
229 scancode = acia.key_data; /* get it or reset the ACIA, I'll get it! */
230 tasklet_schedule(&keyboard_tasklet);
231 interpret_scancode:
232 switch (kb_state.state) {
233 case KEYBOARD:
234 switch (scancode) {
235 case 0xF7:
236 kb_state.state = AMOUSE;
237 kb_state.len = 0;
238 break;
239
240 case 0xF8:
241 case 0xF9:
242 case 0xFA:
243 case 0xFB:
244 kb_state.state = RMOUSE;
245 kb_state.len = 1;
246 kb_state.buf[0] = scancode;
247 break;
248
249 case 0xFC:
250 kb_state.state = CLOCK;
251 kb_state.len = 0;
252 break;
253
254 case 0xFE:
255 case 0xFF:
256 kb_state.state = JOYSTICK;
257 kb_state.len = 1;
258 kb_state.buf[0] = scancode;
259 break;
260
261 case 0xF1:
262 /* during self-test, note that 0xf1 received */
263 if (ikbd_self_test) {
264 ++ikbd_self_test;
265 self_test_last_rcv = jiffies;
266 break;
267 }
268 /* FALL THROUGH */
269
270 default:
271 break_flag = scancode & BREAK_MASK;
272 scancode &= ~BREAK_MASK;
273 if (ikbd_self_test) {
274 /* Scancodes sent during the self-test stand for broken
275 * keys (keys being down). The code *should* be a break
276 * code, but nevertheless some AT keyboard interfaces send
277 * make codes instead. Therefore, simply ignore
278 * break_flag...
279 */
280 int keyval = plain_map[scancode], keytyp;
281
282 set_bit(scancode, broken_keys);
283 self_test_last_rcv = jiffies;
284 keyval = plain_map[scancode];
285 keytyp = KTYP(keyval) - 0xf0;
286 keyval = KVAL(keyval);
287
288 printk(KERN_WARNING "Key with scancode %d ", scancode);
289 if (keytyp == KT_LATIN || keytyp == KT_LETTER) {
290 if (keyval < ' ')
291 printk("('^%c') ", keyval + '@');
292 else
293 printk("('%c') ", keyval);
294 }
295 printk("is broken -- will be ignored.\n");
296 break;
297 } else if (test_bit(scancode, broken_keys))
298 break;
299
300#if 0 // FIXME; hangs at boot
301 if (break_flag) {
302 del_timer(&atakeyb_rep_timer);
303 rep_scancode = 0;
304 } else {
305 del_timer(&atakeyb_rep_timer);
306 rep_scancode = scancode;
307 atakeyb_rep_timer.expires = jiffies + key_repeat_delay;
308 add_timer(&atakeyb_rep_timer);
309 }
310#endif
311
312 // handle_scancode(scancode, !break_flag);
313 if (atari_input_keyboard_interrupt_hook)
314 atari_input_keyboard_interrupt_hook((unsigned char)scancode, !break_flag);
315 break;
316 }
317 break;
318
319 case AMOUSE:
320 kb_state.buf[kb_state.len++] = scancode;
321 if (kb_state.len == 5) {
322 kb_state.state = KEYBOARD;
323 /* not yet used */
324 /* wake up someone waiting for this */
325 }
326 break;
327
328 case RMOUSE:
329 kb_state.buf[kb_state.len++] = scancode;
330 if (kb_state.len == 3) {
331 kb_state.state = KEYBOARD;
332 if (atari_mouse_interrupt_hook)
333 atari_mouse_interrupt_hook(kb_state.buf);
334 }
335 break;
336
337 case JOYSTICK:
338 kb_state.buf[1] = scancode;
339 kb_state.state = KEYBOARD;
340#ifdef FIXED_ATARI_JOYSTICK
341 atari_joystick_interrupt(kb_state.buf);
342#endif
343 break;
344
345 case CLOCK:
346 kb_state.buf[kb_state.len++] = scancode;
347 if (kb_state.len == 6) {
348 kb_state.state = KEYBOARD;
349 /* wake up someone waiting for this.
350 But will this ever be used, as Linux keeps its own time.
351 Perhaps for synchronization purposes? */
352 /* wake_up_interruptible(&clock_wait); */
353 }
354 break;
355
356 case RESYNC:
357 if (kb_state.len <= 0 || IS_SYNC_CODE(scancode)) {
358 kb_state.state = KEYBOARD;
359 goto interpret_scancode;
360 }
361 kb_state.len--;
362 break;
363 }
364 }
365
366#if 0
367 if (acia_stat & ACIA_CTS)
368 /* cannot happen */;
369#endif
370
371 if (acia_stat & (ACIA_FE | ACIA_PE)) {
372 printk("Error in keyboard communication\n");
373 }
374
375 /* handle_scancode() can take a lot of time, so check again if
376 * some character arrived
377 */
378 goto repeat;
379}
380
381/*
382 * I write to the keyboard without using interrupts, I poll instead.
383 * This takes for the maximum length string allowed (7) at 7812.5 baud
384 * 8 data 1 start 1 stop bit: 9.0 ms
385 * If this takes too long for normal operation, interrupt driven writing
386 * is the solution. (I made a feeble attempt in that direction but I
387 * kept it simple for now.)
388 */
389void ikbd_write(const char *str, int len)
390{
391 u_char acia_stat;
392
393 if ((len < 1) || (len > 7))
394 panic("ikbd: maximum string length exceeded");
395 while (len) {
396 acia_stat = acia.key_ctrl;
397 if (acia_stat & ACIA_TDRE) {
398 acia.key_data = *str++;
399 len--;
400 }
401 }
402}
403
404/* Reset (without touching the clock) */
405void ikbd_reset(void)
406{
407 static const char cmd[2] = { 0x80, 0x01 };
408
409 ikbd_write(cmd, 2);
410
411 /*
412 * if all's well code 0xF1 is returned, else the break codes of
413 * all keys making contact
414 */
415}
416
417/* Set mouse button action */
418void ikbd_mouse_button_action(int mode)
419{
420 char cmd[2] = { 0x07, mode };
421
422 ikbd_write(cmd, 2);
423}
424
425/* Set relative mouse position reporting */
426void ikbd_mouse_rel_pos(void)
427{
428 static const char cmd[1] = { 0x08 };
429
430 ikbd_write(cmd, 1);
431}
432
433/* Set absolute mouse position reporting */
434void ikbd_mouse_abs_pos(int xmax, int ymax)
435{
436 char cmd[5] = { 0x09, xmax>>8, xmax&0xFF, ymax>>8, ymax&0xFF };
437
438 ikbd_write(cmd, 5);
439}
440
441/* Set mouse keycode mode */
442void ikbd_mouse_kbd_mode(int dx, int dy)
443{
444 char cmd[3] = { 0x0A, dx, dy };
445
446 ikbd_write(cmd, 3);
447}
448
449/* Set mouse threshold */
450void ikbd_mouse_thresh(int x, int y)
451{
452 char cmd[3] = { 0x0B, x, y };
453
454 ikbd_write(cmd, 3);
455}
456
457/* Set mouse scale */
458void ikbd_mouse_scale(int x, int y)
459{
460 char cmd[3] = { 0x0C, x, y };
461
462 ikbd_write(cmd, 3);
463}
464
465/* Interrogate mouse position */
466void ikbd_mouse_pos_get(int *x, int *y)
467{
468 static const char cmd[1] = { 0x0D };
469
470 ikbd_write(cmd, 1);
471
472 /* wait for returning bytes */
473}
474
475/* Load mouse position */
476void ikbd_mouse_pos_set(int x, int y)
477{
478 char cmd[6] = { 0x0E, 0x00, x>>8, x&0xFF, y>>8, y&0xFF };
479
480 ikbd_write(cmd, 6);
481}
482
483/* Set Y=0 at bottom */
484void ikbd_mouse_y0_bot(void)
485{
486 static const char cmd[1] = { 0x0F };
487
488 ikbd_write(cmd, 1);
489}
490
491/* Set Y=0 at top */
492void ikbd_mouse_y0_top(void)
493{
494 static const char cmd[1] = { 0x10 };
495
496 ikbd_write(cmd, 1);
497}
498
499/* Resume */
500void ikbd_resume(void)
501{
502 static const char cmd[1] = { 0x11 };
503
504 ikbd_write(cmd, 1);
505}
506
507/* Disable mouse */
508void ikbd_mouse_disable(void)
509{
510 static const char cmd[1] = { 0x12 };
511
512 ikbd_write(cmd, 1);
513}
514
515/* Pause output */
516void ikbd_pause(void)
517{
518 static const char cmd[1] = { 0x13 };
519
520 ikbd_write(cmd, 1);
521}
522
523/* Set joystick event reporting */
524void ikbd_joystick_event_on(void)
525{
526 static const char cmd[1] = { 0x14 };
527
528 ikbd_write(cmd, 1);
529}
530
531/* Set joystick interrogation mode */
532void ikbd_joystick_event_off(void)
533{
534 static const char cmd[1] = { 0x15 };
535
536 ikbd_write(cmd, 1);
537}
538
539/* Joystick interrogation */
540void ikbd_joystick_get_state(void)
541{
542 static const char cmd[1] = { 0x16 };
543
544 ikbd_write(cmd, 1);
545}
546
547#if 0
548/* This disables all other ikbd activities !!!! */
549/* Set joystick monitoring */
550void ikbd_joystick_monitor(int rate)
551{
552 static const char cmd[2] = { 0x17, rate };
553
554 ikbd_write(cmd, 2);
555
556 kb_state.state = JOYSTICK_MONITOR;
557}
558#endif
559
560/* some joystick routines not in yet (0x18-0x19) */
561
562/* Disable joysticks */
563void ikbd_joystick_disable(void)
564{
565 static const char cmd[1] = { 0x1A };
566
567 ikbd_write(cmd, 1);
568}
569
570/* Time-of-day clock set */
571void ikbd_clock_set(int year, int month, int day, int hour, int minute, int second)
572{
573 char cmd[7] = { 0x1B, year, month, day, hour, minute, second };
574
575 ikbd_write(cmd, 7);
576}
577
578/* Interrogate time-of-day clock */
579void ikbd_clock_get(int *year, int *month, int *day, int *hour, int *minute, int second)
580{
581 static const char cmd[1] = { 0x1C };
582
583 ikbd_write(cmd, 1);
584}
585
586/* Memory load */
587void ikbd_mem_write(int address, int size, char *data)
588{
589 panic("Attempt to write data into keyboard memory");
590}
591
592/* Memory read */
593void ikbd_mem_read(int address, char data[6])
594{
595 char cmd[3] = { 0x21, address>>8, address&0xFF };
596
597 ikbd_write(cmd, 3);
598
599 /* receive data and put it in data */
600}
601
602/* Controller execute */
603void ikbd_exec(int address)
604{
605 char cmd[3] = { 0x22, address>>8, address&0xFF };
606
607 ikbd_write(cmd, 3);
608}
609
610/* Status inquiries (0x87-0x9A) not yet implemented */
611
612/* Set the state of the caps lock led. */
613void atari_kbd_leds(unsigned int leds)
614{
615 char cmd[6] = {32, 0, 4, 1, 254 + ((leds & 4) != 0), 0};
616
617 ikbd_write(cmd, 6);
618}
619
620/*
621 * The original code sometimes left the interrupt line of
622 * the ACIAs low forever. I hope, it is fixed now.
623 *
624 * Martin Rogge, 20 Aug 1995
625 */
626
627static int atari_keyb_done = 0;
628
629int __init atari_keyb_init(void)
630{
631 if (atari_keyb_done)
632 return 0;
633
634 /* setup key map */
635 memcpy(key_maps[0], ataplain_map, sizeof(plain_map));
636
637 kb_state.state = KEYBOARD;
638 kb_state.len = 0;
639
640 request_irq(IRQ_MFP_ACIA, atari_keyboard_interrupt, IRQ_TYPE_SLOW,
641 "keyboard/mouse/MIDI", atari_keyboard_interrupt);
642
643 atari_turnoff_irq(IRQ_MFP_ACIA);
644 do {
645 /* reset IKBD ACIA */
646 acia.key_ctrl = ACIA_RESET |
647 (atari_switches & ATARI_SWITCH_IKBD) ? ACIA_RHTID : 0;
648 (void)acia.key_ctrl;
649 (void)acia.key_data;
650
651 /* reset MIDI ACIA */
652 acia.mid_ctrl = ACIA_RESET |
653 (atari_switches & ATARI_SWITCH_MIDI) ? ACIA_RHTID : 0;
654 (void)acia.mid_ctrl;
655 (void)acia.mid_data;
656
657 /* divide 500kHz by 64 gives 7812.5 baud */
658 /* 8 data no parity 1 start 1 stop bit */
659 /* receive interrupt enabled */
660 /* RTS low (except if switch selected), transmit interrupt disabled */
661 acia.key_ctrl = (ACIA_DIV64|ACIA_D8N1S|ACIA_RIE) |
662 ((atari_switches & ATARI_SWITCH_IKBD) ?
663 ACIA_RHTID : ACIA_RLTID);
664
665 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S |
666 (atari_switches & ATARI_SWITCH_MIDI) ? ACIA_RHTID : 0;
667
668 /* make sure the interrupt line is up */
669 } while ((mfp.par_dt_reg & 0x10) == 0);
670
671 /* enable ACIA Interrupts */
672 mfp.active_edge &= ~0x10;
673 atari_turnon_irq(IRQ_MFP_ACIA);
674
675 ikbd_self_test = 1;
676 ikbd_reset();
677 /* wait for a period of inactivity (here: 0.25s), then assume the IKBD's
678 * self-test is finished */
679 self_test_last_rcv = jiffies;
680 while (time_before(jiffies, self_test_last_rcv + HZ/4))
681 barrier();
682 /* if not incremented: no 0xf1 received */
683 if (ikbd_self_test == 1)
684 printk(KERN_ERR "WARNING: keyboard self test failed!\n");
685 ikbd_self_test = 0;
686
687 ikbd_mouse_disable();
688 ikbd_joystick_disable();
689
690#ifdef FIXED_ATARI_JOYSTICK
691 atari_joystick_init();
692#endif
693
694 // flag init done
695 atari_keyb_done = 1;
696 return 0;
697}
698
699
700int atari_kbdrate(struct kbd_repeat *k)
701{
702 if (k->delay > 0) {
703 /* convert from msec to jiffies */
704 key_repeat_delay = (k->delay * HZ + 500) / 1000;
705 if (key_repeat_delay < 1)
706 key_repeat_delay = 1;
707 }
708 if (k->period > 0) {
709 key_repeat_rate = (k->period * HZ + 500) / 1000;
710 if (key_repeat_rate < 1)
711 key_repeat_rate = 1;
712 }
713
714 k->delay = key_repeat_delay * 1000 / HZ;
715 k->period = key_repeat_rate * 1000 / HZ;
716
717 return 0;
718}
719
720int atari_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode)
721{
722#ifdef CONFIG_MAGIC_SYSRQ
723 /* ALT+HELP pressed? */
724 if ((keycode == 98) && ((shift_state & 0xff) == 8))
725 *keycodep = 0xff;
726 else
727#endif
728 *keycodep = keycode;
729 return 1;
730}
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index ca5cd4344e3d..e40e5dcaa347 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -50,70 +50,25 @@ int atari_dont_touch_floppy_select;
50int atari_rtc_year_offset; 50int atari_rtc_year_offset;
51 51
52/* local function prototypes */ 52/* local function prototypes */
53static void atari_reset( void ); 53static void atari_reset(void);
54static void atari_get_model(char *model); 54static void atari_get_model(char *model);
55static int atari_get_hardware_list(char *buffer); 55static int atari_get_hardware_list(char *buffer);
56 56
57/* atari specific irq functions */ 57/* atari specific irq functions */
58extern void atari_init_IRQ (void); 58extern void atari_init_IRQ (void);
59extern void atari_mksound( unsigned int count, unsigned int ticks ); 59extern void atari_mksound(unsigned int count, unsigned int ticks);
60#ifdef CONFIG_HEARTBEAT 60#ifdef CONFIG_HEARTBEAT
61static void atari_heartbeat( int on ); 61static void atari_heartbeat(int on);
62#endif 62#endif
63 63
64/* atari specific timer functions (in time.c) */ 64/* atari specific timer functions (in time.c) */
65extern void atari_sched_init(irq_handler_t ); 65extern void atari_sched_init(irq_handler_t);
66extern unsigned long atari_gettimeoffset (void); 66extern unsigned long atari_gettimeoffset (void);
67extern int atari_mste_hwclk (int, struct rtc_time *); 67extern int atari_mste_hwclk (int, struct rtc_time *);
68extern int atari_tt_hwclk (int, struct rtc_time *); 68extern int atari_tt_hwclk (int, struct rtc_time *);
69extern int atari_mste_set_clock_mmss (unsigned long); 69extern int atari_mste_set_clock_mmss (unsigned long);
70extern int atari_tt_set_clock_mmss (unsigned long); 70extern int atari_tt_set_clock_mmss (unsigned long);
71 71
72/* atari specific debug functions (in debug.c) */
73extern void atari_debug_init(void);
74
75
76/* I've moved hwreg_present() and hwreg_present_bywrite() out into
77 * mm/hwtest.c, to avoid having multiple copies of the same routine
78 * in the kernel [I wanted them in hp300 and they were already used
79 * in the nubus code. NB: I don't have an Atari so this might (just
80 * conceivably) break something.
81 * I've preserved the #if 0 version of hwreg_present_bywrite() here
82 * for posterity.
83 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk>, 05/1998
84 */
85
86#if 0
87static int __init
88hwreg_present_bywrite(volatile void *regp, unsigned char val)
89{
90 int ret;
91 long save_sp, save_vbr;
92 static long tmp_vectors[3] = { [2] = (long)&&after_test };
93
94 __asm__ __volatile__
95 ( "movec %/vbr,%2\n\t" /* save vbr value */
96 "movec %4,%/vbr\n\t" /* set up temporary vectors */
97 "movel %/sp,%1\n\t" /* save sp */
98 "moveq #0,%0\n\t" /* assume not present */
99 "moveb %5,%3@\n\t" /* write the hardware reg */
100 "cmpb %3@,%5\n\t" /* compare it */
101 "seq %0" /* comes here only if reg */
102 /* is present */
103 : "=d&" (ret), "=r&" (save_sp), "=r&" (save_vbr)
104 : "a" (regp), "r" (tmp_vectors), "d" (val)
105 );
106 after_test:
107 __asm__ __volatile__
108 ( "movel %0,%/sp\n\t" /* restore sp */
109 "movec %1,%/vbr" /* restore vbr */
110 : : "r" (save_sp), "r" (save_vbr) : "sp"
111 );
112
113 return( ret );
114}
115#endif
116
117 72
118/* ++roman: This is a more elaborate test for an SCC chip, since the plain 73/* ++roman: This is a more elaborate test for an SCC chip, since the plain
119 * Medusa board generates DTACK at the SCC's standard addresses, but a SCC 74 * Medusa board generates DTACK at the SCC's standard addresses, but a SCC
@@ -123,26 +78,34 @@ hwreg_present_bywrite(volatile void *regp, unsigned char val)
123 * should be readable without trouble (from channel A!). 78 * should be readable without trouble (from channel A!).
124 */ 79 */
125 80
126static int __init scc_test( volatile char *ctla ) 81static int __init scc_test(volatile char *ctla)
127{ 82{
128 if (!hwreg_present( ctla )) 83 if (!hwreg_present(ctla))
129 return( 0 ); 84 return 0;
130 MFPDELAY(); 85 MFPDELAY();
131 86
132 *ctla = 2; MFPDELAY(); 87 *ctla = 2;
133 *ctla = 0x40; MFPDELAY(); 88 MFPDELAY();
89 *ctla = 0x40;
90 MFPDELAY();
134 91
135 *ctla = 2; MFPDELAY(); 92 *ctla = 2;
136 if (*ctla != 0x40) return( 0 ); 93 MFPDELAY();
94 if (*ctla != 0x40)
95 return 0;
137 MFPDELAY(); 96 MFPDELAY();
138 97
139 *ctla = 2; MFPDELAY(); 98 *ctla = 2;
140 *ctla = 0x60; MFPDELAY(); 99 MFPDELAY();
100 *ctla = 0x60;
101 MFPDELAY();
141 102
142 *ctla = 2; MFPDELAY(); 103 *ctla = 2;
143 if (*ctla != 0x60) return( 0 ); 104 MFPDELAY();
105 if (*ctla != 0x60)
106 return 0;
144 107
145 return( 1 ); 108 return 1;
146} 109}
147 110
148 111
@@ -152,61 +115,66 @@ static int __init scc_test( volatile char *ctla )
152 115
153int __init atari_parse_bootinfo(const struct bi_record *record) 116int __init atari_parse_bootinfo(const struct bi_record *record)
154{ 117{
155 int unknown = 0; 118 int unknown = 0;
156 const u_long *data = record->data; 119 const u_long *data = record->data;
157 120
158 switch (record->tag) { 121 switch (record->tag) {
159 case BI_ATARI_MCH_COOKIE: 122 case BI_ATARI_MCH_COOKIE:
160 atari_mch_cookie = *data; 123 atari_mch_cookie = *data;
161 break; 124 break;
162 case BI_ATARI_MCH_TYPE: 125 case BI_ATARI_MCH_TYPE:
163 atari_mch_type = *data; 126 atari_mch_type = *data;
164 break; 127 break;
165 default: 128 default:
166 unknown = 1; 129 unknown = 1;
167 } 130 break;
168 return(unknown); 131 }
132 return unknown;
169} 133}
170 134
171 135
172/* Parse the Atari-specific switches= option. */ 136/* Parse the Atari-specific switches= option. */
173void __init atari_switches_setup( const char *str, unsigned len ) 137static int __init atari_switches_setup(char *str)
174{ 138{
175 char switches[len+1]; 139 char switches[strlen(str) + 1];
176 char *p; 140 char *p;
177 int ovsc_shift; 141 int ovsc_shift;
178 char *args = switches; 142 char *args = switches;
179 143
180 /* copy string to local array, strsep works destructively... */ 144 if (!MACH_IS_ATARI)
181 strlcpy( switches, str, sizeof(switches) ); 145 return 0;
182 atari_switches = 0; 146
183 147 /* copy string to local array, strsep works destructively... */
184 /* parse the options */ 148 strcpy(switches, str);
185 while ((p = strsep(&args, ",")) != NULL) { 149 atari_switches = 0;
186 if (!*p) continue; 150
187 ovsc_shift = 0; 151 /* parse the options */
188 if (strncmp( p, "ov_", 3 ) == 0) { 152 while ((p = strsep(&args, ",")) != NULL) {
189 p += 3; 153 if (!*p)
190 ovsc_shift = ATARI_SWITCH_OVSC_SHIFT; 154 continue;
191 } 155 ovsc_shift = 0;
192 156 if (strncmp(p, "ov_", 3) == 0) {
193 if (strcmp( p, "ikbd" ) == 0) { 157 p += 3;
194 /* RTS line of IKBD ACIA */ 158 ovsc_shift = ATARI_SWITCH_OVSC_SHIFT;
195 atari_switches |= ATARI_SWITCH_IKBD << ovsc_shift; 159 }
196 } 160
197 else if (strcmp( p, "midi" ) == 0) { 161 if (strcmp(p, "ikbd") == 0) {
198 /* RTS line of MIDI ACIA */ 162 /* RTS line of IKBD ACIA */
199 atari_switches |= ATARI_SWITCH_MIDI << ovsc_shift; 163 atari_switches |= ATARI_SWITCH_IKBD << ovsc_shift;
164 } else if (strcmp(p, "midi") == 0) {
165 /* RTS line of MIDI ACIA */
166 atari_switches |= ATARI_SWITCH_MIDI << ovsc_shift;
167 } else if (strcmp(p, "snd6") == 0) {
168 atari_switches |= ATARI_SWITCH_SND6 << ovsc_shift;
169 } else if (strcmp(p, "snd7") == 0) {
170 atari_switches |= ATARI_SWITCH_SND7 << ovsc_shift;
171 }
200 } 172 }
201 else if (strcmp( p, "snd6" ) == 0) { 173 return 0;
202 atari_switches |= ATARI_SWITCH_SND6 << ovsc_shift;
203 }
204 else if (strcmp( p, "snd7" ) == 0) {
205 atari_switches |= ATARI_SWITCH_SND7 << ovsc_shift;
206 }
207 }
208} 174}
209 175
176early_param("switches", atari_switches_setup);
177
210 178
211 /* 179 /*
212 * Setup the Atari configuration info 180 * Setup the Atari configuration info
@@ -214,284 +182,281 @@ void __init atari_switches_setup( const char *str, unsigned len )
214 182
215void __init config_atari(void) 183void __init config_atari(void)
216{ 184{
217 unsigned short tos_version; 185 unsigned short tos_version;
218 186
219 memset(&atari_hw_present, 0, sizeof(atari_hw_present)); 187 memset(&atari_hw_present, 0, sizeof(atari_hw_present));
220 188
221 atari_debug_init(); 189 /* Change size of I/O space from 64KB to 4GB. */
190 ioport_resource.end = 0xFFFFFFFF;
222 191
223 ioport_resource.end = 0xFFFFFFFF; /* Change size of I/O space from 64KB 192 mach_sched_init = atari_sched_init;
224 to 4GB. */ 193 mach_init_IRQ = atari_init_IRQ;
225 194 mach_get_model = atari_get_model;
226 mach_sched_init = atari_sched_init; 195 mach_get_hardware_list = atari_get_hardware_list;
227 mach_init_IRQ = atari_init_IRQ; 196 mach_gettimeoffset = atari_gettimeoffset;
228 mach_get_model = atari_get_model; 197 mach_reset = atari_reset;
229 mach_get_hardware_list = atari_get_hardware_list; 198 mach_max_dma_address = 0xffffff;
230 mach_gettimeoffset = atari_gettimeoffset;
231 mach_reset = atari_reset;
232 mach_max_dma_address = 0xffffff;
233#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE) 199#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
234 mach_beep = atari_mksound; 200 mach_beep = atari_mksound;
235#endif 201#endif
236#ifdef CONFIG_HEARTBEAT 202#ifdef CONFIG_HEARTBEAT
237 mach_heartbeat = atari_heartbeat; 203 mach_heartbeat = atari_heartbeat;
238#endif 204#endif
239 205
240 /* Set switches as requested by the user */ 206 /* Set switches as requested by the user */
241 if (atari_switches & ATARI_SWITCH_IKBD) 207 if (atari_switches & ATARI_SWITCH_IKBD)
242 acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID; 208 acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID;
243 if (atari_switches & ATARI_SWITCH_MIDI) 209 if (atari_switches & ATARI_SWITCH_MIDI)
244 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID; 210 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
245 if (atari_switches & (ATARI_SWITCH_SND6|ATARI_SWITCH_SND7)) { 211 if (atari_switches & (ATARI_SWITCH_SND6|ATARI_SWITCH_SND7)) {
246 sound_ym.rd_data_reg_sel = 14; 212 sound_ym.rd_data_reg_sel = 14;
247 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 213 sound_ym.wd_data = sound_ym.rd_data_reg_sel |
248 ((atari_switches&ATARI_SWITCH_SND6) ? 0x40 : 0) | 214 ((atari_switches&ATARI_SWITCH_SND6) ? 0x40 : 0) |
249 ((atari_switches&ATARI_SWITCH_SND7) ? 0x80 : 0); 215 ((atari_switches&ATARI_SWITCH_SND7) ? 0x80 : 0);
250 } 216 }
251
252 /* ++bjoern:
253 * Determine hardware present
254 */
255 217
256 printk( "Atari hardware found: " ); 218 /* ++bjoern:
257 if (MACH_IS_MEDUSA || MACH_IS_HADES) { 219 * Determine hardware present
258 /* There's no Atari video hardware on the Medusa, but all the 220 */
259 * addresses below generate a DTACK so no bus error occurs! */ 221
260 } 222 printk("Atari hardware found: ");
261 else if (hwreg_present( f030_xreg )) { 223 if (MACH_IS_MEDUSA || MACH_IS_HADES) {
262 ATARIHW_SET(VIDEL_SHIFTER); 224 /* There's no Atari video hardware on the Medusa, but all the
263 printk( "VIDEL " ); 225 * addresses below generate a DTACK so no bus error occurs! */
264 /* This is a temporary hack: If there is Falcon video 226 } else if (hwreg_present(f030_xreg)) {
265 * hardware, we assume that the ST-DMA serves SCSI instead of 227 ATARIHW_SET(VIDEL_SHIFTER);
266 * ACSI. In the future, there should be a better method for 228 printk("VIDEL ");
267 * this... 229 /* This is a temporary hack: If there is Falcon video
268 */ 230 * hardware, we assume that the ST-DMA serves SCSI instead of
269 ATARIHW_SET(ST_SCSI); 231 * ACSI. In the future, there should be a better method for
270 printk( "STDMA-SCSI " ); 232 * this...
271 } 233 */
272 else if (hwreg_present( tt_palette )) { 234 ATARIHW_SET(ST_SCSI);
273 ATARIHW_SET(TT_SHIFTER); 235 printk("STDMA-SCSI ");
274 printk( "TT_SHIFTER " ); 236 } else if (hwreg_present(tt_palette)) {
275 } 237 ATARIHW_SET(TT_SHIFTER);
276 else if (hwreg_present( &shifter.bas_hi )) { 238 printk("TT_SHIFTER ");
277 if (hwreg_present( &shifter.bas_lo ) && 239 } else if (hwreg_present(&shifter.bas_hi)) {
278 (shifter.bas_lo = 0x0aau, shifter.bas_lo == 0x0aau)) { 240 if (hwreg_present(&shifter.bas_lo) &&
279 ATARIHW_SET(EXTD_SHIFTER); 241 (shifter.bas_lo = 0x0aau, shifter.bas_lo == 0x0aau)) {
280 printk( "EXTD_SHIFTER " ); 242 ATARIHW_SET(EXTD_SHIFTER);
281 } 243 printk("EXTD_SHIFTER ");
282 else { 244 } else {
283 ATARIHW_SET(STND_SHIFTER); 245 ATARIHW_SET(STND_SHIFTER);
284 printk( "STND_SHIFTER " ); 246 printk("STND_SHIFTER ");
285 } 247 }
286 } 248 }
287 if (hwreg_present( &mfp.par_dt_reg )) { 249 if (hwreg_present(&mfp.par_dt_reg)) {
288 ATARIHW_SET(ST_MFP); 250 ATARIHW_SET(ST_MFP);
289 printk( "ST_MFP " ); 251 printk("ST_MFP ");
290 } 252 }
291 if (hwreg_present( &tt_mfp.par_dt_reg )) { 253 if (hwreg_present(&tt_mfp.par_dt_reg)) {
292 ATARIHW_SET(TT_MFP); 254 ATARIHW_SET(TT_MFP);
293 printk( "TT_MFP " ); 255 printk("TT_MFP ");
294 } 256 }
295 if (hwreg_present( &tt_scsi_dma.dma_addr_hi )) { 257 if (hwreg_present(&tt_scsi_dma.dma_addr_hi)) {
296 ATARIHW_SET(SCSI_DMA); 258 ATARIHW_SET(SCSI_DMA);
297 printk( "TT_SCSI_DMA " ); 259 printk("TT_SCSI_DMA ");
298 } 260 }
299 if (!MACH_IS_HADES && hwreg_present( &st_dma.dma_hi )) { 261 if (!MACH_IS_HADES && hwreg_present(&st_dma.dma_hi)) {
300 ATARIHW_SET(STND_DMA); 262 ATARIHW_SET(STND_DMA);
301 printk( "STND_DMA " ); 263 printk("STND_DMA ");
302 } 264 }
303 if (MACH_IS_MEDUSA || /* The ST-DMA address registers aren't readable 265 /*
304 * on all Medusas, so the test below may fail */ 266 * The ST-DMA address registers aren't readable
305 (hwreg_present( &st_dma.dma_vhi ) && 267 * on all Medusas, so the test below may fail
306 (st_dma.dma_vhi = 0x55) && (st_dma.dma_hi = 0xaa) && 268 */
307 st_dma.dma_vhi == 0x55 && st_dma.dma_hi == 0xaa && 269 if (MACH_IS_MEDUSA ||
308 (st_dma.dma_vhi = 0xaa) && (st_dma.dma_hi = 0x55) && 270 (hwreg_present(&st_dma.dma_vhi) &&
309 st_dma.dma_vhi == 0xaa && st_dma.dma_hi == 0x55)) { 271 (st_dma.dma_vhi = 0x55) && (st_dma.dma_hi = 0xaa) &&
310 ATARIHW_SET(EXTD_DMA); 272 st_dma.dma_vhi == 0x55 && st_dma.dma_hi == 0xaa &&
311 printk( "EXTD_DMA " ); 273 (st_dma.dma_vhi = 0xaa) && (st_dma.dma_hi = 0x55) &&
312 } 274 st_dma.dma_vhi == 0xaa && st_dma.dma_hi == 0x55)) {
313 if (hwreg_present( &tt_scsi.scsi_data )) { 275 ATARIHW_SET(EXTD_DMA);
314 ATARIHW_SET(TT_SCSI); 276 printk("EXTD_DMA ");
315 printk( "TT_SCSI " ); 277 }
316 } 278 if (hwreg_present(&tt_scsi.scsi_data)) {
317 if (hwreg_present( &sound_ym.rd_data_reg_sel )) { 279 ATARIHW_SET(TT_SCSI);
318 ATARIHW_SET(YM_2149); 280 printk("TT_SCSI ");
319 printk( "YM2149 " ); 281 }
320 } 282 if (hwreg_present(&sound_ym.rd_data_reg_sel)) {
321 if (!MACH_IS_MEDUSA && !MACH_IS_HADES && 283 ATARIHW_SET(YM_2149);
322 hwreg_present( &tt_dmasnd.ctrl )) { 284 printk("YM2149 ");
323 ATARIHW_SET(PCM_8BIT); 285 }
324 printk( "PCM " ); 286 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
325 } 287 hwreg_present(&tt_dmasnd.ctrl)) {
326 if (!MACH_IS_HADES && hwreg_present( &falcon_codec.unused5 )) { 288 ATARIHW_SET(PCM_8BIT);
327 ATARIHW_SET(CODEC); 289 printk("PCM ");
328 printk( "CODEC " ); 290 }
329 } 291 if (!MACH_IS_HADES && hwreg_present(&falcon_codec.unused5)) {
330 if (hwreg_present( &dsp56k_host_interface.icr )) { 292 ATARIHW_SET(CODEC);
331 ATARIHW_SET(DSP56K); 293 printk("CODEC ");
332 printk( "DSP56K " ); 294 }
333 } 295 if (hwreg_present(&dsp56k_host_interface.icr)) {
334 if (hwreg_present( &tt_scc_dma.dma_ctrl ) && 296 ATARIHW_SET(DSP56K);
297 printk("DSP56K ");
298 }
299 if (hwreg_present(&tt_scc_dma.dma_ctrl) &&
335#if 0 300#if 0
336 /* This test sucks! Who knows some better? */ 301 /* This test sucks! Who knows some better? */
337 (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) && 302 (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) &&
338 (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0) 303 (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0)
339#else 304#else
340 !MACH_IS_MEDUSA && !MACH_IS_HADES 305 !MACH_IS_MEDUSA && !MACH_IS_HADES
341#endif 306#endif
342 ) { 307 ) {
343 ATARIHW_SET(SCC_DMA); 308 ATARIHW_SET(SCC_DMA);
344 printk( "SCC_DMA " ); 309 printk("SCC_DMA ");
345 } 310 }
346 if (scc_test( &scc.cha_a_ctrl )) { 311 if (scc_test(&scc.cha_a_ctrl)) {
347 ATARIHW_SET(SCC); 312 ATARIHW_SET(SCC);
348 printk( "SCC " ); 313 printk("SCC ");
349 } 314 }
350 if (scc_test( &st_escc.cha_b_ctrl )) { 315 if (scc_test(&st_escc.cha_b_ctrl)) {
351 ATARIHW_SET( ST_ESCC ); 316 ATARIHW_SET(ST_ESCC);
352 printk( "ST_ESCC " ); 317 printk("ST_ESCC ");
353 } 318 }
354 if (MACH_IS_HADES) 319 if (MACH_IS_HADES) {
355 { 320 ATARIHW_SET(VME);
356 ATARIHW_SET( VME ); 321 printk("VME ");
357 printk( "VME " ); 322 } else if (hwreg_present(&tt_scu.sys_mask)) {
358 } 323 ATARIHW_SET(SCU);
359 else if (hwreg_present( &tt_scu.sys_mask )) { 324 /* Assume a VME bus if there's a SCU */
360 ATARIHW_SET(SCU); 325 ATARIHW_SET(VME);
361 /* Assume a VME bus if there's a SCU */ 326 printk("VME SCU ");
362 ATARIHW_SET( VME ); 327 }
363 printk( "VME SCU " ); 328 if (hwreg_present((void *)(0xffff9210))) {
364 } 329 ATARIHW_SET(ANALOG_JOY);
365 if (hwreg_present( (void *)(0xffff9210) )) { 330 printk("ANALOG_JOY ");
366 ATARIHW_SET(ANALOG_JOY); 331 }
367 printk( "ANALOG_JOY " ); 332 if (!MACH_IS_HADES && hwreg_present(blitter.halftone)) {
368 } 333 ATARIHW_SET(BLITTER);
369 if (!MACH_IS_HADES && hwreg_present( blitter.halftone )) { 334 printk("BLITTER ");
370 ATARIHW_SET(BLITTER); 335 }
371 printk( "BLITTER " ); 336 if (hwreg_present((void *)0xfff00039)) {
372 } 337 ATARIHW_SET(IDE);
373 if (hwreg_present((void *)0xfff00039)) { 338 printk("IDE ");
374 ATARIHW_SET(IDE); 339 }
375 printk( "IDE " );
376 }
377#if 1 /* This maybe wrong */ 340#if 1 /* This maybe wrong */
378 if (!MACH_IS_MEDUSA && !MACH_IS_HADES && 341 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
379 hwreg_present( &tt_microwire.data ) && 342 hwreg_present(&tt_microwire.data) &&
380 hwreg_present( &tt_microwire.mask ) && 343 hwreg_present(&tt_microwire.mask) &&
381 (tt_microwire.mask = 0x7ff, 344 (tt_microwire.mask = 0x7ff,
382 udelay(1), 345 udelay(1),
383 tt_microwire.data = MW_LM1992_PSG_HIGH | MW_LM1992_ADDR, 346 tt_microwire.data = MW_LM1992_PSG_HIGH | MW_LM1992_ADDR,
384 udelay(1), 347 udelay(1),
385 tt_microwire.data != 0)) { 348 tt_microwire.data != 0)) {
386 ATARIHW_SET(MICROWIRE); 349 ATARIHW_SET(MICROWIRE);
387 while (tt_microwire.mask != 0x7ff) ; 350 while (tt_microwire.mask != 0x7ff)
388 printk( "MICROWIRE " ); 351 ;
389 } 352 printk("MICROWIRE ");
353 }
390#endif 354#endif
391 if (hwreg_present( &tt_rtc.regsel )) { 355 if (hwreg_present(&tt_rtc.regsel)) {
392 ATARIHW_SET(TT_CLK); 356 ATARIHW_SET(TT_CLK);
393 printk( "TT_CLK " ); 357 printk("TT_CLK ");
394 mach_hwclk = atari_tt_hwclk; 358 mach_hwclk = atari_tt_hwclk;
395 mach_set_clock_mmss = atari_tt_set_clock_mmss; 359 mach_set_clock_mmss = atari_tt_set_clock_mmss;
396 } 360 }
397 if (!MACH_IS_HADES && hwreg_present( &mste_rtc.sec_ones)) { 361 if (!MACH_IS_HADES && hwreg_present(&mste_rtc.sec_ones)) {
398 ATARIHW_SET(MSTE_CLK); 362 ATARIHW_SET(MSTE_CLK);
399 printk( "MSTE_CLK "); 363 printk("MSTE_CLK ");
400 mach_hwclk = atari_mste_hwclk; 364 mach_hwclk = atari_mste_hwclk;
401 mach_set_clock_mmss = atari_mste_set_clock_mmss; 365 mach_set_clock_mmss = atari_mste_set_clock_mmss;
402 } 366 }
403 if (!MACH_IS_MEDUSA && !MACH_IS_HADES && 367 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
404 hwreg_present( &dma_wd.fdc_speed ) && 368 hwreg_present(&dma_wd.fdc_speed) &&
405 hwreg_write( &dma_wd.fdc_speed, 0 )) { 369 hwreg_write(&dma_wd.fdc_speed, 0)) {
406 ATARIHW_SET(FDCSPEED); 370 ATARIHW_SET(FDCSPEED);
407 printk( "FDC_SPEED "); 371 printk("FDC_SPEED ");
408 } 372 }
409 if (!MACH_IS_HADES && !ATARIHW_PRESENT(ST_SCSI)) { 373 if (!MACH_IS_HADES && !ATARIHW_PRESENT(ST_SCSI)) {
410 ATARIHW_SET(ACSI); 374 ATARIHW_SET(ACSI);
411 printk( "ACSI " ); 375 printk("ACSI ");
412 } 376 }
413 printk("\n"); 377 printk("\n");
414 378
415 if (CPU_IS_040_OR_060) 379 if (CPU_IS_040_OR_060)
416 /* Now it seems to be safe to turn of the tt0 transparent 380 /* Now it seems to be safe to turn of the tt0 transparent
417 * translation (the one that must not be turned off in 381 * translation (the one that must not be turned off in
418 * head.S...) 382 * head.S...)
419 */ 383 */
420 __asm__ volatile ("moveq #0,%/d0\n\t" 384 asm volatile ("\n"
421 ".chip 68040\n\t" 385 " moveq #0,%%d0\n"
422 "movec %%d0,%%itt0\n\t" 386 " .chip 68040\n"
423 "movec %%d0,%%dtt0\n\t" 387 " movec %%d0,%%itt0\n"
424 ".chip 68k" 388 " movec %%d0,%%dtt0\n"
425 : /* no outputs */ 389 " .chip 68k"
426 : /* no inputs */ 390 : /* no outputs */
427 : "d0"); 391 : /* no inputs */
428 392 : "d0");
429 /* allocator for memory that must reside in st-ram */ 393
430 atari_stram_init (); 394 /* allocator for memory that must reside in st-ram */
431 395 atari_stram_init();
432 /* Set up a mapping for the VMEbus address region: 396
433 * 397 /* Set up a mapping for the VMEbus address region:
434 * VME is either at phys. 0xfexxxxxx (TT) or 0xa00000..0xdfffff 398 *
435 * (MegaSTE) In both cases, the whole 16 MB chunk is mapped at 399 * VME is either at phys. 0xfexxxxxx (TT) or 0xa00000..0xdfffff
436 * 0xfe000000 virt., because this can be done with a single 400 * (MegaSTE) In both cases, the whole 16 MB chunk is mapped at
437 * transparent translation. On the 68040, lots of often unused 401 * 0xfe000000 virt., because this can be done with a single
438 * page tables would be needed otherwise. On a MegaSTE or similar, 402 * transparent translation. On the 68040, lots of often unused
439 * the highest byte is stripped off by hardware due to the 24 bit 403 * page tables would be needed otherwise. On a MegaSTE or similar,
440 * design of the bus. 404 * the highest byte is stripped off by hardware due to the 24 bit
441 */ 405 * design of the bus.
406 */
407
408 if (CPU_IS_020_OR_030) {
409 unsigned long tt1_val;
410 tt1_val = 0xfe008543; /* Translate 0xfexxxxxx, enable, cache
411 * inhibit, read and write, FDC mask = 3,
412 * FDC val = 4 -> Supervisor only */
413 asm volatile ("\n"
414 " .chip 68030\n"
415 " pmove %0@,%/tt1\n"
416 " .chip 68k"
417 : : "a" (&tt1_val));
418 } else {
419 asm volatile ("\n"
420 " .chip 68040\n"
421 " movec %0,%%itt1\n"
422 " movec %0,%%dtt1\n"
423 " .chip 68k"
424 :
425 : "d" (0xfe00a040)); /* Translate 0xfexxxxxx, enable,
426 * supervisor only, non-cacheable/
427 * serialized, writable */
428
429 }
442 430
443 if (CPU_IS_020_OR_030) { 431 /* Fetch tos version at Physical 2 */
444 unsigned long tt1_val; 432 /*
445 tt1_val = 0xfe008543; /* Translate 0xfexxxxxx, enable, cache 433 * We my not be able to access this address if the kernel is
446 * inhibit, read and write, FDC mask = 3, 434 * loaded to st ram, since the first page is unmapped. On the
447 * FDC val = 4 -> Supervisor only */ 435 * Medusa this is always the case and there is nothing we can do
448 __asm__ __volatile__ ( ".chip 68030\n\t" 436 * about this, so we just assume the smaller offset. For the TT
449 "pmove %0@,%/tt1\n\t" 437 * we use the fact that in head.S we have set up a mapping
450 ".chip 68k" 438 * 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible
451 : : "a" (&tt1_val) ); 439 * in the last 16MB of the address space.
452 } 440 */
453 else { 441 tos_version = (MACH_IS_MEDUSA || MACH_IS_HADES) ?
454 __asm__ __volatile__ 442 0xfff : *(unsigned short *)0xff000002;
455 ( "movel %0,%/d0\n\t" 443 atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68;
456 ".chip 68040\n\t"
457 "movec %%d0,%%itt1\n\t"
458 "movec %%d0,%%dtt1\n\t"
459 ".chip 68k"
460 :
461 : "g" (0xfe00a040) /* Translate 0xfexxxxxx, enable,
462 * supervisor only, non-cacheable/
463 * serialized, writable */
464 : "d0" );
465
466 }
467
468 /* Fetch tos version at Physical 2 */
469 /* We my not be able to access this address if the kernel is
470 loaded to st ram, since the first page is unmapped. On the
471 Medusa this is always the case and there is nothing we can do
472 about this, so we just assume the smaller offset. For the TT
473 we use the fact that in head.S we have set up a mapping
474 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible
475 in the last 16MB of the address space. */
476 tos_version = (MACH_IS_MEDUSA || MACH_IS_HADES) ?
477 0xfff : *(unsigned short *)0xff000002;
478 atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68;
479} 444}
480 445
481#ifdef CONFIG_HEARTBEAT 446#ifdef CONFIG_HEARTBEAT
482static void atari_heartbeat( int on ) 447static void atari_heartbeat(int on)
483{ 448{
484 unsigned char tmp; 449 unsigned char tmp;
485 unsigned long flags; 450 unsigned long flags;
486 451
487 if (atari_dont_touch_floppy_select) 452 if (atari_dont_touch_floppy_select)
488 return; 453 return;
489 454
490 local_irq_save(flags); 455 local_irq_save(flags);
491 sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */ 456 sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
492 tmp = sound_ym.rd_data_reg_sel; 457 tmp = sound_ym.rd_data_reg_sel;
493 sound_ym.wd_data = on ? (tmp & ~0x02) : (tmp | 0x02); 458 sound_ym.wd_data = on ? (tmp & ~0x02) : (tmp | 0x02);
494 local_irq_restore(flags); 459 local_irq_restore(flags);
495} 460}
496#endif 461#endif
497 462
@@ -526,180 +491,171 @@ static void atari_heartbeat( int on )
526 491
527/* ++andreas: no need for complicated code, just depend on prefetch */ 492/* ++andreas: no need for complicated code, just depend on prefetch */
528 493
529static void atari_reset (void) 494static void atari_reset(void)
530{ 495{
531 long tc_val = 0; 496 long tc_val = 0;
532 long reset_addr; 497 long reset_addr;
533 498
534 /* On the Medusa, phys. 0x4 may contain garbage because it's no 499 /*
535 ROM. See above for explanation why we cannot use PTOV(4). */ 500 * On the Medusa, phys. 0x4 may contain garbage because it's no
536 reset_addr = MACH_IS_HADES ? 0x7fe00030 : 501 * ROM. See above for explanation why we cannot use PTOV(4).
537 MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 : 502 */
538 *(unsigned long *) 0xff000004; 503 reset_addr = MACH_IS_HADES ? 0x7fe00030 :
539 504 MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 :
540 /* reset ACIA for switch off OverScan, if it's active */ 505 *(unsigned long *) 0xff000004;
541 if (atari_switches & ATARI_SWITCH_OVSC_IKBD) 506
542 acia.key_ctrl = ACIA_RESET; 507 /* reset ACIA for switch off OverScan, if it's active */
543 if (atari_switches & ATARI_SWITCH_OVSC_MIDI) 508 if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
544 acia.mid_ctrl = ACIA_RESET; 509 acia.key_ctrl = ACIA_RESET;
545 510 if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
546 /* processor independent: turn off interrupts and reset the VBR; 511 acia.mid_ctrl = ACIA_RESET;
547 * the caches must be left enabled, else prefetching the final jump 512
548 * instruction doesn't work. */ 513 /* processor independent: turn off interrupts and reset the VBR;
549 local_irq_disable(); 514 * the caches must be left enabled, else prefetching the final jump
550 __asm__ __volatile__ 515 * instruction doesn't work.
551 ("moveq #0,%/d0\n\t" 516 */
552 "movec %/d0,%/vbr" 517 local_irq_disable();
553 : : : "d0" ); 518 asm volatile ("movec %0,%%vbr"
554 519 : : "d" (0));
555 if (CPU_IS_040_OR_060) { 520
556 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040); 521 if (CPU_IS_040_OR_060) {
557 if (CPU_IS_060) { 522 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
558 /* 68060: clear PCR to turn off superscalar operation */ 523 if (CPU_IS_060) {
559 __asm__ __volatile__ 524 /* 68060: clear PCR to turn off superscalar operation */
560 ("moveq #0,%/d0\n\t" 525 asm volatile ("\n"
561 ".chip 68060\n\t" 526 " .chip 68060\n"
562 "movec %%d0,%%pcr\n\t" 527 " movec %0,%%pcr\n"
563 ".chip 68k" 528 " .chip 68k"
564 : : : "d0" ); 529 : : "d" (0));
565 } 530 }
566 531
567 __asm__ __volatile__ 532 asm volatile ("\n"
568 ("movel %0,%/d0\n\t" 533 " move.l %0,%%d0\n"
569 "andl #0xff000000,%/d0\n\t" 534 " and.l #0xff000000,%%d0\n"
570 "orw #0xe020,%/d0\n\t" /* map 16 MB, enable, cacheable */ 535 " or.w #0xe020,%%d0\n" /* map 16 MB, enable, cacheable */
571 ".chip 68040\n\t" 536 " .chip 68040\n"
572 "movec %%d0,%%itt0\n\t" 537 " movec %%d0,%%itt0\n"
573 "movec %%d0,%%dtt0\n\t" 538 " movec %%d0,%%dtt0\n"
574 ".chip 68k\n\t" 539 " .chip 68k\n"
575 "jmp %0@\n\t" 540 " jmp %0@"
576 : /* no outputs */ 541 : : "a" (jmp_addr040)
577 : "a" (jmp_addr040) 542 : "d0");
578 : "d0" ); 543 jmp_addr_label040:
579 jmp_addr_label040: 544 asm volatile ("\n"
580 __asm__ __volatile__ 545 " moveq #0,%%d0\n"
581 ("moveq #0,%/d0\n\t" 546 " nop\n"
582 "nop\n\t" 547 " .chip 68040\n"
583 ".chip 68040\n\t" 548 " cinva %%bc\n"
584 "cinva %%bc\n\t" 549 " nop\n"
585 "nop\n\t" 550 " pflusha\n"
586 "pflusha\n\t" 551 " nop\n"
587 "nop\n\t" 552 " movec %%d0,%%tc\n"
588 "movec %%d0,%%tc\n\t" 553 " nop\n"
589 "nop\n\t" 554 /* the following setup of transparent translations is needed on the
590 /* the following setup of transparent translations is needed on the 555 * Afterburner040 to successfully reboot. Other machines shouldn't
591 * Afterburner040 to successfully reboot. Other machines shouldn't 556 * care about a different tt regs setup, they also didn't care in
592 * care about a different tt regs setup, they also didn't care in 557 * the past that the regs weren't turned off. */
593 * the past that the regs weren't turned off. */ 558 " move.l #0xffc000,%%d0\n" /* whole insn space cacheable */
594 "movel #0xffc000,%%d0\n\t" /* whole insn space cacheable */ 559 " movec %%d0,%%itt0\n"
595 "movec %%d0,%%itt0\n\t" 560 " movec %%d0,%%itt1\n"
596 "movec %%d0,%%itt1\n\t" 561 " or.w #0x40,%/d0\n" /* whole data space non-cacheable/ser. */
597 "orw #0x40,%/d0\n\t" /* whole data space non-cacheable/ser. */ 562 " movec %%d0,%%dtt0\n"
598 "movec %%d0,%%dtt0\n\t" 563 " movec %%d0,%%dtt1\n"
599 "movec %%d0,%%dtt1\n\t" 564 " .chip 68k\n"
600 ".chip 68k\n\t" 565 " jmp %0@"
601 "jmp %0@" 566 : /* no outputs */
602 : /* no outputs */ 567 : "a" (reset_addr)
603 : "a" (reset_addr) 568 : "d0");
604 : "d0"); 569 } else
605 } 570 asm volatile ("\n"
606 else 571 " pmove %0@,%%tc\n"
607 __asm__ __volatile__ 572 " jmp %1@"
608 ("pmove %0@,%/tc\n\t" 573 : /* no outputs */
609 "jmp %1@" 574 : "a" (&tc_val), "a" (reset_addr));
610 : /* no outputs */
611 : "a" (&tc_val), "a" (reset_addr));
612} 575}
613 576
614 577
615static void atari_get_model(char *model) 578static void atari_get_model(char *model)
616{ 579{
617 strcpy(model, "Atari "); 580 strcpy(model, "Atari ");
618 switch (atari_mch_cookie >> 16) { 581 switch (atari_mch_cookie >> 16) {
619 case ATARI_MCH_ST: 582 case ATARI_MCH_ST:
620 if (ATARIHW_PRESENT(MSTE_CLK)) 583 if (ATARIHW_PRESENT(MSTE_CLK))
621 strcat (model, "Mega ST"); 584 strcat(model, "Mega ST");
622 else 585 else
623 strcat (model, "ST"); 586 strcat(model, "ST");
624 break; 587 break;
625 case ATARI_MCH_STE: 588 case ATARI_MCH_STE:
626 if (MACH_IS_MSTE) 589 if (MACH_IS_MSTE)
627 strcat (model, "Mega STE"); 590 strcat(model, "Mega STE");
628 else 591 else
629 strcat (model, "STE"); 592 strcat(model, "STE");
630 break; 593 break;
631 case ATARI_MCH_TT: 594 case ATARI_MCH_TT:
632 if (MACH_IS_MEDUSA) 595 if (MACH_IS_MEDUSA)
633 /* Medusa has TT _MCH cookie */ 596 /* Medusa has TT _MCH cookie */
634 strcat (model, "Medusa"); 597 strcat(model, "Medusa");
635 else if (MACH_IS_HADES) 598 else if (MACH_IS_HADES)
636 strcat(model, "Hades"); 599 strcat(model, "Hades");
637 else 600 else
638 strcat (model, "TT"); 601 strcat(model, "TT");
639 break; 602 break;
640 case ATARI_MCH_FALCON: 603 case ATARI_MCH_FALCON:
641 strcat (model, "Falcon"); 604 strcat(model, "Falcon");
642 if (MACH_IS_AB40) 605 if (MACH_IS_AB40)
643 strcat (model, " (with Afterburner040)"); 606 strcat(model, " (with Afterburner040)");
644 break; 607 break;
645 default: 608 default:
646 sprintf (model + strlen (model), "(unknown mach cookie 0x%lx)", 609 sprintf(model + strlen(model), "(unknown mach cookie 0x%lx)",
647 atari_mch_cookie); 610 atari_mch_cookie);
648 break; 611 break;
649 } 612 }
650} 613}
651 614
652 615
653static int atari_get_hardware_list(char *buffer) 616static int atari_get_hardware_list(char *buffer)
654{ 617{
655 int len = 0, i; 618 int len = 0, i;
656 619
657 for (i = 0; i < m68k_num_memory; i++) 620 for (i = 0; i < m68k_num_memory; i++)
658 len += sprintf (buffer+len, "\t%3ld MB at 0x%08lx (%s)\n", 621 len += sprintf(buffer+len, "\t%3ld MB at 0x%08lx (%s)\n",
659 m68k_memory[i].size >> 20, m68k_memory[i].addr, 622 m68k_memory[i].size >> 20, m68k_memory[i].addr,
660 (m68k_memory[i].addr & 0xff000000 ? 623 (m68k_memory[i].addr & 0xff000000 ?
661 "alternate RAM" : "ST-RAM")); 624 "alternate RAM" : "ST-RAM"));
662 625
663#define ATARIHW_ANNOUNCE(name,str) \ 626#define ATARIHW_ANNOUNCE(name, str) \
664 if (ATARIHW_PRESENT(name)) \ 627 if (ATARIHW_PRESENT(name)) \
665 len += sprintf (buffer + len, "\t%s\n", str) 628 len += sprintf(buffer + len, "\t%s\n", str)
666 629
667 len += sprintf (buffer + len, "Detected hardware:\n"); 630 len += sprintf(buffer + len, "Detected hardware:\n");
668 ATARIHW_ANNOUNCE(STND_SHIFTER, "ST Shifter"); 631 ATARIHW_ANNOUNCE(STND_SHIFTER, "ST Shifter");
669 ATARIHW_ANNOUNCE(EXTD_SHIFTER, "STe Shifter"); 632 ATARIHW_ANNOUNCE(EXTD_SHIFTER, "STe Shifter");
670 ATARIHW_ANNOUNCE(TT_SHIFTER, "TT Shifter"); 633 ATARIHW_ANNOUNCE(TT_SHIFTER, "TT Shifter");
671 ATARIHW_ANNOUNCE(VIDEL_SHIFTER, "Falcon Shifter"); 634 ATARIHW_ANNOUNCE(VIDEL_SHIFTER, "Falcon Shifter");
672 ATARIHW_ANNOUNCE(YM_2149, "Programmable Sound Generator"); 635 ATARIHW_ANNOUNCE(YM_2149, "Programmable Sound Generator");
673 ATARIHW_ANNOUNCE(PCM_8BIT, "PCM 8 Bit Sound"); 636 ATARIHW_ANNOUNCE(PCM_8BIT, "PCM 8 Bit Sound");
674 ATARIHW_ANNOUNCE(CODEC, "CODEC Sound"); 637 ATARIHW_ANNOUNCE(CODEC, "CODEC Sound");
675 ATARIHW_ANNOUNCE(TT_SCSI, "SCSI Controller NCR5380 (TT style)"); 638 ATARIHW_ANNOUNCE(TT_SCSI, "SCSI Controller NCR5380 (TT style)");
676 ATARIHW_ANNOUNCE(ST_SCSI, "SCSI Controller NCR5380 (Falcon style)"); 639 ATARIHW_ANNOUNCE(ST_SCSI, "SCSI Controller NCR5380 (Falcon style)");
677 ATARIHW_ANNOUNCE(ACSI, "ACSI Interface"); 640 ATARIHW_ANNOUNCE(ACSI, "ACSI Interface");
678 ATARIHW_ANNOUNCE(IDE, "IDE Interface"); 641 ATARIHW_ANNOUNCE(IDE, "IDE Interface");
679 ATARIHW_ANNOUNCE(FDCSPEED, "8/16 Mhz Switch for FDC"); 642 ATARIHW_ANNOUNCE(FDCSPEED, "8/16 Mhz Switch for FDC");
680 ATARIHW_ANNOUNCE(ST_MFP, "Multi Function Peripheral MFP 68901"); 643 ATARIHW_ANNOUNCE(ST_MFP, "Multi Function Peripheral MFP 68901");
681 ATARIHW_ANNOUNCE(TT_MFP, "Second Multi Function Peripheral MFP 68901"); 644 ATARIHW_ANNOUNCE(TT_MFP, "Second Multi Function Peripheral MFP 68901");
682 ATARIHW_ANNOUNCE(SCC, "Serial Communications Controller SCC 8530"); 645 ATARIHW_ANNOUNCE(SCC, "Serial Communications Controller SCC 8530");
683 ATARIHW_ANNOUNCE(ST_ESCC, "Extended Serial Communications Controller SCC 85230"); 646 ATARIHW_ANNOUNCE(ST_ESCC, "Extended Serial Communications Controller SCC 85230");
684 ATARIHW_ANNOUNCE(ANALOG_JOY, "Paddle Interface"); 647 ATARIHW_ANNOUNCE(ANALOG_JOY, "Paddle Interface");
685 ATARIHW_ANNOUNCE(MICROWIRE, "MICROWIRE(tm) Interface"); 648 ATARIHW_ANNOUNCE(MICROWIRE, "MICROWIRE(tm) Interface");
686 ATARIHW_ANNOUNCE(STND_DMA, "DMA Controller (24 bit)"); 649 ATARIHW_ANNOUNCE(STND_DMA, "DMA Controller (24 bit)");
687 ATARIHW_ANNOUNCE(EXTD_DMA, "DMA Controller (32 bit)"); 650 ATARIHW_ANNOUNCE(EXTD_DMA, "DMA Controller (32 bit)");
688 ATARIHW_ANNOUNCE(SCSI_DMA, "DMA Controller for NCR5380"); 651 ATARIHW_ANNOUNCE(SCSI_DMA, "DMA Controller for NCR5380");
689 ATARIHW_ANNOUNCE(SCC_DMA, "DMA Controller for SCC"); 652 ATARIHW_ANNOUNCE(SCC_DMA, "DMA Controller for SCC");
690 ATARIHW_ANNOUNCE(TT_CLK, "Clock Chip MC146818A"); 653 ATARIHW_ANNOUNCE(TT_CLK, "Clock Chip MC146818A");
691 ATARIHW_ANNOUNCE(MSTE_CLK, "Clock Chip RP5C15"); 654 ATARIHW_ANNOUNCE(MSTE_CLK, "Clock Chip RP5C15");
692 ATARIHW_ANNOUNCE(SCU, "System Control Unit"); 655 ATARIHW_ANNOUNCE(SCU, "System Control Unit");
693 ATARIHW_ANNOUNCE(BLITTER, "Blitter"); 656 ATARIHW_ANNOUNCE(BLITTER, "Blitter");
694 ATARIHW_ANNOUNCE(VME, "VME Bus"); 657 ATARIHW_ANNOUNCE(VME, "VME Bus");
695 ATARIHW_ANNOUNCE(DSP56K, "DSP56001 processor"); 658 ATARIHW_ANNOUNCE(DSP56K, "DSP56001 processor");
696 659
697 return(len); 660 return len;
698} 661}
699
700/*
701 * Local variables:
702 * c-indent-level: 4
703 * tab-width: 8
704 * End:
705 */
diff --git a/arch/m68k/atari/debug.c b/arch/m68k/atari/debug.c
index 4ae01004d8dd..fbeed8c8ecbc 100644
--- a/arch/m68k/atari/debug.c
+++ b/arch/m68k/atari/debug.c
@@ -19,8 +19,6 @@
19#include <asm/atarihw.h> 19#include <asm/atarihw.h>
20#include <asm/atariints.h> 20#include <asm/atariints.h>
21 21
22extern char m68k_debug_device[];
23
24/* Flag that Modem1 port is already initialized and used */ 22/* Flag that Modem1 port is already initialized and used */
25int atari_MFP_init_done; 23int atari_MFP_init_done;
26/* Flag that Modem1 port is already initialized and used */ 24/* Flag that Modem1 port is already initialized and used */
@@ -30,317 +28,317 @@ int atari_SCC_init_done;
30int atari_SCC_reset_done; 28int atari_SCC_reset_done;
31 29
32static struct console atari_console_driver = { 30static struct console atari_console_driver = {
33 .name = "debug", 31 .name = "debug",
34 .flags = CON_PRINTBUFFER, 32 .flags = CON_PRINTBUFFER,
35 .index = -1, 33 .index = -1,
36}; 34};
37 35
38 36
39static inline void ata_mfp_out (char c) 37static inline void ata_mfp_out(char c)
40{ 38{
41 while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */ 39 while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */
42 barrier (); 40 barrier();
43 mfp.usart_dta = c; 41 mfp.usart_dta = c;
44} 42}
45 43
46void atari_mfp_console_write (struct console *co, const char *str, 44void atari_mfp_console_write(struct console *co, const char *str,
47 unsigned int count) 45 unsigned int count)
48{ 46{
49 while (count--) { 47 while (count--) {
50 if (*str == '\n') 48 if (*str == '\n')
51 ata_mfp_out( '\r' ); 49 ata_mfp_out('\r');
52 ata_mfp_out( *str++ ); 50 ata_mfp_out(*str++);
53 } 51 }
54} 52}
55 53
56static inline void ata_scc_out (char c) 54static inline void ata_scc_out(char c)
57{ 55{
58 do { 56 do {
57 MFPDELAY();
58 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
59 MFPDELAY(); 59 MFPDELAY();
60 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */ 60 scc.cha_b_data = c;
61 MFPDELAY();
62 scc.cha_b_data = c;
63} 61}
64 62
65void atari_scc_console_write (struct console *co, const char *str, 63void atari_scc_console_write(struct console *co, const char *str,
66 unsigned int count) 64 unsigned int count)
67{ 65{
68 while (count--) { 66 while (count--) {
69 if (*str == '\n') 67 if (*str == '\n')
70 ata_scc_out( '\r' ); 68 ata_scc_out('\r');
71 ata_scc_out( *str++ ); 69 ata_scc_out(*str++);
72 } 70 }
73} 71}
74 72
75static inline void ata_midi_out (char c) 73static inline void ata_midi_out(char c)
76{ 74{
77 while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */ 75 while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */
78 barrier (); 76 barrier();
79 acia.mid_data = c; 77 acia.mid_data = c;
80} 78}
81 79
82void atari_midi_console_write (struct console *co, const char *str, 80void atari_midi_console_write(struct console *co, const char *str,
83 unsigned int count) 81 unsigned int count)
84{ 82{
85 while (count--) { 83 while (count--) {
86 if (*str == '\n') 84 if (*str == '\n')
87 ata_midi_out( '\r' ); 85 ata_midi_out('\r');
88 ata_midi_out( *str++ ); 86 ata_midi_out(*str++);
89 } 87 }
90} 88}
91 89
92static int ata_par_out (char c) 90static int ata_par_out(char c)
93{ 91{
94 unsigned char tmp; 92 unsigned char tmp;
95 /* This a some-seconds timeout in case no printer is connected */ 93 /* This a some-seconds timeout in case no printer is connected */
96 unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ; 94 unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ;
97 95
98 while( (mfp.par_dt_reg & 1) && --i ) /* wait for BUSY == L */ 96 while ((mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */
99 ; 97 ;
100 if (!i) return( 0 ); 98 if (!i)
101 99 return 0;
102 sound_ym.rd_data_reg_sel = 15; /* select port B */ 100
103 sound_ym.wd_data = c; /* put char onto port */ 101 sound_ym.rd_data_reg_sel = 15; /* select port B */
104 sound_ym.rd_data_reg_sel = 14; /* select port A */ 102 sound_ym.wd_data = c; /* put char onto port */
105 tmp = sound_ym.rd_data_reg_sel; 103 sound_ym.rd_data_reg_sel = 14; /* select port A */
106 sound_ym.wd_data = tmp & ~0x20; /* set strobe L */ 104 tmp = sound_ym.rd_data_reg_sel;
107 MFPDELAY(); /* wait a bit */ 105 sound_ym.wd_data = tmp & ~0x20; /* set strobe L */
108 sound_ym.wd_data = tmp | 0x20; /* set strobe H */ 106 MFPDELAY(); /* wait a bit */
109 return( 1 ); 107 sound_ym.wd_data = tmp | 0x20; /* set strobe H */
108 return 1;
110} 109}
111 110
112static void atari_par_console_write (struct console *co, const char *str, 111static void atari_par_console_write(struct console *co, const char *str,
113 unsigned int count) 112 unsigned int count)
114{ 113{
115 static int printer_present = 1; 114 static int printer_present = 1;
116 115
117 if (!printer_present) 116 if (!printer_present)
118 return;
119
120 while (count--) {
121 if (*str == '\n')
122 if (!ata_par_out( '\r' )) {
123 printer_present = 0;
124 return; 117 return;
125 } 118
126 if (!ata_par_out( *str++ )) { 119 while (count--) {
127 printer_present = 0; 120 if (*str == '\n') {
128 return; 121 if (!ata_par_out('\r')) {
122 printer_present = 0;
123 return;
124 }
125 }
126 if (!ata_par_out(*str++)) {
127 printer_present = 0;
128 return;
129 }
129 } 130 }
130 }
131} 131}
132 132
133#ifdef CONFIG_SERIAL_CONSOLE 133#ifdef CONFIG_SERIAL_CONSOLE
134int atari_mfp_console_wait_key(struct console *co) 134int atari_mfp_console_wait_key(struct console *co)
135{ 135{
136 while( !(mfp.rcv_stat & 0x80) ) /* wait for rx buf filled */ 136 while (!(mfp.rcv_stat & 0x80)) /* wait for rx buf filled */
137 barrier(); 137 barrier();
138 return( mfp.usart_dta ); 138 return mfp.usart_dta;
139} 139}
140 140
141int atari_scc_console_wait_key(struct console *co) 141int atari_scc_console_wait_key(struct console *co)
142{ 142{
143 do { 143 do {
144 MFPDELAY();
145 } while (!(scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */
144 MFPDELAY(); 146 MFPDELAY();
145 } while( !(scc.cha_b_ctrl & 0x01) ); /* wait for rx buf filled */ 147 return scc.cha_b_data;
146 MFPDELAY();
147 return( scc.cha_b_data );
148} 148}
149 149
150int atari_midi_console_wait_key(struct console *co) 150int atari_midi_console_wait_key(struct console *co)
151{ 151{
152 while( !(acia.mid_ctrl & ACIA_RDRF) ) /* wait for rx buf filled */ 152 while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */
153 barrier(); 153 barrier();
154 return( acia.mid_data ); 154 return acia.mid_data;
155} 155}
156#endif 156#endif
157 157
158/* The following two functions do a quick'n'dirty initialization of the MFP or 158/*
159 * The following two functions do a quick'n'dirty initialization of the MFP or
159 * SCC serial ports. They're used by the debugging interface, kgdb, and the 160 * SCC serial ports. They're used by the debugging interface, kgdb, and the
160 * serial console code. */ 161 * serial console code.
162 */
161#ifndef CONFIG_SERIAL_CONSOLE 163#ifndef CONFIG_SERIAL_CONSOLE
162static void __init atari_init_mfp_port( int cflag ) 164static void __init atari_init_mfp_port(int cflag)
163#else 165#else
164void atari_init_mfp_port( int cflag ) 166void atari_init_mfp_port(int cflag)
165#endif 167#endif
166{ 168{
167 /* timer values for 1200...115200 bps; > 38400 select 110, 134, or 150 169 /*
168 * bps, resp., and work only correct if there's a RSVE or RSSPEED */ 170 * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150
169 static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 }; 171 * bps, resp., and work only correct if there's a RSVE or RSSPEED
170 int baud = cflag & CBAUD; 172 */
171 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0; 173 static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 };
172 int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00; 174 int baud = cflag & CBAUD;
173 175 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0;
174 if (cflag & CBAUDEX) 176 int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00;
175 baud += B38400; 177
176 if (baud < B1200 || baud > B38400+2) 178 if (cflag & CBAUDEX)
177 baud = B9600; /* use default 9600bps for non-implemented rates */ 179 baud += B38400;
178 baud -= B1200; /* baud_table[] starts at 1200bps */ 180 if (baud < B1200 || baud > B38400+2)
179 181 baud = B9600; /* use default 9600bps for non-implemented rates */
180 mfp.trn_stat &= ~0x01; /* disable TX */ 182 baud -= B1200; /* baud_table[] starts at 1200bps */
181 mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */ 183
182 mfp.tim_ct_cd &= 0x70; /* stop timer D */ 184 mfp.trn_stat &= ~0x01; /* disable TX */
183 mfp.tim_dt_d = baud_table[baud]; 185 mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */
184 mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */ 186 mfp.tim_ct_cd &= 0x70; /* stop timer D */
185 mfp.trn_stat |= 0x01; /* enable TX */ 187 mfp.tim_dt_d = baud_table[baud];
186 188 mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */
187 atari_MFP_init_done = 1; 189 mfp.trn_stat |= 0x01; /* enable TX */
190
191 atari_MFP_init_done = 1;
188} 192}
189 193
190#define SCC_WRITE(reg,val) \ 194#define SCC_WRITE(reg, val) \
191 do { \ 195 do { \
192 scc.cha_b_ctrl = (reg); \ 196 scc.cha_b_ctrl = (reg); \
193 MFPDELAY(); \ 197 MFPDELAY(); \
194 scc.cha_b_ctrl = (val); \ 198 scc.cha_b_ctrl = (val); \
195 MFPDELAY(); \ 199 MFPDELAY(); \
196 } while(0) 200 } while (0)
197 201
198/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a 202/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
199 * delay of ~ 60us. */ 203 * delay of ~ 60us. */
200#define LONG_DELAY() \ 204#define LONG_DELAY() \
201 do { \ 205 do { \
202 int i; \ 206 int i; \
203 for( i = 100; i > 0; --i ) \ 207 for (i = 100; i > 0; --i) \
204 MFPDELAY(); \ 208 MFPDELAY(); \
205 } while(0) 209 } while (0)
206 210
207#ifndef CONFIG_SERIAL_CONSOLE 211#ifndef CONFIG_SERIAL_CONSOLE
208static void __init atari_init_scc_port( int cflag ) 212static void __init atari_init_scc_port(int cflag)
209#else 213#else
210void atari_init_scc_port( int cflag ) 214void atari_init_scc_port(int cflag)
211#endif 215#endif
212{ 216{
213 extern int atari_SCC_reset_done; 217 extern int atari_SCC_reset_done;
214 static int clksrc_table[9] = 218 static int clksrc_table[9] =
215 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */ 219 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
216 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 }; 220 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
217 static int brgsrc_table[9] = 221 static int brgsrc_table[9] =
218 /* reg 14: 0 = RTxC, 2 = PCLK */ 222 /* reg 14: 0 = RTxC, 2 = PCLK */
219 { 2, 2, 2, 2, 2, 2, 0, 2, 2 }; 223 { 2, 2, 2, 2, 2, 2, 0, 2, 2 };
220 static int clkmode_table[9] = 224 static int clkmode_table[9] =
221 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */ 225 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
222 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 }; 226 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
223 static int div_table[9] = 227 static int div_table[9] =
224 /* reg12 (BRG low) */ 228 /* reg12 (BRG low) */
225 { 208, 138, 103, 50, 24, 11, 1, 0, 0 }; 229 { 208, 138, 103, 50, 24, 11, 1, 0, 0 };
226 230
227 int baud = cflag & CBAUD; 231 int baud = cflag & CBAUD;
228 int clksrc, clkmode, div, reg3, reg5; 232 int clksrc, clkmode, div, reg3, reg5;
229 233
230 if (cflag & CBAUDEX) 234 if (cflag & CBAUDEX)
231 baud += B38400; 235 baud += B38400;
232 if (baud < B1200 || baud > B38400+2) 236 if (baud < B1200 || baud > B38400+2)
233 baud = B9600; /* use default 9600bps for non-implemented rates */ 237 baud = B9600; /* use default 9600bps for non-implemented rates */
234 baud -= B1200; /* tables starts at 1200bps */ 238 baud -= B1200; /* tables starts at 1200bps */
235 239
236 clksrc = clksrc_table[baud]; 240 clksrc = clksrc_table[baud];
237 clkmode = clkmode_table[baud]; 241 clkmode = clkmode_table[baud];
238 div = div_table[baud]; 242 div = div_table[baud];
239 if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) { 243 if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) {
240 /* special treatment for TT, where rates >= 38400 are done via TRxC */ 244 /* special treatment for TT, where rates >= 38400 are done via TRxC */
241 clksrc = 0x28; /* TRxC */ 245 clksrc = 0x28; /* TRxC */
242 clkmode = baud == 6 ? 0xc0 : 246 clkmode = baud == 6 ? 0xc0 :
243 baud == 7 ? 0x80 : /* really 76800bps */ 247 baud == 7 ? 0x80 : /* really 76800bps */
244 0x40; /* really 153600bps */ 248 0x40; /* really 153600bps */
245 div = 0; 249 div = 0;
246 } 250 }
247 251
248 reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40; 252 reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40;
249 reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */; 253 reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */;
250 254
251 (void)scc.cha_b_ctrl; /* reset reg pointer */ 255 (void)scc.cha_b_ctrl; /* reset reg pointer */
252 SCC_WRITE( 9, 0xc0 ); /* reset */ 256 SCC_WRITE(9, 0xc0); /* reset */
253 LONG_DELAY(); /* extra delay after WR9 access */ 257 LONG_DELAY(); /* extra delay after WR9 access */
254 SCC_WRITE( 4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 | 258 SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03)
255 0x04 /* 1 stopbit */ | 259 : 0 | 0x04 /* 1 stopbit */ | clkmode);
256 clkmode ); 260 SCC_WRITE(3, reg3);
257 SCC_WRITE( 3, reg3 ); 261 SCC_WRITE(5, reg5);
258 SCC_WRITE( 5, reg5 ); 262 SCC_WRITE(9, 0); /* no interrupts */
259 SCC_WRITE( 9, 0 ); /* no interrupts */ 263 LONG_DELAY(); /* extra delay after WR9 access */
260 LONG_DELAY(); /* extra delay after WR9 access */ 264 SCC_WRITE(10, 0); /* NRZ mode */
261 SCC_WRITE( 10, 0 ); /* NRZ mode */ 265 SCC_WRITE(11, clksrc); /* main clock source */
262 SCC_WRITE( 11, clksrc ); /* main clock source */ 266 SCC_WRITE(12, div); /* BRG value */
263 SCC_WRITE( 12, div ); /* BRG value */ 267 SCC_WRITE(13, 0); /* BRG high byte */
264 SCC_WRITE( 13, 0 ); /* BRG high byte */ 268 SCC_WRITE(14, brgsrc_table[baud]);
265 SCC_WRITE( 14, brgsrc_table[baud] ); 269 SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0));
266 SCC_WRITE( 14, brgsrc_table[baud] | (div ? 1 : 0) ); 270 SCC_WRITE(3, reg3 | 1);
267 SCC_WRITE( 3, reg3 | 1 ); 271 SCC_WRITE(5, reg5 | 8);
268 SCC_WRITE( 5, reg5 | 8 ); 272
269 273 atari_SCC_reset_done = 1;
270 atari_SCC_reset_done = 1; 274 atari_SCC_init_done = 1;
271 atari_SCC_init_done = 1;
272} 275}
273 276
274#ifndef CONFIG_SERIAL_CONSOLE 277#ifndef CONFIG_SERIAL_CONSOLE
275static void __init atari_init_midi_port( int cflag ) 278static void __init atari_init_midi_port(int cflag)
276#else 279#else
277void atari_init_midi_port( int cflag ) 280void atari_init_midi_port(int cflag)
278#endif 281#endif
279{ 282{
280 int baud = cflag & CBAUD; 283 int baud = cflag & CBAUD;
281 int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00; 284 int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00;
282 /* warning 7N1 isn't possible! (instead 7O2 is used...) */ 285 /* warning 7N1 isn't possible! (instead 7O2 is used...) */
283 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04; 286 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04;
284 int div; 287 int div;
285 288
286 /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as 289 /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as
287 * default) the standard MIDI speed 31250. */ 290 * default) the standard MIDI speed 31250. */
288 if (cflag & CBAUDEX) 291 if (cflag & CBAUDEX)
289 baud += B38400; 292 baud += B38400;
290 if (baud == B4800) 293 if (baud == B4800)
291 div = ACIA_DIV64; /* really 7812.5 bps */ 294 div = ACIA_DIV64; /* really 7812.5 bps */
292 else if (baud == B38400+2 /* 115200 */) 295 else if (baud == B38400+2 /* 115200 */)
293 div = ACIA_DIV1; /* really 500 kbps (does that work??) */ 296 div = ACIA_DIV1; /* really 500 kbps (does that work??) */
294 else 297 else
295 div = ACIA_DIV16; /* 31250 bps, standard for MIDI */ 298 div = ACIA_DIV16; /* 31250 bps, standard for MIDI */
296 299
297 /* RTS low, ints disabled */ 300 /* RTS low, ints disabled */
298 acia.mid_ctrl = div | csize | parity | 301 acia.mid_ctrl = div | csize | parity |
299 ((atari_switches & ATARI_SWITCH_MIDI) ? 302 ((atari_switches & ATARI_SWITCH_MIDI) ?
300 ACIA_RHTID : ACIA_RLTID); 303 ACIA_RHTID : ACIA_RLTID);
301} 304}
302 305
303void __init atari_debug_init(void) 306static int __init atari_debug_setup(char *arg)
304{ 307{
305 if (!strcmp( m68k_debug_device, "ser" )) { 308 if (!MACH_IS_ATARI)
306 /* defaults to ser2 for a Falcon and ser1 otherwise */ 309 return 0;
307 strcpy( m68k_debug_device, MACH_IS_FALCON ? "ser2" : "ser1" ); 310
308 311 if (!strcmp(arg, "ser"))
309 } 312 /* defaults to ser2 for a Falcon and ser1 otherwise */
310 313 arg = MACH_IS_FALCON ? "ser2" : "ser1";
311 if (!strcmp( m68k_debug_device, "ser1" )) { 314
312 /* ST-MFP Modem1 serial port */ 315 if (!strcmp(arg, "ser1")) {
313 atari_init_mfp_port( B9600|CS8 ); 316 /* ST-MFP Modem1 serial port */
314 atari_console_driver.write = atari_mfp_console_write; 317 atari_init_mfp_port(B9600|CS8);
315 } 318 atari_console_driver.write = atari_mfp_console_write;
316 else if (!strcmp( m68k_debug_device, "ser2" )) { 319 } else if (!strcmp(arg, "ser2")) {
317 /* SCC Modem2 serial port */ 320 /* SCC Modem2 serial port */
318 atari_init_scc_port( B9600|CS8 ); 321 atari_init_scc_port(B9600|CS8);
319 atari_console_driver.write = atari_scc_console_write; 322 atari_console_driver.write = atari_scc_console_write;
320 } 323 } else if (!strcmp(arg, "midi")) {
321 else if (!strcmp( m68k_debug_device, "midi" )) { 324 /* MIDI port */
322 /* MIDI port */ 325 atari_init_midi_port(B9600|CS8);
323 atari_init_midi_port( B9600|CS8 ); 326 atari_console_driver.write = atari_midi_console_write;
324 atari_console_driver.write = atari_midi_console_write; 327 } else if (!strcmp(arg, "par")) {
325 } 328 /* parallel printer */
326 else if (!strcmp( m68k_debug_device, "par" )) { 329 atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */
327 /* parallel printer */ 330 sound_ym.rd_data_reg_sel = 7; /* select mixer control */
328 atari_turnoff_irq( IRQ_MFP_BUSY ); /* avoid ints */ 331 sound_ym.wd_data = 0xff; /* sound off, ports are output */
329 sound_ym.rd_data_reg_sel = 7; /* select mixer control */ 332 sound_ym.rd_data_reg_sel = 15; /* select port B */
330 sound_ym.wd_data = 0xff; /* sound off, ports are output */ 333 sound_ym.wd_data = 0; /* no char */
331 sound_ym.rd_data_reg_sel = 15; /* select port B */ 334 sound_ym.rd_data_reg_sel = 14; /* select port A */
332 sound_ym.wd_data = 0; /* no char */ 335 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */
333 sound_ym.rd_data_reg_sel = 14; /* select port A */ 336 atari_console_driver.write = atari_par_console_write;
334 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */ 337 }
335 atari_console_driver.write = atari_par_console_write; 338 if (atari_console_driver.write)
336 } 339 register_console(&atari_console_driver);
337 if (atari_console_driver.write) 340
338 register_console(&atari_console_driver); 341 return 0;
339} 342}
340 343
341/* 344early_param("debug", atari_debug_setup);
342 * Local variables:
343 * c-indent-level: 4
344 * tab-width: 8
345 * End:
346 */
diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
index 222ce4244564..e162ee685d20 100644
--- a/arch/m68k/kernel/entry.S
+++ b/arch/m68k/kernel/entry.S
@@ -692,7 +692,7 @@ sys_call_table:
692 .long sys_tgkill /* 265 */ 692 .long sys_tgkill /* 265 */
693 .long sys_utimes 693 .long sys_utimes
694 .long sys_fadvise64_64 694 .long sys_fadvise64_64
695 .long sys_mbind 695 .long sys_mbind
696 .long sys_get_mempolicy 696 .long sys_get_mempolicy
697 .long sys_set_mempolicy /* 270 */ 697 .long sys_set_mempolicy /* 270 */
698 .long sys_mq_open 698 .long sys_mq_open
diff --git a/arch/m68k/kernel/head.S b/arch/m68k/kernel/head.S
index 6739e87fe825..05741f233567 100644
--- a/arch/m68k/kernel/head.S
+++ b/arch/m68k/kernel/head.S
@@ -3195,7 +3195,7 @@ func_start serial_putc,%d0/%d1/%a0/%a1
3195 jbra L(serial_putc_done) 3195 jbra L(serial_putc_done)
31963: 31963:
3197#endif 3197#endif
3198 3198
3199L(serial_putc_done): 3199L(serial_putc_done):
3200func_return serial_putc 3200func_return serial_putc
3201 3201
diff --git a/arch/m68k/kernel/setup.c b/arch/m68k/kernel/setup.c
index 42b8fd09ea8f..610319356691 100644
--- a/arch/m68k/kernel/setup.c
+++ b/arch/m68k/kernel/setup.c
@@ -71,9 +71,6 @@ static struct mem_info m68k_ramdisk;
71 71
72static char m68k_command_line[CL_SIZE]; 72static char m68k_command_line[CL_SIZE];
73 73
74char m68k_debug_device[6] = "";
75EXPORT_SYMBOL(m68k_debug_device);
76
77void (*mach_sched_init) (irq_handler_t handler) __initdata = NULL; 74void (*mach_sched_init) (irq_handler_t handler) __initdata = NULL;
78/* machine dependent irq functions */ 75/* machine dependent irq functions */
79void (*mach_init_IRQ) (void) __initdata = NULL; 76void (*mach_init_IRQ) (void) __initdata = NULL;
@@ -133,78 +130,78 @@ extern void config_hp300(void);
133extern void config_q40(void); 130extern void config_q40(void);
134extern void config_sun3x(void); 131extern void config_sun3x(void);
135 132
136extern void mac_debugging_short (int, short);
137extern void mac_debugging_long (int, long);
138
139#define MASK_256K 0xfffc0000 133#define MASK_256K 0xfffc0000
140 134
141extern void paging_init(void); 135extern void paging_init(void);
142 136
143static void __init m68k_parse_bootinfo(const struct bi_record *record) 137static void __init m68k_parse_bootinfo(const struct bi_record *record)
144{ 138{
145 while (record->tag != BI_LAST) { 139 while (record->tag != BI_LAST) {
146 int unknown = 0; 140 int unknown = 0;
147 const unsigned long *data = record->data; 141 const unsigned long *data = record->data;
148 switch (record->tag) { 142
149 case BI_MACHTYPE: 143 switch (record->tag) {
150 case BI_CPUTYPE: 144 case BI_MACHTYPE:
151 case BI_FPUTYPE: 145 case BI_CPUTYPE:
152 case BI_MMUTYPE: 146 case BI_FPUTYPE:
153 /* Already set up by head.S */ 147 case BI_MMUTYPE:
154 break; 148 /* Already set up by head.S */
155 149 break;
156 case BI_MEMCHUNK: 150
157 if (m68k_num_memory < NUM_MEMINFO) { 151 case BI_MEMCHUNK:
158 m68k_memory[m68k_num_memory].addr = data[0]; 152 if (m68k_num_memory < NUM_MEMINFO) {
159 m68k_memory[m68k_num_memory].size = data[1]; 153 m68k_memory[m68k_num_memory].addr = data[0];
160 m68k_num_memory++; 154 m68k_memory[m68k_num_memory].size = data[1];
161 } else 155 m68k_num_memory++;
162 printk("m68k_parse_bootinfo: too many memory chunks\n"); 156 } else
163 break; 157 printk("m68k_parse_bootinfo: too many memory chunks\n");
164 158 break;
165 case BI_RAMDISK: 159
166 m68k_ramdisk.addr = data[0]; 160 case BI_RAMDISK:
167 m68k_ramdisk.size = data[1]; 161 m68k_ramdisk.addr = data[0];
168 break; 162 m68k_ramdisk.size = data[1];
169 163 break;
170 case BI_COMMAND_LINE: 164
171 strlcpy(m68k_command_line, (const char *)data, sizeof(m68k_command_line)); 165 case BI_COMMAND_LINE:
172 break; 166 strlcpy(m68k_command_line, (const char *)data,
173 167 sizeof(m68k_command_line));
174 default: 168 break;
175 if (MACH_IS_AMIGA) 169
176 unknown = amiga_parse_bootinfo(record); 170 default:
177 else if (MACH_IS_ATARI) 171 if (MACH_IS_AMIGA)
178 unknown = atari_parse_bootinfo(record); 172 unknown = amiga_parse_bootinfo(record);
179 else if (MACH_IS_MAC) 173 else if (MACH_IS_ATARI)
180 unknown = mac_parse_bootinfo(record); 174 unknown = atari_parse_bootinfo(record);
181 else if (MACH_IS_Q40) 175 else if (MACH_IS_MAC)
182 unknown = q40_parse_bootinfo(record); 176 unknown = mac_parse_bootinfo(record);
183 else if (MACH_IS_BVME6000) 177 else if (MACH_IS_Q40)
184 unknown = bvme6000_parse_bootinfo(record); 178 unknown = q40_parse_bootinfo(record);
185 else if (MACH_IS_MVME16x) 179 else if (MACH_IS_BVME6000)
186 unknown = mvme16x_parse_bootinfo(record); 180 unknown = bvme6000_parse_bootinfo(record);
187 else if (MACH_IS_MVME147) 181 else if (MACH_IS_MVME16x)
188 unknown = mvme147_parse_bootinfo(record); 182 unknown = mvme16x_parse_bootinfo(record);
189 else if (MACH_IS_HP300) 183 else if (MACH_IS_MVME147)
190 unknown = hp300_parse_bootinfo(record); 184 unknown = mvme147_parse_bootinfo(record);
191 else 185 else if (MACH_IS_HP300)
192 unknown = 1; 186 unknown = hp300_parse_bootinfo(record);
187 else
188 unknown = 1;
189 }
190 if (unknown)
191 printk("m68k_parse_bootinfo: unknown tag 0x%04x ignored\n",
192 record->tag);
193 record = (struct bi_record *)((unsigned long)record +
194 record->size);
193 } 195 }
194 if (unknown)
195 printk("m68k_parse_bootinfo: unknown tag 0x%04x ignored\n",
196 record->tag);
197 record = (struct bi_record *)((unsigned long)record+record->size);
198 }
199 196
200 m68k_realnum_memory = m68k_num_memory; 197 m68k_realnum_memory = m68k_num_memory;
201#ifdef CONFIG_SINGLE_MEMORY_CHUNK 198#ifdef CONFIG_SINGLE_MEMORY_CHUNK
202 if (m68k_num_memory > 1) { 199 if (m68k_num_memory > 1) {
203 printk("Ignoring last %i chunks of physical memory\n", 200 printk("Ignoring last %i chunks of physical memory\n",
204 (m68k_num_memory - 1)); 201 (m68k_num_memory - 1));
205 m68k_num_memory = 1; 202 m68k_num_memory = 1;
206 } 203 }
207 m68k_memoffset = m68k_memory[0].addr-PAGE_OFFSET; 204 m68k_memoffset = m68k_memory[0].addr-PAGE_OFFSET;
208#endif 205#endif
209} 206}
210 207
@@ -215,7 +212,6 @@ void __init setup_arch(char **cmdline_p)
215 unsigned long endmem, startmem; 212 unsigned long endmem, startmem;
216#endif 213#endif
217 int i; 214 int i;
218 char *p, *q;
219 215
220 /* The bootinfo is located right after the kernel bss */ 216 /* The bootinfo is located right after the kernel bss */
221 m68k_parse_bootinfo((const struct bi_record *)&_end); 217 m68k_parse_bootinfo((const struct bi_record *)&_end);
@@ -234,7 +230,7 @@ void __init setup_arch(char **cmdline_p)
234 /* clear the fpu if we have one */ 230 /* clear the fpu if we have one */
235 if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) { 231 if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
236 volatile int zero = 0; 232 volatile int zero = 0;
237 asm __volatile__ ("frestore %0" : : "m" (zero)); 233 asm volatile ("frestore %0" : : "m" (zero));
238 } 234 }
239#endif 235#endif
240 236
@@ -258,37 +254,7 @@ void __init setup_arch(char **cmdline_p)
258 *cmdline_p = m68k_command_line; 254 *cmdline_p = m68k_command_line;
259 memcpy(boot_command_line, *cmdline_p, CL_SIZE); 255 memcpy(boot_command_line, *cmdline_p, CL_SIZE);
260 256
261 /* Parse the command line for arch-specific options. 257 parse_early_param();
262 * For the m68k, this is currently only "debug=xxx" to enable printing
263 * certain kernel messages to some machine-specific device.
264 */
265 for( p = *cmdline_p; p && *p; ) {
266 i = 0;
267 if (!strncmp( p, "debug=", 6 )) {
268 strlcpy( m68k_debug_device, p+6, sizeof(m68k_debug_device) );
269 if ((q = strchr( m68k_debug_device, ' ' ))) *q = 0;
270 i = 1;
271 }
272#ifdef CONFIG_ATARI
273 /* This option must be parsed very early */
274 if (!strncmp( p, "switches=", 9 )) {
275 extern void atari_switches_setup( const char *, int );
276 atari_switches_setup( p+9, (q = strchr( p+9, ' ' )) ?
277 (q - (p+9)) : strlen(p+9) );
278 i = 1;
279 }
280#endif
281
282 if (i) {
283 /* option processed, delete it */
284 if ((q = strchr( p, ' ' )))
285 strcpy( p, q+1 );
286 else
287 *p = 0;
288 } else {
289 if ((p = strchr( p, ' ' ))) ++p;
290 }
291 }
292 258
293#ifdef CONFIG_DUMMY_CONSOLE 259#ifdef CONFIG_DUMMY_CONSOLE
294 conswitchp = &dummy_con; 260 conswitchp = &dummy_con;
@@ -296,62 +262,62 @@ void __init setup_arch(char **cmdline_p)
296 262
297 switch (m68k_machtype) { 263 switch (m68k_machtype) {
298#ifdef CONFIG_AMIGA 264#ifdef CONFIG_AMIGA
299 case MACH_AMIGA: 265 case MACH_AMIGA:
300 config_amiga(); 266 config_amiga();
301 break; 267 break;
302#endif 268#endif
303#ifdef CONFIG_ATARI 269#ifdef CONFIG_ATARI
304 case MACH_ATARI: 270 case MACH_ATARI:
305 config_atari(); 271 config_atari();
306 break; 272 break;
307#endif 273#endif
308#ifdef CONFIG_MAC 274#ifdef CONFIG_MAC
309 case MACH_MAC: 275 case MACH_MAC:
310 config_mac(); 276 config_mac();
311 break; 277 break;
312#endif 278#endif
313#ifdef CONFIG_SUN3 279#ifdef CONFIG_SUN3
314 case MACH_SUN3: 280 case MACH_SUN3:
315 config_sun3(); 281 config_sun3();
316 break; 282 break;
317#endif 283#endif
318#ifdef CONFIG_APOLLO 284#ifdef CONFIG_APOLLO
319 case MACH_APOLLO: 285 case MACH_APOLLO:
320 config_apollo(); 286 config_apollo();
321 break; 287 break;
322#endif 288#endif
323#ifdef CONFIG_MVME147 289#ifdef CONFIG_MVME147
324 case MACH_MVME147: 290 case MACH_MVME147:
325 config_mvme147(); 291 config_mvme147();
326 break; 292 break;
327#endif 293#endif
328#ifdef CONFIG_MVME16x 294#ifdef CONFIG_MVME16x
329 case MACH_MVME16x: 295 case MACH_MVME16x:
330 config_mvme16x(); 296 config_mvme16x();
331 break; 297 break;
332#endif 298#endif
333#ifdef CONFIG_BVME6000 299#ifdef CONFIG_BVME6000
334 case MACH_BVME6000: 300 case MACH_BVME6000:
335 config_bvme6000(); 301 config_bvme6000();
336 break; 302 break;
337#endif 303#endif
338#ifdef CONFIG_HP300 304#ifdef CONFIG_HP300
339 case MACH_HP300: 305 case MACH_HP300:
340 config_hp300(); 306 config_hp300();
341 break; 307 break;
342#endif 308#endif
343#ifdef CONFIG_Q40 309#ifdef CONFIG_Q40
344 case MACH_Q40: 310 case MACH_Q40:
345 config_q40(); 311 config_q40();
346 break; 312 break;
347#endif 313#endif
348#ifdef CONFIG_SUN3X 314#ifdef CONFIG_SUN3X
349 case MACH_SUN3X: 315 case MACH_SUN3X:
350 config_sun3x(); 316 config_sun3x();
351 break; 317 break;
352#endif 318#endif
353 default: 319 default:
354 panic ("No configuration setup"); 320 panic("No configuration setup");
355 } 321 }
356 322
357#ifndef CONFIG_SUN3 323#ifndef CONFIG_SUN3
@@ -380,7 +346,7 @@ void __init setup_arch(char **cmdline_p)
380 reserve_bootmem(m68k_ramdisk.addr, m68k_ramdisk.size); 346 reserve_bootmem(m68k_ramdisk.addr, m68k_ramdisk.size);
381 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr); 347 initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
382 initrd_end = initrd_start + m68k_ramdisk.size; 348 initrd_end = initrd_start + m68k_ramdisk.size;
383 printk ("initrd: %08lx - %08lx\n", initrd_start, initrd_end); 349 printk("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
384 } 350 }
385#endif 351#endif
386 352
@@ -402,18 +368,18 @@ void __init setup_arch(char **cmdline_p)
402#if defined(CONFIG_ISA) && defined(MULTI_ISA) 368#if defined(CONFIG_ISA) && defined(MULTI_ISA)
403#if defined(CONFIG_Q40) 369#if defined(CONFIG_Q40)
404 if (MACH_IS_Q40) { 370 if (MACH_IS_Q40) {
405 isa_type = Q40_ISA; 371 isa_type = Q40_ISA;
406 isa_sex = 0; 372 isa_sex = 0;
407 } 373 }
408#elif defined(CONFIG_GG2) 374#elif defined(CONFIG_GG2)
409 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(GG2_ISA)){ 375 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(GG2_ISA)) {
410 isa_type = GG2_ISA; 376 isa_type = GG2_ISA;
411 isa_sex = 0; 377 isa_sex = 0;
412 } 378 }
413#elif defined(CONFIG_AMIGA_PCMCIA) 379#elif defined(CONFIG_AMIGA_PCMCIA)
414 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)){ 380 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(PCMCIA)) {
415 isa_type = AG_ISA; 381 isa_type = AG_ISA;
416 isa_sex = 1; 382 isa_sex = 1;
417 } 383 }
418#endif 384#endif
419#endif 385#endif
@@ -421,66 +387,66 @@ void __init setup_arch(char **cmdline_p)
421 387
422static int show_cpuinfo(struct seq_file *m, void *v) 388static int show_cpuinfo(struct seq_file *m, void *v)
423{ 389{
424 const char *cpu, *mmu, *fpu; 390 const char *cpu, *mmu, *fpu;
425 unsigned long clockfreq, clockfactor; 391 unsigned long clockfreq, clockfactor;
426 392
427#define LOOP_CYCLES_68020 (8) 393#define LOOP_CYCLES_68020 (8)
428#define LOOP_CYCLES_68030 (8) 394#define LOOP_CYCLES_68030 (8)
429#define LOOP_CYCLES_68040 (3) 395#define LOOP_CYCLES_68040 (3)
430#define LOOP_CYCLES_68060 (1) 396#define LOOP_CYCLES_68060 (1)
431 397
432 if (CPU_IS_020) { 398 if (CPU_IS_020) {
433 cpu = "68020"; 399 cpu = "68020";
434 clockfactor = LOOP_CYCLES_68020; 400 clockfactor = LOOP_CYCLES_68020;
435 } else if (CPU_IS_030) { 401 } else if (CPU_IS_030) {
436 cpu = "68030"; 402 cpu = "68030";
437 clockfactor = LOOP_CYCLES_68030; 403 clockfactor = LOOP_CYCLES_68030;
438 } else if (CPU_IS_040) { 404 } else if (CPU_IS_040) {
439 cpu = "68040"; 405 cpu = "68040";
440 clockfactor = LOOP_CYCLES_68040; 406 clockfactor = LOOP_CYCLES_68040;
441 } else if (CPU_IS_060) { 407 } else if (CPU_IS_060) {
442 cpu = "68060"; 408 cpu = "68060";
443 clockfactor = LOOP_CYCLES_68060; 409 clockfactor = LOOP_CYCLES_68060;
444 } else { 410 } else {
445 cpu = "680x0"; 411 cpu = "680x0";
446 clockfactor = 0; 412 clockfactor = 0;
447 } 413 }
448 414
449#ifdef CONFIG_M68KFPU_EMU_ONLY 415#ifdef CONFIG_M68KFPU_EMU_ONLY
450 fpu="none(soft float)"; 416 fpu = "none(soft float)";
451#else 417#else
452 if (m68k_fputype & FPU_68881) 418 if (m68k_fputype & FPU_68881)
453 fpu = "68881"; 419 fpu = "68881";
454 else if (m68k_fputype & FPU_68882) 420 else if (m68k_fputype & FPU_68882)
455 fpu = "68882"; 421 fpu = "68882";
456 else if (m68k_fputype & FPU_68040) 422 else if (m68k_fputype & FPU_68040)
457 fpu = "68040"; 423 fpu = "68040";
458 else if (m68k_fputype & FPU_68060) 424 else if (m68k_fputype & FPU_68060)
459 fpu = "68060"; 425 fpu = "68060";
460 else if (m68k_fputype & FPU_SUNFPA) 426 else if (m68k_fputype & FPU_SUNFPA)
461 fpu = "Sun FPA"; 427 fpu = "Sun FPA";
462 else 428 else
463 fpu = "none"; 429 fpu = "none";
464#endif 430#endif
465 431
466 if (m68k_mmutype & MMU_68851) 432 if (m68k_mmutype & MMU_68851)
467 mmu = "68851"; 433 mmu = "68851";
468 else if (m68k_mmutype & MMU_68030) 434 else if (m68k_mmutype & MMU_68030)
469 mmu = "68030"; 435 mmu = "68030";
470 else if (m68k_mmutype & MMU_68040) 436 else if (m68k_mmutype & MMU_68040)
471 mmu = "68040"; 437 mmu = "68040";
472 else if (m68k_mmutype & MMU_68060) 438 else if (m68k_mmutype & MMU_68060)
473 mmu = "68060"; 439 mmu = "68060";
474 else if (m68k_mmutype & MMU_SUN3) 440 else if (m68k_mmutype & MMU_SUN3)
475 mmu = "Sun-3"; 441 mmu = "Sun-3";
476 else if (m68k_mmutype & MMU_APOLLO) 442 else if (m68k_mmutype & MMU_APOLLO)
477 mmu = "Apollo"; 443 mmu = "Apollo";
478 else 444 else
479 mmu = "unknown"; 445 mmu = "unknown";
480 446
481 clockfreq = loops_per_jiffy*HZ*clockfactor; 447 clockfreq = loops_per_jiffy * HZ * clockfactor;
482 448
483 seq_printf(m, "CPU:\t\t%s\n" 449 seq_printf(m, "CPU:\t\t%s\n"
484 "MMU:\t\t%s\n" 450 "MMU:\t\t%s\n"
485 "FPU:\t\t%s\n" 451 "FPU:\t\t%s\n"
486 "Clocking:\t%lu.%1luMHz\n" 452 "Clocking:\t%lu.%1luMHz\n"
@@ -490,7 +456,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
490 clockfreq/1000000,(clockfreq/100000)%10, 456 clockfreq/1000000,(clockfreq/100000)%10,
491 loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100, 457 loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
492 loops_per_jiffy); 458 loops_per_jiffy);
493 return 0; 459 return 0;
494} 460}
495 461
496static void *c_start(struct seq_file *m, loff_t *pos) 462static void *c_start(struct seq_file *m, loff_t *pos)
@@ -506,44 +472,54 @@ static void c_stop(struct seq_file *m, void *v)
506{ 472{
507} 473}
508struct seq_operations cpuinfo_op = { 474struct seq_operations cpuinfo_op = {
509 .start = c_start, 475 .start = c_start,
510 .next = c_next, 476 .next = c_next,
511 .stop = c_stop, 477 .stop = c_stop,
512 .show = show_cpuinfo, 478 .show = show_cpuinfo,
513}; 479};
514 480
515int get_hardware_list(char *buffer) 481int get_hardware_list(char *buffer)
516{ 482{
517 int len = 0; 483 int len = 0;
518 char model[80]; 484 char model[80];
519 unsigned long mem; 485 unsigned long mem;
520 int i; 486 int i;
521 487
522 if (mach_get_model) 488 if (mach_get_model)
523 mach_get_model(model); 489 mach_get_model(model);
524 else 490 else
525 strcpy(model, "Unknown m68k"); 491 strcpy(model, "Unknown m68k");
526 492
527 len += sprintf(buffer+len, "Model:\t\t%s\n", model); 493 len += sprintf(buffer + len, "Model:\t\t%s\n", model);
528 for (mem = 0, i = 0; i < m68k_num_memory; i++) 494 for (mem = 0, i = 0; i < m68k_num_memory; i++)
529 mem += m68k_memory[i].size; 495 mem += m68k_memory[i].size;
530 len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10); 496 len += sprintf(buffer + len, "System Memory:\t%ldK\n", mem >> 10);
531 497
532 if (mach_get_hardware_list) 498 if (mach_get_hardware_list)
533 len += mach_get_hardware_list(buffer+len); 499 len += mach_get_hardware_list(buffer + len);
534 500
535 return(len); 501 return len;
536} 502}
537 503
538void check_bugs(void) 504void check_bugs(void)
539{ 505{
540#ifndef CONFIG_M68KFPU_EMU 506#ifndef CONFIG_M68KFPU_EMU
541 if (m68k_fputype == 0) { 507 if (m68k_fputype == 0) {
542 printk( KERN_EMERG "*** YOU DO NOT HAVE A FLOATING POINT UNIT, " 508 printk(KERN_EMERG "*** YOU DO NOT HAVE A FLOATING POINT UNIT, "
543 "WHICH IS REQUIRED BY LINUX/M68K ***\n" ); 509 "WHICH IS REQUIRED BY LINUX/M68K ***\n");
544 printk( KERN_EMERG "Upgrade your hardware or join the FPU " 510 printk(KERN_EMERG "Upgrade your hardware or join the FPU "
545 "emulation project\n" ); 511 "emulation project\n");
546 panic( "no FPU" ); 512 panic("no FPU");
547 } 513 }
548#endif /* !CONFIG_M68KFPU_EMU */ 514#endif /* !CONFIG_M68KFPU_EMU */
549} 515}
516
517#ifdef CONFIG_ADB
518static int __init adb_probe_sync_enable (char *str) {
519 extern int __adb_probe_sync;
520 __adb_probe_sync = 1;
521 return 1;
522}
523
524__setup("adb_sync", adb_probe_sync_enable);
525#endif /* CONFIG_ADB */
diff --git a/arch/m68k/lib/checksum.c b/arch/m68k/lib/checksum.c
index aed3be29e06b..cf6bb51945a2 100644
--- a/arch/m68k/lib/checksum.c
+++ b/arch/m68k/lib/checksum.c
@@ -320,6 +320,9 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
320 return(sum); 320 return(sum);
321} 321}
322 322
323EXPORT_SYMBOL(csum_partial_copy_from_user);
324
325
323/* 326/*
324 * copy from kernel space while checksumming, otherwise like csum_partial 327 * copy from kernel space while checksumming, otherwise like csum_partial
325 */ 328 */
diff --git a/arch/m68k/mac/baboon.c b/arch/m68k/mac/baboon.c
index a1c7ec706741..673a1085984d 100644
--- a/arch/m68k/mac/baboon.c
+++ b/arch/m68k/mac/baboon.c
@@ -22,7 +22,7 @@
22/* #define DEBUG_BABOON */ 22/* #define DEBUG_BABOON */
23/* #define DEBUG_IRQS */ 23/* #define DEBUG_IRQS */
24 24
25int baboon_present,baboon_active; 25int baboon_present;
26volatile struct baboon *baboon; 26volatile struct baboon *baboon;
27 27
28irqreturn_t baboon_irq(int, void *); 28irqreturn_t baboon_irq(int, void *);
@@ -45,7 +45,6 @@ void __init baboon_init(void)
45 45
46 baboon = (struct baboon *) BABOON_BASE; 46 baboon = (struct baboon *) BABOON_BASE;
47 baboon_present = 1; 47 baboon_present = 1;
48 baboon_active = 0;
49 48
50 printk("Baboon detected at %p\n", baboon); 49 printk("Baboon detected at %p\n", baboon);
51} 50}
@@ -66,26 +65,28 @@ void __init baboon_register_interrupts(void)
66 65
67irqreturn_t baboon_irq(int irq, void *dev_id) 66irqreturn_t baboon_irq(int irq, void *dev_id)
68{ 67{
69 int irq_bit,i; 68 int irq_bit, irq_num;
70 unsigned char events; 69 unsigned char events;
71 70
72#ifdef DEBUG_IRQS 71#ifdef DEBUG_IRQS
73 printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X active %02X\n", 72 printk("baboon_irq: mb_control %02X mb_ifr %02X mb_status %02X\n",
74 (uint) baboon->mb_control, (uint) baboon->mb_ifr, 73 (uint) baboon->mb_control, (uint) baboon->mb_ifr,
75 (uint) baboon->mb_status, baboon_active); 74 (uint) baboon->mb_status);
76#endif 75#endif
77 76
78 if (!(events = baboon->mb_ifr & 0x07)) 77 if (!(events = baboon->mb_ifr & 0x07))
79 return IRQ_NONE; 78 return IRQ_NONE;
80 79
81 for (i = 0, irq_bit = 1 ; i < 3 ; i++, irq_bit <<= 1) { 80 irq_num = IRQ_BABOON_0;
82 if (events & irq_bit/* & baboon_active*/) { 81 irq_bit = 1;
83 baboon_active &= ~irq_bit; 82 do {
84 m68k_handle_int(IRQ_BABOON_0 + i); 83 if (events & irq_bit) {
85 baboon_active |= irq_bit;
86 baboon->mb_ifr &= ~irq_bit; 84 baboon->mb_ifr &= ~irq_bit;
85 m68k_handle_int(irq_num);
87 } 86 }
88 } 87 irq_bit <<= 1;
88 irq_num++;
89 } while(events >= irq_bit);
89#if 0 90#if 0
90 if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL); 91 if (baboon->mb_ifr & 0x02) macide_ack_intr(NULL);
91 /* for now we need to smash all interrupts */ 92 /* for now we need to smash all interrupts */
@@ -95,21 +96,18 @@ irqreturn_t baboon_irq(int irq, void *dev_id)
95} 96}
96 97
97void baboon_irq_enable(int irq) { 98void baboon_irq_enable(int irq) {
98 int irq_idx = IRQ_IDX(irq);
99
100#ifdef DEBUG_IRQUSE 99#ifdef DEBUG_IRQUSE
101 printk("baboon_irq_enable(%d)\n", irq); 100 printk("baboon_irq_enable(%d)\n", irq);
102#endif 101#endif
103 baboon_active |= (1 << irq_idx); 102 /* FIXME: figure out how to mask and unmask baboon interrupt sources */
103 enable_irq(IRQ_NUBUS_C);
104} 104}
105 105
106void baboon_irq_disable(int irq) { 106void baboon_irq_disable(int irq) {
107 int irq_idx = IRQ_IDX(irq);
108
109#ifdef DEBUG_IRQUSE 107#ifdef DEBUG_IRQUSE
110 printk("baboon_irq_disable(%d)\n", irq); 108 printk("baboon_irq_disable(%d)\n", irq);
111#endif 109#endif
112 baboon_active &= ~(1 << irq_idx); 110 disable_irq(IRQ_NUBUS_C);
113} 111}
114 112
115void baboon_irq_clear(int irq) { 113void baboon_irq_clear(int irq) {
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 562b38d00180..5fd413246f89 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -59,15 +59,15 @@ extern struct mem_info m68k_ramdisk;
59 59
60extern char m68k_command_line[CL_SIZE]; 60extern char m68k_command_line[CL_SIZE];
61 61
62void *mac_env; /* Loaded by the boot asm */ 62void *mac_env; /* Loaded by the boot asm */
63 63
64/* The phys. video addr. - might be bogus on some machines */ 64/* The phys. video addr. - might be bogus on some machines */
65unsigned long mac_orig_videoaddr; 65unsigned long mac_orig_videoaddr;
66 66
67/* Mac specific timer functions */ 67/* Mac specific timer functions */
68extern unsigned long mac_gettimeoffset (void); 68extern unsigned long mac_gettimeoffset(void);
69extern int mac_hwclk (int, struct rtc_time *); 69extern int mac_hwclk(int, struct rtc_time *);
70extern int mac_set_clock_mmss (unsigned long); 70extern int mac_set_clock_mmss(unsigned long);
71extern int show_mac_interrupts(struct seq_file *, void *); 71extern int show_mac_interrupts(struct seq_file *, void *);
72extern void iop_preinit(void); 72extern void iop_preinit(void);
73extern void iop_init(void); 73extern void iop_init(void);
@@ -82,10 +82,6 @@ extern void mac_mksound(unsigned int, unsigned int);
82 82
83extern void nubus_sweep_video(void); 83extern void nubus_sweep_video(void);
84 84
85/* Mac specific debug functions (in debug.c) */
86extern void mac_debug_init(void);
87extern void mac_debugging_long(int, long);
88
89static void mac_get_model(char *str); 85static void mac_get_model(char *str);
90 86
91static void mac_sched_init(irq_handler_t vector) 87static void mac_sched_init(irq_handler_t vector)
@@ -99,51 +95,52 @@ static void mac_sched_init(irq_handler_t vector)
99 95
100int __init mac_parse_bootinfo(const struct bi_record *record) 96int __init mac_parse_bootinfo(const struct bi_record *record)
101{ 97{
102 int unknown = 0; 98 int unknown = 0;
103 const u_long *data = record->data; 99 const u_long *data = record->data;
104 100
105 switch (record->tag) { 101 switch (record->tag) {
106 case BI_MAC_MODEL: 102 case BI_MAC_MODEL:
107 mac_bi_data.id = *data; 103 mac_bi_data.id = *data;
108 break; 104 break;
109 case BI_MAC_VADDR: 105 case BI_MAC_VADDR:
110 mac_bi_data.videoaddr = *data; 106 mac_bi_data.videoaddr = *data;
111 break; 107 break;
112 case BI_MAC_VDEPTH: 108 case BI_MAC_VDEPTH:
113 mac_bi_data.videodepth = *data; 109 mac_bi_data.videodepth = *data;
114 break; 110 break;
115 case BI_MAC_VROW: 111 case BI_MAC_VROW:
116 mac_bi_data.videorow = *data; 112 mac_bi_data.videorow = *data;
117 break; 113 break;
118 case BI_MAC_VDIM: 114 case BI_MAC_VDIM:
119 mac_bi_data.dimensions = *data; 115 mac_bi_data.dimensions = *data;
120 break; 116 break;
121 case BI_MAC_VLOGICAL: 117 case BI_MAC_VLOGICAL:
122 mac_bi_data.videological = VIDEOMEMBASE + (*data & ~VIDEOMEMMASK); 118 mac_bi_data.videological = VIDEOMEMBASE + (*data & ~VIDEOMEMMASK);
123 mac_orig_videoaddr = *data; 119 mac_orig_videoaddr = *data;
124 break; 120 break;
125 case BI_MAC_SCCBASE: 121 case BI_MAC_SCCBASE:
126 mac_bi_data.sccbase = *data; 122 mac_bi_data.sccbase = *data;
127 break; 123 break;
128 case BI_MAC_BTIME: 124 case BI_MAC_BTIME:
129 mac_bi_data.boottime = *data; 125 mac_bi_data.boottime = *data;
130 break; 126 break;
131 case BI_MAC_GMTBIAS: 127 case BI_MAC_GMTBIAS:
132 mac_bi_data.gmtbias = *data; 128 mac_bi_data.gmtbias = *data;
133 break; 129 break;
134 case BI_MAC_MEMSIZE: 130 case BI_MAC_MEMSIZE:
135 mac_bi_data.memsize = *data; 131 mac_bi_data.memsize = *data;
136 break; 132 break;
137 case BI_MAC_CPUID: 133 case BI_MAC_CPUID:
138 mac_bi_data.cpuid = *data; 134 mac_bi_data.cpuid = *data;
139 break; 135 break;
140 case BI_MAC_ROMBASE: 136 case BI_MAC_ROMBASE:
141 mac_bi_data.rombase = *data; 137 mac_bi_data.rombase = *data;
142 break; 138 break;
143 default: 139 default:
144 unknown = 1; 140 unknown = 1;
145 } 141 break;
146 return(unknown); 142 }
143 return unknown;
147} 144}
148 145
149/* 146/*
@@ -155,6 +152,7 @@ int __init mac_parse_bootinfo(const struct bi_record *record)
155static void mac_cache_card_flush(int writeback) 152static void mac_cache_card_flush(int writeback)
156{ 153{
157 unsigned long flags; 154 unsigned long flags;
155
158 local_irq_save(flags); 156 local_irq_save(flags);
159 via_flush_cache(); 157 via_flush_cache();
160 local_irq_restore(flags); 158 local_irq_restore(flags);
@@ -162,28 +160,24 @@ static void mac_cache_card_flush(int writeback)
162 160
163void __init config_mac(void) 161void __init config_mac(void)
164{ 162{
165 if (!MACH_IS_MAC) { 163 if (!MACH_IS_MAC)
166 printk(KERN_ERR "ERROR: no Mac, but config_mac() called!! \n"); 164 printk(KERN_ERR "ERROR: no Mac, but config_mac() called!! \n");
167 }
168 165
169 mach_sched_init = mac_sched_init; 166 mach_sched_init = mac_sched_init;
170 mach_init_IRQ = mac_init_IRQ; 167 mach_init_IRQ = mac_init_IRQ;
171 mach_get_model = mac_get_model; 168 mach_get_model = mac_get_model;
172 mach_gettimeoffset = mac_gettimeoffset; 169 mach_gettimeoffset = mac_gettimeoffset;
173#warning move to adb/via init 170#warning move to adb/via init
174#if 0 171#if 0
175 mach_hwclk = mac_hwclk; 172 mach_hwclk = mac_hwclk;
176#endif 173#endif
177 mach_set_clock_mmss = mac_set_clock_mmss; 174 mach_set_clock_mmss = mac_set_clock_mmss;
178 mach_reset = mac_reset; 175 mach_reset = mac_reset;
179 mach_halt = mac_poweroff; 176 mach_halt = mac_poweroff;
180 mach_power_off = mac_poweroff; 177 mach_power_off = mac_poweroff;
181 mach_max_dma_address = 0xffffffff; 178 mach_max_dma_address = 0xffffffff;
182#if 0
183 mach_debug_init = mac_debug_init;
184#endif
185#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE) 179#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
186 mach_beep = mac_mksound; 180 mach_beep = mac_mksound;
187#endif 181#endif
188#ifdef CONFIG_HEARTBEAT 182#ifdef CONFIG_HEARTBEAT
189#if 0 183#if 0
@@ -199,21 +193,22 @@ void __init config_mac(void)
199 mac_identify(); 193 mac_identify();
200 mac_report_hardware(); 194 mac_report_hardware();
201 195
202 /* AFAIK only the IIci takes a cache card. The IIfx has onboard 196 /*
203 cache ... someone needs to figure out how to tell if it's on or 197 * AFAIK only the IIci takes a cache card. The IIfx has onboard
204 not. */ 198 * cache ... someone needs to figure out how to tell if it's on or
199 * not.
200 */
205 201
206 if (macintosh_config->ident == MAC_MODEL_IICI 202 if (macintosh_config->ident == MAC_MODEL_IICI
207 || macintosh_config->ident == MAC_MODEL_IIFX) { 203 || macintosh_config->ident == MAC_MODEL_IIFX)
208 mach_l2_flush = mac_cache_card_flush; 204 mach_l2_flush = mac_cache_card_flush;
209 }
210 205
211 /* 206 /*
212 * Check for machine specific fixups. 207 * Check for machine specific fixups.
213 */ 208 */
214 209
215#ifdef OLD_NUBUS_CODE 210#ifdef OLD_NUBUS_CODE
216 nubus_sweep_video(); 211 nubus_sweep_video();
217#endif 212#endif
218} 213}
219 214
@@ -233,8 +228,7 @@ void __init config_mac(void)
233struct mac_model *macintosh_config; 228struct mac_model *macintosh_config;
234EXPORT_SYMBOL(macintosh_config); 229EXPORT_SYMBOL(macintosh_config);
235 230
236static struct mac_model mac_data_table[]= 231static struct mac_model mac_data_table[] = {
237{
238 /* 232 /*
239 * We'll pretend to be a Macintosh II, that's pretty safe. 233 * We'll pretend to be a Macintosh II, that's pretty safe.
240 */ 234 */
@@ -784,12 +778,12 @@ void mac_identify(void)
784 if (!model) { 778 if (!model) {
785 /* no bootinfo model id -> NetBSD booter was used! */ 779 /* no bootinfo model id -> NetBSD booter was used! */
786 /* XXX FIXME: breaks for model > 31 */ 780 /* XXX FIXME: breaks for model > 31 */
787 model=(mac_bi_data.cpuid>>2)&63; 781 model = (mac_bi_data.cpuid >> 2) & 63;
788 printk (KERN_WARNING "No bootinfo model ID, using cpuid instead (hey, use Penguin!)\n"); 782 printk(KERN_WARNING "No bootinfo model ID, using cpuid instead (hey, use Penguin!)\n");
789 } 783 }
790 784
791 macintosh_config = mac_data_table; 785 macintosh_config = mac_data_table;
792 for (m = macintosh_config ; m->ident != -1 ; m++) { 786 for (m = macintosh_config; m->ident != -1; m++) {
793 if (m->ident == model) { 787 if (m->ident == model) {
794 macintosh_config = m; 788 macintosh_config = m;
795 break; 789 break;
@@ -801,27 +795,26 @@ void mac_identify(void)
801 /* the serial ports set to "Faster" mode in MacOS. */ 795 /* the serial ports set to "Faster" mode in MacOS. */
802 796
803 iop_preinit(); 797 iop_preinit();
804 mac_debug_init();
805 798
806 printk (KERN_INFO "Detected Macintosh model: %d \n", model); 799 printk(KERN_INFO "Detected Macintosh model: %d \n", model);
807 800
808 /* 801 /*
809 * Report booter data: 802 * Report booter data:
810 */ 803 */
811 printk (KERN_DEBUG " Penguin bootinfo data:\n"); 804 printk(KERN_DEBUG " Penguin bootinfo data:\n");
812 printk (KERN_DEBUG " Video: addr 0x%lx row 0x%lx depth %lx dimensions %ld x %ld\n", 805 printk(KERN_DEBUG " Video: addr 0x%lx row 0x%lx depth %lx dimensions %ld x %ld\n",
813 mac_bi_data.videoaddr, mac_bi_data.videorow, 806 mac_bi_data.videoaddr, mac_bi_data.videorow,
814 mac_bi_data.videodepth, mac_bi_data.dimensions & 0xFFFF, 807 mac_bi_data.videodepth, mac_bi_data.dimensions & 0xFFFF,
815 mac_bi_data.dimensions >> 16); 808 mac_bi_data.dimensions >> 16);
816 printk (KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx \n", 809 printk(KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx \n",
817 mac_bi_data.videological, mac_orig_videoaddr, 810 mac_bi_data.videological, mac_orig_videoaddr,
818 mac_bi_data.sccbase); 811 mac_bi_data.sccbase);
819 printk (KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx \n", 812 printk(KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx \n",
820 mac_bi_data.boottime, mac_bi_data.gmtbias); 813 mac_bi_data.boottime, mac_bi_data.gmtbias);
821 printk (KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx \n", 814 printk(KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx \n",
822 mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize); 815 mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize);
823#if 0 816#if 0
824 printk ("Ramdisk: addr 0x%lx size 0x%lx\n", 817 printk("Ramdisk: addr 0x%lx size 0x%lx\n",
825 m68k_ramdisk.addr, m68k_ramdisk.size); 818 m68k_ramdisk.addr, m68k_ramdisk.size);
826#endif 819#endif
827 820
@@ -830,22 +823,22 @@ void mac_identify(void)
830 */ 823 */
831 switch (macintosh_config->scsi_type) { 824 switch (macintosh_config->scsi_type) {
832 case MAC_SCSI_OLD: 825 case MAC_SCSI_OLD:
833 MACHW_SET(MAC_SCSI_80); 826 MACHW_SET(MAC_SCSI_80);
834 break; 827 break;
835 case MAC_SCSI_QUADRA: 828 case MAC_SCSI_QUADRA:
836 case MAC_SCSI_QUADRA2: 829 case MAC_SCSI_QUADRA2:
837 case MAC_SCSI_QUADRA3: 830 case MAC_SCSI_QUADRA3:
838 MACHW_SET(MAC_SCSI_96); 831 MACHW_SET(MAC_SCSI_96);
839 if ((macintosh_config->ident == MAC_MODEL_Q900) || 832 if ((macintosh_config->ident == MAC_MODEL_Q900) ||
840 (macintosh_config->ident == MAC_MODEL_Q950)) 833 (macintosh_config->ident == MAC_MODEL_Q950))
841 MACHW_SET(MAC_SCSI_96_2); 834 MACHW_SET(MAC_SCSI_96_2);
842 break; 835 break;
843 default: 836 default:
844 printk(KERN_WARNING "config.c: wtf: unknown scsi, using 53c80\n"); 837 printk(KERN_WARNING "config.c: wtf: unknown scsi, using 53c80\n");
845 MACHW_SET(MAC_SCSI_80); 838 MACHW_SET(MAC_SCSI_80);
846 break; 839 break;
847
848 } 840 }
841
849 iop_init(); 842 iop_init();
850 via_init(); 843 via_init();
851 oss_init(); 844 oss_init();
@@ -860,6 +853,6 @@ void mac_report_hardware(void)
860 853
861static void mac_get_model(char *str) 854static void mac_get_model(char *str)
862{ 855{
863 strcpy(str,"Macintosh "); 856 strcpy(str, "Macintosh ");
864 strcat(str, macintosh_config->name); 857 strcat(str, macintosh_config->name);
865} 858}
diff --git a/arch/m68k/mac/debug.c b/arch/m68k/mac/debug.c
index 4eeb09dc0e8f..7a5bed5bdc57 100644
--- a/arch/m68k/mac/debug.c
+++ b/arch/m68k/mac/debug.c
@@ -27,10 +27,6 @@
27#include <asm/machw.h> 27#include <asm/machw.h>
28#include <asm/macints.h> 28#include <asm/macints.h>
29 29
30extern char m68k_debug_device[];
31
32extern struct compat_bootinfo compat_boot_info;
33
34extern unsigned long mac_videobase; 30extern unsigned long mac_videobase;
35extern unsigned long mac_videodepth; 31extern unsigned long mac_videodepth;
36extern unsigned long mac_rowbytes; 32extern unsigned long mac_rowbytes;
@@ -52,7 +48,7 @@ extern void mac_serial_print(const char *);
52 */ 48 */
53 49
54#ifdef DEBUG_SCREEN 50#ifdef DEBUG_SCREEN
55static int peng=0, line=0; 51static int peng, line;
56#endif 52#endif
57 53
58void mac_debugging_short(int pos, short num) 54void mac_debugging_short(int pos, short num)
@@ -74,15 +70,14 @@ void mac_debugging_short(int pos, short num)
74 } 70 }
75 71
76 /* calculate current offset */ 72 /* calculate current offset */
77 pengoffset=(unsigned char *)(mac_videobase+(150+line*2)*mac_rowbytes) 73 pengoffset = (unsigned char *)mac_videobase +
78 +80*peng; 74 (150+line*2) * mac_rowbytes) + 80 * peng;
79 75
80 pptr=pengoffset; 76 pptr = pengoffset;
81 77
82 for(i=0;i<8*sizeof(short);i++) /* # of bits */ 78 for (i = 0; i < 8 * sizeof(short); i++) { /* # of bits */
83 {
84 /* value mask for bit i, reverse order */ 79 /* value mask for bit i, reverse order */
85 *pptr++ = (num & ( 1 << (8*sizeof(short)-i-1) ) ? 0xFF : 0x00); 80 *pptr++ = (num & (1 << (8*sizeof(short)-i-1)) ? 0xFF : 0x00);
86 } 81 }
87 82
88 peng++; 83 peng++;
@@ -115,11 +110,10 @@ void mac_debugging_long(int pos, long addr)
115 pengoffset=(unsigned char *)(mac_videobase+(150+line*2)*mac_rowbytes) 110 pengoffset=(unsigned char *)(mac_videobase+(150+line*2)*mac_rowbytes)
116 +80*peng; 111 +80*peng;
117 112
118 pptr=pengoffset; 113 pptr = pengoffset;
119 114
120 for(i=0;i<8*sizeof(long);i++) /* # of bits */ 115 for (i = 0; i < 8 * sizeof(long); i++) { /* # of bits */
121 { 116 *pptr++ = (addr & (1 << (8*sizeof(long)-i-1)) ? 0xFF : 0x00);
122 *pptr++ = (addr & ( 1 << (8*sizeof(long)-i-1) ) ? 0xFF : 0x00);
123 } 117 }
124 118
125 peng++; 119 peng++;
@@ -136,16 +130,15 @@ void mac_debugging_long(int pos, long addr)
136 * TODO: serial debug code 130 * TODO: serial debug code
137 */ 131 */
138 132
139struct mac_SCC 133struct mac_SCC {
140 { 134 u_char cha_b_ctrl;
141 u_char cha_b_ctrl; 135 u_char char_dummy1;
142 u_char char_dummy1; 136 u_char cha_a_ctrl;
143 u_char cha_a_ctrl; 137 u_char char_dummy2;
144 u_char char_dummy2; 138 u_char cha_b_data;
145 u_char cha_b_data; 139 u_char char_dummy3;
146 u_char char_dummy3; 140 u_char cha_a_data;
147 u_char cha_a_data; 141};
148 };
149 142
150# define scc (*((volatile struct mac_SCC*)mac_bi_data.sccbase)) 143# define scc (*((volatile struct mac_SCC*)mac_bi_data.sccbase))
151 144
@@ -158,9 +151,9 @@ int mac_SCC_reset_done;
158static int scc_port = -1; 151static int scc_port = -1;
159 152
160static struct console mac_console_driver = { 153static struct console mac_console_driver = {
161 .name = "debug", 154 .name = "debug",
162 .flags = CON_PRINTBUFFER, 155 .flags = CON_PRINTBUFFER,
163 .index = -1, 156 .index = -1,
164}; 157};
165 158
166/* 159/*
@@ -178,8 +171,8 @@ static struct console mac_console_driver = {
178 * this driver if Mac. 171 * this driver if Mac.
179 */ 172 */
180 173
181void mac_debug_console_write (struct console *co, const char *str, 174void mac_debug_console_write(struct console *co, const char *str,
182 unsigned int count) 175 unsigned int count)
183{ 176{
184 mac_serial_print(str); 177 mac_serial_print(str);
185} 178}
@@ -190,48 +183,50 @@ void mac_debug_console_write (struct console *co, const char *str,
190 183
191#define uSEC 1 184#define uSEC 1
192 185
193static inline void mac_sccb_out (char c) 186static inline void mac_sccb_out(char c)
194{ 187{
195 int i; 188 int i;
196 do { 189
197 for( i = uSEC; i > 0; --i ) 190 do {
191 for (i = uSEC; i > 0; --i)
192 barrier();
193 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
194 for (i = uSEC; i > 0; --i)
198 barrier(); 195 barrier();
199 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */ 196 scc.cha_b_data = c;
200 for( i = uSEC; i > 0; --i )
201 barrier();
202 scc.cha_b_data = c;
203} 197}
204 198
205static inline void mac_scca_out (char c) 199static inline void mac_scca_out(char c)
206{ 200{
207 int i; 201 int i;
208 do { 202
209 for( i = uSEC; i > 0; --i ) 203 do {
204 for (i = uSEC; i > 0; --i)
205 barrier();
206 } while (!(scc.cha_a_ctrl & 0x04)); /* wait for tx buf empty */
207 for (i = uSEC; i > 0; --i)
210 barrier(); 208 barrier();
211 } while (!(scc.cha_a_ctrl & 0x04)); /* wait for tx buf empty */ 209 scc.cha_a_data = c;
212 for( i = uSEC; i > 0; --i )
213 barrier();
214 scc.cha_a_data = c;
215} 210}
216 211
217void mac_sccb_console_write (struct console *co, const char *str, 212void mac_sccb_console_write(struct console *co, const char *str,
218 unsigned int count) 213 unsigned int count)
219{ 214{
220 while (count--) { 215 while (count--) {
221 if (*str == '\n') 216 if (*str == '\n')
222 mac_sccb_out( '\r' ); 217 mac_sccb_out('\r');
223 mac_sccb_out( *str++ ); 218 mac_sccb_out(*str++);
224 } 219 }
225} 220}
226 221
227void mac_scca_console_write (struct console *co, const char *str, 222void mac_scca_console_write(struct console *co, const char *str,
228 unsigned int count) 223 unsigned int count)
229{ 224{
230 while (count--) { 225 while (count--) {
231 if (*str == '\n') 226 if (*str == '\n')
232 mac_scca_out( '\r' ); 227 mac_scca_out('\r');
233 mac_scca_out( *str++ ); 228 mac_scca_out(*str++);
234 } 229 }
235} 230}
236 231
237 232
@@ -239,41 +234,41 @@ void mac_scca_console_write (struct console *co, const char *str,
239 * SCC serial ports. They're used by the debugging interface, kgdb, and the 234 * SCC serial ports. They're used by the debugging interface, kgdb, and the
240 * serial console code. */ 235 * serial console code. */
241#define SCCB_WRITE(reg,val) \ 236#define SCCB_WRITE(reg,val) \
242 do { \ 237 do { \
243 int i; \ 238 int i; \
244 scc.cha_b_ctrl = (reg); \ 239 scc.cha_b_ctrl = (reg); \
245 for( i = uSEC; i > 0; --i ) \ 240 for (i = uSEC; i > 0; --i) \
246 barrier(); \ 241 barrier(); \
247 scc.cha_b_ctrl = (val); \ 242 scc.cha_b_ctrl = (val); \
248 for( i = uSEC; i > 0; --i ) \ 243 for (i = uSEC; i > 0; --i) \
249 barrier(); \ 244 barrier(); \
250 } while(0) 245 } while(0)
251 246
252#define SCCA_WRITE(reg,val) \ 247#define SCCA_WRITE(reg,val) \
253 do { \ 248 do { \
254 int i; \ 249 int i; \
255 scc.cha_a_ctrl = (reg); \ 250 scc.cha_a_ctrl = (reg); \
256 for( i = uSEC; i > 0; --i ) \ 251 for (i = uSEC; i > 0; --i) \
257 barrier(); \ 252 barrier(); \
258 scc.cha_a_ctrl = (val); \ 253 scc.cha_a_ctrl = (val); \
259 for( i = uSEC; i > 0; --i ) \ 254 for (i = uSEC; i > 0; --i) \
260 barrier(); \ 255 barrier(); \
261 } while(0) 256 } while(0)
262 257
263/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a 258/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
264 * delay of ~ 60us. */ 259 * delay of ~ 60us. */
265/* Mac: loops_per_jiffy min. 19000 ^= .5 us; MFPDELAY was 0.6 us*/ 260/* Mac: loops_per_jiffy min. 19000 ^= .5 us; MFPDELAY was 0.6 us*/
266#define LONG_DELAY() \ 261#define LONG_DELAY() \
267 do { \ 262 do { \
268 int i; \ 263 int i; \
269 for( i = 60*uSEC; i > 0; --i ) \ 264 for (i = 60*uSEC; i > 0; --i) \
270 barrier(); \ 265 barrier(); \
271 } while(0) 266 } while(0)
272 267
273#ifndef CONFIG_SERIAL_CONSOLE 268#ifndef CONFIG_SERIAL_CONSOLE
274static void __init mac_init_scc_port( int cflag, int port ) 269static void __init mac_init_scc_port(int cflag, int port)
275#else 270#else
276void mac_init_scc_port( int cflag, int port ) 271void mac_init_scc_port(int cflag, int port)
277#endif 272#endif
278{ 273{
279 extern int mac_SCC_reset_done; 274 extern int mac_SCC_reset_done;
@@ -292,106 +287,102 @@ void mac_init_scc_port( int cflag, int port )
292 /* reg12 (BRG low) */ 287 /* reg12 (BRG low) */
293 { 94, 62, 46, 22, 10, 4, 1, 0, 0 }; 288 { 94, 62, 46, 22, 10, 4, 1, 0, 0 };
294 289
295 int baud = cflag & CBAUD; 290 int baud = cflag & CBAUD;
296 int clksrc, clkmode, div, reg3, reg5; 291 int clksrc, clkmode, div, reg3, reg5;
297 292
298 if (cflag & CBAUDEX) 293 if (cflag & CBAUDEX)
299 baud += B38400; 294 baud += B38400;
300 if (baud < B1200 || baud > B38400+2) 295 if (baud < B1200 || baud > B38400+2)
301 baud = B9600; /* use default 9600bps for non-implemented rates */ 296 baud = B9600; /* use default 9600bps for non-implemented rates */
302 baud -= B1200; /* tables starts at 1200bps */ 297 baud -= B1200; /* tables starts at 1200bps */
303 298
304 clksrc = clksrc_table[baud]; 299 clksrc = clksrc_table[baud];
305 clkmode = clkmode_table[baud]; 300 clkmode = clkmode_table[baud];
306 div = div_table[baud]; 301 div = div_table[baud];
307 302
308 reg3 = (((cflag & CSIZE) == CS8) ? 0xc0 : 0x40); 303 reg3 = (((cflag & CSIZE) == CS8) ? 0xc0 : 0x40);
309 reg5 = (((cflag & CSIZE) == CS8) ? 0x60 : 0x20) | 0x82 /* assert DTR/RTS */; 304 reg5 = (((cflag & CSIZE) == CS8) ? 0x60 : 0x20) | 0x82 /* assert DTR/RTS */;
310 305
311 if (port == 1) { 306 if (port == 1) {
312 (void)scc.cha_b_ctrl; /* reset reg pointer */ 307 (void)scc.cha_b_ctrl; /* reset reg pointer */
313 SCCB_WRITE( 9, 0xc0 ); /* reset */ 308 SCCB_WRITE(9, 0xc0); /* reset */
314 LONG_DELAY(); /* extra delay after WR9 access */ 309 LONG_DELAY(); /* extra delay after WR9 access */
315 SCCB_WRITE( 4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 | 310 SCCB_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
311 0x04 /* 1 stopbit */ |
312 clkmode);
313 SCCB_WRITE(3, reg3);
314 SCCB_WRITE(5, reg5);
315 SCCB_WRITE(9, 0); /* no interrupts */
316 LONG_DELAY(); /* extra delay after WR9 access */
317 SCCB_WRITE(10, 0); /* NRZ mode */
318 SCCB_WRITE(11, clksrc); /* main clock source */
319 SCCB_WRITE(12, div); /* BRG value */
320 SCCB_WRITE(13, 0); /* BRG high byte */
321 SCCB_WRITE(14, 1);
322 SCCB_WRITE(3, reg3 | 1);
323 SCCB_WRITE(5, reg5 | 8);
324 } else if (port == 0) {
325 (void)scc.cha_a_ctrl; /* reset reg pointer */
326 SCCA_WRITE(9, 0xc0); /* reset */
327 LONG_DELAY(); /* extra delay after WR9 access */
328 SCCA_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
316 0x04 /* 1 stopbit */ | 329 0x04 /* 1 stopbit */ |
317 clkmode ); 330 clkmode);
318 SCCB_WRITE( 3, reg3 ); 331 SCCA_WRITE(3, reg3);
319 SCCB_WRITE( 5, reg5 ); 332 SCCA_WRITE(5, reg5);
320 SCCB_WRITE( 9, 0 ); /* no interrupts */ 333 SCCA_WRITE(9, 0); /* no interrupts */
321 LONG_DELAY(); /* extra delay after WR9 access */ 334 LONG_DELAY(); /* extra delay after WR9 access */
322 SCCB_WRITE( 10, 0 ); /* NRZ mode */ 335 SCCA_WRITE(10, 0); /* NRZ mode */
323 SCCB_WRITE( 11, clksrc ); /* main clock source */ 336 SCCA_WRITE(11, clksrc); /* main clock source */
324 SCCB_WRITE( 12, div ); /* BRG value */ 337 SCCA_WRITE(12, div); /* BRG value */
325 SCCB_WRITE( 13, 0 ); /* BRG high byte */ 338 SCCA_WRITE(13, 0); /* BRG high byte */
326 SCCB_WRITE( 14, 1 ); 339 SCCA_WRITE(14, 1);
327 SCCB_WRITE( 3, reg3 | 1 ); 340 SCCA_WRITE(3, reg3 | 1);
328 SCCB_WRITE( 5, reg5 | 8 ); 341 SCCA_WRITE(5, reg5 | 8);
329 } else if (port == 0) { 342 }
330 (void)scc.cha_a_ctrl; /* reset reg pointer */ 343
331 SCCA_WRITE( 9, 0xc0 ); /* reset */ 344 mac_SCC_reset_done = 1;
332 LONG_DELAY(); /* extra delay after WR9 access */ 345 mac_SCC_init_done = 1;
333 SCCA_WRITE( 4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
334 0x04 /* 1 stopbit */ |
335 clkmode );
336 SCCA_WRITE( 3, reg3 );
337 SCCA_WRITE( 5, reg5 );
338 SCCA_WRITE( 9, 0 ); /* no interrupts */
339 LONG_DELAY(); /* extra delay after WR9 access */
340 SCCA_WRITE( 10, 0 ); /* NRZ mode */
341 SCCA_WRITE( 11, clksrc ); /* main clock source */
342 SCCA_WRITE( 12, div ); /* BRG value */
343 SCCA_WRITE( 13, 0 ); /* BRG high byte */
344 SCCA_WRITE( 14, 1 );
345 SCCA_WRITE( 3, reg3 | 1 );
346 SCCA_WRITE( 5, reg5 | 8 );
347 }
348
349 mac_SCC_reset_done = 1;
350 mac_SCC_init_done = 1;
351} 346}
352#endif /* DEBUG_SERIAL */ 347#endif /* DEBUG_SERIAL */
353 348
354void mac_init_scca_port( int cflag ) 349void mac_init_scca_port(int cflag)
355{ 350{
356 mac_init_scc_port(cflag, 0); 351 mac_init_scc_port(cflag, 0);
357} 352}
358 353
359void mac_init_sccb_port( int cflag ) 354void mac_init_sccb_port(int cflag)
360{ 355{
361 mac_init_scc_port(cflag, 1); 356 mac_init_scc_port(cflag, 1);
362} 357}
363 358
364void __init mac_debug_init(void) 359static int __init mac_debug_setup(char *arg)
365{ 360{
361 if (!MACH_IS_MAC)
362 return 0;
363
366#ifdef DEBUG_SERIAL 364#ifdef DEBUG_SERIAL
367 if ( !strcmp( m68k_debug_device, "ser" ) 365 if (!strcmp(arg, "ser") || !strcmp(arg, "ser1")) {
368 || !strcmp( m68k_debug_device, "ser1" )) { 366 /* Mac modem port */
369 /* Mac modem port */ 367 mac_init_scc_port(B9600|CS8, 0);
370 mac_init_scc_port( B9600|CS8, 0 ); 368 mac_console_driver.write = mac_scca_console_write;
371 mac_console_driver.write = mac_scca_console_write; 369 scc_port = 0;
372 scc_port = 0; 370 } else if (!strcmp(arg, "ser2")) {
373 } 371 /* Mac printer port */
374 else if (!strcmp( m68k_debug_device, "ser2" )) { 372 mac_init_scc_port(B9600|CS8, 1);
375 /* Mac printer port */ 373 mac_console_driver.write = mac_sccb_console_write;
376 mac_init_scc_port( B9600|CS8, 1 ); 374 scc_port = 1;
377 mac_console_driver.write = mac_sccb_console_write; 375 }
378 scc_port = 1;
379 }
380#endif 376#endif
381#ifdef DEBUG_HEADS 377#ifdef DEBUG_HEADS
382 if ( !strcmp( m68k_debug_device, "scn" ) 378 if (!strcmp(arg, "scn") || !strcmp(arg, "con")) {
383 || !strcmp( m68k_debug_device, "con" )) { 379 /* display, using head.S console routines */
384 /* display, using head.S console routines */ 380 mac_console_driver.write = mac_debug_console_write;
385 mac_console_driver.write = mac_debug_console_write; 381 }
386 }
387#endif 382#endif
388 if (mac_console_driver.write) 383 if (mac_console_driver.write)
389 register_console(&mac_console_driver); 384 register_console(&mac_console_driver);
385 return 0;
390} 386}
391 387
392/* 388early_param("debug", mac_debug_setup);
393 * Local variables:
394 * c-indent-level: 4
395 * tab-width: 8
396 * End:
397 */
diff --git a/arch/m68k/mac/oss.c b/arch/m68k/mac/oss.c
index 63690819565a..d7be16917efd 100644
--- a/arch/m68k/mac/oss.c
+++ b/arch/m68k/mac/oss.c
@@ -109,13 +109,11 @@ irqreturn_t oss_irq(int irq, void *dev_id)
109 /* FIXME: how do you clear a pending IRQ? */ 109 /* FIXME: how do you clear a pending IRQ? */
110 110
111 if (events & OSS_IP_SOUND) { 111 if (events & OSS_IP_SOUND) {
112 /* FIXME: call sound handler */
113 oss->irq_pending &= ~OSS_IP_SOUND; 112 oss->irq_pending &= ~OSS_IP_SOUND;
113 /* FIXME: call sound handler */
114 } else if (events & OSS_IP_SCSI) { 114 } else if (events & OSS_IP_SCSI) {
115 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
116 m68k_handle_int(IRQ_MAC_SCSI);
117 oss->irq_pending &= ~OSS_IP_SCSI; 115 oss->irq_pending &= ~OSS_IP_SCSI;
118 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI; 116 m68k_handle_int(IRQ_MAC_SCSI);
119 } else { 117 } else {
120 /* FIXME: error check here? */ 118 /* FIXME: error check here? */
121 } 119 }
@@ -143,14 +141,16 @@ irqreturn_t oss_nubus_irq(int irq, void *dev_id)
143#endif 141#endif
144 /* There are only six slots on the OSS, not seven */ 142 /* There are only six slots on the OSS, not seven */
145 143
146 for (i = 0, irq_bit = 1 ; i < 6 ; i++, irq_bit <<= 1) { 144 i = 6;
145 irq_bit = 0x40;
146 do {
147 --i;
148 irq_bit >>= 1;
147 if (events & irq_bit) { 149 if (events & irq_bit) {
148 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
149 m68k_handle_int(NUBUS_SOURCE_BASE + i);
150 oss->irq_pending &= ~irq_bit; 150 oss->irq_pending &= ~irq_bit;
151 oss->irq_level[i] = OSS_IRQLEV_NUBUS; 151 m68k_handle_int(NUBUS_SOURCE_BASE + i);
152 } 152 }
153 } 153 } while(events & (irq_bit - 1));
154 return IRQ_HANDLED; 154 return IRQ_HANDLED;
155} 155}
156 156
diff --git a/arch/m68k/mac/psc.c b/arch/m68k/mac/psc.c
index 15378a5878c9..d66f723b17c3 100644
--- a/arch/m68k/mac/psc.c
+++ b/arch/m68k/mac/psc.c
@@ -131,11 +131,8 @@ irqreturn_t psc_irq(int irq, void *dev_id)
131{ 131{
132 int pIFR = pIFRbase + ((int) dev_id); 132 int pIFR = pIFRbase + ((int) dev_id);
133 int pIER = pIERbase + ((int) dev_id); 133 int pIER = pIERbase + ((int) dev_id);
134 int base_irq; 134 int irq_num;
135 int irq_bit,i; 135 unsigned char irq_bit, events;
136 unsigned char events;
137
138 base_irq = irq << 3;
139 136
140#ifdef DEBUG_IRQS 137#ifdef DEBUG_IRQS
141 printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n", 138 printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
@@ -146,14 +143,16 @@ irqreturn_t psc_irq(int irq, void *dev_id)
146 if (!events) 143 if (!events)
147 return IRQ_NONE; 144 return IRQ_NONE;
148 145
149 for (i = 0, irq_bit = 1 ; i < 4 ; i++, irq_bit <<= 1) { 146 irq_num = irq << 3;
150 if (events & irq_bit) { 147 irq_bit = 1;
151 psc_write_byte(pIER, irq_bit); 148 do {
152 m68k_handle_int(base_irq + i); 149 if (events & irq_bit) {
153 psc_write_byte(pIFR, irq_bit); 150 psc_write_byte(pIFR, irq_bit);
154 psc_write_byte(pIER, irq_bit | 0x80); 151 m68k_handle_int(irq_num);
155 } 152 }
156 } 153 irq_num++;
154 irq_bit <<= 1;
155 } while (events >= irq_bit);
157 return IRQ_HANDLED; 156 return IRQ_HANDLED;
158} 157}
159 158
diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
index e27735be2924..d5cac72eb3db 100644
--- a/arch/m68k/mac/via.c
+++ b/arch/m68k/mac/via.c
@@ -13,6 +13,10 @@
13 * for info. A full-text web search on 6522 AND VIA will probably also 13 * for info. A full-text web search on 6522 AND VIA will probably also
14 * net some usefulness. <cananian@alumni.princeton.edu> 20apr1999 14 * net some usefulness. <cananian@alumni.princeton.edu> 20apr1999
15 * 15 *
16 * Additional data is here (the SY6522 was used in the Mac II etc):
17 * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522.pdf
18 * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522_programming_reference.pdf
19 *
16 * PRAM/RTC access algorithms are from the NetBSD RTC toolkit version 1.08b 20 * PRAM/RTC access algorithms are from the NetBSD RTC toolkit version 1.08b
17 * by Erik Vogan and adapted to Linux by Joshua M. Thompson (funaho@jurai.org) 21 * by Erik Vogan and adapted to Linux by Joshua M. Thompson (funaho@jurai.org)
18 * 22 *
@@ -37,7 +41,7 @@ volatile __u8 *via1, *via2;
37/* See note in mac_via.h about how this is possibly not useful */ 41/* See note in mac_via.h about how this is possibly not useful */
38volatile long *via_memory_bogon=(long *)&via_memory_bogon; 42volatile long *via_memory_bogon=(long *)&via_memory_bogon;
39#endif 43#endif
40int rbv_present,via_alt_mapping; 44int rbv_present, via_alt_mapping;
41__u8 rbv_clear; 45__u8 rbv_clear;
42 46
43/* 47/*
@@ -60,7 +64,19 @@ static int gIER,gIFR,gBufA,gBufB;
60#define MAC_CLOCK_LOW (MAC_CLOCK_TICK&0xFF) 64#define MAC_CLOCK_LOW (MAC_CLOCK_TICK&0xFF)
61#define MAC_CLOCK_HIGH (MAC_CLOCK_TICK>>8) 65#define MAC_CLOCK_HIGH (MAC_CLOCK_TICK>>8)
62 66
63static int nubus_active; 67/* To disable a NuBus slot on Quadras we make the slot IRQ lines outputs, set
68 * high. On RBV we just use the slot interrupt enable register. On Macs with
69 * genuine VIA chips we must use nubus_disabled to keep track of disabled slot
70 * interrupts. When any slot IRQ is disabled we mask the (edge triggered) CA1
71 * or "SLOTS" interrupt. When no slot is disabled, we unmask the CA1 interrupt.
72 * So, on genuine VIAs, having more than one NuBus IRQ can mean trouble,
73 * because closing one of those drivers can mask all of the NuBus interrupts.
74 * Also, since we can't mask the unregistered slot IRQs on genuine VIAs, it's
75 * possible to get interrupts from cards that MacOS or the ROM has configured
76 * but we have not. FWIW, "Designing Cards and Drivers for Macintosh II and
77 * Macintosh SE", page 9-8, says, a slot IRQ with no driver would crash MacOS.
78 */
79static u8 nubus_disabled;
64 80
65void via_debug_dump(void); 81void via_debug_dump(void);
66irqreturn_t via1_irq(int, void *); 82irqreturn_t via1_irq(int, void *);
@@ -138,11 +154,11 @@ void __init via_init(void)
138 154
139 printk(KERN_INFO "VIA2 at %p is ", via2); 155 printk(KERN_INFO "VIA2 at %p is ", via2);
140 if (rbv_present) { 156 if (rbv_present) {
141 printk(KERN_INFO "an RBV\n"); 157 printk("an RBV\n");
142 } else if (oss_present) { 158 } else if (oss_present) {
143 printk(KERN_INFO "an OSS\n"); 159 printk("an OSS\n");
144 } else { 160 } else {
145 printk(KERN_INFO "a 6522 or clone\n"); 161 printk("a 6522 or clone\n");
146 } 162 }
147 163
148#ifdef DEBUG_VIA 164#ifdef DEBUG_VIA
@@ -163,6 +179,7 @@ void __init via_init(void)
163 via1[vT2CL] = 0; 179 via1[vT2CL] = 0;
164 via1[vT2CH] = 0; 180 via1[vT2CH] = 0;
165 via1[vACR] &= 0x3F; 181 via1[vACR] &= 0x3F;
182 via1[vACR] &= ~0x03; /* disable port A & B latches */
166 183
167 /* 184 /*
168 * SE/30: disable video IRQ 185 * SE/30: disable video IRQ
@@ -193,8 +210,14 @@ void __init via_init(void)
193 /* that the IIfx emulates this alternate mapping using the OSS. */ 210 /* that the IIfx emulates this alternate mapping using the OSS. */
194 211
195 switch(macintosh_config->ident) { 212 switch(macintosh_config->ident) {
213 case MAC_MODEL_P475:
214 case MAC_MODEL_P475F:
215 case MAC_MODEL_P575:
216 case MAC_MODEL_Q605:
217 case MAC_MODEL_Q605_ACC:
196 case MAC_MODEL_C610: 218 case MAC_MODEL_C610:
197 case MAC_MODEL_Q610: 219 case MAC_MODEL_Q610:
220 case MAC_MODEL_Q630:
198 case MAC_MODEL_C650: 221 case MAC_MODEL_C650:
199 case MAC_MODEL_Q650: 222 case MAC_MODEL_Q650:
200 case MAC_MODEL_Q700: 223 case MAC_MODEL_Q700:
@@ -228,6 +251,22 @@ void __init via_init(void)
228 via2[vT2CL] = 0; 251 via2[vT2CL] = 0;
229 via2[vT2CH] = 0; 252 via2[vT2CH] = 0;
230 via2[vACR] &= 0x3F; 253 via2[vACR] &= 0x3F;
254 via2[vACR] &= ~0x03; /* disable port A & B latches */
255 }
256
257 /*
258 * Set vPCR for SCSI interrupts (but not on RBV)
259 */
260 if (!rbv_present) {
261 if (macintosh_config->scsi_type == MAC_SCSI_OLD) {
262 /* CB2 (IRQ) indep. input, positive edge */
263 /* CA2 (DRQ) indep. input, positive edge */
264 via2[vPCR] = 0x66;
265 } else {
266 /* CB2 (IRQ) indep. input, negative edge */
267 /* CA2 (DRQ) indep. input, negative edge */
268 via2[vPCR] = 0x22;
269 }
231 } 270 }
232} 271}
233 272
@@ -356,78 +395,75 @@ int via_get_cache_disable(void)
356 395
357void __init via_nubus_init(void) 396void __init via_nubus_init(void)
358{ 397{
359 /* don't set nubus_active = 0 here, it kills the Baboon */
360 /* interrupt that we've already registered. */
361
362 /* unlock nubus transactions */ 398 /* unlock nubus transactions */
363 399
364 if (!rbv_present) { 400 if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
401 (macintosh_config->adb_type != MAC_ADB_PB2)) {
365 /* set the line to be an output on non-RBV machines */ 402 /* set the line to be an output on non-RBV machines */
366 if ((macintosh_config->adb_type != MAC_ADB_PB1) && 403 if (!rbv_present)
367 (macintosh_config->adb_type != MAC_ADB_PB2)) {
368 via2[vDirB] |= 0x02; 404 via2[vDirB] |= 0x02;
369 }
370 }
371 405
372 /* this seems to be an ADB bit on PMU machines */ 406 /* this seems to be an ADB bit on PMU machines */
373 /* according to MkLinux. -- jmt */ 407 /* according to MkLinux. -- jmt */
374
375 if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
376 (macintosh_config->adb_type != MAC_ADB_PB2)) {
377 via2[gBufB] |= 0x02; 408 via2[gBufB] |= 0x02;
378 } 409 }
379 410
380 /* disable nubus slot interrupts. */ 411 /* Disable all the slot interrupts (where possible). */
381 if (rbv_present) { 412
413 switch (macintosh_config->via_type) {
414 case MAC_VIA_II:
415 /* Just make the port A lines inputs. */
416 switch(macintosh_config->ident) {
417 case MAC_MODEL_II:
418 case MAC_MODEL_IIX:
419 case MAC_MODEL_IICX:
420 case MAC_MODEL_SE30:
421 /* The top two bits are RAM size outputs. */
422 via2[vDirA] &= 0xC0;
423 break;
424 default:
425 via2[vDirA] &= 0x80;
426 }
427 break;
428 case MAC_VIA_IIci:
429 /* RBV. Disable all the slot interrupts. SIER works like IER. */
382 via2[rSIER] = 0x7F; 430 via2[rSIER] = 0x7F;
383 via2[rSIER] = nubus_active | 0x80; 431 break;
384 } else { 432 case MAC_VIA_QUADRA:
385 /* These are ADB bits on PMU */ 433 /* Disable the inactive slot interrupts by making those lines outputs. */
386 if ((macintosh_config->adb_type != MAC_ADB_PB1) && 434 if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
387 (macintosh_config->adb_type != MAC_ADB_PB2)) { 435 (macintosh_config->adb_type != MAC_ADB_PB2)) {
388 switch(macintosh_config->ident) 436 via2[vBufA] |= 0x7F;
389 { 437 via2[vDirA] |= 0x7F;
390 case MAC_MODEL_II:
391 case MAC_MODEL_IIX:
392 case MAC_MODEL_IICX:
393 case MAC_MODEL_SE30:
394 via2[vBufA] |= 0x3F;
395 via2[vDirA] = ~nubus_active | 0xc0;
396 break;
397 default:
398 via2[vBufA] = 0xFF;
399 via2[vDirA] = ~nubus_active;
400 }
401 } 438 }
439 break;
402 } 440 }
403} 441}
404 442
405/* 443/*
406 * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's 444 * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's
407 * via6522.c :-), disable/pending masks added. 445 * via6522.c :-), disable/pending masks added.
408 *
409 * The new interrupt architecture in macints.c takes care of a lot of the
410 * gruntwork for us, including tallying the interrupts and calling the
411 * handlers on the linked list. All we need to do here is basically generate
412 * the machspec interrupt number after clearing the interrupt.
413 */ 446 */
414 447
415irqreturn_t via1_irq(int irq, void *dev_id) 448irqreturn_t via1_irq(int irq, void *dev_id)
416{ 449{
417 int irq_bit, i; 450 int irq_num;
418 unsigned char events, mask; 451 unsigned char irq_bit, events;
419 452
420 mask = via1[vIER] & 0x7F; 453 events = via1[vIFR] & via1[vIER] & 0x7F;
421 if (!(events = via1[vIFR] & mask)) 454 if (!events)
422 return IRQ_NONE; 455 return IRQ_NONE;
423 456
424 for (i = 0, irq_bit = 1 ; i < 7 ; i++, irq_bit <<= 1) 457 irq_num = VIA1_SOURCE_BASE;
458 irq_bit = 1;
459 do {
425 if (events & irq_bit) { 460 if (events & irq_bit) {
426 via1[vIER] = irq_bit;
427 m68k_handle_int(VIA1_SOURCE_BASE + i);
428 via1[vIFR] = irq_bit; 461 via1[vIFR] = irq_bit;
429 via1[vIER] = irq_bit | 0x80; 462 m68k_handle_int(irq_num);
430 } 463 }
464 ++irq_num;
465 irq_bit <<= 1;
466 } while (events >= irq_bit);
431 467
432#if 0 /* freakin' pmu is doing weird stuff */ 468#if 0 /* freakin' pmu is doing weird stuff */
433 if (!oss_present) { 469 if (!oss_present) {
@@ -448,20 +484,23 @@ irqreturn_t via1_irq(int irq, void *dev_id)
448 484
449irqreturn_t via2_irq(int irq, void *dev_id) 485irqreturn_t via2_irq(int irq, void *dev_id)
450{ 486{
451 int irq_bit, i; 487 int irq_num;
452 unsigned char events, mask; 488 unsigned char irq_bit, events;
453 489
454 mask = via2[gIER] & 0x7F; 490 events = via2[gIFR] & via2[gIER] & 0x7F;
455 if (!(events = via2[gIFR] & mask)) 491 if (!events)
456 return IRQ_NONE; 492 return IRQ_NONE;
457 493
458 for (i = 0, irq_bit = 1 ; i < 7 ; i++, irq_bit <<= 1) 494 irq_num = VIA2_SOURCE_BASE;
495 irq_bit = 1;
496 do {
459 if (events & irq_bit) { 497 if (events & irq_bit) {
460 via2[gIER] = irq_bit;
461 via2[gIFR] = irq_bit | rbv_clear; 498 via2[gIFR] = irq_bit | rbv_clear;
462 m68k_handle_int(VIA2_SOURCE_BASE + i); 499 m68k_handle_int(irq_num);
463 via2[gIER] = irq_bit | 0x80;
464 } 500 }
501 ++irq_num;
502 irq_bit <<= 1;
503 } while (events >= irq_bit);
465 return IRQ_HANDLED; 504 return IRQ_HANDLED;
466} 505}
467 506
@@ -472,71 +511,75 @@ irqreturn_t via2_irq(int irq, void *dev_id)
472 511
473irqreturn_t via_nubus_irq(int irq, void *dev_id) 512irqreturn_t via_nubus_irq(int irq, void *dev_id)
474{ 513{
475 int irq_bit, i; 514 int slot_irq;
476 unsigned char events; 515 unsigned char slot_bit, events;
477 516
478 if (!(events = ~via2[gBufA] & nubus_active)) 517 events = ~via2[gBufA] & 0x7F;
518 if (rbv_present)
519 events &= via2[rSIER];
520 else
521 events &= ~via2[vDirA];
522 if (!events)
479 return IRQ_NONE; 523 return IRQ_NONE;
480 524
481 for (i = 0, irq_bit = 1 ; i < 7 ; i++, irq_bit <<= 1) { 525 do {
482 if (events & irq_bit) { 526 slot_irq = IRQ_NUBUS_F;
483 via_irq_disable(NUBUS_SOURCE_BASE + i); 527 slot_bit = 0x40;
484 m68k_handle_int(NUBUS_SOURCE_BASE + i); 528 do {
485 via_irq_enable(NUBUS_SOURCE_BASE + i); 529 if (events & slot_bit) {
486 } 530 events &= ~slot_bit;
487 } 531 m68k_handle_int(slot_irq);
532 }
533 --slot_irq;
534 slot_bit >>= 1;
535 } while (events);
536
537 /* clear the CA1 interrupt and make certain there's no more. */
538 via2[gIFR] = 0x02 | rbv_clear;
539 events = ~via2[gBufA] & 0x7F;
540 if (rbv_present)
541 events &= via2[rSIER];
542 else
543 events &= ~via2[vDirA];
544 } while (events);
488 return IRQ_HANDLED; 545 return IRQ_HANDLED;
489} 546}
490 547
491void via_irq_enable(int irq) { 548void via_irq_enable(int irq) {
492 int irq_src = IRQ_SRC(irq); 549 int irq_src = IRQ_SRC(irq);
493 int irq_idx = IRQ_IDX(irq); 550 int irq_idx = IRQ_IDX(irq);
494 int irq_bit = 1 << irq_idx;
495 551
496#ifdef DEBUG_IRQUSE 552#ifdef DEBUG_IRQUSE
497 printk(KERN_DEBUG "via_irq_enable(%d)\n", irq); 553 printk(KERN_DEBUG "via_irq_enable(%d)\n", irq);
498#endif 554#endif
499 555
500 if (irq_src == 1) { 556 if (irq_src == 1) {
501 via1[vIER] = irq_bit | 0x80; 557 via1[vIER] = IER_SET_BIT(irq_idx);
502 } else if (irq_src == 2) { 558 } else if (irq_src == 2) {
503 /* 559 if (irq != IRQ_MAC_NUBUS || nubus_disabled == 0)
504 * Set vPCR for SCSI interrupts (but not on RBV) 560 via2[gIER] = IER_SET_BIT(irq_idx);
505 */
506 if ((irq_idx == 0) && !rbv_present) {
507 if (macintosh_config->scsi_type == MAC_SCSI_OLD) {
508 /* CB2 (IRQ) indep. input, positive edge */
509 /* CA2 (DRQ) indep. input, positive edge */
510 via2[vPCR] = 0x66;
511 } else {
512 /* CB2 (IRQ) indep. input, negative edge */
513 /* CA2 (DRQ) indep. input, negative edge */
514 via2[vPCR] = 0x22;
515 }
516 }
517 via2[gIER] = irq_bit | 0x80;
518 } else if (irq_src == 7) { 561 } else if (irq_src == 7) {
519 nubus_active |= irq_bit; 562 switch (macintosh_config->via_type) {
520 if (rbv_present) { 563 case MAC_VIA_II:
521 /* enable the slot interrupt. SIER works like IER. */ 564 nubus_disabled &= ~(1 << irq_idx);
565 /* Enable the CA1 interrupt when no slot is disabled. */
566 if (!nubus_disabled)
567 via2[gIER] = IER_SET_BIT(1);
568 break;
569 case MAC_VIA_IIci:
570 /* On RBV, enable the slot interrupt.
571 * SIER works like IER.
572 */
522 via2[rSIER] = IER_SET_BIT(irq_idx); 573 via2[rSIER] = IER_SET_BIT(irq_idx);
523 } else { 574 break;
524 /* Make sure the bit is an input, to enable the irq */ 575 case MAC_VIA_QUADRA:
525 /* But not on PowerBooks, that's ADB... */ 576 /* Make the port A line an input to enable the slot irq.
577 * But not on PowerBooks, that's ADB.
578 */
526 if ((macintosh_config->adb_type != MAC_ADB_PB1) && 579 if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
527 (macintosh_config->adb_type != MAC_ADB_PB2)) { 580 (macintosh_config->adb_type != MAC_ADB_PB2))
528 switch(macintosh_config->ident) 581 via2[vDirA] &= ~(1 << irq_idx);
529 { 582 break;
530 case MAC_MODEL_II:
531 case MAC_MODEL_IIX:
532 case MAC_MODEL_IICX:
533 case MAC_MODEL_SE30:
534 via2[vDirA] &= (~irq_bit | 0xc0);
535 break;
536 default:
537 via2[vDirA] &= ~irq_bit;
538 }
539 }
540 } 583 }
541 } 584 }
542} 585}
@@ -544,29 +587,31 @@ void via_irq_enable(int irq) {
544void via_irq_disable(int irq) { 587void via_irq_disable(int irq) {
545 int irq_src = IRQ_SRC(irq); 588 int irq_src = IRQ_SRC(irq);
546 int irq_idx = IRQ_IDX(irq); 589 int irq_idx = IRQ_IDX(irq);
547 int irq_bit = 1 << irq_idx;
548 590
549#ifdef DEBUG_IRQUSE 591#ifdef DEBUG_IRQUSE
550 printk(KERN_DEBUG "via_irq_disable(%d)\n", irq); 592 printk(KERN_DEBUG "via_irq_disable(%d)\n", irq);
551#endif 593#endif
552 594
553 if (irq_src == 1) { 595 if (irq_src == 1) {
554 via1[vIER] = irq_bit; 596 via1[vIER] = IER_CLR_BIT(irq_idx);
555 } else if (irq_src == 2) { 597 } else if (irq_src == 2) {
556 via2[gIER] = irq_bit; 598 via2[gIER] = IER_CLR_BIT(irq_idx);
557 } else if (irq_src == 7) { 599 } else if (irq_src == 7) {
558 if (rbv_present) { 600 switch (macintosh_config->via_type) {
559 /* disable the slot interrupt. SIER works like IER. */ 601 case MAC_VIA_II:
602 nubus_disabled |= 1 << irq_idx;
603 if (nubus_disabled)
604 via2[gIER] = IER_CLR_BIT(1);
605 break;
606 case MAC_VIA_IIci:
560 via2[rSIER] = IER_CLR_BIT(irq_idx); 607 via2[rSIER] = IER_CLR_BIT(irq_idx);
561 } else { 608 break;
562 /* disable the nubus irq by changing dir to output */ 609 case MAC_VIA_QUADRA:
563 /* except on PMU */
564 if ((macintosh_config->adb_type != MAC_ADB_PB1) && 610 if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
565 (macintosh_config->adb_type != MAC_ADB_PB2)) { 611 (macintosh_config->adb_type != MAC_ADB_PB2))
566 via2[vDirA] |= irq_bit; 612 via2[vDirA] |= 1 << irq_idx;
567 } 613 break;
568 } 614 }
569 nubus_active &= ~irq_bit;
570 } 615 }
571} 616}
572 617
@@ -580,7 +625,9 @@ void via_irq_clear(int irq) {
580 } else if (irq_src == 2) { 625 } else if (irq_src == 2) {
581 via2[gIFR] = irq_bit | rbv_clear; 626 via2[gIFR] = irq_bit | rbv_clear;
582 } else if (irq_src == 7) { 627 } else if (irq_src == 7) {
583 /* FIXME: hmm.. */ 628 /* FIXME: There is no way to clear an individual nubus slot
629 * IRQ flag, other than getting the device to do it.
630 */
584 } 631 }
585} 632}
586 633
@@ -600,6 +647,7 @@ int via_irq_pending(int irq)
600 } else if (irq_src == 2) { 647 } else if (irq_src == 2) {
601 return via2[gIFR] & irq_bit; 648 return via2[gIFR] & irq_bit;
602 } else if (irq_src == 7) { 649 } else if (irq_src == 7) {
650 /* Always 0 for MAC_VIA_QUADRA if the slot irq is disabled. */
603 return ~via2[gBufA] & irq_bit; 651 return ~via2[gBufA] & irq_bit;
604 } 652 }
605 return 0; 653 return 0;
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index 92f873cc7060..476e18eca758 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -35,35 +35,35 @@
35#include <asm/machdep.h> 35#include <asm/machdep.h>
36#include <asm/q40_master.h> 36#include <asm/q40_master.h>
37 37
38extern irqreturn_t q40_process_int (int level, struct pt_regs *regs); 38extern irqreturn_t q40_process_int(int level, struct pt_regs *regs);
39extern void q40_init_IRQ (void); 39extern void q40_init_IRQ(void);
40static void q40_get_model(char *model); 40static void q40_get_model(char *model);
41static int q40_get_hardware_list(char *buffer); 41static int q40_get_hardware_list(char *buffer);
42extern void q40_sched_init(irq_handler_t handler); 42extern void q40_sched_init(irq_handler_t handler);
43 43
44extern unsigned long q40_gettimeoffset (void); 44extern unsigned long q40_gettimeoffset(void);
45extern int q40_hwclk (int, struct rtc_time *); 45extern int q40_hwclk(int, struct rtc_time *);
46extern unsigned int q40_get_ss (void); 46extern unsigned int q40_get_ss(void);
47extern int q40_set_clock_mmss (unsigned long); 47extern int q40_set_clock_mmss(unsigned long);
48static int q40_get_rtc_pll(struct rtc_pll_info *pll); 48static int q40_get_rtc_pll(struct rtc_pll_info *pll);
49static int q40_set_rtc_pll(struct rtc_pll_info *pll); 49static int q40_set_rtc_pll(struct rtc_pll_info *pll);
50extern void q40_reset (void); 50extern void q40_reset(void);
51void q40_halt(void); 51void q40_halt(void);
52extern void q40_waitbut(void); 52extern void q40_waitbut(void);
53void q40_set_vectors (void); 53void q40_set_vectors(void);
54 54
55extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/ ); 55extern void q40_mksound(unsigned int /*freq*/, unsigned int /*ticks*/);
56 56
57extern char m68k_debug_device[];
58static void q40_mem_console_write(struct console *co, const char *b, 57static void q40_mem_console_write(struct console *co, const char *b,
59 unsigned int count); 58 unsigned int count);
60 59
61extern int ql_ticks; 60extern int ql_ticks;
62 61
63static struct console q40_console_driver = { 62static struct console q40_console_driver = {
64 .name = "debug", 63 .name = "debug",
65 .flags = CON_PRINTBUFFER, 64 .write = q40_mem_console_write,
66 .index = -1, 65 .flags = CON_PRINTBUFFER,
66 .index = -1,
67}; 67};
68 68
69 69
@@ -74,150 +74,162 @@ static int _cpleft;
74static void q40_mem_console_write(struct console *co, const char *s, 74static void q40_mem_console_write(struct console *co, const char *s,
75 unsigned int count) 75 unsigned int count)
76{ 76{
77 char *p=(char *)s; 77 const char *p = s;
78 78
79 if (count<_cpleft) 79 if (count < _cpleft) {
80 while (count-- >0){ 80 while (count-- > 0) {
81 *q40_mem_cptr=*p++; 81 *q40_mem_cptr = *p++;
82 q40_mem_cptr+=4; 82 q40_mem_cptr += 4;
83 _cpleft--; 83 _cpleft--;
84 } 84 }
85 }
86}
87
88static int __init q40_debug_setup(char *arg)
89{
90 /* useful for early debugging stages - writes kernel messages into SRAM */
91 if (MACH_IS_Q40 && !strncmp(arg, "mem", 3)) {
92 /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
93 _cpleft = 2000 - ((long)q40_mem_cptr-0xff020000) / 4;
94 register_console(&q40_console_driver);
95 }
96 return 0;
85} 97}
98
99early_param("debug", q40_debug_setup);
100
86#if 0 101#if 0
87void printq40(char *str) 102void printq40(char *str)
88{ 103{
89 int l=strlen(str); 104 int l = strlen(str);
90 char *p=q40_mem_cptr; 105 char *p = q40_mem_cptr;
91 106
92 while (l-- >0 && _cpleft-- >0) 107 while (l-- > 0 && _cpleft-- > 0) {
93 { 108 *p = *str++;
94 *p=*str++; 109 p += 4;
95 p+=4; 110 }
96 } 111 q40_mem_cptr = p;
97 q40_mem_cptr=p;
98} 112}
99#endif 113#endif
100 114
101static int halted=0; 115static int halted;
102 116
103#ifdef CONFIG_HEARTBEAT 117#ifdef CONFIG_HEARTBEAT
104static void q40_heartbeat(int on) 118static void q40_heartbeat(int on)
105{ 119{
106 if (halted) return; 120 if (halted)
121 return;
107 122
108 if (on) 123 if (on)
109 Q40_LED_ON(); 124 Q40_LED_ON();
110 else 125 else
111 Q40_LED_OFF(); 126 Q40_LED_OFF();
112} 127}
113#endif 128#endif
114 129
115void q40_reset(void) 130void q40_reset(void)
116{ 131{
117 halted=1; 132 halted = 1;
118 printk ("\n\n*******************************************\n" 133 printk("\n\n*******************************************\n"
119 "Called q40_reset : press the RESET button!! \n" 134 "Called q40_reset : press the RESET button!! \n"
120 "*******************************************\n"); 135 "*******************************************\n");
121 Q40_LED_ON(); 136 Q40_LED_ON();
122 while(1) ; 137 while (1)
138 ;
123} 139}
124void q40_halt(void) 140void q40_halt(void)
125{ 141{
126 halted=1; 142 halted = 1;
127 printk ("\n\n*******************\n" 143 printk("\n\n*******************\n"
128 " Called q40_halt\n" 144 " Called q40_halt\n"
129 "*******************\n"); 145 "*******************\n");
130 Q40_LED_ON(); 146 Q40_LED_ON();
131 while(1) ; 147 while (1)
148 ;
132} 149}
133 150
134static void q40_get_model(char *model) 151static void q40_get_model(char *model)
135{ 152{
136 sprintf(model, "Q40"); 153 sprintf(model, "Q40");
137} 154}
138 155
139/* No hardware options on Q40? */ 156/* No hardware options on Q40? */
140 157
141static int q40_get_hardware_list(char *buffer) 158static int q40_get_hardware_list(char *buffer)
142{ 159{
143 *buffer = '\0'; 160 *buffer = '\0';
144 return 0; 161 return 0;
145} 162}
146 163
147static unsigned int serports[]={0x3f8,0x2f8,0x3e8,0x2e8,0}; 164static unsigned int serports[] =
165{
166 0x3f8,0x2f8,0x3e8,0x2e8,0
167};
148void q40_disable_irqs(void) 168void q40_disable_irqs(void)
149{ 169{
150 unsigned i,j; 170 unsigned i, j;
151 171
152 j=0; 172 j = 0;
153 while((i=serports[j++])) outb(0,i+UART_IER); 173 while ((i = serports[j++]))
154 master_outb(0,EXT_ENABLE_REG); 174 outb(0, i + UART_IER);
155 master_outb(0,KEY_IRQ_ENABLE_REG); 175 master_outb(0, EXT_ENABLE_REG);
176 master_outb(0, KEY_IRQ_ENABLE_REG);
156} 177}
157 178
158void __init config_q40(void) 179void __init config_q40(void)
159{ 180{
160 mach_sched_init = q40_sched_init; 181 mach_sched_init = q40_sched_init;
161 182
162 mach_init_IRQ = q40_init_IRQ; 183 mach_init_IRQ = q40_init_IRQ;
163 mach_gettimeoffset = q40_gettimeoffset; 184 mach_gettimeoffset = q40_gettimeoffset;
164 mach_hwclk = q40_hwclk; 185 mach_hwclk = q40_hwclk;
165 mach_get_ss = q40_get_ss; 186 mach_get_ss = q40_get_ss;
166 mach_get_rtc_pll = q40_get_rtc_pll; 187 mach_get_rtc_pll = q40_get_rtc_pll;
167 mach_set_rtc_pll = q40_set_rtc_pll; 188 mach_set_rtc_pll = q40_set_rtc_pll;
168 mach_set_clock_mmss = q40_set_clock_mmss; 189 mach_set_clock_mmss = q40_set_clock_mmss;
169 190
170 mach_reset = q40_reset; 191 mach_reset = q40_reset;
171 mach_get_model = q40_get_model; 192 mach_get_model = q40_get_model;
172 mach_get_hardware_list = q40_get_hardware_list; 193 mach_get_hardware_list = q40_get_hardware_list;
173 194
174#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE) 195#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
175 mach_beep = q40_mksound; 196 mach_beep = q40_mksound;
176#endif 197#endif
177#ifdef CONFIG_HEARTBEAT 198#ifdef CONFIG_HEARTBEAT
178 mach_heartbeat = q40_heartbeat; 199 mach_heartbeat = q40_heartbeat;
179#endif 200#endif
180 mach_halt = q40_halt; 201 mach_halt = q40_halt;
181 202
182 /* disable a few things that SMSQ might have left enabled */ 203 /* disable a few things that SMSQ might have left enabled */
183 q40_disable_irqs(); 204 q40_disable_irqs();
184 205
185 /* no DMA at all, but ide-scsi requires it.. make sure 206 /* no DMA at all, but ide-scsi requires it.. make sure
186 * all physical RAM fits into the boundary - otherwise 207 * all physical RAM fits into the boundary - otherwise
187 * allocator may play costly and useless tricks */ 208 * allocator may play costly and useless tricks */
188 mach_max_dma_address = 1024*1024*1024; 209 mach_max_dma_address = 1024*1024*1024;
189
190 /* useful for early debugging stages - writes kernel messages into SRAM */
191 if (!strncmp( m68k_debug_device,"mem",3 ))
192 {
193 /*printk("using NVRAM debug, q40_mem_cptr=%p\n",q40_mem_cptr);*/
194 _cpleft=2000-((long)q40_mem_cptr-0xff020000)/4;
195 q40_console_driver.write = q40_mem_console_write;
196 register_console(&q40_console_driver);
197 }
198} 210}
199 211
200 212
201int q40_parse_bootinfo(const struct bi_record *rec) 213int q40_parse_bootinfo(const struct bi_record *rec)
202{ 214{
203 return 1; 215 return 1;
204} 216}
205 217
206 218
207static inline unsigned char bcd2bin (unsigned char b) 219static inline unsigned char bcd2bin(unsigned char b)
208{ 220{
209 return ((b>>4)*10 + (b&15)); 221 return (b >> 4) * 10 + (b & 15);
210} 222}
211 223
212static inline unsigned char bin2bcd (unsigned char b) 224static inline unsigned char bin2bcd(unsigned char b)
213{ 225{
214 return (((b/10)*16) + (b%10)); 226 return (b / 10) * 16 + (b % 10);
215} 227}
216 228
217 229
218unsigned long q40_gettimeoffset (void) 230unsigned long q40_gettimeoffset(void)
219{ 231{
220 return 5000*(ql_ticks!=0); 232 return 5000 * (ql_ticks != 0);
221} 233}
222 234
223 235
@@ -238,9 +250,9 @@ unsigned long q40_gettimeoffset (void)
238 250
239int q40_hwclk(int op, struct rtc_time *t) 251int q40_hwclk(int op, struct rtc_time *t)
240{ 252{
241 if (op) 253 if (op) {
242 { /* Write.... */ 254 /* Write.... */
243 Q40_RTC_CTRL |= Q40_RTC_WRITE; 255 Q40_RTC_CTRL |= Q40_RTC_WRITE;
244 256
245 Q40_RTC_SECS = bin2bcd(t->tm_sec); 257 Q40_RTC_SECS = bin2bcd(t->tm_sec);
246 Q40_RTC_MINS = bin2bcd(t->tm_min); 258 Q40_RTC_MINS = bin2bcd(t->tm_min);
@@ -251,25 +263,23 @@ int q40_hwclk(int op, struct rtc_time *t)
251 if (t->tm_wday >= 0) 263 if (t->tm_wday >= 0)
252 Q40_RTC_DOW = bin2bcd(t->tm_wday+1); 264 Q40_RTC_DOW = bin2bcd(t->tm_wday+1);
253 265
254 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); 266 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
255 } 267 } else {
256 else 268 /* Read.... */
257 { /* Read.... */ 269 Q40_RTC_CTRL |= Q40_RTC_READ;
258 Q40_RTC_CTRL |= Q40_RTC_READ; 270
259 271 t->tm_year = bcd2bin (Q40_RTC_YEAR);
260 t->tm_year = bcd2bin (Q40_RTC_YEAR); 272 t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1;
261 t->tm_mon = bcd2bin (Q40_RTC_MNTH)-1; 273 t->tm_mday = bcd2bin (Q40_RTC_DATE);
262 t->tm_mday = bcd2bin (Q40_RTC_DATE); 274 t->tm_hour = bcd2bin (Q40_RTC_HOUR);
263 t->tm_hour = bcd2bin (Q40_RTC_HOUR); 275 t->tm_min = bcd2bin (Q40_RTC_MINS);
264 t->tm_min = bcd2bin (Q40_RTC_MINS); 276 t->tm_sec = bcd2bin (Q40_RTC_SECS);
265 t->tm_sec = bcd2bin (Q40_RTC_SECS); 277
266 278 Q40_RTC_CTRL &= ~(Q40_RTC_READ);
267 Q40_RTC_CTRL &= ~(Q40_RTC_READ); 279
268 280 if (t->tm_year < 70)
269 if (t->tm_year < 70) 281 t->tm_year += 100;
270 t->tm_year += 100; 282 t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
271 t->tm_wday = bcd2bin(Q40_RTC_DOW)-1;
272
273 } 283 }
274 284
275 return 0; 285 return 0;
@@ -285,29 +295,25 @@ unsigned int q40_get_ss(void)
285 * clock is out by > 30 minutes. Logic lifted from atari code. 295 * clock is out by > 30 minutes. Logic lifted from atari code.
286 */ 296 */
287 297
288int q40_set_clock_mmss (unsigned long nowtime) 298int q40_set_clock_mmss(unsigned long nowtime)
289{ 299{
290 int retval = 0; 300 int retval = 0;
291 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60; 301 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
292 302
293 int rtc_minutes; 303 int rtc_minutes;
294 304
305 rtc_minutes = bcd2bin(Q40_RTC_MINS);
295 306
296 rtc_minutes = bcd2bin (Q40_RTC_MINS); 307 if ((rtc_minutes < real_minutes ?
297 308 real_minutes - rtc_minutes :
298 if ((rtc_minutes < real_minutes 309 rtc_minutes - real_minutes) < 30) {
299 ? real_minutes - rtc_minutes 310 Q40_RTC_CTRL |= Q40_RTC_WRITE;
300 : rtc_minutes - real_minutes) < 30)
301 {
302 Q40_RTC_CTRL |= Q40_RTC_WRITE;
303 Q40_RTC_MINS = bin2bcd(real_minutes); 311 Q40_RTC_MINS = bin2bcd(real_minutes);
304 Q40_RTC_SECS = bin2bcd(real_seconds); 312 Q40_RTC_SECS = bin2bcd(real_seconds);
305 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE); 313 Q40_RTC_CTRL &= ~(Q40_RTC_WRITE);
306 } 314 } else
307 else
308 retval = -1; 315 retval = -1;
309 316
310
311 return retval; 317 return retval;
312} 318}
313 319
@@ -318,21 +324,23 @@ int q40_set_clock_mmss (unsigned long nowtime)
318 324
319static int q40_get_rtc_pll(struct rtc_pll_info *pll) 325static int q40_get_rtc_pll(struct rtc_pll_info *pll)
320{ 326{
321 int tmp=Q40_RTC_CTRL; 327 int tmp = Q40_RTC_CTRL;
328
322 pll->pll_value = tmp & Q40_RTC_PLL_MASK; 329 pll->pll_value = tmp & Q40_RTC_PLL_MASK;
323 if (tmp & Q40_RTC_PLL_SIGN) 330 if (tmp & Q40_RTC_PLL_SIGN)
324 pll->pll_value = -pll->pll_value; 331 pll->pll_value = -pll->pll_value;
325 pll->pll_max=31; 332 pll->pll_max = 31;
326 pll->pll_min=-31; 333 pll->pll_min = -31;
327 pll->pll_posmult=512; 334 pll->pll_posmult = 512;
328 pll->pll_negmult=256; 335 pll->pll_negmult = 256;
329 pll->pll_clock=125829120; 336 pll->pll_clock = 125829120;
337
330 return 0; 338 return 0;
331} 339}
332 340
333static int q40_set_rtc_pll(struct rtc_pll_info *pll) 341static int q40_set_rtc_pll(struct rtc_pll_info *pll)
334{ 342{
335 if (!pll->pll_ctrl){ 343 if (!pll->pll_ctrl) {
336 /* the docs are a bit unclear so I am doublesetting */ 344 /* the docs are a bit unclear so I am doublesetting */
337 /* RTC_WRITE here ... */ 345 /* RTC_WRITE here ... */
338 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) | 346 int tmp = (pll->pll_value & 31) | (pll->pll_value<0 ? 32 : 0) |
diff --git a/arch/m68k/sun3/sun3ints.c b/arch/m68k/sun3/sun3ints.c
index baf74e8de8b5..4232a2c2fae9 100644
--- a/arch/m68k/sun3/sun3ints.c
+++ b/arch/m68k/sun3/sun3ints.c
@@ -103,7 +103,7 @@ void sun3_init_IRQ(void)
103 103
104 m68k_setup_auto_interrupt(sun3_inthandle); 104 m68k_setup_auto_interrupt(sun3_inthandle);
105 m68k_setup_irq_controller(&sun3_irq_controller, IRQ_AUTO_1, 7); 105 m68k_setup_irq_controller(&sun3_irq_controller, IRQ_AUTO_1, 7);
106 m68k_setup_user_interrupt(VEC_USER, 192, NULL); 106 m68k_setup_user_interrupt(VEC_USER, 128, NULL);
107 107
108 request_irq(IRQ_AUTO_5, sun3_int5, 0, "int5", NULL); 108 request_irq(IRQ_AUTO_5, sun3_int5, 0, "int5", NULL);
109 request_irq(IRQ_AUTO_7, sun3_int7, 0, "int7", NULL); 109 request_irq(IRQ_AUTO_7, sun3_int7, 0, "int7", NULL);
diff --git a/arch/m68k/sun3x/prom.c b/arch/m68k/sun3x/prom.c
index 574cf06df9e4..48f8eb7b1565 100644
--- a/arch/m68k/sun3x/prom.c
+++ b/arch/m68k/sun3x/prom.c
@@ -34,100 +34,101 @@ e_vector *sun3x_prom_vbr;
34/* Handle returning to the prom */ 34/* Handle returning to the prom */
35void sun3x_halt(void) 35void sun3x_halt(void)
36{ 36{
37 unsigned long flags; 37 unsigned long flags;
38 38
39 /* Disable interrupts while we mess with things */ 39 /* Disable interrupts while we mess with things */
40 local_irq_save(flags); 40 local_irq_save(flags);
41 41
42 /* Restore prom vbr */ 42 /* Restore prom vbr */
43 __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr)); 43 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
44 44
45 /* Restore prom NMI clock */ 45 /* Restore prom NMI clock */
46// sun3x_disable_intreg(5); 46// sun3x_disable_intreg(5);
47 sun3_enable_irq(7); 47 sun3_enable_irq(7);
48 48
49 /* Let 'er rip */ 49 /* Let 'er rip */
50 __asm__ volatile ("trap #14" : : ); 50 asm volatile ("trap #14");
51 51
52 /* Restore everything */ 52 /* Restore everything */
53 sun3_disable_irq(7); 53 sun3_disable_irq(7);
54 sun3_enable_irq(5); 54 sun3_enable_irq(5);
55 55
56 __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)vectors)); 56 asm volatile ("movec %0,%%vbr" : : "r" ((void*)vectors));
57 local_irq_restore(flags); 57 local_irq_restore(flags);
58} 58}
59 59
60void sun3x_reboot(void) 60void sun3x_reboot(void)
61{ 61{
62 /* This never returns, don't bother saving things */ 62 /* This never returns, don't bother saving things */
63 local_irq_disable(); 63 local_irq_disable();
64 64
65 /* Restore prom vbr */ 65 /* Restore prom vbr */
66 __asm__ volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr)); 66 asm volatile ("movec %0,%%vbr" : : "r" ((void*)sun3x_prom_vbr));
67 67
68 /* Restore prom NMI clock */ 68 /* Restore prom NMI clock */
69 sun3_disable_irq(5); 69 sun3_disable_irq(5);
70 sun3_enable_irq(7); 70 sun3_enable_irq(7);
71 71
72 /* Let 'er rip */ 72 /* Let 'er rip */
73 (*romvec->pv_reboot)("vmlinux"); 73 (*romvec->pv_reboot)("vmlinux");
74} 74}
75 75
76extern char m68k_debug_device[];
77
78static void sun3x_prom_write(struct console *co, const char *s, 76static void sun3x_prom_write(struct console *co, const char *s,
79 unsigned int count) 77 unsigned int count)
80{ 78{
81 while (count--) { 79 while (count--) {
82 if (*s == '\n') 80 if (*s == '\n')
83 sun3x_putchar('\r'); 81 sun3x_putchar('\r');
84 sun3x_putchar(*s++); 82 sun3x_putchar(*s++);
85 } 83 }
86} 84}
87 85
88/* debug console - write-only */ 86/* debug console - write-only */
89 87
90static struct console sun3x_debug = { 88static struct console sun3x_debug = {
91 .name = "debug", 89 .name = "debug",
92 .write = sun3x_prom_write, 90 .write = sun3x_prom_write,
93 .flags = CON_PRINTBUFFER, 91 .flags = CON_PRINTBUFFER,
94 .index = -1, 92 .index = -1,
95}; 93};
96 94
97void sun3x_prom_init(void) 95void sun3x_prom_init(void)
98{ 96{
99 /* Read the vector table */ 97 /* Read the vector table */
100 98
101 sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR); 99 sun3x_putchar = *(void (**)(int)) (SUN3X_P_PUTCHAR);
102 sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR); 100 sun3x_getchar = *(int (**)(void)) (SUN3X_P_GETCHAR);
103 sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET); 101 sun3x_mayget = *(int (**)(void)) (SUN3X_P_MAYGET);
104 sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT); 102 sun3x_mayput = *(int (**)(int)) (SUN3X_P_MAYPUT);
105 sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT); 103 sun3x_prom_reboot = *(void (**)(void)) (SUN3X_P_REBOOT);
106 sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT); 104 sun3x_prom_abort = *(e_vector *) (SUN3X_P_ABORT);
107 romvec = (struct linux_romvec *)SUN3X_PROM_BASE; 105 romvec = (struct linux_romvec *)SUN3X_PROM_BASE;
108 106
109 idprom_init(); 107 idprom_init();
110 108
111 if(!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) { 109 if (!((idprom->id_machtype & SM_ARCH_MASK) == SM_SUN3X)) {
112 printk("Warning: machine reports strange type %02x\n", 110 printk("Warning: machine reports strange type %02x\n",
113 idprom->id_machtype); 111 idprom->id_machtype);
114 printk("Pretending it's a 3/80, but very afraid...\n"); 112 printk("Pretending it's a 3/80, but very afraid...\n");
115 idprom->id_machtype = SM_SUN3X | SM_3_80; 113 idprom->id_machtype = SM_SUN3X | SM_3_80;
116 } 114 }
117 115
118 /* point trap #14 at abort. 116 /* point trap #14 at abort.
119 * XXX this is futile since we restore the vbr first - oops 117 * XXX this is futile since we restore the vbr first - oops
120 */ 118 */
121 vectors[VEC_TRAP14] = sun3x_prom_abort; 119 vectors[VEC_TRAP14] = sun3x_prom_abort;
122 120}
123 /* If debug=prom was specified, start the debug console */
124
125 if (!strcmp(m68k_debug_device, "prom"))
126 register_console(&sun3x_debug);
127
128 121
122static int __init sun3x_debug_setup(char *arg)
123{
124 /* If debug=prom was specified, start the debug console */
125 if (MACH_IS_SUN3X && !strcmp(arg, "prom"))
126 register_console(&sun3x_debug);
127 return 0;
129} 128}
130 129
130early_param("debug", sun3x_debug_setup);
131
131/* some prom functions to export */ 132/* some prom functions to export */
132int prom_getintdefault(int node, char *property, int deflt) 133int prom_getintdefault(int node, char *property, int deflt)
133{ 134{
@@ -141,7 +142,6 @@ int prom_getbool (int node, char *prop)
141 142
142void prom_printf(char *fmt, ...) 143void prom_printf(char *fmt, ...)
143{ 144{
144
145} 145}
146 146
147void prom_halt (void) 147void prom_halt (void)
@@ -159,7 +159,7 @@ prom_get_idprom(char *idbuf, int num_bytes)
159 int i; 159 int i;
160 160
161 /* make a copy of the idprom structure */ 161 /* make a copy of the idprom structure */
162 for(i = 0; i < num_bytes; i++) 162 for (i = 0; i < num_bytes; i++)
163 idbuf[i] = ((char *)SUN3X_IDPROM)[i]; 163 idbuf[i] = ((char *)SUN3X_IDPROM)[i];
164 164
165 return idbuf[0]; 165 return idbuf[0];
diff --git a/arch/powerpc/platforms/powermac/cpufreq_32.c b/arch/powerpc/platforms/powermac/cpufreq_32.c
index 8943a9456bb7..1fe35dab0e9e 100644
--- a/arch/powerpc/platforms/powermac/cpufreq_32.c
+++ b/arch/powerpc/platforms/powermac/cpufreq_32.c
@@ -25,7 +25,6 @@
25#include <linux/cpufreq.h> 25#include <linux/cpufreq.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/sysdev.h> 27#include <linux/sysdev.h>
28#include <linux/i2c.h>
29#include <linux/hardirq.h> 28#include <linux/hardirq.h>
30#include <asm/prom.h> 29#include <asm/prom.h>
31#include <asm/machdep.h> 30#include <asm/machdep.h>
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 91636353f6f0..3660ca6a3306 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -119,7 +119,8 @@ static struct crypto_alg aes_alg = {
119 .cra_name = "aes", 119 .cra_name = "aes",
120 .cra_driver_name = "aes-s390", 120 .cra_driver_name = "aes-s390",
121 .cra_priority = CRYPT_S390_PRIORITY, 121 .cra_priority = CRYPT_S390_PRIORITY,
122 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 122 .cra_flags = CRYPTO_ALG_TYPE_CIPHER |
123 CRYPTO_ALG_NEED_FALLBACK,
123 .cra_blocksize = AES_BLOCK_SIZE, 124 .cra_blocksize = AES_BLOCK_SIZE,
124 .cra_ctxsize = sizeof(struct s390_aes_ctx), 125 .cra_ctxsize = sizeof(struct s390_aes_ctx),
125 .cra_module = THIS_MODULE, 126 .cra_module = THIS_MODULE,
@@ -206,7 +207,8 @@ static struct crypto_alg ecb_aes_alg = {
206 .cra_name = "ecb(aes)", 207 .cra_name = "ecb(aes)",
207 .cra_driver_name = "ecb-aes-s390", 208 .cra_driver_name = "ecb-aes-s390",
208 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 209 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
209 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 210 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
211 CRYPTO_ALG_NEED_FALLBACK,
210 .cra_blocksize = AES_BLOCK_SIZE, 212 .cra_blocksize = AES_BLOCK_SIZE,
211 .cra_ctxsize = sizeof(struct s390_aes_ctx), 213 .cra_ctxsize = sizeof(struct s390_aes_ctx),
212 .cra_type = &crypto_blkcipher_type, 214 .cra_type = &crypto_blkcipher_type,
@@ -300,7 +302,8 @@ static struct crypto_alg cbc_aes_alg = {
300 .cra_name = "cbc(aes)", 302 .cra_name = "cbc(aes)",
301 .cra_driver_name = "cbc-aes-s390", 303 .cra_driver_name = "cbc-aes-s390",
302 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 304 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
303 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 305 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
306 CRYPTO_ALG_NEED_FALLBACK,
304 .cra_blocksize = AES_BLOCK_SIZE, 307 .cra_blocksize = AES_BLOCK_SIZE,
305 .cra_ctxsize = sizeof(struct s390_aes_ctx), 308 .cra_ctxsize = sizeof(struct s390_aes_ctx),
306 .cra_type = &crypto_blkcipher_type, 309 .cra_type = &crypto_blkcipher_type,
@@ -333,10 +336,14 @@ static int __init aes_init(void)
333 return -EOPNOTSUPP; 336 return -EOPNOTSUPP;
334 337
335 /* z9 109 and z9 BC/EC only support 128 bit key length */ 338 /* z9 109 and z9 BC/EC only support 128 bit key length */
336 if (keylen_flag == AES_KEYLEN_128) 339 if (keylen_flag == AES_KEYLEN_128) {
340 aes_alg.cra_u.cipher.cia_max_keysize = AES_MIN_KEY_SIZE;
341 ecb_aes_alg.cra_u.blkcipher.max_keysize = AES_MIN_KEY_SIZE;
342 cbc_aes_alg.cra_u.blkcipher.max_keysize = AES_MIN_KEY_SIZE;
337 printk(KERN_INFO 343 printk(KERN_INFO
338 "aes_s390: hardware acceleration only available for" 344 "aes_s390: hardware acceleration only available for"
339 "128 bit keys\n"); 345 "128 bit keys\n");
346 }
340 347
341 ret = crypto_register_alg(&aes_alg); 348 ret = crypto_register_alg(&aes_alg);
342 if (ret) 349 if (ret)
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 993f35381496..23c61f6d965b 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -516,7 +516,7 @@ out:
516 return 1; 516 return 1;
517} 517}
518 518
519static int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr) 519int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
520{ 520{
521 struct kprobe *cur = kprobe_running(); 521 struct kprobe *cur = kprobe_running();
522 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 522 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -603,7 +603,6 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
603 ret = NOTIFY_STOP; 603 ret = NOTIFY_STOP;
604 break; 604 break;
605 case DIE_TRAP: 605 case DIE_TRAP:
606 case DIE_PAGE_FAULT:
607 /* kprobe_running() needs smp_processor_id() */ 606 /* kprobe_running() needs smp_processor_id() */
608 preempt_disable(); 607 preempt_disable();
609 if (kprobe_running() && 608 if (kprobe_running() &&
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 3dfd0985861c..6bfb0889eb10 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -65,7 +65,7 @@ long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
65 * User copy operations. 65 * User copy operations.
66 */ 66 */
67struct uaccess_ops uaccess; 67struct uaccess_ops uaccess;
68EXPORT_SYMBOL_GPL(uaccess); 68EXPORT_SYMBOL(uaccess);
69 69
70/* 70/*
71 * Machine setup.. 71 * Machine setup..
@@ -74,6 +74,8 @@ unsigned int console_mode = 0;
74unsigned int console_devno = -1; 74unsigned int console_devno = -1;
75unsigned int console_irq = -1; 75unsigned int console_irq = -1;
76unsigned long machine_flags = 0; 76unsigned long machine_flags = 0;
77unsigned long elf_hwcap = 0;
78char elf_platform[ELF_PLATFORM_SIZE];
77 79
78struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS]; 80struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
79volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */ 81volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
@@ -749,6 +751,98 @@ setup_memory(void)
749#endif 751#endif
750} 752}
751 753
754static __init unsigned int stfl(void)
755{
756 asm volatile(
757 " .insn s,0xb2b10000,0(0)\n" /* stfl */
758 "0:\n"
759 EX_TABLE(0b,0b));
760 return S390_lowcore.stfl_fac_list;
761}
762
763static __init int stfle(unsigned long long *list, int doublewords)
764{
765 typedef struct { unsigned long long _[doublewords]; } addrtype;
766 register unsigned long __nr asm("0") = doublewords - 1;
767
768 asm volatile(".insn s,0xb2b00000,%0" /* stfle */
769 : "=m" (*(addrtype *) list), "+d" (__nr) : : "cc");
770 return __nr + 1;
771}
772
773/*
774 * Setup hardware capabilities.
775 */
776static void __init setup_hwcaps(void)
777{
778 static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
779 struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
780 unsigned long long facility_list_extended;
781 unsigned int facility_list;
782 int i;
783
784 facility_list = stfl();
785 /*
786 * The store facility list bits numbers as found in the principles
787 * of operation are numbered with bit 1UL<<31 as number 0 to
788 * bit 1UL<<0 as number 31.
789 * Bit 0: instructions named N3, "backported" to esa-mode
790 * Bit 2: z/Architecture mode is active
791 * Bit 7: the store-facility-list-extended facility is installed
792 * Bit 17: the message-security assist is installed
793 * Bit 19: the long-displacement facility is installed
794 * Bit 21: the extended-immediate facility is installed
795 * These get translated to:
796 * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
797 * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
798 * HWCAP_S390_LDISP bit 4, and HWCAP_S390_EIMM bit 5.
799 */
800 for (i = 0; i < 6; i++)
801 if (facility_list & (1UL << (31 - stfl_bits[i])))
802 elf_hwcap |= 1UL << i;
803
804 /*
805 * Check for additional facilities with store-facility-list-extended.
806 * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
807 * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
808 * as stored by stfl, bits 32-xxx contain additional facilities.
809 * How many facility words are stored depends on the number of
810 * doublewords passed to the instruction. The additional facilites
811 * are:
812 * Bit 43: decimal floating point facility is installed
813 * translated to:
814 * HWCAP_S390_DFP bit 6.
815 */
816 if ((elf_hwcap & (1UL << 2)) &&
817 stfle(&facility_list_extended, 1) > 0) {
818 if (facility_list_extended & (1ULL << (64 - 43)))
819 elf_hwcap |= 1UL << 6;
820 }
821
822 switch (cpuinfo->cpu_id.machine) {
823 case 0x9672:
824#if !defined(CONFIG_64BIT)
825 default: /* Use "g5" as default for 31 bit kernels. */
826#endif
827 strcpy(elf_platform, "g5");
828 break;
829 case 0x2064:
830 case 0x2066:
831#if defined(CONFIG_64BIT)
832 default: /* Use "z900" as default for 64 bit kernels. */
833#endif
834 strcpy(elf_platform, "z900");
835 break;
836 case 0x2084:
837 case 0x2086:
838 strcpy(elf_platform, "z990");
839 break;
840 case 0x2094:
841 strcpy(elf_platform, "z9-109");
842 break;
843 }
844}
845
752/* 846/*
753 * Setup function called from init/main.c just after the banner 847 * Setup function called from init/main.c just after the banner
754 * was printed. 848 * was printed.
@@ -805,6 +899,11 @@ setup_arch(char **cmdline_p)
805 smp_setup_cpu_possible_map(); 899 smp_setup_cpu_possible_map();
806 900
807 /* 901 /*
902 * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
903 */
904 setup_hwcaps();
905
906 /*
808 * Create kernel page tables and switch to virtual addressing. 907 * Create kernel page tables and switch to virtual addressing.
809 */ 908 */
810 paging_init(); 909 paging_init();
@@ -839,8 +938,12 @@ void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
839 938
840static int show_cpuinfo(struct seq_file *m, void *v) 939static int show_cpuinfo(struct seq_file *m, void *v)
841{ 940{
941 static const char *hwcap_str[7] = {
942 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp"
943 };
842 struct cpuinfo_S390 *cpuinfo; 944 struct cpuinfo_S390 *cpuinfo;
843 unsigned long n = (unsigned long) v - 1; 945 unsigned long n = (unsigned long) v - 1;
946 int i;
844 947
845 s390_adjust_jiffies(); 948 s390_adjust_jiffies();
846 preempt_disable(); 949 preempt_disable();
@@ -850,7 +953,13 @@ static int show_cpuinfo(struct seq_file *m, void *v)
850 "bogomips per cpu: %lu.%02lu\n", 953 "bogomips per cpu: %lu.%02lu\n",
851 num_online_cpus(), loops_per_jiffy/(500000/HZ), 954 num_online_cpus(), loops_per_jiffy/(500000/HZ),
852 (loops_per_jiffy/(5000/HZ))%100); 955 (loops_per_jiffy/(5000/HZ))%100);
956 seq_puts(m, "features\t: ");
957 for (i = 0; i < 7; i++)
958 if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
959 seq_printf(m, "%s ", hwcap_str[i]);
960 seq_puts(m, "\n");
853 } 961 }
962
854 if (cpu_online(n)) { 963 if (cpu_online(n)) {
855#ifdef CONFIG_SMP 964#ifdef CONFIG_SMP
856 if (smp_processor_id() == n) 965 if (smp_processor_id() == n)
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 2b76a879a7b5..91f705adc3f9 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -52,38 +52,24 @@ extern int sysctl_userprocess_debug;
52extern void die(const char *,struct pt_regs *,long); 52extern void die(const char *,struct pt_regs *,long);
53 53
54#ifdef CONFIG_KPROBES 54#ifdef CONFIG_KPROBES
55static ATOMIC_NOTIFIER_HEAD(notify_page_fault_chain);
56int register_page_fault_notifier(struct notifier_block *nb)
57{
58 return atomic_notifier_chain_register(&notify_page_fault_chain, nb);
59}
60
61int unregister_page_fault_notifier(struct notifier_block *nb)
62{
63 return atomic_notifier_chain_unregister(&notify_page_fault_chain, nb);
64}
65
66static int __kprobes __notify_page_fault(struct pt_regs *regs, long err)
67{
68 struct die_args args = { .str = "page fault",
69 .trapnr = 14,
70 .signr = SIGSEGV };
71 args.regs = regs;
72 args.err = err;
73 return atomic_notifier_call_chain(&notify_page_fault_chain,
74 DIE_PAGE_FAULT, &args);
75}
76
77static inline int notify_page_fault(struct pt_regs *regs, long err) 55static inline int notify_page_fault(struct pt_regs *regs, long err)
78{ 56{
79 if (unlikely(kprobe_running())) 57 int ret = 0;
80 return __notify_page_fault(regs, err); 58
81 return NOTIFY_DONE; 59 /* kprobe_running() needs smp_processor_id() */
60 if (!user_mode(regs)) {
61 preempt_disable();
62 if (kprobe_running() && kprobe_fault_handler(regs, 14))
63 ret = 1;
64 preempt_enable();
65 }
66
67 return ret;
82} 68}
83#else 69#else
84static inline int notify_page_fault(struct pt_regs *regs, long err) 70static inline int notify_page_fault(struct pt_regs *regs, long err)
85{ 71{
86 return NOTIFY_DONE; 72 return 0;
87} 73}
88#endif 74#endif
89 75
@@ -319,7 +305,7 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write)
319 int space; 305 int space;
320 int si_code; 306 int si_code;
321 307
322 if (notify_page_fault(regs, error_code) == NOTIFY_STOP) 308 if (notify_page_fault(regs, error_code))
323 return; 309 return;
324 310
325 tsk = current; 311 tsk = current;
diff --git a/arch/x86_64/kernel/cpufreq/Kconfig b/arch/x86_64/kernel/cpufreq/Kconfig
index 40acb67fb882..c0749d2479f5 100644
--- a/arch/x86_64/kernel/cpufreq/Kconfig
+++ b/arch/x86_64/kernel/cpufreq/Kconfig
@@ -16,6 +16,9 @@ config X86_POWERNOW_K8
16 help 16 help
17 This adds the CPUFreq driver for mobile AMD Opteron/Athlon64 processors. 17 This adds the CPUFreq driver for mobile AMD Opteron/Athlon64 processors.
18 18
19 To compile this driver as a module, choose M here: the
20 module will be called powernow-k8.
21
19 For details, take a look at <file:Documentation/cpu-freq/>. 22 For details, take a look at <file:Documentation/cpu-freq/>.
20 23
21 If in doubt, say N. 24 If in doubt, say N.
@@ -38,6 +41,9 @@ config X86_SPEEDSTEP_CENTRINO
38 mobile CPUs. This means Intel Pentium M (Centrino) CPUs 41 mobile CPUs. This means Intel Pentium M (Centrino) CPUs
39 or 64bit enabled Intel Xeons. 42 or 64bit enabled Intel Xeons.
40 43
44 To compile this driver as a module, choose M here: the
45 module will be called speedstep-centrino.
46
41 For details, take a look at <file:Documentation/cpu-freq/>. 47 For details, take a look at <file:Documentation/cpu-freq/>.
42 48
43 If in doubt, say N. 49 If in doubt, say N.
@@ -55,6 +61,9 @@ config X86_ACPI_CPUFREQ
55 Processor Performance States. 61 Processor Performance States.
56 This driver also supports Intel Enhanced Speedstep. 62 This driver also supports Intel Enhanced Speedstep.
57 63
64 To compile this driver as a module, choose M here: the
65 module will be called acpi-cpufreq.
66
58 For details, take a look at <file:Documentation/cpu-freq/>. 67 For details, take a look at <file:Documentation/cpu-freq/>.
59 68
60 If in doubt, say N. 69 If in doubt, say N.
@@ -62,7 +71,7 @@ config X86_ACPI_CPUFREQ
62comment "shared options" 71comment "shared options"
63 72
64config X86_ACPI_CPUFREQ_PROC_INTF 73config X86_ACPI_CPUFREQ_PROC_INTF
65 bool "/proc/acpi/processor/../performance interface (deprecated)" 74 bool "/proc/acpi/processor/../performance interface (deprecated)"
66 depends on PROC_FS 75 depends on PROC_FS
67 depends on X86_ACPI_CPUFREQ || X86_SPEEDSTEP_CENTRINO_ACPI || X86_POWERNOW_K8_ACPI 76 depends on X86_ACPI_CPUFREQ || X86_SPEEDSTEP_CENTRINO_ACPI || X86_POWERNOW_K8_ACPI
68 help 77 help
@@ -86,16 +95,18 @@ config X86_P4_CLOCKMOD
86 slowdowns and noticeable latencies. Normally Speedstep should be used 95 slowdowns and noticeable latencies. Normally Speedstep should be used
87 instead. 96 instead.
88 97
98 To compile this driver as a module, choose M here: the
99 module will be called p4-clockmod.
100
89 For details, take a look at <file:Documentation/cpu-freq/>. 101 For details, take a look at <file:Documentation/cpu-freq/>.
90 102
91 Unless you are absolutely sure say N. 103 Unless you are absolutely sure say N.
92 104
93 105
94config X86_SPEEDSTEP_LIB 106config X86_SPEEDSTEP_LIB
95 tristate 107 tristate
96 default X86_P4_CLOCKMOD 108 default X86_P4_CLOCKMOD
97 109
98endif 110endif
99 111
100endmenu 112endmenu
101
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 086fcec44720..620e14cabdc6 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -16,6 +16,10 @@ config CRYPTO_ALGAPI
16 help 16 help
17 This option provides the API for cryptographic algorithms. 17 This option provides the API for cryptographic algorithms.
18 18
19config CRYPTO_ABLKCIPHER
20 tristate
21 select CRYPTO_BLKCIPHER
22
19config CRYPTO_BLKCIPHER 23config CRYPTO_BLKCIPHER
20 tristate 24 tristate
21 select CRYPTO_ALGAPI 25 select CRYPTO_ALGAPI
@@ -171,6 +175,15 @@ config CRYPTO_LRW
171 The first 128, 192 or 256 bits in the key are used for AES and the 175 The first 128, 192 or 256 bits in the key are used for AES and the
172 rest is used to tie each cipher block to its logical position. 176 rest is used to tie each cipher block to its logical position.
173 177
178config CRYPTO_CRYPTD
179 tristate "Software async crypto daemon"
180 select CRYPTO_ABLKCIPHER
181 select CRYPTO_MANAGER
182 help
183 This is a generic software asynchronous crypto daemon that
184 converts an arbitrary synchronous software crypto algorithm
185 into an asynchronous algorithm that executes in a kernel thread.
186
174config CRYPTO_DES 187config CRYPTO_DES
175 tristate "DES and Triple DES EDE cipher algorithms" 188 tristate "DES and Triple DES EDE cipher algorithms"
176 select CRYPTO_ALGAPI 189 select CRYPTO_ALGAPI
diff --git a/crypto/Makefile b/crypto/Makefile
index 12f93f578171..cce46a1c9dc7 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -8,6 +8,7 @@ crypto_algapi-$(CONFIG_PROC_FS) += proc.o
8crypto_algapi-objs := algapi.o $(crypto_algapi-y) 8crypto_algapi-objs := algapi.o $(crypto_algapi-y)
9obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o 9obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o
10 10
11obj-$(CONFIG_CRYPTO_ABLKCIPHER) += ablkcipher.o
11obj-$(CONFIG_CRYPTO_BLKCIPHER) += blkcipher.o 12obj-$(CONFIG_CRYPTO_BLKCIPHER) += blkcipher.o
12 13
13crypto_hash-objs := hash.o 14crypto_hash-objs := hash.o
@@ -29,6 +30,7 @@ obj-$(CONFIG_CRYPTO_ECB) += ecb.o
29obj-$(CONFIG_CRYPTO_CBC) += cbc.o 30obj-$(CONFIG_CRYPTO_CBC) += cbc.o
30obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o 31obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o
31obj-$(CONFIG_CRYPTO_LRW) += lrw.o 32obj-$(CONFIG_CRYPTO_LRW) += lrw.o
33obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
32obj-$(CONFIG_CRYPTO_DES) += des.o 34obj-$(CONFIG_CRYPTO_DES) += des.o
33obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o 35obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
34obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o 36obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
new file mode 100644
index 000000000000..9348ddd84a56
--- /dev/null
+++ b/crypto/ablkcipher.c
@@ -0,0 +1,83 @@
1/*
2 * Asynchronous block chaining cipher operations.
3 *
4 * This is the asynchronous version of blkcipher.c indicating completion
5 * via a callback.
6 *
7 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 */
15
16#include <crypto/algapi.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/seq_file.h>
21
22static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
23 unsigned int keylen)
24{
25 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
26
27 if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
28 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
29 return -EINVAL;
30 }
31
32 return cipher->setkey(tfm, key, keylen);
33}
34
35static unsigned int crypto_ablkcipher_ctxsize(struct crypto_alg *alg, u32 type,
36 u32 mask)
37{
38 return alg->cra_ctxsize;
39}
40
41static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
42 u32 mask)
43{
44 struct ablkcipher_alg *alg = &tfm->__crt_alg->cra_ablkcipher;
45 struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
46
47 if (alg->ivsize > PAGE_SIZE / 8)
48 return -EINVAL;
49
50 crt->setkey = setkey;
51 crt->encrypt = alg->encrypt;
52 crt->decrypt = alg->decrypt;
53 crt->ivsize = alg->ivsize;
54
55 return 0;
56}
57
58static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
59 __attribute__ ((unused));
60static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
61{
62 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
63
64 seq_printf(m, "type : ablkcipher\n");
65 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
66 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
67 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
68 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
69 seq_printf(m, "qlen : %u\n", ablkcipher->queue->qlen);
70 seq_printf(m, "max qlen : %u\n", ablkcipher->queue->max_qlen);
71}
72
73const struct crypto_type crypto_ablkcipher_type = {
74 .ctxsize = crypto_ablkcipher_ctxsize,
75 .init = crypto_init_ablkcipher_ops,
76#ifdef CONFIG_PROC_FS
77 .show = crypto_ablkcipher_show,
78#endif
79};
80EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
81
82MODULE_LICENSE("GPL");
83MODULE_DESCRIPTION("Asynchronous block chaining cipher type");
diff --git a/crypto/algapi.c b/crypto/algapi.c
index f7d2185b2c8f..f137a432061f 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -84,36 +84,47 @@ static void crypto_destroy_instance(struct crypto_alg *alg)
84 crypto_tmpl_put(tmpl); 84 crypto_tmpl_put(tmpl);
85} 85}
86 86
87static void crypto_remove_spawns(struct list_head *spawns, 87static void crypto_remove_spawn(struct crypto_spawn *spawn,
88 struct list_head *list) 88 struct list_head *list,
89 struct list_head *secondary_spawns)
89{ 90{
90 struct crypto_spawn *spawn, *n; 91 struct crypto_instance *inst = spawn->inst;
92 struct crypto_template *tmpl = inst->tmpl;
91 93
92 list_for_each_entry_safe(spawn, n, spawns, list) { 94 list_del_init(&spawn->list);
93 struct crypto_instance *inst = spawn->inst; 95 spawn->alg = NULL;
94 struct crypto_template *tmpl = inst->tmpl;
95 96
96 list_del_init(&spawn->list); 97 if (crypto_is_dead(&inst->alg))
97 spawn->alg = NULL; 98 return;
98 99
99 if (crypto_is_dead(&inst->alg)) 100 inst->alg.cra_flags |= CRYPTO_ALG_DEAD;
100 continue; 101 if (!tmpl || !crypto_tmpl_get(tmpl))
102 return;
101 103
102 inst->alg.cra_flags |= CRYPTO_ALG_DEAD; 104 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, &inst->alg);
103 if (!tmpl || !crypto_tmpl_get(tmpl)) 105 list_move(&inst->alg.cra_list, list);
106 hlist_del(&inst->list);
107 inst->alg.cra_destroy = crypto_destroy_instance;
108
109 list_splice(&inst->alg.cra_users, secondary_spawns);
110}
111
112static void crypto_remove_spawns(struct list_head *spawns,
113 struct list_head *list, u32 new_type)
114{
115 struct crypto_spawn *spawn, *n;
116 LIST_HEAD(secondary_spawns);
117
118 list_for_each_entry_safe(spawn, n, spawns, list) {
119 if ((spawn->alg->cra_flags ^ new_type) & spawn->mask)
104 continue; 120 continue;
105 121
106 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, &inst->alg); 122 crypto_remove_spawn(spawn, list, &secondary_spawns);
107 list_move(&inst->alg.cra_list, list); 123 }
108 hlist_del(&inst->list);
109 inst->alg.cra_destroy = crypto_destroy_instance;
110 124
111 if (!list_empty(&inst->alg.cra_users)) { 125 while (!list_empty(&secondary_spawns)) {
112 if (&n->list == spawns) 126 list_for_each_entry_safe(spawn, n, &secondary_spawns, list)
113 n = list_entry(inst->alg.cra_users.next, 127 crypto_remove_spawn(spawn, list, &secondary_spawns);
114 typeof(*n), list);
115 __list_splice(&inst->alg.cra_users, spawns->prev);
116 }
117 } 128 }
118} 129}
119 130
@@ -164,7 +175,7 @@ static int __crypto_register_alg(struct crypto_alg *alg,
164 q->cra_priority > alg->cra_priority) 175 q->cra_priority > alg->cra_priority)
165 continue; 176 continue;
166 177
167 crypto_remove_spawns(&q->cra_users, list); 178 crypto_remove_spawns(&q->cra_users, list, alg->cra_flags);
168 } 179 }
169 180
170 list_add(&alg->cra_list, &crypto_alg_list); 181 list_add(&alg->cra_list, &crypto_alg_list);
@@ -214,7 +225,7 @@ static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list)
214 225
215 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, alg); 226 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, alg);
216 list_del_init(&alg->cra_list); 227 list_del_init(&alg->cra_list);
217 crypto_remove_spawns(&alg->cra_users, list); 228 crypto_remove_spawns(&alg->cra_users, list, alg->cra_flags);
218 229
219 return 0; 230 return 0;
220} 231}
@@ -351,11 +362,12 @@ err:
351EXPORT_SYMBOL_GPL(crypto_register_instance); 362EXPORT_SYMBOL_GPL(crypto_register_instance);
352 363
353int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, 364int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
354 struct crypto_instance *inst) 365 struct crypto_instance *inst, u32 mask)
355{ 366{
356 int err = -EAGAIN; 367 int err = -EAGAIN;
357 368
358 spawn->inst = inst; 369 spawn->inst = inst;
370 spawn->mask = mask;
359 371
360 down_write(&crypto_alg_sem); 372 down_write(&crypto_alg_sem);
361 if (!crypto_is_moribund(alg)) { 373 if (!crypto_is_moribund(alg)) {
@@ -425,15 +437,45 @@ int crypto_unregister_notifier(struct notifier_block *nb)
425} 437}
426EXPORT_SYMBOL_GPL(crypto_unregister_notifier); 438EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
427 439
428struct crypto_alg *crypto_get_attr_alg(void *param, unsigned int len, 440struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb)
429 u32 type, u32 mask) 441{
442 struct rtattr *rta = tb[CRYPTOA_TYPE - 1];
443 struct crypto_attr_type *algt;
444
445 if (!rta)
446 return ERR_PTR(-ENOENT);
447 if (RTA_PAYLOAD(rta) < sizeof(*algt))
448 return ERR_PTR(-EINVAL);
449
450 algt = RTA_DATA(rta);
451
452 return algt;
453}
454EXPORT_SYMBOL_GPL(crypto_get_attr_type);
455
456int crypto_check_attr_type(struct rtattr **tb, u32 type)
430{ 457{
431 struct rtattr *rta = param; 458 struct crypto_attr_type *algt;
459
460 algt = crypto_get_attr_type(tb);
461 if (IS_ERR(algt))
462 return PTR_ERR(algt);
463
464 if ((algt->type ^ type) & algt->mask)
465 return -EINVAL;
466
467 return 0;
468}
469EXPORT_SYMBOL_GPL(crypto_check_attr_type);
470
471struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, u32 type, u32 mask)
472{
473 struct rtattr *rta = tb[CRYPTOA_ALG - 1];
432 struct crypto_attr_alg *alga; 474 struct crypto_attr_alg *alga;
433 475
434 if (!RTA_OK(rta, len)) 476 if (!rta)
435 return ERR_PTR(-EBADR); 477 return ERR_PTR(-ENOENT);
436 if (rta->rta_type != CRYPTOA_ALG || RTA_PAYLOAD(rta) < sizeof(*alga)) 478 if (RTA_PAYLOAD(rta) < sizeof(*alga))
437 return ERR_PTR(-EINVAL); 479 return ERR_PTR(-EINVAL);
438 480
439 alga = RTA_DATA(rta); 481 alga = RTA_DATA(rta);
@@ -464,7 +506,8 @@ struct crypto_instance *crypto_alloc_instance(const char *name,
464 goto err_free_inst; 506 goto err_free_inst;
465 507
466 spawn = crypto_instance_ctx(inst); 508 spawn = crypto_instance_ctx(inst);
467 err = crypto_init_spawn(spawn, alg, inst); 509 err = crypto_init_spawn(spawn, alg, inst,
510 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
468 511
469 if (err) 512 if (err)
470 goto err_free_inst; 513 goto err_free_inst;
@@ -477,6 +520,68 @@ err_free_inst:
477} 520}
478EXPORT_SYMBOL_GPL(crypto_alloc_instance); 521EXPORT_SYMBOL_GPL(crypto_alloc_instance);
479 522
523void crypto_init_queue(struct crypto_queue *queue, unsigned int max_qlen)
524{
525 INIT_LIST_HEAD(&queue->list);
526 queue->backlog = &queue->list;
527 queue->qlen = 0;
528 queue->max_qlen = max_qlen;
529}
530EXPORT_SYMBOL_GPL(crypto_init_queue);
531
532int crypto_enqueue_request(struct crypto_queue *queue,
533 struct crypto_async_request *request)
534{
535 int err = -EINPROGRESS;
536
537 if (unlikely(queue->qlen >= queue->max_qlen)) {
538 err = -EBUSY;
539 if (!(request->flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
540 goto out;
541 if (queue->backlog == &queue->list)
542 queue->backlog = &request->list;
543 }
544
545 queue->qlen++;
546 list_add_tail(&request->list, &queue->list);
547
548out:
549 return err;
550}
551EXPORT_SYMBOL_GPL(crypto_enqueue_request);
552
553struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue)
554{
555 struct list_head *request;
556
557 if (unlikely(!queue->qlen))
558 return NULL;
559
560 queue->qlen--;
561
562 if (queue->backlog != &queue->list)
563 queue->backlog = queue->backlog->next;
564
565 request = queue->list.next;
566 list_del(request);
567
568 return list_entry(request, struct crypto_async_request, list);
569}
570EXPORT_SYMBOL_GPL(crypto_dequeue_request);
571
572int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm)
573{
574 struct crypto_async_request *req;
575
576 list_for_each_entry(req, &queue->list, list) {
577 if (req->tfm == tfm)
578 return 1;
579 }
580
581 return 0;
582}
583EXPORT_SYMBOL_GPL(crypto_tfm_in_queue);
584
480static int __init crypto_algapi_init(void) 585static int __init crypto_algapi_init(void)
481{ 586{
482 crypto_init_proc(); 587 crypto_init_proc();
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index b5befe8c3a96..8edf40c835a7 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -349,13 +349,48 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key,
349 return cipher->setkey(tfm, key, keylen); 349 return cipher->setkey(tfm, key, keylen);
350} 350}
351 351
352static int async_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
353 unsigned int keylen)
354{
355 return setkey(crypto_ablkcipher_tfm(tfm), key, keylen);
356}
357
358static int async_encrypt(struct ablkcipher_request *req)
359{
360 struct crypto_tfm *tfm = req->base.tfm;
361 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
362 struct blkcipher_desc desc = {
363 .tfm = __crypto_blkcipher_cast(tfm),
364 .info = req->info,
365 .flags = req->base.flags,
366 };
367
368
369 return alg->encrypt(&desc, req->dst, req->src, req->nbytes);
370}
371
372static int async_decrypt(struct ablkcipher_request *req)
373{
374 struct crypto_tfm *tfm = req->base.tfm;
375 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
376 struct blkcipher_desc desc = {
377 .tfm = __crypto_blkcipher_cast(tfm),
378 .info = req->info,
379 .flags = req->base.flags,
380 };
381
382 return alg->decrypt(&desc, req->dst, req->src, req->nbytes);
383}
384
352static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type, 385static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
353 u32 mask) 386 u32 mask)
354{ 387{
355 struct blkcipher_alg *cipher = &alg->cra_blkcipher; 388 struct blkcipher_alg *cipher = &alg->cra_blkcipher;
356 unsigned int len = alg->cra_ctxsize; 389 unsigned int len = alg->cra_ctxsize;
357 390
358 if (cipher->ivsize) { 391 type ^= CRYPTO_ALG_ASYNC;
392 mask &= CRYPTO_ALG_ASYNC;
393 if ((type & mask) && cipher->ivsize) {
359 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1); 394 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
360 len += cipher->ivsize; 395 len += cipher->ivsize;
361 } 396 }
@@ -363,16 +398,26 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
363 return len; 398 return len;
364} 399}
365 400
366static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask) 401static int crypto_init_blkcipher_ops_async(struct crypto_tfm *tfm)
402{
403 struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
404 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
405
406 crt->setkey = async_setkey;
407 crt->encrypt = async_encrypt;
408 crt->decrypt = async_decrypt;
409 crt->ivsize = alg->ivsize;
410
411 return 0;
412}
413
414static int crypto_init_blkcipher_ops_sync(struct crypto_tfm *tfm)
367{ 415{
368 struct blkcipher_tfm *crt = &tfm->crt_blkcipher; 416 struct blkcipher_tfm *crt = &tfm->crt_blkcipher;
369 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher; 417 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
370 unsigned long align = crypto_tfm_alg_alignmask(tfm) + 1; 418 unsigned long align = crypto_tfm_alg_alignmask(tfm) + 1;
371 unsigned long addr; 419 unsigned long addr;
372 420
373 if (alg->ivsize > PAGE_SIZE / 8)
374 return -EINVAL;
375
376 crt->setkey = setkey; 421 crt->setkey = setkey;
377 crt->encrypt = alg->encrypt; 422 crt->encrypt = alg->encrypt;
378 crt->decrypt = alg->decrypt; 423 crt->decrypt = alg->decrypt;
@@ -385,8 +430,23 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
385 return 0; 430 return 0;
386} 431}
387 432
433static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
434{
435 struct blkcipher_alg *alg = &tfm->__crt_alg->cra_blkcipher;
436
437 if (alg->ivsize > PAGE_SIZE / 8)
438 return -EINVAL;
439
440 type ^= CRYPTO_ALG_ASYNC;
441 mask &= CRYPTO_ALG_ASYNC;
442 if (type & mask)
443 return crypto_init_blkcipher_ops_sync(tfm);
444 else
445 return crypto_init_blkcipher_ops_async(tfm);
446}
447
388static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg) 448static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg)
389 __attribute_used__; 449 __attribute__ ((unused));
390static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg) 450static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg)
391{ 451{
392 seq_printf(m, "type : blkcipher\n"); 452 seq_printf(m, "type : blkcipher\n");
diff --git a/crypto/cbc.c b/crypto/cbc.c
index 136fea7e7000..1f2649e13b42 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -275,13 +275,18 @@ static void crypto_cbc_exit_tfm(struct crypto_tfm *tfm)
275 crypto_free_cipher(ctx->child); 275 crypto_free_cipher(ctx->child);
276} 276}
277 277
278static struct crypto_instance *crypto_cbc_alloc(void *param, unsigned int len) 278static struct crypto_instance *crypto_cbc_alloc(struct rtattr **tb)
279{ 279{
280 struct crypto_instance *inst; 280 struct crypto_instance *inst;
281 struct crypto_alg *alg; 281 struct crypto_alg *alg;
282 int err;
283
284 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
285 if (err)
286 return ERR_PTR(err);
282 287
283 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER, 288 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
284 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 289 CRYPTO_ALG_TYPE_MASK);
285 if (IS_ERR(alg)) 290 if (IS_ERR(alg))
286 return ERR_PTR(PTR_ERR(alg)); 291 return ERR_PTR(PTR_ERR(alg));
287 292
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
new file mode 100644
index 000000000000..3ff4e1f0f032
--- /dev/null
+++ b/crypto/cryptd.c
@@ -0,0 +1,375 @@
1/*
2 * Software async crypto daemon.
3 *
4 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <crypto/algapi.h>
14#include <linux/err.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/kthread.h>
18#include <linux/list.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/scatterlist.h>
22#include <linux/sched.h>
23#include <linux/slab.h>
24#include <linux/spinlock.h>
25
26#define CRYPTD_MAX_QLEN 100
27
28struct cryptd_state {
29 spinlock_t lock;
30 struct mutex mutex;
31 struct crypto_queue queue;
32 struct task_struct *task;
33};
34
35struct cryptd_instance_ctx {
36 struct crypto_spawn spawn;
37 struct cryptd_state *state;
38};
39
40struct cryptd_blkcipher_ctx {
41 struct crypto_blkcipher *child;
42};
43
44struct cryptd_blkcipher_request_ctx {
45 crypto_completion_t complete;
46};
47
48
49static inline struct cryptd_state *cryptd_get_state(struct crypto_tfm *tfm)
50{
51 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
52 struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst);
53 return ictx->state;
54}
55
56static int cryptd_blkcipher_setkey(struct crypto_ablkcipher *parent,
57 const u8 *key, unsigned int keylen)
58{
59 struct cryptd_blkcipher_ctx *ctx = crypto_ablkcipher_ctx(parent);
60 struct crypto_blkcipher *child = ctx->child;
61 int err;
62
63 crypto_blkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
64 crypto_blkcipher_set_flags(child, crypto_ablkcipher_get_flags(parent) &
65 CRYPTO_TFM_REQ_MASK);
66 err = crypto_blkcipher_setkey(child, key, keylen);
67 crypto_ablkcipher_set_flags(parent, crypto_blkcipher_get_flags(child) &
68 CRYPTO_TFM_RES_MASK);
69 return err;
70}
71
72static void cryptd_blkcipher_crypt(struct ablkcipher_request *req,
73 struct crypto_blkcipher *child,
74 int err,
75 int (*crypt)(struct blkcipher_desc *desc,
76 struct scatterlist *dst,
77 struct scatterlist *src,
78 unsigned int len))
79{
80 struct cryptd_blkcipher_request_ctx *rctx;
81 struct blkcipher_desc desc;
82
83 rctx = ablkcipher_request_ctx(req);
84
85 if (unlikely(err == -EINPROGRESS)) {
86 rctx->complete(&req->base, err);
87 return;
88 }
89
90 desc.tfm = child;
91 desc.info = req->info;
92 desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
93
94 err = crypt(&desc, req->dst, req->src, req->nbytes);
95
96 req->base.complete = rctx->complete;
97
98 local_bh_disable();
99 req->base.complete(&req->base, err);
100 local_bh_enable();
101}
102
103static void cryptd_blkcipher_encrypt(struct crypto_async_request *req, int err)
104{
105 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(req->tfm);
106 struct crypto_blkcipher *child = ctx->child;
107
108 cryptd_blkcipher_crypt(ablkcipher_request_cast(req), child, err,
109 crypto_blkcipher_crt(child)->encrypt);
110}
111
112static void cryptd_blkcipher_decrypt(struct crypto_async_request *req, int err)
113{
114 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(req->tfm);
115 struct crypto_blkcipher *child = ctx->child;
116
117 cryptd_blkcipher_crypt(ablkcipher_request_cast(req), child, err,
118 crypto_blkcipher_crt(child)->decrypt);
119}
120
121static int cryptd_blkcipher_enqueue(struct ablkcipher_request *req,
122 crypto_completion_t complete)
123{
124 struct cryptd_blkcipher_request_ctx *rctx = ablkcipher_request_ctx(req);
125 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
126 struct cryptd_state *state =
127 cryptd_get_state(crypto_ablkcipher_tfm(tfm));
128 int err;
129
130 rctx->complete = req->base.complete;
131 req->base.complete = complete;
132
133 spin_lock_bh(&state->lock);
134 err = ablkcipher_enqueue_request(crypto_ablkcipher_alg(tfm), req);
135 spin_unlock_bh(&state->lock);
136
137 wake_up_process(state->task);
138 return err;
139}
140
141static int cryptd_blkcipher_encrypt_enqueue(struct ablkcipher_request *req)
142{
143 return cryptd_blkcipher_enqueue(req, cryptd_blkcipher_encrypt);
144}
145
146static int cryptd_blkcipher_decrypt_enqueue(struct ablkcipher_request *req)
147{
148 return cryptd_blkcipher_enqueue(req, cryptd_blkcipher_decrypt);
149}
150
151static int cryptd_blkcipher_init_tfm(struct crypto_tfm *tfm)
152{
153 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
154 struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst);
155 struct crypto_spawn *spawn = &ictx->spawn;
156 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(tfm);
157 struct crypto_blkcipher *cipher;
158
159 cipher = crypto_spawn_blkcipher(spawn);
160 if (IS_ERR(cipher))
161 return PTR_ERR(cipher);
162
163 ctx->child = cipher;
164 tfm->crt_ablkcipher.reqsize =
165 sizeof(struct cryptd_blkcipher_request_ctx);
166 return 0;
167}
168
169static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm)
170{
171 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(tfm);
172 struct cryptd_state *state = cryptd_get_state(tfm);
173 int active;
174
175 mutex_lock(&state->mutex);
176 active = ablkcipher_tfm_in_queue(__crypto_ablkcipher_cast(tfm));
177 mutex_unlock(&state->mutex);
178
179 BUG_ON(active);
180
181 crypto_free_blkcipher(ctx->child);
182}
183
184static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
185 struct cryptd_state *state)
186{
187 struct crypto_instance *inst;
188 struct cryptd_instance_ctx *ctx;
189 int err;
190
191 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
192 if (IS_ERR(inst))
193 goto out;
194
195 err = -ENAMETOOLONG;
196 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
197 "cryptd(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
198 goto out_free_inst;
199
200 ctx = crypto_instance_ctx(inst);
201 err = crypto_init_spawn(&ctx->spawn, alg, inst,
202 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
203 if (err)
204 goto out_free_inst;
205
206 ctx->state = state;
207
208 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
209
210 inst->alg.cra_priority = alg->cra_priority + 50;
211 inst->alg.cra_blocksize = alg->cra_blocksize;
212 inst->alg.cra_alignmask = alg->cra_alignmask;
213
214out:
215 return inst;
216
217out_free_inst:
218 kfree(inst);
219 inst = ERR_PTR(err);
220 goto out;
221}
222
223static struct crypto_instance *cryptd_alloc_blkcipher(
224 struct rtattr **tb, struct cryptd_state *state)
225{
226 struct crypto_instance *inst;
227 struct crypto_alg *alg;
228
229 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
230 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
231 if (IS_ERR(alg))
232 return ERR_PTR(PTR_ERR(alg));
233
234 inst = cryptd_alloc_instance(alg, state);
235 if (IS_ERR(inst))
236 goto out_put_alg;
237
238 inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC;
239 inst->alg.cra_type = &crypto_ablkcipher_type;
240
241 inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize;
242 inst->alg.cra_ablkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
243 inst->alg.cra_ablkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
244
245 inst->alg.cra_ctxsize = sizeof(struct cryptd_blkcipher_ctx);
246
247 inst->alg.cra_init = cryptd_blkcipher_init_tfm;
248 inst->alg.cra_exit = cryptd_blkcipher_exit_tfm;
249
250 inst->alg.cra_ablkcipher.setkey = cryptd_blkcipher_setkey;
251 inst->alg.cra_ablkcipher.encrypt = cryptd_blkcipher_encrypt_enqueue;
252 inst->alg.cra_ablkcipher.decrypt = cryptd_blkcipher_decrypt_enqueue;
253
254 inst->alg.cra_ablkcipher.queue = &state->queue;
255
256out_put_alg:
257 crypto_mod_put(alg);
258 return inst;
259}
260
261static struct cryptd_state state;
262
263static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
264{
265 struct crypto_attr_type *algt;
266
267 algt = crypto_get_attr_type(tb);
268 if (IS_ERR(algt))
269 return ERR_PTR(PTR_ERR(algt));
270
271 switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
272 case CRYPTO_ALG_TYPE_BLKCIPHER:
273 return cryptd_alloc_blkcipher(tb, &state);
274 }
275
276 return ERR_PTR(-EINVAL);
277}
278
279static void cryptd_free(struct crypto_instance *inst)
280{
281 struct cryptd_instance_ctx *ctx = crypto_instance_ctx(inst);
282
283 crypto_drop_spawn(&ctx->spawn);
284 kfree(inst);
285}
286
287static struct crypto_template cryptd_tmpl = {
288 .name = "cryptd",
289 .alloc = cryptd_alloc,
290 .free = cryptd_free,
291 .module = THIS_MODULE,
292};
293
294static inline int cryptd_create_thread(struct cryptd_state *state,
295 int (*fn)(void *data), const char *name)
296{
297 spin_lock_init(&state->lock);
298 mutex_init(&state->mutex);
299 crypto_init_queue(&state->queue, CRYPTD_MAX_QLEN);
300
301 state->task = kthread_create(fn, state, name);
302 if (IS_ERR(state->task))
303 return PTR_ERR(state->task);
304
305 return 0;
306}
307
308static inline void cryptd_stop_thread(struct cryptd_state *state)
309{
310 BUG_ON(state->queue.qlen);
311 kthread_stop(state->task);
312}
313
314static int cryptd_thread(void *data)
315{
316 struct cryptd_state *state = data;
317 int stop;
318
319 do {
320 struct crypto_async_request *req, *backlog;
321
322 mutex_lock(&state->mutex);
323 __set_current_state(TASK_INTERRUPTIBLE);
324
325 spin_lock_bh(&state->lock);
326 backlog = crypto_get_backlog(&state->queue);
327 req = crypto_dequeue_request(&state->queue);
328 spin_unlock_bh(&state->lock);
329
330 stop = kthread_should_stop();
331
332 if (stop || req) {
333 __set_current_state(TASK_RUNNING);
334 if (req) {
335 if (backlog)
336 backlog->complete(backlog,
337 -EINPROGRESS);
338 req->complete(req, 0);
339 }
340 }
341
342 mutex_unlock(&state->mutex);
343
344 schedule();
345 } while (!stop);
346
347 return 0;
348}
349
350static int __init cryptd_init(void)
351{
352 int err;
353
354 err = cryptd_create_thread(&state, cryptd_thread, "cryptd");
355 if (err)
356 return err;
357
358 err = crypto_register_template(&cryptd_tmpl);
359 if (err)
360 kthread_stop(state.task);
361
362 return err;
363}
364
365static void __exit cryptd_exit(void)
366{
367 cryptd_stop_thread(&state);
368 crypto_unregister_template(&cryptd_tmpl);
369}
370
371module_init(cryptd_init);
372module_exit(cryptd_exit);
373
374MODULE_LICENSE("GPL");
375MODULE_DESCRIPTION("Software async crypto daemon");
diff --git a/crypto/cryptomgr.c b/crypto/cryptomgr.c
index 2ebffb84f1d9..6958ea83ee44 100644
--- a/crypto/cryptomgr.c
+++ b/crypto/cryptomgr.c
@@ -14,17 +14,24 @@
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/kthread.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/notifier.h> 19#include <linux/notifier.h>
19#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
20#include <linux/sched.h> 21#include <linux/sched.h>
21#include <linux/string.h> 22#include <linux/string.h>
22#include <linux/workqueue.h>
23 23
24#include "internal.h" 24#include "internal.h"
25 25
26struct cryptomgr_param { 26struct cryptomgr_param {
27 struct work_struct work; 27 struct task_struct *thread;
28
29 struct rtattr *tb[CRYPTOA_MAX];
30
31 struct {
32 struct rtattr attr;
33 struct crypto_attr_type data;
34 } type;
28 35
29 struct { 36 struct {
30 struct rtattr attr; 37 struct rtattr attr;
@@ -32,18 +39,15 @@ struct cryptomgr_param {
32 } alg; 39 } alg;
33 40
34 struct { 41 struct {
35 u32 type;
36 u32 mask;
37 char name[CRYPTO_MAX_ALG_NAME]; 42 char name[CRYPTO_MAX_ALG_NAME];
38 } larval; 43 } larval;
39 44
40 char template[CRYPTO_MAX_ALG_NAME]; 45 char template[CRYPTO_MAX_ALG_NAME];
41}; 46};
42 47
43static void cryptomgr_probe(struct work_struct *work) 48static int cryptomgr_probe(void *data)
44{ 49{
45 struct cryptomgr_param *param = 50 struct cryptomgr_param *param = data;
46 container_of(work, struct cryptomgr_param, work);
47 struct crypto_template *tmpl; 51 struct crypto_template *tmpl;
48 struct crypto_instance *inst; 52 struct crypto_instance *inst;
49 int err; 53 int err;
@@ -53,7 +57,7 @@ static void cryptomgr_probe(struct work_struct *work)
53 goto err; 57 goto err;
54 58
55 do { 59 do {
56 inst = tmpl->alloc(&param->alg, sizeof(param->alg)); 60 inst = tmpl->alloc(param->tb);
57 if (IS_ERR(inst)) 61 if (IS_ERR(inst))
58 err = PTR_ERR(inst); 62 err = PTR_ERR(inst);
59 else if ((err = crypto_register_instance(tmpl, inst))) 63 else if ((err = crypto_register_instance(tmpl, inst)))
@@ -67,11 +71,11 @@ static void cryptomgr_probe(struct work_struct *work)
67 71
68out: 72out:
69 kfree(param); 73 kfree(param);
70 return; 74 module_put_and_exit(0);
71 75
72err: 76err:
73 crypto_larval_error(param->larval.name, param->larval.type, 77 crypto_larval_error(param->larval.name, param->type.data.type,
74 param->larval.mask); 78 param->type.data.mask);
75 goto out; 79 goto out;
76} 80}
77 81
@@ -82,10 +86,13 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
82 const char *p; 86 const char *p;
83 unsigned int len; 87 unsigned int len;
84 88
85 param = kmalloc(sizeof(*param), GFP_KERNEL); 89 if (!try_module_get(THIS_MODULE))
86 if (!param)
87 goto err; 90 goto err;
88 91
92 param = kzalloc(sizeof(*param), GFP_KERNEL);
93 if (!param)
94 goto err_put_module;
95
89 for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++) 96 for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
90 ; 97 ;
91 98
@@ -94,32 +101,45 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
94 goto err_free_param; 101 goto err_free_param;
95 102
96 memcpy(param->template, name, len); 103 memcpy(param->template, name, len);
97 param->template[len] = 0;
98 104
99 name = p + 1; 105 name = p + 1;
100 for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++) 106 len = 0;
101 ; 107 for (p = name; *p; p++) {
108 for (; isalnum(*p) || *p == '-' || *p == '_' || *p == '('; p++)
109 ;
102 110
103 len = p - name; 111 if (*p != ')')
104 if (!len || *p != ')' || p[1]) 112 goto err_free_param;
113
114 len = p - name;
115 }
116
117 if (!len || name[len + 1])
105 goto err_free_param; 118 goto err_free_param;
106 119
120 param->type.attr.rta_len = sizeof(param->type);
121 param->type.attr.rta_type = CRYPTOA_TYPE;
122 param->type.data.type = larval->alg.cra_flags;
123 param->type.data.mask = larval->mask;
124 param->tb[CRYPTOA_TYPE - 1] = &param->type.attr;
125
107 param->alg.attr.rta_len = sizeof(param->alg); 126 param->alg.attr.rta_len = sizeof(param->alg);
108 param->alg.attr.rta_type = CRYPTOA_ALG; 127 param->alg.attr.rta_type = CRYPTOA_ALG;
109 memcpy(param->alg.data.name, name, len); 128 memcpy(param->alg.data.name, name, len);
110 param->alg.data.name[len] = 0; 129 param->tb[CRYPTOA_ALG - 1] = &param->alg.attr;
111 130
112 memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); 131 memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
113 param->larval.type = larval->alg.cra_flags;
114 param->larval.mask = larval->mask;
115 132
116 INIT_WORK(&param->work, cryptomgr_probe); 133 param->thread = kthread_run(cryptomgr_probe, param, "cryptomgr");
117 schedule_work(&param->work); 134 if (IS_ERR(param->thread))
135 goto err_free_param;
118 136
119 return NOTIFY_STOP; 137 return NOTIFY_STOP;
120 138
121err_free_param: 139err_free_param:
122 kfree(param); 140 kfree(param);
141err_put_module:
142 module_put(THIS_MODULE);
123err: 143err:
124 return NOTIFY_OK; 144 return NOTIFY_OK;
125} 145}
diff --git a/crypto/ecb.c b/crypto/ecb.c
index 839a0aed8c22..6310387a872c 100644
--- a/crypto/ecb.c
+++ b/crypto/ecb.c
@@ -115,13 +115,18 @@ static void crypto_ecb_exit_tfm(struct crypto_tfm *tfm)
115 crypto_free_cipher(ctx->child); 115 crypto_free_cipher(ctx->child);
116} 116}
117 117
118static struct crypto_instance *crypto_ecb_alloc(void *param, unsigned int len) 118static struct crypto_instance *crypto_ecb_alloc(struct rtattr **tb)
119{ 119{
120 struct crypto_instance *inst; 120 struct crypto_instance *inst;
121 struct crypto_alg *alg; 121 struct crypto_alg *alg;
122 int err;
123
124 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
125 if (err)
126 return ERR_PTR(err);
122 127
123 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER, 128 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
124 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 129 CRYPTO_ALG_TYPE_MASK);
125 if (IS_ERR(alg)) 130 if (IS_ERR(alg))
126 return ERR_PTR(PTR_ERR(alg)); 131 return ERR_PTR(PTR_ERR(alg));
127 132
diff --git a/crypto/hash.c b/crypto/hash.c
index 12c4514f3478..4ccd22deef39 100644
--- a/crypto/hash.c
+++ b/crypto/hash.c
@@ -41,7 +41,7 @@ static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
41} 41}
42 42
43static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) 43static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
44 __attribute_used__; 44 __attribute__ ((unused));
45static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) 45static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
46{ 46{
47 seq_printf(m, "type : hash\n"); 47 seq_printf(m, "type : hash\n");
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 44187c5ee593..8802fb6dd5a6 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -197,13 +197,18 @@ static void hmac_free(struct crypto_instance *inst)
197 kfree(inst); 197 kfree(inst);
198} 198}
199 199
200static struct crypto_instance *hmac_alloc(void *param, unsigned int len) 200static struct crypto_instance *hmac_alloc(struct rtattr **tb)
201{ 201{
202 struct crypto_instance *inst; 202 struct crypto_instance *inst;
203 struct crypto_alg *alg; 203 struct crypto_alg *alg;
204 int err;
205
206 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH);
207 if (err)
208 return ERR_PTR(err);
204 209
205 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_HASH, 210 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_HASH,
206 CRYPTO_ALG_TYPE_HASH_MASK | CRYPTO_ALG_ASYNC); 211 CRYPTO_ALG_TYPE_HASH_MASK);
207 if (IS_ERR(alg)) 212 if (IS_ERR(alg))
208 return ERR_PTR(PTR_ERR(alg)); 213 return ERR_PTR(PTR_ERR(alg));
209 214
diff --git a/crypto/lrw.c b/crypto/lrw.c
index b4105080ac7a..621095db28b3 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -228,13 +228,18 @@ static void exit_tfm(struct crypto_tfm *tfm)
228 crypto_free_cipher(ctx->child); 228 crypto_free_cipher(ctx->child);
229} 229}
230 230
231static struct crypto_instance *alloc(void *param, unsigned int len) 231static struct crypto_instance *alloc(struct rtattr **tb)
232{ 232{
233 struct crypto_instance *inst; 233 struct crypto_instance *inst;
234 struct crypto_alg *alg; 234 struct crypto_alg *alg;
235 int err;
236
237 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
238 if (err)
239 return ERR_PTR(err);
235 240
236 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER, 241 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
237 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 242 CRYPTO_ALG_TYPE_MASK);
238 if (IS_ERR(alg)) 243 if (IS_ERR(alg))
239 return ERR_PTR(PTR_ERR(alg)); 244 return ERR_PTR(PTR_ERR(alg));
240 245
diff --git a/crypto/pcbc.c b/crypto/pcbc.c
index 5174d7fdad6e..c3ed8a1c9f46 100644
--- a/crypto/pcbc.c
+++ b/crypto/pcbc.c
@@ -279,13 +279,18 @@ static void crypto_pcbc_exit_tfm(struct crypto_tfm *tfm)
279 crypto_free_cipher(ctx->child); 279 crypto_free_cipher(ctx->child);
280} 280}
281 281
282static struct crypto_instance *crypto_pcbc_alloc(void *param, unsigned int len) 282static struct crypto_instance *crypto_pcbc_alloc(struct rtattr **tb)
283{ 283{
284 struct crypto_instance *inst; 284 struct crypto_instance *inst;
285 struct crypto_alg *alg; 285 struct crypto_alg *alg;
286 int err;
287
288 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
289 if (err)
290 return ERR_PTR(err);
286 291
287 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER, 292 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
288 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 293 CRYPTO_ALG_TYPE_MASK);
289 if (IS_ERR(alg)) 294 if (IS_ERR(alg))
290 return ERR_PTR(PTR_ERR(alg)); 295 return ERR_PTR(PTR_ERR(alg));
291 296
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 8eaa5aa210b0..f0aed0106adb 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -57,6 +57,11 @@
57#define ENCRYPT 1 57#define ENCRYPT 1
58#define DECRYPT 0 58#define DECRYPT 0
59 59
60struct tcrypt_result {
61 struct completion completion;
62 int err;
63};
64
60static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 65static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
61 66
62/* 67/*
@@ -84,6 +89,17 @@ static void hexdump(unsigned char *buf, unsigned int len)
84 printk("\n"); 89 printk("\n");
85} 90}
86 91
92static void tcrypt_complete(struct crypto_async_request *req, int err)
93{
94 struct tcrypt_result *res = req->data;
95
96 if (err == -EINPROGRESS)
97 return;
98
99 res->err = err;
100 complete(&res->completion);
101}
102
87static void test_hash(char *algo, struct hash_testvec *template, 103static void test_hash(char *algo, struct hash_testvec *template,
88 unsigned int tcount) 104 unsigned int tcount)
89{ 105{
@@ -203,15 +219,14 @@ static void test_cipher(char *algo, int enc,
203{ 219{
204 unsigned int ret, i, j, k, temp; 220 unsigned int ret, i, j, k, temp;
205 unsigned int tsize; 221 unsigned int tsize;
206 unsigned int iv_len;
207 unsigned int len;
208 char *q; 222 char *q;
209 struct crypto_blkcipher *tfm; 223 struct crypto_ablkcipher *tfm;
210 char *key; 224 char *key;
211 struct cipher_testvec *cipher_tv; 225 struct cipher_testvec *cipher_tv;
212 struct blkcipher_desc desc; 226 struct ablkcipher_request *req;
213 struct scatterlist sg[8]; 227 struct scatterlist sg[8];
214 const char *e; 228 const char *e;
229 struct tcrypt_result result;
215 230
216 if (enc == ENCRYPT) 231 if (enc == ENCRYPT)
217 e = "encryption"; 232 e = "encryption";
@@ -232,15 +247,24 @@ static void test_cipher(char *algo, int enc,
232 memcpy(tvmem, template, tsize); 247 memcpy(tvmem, template, tsize);
233 cipher_tv = (void *)tvmem; 248 cipher_tv = (void *)tvmem;
234 249
235 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); 250 init_completion(&result.completion);
251
252 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
236 253
237 if (IS_ERR(tfm)) { 254 if (IS_ERR(tfm)) {
238 printk("failed to load transform for %s: %ld\n", algo, 255 printk("failed to load transform for %s: %ld\n", algo,
239 PTR_ERR(tfm)); 256 PTR_ERR(tfm));
240 return; 257 return;
241 } 258 }
242 desc.tfm = tfm; 259
243 desc.flags = 0; 260 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
261 if (!req) {
262 printk("failed to allocate request for %s\n", algo);
263 goto out;
264 }
265
266 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
267 tcrypt_complete, &result);
244 268
245 j = 0; 269 j = 0;
246 for (i = 0; i < tcount; i++) { 270 for (i = 0; i < tcount; i++) {
@@ -249,17 +273,17 @@ static void test_cipher(char *algo, int enc,
249 printk("test %u (%d bit key):\n", 273 printk("test %u (%d bit key):\n",
250 j, cipher_tv[i].klen * 8); 274 j, cipher_tv[i].klen * 8);
251 275
252 crypto_blkcipher_clear_flags(tfm, ~0); 276 crypto_ablkcipher_clear_flags(tfm, ~0);
253 if (cipher_tv[i].wk) 277 if (cipher_tv[i].wk)
254 crypto_blkcipher_set_flags( 278 crypto_ablkcipher_set_flags(
255 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 279 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
256 key = cipher_tv[i].key; 280 key = cipher_tv[i].key;
257 281
258 ret = crypto_blkcipher_setkey(tfm, key, 282 ret = crypto_ablkcipher_setkey(tfm, key,
259 cipher_tv[i].klen); 283 cipher_tv[i].klen);
260 if (ret) { 284 if (ret) {
261 printk("setkey() failed flags=%x\n", 285 printk("setkey() failed flags=%x\n",
262 crypto_blkcipher_get_flags(tfm)); 286 crypto_ablkcipher_get_flags(tfm));
263 287
264 if (!cipher_tv[i].fail) 288 if (!cipher_tv[i].fail)
265 goto out; 289 goto out;
@@ -268,19 +292,28 @@ static void test_cipher(char *algo, int enc,
268 sg_set_buf(&sg[0], cipher_tv[i].input, 292 sg_set_buf(&sg[0], cipher_tv[i].input,
269 cipher_tv[i].ilen); 293 cipher_tv[i].ilen);
270 294
271 iv_len = crypto_blkcipher_ivsize(tfm); 295 ablkcipher_request_set_crypt(req, sg, sg,
272 if (iv_len) 296 cipher_tv[i].ilen,
273 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, 297 cipher_tv[i].iv);
274 iv_len);
275 298
276 len = cipher_tv[i].ilen;
277 ret = enc ? 299 ret = enc ?
278 crypto_blkcipher_encrypt(&desc, sg, sg, len) : 300 crypto_ablkcipher_encrypt(req) :
279 crypto_blkcipher_decrypt(&desc, sg, sg, len); 301 crypto_ablkcipher_decrypt(req);
280 302
281 if (ret) { 303 switch (ret) {
282 printk("%s () failed flags=%x\n", e, 304 case 0:
283 desc.flags); 305 break;
306 case -EINPROGRESS:
307 case -EBUSY:
308 ret = wait_for_completion_interruptible(
309 &result.completion);
310 if (!ret && !((ret = result.err))) {
311 INIT_COMPLETION(result.completion);
312 break;
313 }
314 /* fall through */
315 default:
316 printk("%s () failed err=%d\n", e, -ret);
284 goto out; 317 goto out;
285 } 318 }
286 319
@@ -303,17 +336,17 @@ static void test_cipher(char *algo, int enc,
303 printk("test %u (%d bit key):\n", 336 printk("test %u (%d bit key):\n",
304 j, cipher_tv[i].klen * 8); 337 j, cipher_tv[i].klen * 8);
305 338
306 crypto_blkcipher_clear_flags(tfm, ~0); 339 crypto_ablkcipher_clear_flags(tfm, ~0);
307 if (cipher_tv[i].wk) 340 if (cipher_tv[i].wk)
308 crypto_blkcipher_set_flags( 341 crypto_ablkcipher_set_flags(
309 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 342 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
310 key = cipher_tv[i].key; 343 key = cipher_tv[i].key;
311 344
312 ret = crypto_blkcipher_setkey(tfm, key, 345 ret = crypto_ablkcipher_setkey(tfm, key,
313 cipher_tv[i].klen); 346 cipher_tv[i].klen);
314 if (ret) { 347 if (ret) {
315 printk("setkey() failed flags=%x\n", 348 printk("setkey() failed flags=%x\n",
316 crypto_blkcipher_get_flags(tfm)); 349 crypto_ablkcipher_get_flags(tfm));
317 350
318 if (!cipher_tv[i].fail) 351 if (!cipher_tv[i].fail)
319 goto out; 352 goto out;
@@ -329,19 +362,28 @@ static void test_cipher(char *algo, int enc,
329 cipher_tv[i].tap[k]); 362 cipher_tv[i].tap[k]);
330 } 363 }
331 364
332 iv_len = crypto_blkcipher_ivsize(tfm); 365 ablkcipher_request_set_crypt(req, sg, sg,
333 if (iv_len) 366 cipher_tv[i].ilen,
334 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, 367 cipher_tv[i].iv);
335 iv_len);
336 368
337 len = cipher_tv[i].ilen;
338 ret = enc ? 369 ret = enc ?
339 crypto_blkcipher_encrypt(&desc, sg, sg, len) : 370 crypto_ablkcipher_encrypt(req) :
340 crypto_blkcipher_decrypt(&desc, sg, sg, len); 371 crypto_ablkcipher_decrypt(req);
341 372
342 if (ret) { 373 switch (ret) {
343 printk("%s () failed flags=%x\n", e, 374 case 0:
344 desc.flags); 375 break;
376 case -EINPROGRESS:
377 case -EBUSY:
378 ret = wait_for_completion_interruptible(
379 &result.completion);
380 if (!ret && !((ret = result.err))) {
381 INIT_COMPLETION(result.completion);
382 break;
383 }
384 /* fall through */
385 default:
386 printk("%s () failed err=%d\n", e, -ret);
345 goto out; 387 goto out;
346 } 388 }
347 389
@@ -360,7 +402,8 @@ static void test_cipher(char *algo, int enc,
360 } 402 }
361 403
362out: 404out:
363 crypto_free_blkcipher(tfm); 405 crypto_free_ablkcipher(tfm);
406 ablkcipher_request_free(req);
364} 407}
365 408
366static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p, 409static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
@@ -832,7 +875,7 @@ static void test_available(void)
832 875
833 while (*name) { 876 while (*name) {
834 printk("alg %s ", *name); 877 printk("alg %s ", *name);
835 printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ? 878 printk(crypto_has_alg(*name, 0, 0) ?
836 "found\n" : "not found\n"); 879 "found\n" : "not found\n");
837 name++; 880 name++;
838 } 881 }
diff --git a/crypto/xcbc.c b/crypto/xcbc.c
index 53e8ccbf0f5f..9f502b86e0ea 100644
--- a/crypto/xcbc.c
+++ b/crypto/xcbc.c
@@ -288,12 +288,18 @@ static void xcbc_exit_tfm(struct crypto_tfm *tfm)
288 crypto_free_cipher(ctx->child); 288 crypto_free_cipher(ctx->child);
289} 289}
290 290
291static struct crypto_instance *xcbc_alloc(void *param, unsigned int len) 291static struct crypto_instance *xcbc_alloc(struct rtattr **tb)
292{ 292{
293 struct crypto_instance *inst; 293 struct crypto_instance *inst;
294 struct crypto_alg *alg; 294 struct crypto_alg *alg;
295 alg = crypto_get_attr_alg(param, len, CRYPTO_ALG_TYPE_CIPHER, 295 int err;
296 CRYPTO_ALG_TYPE_HASH_MASK | CRYPTO_ALG_ASYNC); 296
297 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH);
298 if (err)
299 return ERR_PTR(err);
300
301 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER,
302 CRYPTO_ALG_TYPE_MASK);
297 if (IS_ERR(alg)) 303 if (IS_ERR(alg))
298 return ERR_PTR(PTR_ERR(alg)); 304 return ERR_PTR(PTR_ERR(alg));
299 305
diff --git a/drivers/Makefile b/drivers/Makefile
index 920c975bb6d4..26ca9031ea49 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -58,7 +58,7 @@ obj-$(CONFIG_GAMEPORT) += input/gameport/
58obj-$(CONFIG_INPUT) += input/ 58obj-$(CONFIG_INPUT) += input/
59obj-$(CONFIG_I2O) += message/ 59obj-$(CONFIG_I2O) += message/
60obj-$(CONFIG_RTC_LIB) += rtc/ 60obj-$(CONFIG_RTC_LIB) += rtc/
61obj-$(CONFIG_I2C) += i2c/ 61obj-y += i2c/
62obj-$(CONFIG_W1) += w1/ 62obj-$(CONFIG_W1) += w1/
63obj-$(CONFIG_HWMON) += hwmon/ 63obj-$(CONFIG_HWMON) += hwmon/
64obj-$(CONFIG_PHONE) += telephony/ 64obj-$(CONFIG_PHONE) += telephony/
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 2f2e7964226d..c4efc0c17f8f 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -433,49 +433,6 @@ static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
433 PDE(inode)->data); 433 PDE(inode)->data);
434} 434}
435 435
436static ssize_t
437acpi_processor_write_performance(struct file *file,
438 const char __user * buffer,
439 size_t count, loff_t * data)
440{
441 int result = 0;
442 struct seq_file *m = file->private_data;
443 struct acpi_processor *pr = m->private;
444 struct acpi_processor_performance *perf;
445 char state_string[12] = { '\0' };
446 unsigned int new_state = 0;
447 struct cpufreq_policy policy;
448
449
450 if (!pr || (count > sizeof(state_string) - 1))
451 return -EINVAL;
452
453 perf = pr->performance;
454 if (!perf)
455 return -EINVAL;
456
457 if (copy_from_user(state_string, buffer, count))
458 return -EFAULT;
459
460 state_string[count] = '\0';
461 new_state = simple_strtoul(state_string, NULL, 0);
462
463 if (new_state >= perf->state_count)
464 return -EINVAL;
465
466 cpufreq_get_policy(&policy, pr->id);
467
468 policy.cpu = pr->id;
469 policy.min = perf->states[new_state].core_frequency * 1000;
470 policy.max = perf->states[new_state].core_frequency * 1000;
471
472 result = cpufreq_set_policy(&policy);
473 if (result)
474 return result;
475
476 return count;
477}
478
479static void acpi_cpufreq_add_file(struct acpi_processor *pr) 436static void acpi_cpufreq_add_file(struct acpi_processor *pr)
480{ 437{
481 struct proc_dir_entry *entry = NULL; 438 struct proc_dir_entry *entry = NULL;
@@ -487,10 +444,9 @@ static void acpi_cpufreq_add_file(struct acpi_processor *pr)
487 444
488 /* add file 'performance' [R/W] */ 445 /* add file 'performance' [R/W] */
489 entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, 446 entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
490 S_IFREG | S_IRUGO | S_IWUSR, 447 S_IFREG | S_IRUGO,
491 acpi_device_dir(device)); 448 acpi_device_dir(device));
492 if (entry){ 449 if (entry){
493 acpi_processor_perf_fops.write = acpi_processor_write_performance;
494 entry->proc_fops = &acpi_processor_perf_fops; 450 entry->proc_fops = &acpi_processor_perf_fops;
495 entry->data = acpi_driver_data(device); 451 entry->data = acpi_driver_data(device);
496 entry->owner = THIS_MODULE; 452 entry->owner = THIS_MODULE;
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index 5b684fddcc03..4941ddb78939 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -145,6 +145,7 @@ static void *m1541_alloc_page(struct agp_bridge_data *bridge)
145 void *addr = agp_generic_alloc_page(agp_bridge); 145 void *addr = agp_generic_alloc_page(agp_bridge);
146 u32 temp; 146 u32 temp;
147 147
148 global_flush_tlb();
148 if (!addr) 149 if (!addr)
149 return NULL; 150 return NULL;
150 151
@@ -160,6 +161,7 @@ static void ali_destroy_page(void * addr)
160 if (addr) { 161 if (addr) {
161 global_cache_flush(); /* is this really needed? --hch */ 162 global_cache_flush(); /* is this really needed? --hch */
162 agp_generic_destroy_page(addr); 163 agp_generic_destroy_page(addr);
164 global_flush_tlb();
163 } 165 }
164} 166}
165 167
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index f902d71947ba..45aeb917ec63 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -51,28 +51,6 @@ int agp_memory_reserved;
51 */ 51 */
52EXPORT_SYMBOL_GPL(agp_memory_reserved); 52EXPORT_SYMBOL_GPL(agp_memory_reserved);
53 53
54#if defined(CONFIG_X86)
55int map_page_into_agp(struct page *page)
56{
57 int i;
58 i = change_page_attr(page, 1, PAGE_KERNEL_NOCACHE);
59 /* Caller's responsibility to call global_flush_tlb() for
60 * performance reasons */
61 return i;
62}
63EXPORT_SYMBOL_GPL(map_page_into_agp);
64
65int unmap_page_from_agp(struct page *page)
66{
67 int i;
68 i = change_page_attr(page, 1, PAGE_KERNEL);
69 /* Caller's responsibility to call global_flush_tlb() for
70 * performance reasons */
71 return i;
72}
73EXPORT_SYMBOL_GPL(unmap_page_from_agp);
74#endif
75
76/* 54/*
77 * Generic routines for handling agp_memory structures - 55 * Generic routines for handling agp_memory structures -
78 * They use the basic page allocation routines to do the brunt of the work. 56 * They use the basic page allocation routines to do the brunt of the work.
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 55392a45a14b..9c69f2e761f5 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -186,8 +186,9 @@ static void *i8xx_alloc_pages(void)
186 return NULL; 186 return NULL;
187 187
188 if (change_page_attr(page, 4, PAGE_KERNEL_NOCACHE) < 0) { 188 if (change_page_attr(page, 4, PAGE_KERNEL_NOCACHE) < 0) {
189 change_page_attr(page, 4, PAGE_KERNEL);
189 global_flush_tlb(); 190 global_flush_tlb();
190 __free_page(page); 191 __free_pages(page, 2);
191 return NULL; 192 return NULL;
192 } 193 }
193 global_flush_tlb(); 194 global_flush_tlb();
@@ -209,7 +210,7 @@ static void i8xx_destroy_pages(void *addr)
209 global_flush_tlb(); 210 global_flush_tlb();
210 put_page(page); 211 put_page(page);
211 unlock_page(page); 212 unlock_page(page);
212 free_pages((unsigned long)addr, 2); 213 __free_pages(page, 2);
213 atomic_dec(&agp_bridge->current_memory_agp); 214 atomic_dec(&agp_bridge->current_memory_agp);
214} 215}
215 216
@@ -315,9 +316,6 @@ static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
315 struct agp_memory *new; 316 struct agp_memory *new;
316 void *addr; 317 void *addr;
317 318
318 if (pg_count != 1 && pg_count != 4)
319 return NULL;
320
321 switch (pg_count) { 319 switch (pg_count) {
322 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge); 320 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
323 global_flush_tlb(); 321 global_flush_tlb();
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 0c9dab557c94..6cd7373dcdf4 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -320,11 +320,11 @@ static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
320 u8 cap_ptr; 320 u8 cap_ptr;
321 321
322 nvidia_private.dev_1 = 322 nvidia_private.dev_1 =
323 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 1)); 323 pci_get_bus_and_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 1));
324 nvidia_private.dev_2 = 324 nvidia_private.dev_2 =
325 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 2)); 325 pci_get_bus_and_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 2));
326 nvidia_private.dev_3 = 326 nvidia_private.dev_3 =
327 pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(30, 0)); 327 pci_get_bus_and_slot((unsigned int)pdev->bus->number, PCI_DEVFN(30, 0));
328 328
329 if (!nvidia_private.dev_1 || !nvidia_private.dev_2 || !nvidia_private.dev_3) { 329 if (!nvidia_private.dev_1 || !nvidia_private.dev_2 || !nvidia_private.dev_3) {
330 printk(KERN_INFO PFX "Detected an NVIDIA nForce/nForce2 " 330 printk(KERN_INFO PFX "Detected an NVIDIA nForce/nForce2 "
@@ -443,6 +443,9 @@ static int __init agp_nvidia_init(void)
443static void __exit agp_nvidia_cleanup(void) 443static void __exit agp_nvidia_cleanup(void)
444{ 444{
445 pci_unregister_driver(&agp_nvidia_pci_driver); 445 pci_unregister_driver(&agp_nvidia_pci_driver);
446 pci_dev_put(nvidia_private.dev_1);
447 pci_dev_put(nvidia_private.dev_2);
448 pci_dev_put(nvidia_private.dev_3);
446} 449}
447 450
448module_init(agp_nvidia_init); 451module_init(agp_nvidia_init);
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index ee8f50edde1b..cda608c42bea 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -47,9 +47,8 @@ static void *sgi_tioca_alloc_page(struct agp_bridge_data *bridge)
47 47
48 nid = info->ca_closest_node; 48 nid = info->ca_closest_node;
49 page = alloc_pages_node(nid, GFP_KERNEL, 0); 49 page = alloc_pages_node(nid, GFP_KERNEL, 0);
50 if (page == NULL) { 50 if (!page)
51 return 0; 51 return NULL;
52 }
53 52
54 get_page(page); 53 get_page(page);
55 SetPageLocked(page); 54 SetPageLocked(page);
diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index 125f4282d955..eb1a1c738190 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -143,96 +143,6 @@ static struct agp_bridge_driver sis_driver = {
143 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 143 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
144}; 144};
145 145
146static struct agp_device_ids sis_agp_device_ids[] __devinitdata =
147{
148 {
149 .device_id = PCI_DEVICE_ID_SI_5591_AGP,
150 .chipset_name = "5591",
151 },
152 {
153 .device_id = PCI_DEVICE_ID_SI_530,
154 .chipset_name = "530",
155 },
156 {
157 .device_id = PCI_DEVICE_ID_SI_540,
158 .chipset_name = "540",
159 },
160 {
161 .device_id = PCI_DEVICE_ID_SI_550,
162 .chipset_name = "550",
163 },
164 {
165 .device_id = PCI_DEVICE_ID_SI_620,
166 .chipset_name = "620",
167 },
168 {
169 .device_id = PCI_DEVICE_ID_SI_630,
170 .chipset_name = "630",
171 },
172 {
173 .device_id = PCI_DEVICE_ID_SI_635,
174 .chipset_name = "635",
175 },
176 {
177 .device_id = PCI_DEVICE_ID_SI_645,
178 .chipset_name = "645",
179 },
180 {
181 .device_id = PCI_DEVICE_ID_SI_646,
182 .chipset_name = "646",
183 },
184 {
185 .device_id = PCI_DEVICE_ID_SI_648,
186 .chipset_name = "648",
187 },
188 {
189 .device_id = PCI_DEVICE_ID_SI_650,
190 .chipset_name = "650",
191 },
192 {
193 .device_id = PCI_DEVICE_ID_SI_651,
194 .chipset_name = "651",
195 },
196 {
197 .device_id = PCI_DEVICE_ID_SI_655,
198 .chipset_name = "655",
199 },
200 {
201 .device_id = PCI_DEVICE_ID_SI_661,
202 .chipset_name = "661",
203 },
204 {
205 .device_id = PCI_DEVICE_ID_SI_730,
206 .chipset_name = "730",
207 },
208 {
209 .device_id = PCI_DEVICE_ID_SI_735,
210 .chipset_name = "735",
211 },
212 {
213 .device_id = PCI_DEVICE_ID_SI_740,
214 .chipset_name = "740",
215 },
216 {
217 .device_id = PCI_DEVICE_ID_SI_741,
218 .chipset_name = "741",
219 },
220 {
221 .device_id = PCI_DEVICE_ID_SI_745,
222 .chipset_name = "745",
223 },
224 {
225 .device_id = PCI_DEVICE_ID_SI_746,
226 .chipset_name = "746",
227 },
228 {
229 .device_id = PCI_DEVICE_ID_SI_760,
230 .chipset_name = "760",
231 },
232 { }, /* dummy final entry, always present */
233};
234
235
236// chipsets that require the 'delay hack' 146// chipsets that require the 'delay hack'
237static int sis_broken_chipsets[] __devinitdata = { 147static int sis_broken_chipsets[] __devinitdata = {
238 PCI_DEVICE_ID_SI_648, 148 PCI_DEVICE_ID_SI_648,
@@ -269,29 +179,15 @@ static void __devinit sis_get_driver(struct agp_bridge_data *bridge)
269static int __devinit agp_sis_probe(struct pci_dev *pdev, 179static int __devinit agp_sis_probe(struct pci_dev *pdev,
270 const struct pci_device_id *ent) 180 const struct pci_device_id *ent)
271{ 181{
272 struct agp_device_ids *devs = sis_agp_device_ids;
273 struct agp_bridge_data *bridge; 182 struct agp_bridge_data *bridge;
274 u8 cap_ptr; 183 u8 cap_ptr;
275 int j;
276 184
277 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); 185 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
278 if (!cap_ptr) 186 if (!cap_ptr)
279 return -ENODEV; 187 return -ENODEV;
280 188
281 /* probe for known chipsets */
282 for (j = 0; devs[j].chipset_name; j++) {
283 if (pdev->device == devs[j].device_id) {
284 printk(KERN_INFO PFX "Detected SiS %s chipset\n",
285 devs[j].chipset_name);
286 goto found;
287 }
288 }
289
290 printk(KERN_ERR PFX "Unsupported SiS chipset (device id: %04x)\n",
291 pdev->device);
292 return -ENODEV;
293 189
294found: 190 printk(KERN_INFO PFX "Detected SiS chipset - id:%i\n", pdev->device);
295 bridge = agp_alloc_bridge(); 191 bridge = agp_alloc_bridge();
296 if (!bridge) 192 if (!bridge)
297 return -ENOMEM; 193 return -ENOMEM;
@@ -320,12 +216,172 @@ static void __devexit agp_sis_remove(struct pci_dev *pdev)
320 216
321static struct pci_device_id agp_sis_pci_table[] = { 217static struct pci_device_id agp_sis_pci_table[] = {
322 { 218 {
323 .class = (PCI_CLASS_BRIDGE_HOST << 8), 219 .class = (PCI_CLASS_BRIDGE_HOST << 8),
324 .class_mask = ~0, 220 .class_mask = ~0,
325 .vendor = PCI_VENDOR_ID_SI, 221 .vendor = PCI_VENDOR_ID_SI,
326 .device = PCI_ANY_ID, 222 .device = PCI_DEVICE_ID_SI_5591_AGP,
327 .subvendor = PCI_ANY_ID, 223 .subvendor = PCI_ANY_ID,
328 .subdevice = PCI_ANY_ID, 224 .subdevice = PCI_ANY_ID,
225 },
226 {
227 .class = (PCI_CLASS_BRIDGE_HOST << 8),
228 .class_mask = ~0,
229 .vendor = PCI_VENDOR_ID_SI,
230 .device = PCI_DEVICE_ID_SI_530,
231 .subvendor = PCI_ANY_ID,
232 .subdevice = PCI_ANY_ID,
233 },
234 {
235 .class = (PCI_CLASS_BRIDGE_HOST << 8),
236 .class_mask = ~0,
237 .vendor = PCI_VENDOR_ID_SI,
238 .device = PCI_DEVICE_ID_SI_540,
239 .subvendor = PCI_ANY_ID,
240 .subdevice = PCI_ANY_ID,
241 },
242 {
243 .class = (PCI_CLASS_BRIDGE_HOST << 8),
244 .class_mask = ~0,
245 .vendor = PCI_VENDOR_ID_SI,
246 .device = PCI_DEVICE_ID_SI_550,
247 .subvendor = PCI_ANY_ID,
248 .subdevice = PCI_ANY_ID,
249 },
250 {
251 .class = (PCI_CLASS_BRIDGE_HOST << 8),
252 .class_mask = ~0,
253 .vendor = PCI_VENDOR_ID_SI,
254 .device = PCI_DEVICE_ID_SI_620,
255 .subvendor = PCI_ANY_ID,
256 .subdevice = PCI_ANY_ID,
257 },
258 {
259 .class = (PCI_CLASS_BRIDGE_HOST << 8),
260 .class_mask = ~0,
261 .vendor = PCI_VENDOR_ID_SI,
262 .device = PCI_DEVICE_ID_SI_630,
263 .subvendor = PCI_ANY_ID,
264 .subdevice = PCI_ANY_ID,
265 },
266 {
267 .class = (PCI_CLASS_BRIDGE_HOST << 8),
268 .class_mask = ~0,
269 .vendor = PCI_VENDOR_ID_SI,
270 .device = PCI_DEVICE_ID_SI_635,
271 .subvendor = PCI_ANY_ID,
272 .subdevice = PCI_ANY_ID,
273 },
274 {
275 .class = (PCI_CLASS_BRIDGE_HOST << 8),
276 .class_mask = ~0,
277 .vendor = PCI_VENDOR_ID_SI,
278 .device = PCI_DEVICE_ID_SI_645,
279 .subvendor = PCI_ANY_ID,
280 .subdevice = PCI_ANY_ID,
281 },
282 {
283 .class = (PCI_CLASS_BRIDGE_HOST << 8),
284 .class_mask = ~0,
285 .vendor = PCI_VENDOR_ID_SI,
286 .device = PCI_DEVICE_ID_SI_646,
287 .subvendor = PCI_ANY_ID,
288 .subdevice = PCI_ANY_ID,
289 },
290 {
291 .class = (PCI_CLASS_BRIDGE_HOST << 8),
292 .class_mask = ~0,
293 .vendor = PCI_VENDOR_ID_SI,
294 .device = PCI_DEVICE_ID_SI_648,
295 .subvendor = PCI_ANY_ID,
296 .subdevice = PCI_ANY_ID,
297 },
298 {
299 .class = (PCI_CLASS_BRIDGE_HOST << 8),
300 .class_mask = ~0,
301 .vendor = PCI_VENDOR_ID_SI,
302 .device = PCI_DEVICE_ID_SI_650,
303 .subvendor = PCI_ANY_ID,
304 .subdevice = PCI_ANY_ID,
305 },
306 {
307 .class = (PCI_CLASS_BRIDGE_HOST << 8),
308 .class_mask = ~0,
309 .vendor = PCI_VENDOR_ID_SI,
310 .device = PCI_DEVICE_ID_SI_651,
311 .subvendor = PCI_ANY_ID,
312 .subdevice = PCI_ANY_ID,
313 },
314 {
315 .class = (PCI_CLASS_BRIDGE_HOST << 8),
316 .class_mask = ~0,
317 .vendor = PCI_VENDOR_ID_SI,
318 .device = PCI_DEVICE_ID_SI_655,
319 .subvendor = PCI_ANY_ID,
320 .subdevice = PCI_ANY_ID,
321 },
322 {
323 .class = (PCI_CLASS_BRIDGE_HOST << 8),
324 .class_mask = ~0,
325 .vendor = PCI_VENDOR_ID_SI,
326 .device = PCI_DEVICE_ID_SI_661,
327 .subvendor = PCI_ANY_ID,
328 .subdevice = PCI_ANY_ID,
329 },
330 {
331 .class = (PCI_CLASS_BRIDGE_HOST << 8),
332 .class_mask = ~0,
333 .vendor = PCI_VENDOR_ID_SI,
334 .device = PCI_DEVICE_ID_SI_730,
335 .subvendor = PCI_ANY_ID,
336 .subdevice = PCI_ANY_ID,
337 },
338 {
339 .class = (PCI_CLASS_BRIDGE_HOST << 8),
340 .class_mask = ~0,
341 .vendor = PCI_VENDOR_ID_SI,
342 .device = PCI_DEVICE_ID_SI_735,
343 .subvendor = PCI_ANY_ID,
344 .subdevice = PCI_ANY_ID,
345 },
346 {
347 .class = (PCI_CLASS_BRIDGE_HOST << 8),
348 .class_mask = ~0,
349 .vendor = PCI_VENDOR_ID_SI,
350 .device = PCI_DEVICE_ID_SI_740,
351 .subvendor = PCI_ANY_ID,
352 .subdevice = PCI_ANY_ID,
353 },
354 {
355 .class = (PCI_CLASS_BRIDGE_HOST << 8),
356 .class_mask = ~0,
357 .vendor = PCI_VENDOR_ID_SI,
358 .device = PCI_DEVICE_ID_SI_741,
359 .subvendor = PCI_ANY_ID,
360 .subdevice = PCI_ANY_ID,
361 },
362 {
363 .class = (PCI_CLASS_BRIDGE_HOST << 8),
364 .class_mask = ~0,
365 .vendor = PCI_VENDOR_ID_SI,
366 .device = PCI_DEVICE_ID_SI_745,
367 .subvendor = PCI_ANY_ID,
368 .subdevice = PCI_ANY_ID,
369 },
370 {
371 .class = (PCI_CLASS_BRIDGE_HOST << 8),
372 .class_mask = ~0,
373 .vendor = PCI_VENDOR_ID_SI,
374 .device = PCI_DEVICE_ID_SI_746,
375 .subvendor = PCI_ANY_ID,
376 .subdevice = PCI_ANY_ID,
377 },
378 {
379 .class = (PCI_CLASS_BRIDGE_HOST << 8),
380 .class_mask = ~0,
381 .vendor = PCI_VENDOR_ID_SI,
382 .device = PCI_DEVICE_ID_SI_760,
383 .subvendor = PCI_ANY_ID,
384 .subdevice = PCI_ANY_ID,
329 }, 385 },
330 { } 386 { }
331}; 387};
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 55212a3811fd..551ef25063ef 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -455,15 +455,6 @@ static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
455 u32 temp, temp2; 455 u32 temp, temp2;
456 u8 cap_ptr = 0; 456 u8 cap_ptr = 0;
457 457
458 /* Everything is on func 1 here so we are hardcoding function one */
459 bridge_dev = pci_find_slot((unsigned int)pdev->bus->number,
460 PCI_DEVFN(0, 1));
461 if (!bridge_dev) {
462 printk(KERN_INFO PFX "Detected a Serverworks chipset "
463 "but could not find the secondary device.\n");
464 return -ENODEV;
465 }
466
467 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); 458 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
468 459
469 switch (pdev->device) { 460 switch (pdev->device) {
@@ -483,6 +474,15 @@ static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
483 return -ENODEV; 474 return -ENODEV;
484 } 475 }
485 476
477 /* Everything is on func 1 here so we are hardcoding function one */
478 bridge_dev = pci_get_bus_and_slot((unsigned int)pdev->bus->number,
479 PCI_DEVFN(0, 1));
480 if (!bridge_dev) {
481 printk(KERN_INFO PFX "Detected a Serverworks chipset "
482 "but could not find the secondary device.\n");
483 return -ENODEV;
484 }
485
486 serverworks_private.svrwrks_dev = bridge_dev; 486 serverworks_private.svrwrks_dev = bridge_dev;
487 serverworks_private.gart_addr_ofs = 0x10; 487 serverworks_private.gart_addr_ofs = 0x10;
488 488
@@ -515,7 +515,7 @@ static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
515 515
516 bridge->driver = &sworks_driver; 516 bridge->driver = &sworks_driver;
517 bridge->dev_private_data = &serverworks_private, 517 bridge->dev_private_data = &serverworks_private,
518 bridge->dev = pdev; 518 bridge->dev = pci_dev_get(pdev);
519 519
520 pci_set_drvdata(pdev, bridge); 520 pci_set_drvdata(pdev, bridge);
521 return agp_add_bridge(bridge); 521 return agp_add_bridge(bridge);
@@ -525,8 +525,11 @@ static void __devexit agp_serverworks_remove(struct pci_dev *pdev)
525{ 525{
526 struct agp_bridge_data *bridge = pci_get_drvdata(pdev); 526 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
527 527
528 pci_dev_put(bridge->dev);
528 agp_remove_bridge(bridge); 529 agp_remove_bridge(bridge);
529 agp_put_bridge(bridge); 530 agp_put_bridge(bridge);
531 pci_dev_put(serverworks_private.svrwrks_dev);
532 serverworks_private.svrwrks_dev = NULL;
530} 533}
531 534
532static struct pci_device_id agp_serverworks_pci_table[] = { 535static struct pci_device_id agp_serverworks_pci_table[] = {
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index d155e81b5c97..993fa7b89253 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -9,6 +9,9 @@ config CPU_FREQ
9 clock speed, you need to either enable a dynamic cpufreq governor 9 clock speed, you need to either enable a dynamic cpufreq governor
10 (see below) after boot, or use a userspace tool. 10 (see below) after boot, or use a userspace tool.
11 11
12 To compile this driver as a module, choose M here: the
13 module will be called cpufreq.
14
12 For details, take a look at <file:Documentation/cpu-freq>. 15 For details, take a look at <file:Documentation/cpu-freq>.
13 16
14 If in doubt, say N. 17 If in doubt, say N.
@@ -16,7 +19,7 @@ config CPU_FREQ
16if CPU_FREQ 19if CPU_FREQ
17 20
18config CPU_FREQ_TABLE 21config CPU_FREQ_TABLE
19 tristate 22 tristate
20 23
21config CPU_FREQ_DEBUG 24config CPU_FREQ_DEBUG
22 bool "Enable CPUfreq debugging" 25 bool "Enable CPUfreq debugging"
@@ -32,19 +35,26 @@ config CPU_FREQ_DEBUG
32 4 to activate CPUfreq governor debugging 35 4 to activate CPUfreq governor debugging
33 36
34config CPU_FREQ_STAT 37config CPU_FREQ_STAT
35 tristate "CPU frequency translation statistics" 38 tristate "CPU frequency translation statistics"
36 select CPU_FREQ_TABLE 39 select CPU_FREQ_TABLE
37 default y 40 default y
38 help 41 help
39 This driver exports CPU frequency statistics information through sysfs 42 This driver exports CPU frequency statistics information through sysfs
40 file system 43 file system.
44
45 To compile this driver as a module, choose M here: the
46 module will be called cpufreq_stats.
47
48 If in doubt, say N.
41 49
42config CPU_FREQ_STAT_DETAILS 50config CPU_FREQ_STAT_DETAILS
43 bool "CPU frequency translation statistics details" 51 bool "CPU frequency translation statistics details"
44 depends on CPU_FREQ_STAT 52 depends on CPU_FREQ_STAT
45 help 53 help
46 This will show detail CPU frequency translation table in sysfs file 54 This will show detail CPU frequency translation table in sysfs file
47 system 55 system.
56
57 If in doubt, say N.
48 58
49# Note that it is not currently possible to set the other governors (such as ondemand) 59# Note that it is not currently possible to set the other governors (such as ondemand)
50# as the default, since if they fail to initialise, cpufreq will be 60# as the default, since if they fail to initialise, cpufreq will be
@@ -78,29 +88,38 @@ config CPU_FREQ_DEFAULT_GOV_USERSPACE
78endchoice 88endchoice
79 89
80config CPU_FREQ_GOV_PERFORMANCE 90config CPU_FREQ_GOV_PERFORMANCE
81 tristate "'performance' governor" 91 tristate "'performance' governor"
82 help 92 help
83 This cpufreq governor sets the frequency statically to the 93 This cpufreq governor sets the frequency statically to the
84 highest available CPU frequency. 94 highest available CPU frequency.
85 95
96 To compile this driver as a module, choose M here: the
97 module will be called cpufreq_performance.
98
86 If in doubt, say Y. 99 If in doubt, say Y.
87 100
88config CPU_FREQ_GOV_POWERSAVE 101config CPU_FREQ_GOV_POWERSAVE
89 tristate "'powersave' governor" 102 tristate "'powersave' governor"
90 help 103 help
91 This cpufreq governor sets the frequency statically to the 104 This cpufreq governor sets the frequency statically to the
92 lowest available CPU frequency. 105 lowest available CPU frequency.
93 106
107 To compile this driver as a module, choose M here: the
108 module will be called cpufreq_powersave.
109
94 If in doubt, say Y. 110 If in doubt, say Y.
95 111
96config CPU_FREQ_GOV_USERSPACE 112config CPU_FREQ_GOV_USERSPACE
97 tristate "'userspace' governor for userspace frequency scaling" 113 tristate "'userspace' governor for userspace frequency scaling"
98 help 114 help
99 Enable this cpufreq governor when you either want to set the 115 Enable this cpufreq governor when you either want to set the
100 CPU frequency manually or when an userspace program shall 116 CPU frequency manually or when an userspace program shall
101 be able to set the CPU dynamically, like on LART 117 be able to set the CPU dynamically, like on LART
102 <http://www.lartmaker.nl/>. 118 <http://www.lartmaker.nl/>.
103 119
120 To compile this driver as a module, choose M here: the
121 module will be called cpufreq_userspace.
122
104 For details, take a look at <file:Documentation/cpu-freq/>. 123 For details, take a look at <file:Documentation/cpu-freq/>.
105 124
106 If in doubt, say Y. 125 If in doubt, say Y.
@@ -116,6 +135,9 @@ config CPU_FREQ_GOV_ONDEMAND
116 do fast frequency switching (i.e, very low latency frequency 135 do fast frequency switching (i.e, very low latency frequency
117 transitions). 136 transitions).
118 137
138 To compile this driver as a module, choose M here: the
139 module will be called cpufreq_ondemand.
140
119 For details, take a look at linux/Documentation/cpu-freq. 141 For details, take a look at linux/Documentation/cpu-freq.
120 142
121 If in doubt, say N. 143 If in doubt, say N.
@@ -136,6 +158,9 @@ config CPU_FREQ_GOV_CONSERVATIVE
136 step-by-step latency issues between the minimum and maximum frequency 158 step-by-step latency issues between the minimum and maximum frequency
137 transitions in the CPU) you will probably want to use this governor. 159 transitions in the CPU) you will probably want to use this governor.
138 160
161 To compile this driver as a module, choose M here: the
162 module will be called cpufreq_conservative.
163
139 For details, take a look at linux/Documentation/cpu-freq. 164 For details, take a look at linux/Documentation/cpu-freq.
140 165
141 If in doubt, say N. 166 If in doubt, say N.
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 3162010900c9..893dbaf386fb 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -768,6 +768,9 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
768 unlock_policy_rwsem_write(cpu); 768 unlock_policy_rwsem_write(cpu);
769 goto err_out; 769 goto err_out;
770 } 770 }
771 policy->user_policy.min = policy->cpuinfo.min_freq;
772 policy->user_policy.max = policy->cpuinfo.max_freq;
773 policy->user_policy.governor = policy->governor;
771 774
772#ifdef CONFIG_SMP 775#ifdef CONFIG_SMP
773 for_each_cpu_mask(j, policy->cpus) { 776 for_each_cpu_mask(j, policy->cpus) {
@@ -858,10 +861,13 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
858 861
859 policy->governor = NULL; /* to assure that the starting sequence is 862 policy->governor = NULL; /* to assure that the starting sequence is
860 * run in cpufreq_set_policy */ 863 * run in cpufreq_set_policy */
861 unlock_policy_rwsem_write(cpu);
862 864
863 /* set default policy */ 865 /* set default policy */
864 ret = cpufreq_set_policy(&new_policy); 866 ret = __cpufreq_set_policy(policy, &new_policy);
867 policy->user_policy.policy = policy->policy;
868
869 unlock_policy_rwsem_write(cpu);
870
865 if (ret) { 871 if (ret) {
866 dprintk("setting policy failed\n"); 872 dprintk("setting policy failed\n");
867 goto err_out_unregister; 873 goto err_out_unregister;
@@ -1620,43 +1626,6 @@ error_out:
1620} 1626}
1621 1627
1622/** 1628/**
1623 * cpufreq_set_policy - set a new CPUFreq policy
1624 * @policy: policy to be set.
1625 *
1626 * Sets a new CPU frequency and voltage scaling policy.
1627 */
1628int cpufreq_set_policy(struct cpufreq_policy *policy)
1629{
1630 int ret = 0;
1631 struct cpufreq_policy *data;
1632
1633 if (!policy)
1634 return -EINVAL;
1635
1636 data = cpufreq_cpu_get(policy->cpu);
1637 if (!data)
1638 return -EINVAL;
1639
1640 if (unlikely(lock_policy_rwsem_write(policy->cpu)))
1641 return -EINVAL;
1642
1643
1644 ret = __cpufreq_set_policy(data, policy);
1645 data->user_policy.min = data->min;
1646 data->user_policy.max = data->max;
1647 data->user_policy.policy = data->policy;
1648 data->user_policy.governor = data->governor;
1649
1650 unlock_policy_rwsem_write(policy->cpu);
1651
1652 cpufreq_cpu_put(data);
1653
1654 return ret;
1655}
1656EXPORT_SYMBOL(cpufreq_set_policy);
1657
1658
1659/**
1660 * cpufreq_update_policy - re-evaluate an existing cpufreq policy 1629 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
1661 * @cpu: CPU which shall be re-evaluated 1630 * @cpu: CPU which shall be re-evaluated
1662 * 1631 *
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index ff8c4beaace4..f21fe66c9eef 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -1,10 +1,10 @@
1menu "Hardware crypto devices" 1menu "Hardware crypto devices"
2 2
3config CRYPTO_DEV_PADLOCK 3config CRYPTO_DEV_PADLOCK
4 tristate "Support for VIA PadLock ACE" 4 bool "Support for VIA PadLock ACE"
5 depends on X86_32 5 depends on X86_32
6 select CRYPTO_ALGAPI 6 select CRYPTO_ALGAPI
7 default m 7 default y
8 help 8 help
9 Some VIA processors come with an integrated crypto engine 9 Some VIA processors come with an integrated crypto engine
10 (so called VIA PadLock ACE, Advanced Cryptography Engine) 10 (so called VIA PadLock ACE, Advanced Cryptography Engine)
@@ -14,16 +14,6 @@ config CRYPTO_DEV_PADLOCK
14 The instructions are used only when the CPU supports them. 14 The instructions are used only when the CPU supports them.
15 Otherwise software encryption is used. 15 Otherwise software encryption is used.
16 16
17 Selecting M for this option will compile a helper module
18 padlock.ko that should autoload all below configured
19 algorithms. Don't worry if your hardware does not support
20 some or all of them. In such case padlock.ko will
21 simply write a single line into the kernel log informing
22 about its failure but everything will keep working fine.
23
24 If you are unsure, say M. The compiled module will be
25 called padlock.ko
26
27config CRYPTO_DEV_PADLOCK_AES 17config CRYPTO_DEV_PADLOCK_AES
28 tristate "PadLock driver for AES algorithm" 18 tristate "PadLock driver for AES algorithm"
29 depends on CRYPTO_DEV_PADLOCK 19 depends on CRYPTO_DEV_PADLOCK
@@ -55,7 +45,7 @@ source "arch/s390/crypto/Kconfig"
55 45
56config CRYPTO_DEV_GEODE 46config CRYPTO_DEV_GEODE
57 tristate "Support for the Geode LX AES engine" 47 tristate "Support for the Geode LX AES engine"
58 depends on CRYPTO && X86_32 && PCI 48 depends on X86_32 && PCI
59 select CRYPTO_ALGAPI 49 select CRYPTO_ALGAPI
60 select CRYPTO_BLKCIPHER 50 select CRYPTO_BLKCIPHER
61 default m 51 default m
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index 6059cf869414..d070030f7d7e 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -1,4 +1,3 @@
1obj-$(CONFIG_CRYPTO_DEV_PADLOCK) += padlock.o
2obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o 1obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o
3obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o 2obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o
4obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o 3obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
diff --git a/drivers/crypto/padlock.c b/drivers/crypto/padlock.c
deleted file mode 100644
index d6d7dd5bb98c..000000000000
--- a/drivers/crypto/padlock.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * Cryptographic API.
3 *
4 * Support for VIA PadLock hardware crypto engine.
5 *
6 * Copyright (c) 2006 Michal Ludvig <michal@logix.cz>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/crypto.h>
19#include <linux/cryptohash.h>
20#include <linux/interrupt.h>
21#include <linux/kernel.h>
22#include <linux/scatterlist.h>
23#include "padlock.h"
24
25static int __init padlock_init(void)
26{
27 int success = 0;
28
29 if (crypto_has_cipher("aes-padlock", 0, 0))
30 success++;
31
32 if (crypto_has_hash("sha1-padlock", 0, 0))
33 success++;
34
35 if (crypto_has_hash("sha256-padlock", 0, 0))
36 success++;
37
38 if (!success) {
39 printk(KERN_WARNING PFX "No VIA PadLock drivers have been loaded.\n");
40 return -ENODEV;
41 }
42
43 printk(KERN_NOTICE PFX "%d drivers are available.\n", success);
44
45 return 0;
46}
47
48static void __exit padlock_fini(void)
49{
50}
51
52module_init(padlock_init);
53module_exit(padlock_fini);
54
55MODULE_DESCRIPTION("Load all configured PadLock algorithms.");
56MODULE_LICENSE("GPL");
57MODULE_AUTHOR("Michal Ludvig");
58
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 11935f66fcd8..434a61b415a3 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -2,9 +2,7 @@
2# I2C subsystem configuration 2# I2C subsystem configuration
3# 3#
4 4
5menu "I2C support" 5menuconfig I2C
6
7config I2C
8 tristate "I2C support" 6 tristate "I2C support"
9 ---help--- 7 ---help---
10 I2C (pronounce: I-square-C) is a slow serial bus protocol used in 8 I2C (pronounce: I-square-C) is a slow serial bus protocol used in
@@ -22,9 +20,14 @@ config I2C
22 This I2C support can also be built as a module. If so, the module 20 This I2C support can also be built as a module. If so, the module
23 will be called i2c-core. 21 will be called i2c-core.
24 22
23if I2C
24
25config I2C_BOARDINFO
26 boolean
27 default y
28
25config I2C_CHARDEV 29config I2C_CHARDEV
26 tristate "I2C device interface" 30 tristate "I2C device interface"
27 depends on I2C
28 help 31 help
29 Say Y here to use i2c-* device files, usually found in the /dev 32 Say Y here to use i2c-* device files, usually found in the /dev
30 directory on your system. They make it possible to have user-space 33 directory on your system. They make it possible to have user-space
@@ -40,7 +43,6 @@ source drivers/i2c/chips/Kconfig
40 43
41config I2C_DEBUG_CORE 44config I2C_DEBUG_CORE
42 bool "I2C Core debugging messages" 45 bool "I2C Core debugging messages"
43 depends on I2C
44 help 46 help
45 Say Y here if you want the I2C core to produce a bunch of debug 47 Say Y here if you want the I2C core to produce a bunch of debug
46 messages to the system log. Select this if you are having a 48 messages to the system log. Select this if you are having a
@@ -48,7 +50,6 @@ config I2C_DEBUG_CORE
48 50
49config I2C_DEBUG_ALGO 51config I2C_DEBUG_ALGO
50 bool "I2C Algorithm debugging messages" 52 bool "I2C Algorithm debugging messages"
51 depends on I2C
52 help 53 help
53 Say Y here if you want the I2C algorithm drivers to produce a bunch 54 Say Y here if you want the I2C algorithm drivers to produce a bunch
54 of debug messages to the system log. Select this if you are having 55 of debug messages to the system log. Select this if you are having
@@ -57,7 +58,6 @@ config I2C_DEBUG_ALGO
57 58
58config I2C_DEBUG_BUS 59config I2C_DEBUG_BUS
59 bool "I2C Bus debugging messages" 60 bool "I2C Bus debugging messages"
60 depends on I2C
61 help 61 help
62 Say Y here if you want the I2C bus drivers to produce a bunch of 62 Say Y here if you want the I2C bus drivers to produce a bunch of
63 debug messages to the system log. Select this if you are having 63 debug messages to the system log. Select this if you are having
@@ -66,12 +66,10 @@ config I2C_DEBUG_BUS
66 66
67config I2C_DEBUG_CHIP 67config I2C_DEBUG_CHIP
68 bool "I2C Chip debugging messages" 68 bool "I2C Chip debugging messages"
69 depends on I2C
70 help 69 help
71 Say Y here if you want the I2C chip drivers to produce a bunch of 70 Say Y here if you want the I2C chip drivers to produce a bunch of
72 debug messages to the system log. Select this if you are having 71 debug messages to the system log. Select this if you are having
73 a problem with I2C support and want to see more of what is going 72 a problem with I2C support and want to see more of what is going
74 on. 73 on.
75 74
76endmenu 75endif # I2C
77
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 71c5a854ac5d..ba26e6cbe74e 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -2,6 +2,7 @@
2# Makefile for the i2c core. 2# Makefile for the i2c core.
3# 3#
4 4
5obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
5obj-$(CONFIG_I2C) += i2c-core.o 6obj-$(CONFIG_I2C) += i2c-core.o
6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 7obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
7obj-y += busses/ chips/ algos/ 8obj-y += busses/ chips/ algos/
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index af0203409dd1..58899078810b 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -3,11 +3,9 @@
3# 3#
4 4
5menu "I2C Algorithms" 5menu "I2C Algorithms"
6 depends on I2C
7 6
8config I2C_ALGOBIT 7config I2C_ALGOBIT
9 tristate "I2C bit-banging interfaces" 8 tristate "I2C bit-banging interfaces"
10 depends on I2C
11 help 9 help
12 This allows you to use a range of I2C adapters called bit-banging 10 This allows you to use a range of I2C adapters called bit-banging
13 adapters. Say Y if you own an I2C adapter belonging to this class 11 adapters. Say Y if you own an I2C adapter belonging to this class
@@ -18,7 +16,6 @@ config I2C_ALGOBIT
18 16
19config I2C_ALGOPCF 17config I2C_ALGOPCF
20 tristate "I2C PCF 8584 interfaces" 18 tristate "I2C PCF 8584 interfaces"
21 depends on I2C
22 help 19 help
23 This allows you to use a range of I2C adapters called PCF adapters. 20 This allows you to use a range of I2C adapters called PCF adapters.
24 Say Y if you own an I2C adapter belonging to this class and then say 21 Say Y if you own an I2C adapter belonging to this class and then say
@@ -29,7 +26,6 @@ config I2C_ALGOPCF
29 26
30config I2C_ALGOPCA 27config I2C_ALGOPCA
31 tristate "I2C PCA 9564 interfaces" 28 tristate "I2C PCA 9564 interfaces"
32 depends on I2C
33 help 29 help
34 This allows you to use a range of I2C adapters called PCA adapters. 30 This allows you to use a range of I2C adapters called PCA adapters.
35 Say Y if you own an I2C adapter belonging to this class and then say 31 Say Y if you own an I2C adapter belonging to this class and then say
@@ -40,11 +36,11 @@ config I2C_ALGOPCA
40 36
41config I2C_ALGO8XX 37config I2C_ALGO8XX
42 tristate "MPC8xx CPM I2C interface" 38 tristate "MPC8xx CPM I2C interface"
43 depends on 8xx && I2C 39 depends on 8xx
44 40
45config I2C_ALGO_SGI 41config I2C_ALGO_SGI
46 tristate "I2C SGI interfaces" 42 tristate "I2C SGI interfaces"
47 depends on I2C && (SGI_IP22 || SGI_IP32 || X86_VISWS) 43 depends on SGI_IP22 || SGI_IP32 || X86_VISWS
48 help 44 help
49 Supports the SGI interfaces like the ones found on SGI Indy VINO 45 Supports the SGI interfaces like the ones found on SGI Indy VINO
50 or SGI O2 MACE. 46 or SGI O2 MACE.
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 95aa5395a5be..8a5f5825bb72 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -33,19 +33,30 @@
33 33
34 34
35/* ----- global defines ----------------------------------------------- */ 35/* ----- global defines ----------------------------------------------- */
36#define DEB(x) if (i2c_debug>=1) x;
37#define DEB2(x) if (i2c_debug>=2) x;
38#define DEBSTAT(x) if (i2c_debug>=3) x; /* print several statistical values*/
39#define DEBPROTO(x) if (i2c_debug>=9) { x; }
40 /* debug the protocol by showing transferred bits */
41 36
37#ifdef DEBUG
38#define bit_dbg(level, dev, format, args...) \
39 do { \
40 if (i2c_debug >= level) \
41 dev_dbg(dev, format, ##args); \
42 } while (0)
43#else
44#define bit_dbg(level, dev, format, args...) \
45 do {} while (0)
46#endif /* DEBUG */
42 47
43/* ----- global variables --------------------------------------------- */ 48/* ----- global variables --------------------------------------------- */
44 49
45/* module parameters:
46 */
47static int i2c_debug;
48static int bit_test; /* see if the line-setting functions work */ 50static int bit_test; /* see if the line-setting functions work */
51module_param(bit_test, bool, 0);
52MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
53
54#ifdef DEBUG
55static int i2c_debug = 1;
56module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
57MODULE_PARM_DESC(i2c_debug,
58 "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose");
59#endif
49 60
50/* --- setting states on the bus with the right timing: --------------- */ 61/* --- setting states on the bus with the right timing: --------------- */
51 62
@@ -57,19 +68,19 @@ static int bit_test; /* see if the line-setting functions work */
57static inline void sdalo(struct i2c_algo_bit_data *adap) 68static inline void sdalo(struct i2c_algo_bit_data *adap)
58{ 69{
59 setsda(adap,0); 70 setsda(adap,0);
60 udelay(adap->udelay); 71 udelay((adap->udelay + 1) / 2);
61} 72}
62 73
63static inline void sdahi(struct i2c_algo_bit_data *adap) 74static inline void sdahi(struct i2c_algo_bit_data *adap)
64{ 75{
65 setsda(adap,1); 76 setsda(adap,1);
66 udelay(adap->udelay); 77 udelay((adap->udelay + 1) / 2);
67} 78}
68 79
69static inline void scllo(struct i2c_algo_bit_data *adap) 80static inline void scllo(struct i2c_algo_bit_data *adap)
70{ 81{
71 setscl(adap,0); 82 setscl(adap,0);
72 udelay(adap->udelay); 83 udelay(adap->udelay / 2);
73} 84}
74 85
75/* 86/*
@@ -98,7 +109,11 @@ static int sclhi(struct i2c_algo_bit_data *adap)
98 } 109 }
99 cond_resched(); 110 cond_resched();
100 } 111 }
101 DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); 112#ifdef DEBUG
113 if (jiffies != start && i2c_debug >= 3)
114 pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go "
115 "high\n", jiffies - start);
116#endif
102 117
103done: 118done:
104 udelay(adap->udelay); 119 udelay(adap->udelay);
@@ -110,30 +125,29 @@ done:
110static void i2c_start(struct i2c_algo_bit_data *adap) 125static void i2c_start(struct i2c_algo_bit_data *adap)
111{ 126{
112 /* assert: scl, sda are high */ 127 /* assert: scl, sda are high */
113 DEBPROTO(printk("S ")); 128 setsda(adap, 0);
114 sdalo(adap); 129 udelay(adap->udelay);
115 scllo(adap); 130 scllo(adap);
116} 131}
117 132
118static void i2c_repstart(struct i2c_algo_bit_data *adap) 133static void i2c_repstart(struct i2c_algo_bit_data *adap)
119{ 134{
120 /* scl, sda may not be high */ 135 /* assert: scl is low */
121 DEBPROTO(printk(" Sr ")); 136 sdahi(adap);
122 setsda(adap,1);
123 sclhi(adap); 137 sclhi(adap);
124 138 setsda(adap, 0);
125 sdalo(adap); 139 udelay(adap->udelay);
126 scllo(adap); 140 scllo(adap);
127} 141}
128 142
129 143
130static void i2c_stop(struct i2c_algo_bit_data *adap) 144static void i2c_stop(struct i2c_algo_bit_data *adap)
131{ 145{
132 DEBPROTO(printk("P\n"));
133 /* assert: scl is low */ 146 /* assert: scl is low */
134 sdalo(adap); 147 sdalo(adap);
135 sclhi(adap); 148 sclhi(adap);
136 sdahi(adap); 149 setsda(adap, 1);
150 udelay(adap->udelay);
137} 151}
138 152
139 153
@@ -145,7 +159,7 @@ static void i2c_stop(struct i2c_algo_bit_data *adap)
145 * 0 if the device did not ack 159 * 0 if the device did not ack
146 * -ETIMEDOUT if an error occurred (while raising the scl line) 160 * -ETIMEDOUT if an error occurred (while raising the scl line)
147 */ 161 */
148static int i2c_outb(struct i2c_adapter *i2c_adap, char c) 162static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c)
149{ 163{
150 int i; 164 int i;
151 int sb; 165 int sb;
@@ -154,34 +168,32 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, char c)
154 168
155 /* assert: scl is low */ 169 /* assert: scl is low */
156 for ( i=7 ; i>=0 ; i-- ) { 170 for ( i=7 ; i>=0 ; i-- ) {
157 sb = c & ( 1 << i ); 171 sb = (c >> i) & 1;
158 setsda(adap,sb); 172 setsda(adap,sb);
159 udelay(adap->udelay); 173 udelay((adap->udelay + 1) / 2);
160 DEBPROTO(printk(KERN_DEBUG "%d",sb!=0));
161 if (sclhi(adap)<0) { /* timed out */ 174 if (sclhi(adap)<0) { /* timed out */
162 sdahi(adap); /* we don't want to block the net */ 175 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
163 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i)); 176 "timeout at bit #%d\n", (int)c, i);
164 return -ETIMEDOUT; 177 return -ETIMEDOUT;
165 }; 178 };
166 /* do arbitration here: 179 /* do arbitration here:
167 * if ( sb && ! getsda(adap) ) -> ouch! Get out of here. 180 * if ( sb && ! getsda(adap) ) -> ouch! Get out of here.
168 */ 181 */
169 setscl(adap, 0 ); 182 scllo(adap);
170 udelay(adap->udelay);
171 } 183 }
172 sdahi(adap); 184 sdahi(adap);
173 if (sclhi(adap)<0){ /* timeout */ 185 if (sclhi(adap)<0){ /* timeout */
174 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff)); 186 bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
175 return -ETIMEDOUT; 187 "timeout at ack\n", (int)c);
188 return -ETIMEDOUT;
176 }; 189 };
177 /* read ack: SDA should be pulled down by slave */ 190 /* read ack: SDA should be pulled down by slave */
178 ack=getsda(adap); /* ack: sda is pulled low ->success. */ 191 ack = !getsda(adap); /* ack: sda is pulled low -> success */
179 DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack)); 192 bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
193 ack ? "A" : "NA");
180 194
181 DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) );
182 DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );
183 scllo(adap); 195 scllo(adap);
184 return 0==ack; /* return 1 if device acked */ 196 return ack;
185 /* assert: scl is low (sda undef) */ 197 /* assert: scl is low (sda undef) */
186} 198}
187 199
@@ -198,19 +210,18 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
198 sdahi(adap); 210 sdahi(adap);
199 for (i=0;i<8;i++) { 211 for (i=0;i<8;i++) {
200 if (sclhi(adap)<0) { /* timeout */ 212 if (sclhi(adap)<0) { /* timeout */
201 DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i)); 213 bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit "
214 "#%d\n", 7 - i);
202 return -ETIMEDOUT; 215 return -ETIMEDOUT;
203 }; 216 };
204 indata *= 2; 217 indata *= 2;
205 if ( getsda(adap) ) 218 if ( getsda(adap) )
206 indata |= 0x01; 219 indata |= 0x01;
207 scllo(adap); 220 setscl(adap, 0);
221 udelay(i == 7 ? adap->udelay / 2 : adap->udelay);
208 } 222 }
209 /* assert: scl is low */ 223 /* assert: scl is low */
210 DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff)); 224 return indata;
211
212 DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff));
213 return (int) (indata & 0xff);
214} 225}
215 226
216/* 227/*
@@ -221,73 +232,67 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) {
221 int scl,sda; 232 int scl,sda;
222 233
223 if (adap->getscl==NULL) 234 if (adap->getscl==NULL)
224 printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, " 235 pr_info("%s: Testing SDA only, SCL is not readable\n", name);
225 "SCL is not readable.\n");
226 236
227 sda=getsda(adap); 237 sda=getsda(adap);
228 scl=(adap->getscl==NULL?1:getscl(adap)); 238 scl=(adap->getscl==NULL?1:getscl(adap));
229 printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda);
230 if (!scl || !sda ) { 239 if (!scl || !sda ) {
231 printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name); 240 printk(KERN_WARNING "%s: bus seems to be busy\n", name);
232 goto bailout; 241 goto bailout;
233 } 242 }
234 243
235 sdalo(adap); 244 sdalo(adap);
236 sda=getsda(adap); 245 sda=getsda(adap);
237 scl=(adap->getscl==NULL?1:getscl(adap)); 246 scl=(adap->getscl==NULL?1:getscl(adap));
238 printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda);
239 if ( 0 != sda ) { 247 if ( 0 != sda ) {
240 printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n"); 248 printk(KERN_WARNING "%s: SDA stuck high!\n", name);
241 goto bailout; 249 goto bailout;
242 } 250 }
243 if ( 0 == scl ) { 251 if ( 0 == scl ) {
244 printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " 252 printk(KERN_WARNING "%s: SCL unexpected low "
245 "while pulling SDA low!\n"); 253 "while pulling SDA low!\n", name);
246 goto bailout; 254 goto bailout;
247 } 255 }
248 256
249 sdahi(adap); 257 sdahi(adap);
250 sda=getsda(adap); 258 sda=getsda(adap);
251 scl=(adap->getscl==NULL?1:getscl(adap)); 259 scl=(adap->getscl==NULL?1:getscl(adap));
252 printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda);
253 if ( 0 == sda ) { 260 if ( 0 == sda ) {
254 printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n"); 261 printk(KERN_WARNING "%s: SDA stuck low!\n", name);
255 goto bailout; 262 goto bailout;
256 } 263 }
257 if ( 0 == scl ) { 264 if ( 0 == scl ) {
258 printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " 265 printk(KERN_WARNING "%s: SCL unexpected low "
259 "while pulling SDA high!\n"); 266 "while pulling SDA high!\n", name);
260 goto bailout; 267 goto bailout;
261 } 268 }
262 269
263 scllo(adap); 270 scllo(adap);
264 sda=getsda(adap); 271 sda=getsda(adap);
265 scl=(adap->getscl==NULL?0:getscl(adap)); 272 scl=(adap->getscl==NULL?0:getscl(adap));
266 printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda);
267 if ( 0 != scl ) { 273 if ( 0 != scl ) {
268 printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n"); 274 printk(KERN_WARNING "%s: SCL stuck high!\n", name);
269 goto bailout; 275 goto bailout;
270 } 276 }
271 if ( 0 == sda ) { 277 if ( 0 == sda ) {
272 printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " 278 printk(KERN_WARNING "%s: SDA unexpected low "
273 "while pulling SCL low!\n"); 279 "while pulling SCL low!\n", name);
274 goto bailout; 280 goto bailout;
275 } 281 }
276 282
277 sclhi(adap); 283 sclhi(adap);
278 sda=getsda(adap); 284 sda=getsda(adap);
279 scl=(adap->getscl==NULL?1:getscl(adap)); 285 scl=(adap->getscl==NULL?1:getscl(adap));
280 printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda);
281 if ( 0 == scl ) { 286 if ( 0 == scl ) {
282 printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n"); 287 printk(KERN_WARNING "%s: SCL stuck low!\n", name);
283 goto bailout; 288 goto bailout;
284 } 289 }
285 if ( 0 == sda ) { 290 if ( 0 == sda ) {
286 printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " 291 printk(KERN_WARNING "%s: SDA unexpected low "
287 "while pulling SCL high!\n"); 292 "while pulling SCL high!\n", name);
288 goto bailout; 293 goto bailout;
289 } 294 }
290 printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name); 295 pr_info("%s: Test OK\n", name);
291 return 0; 296 return 0;
292bailout: 297bailout:
293 sdahi(adap); 298 sdahi(adap);
@@ -312,44 +317,39 @@ static int try_address(struct i2c_adapter *i2c_adap,
312 int i,ret = -1; 317 int i,ret = -1;
313 for (i=0;i<=retries;i++) { 318 for (i=0;i<=retries;i++) {
314 ret = i2c_outb(i2c_adap,addr); 319 ret = i2c_outb(i2c_adap,addr);
315 if (ret==1) 320 if (ret == 1 || i == retries)
316 break; /* success! */
317 i2c_stop(adap);
318 udelay(5/*adap->udelay*/);
319 if (i==retries) /* no success */
320 break; 321 break;
321 i2c_start(adap); 322 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
323 i2c_stop(adap);
322 udelay(adap->udelay); 324 udelay(adap->udelay);
325 yield();
326 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
327 i2c_start(adap);
323 } 328 }
324 DEB2(if (i) 329 if (i && ret)
325 printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n", 330 bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at "
326 i+1, addr & 1 ? "read" : "write", addr>>1, 331 "0x%02x: %s\n", i + 1,
327 ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" ) 332 addr & 1 ? "read from" : "write to", addr >> 1,
328 ); 333 ret == 1 ? "success" : "failed, timeout?");
329 return ret; 334 return ret;
330} 335}
331 336
332static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) 337static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
333{ 338{
334 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 339 const unsigned char *temp = msg->buf;
335 char c;
336 const char *temp = msg->buf;
337 int count = msg->len; 340 int count = msg->len;
338 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; 341 unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK;
339 int retval; 342 int retval;
340 int wrcount=0; 343 int wrcount=0;
341 344
342 while (count > 0) { 345 while (count > 0) {
343 c = *temp; 346 retval = i2c_outb(i2c_adap, *temp);
344 DEB2(dev_dbg(&i2c_adap->dev, "sendbytes: writing %2.2X\n", c&0xff));
345 retval = i2c_outb(i2c_adap,c);
346 if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ 347 if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */
347 count--; 348 count--;
348 temp++; 349 temp++;
349 wrcount++; 350 wrcount++;
350 } else { /* arbitration or no acknowledge */ 351 } else { /* arbitration or no acknowledge */
351 dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n"); 352 dev_err(&i2c_adap->dev, "sendbytes: error - bailout.\n");
352 i2c_stop(adap);
353 return (retval<0)? retval : -EFAULT; 353 return (retval<0)? retval : -EFAULT;
354 /* got a better one ?? */ 354 /* got a better one ?? */
355 } 355 }
@@ -362,7 +362,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
362 int inval; 362 int inval;
363 int rdcount=0; /* counts bytes read */ 363 int rdcount=0; /* counts bytes read */
364 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 364 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
365 char *temp = msg->buf; 365 unsigned char *temp = msg->buf;
366 int count = msg->len; 366 int count = msg->len;
367 367
368 while (count > 0) { 368 while (count > 0) {
@@ -371,30 +371,44 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
371 *temp = inval; 371 *temp = inval;
372 rdcount++; 372 rdcount++;
373 } else { /* read timed out */ 373 } else { /* read timed out */
374 printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n");
375 break; 374 break;
376 } 375 }
377 376
378 temp++; 377 temp++;
379 count--; 378 count--;
380 379
381 if (msg->flags & I2C_M_NO_RD_ACK) 380 if (msg->flags & I2C_M_NO_RD_ACK) {
381 bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x\n",
382 inval);
382 continue; 383 continue;
383
384 if ( count > 0 ) { /* send ack */
385 sdalo(adap);
386 DEBPROTO(printk(" Am "));
387 } else {
388 sdahi(adap); /* neg. ack on last byte */
389 DEBPROTO(printk(" NAm "));
390 } 384 }
385
386 /* assert: sda is high */
387 if (count) /* send ack */
388 setsda(adap, 0);
389 udelay((adap->udelay + 1) / 2);
390 bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x %s\n", inval,
391 count ? "A" : "NA");
391 if (sclhi(adap)<0) { /* timeout */ 392 if (sclhi(adap)<0) { /* timeout */
392 sdahi(adap); 393 dev_err(&i2c_adap->dev, "readbytes: timeout at ack\n");
393 printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n");
394 return -ETIMEDOUT; 394 return -ETIMEDOUT;
395 }; 395 };
396 scllo(adap); 396 scllo(adap);
397 sdahi(adap); 397
398 /* Some SMBus transactions require that we receive the
399 transaction length as the first read byte. */
400 if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) {
401 if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
402 dev_err(&i2c_adap->dev, "readbytes: invalid "
403 "block length (%d)\n", inval);
404 return -EREMOTEIO;
405 }
406 /* The original count value accounts for the extra
407 bytes, that is, either 1 for a regular transaction,
408 or 2 for a PEC transaction. */
409 count += inval;
410 msg->len += inval;
411 }
398 } 412 }
399 return rdcount; 413 return rdcount;
400} 414}
@@ -421,27 +435,31 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
421 if ( (flags & I2C_M_TEN) ) { 435 if ( (flags & I2C_M_TEN) ) {
422 /* a ten bit address */ 436 /* a ten bit address */
423 addr = 0xf0 | (( msg->addr >> 7) & 0x03); 437 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
424 DEB2(printk(KERN_DEBUG "addr0: %d\n",addr)); 438 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
425 /* try extended address code...*/ 439 /* try extended address code...*/
426 ret = try_address(i2c_adap, addr, retries); 440 ret = try_address(i2c_adap, addr, retries);
427 if ((ret != 1) && !nak_ok) { 441 if ((ret != 1) && !nak_ok) {
428 printk(KERN_ERR "died at extended address code.\n"); 442 dev_err(&i2c_adap->dev,
443 "died at extended address code\n");
429 return -EREMOTEIO; 444 return -EREMOTEIO;
430 } 445 }
431 /* the remaining 8 bit address */ 446 /* the remaining 8 bit address */
432 ret = i2c_outb(i2c_adap,msg->addr & 0x7f); 447 ret = i2c_outb(i2c_adap,msg->addr & 0x7f);
433 if ((ret != 1) && !nak_ok) { 448 if ((ret != 1) && !nak_ok) {
434 /* the chip did not ack / xmission error occurred */ 449 /* the chip did not ack / xmission error occurred */
435 printk(KERN_ERR "died at 2nd address code.\n"); 450 dev_err(&i2c_adap->dev, "died at 2nd address code\n");
436 return -EREMOTEIO; 451 return -EREMOTEIO;
437 } 452 }
438 if ( flags & I2C_M_RD ) { 453 if ( flags & I2C_M_RD ) {
454 bit_dbg(3, &i2c_adap->dev, "emitting repeated "
455 "start condition\n");
439 i2c_repstart(adap); 456 i2c_repstart(adap);
440 /* okay, now switch into reading mode */ 457 /* okay, now switch into reading mode */
441 addr |= 0x01; 458 addr |= 0x01;
442 ret = try_address(i2c_adap, addr, retries); 459 ret = try_address(i2c_adap, addr, retries);
443 if ((ret!=1) && !nak_ok) { 460 if ((ret!=1) && !nak_ok) {
444 printk(KERN_ERR "died at extended address code.\n"); 461 dev_err(&i2c_adap->dev,
462 "died at repeated address code\n");
445 return -EREMOTEIO; 463 return -EREMOTEIO;
446 } 464 }
447 } 465 }
@@ -468,44 +486,62 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
468 int i,ret; 486 int i,ret;
469 unsigned short nak_ok; 487 unsigned short nak_ok;
470 488
489 bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
471 i2c_start(adap); 490 i2c_start(adap);
472 for (i=0;i<num;i++) { 491 for (i=0;i<num;i++) {
473 pmsg = &msgs[i]; 492 pmsg = &msgs[i];
474 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; 493 nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
475 if (!(pmsg->flags & I2C_M_NOSTART)) { 494 if (!(pmsg->flags & I2C_M_NOSTART)) {
476 if (i) { 495 if (i) {
496 bit_dbg(3, &i2c_adap->dev, "emitting "
497 "repeated start condition\n");
477 i2c_repstart(adap); 498 i2c_repstart(adap);
478 } 499 }
479 ret = bit_doAddress(i2c_adap, pmsg); 500 ret = bit_doAddress(i2c_adap, pmsg);
480 if ((ret != 0) && !nak_ok) { 501 if ((ret != 0) && !nak_ok) {
481 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n" 502 bit_dbg(1, &i2c_adap->dev, "NAK from "
482 ,msgs[i].addr,i)); 503 "device addr 0x%02x msg #%d\n",
483 return (ret<0) ? ret : -EREMOTEIO; 504 msgs[i].addr, i);
505 goto bailout;
484 } 506 }
485 } 507 }
486 if (pmsg->flags & I2C_M_RD ) { 508 if (pmsg->flags & I2C_M_RD ) {
487 /* read bytes into buffer*/ 509 /* read bytes into buffer*/
488 ret = readbytes(i2c_adap, pmsg); 510 ret = readbytes(i2c_adap, pmsg);
489 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret)); 511 if (ret >= 1)
490 if (ret < pmsg->len ) { 512 bit_dbg(2, &i2c_adap->dev, "read %d byte%s\n",
491 return (ret<0)? ret : -EREMOTEIO; 513 ret, ret == 1 ? "" : "s");
514 if (ret < pmsg->len) {
515 if (ret >= 0)
516 ret = -EREMOTEIO;
517 goto bailout;
492 } 518 }
493 } else { 519 } else {
494 /* write bytes from buffer */ 520 /* write bytes from buffer */
495 ret = sendbytes(i2c_adap, pmsg); 521 ret = sendbytes(i2c_adap, pmsg);
496 DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret)); 522 if (ret >= 1)
497 if (ret < pmsg->len ) { 523 bit_dbg(2, &i2c_adap->dev, "wrote %d byte%s\n",
498 return (ret<0) ? ret : -EREMOTEIO; 524 ret, ret == 1 ? "" : "s");
525 if (ret < pmsg->len) {
526 if (ret >= 0)
527 ret = -EREMOTEIO;
528 goto bailout;
499 } 529 }
500 } 530 }
501 } 531 }
532 ret = i;
533
534bailout:
535 bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
502 i2c_stop(adap); 536 i2c_stop(adap);
503 return num; 537 return ret;
504} 538}
505 539
506static u32 bit_func(struct i2c_adapter *adap) 540static u32 bit_func(struct i2c_adapter *adap)
507{ 541{
508 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 542 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
543 I2C_FUNC_SMBUS_READ_BLOCK_DATA |
544 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
509 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; 545 I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
510} 546}
511 547
@@ -520,7 +556,7 @@ static const struct i2c_algorithm i2c_bit_algo = {
520/* 556/*
521 * registering functions to load algorithms at runtime 557 * registering functions to load algorithms at runtime
522 */ 558 */
523int i2c_bit_add_bus(struct i2c_adapter *adap) 559static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
524{ 560{
525 struct i2c_algo_bit_data *bit_adap = adap->algo_data; 561 struct i2c_algo_bit_data *bit_adap = adap->algo_data;
526 562
@@ -530,25 +566,39 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
530 return -ENODEV; 566 return -ENODEV;
531 } 567 }
532 568
533 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
534
535 /* register new adapter to i2c module... */ 569 /* register new adapter to i2c module... */
536 adap->algo = &i2c_bit_algo; 570 adap->algo = &i2c_bit_algo;
537 571
538 adap->timeout = 100; /* default values, should */ 572 adap->timeout = 100; /* default values, should */
539 adap->retries = 3; /* be replaced by defines */ 573 adap->retries = 3; /* be replaced by defines */
540 574
575 return 0;
576}
577
578int i2c_bit_add_bus(struct i2c_adapter *adap)
579{
580 int err;
581
582 err = i2c_bit_prepare_bus(adap);
583 if (err)
584 return err;
585
541 return i2c_add_adapter(adap); 586 return i2c_add_adapter(adap);
542} 587}
543EXPORT_SYMBOL(i2c_bit_add_bus); 588EXPORT_SYMBOL(i2c_bit_add_bus);
544 589
590int i2c_bit_add_numbered_bus(struct i2c_adapter *adap)
591{
592 int err;
593
594 err = i2c_bit_prepare_bus(adap);
595 if (err)
596 return err;
597
598 return i2c_add_numbered_adapter(adap);
599}
600EXPORT_SYMBOL(i2c_bit_add_numbered_bus);
601
545MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 602MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
546MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); 603MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
547MODULE_LICENSE("GPL"); 604MODULE_LICENSE("GPL");
548
549module_param(bit_test, bool, 0);
550module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
551
552MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
553MODULE_PARM_DESC(i2c_debug,
554 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol");
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index ac2d5053078a..6eaf145e1ada 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * i2c-algo-sgi.c: i2c driver algorithms for SGI adapters. 2 * i2c-algo-sgi.c: i2c driver algorithm used by the VINO (SGI Indy) and
3 * 3 * MACE (SGI O2) chips.
4 *
4 * This file is subject to the terms and conditions of the GNU General Public 5 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation. 6 * License version 2 as published by the Free Software Foundation.
6 * 7 *
@@ -162,8 +163,8 @@ static const struct i2c_algorithm sgi_algo = {
162 .functionality = sgi_func, 163 .functionality = sgi_func,
163}; 164};
164 165
165/* 166/*
166 * registering functions to load algorithms at runtime 167 * registering functions to load algorithms at runtime
167 */ 168 */
168int i2c_sgi_add_bus(struct i2c_adapter *adap) 169int i2c_sgi_add_bus(struct i2c_adapter *adap)
169{ 170{
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ece31d2c6c64..838dc1c19d61 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5menu "I2C Hardware Bus support" 5menu "I2C Hardware Bus support"
6 depends on I2C
7 6
8config I2C_ALI1535 7config I2C_ALI1535
9 tristate "ALI 1535" 8 tristate "ALI 1535"
10 depends on I2C && PCI 9 depends on PCI
11 help 10 help
12 If you say yes to this option, support will be included for the SMB 11 If you say yes to this option, support will be included for the SMB
13 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB 12 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB
@@ -19,7 +18,7 @@ config I2C_ALI1535
19 18
20config I2C_ALI1563 19config I2C_ALI1563
21 tristate "ALI 1563" 20 tristate "ALI 1563"
22 depends on I2C && PCI && EXPERIMENTAL 21 depends on PCI && EXPERIMENTAL
23 help 22 help
24 If you say yes to this option, support will be included for the SMB 23 If you say yes to this option, support will be included for the SMB
25 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB 24 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB
@@ -31,7 +30,7 @@ config I2C_ALI1563
31 30
32config I2C_ALI15X3 31config I2C_ALI15X3
33 tristate "ALI 15x3" 32 tristate "ALI 15x3"
34 depends on I2C && PCI 33 depends on PCI
35 help 34 help
36 If you say yes to this option, support will be included for the 35 If you say yes to this option, support will be included for the
37 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. 36 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces.
@@ -41,7 +40,7 @@ config I2C_ALI15X3
41 40
42config I2C_AMD756 41config I2C_AMD756
43 tristate "AMD 756/766/768/8111 and nVidia nForce" 42 tristate "AMD 756/766/768/8111 and nVidia nForce"
44 depends on I2C && PCI 43 depends on PCI
45 help 44 help
46 If you say yes to this option, support will be included for the AMD 45 If you say yes to this option, support will be included for the AMD
47 756/766/768 mainboard I2C interfaces. The driver also includes 46 756/766/768 mainboard I2C interfaces. The driver also includes
@@ -66,7 +65,7 @@ config I2C_AMD756_S4882
66 65
67config I2C_AMD8111 66config I2C_AMD8111
68 tristate "AMD 8111" 67 tristate "AMD 8111"
69 depends on I2C && PCI 68 depends on PCI
70 help 69 help
71 If you say yes to this option, support will be included for the 70 If you say yes to this option, support will be included for the
72 second (SMBus 2.0) AMD 8111 mainboard I2C interface. 71 second (SMBus 2.0) AMD 8111 mainboard I2C interface.
@@ -76,14 +75,14 @@ config I2C_AMD8111
76 75
77config I2C_AT91 76config I2C_AT91
78 tristate "Atmel AT91 I2C Two-Wire interface (TWI)" 77 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
79 depends on I2C && ARCH_AT91 && EXPERIMENTAL 78 depends on ARCH_AT91 && EXPERIMENTAL
80 help 79 help
81 This supports the use of the I2C interface on Atmel AT91 80 This supports the use of the I2C interface on Atmel AT91
82 processors. 81 processors.
83 82
84config I2C_AU1550 83config I2C_AU1550
85 tristate "Au1550/Au1200 SMBus interface" 84 tristate "Au1550/Au1200 SMBus interface"
86 depends on I2C && (SOC_AU1550 || SOC_AU1200) 85 depends on SOC_AU1550 || SOC_AU1200
87 help 86 help
88 If you say yes to this option, support will be included for the 87 If you say yes to this option, support will be included for the
89 Au1550 and Au1200 SMBus interface. 88 Au1550 and Au1200 SMBus interface.
@@ -91,9 +90,25 @@ config I2C_AU1550
91 This driver can also be built as a module. If so, the module 90 This driver can also be built as a module. If so, the module
92 will be called i2c-au1550. 91 will be called i2c-au1550.
93 92
93config I2C_BLACKFIN_TWI
94 tristate "Blackfin TWI I2C support"
95 depends on BF534 || BF536 || BF537
96 help
97 This is the TWI I2C device driver for Blackfin 534/536/537.
98 This driver can also be built as a module. If so, the module
99 will be called i2c-bfin-twi.
100
101config I2C_BLACKFIN_TWI_CLK_KHZ
102 int "Blackfin TWI I2C clock (kHz)"
103 depends on I2C_BLACKFIN_TWI
104 range 10 400
105 default 50
106 help
107 The unit of the TWI clock is kHz.
108
94config I2C_ELEKTOR 109config I2C_ELEKTOR
95 tristate "Elektor ISA card" 110 tristate "Elektor ISA card"
96 depends on I2C && ISA && BROKEN_ON_SMP 111 depends on ISA && BROKEN_ON_SMP
97 select I2C_ALGOPCF 112 select I2C_ALGOPCF
98 help 113 help
99 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own 114 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
@@ -102,9 +117,17 @@ config I2C_ELEKTOR
102 This support is also available as a module. If so, the module 117 This support is also available as a module. If so, the module
103 will be called i2c-elektor. 118 will be called i2c-elektor.
104 119
120config I2C_GPIO
121 tristate "GPIO-based bitbanging I2C"
122 depends on GENERIC_GPIO
123 select I2C_ALGOBIT
124 help
125 This is a very simple bitbanging I2C driver utilizing the
126 arch-neutral GPIO API to control the SCL and SDA lines.
127
105config I2C_HYDRA 128config I2C_HYDRA
106 tristate "CHRP Apple Hydra Mac I/O I2C interface" 129 tristate "CHRP Apple Hydra Mac I/O I2C interface"
107 depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL 130 depends on PCI && PPC_CHRP && EXPERIMENTAL
108 select I2C_ALGOBIT 131 select I2C_ALGOBIT
109 help 132 help
110 This supports the use of the I2C interface in the Apple Hydra Mac 133 This supports the use of the I2C interface in the Apple Hydra Mac
@@ -116,7 +139,7 @@ config I2C_HYDRA
116 139
117config I2C_I801 140config I2C_I801
118 tristate "Intel 82801 (ICH)" 141 tristate "Intel 82801 (ICH)"
119 depends on I2C && PCI 142 depends on PCI
120 help 143 help
121 If you say yes to this option, support will be included for the Intel 144 If you say yes to this option, support will be included for the Intel
122 801 family of mainboard I2C interfaces. Specifically, the following 145 801 family of mainboard I2C interfaces. Specifically, the following
@@ -139,7 +162,7 @@ config I2C_I801
139 162
140config I2C_I810 163config I2C_I810
141 tristate "Intel 810/815" 164 tristate "Intel 810/815"
142 depends on I2C && PCI 165 depends on PCI
143 select I2C_ALGOBIT 166 select I2C_ALGOBIT
144 help 167 help
145 If you say yes to this option, support will be included for the Intel 168 If you say yes to this option, support will be included for the Intel
@@ -156,7 +179,7 @@ config I2C_I810
156 179
157config I2C_PXA 180config I2C_PXA
158 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" 181 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)"
159 depends on I2C && EXPERIMENTAL && ARCH_PXA 182 depends on EXPERIMENTAL && ARCH_PXA
160 help 183 help
161 If you have devices in the PXA I2C bus, say yes to this option. 184 If you have devices in the PXA I2C bus, say yes to this option.
162 This driver can also be built as a module. If so, the module 185 This driver can also be built as a module. If so, the module
@@ -172,7 +195,7 @@ config I2C_PXA_SLAVE
172 195
173config I2C_PIIX4 196config I2C_PIIX4
174 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" 197 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)"
175 depends on I2C && PCI 198 depends on PCI
176 help 199 help
177 If you say yes to this option, support will be included for the Intel 200 If you say yes to this option, support will be included for the Intel
178 PIIX4 family of mainboard I2C interfaces. Specifically, the following 201 PIIX4 family of mainboard I2C interfaces. Specifically, the following
@@ -195,7 +218,7 @@ config I2C_PIIX4
195 218
196config I2C_IBM_IIC 219config I2C_IBM_IIC
197 tristate "IBM PPC 4xx on-chip I2C interface" 220 tristate "IBM PPC 4xx on-chip I2C interface"
198 depends on IBM_OCP && I2C 221 depends on IBM_OCP
199 help 222 help
200 Say Y here if you want to use IIC peripheral found on 223 Say Y here if you want to use IIC peripheral found on
201 embedded IBM PPC 4xx based systems. 224 embedded IBM PPC 4xx based systems.
@@ -205,7 +228,7 @@ config I2C_IBM_IIC
205 228
206config I2C_IOP3XX 229config I2C_IOP3XX
207 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" 230 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface"
208 depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C 231 depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX
209 help 232 help
210 Say Y here if you want to use the IIC bus controller on 233 Say Y here if you want to use the IIC bus controller on
211 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. 234 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors.
@@ -215,11 +238,10 @@ config I2C_IOP3XX
215 238
216config I2C_ISA 239config I2C_ISA
217 tristate 240 tristate
218 depends on I2C
219 241
220config I2C_IXP4XX 242config I2C_IXP4XX
221 tristate "IXP4xx GPIO-Based I2C Interface" 243 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)"
222 depends on I2C && ARCH_IXP4XX 244 depends on ARCH_IXP4XX
223 select I2C_ALGOBIT 245 select I2C_ALGOBIT
224 help 246 help
225 Say Y here if you have an Intel IXP4xx(420,421,422,425) based 247 Say Y here if you have an Intel IXP4xx(420,421,422,425) based
@@ -228,9 +250,12 @@ config I2C_IXP4XX
228 This support is also available as a module. If so, the module 250 This support is also available as a module. If so, the module
229 will be called i2c-ixp4xx. 251 will be called i2c-ixp4xx.
230 252
253 This driver is deprecated and will be dropped soon. Use i2c-gpio
254 instead.
255
231config I2C_IXP2000 256config I2C_IXP2000
232 tristate "IXP2000 GPIO-Based I2C Interface" 257 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)"
233 depends on I2C && ARCH_IXP2000 258 depends on ARCH_IXP2000
234 select I2C_ALGOBIT 259 select I2C_ALGOBIT
235 help 260 help
236 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based 261 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based
@@ -239,9 +264,12 @@ config I2C_IXP2000
239 This support is also available as a module. If so, the module 264 This support is also available as a module. If so, the module
240 will be called i2c-ixp2000. 265 will be called i2c-ixp2000.
241 266
267 This driver is deprecated and will be dropped soon. Use i2c-gpio
268 instead.
269
242config I2C_POWERMAC 270config I2C_POWERMAC
243 tristate "Powermac I2C interface" 271 tristate "Powermac I2C interface"
244 depends on I2C && PPC_PMAC 272 depends on PPC_PMAC
245 default y 273 default y
246 help 274 help
247 This exposes the various PowerMac i2c interfaces to the linux i2c 275 This exposes the various PowerMac i2c interfaces to the linux i2c
@@ -253,7 +281,7 @@ config I2C_POWERMAC
253 281
254config I2C_MPC 282config I2C_MPC
255 tristate "MPC107/824x/85xx/52xx/86xx" 283 tristate "MPC107/824x/85xx/52xx/86xx"
256 depends on I2C && PPC32 284 depends on PPC32
257 help 285 help
258 If you say yes to this option, support will be included for the 286 If you say yes to this option, support will be included for the
259 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and 287 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and
@@ -265,7 +293,7 @@ config I2C_MPC
265 293
266config I2C_NFORCE2 294config I2C_NFORCE2
267 tristate "Nvidia nForce2, nForce3 and nForce4" 295 tristate "Nvidia nForce2, nForce3 and nForce4"
268 depends on I2C && PCI 296 depends on PCI
269 help 297 help
270 If you say yes to this option, support will be included for the Nvidia 298 If you say yes to this option, support will be included for the Nvidia
271 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. 299 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces.
@@ -275,7 +303,7 @@ config I2C_NFORCE2
275 303
276config I2C_OCORES 304config I2C_OCORES
277 tristate "OpenCores I2C Controller" 305 tristate "OpenCores I2C Controller"
278 depends on I2C && EXPERIMENTAL 306 depends on EXPERIMENTAL
279 help 307 help
280 If you say yes to this option, support will be included for the 308 If you say yes to this option, support will be included for the
281 OpenCores I2C controller. For details see 309 OpenCores I2C controller. For details see
@@ -286,7 +314,7 @@ config I2C_OCORES
286 314
287config I2C_OMAP 315config I2C_OMAP
288 tristate "OMAP I2C adapter" 316 tristate "OMAP I2C adapter"
289 depends on I2C && ARCH_OMAP 317 depends on ARCH_OMAP
290 default y if MACH_OMAP_H3 || MACH_OMAP_OSK 318 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
291 help 319 help
292 If you say yes to this option, support will be included for the 320 If you say yes to this option, support will be included for the
@@ -296,7 +324,7 @@ config I2C_OMAP
296 324
297config I2C_PARPORT 325config I2C_PARPORT
298 tristate "Parallel port adapter" 326 tristate "Parallel port adapter"
299 depends on I2C && PARPORT 327 depends on PARPORT
300 select I2C_ALGOBIT 328 select I2C_ALGOBIT
301 help 329 help
302 This supports parallel port I2C adapters such as the ones made by 330 This supports parallel port I2C adapters such as the ones made by
@@ -320,7 +348,6 @@ config I2C_PARPORT
320 348
321config I2C_PARPORT_LIGHT 349config I2C_PARPORT_LIGHT
322 tristate "Parallel port adapter (light)" 350 tristate "Parallel port adapter (light)"
323 depends on I2C
324 select I2C_ALGOBIT 351 select I2C_ALGOBIT
325 help 352 help
326 This supports parallel port I2C adapters such as the ones made by 353 This supports parallel port I2C adapters such as the ones made by
@@ -344,13 +371,13 @@ config I2C_PARPORT_LIGHT
344 371
345config I2C_PASEMI 372config I2C_PASEMI
346 tristate "PA Semi SMBus interface" 373 tristate "PA Semi SMBus interface"
347 depends on PPC_PASEMI && I2C && PCI 374 depends on PPC_PASEMI && PCI
348 help 375 help
349 Supports the PA Semi PWRficient on-chip SMBus interfaces. 376 Supports the PA Semi PWRficient on-chip SMBus interfaces.
350 377
351config I2C_PROSAVAGE 378config I2C_PROSAVAGE
352 tristate "S3/VIA (Pro)Savage" 379 tristate "S3/VIA (Pro)Savage"
353 depends on I2C && PCI 380 depends on PCI
354 select I2C_ALGOBIT 381 select I2C_ALGOBIT
355 help 382 help
356 If you say yes to this option, support will be included for the 383 If you say yes to this option, support will be included for the
@@ -365,19 +392,19 @@ config I2C_PROSAVAGE
365 392
366config I2C_RPXLITE 393config I2C_RPXLITE
367 tristate "Embedded Planet RPX Lite/Classic support" 394 tristate "Embedded Planet RPX Lite/Classic support"
368 depends on (RPXLITE || RPXCLASSIC) && I2C 395 depends on RPXLITE || RPXCLASSIC
369 select I2C_ALGO8XX 396 select I2C_ALGO8XX
370 397
371config I2C_S3C2410 398config I2C_S3C2410
372 tristate "S3C2410 I2C Driver" 399 tristate "S3C2410 I2C Driver"
373 depends on I2C && ARCH_S3C2410 400 depends on ARCH_S3C2410
374 help 401 help
375 Say Y here to include support for I2C controller in the 402 Say Y here to include support for I2C controller in the
376 Samsung S3C2410 based System-on-Chip devices. 403 Samsung S3C2410 based System-on-Chip devices.
377 404
378config I2C_SAVAGE4 405config I2C_SAVAGE4
379 tristate "S3 Savage 4" 406 tristate "S3 Savage 4"
380 depends on I2C && PCI && EXPERIMENTAL 407 depends on PCI && EXPERIMENTAL
381 select I2C_ALGOBIT 408 select I2C_ALGOBIT
382 help 409 help
383 If you say yes to this option, support will be included for the 410 If you say yes to this option, support will be included for the
@@ -388,13 +415,25 @@ config I2C_SAVAGE4
388 415
389config I2C_SIBYTE 416config I2C_SIBYTE
390 tristate "SiByte SMBus interface" 417 tristate "SiByte SMBus interface"
391 depends on SIBYTE_SB1xxx_SOC && I2C 418 depends on SIBYTE_SB1xxx_SOC
392 help 419 help
393 Supports the SiByte SOC on-chip I2C interfaces (2 channels). 420 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
394 421
422config I2C_SIMTEC
423 tristate "Simtec Generic I2C interface"
424 select I2C_ALGOBIT
425 help
426 If you say yes to this option, support will be inclyded for
427 the Simtec Generic I2C interface. This driver is for the
428 simple I2C bus used on newer Simtec products for general
429 I2C, such as DDC on the Simtec BBD2016A.
430
431 This driver can also be build as a module. If so, the module
432 will be called i2c-simtec.
433
395config SCx200_I2C 434config SCx200_I2C
396 tristate "NatSemi SCx200 I2C using GPIO pins" 435 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)"
397 depends on SCx200_GPIO && I2C 436 depends on SCx200_GPIO
398 select I2C_ALGOBIT 437 select I2C_ALGOBIT
399 help 438 help
400 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. 439 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus.
@@ -404,6 +443,9 @@ config SCx200_I2C
404 This support is also available as a module. If so, the module 443 This support is also available as a module. If so, the module
405 will be called scx200_i2c. 444 will be called scx200_i2c.
406 445
446 This driver is deprecated and will be dropped soon. Use i2c-gpio
447 (or scx200_acb) instead.
448
407config SCx200_I2C_SCL 449config SCx200_I2C_SCL
408 int "GPIO pin used for SCL" 450 int "GPIO pin used for SCL"
409 depends on SCx200_I2C 451 depends on SCx200_I2C
@@ -422,7 +464,7 @@ config SCx200_I2C_SDA
422 464
423config SCx200_ACB 465config SCx200_ACB
424 tristate "Geode ACCESS.bus support" 466 tristate "Geode ACCESS.bus support"
425 depends on X86_32 && I2C && PCI 467 depends on X86_32 && PCI
426 help 468 help
427 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and 469 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
428 SC1100 processors and the CS5535 and CS5536 Geode companion devices. 470 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
@@ -434,7 +476,7 @@ config SCx200_ACB
434 476
435config I2C_SIS5595 477config I2C_SIS5595
436 tristate "SiS 5595" 478 tristate "SiS 5595"
437 depends on I2C && PCI 479 depends on PCI
438 help 480 help
439 If you say yes to this option, support will be included for the 481 If you say yes to this option, support will be included for the
440 SiS5595 SMBus (a subset of I2C) interface. 482 SiS5595 SMBus (a subset of I2C) interface.
@@ -444,7 +486,7 @@ config I2C_SIS5595
444 486
445config I2C_SIS630 487config I2C_SIS630
446 tristate "SiS 630/730" 488 tristate "SiS 630/730"
447 depends on I2C && PCI 489 depends on PCI
448 help 490 help
449 If you say yes to this option, support will be included for the 491 If you say yes to this option, support will be included for the
450 SiS630 and SiS730 SMBus (a subset of I2C) interface. 492 SiS630 and SiS730 SMBus (a subset of I2C) interface.
@@ -454,7 +496,7 @@ config I2C_SIS630
454 496
455config I2C_SIS96X 497config I2C_SIS96X
456 tristate "SiS 96x" 498 tristate "SiS 96x"
457 depends on I2C && PCI 499 depends on PCI
458 help 500 help
459 If you say yes to this option, support will be included for the SiS 501 If you say yes to this option, support will be included for the SiS
460 96x SMBus (a subset of I2C) interfaces. Specifically, the following 502 96x SMBus (a subset of I2C) interfaces. Specifically, the following
@@ -472,7 +514,7 @@ config I2C_SIS96X
472 514
473config I2C_STUB 515config I2C_STUB
474 tristate "I2C/SMBus Test Stub" 516 tristate "I2C/SMBus Test Stub"
475 depends on I2C && EXPERIMENTAL && 'm' 517 depends on EXPERIMENTAL && m
476 default 'n' 518 default 'n'
477 help 519 help
478 This module may be useful to developers of SMBus client drivers, 520 This module may be useful to developers of SMBus client drivers,
@@ -483,9 +525,20 @@ config I2C_STUB
483 525
484 If you don't know what to do here, definitely say N. 526 If you don't know what to do here, definitely say N.
485 527
528config I2C_TINY_USB
529 tristate "I2C-Tiny-USB"
530 depends on USB
531 help
532 If you say yes to this option, support will be included for the
533 i2c-tiny-usb, a simple do-it-yourself USB to I2C interface. See
534 http://www.harbaum.org/till/i2c_tiny_usb for hardware details.
535
536 This driver can also be built as a module. If so, the module
537 will be called i2c-tiny-usb.
538
486config I2C_VERSATILE 539config I2C_VERSATILE
487 tristate "ARM Versatile/Realview I2C bus support" 540 tristate "ARM Versatile/Realview I2C bus support"
488 depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW) 541 depends on ARCH_VERSATILE || ARCH_REALVIEW
489 select I2C_ALGOBIT 542 select I2C_ALGOBIT
490 help 543 help
491 Say yes if you want to support the I2C serial bus on ARMs Versatile 544 Say yes if you want to support the I2C serial bus on ARMs Versatile
@@ -496,7 +549,7 @@ config I2C_VERSATILE
496 549
497config I2C_ACORN 550config I2C_ACORN
498 bool "Acorn IOC/IOMD I2C bus support" 551 bool "Acorn IOC/IOMD I2C bus support"
499 depends on I2C && ARCH_ACORN 552 depends on ARCH_ACORN
500 default y 553 default y
501 select I2C_ALGOBIT 554 select I2C_ALGOBIT
502 help 555 help
@@ -506,7 +559,7 @@ config I2C_ACORN
506 559
507config I2C_VIA 560config I2C_VIA
508 tristate "VIA 82C586B" 561 tristate "VIA 82C586B"
509 depends on I2C && PCI && EXPERIMENTAL 562 depends on PCI && EXPERIMENTAL
510 select I2C_ALGOBIT 563 select I2C_ALGOBIT
511 help 564 help
512 If you say yes to this option, support will be included for the VIA 565 If you say yes to this option, support will be included for the VIA
@@ -517,7 +570,7 @@ config I2C_VIA
517 570
518config I2C_VIAPRO 571config I2C_VIAPRO
519 tristate "VIA VT82C596/82C686/82xx and CX700" 572 tristate "VIA VT82C596/82C686/82xx and CX700"
520 depends on I2C && PCI 573 depends on PCI
521 help 574 help
522 If you say yes to this option, support will be included for the VIA 575 If you say yes to this option, support will be included for the VIA
523 VT82C596 and later SMBus interface. Specifically, the following 576 VT82C596 and later SMBus interface. Specifically, the following
@@ -536,7 +589,7 @@ config I2C_VIAPRO
536 589
537config I2C_VOODOO3 590config I2C_VOODOO3
538 tristate "Voodoo 3" 591 tristate "Voodoo 3"
539 depends on I2C && PCI 592 depends on PCI
540 select I2C_ALGOBIT 593 select I2C_ALGOBIT
541 help 594 help
542 If you say yes to this option, support will be included for the 595 If you say yes to this option, support will be included for the
@@ -547,7 +600,7 @@ config I2C_VOODOO3
547 600
548config I2C_PCA_ISA 601config I2C_PCA_ISA
549 tristate "PCA9564 on an ISA bus" 602 tristate "PCA9564 on an ISA bus"
550 depends on I2C 603 depends on ISA
551 select I2C_ALGOPCA 604 select I2C_ALGOPCA
552 default n 605 default n
553 help 606 help
@@ -564,7 +617,7 @@ config I2C_PCA_ISA
564 617
565config I2C_MV64XXX 618config I2C_MV64XXX
566 tristate "Marvell mv64xxx I2C Controller" 619 tristate "Marvell mv64xxx I2C Controller"
567 depends on I2C && MV64X60 && EXPERIMENTAL 620 depends on MV64X60 && EXPERIMENTAL
568 help 621 help
569 If you say yes to this option, support will be included for the 622 If you say yes to this option, support will be included for the
570 built-in I2C interface on the Marvell 64xxx line of host bridges. 623 built-in I2C interface on the Marvell 64xxx line of host bridges.
@@ -574,7 +627,7 @@ config I2C_MV64XXX
574 627
575config I2C_PNX 628config I2C_PNX
576 tristate "I2C bus support for Philips PNX targets" 629 tristate "I2C bus support for Philips PNX targets"
577 depends on ARCH_PNX4008 && I2C 630 depends on ARCH_PNX4008
578 help 631 help
579 This driver supports the Philips IP3204 I2C IP block master and/or 632 This driver supports the Philips IP3204 I2C IP block master and/or
580 slave controller 633 slave controller
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 290b54018354..14d1432f698b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -10,7 +10,9 @@ obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o
10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
11obj-$(CONFIG_I2C_AT91) += i2c-at91.o 11obj-$(CONFIG_I2C_AT91) += i2c-at91.o
12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
13obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
13obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 14obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
15obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
14obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o 16obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
15obj-$(CONFIG_I2C_I801) += i2c-i801.o 17obj-$(CONFIG_I2C_I801) += i2c-i801.o
16obj-$(CONFIG_I2C_I810) += i2c-i810.o 18obj-$(CONFIG_I2C_I810) += i2c-i810.o
@@ -37,10 +39,12 @@ obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
37obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
38obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o 40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
39obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 41obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
42obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
40obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o 43obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
41obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 44obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
42obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 45obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
43obj-$(CONFIG_I2C_STUB) += i2c-stub.o 46obj-$(CONFIG_I2C_STUB) += i2c-stub.o
47obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
44obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 48obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
45obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 49obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
46obj-$(CONFIG_I2C_VIA) += i2c-via.o 50obj-$(CONFIG_I2C_VIA) += i2c-via.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 1e277ba5a9f3..f14372ac2fc5 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
497 /* set up the sysfs linkage to our parent device */ 497 /* set up the sysfs linkage to our parent device */
498 ali1535_adapter.dev.parent = &dev->dev; 498 ali1535_adapter.dev.parent = &dev->dev;
499 499
500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE, 500 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
501 "SMBus ALI1535 adapter at %04x", ali1535_smba); 501 "SMBus ALI1535 adapter at %04x", ali1535_smba);
502 return i2c_add_adapter(&ali1535_adapter); 502 return i2c_add_adapter(&ali1535_adapter);
503} 503}
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index e47fe01bf42a..93bf87d70961 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
492 /* set up the sysfs linkage to our parent device */ 492 /* set up the sysfs linkage to our parent device */
493 ali15x3_adapter.dev.parent = &dev->dev; 493 ali15x3_adapter.dev.parent = &dev->dev;
494 494
495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, 495 snprintf(ali15x3_adapter.name, sizeof(ali15x3_adapter.name),
496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba); 496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba);
497 return i2c_add_adapter(&ali15x3_adapter); 497 return i2c_add_adapter(&ali15x3_adapter);
498} 498}
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 0c70f8293341..c9fca7b49267 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -365,7 +365,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
365 } 365 }
366 366
367 smbus->adapter.owner = THIS_MODULE; 367 smbus->adapter.owner = THIS_MODULE;
368 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 368 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
369 "SMBus2 AMD8111 adapter at %04x", smbus->base); 369 "SMBus2 AMD8111 adapter at %04x", smbus->base);
370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111; 370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111;
371 smbus->adapter.class = I2C_CLASS_HWMON; 371 smbus->adapter.class = I2C_CLASS_HWMON;
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
new file mode 100644
index 000000000000..6311039dfe60
--- /dev/null
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -0,0 +1,644 @@
1/*
2 * drivers/i2c/busses/i2c-bfin-twi.c
3 *
4 * Description: Driver for Blackfin Two Wire Interface
5 *
6 * Author: sonicz <sonic.zhang@analog.com>
7 *
8 * Copyright (c) 2005-2007 Analog Devices, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/i2c.h>
29#include <linux/mm.h>
30#include <linux/timer.h>
31#include <linux/spinlock.h>
32#include <linux/completion.h>
33#include <linux/interrupt.h>
34#include <linux/platform_device.h>
35
36#include <asm/blackfin.h>
37#include <asm/irq.h>
38
39#define POLL_TIMEOUT (2 * HZ)
40
41/* SMBus mode*/
42#define TWI_I2C_MODE_STANDARD 0x01
43#define TWI_I2C_MODE_STANDARDSUB 0x02
44#define TWI_I2C_MODE_COMBINED 0x04
45
46struct bfin_twi_iface {
47 struct mutex twi_lock;
48 int irq;
49 spinlock_t lock;
50 char read_write;
51 u8 command;
52 u8 *transPtr;
53 int readNum;
54 int writeNum;
55 int cur_mode;
56 int manual_stop;
57 int result;
58 int timeout_count;
59 struct timer_list timeout_timer;
60 struct i2c_adapter adap;
61 struct completion complete;
62};
63
64static struct bfin_twi_iface twi_iface;
65
66static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
67{
68 unsigned short twi_int_status = bfin_read_TWI_INT_STAT();
69 unsigned short mast_stat = bfin_read_TWI_MASTER_STAT();
70
71 if (twi_int_status & XMTSERV) {
72 /* Transmit next data */
73 if (iface->writeNum > 0) {
74 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
75 iface->writeNum--;
76 }
77 /* start receive immediately after complete sending in
78 * combine mode.
79 */
80 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
81 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
82 | MDIR | RSTART);
83 } else if (iface->manual_stop)
84 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
85 | STOP);
86 SSYNC();
87 /* Clear status */
88 bfin_write_TWI_INT_STAT(XMTSERV);
89 SSYNC();
90 }
91 if (twi_int_status & RCVSERV) {
92 if (iface->readNum > 0) {
93 /* Receive next data */
94 *(iface->transPtr) = bfin_read_TWI_RCV_DATA8();
95 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
96 /* Change combine mode into sub mode after
97 * read first data.
98 */
99 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
100 /* Get read number from first byte in block
101 * combine mode.
102 */
103 if (iface->readNum == 1 && iface->manual_stop)
104 iface->readNum = *iface->transPtr + 1;
105 }
106 iface->transPtr++;
107 iface->readNum--;
108 } else if (iface->manual_stop) {
109 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
110 | STOP);
111 SSYNC();
112 }
113 /* Clear interrupt source */
114 bfin_write_TWI_INT_STAT(RCVSERV);
115 SSYNC();
116 }
117 if (twi_int_status & MERR) {
118 bfin_write_TWI_INT_STAT(MERR);
119 bfin_write_TWI_INT_MASK(0);
120 bfin_write_TWI_MASTER_STAT(0x3e);
121 bfin_write_TWI_MASTER_CTL(0);
122 SSYNC();
123 iface->result = -1;
124 /* if both err and complete int stats are set, return proper
125 * results.
126 */
127 if (twi_int_status & MCOMP) {
128 bfin_write_TWI_INT_STAT(MCOMP);
129 bfin_write_TWI_INT_MASK(0);
130 bfin_write_TWI_MASTER_CTL(0);
131 SSYNC();
132 /* If it is a quick transfer, only address bug no data,
133 * not an err, return 1.
134 */
135 if (iface->writeNum == 0 && (mast_stat & BUFRDERR))
136 iface->result = 1;
137 /* If address not acknowledged return -1,
138 * else return 0.
139 */
140 else if (!(mast_stat & ANAK))
141 iface->result = 0;
142 }
143 complete(&iface->complete);
144 return;
145 }
146 if (twi_int_status & MCOMP) {
147 bfin_write_TWI_INT_STAT(MCOMP);
148 SSYNC();
149 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
150 if (iface->readNum == 0) {
151 /* set the read number to 1 and ask for manual
152 * stop in block combine mode
153 */
154 iface->readNum = 1;
155 iface->manual_stop = 1;
156 bfin_write_TWI_MASTER_CTL(
157 bfin_read_TWI_MASTER_CTL()
158 | (0xff << 6));
159 } else {
160 /* set the readd number in other
161 * combine mode.
162 */
163 bfin_write_TWI_MASTER_CTL(
164 (bfin_read_TWI_MASTER_CTL() &
165 (~(0xff << 6))) |
166 ( iface->readNum << 6));
167 }
168 /* remove restart bit and enable master receive */
169 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() &
170 ~RSTART);
171 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() |
172 MEN | MDIR);
173 SSYNC();
174 } else {
175 iface->result = 1;
176 bfin_write_TWI_INT_MASK(0);
177 bfin_write_TWI_MASTER_CTL(0);
178 SSYNC();
179 complete(&iface->complete);
180 }
181 }
182}
183
184/* Interrupt handler */
185static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
186{
187 struct bfin_twi_iface *iface = dev_id;
188 unsigned long flags;
189
190 spin_lock_irqsave(&iface->lock, flags);
191 del_timer(&iface->timeout_timer);
192 bfin_twi_handle_interrupt(iface);
193 spin_unlock_irqrestore(&iface->lock, flags);
194 return IRQ_HANDLED;
195}
196
197static void bfin_twi_timeout(unsigned long data)
198{
199 struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data;
200 unsigned long flags;
201
202 spin_lock_irqsave(&iface->lock, flags);
203 bfin_twi_handle_interrupt(iface);
204 if (iface->result == 0) {
205 iface->timeout_count--;
206 if (iface->timeout_count > 0) {
207 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
208 add_timer(&iface->timeout_timer);
209 } else {
210 iface->result = -1;
211 complete(&iface->complete);
212 }
213 }
214 spin_unlock_irqrestore(&iface->lock, flags);
215}
216
217/*
218 * Generic i2c master transfer entrypoint
219 */
220static int bfin_twi_master_xfer(struct i2c_adapter *adap,
221 struct i2c_msg *msgs, int num)
222{
223 struct bfin_twi_iface *iface = adap->algo_data;
224 struct i2c_msg *pmsg;
225 int i, ret;
226 int rc = 0;
227
228 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
229 return -ENXIO;
230
231 mutex_lock(&iface->twi_lock);
232
233 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
234 mutex_unlock(&iface->twi_lock);
235 yield();
236 mutex_lock(&iface->twi_lock);
237 }
238
239 ret = 0;
240 for (i = 0; rc >= 0 && i < num; i++) {
241 pmsg = &msgs[i];
242 if (pmsg->flags & I2C_M_TEN) {
243 dev_err(&(adap->dev), "i2c-bfin-twi: 10 bits addr "
244 "not supported !\n");
245 rc = -EINVAL;
246 break;
247 }
248
249 iface->cur_mode = TWI_I2C_MODE_STANDARD;
250 iface->manual_stop = 0;
251 iface->transPtr = pmsg->buf;
252 iface->writeNum = iface->readNum = pmsg->len;
253 iface->result = 0;
254 iface->timeout_count = 10;
255 /* Set Transmit device address */
256 bfin_write_TWI_MASTER_ADDR(pmsg->addr);
257
258 /* FIFO Initiation. Data in FIFO should be
259 * discarded before start a new operation.
260 */
261 bfin_write_TWI_FIFO_CTL(0x3);
262 SSYNC();
263 bfin_write_TWI_FIFO_CTL(0);
264 SSYNC();
265
266 if (pmsg->flags & I2C_M_RD)
267 iface->read_write = I2C_SMBUS_READ;
268 else {
269 iface->read_write = I2C_SMBUS_WRITE;
270 /* Transmit first data */
271 if (iface->writeNum > 0) {
272 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
273 iface->writeNum--;
274 SSYNC();
275 }
276 }
277
278 /* clear int stat */
279 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
280
281 /* Interrupt mask . Enable XMT, RCV interrupt */
282 bfin_write_TWI_INT_MASK(MCOMP | MERR |
283 ((iface->read_write == I2C_SMBUS_READ)?
284 RCVSERV : XMTSERV));
285 SSYNC();
286
287 if (pmsg->len > 0 && pmsg->len <= 255)
288 bfin_write_TWI_MASTER_CTL(pmsg->len << 6);
289 else if (pmsg->len > 255) {
290 bfin_write_TWI_MASTER_CTL(0xff << 6);
291 iface->manual_stop = 1;
292 } else
293 break;
294
295 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
296 add_timer(&iface->timeout_timer);
297
298 /* Master enable */
299 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
300 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
301 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
302 SSYNC();
303
304 wait_for_completion(&iface->complete);
305
306 rc = iface->result;
307 if (rc == 1)
308 ret++;
309 else if (rc == -1)
310 break;
311 }
312
313 /* Release mutex */
314 mutex_unlock(&iface->twi_lock);
315
316 return ret;
317}
318
319/*
320 * SMBus type transfer entrypoint
321 */
322
323int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
324 unsigned short flags, char read_write,
325 u8 command, int size, union i2c_smbus_data *data)
326{
327 struct bfin_twi_iface *iface = adap->algo_data;
328 int rc = 0;
329
330 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
331 return -ENXIO;
332
333 mutex_lock(&iface->twi_lock);
334
335 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
336 mutex_unlock(&iface->twi_lock);
337 yield();
338 mutex_lock(&iface->twi_lock);
339 }
340
341 iface->writeNum = 0;
342 iface->readNum = 0;
343
344 /* Prepare datas & select mode */
345 switch (size) {
346 case I2C_SMBUS_QUICK:
347 iface->transPtr = NULL;
348 iface->cur_mode = TWI_I2C_MODE_STANDARD;
349 break;
350 case I2C_SMBUS_BYTE:
351 if (data == NULL)
352 iface->transPtr = NULL;
353 else {
354 if (read_write == I2C_SMBUS_READ)
355 iface->readNum = 1;
356 else
357 iface->writeNum = 1;
358 iface->transPtr = &data->byte;
359 }
360 iface->cur_mode = TWI_I2C_MODE_STANDARD;
361 break;
362 case I2C_SMBUS_BYTE_DATA:
363 if (read_write == I2C_SMBUS_READ) {
364 iface->readNum = 1;
365 iface->cur_mode = TWI_I2C_MODE_COMBINED;
366 } else {
367 iface->writeNum = 1;
368 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
369 }
370 iface->transPtr = &data->byte;
371 break;
372 case I2C_SMBUS_WORD_DATA:
373 if (read_write == I2C_SMBUS_READ) {
374 iface->readNum = 2;
375 iface->cur_mode = TWI_I2C_MODE_COMBINED;
376 } else {
377 iface->writeNum = 2;
378 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
379 }
380 iface->transPtr = (u8 *)&data->word;
381 break;
382 case I2C_SMBUS_PROC_CALL:
383 iface->writeNum = 2;
384 iface->readNum = 2;
385 iface->cur_mode = TWI_I2C_MODE_COMBINED;
386 iface->transPtr = (u8 *)&data->word;
387 break;
388 case I2C_SMBUS_BLOCK_DATA:
389 if (read_write == I2C_SMBUS_READ) {
390 iface->readNum = 0;
391 iface->cur_mode = TWI_I2C_MODE_COMBINED;
392 } else {
393 iface->writeNum = data->block[0] + 1;
394 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
395 }
396 iface->transPtr = data->block;
397 break;
398 default:
399 return -1;
400 }
401
402 iface->result = 0;
403 iface->manual_stop = 0;
404 iface->read_write = read_write;
405 iface->command = command;
406 iface->timeout_count = 10;
407
408 /* FIFO Initiation. Data in FIFO should be discarded before
409 * start a new operation.
410 */
411 bfin_write_TWI_FIFO_CTL(0x3);
412 SSYNC();
413 bfin_write_TWI_FIFO_CTL(0);
414
415 /* clear int stat */
416 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
417
418 /* Set Transmit device address */
419 bfin_write_TWI_MASTER_ADDR(addr);
420 SSYNC();
421
422 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
423 add_timer(&iface->timeout_timer);
424
425 switch (iface->cur_mode) {
426 case TWI_I2C_MODE_STANDARDSUB:
427 bfin_write_TWI_XMT_DATA8(iface->command);
428 bfin_write_TWI_INT_MASK(MCOMP | MERR |
429 ((iface->read_write == I2C_SMBUS_READ) ?
430 RCVSERV : XMTSERV));
431 SSYNC();
432
433 if (iface->writeNum + 1 <= 255)
434 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
435 else {
436 bfin_write_TWI_MASTER_CTL(0xff << 6);
437 iface->manual_stop = 1;
438 }
439 /* Master enable */
440 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
441 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
442 break;
443 case TWI_I2C_MODE_COMBINED:
444 bfin_write_TWI_XMT_DATA8(iface->command);
445 bfin_write_TWI_INT_MASK(MCOMP | MERR | RCVSERV | XMTSERV);
446 SSYNC();
447
448 if (iface->writeNum > 0)
449 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
450 else
451 bfin_write_TWI_MASTER_CTL(0x1 << 6);
452 /* Master enable */
453 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
454 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
455 break;
456 default:
457 bfin_write_TWI_MASTER_CTL(0);
458 if (size != I2C_SMBUS_QUICK) {
459 /* Don't access xmit data register when this is a
460 * read operation.
461 */
462 if (iface->read_write != I2C_SMBUS_READ) {
463 if (iface->writeNum > 0) {
464 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
465 if (iface->writeNum <= 255)
466 bfin_write_TWI_MASTER_CTL(iface->writeNum << 6);
467 else {
468 bfin_write_TWI_MASTER_CTL(0xff << 6);
469 iface->manual_stop = 1;
470 }
471 iface->writeNum--;
472 } else {
473 bfin_write_TWI_XMT_DATA8(iface->command);
474 bfin_write_TWI_MASTER_CTL(1 << 6);
475 }
476 } else {
477 if (iface->readNum > 0 && iface->readNum <= 255)
478 bfin_write_TWI_MASTER_CTL(iface->readNum << 6);
479 else if (iface->readNum > 255) {
480 bfin_write_TWI_MASTER_CTL(0xff << 6);
481 iface->manual_stop = 1;
482 } else {
483 del_timer(&iface->timeout_timer);
484 break;
485 }
486 }
487 }
488 bfin_write_TWI_INT_MASK(MCOMP | MERR |
489 ((iface->read_write == I2C_SMBUS_READ) ?
490 RCVSERV : XMTSERV));
491 SSYNC();
492
493 /* Master enable */
494 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
495 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
496 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
497 break;
498 }
499 SSYNC();
500
501 wait_for_completion(&iface->complete);
502
503 rc = (iface->result >= 0) ? 0 : -1;
504
505 /* Release mutex */
506 mutex_unlock(&iface->twi_lock);
507
508 return rc;
509}
510
511/*
512 * Return what the adapter supports
513 */
514static u32 bfin_twi_functionality(struct i2c_adapter *adap)
515{
516 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
517 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
518 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |
519 I2C_FUNC_I2C;
520}
521
522
523static struct i2c_algorithm bfin_twi_algorithm = {
524 .master_xfer = bfin_twi_master_xfer,
525 .smbus_xfer = bfin_twi_smbus_xfer,
526 .functionality = bfin_twi_functionality,
527};
528
529
530static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
531{
532/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
533
534 /* Disable TWI */
535 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() & ~TWI_ENA);
536 SSYNC();
537
538 return 0;
539}
540
541static int i2c_bfin_twi_resume(struct platform_device *dev)
542{
543/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
544
545 /* Enable TWI */
546 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
547 SSYNC();
548
549 return 0;
550}
551
552static int i2c_bfin_twi_probe(struct platform_device *dev)
553{
554 struct bfin_twi_iface *iface = &twi_iface;
555 struct i2c_adapter *p_adap;
556 int rc;
557
558 mutex_init(&(iface->twi_lock));
559 spin_lock_init(&(iface->lock));
560 init_completion(&(iface->complete));
561 iface->irq = IRQ_TWI;
562
563 init_timer(&(iface->timeout_timer));
564 iface->timeout_timer.function = bfin_twi_timeout;
565 iface->timeout_timer.data = (unsigned long)iface;
566
567 p_adap = &iface->adap;
568 p_adap->id = I2C_HW_BLACKFIN;
569 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name));
570 p_adap->algo = &bfin_twi_algorithm;
571 p_adap->algo_data = iface;
572 p_adap->class = I2C_CLASS_ALL;
573 p_adap->dev.parent = &dev->dev;
574
575 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
576 IRQF_DISABLED, dev->name, iface);
577 if (rc) {
578 dev_err(&(p_adap->dev), "i2c-bfin-twi: can't get IRQ %d !\n",
579 iface->irq);
580 return -ENODEV;
581 }
582
583 /* Set TWI internal clock as 10MHz */
584 bfin_write_TWI_CONTROL(((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
585
586 /* Set Twi interface clock as specified */
587 bfin_write_TWI_CLKDIV((( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
588 << 8) | (( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
589 & 0xFF));
590
591 /* Enable TWI */
592 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
593 SSYNC();
594
595 rc = i2c_add_adapter(p_adap);
596 if (rc < 0)
597 free_irq(iface->irq, iface);
598 else
599 platform_set_drvdata(dev, iface);
600
601 return rc;
602}
603
604static int i2c_bfin_twi_remove(struct platform_device *pdev)
605{
606 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
607
608 platform_set_drvdata(pdev, NULL);
609
610 i2c_del_adapter(&(iface->adap));
611 free_irq(iface->irq, iface);
612
613 return 0;
614}
615
616static struct platform_driver i2c_bfin_twi_driver = {
617 .probe = i2c_bfin_twi_probe,
618 .remove = i2c_bfin_twi_remove,
619 .suspend = i2c_bfin_twi_suspend,
620 .resume = i2c_bfin_twi_resume,
621 .driver = {
622 .name = "i2c-bfin-twi",
623 .owner = THIS_MODULE,
624 },
625};
626
627static int __init i2c_bfin_twi_init(void)
628{
629 pr_info("I2C: Blackfin I2C TWI driver\n");
630
631 return platform_driver_register(&i2c_bfin_twi_driver);
632}
633
634static void __exit i2c_bfin_twi_exit(void)
635{
636 platform_driver_unregister(&i2c_bfin_twi_driver);
637}
638
639MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
640MODULE_DESCRIPTION("I2C-Bus adapter routines for Blackfin TWI");
641MODULE_LICENSE("GPL");
642
643module_init(i2c_bfin_twi_init);
644module_exit(i2c_bfin_twi_exit);
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 834967464814..804f0a551c05 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -35,6 +35,7 @@
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/wait.h> 36#include <linux/wait.h>
37 37
38#include <linux/isa.h>
38#include <linux/i2c.h> 39#include <linux/i2c.h>
39#include <linux/i2c-algo-pcf.h> 40#include <linux/i2c-algo-pcf.h>
40 41
@@ -207,7 +208,7 @@ static struct i2c_adapter pcf_isa_ops = {
207 .name = "i2c-elektor", 208 .name = "i2c-elektor",
208}; 209};
209 210
210static int __init i2c_pcfisa_init(void) 211static int __devinit elektor_match(struct device *dev, unsigned int id)
211{ 212{
212#ifdef __alpha__ 213#ifdef __alpha__
213 /* check to see we have memory mapped PCF8584 connected to the 214 /* check to see we have memory mapped PCF8584 connected to the
@@ -222,9 +223,8 @@ static int __init i2c_pcfisa_init(void)
222 /* yeap, we've found cypress, let's check config */ 223 /* yeap, we've found cypress, let's check config */
223 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 224 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
224 225
225 pr_debug("%s: found cy82c693, config " 226 dev_dbg(dev, "found cy82c693, config "
226 "register 0x47 = 0x%02x\n", 227 "register 0x47 = 0x%02x\n", config);
227 pcf_isa_ops.name, config);
228 228
229 /* UP2000 board has this register set to 0xe1, 229 /* UP2000 board has this register set to 0xe1,
230 but the most significant bit as seems can be 230 but the most significant bit as seems can be
@@ -244,9 +244,9 @@ static int __init i2c_pcfisa_init(void)
244 8.25 MHz (PCI/4) clock 244 8.25 MHz (PCI/4) clock
245 (this can be read from cypress) */ 245 (this can be read from cypress) */
246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90; 246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
247 pr_info("%s: found API UP2000 like " 247 dev_info(dev, "found API UP2000 like "
248 "board, will probe PCF8584 " 248 "board, will probe PCF8584 "
249 "later\n", pcf_isa_ops.name); 249 "later\n");
250 } 250 }
251 } 251 }
252 pci_dev_put(cy693_dev); 252 pci_dev_put(cy693_dev);
@@ -256,22 +256,27 @@ static int __init i2c_pcfisa_init(void)
256 256
257 /* sanity checks for mmapped I/O */ 257 /* sanity checks for mmapped I/O */
258 if (mmapped && base < 0xc8000) { 258 if (mmapped && base < 0xc8000) {
259 printk(KERN_ERR "%s: incorrect base address (%#x) specified " 259 dev_err(dev, "incorrect base address (%#x) specified "
260 "for mmapped I/O\n", pcf_isa_ops.name, base); 260 "for mmapped I/O\n", base);
261 return -ENODEV; 261 return 0;
262 } 262 }
263 263
264 if (base == 0) { 264 if (base == 0) {
265 base = DEFAULT_BASE; 265 base = DEFAULT_BASE;
266 } 266 }
267 return 1;
268}
267 269
270static int __devinit elektor_probe(struct device *dev, unsigned int id)
271{
268 init_waitqueue_head(&pcf_wait); 272 init_waitqueue_head(&pcf_wait);
269 if (pcf_isa_init()) 273 if (pcf_isa_init())
270 return -ENODEV; 274 return -ENODEV;
275 pcf_isa_ops.dev.parent = dev;
271 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) 276 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
272 goto fail; 277 goto fail;
273 278
274 dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base); 279 dev_info(dev, "found device at %#x\n", base);
275 280
276 return 0; 281 return 0;
277 282
@@ -291,7 +296,7 @@ static int __init i2c_pcfisa_init(void)
291 return -ENODEV; 296 return -ENODEV;
292} 297}
293 298
294static void i2c_pcfisa_exit(void) 299static int __devexit elektor_remove(struct device *dev, unsigned int id)
295{ 300{
296 i2c_del_adapter(&pcf_isa_ops); 301 i2c_del_adapter(&pcf_isa_ops);
297 302
@@ -307,6 +312,28 @@ static void i2c_pcfisa_exit(void)
307 iounmap(base_iomem); 312 iounmap(base_iomem);
308 release_mem_region(base, 2); 313 release_mem_region(base, 2);
309 } 314 }
315
316 return 0;
317}
318
319static struct isa_driver i2c_elektor_driver = {
320 .match = elektor_match,
321 .probe = elektor_probe,
322 .remove = __devexit_p(elektor_remove),
323 .driver = {
324 .owner = THIS_MODULE,
325 .name = "i2c-elektor",
326 },
327};
328
329static int __init i2c_pcfisa_init(void)
330{
331 return isa_register_driver(&i2c_elektor_driver, 1);
332}
333
334static void __exit i2c_pcfisa_exit(void)
335{
336 isa_unregister_driver(&i2c_elektor_driver);
310} 337}
311 338
312MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 339MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
new file mode 100644
index 000000000000..a7dd54654a9a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -0,0 +1,215 @@
1/*
2 * Bitbanging I2C bus driver using the GPIO API
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/i2c.h>
11#include <linux/i2c-algo-bit.h>
12#include <linux/i2c-gpio.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#include <asm/gpio.h>
18
19/* Toggle SDA by changing the direction of the pin */
20static void i2c_gpio_setsda_dir(void *data, int state)
21{
22 struct i2c_gpio_platform_data *pdata = data;
23
24 if (state)
25 gpio_direction_input(pdata->sda_pin);
26 else
27 gpio_direction_output(pdata->sda_pin, 0);
28}
29
30/*
31 * Toggle SDA by changing the output value of the pin. This is only
32 * valid for pins configured as open drain (i.e. setting the value
33 * high effectively turns off the output driver.)
34 */
35static void i2c_gpio_setsda_val(void *data, int state)
36{
37 struct i2c_gpio_platform_data *pdata = data;
38
39 gpio_set_value(pdata->sda_pin, state);
40}
41
42/* Toggle SCL by changing the direction of the pin. */
43static void i2c_gpio_setscl_dir(void *data, int state)
44{
45 struct i2c_gpio_platform_data *pdata = data;
46
47 if (state)
48 gpio_direction_input(pdata->scl_pin);
49 else
50 gpio_direction_output(pdata->scl_pin, 0);
51}
52
53/*
54 * Toggle SCL by changing the output value of the pin. This is used
55 * for pins that are configured as open drain and for output-only
56 * pins. The latter case will break the i2c protocol, but it will
57 * often work in practice.
58 */
59static void i2c_gpio_setscl_val(void *data, int state)
60{
61 struct i2c_gpio_platform_data *pdata = data;
62
63 gpio_set_value(pdata->scl_pin, state);
64}
65
66int i2c_gpio_getsda(void *data)
67{
68 struct i2c_gpio_platform_data *pdata = data;
69
70 return gpio_get_value(pdata->sda_pin);
71}
72
73int i2c_gpio_getscl(void *data)
74{
75 struct i2c_gpio_platform_data *pdata = data;
76
77 return gpio_get_value(pdata->scl_pin);
78}
79
80static int __init i2c_gpio_probe(struct platform_device *pdev)
81{
82 struct i2c_gpio_platform_data *pdata;
83 struct i2c_algo_bit_data *bit_data;
84 struct i2c_adapter *adap;
85 int ret;
86
87 pdata = pdev->dev.platform_data;
88 if (!pdata)
89 return -ENXIO;
90
91 ret = -ENOMEM;
92 adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
93 if (!adap)
94 goto err_alloc_adap;
95 bit_data = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL);
96 if (!bit_data)
97 goto err_alloc_bit_data;
98
99 ret = gpio_request(pdata->sda_pin, "sda");
100 if (ret)
101 goto err_request_sda;
102 ret = gpio_request(pdata->scl_pin, "scl");
103 if (ret)
104 goto err_request_scl;
105
106 if (pdata->sda_is_open_drain) {
107 gpio_direction_output(pdata->sda_pin, 1);
108 bit_data->setsda = i2c_gpio_setsda_val;
109 } else {
110 gpio_direction_input(pdata->sda_pin);
111 bit_data->setsda = i2c_gpio_setsda_dir;
112 }
113
114 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) {
115 gpio_direction_output(pdata->scl_pin, 1);
116 bit_data->setscl = i2c_gpio_setscl_val;
117 } else {
118 gpio_direction_input(pdata->scl_pin);
119 bit_data->setscl = i2c_gpio_setscl_dir;
120 }
121
122 if (!pdata->scl_is_output_only)
123 bit_data->getscl = i2c_gpio_getscl;
124 bit_data->getsda = i2c_gpio_getsda;
125
126 if (pdata->udelay)
127 bit_data->udelay = pdata->udelay;
128 else if (pdata->scl_is_output_only)
129 bit_data->udelay = 50; /* 10 kHz */
130 else
131 bit_data->udelay = 5; /* 100 kHz */
132
133 if (pdata->timeout)
134 bit_data->timeout = pdata->timeout;
135 else
136 bit_data->timeout = HZ / 10; /* 100 ms */
137
138 bit_data->data = pdata;
139
140 adap->owner = THIS_MODULE;
141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
142 adap->algo_data = bit_data;
143 adap->dev.parent = &pdev->dev;
144
145 ret = i2c_bit_add_bus(adap);
146 if (ret)
147 goto err_add_bus;
148
149 platform_set_drvdata(pdev, adap);
150
151 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n",
152 pdata->sda_pin, pdata->scl_pin,
153 pdata->scl_is_output_only
154 ? ", no clock stretching" : "");
155
156 return 0;
157
158err_add_bus:
159 gpio_free(pdata->scl_pin);
160err_request_scl:
161 gpio_free(pdata->sda_pin);
162err_request_sda:
163 kfree(bit_data);
164err_alloc_bit_data:
165 kfree(adap);
166err_alloc_adap:
167 return ret;
168}
169
170static int __exit i2c_gpio_remove(struct platform_device *pdev)
171{
172 struct i2c_gpio_platform_data *pdata;
173 struct i2c_adapter *adap;
174
175 adap = platform_get_drvdata(pdev);
176 pdata = pdev->dev.platform_data;
177
178 i2c_del_adapter(adap);
179 gpio_free(pdata->scl_pin);
180 gpio_free(pdata->sda_pin);
181 kfree(adap->algo_data);
182 kfree(adap);
183
184 return 0;
185}
186
187static struct platform_driver i2c_gpio_driver = {
188 .driver = {
189 .name = "i2c-gpio",
190 .owner = THIS_MODULE,
191 },
192 .remove = __exit_p(i2c_gpio_remove),
193};
194
195static int __init i2c_gpio_init(void)
196{
197 int ret;
198
199 ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe);
200 if (ret)
201 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
202
203 return ret;
204}
205module_init(i2c_gpio_init);
206
207static void __exit i2c_gpio_exit(void)
208{
209 platform_driver_unregister(&i2c_gpio_driver);
210}
211module_exit(i2c_gpio_exit);
212
213MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
214MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver");
215MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index a320e7d82c1f..611b57192c96 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -527,7 +527,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
527 /* set up the sysfs linkage to our parent device */ 527 /* set up the sysfs linkage to our parent device */
528 i801_adapter.dev.parent = &dev->dev; 528 i801_adapter.dev.parent = &dev->dev;
529 529
530 snprintf(i801_adapter.name, I2C_NAME_SIZE, 530 snprintf(i801_adapter.name, sizeof(i801_adapter.name),
531 "SMBus I801 adapter at %04lx", i801_smba); 531 "SMBus I801 adapter at %04lx", i801_smba);
532 err = i2c_add_adapter(&i801_adapter); 532 err = i2c_add_adapter(&i801_adapter);
533 if (err) { 533 if (err) {
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 5f33bc9c1e02..b0e1370075de 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -41,6 +41,10 @@
41#include <linux/platform_device.h> 41#include <linux/platform_device.h>
42#include <linux/completion.h> 42#include <linux/completion.h>
43 43
44/* Exported by i2c-core for i2c-isa only */
45extern void i2c_adapter_dev_release(struct device *dev);
46extern struct class i2c_adapter_class;
47
44static u32 isa_func(struct i2c_adapter *adapter); 48static u32 isa_func(struct i2c_adapter *adapter);
45 49
46/* This is the actual algorithm we define */ 50/* This is the actual algorithm we define */
@@ -64,16 +68,6 @@ static u32 isa_func(struct i2c_adapter *adapter)
64} 68}
65 69
66 70
67/* Copied from i2c-core */
68static ssize_t show_adapter_name(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
72 return sprintf(buf, "%s\n", adap->name);
73}
74static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
75
76
77/* We implement an interface which resembles i2c_{add,del}_driver, 71/* We implement an interface which resembles i2c_{add,del}_driver,
78 but for i2c-isa drivers. We don't have to remember and handle lists 72 but for i2c-isa drivers. We don't have to remember and handle lists
79 of drivers and adapters so this is much more simple, of course. */ 73 of drivers and adapters so this is much more simple, of course. */
@@ -139,41 +133,18 @@ static int __init i2c_isa_init(void)
139 isa_adapter.nr = ANY_I2C_ISA_BUS; 133 isa_adapter.nr = ANY_I2C_ISA_BUS;
140 isa_adapter.dev.parent = &platform_bus; 134 isa_adapter.dev.parent = &platform_bus;
141 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 135 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
142 isa_adapter.dev.driver = &i2c_adapter_driver;
143 isa_adapter.dev.release = &i2c_adapter_dev_release; 136 isa_adapter.dev.release = &i2c_adapter_dev_release;
137 isa_adapter.dev.class = &i2c_adapter_class;
144 err = device_register(&isa_adapter.dev); 138 err = device_register(&isa_adapter.dev);
145 if (err) { 139 if (err) {
146 printk(KERN_ERR "i2c-isa: Failed to register device\n"); 140 printk(KERN_ERR "i2c-isa: Failed to register device\n");
147 goto exit; 141 goto exit;
148 } 142 }
149 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
150 if (err) {
151 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
152 goto exit_unregister;
153 }
154
155 /* Add this adapter to the i2c_adapter class */
156 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
157 isa_adapter.class_dev.dev = &isa_adapter.dev;
158 isa_adapter.class_dev.class = &i2c_adapter_class;
159 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
160 BUS_ID_SIZE);
161 err = class_device_register(&isa_adapter.class_dev);
162 if (err) {
163 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
164 goto exit_remove_name;
165 }
166 143
167 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 144 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
168 145
169 return 0; 146 return 0;
170 147
171exit_remove_name:
172 device_remove_file(&isa_adapter.dev, &dev_attr_name);
173exit_unregister:
174 init_completion(&isa_adapter.dev_released); /* Needed? */
175 device_unregister(&isa_adapter.dev);
176 wait_for_completion(&isa_adapter.dev_released);
177exit: 148exit:
178 return err; 149 return err;
179} 150}
@@ -201,15 +172,11 @@ static void __exit i2c_isa_exit(void)
201 /* Clean up the sysfs representation */ 172 /* Clean up the sysfs representation */
202 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); 173 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
203 init_completion(&isa_adapter.dev_released); 174 init_completion(&isa_adapter.dev_released);
204 init_completion(&isa_adapter.class_dev_released);
205 class_device_unregister(&isa_adapter.class_dev);
206 device_remove_file(&isa_adapter.dev, &dev_attr_name);
207 device_unregister(&isa_adapter.dev); 175 device_unregister(&isa_adapter.dev);
208 176
209 /* Wait for sysfs to drop all references */ 177 /* Wait for sysfs to drop all references */
210 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); 178 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
211 wait_for_completion(&isa_adapter.dev_released); 179 wait_for_completion(&isa_adapter.dev_released);
212 wait_for_completion(&isa_adapter.class_dev_released);
213 180
214 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); 181 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
215} 182}
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index efa3ecc5522a..6352121a2827 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
118 118
119 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
121 I2C_NAME_SIZE); 121 sizeof(drv_data->adapter.name));
122 drv_data->adapter.algo_data = &drv_data->algo_data, 122 drv_data->adapter.algo_data = &drv_data->algo_data,
123 123
124 drv_data->adapter.dev.parent = &plat_dev->dev; 124 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 08e89b83984a..069ed7f3b395 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
127 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
128 drv_data->adapter.class = I2C_CLASS_HWMON; 128 drv_data->adapter.class = I2C_CLASS_HWMON;
129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
130 I2C_NAME_SIZE); 130 sizeof(drv_data->adapter.name));
131 drv_data->adapter.algo_data = &drv_data->algo_data; 131 drv_data->adapter.algo_data = &drv_data->algo_data;
132 132
133 drv_data->adapter.dev.parent = &plat_dev->dev; 133 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a3283b907eb8..a55b3335d1be 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
508 } 508 }
509 509
510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", 510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter",
511 I2C_NAME_SIZE); 511 sizeof(drv_data->adapter.name));
512 512
513 init_waitqueue_head(&drv_data->waitq); 513 init_waitqueue_head(&drv_data->waitq);
514 spin_lock_init(&drv_data->lock); 514 spin_lock_init(&drv_data->lock);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 1514ec5b77f8..3cd0d63e7b50 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -33,6 +33,8 @@
33 nForce4 MCP-04 0034 33 nForce4 MCP-04 0034
34 nForce4 MCP51 0264 34 nForce4 MCP51 0264
35 nForce4 MCP55 0368 35 nForce4 MCP55 0368
36 nForce MCP61 03EB
37 nForce MCP65 0446
36 38
37 This driver supports the 2 SMBuses that are included in the MCP of the 39 This driver supports the 2 SMBuses that are included in the MCP of the
38 nForce2/3/4/5xx chipsets. 40 nForce2/3/4/5xx chipsets.
@@ -200,6 +202,8 @@ static struct pci_device_id nforce2_ids[] = {
200 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, 202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) },
201 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, 203 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) },
202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, 204 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) },
205 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) },
206 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) },
203 { 0 } 207 { 0 }
204}; 208};
205 209
@@ -240,7 +244,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
240 smbus->adapter.algo = &smbus_algorithm; 244 smbus->adapter.algo = &smbus_algorithm;
241 smbus->adapter.algo_data = smbus; 245 smbus->adapter.algo_data = smbus;
242 smbus->adapter.dev.parent = &dev->dev; 246 smbus->adapter.dev.parent = &dev->dev;
243 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 247 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
244 "SMBus nForce2 adapter at %04x", smbus->base); 248 "SMBus nForce2 adapter at %04x", smbus->base);
245 249
246 error = i2c_add_adapter(&smbus->adapter); 250 error = i2c_add_adapter(&smbus->adapter);
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index bcd8367cede1..e471e3bfdc1e 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -605,7 +605,8 @@ omap_i2c_probe(struct platform_device *pdev)
605 adap->dev.parent = &pdev->dev; 605 adap->dev.parent = &pdev->dev;
606 606
607 /* i2c device drivers may be active on return from add_adapter() */ 607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap); 608 adap->nr = pdev->id;
609 r = i2c_add_numbered_adapter(adap);
609 if (r) { 610 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n"); 611 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq; 612 goto err_free_irq;
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 4bc42810b9aa..49a95e2887bc 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport-light.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-velleman.c driver 6 Based on older i2c-velleman.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/platform_device.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
32#include <linux/i2c-algo-bit.h> 33#include <linux/i2c-algo-bit.h>
@@ -34,6 +35,9 @@
34#include "i2c-parport.h" 35#include "i2c-parport.h"
35 36
36#define DEFAULT_BASE 0x378 37#define DEFAULT_BASE 0x378
38#define DRVNAME "i2c-parport-light"
39
40static struct platform_device *pdev;
37 41
38static u16 base; 42static u16 base;
39module_param(base, ushort, 0); 43module_param(base, ushort, 0);
@@ -106,7 +110,7 @@ static struct i2c_algo_bit_data parport_algo_data = {
106 .timeout = HZ, 110 .timeout = HZ,
107}; 111};
108 112
109/* ----- I2c structure ---------------------------------------------------- */ 113/* ----- Driver registration ---------------------------------------------- */
110 114
111static struct i2c_adapter parport_adapter = { 115static struct i2c_adapter parport_adapter = {
112 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
@@ -116,55 +120,141 @@ static struct i2c_adapter parport_adapter = {
116 .name = "Parallel port adapter (light)", 120 .name = "Parallel port adapter (light)",
117}; 121};
118 122
119/* ----- Module loading, unloading and information ------------------------ */ 123static int __devinit i2c_parport_probe(struct platform_device *pdev)
124{
125 int err;
126 struct resource *res;
127
128 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
129 if (!request_region(res->start, res->end - res->start + 1, DRVNAME))
130 return -EBUSY;
131
132 /* Reset hardware to a sane state (SCL and SDA high) */
133 parport_setsda(NULL, 1);
134 parport_setscl(NULL, 1);
135 /* Other init if needed (power on...) */
136 if (adapter_parm[type].init.val)
137 line_set(1, &adapter_parm[type].init);
138
139 parport_adapter.dev.parent = &pdev->dev;
140 err = i2c_bit_add_bus(&parport_adapter);
141 if (err) {
142 dev_err(&pdev->dev, "Unable to register with I2C\n");
143 goto exit_region;
144 }
145 return 0;
146
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err;
150}
151
152static int __devexit i2c_parport_remove(struct platform_device *pdev)
153{
154 struct resource *res;
155
156 i2c_del_adapter(&parport_adapter);
157
158 /* Un-init if needed (power off...) */
159 if (adapter_parm[type].init.val)
160 line_set(0, &adapter_parm[type].init);
161
162 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
163 release_region(res->start, res->end - res->start + 1);
164 return 0;
165}
166
167static struct platform_driver i2c_parport_driver = {
168 .driver = {
169 .owner = THIS_MODULE,
170 .name = DRVNAME,
171 },
172 .probe = i2c_parport_probe,
173 .remove = __devexit_p(i2c_parport_remove),
174};
175
176static int __init i2c_parport_device_add(u16 address)
177{
178 struct resource res = {
179 .start = address,
180 .end = address + 2,
181 .name = DRVNAME,
182 .flags = IORESOURCE_IO,
183 };
184 int err;
185
186 pdev = platform_device_alloc(DRVNAME, -1);
187 if (!pdev) {
188 err = -ENOMEM;
189 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
190 goto exit;
191 }
192
193 err = platform_device_add_resources(pdev, &res, 1);
194 if (err) {
195 printk(KERN_ERR DRVNAME ": Device resource addition failed "
196 "(%d)\n", err);
197 goto exit_device_put;
198 }
199
200 err = platform_device_add(pdev);
201 if (err) {
202 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
203 err);
204 goto exit_device_put;
205 }
206
207 return 0;
208
209exit_device_put:
210 platform_device_put(pdev);
211exit:
212 return err;
213}
120 214
121static int __init i2c_parport_init(void) 215static int __init i2c_parport_init(void)
122{ 216{
217 int err;
218
123 if (type < 0) { 219 if (type < 0) {
124 printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); 220 printk(KERN_ERR DRVNAME ": adapter type unspecified\n");
125 return -ENODEV; 221 return -ENODEV;
126 } 222 }
127 223
128 if (type >= ARRAY_SIZE(adapter_parm)) { 224 if (type >= ARRAY_SIZE(adapter_parm)) {
129 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 225 printk(KERN_ERR DRVNAME ": invalid type (%d)\n", type);
130 return -ENODEV; 226 return -ENODEV;
131 } 227 }
132 228
133 if (base == 0) { 229 if (base == 0) {
134 printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE); 230 pr_info(DRVNAME ": using default base 0x%x\n", DEFAULT_BASE);
135 base = DEFAULT_BASE; 231 base = DEFAULT_BASE;
136 } 232 }
137 233
138 if (!request_region(base, 3, "i2c-parport"))
139 return -ENODEV;
140
141 if (!adapter_parm[type].getscl.val) 234 if (!adapter_parm[type].getscl.val)
142 parport_algo_data.getscl = NULL; 235 parport_algo_data.getscl = NULL;
143 236
144 /* Reset hardware to a sane state (SCL and SDA high) */ 237 /* Sets global pdev as a side effect */
145 parport_setsda(NULL, 1); 238 err = i2c_parport_device_add(base);
146 parport_setscl(NULL, 1); 239 if (err)
147 /* Other init if needed (power on...) */ 240 goto exit;
148 if (adapter_parm[type].init.val)
149 line_set(1, &adapter_parm[type].init);
150 241
151 if (i2c_bit_add_bus(&parport_adapter) < 0) { 242 err = platform_driver_register(&i2c_parport_driver);
152 printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); 243 if (err)
153 release_region(base, 3); 244 goto exit_device;
154 return -ENODEV;
155 }
156 245
157 return 0; 246 return 0;
247
248exit_device:
249 platform_device_unregister(pdev);
250exit:
251 return err;
158} 252}
159 253
160static void __exit i2c_parport_exit(void) 254static void __exit i2c_parport_exit(void)
161{ 255{
162 /* Un-init if needed (power off...) */ 256 platform_driver_unregister(&i2c_parport_driver);
163 if (adapter_parm[type].init.val) 257 platform_device_unregister(pdev);
164 line_set(0, &adapter_parm[type].init);
165
166 i2c_del_adapter(&parport_adapter);
167 release_region(base, 3);
168} 258}
169 259
170MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 66696a40c7b5..8c953707253f 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-philips-par.c driver 6 Based on older i2c-philips-par.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -137,19 +137,12 @@ static struct i2c_algo_bit_data parport_algo_data = {
137 .setscl = parport_setscl, 137 .setscl = parport_setscl,
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 10, /* ~50 kbps */
141 .timeout = HZ, 141 .timeout = HZ,
142}; 142};
143 143
144/* ----- I2c and parallel port call-back functions and structures --------- */ 144/* ----- I2c and parallel port call-back functions and structures --------- */
145 145
146static struct i2c_adapter parport_adapter = {
147 .owner = THIS_MODULE,
148 .class = I2C_CLASS_HWMON,
149 .id = I2C_HW_B_LP,
150 .name = "Parallel port adapter",
151};
152
153static void i2c_parport_attach (struct parport *port) 146static void i2c_parport_attach (struct parport *port)
154{ 147{
155 struct i2c_par *adapter; 148 struct i2c_par *adapter;
@@ -169,10 +162,17 @@ static void i2c_parport_attach (struct parport *port)
169 } 162 }
170 163
171 /* Fill the rest of the structure */ 164 /* Fill the rest of the structure */
172 adapter->adapter = parport_adapter; 165 adapter->adapter.owner = THIS_MODULE;
166 adapter->adapter.class = I2C_CLASS_HWMON;
167 adapter->adapter.id = I2C_HW_B_LP;
168 strlcpy(adapter->adapter.name, "Parallel port adapter",
169 sizeof(adapter->adapter.name));
173 adapter->algo_data = parport_algo_data; 170 adapter->algo_data = parport_algo_data;
174 if (!adapter_parm[type].getscl.val) 171 /* Slow down if we can't sense SCL */
172 if (!adapter_parm[type].getscl.val) {
175 adapter->algo_data.getscl = NULL; 173 adapter->algo_data.getscl = NULL;
174 adapter->algo_data.udelay = 50; /* ~10 kbps */
175 }
176 adapter->algo_data.data = port; 176 adapter->algo_data.data = port;
177 adapter->adapter.algo_data = &adapter->algo_data; 177 adapter->adapter.algo_data = &adapter->algo_data;
178 178
@@ -214,11 +214,12 @@ static void i2c_parport_detach (struct parport *port)
214 for (prev = NULL, adapter = adapter_list; adapter; 214 for (prev = NULL, adapter = adapter_list; adapter;
215 prev = adapter, adapter = adapter->next) { 215 prev = adapter, adapter = adapter->next) {
216 if (adapter->pdev->port == port) { 216 if (adapter->pdev->port == port) {
217 i2c_del_adapter(&adapter->adapter);
218
217 /* Un-init if needed (power off...) */ 219 /* Un-init if needed (power off...) */
218 if (adapter_parm[type].init.val) 220 if (adapter_parm[type].init.val)
219 line_set(port, 0, &adapter_parm[type].init); 221 line_set(port, 0, &adapter_parm[type].init);
220 222
221 i2c_del_adapter(&adapter->adapter);
222 parport_unregister_device(adapter->pdev); 223 parport_unregister_device(adapter->pdev);
223 if (prev) 224 if (prev)
224 prev->next = adapter->next; 225 prev->next = adapter->next;
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index bf89eeef74e9..58e32714afb5 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
358 } 358 }
359 359
360 smbus->adapter.owner = THIS_MODULE; 360 smbus->adapter.owner = THIS_MODULE;
361 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 361 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
362 "PA Semi SMBus adapter at 0x%lx", smbus->base); 362 "PA Semi SMBus adapter at 0x%lx", smbus->base);
363 smbus->adapter.class = I2C_CLASS_HWMON; 363 smbus->adapter.class = I2C_CLASS_HWMON;
364 smbus->adapter.algo = &smbus_algorithm; 364 smbus->adapter.algo = &smbus_algorithm;
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 6b03e0d0a8e3..5161aaf9341b 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -27,6 +27,7 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/wait.h> 28#include <linux/wait.h>
29 29
30#include <linux/isa.h>
30#include <linux/i2c.h> 31#include <linux/i2c.h>
31#include <linux/i2c-algo-pca.h> 32#include <linux/i2c-algo-pca.h>
32 33
@@ -118,27 +119,26 @@ static struct i2c_adapter pca_isa_ops = {
118 .name = "PCA9564 ISA Adapter", 119 .name = "PCA9564 ISA Adapter",
119}; 120};
120 121
121static int __init pca_isa_init(void) 122static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
122{ 123{
123
124 init_waitqueue_head(&pca_wait); 124 init_waitqueue_head(&pca_wait);
125 125
126 printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq); 126 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
127 127
128 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { 128 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
129 printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base); 129 dev_err(dev, "I/O address %#08lx is in use\n", base);
130 goto out; 130 goto out;
131 } 131 }
132 132
133 if (irq > -1) { 133 if (irq > -1) {
134 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { 134 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
135 printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq); 135 dev_err(dev, "Request irq%d failed\n", irq);
136 goto out_region; 136 goto out_region;
137 } 137 }
138 } 138 }
139 139
140 if (i2c_pca_add_bus(&pca_isa_ops) < 0) { 140 if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
141 printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n"); 141 dev_err(dev, "Failed to add i2c bus\n");
142 goto out_irq; 142 goto out_irq;
143 } 143 }
144 144
@@ -153,7 +153,7 @@ static int __init pca_isa_init(void)
153 return -ENODEV; 153 return -ENODEV;
154} 154}
155 155
156static void pca_isa_exit(void) 156static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
157{ 157{
158 i2c_del_adapter(&pca_isa_ops); 158 i2c_del_adapter(&pca_isa_ops);
159 159
@@ -162,6 +162,27 @@ static void pca_isa_exit(void)
162 free_irq(irq, &pca_isa_ops); 162 free_irq(irq, &pca_isa_ops);
163 } 163 }
164 release_region(base, IO_SIZE); 164 release_region(base, IO_SIZE);
165
166 return 0;
167}
168
169static struct isa_driver pca_isa_driver = {
170 .probe = pca_isa_probe,
171 .remove = __devexit_p(pca_isa_remove),
172 .driver = {
173 .owner = THIS_MODULE,
174 .name = "i2c-pca-isa",
175 }
176};
177
178static int __init pca_isa_init(void)
179{
180 return isa_register_driver(&pca_isa_driver, 1);
181}
182
183static void __exit pca_isa_exit(void)
184{
185 isa_unregister_driver(&pca_isa_driver);
165} 186}
166 187
167MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 188MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 21b180904085..5a52bf5e3fb0 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
428 /* set up the sysfs linkage to our parent device */ 428 /* set up the sysfs linkage to our parent device */
429 piix4_adapter.dev.parent = &dev->dev; 429 piix4_adapter.dev.parent = &dev->dev;
430 430
431 snprintf(piix4_adapter.name, I2C_NAME_SIZE, 431 snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
432 "SMBus PIIX4 adapter at %04x", piix4_smba); 432 "SMBus PIIX4 adapter at %04x", piix4_smba);
433 433
434 if ((retval = i2c_add_adapter(&piix4_adapter))) { 434 if ((retval = i2c_add_adapter(&piix4_adapter))) {
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 14e83d0aac8c..c059b27fa881 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -539,6 +539,18 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
539 writel(icr | ICR_START | ICR_TB, _ICR(i2c)); 539 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
540} 540}
541 541
542static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
543{
544 u32 icr;
545
546 /*
547 * Clear the STOP and ACK flags
548 */
549 icr = readl(_ICR(i2c));
550 icr &= ~(ICR_STOP | ICR_ACKNAK);
551 writel(icr, _IRC(i2c));
552}
553
542/* 554/*
543 * We are protected by the adapter bus mutex. 555 * We are protected by the adapter bus mutex.
544 */ 556 */
@@ -581,6 +593,7 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
581 * The rest of the processing occurs in the interrupt handler. 593 * The rest of the processing occurs in the interrupt handler.
582 */ 594 */
583 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 595 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
596 i2c_pxa_stop_message(i2c);
584 597
585 /* 598 /*
586 * We place the return code in i2c->msg_idx. 599 * We place the return code in i2c->msg_idx.
@@ -825,7 +838,7 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
825}; 838};
826 839
827static struct pxa_i2c i2c_pxa = { 840static struct pxa_i2c i2c_pxa = {
828 .lock = SPIN_LOCK_UNLOCKED, 841 .lock = __SPIN_LOCK_UNLOCKED(i2c_pxa.lock),
829 .adap = { 842 .adap = {
830 .owner = THIS_MODULE, 843 .owner = THIS_MODULE,
831 .algo = &i2c_pxa_algorithm, 844 .algo = &i2c_pxa_algorithm,
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 556f244aae76..e68a96f589fd 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -61,6 +61,8 @@ struct s3c24xx_i2c {
61 unsigned int msg_idx; 61 unsigned int msg_idx;
62 unsigned int msg_ptr; 62 unsigned int msg_ptr;
63 63
64 unsigned int tx_setup;
65
64 enum s3c24xx_i2c_state state; 66 enum s3c24xx_i2c_state state;
65 67
66 void __iomem *regs; 68 void __iomem *regs;
@@ -199,8 +201,11 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
199 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 201 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
200 writeb(addr, i2c->regs + S3C2410_IICDS); 202 writeb(addr, i2c->regs + S3C2410_IICDS);
201 203
202 // delay a bit and reset iiccon before setting start (per samsung) 204 /* delay here to ensure the data byte has gotten onto the bus
203 udelay(1); 205 * before the transaction is started */
206
207 ndelay(i2c->tx_setup);
208
204 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 209 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
205 writel(iiccon, i2c->regs + S3C2410_IICCON); 210 writel(iiccon, i2c->regs + S3C2410_IICCON);
206 211
@@ -322,7 +327,15 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
322 if (!is_msgend(i2c)) { 327 if (!is_msgend(i2c)) {
323 byte = i2c->msg->buf[i2c->msg_ptr++]; 328 byte = i2c->msg->buf[i2c->msg_ptr++];
324 writeb(byte, i2c->regs + S3C2410_IICDS); 329 writeb(byte, i2c->regs + S3C2410_IICDS);
325 330
331 /* delay after writing the byte to allow the
332 * data setup time on the bus, as writing the
333 * data to the register causes the first bit
334 * to appear on SDA, and SCL will change as
335 * soon as the interrupt is acknowledged */
336
337 ndelay(i2c->tx_setup);
338
326 } else if (!is_lastmsg(i2c)) { 339 } else if (!is_lastmsg(i2c)) {
327 /* we need to go to the next i2c message */ 340 /* we need to go to the next i2c message */
328 341
@@ -570,9 +583,10 @@ static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570}; 583};
571 584
572static struct s3c24xx_i2c s3c24xx_i2c = { 585static struct s3c24xx_i2c s3c24xx_i2c = {
573 .lock = SPIN_LOCK_UNLOCKED, 586 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock),
574 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), 587 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait),
575 .adap = { 588 .tx_setup = 50,
589 .adap = {
576 .name = "s3c2410-i2c", 590 .name = "s3c2410-i2c",
577 .owner = THIS_MODULE, 591 .owner = THIS_MODULE,
578 .algo = &s3c24xx_i2c_algorithm, 592 .algo = &s3c24xx_i2c_algorithm,
@@ -731,26 +745,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
731 return 0; 745 return 0;
732} 746}
733 747
734static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c)
735{
736 if (i2c->clk != NULL && !IS_ERR(i2c->clk)) {
737 clk_disable(i2c->clk);
738 clk_put(i2c->clk);
739 i2c->clk = NULL;
740 }
741
742 if (i2c->regs != NULL) {
743 iounmap(i2c->regs);
744 i2c->regs = NULL;
745 }
746
747 if (i2c->ioarea != NULL) {
748 release_resource(i2c->ioarea);
749 kfree(i2c->ioarea);
750 i2c->ioarea = NULL;
751 }
752}
753
754/* s3c24xx_i2c_probe 748/* s3c24xx_i2c_probe
755 * 749 *
756 * called by the bus driver when a suitable device is found 750 * called by the bus driver when a suitable device is found
@@ -769,7 +763,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
769 if (IS_ERR(i2c->clk)) { 763 if (IS_ERR(i2c->clk)) {
770 dev_err(&pdev->dev, "cannot get clock\n"); 764 dev_err(&pdev->dev, "cannot get clock\n");
771 ret = -ENOENT; 765 ret = -ENOENT;
772 goto out; 766 goto err_noclk;
773 } 767 }
774 768
775 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); 769 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
@@ -782,7 +776,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
782 if (res == NULL) { 776 if (res == NULL) {
783 dev_err(&pdev->dev, "cannot find IO resource\n"); 777 dev_err(&pdev->dev, "cannot find IO resource\n");
784 ret = -ENOENT; 778 ret = -ENOENT;
785 goto out; 779 goto err_clk;
786 } 780 }
787 781
788 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1, 782 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1,
@@ -791,7 +785,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
791 if (i2c->ioarea == NULL) { 785 if (i2c->ioarea == NULL) {
792 dev_err(&pdev->dev, "cannot request IO\n"); 786 dev_err(&pdev->dev, "cannot request IO\n");
793 ret = -ENXIO; 787 ret = -ENXIO;
794 goto out; 788 goto err_clk;
795 } 789 }
796 790
797 i2c->regs = ioremap(res->start, (res->end-res->start)+1); 791 i2c->regs = ioremap(res->start, (res->end-res->start)+1);
@@ -799,7 +793,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
799 if (i2c->regs == NULL) { 793 if (i2c->regs == NULL) {
800 dev_err(&pdev->dev, "cannot map IO\n"); 794 dev_err(&pdev->dev, "cannot map IO\n");
801 ret = -ENXIO; 795 ret = -ENXIO;
802 goto out; 796 goto err_ioarea;
803 } 797 }
804 798
805 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); 799 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
@@ -813,7 +807,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
813 807
814 ret = s3c24xx_i2c_init(i2c); 808 ret = s3c24xx_i2c_init(i2c);
815 if (ret != 0) 809 if (ret != 0)
816 goto out; 810 goto err_iomap;
817 811
818 /* find the IRQ for this unit (note, this relies on the init call to 812 /* find the IRQ for this unit (note, this relies on the init call to
819 * ensure no current IRQs pending 813 * ensure no current IRQs pending
@@ -823,7 +817,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
823 if (res == NULL) { 817 if (res == NULL) {
824 dev_err(&pdev->dev, "cannot find IRQ\n"); 818 dev_err(&pdev->dev, "cannot find IRQ\n");
825 ret = -ENOENT; 819 ret = -ENOENT;
826 goto out; 820 goto err_iomap;
827 } 821 }
828 822
829 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 823 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED,
@@ -831,7 +825,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
831 825
832 if (ret != 0) { 826 if (ret != 0) {
833 dev_err(&pdev->dev, "cannot claim IRQ\n"); 827 dev_err(&pdev->dev, "cannot claim IRQ\n");
834 goto out; 828 goto err_iomap;
835 } 829 }
836 830
837 i2c->irq = res; 831 i2c->irq = res;
@@ -841,17 +835,29 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
841 ret = i2c_add_adapter(&i2c->adap); 835 ret = i2c_add_adapter(&i2c->adap);
842 if (ret < 0) { 836 if (ret < 0) {
843 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 837 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
844 goto out; 838 goto err_irq;
845 } 839 }
846 840
847 platform_set_drvdata(pdev, i2c); 841 platform_set_drvdata(pdev, i2c);
848 842
849 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); 843 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
844 return 0;
850 845
851 out: 846 err_irq:
852 if (ret < 0) 847 free_irq(i2c->irq->start, i2c);
853 s3c24xx_i2c_free(i2c); 848
849 err_iomap:
850 iounmap(i2c->regs);
854 851
852 err_ioarea:
853 release_resource(i2c->ioarea);
854 kfree(i2c->ioarea);
855
856 err_clk:
857 clk_disable(i2c->clk);
858 clk_put(i2c->clk);
859
860 err_noclk:
855 return ret; 861 return ret;
856} 862}
857 863
@@ -863,11 +869,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
863static int s3c24xx_i2c_remove(struct platform_device *pdev) 869static int s3c24xx_i2c_remove(struct platform_device *pdev)
864{ 870{
865 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 871 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
866 872
867 if (i2c != NULL) { 873 i2c_del_adapter(&i2c->adap);
868 s3c24xx_i2c_free(i2c); 874 free_irq(i2c->irq->start, i2c);
869 platform_set_drvdata(pdev, NULL); 875
870 } 876 clk_disable(i2c->clk);
877 clk_put(i2c->clk);
878
879 iounmap(i2c->regs);
880
881 release_resource(i2c->ioarea);
882 kfree(i2c->ioarea);
871 883
872 return 0; 884 return 0;
873} 885}
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
new file mode 100644
index 000000000000..10af8d31e12a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -0,0 +1,186 @@
1/*
2 * Copyright (C) 2005 Simtec Electronics
3 * Ben Dooks <ben@simtec.co.uk>
4 *
5 * Simtec Generic I2C Controller
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h>
26
27#include <linux/i2c.h>
28#include <linux/i2c-algo-bit.h>
29
30#include <asm/io.h>
31
32struct simtec_i2c_data {
33 struct resource *ioarea;
34 void __iomem *reg;
35 struct i2c_adapter adap;
36 struct i2c_algo_bit_data bit;
37};
38
39#define CMD_SET_SDA (1<<2)
40#define CMD_SET_SCL (1<<3)
41
42#define STATE_SDA (1<<0)
43#define STATE_SCL (1<<1)
44
45/* i2c bit-bus functions */
46
47static void simtec_i2c_setsda(void *pw, int state)
48{
49 struct simtec_i2c_data *pd = pw;
50 writeb(CMD_SET_SDA | (state ? STATE_SDA : 0), pd->reg);
51}
52
53static void simtec_i2c_setscl(void *pw, int state)
54{
55 struct simtec_i2c_data *pd = pw;
56 writeb(CMD_SET_SCL | (state ? STATE_SCL : 0), pd->reg);
57}
58
59static int simtec_i2c_getsda(void *pw)
60{
61 struct simtec_i2c_data *pd = pw;
62 return readb(pd->reg) & STATE_SDA ? 1 : 0;
63}
64
65static int simtec_i2c_getscl(void *pw)
66{
67 struct simtec_i2c_data *pd = pw;
68 return readb(pd->reg) & STATE_SCL ? 1 : 0;
69}
70
71/* device registration */
72
73static int simtec_i2c_probe(struct platform_device *dev)
74{
75 struct simtec_i2c_data *pd;
76 struct resource *res;
77 int size;
78 int ret;
79
80 pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL);
81 if (pd == NULL) {
82 dev_err(&dev->dev, "cannot allocate private data\n");
83 return -ENOMEM;
84 }
85
86 platform_set_drvdata(dev, pd);
87
88 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
89 if (res == NULL) {
90 dev_err(&dev->dev, "cannot find IO resource\n");
91 ret = -ENOENT;
92 goto err;
93 }
94
95 size = (res->end-res->start)+1;
96
97 pd->ioarea = request_mem_region(res->start, size, dev->name);
98 if (pd->ioarea == NULL) {
99 dev_err(&dev->dev, "cannot request IO\n");
100 ret = -ENXIO;
101 goto err;
102 }
103
104 pd->reg = ioremap(res->start, size);
105 if (pd->reg == NULL) {
106 dev_err(&dev->dev, "cannot map IO\n");
107 ret = -ENXIO;
108 goto err_res;
109 }
110
111 /* setup the private data */
112
113 pd->adap.owner = THIS_MODULE;
114 pd->adap.algo_data = &pd->bit;
115 pd->adap.dev.parent = &dev->dev;
116
117 strlcpy(pd->adap.name, "Simtec I2C", sizeof(pd->adap.name));
118
119 pd->bit.data = pd;
120 pd->bit.setsda = simtec_i2c_setsda;
121 pd->bit.setscl = simtec_i2c_setscl;
122 pd->bit.getsda = simtec_i2c_getsda;
123 pd->bit.getscl = simtec_i2c_getscl;
124 pd->bit.timeout = HZ;
125 pd->bit.udelay = 20;
126
127 ret = i2c_bit_add_bus(&pd->adap);
128 if (ret)
129 goto err_all;
130
131 return 0;
132
133 err_all:
134 iounmap(pd->reg);
135
136 err_res:
137 release_resource(pd->ioarea);
138 kfree(pd->ioarea);
139
140 err:
141 kfree(pd);
142 return ret;
143}
144
145static int simtec_i2c_remove(struct platform_device *dev)
146{
147 struct simtec_i2c_data *pd = platform_get_drvdata(dev);
148
149 i2c_del_adapter(&pd->adap);
150
151 iounmap(pd->reg);
152 release_resource(pd->ioarea);
153 kfree(pd->ioarea);
154 kfree(pd);
155
156 return 0;
157}
158
159
160/* device driver */
161
162static struct platform_driver simtec_i2c_driver = {
163 .driver = {
164 .name = "simtec-i2c",
165 .owner = THIS_MODULE,
166 },
167 .probe = simtec_i2c_probe,
168 .remove = simtec_i2c_remove,
169};
170
171static int __init i2c_adap_simtec_init(void)
172{
173 return platform_driver_register(&simtec_i2c_driver);
174}
175
176static void __exit i2c_adap_simtec_exit(void)
177{
178 platform_driver_unregister(&simtec_i2c_driver);
179}
180
181module_init(i2c_adap_simtec_init);
182module_exit(i2c_adap_simtec_exit);
183
184MODULE_DESCRIPTION("Simtec Generic I2C Bus driver");
185MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
186MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 4157b0cd604c..dc235bb8e24d 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
300 /* set up the sysfs linkage to our parent device */ 300 /* set up the sysfs linkage to our parent device */
301 sis96x_adapter.dev.parent = &dev->dev; 301 sis96x_adapter.dev.parent = &dev->dev;
302 302
303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE, 303 snprintf(sis96x_adapter.name, sizeof(sis96x_adapter.name),
304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base); 304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base);
305 305
306 if ((retval = i2c_add_adapter(&sis96x_adapter))) { 306 if ((retval = i2c_add_adapter(&sis96x_adapter))) {
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
new file mode 100644
index 000000000000..907999049d50
--- /dev/null
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -0,0 +1,277 @@
1/*
2 * driver for the i2c-tiny-usb adapter - 1.0
3 * http://www.harbaum.org/till/i2c_tiny_usb
4 *
5 * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/module.h>
16
17/* include interfaces to usb layer */
18#include <linux/usb.h>
19
20/* include interface to i2c layer */
21#include <linux/i2c.h>
22
23/* commands via USB, must match command ids in the firmware */
24#define CMD_ECHO 0
25#define CMD_GET_FUNC 1
26#define CMD_SET_DELAY 2
27#define CMD_GET_STATUS 3
28
29#define CMD_I2C_IO 4
30#define CMD_I2C_IO_BEGIN (1<<0)
31#define CMD_I2C_IO_END (1<<1)
32
33/* i2c bit delay, default is 10us -> 100kHz */
34static int delay = 10;
35module_param(delay, int, 0);
36MODULE_PARM_DESC(delay, "bit delay in microseconds, "
37 "e.g. 10 for 100kHz (default is 100kHz)");
38
39static int usb_read(struct i2c_adapter *adapter, int cmd,
40 int value, int index, void *data, int len);
41
42static int usb_write(struct i2c_adapter *adapter, int cmd,
43 int value, int index, void *data, int len);
44
45/* ----- begin of i2c layer ---------------------------------------------- */
46
47#define STATUS_IDLE 0
48#define STATUS_ADDRESS_ACK 1
49#define STATUS_ADDRESS_NAK 2
50
51static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
52{
53 unsigned char status;
54 struct i2c_msg *pmsg;
55 int i;
56
57 dev_dbg(&adapter->dev, "master xfer %d messages:\n", num);
58
59 for (i = 0 ; i < num ; i++) {
60 int cmd = CMD_I2C_IO;
61
62 if (i == 0)
63 cmd |= CMD_I2C_IO_BEGIN;
64
65 if (i == num-1)
66 cmd |= CMD_I2C_IO_END;
67
68 pmsg = &msgs[i];
69
70 dev_dbg(&adapter->dev,
71 " %d: %s (flags %d) %d bytes to 0x%02x\n",
72 i, pmsg->flags & I2C_M_RD ? "read" : "write",
73 pmsg->flags, pmsg->len, pmsg->addr);
74
75 /* and directly send the message */
76 if (pmsg->flags & I2C_M_RD) {
77 /* read data */
78 if (usb_read(adapter, cmd,
79 pmsg->flags, pmsg->addr,
80 pmsg->buf, pmsg->len) != pmsg->len) {
81 dev_err(&adapter->dev,
82 "failure reading data\n");
83 return -EREMOTEIO;
84 }
85 } else {
86 /* write data */
87 if (usb_write(adapter, cmd,
88 pmsg->flags, pmsg->addr,
89 pmsg->buf, pmsg->len) != pmsg->len) {
90 dev_err(&adapter->dev,
91 "failure writing data\n");
92 return -EREMOTEIO;
93 }
94 }
95
96 /* read status */
97 if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) {
98 dev_err(&adapter->dev, "failure reading status\n");
99 return -EREMOTEIO;
100 }
101
102 dev_dbg(&adapter->dev, " status = %d\n", status);
103 if (status == STATUS_ADDRESS_NAK)
104 return -EREMOTEIO;
105 }
106
107 return i;
108}
109
110static u32 usb_func(struct i2c_adapter *adapter)
111{
112 u32 func;
113
114 /* get functionality from adapter */
115 if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) !=
116 sizeof(func)) {
117 dev_err(&adapter->dev, "failure reading functionality\n");
118 return 0;
119 }
120
121 return func;
122}
123
124/* This is the actual algorithm we define */
125static const struct i2c_algorithm usb_algorithm = {
126 .master_xfer = usb_xfer,
127 .functionality = usb_func,
128};
129
130/* ----- end of i2c layer ------------------------------------------------ */
131
132/* ----- begin of usb layer ---------------------------------------------- */
133
134/* The usb i2c interface uses a vid/pid pair donated by */
135/* Future Technology Devices International Ltd. */
136static struct usb_device_id i2c_tiny_usb_table [] = {
137 { USB_DEVICE(0x0403, 0xc631) },
138 { } /* Terminating entry */
139};
140
141MODULE_DEVICE_TABLE(usb, i2c_tiny_usb_table);
142
143/* Structure to hold all of our device specific stuff */
144struct i2c_tiny_usb {
145 struct usb_device *usb_dev; /* the usb device for this device */
146 struct usb_interface *interface; /* the interface for this device */
147 struct i2c_adapter adapter; /* i2c related things */
148};
149
150static int usb_read(struct i2c_adapter *adapter, int cmd,
151 int value, int index, void *data, int len)
152{
153 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
154
155 /* do control transfer */
156 return usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0),
157 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE |
158 USB_DIR_IN, value, index, data, len, 2000);
159}
160
161static int usb_write(struct i2c_adapter *adapter, int cmd,
162 int value, int index, void *data, int len)
163{
164 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
165
166 /* do control transfer */
167 return usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0),
168 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
169 value, index, data, len, 2000);
170}
171
172static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
173{
174 usb_put_dev(dev->usb_dev);
175 kfree(dev);
176}
177
178static int i2c_tiny_usb_probe(struct usb_interface *interface,
179 const struct usb_device_id *id)
180{
181 struct i2c_tiny_usb *dev;
182 int retval = -ENOMEM;
183 u16 version;
184
185 dev_dbg(&interface->dev, "probing usb device\n");
186
187 /* allocate memory for our device state and initialize it */
188 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
189 if (dev == NULL) {
190 dev_err(&interface->dev, "Out of memory\n");
191 goto error;
192 }
193
194 dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
195 dev->interface = interface;
196
197 /* save our data pointer in this interface device */
198 usb_set_intfdata(interface, dev);
199
200 version = le16_to_cpu(dev->usb_dev->descriptor.bcdDevice);
201 dev_info(&interface->dev,
202 "version %x.%02x found at bus %03d address %03d\n",
203 version >> 8, version & 0xff,
204 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
205
206 /* setup i2c adapter description */
207 dev->adapter.owner = THIS_MODULE;
208 dev->adapter.class = I2C_CLASS_HWMON;
209 dev->adapter.algo = &usb_algorithm;
210 dev->adapter.algo_data = dev;
211 snprintf(dev->adapter.name, I2C_NAME_SIZE,
212 "i2c-tiny-usb at bus %03d device %03d",
213 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
214
215 if (usb_write(&dev->adapter, CMD_SET_DELAY,
216 cpu_to_le16(delay), 0, NULL, 0) != 0) {
217 dev_err(&dev->adapter.dev,
218 "failure setting delay to %dus\n", delay);
219 retval = -EIO;
220 goto error;
221 }
222
223 dev->adapter.dev.parent = &dev->interface->dev;
224
225 /* and finally attach to i2c layer */
226 i2c_add_adapter(&dev->adapter);
227
228 /* inform user about successful attachment to i2c layer */
229 dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
230
231 return 0;
232
233 error:
234 if (dev)
235 i2c_tiny_usb_free(dev);
236
237 return retval;
238}
239
240static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
241{
242 struct i2c_tiny_usb *dev = usb_get_intfdata(interface);
243
244 i2c_del_adapter(&dev->adapter);
245 usb_set_intfdata(interface, NULL);
246 i2c_tiny_usb_free(dev);
247
248 dev_dbg(&interface->dev, "disconnected\n");
249}
250
251static struct usb_driver i2c_tiny_usb_driver = {
252 .name = "i2c-tiny-usb",
253 .probe = i2c_tiny_usb_probe,
254 .disconnect = i2c_tiny_usb_disconnect,
255 .id_table = i2c_tiny_usb_table,
256};
257
258static int __init usb_i2c_tiny_usb_init(void)
259{
260 /* register this driver with the USB subsystem */
261 return usb_register(&i2c_tiny_usb_driver);
262}
263
264static void __exit usb_i2c_tiny_usb_exit(void)
265{
266 /* deregister this driver with the USB subsystem */
267 usb_deregister(&i2c_tiny_usb_driver);
268}
269
270module_init(usb_i2c_tiny_usb_init);
271module_exit(usb_i2c_tiny_usb_exit);
272
273/* ----- end of usb layer ------------------------------------------------ */
274
275MODULE_AUTHOR("Till Harbaum <Till@Harbaum.org>");
276MODULE_DESCRIPTION("i2c-tiny-usb driver v1.0");
277MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 03c5fc868548..7a2bc06304fc 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -404,7 +404,7 @@ found:
404 } 404 }
405 405
406 vt596_adapter.dev.parent = &pdev->dev; 406 vt596_adapter.dev.parent = &pdev->dev;
407 snprintf(vt596_adapter.name, I2C_NAME_SIZE, 407 snprintf(vt596_adapter.name, sizeof(vt596_adapter.name),
408 "SMBus Via Pro adapter at %04x", vt596_smba); 408 "SMBus Via Pro adapter at %04x", vt596_smba);
409 409
410 vt596_pdev = pci_dev_get(pdev); 410 vt596_pdev = pci_dev_get(pdev);
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0b082c5a0195..0db56e7bc34e 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -441,7 +441,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text,
441 441
442 adapter = &iface->adapter; 442 adapter = &iface->adapter;
443 i2c_set_adapdata(adapter, iface); 443 i2c_set_adapdata(adapter, iface);
444 snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index); 444 snprintf(adapter->name, sizeof(adapter->name), "%s ACB%d", text, index);
445 adapter->owner = THIS_MODULE; 445 adapter->owner = THIS_MODULE;
446 adapter->id = I2C_HW_SMBUS_SCX200; 446 adapter->id = I2C_HW_SMBUS_SCX200;
447 adapter->algo = &scx200_acb_algorithm; 447 adapter->algo = &scx200_acb_algorithm;
@@ -599,6 +599,7 @@ static __init int scx200_scan_pci(void)
599 else { 599 else {
600 int i; 600 int i;
601 601
602 pci_dev_put(pdev);
602 for (i = 0; i < MAX_DEVICES; ++i) { 603 for (i = 0; i < MAX_DEVICES; ++i) {
603 if (base[i] == 0) 604 if (base[i] == 0)
604 continue; 605 continue;
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 87ee3ce58618..ea085a006ead 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
6 depends on I2C
7 6
8config SENSORS_DS1337 7config SENSORS_DS1337
9 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" 8 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock"
10 depends on I2C && EXPERIMENTAL 9 depends on EXPERIMENTAL
11 help 10 help
12 If you say yes here you get support for Dallas Semiconductor 11 If you say yes here you get support for Dallas Semiconductor
13 DS1337 and DS1339 real-time clock chips. 12 DS1337 and DS1339 real-time clock chips.
@@ -17,7 +16,7 @@ config SENSORS_DS1337
17 16
18config SENSORS_DS1374 17config SENSORS_DS1374
19 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" 18 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
20 depends on I2C && EXPERIMENTAL 19 depends on EXPERIMENTAL
21 help 20 help
22 If you say yes here you get support for Dallas Semiconductor 21 If you say yes here you get support for Dallas Semiconductor
23 DS1374 real-time clock chips. 22 DS1374 real-time clock chips.
@@ -27,7 +26,7 @@ config SENSORS_DS1374
27 26
28config SENSORS_EEPROM 27config SENSORS_EEPROM
29 tristate "EEPROM reader" 28 tristate "EEPROM reader"
30 depends on I2C && EXPERIMENTAL 29 depends on EXPERIMENTAL
31 help 30 help
32 If you say yes here you get read-only access to the EEPROM data 31 If you say yes here you get read-only access to the EEPROM data
33 available on modern memory DIMMs and Sony Vaio laptops. Such 32 available on modern memory DIMMs and Sony Vaio laptops. Such
@@ -38,7 +37,7 @@ config SENSORS_EEPROM
38 37
39config SENSORS_PCF8574 38config SENSORS_PCF8574
40 tristate "Philips PCF8574 and PCF8574A" 39 tristate "Philips PCF8574 and PCF8574A"
41 depends on I2C && EXPERIMENTAL 40 depends on EXPERIMENTAL
42 default n 41 default n
43 help 42 help
44 If you say yes here you get support for Philips PCF8574 and 43 If you say yes here you get support for Philips PCF8574 and
@@ -52,7 +51,7 @@ config SENSORS_PCF8574
52 51
53config SENSORS_PCA9539 52config SENSORS_PCA9539
54 tristate "Philips PCA9539 16-bit I/O port" 53 tristate "Philips PCA9539 16-bit I/O port"
55 depends on I2C && EXPERIMENTAL 54 depends on EXPERIMENTAL
56 help 55 help
57 If you say yes here you get support for the Philips PCA9539 56 If you say yes here you get support for the Philips PCA9539
58 16-bit I/O port. 57 16-bit I/O port.
@@ -62,7 +61,7 @@ config SENSORS_PCA9539
62 61
63config SENSORS_PCF8591 62config SENSORS_PCF8591
64 tristate "Philips PCF8591" 63 tristate "Philips PCF8591"
65 depends on I2C && EXPERIMENTAL 64 depends on EXPERIMENTAL
66 default n 65 default n
67 help 66 help
68 If you say yes here you get support for Philips PCF8591 chips. 67 If you say yes here you get support for Philips PCF8591 chips.
@@ -75,7 +74,7 @@ config SENSORS_PCF8591
75 74
76config ISP1301_OMAP 75config ISP1301_OMAP
77 tristate "Philips ISP1301 with OMAP OTG" 76 tristate "Philips ISP1301 with OMAP OTG"
78 depends on I2C && ARCH_OMAP_OTG 77 depends on ARCH_OMAP_OTG
79 help 78 help
80 If you say yes here you get support for the Philips ISP1301 79 If you say yes here you get support for the Philips ISP1301
81 USB-On-The-Go transceiver working with the OMAP OTG controller. 80 USB-On-The-Go transceiver working with the OMAP OTG controller.
@@ -90,7 +89,7 @@ config ISP1301_OMAP
90# and having mostly OMAP-specific board support 89# and having mostly OMAP-specific board support
91config TPS65010 90config TPS65010
92 tristate "TPS6501x Power Management chips" 91 tristate "TPS6501x Power Management chips"
93 depends on I2C && ARCH_OMAP 92 depends on ARCH_OMAP
94 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 93 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
95 help 94 help
96 If you say yes here you get support for the TPS6501x series of 95 If you say yes here you get support for the TPS6501x series of
@@ -103,7 +102,7 @@ config TPS65010
103 102
104config SENSORS_M41T00 103config SENSORS_M41T00
105 tristate "ST M41T00 RTC chip" 104 tristate "ST M41T00 RTC chip"
106 depends on I2C && PPC32 105 depends on PPC32
107 help 106 help
108 If you say yes here you get support for the ST M41T00 RTC chip. 107 If you say yes here you get support for the ST M41T00 RTC chip.
109 108
@@ -112,7 +111,7 @@ config SENSORS_M41T00
112 111
113config SENSORS_MAX6875 112config SENSORS_MAX6875
114 tristate "Maxim MAX6875 Power supply supervisor" 113 tristate "Maxim MAX6875 Power supply supervisor"
115 depends on I2C && EXPERIMENTAL 114 depends on EXPERIMENTAL
116 help 115 help
117 If you say yes here you get support for the Maxim MAX6875 116 If you say yes here you get support for the Maxim MAX6875
118 EEPROM-programmable, quad power-supply sequencer/supervisor. 117 EEPROM-programmable, quad power-supply sequencer/supervisor.
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c
new file mode 100644
index 000000000000..ffb35f09df03
--- /dev/null
+++ b/drivers/i2c/i2c-boardinfo.c
@@ -0,0 +1,90 @@
1/*
2 * i2c-boardinfo.h - collect pre-declarations of I2C devices
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <linux/kernel.h>
20#include <linux/i2c.h>
21
22#include "i2c-core.h"
23
24
25/* These symbols are exported ONLY FOR the i2c core.
26 * No other users will be supported.
27 */
28DEFINE_MUTEX(__i2c_board_lock);
29EXPORT_SYMBOL_GPL(__i2c_board_lock);
30
31LIST_HEAD(__i2c_board_list);
32EXPORT_SYMBOL_GPL(__i2c_board_list);
33
34int __i2c_first_dynamic_bus_num;
35EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num);
36
37
38/**
39 * i2c_register_board_info - statically declare I2C devices
40 * @busnum: identifies the bus to which these devices belong
41 * @info: vector of i2c device descriptors
42 * @len: how many descriptors in the vector; may be zero to reserve
43 * the specified bus number.
44 *
45 * Systems using the Linux I2C driver stack can declare tables of board info
46 * while they initialize. This should be done in board-specific init code
47 * near arch_initcall() time, or equivalent, before any I2C adapter driver is
48 * registered. For example, mainboard init code could define several devices,
49 * as could the init code for each daughtercard in a board stack.
50 *
51 * The I2C devices will be created later, after the adapter for the relevant
52 * bus has been registered. After that moment, standard driver model tools
53 * are used to bind "new style" I2C drivers to the devices. The bus number
54 * for any device declared using this routine is not available for dynamic
55 * allocation.
56 *
57 * The board info passed can safely be __initdata, but be careful of embedded
58 * pointers (for platform_data, functions, etc) since that won't be copied.
59 */
60int __init
61i2c_register_board_info(int busnum,
62 struct i2c_board_info const *info, unsigned len)
63{
64 int status;
65
66 mutex_lock(&__i2c_board_lock);
67
68 /* dynamic bus numbers will be assigned after the last static one */
69 if (busnum >= __i2c_first_dynamic_bus_num)
70 __i2c_first_dynamic_bus_num = busnum + 1;
71
72 for (status = 0; len; len--, info++) {
73 struct i2c_devinfo *devinfo;
74
75 devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
76 if (!devinfo) {
77 pr_debug("i2c-core: can't register boardinfo!\n");
78 status = -ENOMEM;
79 break;
80 }
81
82 devinfo->busnum = busnum;
83 devinfo->board_info = *info;
84 list_add_tail(&devinfo->list, &__i2c_board_list);
85 }
86
87 mutex_unlock(&__i2c_board_lock);
88
89 return status;
90}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 21fe1406c8b4..64f8e56d300e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -35,29 +35,92 @@
35#include <linux/completion.h> 35#include <linux/completion.h>
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37 37
38#include "i2c-core.h"
39
38 40
39static LIST_HEAD(adapters); 41static LIST_HEAD(adapters);
40static LIST_HEAD(drivers); 42static LIST_HEAD(drivers);
41static DEFINE_MUTEX(core_lists); 43static DEFINE_MUTEX(core_lists);
42static DEFINE_IDR(i2c_adapter_idr); 44static DEFINE_IDR(i2c_adapter_idr);
43 45
46#define is_newstyle_driver(d) ((d)->probe || (d)->remove)
44 47
45/* ------------------------------------------------------------------------- */ 48/* ------------------------------------------------------------------------- */
46 49
47/* match always succeeds, as we want the probe() to tell if we really accept this match */
48static int i2c_device_match(struct device *dev, struct device_driver *drv) 50static int i2c_device_match(struct device *dev, struct device_driver *drv)
49{ 51{
50 return 1; 52 struct i2c_client *client = to_i2c_client(dev);
53 struct i2c_driver *driver = to_i2c_driver(drv);
54
55 /* make legacy i2c drivers bypass driver model probing entirely;
56 * such drivers scan each i2c adapter/bus themselves.
57 */
58 if (!is_newstyle_driver(driver))
59 return 0;
60
61 /* new style drivers use the same kind of driver matching policy
62 * as platform devices or SPI: compare device and driver IDs.
63 */
64 return strcmp(client->driver_name, drv->name) == 0;
65}
66
67#ifdef CONFIG_HOTPLUG
68
69/* uevent helps with hotplug: modprobe -q $(MODALIAS) */
70static int i2c_device_uevent(struct device *dev, char **envp, int num_envp,
71 char *buffer, int buffer_size)
72{
73 struct i2c_client *client = to_i2c_client(dev);
74 int i = 0, length = 0;
75
76 /* by definition, legacy drivers can't hotplug */
77 if (dev->driver || !client->driver_name)
78 return 0;
79
80 if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
81 "MODALIAS=%s", client->driver_name))
82 return -ENOMEM;
83 envp[i] = NULL;
84 dev_dbg(dev, "uevent\n");
85 return 0;
51} 86}
52 87
88#else
89#define i2c_device_uevent NULL
90#endif /* CONFIG_HOTPLUG */
91
53static int i2c_device_probe(struct device *dev) 92static int i2c_device_probe(struct device *dev)
54{ 93{
55 return -ENODEV; 94 struct i2c_client *client = to_i2c_client(dev);
95 struct i2c_driver *driver = to_i2c_driver(dev->driver);
96
97 if (!driver->probe)
98 return -ENODEV;
99 client->driver = driver;
100 dev_dbg(dev, "probe\n");
101 return driver->probe(client);
56} 102}
57 103
58static int i2c_device_remove(struct device *dev) 104static int i2c_device_remove(struct device *dev)
59{ 105{
60 return 0; 106 struct i2c_client *client = to_i2c_client(dev);
107 struct i2c_driver *driver;
108 int status;
109
110 if (!dev->driver)
111 return 0;
112
113 driver = to_i2c_driver(dev->driver);
114 if (driver->remove) {
115 dev_dbg(dev, "remove\n");
116 status = driver->remove(client);
117 } else {
118 dev->driver = NULL;
119 status = 0;
120 }
121 if (status == 0)
122 client->driver = NULL;
123 return status;
61} 124}
62 125
63static void i2c_device_shutdown(struct device *dev) 126static void i2c_device_shutdown(struct device *dev)
@@ -95,122 +158,184 @@ static int i2c_device_resume(struct device * dev)
95 return driver->resume(to_i2c_client(dev)); 158 return driver->resume(to_i2c_client(dev));
96} 159}
97 160
161static void i2c_client_release(struct device *dev)
162{
163 struct i2c_client *client = to_i2c_client(dev);
164 complete(&client->released);
165}
166
167static void i2c_client_dev_release(struct device *dev)
168{
169 kfree(to_i2c_client(dev));
170}
171
172static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
173{
174 struct i2c_client *client = to_i2c_client(dev);
175 return sprintf(buf, "%s\n", client->name);
176}
177
178static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
179{
180 struct i2c_client *client = to_i2c_client(dev);
181 return client->driver_name
182 ? sprintf(buf, "%s\n", client->driver_name)
183 : 0;
184}
185
186static struct device_attribute i2c_dev_attrs[] = {
187 __ATTR(name, S_IRUGO, show_client_name, NULL),
188 /* modalias helps coldplug: modprobe $(cat .../modalias) */
189 __ATTR(modalias, S_IRUGO, show_modalias, NULL),
190 { },
191};
192
98struct bus_type i2c_bus_type = { 193struct bus_type i2c_bus_type = {
99 .name = "i2c", 194 .name = "i2c",
195 .dev_attrs = i2c_dev_attrs,
100 .match = i2c_device_match, 196 .match = i2c_device_match,
197 .uevent = i2c_device_uevent,
101 .probe = i2c_device_probe, 198 .probe = i2c_device_probe,
102 .remove = i2c_device_remove, 199 .remove = i2c_device_remove,
103 .shutdown = i2c_device_shutdown, 200 .shutdown = i2c_device_shutdown,
104 .suspend = i2c_device_suspend, 201 .suspend = i2c_device_suspend,
105 .resume = i2c_device_resume, 202 .resume = i2c_device_resume,
106}; 203};
204EXPORT_SYMBOL_GPL(i2c_bus_type);
107 205
108/* ------------------------------------------------------------------------- */ 206/**
207 * i2c_new_device - instantiate an i2c device for use with a new style driver
208 * @adap: the adapter managing the device
209 * @info: describes one I2C device; bus_num is ignored
210 *
211 * Create a device to work with a new style i2c driver, where binding is
212 * handled through driver model probe()/remove() methods. This call is not
213 * appropriate for use by mainboad initialization logic, which usually runs
214 * during an arch_initcall() long before any i2c_adapter could exist.
215 *
216 * This returns the new i2c client, which may be saved for later use with
217 * i2c_unregister_device(); or NULL to indicate an error.
218 */
219struct i2c_client *
220i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
221{
222 struct i2c_client *client;
223 int status;
109 224
110void i2c_adapter_dev_release(struct device *dev) 225 client = kzalloc(sizeof *client, GFP_KERNEL);
226 if (!client)
227 return NULL;
228
229 client->adapter = adap;
230
231 client->dev.platform_data = info->platform_data;
232 client->flags = info->flags;
233 client->addr = info->addr;
234 client->irq = info->irq;
235
236 strlcpy(client->driver_name, info->driver_name,
237 sizeof(client->driver_name));
238 strlcpy(client->name, info->type, sizeof(client->name));
239
240 /* a new style driver may be bound to this device when we
241 * return from this function, or any later moment (e.g. maybe
242 * hotplugging will load the driver module). and the device
243 * refcount model is the standard driver model one.
244 */
245 status = i2c_attach_client(client);
246 if (status < 0) {
247 kfree(client);
248 client = NULL;
249 }
250 return client;
251}
252EXPORT_SYMBOL_GPL(i2c_new_device);
253
254
255/**
256 * i2c_unregister_device - reverse effect of i2c_new_device()
257 * @client: value returned from i2c_new_device()
258 */
259void i2c_unregister_device(struct i2c_client *client)
111{ 260{
112 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 261 struct i2c_adapter *adapter = client->adapter;
113 complete(&adap->dev_released); 262 struct i2c_driver *driver = client->driver;
263
264 if (driver && !is_newstyle_driver(driver)) {
265 dev_err(&client->dev, "can't unregister devices "
266 "with legacy drivers\n");
267 WARN_ON(1);
268 return;
269 }
270
271 mutex_lock(&adapter->clist_lock);
272 list_del(&client->list);
273 mutex_unlock(&adapter->clist_lock);
274
275 device_unregister(&client->dev);
114} 276}
277EXPORT_SYMBOL_GPL(i2c_unregister_device);
115 278
116struct device_driver i2c_adapter_driver = {
117 .owner = THIS_MODULE,
118 .name = "i2c_adapter",
119 .bus = &i2c_bus_type,
120};
121 279
122/* ------------------------------------------------------------------------- */ 280/* ------------------------------------------------------------------------- */
123 281
124/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 282/* I2C bus adapters -- one roots each I2C or SMBUS segment */
125 283
126static void i2c_adapter_class_dev_release(struct class_device *dev) 284void i2c_adapter_dev_release(struct device *dev)
127{ 285{
128 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev); 286 struct i2c_adapter *adap = to_i2c_adapter(dev);
129 complete(&adap->class_dev_released); 287 complete(&adap->dev_released);
130} 288}
289EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */
131 290
132static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf) 291static ssize_t
292show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
133{ 293{
134 struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev); 294 struct i2c_adapter *adap = to_i2c_adapter(dev);
135 return sprintf(buf, "%s\n", adap->name); 295 return sprintf(buf, "%s\n", adap->name);
136} 296}
137 297
138static struct class_device_attribute i2c_adapter_attrs[] = { 298static struct device_attribute i2c_adapter_attrs[] = {
139 __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL), 299 __ATTR(name, S_IRUGO, show_adapter_name, NULL),
140 { }, 300 { },
141}; 301};
142 302
143struct class i2c_adapter_class = { 303struct class i2c_adapter_class = {
144 .owner = THIS_MODULE, 304 .owner = THIS_MODULE,
145 .name = "i2c-adapter", 305 .name = "i2c-adapter",
146 .class_dev_attrs = i2c_adapter_attrs, 306 .dev_attrs = i2c_adapter_attrs,
147 .release = &i2c_adapter_class_dev_release,
148}; 307};
308EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */
149 309
150static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) 310static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
151{
152 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
153 return sprintf(buf, "%s\n", adap->name);
154}
155static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
156
157
158static void i2c_client_release(struct device *dev)
159{
160 struct i2c_client *client = to_i2c_client(dev);
161 complete(&client->released);
162}
163
164static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
165{ 311{
166 struct i2c_client *client = to_i2c_client(dev); 312 struct i2c_devinfo *devinfo;
167 return sprintf(buf, "%s\n", client->name); 313
314 mutex_lock(&__i2c_board_lock);
315 list_for_each_entry(devinfo, &__i2c_board_list, list) {
316 if (devinfo->busnum == adapter->nr
317 && !i2c_new_device(adapter,
318 &devinfo->board_info))
319 printk(KERN_ERR "i2c-core: can't create i2c%d-%04x\n",
320 i2c_adapter_id(adapter),
321 devinfo->board_info.addr);
322 }
323 mutex_unlock(&__i2c_board_lock);
168} 324}
169 325
170/* 326static int i2c_register_adapter(struct i2c_adapter *adap)
171 * We can't use the DEVICE_ATTR() macro here, as we used the same name for
172 * an i2c adapter attribute (above).
173 */
174static struct device_attribute dev_attr_client_name =
175 __ATTR(name, S_IRUGO, &show_client_name, NULL);
176
177
178/* ---------------------------------------------------
179 * registering functions
180 * ---------------------------------------------------
181 */
182
183/* -----
184 * i2c_add_adapter is called from within the algorithm layer,
185 * when a new hw adapter registers. A new device is register to be
186 * available for clients.
187 */
188int i2c_add_adapter(struct i2c_adapter *adap)
189{ 327{
190 int id, res = 0; 328 int res = 0;
191 struct list_head *item; 329 struct list_head *item;
192 struct i2c_driver *driver; 330 struct i2c_driver *driver;
193 331
194 mutex_lock(&core_lists);
195
196 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
197 res = -ENOMEM;
198 goto out_unlock;
199 }
200
201 res = idr_get_new(&i2c_adapter_idr, adap, &id);
202 if (res < 0) {
203 if (res == -EAGAIN)
204 res = -ENOMEM;
205 goto out_unlock;
206 }
207
208 adap->nr = id & MAX_ID_MASK;
209 mutex_init(&adap->bus_lock); 332 mutex_init(&adap->bus_lock);
210 mutex_init(&adap->clist_lock); 333 mutex_init(&adap->clist_lock);
211 list_add_tail(&adap->list,&adapters);
212 INIT_LIST_HEAD(&adap->clients); 334 INIT_LIST_HEAD(&adap->clients);
213 335
336 mutex_lock(&core_lists);
337 list_add_tail(&adap->list, &adapters);
338
214 /* Add the adapter to the driver core. 339 /* Add the adapter to the driver core.
215 * If the parent pointer is not set up, 340 * If the parent pointer is not set up,
216 * we add this adapter to the host bus. 341 * we add this adapter to the host bus.
@@ -221,27 +346,19 @@ int i2c_add_adapter(struct i2c_adapter *adap)
221 "physical device\n", adap->name); 346 "physical device\n", adap->name);
222 } 347 }
223 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 348 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
224 adap->dev.driver = &i2c_adapter_driver;
225 adap->dev.release = &i2c_adapter_dev_release; 349 adap->dev.release = &i2c_adapter_dev_release;
350 adap->dev.class = &i2c_adapter_class;
226 res = device_register(&adap->dev); 351 res = device_register(&adap->dev);
227 if (res) 352 if (res)
228 goto out_list; 353 goto out_list;
229 res = device_create_file(&adap->dev, &dev_attr_name);
230 if (res)
231 goto out_unregister;
232
233 /* Add this adapter to the i2c_adapter class */
234 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
235 adap->class_dev.dev = &adap->dev;
236 adap->class_dev.class = &i2c_adapter_class;
237 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
238 res = class_device_register(&adap->class_dev);
239 if (res)
240 goto out_remove_name;
241 354
242 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 355 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
243 356
244 /* inform drivers of new adapters */ 357 /* create pre-declared device nodes for new-style drivers */
358 if (adap->nr < __i2c_first_dynamic_bus_num)
359 i2c_scan_static_board_info(adap);
360
361 /* let legacy drivers scan this bus for matching devices */
245 list_for_each(item,&drivers) { 362 list_for_each(item,&drivers) {
246 driver = list_entry(item, struct i2c_driver, list); 363 driver = list_entry(item, struct i2c_driver, list);
247 if (driver->attach_adapter) 364 if (driver->attach_adapter)
@@ -253,18 +370,98 @@ out_unlock:
253 mutex_unlock(&core_lists); 370 mutex_unlock(&core_lists);
254 return res; 371 return res;
255 372
256out_remove_name:
257 device_remove_file(&adap->dev, &dev_attr_name);
258out_unregister:
259 init_completion(&adap->dev_released); /* Needed? */
260 device_unregister(&adap->dev);
261 wait_for_completion(&adap->dev_released);
262out_list: 373out_list:
263 list_del(&adap->list); 374 list_del(&adap->list);
264 idr_remove(&i2c_adapter_idr, adap->nr); 375 idr_remove(&i2c_adapter_idr, adap->nr);
265 goto out_unlock; 376 goto out_unlock;
266} 377}
267 378
379/**
380 * i2c_add_adapter - declare i2c adapter, use dynamic bus number
381 * @adapter: the adapter to add
382 *
383 * This routine is used to declare an I2C adapter when its bus number
384 * doesn't matter. Examples: for I2C adapters dynamically added by
385 * USB links or PCI plugin cards.
386 *
387 * When this returns zero, a new bus number was allocated and stored
388 * in adap->nr, and the specified adapter became available for clients.
389 * Otherwise, a negative errno value is returned.
390 */
391int i2c_add_adapter(struct i2c_adapter *adapter)
392{
393 int id, res = 0;
394
395retry:
396 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
397 return -ENOMEM;
398
399 mutex_lock(&core_lists);
400 /* "above" here means "above or equal to", sigh */
401 res = idr_get_new_above(&i2c_adapter_idr, adapter,
402 __i2c_first_dynamic_bus_num, &id);
403 mutex_unlock(&core_lists);
404
405 if (res < 0) {
406 if (res == -EAGAIN)
407 goto retry;
408 return res;
409 }
410
411 adapter->nr = id;
412 return i2c_register_adapter(adapter);
413}
414EXPORT_SYMBOL(i2c_add_adapter);
415
416/**
417 * i2c_add_numbered_adapter - declare i2c adapter, use static bus number
418 * @adap: the adapter to register (with adap->nr initialized)
419 *
420 * This routine is used to declare an I2C adapter when its bus number
421 * matters. Example: for I2C adapters from system-on-chip CPUs, or
422 * otherwise built in to the system's mainboard, and where i2c_board_info
423 * is used to properly configure I2C devices.
424 *
425 * If no devices have pre-been declared for this bus, then be sure to
426 * register the adapter before any dynamically allocated ones. Otherwise
427 * the required bus ID may not be available.
428 *
429 * When this returns zero, the specified adapter became available for
430 * clients using the bus number provided in adap->nr. Also, the table
431 * of I2C devices pre-declared using i2c_register_board_info() is scanned,
432 * and the appropriate driver model device nodes are created. Otherwise, a
433 * negative errno value is returned.
434 */
435int i2c_add_numbered_adapter(struct i2c_adapter *adap)
436{
437 int id;
438 int status;
439
440 if (adap->nr & ~MAX_ID_MASK)
441 return -EINVAL;
442
443retry:
444 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
445 return -ENOMEM;
446
447 mutex_lock(&core_lists);
448 /* "above" here means "above or equal to", sigh;
449 * we need the "equal to" result to force the result
450 */
451 status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id);
452 if (status == 0 && id != adap->nr) {
453 status = -EBUSY;
454 idr_remove(&i2c_adapter_idr, id);
455 }
456 mutex_unlock(&core_lists);
457 if (status == -EAGAIN)
458 goto retry;
459
460 if (status == 0)
461 status = i2c_register_adapter(adap);
462 return status;
463}
464EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
268 465
269int i2c_del_adapter(struct i2c_adapter *adap) 466int i2c_del_adapter(struct i2c_adapter *adap)
270{ 467{
@@ -302,9 +499,19 @@ int i2c_del_adapter(struct i2c_adapter *adap)
302 /* detach any active clients. This must be done first, because 499 /* detach any active clients. This must be done first, because
303 * it can fail; in which case we give up. */ 500 * it can fail; in which case we give up. */
304 list_for_each_safe(item, _n, &adap->clients) { 501 list_for_each_safe(item, _n, &adap->clients) {
502 struct i2c_driver *driver;
503
305 client = list_entry(item, struct i2c_client, list); 504 client = list_entry(item, struct i2c_client, list);
505 driver = client->driver;
506
507 /* new style, follow standard driver model */
508 if (!driver || is_newstyle_driver(driver)) {
509 i2c_unregister_device(client);
510 continue;
511 }
306 512
307 if ((res=client->driver->detach_client(client))) { 513 /* legacy drivers create and remove clients themselves */
514 if ((res = driver->detach_client(client))) {
308 dev_err(&adap->dev, "detach_client failed for client " 515 dev_err(&adap->dev, "detach_client failed for client "
309 "[%s] at address 0x%02x\n", client->name, 516 "[%s] at address 0x%02x\n", client->name,
310 client->addr); 517 client->addr);
@@ -314,17 +521,13 @@ int i2c_del_adapter(struct i2c_adapter *adap)
314 521
315 /* clean up the sysfs representation */ 522 /* clean up the sysfs representation */
316 init_completion(&adap->dev_released); 523 init_completion(&adap->dev_released);
317 init_completion(&adap->class_dev_released);
318 class_device_unregister(&adap->class_dev);
319 device_remove_file(&adap->dev, &dev_attr_name);
320 device_unregister(&adap->dev); 524 device_unregister(&adap->dev);
321 list_del(&adap->list); 525 list_del(&adap->list);
322 526
323 /* wait for sysfs to drop all references */ 527 /* wait for sysfs to drop all references */
324 wait_for_completion(&adap->dev_released); 528 wait_for_completion(&adap->dev_released);
325 wait_for_completion(&adap->class_dev_released);
326 529
327 /* free dynamically allocated bus id */ 530 /* free bus id */
328 idr_remove(&i2c_adapter_idr, adap->nr); 531 idr_remove(&i2c_adapter_idr, adap->nr);
329 532
330 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 533 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
@@ -333,24 +536,42 @@ int i2c_del_adapter(struct i2c_adapter *adap)
333 mutex_unlock(&core_lists); 536 mutex_unlock(&core_lists);
334 return res; 537 return res;
335} 538}
539EXPORT_SYMBOL(i2c_del_adapter);
540
336 541
542/* ------------------------------------------------------------------------- */
337 543
338/* ----- 544/*
339 * What follows is the "upwards" interface: commands for talking to clients, 545 * An i2c_driver is used with one or more i2c_client (device) nodes to access
340 * which implement the functions to access the physical information of the 546 * i2c slave chips, on a bus instance associated with some i2c_adapter. There
341 * chips. 547 * are two models for binding the driver to its device: "new style" drivers
548 * follow the standard Linux driver model and just respond to probe() calls
549 * issued if the driver core sees they match(); "legacy" drivers create device
550 * nodes themselves.
342 */ 551 */
343 552
344int i2c_register_driver(struct module *owner, struct i2c_driver *driver) 553int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
345{ 554{
346 struct list_head *item;
347 struct i2c_adapter *adapter;
348 int res; 555 int res;
349 556
557 /* new style driver methods can't mix with legacy ones */
558 if (is_newstyle_driver(driver)) {
559 if (driver->attach_adapter || driver->detach_adapter
560 || driver->detach_client) {
561 printk(KERN_WARNING
562 "i2c-core: driver [%s] is confused\n",
563 driver->driver.name);
564 return -EINVAL;
565 }
566 }
567
350 /* add the driver to the list of i2c drivers in the driver core */ 568 /* add the driver to the list of i2c drivers in the driver core */
351 driver->driver.owner = owner; 569 driver->driver.owner = owner;
352 driver->driver.bus = &i2c_bus_type; 570 driver->driver.bus = &i2c_bus_type;
353 571
572 /* for new style drivers, when registration returns the driver core
573 * will have called probe() for all matching-but-unbound devices.
574 */
354 res = driver_register(&driver->driver); 575 res = driver_register(&driver->driver);
355 if (res) 576 if (res)
356 return res; 577 return res;
@@ -360,10 +581,11 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
360 list_add_tail(&driver->list,&drivers); 581 list_add_tail(&driver->list,&drivers);
361 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 582 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
362 583
363 /* now look for instances of driver on our adapters */ 584 /* legacy drivers scan i2c busses directly */
364 if (driver->attach_adapter) { 585 if (driver->attach_adapter) {
365 list_for_each(item,&adapters) { 586 struct i2c_adapter *adapter;
366 adapter = list_entry(item, struct i2c_adapter, list); 587
588 list_for_each_entry(adapter, &adapters, list) {
367 driver->attach_adapter(adapter); 589 driver->attach_adapter(adapter);
368 } 590 }
369 } 591 }
@@ -373,16 +595,22 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
373} 595}
374EXPORT_SYMBOL(i2c_register_driver); 596EXPORT_SYMBOL(i2c_register_driver);
375 597
376int i2c_del_driver(struct i2c_driver *driver) 598/**
599 * i2c_del_driver - unregister I2C driver
600 * @driver: the driver being unregistered
601 */
602void i2c_del_driver(struct i2c_driver *driver)
377{ 603{
378 struct list_head *item1, *item2, *_n; 604 struct list_head *item1, *item2, *_n;
379 struct i2c_client *client; 605 struct i2c_client *client;
380 struct i2c_adapter *adap; 606 struct i2c_adapter *adap;
381 607
382 int res = 0;
383
384 mutex_lock(&core_lists); 608 mutex_lock(&core_lists);
385 609
610 /* new-style driver? */
611 if (is_newstyle_driver(driver))
612 goto unregister;
613
386 /* Have a look at each adapter, if clients of this driver are still 614 /* Have a look at each adapter, if clients of this driver are still
387 * attached. If so, detach them to be able to kill the driver 615 * attached. If so, detach them to be able to kill the driver
388 * afterwards. 616 * afterwards.
@@ -390,11 +618,10 @@ int i2c_del_driver(struct i2c_driver *driver)
390 list_for_each(item1,&adapters) { 618 list_for_each(item1,&adapters) {
391 adap = list_entry(item1, struct i2c_adapter, list); 619 adap = list_entry(item1, struct i2c_adapter, list);
392 if (driver->detach_adapter) { 620 if (driver->detach_adapter) {
393 if ((res = driver->detach_adapter(adap))) { 621 if (driver->detach_adapter(adap)) {
394 dev_err(&adap->dev, "detach_adapter failed " 622 dev_err(&adap->dev, "detach_adapter failed "
395 "for driver [%s]\n", 623 "for driver [%s]\n",
396 driver->driver.name); 624 driver->driver.name);
397 goto out_unlock;
398 } 625 }
399 } else { 626 } else {
400 list_for_each_safe(item2, _n, &adap->clients) { 627 list_for_each_safe(item2, _n, &adap->clients) {
@@ -404,25 +631,26 @@ int i2c_del_driver(struct i2c_driver *driver)
404 dev_dbg(&adap->dev, "detaching client [%s] " 631 dev_dbg(&adap->dev, "detaching client [%s] "
405 "at 0x%02x\n", client->name, 632 "at 0x%02x\n", client->name,
406 client->addr); 633 client->addr);
407 if ((res = driver->detach_client(client))) { 634 if (driver->detach_client(client)) {
408 dev_err(&adap->dev, "detach_client " 635 dev_err(&adap->dev, "detach_client "
409 "failed for client [%s] at " 636 "failed for client [%s] at "
410 "0x%02x\n", client->name, 637 "0x%02x\n", client->name,
411 client->addr); 638 client->addr);
412 goto out_unlock;
413 } 639 }
414 } 640 }
415 } 641 }
416 } 642 }
417 643
644 unregister:
418 driver_unregister(&driver->driver); 645 driver_unregister(&driver->driver);
419 list_del(&driver->list); 646 list_del(&driver->list);
420 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 647 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
421 648
422 out_unlock:
423 mutex_unlock(&core_lists); 649 mutex_unlock(&core_lists);
424 return 0;
425} 650}
651EXPORT_SYMBOL(i2c_del_driver);
652
653/* ------------------------------------------------------------------------- */
426 654
427static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr) 655static int __i2c_check_addr(struct i2c_adapter *adapter, unsigned int addr)
428{ 656{
@@ -447,6 +675,7 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
447 675
448 return rval; 676 return rval;
449} 677}
678EXPORT_SYMBOL(i2c_check_addr);
450 679
451int i2c_attach_client(struct i2c_client *client) 680int i2c_attach_client(struct i2c_client *client)
452{ 681{
@@ -463,9 +692,15 @@ int i2c_attach_client(struct i2c_client *client)
463 client->usage_count = 0; 692 client->usage_count = 0;
464 693
465 client->dev.parent = &client->adapter->dev; 694 client->dev.parent = &client->adapter->dev;
466 client->dev.driver = &client->driver->driver;
467 client->dev.bus = &i2c_bus_type; 695 client->dev.bus = &i2c_bus_type;
468 client->dev.release = &i2c_client_release; 696
697 if (client->driver)
698 client->dev.driver = &client->driver->driver;
699
700 if (client->driver && !is_newstyle_driver(client->driver))
701 client->dev.release = i2c_client_release;
702 else
703 client->dev.release = i2c_client_dev_release;
469 704
470 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 705 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
471 "%d-%04x", i2c_adapter_id(adapter), client->addr); 706 "%d-%04x", i2c_adapter_id(adapter), client->addr);
@@ -474,9 +709,6 @@ int i2c_attach_client(struct i2c_client *client)
474 res = device_register(&client->dev); 709 res = device_register(&client->dev);
475 if (res) 710 if (res)
476 goto out_list; 711 goto out_list;
477 res = device_create_file(&client->dev, &dev_attr_client_name);
478 if (res)
479 goto out_unregister;
480 mutex_unlock(&adapter->clist_lock); 712 mutex_unlock(&adapter->clist_lock);
481 713
482 if (adapter->client_register) { 714 if (adapter->client_register) {
@@ -489,10 +721,6 @@ int i2c_attach_client(struct i2c_client *client)
489 721
490 return 0; 722 return 0;
491 723
492out_unregister:
493 init_completion(&client->released); /* Needed? */
494 device_unregister(&client->dev);
495 wait_for_completion(&client->released);
496out_list: 724out_list:
497 list_del(&client->list); 725 list_del(&client->list);
498 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " 726 dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
@@ -501,7 +729,7 @@ out_unlock:
501 mutex_unlock(&adapter->clist_lock); 729 mutex_unlock(&adapter->clist_lock);
502 return res; 730 return res;
503} 731}
504 732EXPORT_SYMBOL(i2c_attach_client);
505 733
506int i2c_detach_client(struct i2c_client *client) 734int i2c_detach_client(struct i2c_client *client)
507{ 735{
@@ -527,7 +755,6 @@ int i2c_detach_client(struct i2c_client *client)
527 mutex_lock(&adapter->clist_lock); 755 mutex_lock(&adapter->clist_lock);
528 list_del(&client->list); 756 list_del(&client->list);
529 init_completion(&client->released); 757 init_completion(&client->released);
530 device_remove_file(&client->dev, &dev_attr_client_name);
531 device_unregister(&client->dev); 758 device_unregister(&client->dev);
532 mutex_unlock(&adapter->clist_lock); 759 mutex_unlock(&adapter->clist_lock);
533 wait_for_completion(&client->released); 760 wait_for_completion(&client->released);
@@ -535,6 +762,7 @@ int i2c_detach_client(struct i2c_client *client)
535 out: 762 out:
536 return res; 763 return res;
537} 764}
765EXPORT_SYMBOL(i2c_detach_client);
538 766
539static int i2c_inc_use_client(struct i2c_client *client) 767static int i2c_inc_use_client(struct i2c_client *client)
540{ 768{
@@ -567,6 +795,7 @@ int i2c_use_client(struct i2c_client *client)
567 795
568 return 0; 796 return 0;
569} 797}
798EXPORT_SYMBOL(i2c_use_client);
570 799
571int i2c_release_client(struct i2c_client *client) 800int i2c_release_client(struct i2c_client *client)
572{ 801{
@@ -581,6 +810,7 @@ int i2c_release_client(struct i2c_client *client)
581 810
582 return 0; 811 return 0;
583} 812}
813EXPORT_SYMBOL(i2c_release_client);
584 814
585void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg) 815void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
586{ 816{
@@ -601,6 +831,7 @@ void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
601 } 831 }
602 mutex_unlock(&adap->clist_lock); 832 mutex_unlock(&adap->clist_lock);
603} 833}
834EXPORT_SYMBOL(i2c_clients_command);
604 835
605static int __init i2c_init(void) 836static int __init i2c_init(void)
606{ 837{
@@ -609,16 +840,12 @@ static int __init i2c_init(void)
609 retval = bus_register(&i2c_bus_type); 840 retval = bus_register(&i2c_bus_type);
610 if (retval) 841 if (retval)
611 return retval; 842 return retval;
612 retval = driver_register(&i2c_adapter_driver);
613 if (retval)
614 return retval;
615 return class_register(&i2c_adapter_class); 843 return class_register(&i2c_adapter_class);
616} 844}
617 845
618static void __exit i2c_exit(void) 846static void __exit i2c_exit(void)
619{ 847{
620 class_unregister(&i2c_adapter_class); 848 class_unregister(&i2c_adapter_class);
621 driver_unregister(&i2c_adapter_driver);
622 bus_unregister(&i2c_bus_type); 849 bus_unregister(&i2c_bus_type);
623} 850}
624 851
@@ -638,8 +865,9 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
638#ifdef DEBUG 865#ifdef DEBUG
639 for (ret = 0; ret < num; ret++) { 866 for (ret = 0; ret < num; ret++) {
640 dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, " 867 dev_dbg(&adap->dev, "master_xfer[%d] %c, addr=0x%02x, "
641 "len=%d\n", ret, msgs[ret].flags & I2C_M_RD ? 868 "len=%d%s\n", ret, (msgs[ret].flags & I2C_M_RD)
642 'R' : 'W', msgs[ret].addr, msgs[ret].len); 869 ? 'R' : 'W', msgs[ret].addr, msgs[ret].len,
870 (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "");
643 } 871 }
644#endif 872#endif
645 873
@@ -653,6 +881,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
653 return -ENOSYS; 881 return -ENOSYS;
654 } 882 }
655} 883}
884EXPORT_SYMBOL(i2c_transfer);
656 885
657int i2c_master_send(struct i2c_client *client,const char *buf ,int count) 886int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
658{ 887{
@@ -671,6 +900,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
671 transmitted, else error code. */ 900 transmitted, else error code. */
672 return (ret == 1) ? count : ret; 901 return (ret == 1) ? count : ret;
673} 902}
903EXPORT_SYMBOL(i2c_master_send);
674 904
675int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 905int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
676{ 906{
@@ -690,7 +920,7 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
690 transmitted, else error code. */ 920 transmitted, else error code. */
691 return (ret == 1) ? count : ret; 921 return (ret == 1) ? count : ret;
692} 922}
693 923EXPORT_SYMBOL(i2c_master_recv);
694 924
695int i2c_control(struct i2c_client *client, 925int i2c_control(struct i2c_client *client,
696 unsigned int cmd, unsigned long arg) 926 unsigned int cmd, unsigned long arg)
@@ -712,6 +942,7 @@ int i2c_control(struct i2c_client *client,
712 } 942 }
713 return ret; 943 return ret;
714} 944}
945EXPORT_SYMBOL(i2c_control);
715 946
716/* ---------------------------------------------------- 947/* ----------------------------------------------------
717 * the i2c address scanning function 948 * the i2c address scanning function
@@ -853,6 +1084,70 @@ int i2c_probe(struct i2c_adapter *adapter,
853 1084
854 return 0; 1085 return 0;
855} 1086}
1087EXPORT_SYMBOL(i2c_probe);
1088
1089struct i2c_client *
1090i2c_new_probed_device(struct i2c_adapter *adap,
1091 struct i2c_board_info *info,
1092 unsigned short const *addr_list)
1093{
1094 int i;
1095
1096 /* Stop here if the bus doesn't support probing */
1097 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) {
1098 dev_err(&adap->dev, "Probing not supported\n");
1099 return NULL;
1100 }
1101
1102 mutex_lock(&adap->clist_lock);
1103 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1104 /* Check address validity */
1105 if (addr_list[i] < 0x03 || addr_list[i] > 0x77) {
1106 dev_warn(&adap->dev, "Invalid 7-bit address "
1107 "0x%02x\n", addr_list[i]);
1108 continue;
1109 }
1110
1111 /* Check address availability */
1112 if (__i2c_check_addr(adap, addr_list[i])) {
1113 dev_dbg(&adap->dev, "Address 0x%02x already in "
1114 "use, not probing\n", addr_list[i]);
1115 continue;
1116 }
1117
1118 /* Test address responsiveness
1119 The default probe method is a quick write, but it is known
1120 to corrupt the 24RF08 EEPROMs due to a state machine bug,
1121 and could also irreversibly write-protect some EEPROMs, so
1122 for address ranges 0x30-0x37 and 0x50-0x5f, we use a byte
1123 read instead. Also, some bus drivers don't implement
1124 quick write, so we fallback to a byte read it that case
1125 too. */
1126 if ((addr_list[i] & ~0x07) == 0x30
1127 || (addr_list[i] & ~0x0f) == 0x50
1128 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
1129 if (i2c_smbus_xfer(adap, addr_list[i], 0,
1130 I2C_SMBUS_READ, 0,
1131 I2C_SMBUS_BYTE, NULL) >= 0)
1132 break;
1133 } else {
1134 if (i2c_smbus_xfer(adap, addr_list[i], 0,
1135 I2C_SMBUS_WRITE, 0,
1136 I2C_SMBUS_QUICK, NULL) >= 0)
1137 break;
1138 }
1139 }
1140 mutex_unlock(&adap->clist_lock);
1141
1142 if (addr_list[i] == I2C_CLIENT_END) {
1143 dev_dbg(&adap->dev, "Probing failed, no device found\n");
1144 return NULL;
1145 }
1146
1147 info->addr = addr_list[i];
1148 return i2c_new_device(adap, info);
1149}
1150EXPORT_SYMBOL_GPL(i2c_new_probed_device);
856 1151
857struct i2c_adapter* i2c_get_adapter(int id) 1152struct i2c_adapter* i2c_get_adapter(int id)
858{ 1153{
@@ -866,11 +1161,13 @@ struct i2c_adapter* i2c_get_adapter(int id)
866 mutex_unlock(&core_lists); 1161 mutex_unlock(&core_lists);
867 return adapter; 1162 return adapter;
868} 1163}
1164EXPORT_SYMBOL(i2c_get_adapter);
869 1165
870void i2c_put_adapter(struct i2c_adapter *adap) 1166void i2c_put_adapter(struct i2c_adapter *adap)
871{ 1167{
872 module_put(adap->owner); 1168 module_put(adap->owner);
873} 1169}
1170EXPORT_SYMBOL(i2c_put_adapter);
874 1171
875/* The SMBus parts */ 1172/* The SMBus parts */
876 1173
@@ -939,6 +1236,7 @@ s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value)
939 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1236 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
940 value,0,I2C_SMBUS_QUICK,NULL); 1237 value,0,I2C_SMBUS_QUICK,NULL);
941} 1238}
1239EXPORT_SYMBOL(i2c_smbus_write_quick);
942 1240
943s32 i2c_smbus_read_byte(struct i2c_client *client) 1241s32 i2c_smbus_read_byte(struct i2c_client *client)
944{ 1242{
@@ -949,12 +1247,14 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
949 else 1247 else
950 return data.byte; 1248 return data.byte;
951} 1249}
1250EXPORT_SYMBOL(i2c_smbus_read_byte);
952 1251
953s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1252s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
954{ 1253{
955 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1254 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
956 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); 1255 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
957} 1256}
1257EXPORT_SYMBOL(i2c_smbus_write_byte);
958 1258
959s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1259s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
960{ 1260{
@@ -965,6 +1265,7 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
965 else 1265 else
966 return data.byte; 1266 return data.byte;
967} 1267}
1268EXPORT_SYMBOL(i2c_smbus_read_byte_data);
968 1269
969s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1270s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
970{ 1271{
@@ -974,6 +1275,7 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
974 I2C_SMBUS_WRITE,command, 1275 I2C_SMBUS_WRITE,command,
975 I2C_SMBUS_BYTE_DATA,&data); 1276 I2C_SMBUS_BYTE_DATA,&data);
976} 1277}
1278EXPORT_SYMBOL(i2c_smbus_write_byte_data);
977 1279
978s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1280s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
979{ 1281{
@@ -984,6 +1286,7 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
984 else 1286 else
985 return data.word; 1287 return data.word;
986} 1288}
1289EXPORT_SYMBOL(i2c_smbus_read_word_data);
987 1290
988s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1291s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
989{ 1292{
@@ -993,6 +1296,23 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
993 I2C_SMBUS_WRITE,command, 1296 I2C_SMBUS_WRITE,command,
994 I2C_SMBUS_WORD_DATA,&data); 1297 I2C_SMBUS_WORD_DATA,&data);
995} 1298}
1299EXPORT_SYMBOL(i2c_smbus_write_word_data);
1300
1301/* Returns the number of read bytes */
1302s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
1303 u8 *values)
1304{
1305 union i2c_smbus_data data;
1306
1307 if (i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1308 I2C_SMBUS_READ, command,
1309 I2C_SMBUS_BLOCK_DATA, &data))
1310 return -1;
1311
1312 memcpy(values, &data.block[1], data.block[0]);
1313 return data.block[0];
1314}
1315EXPORT_SYMBOL(i2c_smbus_read_block_data);
996 1316
997s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1317s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
998 u8 length, const u8 *values) 1318 u8 length, const u8 *values)
@@ -1007,6 +1327,7 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1007 I2C_SMBUS_WRITE,command, 1327 I2C_SMBUS_WRITE,command,
1008 I2C_SMBUS_BLOCK_DATA,&data); 1328 I2C_SMBUS_BLOCK_DATA,&data);
1009} 1329}
1330EXPORT_SYMBOL(i2c_smbus_write_block_data);
1010 1331
1011/* Returns the number of read bytes */ 1332/* Returns the number of read bytes */
1012s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) 1333s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
@@ -1021,6 +1342,7 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *val
1021 memcpy(values, &data.block[1], data.block[0]); 1342 memcpy(values, &data.block[1], data.block[0]);
1022 return data.block[0]; 1343 return data.block[0];
1023} 1344}
1345EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1024 1346
1025s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 1347s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
1026 u8 length, const u8 *values) 1348 u8 length, const u8 *values)
@@ -1035,6 +1357,7 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
1035 I2C_SMBUS_WRITE, command, 1357 I2C_SMBUS_WRITE, command,
1036 I2C_SMBUS_I2C_BLOCK_DATA, &data); 1358 I2C_SMBUS_I2C_BLOCK_DATA, &data);
1037} 1359}
1360EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
1038 1361
1039/* Simulate a SMBus command using the i2c protocol 1362/* Simulate a SMBus command using the i2c protocol
1040 No checking of parameters is done! */ 1363 No checking of parameters is done! */
@@ -1098,9 +1421,9 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1098 break; 1421 break;
1099 case I2C_SMBUS_BLOCK_DATA: 1422 case I2C_SMBUS_BLOCK_DATA:
1100 if (read_write == I2C_SMBUS_READ) { 1423 if (read_write == I2C_SMBUS_READ) {
1101 dev_err(&adapter->dev, "Block read not supported " 1424 msg[1].flags |= I2C_M_RECV_LEN;
1102 "under I2C emulation!\n"); 1425 msg[1].len = 1; /* block length will be added by
1103 return -1; 1426 the underlying bus driver */
1104 } else { 1427 } else {
1105 msg[0].len = data->block[0] + 2; 1428 msg[0].len = data->block[0] + 2;
1106 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { 1429 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
@@ -1114,9 +1437,21 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1114 } 1437 }
1115 break; 1438 break;
1116 case I2C_SMBUS_BLOCK_PROC_CALL: 1439 case I2C_SMBUS_BLOCK_PROC_CALL:
1117 dev_dbg(&adapter->dev, "Block process call not supported " 1440 num = 2; /* Another special case */
1118 "under I2C emulation!\n"); 1441 read_write = I2C_SMBUS_READ;
1119 return -1; 1442 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
1443 dev_err(&adapter->dev, "%s called with invalid "
1444 "block proc call size (%d)\n", __FUNCTION__,
1445 data->block[0]);
1446 return -1;
1447 }
1448 msg[0].len = data->block[0] + 2;
1449 for (i = 1; i < msg[0].len; i++)
1450 msgbuf0[i] = data->block[i-1];
1451 msg[1].flags |= I2C_M_RECV_LEN;
1452 msg[1].len = 1; /* block length will be added by
1453 the underlying bus driver */
1454 break;
1120 case I2C_SMBUS_I2C_BLOCK_DATA: 1455 case I2C_SMBUS_I2C_BLOCK_DATA:
1121 if (read_write == I2C_SMBUS_READ) { 1456 if (read_write == I2C_SMBUS_READ) {
1122 msg[1].len = I2C_SMBUS_BLOCK_MAX; 1457 msg[1].len = I2C_SMBUS_BLOCK_MAX;
@@ -1180,6 +1515,11 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1180 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 1515 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
1181 data->block[i+1] = msgbuf1[i]; 1516 data->block[i+1] = msgbuf1[i];
1182 break; 1517 break;
1518 case I2C_SMBUS_BLOCK_DATA:
1519 case I2C_SMBUS_BLOCK_PROC_CALL:
1520 for (i = 0; i < msgbuf1[0] + 1; i++)
1521 data->block[i] = msgbuf1[i];
1522 break;
1183 } 1523 }
1184 return 0; 1524 return 0;
1185} 1525}
@@ -1204,43 +1544,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1204 1544
1205 return res; 1545 return res;
1206} 1546}
1207
1208
1209/* Next four are needed by i2c-isa */
1210EXPORT_SYMBOL_GPL(i2c_adapter_dev_release);
1211EXPORT_SYMBOL_GPL(i2c_adapter_driver);
1212EXPORT_SYMBOL_GPL(i2c_adapter_class);
1213EXPORT_SYMBOL_GPL(i2c_bus_type);
1214
1215EXPORT_SYMBOL(i2c_add_adapter);
1216EXPORT_SYMBOL(i2c_del_adapter);
1217EXPORT_SYMBOL(i2c_del_driver);
1218EXPORT_SYMBOL(i2c_attach_client);
1219EXPORT_SYMBOL(i2c_detach_client);
1220EXPORT_SYMBOL(i2c_use_client);
1221EXPORT_SYMBOL(i2c_release_client);
1222EXPORT_SYMBOL(i2c_clients_command);
1223EXPORT_SYMBOL(i2c_check_addr);
1224
1225EXPORT_SYMBOL(i2c_master_send);
1226EXPORT_SYMBOL(i2c_master_recv);
1227EXPORT_SYMBOL(i2c_control);
1228EXPORT_SYMBOL(i2c_transfer);
1229EXPORT_SYMBOL(i2c_get_adapter);
1230EXPORT_SYMBOL(i2c_put_adapter);
1231EXPORT_SYMBOL(i2c_probe);
1232
1233EXPORT_SYMBOL(i2c_smbus_xfer); 1547EXPORT_SYMBOL(i2c_smbus_xfer);
1234EXPORT_SYMBOL(i2c_smbus_write_quick);
1235EXPORT_SYMBOL(i2c_smbus_read_byte);
1236EXPORT_SYMBOL(i2c_smbus_write_byte);
1237EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1238EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1239EXPORT_SYMBOL(i2c_smbus_read_word_data);
1240EXPORT_SYMBOL(i2c_smbus_write_word_data);
1241EXPORT_SYMBOL(i2c_smbus_write_block_data);
1242EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
1243EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data);
1244 1548
1245MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 1549MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
1246MODULE_DESCRIPTION("I2C-Bus main module"); 1550MODULE_DESCRIPTION("I2C-Bus main module");
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
new file mode 100644
index 000000000000..cd5bff874855
--- /dev/null
+++ b/drivers/i2c/i2c-core.h
@@ -0,0 +1,31 @@
1/*
2 * i2c-core.h - interfaces internal to the I2C framework
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19struct i2c_devinfo {
20 struct list_head list;
21 int busnum;
22 struct i2c_board_info board_info;
23};
24
25/* board_lock protects board_list and first_dynamic_bus_num.
26 * only i2c core components are allowed to use these symbols.
27 */
28extern struct mutex __i2c_board_lock;
29extern struct list_head __i2c_board_list;
30extern int __i2c_first_dynamic_bus_num;
31
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index f17e9c7d4b36..c845d5c4cbba 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -164,6 +164,17 @@ config KEYBOARD_AMIGA
164 To compile this driver as a module, choose M here: the 164 To compile this driver as a module, choose M here: the
165 module will be called amikbd. 165 module will be called amikbd.
166 166
167config KEYBOARD_ATARI
168 tristate "Atari keyboard"
169 depends on ATARI
170 select ATARI_KBD_CORE
171 help
172 Say Y here if you are running Linux on any Atari and have a keyboard
173 attached.
174
175 To compile this driver as a module, choose M here: the
176 module will be called atakbd.
177
167config KEYBOARD_HIL_OLD 178config KEYBOARD_HIL_OLD
168 tristate "HP HIL keyboard support (simple driver)" 179 tristate "HP HIL keyboard support (simple driver)"
169 depends on GSC || HP300 180 depends on GSC || HP300
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 586a0fe53be6..7aa59ee5a0b6 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
9obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o 9obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
10obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o 10obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o
11obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o 11obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o
12obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o
12obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o 13obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
13obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 14obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
14obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 15obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
diff --git a/drivers/input/keyboard/atakbd.c b/drivers/input/keyboard/atakbd.c
new file mode 100644
index 000000000000..ded1d6ac6ff3
--- /dev/null
+++ b/drivers/input/keyboard/atakbd.c
@@ -0,0 +1,134 @@
1/*
2 * atakbd.c
3 *
4 * Copyright (c) 2005 Michael Schmitz
5 *
6 * Based on amikbd.c, which is
7 *
8 * Copyright (c) 2000-2001 Vojtech Pavlik
9 *
10 * Based on the work of:
11 * Hamish Macdonald
12 */
13
14/*
15 * Atari keyboard driver for Linux/m68k
16 *
17 * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
18 * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
19 * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
20 * This driver only deals with handing key events off to the input layer.
21 */
22
23/*
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 *
38 * Should you need to contact me, the author, you can do so either by
39 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
40 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
41 */
42
43#include <linux/module.h>
44#include <linux/init.h>
45#include <linux/input.h>
46#include <linux/delay.h>
47#include <linux/interrupt.h>
48
49#include <asm/atariints.h>
50#include <asm/atarihw.h>
51#include <asm/atarikb.h>
52#include <asm/irq.h>
53
54MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
55MODULE_DESCRIPTION("Atari keyboard driver");
56MODULE_LICENSE("GPL");
57
58static unsigned char atakbd_keycode[0x72];
59
60static struct input_dev *atakbd_dev;
61
62static void atakbd_interrupt(unsigned char scancode, char down)
63{
64
65 if (scancode < 0x72) { /* scancodes < 0xf2 are keys */
66
67 // report raw events here?
68
69 scancode = atakbd_keycode[scancode];
70
71 if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */
72 input_report_key(atakbd_dev, scancode, 1);
73 input_report_key(atakbd_dev, scancode, 0);
74 input_sync(atakbd_dev);
75 } else {
76 input_report_key(atakbd_dev, scancode, down);
77 input_sync(atakbd_dev);
78 }
79 } else /* scancodes >= 0xf2 are mouse data, most likely */
80 printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
81
82 return;
83}
84
85static int __init atakbd_init(void)
86{
87 int i;
88
89 if (!ATARIHW_PRESENT(ST_MFP))
90 return -EIO;
91
92 // TODO: request_mem_region if not done in arch code
93
94 if (!(atakbd_dev = input_allocate_device()))
95 return -ENOMEM;
96
97 // need to init core driver if not already done so
98 if (atari_keyb_init())
99 return -ENODEV;
100
101 atakbd_dev->name = "Atari Keyboard";
102 atakbd_dev->phys = "atakbd/input0";
103 atakbd_dev->id.bustype = BUS_ATARI;
104 atakbd_dev->id.vendor = 0x0001;
105 atakbd_dev->id.product = 0x0001;
106 atakbd_dev->id.version = 0x0100;
107
108 atakbd_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
109 atakbd_dev->keycode = atakbd_keycode;
110 atakbd_dev->keycodesize = sizeof(unsigned char);
111 atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
112
113 for (i = 1; i < 0x72; i++) {
114 atakbd_keycode[i] = i;
115 set_bit(atakbd_keycode[i], atakbd_dev->keybit);
116 }
117
118 input_register_device(atakbd_dev);
119
120 atari_input_keyboard_interrupt_hook = atakbd_interrupt;
121
122 printk(KERN_INFO "input: %s at IKBD ACIA\n", atakbd_dev->name);
123
124 return 0;
125}
126
127static void __exit atakbd_exit(void)
128{
129 atari_input_keyboard_interrupt_hook = NULL;
130 input_unregister_device(atakbd_dev);
131}
132
133module_init(atakbd_init);
134module_exit(atakbd_exit);
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index 4de4dc297d50..56277fb291cd 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -52,7 +52,7 @@ MODULE_LICENSE("GPL v2");
52 52
53#elif defined(CONFIG_HP300) 53#elif defined(CONFIG_HP300)
54 54
55 #define HILBASE 0xf0428000 /* HP300 (m86k) port address */ 55 #define HILBASE 0xf0428000UL /* HP300 (m68k) port address */
56 #define HIL_DATA 0x1 56 #define HIL_DATA 0x1
57 #define HIL_CMD 0x3 57 #define HIL_CMD 0x3
58 #define HIL_IRQ 2 58 #define HIL_IRQ 2
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 35d998c3e578..b40784a60aa1 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -96,6 +96,17 @@ config MOUSE_AMIGA
96 To compile this driver as a module, choose M here: the 96 To compile this driver as a module, choose M here: the
97 module will be called amimouse. 97 module will be called amimouse.
98 98
99config MOUSE_ATARI
100 tristate "Atari mouse"
101 depends on ATARI
102 select ATARI_KBD_CORE
103 help
104 Say Y here if you have an Atari and want its native mouse
105 supported by the kernel.
106
107 To compile this driver as a module, choose M here: the
108 module will be called atarimouse.
109
99config MOUSE_RISCPC 110config MOUSE_RISCPC
100 tristate "Acorn RiscPC mouse" 111 tristate "Acorn RiscPC mouse"
101 depends on ARCH_ACORN 112 depends on ARCH_ACORN
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 21a1de61a79b..700f61200dfc 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -5,6 +5,7 @@
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_MOUSE_AMIGA) += amimouse.o 7obj-$(CONFIG_MOUSE_AMIGA) += amimouse.o
8obj-$(CONFIG_MOUSE_ATARI) += atarimouse.o
8obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o 9obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o
9obj-$(CONFIG_MOUSE_INPORT) += inport.o 10obj-$(CONFIG_MOUSE_INPORT) += inport.o
10obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o 11obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/atarimouse.c b/drivers/input/mouse/atarimouse.c
new file mode 100644
index 000000000000..43ab6566fb65
--- /dev/null
+++ b/drivers/input/mouse/atarimouse.c
@@ -0,0 +1,160 @@
1/*
2 * Atari mouse driver for Linux/m68k
3 *
4 * Copyright (c) 2005 Michael Schmitz
5 *
6 * Based on:
7 * Amiga mouse driver for Linux/m68k
8 *
9 * Copyright (c) 2000-2002 Vojtech Pavlik
10 *
11 */
12/*
13 * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
14 * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
15 * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
16 * This driver only deals with handing key events off to the input layer.
17 *
18 * Largely based on the old:
19 *
20 * Atari Mouse Driver for Linux
21 * by Robert de Vries (robert@and.nl) 19Jul93
22 *
23 * 16 Nov 1994 Andreas Schwab
24 * Compatibility with busmouse
25 * Support for three button mouse (shamelessly stolen from MiNT)
26 * third button wired to one of the joystick directions on joystick 1
27 *
28 * 1996/02/11 Andreas Schwab
29 * Module support
30 * Allow multiple open's
31 *
32 * Converted to use new generic busmouse code. 5 Apr 1998
33 * Russell King <rmk@arm.uk.linux.org>
34 */
35
36
37/*
38 * This program is free software; you can redistribute it and/or modify it
39 * under the terms of the GNU General Public License version 2 as published by
40 * the Free Software Foundation
41 */
42
43#include <linux/module.h>
44#include <linux/init.h>
45#include <linux/input.h>
46#include <linux/interrupt.h>
47
48#include <asm/irq.h>
49#include <asm/setup.h>
50#include <asm/system.h>
51#include <asm/uaccess.h>
52#include <asm/atarihw.h>
53#include <asm/atarikb.h>
54#include <asm/atariints.h>
55
56MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
57MODULE_DESCRIPTION("Atari mouse driver");
58MODULE_LICENSE("GPL");
59
60static int mouse_threshold[2] = {2,2};
61
62#ifdef __MODULE__
63MODULE_PARM(mouse_threshold, "2i");
64#endif
65#ifdef FIXED_ATARI_JOYSTICK
66extern int atari_mouse_buttons;
67#endif
68static int atamouse_used = 0;
69
70static struct input_dev *atamouse_dev;
71
72static void atamouse_interrupt(char *buf)
73{
74 int buttons, dx, dy;
75
76/* ikbd_mouse_disable(); */
77
78 buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
79#ifdef FIXED_ATARI_JOYSTICK
80 buttons |= atari_mouse_buttons & 2;
81 atari_mouse_buttons = buttons;
82#endif
83/* ikbd_mouse_rel_pos(); */
84
85 /* only relative events get here */
86 dx = buf[1];
87 dy = -buf[2];
88
89 input_report_rel(atamouse_dev, REL_X, dx);
90 input_report_rel(atamouse_dev, REL_Y, dy);
91
92 input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x1);
93 input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2);
94 input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x4);
95
96 input_sync(atamouse_dev);
97
98 return;
99}
100
101static int atamouse_open(struct input_dev *dev)
102{
103 if (atamouse_used++)
104 return 0;
105
106#ifdef FIXED_ATARI_JOYSTICK
107 atari_mouse_buttons = 0;
108#endif
109 ikbd_mouse_y0_top();
110 ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
111 ikbd_mouse_rel_pos();
112 atari_input_mouse_interrupt_hook = atamouse_interrupt;
113 return 0;
114}
115
116static void atamouse_close(struct input_dev *dev)
117{
118 if (!--atamouse_used) {
119 ikbd_mouse_disable();
120 atari_mouse_interrupt_hook = NULL;
121 }
122}
123
124static int __init atamouse_init(void)
125{
126 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
127 return -ENODEV;
128
129 if (!(atamouse_dev = input_allocate_device()))
130 return -ENOMEM;
131
132 if (!(atari_keyb_init()))
133 return -ENODEV;
134
135 atamouse_dev->name = "Atari mouse";
136 atamouse_dev->phys = "atamouse/input0";
137 atamouse_dev->id.bustype = BUS_ATARI;
138 atamouse_dev->id.vendor = 0x0001;
139 atamouse_dev->id.product = 0x0002;
140 atamouse_dev->id.version = 0x0100;
141
142 atamouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
143 atamouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
144 atamouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
145 atamouse_dev->open = atamouse_open;
146 atamouse_dev->close = atamouse_close;
147
148 input_register_device(atamouse_dev);
149
150 printk(KERN_INFO "input: %s at keyboard ACIA\n", atamouse_dev->name);
151 return 0;
152}
153
154static void __exit atamouse_exit(void)
155{
156 input_unregister_device(atamouse_dev);
157}
158
159module_init(atamouse_init);
160module_exit(atamouse_exit);
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 35233de460ad..3d0354e96a97 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -459,7 +459,8 @@ therm_of_probe( struct of_device *dev, const struct of_device_id *match )
459static int 459static int
460therm_of_remove( struct of_device *dev ) 460therm_of_remove( struct of_device *dev )
461{ 461{
462 return i2c_del_driver( &g4fan_driver ); 462 i2c_del_driver( &g4fan_driver );
463 return 0;
463} 464}
464 465
465static struct of_device_id therm_of_match[] = {{ 466static struct of_device_id therm_of_match[] = {{
diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c
index 76d21775fc35..741a93a3eb61 100644
--- a/drivers/macintosh/via-cuda.c
+++ b/drivers/macintosh/via-cuda.c
@@ -82,6 +82,7 @@ static unsigned char cuda_rbuf[16];
82static unsigned char *reply_ptr; 82static unsigned char *reply_ptr;
83static int reading_reply; 83static int reading_reply;
84static int data_index; 84static int data_index;
85static int cuda_irq;
85#ifdef CONFIG_PPC 86#ifdef CONFIG_PPC
86static struct device_node *vias; 87static struct device_node *vias;
87#endif 88#endif
@@ -160,10 +161,8 @@ int __init find_via_cuda(void)
160 /* Clear and enable interrupts, but only on PPC. On 68K it's done */ 161 /* Clear and enable interrupts, but only on PPC. On 68K it's done */
161 /* for us by the main VIA driver in arch/m68k/mac/via.c */ 162 /* for us by the main VIA driver in arch/m68k/mac/via.c */
162 163
163#ifndef CONFIG_MAC
164 out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */ 164 out_8(&via[IFR], 0x7f); /* clear interrupts by writing 1s */
165 out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */ 165 out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */
166#endif
167 166
168 /* enable autopoll */ 167 /* enable autopoll */
169 cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1); 168 cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
@@ -181,24 +180,22 @@ int __init find_via_cuda(void)
181 180
182static int __init via_cuda_start(void) 181static int __init via_cuda_start(void)
183{ 182{
184 unsigned int irq;
185
186 if (via == NULL) 183 if (via == NULL)
187 return -ENODEV; 184 return -ENODEV;
188 185
189#ifdef CONFIG_MAC 186#ifdef CONFIG_MAC
190 irq = IRQ_MAC_ADB; 187 cuda_irq = IRQ_MAC_ADB;
191#else /* CONFIG_MAC */ 188#else /* CONFIG_MAC */
192 irq = irq_of_parse_and_map(vias, 0); 189 cuda_irq = irq_of_parse_and_map(vias, 0);
193 if (irq == NO_IRQ) { 190 if (cuda_irq == NO_IRQ) {
194 printk(KERN_ERR "via-cuda: can't map interrupts for %s\n", 191 printk(KERN_ERR "via-cuda: can't map interrupts for %s\n",
195 vias->full_name); 192 vias->full_name);
196 return -ENODEV; 193 return -ENODEV;
197 } 194 }
198#endif /* CONFIG_MAP */ 195#endif /* CONFIG_MAC */
199 196
200 if (request_irq(irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) { 197 if (request_irq(cuda_irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) {
201 printk(KERN_ERR "via-cuda: can't request irq %d\n", irq); 198 printk(KERN_ERR "via-cuda: can't request irq %d\n", cuda_irq);
202 return -EAGAIN; 199 return -EAGAIN;
203 } 200 }
204 201
@@ -238,6 +235,7 @@ cuda_init(void)
238 printk(KERN_ERR "cuda_init_via() failed\n"); 235 printk(KERN_ERR "cuda_init_via() failed\n");
239 return -ENODEV; 236 return -ENODEV;
240 } 237 }
238 out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */
241 239
242 return via_cuda_start(); 240 return via_cuda_start();
243#endif 241#endif
@@ -263,15 +261,17 @@ cuda_init_via(void)
263 out_8(&via[B], in_8(&via[B]) | TACK | TIP); /* negate them */ 261 out_8(&via[B], in_8(&via[B]) | TACK | TIP); /* negate them */
264 out_8(&via[ACR] ,(in_8(&via[ACR]) & ~SR_CTRL) | SR_EXT); /* SR data in */ 262 out_8(&via[ACR] ,(in_8(&via[ACR]) & ~SR_CTRL) | SR_EXT); /* SR data in */
265 (void)in_8(&via[SR]); /* clear any left-over data */ 263 (void)in_8(&via[SR]); /* clear any left-over data */
266#ifndef CONFIG_MAC 264#ifdef CONFIG_PPC
267 out_8(&via[IER], 0x7f); /* disable interrupts from VIA */ 265 out_8(&via[IER], 0x7f); /* disable interrupts from VIA */
268 (void)in_8(&via[IER]); 266 (void)in_8(&via[IER]);
267#else
268 out_8(&via[IER], SR_INT); /* disable SR interrupt from VIA */
269#endif 269#endif
270 270
271 /* delay 4ms and then clear any pending interrupt */ 271 /* delay 4ms and then clear any pending interrupt */
272 mdelay(4); 272 mdelay(4);
273 (void)in_8(&via[SR]); 273 (void)in_8(&via[SR]);
274 out_8(&via[IFR], in_8(&via[IFR]) & 0x7f); 274 out_8(&via[IFR], SR_INT);
275 275
276 /* sync with the CUDA - assert TACK without TIP */ 276 /* sync with the CUDA - assert TACK without TIP */
277 out_8(&via[B], in_8(&via[B]) & ~TACK); 277 out_8(&via[B], in_8(&via[B]) & ~TACK);
@@ -282,7 +282,7 @@ cuda_init_via(void)
282 /* wait for the interrupt and then clear it */ 282 /* wait for the interrupt and then clear it */
283 WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (2)"); 283 WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (2)");
284 (void)in_8(&via[SR]); 284 (void)in_8(&via[SR]);
285 out_8(&via[IFR], in_8(&via[IFR]) & 0x7f); 285 out_8(&via[IFR], SR_INT);
286 286
287 /* finish the sync by negating TACK */ 287 /* finish the sync by negating TACK */
288 out_8(&via[B], in_8(&via[B]) | TACK); 288 out_8(&via[B], in_8(&via[B]) | TACK);
@@ -291,7 +291,7 @@ cuda_init_via(void)
291 WAIT_FOR(in_8(&via[B]) & TREQ, "CUDA response to sync (3)"); 291 WAIT_FOR(in_8(&via[B]) & TREQ, "CUDA response to sync (3)");
292 WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (4)"); 292 WAIT_FOR(in_8(&via[IFR]) & SR_INT, "CUDA response to sync (4)");
293 (void)in_8(&via[SR]); 293 (void)in_8(&via[SR]);
294 out_8(&via[IFR], in_8(&via[IFR]) & 0x7f); 294 out_8(&via[IFR], SR_INT);
295 out_8(&via[B], in_8(&via[B]) | TIP); /* should be unnecessary */ 295 out_8(&via[B], in_8(&via[B]) | TIP); /* should be unnecessary */
296 296
297 return 0; 297 return 0;
@@ -428,16 +428,12 @@ cuda_start(void)
428void 428void
429cuda_poll(void) 429cuda_poll(void)
430{ 430{
431 unsigned long flags;
432
433 /* cuda_interrupt only takes a normal lock, we disable 431 /* cuda_interrupt only takes a normal lock, we disable
434 * interrupts here to avoid re-entering and thus deadlocking. 432 * interrupts here to avoid re-entering and thus deadlocking.
435 * An option would be to disable only the IRQ source with
436 * disable_irq(), would that work on m68k ? --BenH
437 */ 433 */
438 local_irq_save(flags); 434 disable_irq(cuda_irq);
439 cuda_interrupt(0, NULL); 435 cuda_interrupt(0, NULL);
440 local_irq_restore(flags); 436 enable_irq(cuda_irq);
441} 437}
442 438
443static irqreturn_t 439static irqreturn_t
@@ -448,15 +444,25 @@ cuda_interrupt(int irq, void *arg)
448 unsigned char ibuf[16]; 444 unsigned char ibuf[16];
449 int ibuf_len = 0; 445 int ibuf_len = 0;
450 int complete = 0; 446 int complete = 0;
451 unsigned char virq;
452 447
453 spin_lock(&cuda_lock); 448 spin_lock(&cuda_lock);
454 449
455 virq = in_8(&via[IFR]) & 0x7f; 450 /* On powermacs, this handler is registered for the VIA IRQ. But it uses
456 out_8(&via[IFR], virq); 451 * just the shift register IRQ -- other VIA interrupt sources are disabled.
457 if ((virq & SR_INT) == 0) { 452 * On m68k macs, the VIA IRQ sources are dispatched individually. Unless
458 spin_unlock(&cuda_lock); 453 * we are polling, the shift register IRQ flag has already been cleared.
459 return IRQ_NONE; 454 */
455
456#ifdef CONFIG_MAC
457 if (!arg)
458#endif
459 {
460 if ((in_8(&via[IFR]) & SR_INT) == 0) {
461 spin_unlock(&cuda_lock);
462 return IRQ_NONE;
463 } else {
464 out_8(&via[IFR], SR_INT);
465 }
460 } 466 }
461 467
462 status = (~in_8(&via[B]) & (TIP|TREQ)) | (in_8(&via[ACR]) & SR_OUT); 468 status = (~in_8(&via[B]) & (TIP|TREQ)) | (in_8(&via[ACR]) & SR_OUT);
diff --git a/drivers/macintosh/via-macii.c b/drivers/macintosh/via-macii.c
index 1b3bad62a1be..01b8eca7ccd5 100644
--- a/drivers/macintosh/via-macii.c
+++ b/drivers/macintosh/via-macii.c
@@ -12,6 +12,15 @@
12 * 1999-08-02 (jmt) - Initial rewrite for Unified ADB. 12 * 1999-08-02 (jmt) - Initial rewrite for Unified ADB.
13 * 2000-03-29 Tony Mantler <tonym@mac.linux-m68k.org> 13 * 2000-03-29 Tony Mantler <tonym@mac.linux-m68k.org>
14 * - Big overhaul, should actually work now. 14 * - Big overhaul, should actually work now.
15 * 2006-12-31 Finn Thain <fthain@telegraphics.com.au> - Another overhaul.
16 *
17 * Suggested reading:
18 * Inside Macintosh, ch. 5 ADB Manager
19 * Guide to the Macinstosh Family Hardware, ch. 8 Apple Desktop Bus
20 * Rockwell R6522 VIA datasheet
21 *
22 * Apple's "ADB Analyzer" bus sniffer is invaluable:
23 * ftp://ftp.apple.com/developer/Tool_Chest/Devices_-_Hardware/Apple_Desktop_Bus/
15 */ 24 */
16 25
17#include <stdarg.h> 26#include <stdarg.h>
@@ -26,7 +35,6 @@
26#include <asm/macints.h> 35#include <asm/macints.h>
27#include <asm/machw.h> 36#include <asm/machw.h>
28#include <asm/mac_via.h> 37#include <asm/mac_via.h>
29#include <asm/io.h>
30#include <asm/system.h> 38#include <asm/system.h>
31 39
32static volatile unsigned char *via; 40static volatile unsigned char *via;
@@ -51,9 +59,7 @@ static volatile unsigned char *via;
51#define ANH (15*RS) /* A-side data, no handshake */ 59#define ANH (15*RS) /* A-side data, no handshake */
52 60
53/* Bits in B data register: all active low */ 61/* Bits in B data register: all active low */
54#define TREQ 0x08 /* Transfer request (input) */ 62#define CTLR_IRQ 0x08 /* Controller rcv status (input) */
55#define TACK 0x10 /* Transfer acknowledge (output) */
56#define TIP 0x20 /* Transfer in progress (output) */
57#define ST_MASK 0x30 /* mask for selecting ADB state bits */ 63#define ST_MASK 0x30 /* mask for selecting ADB state bits */
58 64
59/* Bits in ACR */ 65/* Bits in ACR */
@@ -65,8 +71,6 @@ static volatile unsigned char *via;
65#define IER_SET 0x80 /* set bits in IER */ 71#define IER_SET 0x80 /* set bits in IER */
66#define IER_CLR 0 /* clear bits in IER */ 72#define IER_CLR 0 /* clear bits in IER */
67#define SR_INT 0x04 /* Shift register full/empty */ 73#define SR_INT 0x04 /* Shift register full/empty */
68#define SR_DATA 0x08 /* Shift register data */
69#define SR_CLOCK 0x10 /* Shift register clock */
70 74
71/* ADB transaction states according to GMHW */ 75/* ADB transaction states according to GMHW */
72#define ST_CMD 0x00 /* ADB state: command byte */ 76#define ST_CMD 0x00 /* ADB state: command byte */
@@ -77,7 +81,6 @@ static volatile unsigned char *via;
77static int macii_init_via(void); 81static int macii_init_via(void);
78static void macii_start(void); 82static void macii_start(void);
79static irqreturn_t macii_interrupt(int irq, void *arg); 83static irqreturn_t macii_interrupt(int irq, void *arg);
80static void macii_retransmit(int);
81static void macii_queue_poll(void); 84static void macii_queue_poll(void);
82 85
83static int macii_probe(void); 86static int macii_probe(void);
@@ -103,29 +106,37 @@ static enum macii_state {
103 sending, 106 sending,
104 reading, 107 reading,
105 read_done, 108 read_done,
106 awaiting_reply
107} macii_state; 109} macii_state;
108 110
109static int need_poll; 111static struct adb_request *current_req; /* first request struct in the queue */
110static int command_byte; 112static struct adb_request *last_req; /* last request struct in the queue */
111static int last_reply; 113static unsigned char reply_buf[16]; /* storage for autopolled replies */
112static int last_active; 114static unsigned char *reply_ptr; /* next byte in req->data or reply_buf */
113 115static int reading_reply; /* store reply in reply_buf else req->reply */
114static struct adb_request *current_req; 116static int data_index; /* index of the next byte to send from req->data */
115static struct adb_request *last_req; 117static int reply_len; /* number of bytes received in reply_buf or req->reply */
116static struct adb_request *retry_req; 118static int status; /* VIA's ADB status bits captured upon interrupt */
117static unsigned char reply_buf[16]; 119static int last_status; /* status bits as at previous interrupt */
118static unsigned char *reply_ptr; 120static int srq_asserted; /* have to poll for the device that asserted it */
119static int reply_len; 121static int command_byte; /* the most recent command byte transmitted */
120static int reading_reply; 122static int autopoll_devs; /* bits set are device addresses to be polled */
121static int data_index; 123
122static int first_byte; 124/* Sanity check for request queue. Doesn't check for cycles. */
123static int prefix_len; 125static int request_is_queued(struct adb_request *req) {
124static int status = ST_IDLE|TREQ; 126 struct adb_request *cur;
125static int last_status; 127 unsigned long flags;
126static int driver_running; 128 local_irq_save(flags);
127 129 cur = current_req;
128/* debug level 10 required for ADB logging (should be && debug_adb, ideally) */ 130 while (cur) {
131 if (cur == req) {
132 local_irq_restore(flags);
133 return 1;
134 }
135 cur = cur->next;
136 }
137 local_irq_restore(flags);
138 return 0;
139}
129 140
130/* Check for MacII style ADB */ 141/* Check for MacII style ADB */
131static int macii_probe(void) 142static int macii_probe(void)
@@ -147,15 +158,16 @@ int macii_init(void)
147 local_irq_save(flags); 158 local_irq_save(flags);
148 159
149 err = macii_init_via(); 160 err = macii_init_via();
150 if (err) return err; 161 if (err) goto out;
151 162
152 err = request_irq(IRQ_MAC_ADB, macii_interrupt, IRQ_FLG_LOCK, "ADB", 163 err = request_irq(IRQ_MAC_ADB, macii_interrupt, IRQ_FLG_LOCK, "ADB",
153 macii_interrupt); 164 macii_interrupt);
154 if (err) return err; 165 if (err) goto out;
155 166
156 macii_state = idle; 167 macii_state = idle;
168out:
157 local_irq_restore(flags); 169 local_irq_restore(flags);
158 return 0; 170 return err;
159} 171}
160 172
161/* initialize the hardware */ 173/* initialize the hardware */
@@ -163,12 +175,12 @@ static int macii_init_via(void)
163{ 175{
164 unsigned char x; 176 unsigned char x;
165 177
166 /* Set the lines up. We want TREQ as input TACK|TIP as output */ 178 /* We want CTLR_IRQ as input and ST_EVEN | ST_ODD as output lines. */
167 via[DIRB] = (via[DIRB] | TACK | TIP) & ~TREQ; 179 via[DIRB] = (via[DIRB] | ST_EVEN | ST_ODD) & ~CTLR_IRQ;
168 180
169 /* Set up state: idle */ 181 /* Set up state: idle */
170 via[B] |= ST_IDLE; 182 via[B] |= ST_IDLE;
171 last_status = via[B] & (ST_MASK|TREQ); 183 last_status = via[B] & (ST_MASK|CTLR_IRQ);
172 184
173 /* Shift register on input */ 185 /* Shift register on input */
174 via[ACR] = (via[ACR] & ~SR_CTRL) | SR_EXT; 186 via[ACR] = (via[ACR] & ~SR_CTRL) | SR_EXT;
@@ -179,81 +191,72 @@ static int macii_init_via(void)
179 return 0; 191 return 0;
180} 192}
181 193
182/* Send an ADB poll (Talk Register 0 command, tagged on the front of the request queue) */ 194/* Send an ADB poll (Talk Register 0 command prepended to the request queue) */
183static void macii_queue_poll(void) 195static void macii_queue_poll(void)
184{ 196{
185 static int device = 0; 197 /* No point polling the active device as it will never assert SRQ, so
186 static int in_poll=0; 198 * poll the next device in the autopoll list. This could leave us
199 * stuck in a polling loop if an unprobed device is asserting SRQ.
200 * In theory, that could only happen if a device was plugged in after
201 * probing started. Unplugging it again will break the cycle.
202 * (Simply polling the next higher device often ends up polling almost
203 * every device (after wrapping around), which takes too long.)
204 */
205 int device_mask;
206 int next_device;
187 static struct adb_request req; 207 static struct adb_request req;
188 unsigned long flags;
189
190 if (in_poll) printk("macii_queue_poll: double poll!\n");
191
192 in_poll++;
193 if (++device > 15) device = 1;
194
195 adb_request(&req, NULL, ADBREQ_REPLY|ADBREQ_NOSEND, 1,
196 ADB_READREG(device, 0));
197
198 local_irq_save(flags);
199
200 req.next = current_req;
201 current_req = &req;
202 208
203 local_irq_restore(flags); 209 if (!autopoll_devs) return;
204 macii_start();
205 in_poll--;
206}
207 210
208/* Send an ADB retransmit (Talk, appended to the request queue) */ 211 device_mask = (1 << (((command_byte & 0xF0) >> 4) + 1)) - 1;
209static void macii_retransmit(int device) 212 if (autopoll_devs & ~device_mask)
210{ 213 next_device = ffs(autopoll_devs & ~device_mask) - 1;
211 static int in_retransmit = 0; 214 else
212 static struct adb_request rt; 215 next_device = ffs(autopoll_devs) - 1;
213 unsigned long flags;
214
215 if (in_retransmit) printk("macii_retransmit: double retransmit!\n");
216 216
217 in_retransmit++; 217 BUG_ON(request_is_queued(&req));
218 218
219 adb_request(&rt, NULL, ADBREQ_REPLY|ADBREQ_NOSEND, 1, 219 adb_request(&req, NULL, ADBREQ_NOSEND, 1,
220 ADB_READREG(device, 0)); 220 ADB_READREG(next_device, 0));
221 221
222 local_irq_save(flags); 222 req.sent = 0;
223 req.complete = 0;
224 req.reply_len = 0;
225 req.next = current_req;
223 226
224 if (current_req != NULL) { 227 if (current_req != NULL) {
225 last_req->next = &rt; 228 current_req = &req;
226 last_req = &rt;
227 } else { 229 } else {
228 current_req = &rt; 230 current_req = &req;
229 last_req = &rt; 231 last_req = &req;
230 } 232 }
231
232 if (macii_state == idle) macii_start();
233
234 local_irq_restore(flags);
235 in_retransmit--;
236} 233}
237 234
238/* Send an ADB request; if sync, poll out the reply 'till it's done */ 235/* Send an ADB request; if sync, poll out the reply 'till it's done */
239static int macii_send_request(struct adb_request *req, int sync) 236static int macii_send_request(struct adb_request *req, int sync)
240{ 237{
241 int i; 238 int err;
239 unsigned long flags;
242 240
243 i = macii_write(req); 241 BUG_ON(request_is_queued(req));
244 if (i) return i;
245 242
246 if (sync) { 243 local_irq_save(flags);
247 while (!req->complete) macii_poll(); 244 err = macii_write(req);
245 local_irq_restore(flags);
246
247 if (!err && sync) {
248 while (!req->complete) {
249 macii_poll();
250 }
251 BUG_ON(request_is_queued(req));
248 } 252 }
249 return 0; 253
254 return err;
250} 255}
251 256
252/* Send an ADB request */ 257/* Send an ADB request (append to request queue) */
253static int macii_write(struct adb_request *req) 258static int macii_write(struct adb_request *req)
254{ 259{
255 unsigned long flags;
256
257 if (req->nbytes < 2 || req->data[0] != ADB_PACKET || req->nbytes > 15) { 260 if (req->nbytes < 2 || req->data[0] != ADB_PACKET || req->nbytes > 15) {
258 req->complete = 1; 261 req->complete = 1;
259 return -EINVAL; 262 return -EINVAL;
@@ -264,8 +267,6 @@ static int macii_write(struct adb_request *req)
264 req->complete = 0; 267 req->complete = 0;
265 req->reply_len = 0; 268 req->reply_len = 0;
266 269
267 local_irq_save(flags);
268
269 if (current_req != NULL) { 270 if (current_req != NULL) {
270 last_req->next = req; 271 last_req->next = req;
271 last_req = req; 272 last_req = req;
@@ -274,28 +275,52 @@ static int macii_write(struct adb_request *req)
274 last_req = req; 275 last_req = req;
275 if (macii_state == idle) macii_start(); 276 if (macii_state == idle) macii_start();
276 } 277 }
277
278 local_irq_restore(flags);
279 return 0; 278 return 0;
280} 279}
281 280
282/* Start auto-polling */ 281/* Start auto-polling */
283static int macii_autopoll(int devs) 282static int macii_autopoll(int devs)
284{ 283{
285 /* Just ping a random default address */ 284 static struct adb_request req;
286 if (!(current_req || retry_req)) 285 unsigned long flags;
287 macii_retransmit( (last_active < 16 && last_active > 0) ? last_active : 3); 286 int err = 0;
288 return 0; 287
288 /* bit 1 == device 1, and so on. */
289 autopoll_devs = devs & 0xFFFE;
290
291 if (!autopoll_devs) return 0;
292
293 local_irq_save(flags);
294
295 if (current_req == NULL) {
296 /* Send a Talk Reg 0. The controller will repeatedly transmit
297 * this as long as it is idle.
298 */
299 adb_request(&req, NULL, ADBREQ_NOSEND, 1,
300 ADB_READREG(ffs(autopoll_devs) - 1, 0));
301 err = macii_write(&req);
302 }
303
304 local_irq_restore(flags);
305 return err;
306}
307
308static inline int need_autopoll(void) {
309 /* Was the last command Talk Reg 0
310 * and is the target on the autopoll list?
311 */
312 if ((command_byte & 0x0F) == 0x0C &&
313 ((1 << ((command_byte & 0xF0) >> 4)) & autopoll_devs))
314 return 0;
315 return 1;
289} 316}
290 317
291/* Prod the chip without interrupts */ 318/* Prod the chip without interrupts */
292static void macii_poll(void) 319static void macii_poll(void)
293{ 320{
294 unsigned long flags; 321 disable_irq(IRQ_MAC_ADB);
295 322 macii_interrupt(0, NULL);
296 local_irq_save(flags); 323 enable_irq(IRQ_MAC_ADB);
297 if (via[IFR] & SR_INT) macii_interrupt(0, NULL);
298 local_irq_restore(flags);
299} 324}
300 325
301/* Reset the bus */ 326/* Reset the bus */
@@ -303,73 +328,34 @@ static int macii_reset_bus(void)
303{ 328{
304 static struct adb_request req; 329 static struct adb_request req;
305 330
331 if (request_is_queued(&req))
332 return 0;
333
306 /* Command = 0, Address = ignored */ 334 /* Command = 0, Address = ignored */
307 adb_request(&req, NULL, 0, 1, ADB_BUSRESET); 335 adb_request(&req, NULL, 0, 1, ADB_BUSRESET);
308 336
337 /* Don't want any more requests during the Global Reset low time. */
338 udelay(3000);
339
309 return 0; 340 return 0;
310} 341}
311 342
312/* Start sending ADB packet */ 343/* Start sending ADB packet */
313static void macii_start(void) 344static void macii_start(void)
314{ 345{
315 unsigned long flags;
316 struct adb_request *req; 346 struct adb_request *req;
317 347
318 req = current_req; 348 req = current_req;
319 if (!req) return;
320
321 /* assert macii_state == idle */
322 if (macii_state != idle) {
323 printk("macii_start: called while driver busy (%p %x %x)!\n",
324 req, macii_state, (uint) via1[B] & (ST_MASK|TREQ));
325 return;
326 }
327 349
328 local_irq_save(flags); 350 BUG_ON(req == NULL);
329 351
330 /* 352 BUG_ON(macii_state != idle);
331 * IRQ signaled ?? (means ADB controller wants to send, or might 353
332 * be end of packet if we were reading) 354 /* Now send it. Be careful though, that first byte of the request
333 */ 355 * is actually ADB_PACKET; the real data begins at index 1!
334#if 0 /* FIXME: This is broke broke broke, for some reason */ 356 * And req->nbytes is the number of bytes of real data plus one.
335 if ((via[B] & TREQ) == 0) {
336 printk("macii_start: weird poll stuff. huh?\n");
337 /*
338 * FIXME - we need to restart this on a timer
339 * or a collision at boot hangs us.
340 * Never set macii_state to idle here, or macii_start
341 * won't be called again from send_request!
342 * (need to re-check other cases ...)
343 */
344 /*
345 * if the interrupt handler set the need_poll
346 * flag, it's hopefully a SRQ poll or re-Talk
347 * so we try to send here anyway
348 */
349 if (!need_poll) {
350 if (console_loglevel == 10)
351 printk("macii_start: device busy - retry %p state %d status %x!\n",
352 req, macii_state,
353 (uint) via[B] & (ST_MASK|TREQ));
354 retry_req = req;
355 /* set ADB status here ? */
356 local_irq_restore(flags);
357 return;
358 } else {
359 need_poll = 0;
360 }
361 }
362#endif
363 /*
364 * Another retry pending? (sanity check)
365 */ 357 */
366 if (retry_req) {
367 retry_req = NULL;
368 }
369 358
370 /* Now send it. Be careful though, that first byte of the request */
371 /* is actually ADB_PACKET; the real data begins at index 1! */
372
373 /* store command byte */ 359 /* store command byte */
374 command_byte = req->data[1]; 360 command_byte = req->data[1];
375 /* Output mode */ 361 /* Output mode */
@@ -381,115 +367,97 @@ static void macii_start(void)
381 367
382 macii_state = sending; 368 macii_state = sending;
383 data_index = 2; 369 data_index = 2;
384
385 local_irq_restore(flags);
386} 370}
387 371
388/* 372/*
389 * The notorious ADB interrupt handler - does all of the protocol handling, 373 * The notorious ADB interrupt handler - does all of the protocol handling.
390 * except for starting new send operations. Relies heavily on the ADB 374 * Relies on the ADB controller sending and receiving data, thereby
391 * controller sending and receiving data, thereby generating SR interrupts 375 * generating shift register interrupts (SR_INT) for us. This means there has
392 * for us. This means there has to be always activity on the ADB bus, otherwise 376 * to be activity on the ADB bus. The chip will poll to achieve this.
393 * the whole process dies and has to be re-kicked by sending TALK requests ...
394 * CUDA-based Macs seem to solve this with the autopoll option, for MacII-type
395 * ADB the problem isn't solved yet (retransmit of the latest active TALK seems
396 * a good choice; either on timeout or on a timer interrupt).
397 * 377 *
398 * The basic ADB state machine was left unchanged from the original MacII code 378 * The basic ADB state machine was left unchanged from the original MacII code
399 * by Alan Cox, which was based on the CUDA driver for PowerMac. 379 * by Alan Cox, which was based on the CUDA driver for PowerMac.
400 * The syntax of the ADB status lines seems to be totally different on MacII, 380 * The syntax of the ADB status lines is totally different on MacII,
401 * though. MacII uses the states Command -> Even -> Odd -> Even ->...-> Idle for 381 * though. MacII uses the states Command -> Even -> Odd -> Even ->...-> Idle
402 * sending, and Idle -> Even -> Odd -> Even ->...-> Idle for receiving. Start 382 * for sending and Idle -> Even -> Odd -> Even ->...-> Idle for receiving.
403 * and end of a receive packet are signaled by asserting /IRQ on the interrupt 383 * Start and end of a receive packet are signalled by asserting /IRQ on the
404 * line. Timeouts are signaled by a sequence of 4 0xFF, with /IRQ asserted on 384 * interrupt line (/IRQ means the CTLR_IRQ bit in port B; not to be confused
405 * every other byte. SRQ is probably signaled by 3 or more 0xFF tacked on the 385 * with the VIA shift register interrupt. /IRQ never actually interrupts the
406 * end of a packet. (Thanks to Guido Koerber for eavesdropping on the ADB 386 * processor, it's just an ordinary input.)
407 * protocol with a logic analyzer!!)
408 *
409 * Note: As of 21/10/97, the MacII ADB part works including timeout detection
410 * and retransmit (Talk to the last active device).
411 */ 387 */
412static irqreturn_t macii_interrupt(int irq, void *arg) 388static irqreturn_t macii_interrupt(int irq, void *arg)
413{ 389{
414 int x, adbdir; 390 int x;
415 unsigned long flags; 391 static int entered;
416 struct adb_request *req; 392 struct adb_request *req;
417 393
418 last_status = status; 394 if (!arg) {
419 395 /* Clear the SR IRQ flag when polling. */
420 /* prevent races due to SCSI enabling ints */ 396 if (via[IFR] & SR_INT)
421 local_irq_save(flags); 397 via[IFR] = SR_INT;
422 398 else
423 if (driver_running) { 399 return IRQ_NONE;
424 local_irq_restore(flags);
425 return IRQ_NONE;
426 } 400 }
427 401
428 driver_running = 1; 402 BUG_ON(entered++);
429 403
430 status = via[B] & (ST_MASK|TREQ); 404 last_status = status;
431 adbdir = via[ACR] & SR_OUT; 405 status = via[B] & (ST_MASK|CTLR_IRQ);
432 406
433 switch (macii_state) { 407 switch (macii_state) {
434 case idle: 408 case idle:
409 if (reading_reply) {
410 reply_ptr = current_req->reply;
411 } else {
412 BUG_ON(current_req != NULL);
413 reply_ptr = reply_buf;
414 }
415
435 x = via[SR]; 416 x = via[SR];
436 first_byte = x;
437 /* set ADB state = even for first data byte */
438 via[B] = (via[B] & ~ST_MASK) | ST_EVEN;
439 417
440 reply_buf[0] = first_byte; /* was command_byte?? */ 418 if ((status & CTLR_IRQ) && (x == 0xFF)) {
441 reply_ptr = reply_buf + 1; 419 /* Bus timeout without SRQ sequence:
442 reply_len = 1; 420 * data is "FF" while CTLR_IRQ is "H"
443 prefix_len = 1; 421 */
444 reading_reply = 0; 422 reply_len = 0;
445 423 srq_asserted = 0;
446 macii_state = reading; 424 macii_state = read_done;
447 break; 425 } else {
426 macii_state = reading;
427 *reply_ptr = x;
428 reply_len = 1;
429 }
448 430
449 case awaiting_reply:
450 /* handshake etc. for II ?? */
451 x = via[SR];
452 first_byte = x;
453 /* set ADB state = even for first data byte */ 431 /* set ADB state = even for first data byte */
454 via[B] = (via[B] & ~ST_MASK) | ST_EVEN; 432 via[B] = (via[B] & ~ST_MASK) | ST_EVEN;
455
456 current_req->reply[0] = first_byte;
457 reply_ptr = current_req->reply + 1;
458 reply_len = 1;
459 prefix_len = 1;
460 reading_reply = 1;
461
462 macii_state = reading;
463 break; 433 break;
464 434
465 case sending: 435 case sending:
466 req = current_req; 436 req = current_req;
467 if (data_index >= req->nbytes) { 437 if (data_index >= req->nbytes) {
468 /* print an error message if a listen command has no data */
469 if (((command_byte & 0x0C) == 0x08)
470 /* && (console_loglevel == 10) */
471 && (data_index == 2))
472 printk("MacII ADB: listen command with no data: %x!\n",
473 command_byte);
474 /* reset to shift in */
475 via[ACR] &= ~SR_OUT;
476 x = via[SR];
477 /* set ADB state idle - might get SRQ */
478 via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
479
480 req->sent = 1; 438 req->sent = 1;
439 macii_state = idle;
481 440
482 if (req->reply_expected) { 441 if (req->reply_expected) {
483 macii_state = awaiting_reply; 442 reading_reply = 1;
484 } else { 443 } else {
485 req->complete = 1; 444 req->complete = 1;
486 current_req = req->next; 445 current_req = req->next;
487 if (req->done) (*req->done)(req); 446 if (req->done) (*req->done)(req);
488 macii_state = idle; 447
489 if (current_req || retry_req) 448 if (current_req)
490 macii_start(); 449 macii_start();
491 else 450 else
492 macii_retransmit((command_byte & 0xF0) >> 4); 451 if (need_autopoll())
452 macii_autopoll(autopoll_devs);
453 }
454
455 if (macii_state == idle) {
456 /* reset to shift in */
457 via[ACR] &= ~SR_OUT;
458 x = via[SR];
459 /* set ADB state idle - might get SRQ */
460 via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
493 } 461 }
494 } else { 462 } else {
495 via[SR] = req->data[data_index++]; 463 via[SR] = req->data[data_index++];
@@ -505,147 +473,79 @@ static irqreturn_t macii_interrupt(int irq, void *arg)
505 break; 473 break;
506 474
507 case reading: 475 case reading:
476 x = via[SR];
477 BUG_ON((status & ST_MASK) == ST_CMD ||
478 (status & ST_MASK) == ST_IDLE);
479
480 /* Bus timeout with SRQ sequence:
481 * data is "XX FF" while CTLR_IRQ is "L L"
482 * End of packet without SRQ sequence:
483 * data is "XX...YY 00" while CTLR_IRQ is "L...H L"
484 * End of packet SRQ sequence:
485 * data is "XX...YY 00" while CTLR_IRQ is "L...L L"
486 * (where XX is the first response byte and
487 * YY is the last byte of valid response data.)
488 */
508 489
509 /* timeout / SRQ handling for II hw */ 490 srq_asserted = 0;
510 if( (first_byte == 0xFF && (reply_len-prefix_len)==2 491 if (!(status & CTLR_IRQ)) {
511 && memcmp(reply_ptr-2,"\xFF\xFF",2)==0) || 492 if (x == 0xFF) {
512 ((reply_len-prefix_len)==3 493 if (!(last_status & CTLR_IRQ)) {
513 && memcmp(reply_ptr-3,"\xFF\xFF\xFF",3)==0)) 494 macii_state = read_done;
514 { 495 reply_len = 0;
515 /* 496 srq_asserted = 1;
516 * possible timeout (in fact, most probably a 497 }
517 * timeout, since SRQ can't be signaled without 498 } else if (x == 0x00) {
518 * transfer on the bus). 499 macii_state = read_done;
519 * The last three bytes seen were FF, together 500 if (!(last_status & CTLR_IRQ))
520 * with the starting byte (in case we started 501 srq_asserted = 1;
521 * on 'idle' or 'awaiting_reply') this probably
522 * makes four. So this is mostl likely #5!
523 * The timeout signal is a pattern 1 0 1 0 0..
524 * on /INT, meaning we missed it :-(
525 */
526 x = via[SR];
527 if (x != 0xFF) printk("MacII ADB: mistaken timeout/SRQ!\n");
528
529 if ((status & TREQ) == (last_status & TREQ)) {
530 /* Not a timeout. Unsolicited SRQ? weird. */
531 /* Terminate the SRQ packet and poll */
532 need_poll = 1;
533 } 502 }
534 /* There's no packet to get, so reply is blank */ 503 }
535 via[B] ^= ST_MASK; 504
536 reply_ptr -= (reply_len-prefix_len); 505 if (macii_state == reading) {
537 reply_len = prefix_len; 506 BUG_ON(reply_len > 15);
538 macii_state = read_done;
539 break;
540 } /* end timeout / SRQ handling for II hw. */
541
542 if((reply_len-prefix_len)>3
543 && memcmp(reply_ptr-3,"\xFF\xFF\xFF",3)==0)
544 {
545 /* SRQ tacked on data packet */
546 /* Terminate the packet (SRQ never ends) */
547 x = via[SR];
548 macii_state = read_done;
549 reply_len -= 3;
550 reply_ptr -= 3;
551 need_poll = 1;
552 /* need to continue; next byte not seen else */
553 } else {
554 /* Sanity check */
555 if (reply_len > 15) reply_len = 0;
556 /* read byte */
557 x = via[SR];
558 *reply_ptr = x;
559 reply_ptr++; 507 reply_ptr++;
508 *reply_ptr = x;
560 reply_len++; 509 reply_len++;
561 } 510 }
562 /* The usual handshake ... */
563
564 /*
565 * NetBSD hints that the next to last byte
566 * is sent with IRQ !!
567 * Guido found out it's the last one (0x0),
568 * but IRQ should be asserted already.
569 * Problem with timeout detection: First
570 * transition to /IRQ might be second
571 * byte of timeout packet!
572 * Timeouts are signaled by 4x FF.
573 */
574 if (((status & TREQ) == 0) && (x == 0x00)) { /* != 0xFF */
575 /* invert state bits, toggle ODD/EVEN */
576 via[B] ^= ST_MASK;
577 511
578 /* adjust packet length */ 512 /* invert state bits, toggle ODD/EVEN */
579 reply_len--; 513 via[B] ^= ST_MASK;
580 reply_ptr--;
581 macii_state = read_done;
582 } else {
583 /* not caught: ST_CMD */
584 /* required for re-entry 'reading'! */
585 if ((status & ST_MASK) == ST_IDLE) {
586 /* (in)sanity check - set even */
587 via[B] = (via[B] & ~ST_MASK) | ST_EVEN;
588 } else {
589 /* invert state bits */
590 via[B] ^= ST_MASK;
591 }
592 }
593 break; 514 break;
594 515
595 case read_done: 516 case read_done:
596 x = via[SR]; 517 x = via[SR];
518
597 if (reading_reply) { 519 if (reading_reply) {
520 reading_reply = 0;
598 req = current_req; 521 req = current_req;
599 req->reply_len = reply_ptr - req->reply; 522 req->reply_len = reply_len;
600 req->complete = 1; 523 req->complete = 1;
601 current_req = req->next; 524 current_req = req->next;
602 if (req->done) (*req->done)(req); 525 if (req->done) (*req->done)(req);
603 } else { 526 } else if (reply_len && autopoll_devs)
604 adb_input(reply_buf, reply_ptr - reply_buf, 0); 527 adb_input(reply_buf, reply_len, 0);
605 }
606 528
607 /* 529 macii_state = idle;
608 * remember this device ID; it's the latest we got a
609 * reply from!
610 */
611 last_reply = command_byte;
612 last_active = (command_byte & 0xF0) >> 4;
613 530
614 /* SRQ seen before, initiate poll now */ 531 /* SRQ seen before, initiate poll now */
615 if (need_poll) { 532 if (srq_asserted)
616 macii_state = idle;
617 macii_queue_poll(); 533 macii_queue_poll();
618 need_poll = 0;
619 break;
620 }
621
622 /* set ADB state to idle */
623 via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
624
625 /* /IRQ seen, so the ADB controller has data for us */
626 if ((via[B] & TREQ) != 0) {
627 macii_state = reading;
628 534
629 reply_buf[0] = command_byte; 535 if (current_req)
630 reply_ptr = reply_buf + 1; 536 macii_start();
631 reply_len = 1; 537 else
632 prefix_len = 1; 538 if (need_autopoll())
633 reading_reply = 0; 539 macii_autopoll(autopoll_devs);
634 } else { 540
635 /* no IRQ, send next packet or wait */ 541 if (macii_state == idle)
636 macii_state = idle; 542 via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
637 if (current_req)
638 macii_start();
639 else
640 macii_retransmit(last_active);
641 }
642 break; 543 break;
643 544
644 default: 545 default:
645 break; 546 break;
646 } 547 }
647 /* reset mutex and interrupts */ 548
648 driver_running = 0; 549 entered--;
649 local_irq_restore(flags);
650 return IRQ_HANDLED; 550 return IRQ_HANDLED;
651} 551}
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 356c7216a179..dfdf11c1eec4 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -111,7 +111,6 @@ static int pmu_send_request(struct adb_request *req, int sync);
111static int pmu_autopoll(int devs); 111static int pmu_autopoll(int devs);
112void pmu_poll(void); 112void pmu_poll(void);
113static int pmu_reset_bus(void); 113static int pmu_reset_bus(void);
114static int pmu_queue_request(struct adb_request *req);
115 114
116static void pmu_start(void); 115static void pmu_start(void);
117static void send_byte(int x); 116static void send_byte(int x);
@@ -475,7 +474,7 @@ pmu_request(struct adb_request *req, void (*done)(struct adb_request *),
475 return pmu_queue_request(req); 474 return pmu_queue_request(req);
476} 475}
477 476
478static int 477int
479pmu_queue_request(struct adb_request *req) 478pmu_queue_request(struct adb_request *req)
480{ 479{
481 unsigned long flags; 480 unsigned long flags;
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index 5347a406fff7..02a0ea6e1c17 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -183,7 +183,8 @@ int flexcop_i2c_init(struct flexcop_device *fc)
183 mutex_init(&fc->i2c_mutex); 183 mutex_init(&fc->i2c_mutex);
184 184
185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter)); 185 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter));
186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",I2C_NAME_SIZE); 186 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device",
187 sizeof(fc->i2c_adap.name));
187 188
188 i2c_set_adapdata(&fc->i2c_adap,fc); 189 i2c_set_adapdata(&fc->i2c_adap,fc);
189 190
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
index 70df31b0a8a9..088b6dee3a7f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
@@ -19,7 +19,7 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d)
19 return -EINVAL; 19 return -EINVAL;
20 } 20 }
21 21
22 strncpy(d->i2c_adap.name,d->desc->name,I2C_NAME_SIZE); 22 strncpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
23#ifdef I2C_ADAP_CLASS_TV_DIGITAL 23#ifdef I2C_ADAP_CLASS_TV_DIGITAL
24 d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL, 24 d->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
25#else 25#else
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index a18c8f45a2ee..315e09e95b0c 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -105,9 +105,9 @@ struct i2c_adapter * dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, enu
105} 105}
106EXPORT_SYMBOL(dibx000_get_i2c_adapter); 106EXPORT_SYMBOL(dibx000_get_i2c_adapter);
107 107
108static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char name[I2C_NAME_SIZE], struct dibx000_i2c_master *mst) 108static int i2c_adapter_init(struct i2c_adapter *i2c_adap, struct i2c_algorithm *algo, const char *name, struct dibx000_i2c_master *mst)
109{ 109{
110 strncpy(i2c_adap->name, name, I2C_NAME_SIZE); 110 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
111 i2c_adap->class = I2C_CLASS_TV_DIGITAL, 111 i2c_adap->class = I2C_CLASS_TV_DIGITAL,
112 i2c_adap->algo = algo; 112 i2c_adap->algo = algo;
113 i2c_adap->algo_data = NULL; 113 i2c_adap->algo_data = NULL;
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 88dbdddeec42..d73c86aeeaac 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -26,7 +26,6 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <linux/i2c.h>
30 29
31#include <media/tuner.h> 30#include <media/tuner.h>
32#include <media/cx2341x.h> 31#include <media/cx2341x.h>
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index 1231335a9f4a..50c7763d44b3 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -15,6 +15,7 @@
15#ifndef __LINUX_OVCAMCHIP_PRIV_H 15#ifndef __LINUX_OVCAMCHIP_PRIV_H
16#define __LINUX_OVCAMCHIP_PRIV_H 16#define __LINUX_OVCAMCHIP_PRIV_H
17 17
18#include <linux/i2c.h>
18#include <media/ovcamchip.h> 19#include <media/ovcamchip.h>
19 20
20#ifdef DEBUG 21#ifdef DEBUG
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 13f69fe6360d..51ab265d566a 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -24,7 +24,6 @@
24 24
25 25
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/i2c.h>
28#include <media/v4l2-dev.h> 27#include <media/v4l2-dev.h>
29#include <media/tuner.h> 28#include <media/tuner.h>
30#include "usbvision.h" 29#include "usbvision.h"
diff --git a/drivers/net/7990.c b/drivers/net/7990.c
index d396f996af57..0877fc372f4b 100644
--- a/drivers/net/7990.c
+++ b/drivers/net/7990.c
@@ -565,9 +565,9 @@ int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
565 ib->btx_ring [entry].length = (-len) | 0xf000; 565 ib->btx_ring [entry].length = (-len) | 0xf000;
566 ib->btx_ring [entry].misc = 0; 566 ib->btx_ring [entry].misc = 0;
567 567
568 if (skb->len < ETH_ZLEN) 568 if (skb->len < ETH_ZLEN)
569 memset((char *)&ib->tx_buf[entry][0], 0, ETH_ZLEN); 569 memset((void *)&ib->tx_buf[entry][0], 0, ETH_ZLEN);
570 skb_copy_from_linear_data(skb, &ib->tx_buf[entry][0], skblen); 570 skb_copy_from_linear_data(skb, (void *)&ib->tx_buf[entry][0], skblen);
571 571
572 /* Now, give the packet to the lance */ 572 /* Now, give the packet to the lance */
573 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN); 573 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index dcdad217df51..69dba62e0bad 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -311,7 +311,7 @@ config MAC8390
311 311
312config MAC89x0 312config MAC89x0
313 tristate "Macintosh CS89x0 based ethernet cards" 313 tristate "Macintosh CS89x0 based ethernet cards"
314 depends on NET_ETHERNET && MAC && BROKEN 314 depends on NET_ETHERNET && MAC
315 ---help--- 315 ---help---
316 Support for CS89x0 chipset based Ethernet cards. If you have a 316 Support for CS89x0 chipset based Ethernet cards. If you have a
317 Nubus or LC-PDS network (Ethernet) card of this type, say Y and 317 Nubus or LC-PDS network (Ethernet) card of this type, say Y and
@@ -337,8 +337,8 @@ config MACSONIC
337 be called macsonic. 337 be called macsonic.
338 338
339config MACMACE 339config MACMACE
340 bool "Macintosh (AV) onboard MACE ethernet (EXPERIMENTAL)" 340 bool "Macintosh (AV) onboard MACE ethernet"
341 depends on NET_ETHERNET && MAC && EXPERIMENTAL 341 depends on NET_ETHERNET && MAC
342 select CRC32 342 select CRC32
343 help 343 help
344 Support for the onboard AMD 79C940 MACE Ethernet controller used in 344 Support for the onboard AMD 79C940 MACE Ethernet controller used in
diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index dd8ed456c8b2..1c3e293fbaf7 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -83,7 +83,6 @@ extern struct net_device *bagetlance_probe(int unit);
83extern struct net_device *mvme147lance_probe(int unit); 83extern struct net_device *mvme147lance_probe(int unit);
84extern struct net_device *tc515_probe(int unit); 84extern struct net_device *tc515_probe(int unit);
85extern struct net_device *lance_probe(int unit); 85extern struct net_device *lance_probe(int unit);
86extern struct net_device *mace_probe(int unit);
87extern struct net_device *mac8390_probe(int unit); 86extern struct net_device *mac8390_probe(int unit);
88extern struct net_device *mac89x0_probe(int unit); 87extern struct net_device *mac89x0_probe(int unit);
89extern struct net_device *mc32_probe(int unit); 88extern struct net_device *mc32_probe(int unit);
@@ -274,9 +273,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
274#ifdef CONFIG_MVME147_NET /* MVME147 internal Ethernet */ 273#ifdef CONFIG_MVME147_NET /* MVME147 internal Ethernet */
275 {mvme147lance_probe, 0}, 274 {mvme147lance_probe, 0},
276#endif 275#endif
277#ifdef CONFIG_MACMACE /* Mac 68k Quadra AV builtin Ethernet */
278 {mace_probe, 0},
279#endif
280#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */ 276#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
281 {mac8390_probe, 0}, 277 {mac8390_probe, 0},
282#endif 278#endif
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 1226cbba0450..81d5a374042a 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -562,7 +562,6 @@ static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
562 volatile struct lance_init_block *ib = lp->init_block; 562 volatile struct lance_init_block *ib = lp->init_block;
563 int entry, skblen, len; 563 int entry, skblen, len;
564 int status = 0; 564 int status = 0;
565 static int outs;
566 unsigned long flags; 565 unsigned long flags;
567 566
568 skblen = skb->len; 567 skblen = skb->len;
@@ -598,17 +597,16 @@ static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
598 ib->btx_ring [entry].length = (-len) | 0xf000; 597 ib->btx_ring [entry].length = (-len) | 0xf000;
599 ib->btx_ring [entry].misc = 0; 598 ib->btx_ring [entry].misc = 0;
600 599
601 skb_copy_from_linear_data(skb, &ib->tx_buf [entry][0], skblen); 600 skb_copy_from_linear_data(skb, (void *)&ib->tx_buf [entry][0], skblen);
602 601
603 /* Clear the slack of the packet, do I need this? */ 602 /* Clear the slack of the packet, do I need this? */
604 if (len != skblen) 603 if (len != skblen)
605 memset ((char *) &ib->tx_buf [entry][skblen], 0, len - skblen); 604 memset ((void *) &ib->tx_buf [entry][skblen], 0, len - skblen);
606 605
607 /* Now, give the packet to the lance */ 606 /* Now, give the packet to the lance */
608 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN); 607 ib->btx_ring [entry].tmd1_bits = (LE_T1_POK|LE_T1_OWN);
609 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask; 608 lp->tx_new = (lp->tx_new+1) & lp->tx_ring_mod_mask;
610 609 lp->stats.tx_bytes += skblen;
611 outs++;
612 610
613 if (TX_BUFFS_AVAIL <= 0) 611 if (TX_BUFFS_AVAIL <= 0)
614 netif_stop_queue(dev); 612 netif_stop_queue(dev);
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c
index a0e68e718531..a241ae7855a3 100644
--- a/drivers/net/ariadne.c
+++ b/drivers/net/ariadne.c
@@ -677,6 +677,7 @@ static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
677 priv->cur_tx -= TX_RING_SIZE; 677 priv->cur_tx -= TX_RING_SIZE;
678 priv->dirty_tx -= TX_RING_SIZE; 678 priv->dirty_tx -= TX_RING_SIZE;
679 } 679 }
680 priv->stats.tx_bytes += len;
680 681
681 /* Trigger an immediate send poll. */ 682 /* Trigger an immediate send poll. */
682 lance->RAP = CSR0; /* PCnet-ISA Controller Status */ 683 lance->RAP = CSR0; /* PCnet-ISA Controller Status */
diff --git a/drivers/net/jazzsonic.c b/drivers/net/jazzsonic.c
index d34afb52ea7f..75f6f441e876 100644
--- a/drivers/net/jazzsonic.c
+++ b/drivers/net/jazzsonic.c
@@ -88,6 +88,23 @@ static unsigned short known_revisions[] =
88 0xffff /* end of list */ 88 0xffff /* end of list */
89}; 89};
90 90
91static int jazzsonic_open(struct net_device* dev)
92{
93 if (request_irq(dev->irq, &sonic_interrupt, IRQF_DISABLED, "sonic", dev)) {
94 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
95 return -EAGAIN;
96 }
97 return sonic_open(dev);
98}
99
100static int jazzsonic_close(struct net_device* dev)
101{
102 int err;
103 err = sonic_close(dev);
104 free_irq(dev->irq, dev);
105 return err;
106}
107
91static int __init sonic_probe1(struct net_device *dev) 108static int __init sonic_probe1(struct net_device *dev)
92{ 109{
93 static unsigned version_printed; 110 static unsigned version_printed;
@@ -169,8 +186,8 @@ static int __init sonic_probe1(struct net_device *dev)
169 lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 186 lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
170 * SONIC_BUS_SCALE(lp->dma_bitmode)); 187 * SONIC_BUS_SCALE(lp->dma_bitmode));
171 188
172 dev->open = sonic_open; 189 dev->open = jazzsonic_open;
173 dev->stop = sonic_close; 190 dev->stop = jazzsonic_close;
174 dev->hard_start_xmit = sonic_send_packet; 191 dev->hard_start_xmit = sonic_send_packet;
175 dev->get_stats = sonic_get_stats; 192 dev->get_stats = sonic_get_stats;
176 dev->set_multicast_list = &sonic_multicast_list; 193 dev->set_multicast_list = &sonic_multicast_list;
@@ -260,8 +277,6 @@ MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
260module_param(sonic_debug, int, 0); 277module_param(sonic_debug, int, 0);
261MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)"); 278MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
262 279
263#define SONIC_IRQ_FLAG IRQF_DISABLED
264
265#include "sonic.c" 280#include "sonic.c"
266 281
267static int __devexit jazz_sonic_device_remove (struct platform_device *pdev) 282static int __devexit jazz_sonic_device_remove (struct platform_device *pdev)
@@ -269,11 +284,11 @@ static int __devexit jazz_sonic_device_remove (struct platform_device *pdev)
269 struct net_device *dev = platform_get_drvdata(pdev); 284 struct net_device *dev = platform_get_drvdata(pdev);
270 struct sonic_local* lp = netdev_priv(dev); 285 struct sonic_local* lp = netdev_priv(dev);
271 286
272 unregister_netdev (dev); 287 unregister_netdev(dev);
273 dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 288 dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
274 lp->descriptors, lp->descriptors_laddr); 289 lp->descriptors, lp->descriptors_laddr);
275 release_region (dev->base_addr, SONIC_MEM_SIZE); 290 release_region (dev->base_addr, SONIC_MEM_SIZE);
276 free_netdev (dev); 291 free_netdev(dev);
277 292
278 return 0; 293 return 0;
279} 294}
diff --git a/drivers/net/mac8390.c b/drivers/net/mac8390.c
index a12bb64e3694..90b0c3ed4bb6 100644
--- a/drivers/net/mac8390.c
+++ b/drivers/net/mac8390.c
@@ -14,6 +14,8 @@
14/* 2001-05-15: support for Cabletron ported from old daynaport driver 14/* 2001-05-15: support for Cabletron ported from old daynaport driver
15 * and fixed access to Sonic Sys card which masquerades as a Farallon 15 * and fixed access to Sonic Sys card which masquerades as a Farallon
16 * by rayk@knightsmanor.org */ 16 * by rayk@knightsmanor.org */
17/* 2002-12-30: Try to support more cards, some clues from NetBSD driver */
18/* 2003-12-26: Make sure Asante cards always work. */
17 19
18#include <linux/module.h> 20#include <linux/module.h>
19#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -61,25 +63,21 @@ static char version[] =
61#define DAYNA_8390_BASE 0x80000 63#define DAYNA_8390_BASE 0x80000
62#define DAYNA_8390_MEM 0x00000 64#define DAYNA_8390_MEM 0x00000
63 65
64#define KINETICS_8390_BASE 0x80000
65#define KINETICS_8390_MEM 0x00000
66
67#define CABLETRON_8390_BASE 0x90000 66#define CABLETRON_8390_BASE 0x90000
68#define CABLETRON_8390_MEM 0x00000 67#define CABLETRON_8390_MEM 0x00000
69 68
69#define INTERLAN_8390_BASE 0xE0000
70#define INTERLAN_8390_MEM 0xD0000
71
70enum mac8390_type { 72enum mac8390_type {
71 MAC8390_NONE = -1, 73 MAC8390_NONE = -1,
72 MAC8390_APPLE, 74 MAC8390_APPLE,
73 MAC8390_ASANTE, 75 MAC8390_ASANTE,
74 MAC8390_FARALLON, /* Apple, Asante, and Farallon are all compatible */ 76 MAC8390_FARALLON,
75 MAC8390_CABLETRON, 77 MAC8390_CABLETRON,
76 MAC8390_DAYNA, 78 MAC8390_DAYNA,
77 MAC8390_INTERLAN, 79 MAC8390_INTERLAN,
78 MAC8390_KINETICS, 80 MAC8390_KINETICS,
79 MAC8390_FOCUS,
80 MAC8390_SONICSYS,
81 MAC8390_DAYNA2,
82 MAC8390_DAYNA3,
83}; 81};
84 82
85static const char * cardname[] = { 83static const char * cardname[] = {
@@ -90,10 +88,6 @@ static const char * cardname[] = {
90 "dayna", 88 "dayna",
91 "interlan", 89 "interlan",
92 "kinetics", 90 "kinetics",
93 "focus",
94 "sonic systems",
95 "dayna2",
96 "dayna_lc",
97}; 91};
98 92
99static int word16[] = { 93static int word16[] = {
@@ -104,10 +98,6 @@ static int word16[] = {
104 0, /* dayna */ 98 0, /* dayna */
105 1, /* interlan */ 99 1, /* interlan */
106 0, /* kinetics */ 100 0, /* kinetics */
107 1, /* focus (??) */
108 1, /* sonic systems */
109 1, /* dayna2 */
110 1, /* dayna-lc */
111}; 101};
112 102
113/* on which cards do we use NuBus resources? */ 103/* on which cards do we use NuBus resources? */
@@ -119,10 +109,12 @@ static int useresources[] = {
119 0, /* dayna */ 109 0, /* dayna */
120 0, /* interlan */ 110 0, /* interlan */
121 0, /* kinetics */ 111 0, /* kinetics */
122 0, /* focus (??) */ 112};
123 1, /* sonic systems */ 113
124 1, /* dayna2 */ 114enum mac8390_access {
125 1, /* dayna-lc */ 115 ACCESS_UNKNOWN = 0,
116 ACCESS_32,
117 ACCESS_16,
126}; 118};
127 119
128extern enum mac8390_type mac8390_ident(struct nubus_dev * dev); 120extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
@@ -134,8 +126,9 @@ static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
134static int mac8390_open(struct net_device * dev); 126static int mac8390_open(struct net_device * dev);
135static int mac8390_close(struct net_device * dev); 127static int mac8390_close(struct net_device * dev);
136static void mac8390_no_reset(struct net_device *dev); 128static void mac8390_no_reset(struct net_device *dev);
129static void interlan_reset(struct net_device *dev);
137 130
138/* Sane (32-bit chunk memory read/write) - Apple/Asante/Farallon do this*/ 131/* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/
139static void sane_get_8390_hdr(struct net_device *dev, 132static void sane_get_8390_hdr(struct net_device *dev,
140 struct e8390_pkt_hdr *hdr, int ring_page); 133 struct e8390_pkt_hdr *hdr, int ring_page);
141static void sane_block_input(struct net_device * dev, int count, 134static void sane_block_input(struct net_device * dev, int count,
@@ -172,23 +165,93 @@ static void word_memcpy_fromcard(void *tp, const void *fp, int count);
172 165
173enum mac8390_type __init mac8390_ident(struct nubus_dev * dev) 166enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
174{ 167{
175 if (dev->dr_sw == NUBUS_DRSW_ASANTE) 168 switch (dev->dr_sw) {
176 return MAC8390_ASANTE; 169 case NUBUS_DRSW_3COM:
177 if (dev->dr_sw == NUBUS_DRSW_FARALLON) 170 switch (dev->dr_hw) {
178 return MAC8390_FARALLON; 171 case NUBUS_DRHW_APPLE_SONIC_NB:
179 if (dev->dr_sw == NUBUS_DRSW_KINETICS) 172 case NUBUS_DRHW_APPLE_SONIC_LC:
180 return MAC8390_KINETICS; 173 case NUBUS_DRHW_SONNET:
181 if (dev->dr_sw == NUBUS_DRSW_DAYNA) 174 return MAC8390_NONE;
182 return MAC8390_DAYNA; 175 break;
183 if (dev->dr_sw == NUBUS_DRSW_DAYNA2) 176 default:
184 return MAC8390_DAYNA2; 177 return MAC8390_APPLE;
185 if (dev->dr_sw == NUBUS_DRSW_DAYNA_LC) 178 break;
186 return MAC8390_DAYNA3; 179 }
187 if (dev->dr_hw == NUBUS_DRHW_CABLETRON) 180 break;
188 return MAC8390_CABLETRON; 181
182 case NUBUS_DRSW_APPLE:
183 switch (dev->dr_hw) {
184 case NUBUS_DRHW_ASANTE_LC:
185 return MAC8390_NONE;
186 break;
187 case NUBUS_DRHW_CABLETRON:
188 return MAC8390_CABLETRON;
189 break;
190 default:
191 return MAC8390_APPLE;
192 break;
193 }
194 break;
195
196 case NUBUS_DRSW_ASANTE:
197 return MAC8390_ASANTE;
198 break;
199
200 case NUBUS_DRSW_TECHWORKS:
201 case NUBUS_DRSW_DAYNA2:
202 case NUBUS_DRSW_DAYNA_LC:
203 if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
204 return MAC8390_CABLETRON;
205 else
206 return MAC8390_APPLE;
207 break;
208
209 case NUBUS_DRSW_FARALLON:
210 return MAC8390_FARALLON;
211 break;
212
213 case NUBUS_DRSW_KINETICS:
214 switch (dev->dr_hw) {
215 case NUBUS_DRHW_INTERLAN:
216 return MAC8390_INTERLAN;
217 break;
218 default:
219 return MAC8390_KINETICS;
220 break;
221 }
222 break;
223
224 case NUBUS_DRSW_DAYNA:
225 // These correspond to Dayna Sonic cards
226 // which use the macsonic driver
227 if (dev->dr_hw == NUBUS_DRHW_SMC9194 ||
228 dev->dr_hw == NUBUS_DRHW_INTERLAN )
229 return MAC8390_NONE;
230 else
231 return MAC8390_DAYNA;
232 break;
233 }
189 return MAC8390_NONE; 234 return MAC8390_NONE;
190} 235}
191 236
237enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
238{
239 unsigned long outdata = 0xA5A0B5B0;
240 unsigned long indata = 0x00000000;
241 /* Try writing 32 bits */
242 memcpy((char *)membase, (char *)&outdata, 4);
243 /* Now compare them */
244 if (memcmp((char *)&outdata, (char *)membase, 4) == 0)
245 return ACCESS_32;
246 /* Write 16 bit output */
247 word_memcpy_tocard((char *)membase, (char *)&outdata, 4);
248 /* Now read it back */
249 word_memcpy_fromcard((char *)&indata, (char *)membase, 4);
250 if (outdata == indata)
251 return ACCESS_16;
252 return ACCESS_UNKNOWN;
253}
254
192int __init mac8390_memsize(unsigned long membase) 255int __init mac8390_memsize(unsigned long membase)
193{ 256{
194 unsigned long flags; 257 unsigned long flags;
@@ -287,14 +350,6 @@ struct net_device * __init mac8390_probe(int unit)
287 continue; 350 continue;
288 } else { 351 } else {
289 nubus_get_rsrc_mem(dev->dev_addr, &ent, 6); 352 nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
290 /* Some Sonic Sys cards masquerade as Farallon */
291 if (cardtype == MAC8390_FARALLON &&
292 dev->dev_addr[0] == 0x0 &&
293 dev->dev_addr[1] == 0x40 &&
294 dev->dev_addr[2] == 0x10) {
295 /* This is really Sonic Sys card */
296 cardtype = MAC8390_SONICSYS;
297 }
298 } 353 }
299 354
300 if (useresources[cardtype] == 1) { 355 if (useresources[cardtype] == 1) {
@@ -334,6 +389,17 @@ struct net_device * __init mac8390_probe(int unit)
334 dev->mem_start + 389 dev->mem_start +
335 mac8390_memsize(dev->mem_start); 390 mac8390_memsize(dev->mem_start);
336 break; 391 break;
392 case MAC8390_INTERLAN:
393 dev->base_addr =
394 (int)(ndev->board->slot_addr +
395 INTERLAN_8390_BASE);
396 dev->mem_start =
397 (int)(ndev->board->slot_addr +
398 INTERLAN_8390_MEM);
399 dev->mem_end =
400 dev->mem_start +
401 mac8390_memsize(dev->mem_start);
402 break;
337 case MAC8390_CABLETRON: 403 case MAC8390_CABLETRON:
338 dev->base_addr = 404 dev->base_addr =
339 (int)(ndev->board->slot_addr + 405 (int)(ndev->board->slot_addr +
@@ -356,8 +422,8 @@ struct net_device * __init mac8390_probe(int unit)
356 422
357 default: 423 default:
358 printk(KERN_ERR "Card type %s is" 424 printk(KERN_ERR "Card type %s is"
359 " unsupported, sorry\n", 425 " unsupported, sorry\n",
360 cardname[cardtype]); 426 ndev->board->name);
361 continue; 427 continue;
362 } 428 }
363 } 429 }
@@ -438,7 +504,7 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
438 24, 26, 28, 30 504 24, 26, 28, 30
439 }; 505 };
440 506
441 int access_bitmode; 507 int access_bitmode = 0;
442 508
443 /* Now fill in our stuff */ 509 /* Now fill in our stuff */
444 dev->open = &mac8390_open; 510 dev->open = &mac8390_open;
@@ -468,29 +534,47 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
468 534
469 /* Fill in model-specific information and functions */ 535 /* Fill in model-specific information and functions */
470 switch(type) { 536 switch(type) {
471 case MAC8390_SONICSYS:
472 /* 16 bit card, register map is reversed */
473 ei_status.reset_8390 = &mac8390_no_reset;
474 ei_status.block_input = &slow_sane_block_input;
475 ei_status.block_output = &slow_sane_block_output;
476 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
477 ei_status.reg_offset = back4_offsets;
478 access_bitmode = 0;
479 break;
480 case MAC8390_FARALLON: 537 case MAC8390_FARALLON:
481 case MAC8390_APPLE: 538 case MAC8390_APPLE:
539 switch(mac8390_testio(dev->mem_start)) {
540 case ACCESS_UNKNOWN:
541 printk("Don't know how to access card memory!\n");
542 return -ENODEV;
543 break;
544
545 case ACCESS_16:
546 /* 16 bit card, register map is reversed */
547 ei_status.reset_8390 = &mac8390_no_reset;
548 ei_status.block_input = &slow_sane_block_input;
549 ei_status.block_output = &slow_sane_block_output;
550 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
551 ei_status.reg_offset = back4_offsets;
552 break;
553
554 case ACCESS_32:
555 /* 32 bit card, register map is reversed */
556 ei_status.reset_8390 = &mac8390_no_reset;
557 ei_status.block_input = &sane_block_input;
558 ei_status.block_output = &sane_block_output;
559 ei_status.get_8390_hdr = &sane_get_8390_hdr;
560 ei_status.reg_offset = back4_offsets;
561 access_bitmode = 1;
562 break;
563 }
564 break;
565
482 case MAC8390_ASANTE: 566 case MAC8390_ASANTE:
483 case MAC8390_DAYNA2: 567 /* Some Asante cards pass the 32 bit test
484 case MAC8390_DAYNA3: 568 * but overwrite system memory when run at 32 bit.
485 /* 32 bit card, register map is reversed */ 569 * so we run them all at 16 bit.
486 /* sane */ 570 */
487 ei_status.reset_8390 = &mac8390_no_reset; 571 ei_status.reset_8390 = &mac8390_no_reset;
488 ei_status.block_input = &sane_block_input; 572 ei_status.block_input = &slow_sane_block_input;
489 ei_status.block_output = &sane_block_output; 573 ei_status.block_output = &slow_sane_block_output;
490 ei_status.get_8390_hdr = &sane_get_8390_hdr; 574 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
491 ei_status.reg_offset = back4_offsets; 575 ei_status.reg_offset = back4_offsets;
492 access_bitmode = 1;
493 break; 576 break;
577
494 case MAC8390_CABLETRON: 578 case MAC8390_CABLETRON:
495 /* 16 bit card, register map is short forward */ 579 /* 16 bit card, register map is short forward */
496 ei_status.reset_8390 = &mac8390_no_reset; 580 ei_status.reset_8390 = &mac8390_no_reset;
@@ -498,21 +582,30 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
498 ei_status.block_output = &slow_sane_block_output; 582 ei_status.block_output = &slow_sane_block_output;
499 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr; 583 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
500 ei_status.reg_offset = fwrd2_offsets; 584 ei_status.reg_offset = fwrd2_offsets;
501 access_bitmode = 0;
502 break; 585 break;
586
503 case MAC8390_DAYNA: 587 case MAC8390_DAYNA:
504 case MAC8390_KINETICS: 588 case MAC8390_KINETICS:
505 /* 16 bit memory */ 589 /* 16 bit memory, register map is forward */
506 /* dayna and similar */ 590 /* dayna and similar */
507 ei_status.reset_8390 = &mac8390_no_reset; 591 ei_status.reset_8390 = &mac8390_no_reset;
508 ei_status.block_input = &dayna_block_input; 592 ei_status.block_input = &dayna_block_input;
509 ei_status.block_output = &dayna_block_output; 593 ei_status.block_output = &dayna_block_output;
510 ei_status.get_8390_hdr = &dayna_get_8390_hdr; 594 ei_status.get_8390_hdr = &dayna_get_8390_hdr;
511 ei_status.reg_offset = fwrd4_offsets; 595 ei_status.reg_offset = fwrd4_offsets;
512 access_bitmode = 0;
513 break; 596 break;
597
598 case MAC8390_INTERLAN:
599 /* 16 bit memory, register map is forward */
600 ei_status.reset_8390 = &interlan_reset;
601 ei_status.block_input = &slow_sane_block_input;
602 ei_status.block_output = &slow_sane_block_output;
603 ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
604 ei_status.reg_offset = fwrd4_offsets;
605 break;
606
514 default: 607 default:
515 printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]); 608 printk(KERN_ERR "Card type %s is unsupported, sorry\n", ndev->board->name);
516 return -ENODEV; 609 return -ENODEV;
517 } 610 }
518 611
@@ -530,9 +623,9 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
530 printk(":"); 623 printk(":");
531 } 624 }
532 } 625 }
533 printk(" IRQ %d, shared memory at %#lx-%#lx, %d-bit access.\n", 626 printk(" IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
534 dev->irq, dev->mem_start, dev->mem_end-1, 627 dev->irq, (int)((dev->mem_end - dev->mem_start)/0x1000) * 4,
535 access_bitmode?32:16); 628 dev->mem_start, access_bitmode?32:16);
536 return 0; 629 return 0;
537} 630}
538 631
@@ -561,6 +654,18 @@ static void mac8390_no_reset(struct net_device *dev)
561 return; 654 return;
562} 655}
563 656
657static void interlan_reset(struct net_device *dev)
658{
659 unsigned char *target=nubus_slot_addr(IRQ2SLOT(dev->irq));
660 if (ei_debug > 1)
661 printk("Need to reset the NS8390 t=%lu...", jiffies);
662 ei_status.txing = 0;
663 target[0xC0000] = 0;
664 if (ei_debug > 1)
665 printk("reset complete\n");
666 return;
667}
668
564/* dayna_memcpy_fromio/dayna_memcpy_toio */ 669/* dayna_memcpy_fromio/dayna_memcpy_toio */
565/* directly from daynaport.c by Alan Cox */ 670/* directly from daynaport.c by Alan Cox */
566static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count) 671static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
diff --git a/drivers/net/mac89x0.c b/drivers/net/mac89x0.c
index 90e695d53266..26a3b45a4a34 100644
--- a/drivers/net/mac89x0.c
+++ b/drivers/net/mac89x0.c
@@ -128,7 +128,7 @@ struct net_local {
128extern void reset_chip(struct net_device *dev); 128extern void reset_chip(struct net_device *dev);
129#endif 129#endif
130static int net_open(struct net_device *dev); 130static int net_open(struct net_device *dev);
131static int net_send_packet(struct sk_buff *skb, struct net_device *dev); 131static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
132static irqreturn_t net_interrupt(int irq, void *dev_id); 132static irqreturn_t net_interrupt(int irq, void *dev_id);
133static void set_multicast_list(struct net_device *dev); 133static void set_multicast_list(struct net_device *dev);
134static void net_rx(struct net_device *dev); 134static void net_rx(struct net_device *dev);
@@ -374,56 +374,39 @@ net_open(struct net_device *dev)
374static int 374static int
375net_send_packet(struct sk_buff *skb, struct net_device *dev) 375net_send_packet(struct sk_buff *skb, struct net_device *dev)
376{ 376{
377 if (dev->tbusy) { 377 struct net_local *lp = netdev_priv(dev);
378 /* If we get here, some higher level has decided we are broken. 378 unsigned long flags;
379 There should really be a "kick me" function call instead. */
380 int tickssofar = jiffies - dev->trans_start;
381 if (tickssofar < 5)
382 return 1;
383 if (net_debug > 0) printk("%s: transmit timed out, %s?\n", dev->name,
384 tx_done(dev) ? "IRQ conflict" : "network cable problem");
385 /* Try to restart the adaptor. */
386 dev->tbusy=0;
387 dev->trans_start = jiffies;
388 }
389
390 /* Block a timer-based transmit from overlapping. This could better be
391 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
392 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0)
393 printk("%s: Transmitter access conflict.\n", dev->name);
394 else {
395 struct net_local *lp = netdev_priv(dev);
396 unsigned long flags;
397
398 if (net_debug > 3)
399 printk("%s: sent %d byte packet of type %x\n",
400 dev->name, skb->len,
401 (skb->data[ETH_ALEN+ETH_ALEN] << 8)
402 | skb->data[ETH_ALEN+ETH_ALEN+1]);
403
404 /* keep the upload from being interrupted, since we
405 ask the chip to start transmitting before the
406 whole packet has been completely uploaded. */
407 local_irq_save(flags);
408 379
409 /* initiate a transmit sequence */ 380 if (net_debug > 3)
410 writereg(dev, PP_TxCMD, lp->send_cmd); 381 printk("%s: sent %d byte packet of type %x\n",
411 writereg(dev, PP_TxLength, skb->len); 382 dev->name, skb->len,
383 (skb->data[ETH_ALEN+ETH_ALEN] << 8)
384 | skb->data[ETH_ALEN+ETH_ALEN+1]);
412 385
413 /* Test to see if the chip has allocated memory for the packet */ 386 /* keep the upload from being interrupted, since we
414 if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) { 387 ask the chip to start transmitting before the
415 /* Gasp! It hasn't. But that shouldn't happen since 388 whole packet has been completely uploaded. */
416 we're waiting for TxOk, so return 1 and requeue this packet. */ 389 local_irq_save(flags);
417 local_irq_restore(flags); 390 netif_stop_queue(dev);
418 return 1;
419 }
420 391
421 /* Write the contents of the packet */ 392 /* initiate a transmit sequence */
422 memcpy_toio(dev->mem_start + PP_TxFrame, skb->data, skb->len+1); 393 writereg(dev, PP_TxCMD, lp->send_cmd);
394 writereg(dev, PP_TxLength, skb->len);
423 395
396 /* Test to see if the chip has allocated memory for the packet */
397 if ((readreg(dev, PP_BusST) & READY_FOR_TX_NOW) == 0) {
398 /* Gasp! It hasn't. But that shouldn't happen since
399 we're waiting for TxOk, so return 1 and requeue this packet. */
424 local_irq_restore(flags); 400 local_irq_restore(flags);
425 dev->trans_start = jiffies; 401 return 1;
426 } 402 }
403
404 /* Write the contents of the packet */
405 skb_copy_from_linear_data(skb, (void *)(dev->mem_start + PP_TxFrame),
406 skb->len+1);
407
408 local_irq_restore(flags);
409 dev->trans_start = jiffies;
427 dev_kfree_skb (skb); 410 dev_kfree_skb (skb);
428 411
429 return 0; 412 return 0;
@@ -441,9 +424,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
441 printk ("net_interrupt(): irq %d for unknown device.\n", irq); 424 printk ("net_interrupt(): irq %d for unknown device.\n", irq);
442 return IRQ_NONE; 425 return IRQ_NONE;
443 } 426 }
444 if (dev->interrupt)
445 printk("%s: Re-entering the interrupt handler.\n", dev->name);
446 dev->interrupt = 1;
447 427
448 ioaddr = dev->base_addr; 428 ioaddr = dev->base_addr;
449 lp = netdev_priv(dev); 429 lp = netdev_priv(dev);
@@ -464,8 +444,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
464 break; 444 break;
465 case ISQ_TRANSMITTER_EVENT: 445 case ISQ_TRANSMITTER_EVENT:
466 lp->stats.tx_packets++; 446 lp->stats.tx_packets++;
467 dev->tbusy = 0; 447 netif_wake_queue(dev);
468 mark_bh(NET_BH); /* Inform upper layers. */
469 if ((status & TX_OK) == 0) lp->stats.tx_errors++; 448 if ((status & TX_OK) == 0) lp->stats.tx_errors++;
470 if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++; 449 if (status & TX_LOST_CRS) lp->stats.tx_carrier_errors++;
471 if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++; 450 if (status & TX_SQE_ERROR) lp->stats.tx_heartbeat_errors++;
@@ -479,8 +458,7 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
479 That shouldn't happen since we only ever 458 That shouldn't happen since we only ever
480 load one packet. Shrug. Do the right 459 load one packet. Shrug. Do the right
481 thing anyway. */ 460 thing anyway. */
482 dev->tbusy = 0; 461 netif_wake_queue(dev);
483 mark_bh(NET_BH); /* Inform upper layers. */
484 } 462 }
485 if (status & TX_UNDERRUN) { 463 if (status & TX_UNDERRUN) {
486 if (net_debug > 0) printk("%s: transmit underrun\n", dev->name); 464 if (net_debug > 0) printk("%s: transmit underrun\n", dev->name);
@@ -497,7 +475,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
497 break; 475 break;
498 } 476 }
499 } 477 }
500 dev->interrupt = 0;
501 return IRQ_HANDLED; 478 return IRQ_HANDLED;
502} 479}
503 480
@@ -531,7 +508,8 @@ net_rx(struct net_device *dev)
531 } 508 }
532 skb_put(skb, length); 509 skb_put(skb, length);
533 510
534 memcpy_fromio(skb->data, dev->mem_start + PP_RxFrame, length); 511 skb_copy_to_linear_data(skb, (void *)(dev->mem_start + PP_RxFrame),
512 length);
535 513
536 if (net_debug > 3)printk("%s: received %d byte packet of type %x\n", 514 if (net_debug > 3)printk("%s: received %d byte packet of type %x\n",
537 dev->name, length, 515 dev->name, length,
@@ -610,8 +588,6 @@ static void set_multicast_list(struct net_device *dev)
610static int set_mac_address(struct net_device *dev, void *addr) 588static int set_mac_address(struct net_device *dev, void *addr)
611{ 589{
612 int i; 590 int i;
613 if (dev->start)
614 return -EBUSY;
615 printk("%s: Setting MAC address to ", dev->name); 591 printk("%s: Setting MAC address to ", dev->name);
616 for (i = 0; i < 6; i++) 592 for (i = 0; i < 6; i++)
617 printk(" %2.2x", dev->dev_addr[i] = ((unsigned char *)addr)[i]); 593 printk(" %2.2x", dev->dev_addr[i] = ((unsigned char *)addr)[i]);
diff --git a/drivers/net/macmace.c b/drivers/net/macmace.c
index 27911c07558d..fef3193121f9 100644
--- a/drivers/net/macmace.c
+++ b/drivers/net/macmace.c
@@ -12,6 +12,11 @@
12 * Copyright (C) 1998 Alan Cox <alan@redhat.com> 12 * Copyright (C) 1998 Alan Cox <alan@redhat.com>
13 * 13 *
14 * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver 14 * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
15 *
16 * Copyright (C) 2007 Finn Thain
17 *
18 * Converted to DMA API, converted to unified driver model,
19 * sync'd some routines with mace.c and fixed various bugs.
15 */ 20 */
16 21
17 22
@@ -23,8 +28,9 @@
23#include <linux/string.h> 28#include <linux/string.h>
24#include <linux/crc32.h> 29#include <linux/crc32.h>
25#include <linux/bitrev.h> 30#include <linux/bitrev.h>
31#include <linux/dma-mapping.h>
32#include <linux/platform_device.h>
26#include <asm/io.h> 33#include <asm/io.h>
27#include <asm/pgtable.h>
28#include <asm/irq.h> 34#include <asm/irq.h>
29#include <asm/macintosh.h> 35#include <asm/macintosh.h>
30#include <asm/macints.h> 36#include <asm/macints.h>
@@ -32,13 +38,20 @@
32#include <asm/page.h> 38#include <asm/page.h>
33#include "mace.h" 39#include "mace.h"
34 40
35#define N_TX_RING 1 41static char mac_mace_string[] = "macmace";
36#define N_RX_RING 8 42static struct platform_device *mac_mace_device;
37#define N_RX_PAGES ((N_RX_RING * 0x0800 + PAGE_SIZE - 1) / PAGE_SIZE) 43
44#define N_TX_BUFF_ORDER 0
45#define N_TX_RING (1 << N_TX_BUFF_ORDER)
46#define N_RX_BUFF_ORDER 3
47#define N_RX_RING (1 << N_RX_BUFF_ORDER)
48
38#define TX_TIMEOUT HZ 49#define TX_TIMEOUT HZ
39 50
40/* Bits in transmit DMA status */ 51#define MACE_BUFF_SIZE 0x800
41#define TX_DMA_ERR 0x80 52
53/* Chip rev needs workaround on HW & multicast addr change */
54#define BROKEN_ADDRCHG_REV 0x0941
42 55
43/* The MACE is simply wired down on a Mac68K box */ 56/* The MACE is simply wired down on a Mac68K box */
44 57
@@ -47,40 +60,46 @@
47 60
48struct mace_data { 61struct mace_data {
49 volatile struct mace *mace; 62 volatile struct mace *mace;
50 volatile unsigned char *tx_ring; 63 unsigned char *tx_ring;
51 volatile unsigned char *tx_ring_phys; 64 dma_addr_t tx_ring_phys;
52 volatile unsigned char *rx_ring; 65 unsigned char *rx_ring;
53 volatile unsigned char *rx_ring_phys; 66 dma_addr_t rx_ring_phys;
54 int dma_intr; 67 int dma_intr;
55 struct net_device_stats stats; 68 struct net_device_stats stats;
56 int rx_slot, rx_tail; 69 int rx_slot, rx_tail;
57 int tx_slot, tx_sloti, tx_count; 70 int tx_slot, tx_sloti, tx_count;
71 int chipid;
72 struct device *device;
58}; 73};
59 74
60struct mace_frame { 75struct mace_frame {
61 u16 len; 76 u8 rcvcnt;
62 u16 status; 77 u8 pad1;
63 u16 rntpc; 78 u8 rcvsts;
64 u16 rcvcc; 79 u8 pad2;
65 u32 pad1; 80 u8 rntpc;
66 u32 pad2; 81 u8 pad3;
82 u8 rcvcc;
83 u8 pad4;
84 u32 pad5;
85 u32 pad6;
67 u8 data[1]; 86 u8 data[1];
68 /* And frame continues.. */ 87 /* And frame continues.. */
69}; 88};
70 89
71#define PRIV_BYTES sizeof(struct mace_data) 90#define PRIV_BYTES sizeof(struct mace_data)
72 91
73extern void psc_debug_dump(void);
74
75static int mace_open(struct net_device *dev); 92static int mace_open(struct net_device *dev);
76static int mace_close(struct net_device *dev); 93static int mace_close(struct net_device *dev);
77static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev); 94static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
78static struct net_device_stats *mace_stats(struct net_device *dev); 95static struct net_device_stats *mace_stats(struct net_device *dev);
79static void mace_set_multicast(struct net_device *dev); 96static void mace_set_multicast(struct net_device *dev);
80static int mace_set_address(struct net_device *dev, void *addr); 97static int mace_set_address(struct net_device *dev, void *addr);
98static void mace_reset(struct net_device *dev);
81static irqreturn_t mace_interrupt(int irq, void *dev_id); 99static irqreturn_t mace_interrupt(int irq, void *dev_id);
82static irqreturn_t mace_dma_intr(int irq, void *dev_id); 100static irqreturn_t mace_dma_intr(int irq, void *dev_id);
83static void mace_tx_timeout(struct net_device *dev); 101static void mace_tx_timeout(struct net_device *dev);
102static void __mace_set_address(struct net_device *dev, void *addr);
84 103
85/* 104/*
86 * Load a receive DMA channel with a base address and ring length 105 * Load a receive DMA channel with a base address and ring length
@@ -88,7 +107,7 @@ static void mace_tx_timeout(struct net_device *dev);
88 107
89static void mace_load_rxdma_base(struct net_device *dev, int set) 108static void mace_load_rxdma_base(struct net_device *dev, int set)
90{ 109{
91 struct mace_data *mp = (struct mace_data *) dev->priv; 110 struct mace_data *mp = netdev_priv(dev);
92 111
93 psc_write_word(PSC_ENETRD_CMD + set, 0x0100); 112 psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
94 psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys); 113 psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
@@ -103,7 +122,7 @@ static void mace_load_rxdma_base(struct net_device *dev, int set)
103 122
104static void mace_rxdma_reset(struct net_device *dev) 123static void mace_rxdma_reset(struct net_device *dev)
105{ 124{
106 struct mace_data *mp = (struct mace_data *) dev->priv; 125 struct mace_data *mp = netdev_priv(dev);
107 volatile struct mace *mace = mp->mace; 126 volatile struct mace *mace = mp->mace;
108 u8 maccc = mace->maccc; 127 u8 maccc = mace->maccc;
109 128
@@ -130,7 +149,7 @@ static void mace_rxdma_reset(struct net_device *dev)
130 149
131static void mace_txdma_reset(struct net_device *dev) 150static void mace_txdma_reset(struct net_device *dev)
132{ 151{
133 struct mace_data *mp = (struct mace_data *) dev->priv; 152 struct mace_data *mp = netdev_priv(dev);
134 volatile struct mace *mace = mp->mace; 153 volatile struct mace *mace = mp->mace;
135 u8 maccc; 154 u8 maccc;
136 155
@@ -168,7 +187,7 @@ static void mace_dma_off(struct net_device *dev)
168 * model of Macintrash has a MACE (AV macintoshes) 187 * model of Macintrash has a MACE (AV macintoshes)
169 */ 188 */
170 189
171struct net_device *mace_probe(int unit) 190static int __devinit mace_probe(struct platform_device *pdev)
172{ 191{
173 int j; 192 int j;
174 struct mace_data *mp; 193 struct mace_data *mp;
@@ -179,24 +198,28 @@ struct net_device *mace_probe(int unit)
179 int err; 198 int err;
180 199
181 if (found || macintosh_config->ether_type != MAC_ETHER_MACE) 200 if (found || macintosh_config->ether_type != MAC_ETHER_MACE)
182 return ERR_PTR(-ENODEV); 201 return -ENODEV;
183 202
184 found = 1; /* prevent 'finding' one on every device probe */ 203 found = 1; /* prevent 'finding' one on every device probe */
185 204
186 dev = alloc_etherdev(PRIV_BYTES); 205 dev = alloc_etherdev(PRIV_BYTES);
187 if (!dev) 206 if (!dev)
188 return ERR_PTR(-ENOMEM); 207 return -ENOMEM;
189 208
190 if (unit >= 0) 209 mp = netdev_priv(dev);
191 sprintf(dev->name, "eth%d", unit); 210
211 mp->device = &pdev->dev;
212 SET_NETDEV_DEV(dev, &pdev->dev);
213 SET_MODULE_OWNER(dev);
192 214
193 mp = (struct mace_data *) dev->priv;
194 dev->base_addr = (u32)MACE_BASE; 215 dev->base_addr = (u32)MACE_BASE;
195 mp->mace = (volatile struct mace *) MACE_BASE; 216 mp->mace = (volatile struct mace *) MACE_BASE;
196 217
197 dev->irq = IRQ_MAC_MACE; 218 dev->irq = IRQ_MAC_MACE;
198 mp->dma_intr = IRQ_MAC_MACE_DMA; 219 mp->dma_intr = IRQ_MAC_MACE_DMA;
199 220
221 mp->chipid = mp->mace->chipid_hi << 8 | mp->mace->chipid_lo;
222
200 /* 223 /*
201 * The PROM contains 8 bytes which total 0xFF when XOR'd 224 * The PROM contains 8 bytes which total 0xFF when XOR'd
202 * together. Due to the usual peculiar apple brain damage 225 * together. Due to the usual peculiar apple brain damage
@@ -217,7 +240,7 @@ struct net_device *mace_probe(int unit)
217 240
218 if (checksum != 0xFF) { 241 if (checksum != 0xFF) {
219 free_netdev(dev); 242 free_netdev(dev);
220 return ERR_PTR(-ENODEV); 243 return -ENODEV;
221 } 244 }
222 245
223 memset(&mp->stats, 0, sizeof(mp->stats)); 246 memset(&mp->stats, 0, sizeof(mp->stats));
@@ -237,22 +260,98 @@ struct net_device *mace_probe(int unit)
237 260
238 err = register_netdev(dev); 261 err = register_netdev(dev);
239 if (!err) 262 if (!err)
240 return dev; 263 return 0;
241 264
242 free_netdev(dev); 265 free_netdev(dev);
243 return ERR_PTR(err); 266 return err;
267}
268
269/*
270 * Reset the chip.
271 */
272
273static void mace_reset(struct net_device *dev)
274{
275 struct mace_data *mp = netdev_priv(dev);
276 volatile struct mace *mb = mp->mace;
277 int i;
278
279 /* soft-reset the chip */
280 i = 200;
281 while (--i) {
282 mb->biucc = SWRST;
283 if (mb->biucc & SWRST) {
284 udelay(10);
285 continue;
286 }
287 break;
288 }
289 if (!i) {
290 printk(KERN_ERR "macmace: cannot reset chip!\n");
291 return;
292 }
293
294 mb->maccc = 0; /* turn off tx, rx */
295 mb->imr = 0xFF; /* disable all intrs for now */
296 i = mb->ir;
297
298 mb->biucc = XMTSP_64;
299 mb->utr = RTRD;
300 mb->fifocc = XMTFW_8 | RCVFW_64 | XMTFWU | RCVFWU;
301
302 mb->xmtfc = AUTO_PAD_XMIT; /* auto-pad short frames */
303 mb->rcvfc = 0;
304
305 /* load up the hardware address */
306 __mace_set_address(dev, dev->dev_addr);
307
308 /* clear the multicast filter */
309 if (mp->chipid == BROKEN_ADDRCHG_REV)
310 mb->iac = LOGADDR;
311 else {
312 mb->iac = ADDRCHG | LOGADDR;
313 while ((mb->iac & ADDRCHG) != 0)
314 ;
315 }
316 for (i = 0; i < 8; ++i)
317 mb->ladrf = 0;
318
319 /* done changing address */
320 if (mp->chipid != BROKEN_ADDRCHG_REV)
321 mb->iac = 0;
322
323 mb->plscc = PORTSEL_AUI;
244} 324}
245 325
246/* 326/*
247 * Load the address on a mace controller. 327 * Load the address on a mace controller.
248 */ 328 */
249 329
250static int mace_set_address(struct net_device *dev, void *addr) 330static void __mace_set_address(struct net_device *dev, void *addr)
251{ 331{
252 unsigned char *p = addr; 332 struct mace_data *mp = netdev_priv(dev);
253 struct mace_data *mp = (struct mace_data *) dev->priv;
254 volatile struct mace *mb = mp->mace; 333 volatile struct mace *mb = mp->mace;
334 unsigned char *p = addr;
255 int i; 335 int i;
336
337 /* load up the hardware address */
338 if (mp->chipid == BROKEN_ADDRCHG_REV)
339 mb->iac = PHYADDR;
340 else {
341 mb->iac = ADDRCHG | PHYADDR;
342 while ((mb->iac & ADDRCHG) != 0)
343 ;
344 }
345 for (i = 0; i < 6; ++i)
346 mb->padr = dev->dev_addr[i] = p[i];
347 if (mp->chipid != BROKEN_ADDRCHG_REV)
348 mb->iac = 0;
349}
350
351static int mace_set_address(struct net_device *dev, void *addr)
352{
353 struct mace_data *mp = netdev_priv(dev);
354 volatile struct mace *mb = mp->mace;
256 unsigned long flags; 355 unsigned long flags;
257 u8 maccc; 356 u8 maccc;
258 357
@@ -260,15 +359,10 @@ static int mace_set_address(struct net_device *dev, void *addr)
260 359
261 maccc = mb->maccc; 360 maccc = mb->maccc;
262 361
263 /* load up the hardware address */ 362 __mace_set_address(dev, addr);
264 mb->iac = ADDRCHG | PHYADDR;
265 while ((mb->iac & ADDRCHG) != 0);
266
267 for (i = 0; i < 6; ++i) {
268 mb->padr = dev->dev_addr[i] = p[i];
269 }
270 363
271 mb->maccc = maccc; 364 mb->maccc = maccc;
365
272 local_irq_restore(flags); 366 local_irq_restore(flags);
273 367
274 return 0; 368 return 0;
@@ -281,31 +375,11 @@ static int mace_set_address(struct net_device *dev, void *addr)
281 375
282static int mace_open(struct net_device *dev) 376static int mace_open(struct net_device *dev)
283{ 377{
284 struct mace_data *mp = (struct mace_data *) dev->priv; 378 struct mace_data *mp = netdev_priv(dev);
285 volatile struct mace *mb = mp->mace; 379 volatile struct mace *mb = mp->mace;
286#if 0
287 int i;
288 380
289 i = 200; 381 /* reset the chip */
290 while (--i) { 382 mace_reset(dev);
291 mb->biucc = SWRST;
292 if (mb->biucc & SWRST) {
293 udelay(10);
294 continue;
295 }
296 break;
297 }
298 if (!i) {
299 printk(KERN_ERR "%s: software reset failed!!\n", dev->name);
300 return -EAGAIN;
301 }
302#endif
303
304 mb->biucc = XMTSP_64;
305 mb->fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU | XMTBRST | RCVBRST;
306 mb->xmtfc = AUTO_PAD_XMIT;
307 mb->plscc = PORTSEL_AUI;
308 /* mb->utr = RTRD; */
309 383
310 if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) { 384 if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
311 printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq); 385 printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
@@ -319,25 +393,21 @@ static int mace_open(struct net_device *dev)
319 393
320 /* Allocate the DMA ring buffers */ 394 /* Allocate the DMA ring buffers */
321 395
322 mp->rx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, N_RX_PAGES); 396 mp->tx_ring = dma_alloc_coherent(mp->device,
323 mp->tx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, 0); 397 N_TX_RING * MACE_BUFF_SIZE,
324 398 &mp->tx_ring_phys, GFP_KERNEL);
325 if (mp->tx_ring==NULL || mp->rx_ring==NULL) { 399 if (mp->tx_ring == NULL) {
326 if (mp->rx_ring) free_pages((u32) mp->rx_ring, N_RX_PAGES); 400 printk(KERN_ERR "%s: unable to allocate DMA tx buffers\n", dev->name);
327 if (mp->tx_ring) free_pages((u32) mp->tx_ring, 0); 401 goto out1;
328 free_irq(dev->irq, dev);
329 free_irq(mp->dma_intr, dev);
330 printk(KERN_ERR "%s: unable to allocate DMA buffers\n", dev->name);
331 return -ENOMEM;
332 } 402 }
333 403
334 mp->rx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->rx_ring); 404 mp->rx_ring = dma_alloc_coherent(mp->device,
335 mp->tx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->tx_ring); 405 N_RX_RING * MACE_BUFF_SIZE,
336 406 &mp->rx_ring_phys, GFP_KERNEL);
337 /* We want the Rx buffer to be uncached and the Tx buffer to be writethrough */ 407 if (mp->rx_ring == NULL) {
338 408 printk(KERN_ERR "%s: unable to allocate DMA rx buffers\n", dev->name);
339 kernel_set_cachemode((void *)mp->rx_ring, N_RX_PAGES * PAGE_SIZE, IOMAP_NOCACHE_NONSER); 409 goto out2;
340 kernel_set_cachemode((void *)mp->tx_ring, PAGE_SIZE, IOMAP_WRITETHROUGH); 410 }
341 411
342 mace_dma_off(dev); 412 mace_dma_off(dev);
343 413
@@ -348,34 +418,22 @@ static int mace_open(struct net_device *dev)
348 psc_write_word(PSC_ENETWR_CTL, 0x0400); 418 psc_write_word(PSC_ENETWR_CTL, 0x0400);
349 psc_write_word(PSC_ENETRD_CTL, 0x0400); 419 psc_write_word(PSC_ENETRD_CTL, 0x0400);
350 420
351#if 0
352 /* load up the hardware address */
353
354 mb->iac = ADDRCHG | PHYADDR;
355
356 while ((mb->iac & ADDRCHG) != 0);
357
358 for (i = 0; i < 6; ++i)
359 mb->padr = dev->dev_addr[i];
360
361 /* clear the multicast filter */
362 mb->iac = ADDRCHG | LOGADDR;
363
364 while ((mb->iac & ADDRCHG) != 0);
365
366 for (i = 0; i < 8; ++i)
367 mb->ladrf = 0;
368
369 mb->plscc = PORTSEL_GPSI + ENPLSIO;
370
371 mb->maccc = ENXMT | ENRCV;
372 mb->imr = RCVINT;
373#endif
374
375 mace_rxdma_reset(dev); 421 mace_rxdma_reset(dev);
376 mace_txdma_reset(dev); 422 mace_txdma_reset(dev);
377 423
424 /* turn it on! */
425 mb->maccc = ENXMT | ENRCV;
426 /* enable all interrupts except receive interrupts */
427 mb->imr = RCVINT;
378 return 0; 428 return 0;
429
430out2:
431 dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
432 mp->tx_ring, mp->tx_ring_phys);
433out1:
434 free_irq(dev->irq, dev);
435 free_irq(mp->dma_intr, dev);
436 return -ENOMEM;
379} 437}
380 438
381/* 439/*
@@ -384,19 +442,13 @@ static int mace_open(struct net_device *dev)
384 442
385static int mace_close(struct net_device *dev) 443static int mace_close(struct net_device *dev)
386{ 444{
387 struct mace_data *mp = (struct mace_data *) dev->priv; 445 struct mace_data *mp = netdev_priv(dev);
388 volatile struct mace *mb = mp->mace; 446 volatile struct mace *mb = mp->mace;
389 447
390 mb->maccc = 0; /* disable rx and tx */ 448 mb->maccc = 0; /* disable rx and tx */
391 mb->imr = 0xFF; /* disable all irqs */ 449 mb->imr = 0xFF; /* disable all irqs */
392 mace_dma_off(dev); /* disable rx and tx dma */ 450 mace_dma_off(dev); /* disable rx and tx dma */
393 451
394 free_irq(dev->irq, dev);
395 free_irq(IRQ_MAC_MACE_DMA, dev);
396
397 free_pages((u32) mp->rx_ring, N_RX_PAGES);
398 free_pages((u32) mp->tx_ring, 0);
399
400 return 0; 452 return 0;
401} 453}
402 454
@@ -406,15 +458,20 @@ static int mace_close(struct net_device *dev)
406 458
407static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev) 459static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
408{ 460{
409 struct mace_data *mp = (struct mace_data *) dev->priv; 461 struct mace_data *mp = netdev_priv(dev);
462 unsigned long flags;
410 463
411 /* Stop the queue if the buffer is full */ 464 /* Stop the queue since there's only the one buffer */
412 465
466 local_irq_save(flags);
467 netif_stop_queue(dev);
413 if (!mp->tx_count) { 468 if (!mp->tx_count) {
414 netif_stop_queue(dev); 469 printk(KERN_ERR "macmace: tx queue running but no free buffers.\n");
415 return 1; 470 local_irq_restore(flags);
471 return NETDEV_TX_BUSY;
416 } 472 }
417 mp->tx_count--; 473 mp->tx_count--;
474 local_irq_restore(flags);
418 475
419 mp->stats.tx_packets++; 476 mp->stats.tx_packets++;
420 mp->stats.tx_bytes += skb->len; 477 mp->stats.tx_bytes += skb->len;
@@ -432,23 +489,26 @@ static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
432 489
433 dev_kfree_skb(skb); 490 dev_kfree_skb(skb);
434 491
435 return 0; 492 dev->trans_start = jiffies;
493 return NETDEV_TX_OK;
436} 494}
437 495
438static struct net_device_stats *mace_stats(struct net_device *dev) 496static struct net_device_stats *mace_stats(struct net_device *dev)
439{ 497{
440 struct mace_data *p = (struct mace_data *) dev->priv; 498 struct mace_data *mp = netdev_priv(dev);
441 return &p->stats; 499 return &mp->stats;
442} 500}
443 501
444static void mace_set_multicast(struct net_device *dev) 502static void mace_set_multicast(struct net_device *dev)
445{ 503{
446 struct mace_data *mp = (struct mace_data *) dev->priv; 504 struct mace_data *mp = netdev_priv(dev);
447 volatile struct mace *mb = mp->mace; 505 volatile struct mace *mb = mp->mace;
448 int i, j; 506 int i, j;
449 u32 crc; 507 u32 crc;
450 u8 maccc; 508 u8 maccc;
509 unsigned long flags;
451 510
511 local_irq_save(flags);
452 maccc = mb->maccc; 512 maccc = mb->maccc;
453 mb->maccc &= ~PROM; 513 mb->maccc &= ~PROM;
454 514
@@ -473,116 +533,122 @@ static void mace_set_multicast(struct net_device *dev)
473 } 533 }
474 } 534 }
475 535
476 mb->iac = ADDRCHG | LOGADDR; 536 if (mp->chipid == BROKEN_ADDRCHG_REV)
477 while (mb->iac & ADDRCHG); 537 mb->iac = LOGADDR;
478 538 else {
479 for (i = 0; i < 8; ++i) { 539 mb->iac = ADDRCHG | LOGADDR;
480 mb->ladrf = multicast_filter[i]; 540 while ((mb->iac & ADDRCHG) != 0)
541 ;
481 } 542 }
543 for (i = 0; i < 8; ++i)
544 mb->ladrf = multicast_filter[i];
545 if (mp->chipid != BROKEN_ADDRCHG_REV)
546 mb->iac = 0;
482 } 547 }
483 548
484 mb->maccc = maccc; 549 mb->maccc = maccc;
550 local_irq_restore(flags);
485} 551}
486 552
487/*
488 * Miscellaneous interrupts are handled here. We may end up
489 * having to bash the chip on the head for bad errors
490 */
491
492static void mace_handle_misc_intrs(struct mace_data *mp, int intr) 553static void mace_handle_misc_intrs(struct mace_data *mp, int intr)
493{ 554{
494 volatile struct mace *mb = mp->mace; 555 volatile struct mace *mb = mp->mace;
495 static int mace_babbles, mace_jabbers; 556 static int mace_babbles, mace_jabbers;
496 557
497 if (intr & MPCO) { 558 if (intr & MPCO)
498 mp->stats.rx_missed_errors += 256; 559 mp->stats.rx_missed_errors += 256;
499 } 560 mp->stats.rx_missed_errors += mb->mpc; /* reading clears it */
500 mp->stats.rx_missed_errors += mb->mpc; /* reading clears it */ 561 if (intr & RNTPCO)
501
502 if (intr & RNTPCO) {
503 mp->stats.rx_length_errors += 256; 562 mp->stats.rx_length_errors += 256;
504 } 563 mp->stats.rx_length_errors += mb->rntpc; /* reading clears it */
505 mp->stats.rx_length_errors += mb->rntpc; /* reading clears it */ 564 if (intr & CERR)
506
507 if (intr & CERR) {
508 ++mp->stats.tx_heartbeat_errors; 565 ++mp->stats.tx_heartbeat_errors;
509 } 566 if (intr & BABBLE)
510 if (intr & BABBLE) { 567 if (mace_babbles++ < 4)
511 if (mace_babbles++ < 4) { 568 printk(KERN_DEBUG "macmace: babbling transmitter\n");
512 printk(KERN_DEBUG "mace: babbling transmitter\n"); 569 if (intr & JABBER)
513 } 570 if (mace_jabbers++ < 4)
514 } 571 printk(KERN_DEBUG "macmace: jabbering transceiver\n");
515 if (intr & JABBER) {
516 if (mace_jabbers++ < 4) {
517 printk(KERN_DEBUG "mace: jabbering transceiver\n");
518 }
519 }
520} 572}
521 573
522/* 574static irqreturn_t mace_interrupt(int irq, void *dev_id)
523 * A transmit error has occurred. (We kick the transmit side from
524 * the DMA completion)
525 */
526
527static void mace_xmit_error(struct net_device *dev)
528{ 575{
529 struct mace_data *mp = (struct mace_data *) dev->priv; 576 struct net_device *dev = (struct net_device *) dev_id;
577 struct mace_data *mp = netdev_priv(dev);
530 volatile struct mace *mb = mp->mace; 578 volatile struct mace *mb = mp->mace;
531 u8 xmtfs, xmtrc; 579 int intr, fs;
580 unsigned int flags;
532 581
533 xmtfs = mb->xmtfs; 582 /* don't want the dma interrupt handler to fire */
534 xmtrc = mb->xmtrc; 583 local_irq_save(flags);
535 584
536 if (xmtfs & XMTSV) { 585 intr = mb->ir; /* read interrupt register */
537 if (xmtfs & UFLO) { 586 mace_handle_misc_intrs(mp, intr);
538 printk("%s: DMA underrun.\n", dev->name); 587
539 mp->stats.tx_errors++; 588 if (intr & XMTINT) {
540 mp->stats.tx_fifo_errors++; 589 fs = mb->xmtfs;
541 mace_txdma_reset(dev); 590 if ((fs & XMTSV) == 0) {
591 printk(KERN_ERR "macmace: xmtfs not valid! (fs=%x)\n", fs);
592 mace_reset(dev);
593 /*
594 * XXX mace likes to hang the machine after a xmtfs error.
595 * This is hard to reproduce, reseting *may* help
596 */
542 } 597 }
543 if (xmtfs & RTRY) { 598 /* dma should have finished */
544 mp->stats.collisions++; 599 if (!mp->tx_count) {
600 printk(KERN_DEBUG "macmace: tx ring ran out? (fs=%x)\n", fs);
601 }
602 /* Update stats */
603 if (fs & (UFLO|LCOL|LCAR|RTRY)) {
604 ++mp->stats.tx_errors;
605 if (fs & LCAR)
606 ++mp->stats.tx_carrier_errors;
607 else if (fs & (UFLO|LCOL|RTRY)) {
608 ++mp->stats.tx_aborted_errors;
609 if (mb->xmtfs & UFLO) {
610 printk(KERN_ERR "%s: DMA underrun.\n", dev->name);
611 mp->stats.tx_fifo_errors++;
612 mace_txdma_reset(dev);
613 }
614 }
545 } 615 }
546 } 616 }
547}
548 617
549/* 618 if (mp->tx_count)
550 * A receive interrupt occurred. 619 netif_wake_queue(dev);
551 */
552 620
553static void mace_recv_interrupt(struct net_device *dev) 621 local_irq_restore(flags);
554{
555/* struct mace_data *mp = (struct mace_data *) dev->priv; */
556// volatile struct mace *mb = mp->mace;
557}
558 622
559/* 623 return IRQ_HANDLED;
560 * Process the chip interrupt 624}
561 */
562 625
563static irqreturn_t mace_interrupt(int irq, void *dev_id) 626static void mace_tx_timeout(struct net_device *dev)
564{ 627{
565 struct net_device *dev = (struct net_device *) dev_id; 628 struct mace_data *mp = netdev_priv(dev);
566 struct mace_data *mp = (struct mace_data *) dev->priv;
567 volatile struct mace *mb = mp->mace; 629 volatile struct mace *mb = mp->mace;
568 u8 ir; 630 unsigned long flags;
569 631
570 ir = mb->ir; 632 local_irq_save(flags);
571 mace_handle_misc_intrs(mp, ir);
572 633
573 if (ir & XMTINT) { 634 /* turn off both tx and rx and reset the chip */
574 mace_xmit_error(dev); 635 mb->maccc = 0;
575 } 636 printk(KERN_ERR "macmace: transmit timeout - resetting\n");
576 if (ir & RCVINT) { 637 mace_txdma_reset(dev);
577 mace_recv_interrupt(dev); 638 mace_reset(dev);
578 }
579 return IRQ_HANDLED;
580}
581 639
582static void mace_tx_timeout(struct net_device *dev) 640 /* restart rx dma */
583{ 641 mace_rxdma_reset(dev);
584/* struct mace_data *mp = (struct mace_data *) dev->priv; */ 642
585// volatile struct mace *mb = mp->mace; 643 mp->tx_count = N_TX_RING;
644 netif_wake_queue(dev);
645
646 /* turn it on! */
647 mb->maccc = ENXMT | ENRCV;
648 /* enable all interrupts except receive interrupts */
649 mb->imr = RCVINT;
650
651 local_irq_restore(flags);
586} 652}
587 653
588/* 654/*
@@ -591,40 +657,39 @@ static void mace_tx_timeout(struct net_device *dev)
591 657
592static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf) 658static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
593{ 659{
594 struct mace_data *mp = (struct mace_data *) dev->priv; 660 struct mace_data *mp = netdev_priv(dev);
595 struct sk_buff *skb; 661 struct sk_buff *skb;
662 unsigned int frame_status = mf->rcvsts;
596 663
597 if (mf->status & RS_OFLO) { 664 if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
598 printk("%s: fifo overflow.\n", dev->name);
599 mp->stats.rx_errors++;
600 mp->stats.rx_fifo_errors++;
601 }
602 if (mf->status&(RS_CLSN|RS_FRAMERR|RS_FCSERR))
603 mp->stats.rx_errors++; 665 mp->stats.rx_errors++;
666 if (frame_status & RS_OFLO) {
667 printk(KERN_DEBUG "%s: fifo overflow.\n", dev->name);
668 mp->stats.rx_fifo_errors++;
669 }
670 if (frame_status & RS_CLSN)
671 mp->stats.collisions++;
672 if (frame_status & RS_FRAMERR)
673 mp->stats.rx_frame_errors++;
674 if (frame_status & RS_FCSERR)
675 mp->stats.rx_crc_errors++;
676 } else {
677 unsigned int frame_length = mf->rcvcnt + ((frame_status & 0x0F) << 8 );
604 678
605 if (mf->status&RS_CLSN) { 679 skb = dev_alloc_skb(frame_length + 2);
606 mp->stats.collisions++; 680 if (!skb) {
607 } 681 mp->stats.rx_dropped++;
608 if (mf->status&RS_FRAMERR) { 682 return;
609 mp->stats.rx_frame_errors++; 683 }
610 } 684 skb_reserve(skb, 2);
611 if (mf->status&RS_FCSERR) { 685 memcpy(skb_put(skb, frame_length), mf->data, frame_length);
612 mp->stats.rx_crc_errors++; 686
613 } 687 skb->protocol = eth_type_trans(skb, dev);
614 688 netif_rx(skb);
615 skb = dev_alloc_skb(mf->len+2); 689 dev->last_rx = jiffies;
616 if (!skb) { 690 mp->stats.rx_packets++;
617 mp->stats.rx_dropped++; 691 mp->stats.rx_bytes += frame_length;
618 return;
619 } 692 }
620 skb_reserve(skb,2);
621 memcpy(skb_put(skb, mf->len), mf->data, mf->len);
622
623 skb->protocol = eth_type_trans(skb, dev);
624 netif_rx(skb);
625 dev->last_rx = jiffies;
626 mp->stats.rx_packets++;
627 mp->stats.rx_bytes += mf->len;
628} 693}
629 694
630/* 695/*
@@ -634,7 +699,7 @@ static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
634static irqreturn_t mace_dma_intr(int irq, void *dev_id) 699static irqreturn_t mace_dma_intr(int irq, void *dev_id)
635{ 700{
636 struct net_device *dev = (struct net_device *) dev_id; 701 struct net_device *dev = (struct net_device *) dev_id;
637 struct mace_data *mp = (struct mace_data *) dev->priv; 702 struct mace_data *mp = netdev_priv(dev);
638 int left, head; 703 int left, head;
639 u16 status; 704 u16 status;
640 u32 baka; 705 u32 baka;
@@ -661,7 +726,8 @@ static irqreturn_t mace_dma_intr(int irq, void *dev_id)
661 /* Loop through the ring buffer and process new packages */ 726 /* Loop through the ring buffer and process new packages */
662 727
663 while (mp->rx_tail < head) { 728 while (mp->rx_tail < head) {
664 mace_dma_rx_frame(dev, (struct mace_frame *) (mp->rx_ring + (mp->rx_tail * 0x0800))); 729 mace_dma_rx_frame(dev, (struct mace_frame*) (mp->rx_ring
730 + (mp->rx_tail * MACE_BUFF_SIZE)));
665 mp->rx_tail++; 731 mp->rx_tail++;
666 } 732 }
667 733
@@ -688,9 +754,76 @@ static irqreturn_t mace_dma_intr(int irq, void *dev_id)
688 psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100); 754 psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
689 mp->tx_sloti ^= 0x10; 755 mp->tx_sloti ^= 0x10;
690 mp->tx_count++; 756 mp->tx_count++;
691 netif_wake_queue(dev);
692 } 757 }
693 return IRQ_HANDLED; 758 return IRQ_HANDLED;
694} 759}
695 760
696MODULE_LICENSE("GPL"); 761MODULE_LICENSE("GPL");
762MODULE_DESCRIPTION("Macintosh MACE ethernet driver");
763
764static int __devexit mac_mace_device_remove (struct platform_device *pdev)
765{
766 struct net_device *dev = platform_get_drvdata(pdev);
767 struct mace_data *mp = netdev_priv(dev);
768
769 unregister_netdev(dev);
770
771 free_irq(dev->irq, dev);
772 free_irq(IRQ_MAC_MACE_DMA, dev);
773
774 dma_free_coherent(mp->device, N_RX_RING * MACE_BUFF_SIZE,
775 mp->rx_ring, mp->rx_ring_phys);
776 dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
777 mp->tx_ring, mp->tx_ring_phys);
778
779 free_netdev(dev);
780
781 return 0;
782}
783
784static struct platform_driver mac_mace_driver = {
785 .probe = mace_probe,
786 .remove = __devexit_p(mac_mace_device_remove),
787 .driver = {
788 .name = mac_mace_string,
789 },
790};
791
792static int __init mac_mace_init_module(void)
793{
794 int err;
795
796 if ((err = platform_driver_register(&mac_mace_driver))) {
797 printk(KERN_ERR "Driver registration failed\n");
798 return err;
799 }
800
801 mac_mace_device = platform_device_alloc(mac_mace_string, 0);
802 if (!mac_mace_device)
803 goto out_unregister;
804
805 if (platform_device_add(mac_mace_device)) {
806 platform_device_put(mac_mace_device);
807 mac_mace_device = NULL;
808 }
809
810 return 0;
811
812out_unregister:
813 platform_driver_unregister(&mac_mace_driver);
814
815 return -ENOMEM;
816}
817
818static void __exit mac_mace_cleanup_module(void)
819{
820 platform_driver_unregister(&mac_mace_driver);
821
822 if (mac_mace_device) {
823 platform_device_unregister(mac_mace_device);
824 mac_mace_device = NULL;
825 }
826}
827
828module_init(mac_mace_init_module);
829module_exit(mac_mace_cleanup_module);
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index 8ca57a0a4c11..e9ecdbf352ae 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -130,6 +130,46 @@ static inline void bit_reverse_addr(unsigned char addr[6])
130 addr[i] = bitrev8(addr[i]); 130 addr[i] = bitrev8(addr[i]);
131} 131}
132 132
133static irqreturn_t macsonic_interrupt(int irq, void *dev_id)
134{
135 irqreturn_t result;
136 unsigned long flags;
137
138 local_irq_save(flags);
139 result = sonic_interrupt(irq, dev_id);
140 local_irq_restore(flags);
141 return result;
142}
143
144static int macsonic_open(struct net_device* dev)
145{
146 if (request_irq(dev->irq, &sonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
147 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
148 return -EAGAIN;
149 }
150 /* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes
151 * in at priority level 3. However, we sometimes get the level 2 inter-
152 * rupt as well, which must prevent re-entrance of the sonic handler.
153 */
154 if (dev->irq == IRQ_AUTO_3)
155 if (request_irq(IRQ_NUBUS_9, &macsonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
156 printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, IRQ_NUBUS_9);
157 free_irq(dev->irq, dev);
158 return -EAGAIN;
159 }
160 return sonic_open(dev);
161}
162
163static int macsonic_close(struct net_device* dev)
164{
165 int err;
166 err = sonic_close(dev);
167 free_irq(dev->irq, dev);
168 if (dev->irq == IRQ_AUTO_3)
169 free_irq(IRQ_NUBUS_9, dev);
170 return err;
171}
172
133int __init macsonic_init(struct net_device* dev) 173int __init macsonic_init(struct net_device* dev)
134{ 174{
135 struct sonic_local* lp = netdev_priv(dev); 175 struct sonic_local* lp = netdev_priv(dev);
@@ -160,8 +200,8 @@ int __init macsonic_init(struct net_device* dev)
160 lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 200 lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
161 * SONIC_BUS_SCALE(lp->dma_bitmode)); 201 * SONIC_BUS_SCALE(lp->dma_bitmode));
162 202
163 dev->open = sonic_open; 203 dev->open = macsonic_open;
164 dev->stop = sonic_close; 204 dev->stop = macsonic_close;
165 dev->hard_start_xmit = sonic_send_packet; 205 dev->hard_start_xmit = sonic_send_packet;
166 dev->get_stats = sonic_get_stats; 206 dev->get_stats = sonic_get_stats;
167 dev->set_multicast_list = &sonic_multicast_list; 207 dev->set_multicast_list = &sonic_multicast_list;
@@ -402,7 +442,7 @@ int __init macsonic_ident(struct nubus_dev* ndev)
402 ndev->dr_sw == NUBUS_DRSW_DAYNA) 442 ndev->dr_sw == NUBUS_DRSW_DAYNA)
403 return MACSONIC_DAYNA; 443 return MACSONIC_DAYNA;
404 444
405 if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC && 445 if (ndev->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
406 ndev->dr_sw == 0) { /* huh? */ 446 ndev->dr_sw == 0) { /* huh? */
407 return MACSONIC_APPLE16; 447 return MACSONIC_APPLE16;
408 } 448 }
@@ -522,7 +562,7 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
522 return macsonic_init(dev); 562 return macsonic_init(dev);
523} 563}
524 564
525static int __init mac_sonic_probe(struct platform_device *device) 565static int __init mac_sonic_probe(struct platform_device *pdev)
526{ 566{
527 struct net_device *dev; 567 struct net_device *dev;
528 struct sonic_local *lp; 568 struct sonic_local *lp;
@@ -534,8 +574,8 @@ static int __init mac_sonic_probe(struct platform_device *device)
534 return -ENOMEM; 574 return -ENOMEM;
535 575
536 lp = netdev_priv(dev); 576 lp = netdev_priv(dev);
537 lp->device = &device->dev; 577 lp->device = &pdev->dev;
538 SET_NETDEV_DEV(dev, &device->dev); 578 SET_NETDEV_DEV(dev, &pdev->dev);
539 SET_MODULE_OWNER(dev); 579 SET_MODULE_OWNER(dev);
540 580
541 /* This will catch fatal stuff like -ENOMEM as well as success */ 581 /* This will catch fatal stuff like -ENOMEM as well as success */
@@ -572,19 +612,17 @@ MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
572module_param(sonic_debug, int, 0); 612module_param(sonic_debug, int, 0);
573MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)"); 613MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
574 614
575#define SONIC_IRQ_FLAG IRQ_FLG_FAST
576
577#include "sonic.c" 615#include "sonic.c"
578 616
579static int __devexit mac_sonic_device_remove (struct platform_device *device) 617static int __devexit mac_sonic_device_remove (struct platform_device *pdev)
580{ 618{
581 struct net_device *dev = platform_get_drvdata(device); 619 struct net_device *dev = platform_get_drvdata(pdev);
582 struct sonic_local* lp = netdev_priv(dev); 620 struct sonic_local* lp = netdev_priv(dev);
583 621
584 unregister_netdev (dev); 622 unregister_netdev(dev);
585 dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 623 dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
586 lp->descriptors, lp->descriptors_laddr); 624 lp->descriptors, lp->descriptors_laddr);
587 free_netdev (dev); 625 free_netdev(dev);
588 626
589 return 0; 627 return 0;
590} 628}
@@ -607,9 +645,8 @@ static int __init mac_sonic_init_module(void)
607 } 645 }
608 646
609 mac_sonic_device = platform_device_alloc(mac_sonic_string, 0); 647 mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
610 if (!mac_sonic_device) { 648 if (!mac_sonic_device)
611 goto out_unregister; 649 goto out_unregister;
612 }
613 650
614 if (platform_device_add(mac_sonic_device)) { 651 if (platform_device_add(mac_sonic_device)) {
615 platform_device_put(mac_sonic_device); 652 platform_device_put(mac_sonic_device);
diff --git a/drivers/net/sonic.c b/drivers/net/sonic.c
index c6320c719931..8069f3e32d83 100644
--- a/drivers/net/sonic.c
+++ b/drivers/net/sonic.c
@@ -50,29 +50,6 @@ static int sonic_open(struct net_device *dev)
50 if (sonic_debug > 2) 50 if (sonic_debug > 2)
51 printk("sonic_open: initializing sonic driver.\n"); 51 printk("sonic_open: initializing sonic driver.\n");
52 52
53 /*
54 * We don't need to deal with auto-irq stuff since we
55 * hardwire the sonic interrupt.
56 */
57/*
58 * XXX Horrible work around: We install sonic_interrupt as fast interrupt.
59 * This means that during execution of the handler interrupt are disabled
60 * covering another bug otherwise corrupting data. This doesn't mean
61 * this glue works ok under all situations.
62 *
63 * Note (dhd): this also appears to prevent lockups on the Macintrash
64 * when more than one Ethernet card is installed (knock on wood)
65 *
66 * Note (fthain): whether the above is still true is anyones guess. Certainly
67 * the buffer handling algorithms will not tolerate re-entrance without some
68 * mutual exclusion added. Anyway, the memcpy has now been eliminated from the
69 * rx code to make this a faster "fast interrupt".
70 */
71 if (request_irq(dev->irq, &sonic_interrupt, SONIC_IRQ_FLAG, "sonic", dev)) {
72 printk(KERN_ERR "\n%s: unable to get IRQ %d .\n", dev->name, dev->irq);
73 return -EAGAIN;
74 }
75
76 for (i = 0; i < SONIC_NUM_RRS; i++) { 53 for (i = 0; i < SONIC_NUM_RRS; i++) {
77 struct sk_buff *skb = dev_alloc_skb(SONIC_RBSIZE + 2); 54 struct sk_buff *skb = dev_alloc_skb(SONIC_RBSIZE + 2);
78 if (skb == NULL) { 55 if (skb == NULL) {
@@ -169,8 +146,6 @@ static int sonic_close(struct net_device *dev)
169 } 146 }
170 } 147 }
171 148
172 free_irq(dev->irq, dev); /* release the IRQ */
173
174 return 0; 149 return 0;
175} 150}
176 151
@@ -178,8 +153,13 @@ static void sonic_tx_timeout(struct net_device *dev)
178{ 153{
179 struct sonic_local *lp = netdev_priv(dev); 154 struct sonic_local *lp = netdev_priv(dev);
180 int i; 155 int i;
181 /* Stop the interrupts for this */ 156 /*
157 * put the Sonic into software-reset mode and
158 * disable all interrupts before releasing DMA buffers
159 */
182 SONIC_WRITE(SONIC_IMR, 0); 160 SONIC_WRITE(SONIC_IMR, 0);
161 SONIC_WRITE(SONIC_ISR, 0x7fff);
162 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
183 /* We could resend the original skbs. Easier to re-initialise. */ 163 /* We could resend the original skbs. Easier to re-initialise. */
184 for (i = 0; i < SONIC_NUM_TDS; i++) { 164 for (i = 0; i < SONIC_NUM_TDS; i++) {
185 if(lp->tx_laddr[i]) { 165 if(lp->tx_laddr[i]) {
diff --git a/drivers/net/sun3_82586.c b/drivers/net/sun3_82586.c
index 396c3d961f88..a123ea87893b 100644
--- a/drivers/net/sun3_82586.c
+++ b/drivers/net/sun3_82586.c
@@ -1023,10 +1023,11 @@ static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
1023 { 1023 {
1024 len = skb->len; 1024 len = skb->len;
1025 if (len < ETH_ZLEN) { 1025 if (len < ETH_ZLEN) {
1026 memset((char *)p->xmit_cbuffs[p->xmit_count], 0, ETH_ZLEN); 1026 memset((void *)p->xmit_cbuffs[p->xmit_count], 0,
1027 ETH_ZLEN);
1027 len = ETH_ZLEN; 1028 len = ETH_ZLEN;
1028 } 1029 }
1029 skb_copy_from_linear_data(skb, p->xmit_cbuffs[p->xmit_count], skb->len); 1030 skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len);
1030 1031
1031#if (NUM_XMIT_BUFFS == 1) 1032#if (NUM_XMIT_BUFFS == 1)
1032# ifdef NO_NOPCOMMANDS 1033# ifdef NO_NOPCOMMANDS
diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c
index d21e04ccb021..1393e64335f9 100644
--- a/drivers/ps3/ps3av.c
+++ b/drivers/ps3/ps3av.c
@@ -38,7 +38,24 @@
38static int timeout = 5000; /* in msec ( 5 sec ) */ 38static int timeout = 5000; /* in msec ( 5 sec ) */
39module_param(timeout, int, 0644); 39module_param(timeout, int, 0644);
40 40
41static struct ps3av ps3av; 41static struct ps3av {
42 int available;
43 struct mutex mutex;
44 struct work_struct work;
45 struct completion done;
46 struct workqueue_struct *wq;
47 int open_count;
48 struct ps3_vuart_port_device *dev;
49
50 int region;
51 struct ps3av_pkt_av_get_hw_conf av_hw_conf;
52 u32 av_port[PS3AV_AV_PORT_MAX + PS3AV_OPT_PORT_MAX];
53 u32 opt_port[PS3AV_OPT_PORT_MAX];
54 u32 head[PS3AV_HEAD_MAX];
55 u32 audio_port;
56 int ps3av_mode;
57 int ps3av_mode_old;
58} ps3av;
42 59
43static struct ps3_vuart_port_device ps3av_dev = { 60static struct ps3_vuart_port_device ps3av_dev = {
44 .match_id = PS3_MATCH_ID_AV_SETTINGS 61 .match_id = PS3_MATCH_ID_AV_SETTINGS
@@ -159,7 +176,7 @@ static int ps3av_parse_event_packet(const struct ps3av_reply_hdr *hdr)
159 else 176 else
160 printk(KERN_ERR 177 printk(KERN_ERR
161 "%s: failed event packet, cid:%08x size:%d\n", 178 "%s: failed event packet, cid:%08x size:%d\n",
162 __FUNCTION__, hdr->cid, hdr->size); 179 __func__, hdr->cid, hdr->size);
163 return 1; /* receive event packet */ 180 return 1; /* receive event packet */
164 } 181 }
165 return 0; 182 return 0;
@@ -181,7 +198,7 @@ static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
181 if (res < 0) { 198 if (res < 0) {
182 dev_dbg(&ps3av_dev.core, 199 dev_dbg(&ps3av_dev.core,
183 "%s: ps3av_vuart_write() failed (result=%d)\n", 200 "%s: ps3av_vuart_write() failed (result=%d)\n",
184 __FUNCTION__, res); 201 __func__, res);
185 return res; 202 return res;
186 } 203 }
187 204
@@ -194,7 +211,7 @@ static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
194 if (res != PS3AV_HDR_SIZE) { 211 if (res != PS3AV_HDR_SIZE) {
195 dev_dbg(&ps3av_dev.core, 212 dev_dbg(&ps3av_dev.core,
196 "%s: ps3av_vuart_read() failed (result=%d)\n", 213 "%s: ps3av_vuart_read() failed (result=%d)\n",
197 __FUNCTION__, res); 214 __func__, res);
198 return res; 215 return res;
199 } 216 }
200 217
@@ -204,7 +221,7 @@ static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
204 if (res < 0) { 221 if (res < 0) {
205 dev_dbg(&ps3av_dev.core, 222 dev_dbg(&ps3av_dev.core,
206 "%s: ps3av_vuart_read() failed (result=%d)\n", 223 "%s: ps3av_vuart_read() failed (result=%d)\n",
207 __FUNCTION__, res); 224 __func__, res);
208 return res; 225 return res;
209 } 226 }
210 res += PS3AV_HDR_SIZE; /* total len */ 227 res += PS3AV_HDR_SIZE; /* total len */
@@ -214,7 +231,7 @@ static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
214 231
215 if ((cmd | PS3AV_REPLY_BIT) != recv_buf->cid) { 232 if ((cmd | PS3AV_REPLY_BIT) != recv_buf->cid) {
216 dev_dbg(&ps3av_dev.core, "%s: reply err (result=%x)\n", 233 dev_dbg(&ps3av_dev.core, "%s: reply err (result=%x)\n",
217 __FUNCTION__, recv_buf->cid); 234 __func__, recv_buf->cid);
218 return -EINVAL; 235 return -EINVAL;
219 } 236 }
220 237
@@ -250,7 +267,7 @@ int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
250 struct ps3av_send_hdr *buf) 267 struct ps3av_send_hdr *buf)
251{ 268{
252 int res = 0; 269 int res = 0;
253 union { 270 static union {
254 struct ps3av_reply_hdr reply_hdr; 271 struct ps3av_reply_hdr reply_hdr;
255 u8 raw[PS3AV_BUF_SIZE]; 272 u8 raw[PS3AV_BUF_SIZE];
256 } recv_buf; 273 } recv_buf;
@@ -259,8 +276,7 @@ int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
259 276
260 BUG_ON(!ps3av.available); 277 BUG_ON(!ps3av.available);
261 278
262 if (down_interruptible(&ps3av.sem)) 279 mutex_lock(&ps3av.mutex);
263 return -ERESTARTSYS;
264 280
265 table = ps3av_search_cmd_table(cid, PS3AV_CID_MASK); 281 table = ps3av_search_cmd_table(cid, PS3AV_CID_MASK);
266 BUG_ON(!table); 282 BUG_ON(!table);
@@ -277,7 +293,7 @@ int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
277 if (res < 0) { 293 if (res < 0) {
278 printk(KERN_ERR 294 printk(KERN_ERR
279 "%s: ps3av_send_cmd_pkt() failed (result=%d)\n", 295 "%s: ps3av_send_cmd_pkt() failed (result=%d)\n",
280 __FUNCTION__, res); 296 __func__, res);
281 goto err; 297 goto err;
282 } 298 }
283 299
@@ -286,16 +302,16 @@ int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
286 usr_buf_size); 302 usr_buf_size);
287 if (res < 0) { 303 if (res < 0) {
288 printk(KERN_ERR "%s: put_return_status() failed (result=%d)\n", 304 printk(KERN_ERR "%s: put_return_status() failed (result=%d)\n",
289 __FUNCTION__, res); 305 __func__, res);
290 goto err; 306 goto err;
291 } 307 }
292 308
293 up(&ps3av.sem); 309 mutex_unlock(&ps3av.mutex);
294 return 0; 310 return 0;
295 311
296 err: 312 err:
297 up(&ps3av.sem); 313 mutex_unlock(&ps3av.mutex);
298 printk(KERN_ERR "%s: failed cid:%x res:%d\n", __FUNCTION__, cid, res); 314 printk(KERN_ERR "%s: failed cid:%x res:%d\n", __func__, cid, res);
299 return res; 315 return res;
300} 316}
301 317
@@ -440,7 +456,7 @@ static int ps3av_set_videomode(void)
440 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_ON); 456 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_ON);
441 457
442 /* wake up ps3avd to do the actual video mode setting */ 458 /* wake up ps3avd to do the actual video mode setting */
443 up(&ps3av.ping); 459 queue_work(ps3av.wq, &ps3av.work);
444 460
445 return 0; 461 return 0;
446} 462}
@@ -506,7 +522,7 @@ static void ps3av_set_videomode_cont(u32 id, u32 old_id)
506 if (res == PS3AV_STATUS_NO_SYNC_HEAD) 522 if (res == PS3AV_STATUS_NO_SYNC_HEAD)
507 printk(KERN_WARNING 523 printk(KERN_WARNING
508 "%s: Command failed. Please try your request again. \n", 524 "%s: Command failed. Please try your request again. \n",
509 __FUNCTION__); 525 __func__);
510 else if (res) 526 else if (res)
511 dev_dbg(&ps3av_dev.core, "ps3av_cmd_avb_param failed\n"); 527 dev_dbg(&ps3av_dev.core, "ps3av_cmd_avb_param failed\n");
512 528
@@ -515,18 +531,10 @@ static void ps3av_set_videomode_cont(u32 id, u32 old_id)
515 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_OFF); 531 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_OFF);
516} 532}
517 533
518static int ps3avd(void *p) 534static void ps3avd(struct work_struct *work)
519{ 535{
520 struct ps3av *info = p; 536 ps3av_set_videomode_cont(ps3av.ps3av_mode, ps3av.ps3av_mode_old);
521 537 complete(&ps3av.done);
522 daemonize("ps3avd");
523 while (1) {
524 down(&info->ping);
525 ps3av_set_videomode_cont(info->ps3av_mode,
526 info->ps3av_mode_old);
527 up(&info->pong);
528 }
529 return 0;
530} 538}
531 539
532static int ps3av_vid2table_id(int vid) 540static int ps3av_vid2table_id(int vid)
@@ -707,8 +715,7 @@ int ps3av_set_video_mode(u32 id, int boot)
707 715
708 size = ARRAY_SIZE(video_mode_table); 716 size = ARRAY_SIZE(video_mode_table);
709 if ((id & PS3AV_MODE_MASK) > size - 1 || id < 0) { 717 if ((id & PS3AV_MODE_MASK) > size - 1 || id < 0) {
710 dev_dbg(&ps3av_dev.core, "%s: error id :%d\n", __FUNCTION__, 718 dev_dbg(&ps3av_dev.core, "%s: error id :%d\n", __func__, id);
711 id);
712 return -EINVAL; 719 return -EINVAL;
713 } 720 }
714 721
@@ -717,15 +724,14 @@ int ps3av_set_video_mode(u32 id, int boot)
717 if ((id & PS3AV_MODE_MASK) == 0) { 724 if ((id & PS3AV_MODE_MASK) == 0) {
718 id = ps3av_auto_videomode(&ps3av.av_hw_conf, boot); 725 id = ps3av_auto_videomode(&ps3av.av_hw_conf, boot);
719 if (id < 1) { 726 if (id < 1) {
720 printk(KERN_ERR "%s: invalid id :%d\n", __FUNCTION__, 727 printk(KERN_ERR "%s: invalid id :%d\n", __func__, id);
721 id);
722 return -EINVAL; 728 return -EINVAL;
723 } 729 }
724 id |= option; 730 id |= option;
725 } 731 }
726 732
727 /* set videomode */ 733 /* set videomode */
728 down(&ps3av.pong); 734 wait_for_completion(&ps3av.done);
729 ps3av.ps3av_mode_old = ps3av.ps3av_mode; 735 ps3av.ps3av_mode_old = ps3av.ps3av_mode;
730 ps3av.ps3av_mode = id; 736 ps3av.ps3av_mode = id;
731 if (ps3av_set_videomode()) 737 if (ps3av_set_videomode())
@@ -736,6 +742,13 @@ int ps3av_set_video_mode(u32 id, int boot)
736 742
737EXPORT_SYMBOL_GPL(ps3av_set_video_mode); 743EXPORT_SYMBOL_GPL(ps3av_set_video_mode);
738 744
745int ps3av_get_auto_mode(int boot)
746{
747 return ps3av_auto_videomode(&ps3av.av_hw_conf, boot);
748}
749
750EXPORT_SYMBOL_GPL(ps3av_get_auto_mode);
751
739int ps3av_set_mode(u32 id, int boot) 752int ps3av_set_mode(u32 id, int boot)
740{ 753{
741 int res; 754 int res;
@@ -771,7 +784,7 @@ int ps3av_get_scanmode(int id)
771 id = id & PS3AV_MODE_MASK; 784 id = id & PS3AV_MODE_MASK;
772 size = ARRAY_SIZE(video_mode_table); 785 size = ARRAY_SIZE(video_mode_table);
773 if (id > size - 1 || id < 0) { 786 if (id > size - 1 || id < 0) {
774 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id); 787 printk(KERN_ERR "%s: invalid mode %d\n", __func__, id);
775 return -EINVAL; 788 return -EINVAL;
776 } 789 }
777 return video_mode_table[id].interlace; 790 return video_mode_table[id].interlace;
@@ -786,7 +799,7 @@ int ps3av_get_refresh_rate(int id)
786 id = id & PS3AV_MODE_MASK; 799 id = id & PS3AV_MODE_MASK;
787 size = ARRAY_SIZE(video_mode_table); 800 size = ARRAY_SIZE(video_mode_table);
788 if (id > size - 1 || id < 0) { 801 if (id > size - 1 || id < 0) {
789 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id); 802 printk(KERN_ERR "%s: invalid mode %d\n", __func__, id);
790 return -EINVAL; 803 return -EINVAL;
791 } 804 }
792 return video_mode_table[id].freq; 805 return video_mode_table[id].freq;
@@ -802,7 +815,7 @@ int ps3av_video_mode2res(u32 id, u32 *xres, u32 *yres)
802 id = id & PS3AV_MODE_MASK; 815 id = id & PS3AV_MODE_MASK;
803 size = ARRAY_SIZE(video_mode_table); 816 size = ARRAY_SIZE(video_mode_table);
804 if (id > size - 1 || id < 0) { 817 if (id > size - 1 || id < 0) {
805 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id); 818 printk(KERN_ERR "%s: invalid mode %d\n", __func__, id);
806 return -EINVAL; 819 return -EINVAL;
807 } 820 }
808 *xres = video_mode_table[id].x; 821 *xres = video_mode_table[id].x;
@@ -838,7 +851,7 @@ int ps3av_dev_open(void)
838 status = lv1_gpu_open(0); 851 status = lv1_gpu_open(0);
839 if (status) { 852 if (status) {
840 printk(KERN_ERR "%s: lv1_gpu_open failed %d\n", 853 printk(KERN_ERR "%s: lv1_gpu_open failed %d\n",
841 __FUNCTION__, status); 854 __func__, status);
842 ps3av.open_count--; 855 ps3av.open_count--;
843 } 856 }
844 } 857 }
@@ -855,13 +868,13 @@ int ps3av_dev_close(void)
855 868
856 mutex_lock(&ps3av.mutex); 869 mutex_lock(&ps3av.mutex);
857 if (ps3av.open_count <= 0) { 870 if (ps3av.open_count <= 0) {
858 printk(KERN_ERR "%s: GPU already closed\n", __FUNCTION__); 871 printk(KERN_ERR "%s: GPU already closed\n", __func__);
859 status = -1; 872 status = -1;
860 } else if (!--ps3av.open_count) { 873 } else if (!--ps3av.open_count) {
861 status = lv1_gpu_close(); 874 status = lv1_gpu_close();
862 if (status) 875 if (status)
863 printk(KERN_WARNING "%s: lv1_gpu_close failed %d\n", 876 printk(KERN_WARNING "%s: lv1_gpu_close failed %d\n",
864 __FUNCTION__, status); 877 __func__, status);
865 } 878 }
866 mutex_unlock(&ps3av.mutex); 879 mutex_unlock(&ps3av.mutex);
867 880
@@ -880,13 +893,16 @@ static int ps3av_probe(struct ps3_vuart_port_device *dev)
880 893
881 memset(&ps3av, 0, sizeof(ps3av)); 894 memset(&ps3av, 0, sizeof(ps3av));
882 895
883 init_MUTEX(&ps3av.sem);
884 init_MUTEX_LOCKED(&ps3av.ping);
885 init_MUTEX(&ps3av.pong);
886 mutex_init(&ps3av.mutex); 896 mutex_init(&ps3av.mutex);
887 ps3av.ps3av_mode = 0; 897 ps3av.ps3av_mode = 0;
888 ps3av.dev = dev; 898 ps3av.dev = dev;
889 kernel_thread(ps3avd, &ps3av, CLONE_KERNEL); 899
900 INIT_WORK(&ps3av.work, ps3avd);
901 init_completion(&ps3av.done);
902 complete(&ps3av.done);
903 ps3av.wq = create_singlethread_workqueue("ps3avd");
904 if (!ps3av.wq)
905 return -ENOMEM;
890 906
891 ps3av.available = 1; 907 ps3av.available = 1;
892 switch (ps3_os_area_get_av_multi_out()) { 908 switch (ps3_os_area_get_av_multi_out()) {
@@ -908,7 +924,7 @@ static int ps3av_probe(struct ps3_vuart_port_device *dev)
908 /* init avsetting modules */ 924 /* init avsetting modules */
909 res = ps3av_cmd_init(); 925 res = ps3av_cmd_init();
910 if (res < 0) 926 if (res < 0)
911 printk(KERN_ERR "%s: ps3av_cmd_init failed %d\n", __FUNCTION__, 927 printk(KERN_ERR "%s: ps3av_cmd_init failed %d\n", __func__,
912 res); 928 res);
913 929
914 ps3av_get_hw_conf(&ps3av); 930 ps3av_get_hw_conf(&ps3av);
@@ -926,6 +942,8 @@ static int ps3av_remove(struct ps3_vuart_port_device *dev)
926{ 942{
927 if (ps3av.available) { 943 if (ps3av.available) {
928 ps3av_cmd_fin(); 944 ps3av_cmd_fin();
945 if (ps3av.wq)
946 destroy_workqueue(ps3av.wq);
929 ps3av.available = 0; 947 ps3av.available = 0;
930 } 948 }
931 949
@@ -958,7 +976,7 @@ static int ps3av_module_init(void)
958 if (error) { 976 if (error) {
959 printk(KERN_ERR 977 printk(KERN_ERR
960 "%s: ps3_vuart_port_driver_register failed %d\n", 978 "%s: ps3_vuart_port_driver_register failed %d\n",
961 __FUNCTION__, error); 979 __func__, error);
962 return error; 980 return error;
963 } 981 }
964 982
@@ -966,7 +984,7 @@ static int ps3av_module_init(void)
966 if (error) 984 if (error)
967 printk(KERN_ERR 985 printk(KERN_ERR
968 "%s: ps3_vuart_port_device_register failed %d\n", 986 "%s: ps3_vuart_port_device_register failed %d\n",
969 __FUNCTION__, error); 987 __func__, error);
970 988
971 return error; 989 return error;
972} 990}
diff --git a/drivers/ps3/ps3av_cmd.c b/drivers/ps3/ps3av_cmd.c
index bc70e81f8cb0..0145ea173c42 100644
--- a/drivers/ps3/ps3av_cmd.c
+++ b/drivers/ps3/ps3av_cmd.c
@@ -395,7 +395,7 @@ u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt,
395 video_mode->video_order = ps3av_video_fmt_table[video_fmt].order; 395 video_mode->video_order = ps3av_video_fmt_table[video_fmt].order;
396 396
397 pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n", 397 pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n",
398 __FUNCTION__, video_vid, video_mode->width, video_mode->height, 398 __func__, video_vid, video_mode->width, video_mode->height,
399 video_mode->pitch, video_mode->video_out_format, 399 video_mode->pitch, video_mode->video_out_format,
400 video_mode->video_format, video_mode->video_order); 400 video_mode->video_format, video_mode->video_order);
401 return sizeof(*video_mode); 401 return sizeof(*video_mode);
@@ -477,7 +477,7 @@ static u8 ps3av_cnv_mclk(u32 fs)
477 if (ps3av_cnv_mclk_table[i].fs == fs) 477 if (ps3av_cnv_mclk_table[i].fs == fs)
478 return ps3av_cnv_mclk_table[i].mclk; 478 return ps3av_cnv_mclk_table[i].mclk;
479 479
480 printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs); 480 printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
481 return 0; 481 return 0;
482} 482}
483 483
@@ -526,13 +526,12 @@ static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid)
526 d = 4; 526 d = 4;
527 break; 527 break;
528 default: 528 default:
529 printk(KERN_ERR "%s failed, vid:%x\n", __FUNCTION__, 529 printk(KERN_ERR "%s failed, vid:%x\n", __func__, video_vid);
530 video_vid);
531 break; 530 break;
532 } 531 }
533 532
534 if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K) 533 if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
535 printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs); 534 printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
536 else 535 else
537 ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d]; 536 ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
538 537
@@ -555,8 +554,7 @@ static u8 ps3av_cnv_enable(u32 source, const u8 *enable)
555 ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) | 554 ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) |
556 0x01; 555 0x01;
557 } else 556 } else
558 printk(KERN_ERR "%s failed, source:%x\n", __FUNCTION__, 557 printk(KERN_ERR "%s failed, source:%x\n", __func__, source);
559 source);
560 return ret; 558 return ret;
561} 559}
562 560
@@ -585,7 +583,7 @@ static u8 ps3av_cnv_inputlen(u32 word_bits)
585 ret = PS3AV_CMD_AV_INPUTLEN_24; 583 ret = PS3AV_CMD_AV_INPUTLEN_24;
586 break; 584 break;
587 default: 585 default:
588 printk(KERN_ERR "%s failed, word_bits:%x\n", __FUNCTION__, 586 printk(KERN_ERR "%s failed, word_bits:%x\n", __func__,
589 word_bits); 587 word_bits);
590 break; 588 break;
591 } 589 }
@@ -595,7 +593,7 @@ static u8 ps3av_cnv_inputlen(u32 word_bits)
595static u8 ps3av_cnv_layout(u32 num_of_ch) 593static u8 ps3av_cnv_layout(u32 num_of_ch)
596{ 594{
597 if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) { 595 if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
598 printk(KERN_ERR "%s failed, num_of_ch:%x\n", __FUNCTION__, 596 printk(KERN_ERR "%s failed, num_of_ch:%x\n", __func__,
599 num_of_ch); 597 num_of_ch);
600 return 0; 598 return 0;
601 } 599 }
@@ -864,7 +862,7 @@ int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
864 862
865 res = get_status(avb); 863 res = get_status(avb);
866 if (res) 864 if (res)
867 pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __FUNCTION__, 865 pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __func__,
868 res); 866 res);
869 867
870 out: 868 out:
@@ -1013,7 +1011,7 @@ int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
1013 return size; 1011 return size;
1014 if (error != -EAGAIN) { 1012 if (error != -EAGAIN) {
1015 printk(KERN_ERR "%s: ps3_vuart_read failed %d\n", 1013 printk(KERN_ERR "%s: ps3_vuart_read failed %d\n",
1016 __FUNCTION__, error); 1014 __func__, error);
1017 return error; 1015 return error;
1018 } 1016 }
1019 msleep(POLLING_INTERVAL); 1017 msleep(POLLING_INTERVAL);
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index e71929db8b06..977521013fe8 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -2174,6 +2174,51 @@ dasd_generic_notify(struct ccw_device *cdev, int event)
2174 return ret; 2174 return ret;
2175} 2175}
2176 2176
2177struct dasd_ccw_req * dasd_generic_build_rdc(struct dasd_device *device,
2178 void *rdc_buffer,
2179 int rdc_buffer_size, char *magic)
2180{
2181 struct dasd_ccw_req *cqr;
2182 struct ccw1 *ccw;
2183
2184 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
2185
2186 if (IS_ERR(cqr)) {
2187 DEV_MESSAGE(KERN_WARNING, device, "%s",
2188 "Could not allocate RDC request");
2189 return cqr;
2190 }
2191
2192 ccw = cqr->cpaddr;
2193 ccw->cmd_code = CCW_CMD_RDC;
2194 ccw->cda = (__u32)(addr_t)rdc_buffer;
2195 ccw->count = rdc_buffer_size;
2196
2197 cqr->device = device;
2198 cqr->expires = 10*HZ;
2199 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2200 cqr->retries = 2;
2201 cqr->buildclk = get_clock();
2202 cqr->status = DASD_CQR_FILLED;
2203 return cqr;
2204}
2205
2206
2207int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
2208 void **rdc_buffer, int rdc_buffer_size)
2209{
2210 int ret;
2211 struct dasd_ccw_req *cqr;
2212
2213 cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
2214 magic);
2215 if (IS_ERR(cqr))
2216 return PTR_ERR(cqr);
2217
2218 ret = dasd_sleep_on(cqr);
2219 dasd_sfree_request(cqr, cqr->device);
2220 return ret;
2221}
2177 2222
2178static int __init 2223static int __init
2179dasd_init(void) 2224dasd_init(void)
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index cecab2274a6e..c9583fbc2a7d 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -450,6 +450,81 @@ dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
450 return 0; 450 return 0;
451} 451}
452 452
453struct dasd_ccw_req * dasd_eckd_build_rcd_lpm(struct dasd_device *device,
454 void *rcd_buffer,
455 struct ciw *ciw, __u8 lpm)
456{
457 struct dasd_ccw_req *cqr;
458 struct ccw1 *ccw;
459
460 cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
461
462 if (IS_ERR(cqr)) {
463 DEV_MESSAGE(KERN_WARNING, device, "%s",
464 "Could not allocate RCD request");
465 return cqr;
466 }
467
468 ccw = cqr->cpaddr;
469 ccw->cmd_code = ciw->cmd;
470 ccw->cda = (__u32)(addr_t)rcd_buffer;
471 ccw->count = ciw->count;
472
473 cqr->device = device;
474 cqr->expires = 10*HZ;
475 cqr->lpm = lpm;
476 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
477 cqr->retries = 2;
478 cqr->buildclk = get_clock();
479 cqr->status = DASD_CQR_FILLED;
480 return cqr;
481}
482
483static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
484 void **rcd_buffer,
485 int *rcd_buffer_size, __u8 lpm)
486{
487 struct ciw *ciw;
488 char *rcd_buf = NULL;
489 int ret;
490 struct dasd_ccw_req *cqr;
491
492 /*
493 * scan for RCD command in extended SenseID data
494 */
495 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
496 if (!ciw || ciw->cmd == 0) {
497 ret = -EOPNOTSUPP;
498 goto out_error;
499 }
500 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
501 if (!rcd_buf) {
502 ret = -ENOMEM;
503 goto out_error;
504 }
505 cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
506 if (IS_ERR(cqr)) {
507 ret = PTR_ERR(cqr);
508 goto out_error;
509 }
510 ret = dasd_sleep_on(cqr);
511 /*
512 * on success we update the user input parms
513 */
514 dasd_sfree_request(cqr, cqr->device);
515 if (ret)
516 goto out_error;
517
518 *rcd_buffer_size = ciw->count;
519 *rcd_buffer = rcd_buf;
520 return 0;
521out_error:
522 kfree(rcd_buf);
523 *rcd_buffer = NULL;
524 *rcd_buffer_size = 0;
525 return ret;
526}
527
453static int 528static int
454dasd_eckd_read_conf(struct dasd_device *device) 529dasd_eckd_read_conf(struct dasd_device *device)
455{ 530{
@@ -469,8 +544,8 @@ dasd_eckd_read_conf(struct dasd_device *device)
469 /* get configuration data per operational path */ 544 /* get configuration data per operational path */
470 for (lpm = 0x80; lpm; lpm>>= 1) { 545 for (lpm = 0x80; lpm; lpm>>= 1) {
471 if (lpm & path_data->opm){ 546 if (lpm & path_data->opm){
472 rc = read_conf_data_lpm(device->cdev, &conf_data, 547 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
473 &conf_len, lpm); 548 &conf_len, lpm);
474 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */ 549 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
475 MESSAGE(KERN_WARNING, 550 MESSAGE(KERN_WARNING,
476 "Read configuration data returned " 551 "Read configuration data returned "
@@ -639,7 +714,7 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
639 /* Read Device Characteristics */ 714 /* Read Device Characteristics */
640 rdc_data = (void *) &(private->rdc_data); 715 rdc_data = (void *) &(private->rdc_data);
641 memset(rdc_data, 0, sizeof(rdc_data)); 716 memset(rdc_data, 0, sizeof(rdc_data));
642 rc = read_dev_chars(device->cdev, &rdc_data, 64); 717 rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64);
643 if (rc) 718 if (rc)
644 DEV_MESSAGE(KERN_WARNING, device, 719 DEV_MESSAGE(KERN_WARNING, device,
645 "Read device characteristics returned " 720 "Read device characteristics returned "
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index be0909e39226..da16ead8aff2 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -135,7 +135,7 @@ dasd_fba_check_characteristics(struct dasd_device *device)
135 } 135 }
136 /* Read Device Characteristics */ 136 /* Read Device Characteristics */
137 rdc_data = (void *) &(private->rdc_data); 137 rdc_data = (void *) &(private->rdc_data);
138 rc = read_dev_chars(device->cdev, &rdc_data, 32); 138 rc = dasd_generic_read_dev_chars(device, "FBA ", &rdc_data, 32);
139 if (rc) { 139 if (rc) {
140 DEV_MESSAGE(KERN_WARNING, device, 140 DEV_MESSAGE(KERN_WARNING, device,
141 "Read device characteristics returned error %d", 141 "Read device characteristics returned error %d",
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index a2cc69e11410..241294cba415 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -509,6 +509,8 @@ int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
509int dasd_generic_set_offline (struct ccw_device *cdev); 509int dasd_generic_set_offline (struct ccw_device *cdev);
510int dasd_generic_notify(struct ccw_device *, int); 510int dasd_generic_notify(struct ccw_device *, int);
511 511
512int dasd_generic_read_dev_chars(struct dasd_device *, char *, void **, int);
513
512/* externals in dasd_devmap.c */ 514/* externals in dasd_devmap.c */
513extern int dasd_max_devindex; 515extern int dasd_max_devindex;
514extern int dasd_probeonly; 516extern int dasd_probeonly;
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h
index bb4ff537729d..3b52f5c1dbef 100644
--- a/drivers/s390/char/tape.h
+++ b/drivers/s390/char/tape.h
@@ -103,6 +103,7 @@ enum tape_op {
103 TO_CRYPT_OFF, /* Disable encrpytion */ 103 TO_CRYPT_OFF, /* Disable encrpytion */
104 TO_KEKL_SET, /* Set KEK label */ 104 TO_KEKL_SET, /* Set KEK label */
105 TO_KEKL_QUERY, /* Query KEK label */ 105 TO_KEKL_QUERY, /* Query KEK label */
106 TO_RDC, /* Read device characteristics */
106 TO_SIZE, /* #entries in tape_op_t */ 107 TO_SIZE, /* #entries in tape_op_t */
107}; 108};
108 109
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c
index 50f5edab83d7..7e2b2ab49264 100644
--- a/drivers/s390/char/tape_3590.c
+++ b/drivers/s390/char/tape_3590.c
@@ -788,6 +788,7 @@ tape_3590_done(struct tape_device *device, struct tape_request *request)
788 case TO_SIZE: 788 case TO_SIZE:
789 case TO_KEKL_SET: 789 case TO_KEKL_SET:
790 case TO_KEKL_QUERY: 790 case TO_KEKL_QUERY:
791 case TO_RDC:
791 break; 792 break;
792 } 793 }
793 return TAPE_IO_SUCCESS; 794 return TAPE_IO_SUCCESS;
@@ -1549,6 +1550,26 @@ tape_3590_irq(struct tape_device *device, struct tape_request *request,
1549 return TAPE_IO_STOP; 1550 return TAPE_IO_STOP;
1550} 1551}
1551 1552
1553
1554static int tape_3590_read_dev_chars(struct tape_device *device,
1555 struct tape_3590_rdc_data *rdc_data)
1556{
1557 int rc;
1558 struct tape_request *request;
1559
1560 request = tape_alloc_request(1, sizeof(*rdc_data));
1561 if (IS_ERR(request))
1562 return PTR_ERR(request);
1563 request->op = TO_RDC;
1564 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1565 request->cpdata);
1566 rc = tape_do_io(device, request);
1567 if (rc == 0)
1568 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1569 tape_free_request(request);
1570 return rc;
1571}
1572
1552/* 1573/*
1553 * Setup device function 1574 * Setup device function
1554 */ 1575 */
@@ -1557,7 +1578,7 @@ tape_3590_setup_device(struct tape_device *device)
1557{ 1578{
1558 int rc; 1579 int rc;
1559 struct tape_3590_disc_data *data; 1580 struct tape_3590_disc_data *data;
1560 char *rdc_data; 1581 struct tape_3590_rdc_data *rdc_data;
1561 1582
1562 DBF_EVENT(6, "3590 device setup\n"); 1583 DBF_EVENT(6, "3590 device setup\n");
1563 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA); 1584 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
@@ -1566,12 +1587,12 @@ tape_3590_setup_device(struct tape_device *device)
1566 data->read_back_op = READ_PREVIOUS; 1587 data->read_back_op = READ_PREVIOUS;
1567 device->discdata = data; 1588 device->discdata = data;
1568 1589
1569 rdc_data = kmalloc(64, GFP_KERNEL | GFP_DMA); 1590 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
1570 if (!rdc_data) { 1591 if (!rdc_data) {
1571 rc = -ENOMEM; 1592 rc = -ENOMEM;
1572 goto fail_kmalloc; 1593 goto fail_kmalloc;
1573 } 1594 }
1574 rc = read_dev_chars(device->cdev, (void**)&rdc_data, 64); 1595 rc = tape_3590_read_dev_chars(device, rdc_data);
1575 if (rc) { 1596 if (rc) {
1576 DBF_LH(3, "Read device characteristics failed!\n"); 1597 DBF_LH(3, "Read device characteristics failed!\n");
1577 goto fail_kmalloc; 1598 goto fail_kmalloc;
@@ -1579,7 +1600,7 @@ tape_3590_setup_device(struct tape_device *device)
1579 rc = tape_std_assign(device); 1600 rc = tape_std_assign(device);
1580 if (rc) 1601 if (rc)
1581 goto fail_rdc_data; 1602 goto fail_rdc_data;
1582 if (rdc_data[31] == 0x13) { 1603 if (rdc_data->data[31] == 0x13) {
1583 PRINT_INFO("Device has crypto support\n"); 1604 PRINT_INFO("Device has crypto support\n");
1584 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK; 1605 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1585 tape_3592_disable_crypt(device); 1606 tape_3592_disable_crypt(device);
diff --git a/drivers/s390/char/tape_3590.h b/drivers/s390/char/tape_3590.h
index aa5138807af1..4534055f1376 100644
--- a/drivers/s390/char/tape_3590.h
+++ b/drivers/s390/char/tape_3590.h
@@ -129,6 +129,10 @@ struct tape_3590_med_sense {
129 char pad2[116]; 129 char pad2[116];
130} __attribute__ ((packed)); 130} __attribute__ ((packed));
131 131
132struct tape_3590_rdc_data {
133 char data[64];
134} __attribute__ ((packed));
135
132/* Datastructures for 3592 encryption support */ 136/* Datastructures for 3592 encryption support */
133 137
134struct tape3592_kekl { 138struct tape3592_kekl {
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index e2a8a1a04bab..2fae6338ee1c 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -73,7 +73,7 @@ const char *tape_op_verbose[TO_SIZE] =
73 [TO_DIS] = "DIS", [TO_ASSIGN] = "ASS", 73 [TO_DIS] = "DIS", [TO_ASSIGN] = "ASS",
74 [TO_UNASSIGN] = "UAS", [TO_CRYPT_ON] = "CON", 74 [TO_UNASSIGN] = "UAS", [TO_CRYPT_ON] = "CON",
75 [TO_CRYPT_OFF] = "COF", [TO_KEKL_SET] = "KLS", 75 [TO_CRYPT_OFF] = "COF", [TO_KEKL_SET] = "KLS",
76 [TO_KEKL_QUERY] = "KLQ", 76 [TO_KEKL_QUERY] = "KLQ",[TO_RDC] = "RDC",
77}; 77};
78 78
79static int 79static int
@@ -911,6 +911,7 @@ __tape_start_request(struct tape_device *device, struct tape_request *request)
911 case TO_ASSIGN: 911 case TO_ASSIGN:
912 case TO_UNASSIGN: 912 case TO_UNASSIGN:
913 case TO_READ_ATTMSG: 913 case TO_READ_ATTMSG:
914 case TO_RDC:
914 if (device->tape_state == TS_INIT) 915 if (device->tape_state == TS_INIT)
915 break; 916 break;
916 if (device->tape_state == TS_UNUSED) 917 if (device->tape_state == TS_UNUSED)
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 05fac0733f3d..cba64e4cfcd4 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -69,7 +69,6 @@ static const char version[] = "QDIO base support version 2";
69 69
70static int qdio_performance_stats = 0; 70static int qdio_performance_stats = 0;
71static int proc_perf_file_registration; 71static int proc_perf_file_registration;
72static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
73static struct qdio_perf_stats perf_stats; 72static struct qdio_perf_stats perf_stats;
74 73
75static int hydra_thinints; 74static int hydra_thinints;
@@ -111,6 +110,31 @@ qdio_min(int a,int b)
111} 110}
112 111
113/***************** SCRUBBER HELPER ROUTINES **********************/ 112/***************** SCRUBBER HELPER ROUTINES **********************/
113#ifdef CONFIG_64BIT
114static inline void qdio_perf_stat_inc(atomic64_t *count)
115{
116 if (qdio_performance_stats)
117 atomic64_inc(count);
118}
119
120static inline void qdio_perf_stat_dec(atomic64_t *count)
121{
122 if (qdio_performance_stats)
123 atomic64_dec(count);
124}
125#else /* CONFIG_64BIT */
126static inline void qdio_perf_stat_inc(atomic_t *count)
127{
128 if (qdio_performance_stats)
129 atomic_inc(count);
130}
131
132static inline void qdio_perf_stat_dec(atomic_t *count)
133{
134 if (qdio_performance_stats)
135 atomic_dec(count);
136}
137#endif /* CONFIG_64BIT */
114 138
115static inline __u64 139static inline __u64
116qdio_get_micros(void) 140qdio_get_micros(void)
@@ -277,8 +301,7 @@ qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
277 QDIO_DBF_TEXT4(0,trace,"sigasync"); 301 QDIO_DBF_TEXT4(0,trace,"sigasync");
278 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 302 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
279 303
280 if (qdio_performance_stats) 304 qdio_perf_stat_inc(&perf_stats.siga_syncs);
281 perf_stats.siga_syncs++;
282 305
283 cc = do_siga_sync(q->schid, gpr2, gpr3); 306 cc = do_siga_sync(q->schid, gpr2, gpr3);
284 if (cc) 307 if (cc)
@@ -323,8 +346,7 @@ qdio_siga_output(struct qdio_q *q)
323 __u32 busy_bit; 346 __u32 busy_bit;
324 __u64 start_time=0; 347 __u64 start_time=0;
325 348
326 if (qdio_performance_stats) 349 qdio_perf_stat_inc(&perf_stats.siga_outs);
327 perf_stats.siga_outs++;
328 350
329 QDIO_DBF_TEXT4(0,trace,"sigaout"); 351 QDIO_DBF_TEXT4(0,trace,"sigaout");
330 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 352 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
@@ -358,8 +380,7 @@ qdio_siga_input(struct qdio_q *q)
358 QDIO_DBF_TEXT4(0,trace,"sigain"); 380 QDIO_DBF_TEXT4(0,trace,"sigain");
359 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 381 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
360 382
361 if (qdio_performance_stats) 383 qdio_perf_stat_inc(&perf_stats.siga_ins);
362 perf_stats.siga_ins++;
363 384
364 cc = do_siga_input(q->schid, q->mask); 385 cc = do_siga_input(q->schid, q->mask);
365 386
@@ -953,8 +974,7 @@ __qdio_outbound_processing(struct qdio_q *q)
953 974
954 if (unlikely(qdio_reserve_q(q))) { 975 if (unlikely(qdio_reserve_q(q))) {
955 qdio_release_q(q); 976 qdio_release_q(q);
956 if (qdio_performance_stats) 977 qdio_perf_stat_inc(&perf_stats.outbound_tl_runs_resched);
957 o_p_c++;
958 /* as we're sissies, we'll check next time */ 978 /* as we're sissies, we'll check next time */
959 if (likely(!atomic_read(&q->is_in_shutdown))) { 979 if (likely(!atomic_read(&q->is_in_shutdown))) {
960 qdio_mark_q(q); 980 qdio_mark_q(q);
@@ -962,10 +982,8 @@ __qdio_outbound_processing(struct qdio_q *q)
962 } 982 }
963 return; 983 return;
964 } 984 }
965 if (qdio_performance_stats) { 985 qdio_perf_stat_inc(&perf_stats.outbound_tl_runs);
966 o_p_nc++; 986 qdio_perf_stat_inc(&perf_stats.tl_runs);
967 perf_stats.tl_runs++;
968 }
969 987
970 /* see comment in qdio_kick_outbound_q */ 988 /* see comment in qdio_kick_outbound_q */
971 siga_attempts=atomic_read(&q->busy_siga_counter); 989 siga_attempts=atomic_read(&q->busy_siga_counter);
@@ -1139,17 +1157,6 @@ qdio_has_inbound_q_moved(struct qdio_q *q)
1139{ 1157{
1140 int i; 1158 int i;
1141 1159
1142 static int old_pcis=0;
1143 static int old_thinints=0;
1144
1145 if (qdio_performance_stats) {
1146 if ((old_pcis==perf_stats.pcis)&&
1147 (old_thinints==perf_stats.thinints))
1148 perf_stats.start_time_inbound=NOW;
1149 else
1150 old_pcis=perf_stats.pcis;
1151 }
1152
1153 i=qdio_get_inbound_buffer_frontier(q); 1160 i=qdio_get_inbound_buffer_frontier(q);
1154 if ( (i!=GET_SAVED_FRONTIER(q)) || 1161 if ( (i!=GET_SAVED_FRONTIER(q)) ||
1155 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) { 1162 (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) {
@@ -1337,10 +1344,7 @@ qdio_kick_inbound_handler(struct qdio_q *q)
1337 q->siga_error=0; 1344 q->siga_error=0;
1338 q->error_status_flags=0; 1345 q->error_status_flags=0;
1339 1346
1340 if (qdio_performance_stats) { 1347 qdio_perf_stat_inc(&perf_stats.inbound_cnt);
1341 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
1342 perf_stats.inbound_cnt++;
1343 }
1344} 1348}
1345 1349
1346static void 1350static void
@@ -1360,8 +1364,7 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1360 */ 1364 */
1361 if (unlikely(qdio_reserve_q(q))) { 1365 if (unlikely(qdio_reserve_q(q))) {
1362 qdio_release_q(q); 1366 qdio_release_q(q);
1363 if (qdio_performance_stats) 1367 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1364 ii_p_c++;
1365 /* 1368 /*
1366 * as we might just be about to stop polling, we make 1369 * as we might just be about to stop polling, we make
1367 * sure that we check again at least once more 1370 * sure that we check again at least once more
@@ -1369,8 +1372,7 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1369 tiqdio_sched_tl(); 1372 tiqdio_sched_tl();
1370 return; 1373 return;
1371 } 1374 }
1372 if (qdio_performance_stats) 1375 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs);
1373 ii_p_nc++;
1374 if (unlikely(atomic_read(&q->is_in_shutdown))) { 1376 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1375 qdio_unmark_q(q); 1377 qdio_unmark_q(q);
1376 goto out; 1378 goto out;
@@ -1412,8 +1414,7 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1412 for (i=0;i<irq_ptr->no_output_qs;i++) { 1414 for (i=0;i<irq_ptr->no_output_qs;i++) {
1413 oq = irq_ptr->output_qs[i]; 1415 oq = irq_ptr->output_qs[i];
1414 if (!qdio_is_outbound_q_done(oq)) { 1416 if (!qdio_is_outbound_q_done(oq)) {
1415 if (qdio_performance_stats) 1417 qdio_perf_stat_dec(&perf_stats.tl_runs);
1416 perf_stats.tl_runs--;
1417 __qdio_outbound_processing(oq); 1418 __qdio_outbound_processing(oq);
1418 } 1419 }
1419 } 1420 }
@@ -1452,8 +1453,7 @@ __qdio_inbound_processing(struct qdio_q *q)
1452 1453
1453 if (unlikely(qdio_reserve_q(q))) { 1454 if (unlikely(qdio_reserve_q(q))) {
1454 qdio_release_q(q); 1455 qdio_release_q(q);
1455 if (qdio_performance_stats) 1456 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs_resched);
1456 i_p_c++;
1457 /* as we're sissies, we'll check next time */ 1457 /* as we're sissies, we'll check next time */
1458 if (likely(!atomic_read(&q->is_in_shutdown))) { 1458 if (likely(!atomic_read(&q->is_in_shutdown))) {
1459 qdio_mark_q(q); 1459 qdio_mark_q(q);
@@ -1461,10 +1461,8 @@ __qdio_inbound_processing(struct qdio_q *q)
1461 } 1461 }
1462 return; 1462 return;
1463 } 1463 }
1464 if (qdio_performance_stats) { 1464 qdio_perf_stat_inc(&perf_stats.inbound_tl_runs);
1465 i_p_nc++; 1465 qdio_perf_stat_inc(&perf_stats.tl_runs);
1466 perf_stats.tl_runs++;
1467 }
1468 1466
1469again: 1467again:
1470 if (qdio_has_inbound_q_moved(q)) { 1468 if (qdio_has_inbound_q_moved(q)) {
@@ -1510,8 +1508,7 @@ tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1510 1508
1511 if (unlikely(qdio_reserve_q(q))) { 1509 if (unlikely(qdio_reserve_q(q))) {
1512 qdio_release_q(q); 1510 qdio_release_q(q);
1513 if (qdio_performance_stats) 1511 qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched);
1514 ii_p_c++;
1515 /* 1512 /*
1516 * as we might just be about to stop polling, we make 1513 * as we might just be about to stop polling, we make
1517 * sure that we check again at least once more 1514 * sure that we check again at least once more
@@ -1602,8 +1599,7 @@ tiqdio_tl(unsigned long data)
1602{ 1599{
1603 QDIO_DBF_TEXT4(0,trace,"iqdio_tl"); 1600 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1604 1601
1605 if (qdio_performance_stats) 1602 qdio_perf_stat_inc(&perf_stats.tl_runs);
1606 perf_stats.tl_runs++;
1607 1603
1608 tiqdio_inbound_checks(); 1604 tiqdio_inbound_checks();
1609} 1605}
@@ -1914,10 +1910,7 @@ tiqdio_thinint_handler(void)
1914{ 1910{
1915 QDIO_DBF_TEXT4(0,trace,"thin_int"); 1911 QDIO_DBF_TEXT4(0,trace,"thin_int");
1916 1912
1917 if (qdio_performance_stats) { 1913 qdio_perf_stat_inc(&perf_stats.thinints);
1918 perf_stats.thinints++;
1919 perf_stats.start_time_inbound=NOW;
1920 }
1921 1914
1922 /* SVS only when needed: 1915 /* SVS only when needed:
1923 * issue SVS to benefit from iqdio interrupt avoidance 1916 * issue SVS to benefit from iqdio interrupt avoidance
@@ -1972,17 +1965,12 @@ qdio_handle_pci(struct qdio_irq *irq_ptr)
1972 int i; 1965 int i;
1973 struct qdio_q *q; 1966 struct qdio_q *q;
1974 1967
1975 if (qdio_performance_stats) { 1968 qdio_perf_stat_inc(&perf_stats.pcis);
1976 perf_stats.pcis++;
1977 perf_stats.start_time_inbound=NOW;
1978 }
1979 for (i=0;i<irq_ptr->no_input_qs;i++) { 1969 for (i=0;i<irq_ptr->no_input_qs;i++) {
1980 q=irq_ptr->input_qs[i]; 1970 q=irq_ptr->input_qs[i];
1981 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) 1971 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1982 qdio_mark_q(q); 1972 qdio_mark_q(q);
1983 else { 1973 else {
1984 if (qdio_performance_stats)
1985 perf_stats.tl_runs--;
1986 __qdio_inbound_processing(q); 1974 __qdio_inbound_processing(q);
1987 } 1975 }
1988 } 1976 }
@@ -1992,8 +1980,7 @@ qdio_handle_pci(struct qdio_irq *irq_ptr)
1992 q=irq_ptr->output_qs[i]; 1980 q=irq_ptr->output_qs[i];
1993 if (qdio_is_outbound_q_done(q)) 1981 if (qdio_is_outbound_q_done(q))
1994 continue; 1982 continue;
1995 if (qdio_performance_stats) 1983 qdio_perf_stat_dec(&perf_stats.tl_runs);
1996 perf_stats.tl_runs--;
1997 if (!irq_ptr->sync_done_on_outb_pcis) 1984 if (!irq_ptr->sync_done_on_outb_pcis)
1998 SYNC_MEMORY; 1985 SYNC_MEMORY;
1999 __qdio_outbound_processing(q); 1986 __qdio_outbound_processing(q);
@@ -3463,18 +3450,12 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3463 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; 3450 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3464 3451
3465 /* This is the outbound handling of queues */ 3452 /* This is the outbound handling of queues */
3466 if (qdio_performance_stats)
3467 perf_stats.start_time_outbound=NOW;
3468
3469 qdio_do_qdio_fill_output(q,qidx,count,buffers); 3453 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3470 3454
3471 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; 3455 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3472 3456
3473 if (callflags&QDIO_FLAG_DONT_SIGA) { 3457 if (callflags&QDIO_FLAG_DONT_SIGA) {
3474 if (qdio_performance_stats) { 3458 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3475 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3476 perf_stats.outbound_cnt++;
3477 }
3478 return; 3459 return;
3479 } 3460 }
3480 if (q->is_iqdio_q) { 3461 if (q->is_iqdio_q) {
@@ -3504,8 +3485,7 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3504 qdio_kick_outbound_q(q); 3485 qdio_kick_outbound_q(q);
3505 } else { 3486 } else {
3506 QDIO_DBF_TEXT3(0,trace, "fast-req"); 3487 QDIO_DBF_TEXT3(0,trace, "fast-req");
3507 if (qdio_performance_stats) 3488 qdio_perf_stat_inc(&perf_stats.fast_reqs);
3508 perf_stats.fast_reqs++;
3509 } 3489 }
3510 } 3490 }
3511 /* 3491 /*
@@ -3516,10 +3496,7 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3516 __qdio_outbound_processing(q); 3496 __qdio_outbound_processing(q);
3517 } 3497 }
3518 3498
3519 if (qdio_performance_stats) { 3499 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3520 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3521 perf_stats.outbound_cnt++;
3522 }
3523} 3500}
3524 3501
3525/* count must be 1 in iqdio */ 3502/* count must be 1 in iqdio */
@@ -3589,33 +3566,67 @@ qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3589 return 0; 3566 return 0;
3590 3567
3591#define _OUTP_IT(x...) c+=sprintf(buffer+c,x) 3568#define _OUTP_IT(x...) c+=sprintf(buffer+c,x)
3592 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c); 3569#ifdef CONFIG_64BIT
3593 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c); 3570 _OUTP_IT("Number of tasklet runs (total) : %li\n",
3594 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c); 3571 (long)atomic64_read(&perf_stats.tl_runs));
3595 _OUTP_IT("Number of tasklet runs (total) : %lu\n", 3572 _OUTP_IT("Inbound tasklet runs tried/retried : %li/%li\n",
3596 perf_stats.tl_runs); 3573 (long)atomic64_read(&perf_stats.inbound_tl_runs),
3574 (long)atomic64_read(&perf_stats.inbound_tl_runs_resched));
3575 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %li/%li\n",
3576 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs),
3577 (long)atomic64_read(&perf_stats.inbound_thin_tl_runs_resched));
3578 _OUTP_IT("Outbound tasklet runs tried/retried : %li/%li\n",
3579 (long)atomic64_read(&perf_stats.outbound_tl_runs),
3580 (long)atomic64_read(&perf_stats.outbound_tl_runs_resched));
3597 _OUTP_IT("\n"); 3581 _OUTP_IT("\n");
3598 _OUTP_IT("Number of SIGA sync's issued : %lu\n", 3582 _OUTP_IT("Number of SIGA sync's issued : %li\n",
3599 perf_stats.siga_syncs); 3583 (long)atomic64_read(&perf_stats.siga_syncs));
3600 _OUTP_IT("Number of SIGA in's issued : %lu\n", 3584 _OUTP_IT("Number of SIGA in's issued : %li\n",
3601 perf_stats.siga_ins); 3585 (long)atomic64_read(&perf_stats.siga_ins));
3602 _OUTP_IT("Number of SIGA out's issued : %lu\n", 3586 _OUTP_IT("Number of SIGA out's issued : %li\n",
3603 perf_stats.siga_outs); 3587 (long)atomic64_read(&perf_stats.siga_outs));
3604 _OUTP_IT("Number of PCIs caught : %lu\n", 3588 _OUTP_IT("Number of PCIs caught : %li\n",
3605 perf_stats.pcis); 3589 (long)atomic64_read(&perf_stats.pcis));
3606 _OUTP_IT("Number of adapter interrupts caught : %lu\n", 3590 _OUTP_IT("Number of adapter interrupts caught : %li\n",
3607 perf_stats.thinints); 3591 (long)atomic64_read(&perf_stats.thinints));
3608 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %lu\n", 3592 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %li\n",
3609 perf_stats.fast_reqs); 3593 (long)atomic64_read(&perf_stats.fast_reqs));
3610 _OUTP_IT("\n"); 3594 _OUTP_IT("\n");
3611 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %lu\n", 3595 _OUTP_IT("Number of inbound transfers : %li\n",
3612 perf_stats.inbound_time); 3596 (long)atomic64_read(&perf_stats.inbound_cnt));
3613 _OUTP_IT("Number of inbound transfers : %lu\n", 3597 _OUTP_IT("Number of do_QDIOs outbound : %li\n",
3614 perf_stats.inbound_cnt); 3598 (long)atomic64_read(&perf_stats.outbound_cnt));
3615 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %lu\n", 3599#else /* CONFIG_64BIT */
3616 perf_stats.outbound_time); 3600 _OUTP_IT("Number of tasklet runs (total) : %i\n",
3617 _OUTP_IT("Number of do_QDIOs outbound : %lu\n", 3601 atomic_read(&perf_stats.tl_runs));
3618 perf_stats.outbound_cnt); 3602 _OUTP_IT("Inbound tasklet runs tried/retried : %i/%i\n",
3603 atomic_read(&perf_stats.inbound_tl_runs),
3604 atomic_read(&perf_stats.inbound_tl_runs_resched));
3605 _OUTP_IT("Inbound-thin tasklet runs tried/retried : %i/%i\n",
3606 atomic_read(&perf_stats.inbound_thin_tl_runs),
3607 atomic_read(&perf_stats.inbound_thin_tl_runs_resched));
3608 _OUTP_IT("Outbound tasklet runs tried/retried : %i/%i\n",
3609 atomic_read(&perf_stats.outbound_tl_runs),
3610 atomic_read(&perf_stats.outbound_tl_runs_resched));
3611 _OUTP_IT("\n");
3612 _OUTP_IT("Number of SIGA sync's issued : %i\n",
3613 atomic_read(&perf_stats.siga_syncs));
3614 _OUTP_IT("Number of SIGA in's issued : %i\n",
3615 atomic_read(&perf_stats.siga_ins));
3616 _OUTP_IT("Number of SIGA out's issued : %i\n",
3617 atomic_read(&perf_stats.siga_outs));
3618 _OUTP_IT("Number of PCIs caught : %i\n",
3619 atomic_read(&perf_stats.pcis));
3620 _OUTP_IT("Number of adapter interrupts caught : %i\n",
3621 atomic_read(&perf_stats.thinints));
3622 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %i\n",
3623 atomic_read(&perf_stats.fast_reqs));
3624 _OUTP_IT("\n");
3625 _OUTP_IT("Number of inbound transfers : %i\n",
3626 atomic_read(&perf_stats.inbound_cnt));
3627 _OUTP_IT("Number of do_QDIOs outbound : %i\n",
3628 atomic_read(&perf_stats.outbound_cnt));
3629#endif /* CONFIG_64BIT */
3619 _OUTP_IT("\n"); 3630 _OUTP_IT("\n");
3620 3631
3621 return c; 3632 return c;
@@ -3642,8 +3653,6 @@ qdio_add_procfs_entry(void)
3642static void 3653static void
3643qdio_remove_procfs_entry(void) 3654qdio_remove_procfs_entry(void)
3644{ 3655{
3645 perf_stats.tl_runs=0;
3646
3647 if (!proc_perf_file_registration) /* means if it went ok earlier */ 3656 if (!proc_perf_file_registration) /* means if it went ok earlier */
3648 remove_proc_entry(QDIO_PERF,&proc_root); 3657 remove_proc_entry(QDIO_PERF,&proc_root);
3649} 3658}
@@ -3671,13 +3680,38 @@ qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count
3671 qdio_performance_stats = i; 3680 qdio_performance_stats = i;
3672 if (i==0) { 3681 if (i==0) {
3673 /* reset perf. stat. info */ 3682 /* reset perf. stat. info */
3674 i_p_nc = 0; 3683#ifdef CONFIG_64BIT
3675 i_p_c = 0; 3684 atomic64_set(&perf_stats.tl_runs, 0);
3676 ii_p_nc = 0; 3685 atomic64_set(&perf_stats.outbound_tl_runs, 0);
3677 ii_p_c = 0; 3686 atomic64_set(&perf_stats.inbound_tl_runs, 0);
3678 o_p_nc = 0; 3687 atomic64_set(&perf_stats.inbound_tl_runs_resched, 0);
3679 o_p_c = 0; 3688 atomic64_set(&perf_stats.inbound_thin_tl_runs, 0);
3680 memset(&perf_stats, 0, sizeof(struct qdio_perf_stats)); 3689 atomic64_set(&perf_stats.inbound_thin_tl_runs_resched,
3690 0);
3691 atomic64_set(&perf_stats.siga_outs, 0);
3692 atomic64_set(&perf_stats.siga_ins, 0);
3693 atomic64_set(&perf_stats.siga_syncs, 0);
3694 atomic64_set(&perf_stats.pcis, 0);
3695 atomic64_set(&perf_stats.thinints, 0);
3696 atomic64_set(&perf_stats.fast_reqs, 0);
3697 atomic64_set(&perf_stats.outbound_cnt, 0);
3698 atomic64_set(&perf_stats.inbound_cnt, 0);
3699#else /* CONFIG_64BIT */
3700 atomic_set(&perf_stats.tl_runs, 0);
3701 atomic_set(&perf_stats.outbound_tl_runs, 0);
3702 atomic_set(&perf_stats.inbound_tl_runs, 0);
3703 atomic_set(&perf_stats.inbound_tl_runs_resched, 0);
3704 atomic_set(&perf_stats.inbound_thin_tl_runs, 0);
3705 atomic_set(&perf_stats.inbound_thin_tl_runs_resched, 0);
3706 atomic_set(&perf_stats.siga_outs, 0);
3707 atomic_set(&perf_stats.siga_ins, 0);
3708 atomic_set(&perf_stats.siga_syncs, 0);
3709 atomic_set(&perf_stats.pcis, 0);
3710 atomic_set(&perf_stats.thinints, 0);
3711 atomic_set(&perf_stats.fast_reqs, 0);
3712 atomic_set(&perf_stats.outbound_cnt, 0);
3713 atomic_set(&perf_stats.inbound_cnt, 0);
3714#endif /* CONFIG_64BIT */
3681 } 3715 }
3682 } else { 3716 } else {
3683 QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n"); 3717 QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n");
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index ec9af72b2afc..2895392eaae4 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -406,21 +406,43 @@ do_clear_global_summary(void)
406#define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04 406#define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04
407 407
408struct qdio_perf_stats { 408struct qdio_perf_stats {
409 unsigned long tl_runs; 409#ifdef CONFIG_64BIT
410 410 atomic64_t tl_runs;
411 unsigned long siga_outs; 411 atomic64_t outbound_tl_runs;
412 unsigned long siga_ins; 412 atomic64_t outbound_tl_runs_resched;
413 unsigned long siga_syncs; 413 atomic64_t inbound_tl_runs;
414 unsigned long pcis; 414 atomic64_t inbound_tl_runs_resched;
415 unsigned long thinints; 415 atomic64_t inbound_thin_tl_runs;
416 unsigned long fast_reqs; 416 atomic64_t inbound_thin_tl_runs_resched;
417 417
418 __u64 start_time_outbound; 418 atomic64_t siga_outs;
419 unsigned long outbound_cnt; 419 atomic64_t siga_ins;
420 unsigned long outbound_time; 420 atomic64_t siga_syncs;
421 __u64 start_time_inbound; 421 atomic64_t pcis;
422 unsigned long inbound_cnt; 422 atomic64_t thinints;
423 unsigned long inbound_time; 423 atomic64_t fast_reqs;
424
425 atomic64_t outbound_cnt;
426 atomic64_t inbound_cnt;
427#else /* CONFIG_64BIT */
428 atomic_t tl_runs;
429 atomic_t outbound_tl_runs;
430 atomic_t outbound_tl_runs_resched;
431 atomic_t inbound_tl_runs;
432 atomic_t inbound_tl_runs_resched;
433 atomic_t inbound_thin_tl_runs;
434 atomic_t inbound_thin_tl_runs_resched;
435
436 atomic_t siga_outs;
437 atomic_t siga_ins;
438 atomic_t siga_syncs;
439 atomic_t pcis;
440 atomic_t thinints;
441 atomic_t fast_reqs;
442
443 atomic_t outbound_cnt;
444 atomic_t inbound_cnt;
445#endif /* CONFIG_64BIT */
424}; 446};
425 447
426/* unlikely as the later the better */ 448/* unlikely as the later the better */
diff --git a/drivers/s390/net/qeth.h b/drivers/s390/net/qeth.h
index 84b108d7c7fd..b34eb82edd98 100644
--- a/drivers/s390/net/qeth.h
+++ b/drivers/s390/net/qeth.h
@@ -288,6 +288,7 @@ qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
288 */ 288 */
289#define IF_NAME_LEN 16 289#define IF_NAME_LEN 16
290#define QETH_TX_TIMEOUT 100 * HZ 290#define QETH_TX_TIMEOUT 100 * HZ
291#define QETH_RCD_TIMEOUT 60 * HZ
291#define QETH_HEADER_SIZE 32 292#define QETH_HEADER_SIZE 32
292#define MAX_PORTNO 15 293#define MAX_PORTNO 15
293#define QETH_FAKE_LL_LEN_ETH ETH_HLEN 294#define QETH_FAKE_LL_LEN_ETH ETH_HLEN
@@ -582,6 +583,8 @@ enum qeth_channel_states {
582 CH_STATE_ACTIVATING, 583 CH_STATE_ACTIVATING,
583 CH_STATE_HALTED, 584 CH_STATE_HALTED,
584 CH_STATE_STOPPED, 585 CH_STATE_STOPPED,
586 CH_STATE_RCD,
587 CH_STATE_RCD_DONE,
585}; 588};
586/** 589/**
587 * card state machine 590 * card state machine
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index ad7792dc1a04..6fd8870551d3 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -315,7 +315,8 @@ qeth_alloc_card(void)
315} 315}
316 316
317static long 317static long
318__qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb) 318__qeth_check_irb_error(struct ccw_device *cdev, unsigned long intparm,
319 struct irb *irb)
319{ 320{
320 if (!IS_ERR(irb)) 321 if (!IS_ERR(irb))
321 return 0; 322 return 0;
@@ -330,6 +331,14 @@ __qeth_check_irb_error(struct ccw_device *cdev, struct irb *irb)
330 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id); 331 PRINT_WARN("timeout on device %s\n", cdev->dev.bus_id);
331 QETH_DBF_TEXT(trace, 2, "ckirberr"); 332 QETH_DBF_TEXT(trace, 2, "ckirberr");
332 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT); 333 QETH_DBF_TEXT_(trace, 2, " rc%d", -ETIMEDOUT);
334 if (intparm == QETH_RCD_PARM) {
335 struct qeth_card *card = CARD_FROM_CDEV(cdev);
336
337 if (card && (card->data.ccwdev == cdev)) {
338 card->data.state = CH_STATE_DOWN;
339 wake_up(&card->wait_q);
340 }
341 }
333 break; 342 break;
334 default: 343 default:
335 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb), 344 PRINT_WARN("unknown error %ld on device %s\n", PTR_ERR(irb),
@@ -401,7 +410,7 @@ qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
401 410
402 QETH_DBF_TEXT(trace,5,"irq"); 411 QETH_DBF_TEXT(trace,5,"irq");
403 412
404 if (__qeth_check_irb_error(cdev, irb)) 413 if (__qeth_check_irb_error(cdev, intparm, irb))
405 return; 414 return;
406 cstat = irb->scsw.cstat; 415 cstat = irb->scsw.cstat;
407 dstat = irb->scsw.dstat; 416 dstat = irb->scsw.dstat;
@@ -429,7 +438,8 @@ qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
429 channel->state = CH_STATE_HALTED; 438 channel->state = CH_STATE_HALTED;
430 439
431 /*let's wake up immediately on data channel*/ 440 /*let's wake up immediately on data channel*/
432 if ((channel == &card->data) && (intparm != 0)) 441 if ((channel == &card->data) && (intparm != 0) &&
442 (intparm != QETH_RCD_PARM))
433 goto out; 443 goto out;
434 444
435 if (intparm == QETH_CLEAR_CHANNEL_PARM) { 445 if (intparm == QETH_CLEAR_CHANNEL_PARM) {
@@ -453,6 +463,10 @@ qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
453 HEXDUMP16(WARN,"irb: ",irb); 463 HEXDUMP16(WARN,"irb: ",irb);
454 HEXDUMP16(WARN,"sense data: ",irb->ecw); 464 HEXDUMP16(WARN,"sense data: ",irb->ecw);
455 } 465 }
466 if (intparm == QETH_RCD_PARM) {
467 channel->state = CH_STATE_DOWN;
468 goto out;
469 }
456 rc = qeth_get_problem(cdev,irb); 470 rc = qeth_get_problem(cdev,irb);
457 if (rc) { 471 if (rc) {
458 qeth_schedule_recovery(card); 472 qeth_schedule_recovery(card);
@@ -460,6 +474,10 @@ qeth_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
460 } 474 }
461 } 475 }
462 476
477 if (intparm == QETH_RCD_PARM) {
478 channel->state = CH_STATE_RCD_DONE;
479 goto out;
480 }
463 if (intparm) { 481 if (intparm) {
464 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm); 482 buffer = (struct qeth_cmd_buffer *) __va((addr_t)intparm);
465 buffer->state = BUF_STATE_PROCESSED; 483 buffer->state = BUF_STATE_PROCESSED;
@@ -1204,6 +1222,54 @@ qeth_probe_device(struct ccwgroup_device *gdev)
1204} 1222}
1205 1223
1206 1224
1225static int qeth_read_conf_data(struct qeth_card *card, void **buffer,
1226 int *length)
1227{
1228 struct ciw *ciw;
1229 char *rcd_buf;
1230 int ret;
1231 struct qeth_channel *channel = &card->data;
1232 unsigned long flags;
1233
1234 /*
1235 * scan for RCD command in extended SenseID data
1236 */
1237 ciw = ccw_device_get_ciw(channel->ccwdev, CIW_TYPE_RCD);
1238 if (!ciw || ciw->cmd == 0)
1239 return -EOPNOTSUPP;
1240 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
1241 if (!rcd_buf)
1242 return -ENOMEM;
1243
1244 channel->ccw.cmd_code = ciw->cmd;
1245 channel->ccw.cda = (__u32) __pa (rcd_buf);
1246 channel->ccw.count = ciw->count;
1247 channel->ccw.flags = CCW_FLAG_SLI;
1248 channel->state = CH_STATE_RCD;
1249 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
1250 ret = ccw_device_start_timeout(channel->ccwdev, &channel->ccw,
1251 QETH_RCD_PARM, LPM_ANYPATH, 0,
1252 QETH_RCD_TIMEOUT);
1253 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
1254 if (!ret)
1255 wait_event(card->wait_q,
1256 (channel->state == CH_STATE_RCD_DONE ||
1257 channel->state == CH_STATE_DOWN));
1258 if (channel->state == CH_STATE_DOWN)
1259 ret = -EIO;
1260 else
1261 channel->state = CH_STATE_DOWN;
1262 if (ret) {
1263 kfree(rcd_buf);
1264 *buffer = NULL;
1265 *length = 0;
1266 } else {
1267 *length = ciw->count;
1268 *buffer = rcd_buf;
1269 }
1270 return ret;
1271}
1272
1207static int 1273static int
1208qeth_get_unitaddr(struct qeth_card *card) 1274qeth_get_unitaddr(struct qeth_card *card)
1209{ 1275{
@@ -1212,9 +1278,9 @@ qeth_get_unitaddr(struct qeth_card *card)
1212 int rc; 1278 int rc;
1213 1279
1214 QETH_DBF_TEXT(setup, 2, "getunit"); 1280 QETH_DBF_TEXT(setup, 2, "getunit");
1215 rc = read_conf_data(CARD_DDEV(card), (void **) &prcd, &length); 1281 rc = qeth_read_conf_data(card, (void **) &prcd, &length);
1216 if (rc) { 1282 if (rc) {
1217 PRINT_ERR("read_conf_data for device %s returned %i\n", 1283 PRINT_ERR("qeth_read_conf_data for device %s returned %i\n",
1218 CARD_DDEV_ID(card), rc); 1284 CARD_DDEV_ID(card), rc);
1219 return rc; 1285 return rc;
1220 } 1286 }
@@ -1223,6 +1289,7 @@ qeth_get_unitaddr(struct qeth_card *card)
1223 card->info.cula = prcd[63]; 1289 card->info.cula = prcd[63];
1224 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) && 1290 card->info.guestlan = ((prcd[0x10] == _ascebc['V']) &&
1225 (prcd[0x11] == _ascebc['M'])); 1291 (prcd[0x11] == _ascebc['M']));
1292 kfree(prcd);
1226 return 0; 1293 return 0;
1227} 1294}
1228 1295
diff --git a/drivers/s390/net/qeth_mpc.h b/drivers/s390/net/qeth_mpc.h
index 0477c47471c5..d74bc43da72a 100644
--- a/drivers/s390/net/qeth_mpc.h
+++ b/drivers/s390/net/qeth_mpc.h
@@ -37,6 +37,7 @@ extern unsigned char IPA_PDU_HEADER[];
37 37
38#define QETH_CLEAR_CHANNEL_PARM -10 38#define QETH_CLEAR_CHANNEL_PARM -10
39#define QETH_HALT_CHANNEL_PARM -11 39#define QETH_HALT_CHANNEL_PARM -11
40#define QETH_RCD_PARM -12
40 41
41/*****************************************************************************/ 42/*****************************************************************************/
42/* IP Assist related definitions */ 43/* IP Assist related definitions */
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index fcc4cb6c7f46..e1ebed0f0755 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1649,7 +1649,7 @@ config OKTAGON_SCSI
1649 1649
1650config ATARI_SCSI 1650config ATARI_SCSI
1651 tristate "Atari native SCSI support" 1651 tristate "Atari native SCSI support"
1652 depends on ATARI && SCSI && BROKEN 1652 depends on ATARI && SCSI
1653 select SCSI_SPI_ATTRS 1653 select SCSI_SPI_ATTRS
1654 ---help--- 1654 ---help---
1655 If you have an Atari with built-in NCR5380 SCSI controller (TT, 1655 If you have an Atari with built-in NCR5380 SCSI controller (TT,
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 0f920c84ac0f..eff846ae0aff 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -1,19 +1,19 @@
1/* 1/*
2 * NCR 5380 generic driver routines. These should make it *trivial* 2 * NCR 5380 generic driver routines. These should make it *trivial*
3 * to implement 5380 SCSI drivers under Linux with a non-trantor 3 * to implement 5380 SCSI drivers under Linux with a non-trantor
4 * architecture. 4 * architecture.
5 * 5 *
6 * Note that these routines also work with NR53c400 family chips. 6 * Note that these routines also work with NR53c400 family chips.
7 * 7 *
8 * Copyright 1993, Drew Eckhardt 8 * Copyright 1993, Drew Eckhardt
9 * Visionary Computing 9 * Visionary Computing
10 * (Unix and Linux consulting and custom programming) 10 * (Unix and Linux consulting and custom programming)
11 * drew@colorado.edu 11 * drew@colorado.edu
12 * +1 (303) 666-5836 12 * +1 (303) 666-5836
13 * 13 *
14 * DISTRIBUTION RELEASE 6. 14 * DISTRIBUTION RELEASE 6.
15 * 15 *
16 * For more information, please consult 16 * For more information, please consult
17 * 17 *
18 * NCR 5380 Family 18 * NCR 5380 Family
19 * SCSI Protocol Controller 19 * SCSI Protocol Controller
@@ -57,7 +57,7 @@
57 * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA 57 * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA
58 * and USLEEP, because these were messing up readability and will never be 58 * and USLEEP, because these were messing up readability and will never be
59 * needed for Atari SCSI. 59 * needed for Atari SCSI.
60 * 60 *
61 * - I've revised the NCR5380_main() calling scheme (relax the 'main_running' 61 * - I've revised the NCR5380_main() calling scheme (relax the 'main_running'
62 * stuff), and 'main' is executed in a bottom half if awoken by an 62 * stuff), and 'main' is executed in a bottom half if awoken by an
63 * interrupt. 63 * interrupt.
@@ -69,21 +69,29 @@
69 */ 69 */
70 70
71/* 71/*
72 * Further development / testing that should be done : 72 * Further development / testing that should be done :
73 * 1. Test linked command handling code after Eric is ready with 73 * 1. Test linked command handling code after Eric is ready with
74 * the high level code. 74 * the high level code.
75 */ 75 */
76#include <scsi/scsi_dbg.h> 76#include <scsi/scsi_dbg.h>
77#include <scsi/scsi_transport_spi.h> 77#include <scsi/scsi_transport_spi.h>
78 78
79#if (NDEBUG & NDEBUG_LISTS) 79#if (NDEBUG & NDEBUG_LISTS)
80#define LIST(x,y) \ 80#define LIST(x, y) \
81 { printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); \ 81 do { \
82 if ((x)==(y)) udelay(5); } 82 printk("LINE:%d Adding %p to %p\n", \
83#define REMOVE(w,x,y,z) \ 83 __LINE__, (void*)(x), (void*)(y)); \
84 { printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, \ 84 if ((x) == (y)) \
85 (void*)(w), (void*)(x), (void*)(y), (void*)(z)); \ 85 udelay(5); \
86 if ((x)==(y)) udelay(5); } 86 } while (0)
87#define REMOVE(w, x, y, z) \
88 do { \
89 printk("LINE:%d Removing: %p->%p %p->%p \n", \
90 __LINE__, (void*)(w), (void*)(x), \
91 (void*)(y), (void*)(z)); \
92 if ((x) == (y)) \
93 udelay(5); \
94 } while (0)
87#else 95#else
88#define LIST(x,y) 96#define LIST(x,y)
89#define REMOVE(w,x,y,z) 97#define REMOVE(w,x,y,z)
@@ -103,62 +111,62 @@
103 * more difficult than it has to be. 111 * more difficult than it has to be.
104 * 112 *
105 * Also, many of the SCSI drivers were written before the command queuing 113 * Also, many of the SCSI drivers were written before the command queuing
106 * routines were implemented, meaning their implementations of queued 114 * routines were implemented, meaning their implementations of queued
107 * commands were hacked on rather than designed in from the start. 115 * commands were hacked on rather than designed in from the start.
108 * 116 *
109 * When I designed the Linux SCSI drivers I figured that 117 * When I designed the Linux SCSI drivers I figured that
110 * while having two different SCSI boards in a system might be useful 118 * while having two different SCSI boards in a system might be useful
111 * for debugging things, two of the same type wouldn't be used. 119 * for debugging things, two of the same type wouldn't be used.
112 * Well, I was wrong and a number of users have mailed me about running 120 * Well, I was wrong and a number of users have mailed me about running
113 * multiple high-performance SCSI boards in a server. 121 * multiple high-performance SCSI boards in a server.
114 * 122 *
115 * Finally, when I get questions from users, I have no idea what 123 * Finally, when I get questions from users, I have no idea what
116 * revision of my driver they are running. 124 * revision of my driver they are running.
117 * 125 *
118 * This driver attempts to address these problems : 126 * This driver attempts to address these problems :
119 * This is a generic 5380 driver. To use it on a different platform, 127 * This is a generic 5380 driver. To use it on a different platform,
120 * one simply writes appropriate system specific macros (ie, data 128 * one simply writes appropriate system specific macros (ie, data
121 * transfer - some PC's will use the I/O bus, 68K's must use 129 * transfer - some PC's will use the I/O bus, 68K's must use
122 * memory mapped) and drops this file in their 'C' wrapper. 130 * memory mapped) and drops this file in their 'C' wrapper.
123 * 131 *
124 * As far as command queueing, two queues are maintained for 132 * As far as command queueing, two queues are maintained for
125 * each 5380 in the system - commands that haven't been issued yet, 133 * each 5380 in the system - commands that haven't been issued yet,
126 * and commands that are currently executing. This means that an 134 * and commands that are currently executing. This means that an
127 * unlimited number of commands may be queued, letting 135 * unlimited number of commands may be queued, letting
128 * more commands propagate from the higher driver levels giving higher 136 * more commands propagate from the higher driver levels giving higher
129 * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported, 137 * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported,
130 * allowing multiple commands to propagate all the way to a SCSI-II device 138 * allowing multiple commands to propagate all the way to a SCSI-II device
131 * while a command is already executing. 139 * while a command is already executing.
132 * 140 *
133 * To solve the multiple-boards-in-the-same-system problem, 141 * To solve the multiple-boards-in-the-same-system problem,
134 * there is a separate instance structure for each instance 142 * there is a separate instance structure for each instance
135 * of a 5380 in the system. So, multiple NCR5380 drivers will 143 * of a 5380 in the system. So, multiple NCR5380 drivers will
136 * be able to coexist with appropriate changes to the high level 144 * be able to coexist with appropriate changes to the high level
137 * SCSI code. 145 * SCSI code.
138 * 146 *
139 * A NCR5380_PUBLIC_REVISION macro is provided, with the release 147 * A NCR5380_PUBLIC_REVISION macro is provided, with the release
140 * number (updated for each public release) printed by the 148 * number (updated for each public release) printed by the
141 * NCR5380_print_options command, which should be called from the 149 * NCR5380_print_options command, which should be called from the
142 * wrapper detect function, so that I know what release of the driver 150 * wrapper detect function, so that I know what release of the driver
143 * users are using. 151 * users are using.
144 * 152 *
145 * Issues specific to the NCR5380 : 153 * Issues specific to the NCR5380 :
146 * 154 *
147 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead 155 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead
148 * piece of hardware that requires you to sit in a loop polling for 156 * piece of hardware that requires you to sit in a loop polling for
149 * the REQ signal as long as you are connected. Some devices are 157 * the REQ signal as long as you are connected. Some devices are
150 * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect 158 * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect
151 * while doing long seek operations. 159 * while doing long seek operations.
152 * 160 *
153 * The workaround for this is to keep track of devices that have 161 * The workaround for this is to keep track of devices that have
154 * disconnected. If the device hasn't disconnected, for commands that 162 * disconnected. If the device hasn't disconnected, for commands that
155 * should disconnect, we do something like 163 * should disconnect, we do something like
156 * 164 *
157 * while (!REQ is asserted) { sleep for N usecs; poll for M usecs } 165 * while (!REQ is asserted) { sleep for N usecs; poll for M usecs }
158 * 166 *
159 * Some tweaking of N and M needs to be done. An algorithm based 167 * Some tweaking of N and M needs to be done. An algorithm based
160 * on "time to data" would give the best results as long as short time 168 * on "time to data" would give the best results as long as short time
161 * to datas (ie, on the same track) were considered, however these 169 * to datas (ie, on the same track) were considered, however these
162 * broken devices are the exception rather than the rule and I'd rather 170 * broken devices are the exception rather than the rule and I'd rather
163 * spend my time optimizing for the normal case. 171 * spend my time optimizing for the normal case.
164 * 172 *
@@ -167,9 +175,9 @@
167 * At the heart of the design is a coroutine, NCR5380_main, 175 * At the heart of the design is a coroutine, NCR5380_main,
168 * which is started when not running by the interrupt handler, 176 * which is started when not running by the interrupt handler,
169 * timer, and queue command function. It attempts to establish 177 * timer, and queue command function. It attempts to establish
170 * I_T_L or I_T_L_Q nexuses by removing the commands from the 178 * I_T_L or I_T_L_Q nexuses by removing the commands from the
171 * issue queue and calling NCR5380_select() if a nexus 179 * issue queue and calling NCR5380_select() if a nexus
172 * is not established. 180 * is not established.
173 * 181 *
174 * Once a nexus is established, the NCR5380_information_transfer() 182 * Once a nexus is established, the NCR5380_information_transfer()
175 * phase goes through the various phases as instructed by the target. 183 * phase goes through the various phases as instructed by the target.
@@ -183,10 +191,10 @@
183 * calling NCR5380_intr() which will in turn call NCR5380_reselect 191 * calling NCR5380_intr() which will in turn call NCR5380_reselect
184 * to reestablish a nexus. This will run main if necessary. 192 * to reestablish a nexus. This will run main if necessary.
185 * 193 *
186 * On command termination, the done function will be called as 194 * On command termination, the done function will be called as
187 * appropriate. 195 * appropriate.
188 * 196 *
189 * SCSI pointers are maintained in the SCp field of SCSI command 197 * SCSI pointers are maintained in the SCp field of SCSI command
190 * structures, being initialized after the command is connected 198 * structures, being initialized after the command is connected
191 * in NCR5380_select, and set as appropriate in NCR5380_information_transfer. 199 * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
192 * Note that in violation of the standard, an implicit SAVE POINTERS operation 200 * Note that in violation of the standard, an implicit SAVE POINTERS operation
@@ -196,12 +204,12 @@
196/* 204/*
197 * Using this file : 205 * Using this file :
198 * This file a skeleton Linux SCSI driver for the NCR 5380 series 206 * This file a skeleton Linux SCSI driver for the NCR 5380 series
199 * of chips. To use it, you write an architecture specific functions 207 * of chips. To use it, you write an architecture specific functions
200 * and macros and include this file in your driver. 208 * and macros and include this file in your driver.
201 * 209 *
202 * These macros control options : 210 * These macros control options :
203 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically 211 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
204 * for commands that return with a CHECK CONDITION status. 212 * for commands that return with a CHECK CONDITION status.
205 * 213 *
206 * LINKED - if defined, linked commands are supported. 214 * LINKED - if defined, linked commands are supported.
207 * 215 *
@@ -210,18 +218,18 @@
210 * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible 218 * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible
211 * 219 *
212 * These macros MUST be defined : 220 * These macros MUST be defined :
213 * 221 *
214 * NCR5380_read(register) - read from the specified register 222 * NCR5380_read(register) - read from the specified register
215 * 223 *
216 * NCR5380_write(register, value) - write to the specific register 224 * NCR5380_write(register, value) - write to the specific register
217 * 225 *
218 * Either real DMA *or* pseudo DMA may be implemented 226 * Either real DMA *or* pseudo DMA may be implemented
219 * REAL functions : 227 * REAL functions :
220 * NCR5380_REAL_DMA should be defined if real DMA is to be used. 228 * NCR5380_REAL_DMA should be defined if real DMA is to be used.
221 * Note that the DMA setup functions should return the number of bytes 229 * Note that the DMA setup functions should return the number of bytes
222 * that they were able to program the controller for. 230 * that they were able to program the controller for.
223 * 231 *
224 * Also note that generic i386/PC versions of these macros are 232 * Also note that generic i386/PC versions of these macros are
225 * available as NCR5380_i386_dma_write_setup, 233 * available as NCR5380_i386_dma_write_setup,
226 * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual. 234 * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual.
227 * 235 *
@@ -234,14 +242,14 @@
234 * NCR5380_pread(instance, dst, count); 242 * NCR5380_pread(instance, dst, count);
235 * 243 *
236 * If nothing specific to this implementation needs doing (ie, with external 244 * If nothing specific to this implementation needs doing (ie, with external
237 * hardware), you must also define 245 * hardware), you must also define
238 * 246 *
239 * NCR5380_queue_command 247 * NCR5380_queue_command
240 * NCR5380_reset 248 * NCR5380_reset
241 * NCR5380_abort 249 * NCR5380_abort
242 * NCR5380_proc_info 250 * NCR5380_proc_info
243 * 251 *
244 * to be the global entry points into the specific driver, ie 252 * to be the global entry points into the specific driver, ie
245 * #define NCR5380_queue_command t128_queue_command. 253 * #define NCR5380_queue_command t128_queue_command.
246 * 254 *
247 * If this is not done, the routines will be defined as static functions 255 * If this is not done, the routines will be defined as static functions
@@ -249,7 +257,7 @@
249 * accessible wrapper function. 257 * accessible wrapper function.
250 * 258 *
251 * The generic driver is initialized by calling NCR5380_init(instance), 259 * The generic driver is initialized by calling NCR5380_init(instance),
252 * after setting the appropriate host specific fields and ID. If the 260 * after setting the appropriate host specific fields and ID. If the
253 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance, 261 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
254 * possible) function may be used. Before the specific driver initialization 262 * possible) function may be used. Before the specific driver initialization
255 * code finishes, NCR5380_print_options should be called. 263 * code finishes, NCR5380_print_options should be called.
@@ -264,8 +272,9 @@ static struct scsi_host_template *the_template = NULL;
264 (struct NCR5380_hostdata *)(in)->hostdata 272 (struct NCR5380_hostdata *)(in)->hostdata
265#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata) 273#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
266 274
267#define NEXT(cmd) ((Scsi_Cmnd *)((cmd)->host_scribble)) 275#define NEXT(cmd) ((Scsi_Cmnd *)(cmd)->host_scribble)
268#define NEXTADDR(cmd) ((Scsi_Cmnd **)&((cmd)->host_scribble)) 276#define SET_NEXT(cmd,next) ((cmd)->host_scribble = (void *)(next))
277#define NEXTADDR(cmd) ((Scsi_Cmnd **)&(cmd)->host_scribble)
269 278
270#define HOSTNO instance->host_no 279#define HOSTNO instance->host_no
271#define H_NO(cmd) (cmd)->device->host->host_no 280#define H_NO(cmd) (cmd)->device->host->host_no
@@ -312,34 +321,34 @@ static struct scsi_host_template *the_template = NULL;
312#define TAG_NONE 0xff 321#define TAG_NONE 0xff
313 322
314typedef struct { 323typedef struct {
315 DECLARE_BITMAP(allocated, MAX_TAGS); 324 DECLARE_BITMAP(allocated, MAX_TAGS);
316 int nr_allocated; 325 int nr_allocated;
317 int queue_size; 326 int queue_size;
318} TAG_ALLOC; 327} TAG_ALLOC;
319 328
320static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */ 329static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */
321 330
322 331
323static void __init init_tags( void ) 332static void __init init_tags(void)
324{ 333{
325 int target, lun; 334 int target, lun;
326 TAG_ALLOC *ta; 335 TAG_ALLOC *ta;
327 336
328 if (!setup_use_tagged_queuing) 337 if (!setup_use_tagged_queuing)
329 return; 338 return;
330 339
331 for( target = 0; target < 8; ++target ) { 340 for (target = 0; target < 8; ++target) {
332 for( lun = 0; lun < 8; ++lun ) { 341 for (lun = 0; lun < 8; ++lun) {
333 ta = &TagAlloc[target][lun]; 342 ta = &TagAlloc[target][lun];
334 bitmap_zero(ta->allocated, MAX_TAGS); 343 bitmap_zero(ta->allocated, MAX_TAGS);
335 ta->nr_allocated = 0; 344 ta->nr_allocated = 0;
336 /* At the beginning, assume the maximum queue size we could 345 /* At the beginning, assume the maximum queue size we could
337 * support (MAX_TAGS). This value will be decreased if the target 346 * support (MAX_TAGS). This value will be decreased if the target
338 * returns QUEUE_FULL status. 347 * returns QUEUE_FULL status.
339 */ 348 */
340 ta->queue_size = MAX_TAGS; 349 ta->queue_size = MAX_TAGS;
350 }
341 } 351 }
342 }
343} 352}
344 353
345 354
@@ -348,24 +357,24 @@ static void __init init_tags( void )
348 * check that there is a free tag and the target's queue won't overflow. This 357 * check that there is a free tag and the target's queue won't overflow. This
349 * function should be called with interrupts disabled to avoid race 358 * function should be called with interrupts disabled to avoid race
350 * conditions. 359 * conditions.
351 */ 360 */
352 361
353static int is_lun_busy( Scsi_Cmnd *cmd, int should_be_tagged ) 362static int is_lun_busy(Scsi_Cmnd *cmd, int should_be_tagged)
354{ 363{
355 SETUP_HOSTDATA(cmd->device->host); 364 SETUP_HOSTDATA(cmd->device->host);
356 365
357 if (hostdata->busy[cmd->device->id] & (1 << cmd->device->lun)) 366 if (hostdata->busy[cmd->device->id] & (1 << cmd->device->lun))
358 return( 1 ); 367 return 1;
359 if (!should_be_tagged || 368 if (!should_be_tagged ||
360 !setup_use_tagged_queuing || !cmd->device->tagged_supported) 369 !setup_use_tagged_queuing || !cmd->device->tagged_supported)
361 return( 0 ); 370 return 0;
362 if (TagAlloc[cmd->device->id][cmd->device->lun].nr_allocated >= 371 if (TagAlloc[cmd->device->id][cmd->device->lun].nr_allocated >=
363 TagAlloc[cmd->device->id][cmd->device->lun].queue_size ) { 372 TagAlloc[cmd->device->id][cmd->device->lun].queue_size) {
364 TAG_PRINTK( "scsi%d: target %d lun %d: no free tags\n", 373 TAG_PRINTK("scsi%d: target %d lun %d: no free tags\n",
365 H_NO(cmd), cmd->device->id, cmd->device->lun ); 374 H_NO(cmd), cmd->device->id, cmd->device->lun);
366 return( 1 ); 375 return 1;
367 } 376 }
368 return( 0 ); 377 return 0;
369} 378}
370 379
371 380
@@ -374,31 +383,30 @@ static int is_lun_busy( Scsi_Cmnd *cmd, int should_be_tagged )
374 * untagged. 383 * untagged.
375 */ 384 */
376 385
377static void cmd_get_tag( Scsi_Cmnd *cmd, int should_be_tagged ) 386static void cmd_get_tag(Scsi_Cmnd *cmd, int should_be_tagged)
378{ 387{
379 SETUP_HOSTDATA(cmd->device->host); 388 SETUP_HOSTDATA(cmd->device->host);
380 389
381 /* If we or the target don't support tagged queuing, allocate the LUN for 390 /* If we or the target don't support tagged queuing, allocate the LUN for
382 * an untagged command. 391 * an untagged command.
383 */ 392 */
384 if (!should_be_tagged || 393 if (!should_be_tagged ||
385 !setup_use_tagged_queuing || !cmd->device->tagged_supported) { 394 !setup_use_tagged_queuing || !cmd->device->tagged_supported) {
386 cmd->tag = TAG_NONE; 395 cmd->tag = TAG_NONE;
387 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); 396 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
388 TAG_PRINTK( "scsi%d: target %d lun %d now allocated by untagged " 397 TAG_PRINTK("scsi%d: target %d lun %d now allocated by untagged "
389 "command\n", H_NO(cmd), cmd->device->id, cmd->device->lun ); 398 "command\n", H_NO(cmd), cmd->device->id, cmd->device->lun);
390 } 399 } else {
391 else { 400 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
392 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun]; 401
393 402 cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS);
394 cmd->tag = find_first_zero_bit( ta->allocated, MAX_TAGS ); 403 set_bit(cmd->tag, ta->allocated);
395 set_bit( cmd->tag, ta->allocated ); 404 ta->nr_allocated++;
396 ta->nr_allocated++; 405 TAG_PRINTK("scsi%d: using tag %d for target %d lun %d "
397 TAG_PRINTK( "scsi%d: using tag %d for target %d lun %d " 406 "(now %d tags in use)\n",
398 "(now %d tags in use)\n", 407 H_NO(cmd), cmd->tag, cmd->device->id,
399 H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun, 408 cmd->device->lun, ta->nr_allocated);
400 ta->nr_allocated ); 409 }
401 }
402} 410}
403 411
404 412
@@ -406,44 +414,42 @@ static void cmd_get_tag( Scsi_Cmnd *cmd, int should_be_tagged )
406 * unlock the LUN. 414 * unlock the LUN.
407 */ 415 */
408 416
409static void cmd_free_tag( Scsi_Cmnd *cmd ) 417static void cmd_free_tag(Scsi_Cmnd *cmd)
410{ 418{
411 SETUP_HOSTDATA(cmd->device->host); 419 SETUP_HOSTDATA(cmd->device->host);
412 420
413 if (cmd->tag == TAG_NONE) { 421 if (cmd->tag == TAG_NONE) {
414 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 422 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
415 TAG_PRINTK( "scsi%d: target %d lun %d untagged cmd finished\n", 423 TAG_PRINTK("scsi%d: target %d lun %d untagged cmd finished\n",
416 H_NO(cmd), cmd->device->id, cmd->device->lun ); 424 H_NO(cmd), cmd->device->id, cmd->device->lun);
417 } 425 } else if (cmd->tag >= MAX_TAGS) {
418 else if (cmd->tag >= MAX_TAGS) { 426 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n",
419 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n", 427 H_NO(cmd), cmd->tag);
420 H_NO(cmd), cmd->tag ); 428 } else {
421 } 429 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
422 else { 430 clear_bit(cmd->tag, ta->allocated);
423 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun]; 431 ta->nr_allocated--;
424 clear_bit( cmd->tag, ta->allocated ); 432 TAG_PRINTK("scsi%d: freed tag %d for target %d lun %d\n",
425 ta->nr_allocated--; 433 H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun);
426 TAG_PRINTK( "scsi%d: freed tag %d for target %d lun %d\n", 434 }
427 H_NO(cmd), cmd->tag, cmd->device->id, cmd->device->lun );
428 }
429} 435}
430 436
431 437
432static void free_all_tags( void ) 438static void free_all_tags(void)
433{ 439{
434 int target, lun; 440 int target, lun;
435 TAG_ALLOC *ta; 441 TAG_ALLOC *ta;
436 442
437 if (!setup_use_tagged_queuing) 443 if (!setup_use_tagged_queuing)
438 return; 444 return;
439 445
440 for( target = 0; target < 8; ++target ) { 446 for (target = 0; target < 8; ++target) {
441 for( lun = 0; lun < 8; ++lun ) { 447 for (lun = 0; lun < 8; ++lun) {
442 ta = &TagAlloc[target][lun]; 448 ta = &TagAlloc[target][lun];
443 bitmap_zero(ta->allocated, MAX_TAGS); 449 bitmap_zero(ta->allocated, MAX_TAGS);
444 ta->nr_allocated = 0; 450 ta->nr_allocated = 0;
451 }
445 } 452 }
446 }
447} 453}
448 454
449#endif /* SUPPORT_TAGS */ 455#endif /* SUPPORT_TAGS */
@@ -461,89 +467,94 @@ static void free_all_tags( void )
461 * assumed to be already transfered into ptr/this_residual. 467 * assumed to be already transfered into ptr/this_residual.
462 */ 468 */
463 469
464static void merge_contiguous_buffers( Scsi_Cmnd *cmd ) 470static void merge_contiguous_buffers(Scsi_Cmnd *cmd)
465{ 471{
466 unsigned long endaddr; 472 unsigned long endaddr;
467#if (NDEBUG & NDEBUG_MERGING) 473#if (NDEBUG & NDEBUG_MERGING)
468 unsigned long oldlen = cmd->SCp.this_residual; 474 unsigned long oldlen = cmd->SCp.this_residual;
469 int cnt = 1; 475 int cnt = 1;
470#endif 476#endif
471 477
472 for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1; 478 for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1;
473 cmd->SCp.buffers_residual && 479 cmd->SCp.buffers_residual &&
474 virt_to_phys(page_address(cmd->SCp.buffer[1].page)+ 480 virt_to_phys(page_address(cmd->SCp.buffer[1].page) +
475 cmd->SCp.buffer[1].offset) == endaddr; ) { 481 cmd->SCp.buffer[1].offset) == endaddr;) {
476 MER_PRINTK("VTOP(%p) == %08lx -> merging\n", 482 MER_PRINTK("VTOP(%p) == %08lx -> merging\n",
477 cmd->SCp.buffer[1].address, endaddr); 483 page_address(cmd->SCp.buffer[1].page), endaddr);
478#if (NDEBUG & NDEBUG_MERGING) 484#if (NDEBUG & NDEBUG_MERGING)
479 ++cnt; 485 ++cnt;
480#endif 486#endif
481 ++cmd->SCp.buffer; 487 ++cmd->SCp.buffer;
482 --cmd->SCp.buffers_residual; 488 --cmd->SCp.buffers_residual;
483 cmd->SCp.this_residual += cmd->SCp.buffer->length; 489 cmd->SCp.this_residual += cmd->SCp.buffer->length;
484 endaddr += cmd->SCp.buffer->length; 490 endaddr += cmd->SCp.buffer->length;
485 } 491 }
486#if (NDEBUG & NDEBUG_MERGING) 492#if (NDEBUG & NDEBUG_MERGING)
487 if (oldlen != cmd->SCp.this_residual) 493 if (oldlen != cmd->SCp.this_residual)
488 MER_PRINTK("merged %d buffers from %p, new length %08x\n", 494 MER_PRINTK("merged %d buffers from %p, new length %08x\n",
489 cnt, cmd->SCp.ptr, cmd->SCp.this_residual); 495 cnt, cmd->SCp.ptr, cmd->SCp.this_residual);
490#endif 496#endif
491} 497}
492 498
493/* 499/*
494 * Function : void initialize_SCp(Scsi_Cmnd *cmd) 500 * Function : void initialize_SCp(Scsi_Cmnd *cmd)
495 * 501 *
496 * Purpose : initialize the saved data pointers for cmd to point to the 502 * Purpose : initialize the saved data pointers for cmd to point to the
497 * start of the buffer. 503 * start of the buffer.
498 * 504 *
499 * Inputs : cmd - Scsi_Cmnd structure to have pointers reset. 505 * Inputs : cmd - Scsi_Cmnd structure to have pointers reset.
500 */ 506 */
501 507
502static __inline__ void initialize_SCp(Scsi_Cmnd *cmd) 508static inline void initialize_SCp(Scsi_Cmnd *cmd)
503{ 509{
504 /* 510 /*
505 * Initialize the Scsi Pointer field so that all of the commands in the 511 * Initialize the Scsi Pointer field so that all of the commands in the
506 * various queues are valid. 512 * various queues are valid.
507 */
508
509 if (cmd->use_sg) {
510 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
511 cmd->SCp.buffers_residual = cmd->use_sg - 1;
512 cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page)+
513 cmd->SCp.buffer->offset;
514 cmd->SCp.this_residual = cmd->SCp.buffer->length;
515 /* ++roman: Try to merge some scatter-buffers if they are at
516 * contiguous physical addresses.
517 */ 513 */
518 merge_contiguous_buffers( cmd ); 514
519 } else { 515 if (cmd->use_sg) {
520 cmd->SCp.buffer = NULL; 516 cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer;
521 cmd->SCp.buffers_residual = 0; 517 cmd->SCp.buffers_residual = cmd->use_sg - 1;
522 cmd->SCp.ptr = (char *) cmd->request_buffer; 518 cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page) +
523 cmd->SCp.this_residual = cmd->request_bufflen; 519 cmd->SCp.buffer->offset;
524 } 520 cmd->SCp.this_residual = cmd->SCp.buffer->length;
521 /* ++roman: Try to merge some scatter-buffers if they are at
522 * contiguous physical addresses.
523 */
524 merge_contiguous_buffers(cmd);
525 } else {
526 cmd->SCp.buffer = NULL;
527 cmd->SCp.buffers_residual = 0;
528 cmd->SCp.ptr = (char *)cmd->request_buffer;
529 cmd->SCp.this_residual = cmd->request_bufflen;
530 }
525} 531}
526 532
527#include <linux/delay.h> 533#include <linux/delay.h>
528 534
529#if NDEBUG 535#if NDEBUG
530static struct { 536static struct {
531 unsigned char mask; 537 unsigned char mask;
532 const char * name;} 538 const char *name;
533signals[] = {{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" }, 539} signals[] = {
534 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" }, 540 { SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
535 { SR_SEL, "SEL" }, {0, NULL}}, 541 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
536basrs[] = {{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}}, 542 { SR_SEL, "SEL" }, {0, NULL}
537icrs[] = {{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"}, 543}, basrs[] = {
538 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"}, 544 {BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}
539 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"}, 545}, icrs[] = {
540 {0, NULL}}, 546 {ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
541mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"}, 547 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
542 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR, 548 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
543 "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"}, 549 {0, NULL}
544 {MR_MONITOR_BSY, "MODE MONITOR BSY"}, 550}, mrs[] = {
545 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"}, 551 {MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
546 {0, NULL}}; 552 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
553 "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"},
554 {MR_MONITOR_BSY, "MODE MONITOR BSY"},
555 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
556 {0, NULL}
557};
547 558
548/* 559/*
549 * Function : void NCR5380_print(struct Scsi_Host *instance) 560 * Function : void NCR5380_print(struct Scsi_Host *instance)
@@ -553,45 +564,47 @@ mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
553 * Input : instance - which NCR5380 564 * Input : instance - which NCR5380
554 */ 565 */
555 566
556static void NCR5380_print(struct Scsi_Host *instance) { 567static void NCR5380_print(struct Scsi_Host *instance)
557 unsigned char status, data, basr, mr, icr, i; 568{
558 unsigned long flags; 569 unsigned char status, data, basr, mr, icr, i;
559 570 unsigned long flags;
560 local_irq_save(flags); 571
561 data = NCR5380_read(CURRENT_SCSI_DATA_REG); 572 local_irq_save(flags);
562 status = NCR5380_read(STATUS_REG); 573 data = NCR5380_read(CURRENT_SCSI_DATA_REG);
563 mr = NCR5380_read(MODE_REG); 574 status = NCR5380_read(STATUS_REG);
564 icr = NCR5380_read(INITIATOR_COMMAND_REG); 575 mr = NCR5380_read(MODE_REG);
565 basr = NCR5380_read(BUS_AND_STATUS_REG); 576 icr = NCR5380_read(INITIATOR_COMMAND_REG);
566 local_irq_restore(flags); 577 basr = NCR5380_read(BUS_AND_STATUS_REG);
567 printk("STATUS_REG: %02x ", status); 578 local_irq_restore(flags);
568 for (i = 0; signals[i].mask ; ++i) 579 printk("STATUS_REG: %02x ", status);
569 if (status & signals[i].mask) 580 for (i = 0; signals[i].mask; ++i)
570 printk(",%s", signals[i].name); 581 if (status & signals[i].mask)
571 printk("\nBASR: %02x ", basr); 582 printk(",%s", signals[i].name);
572 for (i = 0; basrs[i].mask ; ++i) 583 printk("\nBASR: %02x ", basr);
573 if (basr & basrs[i].mask) 584 for (i = 0; basrs[i].mask; ++i)
574 printk(",%s", basrs[i].name); 585 if (basr & basrs[i].mask)
575 printk("\nICR: %02x ", icr); 586 printk(",%s", basrs[i].name);
576 for (i = 0; icrs[i].mask; ++i) 587 printk("\nICR: %02x ", icr);
577 if (icr & icrs[i].mask) 588 for (i = 0; icrs[i].mask; ++i)
578 printk(",%s", icrs[i].name); 589 if (icr & icrs[i].mask)
579 printk("\nMODE: %02x ", mr); 590 printk(",%s", icrs[i].name);
580 for (i = 0; mrs[i].mask; ++i) 591 printk("\nMODE: %02x ", mr);
581 if (mr & mrs[i].mask) 592 for (i = 0; mrs[i].mask; ++i)
582 printk(",%s", mrs[i].name); 593 if (mr & mrs[i].mask)
583 printk("\n"); 594 printk(",%s", mrs[i].name);
595 printk("\n");
584} 596}
585 597
586static struct { 598static struct {
587 unsigned char value; 599 unsigned char value;
588 const char *name; 600 const char *name;
589} phases[] = { 601} phases[] = {
590 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"}, 602 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
591 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"}, 603 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
592 {PHASE_UNKNOWN, "UNKNOWN"}}; 604 {PHASE_UNKNOWN, "UNKNOWN"}
605};
593 606
594/* 607/*
595 * Function : void NCR5380_print_phase(struct Scsi_Host *instance) 608 * Function : void NCR5380_print_phase(struct Scsi_Host *instance)
596 * 609 *
597 * Purpose : print the current SCSI phase for debugging purposes 610 * Purpose : print the current SCSI phase for debugging purposes
@@ -601,30 +614,35 @@ static struct {
601 614
602static void NCR5380_print_phase(struct Scsi_Host *instance) 615static void NCR5380_print_phase(struct Scsi_Host *instance)
603{ 616{
604 unsigned char status; 617 unsigned char status;
605 int i; 618 int i;
606 619
607 status = NCR5380_read(STATUS_REG); 620 status = NCR5380_read(STATUS_REG);
608 if (!(status & SR_REQ)) 621 if (!(status & SR_REQ))
609 printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO); 622 printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO);
610 else { 623 else {
611 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && 624 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
612 (phases[i].value != (status & PHASE_MASK)); ++i); 625 (phases[i].value != (status & PHASE_MASK)); ++i)
613 printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name); 626 ;
614 } 627 printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name);
628 }
615} 629}
616 630
617#else /* !NDEBUG */ 631#else /* !NDEBUG */
618 632
619/* dummies... */ 633/* dummies... */
620__inline__ void NCR5380_print(struct Scsi_Host *instance) { }; 634static inline void NCR5380_print(struct Scsi_Host *instance)
621__inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { }; 635{
636};
637static inline void NCR5380_print_phase(struct Scsi_Host *instance)
638{
639};
622 640
623#endif 641#endif
624 642
625/* 643/*
626 * ++roman: New scheme of calling NCR5380_main() 644 * ++roman: New scheme of calling NCR5380_main()
627 * 645 *
628 * If we're not in an interrupt, we can call our main directly, it cannot be 646 * If we're not in an interrupt, we can call our main directly, it cannot be
629 * already running. Else, we queue it on a task queue, if not 'main_running' 647 * already running. Else, we queue it on a task queue, if not 'main_running'
630 * tells us that a lower level is already executing it. This way, 648 * tells us that a lower level is already executing it. This way,
@@ -638,33 +656,33 @@ __inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { };
638#include <linux/workqueue.h> 656#include <linux/workqueue.h>
639#include <linux/interrupt.h> 657#include <linux/interrupt.h>
640 658
641static volatile int main_running = 0; 659static volatile int main_running;
642static DECLARE_WORK(NCR5380_tqueue, (void (*)(void*))NCR5380_main, NULL); 660static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
643 661
644static __inline__ void queue_main(void) 662static inline void queue_main(void)
645{ 663{
646 if (!main_running) { 664 if (!main_running) {
647 /* If in interrupt and NCR5380_main() not already running, 665 /* If in interrupt and NCR5380_main() not already running,
648 queue it on the 'immediate' task queue, to be processed 666 queue it on the 'immediate' task queue, to be processed
649 immediately after the current interrupt processing has 667 immediately after the current interrupt processing has
650 finished. */ 668 finished. */
651 schedule_work(&NCR5380_tqueue); 669 schedule_work(&NCR5380_tqueue);
652 } 670 }
653 /* else: nothing to do: the running NCR5380_main() will pick up 671 /* else: nothing to do: the running NCR5380_main() will pick up
654 any newly queued command. */ 672 any newly queued command. */
655} 673}
656 674
657 675
658static inline void NCR5380_all_init (void) 676static inline void NCR5380_all_init(void)
659{ 677{
660 static int done = 0; 678 static int done = 0;
661 if (!done) { 679 if (!done) {
662 INI_PRINTK("scsi : NCR5380_all_init()\n"); 680 INI_PRINTK("scsi : NCR5380_all_init()\n");
663 done = 1; 681 done = 1;
664 } 682 }
665} 683}
666 684
667 685
668/* 686/*
669 * Function : void NCR58380_print_options (struct Scsi_Host *instance) 687 * Function : void NCR58380_print_options (struct Scsi_Host *instance)
670 * 688 *
@@ -674,23 +692,23 @@ static inline void NCR5380_all_init (void)
674 * Inputs : instance, pointer to this instance. Unused. 692 * Inputs : instance, pointer to this instance. Unused.
675 */ 693 */
676 694
677static void __init NCR5380_print_options (struct Scsi_Host *instance) 695static void __init NCR5380_print_options(struct Scsi_Host *instance)
678{ 696{
679 printk(" generic options" 697 printk(" generic options"
680#ifdef AUTOSENSE 698#ifdef AUTOSENSE
681 " AUTOSENSE" 699 " AUTOSENSE"
682#endif 700#endif
683#ifdef REAL_DMA 701#ifdef REAL_DMA
684 " REAL DMA" 702 " REAL DMA"
685#endif 703#endif
686#ifdef PARITY 704#ifdef PARITY
687 " PARITY" 705 " PARITY"
688#endif 706#endif
689#ifdef SUPPORT_TAGS 707#ifdef SUPPORT_TAGS
690 " SCSI-2 TAGGED QUEUING" 708 " SCSI-2 TAGGED QUEUING"
691#endif 709#endif
692 ); 710 );
693 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE); 711 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
694} 712}
695 713
696/* 714/*
@@ -699,27 +717,27 @@ static void __init NCR5380_print_options (struct Scsi_Host *instance)
699 * Purpose : print commands in the various queues, called from 717 * Purpose : print commands in the various queues, called from
700 * NCR5380_abort and NCR5380_debug to aid debugging. 718 * NCR5380_abort and NCR5380_debug to aid debugging.
701 * 719 *
702 * Inputs : instance, pointer to this instance. 720 * Inputs : instance, pointer to this instance.
703 */ 721 */
704 722
705static void NCR5380_print_status (struct Scsi_Host *instance) 723static void NCR5380_print_status(struct Scsi_Host *instance)
706{ 724{
707 char *pr_bfr; 725 char *pr_bfr;
708 char *start; 726 char *start;
709 int len; 727 int len;
710 728
711 NCR_PRINT(NDEBUG_ANY); 729 NCR_PRINT(NDEBUG_ANY);
712 NCR_PRINT_PHASE(NDEBUG_ANY); 730 NCR_PRINT_PHASE(NDEBUG_ANY);
713 731
714 pr_bfr = (char *) __get_free_page(GFP_ATOMIC); 732 pr_bfr = (char *)__get_free_page(GFP_ATOMIC);
715 if (!pr_bfr) { 733 if (!pr_bfr) {
716 printk("NCR5380_print_status: no memory for print buffer\n"); 734 printk("NCR5380_print_status: no memory for print buffer\n");
717 return; 735 return;
718 } 736 }
719 len = NCR5380_proc_info(pr_bfr, &start, 0, PAGE_SIZE, HOSTNO, 0); 737 len = NCR5380_proc_info(instance, pr_bfr, &start, 0, PAGE_SIZE, 0);
720 pr_bfr[len] = 0; 738 pr_bfr[len] = 0;
721 printk("\n%s\n", pr_bfr); 739 printk("\n%s\n", pr_bfr);
722 free_page((unsigned long) pr_bfr); 740 free_page((unsigned long)pr_bfr);
723} 741}
724 742
725 743
@@ -738,443 +756,478 @@ static void NCR5380_print_status (struct Scsi_Host *instance)
738*/ 756*/
739 757
740#undef SPRINTF 758#undef SPRINTF
741#define SPRINTF(fmt,args...) \ 759#define SPRINTF(fmt,args...) \
742 do { if (pos + strlen(fmt) + 20 /* slop */ < buffer + length) \ 760 do { \
743 pos += sprintf(pos, fmt , ## args); } while(0) 761 if (pos + strlen(fmt) + 20 /* slop */ < buffer + length) \
744static 762 pos += sprintf(pos, fmt , ## args); \
745char *lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length); 763 } while(0)
746 764static char *lprint_Scsi_Cmnd(Scsi_Cmnd *cmd, char *pos, char *buffer, int length);
747static 765
748int NCR5380_proc_info (struct Scsi_Host *instance, char *buffer, char **start, off_t offset, 766static int NCR5380_proc_info(struct Scsi_Host *instance, char *buffer,
749 int length, int inout) 767 char **start, off_t offset, int length, int inout)
750{ 768{
751 char *pos = buffer; 769 char *pos = buffer;
752 struct NCR5380_hostdata *hostdata; 770 struct NCR5380_hostdata *hostdata;
753 Scsi_Cmnd *ptr; 771 Scsi_Cmnd *ptr;
754 unsigned long flags; 772 unsigned long flags;
755 off_t begin = 0; 773 off_t begin = 0;
756#define check_offset() \ 774#define check_offset() \
757 do { \ 775 do { \
758 if (pos - buffer < offset - begin) { \ 776 if (pos - buffer < offset - begin) { \
759 begin += pos - buffer; \ 777 begin += pos - buffer; \
760 pos = buffer; \ 778 pos = buffer; \
761 } \ 779 } \
762 } while (0) 780 } while (0)
763 781
764 hostdata = (struct NCR5380_hostdata *)instance->hostdata; 782 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
765 783
766 if (inout) { /* Has data been written to the file ? */ 784 if (inout) /* Has data been written to the file ? */
767 return(-ENOSYS); /* Currently this is a no-op */ 785 return -ENOSYS; /* Currently this is a no-op */
768 } 786 SPRINTF("NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
769 SPRINTF("NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
770 check_offset();
771 local_irq_save(flags);
772 SPRINTF("NCR5380: coroutine is%s running.\n", main_running ? "" : "n't");
773 check_offset();
774 if (!hostdata->connected)
775 SPRINTF("scsi%d: no currently connected command\n", HOSTNO);
776 else
777 pos = lprint_Scsi_Cmnd ((Scsi_Cmnd *) hostdata->connected,
778 pos, buffer, length);
779 SPRINTF("scsi%d: issue_queue\n", HOSTNO);
780 check_offset();
781 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = NEXT(ptr)) {
782 pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
783 check_offset(); 787 check_offset();
784 } 788 local_irq_save(flags);
789 SPRINTF("NCR5380: coroutine is%s running.\n",
790 main_running ? "" : "n't");
791 check_offset();
792 if (!hostdata->connected)
793 SPRINTF("scsi%d: no currently connected command\n", HOSTNO);
794 else
795 pos = lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected,
796 pos, buffer, length);
797 SPRINTF("scsi%d: issue_queue\n", HOSTNO);
798 check_offset();
799 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) {
800 pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
801 check_offset();
802 }
785 803
786 SPRINTF("scsi%d: disconnected_queue\n", HOSTNO); 804 SPRINTF("scsi%d: disconnected_queue\n", HOSTNO);
787 check_offset();
788 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
789 ptr = NEXT(ptr)) {
790 pos = lprint_Scsi_Cmnd (ptr, pos, buffer, length);
791 check_offset(); 805 check_offset();
792 } 806 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
807 ptr = NEXT(ptr)) {
808 pos = lprint_Scsi_Cmnd(ptr, pos, buffer, length);
809 check_offset();
810 }
793 811
794 local_irq_restore(flags); 812 local_irq_restore(flags);
795 *start = buffer + (offset - begin); 813 *start = buffer + (offset - begin);
796 if (pos - buffer < offset - begin) 814 if (pos - buffer < offset - begin)
797 return 0; 815 return 0;
798 else if (pos - buffer - (offset - begin) < length) 816 else if (pos - buffer - (offset - begin) < length)
799 return pos - buffer - (offset - begin); 817 return pos - buffer - (offset - begin);
800 return length; 818 return length;
801} 819}
802 820
803static char * 821static char *lprint_Scsi_Cmnd(Scsi_Cmnd *cmd, char *pos, char *buffer, int length)
804lprint_Scsi_Cmnd (Scsi_Cmnd *cmd, char *pos, char *buffer, int length)
805{ 822{
806 int i, s; 823 int i, s;
807 unsigned char *command; 824 unsigned char *command;
808 SPRINTF("scsi%d: destination target %d, lun %d\n", 825 SPRINTF("scsi%d: destination target %d, lun %d\n",
809 H_NO(cmd), cmd->device->id, cmd->device->lun); 826 H_NO(cmd), cmd->device->id, cmd->device->lun);
810 SPRINTF(" command = "); 827 SPRINTF(" command = ");
811 command = cmd->cmnd; 828 command = cmd->cmnd;
812 SPRINTF("%2d (0x%02x)", command[0], command[0]); 829 SPRINTF("%2d (0x%02x)", command[0], command[0]);
813 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) 830 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
814 SPRINTF(" %02x", command[i]); 831 SPRINTF(" %02x", command[i]);
815 SPRINTF("\n"); 832 SPRINTF("\n");
816 return pos; 833 return pos;
817} 834}
818 835
819 836
820/* 837/*
821 * Function : void NCR5380_init (struct Scsi_Host *instance) 838 * Function : void NCR5380_init (struct Scsi_Host *instance)
822 * 839 *
823 * Purpose : initializes *instance and corresponding 5380 chip. 840 * Purpose : initializes *instance and corresponding 5380 chip.
824 * 841 *
825 * Inputs : instance - instantiation of the 5380 driver. 842 * Inputs : instance - instantiation of the 5380 driver.
826 * 843 *
827 * Notes : I assume that the host, hostno, and id bits have been 844 * Notes : I assume that the host, hostno, and id bits have been
828 * set correctly. I don't care about the irq and other fields. 845 * set correctly. I don't care about the irq and other fields.
829 * 846 *
830 */ 847 */
831 848
832static int NCR5380_init (struct Scsi_Host *instance, int flags) 849static int NCR5380_init(struct Scsi_Host *instance, int flags)
833{ 850{
834 int i; 851 int i;
835 SETUP_HOSTDATA(instance); 852 SETUP_HOSTDATA(instance);
836 853
837 NCR5380_all_init(); 854 NCR5380_all_init();
838 855
839 hostdata->aborted = 0; 856 hostdata->aborted = 0;
840 hostdata->id_mask = 1 << instance->this_id; 857 hostdata->id_mask = 1 << instance->this_id;
841 hostdata->id_higher_mask = 0; 858 hostdata->id_higher_mask = 0;
842 for (i = hostdata->id_mask; i <= 0x80; i <<= 1) 859 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
843 if (i > hostdata->id_mask) 860 if (i > hostdata->id_mask)
844 hostdata->id_higher_mask |= i; 861 hostdata->id_higher_mask |= i;
845 for (i = 0; i < 8; ++i) 862 for (i = 0; i < 8; ++i)
846 hostdata->busy[i] = 0; 863 hostdata->busy[i] = 0;
847#ifdef SUPPORT_TAGS 864#ifdef SUPPORT_TAGS
848 init_tags(); 865 init_tags();
849#endif 866#endif
850#if defined (REAL_DMA) 867#if defined (REAL_DMA)
851 hostdata->dma_len = 0; 868 hostdata->dma_len = 0;
852#endif 869#endif
853 hostdata->targets_present = 0; 870 hostdata->targets_present = 0;
854 hostdata->connected = NULL; 871 hostdata->connected = NULL;
855 hostdata->issue_queue = NULL; 872 hostdata->issue_queue = NULL;
856 hostdata->disconnected_queue = NULL; 873 hostdata->disconnected_queue = NULL;
857 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT; 874 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT;
858 875
859 if (!the_template) { 876 if (!the_template) {
860 the_template = instance->hostt; 877 the_template = instance->hostt;
861 first_instance = instance; 878 first_instance = instance;
862 } 879 }
863
864 880
865#ifndef AUTOSENSE 881#ifndef AUTOSENSE
866 if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1)) 882 if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1))
867 printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n" 883 printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n"
868 " without AUTOSENSE option, contingent allegiance conditions may\n" 884 " without AUTOSENSE option, contingent allegiance conditions may\n"
869 " be incorrectly cleared.\n", HOSTNO); 885 " be incorrectly cleared.\n", HOSTNO);
870#endif /* def AUTOSENSE */ 886#endif /* def AUTOSENSE */
871 887
872 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 888 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
873 NCR5380_write(MODE_REG, MR_BASE); 889 NCR5380_write(MODE_REG, MR_BASE);
874 NCR5380_write(TARGET_COMMAND_REG, 0); 890 NCR5380_write(TARGET_COMMAND_REG, 0);
875 NCR5380_write(SELECT_ENABLE_REG, 0); 891 NCR5380_write(SELECT_ENABLE_REG, 0);
876 892
877 return 0; 893 return 0;
878} 894}
879 895
880/* 896/*
881 * Function : int NCR5380_queue_command (Scsi_Cmnd *cmd, 897 * our own old-style timeout update
882 * void (*done)(Scsi_Cmnd *)) 898 */
899/*
900 * The strategy is to cause the timer code to call scsi_times_out()
901 * when the soonest timeout is pending.
902 * The arguments are used when we are queueing a new command, because
903 * we do not want to subtract the time used from this time, but when we
904 * set the timer, we want to take this value into account.
905 */
906
907int atari_scsi_update_timeout(Scsi_Cmnd * SCset, int timeout)
908{
909 int rtn;
910
911 /*
912 * We are using the new error handling code to actually register/deregister
913 * timers for timeout.
914 */
915
916 if (!timer_pending(&SCset->eh_timeout))
917 rtn = 0;
918 else
919 rtn = SCset->eh_timeout.expires - jiffies;
920
921 if (timeout == 0) {
922 del_timer(&SCset->eh_timeout);
923 SCset->eh_timeout.data = (unsigned long)NULL;
924 SCset->eh_timeout.expires = 0;
925 } else {
926 if (SCset->eh_timeout.data != (unsigned long)NULL)
927 del_timer(&SCset->eh_timeout);
928 SCset->eh_timeout.data = (unsigned long)SCset;
929 SCset->eh_timeout.expires = jiffies + timeout;
930 add_timer(&SCset->eh_timeout);
931 }
932 return rtn;
933}
934
935/*
936 * Function : int NCR5380_queue_command (Scsi_Cmnd *cmd,
937 * void (*done)(Scsi_Cmnd *))
883 * 938 *
884 * Purpose : enqueues a SCSI command 939 * Purpose : enqueues a SCSI command
885 * 940 *
886 * Inputs : cmd - SCSI command, done - function called on completion, with 941 * Inputs : cmd - SCSI command, done - function called on completion, with
887 * a pointer to the command descriptor. 942 * a pointer to the command descriptor.
888 * 943 *
889 * Returns : 0 944 * Returns : 0
890 * 945 *
891 * Side effects : 946 * Side effects :
892 * cmd is added to the per instance issue_queue, with minor 947 * cmd is added to the per instance issue_queue, with minor
893 * twiddling done to the host specific fields of cmd. If the 948 * twiddling done to the host specific fields of cmd. If the
894 * main coroutine is not running, it is restarted. 949 * main coroutine is not running, it is restarted.
895 * 950 *
896 */ 951 */
897 952
898static 953static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
899int NCR5380_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
900{ 954{
901 SETUP_HOSTDATA(cmd->device->host); 955 SETUP_HOSTDATA(cmd->device->host);
902 Scsi_Cmnd *tmp; 956 Scsi_Cmnd *tmp;
903 int oldto; 957 int oldto;
904 unsigned long flags; 958 unsigned long flags;
905 extern int update_timeout(Scsi_Cmnd * SCset, int timeout); 959 // extern int update_timeout(Scsi_Cmnd * SCset, int timeout);
906 960
907#if (NDEBUG & NDEBUG_NO_WRITE) 961#if (NDEBUG & NDEBUG_NO_WRITE)
908 switch (cmd->cmnd[0]) { 962 switch (cmd->cmnd[0]) {
909 case WRITE_6: 963 case WRITE_6:
910 case WRITE_10: 964 case WRITE_10:
911 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n", 965 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n",
912 H_NO(cmd)); 966 H_NO(cmd));
913 cmd->result = (DID_ERROR << 16); 967 cmd->result = (DID_ERROR << 16);
914 done(cmd); 968 done(cmd);
915 return 0; 969 return 0;
916 } 970 }
917#endif /* (NDEBUG & NDEBUG_NO_WRITE) */ 971#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
918 972
919
920#ifdef NCR5380_STATS 973#ifdef NCR5380_STATS
921# if 0 974# if 0
922 if (!hostdata->connected && !hostdata->issue_queue && 975 if (!hostdata->connected && !hostdata->issue_queue &&
923 !hostdata->disconnected_queue) { 976 !hostdata->disconnected_queue) {
924 hostdata->timebase = jiffies; 977 hostdata->timebase = jiffies;
925 } 978 }
926# endif 979# endif
927# ifdef NCR5380_STAT_LIMIT 980# ifdef NCR5380_STAT_LIMIT
928 if (cmd->request_bufflen > NCR5380_STAT_LIMIT) 981 if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
929# endif 982# endif
930 switch (cmd->cmnd[0]) 983 switch (cmd->cmnd[0]) {
931 { 984 case WRITE:
932 case WRITE: 985 case WRITE_6:
933 case WRITE_6: 986 case WRITE_10:
934 case WRITE_10: 987 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
935 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase); 988 hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen;
936 hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen; 989 hostdata->pendingw++;
937 hostdata->pendingw++; 990 break;
938 break; 991 case READ:
939 case READ: 992 case READ_6:
940 case READ_6: 993 case READ_10:
941 case READ_10: 994 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
942 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase); 995 hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen;
943 hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen; 996 hostdata->pendingr++;
944 hostdata->pendingr++; 997 break;
945 break; 998 }
946 }
947#endif 999#endif
948 1000
949 /* 1001 /*
950 * We use the host_scribble field as a pointer to the next command 1002 * We use the host_scribble field as a pointer to the next command
951 * in a queue 1003 * in a queue
952 */ 1004 */
953 1005
954 NEXT(cmd) = NULL; 1006 SET_NEXT(cmd, NULL);
955 cmd->scsi_done = done; 1007 cmd->scsi_done = done;
956 1008
957 cmd->result = 0; 1009 cmd->result = 0;
958 1010
959 1011 /*
960 /* 1012 * Insert the cmd into the issue queue. Note that REQUEST SENSE
961 * Insert the cmd into the issue queue. Note that REQUEST SENSE 1013 * commands are added to the head of the queue since any command will
962 * commands are added to the head of the queue since any command will 1014 * clear the contingent allegiance condition that exists and the
963 * clear the contingent allegiance condition that exists and the 1015 * sense data is only guaranteed to be valid while the condition exists.
964 * sense data is only guaranteed to be valid while the condition exists. 1016 */
965 */ 1017
966 1018 local_irq_save(flags);
967 local_irq_save(flags); 1019 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA.
968 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA. 1020 * Otherwise a running NCR5380_main may steal the lock.
969 * Otherwise a running NCR5380_main may steal the lock. 1021 * Lock before actually inserting due to fairness reasons explained in
970 * Lock before actually inserting due to fairness reasons explained in 1022 * atari_scsi.c. If we insert first, then it's impossible for this driver
971 * atari_scsi.c. If we insert first, then it's impossible for this driver 1023 * to release the lock.
972 * to release the lock. 1024 * Stop timer for this command while waiting for the lock, or timeouts
973 * Stop timer for this command while waiting for the lock, or timeouts 1025 * may happen (and they really do), and it's no good if the command doesn't
974 * may happen (and they really do), and it's no good if the command doesn't 1026 * appear in any of the queues.
975 * appear in any of the queues. 1027 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
976 * ++roman: Just disabling the NCR interrupt isn't sufficient here, 1028 * because also a timer int can trigger an abort or reset, which would
977 * because also a timer int can trigger an abort or reset, which would 1029 * alter queues and touch the lock.
978 * alter queues and touch the lock. 1030 */
979 */ 1031 if (!IS_A_TT()) {
980 if (!IS_A_TT()) { 1032 oldto = atari_scsi_update_timeout(cmd, 0);
981 oldto = update_timeout(cmd, 0); 1033 falcon_get_lock();
982 falcon_get_lock(); 1034 atari_scsi_update_timeout(cmd, oldto);
983 update_timeout(cmd, oldto); 1035 }
984 } 1036 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
985 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) { 1037 LIST(cmd, hostdata->issue_queue);
986 LIST(cmd, hostdata->issue_queue); 1038 SET_NEXT(cmd, hostdata->issue_queue);
987 NEXT(cmd) = hostdata->issue_queue; 1039 hostdata->issue_queue = cmd;
988 hostdata->issue_queue = cmd; 1040 } else {
989 } else { 1041 for (tmp = (Scsi_Cmnd *)hostdata->issue_queue;
990 for (tmp = (Scsi_Cmnd *)hostdata->issue_queue; 1042 NEXT(tmp); tmp = NEXT(tmp))
991 NEXT(tmp); tmp = NEXT(tmp)) 1043 ;
992 ; 1044 LIST(cmd, tmp);
993 LIST(cmd, tmp); 1045 SET_NEXT(tmp, cmd);
994 NEXT(tmp) = cmd; 1046 }
995 } 1047 local_irq_restore(flags);
996 local_irq_restore(flags); 1048
997 1049 QU_PRINTK("scsi%d: command added to %s of queue\n", H_NO(cmd),
998 QU_PRINTK("scsi%d: command added to %s of queue\n", H_NO(cmd), 1050 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
999 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"); 1051
1000 1052 /* If queue_command() is called from an interrupt (real one or bottom
1001 /* If queue_command() is called from an interrupt (real one or bottom 1053 * half), we let queue_main() do the job of taking care about main. If it
1002 * half), we let queue_main() do the job of taking care about main. If it 1054 * is already running, this is a no-op, else main will be queued.
1003 * is already running, this is a no-op, else main will be queued. 1055 *
1004 * 1056 * If we're not in an interrupt, we can call NCR5380_main()
1005 * If we're not in an interrupt, we can call NCR5380_main() 1057 * unconditionally, because it cannot be already running.
1006 * unconditionally, because it cannot be already running. 1058 */
1007 */ 1059 if (in_interrupt() || ((flags >> 8) & 7) >= 6)
1008 if (in_interrupt() || ((flags >> 8) & 7) >= 6) 1060 queue_main();
1009 queue_main(); 1061 else
1010 else 1062 NCR5380_main(NULL);
1011 NCR5380_main(NULL); 1063 return 0;
1012 return 0;
1013} 1064}
1014 1065
1015/* 1066/*
1016 * Function : NCR5380_main (void) 1067 * Function : NCR5380_main (void)
1017 * 1068 *
1018 * Purpose : NCR5380_main is a coroutine that runs as long as more work can 1069 * Purpose : NCR5380_main is a coroutine that runs as long as more work can
1019 * be done on the NCR5380 host adapters in a system. Both 1070 * be done on the NCR5380 host adapters in a system. Both
1020 * NCR5380_queue_command() and NCR5380_intr() will try to start it 1071 * NCR5380_queue_command() and NCR5380_intr() will try to start it
1021 * in case it is not running. 1072 * in case it is not running.
1022 * 1073 *
1023 * NOTE : NCR5380_main exits with interrupts *disabled*, the caller should 1074 * NOTE : NCR5380_main exits with interrupts *disabled*, the caller should
1024 * reenable them. This prevents reentrancy and kernel stack overflow. 1075 * reenable them. This prevents reentrancy and kernel stack overflow.
1025 */ 1076 */
1026 1077
1027static void NCR5380_main (void *bl) 1078static void NCR5380_main(struct work_struct *work)
1028{ 1079{
1029 Scsi_Cmnd *tmp, *prev; 1080 Scsi_Cmnd *tmp, *prev;
1030 struct Scsi_Host *instance = first_instance; 1081 struct Scsi_Host *instance = first_instance;
1031 struct NCR5380_hostdata *hostdata = HOSTDATA(instance); 1082 struct NCR5380_hostdata *hostdata = HOSTDATA(instance);
1032 int done; 1083 int done;
1033 unsigned long flags; 1084 unsigned long flags;
1034 1085
1035 /* 1086 /*
1036 * We run (with interrupts disabled) until we're sure that none of 1087 * We run (with interrupts disabled) until we're sure that none of
1037 * the host adapters have anything that can be done, at which point 1088 * the host adapters have anything that can be done, at which point
1038 * we set main_running to 0 and exit. 1089 * we set main_running to 0 and exit.
1039 * 1090 *
1040 * Interrupts are enabled before doing various other internal 1091 * Interrupts are enabled before doing various other internal
1041 * instructions, after we've decided that we need to run through 1092 * instructions, after we've decided that we need to run through
1042 * the loop again. 1093 * the loop again.
1043 * 1094 *
1044 * this should prevent any race conditions. 1095 * this should prevent any race conditions.
1045 * 1096 *
1046 * ++roman: Just disabling the NCR interrupt isn't sufficient here, 1097 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
1047 * because also a timer int can trigger an abort or reset, which can 1098 * because also a timer int can trigger an abort or reset, which can
1048 * alter queues and touch the Falcon lock. 1099 * alter queues and touch the Falcon lock.
1049 */ 1100 */
1050 1101
1051 /* Tell int handlers main() is now already executing. Note that 1102 /* Tell int handlers main() is now already executing. Note that
1052 no races are possible here. If an int comes in before 1103 no races are possible here. If an int comes in before
1053 'main_running' is set here, and queues/executes main via the 1104 'main_running' is set here, and queues/executes main via the
1054 task queue, it doesn't do any harm, just this instance of main 1105 task queue, it doesn't do any harm, just this instance of main
1055 won't find any work left to do. */ 1106 won't find any work left to do. */
1056 if (main_running) 1107 if (main_running)
1057 return; 1108 return;
1058 main_running = 1; 1109 main_running = 1;
1059 1110
1060 local_save_flags(flags); 1111 local_save_flags(flags);
1061 do { 1112 do {
1062 local_irq_disable(); /* Freeze request queues */ 1113 local_irq_disable(); /* Freeze request queues */
1063 done = 1; 1114 done = 1;
1064 1115
1065 if (!hostdata->connected) { 1116 if (!hostdata->connected) {
1066 MAIN_PRINTK( "scsi%d: not connected\n", HOSTNO ); 1117 MAIN_PRINTK("scsi%d: not connected\n", HOSTNO);
1067 /* 1118 /*
1068 * Search through the issue_queue for a command destined 1119 * Search through the issue_queue for a command destined
1069 * for a target that's not busy. 1120 * for a target that's not busy.
1070 */ 1121 */
1071#if (NDEBUG & NDEBUG_LISTS) 1122#if (NDEBUG & NDEBUG_LISTS)
1072 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL; 1123 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL;
1073 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp)) 1124 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp))
1074 ; 1125 ;
1075 /*printk("%p ", tmp);*/ 1126 /*printk("%p ", tmp);*/
1076 if ((tmp == prev) && tmp) printk(" LOOP\n");/* else printk("\n");*/ 1127 if ((tmp == prev) && tmp)
1128 printk(" LOOP\n");
1129 /* else printk("\n"); */
1077#endif 1130#endif
1078 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, 1131 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue,
1079 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp) ) { 1132 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) {
1080 1133
1081#if (NDEBUG & NDEBUG_LISTS) 1134#if (NDEBUG & NDEBUG_LISTS)
1082 if (prev != tmp) 1135 if (prev != tmp)
1083 printk("MAIN tmp=%p target=%d busy=%d lun=%d\n", 1136 printk("MAIN tmp=%p target=%d busy=%d lun=%d\n",
1084 tmp, tmp->device->id, hostdata->busy[tmp->device->id], 1137 tmp, tmp->device->id, hostdata->busy[tmp->device->id],
1085 tmp->device->lun); 1138 tmp->device->lun);
1086#endif 1139#endif
1087 /* When we find one, remove it from the issue queue. */ 1140 /* When we find one, remove it from the issue queue. */
1088 /* ++guenther: possible race with Falcon locking */ 1141 /* ++guenther: possible race with Falcon locking */
1089 if ( 1142 if (
1090#ifdef SUPPORT_TAGS 1143#ifdef SUPPORT_TAGS
1091 !is_lun_busy( tmp, tmp->cmnd[0] != REQUEST_SENSE) 1144 !is_lun_busy( tmp, tmp->cmnd[0] != REQUEST_SENSE)
1092#else 1145#else
1093 !(hostdata->busy[tmp->device->id] & (1 << tmp->device->lun)) 1146 !(hostdata->busy[tmp->device->id] & (1 << tmp->device->lun))
1094#endif 1147#endif
1095 ) { 1148 ) {
1096 /* ++guenther: just to be sure, this must be atomic */ 1149 /* ++guenther: just to be sure, this must be atomic */
1097 local_irq_disable(); 1150 local_irq_disable();
1098 if (prev) { 1151 if (prev) {
1099 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp)); 1152 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
1100 NEXT(prev) = NEXT(tmp); 1153 SET_NEXT(prev, NEXT(tmp));
1101 } else { 1154 } else {
1102 REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp)); 1155 REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp));
1103 hostdata->issue_queue = NEXT(tmp); 1156 hostdata->issue_queue = NEXT(tmp);
1104 } 1157 }
1105 NEXT(tmp) = NULL; 1158 SET_NEXT(tmp, NULL);
1106 falcon_dont_release++; 1159 falcon_dont_release++;
1107 1160
1108 /* reenable interrupts after finding one */ 1161 /* reenable interrupts after finding one */
1109 local_irq_restore(flags); 1162 local_irq_restore(flags);
1110 1163
1111 /* 1164 /*
1112 * Attempt to establish an I_T_L nexus here. 1165 * Attempt to establish an I_T_L nexus here.
1113 * On success, instance->hostdata->connected is set. 1166 * On success, instance->hostdata->connected is set.
1114 * On failure, we must add the command back to the 1167 * On failure, we must add the command back to the
1115 * issue queue so we can keep trying. 1168 * issue queue so we can keep trying.
1116 */ 1169 */
1117 MAIN_PRINTK("scsi%d: main(): command for target %d " 1170 MAIN_PRINTK("scsi%d: main(): command for target %d "
1118 "lun %d removed from issue_queue\n", 1171 "lun %d removed from issue_queue\n",
1119 HOSTNO, tmp->device->id, tmp->device->lun); 1172 HOSTNO, tmp->device->id, tmp->device->lun);
1120 /* 1173 /*
1121 * REQUEST SENSE commands are issued without tagged 1174 * REQUEST SENSE commands are issued without tagged
1122 * queueing, even on SCSI-II devices because the 1175 * queueing, even on SCSI-II devices because the
1123 * contingent allegiance condition exists for the 1176 * contingent allegiance condition exists for the
1124 * entire unit. 1177 * entire unit.
1125 */ 1178 */
1126 /* ++roman: ...and the standard also requires that 1179 /* ++roman: ...and the standard also requires that
1127 * REQUEST SENSE command are untagged. 1180 * REQUEST SENSE command are untagged.
1128 */ 1181 */
1129 1182
1130#ifdef SUPPORT_TAGS 1183#ifdef SUPPORT_TAGS
1131 cmd_get_tag( tmp, tmp->cmnd[0] != REQUEST_SENSE ); 1184 cmd_get_tag(tmp, tmp->cmnd[0] != REQUEST_SENSE);
1132#endif 1185#endif
1133 if (!NCR5380_select(instance, tmp, 1186 if (!NCR5380_select(instance, tmp,
1134 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE : 1187 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
1135 TAG_NEXT)) { 1188 TAG_NEXT)) {
1136 falcon_dont_release--; 1189 falcon_dont_release--;
1137 /* release if target did not response! */ 1190 /* release if target did not response! */
1138 falcon_release_lock_if_possible( hostdata ); 1191 falcon_release_lock_if_possible(hostdata);
1139 break; 1192 break;
1140 } else { 1193 } else {
1141 local_irq_disable(); 1194 local_irq_disable();
1142 LIST(tmp, hostdata->issue_queue); 1195 LIST(tmp, hostdata->issue_queue);
1143 NEXT(tmp) = hostdata->issue_queue; 1196 SET_NEXT(tmp, hostdata->issue_queue);
1144 hostdata->issue_queue = tmp; 1197 hostdata->issue_queue = tmp;
1145#ifdef SUPPORT_TAGS 1198#ifdef SUPPORT_TAGS
1146 cmd_free_tag( tmp ); 1199 cmd_free_tag(tmp);
1147#endif 1200#endif
1148 falcon_dont_release--; 1201 falcon_dont_release--;
1149 local_irq_restore(flags); 1202 local_irq_restore(flags);
1150 MAIN_PRINTK("scsi%d: main(): select() failed, " 1203 MAIN_PRINTK("scsi%d: main(): select() failed, "
1151 "returned to issue_queue\n", HOSTNO); 1204 "returned to issue_queue\n", HOSTNO);
1152 if (hostdata->connected) 1205 if (hostdata->connected)
1153 break; 1206 break;
1154 } 1207 }
1155 } /* if target/lun/target queue is not busy */ 1208 } /* if target/lun/target queue is not busy */
1156 } /* for issue_queue */ 1209 } /* for issue_queue */
1157 } /* if (!hostdata->connected) */ 1210 } /* if (!hostdata->connected) */
1158 1211
1159 if (hostdata->connected 1212 if (hostdata->connected
1160#ifdef REAL_DMA 1213#ifdef REAL_DMA
1161 && !hostdata->dma_len 1214 && !hostdata->dma_len
1162#endif 1215#endif
1163 ) { 1216 ) {
1164 local_irq_restore(flags); 1217 local_irq_restore(flags);
1165 MAIN_PRINTK("scsi%d: main: performing information transfer\n", 1218 MAIN_PRINTK("scsi%d: main: performing information transfer\n",
1166 HOSTNO); 1219 HOSTNO);
1167 NCR5380_information_transfer(instance); 1220 NCR5380_information_transfer(instance);
1168 MAIN_PRINTK("scsi%d: main: done set false\n", HOSTNO); 1221 MAIN_PRINTK("scsi%d: main: done set false\n", HOSTNO);
1169 done = 0; 1222 done = 0;
1170 } 1223 }
1171 } while (!done); 1224 } while (!done);
1172 1225
1173 /* Better allow ints _after_ 'main_running' has been cleared, else 1226 /* Better allow ints _after_ 'main_running' has been cleared, else
1174 an interrupt could believe we'll pick up the work it left for 1227 an interrupt could believe we'll pick up the work it left for
1175 us, but we won't see it anymore here... */ 1228 us, but we won't see it anymore here... */
1176 main_running = 0; 1229 main_running = 0;
1177 local_irq_restore(flags); 1230 local_irq_restore(flags);
1178} 1231}
1179 1232
1180 1233
@@ -1183,1441 +1236,1439 @@ static void NCR5380_main (void *bl)
1183 * Function : void NCR5380_dma_complete (struct Scsi_Host *instance) 1236 * Function : void NCR5380_dma_complete (struct Scsi_Host *instance)
1184 * 1237 *
1185 * Purpose : Called by interrupt handler when DMA finishes or a phase 1238 * Purpose : Called by interrupt handler when DMA finishes or a phase
1186 * mismatch occurs (which would finish the DMA transfer). 1239 * mismatch occurs (which would finish the DMA transfer).
1187 * 1240 *
1188 * Inputs : instance - this instance of the NCR5380. 1241 * Inputs : instance - this instance of the NCR5380.
1189 * 1242 *
1190 */ 1243 */
1191 1244
1192static void NCR5380_dma_complete( struct Scsi_Host *instance ) 1245static void NCR5380_dma_complete(struct Scsi_Host *instance)
1193{ 1246{
1194 SETUP_HOSTDATA(instance); 1247 SETUP_HOSTDATA(instance);
1195 int transfered, saved_data = 0, overrun = 0, cnt, toPIO; 1248 int transfered, saved_data = 0, overrun = 0, cnt, toPIO;
1196 unsigned char **data, p; 1249 unsigned char **data, p;
1197 volatile int *count; 1250 volatile int *count;
1198 1251
1199 if (!hostdata->connected) { 1252 if (!hostdata->connected) {
1200 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with " 1253 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with "
1201 "no connected cmd\n", HOSTNO); 1254 "no connected cmd\n", HOSTNO);
1202 return; 1255 return;
1203 }
1204
1205 if (atari_read_overruns) {
1206 p = hostdata->connected->SCp.phase;
1207 if (p & SR_IO) {
1208 udelay(10);
1209 if ((((NCR5380_read(BUS_AND_STATUS_REG)) &
1210 (BASR_PHASE_MATCH|BASR_ACK)) ==
1211 (BASR_PHASE_MATCH|BASR_ACK))) {
1212 saved_data = NCR5380_read(INPUT_DATA_REG);
1213 overrun = 1;
1214 DMA_PRINTK("scsi%d: read overrun handled\n", HOSTNO);
1215 }
1216 } 1256 }
1217 } 1257
1218 1258 if (atari_read_overruns) {
1219 DMA_PRINTK("scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n", 1259 p = hostdata->connected->SCp.phase;
1220 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG), 1260 if (p & SR_IO) {
1221 NCR5380_read(STATUS_REG)); 1261 udelay(10);
1222 1262 if ((NCR5380_read(BUS_AND_STATUS_REG) &
1223 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1263 (BASR_PHASE_MATCH|BASR_ACK)) ==
1224 NCR5380_write(MODE_REG, MR_BASE); 1264 (BASR_PHASE_MATCH|BASR_ACK)) {
1225 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1265 saved_data = NCR5380_read(INPUT_DATA_REG);
1226 1266 overrun = 1;
1227 transfered = hostdata->dma_len - NCR5380_dma_residual(instance); 1267 DMA_PRINTK("scsi%d: read overrun handled\n", HOSTNO);
1228 hostdata->dma_len = 0; 1268 }
1229 1269 }
1230 data = (unsigned char **) &(hostdata->connected->SCp.ptr); 1270 }
1231 count = &(hostdata->connected->SCp.this_residual); 1271
1232 *data += transfered; 1272 DMA_PRINTK("scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n",
1233 *count -= transfered; 1273 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
1234 1274 NCR5380_read(STATUS_REG));
1235 if (atari_read_overruns) { 1275
1236 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) { 1276 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1237 cnt = toPIO = atari_read_overruns; 1277 NCR5380_write(MODE_REG, MR_BASE);
1238 if (overrun) { 1278 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1239 DMA_PRINTK("Got an input overrun, using saved byte\n"); 1279
1240 *(*data)++ = saved_data; 1280 transfered = hostdata->dma_len - NCR5380_dma_residual(instance);
1241 (*count)--; 1281 hostdata->dma_len = 0;
1242 cnt--; 1282
1243 toPIO--; 1283 data = (unsigned char **)&hostdata->connected->SCp.ptr;
1244 } 1284 count = &hostdata->connected->SCp.this_residual;
1245 DMA_PRINTK("Doing %d-byte PIO to 0x%08lx\n", cnt, (long)*data); 1285 *data += transfered;
1246 NCR5380_transfer_pio(instance, &p, &cnt, data); 1286 *count -= transfered;
1247 *count -= toPIO - cnt; 1287
1288 if (atari_read_overruns) {
1289 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) {
1290 cnt = toPIO = atari_read_overruns;
1291 if (overrun) {
1292 DMA_PRINTK("Got an input overrun, using saved byte\n");
1293 *(*data)++ = saved_data;
1294 (*count)--;
1295 cnt--;
1296 toPIO--;
1297 }
1298 DMA_PRINTK("Doing %d-byte PIO to 0x%08lx\n", cnt, (long)*data);
1299 NCR5380_transfer_pio(instance, &p, &cnt, data);
1300 *count -= toPIO - cnt;
1301 }
1248 } 1302 }
1249 }
1250} 1303}
1251#endif /* REAL_DMA */ 1304#endif /* REAL_DMA */
1252 1305
1253 1306
1254/* 1307/*
1255 * Function : void NCR5380_intr (int irq) 1308 * Function : void NCR5380_intr (int irq)
1256 * 1309 *
1257 * Purpose : handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses 1310 * Purpose : handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses
1258 * from the disconnected queue, and restarting NCR5380_main() 1311 * from the disconnected queue, and restarting NCR5380_main()
1259 * as required. 1312 * as required.
1260 * 1313 *
1261 * Inputs : int irq, irq that caused this interrupt. 1314 * Inputs : int irq, irq that caused this interrupt.
1262 * 1315 *
1263 */ 1316 */
1264 1317
1265static irqreturn_t NCR5380_intr (int irq, void *dev_id) 1318static irqreturn_t NCR5380_intr(int irq, void *dev_id)
1266{ 1319{
1267 struct Scsi_Host *instance = first_instance; 1320 struct Scsi_Host *instance = first_instance;
1268 int done = 1, handled = 0; 1321 int done = 1, handled = 0;
1269 unsigned char basr; 1322 unsigned char basr;
1270 1323
1271 INT_PRINTK("scsi%d: NCR5380 irq triggered\n", HOSTNO); 1324 INT_PRINTK("scsi%d: NCR5380 irq triggered\n", HOSTNO);
1272 1325
1273 /* Look for pending interrupts */ 1326 /* Look for pending interrupts */
1274 basr = NCR5380_read(BUS_AND_STATUS_REG); 1327 basr = NCR5380_read(BUS_AND_STATUS_REG);
1275 INT_PRINTK("scsi%d: BASR=%02x\n", HOSTNO, basr); 1328 INT_PRINTK("scsi%d: BASR=%02x\n", HOSTNO, basr);
1276 /* dispatch to appropriate routine if found and done=0 */ 1329 /* dispatch to appropriate routine if found and done=0 */
1277 if (basr & BASR_IRQ) { 1330 if (basr & BASR_IRQ) {
1278 NCR_PRINT(NDEBUG_INTR); 1331 NCR_PRINT(NDEBUG_INTR);
1279 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) { 1332 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
1280 done = 0; 1333 done = 0;
1281 ENABLE_IRQ(); 1334 ENABLE_IRQ();
1282 INT_PRINTK("scsi%d: SEL interrupt\n", HOSTNO); 1335 INT_PRINTK("scsi%d: SEL interrupt\n", HOSTNO);
1283 NCR5380_reselect(instance); 1336 NCR5380_reselect(instance);
1284 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1337 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1285 } 1338 } else if (basr & BASR_PARITY_ERROR) {
1286 else if (basr & BASR_PARITY_ERROR) { 1339 INT_PRINTK("scsi%d: PARITY interrupt\n", HOSTNO);
1287 INT_PRINTK("scsi%d: PARITY interrupt\n", HOSTNO); 1340 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1288 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1341 } else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
1289 } 1342 INT_PRINTK("scsi%d: RESET interrupt\n", HOSTNO);
1290 else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) { 1343 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1291 INT_PRINTK("scsi%d: RESET interrupt\n", HOSTNO); 1344 } else {
1292 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1345 /*
1293 } 1346 * The rest of the interrupt conditions can occur only during a
1294 else { 1347 * DMA transfer
1295 /* 1348 */
1296 * The rest of the interrupt conditions can occur only during a
1297 * DMA transfer
1298 */
1299 1349
1300#if defined(REAL_DMA) 1350#if defined(REAL_DMA)
1301 /* 1351 /*
1302 * We should only get PHASE MISMATCH and EOP interrupts if we have 1352 * We should only get PHASE MISMATCH and EOP interrupts if we have
1303 * DMA enabled, so do a sanity check based on the current setting 1353 * DMA enabled, so do a sanity check based on the current setting
1304 * of the MODE register. 1354 * of the MODE register.
1305 */ 1355 */
1306 1356
1307 if ((NCR5380_read(MODE_REG) & MR_DMA_MODE) && 1357 if ((NCR5380_read(MODE_REG) & MR_DMA_MODE) &&
1308 ((basr & BASR_END_DMA_TRANSFER) || 1358 ((basr & BASR_END_DMA_TRANSFER) ||
1309 !(basr & BASR_PHASE_MATCH))) { 1359 !(basr & BASR_PHASE_MATCH))) {
1310 1360
1311 INT_PRINTK("scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO); 1361 INT_PRINTK("scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO);
1312 NCR5380_dma_complete( instance ); 1362 NCR5380_dma_complete( instance );
1313 done = 0; 1363 done = 0;
1314 ENABLE_IRQ(); 1364 ENABLE_IRQ();
1315 } else 1365 } else
1316#endif /* REAL_DMA */ 1366#endif /* REAL_DMA */
1317 { 1367 {
1318/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */ 1368/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */
1319 if (basr & BASR_PHASE_MATCH) 1369 if (basr & BASR_PHASE_MATCH)
1320 printk(KERN_NOTICE "scsi%d: unknown interrupt, " 1370 printk(KERN_NOTICE "scsi%d: unknown interrupt, "
1321 "BASR 0x%x, MR 0x%x, SR 0x%x\n", 1371 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1322 HOSTNO, basr, NCR5380_read(MODE_REG), 1372 HOSTNO, basr, NCR5380_read(MODE_REG),
1323 NCR5380_read(STATUS_REG)); 1373 NCR5380_read(STATUS_REG));
1324 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1374 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1325 } 1375 }
1326 } /* if !(SELECTION || PARITY) */ 1376 } /* if !(SELECTION || PARITY) */
1327 handled = 1; 1377 handled = 1;
1328 } /* BASR & IRQ */ 1378 } /* BASR & IRQ */ else {
1329 else { 1379 printk(KERN_NOTICE "scsi%d: interrupt without IRQ bit set in BASR, "
1330 printk(KERN_NOTICE "scsi%d: interrupt without IRQ bit set in BASR, " 1380 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
1331 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr, 1381 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1332 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG)); 1382 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1333 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1383 }
1334 } 1384
1335 1385 if (!done) {
1336 if (!done) { 1386 INT_PRINTK("scsi%d: in int routine, calling main\n", HOSTNO);
1337 INT_PRINTK("scsi%d: in int routine, calling main\n", HOSTNO); 1387 /* Put a call to NCR5380_main() on the queue... */
1338 /* Put a call to NCR5380_main() on the queue... */ 1388 queue_main();
1339 queue_main(); 1389 }
1340 } 1390 return IRQ_RETVAL(handled);
1341 return IRQ_RETVAL(handled);
1342} 1391}
1343 1392
1344#ifdef NCR5380_STATS 1393#ifdef NCR5380_STATS
1345static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd* cmd) 1394static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)
1346{ 1395{
1347# ifdef NCR5380_STAT_LIMIT 1396# ifdef NCR5380_STAT_LIMIT
1348 if (cmd->request_bufflen > NCR5380_STAT_LIMIT) 1397 if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
1349# endif 1398# endif
1350 switch (cmd->cmnd[0]) 1399 switch (cmd->cmnd[0]) {
1351 { 1400 case WRITE:
1352 case WRITE: 1401 case WRITE_6:
1353 case WRITE_6: 1402 case WRITE_10:
1354 case WRITE_10: 1403 hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase);
1355 hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase); 1404 /*hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen;*/
1356 /*hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen;*/ 1405 hostdata->pendingw--;
1357 hostdata->pendingw--; 1406 break;
1358 break; 1407 case READ:
1359 case READ: 1408 case READ_6:
1360 case READ_6: 1409 case READ_10:
1361 case READ_10: 1410 hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase);
1362 hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase); 1411 /*hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen;*/
1363 /*hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen;*/ 1412 hostdata->pendingr--;
1364 hostdata->pendingr--; 1413 break;
1365 break; 1414 }
1366 }
1367} 1415}
1368#endif 1416#endif
1369 1417
1370/* 1418/*
1371 * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, 1419 * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd,
1372 * int tag); 1420 * int tag);
1373 * 1421 *
1374 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command, 1422 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
1375 * including ARBITRATION, SELECTION, and initial message out for 1423 * including ARBITRATION, SELECTION, and initial message out for
1376 * IDENTIFY and queue messages. 1424 * IDENTIFY and queue messages.
1377 * 1425 *
1378 * Inputs : instance - instantiation of the 5380 driver on which this 1426 * Inputs : instance - instantiation of the 5380 driver on which this
1379 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for 1427 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for
1380 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for 1428 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
1381 * the command that is presently connected. 1429 * the command that is presently connected.
1382 * 1430 *
1383 * Returns : -1 if selection could not execute for some reason, 1431 * Returns : -1 if selection could not execute for some reason,
1384 * 0 if selection succeeded or failed because the target 1432 * 0 if selection succeeded or failed because the target
1385 * did not respond. 1433 * did not respond.
1386 * 1434 *
1387 * Side effects : 1435 * Side effects :
1388 * If bus busy, arbitration failed, etc, NCR5380_select() will exit 1436 * If bus busy, arbitration failed, etc, NCR5380_select() will exit
1389 * with registers as they should have been on entry - ie 1437 * with registers as they should have been on entry - ie
1390 * SELECT_ENABLE will be set appropriately, the NCR5380 1438 * SELECT_ENABLE will be set appropriately, the NCR5380
1391 * will cease to drive any SCSI bus signals. 1439 * will cease to drive any SCSI bus signals.
1392 * 1440 *
1393 * If successful : I_T_L or I_T_L_Q nexus will be established, 1441 * If successful : I_T_L or I_T_L_Q nexus will be established,
1394 * instance->connected will be set to cmd. 1442 * instance->connected will be set to cmd.
1395 * SELECT interrupt will be disabled. 1443 * SELECT interrupt will be disabled.
1396 * 1444 *
1397 * If failed (no target) : cmd->scsi_done() will be called, and the 1445 * If failed (no target) : cmd->scsi_done() will be called, and the
1398 * cmd->result host byte set to DID_BAD_TARGET. 1446 * cmd->result host byte set to DID_BAD_TARGET.
1399 */ 1447 */
1400 1448
1401static int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag) 1449static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1402{ 1450{
1403 SETUP_HOSTDATA(instance); 1451 SETUP_HOSTDATA(instance);
1404 unsigned char tmp[3], phase; 1452 unsigned char tmp[3], phase;
1405 unsigned char *data; 1453 unsigned char *data;
1406 int len; 1454 int len;
1407 unsigned long timeout; 1455 unsigned long timeout;
1408 unsigned long flags; 1456 unsigned long flags;
1409 1457
1410 hostdata->restart_select = 0; 1458 hostdata->restart_select = 0;
1411 NCR_PRINT(NDEBUG_ARBITRATION); 1459 NCR_PRINT(NDEBUG_ARBITRATION);
1412 ARB_PRINTK("scsi%d: starting arbitration, id = %d\n", HOSTNO, 1460 ARB_PRINTK("scsi%d: starting arbitration, id = %d\n", HOSTNO,
1413 instance->this_id); 1461 instance->this_id);
1414 1462
1415 /* 1463 /*
1416 * Set the phase bits to 0, otherwise the NCR5380 won't drive the 1464 * Set the phase bits to 0, otherwise the NCR5380 won't drive the
1417 * data bus during SELECTION. 1465 * data bus during SELECTION.
1418 */ 1466 */
1419 1467
1420 local_irq_save(flags); 1468 local_irq_save(flags);
1421 if (hostdata->connected) { 1469 if (hostdata->connected) {
1470 local_irq_restore(flags);
1471 return -1;
1472 }
1473 NCR5380_write(TARGET_COMMAND_REG, 0);
1474
1475 /*
1476 * Start arbitration.
1477 */
1478
1479 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1480 NCR5380_write(MODE_REG, MR_ARBITRATE);
1481
1422 local_irq_restore(flags); 1482 local_irq_restore(flags);
1423 return -1; 1483
1424 } 1484 /* Wait for arbitration logic to complete */
1425 NCR5380_write(TARGET_COMMAND_REG, 0); 1485#if defined(NCR_TIMEOUT)
1426 1486 {
1427 1487 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1428 /* 1488
1429 * Start arbitration. 1489 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS) &&
1430 */ 1490 time_before(jiffies, timeout) && !hostdata->connected)
1431 1491 ;
1432 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); 1492 if (time_after_eq(jiffies, timeout)) {
1433 NCR5380_write(MODE_REG, MR_ARBITRATE); 1493 printk("scsi : arbitration timeout at %d\n", __LINE__);
1434 1494 NCR5380_write(MODE_REG, MR_BASE);
1435 local_irq_restore(flags); 1495 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1436 1496 return -1;
1437 /* Wait for arbitration logic to complete */ 1497 }
1438#if NCR_TIMEOUT 1498 }
1439 {
1440 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1441
1442 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1443 && time_before(jiffies, timeout) && !hostdata->connected)
1444 ;
1445 if (time_after_eq(jiffies, timeout))
1446 {
1447 printk("scsi : arbitration timeout at %d\n", __LINE__);
1448 NCR5380_write(MODE_REG, MR_BASE);
1449 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1450 return -1;
1451 }
1452 }
1453#else /* NCR_TIMEOUT */ 1499#else /* NCR_TIMEOUT */
1454 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS) 1500 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS) &&
1455 && !hostdata->connected); 1501 !hostdata->connected)
1502 ;
1456#endif 1503#endif
1457 1504
1458 ARB_PRINTK("scsi%d: arbitration complete\n", HOSTNO); 1505 ARB_PRINTK("scsi%d: arbitration complete\n", HOSTNO);
1459
1460 if (hostdata->connected) {
1461 NCR5380_write(MODE_REG, MR_BASE);
1462 return -1;
1463 }
1464 /*
1465 * The arbitration delay is 2.2us, but this is a minimum and there is
1466 * no maximum so we can safely sleep for ceil(2.2) usecs to accommodate
1467 * the integral nature of udelay().
1468 *
1469 */
1470
1471 udelay(3);
1472
1473 /* Check for lost arbitration */
1474 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1475 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1476 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1477 hostdata->connected) {
1478 NCR5380_write(MODE_REG, MR_BASE);
1479 ARB_PRINTK("scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1480 HOSTNO);
1481 return -1;
1482 }
1483
1484 /* after/during arbitration, BSY should be asserted.
1485 IBM DPES-31080 Version S31Q works now */
1486 /* Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) */
1487 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL |
1488 ICR_ASSERT_BSY ) ;
1489
1490 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1491 hostdata->connected) {
1492 NCR5380_write(MODE_REG, MR_BASE);
1493 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1494 ARB_PRINTK("scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1495 HOSTNO);
1496 return -1;
1497 }
1498 1506
1499 /* 1507 if (hostdata->connected) {
1500 * Again, bus clear + bus settle time is 1.2us, however, this is 1508 NCR5380_write(MODE_REG, MR_BASE);
1501 * a minimum so we'll udelay ceil(1.2) 1509 return -1;
1502 */ 1510 }
1511 /*
1512 * The arbitration delay is 2.2us, but this is a minimum and there is
1513 * no maximum so we can safely sleep for ceil(2.2) usecs to accommodate
1514 * the integral nature of udelay().
1515 *
1516 */
1517
1518 udelay(3);
1519
1520 /* Check for lost arbitration */
1521 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1522 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1523 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1524 hostdata->connected) {
1525 NCR5380_write(MODE_REG, MR_BASE);
1526 ARB_PRINTK("scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1527 HOSTNO);
1528 return -1;
1529 }
1530
1531 /* after/during arbitration, BSY should be asserted.
1532 IBM DPES-31080 Version S31Q works now */
1533 /* Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) */
1534 NCR5380_write(INITIATOR_COMMAND_REG,
1535 ICR_BASE | ICR_ASSERT_SEL | ICR_ASSERT_BSY);
1536
1537 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1538 hostdata->connected) {
1539 NCR5380_write(MODE_REG, MR_BASE);
1540 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1541 ARB_PRINTK("scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1542 HOSTNO);
1543 return -1;
1544 }
1545
1546 /*
1547 * Again, bus clear + bus settle time is 1.2us, however, this is
1548 * a minimum so we'll udelay ceil(1.2)
1549 */
1503 1550
1504#ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY 1551#ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
1505 /* ++roman: But some targets (see above :-) seem to need a bit more... */ 1552 /* ++roman: But some targets (see above :-) seem to need a bit more... */
1506 udelay(15); 1553 udelay(15);
1507#else 1554#else
1508 udelay(2); 1555 udelay(2);
1509#endif 1556#endif
1510 1557
1511 if (hostdata->connected) { 1558 if (hostdata->connected) {
1559 NCR5380_write(MODE_REG, MR_BASE);
1560 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1561 return -1;
1562 }
1563
1564 ARB_PRINTK("scsi%d: won arbitration\n", HOSTNO);
1565
1566 /*
1567 * Now that we have won arbitration, start Selection process, asserting
1568 * the host and target ID's on the SCSI bus.
1569 */
1570
1571 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id)));
1572
1573 /*
1574 * Raise ATN while SEL is true before BSY goes false from arbitration,
1575 * since this is the only way to guarantee that we'll get a MESSAGE OUT
1576 * phase immediately after selection.
1577 */
1578
1579 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1580 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
1512 NCR5380_write(MODE_REG, MR_BASE); 1581 NCR5380_write(MODE_REG, MR_BASE);
1513 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1514 return -1;
1515 }
1516 1582
1517 ARB_PRINTK("scsi%d: won arbitration\n", HOSTNO); 1583 /*
1584 * Reselect interrupts must be turned off prior to the dropping of BSY,
1585 * otherwise we will trigger an interrupt.
1586 */
1587
1588 if (hostdata->connected) {
1589 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1590 return -1;
1591 }
1518 1592
1519 /* 1593 NCR5380_write(SELECT_ENABLE_REG, 0);
1520 * Now that we have won arbitration, start Selection process, asserting 1594
1521 * the host and target ID's on the SCSI bus. 1595 /*
1522 */ 1596 * The initiator shall then wait at least two deskew delays and release
1597 * the BSY signal.
1598 */
1599 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */
1600
1601 /* Reset BSY */
1602 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1603 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1604
1605 /*
1606 * Something weird happens when we cease to drive BSY - looks
1607 * like the board/chip is letting us do another read before the
1608 * appropriate propagation delay has expired, and we're confusing
1609 * a BSY signal from ourselves as the target's response to SELECTION.
1610 *
1611 * A small delay (the 'C++' frontend breaks the pipeline with an
1612 * unnecessary jump, making it work on my 386-33/Trantor T128, the
1613 * tighter 'C' code breaks and requires this) solves the problem -
1614 * the 1 us delay is arbitrary, and only used because this delay will
1615 * be the same on other platforms and since it works here, it should
1616 * work there.
1617 *
1618 * wingel suggests that this could be due to failing to wait
1619 * one deskew delay.
1620 */
1523 1621
1524 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id))); 1622 udelay(1);
1525 1623
1526 /* 1624 SEL_PRINTK("scsi%d: selecting target %d\n", HOSTNO, cmd->device->id);
1527 * Raise ATN while SEL is true before BSY goes false from arbitration,
1528 * since this is the only way to guarantee that we'll get a MESSAGE OUT
1529 * phase immediately after selection.
1530 */
1531 1625
1532 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY | 1626 /*
1533 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL )); 1627 * The SCSI specification calls for a 250 ms timeout for the actual
1534 NCR5380_write(MODE_REG, MR_BASE); 1628 * selection.
1629 */
1535 1630
1536 /* 1631 timeout = jiffies + 25;
1537 * Reselect interrupts must be turned off prior to the dropping of BSY,
1538 * otherwise we will trigger an interrupt.
1539 */
1540 1632
1541 if (hostdata->connected) { 1633 /*
1542 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1634 * XXX very interesting - we're seeing a bounce where the BSY we
1543 return -1; 1635 * asserted is being reflected / still asserted (propagation delay?)
1544 } 1636 * and it's detecting as true. Sigh.
1545 1637 */
1546 NCR5380_write(SELECT_ENABLE_REG, 0);
1547
1548 /*
1549 * The initiator shall then wait at least two deskew delays and release
1550 * the BSY signal.
1551 */
1552 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */
1553
1554 /* Reset BSY */
1555 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1556 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1557
1558 /*
1559 * Something weird happens when we cease to drive BSY - looks
1560 * like the board/chip is letting us do another read before the
1561 * appropriate propagation delay has expired, and we're confusing
1562 * a BSY signal from ourselves as the target's response to SELECTION.
1563 *
1564 * A small delay (the 'C++' frontend breaks the pipeline with an
1565 * unnecessary jump, making it work on my 386-33/Trantor T128, the
1566 * tighter 'C' code breaks and requires this) solves the problem -
1567 * the 1 us delay is arbitrary, and only used because this delay will
1568 * be the same on other platforms and since it works here, it should
1569 * work there.
1570 *
1571 * wingel suggests that this could be due to failing to wait
1572 * one deskew delay.
1573 */
1574
1575 udelay(1);
1576
1577 SEL_PRINTK("scsi%d: selecting target %d\n", HOSTNO, cmd->device->id);
1578
1579 /*
1580 * The SCSI specification calls for a 250 ms timeout for the actual
1581 * selection.
1582 */
1583
1584 timeout = jiffies + 25;
1585
1586 /*
1587 * XXX very interesting - we're seeing a bounce where the BSY we
1588 * asserted is being reflected / still asserted (propagation delay?)
1589 * and it's detecting as true. Sigh.
1590 */
1591 1638
1592#if 0 1639#if 0
1593 /* ++roman: If a target conformed to the SCSI standard, it wouldn't assert 1640 /* ++roman: If a target conformed to the SCSI standard, it wouldn't assert
1594 * IO while SEL is true. But again, there are some disks out the in the 1641 * IO while SEL is true. But again, there are some disks out the in the
1595 * world that do that nevertheless. (Somebody claimed that this announces 1642 * world that do that nevertheless. (Somebody claimed that this announces
1596 * reselection capability of the target.) So we better skip that test and 1643 * reselection capability of the target.) So we better skip that test and
1597 * only wait for BSY... (Famous german words: Der Klügere gibt nach :-) 1644 * only wait for BSY... (Famous german words: Der Klügere gibt nach :-)
1598 */ 1645 */
1599 1646
1600 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & 1647 while (time_before(jiffies, timeout) &&
1601 (SR_BSY | SR_IO))); 1648 !(NCR5380_read(STATUS_REG) & (SR_BSY | SR_IO)))
1602 1649 ;
1603 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == 1650
1604 (SR_SEL | SR_IO)) { 1651 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
1605 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1652 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1606 NCR5380_reselect(instance); 1653 NCR5380_reselect(instance);
1607 printk (KERN_ERR "scsi%d: reselection after won arbitration?\n", 1654 printk(KERN_ERR "scsi%d: reselection after won arbitration?\n",
1608 HOSTNO); 1655 HOSTNO);
1609 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 1656 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1610 return -1; 1657 return -1;
1611 } 1658 }
1612#else 1659#else
1613 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY)); 1660 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY))
1661 ;
1614#endif 1662#endif
1615 1663
1616 /* 1664 /*
1617 * No less than two deskew delays after the initiator detects the 1665 * No less than two deskew delays after the initiator detects the
1618 * BSY signal is true, it shall release the SEL signal and may 1666 * BSY signal is true, it shall release the SEL signal and may
1619 * change the DATA BUS. -wingel 1667 * change the DATA BUS. -wingel
1620 */ 1668 */
1621 1669
1622 udelay(1); 1670 udelay(1);
1623 1671
1624 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); 1672 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1625 1673
1626 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) { 1674 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {
1627 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1675 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1628 if (hostdata->targets_present & (1 << cmd->device->id)) { 1676 if (hostdata->targets_present & (1 << cmd->device->id)) {
1629 printk(KERN_ERR "scsi%d: weirdness\n", HOSTNO); 1677 printk(KERN_ERR "scsi%d: weirdness\n", HOSTNO);
1630 if (hostdata->restart_select) 1678 if (hostdata->restart_select)
1631 printk(KERN_NOTICE "\trestart select\n"); 1679 printk(KERN_NOTICE "\trestart select\n");
1632 NCR_PRINT(NDEBUG_ANY); 1680 NCR_PRINT(NDEBUG_ANY);
1633 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 1681 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1634 return -1; 1682 return -1;
1635 } 1683 }
1636 cmd->result = DID_BAD_TARGET << 16; 1684 cmd->result = DID_BAD_TARGET << 16;
1637#ifdef NCR5380_STATS 1685#ifdef NCR5380_STATS
1638 collect_stats(hostdata, cmd); 1686 collect_stats(hostdata, cmd);
1639#endif 1687#endif
1640#ifdef SUPPORT_TAGS 1688#ifdef SUPPORT_TAGS
1641 cmd_free_tag( cmd ); 1689 cmd_free_tag(cmd);
1642#endif 1690#endif
1643 cmd->scsi_done(cmd); 1691 cmd->scsi_done(cmd);
1644 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 1692 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1645 SEL_PRINTK("scsi%d: target did not respond within 250ms\n", HOSTNO); 1693 SEL_PRINTK("scsi%d: target did not respond within 250ms\n", HOSTNO);
1646 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 1694 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1647 return 0; 1695 return 0;
1648 } 1696 }
1649 1697
1650 hostdata->targets_present |= (1 << cmd->device->id); 1698 hostdata->targets_present |= (1 << cmd->device->id);
1651 1699
1652 /* 1700 /*
1653 * Since we followed the SCSI spec, and raised ATN while SEL 1701 * Since we followed the SCSI spec, and raised ATN while SEL
1654 * was true but before BSY was false during selection, the information 1702 * was true but before BSY was false during selection, the information
1655 * transfer phase should be a MESSAGE OUT phase so that we can send the 1703 * transfer phase should be a MESSAGE OUT phase so that we can send the
1656 * IDENTIFY message. 1704 * IDENTIFY message.
1657 * 1705 *
1658 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG 1706 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG
1659 * message (2 bytes) with a tag ID that we increment with every command 1707 * message (2 bytes) with a tag ID that we increment with every command
1660 * until it wraps back to 0. 1708 * until it wraps back to 0.
1661 * 1709 *
1662 * XXX - it turns out that there are some broken SCSI-II devices, 1710 * XXX - it turns out that there are some broken SCSI-II devices,
1663 * which claim to support tagged queuing but fail when more than 1711 * which claim to support tagged queuing but fail when more than
1664 * some number of commands are issued at once. 1712 * some number of commands are issued at once.
1665 */ 1713 */
1666 1714
1667 /* Wait for start of REQ/ACK handshake */ 1715 /* Wait for start of REQ/ACK handshake */
1668 while (!(NCR5380_read(STATUS_REG) & SR_REQ)); 1716 while (!(NCR5380_read(STATUS_REG) & SR_REQ))
1669 1717 ;
1670 SEL_PRINTK("scsi%d: target %d selected, going into MESSAGE OUT phase.\n", 1718
1671 HOSTNO, cmd->device->id); 1719 SEL_PRINTK("scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
1672 tmp[0] = IDENTIFY(1, cmd->device->lun); 1720 HOSTNO, cmd->device->id);
1721 tmp[0] = IDENTIFY(1, cmd->device->lun);
1673 1722
1674#ifdef SUPPORT_TAGS 1723#ifdef SUPPORT_TAGS
1675 if (cmd->tag != TAG_NONE) { 1724 if (cmd->tag != TAG_NONE) {
1676 tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG; 1725 tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG;
1677 tmp[2] = cmd->tag; 1726 tmp[2] = cmd->tag;
1678 len = 3; 1727 len = 3;
1679 } else 1728 } else
1680 len = 1; 1729 len = 1;
1681#else 1730#else
1682 len = 1; 1731 len = 1;
1683 cmd->tag=0; 1732 cmd->tag = 0;
1684#endif /* SUPPORT_TAGS */ 1733#endif /* SUPPORT_TAGS */
1685 1734
1686 /* Send message(s) */ 1735 /* Send message(s) */
1687 data = tmp; 1736 data = tmp;
1688 phase = PHASE_MSGOUT; 1737 phase = PHASE_MSGOUT;
1689 NCR5380_transfer_pio(instance, &phase, &len, &data); 1738 NCR5380_transfer_pio(instance, &phase, &len, &data);
1690 SEL_PRINTK("scsi%d: nexus established.\n", HOSTNO); 1739 SEL_PRINTK("scsi%d: nexus established.\n", HOSTNO);
1691 /* XXX need to handle errors here */ 1740 /* XXX need to handle errors here */
1692 hostdata->connected = cmd; 1741 hostdata->connected = cmd;
1693#ifndef SUPPORT_TAGS 1742#ifndef SUPPORT_TAGS
1694 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); 1743 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
1695#endif 1744#endif
1696
1697 initialize_SCp(cmd);
1698 1745
1746 initialize_SCp(cmd);
1699 1747
1700 return 0; 1748 return 0;
1701} 1749}
1702 1750
1703/* 1751/*
1704 * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance, 1752 * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance,
1705 * unsigned char *phase, int *count, unsigned char **data) 1753 * unsigned char *phase, int *count, unsigned char **data)
1706 * 1754 *
1707 * Purpose : transfers data in given phase using polled I/O 1755 * Purpose : transfers data in given phase using polled I/O
1708 * 1756 *
1709 * Inputs : instance - instance of driver, *phase - pointer to 1757 * Inputs : instance - instance of driver, *phase - pointer to
1710 * what phase is expected, *count - pointer to number of 1758 * what phase is expected, *count - pointer to number of
1711 * bytes to transfer, **data - pointer to data pointer. 1759 * bytes to transfer, **data - pointer to data pointer.
1712 * 1760 *
1713 * Returns : -1 when different phase is entered without transferring 1761 * Returns : -1 when different phase is entered without transferring
1714 * maximum number of bytes, 0 if all bytes are transfered or exit 1762 * maximum number of bytes, 0 if all bytes are transfered or exit
1715 * is in same phase. 1763 * is in same phase.
1716 * 1764 *
1717 * Also, *phase, *count, *data are modified in place. 1765 * Also, *phase, *count, *data are modified in place.
1718 * 1766 *
1719 * XXX Note : handling for bus free may be useful. 1767 * XXX Note : handling for bus free may be useful.
1720 */ 1768 */
1721 1769
1722/* 1770/*
1723 * Note : this code is not as quick as it could be, however it 1771 * Note : this code is not as quick as it could be, however it
1724 * IS 100% reliable, and for the actual data transfer where speed 1772 * IS 100% reliable, and for the actual data transfer where speed
1725 * counts, we will always do a pseudo DMA or DMA transfer. 1773 * counts, we will always do a pseudo DMA or DMA transfer.
1726 */ 1774 */
1727 1775
1728static int NCR5380_transfer_pio( struct Scsi_Host *instance, 1776static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1729 unsigned char *phase, int *count, 1777 unsigned char *phase, int *count,
1730 unsigned char **data) 1778 unsigned char **data)
1731{ 1779{
1732 register unsigned char p = *phase, tmp; 1780 register unsigned char p = *phase, tmp;
1733 register int c = *count; 1781 register int c = *count;
1734 register unsigned char *d = *data; 1782 register unsigned char *d = *data;
1735 1783
1736 /* 1784 /*
1737 * The NCR5380 chip will only drive the SCSI bus when the 1785 * The NCR5380 chip will only drive the SCSI bus when the
1738 * phase specified in the appropriate bits of the TARGET COMMAND 1786 * phase specified in the appropriate bits of the TARGET COMMAND
1739 * REGISTER match the STATUS REGISTER 1787 * REGISTER match the STATUS REGISTER
1740 */
1741
1742 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1743
1744 do {
1745 /*
1746 * Wait for assertion of REQ, after which the phase bits will be
1747 * valid
1748 */ 1788 */
1749 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1750 1789
1751 HSH_PRINTK("scsi%d: REQ detected\n", HOSTNO); 1790 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1752 1791
1753 /* Check for phase mismatch */ 1792 do {
1754 if ((tmp & PHASE_MASK) != p) { 1793 /*
1755 PIO_PRINTK("scsi%d: phase mismatch\n", HOSTNO); 1794 * Wait for assertion of REQ, after which the phase bits will be
1756 NCR_PRINT_PHASE(NDEBUG_PIO); 1795 * valid
1757 break; 1796 */
1758 } 1797 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ))
1798 ;
1759 1799
1760 /* Do actual transfer from SCSI bus to / from memory */ 1800 HSH_PRINTK("scsi%d: REQ detected\n", HOSTNO);
1761 if (!(p & SR_IO))
1762 NCR5380_write(OUTPUT_DATA_REG, *d);
1763 else
1764 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1765 1801
1766 ++d; 1802 /* Check for phase mismatch */
1803 if ((tmp & PHASE_MASK) != p) {
1804 PIO_PRINTK("scsi%d: phase mismatch\n", HOSTNO);
1805 NCR_PRINT_PHASE(NDEBUG_PIO);
1806 break;
1807 }
1767 1808
1768 /* 1809 /* Do actual transfer from SCSI bus to / from memory */
1769 * The SCSI standard suggests that in MSGOUT phase, the initiator 1810 if (!(p & SR_IO))
1770 * should drop ATN on the last byte of the message phase 1811 NCR5380_write(OUTPUT_DATA_REG, *d);
1771 * after REQ has been asserted for the handshake but before 1812 else
1772 * the initiator raises ACK. 1813 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1773 */
1774 1814
1775 if (!(p & SR_IO)) { 1815 ++d;
1776 if (!((p & SR_MSG) && c > 1)) {
1777 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1778 ICR_ASSERT_DATA);
1779 NCR_PRINT(NDEBUG_PIO);
1780 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1781 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1782 } else {
1783 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1784 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1785 NCR_PRINT(NDEBUG_PIO);
1786 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1787 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1788 }
1789 } else {
1790 NCR_PRINT(NDEBUG_PIO);
1791 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1792 }
1793 1816
1794 while (NCR5380_read(STATUS_REG) & SR_REQ); 1817 /*
1818 * The SCSI standard suggests that in MSGOUT phase, the initiator
1819 * should drop ATN on the last byte of the message phase
1820 * after REQ has been asserted for the handshake but before
1821 * the initiator raises ACK.
1822 */
1795 1823
1796 HSH_PRINTK("scsi%d: req false, handshake complete\n", HOSTNO); 1824 if (!(p & SR_IO)) {
1825 if (!((p & SR_MSG) && c > 1)) {
1826 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
1827 NCR_PRINT(NDEBUG_PIO);
1828 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1829 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1830 } else {
1831 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1832 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1833 NCR_PRINT(NDEBUG_PIO);
1834 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1835 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1836 }
1837 } else {
1838 NCR_PRINT(NDEBUG_PIO);
1839 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1840 }
1797 1841
1798/* 1842 while (NCR5380_read(STATUS_REG) & SR_REQ)
1799 * We have several special cases to consider during REQ/ACK handshaking : 1843 ;
1800 * 1. We were in MSGOUT phase, and we are on the last byte of the 1844
1801 * message. ATN must be dropped as ACK is dropped. 1845 HSH_PRINTK("scsi%d: req false, handshake complete\n", HOSTNO);
1802 * 1846
1803 * 2. We are in a MSGIN phase, and we are on the last byte of the 1847 /*
1804 * message. We must exit with ACK asserted, so that the calling 1848 * We have several special cases to consider during REQ/ACK handshaking :
1805 * code may raise ATN before dropping ACK to reject the message. 1849 * 1. We were in MSGOUT phase, and we are on the last byte of the
1806 * 1850 * message. ATN must be dropped as ACK is dropped.
1807 * 3. ACK and ATN are clear and the target may proceed as normal. 1851 *
1808 */ 1852 * 2. We are in a MSGIN phase, and we are on the last byte of the
1809 if (!(p == PHASE_MSGIN && c == 1)) { 1853 * message. We must exit with ACK asserted, so that the calling
1810 if (p == PHASE_MSGOUT && c > 1) 1854 * code may raise ATN before dropping ACK to reject the message.
1811 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); 1855 *
1812 else 1856 * 3. ACK and ATN are clear and the target may proceed as normal.
1813 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1857 */
1814 } 1858 if (!(p == PHASE_MSGIN && c == 1)) {
1815 } while (--c); 1859 if (p == PHASE_MSGOUT && c > 1)
1816 1860 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1817 PIO_PRINTK("scsi%d: residual %d\n", HOSTNO, c); 1861 else
1818 1862 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1819 *count = c; 1863 }
1820 *data = d; 1864 } while (--c);
1821 tmp = NCR5380_read(STATUS_REG); 1865
1822 /* The phase read from the bus is valid if either REQ is (already) 1866 PIO_PRINTK("scsi%d: residual %d\n", HOSTNO, c);
1823 * asserted or if ACK hasn't been released yet. The latter is the case if 1867
1824 * we're in MSGIN and all wanted bytes have been received. */ 1868 *count = c;
1825 if ((tmp & SR_REQ) || (p == PHASE_MSGIN && c == 0)) 1869 *data = d;
1826 *phase = tmp & PHASE_MASK; 1870 tmp = NCR5380_read(STATUS_REG);
1827 else 1871 /* The phase read from the bus is valid if either REQ is (already)
1828 *phase = PHASE_UNKNOWN; 1872 * asserted or if ACK hasn't been released yet. The latter is the case if
1829 1873 * we're in MSGIN and all wanted bytes have been received.
1830 if (!c || (*phase == p)) 1874 */
1831 return 0; 1875 if ((tmp & SR_REQ) || (p == PHASE_MSGIN && c == 0))
1832 else 1876 *phase = tmp & PHASE_MASK;
1833 return -1; 1877 else
1878 *phase = PHASE_UNKNOWN;
1879
1880 if (!c || (*phase == p))
1881 return 0;
1882 else
1883 return -1;
1834} 1884}
1835 1885
1836/* 1886/*
1837 * Function : do_abort (Scsi_Host *host) 1887 * Function : do_abort (Scsi_Host *host)
1838 * 1888 *
1839 * Purpose : abort the currently established nexus. Should only be 1889 * Purpose : abort the currently established nexus. Should only be
1840 * called from a routine which can drop into a 1890 * called from a routine which can drop into a
1841 * 1891 *
1842 * Returns : 0 on success, -1 on failure. 1892 * Returns : 0 on success, -1 on failure.
1843 */ 1893 */
1844 1894
1845static int do_abort (struct Scsi_Host *host) 1895static int do_abort(struct Scsi_Host *host)
1846{ 1896{
1847 unsigned char tmp, *msgptr, phase; 1897 unsigned char tmp, *msgptr, phase;
1848 int len; 1898 int len;
1849 1899
1850 /* Request message out phase */ 1900 /* Request message out phase */
1851 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1852
1853 /*
1854 * Wait for the target to indicate a valid phase by asserting
1855 * REQ. Once this happens, we'll have either a MSGOUT phase
1856 * and can immediately send the ABORT message, or we'll have some
1857 * other phase and will have to source/sink data.
1858 *
1859 * We really don't care what value was on the bus or what value
1860 * the target sees, so we just handshake.
1861 */
1862
1863 while (!(tmp = NCR5380_read(STATUS_REG)) & SR_REQ);
1864
1865 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1866
1867 if ((tmp & PHASE_MASK) != PHASE_MSGOUT) {
1868 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1869 ICR_ASSERT_ACK);
1870 while (NCR5380_read(STATUS_REG) & SR_REQ);
1871 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); 1901 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1872 } 1902
1873 1903 /*
1874 tmp = ABORT; 1904 * Wait for the target to indicate a valid phase by asserting
1875 msgptr = &tmp; 1905 * REQ. Once this happens, we'll have either a MSGOUT phase
1876 len = 1; 1906 * and can immediately send the ABORT message, or we'll have some
1877 phase = PHASE_MSGOUT; 1907 * other phase and will have to source/sink data.
1878 NCR5380_transfer_pio (host, &phase, &len, &msgptr); 1908 *
1879 1909 * We really don't care what value was on the bus or what value
1880 /* 1910 * the target sees, so we just handshake.
1881 * If we got here, and the command completed successfully, 1911 */
1882 * we're about to go into bus free state. 1912
1883 */ 1913 while (!(tmp = NCR5380_read(STATUS_REG)) & SR_REQ)
1884 1914 ;
1885 return len ? -1 : 0; 1915
1916 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1917
1918 if ((tmp & PHASE_MASK) != PHASE_MSGOUT) {
1919 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1920 ICR_ASSERT_ACK);
1921 while (NCR5380_read(STATUS_REG) & SR_REQ)
1922 ;
1923 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1924 }
1925
1926 tmp = ABORT;
1927 msgptr = &tmp;
1928 len = 1;
1929 phase = PHASE_MSGOUT;
1930 NCR5380_transfer_pio(host, &phase, &len, &msgptr);
1931
1932 /*
1933 * If we got here, and the command completed successfully,
1934 * we're about to go into bus free state.
1935 */
1936
1937 return len ? -1 : 0;
1886} 1938}
1887 1939
1888#if defined(REAL_DMA) 1940#if defined(REAL_DMA)
1889/* 1941/*
1890 * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance, 1942 * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance,
1891 * unsigned char *phase, int *count, unsigned char **data) 1943 * unsigned char *phase, int *count, unsigned char **data)
1892 * 1944 *
1893 * Purpose : transfers data in given phase using either real 1945 * Purpose : transfers data in given phase using either real
1894 * or pseudo DMA. 1946 * or pseudo DMA.
1895 * 1947 *
1896 * Inputs : instance - instance of driver, *phase - pointer to 1948 * Inputs : instance - instance of driver, *phase - pointer to
1897 * what phase is expected, *count - pointer to number of 1949 * what phase is expected, *count - pointer to number of
1898 * bytes to transfer, **data - pointer to data pointer. 1950 * bytes to transfer, **data - pointer to data pointer.
1899 * 1951 *
1900 * Returns : -1 when different phase is entered without transferring 1952 * Returns : -1 when different phase is entered without transferring
1901 * maximum number of bytes, 0 if all bytes or transfered or exit 1953 * maximum number of bytes, 0 if all bytes or transfered or exit
1902 * is in same phase. 1954 * is in same phase.
1903 * 1955 *
1904 * Also, *phase, *count, *data are modified in place. 1956 * Also, *phase, *count, *data are modified in place.
1905 * 1957 *
1906 */ 1958 */
1907 1959
1908 1960
1909static int NCR5380_transfer_dma( struct Scsi_Host *instance, 1961static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1910 unsigned char *phase, int *count, 1962 unsigned char *phase, int *count,
1911 unsigned char **data) 1963 unsigned char **data)
1912{ 1964{
1913 SETUP_HOSTDATA(instance); 1965 SETUP_HOSTDATA(instance);
1914 register int c = *count; 1966 register int c = *count;
1915 register unsigned char p = *phase; 1967 register unsigned char p = *phase;
1916 register unsigned char *d = *data; 1968 register unsigned char *d = *data;
1917 unsigned char tmp; 1969 unsigned char tmp;
1918 unsigned long flags; 1970 unsigned long flags;
1919 1971
1920 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) { 1972 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) {
1921 *phase = tmp; 1973 *phase = tmp;
1922 return -1; 1974 return -1;
1923 } 1975 }
1924 1976
1925 if (atari_read_overruns && (p & SR_IO)) { 1977 if (atari_read_overruns && (p & SR_IO))
1926 c -= atari_read_overruns; 1978 c -= atari_read_overruns;
1927 }
1928 1979
1929 DMA_PRINTK("scsi%d: initializing DMA for %s, %d bytes %s %p\n", 1980 DMA_PRINTK("scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1930 HOSTNO, (p & SR_IO) ? "reading" : "writing", 1981 HOSTNO, (p & SR_IO) ? "reading" : "writing",
1931 c, (p & SR_IO) ? "to" : "from", d); 1982 c, (p & SR_IO) ? "to" : "from", d);
1932 1983
1933 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); 1984 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1934 1985
1935#ifdef REAL_DMA 1986#ifdef REAL_DMA
1936 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY); 1987 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1937#endif /* def REAL_DMA */ 1988#endif /* def REAL_DMA */
1938 1989
1939 if (IS_A_TT()) { 1990 if (IS_A_TT()) {
1940 /* On the Medusa, it is a must to initialize the DMA before 1991 /* On the Medusa, it is a must to initialize the DMA before
1941 * starting the NCR. This is also the cleaner way for the TT. 1992 * starting the NCR. This is also the cleaner way for the TT.
1942 */ 1993 */
1943 local_irq_save(flags); 1994 local_irq_save(flags);
1944 hostdata->dma_len = (p & SR_IO) ? 1995 hostdata->dma_len = (p & SR_IO) ?
1945 NCR5380_dma_read_setup(instance, d, c) : 1996 NCR5380_dma_read_setup(instance, d, c) :
1946 NCR5380_dma_write_setup(instance, d, c); 1997 NCR5380_dma_write_setup(instance, d, c);
1947 local_irq_restore(flags); 1998 local_irq_restore(flags);
1948 } 1999 }
1949 2000
1950 if (p & SR_IO) 2001 if (p & SR_IO)
1951 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0); 2002 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1952 else { 2003 else {
1953 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA); 2004 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
1954 NCR5380_write(START_DMA_SEND_REG, 0); 2005 NCR5380_write(START_DMA_SEND_REG, 0);
1955 } 2006 }
1956 2007
1957 if (!IS_A_TT()) { 2008 if (!IS_A_TT()) {
1958 /* On the Falcon, the DMA setup must be done after the last */ 2009 /* On the Falcon, the DMA setup must be done after the last */
1959 /* NCR access, else the DMA setup gets trashed! 2010 /* NCR access, else the DMA setup gets trashed!
1960 */ 2011 */
1961 local_irq_save(flags); 2012 local_irq_save(flags);
1962 hostdata->dma_len = (p & SR_IO) ? 2013 hostdata->dma_len = (p & SR_IO) ?
1963 NCR5380_dma_read_setup(instance, d, c) : 2014 NCR5380_dma_read_setup(instance, d, c) :
1964 NCR5380_dma_write_setup(instance, d, c); 2015 NCR5380_dma_write_setup(instance, d, c);
1965 local_irq_restore(flags); 2016 local_irq_restore(flags);
1966 } 2017 }
1967 return 0; 2018 return 0;
1968} 2019}
1969#endif /* defined(REAL_DMA) */ 2020#endif /* defined(REAL_DMA) */
1970 2021
1971/* 2022/*
1972 * Function : NCR5380_information_transfer (struct Scsi_Host *instance) 2023 * Function : NCR5380_information_transfer (struct Scsi_Host *instance)
1973 * 2024 *
1974 * Purpose : run through the various SCSI phases and do as the target 2025 * Purpose : run through the various SCSI phases and do as the target
1975 * directs us to. Operates on the currently connected command, 2026 * directs us to. Operates on the currently connected command,
1976 * instance->connected. 2027 * instance->connected.
1977 * 2028 *
1978 * Inputs : instance, instance for which we are doing commands 2029 * Inputs : instance, instance for which we are doing commands
1979 * 2030 *
1980 * Side effects : SCSI things happen, the disconnected queue will be 2031 * Side effects : SCSI things happen, the disconnected queue will be
1981 * modified if a command disconnects, *instance->connected will 2032 * modified if a command disconnects, *instance->connected will
1982 * change. 2033 * change.
1983 * 2034 *
1984 * XXX Note : we need to watch for bus free or a reset condition here 2035 * XXX Note : we need to watch for bus free or a reset condition here
1985 * to recover from an unexpected bus free condition. 2036 * to recover from an unexpected bus free condition.
1986 */ 2037 */
1987 2038
1988static void NCR5380_information_transfer (struct Scsi_Host *instance) 2039static void NCR5380_information_transfer(struct Scsi_Host *instance)
1989{ 2040{
1990 SETUP_HOSTDATA(instance); 2041 SETUP_HOSTDATA(instance);
1991 unsigned long flags; 2042 unsigned long flags;
1992 unsigned char msgout = NOP; 2043 unsigned char msgout = NOP;
1993 int sink = 0; 2044 int sink = 0;
1994 int len; 2045 int len;
1995#if defined(REAL_DMA) 2046#if defined(REAL_DMA)
1996 int transfersize; 2047 int transfersize;
1997#endif 2048#endif
1998 unsigned char *data; 2049 unsigned char *data;
1999 unsigned char phase, tmp, extended_msg[10], old_phase=0xff; 2050 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
2000 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected; 2051 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected;
2052
2053 while (1) {
2054 tmp = NCR5380_read(STATUS_REG);
2055 /* We only have a valid SCSI phase when REQ is asserted */
2056 if (tmp & SR_REQ) {
2057 phase = (tmp & PHASE_MASK);
2058 if (phase != old_phase) {
2059 old_phase = phase;
2060 NCR_PRINT_PHASE(NDEBUG_INFORMATION);
2061 }
2001 2062
2002 while (1) { 2063 if (sink && (phase != PHASE_MSGOUT)) {
2003 tmp = NCR5380_read(STATUS_REG); 2064 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
2004 /* We only have a valid SCSI phase when REQ is asserted */ 2065
2005 if (tmp & SR_REQ) { 2066 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
2006 phase = (tmp & PHASE_MASK); 2067 ICR_ASSERT_ACK);
2007 if (phase != old_phase) { 2068 while (NCR5380_read(STATUS_REG) & SR_REQ)
2008 old_phase = phase; 2069 ;
2009 NCR_PRINT_PHASE(NDEBUG_INFORMATION); 2070 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2010 } 2071 ICR_ASSERT_ATN);
2011 2072 sink = 0;
2012 if (sink && (phase != PHASE_MSGOUT)) { 2073 continue;
2013 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); 2074 }
2014 2075
2015 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN | 2076 switch (phase) {
2016 ICR_ASSERT_ACK); 2077 case PHASE_DATAOUT:
2017 while (NCR5380_read(STATUS_REG) & SR_REQ);
2018 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2019 ICR_ASSERT_ATN);
2020 sink = 0;
2021 continue;
2022 }
2023
2024 switch (phase) {
2025 case PHASE_DATAOUT:
2026#if (NDEBUG & NDEBUG_NO_DATAOUT) 2078#if (NDEBUG & NDEBUG_NO_DATAOUT)
2027 printk("scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT " 2079 printk("scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT "
2028 "aborted\n", HOSTNO); 2080 "aborted\n", HOSTNO);
2029 sink = 1; 2081 sink = 1;
2030 do_abort(instance); 2082 do_abort(instance);
2031 cmd->result = DID_ERROR << 16; 2083 cmd->result = DID_ERROR << 16;
2032 cmd->done(cmd); 2084 cmd->done(cmd);
2033 return; 2085 return;
2034#endif 2086#endif
2035 case PHASE_DATAIN: 2087 case PHASE_DATAIN:
2036 /* 2088 /*
2037 * If there is no room left in the current buffer in the 2089 * If there is no room left in the current buffer in the
2038 * scatter-gather list, move onto the next one. 2090 * scatter-gather list, move onto the next one.
2039 */ 2091 */
2040 2092
2041 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { 2093 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
2042 ++cmd->SCp.buffer; 2094 ++cmd->SCp.buffer;
2043 --cmd->SCp.buffers_residual; 2095 --cmd->SCp.buffers_residual;
2044 cmd->SCp.this_residual = cmd->SCp.buffer->length; 2096 cmd->SCp.this_residual = cmd->SCp.buffer->length;
2045 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page)+ 2097 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
2046 cmd->SCp.buffer->offset; 2098 cmd->SCp.buffer->offset;
2047 /* ++roman: Try to merge some scatter-buffers if 2099 /* ++roman: Try to merge some scatter-buffers if
2048 * they are at contiguous physical addresses. 2100 * they are at contiguous physical addresses.
2049 */ 2101 */
2050 merge_contiguous_buffers( cmd ); 2102 merge_contiguous_buffers(cmd);
2051 INF_PRINTK("scsi%d: %d bytes and %d buffers left\n", 2103 INF_PRINTK("scsi%d: %d bytes and %d buffers left\n",
2052 HOSTNO, cmd->SCp.this_residual, 2104 HOSTNO, cmd->SCp.this_residual,
2053 cmd->SCp.buffers_residual); 2105 cmd->SCp.buffers_residual);
2054 } 2106 }
2055 2107
2056 /* 2108 /*
2057 * The preferred transfer method is going to be 2109 * The preferred transfer method is going to be
2058 * PSEUDO-DMA for systems that are strictly PIO, 2110 * PSEUDO-DMA for systems that are strictly PIO,
2059 * since we can let the hardware do the handshaking. 2111 * since we can let the hardware do the handshaking.
2060 * 2112 *
2061 * For this to work, we need to know the transfersize 2113 * For this to work, we need to know the transfersize
2062 * ahead of time, since the pseudo-DMA code will sit 2114 * ahead of time, since the pseudo-DMA code will sit
2063 * in an unconditional loop. 2115 * in an unconditional loop.
2064 */ 2116 */
2065 2117
2066/* ++roman: I suggest, this should be 2118 /* ++roman: I suggest, this should be
2067 * #if def(REAL_DMA) 2119 * #if def(REAL_DMA)
2068 * instead of leaving REAL_DMA out. 2120 * instead of leaving REAL_DMA out.
2069 */ 2121 */
2070 2122
2071#if defined(REAL_DMA) 2123#if defined(REAL_DMA)
2072 if (!cmd->device->borken && 2124 if (!cmd->device->borken &&
2073 (transfersize = NCR5380_dma_xfer_len(instance,cmd,phase)) > 31) { 2125 (transfersize = NCR5380_dma_xfer_len(instance,cmd,phase)) > 31) {
2074 len = transfersize; 2126 len = transfersize;
2075 cmd->SCp.phase = phase; 2127 cmd->SCp.phase = phase;
2076 if (NCR5380_transfer_dma(instance, &phase, 2128 if (NCR5380_transfer_dma(instance, &phase,
2077 &len, (unsigned char **) &cmd->SCp.ptr)) { 2129 &len, (unsigned char **)&cmd->SCp.ptr)) {
2078 /* 2130 /*
2079 * If the watchdog timer fires, all future 2131 * If the watchdog timer fires, all future
2080 * accesses to this device will use the 2132 * accesses to this device will use the
2081 * polled-IO. */ 2133 * polled-IO. */
2082 printk(KERN_NOTICE "scsi%d: switching target %d " 2134 printk(KERN_NOTICE "scsi%d: switching target %d "
2083 "lun %d to slow handshake\n", HOSTNO, 2135 "lun %d to slow handshake\n", HOSTNO,
2084 cmd->device->id, cmd->device->lun); 2136 cmd->device->id, cmd->device->lun);
2085 cmd->device->borken = 1; 2137 cmd->device->borken = 1;
2086 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | 2138 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2087 ICR_ASSERT_ATN); 2139 ICR_ASSERT_ATN);
2088 sink = 1; 2140 sink = 1;
2089 do_abort(instance); 2141 do_abort(instance);
2090 cmd->result = DID_ERROR << 16; 2142 cmd->result = DID_ERROR << 16;
2091 cmd->done(cmd); 2143 cmd->done(cmd);
2092 /* XXX - need to source or sink data here, as appropriate */ 2144 /* XXX - need to source or sink data here, as appropriate */
2093 } else { 2145 } else {
2094#ifdef REAL_DMA 2146#ifdef REAL_DMA
2095 /* ++roman: When using real DMA, 2147 /* ++roman: When using real DMA,
2096 * information_transfer() should return after 2148 * information_transfer() should return after
2097 * starting DMA since it has nothing more to 2149 * starting DMA since it has nothing more to
2098 * do. 2150 * do.
2099 */ 2151 */
2100 return; 2152 return;
2101#else 2153#else
2102 cmd->SCp.this_residual -= transfersize - len; 2154 cmd->SCp.this_residual -= transfersize - len;
2103#endif 2155#endif
2104 } 2156 }
2105 } else 2157 } else
2106#endif /* defined(REAL_DMA) */ 2158#endif /* defined(REAL_DMA) */
2107 NCR5380_transfer_pio(instance, &phase, 2159 NCR5380_transfer_pio(instance, &phase,
2108 (int *) &cmd->SCp.this_residual, (unsigned char **) 2160 (int *)&cmd->SCp.this_residual,
2109 &cmd->SCp.ptr); 2161 (unsigned char **)&cmd->SCp.ptr);
2110 break; 2162 break;
2111 case PHASE_MSGIN: 2163 case PHASE_MSGIN:
2112 len = 1; 2164 len = 1;
2113 data = &tmp; 2165 data = &tmp;
2114 NCR5380_write(SELECT_ENABLE_REG, 0); /* disable reselects */ 2166 NCR5380_write(SELECT_ENABLE_REG, 0); /* disable reselects */
2115 NCR5380_transfer_pio(instance, &phase, &len, &data); 2167 NCR5380_transfer_pio(instance, &phase, &len, &data);
2116 cmd->SCp.Message = tmp; 2168 cmd->SCp.Message = tmp;
2117 2169
2118 switch (tmp) { 2170 switch (tmp) {
2119 /* 2171 /*
2120 * Linking lets us reduce the time required to get the 2172 * Linking lets us reduce the time required to get the
2121 * next command out to the device, hopefully this will 2173 * next command out to the device, hopefully this will
2122 * mean we don't waste another revolution due to the delays 2174 * mean we don't waste another revolution due to the delays
2123 * required by ARBITRATION and another SELECTION. 2175 * required by ARBITRATION and another SELECTION.
2124 * 2176 *
2125 * In the current implementation proposal, low level drivers 2177 * In the current implementation proposal, low level drivers
2126 * merely have to start the next command, pointed to by 2178 * merely have to start the next command, pointed to by
2127 * next_link, done() is called as with unlinked commands. 2179 * next_link, done() is called as with unlinked commands.
2128 */ 2180 */
2129#ifdef LINKED 2181#ifdef LINKED
2130 case LINKED_CMD_COMPLETE: 2182 case LINKED_CMD_COMPLETE:
2131 case LINKED_FLG_CMD_COMPLETE: 2183 case LINKED_FLG_CMD_COMPLETE:
2132 /* Accept message by clearing ACK */ 2184 /* Accept message by clearing ACK */
2133 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2185 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2134 2186
2135 LNK_PRINTK("scsi%d: target %d lun %d linked command " 2187 LNK_PRINTK("scsi%d: target %d lun %d linked command "
2136 "complete.\n", HOSTNO, cmd->device->id, cmd->device->lun); 2188 "complete.\n", HOSTNO, cmd->device->id, cmd->device->lun);
2137 2189
2138 /* Enable reselect interrupts */ 2190 /* Enable reselect interrupts */
2139 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2191 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2140 /* 2192 /*
2141 * Sanity check : A linked command should only terminate 2193 * Sanity check : A linked command should only terminate
2142 * with one of these messages if there are more linked 2194 * with one of these messages if there are more linked
2143 * commands available. 2195 * commands available.
2144 */ 2196 */
2145 2197
2146 if (!cmd->next_link) { 2198 if (!cmd->next_link) {
2147 printk(KERN_NOTICE "scsi%d: target %d lun %d " 2199 printk(KERN_NOTICE "scsi%d: target %d lun %d "
2148 "linked command complete, no next_link\n", 2200 "linked command complete, no next_link\n",
2149 HOSTNO, cmd->device->id, cmd->device->lun); 2201 HOSTNO, cmd->device->id, cmd->device->lun);
2150 sink = 1; 2202 sink = 1;
2151 do_abort (instance); 2203 do_abort(instance);
2152 return; 2204 return;
2153 } 2205 }
2154 2206
2155 initialize_SCp(cmd->next_link); 2207 initialize_SCp(cmd->next_link);
2156 /* The next command is still part of this process; copy it 2208 /* The next command is still part of this process; copy it
2157 * and don't free it! */ 2209 * and don't free it! */
2158 cmd->next_link->tag = cmd->tag; 2210 cmd->next_link->tag = cmd->tag;
2159 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8); 2211 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2160 LNK_PRINTK("scsi%d: target %d lun %d linked request " 2212 LNK_PRINTK("scsi%d: target %d lun %d linked request "
2161 "done, calling scsi_done().\n", 2213 "done, calling scsi_done().\n",
2162 HOSTNO, cmd->device->id, cmd->device->lun); 2214 HOSTNO, cmd->device->id, cmd->device->lun);
2163#ifdef NCR5380_STATS 2215#ifdef NCR5380_STATS
2164 collect_stats(hostdata, cmd); 2216 collect_stats(hostdata, cmd);
2165#endif 2217#endif
2166 cmd->scsi_done(cmd); 2218 cmd->scsi_done(cmd);
2167 cmd = hostdata->connected; 2219 cmd = hostdata->connected;
2168 break; 2220 break;
2169#endif /* def LINKED */ 2221#endif /* def LINKED */
2170 case ABORT: 2222 case ABORT:
2171 case COMMAND_COMPLETE: 2223 case COMMAND_COMPLETE:
2172 /* Accept message by clearing ACK */ 2224 /* Accept message by clearing ACK */
2173 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2225 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2174 /* ++guenther: possible race with Falcon locking */ 2226 /* ++guenther: possible race with Falcon locking */
2175 falcon_dont_release++; 2227 falcon_dont_release++;
2176 hostdata->connected = NULL; 2228 hostdata->connected = NULL;
2177 QU_PRINTK("scsi%d: command for target %d, lun %d " 2229 QU_PRINTK("scsi%d: command for target %d, lun %d "
2178 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun); 2230 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun);
2179#ifdef SUPPORT_TAGS 2231#ifdef SUPPORT_TAGS
2180 cmd_free_tag( cmd ); 2232 cmd_free_tag(cmd);
2181 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) { 2233 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
2182 /* Turn a QUEUE FULL status into BUSY, I think the 2234 /* Turn a QUEUE FULL status into BUSY, I think the
2183 * mid level cannot handle QUEUE FULL :-( (The 2235 * mid level cannot handle QUEUE FULL :-( (The
2184 * command is retried after BUSY). Also update our 2236 * command is retried after BUSY). Also update our
2185 * queue size to the number of currently issued 2237 * queue size to the number of currently issued
2186 * commands now. 2238 * commands now.
2187 */ 2239 */
2188 /* ++Andreas: the mid level code knows about 2240 /* ++Andreas: the mid level code knows about
2189 QUEUE_FULL now. */ 2241 QUEUE_FULL now. */
2190 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun]; 2242 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
2191 TAG_PRINTK("scsi%d: target %d lun %d returned " 2243 TAG_PRINTK("scsi%d: target %d lun %d returned "
2192 "QUEUE_FULL after %d commands\n", 2244 "QUEUE_FULL after %d commands\n",
2193 HOSTNO, cmd->device->id, cmd->device->lun, 2245 HOSTNO, cmd->device->id, cmd->device->lun,
2194 ta->nr_allocated); 2246 ta->nr_allocated);
2195 if (ta->queue_size > ta->nr_allocated) 2247 if (ta->queue_size > ta->nr_allocated)
2196 ta->nr_allocated = ta->queue_size; 2248 ta->nr_allocated = ta->queue_size;
2197 } 2249 }
2198#else 2250#else
2199 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2251 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2200#endif 2252#endif
2201 /* Enable reselect interrupts */ 2253 /* Enable reselect interrupts */
2202 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2254 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2203 2255
2204 /* 2256 /*
2205 * I'm not sure what the correct thing to do here is : 2257 * I'm not sure what the correct thing to do here is :
2206 * 2258 *
2207 * If the command that just executed is NOT a request 2259 * If the command that just executed is NOT a request
2208 * sense, the obvious thing to do is to set the result 2260 * sense, the obvious thing to do is to set the result
2209 * code to the values of the stored parameters. 2261 * code to the values of the stored parameters.
2210 * 2262 *
2211 * If it was a REQUEST SENSE command, we need some way to 2263 * If it was a REQUEST SENSE command, we need some way to
2212 * differentiate between the failure code of the original 2264 * differentiate between the failure code of the original
2213 * and the failure code of the REQUEST sense - the obvious 2265 * and the failure code of the REQUEST sense - the obvious
2214 * case is success, where we fall through and leave the 2266 * case is success, where we fall through and leave the
2215 * result code unchanged. 2267 * result code unchanged.
2216 * 2268 *
2217 * The non-obvious place is where the REQUEST SENSE failed 2269 * The non-obvious place is where the REQUEST SENSE failed
2218 */ 2270 */
2219 2271
2220 if (cmd->cmnd[0] != REQUEST_SENSE) 2272 if (cmd->cmnd[0] != REQUEST_SENSE)
2221 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8); 2273 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2222 else if (status_byte(cmd->SCp.Status) != GOOD) 2274 else if (status_byte(cmd->SCp.Status) != GOOD)
2223 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16); 2275 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2224
2225#ifdef AUTOSENSE
2226 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2227 (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
2228 ASEN_PRINTK("scsi%d: performing request sense\n",
2229 HOSTNO);
2230 cmd->cmnd[0] = REQUEST_SENSE;
2231 cmd->cmnd[1] &= 0xe0;
2232 cmd->cmnd[2] = 0;
2233 cmd->cmnd[3] = 0;
2234 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
2235 cmd->cmnd[5] = 0;
2236 cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
2237
2238 cmd->use_sg = 0;
2239 /* this is initialized from initialize_SCp
2240 cmd->SCp.buffer = NULL;
2241 cmd->SCp.buffers_residual = 0;
2242 */
2243 cmd->request_buffer = (char *) cmd->sense_buffer;
2244 cmd->request_bufflen = sizeof(cmd->sense_buffer);
2245 2276
2246 local_irq_save(flags); 2277#ifdef AUTOSENSE
2247 LIST(cmd,hostdata->issue_queue); 2278 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2248 NEXT(cmd) = hostdata->issue_queue; 2279 (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
2249 hostdata->issue_queue = (Scsi_Cmnd *) cmd; 2280 ASEN_PRINTK("scsi%d: performing request sense\n", HOSTNO);
2250 local_irq_restore(flags); 2281 cmd->cmnd[0] = REQUEST_SENSE;
2251 QU_PRINTK("scsi%d: REQUEST SENSE added to head of " 2282 cmd->cmnd[1] &= 0xe0;
2252 "issue queue\n", H_NO(cmd)); 2283 cmd->cmnd[2] = 0;
2253 } else 2284 cmd->cmnd[3] = 0;
2285 cmd->cmnd[4] = sizeof(cmd->sense_buffer);
2286 cmd->cmnd[5] = 0;
2287 cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
2288
2289 cmd->use_sg = 0;
2290 /* this is initialized from initialize_SCp
2291 cmd->SCp.buffer = NULL;
2292 cmd->SCp.buffers_residual = 0;
2293 */
2294 cmd->request_buffer = (char *) cmd->sense_buffer;
2295 cmd->request_bufflen = sizeof(cmd->sense_buffer);
2296
2297 local_irq_save(flags);
2298 LIST(cmd,hostdata->issue_queue);
2299 SET_NEXT(cmd, hostdata->issue_queue);
2300 hostdata->issue_queue = (Scsi_Cmnd *) cmd;
2301 local_irq_restore(flags);
2302 QU_PRINTK("scsi%d: REQUEST SENSE added to head of "
2303 "issue queue\n", H_NO(cmd));
2304 } else
2254#endif /* def AUTOSENSE */ 2305#endif /* def AUTOSENSE */
2255 { 2306 {
2256#ifdef NCR5380_STATS 2307#ifdef NCR5380_STATS
2257 collect_stats(hostdata, cmd); 2308 collect_stats(hostdata, cmd);
2258#endif 2309#endif
2259 cmd->scsi_done(cmd); 2310 cmd->scsi_done(cmd);
2260 } 2311 }
2261 2312
2262 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2313 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2263 /* 2314 /*
2264 * Restore phase bits to 0 so an interrupted selection, 2315 * Restore phase bits to 0 so an interrupted selection,
2265 * arbitration can resume. 2316 * arbitration can resume.
2266 */ 2317 */
2267 NCR5380_write(TARGET_COMMAND_REG, 0); 2318 NCR5380_write(TARGET_COMMAND_REG, 0);
2268 2319
2269 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected) 2320 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2270 barrier(); 2321 barrier();
2271 2322
2272 falcon_dont_release--; 2323 falcon_dont_release--;
2273 /* ++roman: For Falcon SCSI, release the lock on the 2324 /* ++roman: For Falcon SCSI, release the lock on the
2274 * ST-DMA here if no other commands are waiting on the 2325 * ST-DMA here if no other commands are waiting on the
2275 * disconnected queue. 2326 * disconnected queue.
2276 */ 2327 */
2277 falcon_release_lock_if_possible( hostdata ); 2328 falcon_release_lock_if_possible(hostdata);
2278 return; 2329 return;
2279 case MESSAGE_REJECT: 2330 case MESSAGE_REJECT:
2280 /* Accept message by clearing ACK */ 2331 /* Accept message by clearing ACK */
2281 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2332 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2282 /* Enable reselect interrupts */ 2333 /* Enable reselect interrupts */
2283 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2334 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2284 switch (hostdata->last_message) { 2335 switch (hostdata->last_message) {
2285 case HEAD_OF_QUEUE_TAG: 2336 case HEAD_OF_QUEUE_TAG:
2286 case ORDERED_QUEUE_TAG: 2337 case ORDERED_QUEUE_TAG:
2287 case SIMPLE_QUEUE_TAG: 2338 case SIMPLE_QUEUE_TAG:
2288 /* The target obviously doesn't support tagged 2339 /* The target obviously doesn't support tagged
2289 * queuing, even though it announced this ability in 2340 * queuing, even though it announced this ability in
2290 * its INQUIRY data ?!? (maybe only this LUN?) Ok, 2341 * its INQUIRY data ?!? (maybe only this LUN?) Ok,
2291 * clear 'tagged_supported' and lock the LUN, since 2342 * clear 'tagged_supported' and lock the LUN, since
2292 * the command is treated as untagged further on. 2343 * the command is treated as untagged further on.
2293 */ 2344 */
2294 cmd->device->tagged_supported = 0; 2345 cmd->device->tagged_supported = 0;
2295 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); 2346 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
2296 cmd->tag = TAG_NONE; 2347 cmd->tag = TAG_NONE;
2297 TAG_PRINTK("scsi%d: target %d lun %d rejected " 2348 TAG_PRINTK("scsi%d: target %d lun %d rejected "
2298 "QUEUE_TAG message; tagged queuing " 2349 "QUEUE_TAG message; tagged queuing "
2299 "disabled\n", 2350 "disabled\n",
2300 HOSTNO, cmd->device->id, cmd->device->lun); 2351 HOSTNO, cmd->device->id, cmd->device->lun);
2301 break; 2352 break;
2302 } 2353 }
2303 break; 2354 break;
2304 case DISCONNECT: 2355 case DISCONNECT:
2305 /* Accept message by clearing ACK */ 2356 /* Accept message by clearing ACK */
2306 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2357 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2307 local_irq_save(flags); 2358 local_irq_save(flags);
2308 cmd->device->disconnect = 1; 2359 cmd->device->disconnect = 1;
2309 LIST(cmd,hostdata->disconnected_queue); 2360 LIST(cmd,hostdata->disconnected_queue);
2310 NEXT(cmd) = hostdata->disconnected_queue; 2361 SET_NEXT(cmd, hostdata->disconnected_queue);
2311 hostdata->connected = NULL; 2362 hostdata->connected = NULL;
2312 hostdata->disconnected_queue = cmd; 2363 hostdata->disconnected_queue = cmd;
2313 local_irq_restore(flags); 2364 local_irq_restore(flags);
2314 QU_PRINTK("scsi%d: command for target %d lun %d was " 2365 QU_PRINTK("scsi%d: command for target %d lun %d was "
2315 "moved from connected to the " 2366 "moved from connected to the "
2316 "disconnected_queue\n", HOSTNO, 2367 "disconnected_queue\n", HOSTNO,
2317 cmd->device->id, cmd->device->lun); 2368 cmd->device->id, cmd->device->lun);
2318 /* 2369 /*
2319 * Restore phase bits to 0 so an interrupted selection, 2370 * Restore phase bits to 0 so an interrupted selection,
2320 * arbitration can resume. 2371 * arbitration can resume.
2321 */ 2372 */
2322 NCR5380_write(TARGET_COMMAND_REG, 0); 2373 NCR5380_write(TARGET_COMMAND_REG, 0);
2323 2374
2324 /* Enable reselect interrupts */ 2375 /* Enable reselect interrupts */
2325 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2376 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2326 /* Wait for bus free to avoid nasty timeouts */ 2377 /* Wait for bus free to avoid nasty timeouts */
2327 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected) 2378 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2328 barrier(); 2379 barrier();
2329 return; 2380 return;
2330 /* 2381 /*
2331 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect 2382 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
2332 * operation, in violation of the SCSI spec so we can safely 2383 * operation, in violation of the SCSI spec so we can safely
2333 * ignore SAVE/RESTORE pointers calls. 2384 * ignore SAVE/RESTORE pointers calls.
2334 * 2385 *
2335 * Unfortunately, some disks violate the SCSI spec and 2386 * Unfortunately, some disks violate the SCSI spec and
2336 * don't issue the required SAVE_POINTERS message before 2387 * don't issue the required SAVE_POINTERS message before
2337 * disconnecting, and we have to break spec to remain 2388 * disconnecting, and we have to break spec to remain
2338 * compatible. 2389 * compatible.
2339 */ 2390 */
2340 case SAVE_POINTERS: 2391 case SAVE_POINTERS:
2341 case RESTORE_POINTERS: 2392 case RESTORE_POINTERS:
2342 /* Accept message by clearing ACK */ 2393 /* Accept message by clearing ACK */
2343 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2394 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2344 /* Enable reselect interrupts */ 2395 /* Enable reselect interrupts */
2345 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2396 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2346 break; 2397 break;
2347 case EXTENDED_MESSAGE: 2398 case EXTENDED_MESSAGE:
2348/* 2399 /*
2349 * Extended messages are sent in the following format : 2400 * Extended messages are sent in the following format :
2350 * Byte 2401 * Byte
2351 * 0 EXTENDED_MESSAGE == 1 2402 * 0 EXTENDED_MESSAGE == 1
2352 * 1 length (includes one byte for code, doesn't 2403 * 1 length (includes one byte for code, doesn't
2353 * include first two bytes) 2404 * include first two bytes)
2354 * 2 code 2405 * 2 code
2355 * 3..length+1 arguments 2406 * 3..length+1 arguments
2356 * 2407 *
2357 * Start the extended message buffer with the EXTENDED_MESSAGE 2408 * Start the extended message buffer with the EXTENDED_MESSAGE
2358 * byte, since spi_print_msg() wants the whole thing. 2409 * byte, since spi_print_msg() wants the whole thing.
2359 */ 2410 */
2360 extended_msg[0] = EXTENDED_MESSAGE; 2411 extended_msg[0] = EXTENDED_MESSAGE;
2361 /* Accept first byte by clearing ACK */ 2412 /* Accept first byte by clearing ACK */
2362 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2413 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2363 2414
2364 EXT_PRINTK("scsi%d: receiving extended message\n", HOSTNO); 2415 EXT_PRINTK("scsi%d: receiving extended message\n", HOSTNO);
2365 2416
2366 len = 2; 2417 len = 2;
2367 data = extended_msg + 1; 2418 data = extended_msg + 1;
2368 phase = PHASE_MSGIN; 2419 phase = PHASE_MSGIN;
2369 NCR5380_transfer_pio(instance, &phase, &len, &data); 2420 NCR5380_transfer_pio(instance, &phase, &len, &data);
2370 EXT_PRINTK("scsi%d: length=%d, code=0x%02x\n", HOSTNO, 2421 EXT_PRINTK("scsi%d: length=%d, code=0x%02x\n", HOSTNO,
2371 (int)extended_msg[1], (int)extended_msg[2]); 2422 (int)extended_msg[1], (int)extended_msg[2]);
2372 2423
2373 if (!len && extended_msg[1] <= 2424 if (!len && extended_msg[1] <=
2374 (sizeof (extended_msg) - 1)) { 2425 (sizeof(extended_msg) - 1)) {
2375 /* Accept third byte by clearing ACK */ 2426 /* Accept third byte by clearing ACK */
2376 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2427 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2377 len = extended_msg[1] - 1; 2428 len = extended_msg[1] - 1;
2378 data = extended_msg + 3; 2429 data = extended_msg + 3;
2379 phase = PHASE_MSGIN; 2430 phase = PHASE_MSGIN;
2380 2431
2381 NCR5380_transfer_pio(instance, &phase, &len, &data); 2432 NCR5380_transfer_pio(instance, &phase, &len, &data);
2382 EXT_PRINTK("scsi%d: message received, residual %d\n", 2433 EXT_PRINTK("scsi%d: message received, residual %d\n",
2383 HOSTNO, len); 2434 HOSTNO, len);
2384 2435
2385 switch (extended_msg[2]) { 2436 switch (extended_msg[2]) {
2386 case EXTENDED_SDTR: 2437 case EXTENDED_SDTR:
2387 case EXTENDED_WDTR: 2438 case EXTENDED_WDTR:
2388 case EXTENDED_MODIFY_DATA_POINTER: 2439 case EXTENDED_MODIFY_DATA_POINTER:
2389 case EXTENDED_EXTENDED_IDENTIFY: 2440 case EXTENDED_EXTENDED_IDENTIFY:
2390 tmp = 0; 2441 tmp = 0;
2391 } 2442 }
2392 } else if (len) { 2443 } else if (len) {
2393 printk(KERN_NOTICE "scsi%d: error receiving " 2444 printk(KERN_NOTICE "scsi%d: error receiving "
2394 "extended message\n", HOSTNO); 2445 "extended message\n", HOSTNO);
2395 tmp = 0; 2446 tmp = 0;
2396 } else { 2447 } else {
2397 printk(KERN_NOTICE "scsi%d: extended message " 2448 printk(KERN_NOTICE "scsi%d: extended message "
2398 "code %02x length %d is too long\n", 2449 "code %02x length %d is too long\n",
2399 HOSTNO, extended_msg[2], extended_msg[1]); 2450 HOSTNO, extended_msg[2], extended_msg[1]);
2400 tmp = 0; 2451 tmp = 0;
2401 } 2452 }
2402 /* Fall through to reject message */ 2453 /* Fall through to reject message */
2403 2454
2404 /* 2455 /*
2405 * If we get something weird that we aren't expecting, 2456 * If we get something weird that we aren't expecting,
2406 * reject it. 2457 * reject it.
2407 */ 2458 */
2408 default: 2459 default:
2409 if (!tmp) { 2460 if (!tmp) {
2410 printk(KERN_DEBUG "scsi%d: rejecting message ", HOSTNO); 2461 printk(KERN_DEBUG "scsi%d: rejecting message ", HOSTNO);
2411 spi_print_msg(extended_msg); 2462 spi_print_msg(extended_msg);
2412 printk("\n"); 2463 printk("\n");
2413 } else if (tmp != EXTENDED_MESSAGE) 2464 } else if (tmp != EXTENDED_MESSAGE)
2414 printk(KERN_DEBUG "scsi%d: rejecting unknown " 2465 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2415 "message %02x from target %d, lun %d\n", 2466 "message %02x from target %d, lun %d\n",
2416 HOSTNO, tmp, cmd->device->id, cmd->device->lun); 2467 HOSTNO, tmp, cmd->device->id, cmd->device->lun);
2417 else 2468 else
2418 printk(KERN_DEBUG "scsi%d: rejecting unknown " 2469 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2419 "extended message " 2470 "extended message "
2420 "code %02x, length %d from target %d, lun %d\n", 2471 "code %02x, length %d from target %d, lun %d\n",
2421 HOSTNO, extended_msg[1], extended_msg[0], 2472 HOSTNO, extended_msg[1], extended_msg[0],
2422 cmd->device->id, cmd->device->lun); 2473 cmd->device->id, cmd->device->lun);
2423 2474
2424 2475
2425 msgout = MESSAGE_REJECT; 2476 msgout = MESSAGE_REJECT;
2426 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | 2477 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2427 ICR_ASSERT_ATN); 2478 break;
2428 break; 2479 } /* switch (tmp) */
2429 } /* switch (tmp) */ 2480 break;
2430 break; 2481 case PHASE_MSGOUT:
2431 case PHASE_MSGOUT: 2482 len = 1;
2432 len = 1; 2483 data = &msgout;
2433 data = &msgout; 2484 hostdata->last_message = msgout;
2434 hostdata->last_message = msgout; 2485 NCR5380_transfer_pio(instance, &phase, &len, &data);
2435 NCR5380_transfer_pio(instance, &phase, &len, &data); 2486 if (msgout == ABORT) {
2436 if (msgout == ABORT) {
2437#ifdef SUPPORT_TAGS 2487#ifdef SUPPORT_TAGS
2438 cmd_free_tag( cmd ); 2488 cmd_free_tag(cmd);
2439#else 2489#else
2440 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2490 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2441#endif 2491#endif
2442 hostdata->connected = NULL; 2492 hostdata->connected = NULL;
2443 cmd->result = DID_ERROR << 16; 2493 cmd->result = DID_ERROR << 16;
2444#ifdef NCR5380_STATS 2494#ifdef NCR5380_STATS
2445 collect_stats(hostdata, cmd); 2495 collect_stats(hostdata, cmd);
2446#endif 2496#endif
2447 cmd->scsi_done(cmd); 2497 cmd->scsi_done(cmd);
2448 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2498 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2449 falcon_release_lock_if_possible( hostdata ); 2499 falcon_release_lock_if_possible(hostdata);
2450 return; 2500 return;
2451 } 2501 }
2452 msgout = NOP; 2502 msgout = NOP;
2453 break; 2503 break;
2454 case PHASE_CMDOUT: 2504 case PHASE_CMDOUT:
2455 len = cmd->cmd_len; 2505 len = cmd->cmd_len;
2456 data = cmd->cmnd; 2506 data = cmd->cmnd;
2457 /* 2507 /*
2458 * XXX for performance reasons, on machines with a 2508 * XXX for performance reasons, on machines with a
2459 * PSEUDO-DMA architecture we should probably 2509 * PSEUDO-DMA architecture we should probably
2460 * use the dma transfer function. 2510 * use the dma transfer function.
2461 */ 2511 */
2462 NCR5380_transfer_pio(instance, &phase, &len, 2512 NCR5380_transfer_pio(instance, &phase, &len, &data);
2463 &data); 2513 break;
2464 break; 2514 case PHASE_STATIN:
2465 case PHASE_STATIN: 2515 len = 1;
2466 len = 1; 2516 data = &tmp;
2467 data = &tmp; 2517 NCR5380_transfer_pio(instance, &phase, &len, &data);
2468 NCR5380_transfer_pio(instance, &phase, &len, &data); 2518 cmd->SCp.Status = tmp;
2469 cmd->SCp.Status = tmp; 2519 break;
2470 break; 2520 default:
2471 default: 2521 printk("scsi%d: unknown phase\n", HOSTNO);
2472 printk("scsi%d: unknown phase\n", HOSTNO); 2522 NCR_PRINT(NDEBUG_ANY);
2473 NCR_PRINT(NDEBUG_ANY); 2523 } /* switch(phase) */
2474 } /* switch(phase) */ 2524 } /* if (tmp * SR_REQ) */
2475 } /* if (tmp * SR_REQ) */ 2525 } /* while (1) */
2476 } /* while (1) */
2477} 2526}
2478 2527
2479/* 2528/*
2480 * Function : void NCR5380_reselect (struct Scsi_Host *instance) 2529 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2481 * 2530 *
2482 * Purpose : does reselection, initializing the instance->connected 2531 * Purpose : does reselection, initializing the instance->connected
2483 * field to point to the Scsi_Cmnd for which the I_T_L or I_T_L_Q 2532 * field to point to the Scsi_Cmnd for which the I_T_L or I_T_L_Q
2484 * nexus has been reestablished, 2533 * nexus has been reestablished,
2485 * 2534 *
2486 * Inputs : instance - this instance of the NCR5380. 2535 * Inputs : instance - this instance of the NCR5380.
2487 * 2536 *
2488 */ 2537 */
2489 2538
2490 2539
2491static void NCR5380_reselect (struct Scsi_Host *instance) 2540static void NCR5380_reselect(struct Scsi_Host *instance)
2492{ 2541{
2493 SETUP_HOSTDATA(instance); 2542 SETUP_HOSTDATA(instance);
2494 unsigned char target_mask; 2543 unsigned char target_mask;
2495 unsigned char lun, phase; 2544 unsigned char lun, phase;
2496 int len; 2545 int len;
2497#ifdef SUPPORT_TAGS 2546#ifdef SUPPORT_TAGS
2498 unsigned char tag; 2547 unsigned char tag;
2499#endif 2548#endif
2500 unsigned char msg[3]; 2549 unsigned char msg[3];
2501 unsigned char *data; 2550 unsigned char *data;
2502 Scsi_Cmnd *tmp = NULL, *prev; 2551 Scsi_Cmnd *tmp = NULL, *prev;
2503/* unsigned long flags; */ 2552/* unsigned long flags; */
2504 2553
2505 /* 2554 /*
2506 * Disable arbitration, etc. since the host adapter obviously 2555 * Disable arbitration, etc. since the host adapter obviously
2507 * lost, and tell an interrupted NCR5380_select() to restart. 2556 * lost, and tell an interrupted NCR5380_select() to restart.
2508 */ 2557 */
2509 2558
2510 NCR5380_write(MODE_REG, MR_BASE); 2559 NCR5380_write(MODE_REG, MR_BASE);
2511 hostdata->restart_select = 1; 2560 hostdata->restart_select = 1;
2512 2561
2513 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask); 2562 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2514 2563
2515 RSL_PRINTK("scsi%d: reselect\n", HOSTNO); 2564 RSL_PRINTK("scsi%d: reselect\n", HOSTNO);
2516 2565
2517 /* 2566 /*
2518 * At this point, we have detected that our SCSI ID is on the bus, 2567 * At this point, we have detected that our SCSI ID is on the bus,
2519 * SEL is true and BSY was false for at least one bus settle delay 2568 * SEL is true and BSY was false for at least one bus settle delay
2520 * (400 ns). 2569 * (400 ns).
2521 * 2570 *
2522 * We must assert BSY ourselves, until the target drops the SEL 2571 * We must assert BSY ourselves, until the target drops the SEL
2523 * signal. 2572 * signal.
2524 */ 2573 */
2525 2574
2526 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY); 2575 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2527 2576
2528 while (NCR5380_read(STATUS_REG) & SR_SEL); 2577 while (NCR5380_read(STATUS_REG) & SR_SEL)
2529 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2578 ;
2530 2579 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2531 /* 2580
2532 * Wait for target to go into MSGIN. 2581 /*
2533 */ 2582 * Wait for target to go into MSGIN.
2534 2583 */
2535 while (!(NCR5380_read(STATUS_REG) & SR_REQ)); 2584
2536 2585 while (!(NCR5380_read(STATUS_REG) & SR_REQ))
2537 len = 1; 2586 ;
2538 data = msg; 2587
2539 phase = PHASE_MSGIN; 2588 len = 1;
2540 NCR5380_transfer_pio(instance, &phase, &len, &data); 2589 data = msg;
2541 2590 phase = PHASE_MSGIN;
2542 if (!(msg[0] & 0x80)) { 2591 NCR5380_transfer_pio(instance, &phase, &len, &data);
2543 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO); 2592
2544 spi_print_msg(msg); 2593 if (!(msg[0] & 0x80)) {
2545 do_abort(instance); 2594 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO);
2546 return; 2595 spi_print_msg(msg);
2547 } 2596 do_abort(instance);
2548 lun = (msg[0] & 0x07); 2597 return;
2598 }
2599 lun = (msg[0] & 0x07);
2549 2600
2550#ifdef SUPPORT_TAGS 2601#ifdef SUPPORT_TAGS
2551 /* If the phase is still MSGIN, the target wants to send some more 2602 /* If the phase is still MSGIN, the target wants to send some more
2552 * messages. In case it supports tagged queuing, this is probably a 2603 * messages. In case it supports tagged queuing, this is probably a
2553 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus. 2604 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2554 */ 2605 */
2555 tag = TAG_NONE; 2606 tag = TAG_NONE;
2556 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) { 2607 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
2557 /* Accept previous IDENTIFY message by clearing ACK */ 2608 /* Accept previous IDENTIFY message by clearing ACK */
2558 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); 2609 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2559 len = 2; 2610 len = 2;
2560 data = msg+1; 2611 data = msg + 1;
2561 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) && 2612 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2562 msg[1] == SIMPLE_QUEUE_TAG) 2613 msg[1] == SIMPLE_QUEUE_TAG)
2563 tag = msg[2]; 2614 tag = msg[2];
2564 TAG_PRINTK("scsi%d: target mask %02x, lun %d sent tag %d at " 2615 TAG_PRINTK("scsi%d: target mask %02x, lun %d sent tag %d at "
2565 "reselection\n", HOSTNO, target_mask, lun, tag); 2616 "reselection\n", HOSTNO, target_mask, lun, tag);
2566 } 2617 }
2567#endif 2618#endif
2568 2619
2569 /* 2620 /*
2570 * Find the command corresponding to the I_T_L or I_T_L_Q nexus we 2621 * Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2571 * just reestablished, and remove it from the disconnected queue. 2622 * just reestablished, and remove it from the disconnected queue.
2572 */ 2623 */
2573 2624
2574 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL; 2625 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL;
2575 tmp; prev = tmp, tmp = NEXT(tmp) ) { 2626 tmp; prev = tmp, tmp = NEXT(tmp)) {
2576 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun) 2627 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
2577#ifdef SUPPORT_TAGS 2628#ifdef SUPPORT_TAGS
2578 && (tag == tmp->tag) 2629 && (tag == tmp->tag)
2579#endif 2630#endif
2580 ) { 2631 ) {
2581 /* ++guenther: prevent race with falcon_release_lock */ 2632 /* ++guenther: prevent race with falcon_release_lock */
2582 falcon_dont_release++; 2633 falcon_dont_release++;
2583 if (prev) { 2634 if (prev) {
2584 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp)); 2635 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
2585 NEXT(prev) = NEXT(tmp); 2636 SET_NEXT(prev, NEXT(tmp));
2586 } else { 2637 } else {
2587 REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp)); 2638 REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp));
2588 hostdata->disconnected_queue = NEXT(tmp); 2639 hostdata->disconnected_queue = NEXT(tmp);
2589 } 2640 }
2590 NEXT(tmp) = NULL; 2641 SET_NEXT(tmp, NULL);
2591 break; 2642 break;
2643 }
2592 } 2644 }
2593 } 2645
2594 2646 if (!tmp) {
2595 if (!tmp) { 2647 printk(KERN_WARNING "scsi%d: warning: target bitmask %02x lun %d "
2596 printk(KERN_WARNING "scsi%d: warning: target bitmask %02x lun %d "
2597#ifdef SUPPORT_TAGS 2648#ifdef SUPPORT_TAGS
2598 "tag %d " 2649 "tag %d "
2599#endif 2650#endif
2600 "not in disconnected_queue.\n", 2651 "not in disconnected_queue.\n",
2601 HOSTNO, target_mask, lun 2652 HOSTNO, target_mask, lun
2602#ifdef SUPPORT_TAGS 2653#ifdef SUPPORT_TAGS
2603 , tag 2654 , tag
2604#endif 2655#endif
2605 ); 2656 );
2606 /* 2657 /*
2607 * Since we have an established nexus that we can't do anything 2658 * Since we have an established nexus that we can't do anything
2608 * with, we must abort it. 2659 * with, we must abort it.
2609 */ 2660 */
2610 do_abort(instance); 2661 do_abort(instance);
2611 return; 2662 return;
2612 } 2663 }
2613 2664
2614 /* Accept message by clearing ACK */ 2665 /* Accept message by clearing ACK */
2615 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2666 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2616 2667
2617 hostdata->connected = tmp; 2668 hostdata->connected = tmp;
2618 RSL_PRINTK("scsi%d: nexus established, target = %d, lun = %d, tag = %d\n", 2669 RSL_PRINTK("scsi%d: nexus established, target = %d, lun = %d, tag = %d\n",
2619 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag); 2670 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag);
2620 falcon_dont_release--; 2671 falcon_dont_release--;
2621} 2672}
2622 2673
2623 2674
@@ -2626,362 +2677,361 @@ static void NCR5380_reselect (struct Scsi_Host *instance)
2626 * 2677 *
2627 * Purpose : abort a command 2678 * Purpose : abort a command
2628 * 2679 *
2629 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the 2680 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the
2630 * host byte of the result field to, if zero DID_ABORTED is 2681 * host byte of the result field to, if zero DID_ABORTED is
2631 * used. 2682 * used.
2632 * 2683 *
2633 * Returns : 0 - success, -1 on failure. 2684 * Returns : 0 - success, -1 on failure.
2634 * 2685 *
2635 * XXX - there is no way to abort the command that is currently 2686 * XXX - there is no way to abort the command that is currently
2636 * connected, you have to wait for it to complete. If this is 2687 * connected, you have to wait for it to complete. If this is
2637 * a problem, we could implement longjmp() / setjmp(), setjmp() 2688 * a problem, we could implement longjmp() / setjmp(), setjmp()
2638 * called where the loop started in NCR5380_main(). 2689 * called where the loop started in NCR5380_main().
2639 */ 2690 */
2640 2691
2641static 2692static
2642int NCR5380_abort (Scsi_Cmnd *cmd) 2693int NCR5380_abort(Scsi_Cmnd *cmd)
2643{ 2694{
2644 struct Scsi_Host *instance = cmd->device->host; 2695 struct Scsi_Host *instance = cmd->device->host;
2645 SETUP_HOSTDATA(instance); 2696 SETUP_HOSTDATA(instance);
2646 Scsi_Cmnd *tmp, **prev; 2697 Scsi_Cmnd *tmp, **prev;
2647 unsigned long flags; 2698 unsigned long flags;
2699
2700 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO);
2701 scsi_print_command(cmd);
2648 2702
2649 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO); 2703 NCR5380_print_status(instance);
2650 scsi_print_command(cmd);
2651 2704
2652 NCR5380_print_status (instance); 2705 local_irq_save(flags);
2653 2706
2654 local_irq_save(flags); 2707 if (!IS_A_TT() && !falcon_got_lock)
2655 2708 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_abort\n",
2656 if (!IS_A_TT() && !falcon_got_lock) 2709 HOSTNO);
2657 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_abort\n",
2658 HOSTNO);
2659 2710
2660 ABRT_PRINTK("scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO, 2711 ABRT_PRINTK("scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO,
2661 NCR5380_read(BUS_AND_STATUS_REG), 2712 NCR5380_read(BUS_AND_STATUS_REG),
2662 NCR5380_read(STATUS_REG)); 2713 NCR5380_read(STATUS_REG));
2663 2714
2664#if 1 2715#if 1
2665/* 2716 /*
2666 * Case 1 : If the command is the currently executing command, 2717 * Case 1 : If the command is the currently executing command,
2667 * we'll set the aborted flag and return control so that 2718 * we'll set the aborted flag and return control so that
2668 * information transfer routine can exit cleanly. 2719 * information transfer routine can exit cleanly.
2669 */ 2720 */
2670 2721
2671 if (hostdata->connected == cmd) { 2722 if (hostdata->connected == cmd) {
2672 2723
2673 ABRT_PRINTK("scsi%d: aborting connected command\n", HOSTNO); 2724 ABRT_PRINTK("scsi%d: aborting connected command\n", HOSTNO);
2674/* 2725 /*
2675 * We should perform BSY checking, and make sure we haven't slipped 2726 * We should perform BSY checking, and make sure we haven't slipped
2676 * into BUS FREE. 2727 * into BUS FREE.
2677 */ 2728 */
2678 2729
2679/* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */ 2730 /* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */
2680/* 2731 /*
2681 * Since we can't change phases until we've completed the current 2732 * Since we can't change phases until we've completed the current
2682 * handshake, we have to source or sink a byte of data if the current 2733 * handshake, we have to source or sink a byte of data if the current
2683 * phase is not MSGOUT. 2734 * phase is not MSGOUT.
2684 */ 2735 */
2685 2736
2686/* 2737 /*
2687 * Return control to the executing NCR drive so we can clear the 2738 * Return control to the executing NCR drive so we can clear the
2688 * aborted flag and get back into our main loop. 2739 * aborted flag and get back into our main loop.
2689 */ 2740 */
2690 2741
2691 if (do_abort(instance) == 0) { 2742 if (do_abort(instance) == 0) {
2692 hostdata->aborted = 1; 2743 hostdata->aborted = 1;
2693 hostdata->connected = NULL; 2744 hostdata->connected = NULL;
2694 cmd->result = DID_ABORT << 16; 2745 cmd->result = DID_ABORT << 16;
2695#ifdef SUPPORT_TAGS 2746#ifdef SUPPORT_TAGS
2696 cmd_free_tag( cmd ); 2747 cmd_free_tag(cmd);
2697#else 2748#else
2698 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2749 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2699#endif 2750#endif
2700 local_irq_restore(flags); 2751 local_irq_restore(flags);
2701 cmd->scsi_done(cmd); 2752 cmd->scsi_done(cmd);
2702 falcon_release_lock_if_possible( hostdata ); 2753 falcon_release_lock_if_possible(hostdata);
2703 return SCSI_ABORT_SUCCESS; 2754 return SCSI_ABORT_SUCCESS;
2704 } else { 2755 } else {
2705/* local_irq_restore(flags); */ 2756/* local_irq_restore(flags); */
2706 printk("scsi%d: abort of connected command failed!\n", HOSTNO); 2757 printk("scsi%d: abort of connected command failed!\n", HOSTNO);
2707 return SCSI_ABORT_ERROR; 2758 return SCSI_ABORT_ERROR;
2708 } 2759 }
2709 } 2760 }
2710#endif 2761#endif
2711 2762
2712/* 2763 /*
2713 * Case 2 : If the command hasn't been issued yet, we simply remove it 2764 * Case 2 : If the command hasn't been issued yet, we simply remove it
2714 * from the issue queue. 2765 * from the issue queue.
2715 */ 2766 */
2716 for (prev = (Scsi_Cmnd **) &(hostdata->issue_queue), 2767 for (prev = (Scsi_Cmnd **)&(hostdata->issue_queue),
2717 tmp = (Scsi_Cmnd *) hostdata->issue_queue; 2768 tmp = (Scsi_Cmnd *)hostdata->issue_queue;
2718 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) ) 2769 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
2719 if (cmd == tmp) { 2770 if (cmd == tmp) {
2720 REMOVE(5, *prev, tmp, NEXT(tmp)); 2771 REMOVE(5, *prev, tmp, NEXT(tmp));
2721 (*prev) = NEXT(tmp); 2772 (*prev) = NEXT(tmp);
2722 NEXT(tmp) = NULL; 2773 SET_NEXT(tmp, NULL);
2723 tmp->result = DID_ABORT << 16; 2774 tmp->result = DID_ABORT << 16;
2724 local_irq_restore(flags); 2775 local_irq_restore(flags);
2725 ABRT_PRINTK("scsi%d: abort removed command from issue queue.\n", 2776 ABRT_PRINTK("scsi%d: abort removed command from issue queue.\n",
2726 HOSTNO); 2777 HOSTNO);
2727 /* Tagged queuing note: no tag to free here, hasn't been assigned 2778 /* Tagged queuing note: no tag to free here, hasn't been assigned
2728 * yet... */ 2779 * yet... */
2729 tmp->scsi_done(tmp); 2780 tmp->scsi_done(tmp);
2730 falcon_release_lock_if_possible( hostdata ); 2781 falcon_release_lock_if_possible(hostdata);
2731 return SCSI_ABORT_SUCCESS; 2782 return SCSI_ABORT_SUCCESS;
2783 }
2732 } 2784 }
2733 2785
2734/* 2786 /*
2735 * Case 3 : If any commands are connected, we're going to fail the abort 2787 * Case 3 : If any commands are connected, we're going to fail the abort
2736 * and let the high level SCSI driver retry at a later time or 2788 * and let the high level SCSI driver retry at a later time or
2737 * issue a reset. 2789 * issue a reset.
2738 * 2790 *
2739 * Timeouts, and therefore aborted commands, will be highly unlikely 2791 * Timeouts, and therefore aborted commands, will be highly unlikely
2740 * and handling them cleanly in this situation would make the common 2792 * and handling them cleanly in this situation would make the common
2741 * case of noresets less efficient, and would pollute our code. So, 2793 * case of noresets less efficient, and would pollute our code. So,
2742 * we fail. 2794 * we fail.
2743 */ 2795 */
2744 2796
2745 if (hostdata->connected) { 2797 if (hostdata->connected) {
2746 local_irq_restore(flags); 2798 local_irq_restore(flags);
2747 ABRT_PRINTK("scsi%d: abort failed, command connected.\n", HOSTNO); 2799 ABRT_PRINTK("scsi%d: abort failed, command connected.\n", HOSTNO);
2748 return SCSI_ABORT_SNOOZE; 2800 return SCSI_ABORT_SNOOZE;
2749 } 2801 }
2750 2802
2751/* 2803 /*
2752 * Case 4: If the command is currently disconnected from the bus, and 2804 * Case 4: If the command is currently disconnected from the bus, and
2753 * there are no connected commands, we reconnect the I_T_L or 2805 * there are no connected commands, we reconnect the I_T_L or
2754 * I_T_L_Q nexus associated with it, go into message out, and send 2806 * I_T_L_Q nexus associated with it, go into message out, and send
2755 * an abort message. 2807 * an abort message.
2756 * 2808 *
2757 * This case is especially ugly. In order to reestablish the nexus, we 2809 * This case is especially ugly. In order to reestablish the nexus, we
2758 * need to call NCR5380_select(). The easiest way to implement this 2810 * need to call NCR5380_select(). The easiest way to implement this
2759 * function was to abort if the bus was busy, and let the interrupt 2811 * function was to abort if the bus was busy, and let the interrupt
2760 * handler triggered on the SEL for reselect take care of lost arbitrations 2812 * handler triggered on the SEL for reselect take care of lost arbitrations
2761 * where necessary, meaning interrupts need to be enabled. 2813 * where necessary, meaning interrupts need to be enabled.
2762 * 2814 *
2763 * When interrupts are enabled, the queues may change - so we 2815 * When interrupts are enabled, the queues may change - so we
2764 * can't remove it from the disconnected queue before selecting it 2816 * can't remove it from the disconnected queue before selecting it
2765 * because that could cause a failure in hashing the nexus if that 2817 * because that could cause a failure in hashing the nexus if that
2766 * device reselected. 2818 * device reselected.
2767 * 2819 *
2768 * Since the queues may change, we can't use the pointers from when we 2820 * Since the queues may change, we can't use the pointers from when we
2769 * first locate it. 2821 * first locate it.
2770 * 2822 *
2771 * So, we must first locate the command, and if NCR5380_select() 2823 * So, we must first locate the command, and if NCR5380_select()
2772 * succeeds, then issue the abort, relocate the command and remove 2824 * succeeds, then issue the abort, relocate the command and remove
2773 * it from the disconnected queue. 2825 * it from the disconnected queue.
2774 */ 2826 */
2827
2828 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp;
2829 tmp = NEXT(tmp)) {
2830 if (cmd == tmp) {
2831 local_irq_restore(flags);
2832 ABRT_PRINTK("scsi%d: aborting disconnected command.\n", HOSTNO);
2775 2833
2776 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp; 2834 if (NCR5380_select(instance, cmd, (int)cmd->tag))
2777 tmp = NEXT(tmp)) 2835 return SCSI_ABORT_BUSY;
2778 if (cmd == tmp) { 2836
2779 local_irq_restore(flags); 2837 ABRT_PRINTK("scsi%d: nexus reestablished.\n", HOSTNO);
2780 ABRT_PRINTK("scsi%d: aborting disconnected command.\n", HOSTNO); 2838
2781 2839 do_abort(instance);
2782 if (NCR5380_select (instance, cmd, (int) cmd->tag)) 2840
2783 return SCSI_ABORT_BUSY; 2841 local_irq_save(flags);
2784 2842 for (prev = (Scsi_Cmnd **)&(hostdata->disconnected_queue),
2785 ABRT_PRINTK("scsi%d: nexus reestablished.\n", HOSTNO); 2843 tmp = (Scsi_Cmnd *)hostdata->disconnected_queue;
2786 2844 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
2787 do_abort (instance); 2845 if (cmd == tmp) {
2788 2846 REMOVE(5, *prev, tmp, NEXT(tmp));
2789 local_irq_save(flags); 2847 *prev = NEXT(tmp);
2790 for (prev = (Scsi_Cmnd **) &(hostdata->disconnected_queue), 2848 SET_NEXT(tmp, NULL);
2791 tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; 2849 tmp->result = DID_ABORT << 16;
2792 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) ) 2850 /* We must unlock the tag/LUN immediately here, since the
2793 if (cmd == tmp) { 2851 * target goes to BUS FREE and doesn't send us another
2794 REMOVE(5, *prev, tmp, NEXT(tmp)); 2852 * message (COMMAND_COMPLETE or the like)
2795 *prev = NEXT(tmp); 2853 */
2796 NEXT(tmp) = NULL;
2797 tmp->result = DID_ABORT << 16;
2798 /* We must unlock the tag/LUN immediately here, since the
2799 * target goes to BUS FREE and doesn't send us another
2800 * message (COMMAND_COMPLETE or the like)
2801 */
2802#ifdef SUPPORT_TAGS 2854#ifdef SUPPORT_TAGS
2803 cmd_free_tag( tmp ); 2855 cmd_free_tag(tmp);
2804#else 2856#else
2805 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2857 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2806#endif 2858#endif
2807 local_irq_restore(flags); 2859 local_irq_restore(flags);
2808 tmp->scsi_done(tmp); 2860 tmp->scsi_done(tmp);
2809 falcon_release_lock_if_possible( hostdata ); 2861 falcon_release_lock_if_possible(hostdata);
2810 return SCSI_ABORT_SUCCESS; 2862 return SCSI_ABORT_SUCCESS;
2863 }
2864 }
2811 } 2865 }
2812 } 2866 }
2813 2867
2814/* 2868 /*
2815 * Case 5 : If we reached this point, the command was not found in any of 2869 * Case 5 : If we reached this point, the command was not found in any of
2816 * the queues. 2870 * the queues.
2817 * 2871 *
2818 * We probably reached this point because of an unlikely race condition 2872 * We probably reached this point because of an unlikely race condition
2819 * between the command completing successfully and the abortion code, 2873 * between the command completing successfully and the abortion code,
2820 * so we won't panic, but we will notify the user in case something really 2874 * so we won't panic, but we will notify the user in case something really
2821 * broke. 2875 * broke.
2822 */ 2876 */
2823 2877
2824 local_irq_restore(flags); 2878 local_irq_restore(flags);
2825 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully\n" 2879 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully\n"
2826 KERN_INFO " before abortion\n", HOSTNO); 2880 KERN_INFO " before abortion\n", HOSTNO);
2827 2881
2828/* Maybe it is sufficient just to release the ST-DMA lock... (if 2882 /* Maybe it is sufficient just to release the ST-DMA lock... (if
2829 * possible at all) At least, we should check if the lock could be 2883 * possible at all) At least, we should check if the lock could be
2830 * released after the abort, in case it is kept due to some bug. 2884 * released after the abort, in case it is kept due to some bug.
2831 */ 2885 */
2832 falcon_release_lock_if_possible( hostdata ); 2886 falcon_release_lock_if_possible(hostdata);
2833 2887
2834 return SCSI_ABORT_NOT_RUNNING; 2888 return SCSI_ABORT_NOT_RUNNING;
2835} 2889}
2836 2890
2837 2891
2838/* 2892/*
2839 * Function : int NCR5380_reset (Scsi_Cmnd *cmd) 2893 * Function : int NCR5380_reset (Scsi_Cmnd *cmd)
2840 * 2894 *
2841 * Purpose : reset the SCSI bus. 2895 * Purpose : reset the SCSI bus.
2842 * 2896 *
2843 * Returns : SCSI_RESET_WAKEUP 2897 * Returns : SCSI_RESET_WAKEUP
2844 * 2898 *
2845 */ 2899 */
2846 2900
2847static int NCR5380_bus_reset( Scsi_Cmnd *cmd) 2901static int NCR5380_bus_reset(Scsi_Cmnd *cmd)
2848{ 2902{
2849 SETUP_HOSTDATA(cmd->device->host); 2903 SETUP_HOSTDATA(cmd->device->host);
2850 int i; 2904 int i;
2851 unsigned long flags; 2905 unsigned long flags;
2852#if 1 2906#if 1
2853 Scsi_Cmnd *connected, *disconnected_queue; 2907 Scsi_Cmnd *connected, *disconnected_queue;
2854#endif 2908#endif
2855 2909
2856 if (!IS_A_TT() && !falcon_got_lock) 2910 if (!IS_A_TT() && !falcon_got_lock)
2857 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_reset\n", 2911 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_reset\n",
2858 H_NO(cmd) ); 2912 H_NO(cmd));
2859 2913
2860 NCR5380_print_status (cmd->device->host); 2914 NCR5380_print_status(cmd->device->host);
2861 2915
2862 /* get in phase */ 2916 /* get in phase */
2863 NCR5380_write( TARGET_COMMAND_REG, 2917 NCR5380_write(TARGET_COMMAND_REG,
2864 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) )); 2918 PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG)));
2865 /* assert RST */ 2919 /* assert RST */
2866 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST ); 2920 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
2867 udelay (40); 2921 udelay(40);
2868 /* reset NCR registers */ 2922 /* reset NCR registers */
2869 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); 2923 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2870 NCR5380_write( MODE_REG, MR_BASE ); 2924 NCR5380_write(MODE_REG, MR_BASE);
2871 NCR5380_write( TARGET_COMMAND_REG, 0 ); 2925 NCR5380_write(TARGET_COMMAND_REG, 0);
2872 NCR5380_write( SELECT_ENABLE_REG, 0 ); 2926 NCR5380_write(SELECT_ENABLE_REG, 0);
2873 /* ++roman: reset interrupt condition! otherwise no interrupts don't get 2927 /* ++roman: reset interrupt condition! otherwise no interrupts don't get
2874 * through anymore ... */ 2928 * through anymore ... */
2875 (void)NCR5380_read( RESET_PARITY_INTERRUPT_REG ); 2929 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
2876 2930
2877#if 1 /* XXX Should now be done by midlevel code, but it's broken XXX */ 2931#if 1 /* XXX Should now be done by midlevel code, but it's broken XXX */
2878 /* XXX see below XXX */ 2932 /* XXX see below XXX */
2879 2933
2880 /* MSch: old-style reset: actually abort all command processing here */ 2934 /* MSch: old-style reset: actually abort all command processing here */
2881 2935
2882 /* After the reset, there are no more connected or disconnected commands 2936 /* After the reset, there are no more connected or disconnected commands
2883 * and no busy units; to avoid problems with re-inserting the commands 2937 * and no busy units; to avoid problems with re-inserting the commands
2884 * into the issue_queue (via scsi_done()), the aborted commands are 2938 * into the issue_queue (via scsi_done()), the aborted commands are
2885 * remembered in local variables first. 2939 * remembered in local variables first.
2886 */ 2940 */
2887 local_irq_save(flags); 2941 local_irq_save(flags);
2888 connected = (Scsi_Cmnd *)hostdata->connected; 2942 connected = (Scsi_Cmnd *)hostdata->connected;
2889 hostdata->connected = NULL; 2943 hostdata->connected = NULL;
2890 disconnected_queue = (Scsi_Cmnd *)hostdata->disconnected_queue; 2944 disconnected_queue = (Scsi_Cmnd *)hostdata->disconnected_queue;
2891 hostdata->disconnected_queue = NULL; 2945 hostdata->disconnected_queue = NULL;
2892#ifdef SUPPORT_TAGS 2946#ifdef SUPPORT_TAGS
2893 free_all_tags(); 2947 free_all_tags();
2894#endif 2948#endif
2895 for( i = 0; i < 8; ++i ) 2949 for (i = 0; i < 8; ++i)
2896 hostdata->busy[i] = 0; 2950 hostdata->busy[i] = 0;
2897#ifdef REAL_DMA 2951#ifdef REAL_DMA
2898 hostdata->dma_len = 0; 2952 hostdata->dma_len = 0;
2899#endif 2953#endif
2900 local_irq_restore(flags); 2954 local_irq_restore(flags);
2901 2955
2902 /* In order to tell the mid-level code which commands were aborted, 2956 /* In order to tell the mid-level code which commands were aborted,
2903 * set the command status to DID_RESET and call scsi_done() !!! 2957 * set the command status to DID_RESET and call scsi_done() !!!
2904 * This ultimately aborts processing of these commands in the mid-level. 2958 * This ultimately aborts processing of these commands in the mid-level.
2905 */ 2959 */
2906 2960
2907 if ((cmd = connected)) { 2961 if ((cmd = connected)) {
2908 ABRT_PRINTK("scsi%d: reset aborted a connected command\n", H_NO(cmd)); 2962 ABRT_PRINTK("scsi%d: reset aborted a connected command\n", H_NO(cmd));
2909 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16); 2963 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2910 cmd->scsi_done( cmd ); 2964 cmd->scsi_done(cmd);
2911 } 2965 }
2912
2913 for (i = 0; (cmd = disconnected_queue); ++i) {
2914 disconnected_queue = NEXT(cmd);
2915 NEXT(cmd) = NULL;
2916 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2917 cmd->scsi_done( cmd );
2918 }
2919 if (i > 0)
2920 ABRT_PRINTK("scsi: reset aborted %d disconnected command(s)\n", i);
2921
2922/* The Falcon lock should be released after a reset...
2923 */
2924/* ++guenther: moved to atari_scsi_reset(), to prevent a race between
2925 * unlocking and enabling dma interrupt.
2926 */
2927/* falcon_release_lock_if_possible( hostdata );*/
2928 2966
2929 /* since all commands have been explicitly terminated, we need to tell 2967 for (i = 0; (cmd = disconnected_queue); ++i) {
2930 * the midlevel code that the reset was SUCCESSFUL, and there is no 2968 disconnected_queue = NEXT(cmd);
2931 * need to 'wake up' the commands by a request_sense 2969 SET_NEXT(cmd, NULL);
2932 */ 2970 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2933 return SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET; 2971 cmd->scsi_done(cmd);
2972 }
2973 if (i > 0)
2974 ABRT_PRINTK("scsi: reset aborted %d disconnected command(s)\n", i);
2975
2976 /* The Falcon lock should be released after a reset...
2977 */
2978 /* ++guenther: moved to atari_scsi_reset(), to prevent a race between
2979 * unlocking and enabling dma interrupt.
2980 */
2981/* falcon_release_lock_if_possible( hostdata );*/
2982
2983 /* since all commands have been explicitly terminated, we need to tell
2984 * the midlevel code that the reset was SUCCESSFUL, and there is no
2985 * need to 'wake up' the commands by a request_sense
2986 */
2987 return SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET;
2934#else /* 1 */ 2988#else /* 1 */
2935 2989
2936 /* MSch: new-style reset handling: let the mid-level do what it can */ 2990 /* MSch: new-style reset handling: let the mid-level do what it can */
2937 2991
2938 /* ++guenther: MID-LEVEL IS STILL BROKEN. 2992 /* ++guenther: MID-LEVEL IS STILL BROKEN.
2939 * Mid-level is supposed to requeue all commands that were active on the 2993 * Mid-level is supposed to requeue all commands that were active on the
2940 * various low-level queues. In fact it does this, but that's not enough 2994 * various low-level queues. In fact it does this, but that's not enough
2941 * because all these commands are subject to timeout. And if a timeout 2995 * because all these commands are subject to timeout. And if a timeout
2942 * happens for any removed command, *_abort() is called but all queues 2996 * happens for any removed command, *_abort() is called but all queues
2943 * are now empty. Abort then gives up the falcon lock, which is fatal, 2997 * are now empty. Abort then gives up the falcon lock, which is fatal,
2944 * since the mid-level will queue more commands and must have the lock 2998 * since the mid-level will queue more commands and must have the lock
2945 * (it's all happening inside timer interrupt handler!!). 2999 * (it's all happening inside timer interrupt handler!!).
2946 * Even worse, abort will return NOT_RUNNING for all those commands not 3000 * Even worse, abort will return NOT_RUNNING for all those commands not
2947 * on any queue, so they won't be retried ... 3001 * on any queue, so they won't be retried ...
2948 * 3002 *
2949 * Conclusion: either scsi.c disables timeout for all resetted commands 3003 * Conclusion: either scsi.c disables timeout for all resetted commands
2950 * immediately, or we lose! As of linux-2.0.20 it doesn't. 3004 * immediately, or we lose! As of linux-2.0.20 it doesn't.
2951 */ 3005 */
2952 3006
2953 /* After the reset, there are no more connected or disconnected commands 3007 /* After the reset, there are no more connected or disconnected commands
2954 * and no busy units; so clear the low-level status here to avoid 3008 * and no busy units; so clear the low-level status here to avoid
2955 * conflicts when the mid-level code tries to wake up the affected 3009 * conflicts when the mid-level code tries to wake up the affected
2956 * commands! 3010 * commands!
2957 */ 3011 */
2958 3012
2959 if (hostdata->issue_queue) 3013 if (hostdata->issue_queue)
2960 ABRT_PRINTK("scsi%d: reset aborted issued command(s)\n", H_NO(cmd)); 3014 ABRT_PRINTK("scsi%d: reset aborted issued command(s)\n", H_NO(cmd));
2961 if (hostdata->connected) 3015 if (hostdata->connected)
2962 ABRT_PRINTK("scsi%d: reset aborted a connected command\n", H_NO(cmd)); 3016 ABRT_PRINTK("scsi%d: reset aborted a connected command\n", H_NO(cmd));
2963 if (hostdata->disconnected_queue) 3017 if (hostdata->disconnected_queue)
2964 ABRT_PRINTK("scsi%d: reset aborted disconnected command(s)\n", H_NO(cmd)); 3018 ABRT_PRINTK("scsi%d: reset aborted disconnected command(s)\n", H_NO(cmd));
2965 3019
2966 local_irq_save(flags); 3020 local_irq_save(flags);
2967 hostdata->issue_queue = NULL; 3021 hostdata->issue_queue = NULL;
2968 hostdata->connected = NULL; 3022 hostdata->connected = NULL;
2969 hostdata->disconnected_queue = NULL; 3023 hostdata->disconnected_queue = NULL;
2970#ifdef SUPPORT_TAGS 3024#ifdef SUPPORT_TAGS
2971 free_all_tags(); 3025 free_all_tags();
2972#endif 3026#endif
2973 for( i = 0; i < 8; ++i ) 3027 for (i = 0; i < 8; ++i)
2974 hostdata->busy[i] = 0; 3028 hostdata->busy[i] = 0;
2975#ifdef REAL_DMA 3029#ifdef REAL_DMA
2976 hostdata->dma_len = 0; 3030 hostdata->dma_len = 0;
2977#endif 3031#endif
2978 local_irq_restore(flags); 3032 local_irq_restore(flags);
2979 3033
2980 /* we did no complete reset of all commands, so a wakeup is required */ 3034 /* we did no complete reset of all commands, so a wakeup is required */
2981 return SCSI_RESET_WAKEUP | SCSI_RESET_BUS_RESET; 3035 return SCSI_RESET_WAKEUP | SCSI_RESET_BUS_RESET;
2982#endif /* 1 */ 3036#endif /* 1 */
2983} 3037}
2984
2985/* Local Variables: */
2986/* tab-width: 8 */
2987/* End: */
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index 642de7b2b7a2..6f8403b82ba1 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -69,9 +69,9 @@
69 69
70#define NDEBUG (0) 70#define NDEBUG (0)
71 71
72#define NDEBUG_ABORT 0x800000 72#define NDEBUG_ABORT 0x00100000
73#define NDEBUG_TAGS 0x1000000 73#define NDEBUG_TAGS 0x00200000
74#define NDEBUG_MERGING 0x2000000 74#define NDEBUG_MERGING 0x00400000
75 75
76#define AUTOSENSE 76#define AUTOSENSE
77/* For the Atari version, use only polled IO or REAL_DMA */ 77/* For the Atari version, use only polled IO or REAL_DMA */
@@ -186,38 +186,37 @@ static inline void DISABLE_IRQ(void)
186/***************************** Prototypes *****************************/ 186/***************************** Prototypes *****************************/
187 187
188#ifdef REAL_DMA 188#ifdef REAL_DMA
189static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ); 189static int scsi_dma_is_ignored_buserr(unsigned char dma_stat);
190static void atari_scsi_fetch_restbytes( void ); 190static void atari_scsi_fetch_restbytes(void);
191static long atari_scsi_dma_residual( struct Scsi_Host *instance ); 191static long atari_scsi_dma_residual(struct Scsi_Host *instance);
192static int falcon_classify_cmd( Scsi_Cmnd *cmd ); 192static int falcon_classify_cmd(Scsi_Cmnd *cmd);
193static unsigned long atari_dma_xfer_len( unsigned long wanted_len, 193static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
194 Scsi_Cmnd *cmd, int write_flag ); 194 Scsi_Cmnd *cmd, int write_flag);
195#endif 195#endif
196static irqreturn_t scsi_tt_intr( int irq, void *dummy); 196static irqreturn_t scsi_tt_intr(int irq, void *dummy);
197static irqreturn_t scsi_falcon_intr( int irq, void *dummy); 197static irqreturn_t scsi_falcon_intr(int irq, void *dummy);
198static void falcon_release_lock_if_possible( struct NCR5380_hostdata * 198static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata);
199 hostdata ); 199static void falcon_get_lock(void);
200static void falcon_get_lock( void );
201#ifdef CONFIG_ATARI_SCSI_RESET_BOOT 200#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
202static void atari_scsi_reset_boot( void ); 201static void atari_scsi_reset_boot(void);
203#endif 202#endif
204static unsigned char atari_scsi_tt_reg_read( unsigned char reg ); 203static unsigned char atari_scsi_tt_reg_read(unsigned char reg);
205static void atari_scsi_tt_reg_write( unsigned char reg, unsigned char value); 204static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value);
206static unsigned char atari_scsi_falcon_reg_read( unsigned char reg ); 205static unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
207static void atari_scsi_falcon_reg_write( unsigned char reg, unsigned char value ); 206static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value);
208 207
209/************************* End of Prototypes **************************/ 208/************************* End of Prototypes **************************/
210 209
211 210
212static struct Scsi_Host *atari_scsi_host = NULL; 211static struct Scsi_Host *atari_scsi_host;
213static unsigned char (*atari_scsi_reg_read)( unsigned char reg ); 212static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
214static void (*atari_scsi_reg_write)( unsigned char reg, unsigned char value ); 213static void (*atari_scsi_reg_write)(unsigned char reg, unsigned char value);
215 214
216#ifdef REAL_DMA 215#ifdef REAL_DMA
217static unsigned long atari_dma_residual, atari_dma_startaddr; 216static unsigned long atari_dma_residual, atari_dma_startaddr;
218static short atari_dma_active; 217static short atari_dma_active;
219/* pointer to the dribble buffer */ 218/* pointer to the dribble buffer */
220static char *atari_dma_buffer = NULL; 219static char *atari_dma_buffer;
221/* precalculated physical address of the dribble buffer */ 220/* precalculated physical address of the dribble buffer */
222static unsigned long atari_dma_phys_buffer; 221static unsigned long atari_dma_phys_buffer;
223/* != 0 tells the Falcon int handler to copy data from the dribble buffer */ 222/* != 0 tells the Falcon int handler to copy data from the dribble buffer */
@@ -233,7 +232,7 @@ static char *atari_dma_orig_addr;
233static unsigned long atari_dma_stram_mask; 232static unsigned long atari_dma_stram_mask;
234#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0) 233#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0)
235/* number of bytes to cut from a transfer to handle NCR overruns */ 234/* number of bytes to cut from a transfer to handle NCR overruns */
236static int atari_read_overruns = 0; 235static int atari_read_overruns;
237#endif 236#endif
238 237
239static int setup_can_queue = -1; 238static int setup_can_queue = -1;
@@ -256,10 +255,10 @@ module_param(setup_hostid, int, 0);
256 255
257#if defined(REAL_DMA) 256#if defined(REAL_DMA)
258 257
259static int scsi_dma_is_ignored_buserr( unsigned char dma_stat ) 258static int scsi_dma_is_ignored_buserr(unsigned char dma_stat)
260{ 259{
261 int i; 260 int i;
262 unsigned long addr = SCSI_DMA_READ_P( dma_addr ), end_addr; 261 unsigned long addr = SCSI_DMA_READ_P(dma_addr), end_addr;
263 262
264 if (dma_stat & 0x01) { 263 if (dma_stat & 0x01) {
265 264
@@ -267,15 +266,14 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat )
267 * physical memory chunk (DMA prefetch!), but that doesn't hurt. 266 * physical memory chunk (DMA prefetch!), but that doesn't hurt.
268 * Check for this case: 267 * Check for this case:
269 */ 268 */
270 269
271 for( i = 0; i < m68k_num_memory; ++i ) { 270 for (i = 0; i < m68k_num_memory; ++i) {
272 end_addr = m68k_memory[i].addr + 271 end_addr = m68k_memory[i].addr + m68k_memory[i].size;
273 m68k_memory[i].size;
274 if (end_addr <= addr && addr <= end_addr + 4) 272 if (end_addr <= addr && addr <= end_addr + 4)
275 return( 1 ); 273 return 1;
276 } 274 }
277 } 275 }
278 return( 0 ); 276 return 0;
279} 277}
280 278
281 279
@@ -284,28 +282,27 @@ static int scsi_dma_is_ignored_buserr( unsigned char dma_stat )
284 * end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has 282 * end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has
285 * to clear the DMA int pending bit before it allows other level 6 interrupts. 283 * to clear the DMA int pending bit before it allows other level 6 interrupts.
286 */ 284 */
287static void scsi_dma_buserr (int irq, void *dummy) 285static void scsi_dma_buserr(int irq, void *dummy)
288{ 286{
289 unsigned char dma_stat = tt_scsi_dma.dma_ctrl; 287 unsigned char dma_stat = tt_scsi_dma.dma_ctrl;
290 288
291 /* Don't do anything if a NCR interrupt is pending. Probably it's just 289 /* Don't do anything if a NCR interrupt is pending. Probably it's just
292 * masked... */ 290 * masked... */
293 if (atari_irq_pending( IRQ_TT_MFP_SCSI )) 291 if (atari_irq_pending(IRQ_TT_MFP_SCSI))
294 return; 292 return;
295 293
296 printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n", 294 printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n",
297 SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt)); 295 SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt));
298 if (dma_stat & 0x80) { 296 if (dma_stat & 0x80) {
299 if (!scsi_dma_is_ignored_buserr( dma_stat )) 297 if (!scsi_dma_is_ignored_buserr(dma_stat))
300 printk( "SCSI DMA bus error -- bad DMA programming!\n" ); 298 printk("SCSI DMA bus error -- bad DMA programming!\n");
301 } 299 } else {
302 else {
303 /* Under normal circumstances we never should get to this point, 300 /* Under normal circumstances we never should get to this point,
304 * since both interrupts are triggered simultaneously and the 5380 301 * since both interrupts are triggered simultaneously and the 5380
305 * int has higher priority. When this irq is handled, that DMA 302 * int has higher priority. When this irq is handled, that DMA
306 * interrupt is cleared. So a warning message is printed here. 303 * interrupt is cleared. So a warning message is printed here.
307 */ 304 */
308 printk( "SCSI DMA intr ?? -- this shouldn't happen!\n" ); 305 printk("SCSI DMA intr ?? -- this shouldn't happen!\n");
309 } 306 }
310} 307}
311#endif 308#endif
@@ -313,7 +310,7 @@ static void scsi_dma_buserr (int irq, void *dummy)
313#endif 310#endif
314 311
315 312
316static irqreturn_t scsi_tt_intr (int irq, void *dummy) 313static irqreturn_t scsi_tt_intr(int irq, void *dummy)
317{ 314{
318#ifdef REAL_DMA 315#ifdef REAL_DMA
319 int dma_stat; 316 int dma_stat;
@@ -327,7 +324,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
327 * is that a bus error occurred... 324 * is that a bus error occurred...
328 */ 325 */
329 if (dma_stat & 0x80) { 326 if (dma_stat & 0x80) {
330 if (!scsi_dma_is_ignored_buserr( dma_stat )) { 327 if (!scsi_dma_is_ignored_buserr(dma_stat)) {
331 printk(KERN_ERR "SCSI DMA caused bus error near 0x%08lx\n", 328 printk(KERN_ERR "SCSI DMA caused bus error near 0x%08lx\n",
332 SCSI_DMA_READ_P(dma_addr)); 329 SCSI_DMA_READ_P(dma_addr));
333 printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!"); 330 printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!");
@@ -344,8 +341,7 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
344 * data reg! 341 * data reg!
345 */ 342 */
346 if ((dma_stat & 0x02) && !(dma_stat & 0x40)) { 343 if ((dma_stat & 0x02) && !(dma_stat & 0x40)) {
347 atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P( dma_addr ) - 344 atari_dma_residual = HOSTDATA_DMALEN - (SCSI_DMA_READ_P(dma_addr) - atari_dma_startaddr);
348 atari_dma_startaddr);
349 345
350 DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n", 346 DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
351 atari_dma_residual); 347 atari_dma_residual);
@@ -353,28 +349,30 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
353 if ((signed int)atari_dma_residual < 0) 349 if ((signed int)atari_dma_residual < 0)
354 atari_dma_residual = 0; 350 atari_dma_residual = 0;
355 if ((dma_stat & 1) == 0) { 351 if ((dma_stat & 1) == 0) {
356 /* After read operations, we maybe have to 352 /*
357 transport some rest bytes */ 353 * After read operations, we maybe have to
354 * transport some rest bytes
355 */
358 atari_scsi_fetch_restbytes(); 356 atari_scsi_fetch_restbytes();
359 } 357 } else {
360 else { 358 /*
361 /* There seems to be a nasty bug in some SCSI-DMA/NCR 359 * There seems to be a nasty bug in some SCSI-DMA/NCR
362 combinations: If a target disconnects while a write 360 * combinations: If a target disconnects while a write
363 operation is going on, the address register of the 361 * operation is going on, the address register of the
364 DMA may be a few bytes farer than it actually read. 362 * DMA may be a few bytes farer than it actually read.
365 This is probably due to DMA prefetching and a delay 363 * This is probably due to DMA prefetching and a delay
366 between DMA and NCR. Experiments showed that the 364 * between DMA and NCR. Experiments showed that the
367 dma_addr is 9 bytes to high, but this could vary. 365 * dma_addr is 9 bytes to high, but this could vary.
368 The problem is, that the residual is thus calculated 366 * The problem is, that the residual is thus calculated
369 wrong and the next transfer will start behind where 367 * wrong and the next transfer will start behind where
370 it should. So we round up the residual to the next 368 * it should. So we round up the residual to the next
371 multiple of a sector size, if it isn't already a 369 * multiple of a sector size, if it isn't already a
372 multiple and the originally expected transfer size 370 * multiple and the originally expected transfer size
373 was. The latter condition is there to ensure that 371 * was. The latter condition is there to ensure that
374 the correction is taken only for "real" data 372 * the correction is taken only for "real" data
375 transfers and not for, e.g., the parameters of some 373 * transfers and not for, e.g., the parameters of some
376 other command. These shouldn't disconnect anyway. 374 * other command. These shouldn't disconnect anyway.
377 */ 375 */
378 if (atari_dma_residual & 0x1ff) { 376 if (atari_dma_residual & 0x1ff) {
379 DMA_PRINTK("SCSI DMA: DMA bug corrected, " 377 DMA_PRINTK("SCSI DMA: DMA bug corrected, "
380 "difference %ld bytes\n", 378 "difference %ld bytes\n",
@@ -394,18 +392,18 @@ static irqreturn_t scsi_tt_intr (int irq, void *dummy)
394 } 392 }
395 393
396#endif /* REAL_DMA */ 394#endif /* REAL_DMA */
397 395
398 NCR5380_intr (0, 0, 0); 396 NCR5380_intr(0, 0);
399 397
400#if 0 398#if 0
401 /* To be sure the int is not masked */ 399 /* To be sure the int is not masked */
402 atari_enable_irq( IRQ_TT_MFP_SCSI ); 400 atari_enable_irq(IRQ_TT_MFP_SCSI);
403#endif 401#endif
404 return IRQ_HANDLED; 402 return IRQ_HANDLED;
405} 403}
406 404
407 405
408static irqreturn_t scsi_falcon_intr (int irq, void *dummy) 406static irqreturn_t scsi_falcon_intr(int irq, void *dummy)
409{ 407{
410#ifdef REAL_DMA 408#ifdef REAL_DMA
411 int dma_stat; 409 int dma_stat;
@@ -430,7 +428,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
430 * bytes are stuck in the ST-DMA fifo (there's no way to reach them!) 428 * bytes are stuck in the ST-DMA fifo (there's no way to reach them!)
431 */ 429 */
432 if (atari_dma_active && (dma_stat & 0x02)) { 430 if (atari_dma_active && (dma_stat & 0x02)) {
433 unsigned long transferred; 431 unsigned long transferred;
434 432
435 transferred = SCSI_DMA_GETADR() - atari_dma_startaddr; 433 transferred = SCSI_DMA_GETADR() - atari_dma_startaddr;
436 /* The ST-DMA address is incremented in 2-byte steps, but the 434 /* The ST-DMA address is incremented in 2-byte steps, but the
@@ -445,8 +443,7 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
445 atari_dma_residual = HOSTDATA_DMALEN - transferred; 443 atari_dma_residual = HOSTDATA_DMALEN - transferred;
446 DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n", 444 DMA_PRINTK("SCSI DMA: There are %ld residual bytes.\n",
447 atari_dma_residual); 445 atari_dma_residual);
448 } 446 } else
449 else
450 atari_dma_residual = 0; 447 atari_dma_residual = 0;
451 atari_dma_active = 0; 448 atari_dma_active = 0;
452 449
@@ -461,13 +458,13 @@ static irqreturn_t scsi_falcon_intr (int irq, void *dummy)
461 458
462#endif /* REAL_DMA */ 459#endif /* REAL_DMA */
463 460
464 NCR5380_intr (0, 0, 0); 461 NCR5380_intr(0, 0);
465 return IRQ_HANDLED; 462 return IRQ_HANDLED;
466} 463}
467 464
468 465
469#ifdef REAL_DMA 466#ifdef REAL_DMA
470static void atari_scsi_fetch_restbytes( void ) 467static void atari_scsi_fetch_restbytes(void)
471{ 468{
472 int nr; 469 int nr;
473 char *src, *dst; 470 char *src, *dst;
@@ -505,19 +502,17 @@ static int falcon_dont_release = 0;
505 * again (but others waiting longer more probably will win). 502 * again (but others waiting longer more probably will win).
506 */ 503 */
507 504
508static void 505static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata)
509falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
510{ 506{
511 unsigned long flags; 507 unsigned long flags;
512 508
513 if (IS_A_TT()) return; 509 if (IS_A_TT())
514 510 return;
511
515 local_irq_save(flags); 512 local_irq_save(flags);
516 513
517 if (falcon_got_lock && 514 if (falcon_got_lock && !hostdata->disconnected_queue &&
518 !hostdata->disconnected_queue && 515 !hostdata->issue_queue && !hostdata->connected) {
519 !hostdata->issue_queue &&
520 !hostdata->connected) {
521 516
522 if (falcon_dont_release) { 517 if (falcon_dont_release) {
523#if 0 518#if 0
@@ -528,7 +523,7 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
528 } 523 }
529 falcon_got_lock = 0; 524 falcon_got_lock = 0;
530 stdma_release(); 525 stdma_release();
531 wake_up( &falcon_fairness_wait ); 526 wake_up(&falcon_fairness_wait);
532 } 527 }
533 528
534 local_irq_restore(flags); 529 local_irq_restore(flags);
@@ -549,31 +544,31 @@ falcon_release_lock_if_possible( struct NCR5380_hostdata * hostdata )
549 * Complicated, complicated.... Sigh... 544 * Complicated, complicated.... Sigh...
550 */ 545 */
551 546
552static void falcon_get_lock( void ) 547static void falcon_get_lock(void)
553{ 548{
554 unsigned long flags; 549 unsigned long flags;
555 550
556 if (IS_A_TT()) return; 551 if (IS_A_TT())
552 return;
557 553
558 local_irq_save(flags); 554 local_irq_save(flags);
559 555
560 while( !in_interrupt() && falcon_got_lock && stdma_others_waiting() ) 556 while (!in_irq() && falcon_got_lock && stdma_others_waiting())
561 sleep_on( &falcon_fairness_wait ); 557 sleep_on(&falcon_fairness_wait);
562 558
563 while (!falcon_got_lock) { 559 while (!falcon_got_lock) {
564 if (in_interrupt()) 560 if (in_irq())
565 panic( "Falcon SCSI hasn't ST-DMA lock in interrupt" ); 561 panic("Falcon SCSI hasn't ST-DMA lock in interrupt");
566 if (!falcon_trying_lock) { 562 if (!falcon_trying_lock) {
567 falcon_trying_lock = 1; 563 falcon_trying_lock = 1;
568 stdma_lock(scsi_falcon_intr, NULL); 564 stdma_lock(scsi_falcon_intr, NULL);
569 falcon_got_lock = 1; 565 falcon_got_lock = 1;
570 falcon_trying_lock = 0; 566 falcon_trying_lock = 0;
571 wake_up( &falcon_try_wait ); 567 wake_up(&falcon_try_wait);
572 } 568 } else {
573 else { 569 sleep_on(&falcon_try_wait);
574 sleep_on( &falcon_try_wait );
575 } 570 }
576 } 571 }
577 572
578 local_irq_restore(flags); 573 local_irq_restore(flags);
579 if (!falcon_got_lock) 574 if (!falcon_got_lock)
@@ -587,18 +582,18 @@ static void falcon_get_lock( void )
587 */ 582 */
588 583
589#if 0 584#if 0
590int atari_queue_command (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) 585int atari_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
591{ 586{
592 /* falcon_get_lock(); 587 /* falcon_get_lock();
593 * ++guenther: moved to NCR5380_queue_command() to prevent 588 * ++guenther: moved to NCR5380_queue_command() to prevent
594 * race condition, see there for an explanation. 589 * race condition, see there for an explanation.
595 */ 590 */
596 return( NCR5380_queue_command( cmd, done ) ); 591 return NCR5380_queue_command(cmd, done);
597} 592}
598#endif 593#endif
599 594
600 595
601int atari_scsi_detect (struct scsi_host_template *host) 596int atari_scsi_detect(struct scsi_host_template *host)
602{ 597{
603 static int called = 0; 598 static int called = 0;
604 struct Scsi_Host *instance; 599 struct Scsi_Host *instance;
@@ -606,7 +601,7 @@ int atari_scsi_detect (struct scsi_host_template *host)
606 if (!MACH_IS_ATARI || 601 if (!MACH_IS_ATARI ||
607 (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) || 602 (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
608 called) 603 called)
609 return( 0 ); 604 return 0;
610 605
611 host->proc_name = "Atari"; 606 host->proc_name = "Atari";
612 607
@@ -655,32 +650,33 @@ int atari_scsi_detect (struct scsi_host_template *host)
655 !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) { 650 !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
656 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI"); 651 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
657 if (!atari_dma_buffer) { 652 if (!atari_dma_buffer) {
658 printk( KERN_ERR "atari_scsi_detect: can't allocate ST-RAM " 653 printk(KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
659 "double buffer\n" ); 654 "double buffer\n");
660 return( 0 ); 655 return 0;
661 } 656 }
662 atari_dma_phys_buffer = virt_to_phys( atari_dma_buffer ); 657 atari_dma_phys_buffer = virt_to_phys(atari_dma_buffer);
663 atari_dma_orig_addr = 0; 658 atari_dma_orig_addr = 0;
664 } 659 }
665#endif 660#endif
666 instance = scsi_register (host, sizeof (struct NCR5380_hostdata)); 661 instance = scsi_register(host, sizeof(struct NCR5380_hostdata));
667 if(instance == NULL) 662 if (instance == NULL) {
668 {
669 atari_stram_free(atari_dma_buffer); 663 atari_stram_free(atari_dma_buffer);
670 atari_dma_buffer = 0; 664 atari_dma_buffer = 0;
671 return 0; 665 return 0;
672 } 666 }
673 atari_scsi_host = instance; 667 atari_scsi_host = instance;
674 /* Set irq to 0, to avoid that the mid-level code disables our interrupt 668 /*
675 * during queue_command calls. This is completely unnecessary, and even 669 * Set irq to 0, to avoid that the mid-level code disables our interrupt
676 * worse causes bad problems on the Falcon, where the int is shared with 670 * during queue_command calls. This is completely unnecessary, and even
677 * IDE and floppy! */ 671 * worse causes bad problems on the Falcon, where the int is shared with
672 * IDE and floppy!
673 */
678 instance->irq = 0; 674 instance->irq = 0;
679 675
680#ifdef CONFIG_ATARI_SCSI_RESET_BOOT 676#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
681 atari_scsi_reset_boot(); 677 atari_scsi_reset_boot();
682#endif 678#endif
683 NCR5380_init (instance, 0); 679 NCR5380_init(instance, 0);
684 680
685 if (IS_A_TT()) { 681 if (IS_A_TT()) {
686 682
@@ -727,11 +723,10 @@ int atari_scsi_detect (struct scsi_host_template *host)
727 * the rest data bug is fixed, this can be lowered to 1. 723 * the rest data bug is fixed, this can be lowered to 1.
728 */ 724 */
729 atari_read_overruns = 4; 725 atari_read_overruns = 4;
730 } 726 }
731#endif /*REAL_DMA*/ 727#endif /*REAL_DMA*/
732 } 728 } else { /* ! IS_A_TT */
733 else { /* ! IS_A_TT */ 729
734
735 /* Nothing to do for the interrupt: the ST-DMA is initialized 730 /* Nothing to do for the interrupt: the ST-DMA is initialized
736 * already by atari_init_INTS() 731 * already by atari_init_INTS()
737 */ 732 */
@@ -756,23 +751,21 @@ int atari_scsi_detect (struct scsi_host_template *host)
756 setup_use_tagged_queuing ? "yes" : "no", 751 setup_use_tagged_queuing ? "yes" : "no",
757#endif 752#endif
758 instance->hostt->this_id ); 753 instance->hostt->this_id );
759 NCR5380_print_options (instance); 754 NCR5380_print_options(instance);
760 printk ("\n"); 755 printk("\n");
761 756
762 called = 1; 757 called = 1;
763 return( 1 ); 758 return 1;
764} 759}
765 760
766#ifdef MODULE 761int atari_scsi_release(struct Scsi_Host *sh)
767int atari_scsi_release (struct Scsi_Host *sh)
768{ 762{
769 if (IS_A_TT()) 763 if (IS_A_TT())
770 free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr); 764 free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr);
771 if (atari_dma_buffer) 765 if (atari_dma_buffer)
772 atari_stram_free (atari_dma_buffer); 766 atari_stram_free(atari_dma_buffer);
773 return 1; 767 return 1;
774} 768}
775#endif
776 769
777void __init atari_scsi_setup(char *str, int *ints) 770void __init atari_scsi_setup(char *str, int *ints)
778{ 771{
@@ -781,9 +774,9 @@ void __init atari_scsi_setup(char *str, int *ints)
781 * Defaults depend on TT or Falcon, hostid determined at run time. 774 * Defaults depend on TT or Falcon, hostid determined at run time.
782 * Negative values mean don't change. 775 * Negative values mean don't change.
783 */ 776 */
784 777
785 if (ints[0] < 1) { 778 if (ints[0] < 1) {
786 printk( "atari_scsi_setup: no arguments!\n" ); 779 printk("atari_scsi_setup: no arguments!\n");
787 return; 780 return;
788 } 781 }
789 782
@@ -809,7 +802,7 @@ void __init atari_scsi_setup(char *str, int *ints)
809 if (ints[4] >= 0 && ints[4] <= 7) 802 if (ints[4] >= 0 && ints[4] <= 7)
810 setup_hostid = ints[4]; 803 setup_hostid = ints[4];
811 else if (ints[4] > 7) 804 else if (ints[4] > 7)
812 printk( "atari_scsi_setup: invalid host ID %d !\n", ints[4] ); 805 printk("atari_scsi_setup: invalid host ID %d !\n", ints[4]);
813 } 806 }
814#ifdef SUPPORT_TAGS 807#ifdef SUPPORT_TAGS
815 if (ints[0] >= 5) { 808 if (ints[0] >= 5) {
@@ -821,7 +814,7 @@ void __init atari_scsi_setup(char *str, int *ints)
821 814
822int atari_scsi_bus_reset(Scsi_Cmnd *cmd) 815int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
823{ 816{
824 int rv; 817 int rv;
825 struct NCR5380_hostdata *hostdata = 818 struct NCR5380_hostdata *hostdata =
826 (struct NCR5380_hostdata *)cmd->device->host->hostdata; 819 (struct NCR5380_hostdata *)cmd->device->host->hostdata;
827 820
@@ -831,13 +824,12 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
831 */ 824 */
832 /* And abort a maybe active DMA transfer */ 825 /* And abort a maybe active DMA transfer */
833 if (IS_A_TT()) { 826 if (IS_A_TT()) {
834 atari_turnoff_irq( IRQ_TT_MFP_SCSI ); 827 atari_turnoff_irq(IRQ_TT_MFP_SCSI);
835#ifdef REAL_DMA 828#ifdef REAL_DMA
836 tt_scsi_dma.dma_ctrl = 0; 829 tt_scsi_dma.dma_ctrl = 0;
837#endif /* REAL_DMA */ 830#endif /* REAL_DMA */
838 } 831 } else {
839 else { 832 atari_turnoff_irq(IRQ_MFP_FSCSI);
840 atari_turnoff_irq( IRQ_MFP_FSCSI );
841#ifdef REAL_DMA 833#ifdef REAL_DMA
842 st_dma.dma_mode_status = 0x90; 834 st_dma.dma_mode_status = 0x90;
843 atari_dma_active = 0; 835 atari_dma_active = 0;
@@ -849,52 +841,51 @@ int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
849 841
850 /* Re-enable ints */ 842 /* Re-enable ints */
851 if (IS_A_TT()) { 843 if (IS_A_TT()) {
852 atari_turnon_irq( IRQ_TT_MFP_SCSI ); 844 atari_turnon_irq(IRQ_TT_MFP_SCSI);
853 } 845 } else {
854 else { 846 atari_turnon_irq(IRQ_MFP_FSCSI);
855 atari_turnon_irq( IRQ_MFP_FSCSI );
856 } 847 }
857 if ((rv & SCSI_RESET_ACTION) == SCSI_RESET_SUCCESS) 848 if ((rv & SCSI_RESET_ACTION) == SCSI_RESET_SUCCESS)
858 falcon_release_lock_if_possible(hostdata); 849 falcon_release_lock_if_possible(hostdata);
859 850
860 return( rv ); 851 return rv;
861} 852}
862 853
863 854
864#ifdef CONFIG_ATARI_SCSI_RESET_BOOT 855#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
865static void __init atari_scsi_reset_boot(void) 856static void __init atari_scsi_reset_boot(void)
866{ 857{
867 unsigned long end; 858 unsigned long end;
868 859
869 /* 860 /*
870 * Do a SCSI reset to clean up the bus during initialization. No messing 861 * Do a SCSI reset to clean up the bus during initialization. No messing
871 * with the queues, interrupts, or locks necessary here. 862 * with the queues, interrupts, or locks necessary here.
872 */ 863 */
873 864
874 printk( "Atari SCSI: resetting the SCSI bus..." ); 865 printk("Atari SCSI: resetting the SCSI bus...");
875 866
876 /* get in phase */ 867 /* get in phase */
877 NCR5380_write( TARGET_COMMAND_REG, 868 NCR5380_write(TARGET_COMMAND_REG,
878 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) )); 869 PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG)));
879 870
880 /* assert RST */ 871 /* assert RST */
881 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST ); 872 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
882 /* The min. reset hold time is 25us, so 40us should be enough */ 873 /* The min. reset hold time is 25us, so 40us should be enough */
883 udelay( 50 ); 874 udelay(50);
884 /* reset RST and interrupt */ 875 /* reset RST and interrupt */
885 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); 876 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
886 NCR5380_read( RESET_PARITY_INTERRUPT_REG ); 877 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
887 878
888 end = jiffies + AFTER_RESET_DELAY; 879 end = jiffies + AFTER_RESET_DELAY;
889 while (time_before(jiffies, end)) 880 while (time_before(jiffies, end))
890 barrier(); 881 barrier();
891 882
892 printk( " done\n" ); 883 printk(" done\n");
893} 884}
894#endif 885#endif
895 886
896 887
897const char * atari_scsi_info (struct Scsi_Host *host) 888const char *atari_scsi_info(struct Scsi_Host *host)
898{ 889{
899 /* atari_scsi_detect() is verbose enough... */ 890 /* atari_scsi_detect() is verbose enough... */
900 static const char string[] = "Atari native SCSI"; 891 static const char string[] = "Atari native SCSI";
@@ -904,10 +895,10 @@ const char * atari_scsi_info (struct Scsi_Host *host)
904 895
905#if defined(REAL_DMA) 896#if defined(REAL_DMA)
906 897
907unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data, 898unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance, void *data,
908 unsigned long count, int dir ) 899 unsigned long count, int dir)
909{ 900{
910 unsigned long addr = virt_to_phys( data ); 901 unsigned long addr = virt_to_phys(data);
911 902
912 DMA_PRINTK("scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, " 903 DMA_PRINTK("scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, "
913 "dir = %d\n", instance->host_no, data, addr, count, dir); 904 "dir = %d\n", instance->host_no, data, addr, count, dir);
@@ -919,38 +910,37 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
919 * wanted address. 910 * wanted address.
920 */ 911 */
921 if (dir) 912 if (dir)
922 memcpy( atari_dma_buffer, data, count ); 913 memcpy(atari_dma_buffer, data, count);
923 else 914 else
924 atari_dma_orig_addr = data; 915 atari_dma_orig_addr = data;
925 addr = atari_dma_phys_buffer; 916 addr = atari_dma_phys_buffer;
926 } 917 }
927 918
928 atari_dma_startaddr = addr; /* Needed for calculating residual later. */ 919 atari_dma_startaddr = addr; /* Needed for calculating residual later. */
929 920
930 /* Cache cleanup stuff: On writes, push any dirty cache out before sending 921 /* Cache cleanup stuff: On writes, push any dirty cache out before sending
931 * it to the peripheral. (Must be done before DMA setup, since at least 922 * it to the peripheral. (Must be done before DMA setup, since at least
932 * the ST-DMA begins to fill internal buffers right after setup. For 923 * the ST-DMA begins to fill internal buffers right after setup. For
933 * reads, invalidate any cache, may be altered after DMA without CPU 924 * reads, invalidate any cache, may be altered after DMA without CPU
934 * knowledge. 925 * knowledge.
935 * 926 *
936 * ++roman: For the Medusa, there's no need at all for that cache stuff, 927 * ++roman: For the Medusa, there's no need at all for that cache stuff,
937 * because the hardware does bus snooping (fine!). 928 * because the hardware does bus snooping (fine!).
938 */ 929 */
939 dma_cache_maintenance( addr, count, dir ); 930 dma_cache_maintenance(addr, count, dir);
940 931
941 if (count == 0) 932 if (count == 0)
942 printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n"); 933 printk(KERN_NOTICE "SCSI warning: DMA programmed for 0 bytes !\n");
943 934
944 if (IS_A_TT()) { 935 if (IS_A_TT()) {
945 tt_scsi_dma.dma_ctrl = dir; 936 tt_scsi_dma.dma_ctrl = dir;
946 SCSI_DMA_WRITE_P( dma_addr, addr ); 937 SCSI_DMA_WRITE_P(dma_addr, addr);
947 SCSI_DMA_WRITE_P( dma_cnt, count ); 938 SCSI_DMA_WRITE_P(dma_cnt, count);
948 tt_scsi_dma.dma_ctrl = dir | 2; 939 tt_scsi_dma.dma_ctrl = dir | 2;
949 } 940 } else { /* ! IS_A_TT */
950 else { /* ! IS_A_TT */ 941
951
952 /* set address */ 942 /* set address */
953 SCSI_DMA_SETADR( addr ); 943 SCSI_DMA_SETADR(addr);
954 944
955 /* toggle direction bit to clear FIFO and set DMA direction */ 945 /* toggle direction bit to clear FIFO and set DMA direction */
956 dir <<= 8; 946 dir <<= 8;
@@ -968,13 +958,13 @@ unsigned long atari_scsi_dma_setup( struct Scsi_Host *instance, void *data,
968 atari_dma_active = 1; 958 atari_dma_active = 1;
969 } 959 }
970 960
971 return( count ); 961 return count;
972} 962}
973 963
974 964
975static long atari_scsi_dma_residual( struct Scsi_Host *instance ) 965static long atari_scsi_dma_residual(struct Scsi_Host *instance)
976{ 966{
977 return( atari_dma_residual ); 967 return atari_dma_residual;
978} 968}
979 969
980 970
@@ -982,13 +972,13 @@ static long atari_scsi_dma_residual( struct Scsi_Host *instance )
982#define CMD_SURELY_BYTE_MODE 1 972#define CMD_SURELY_BYTE_MODE 1
983#define CMD_MODE_UNKNOWN 2 973#define CMD_MODE_UNKNOWN 2
984 974
985static int falcon_classify_cmd( Scsi_Cmnd *cmd ) 975static int falcon_classify_cmd(Scsi_Cmnd *cmd)
986{ 976{
987 unsigned char opcode = cmd->cmnd[0]; 977 unsigned char opcode = cmd->cmnd[0];
988 978
989 if (opcode == READ_DEFECT_DATA || opcode == READ_LONG || 979 if (opcode == READ_DEFECT_DATA || opcode == READ_LONG ||
990 opcode == READ_BUFFER) 980 opcode == READ_BUFFER)
991 return( CMD_SURELY_BYTE_MODE ); 981 return CMD_SURELY_BYTE_MODE;
992 else if (opcode == READ_6 || opcode == READ_10 || 982 else if (opcode == READ_6 || opcode == READ_10 ||
993 opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE || 983 opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE ||
994 opcode == RECOVER_BUFFERED_DATA) { 984 opcode == RECOVER_BUFFERED_DATA) {
@@ -996,12 +986,11 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd )
996 * needed here: The transfer is block-mode only if the 'fixed' bit is 986 * needed here: The transfer is block-mode only if the 'fixed' bit is
997 * set! */ 987 * set! */
998 if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1)) 988 if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1))
999 return( CMD_SURELY_BYTE_MODE ); 989 return CMD_SURELY_BYTE_MODE;
1000 else 990 else
1001 return( CMD_SURELY_BLOCK_MODE ); 991 return CMD_SURELY_BLOCK_MODE;
1002 } 992 } else
1003 else 993 return CMD_MODE_UNKNOWN;
1004 return( CMD_MODE_UNKNOWN );
1005} 994}
1006 995
1007 996
@@ -1014,19 +1003,18 @@ static int falcon_classify_cmd( Scsi_Cmnd *cmd )
1014 * the overrun problem, so this question is academic :-) 1003 * the overrun problem, so this question is academic :-)
1015 */ 1004 */
1016 1005
1017static unsigned long atari_dma_xfer_len( unsigned long wanted_len, 1006static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
1018 Scsi_Cmnd *cmd, 1007 Scsi_Cmnd *cmd, int write_flag)
1019 int write_flag )
1020{ 1008{
1021 unsigned long possible_len, limit; 1009 unsigned long possible_len, limit;
1022#ifndef CONFIG_TT_DMA_EMUL 1010#ifndef CONFIG_TT_DMA_EMUL
1023 if (MACH_IS_HADES) 1011 if (MACH_IS_HADES)
1024 /* Hades has no SCSI DMA at all :-( Always force use of PIO */ 1012 /* Hades has no SCSI DMA at all :-( Always force use of PIO */
1025 return( 0 ); 1013 return 0;
1026#endif 1014#endif
1027 if (IS_A_TT()) 1015 if (IS_A_TT())
1028 /* TT SCSI DMA can transfer arbitrary #bytes */ 1016 /* TT SCSI DMA can transfer arbitrary #bytes */
1029 return( wanted_len ); 1017 return wanted_len;
1030 1018
1031 /* ST DMA chip is stupid -- only multiples of 512 bytes! (and max. 1019 /* ST DMA chip is stupid -- only multiples of 512 bytes! (and max.
1032 * 255*512 bytes, but this should be enough) 1020 * 255*512 bytes, but this should be enough)
@@ -1062,8 +1050,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
1062 * this). 1050 * this).
1063 */ 1051 */
1064 possible_len = wanted_len; 1052 possible_len = wanted_len;
1065 } 1053 } else {
1066 else {
1067 /* Read operations: if the wanted transfer length is not a multiple of 1054 /* Read operations: if the wanted transfer length is not a multiple of
1068 * 512, we cannot use DMA, since the ST-DMA cannot split transfers 1055 * 512, we cannot use DMA, since the ST-DMA cannot split transfers
1069 * (no interrupt on DMA finished!) 1056 * (no interrupt on DMA finished!)
@@ -1073,15 +1060,15 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
1073 else { 1060 else {
1074 /* Now classify the command (see above) and decide whether it is 1061 /* Now classify the command (see above) and decide whether it is
1075 * allowed to do DMA at all */ 1062 * allowed to do DMA at all */
1076 switch( falcon_classify_cmd( cmd )) { 1063 switch (falcon_classify_cmd(cmd)) {
1077 case CMD_SURELY_BLOCK_MODE: 1064 case CMD_SURELY_BLOCK_MODE:
1078 possible_len = wanted_len; 1065 possible_len = wanted_len;
1079 break; 1066 break;
1080 case CMD_SURELY_BYTE_MODE: 1067 case CMD_SURELY_BYTE_MODE:
1081 possible_len = 0; /* DMA prohibited */ 1068 possible_len = 0; /* DMA prohibited */
1082 break; 1069 break;
1083 case CMD_MODE_UNKNOWN: 1070 case CMD_MODE_UNKNOWN:
1084 default: 1071 default:
1085 /* For unknown commands assume block transfers if the transfer 1072 /* For unknown commands assume block transfers if the transfer
1086 * size/allocation length is >= 1024 */ 1073 * size/allocation length is >= 1024 */
1087 possible_len = (wanted_len < 1024) ? 0 : wanted_len; 1074 possible_len = (wanted_len < 1024) ? 0 : wanted_len;
@@ -1089,9 +1076,9 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
1089 } 1076 }
1090 } 1077 }
1091 } 1078 }
1092 1079
1093 /* Last step: apply the hard limit on DMA transfers */ 1080 /* Last step: apply the hard limit on DMA transfers */
1094 limit = (atari_dma_buffer && !STRAM_ADDR( virt_to_phys(cmd->SCp.ptr) )) ? 1081 limit = (atari_dma_buffer && !STRAM_ADDR(virt_to_phys(cmd->SCp.ptr))) ?
1095 STRAM_BUFFER_SIZE : 255*512; 1082 STRAM_BUFFER_SIZE : 255*512;
1096 if (possible_len > limit) 1083 if (possible_len > limit)
1097 possible_len = limit; 1084 possible_len = limit;
@@ -1100,7 +1087,7 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
1100 DMA_PRINTK("Sorry, must cut DMA transfer size to %ld bytes " 1087 DMA_PRINTK("Sorry, must cut DMA transfer size to %ld bytes "
1101 "instead of %ld\n", possible_len, wanted_len); 1088 "instead of %ld\n", possible_len, wanted_len);
1102 1089
1103 return( possible_len ); 1090 return possible_len;
1104} 1091}
1105 1092
1106 1093
@@ -1114,23 +1101,23 @@ static unsigned long atari_dma_xfer_len( unsigned long wanted_len,
1114 * NCR5380_write call these functions via function pointers. 1101 * NCR5380_write call these functions via function pointers.
1115 */ 1102 */
1116 1103
1117static unsigned char atari_scsi_tt_reg_read( unsigned char reg ) 1104static unsigned char atari_scsi_tt_reg_read(unsigned char reg)
1118{ 1105{
1119 return( tt_scsi_regp[reg * 2] ); 1106 return tt_scsi_regp[reg * 2];
1120} 1107}
1121 1108
1122static void atari_scsi_tt_reg_write( unsigned char reg, unsigned char value ) 1109static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value)
1123{ 1110{
1124 tt_scsi_regp[reg * 2] = value; 1111 tt_scsi_regp[reg * 2] = value;
1125} 1112}
1126 1113
1127static unsigned char atari_scsi_falcon_reg_read( unsigned char reg ) 1114static unsigned char atari_scsi_falcon_reg_read(unsigned char reg)
1128{ 1115{
1129 dma_wd.dma_mode_status= (u_short)(0x88 + reg); 1116 dma_wd.dma_mode_status= (u_short)(0x88 + reg);
1130 return( (u_char)dma_wd.fdc_acces_seccount ); 1117 return (u_char)dma_wd.fdc_acces_seccount;
1131} 1118}
1132 1119
1133static void atari_scsi_falcon_reg_write( unsigned char reg, unsigned char value ) 1120static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
1134{ 1121{
1135 dma_wd.dma_mode_status = (u_short)(0x88 + reg); 1122 dma_wd.dma_mode_status = (u_short)(0x88 + reg);
1136 dma_wd.fdc_acces_seccount = (u_short)value; 1123 dma_wd.fdc_acces_seccount = (u_short)value;
diff --git a/drivers/scsi/atari_scsi.h b/drivers/scsi/atari_scsi.h
index f917bdd09b41..efadb8d567c2 100644
--- a/drivers/scsi/atari_scsi.h
+++ b/drivers/scsi/atari_scsi.h
@@ -21,11 +21,7 @@
21int atari_scsi_detect (struct scsi_host_template *); 21int atari_scsi_detect (struct scsi_host_template *);
22const char *atari_scsi_info (struct Scsi_Host *); 22const char *atari_scsi_info (struct Scsi_Host *);
23int atari_scsi_reset (Scsi_Cmnd *, unsigned int); 23int atari_scsi_reset (Scsi_Cmnd *, unsigned int);
24#ifdef MODULE
25int atari_scsi_release (struct Scsi_Host *); 24int atari_scsi_release (struct Scsi_Host *);
26#else
27#define atari_scsi_release NULL
28#endif
29 25
30/* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary. Higher 26/* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary. Higher
31 * values should work, too; try it! (but cmd_per_lun costs memory!) */ 27 * values should work, too; try it! (but cmd_per_lun costs memory!) */
@@ -63,6 +59,32 @@ int atari_scsi_release (struct Scsi_Host *);
63#define NCR5380_dma_xfer_len(i,cmd,phase) \ 59#define NCR5380_dma_xfer_len(i,cmd,phase) \
64 atari_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1) 60 atari_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1)
65 61
62/* former generic SCSI error handling stuff */
63
64#define SCSI_ABORT_SNOOZE 0
65#define SCSI_ABORT_SUCCESS 1
66#define SCSI_ABORT_PENDING 2
67#define SCSI_ABORT_BUSY 3
68#define SCSI_ABORT_NOT_RUNNING 4
69#define SCSI_ABORT_ERROR 5
70
71#define SCSI_RESET_SNOOZE 0
72#define SCSI_RESET_PUNT 1
73#define SCSI_RESET_SUCCESS 2
74#define SCSI_RESET_PENDING 3
75#define SCSI_RESET_WAKEUP 4
76#define SCSI_RESET_NOT_RUNNING 5
77#define SCSI_RESET_ERROR 6
78
79#define SCSI_RESET_SYNCHRONOUS 0x01
80#define SCSI_RESET_ASYNCHRONOUS 0x02
81#define SCSI_RESET_SUGGEST_BUS_RESET 0x04
82#define SCSI_RESET_SUGGEST_HOST_RESET 0x08
83
84#define SCSI_RESET_BUS_RESET 0x100
85#define SCSI_RESET_HOST_RESET 0x200
86#define SCSI_RESET_ACTION 0xff
87
66/* Debugging printk definitions: 88/* Debugging printk definitions:
67 * 89 *
68 * ARB -> arbitration 90 * ARB -> arbitration
@@ -91,144 +113,58 @@ int atari_scsi_release (struct Scsi_Host *);
91 * 113 *
92 */ 114 */
93 115
94#if NDEBUG & NDEBUG_ARBITRATION 116#define dprint(flg, format...) \
117({ \
118 if (NDEBUG & (flg)) \
119 printk(KERN_DEBUG format); \
120})
121
95#define ARB_PRINTK(format, args...) \ 122#define ARB_PRINTK(format, args...) \
96 printk(KERN_DEBUG format , ## args) 123 dprint(NDEBUG_ARBITRATION, format , ## args)
97#else
98#define ARB_PRINTK(format, args...)
99#endif
100#if NDEBUG & NDEBUG_AUTOSENSE
101#define ASEN_PRINTK(format, args...) \ 124#define ASEN_PRINTK(format, args...) \
102 printk(KERN_DEBUG format , ## args) 125 dprint(NDEBUG_AUTOSENSE, format , ## args)
103#else
104#define ASEN_PRINTK(format, args...)
105#endif
106#if NDEBUG & NDEBUG_DMA
107#define DMA_PRINTK(format, args...) \ 126#define DMA_PRINTK(format, args...) \
108 printk(KERN_DEBUG format , ## args) 127 dprint(NDEBUG_DMA, format , ## args)
109#else
110#define DMA_PRINTK(format, args...)
111#endif
112#if NDEBUG & NDEBUG_HANDSHAKE
113#define HSH_PRINTK(format, args...) \ 128#define HSH_PRINTK(format, args...) \
114 printk(KERN_DEBUG format , ## args) 129 dprint(NDEBUG_HANDSHAKE, format , ## args)
115#else
116#define HSH_PRINTK(format, args...)
117#endif
118#if NDEBUG & NDEBUG_INFORMATION
119#define INF_PRINTK(format, args...) \ 130#define INF_PRINTK(format, args...) \
120 printk(KERN_DEBUG format , ## args) 131 dprint(NDEBUG_INFORMATION, format , ## args)
121#else
122#define INF_PRINTK(format, args...)
123#endif
124#if NDEBUG & NDEBUG_INIT
125#define INI_PRINTK(format, args...) \ 132#define INI_PRINTK(format, args...) \
126 printk(KERN_DEBUG format , ## args) 133 dprint(NDEBUG_INIT, format , ## args)
127#else
128#define INI_PRINTK(format, args...)
129#endif
130#if NDEBUG & NDEBUG_INTR
131#define INT_PRINTK(format, args...) \ 134#define INT_PRINTK(format, args...) \
132 printk(KERN_DEBUG format , ## args) 135 dprint(NDEBUG_INTR, format , ## args)
133#else
134#define INT_PRINTK(format, args...)
135#endif
136#if NDEBUG & NDEBUG_LINKED
137#define LNK_PRINTK(format, args...) \ 136#define LNK_PRINTK(format, args...) \
138 printk(KERN_DEBUG format , ## args) 137 dprint(NDEBUG_LINKED, format , ## args)
139#else
140#define LNK_PRINTK(format, args...)
141#endif
142#if NDEBUG & NDEBUG_MAIN
143#define MAIN_PRINTK(format, args...) \ 138#define MAIN_PRINTK(format, args...) \
144 printk(KERN_DEBUG format , ## args) 139 dprint(NDEBUG_MAIN, format , ## args)
145#else
146#define MAIN_PRINTK(format, args...)
147#endif
148#if NDEBUG & NDEBUG_NO_DATAOUT
149#define NDAT_PRINTK(format, args...) \ 140#define NDAT_PRINTK(format, args...) \
150 printk(KERN_DEBUG format , ## args) 141 dprint(NDEBUG_NO_DATAOUT, format , ## args)
151#else
152#define NDAT_PRINTK(format, args...)
153#endif
154#if NDEBUG & NDEBUG_NO_WRITE
155#define NWR_PRINTK(format, args...) \ 142#define NWR_PRINTK(format, args...) \
156 printk(KERN_DEBUG format , ## args) 143 dprint(NDEBUG_NO_WRITE, format , ## args)
157#else
158#define NWR_PRINTK(format, args...)
159#endif
160#if NDEBUG & NDEBUG_PIO
161#define PIO_PRINTK(format, args...) \ 144#define PIO_PRINTK(format, args...) \
162 printk(KERN_DEBUG format , ## args) 145 dprint(NDEBUG_PIO, format , ## args)
163#else
164#define PIO_PRINTK(format, args...)
165#endif
166#if NDEBUG & NDEBUG_PSEUDO_DMA
167#define PDMA_PRINTK(format, args...) \ 146#define PDMA_PRINTK(format, args...) \
168 printk(KERN_DEBUG format , ## args) 147 dprint(NDEBUG_PSEUDO_DMA, format , ## args)
169#else
170#define PDMA_PRINTK(format, args...)
171#endif
172#if NDEBUG & NDEBUG_QUEUES
173#define QU_PRINTK(format, args...) \ 148#define QU_PRINTK(format, args...) \
174 printk(KERN_DEBUG format , ## args) 149 dprint(NDEBUG_QUEUES, format , ## args)
175#else
176#define QU_PRINTK(format, args...)
177#endif
178#if NDEBUG & NDEBUG_RESELECTION
179#define RSL_PRINTK(format, args...) \ 150#define RSL_PRINTK(format, args...) \
180 printk(KERN_DEBUG format , ## args) 151 dprint(NDEBUG_RESELECTION, format , ## args)
181#else
182#define RSL_PRINTK(format, args...)
183#endif
184#if NDEBUG & NDEBUG_SELECTION
185#define SEL_PRINTK(format, args...) \ 152#define SEL_PRINTK(format, args...) \
186 printk(KERN_DEBUG format , ## args) 153 dprint(NDEBUG_SELECTION, format , ## args)
187#else
188#define SEL_PRINTK(format, args...)
189#endif
190#if NDEBUG & NDEBUG_USLEEP
191#define USL_PRINTK(format, args...) \ 154#define USL_PRINTK(format, args...) \
192 printk(KERN_DEBUG format , ## args) 155 dprint(NDEBUG_USLEEP, format , ## args)
193#else
194#define USL_PRINTK(format, args...)
195#endif
196#if NDEBUG & NDEBUG_LAST_BYTE_SENT
197#define LBS_PRINTK(format, args...) \ 156#define LBS_PRINTK(format, args...) \
198 printk(KERN_DEBUG format , ## args) 157 dprint(NDEBUG_LAST_BYTE_SENT, format , ## args)
199#else
200#define LBS_PRINTK(format, args...)
201#endif
202#if NDEBUG & NDEBUG_RESTART_SELECT
203#define RSS_PRINTK(format, args...) \ 158#define RSS_PRINTK(format, args...) \
204 printk(KERN_DEBUG format , ## args) 159 dprint(NDEBUG_RESTART_SELECT, format , ## args)
205#else
206#define RSS_PRINTK(format, args...)
207#endif
208#if NDEBUG & NDEBUG_EXTENDED
209#define EXT_PRINTK(format, args...) \ 160#define EXT_PRINTK(format, args...) \
210 printk(KERN_DEBUG format , ## args) 161 dprint(NDEBUG_EXTENDED, format , ## args)
211#else
212#define EXT_PRINTK(format, args...)
213#endif
214#if NDEBUG & NDEBUG_ABORT
215#define ABRT_PRINTK(format, args...) \ 162#define ABRT_PRINTK(format, args...) \
216 printk(KERN_DEBUG format , ## args) 163 dprint(NDEBUG_ABORT, format , ## args)
217#else
218#define ABRT_PRINTK(format, args...)
219#endif
220#if NDEBUG & NDEBUG_TAGS
221#define TAG_PRINTK(format, args...) \ 164#define TAG_PRINTK(format, args...) \
222 printk(KERN_DEBUG format , ## args) 165 dprint(NDEBUG_TAGS, format , ## args)
223#else
224#define TAG_PRINTK(format, args...)
225#endif
226#if NDEBUG & NDEBUG_MERGING
227#define MER_PRINTK(format, args...) \ 166#define MER_PRINTK(format, args...) \
228 printk(KERN_DEBUG format , ## args) 167 dprint(NDEBUG_MERGING, format , ## args)
229#else
230#define MER_PRINTK(format, args...)
231#endif
232 168
233/* conditional macros for NCR5380_print_{,phase,status} */ 169/* conditional macros for NCR5380_print_{,phase,status} */
234 170
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index b1cb72c3780f..d18b51f989c9 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -389,7 +389,10 @@ config FB_ARC
389 389
390config FB_ATARI 390config FB_ATARI
391 bool "Atari native chipset support" 391 bool "Atari native chipset support"
392 depends on (FB = y) && ATARI && BROKEN 392 depends on (FB = y) && ATARI
393 select FB_CFB_FILLRECT
394 select FB_CFB_COPYAREA
395 select FB_CFB_IMAGEBLIT
393 help 396 help
394 This is the frame buffer device driver for the builtin graphics 397 This is the frame buffer device driver for the builtin graphics
395 chipset found in Ataris. 398 chipset found in Ataris.
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 760305c8a841..869351785ee8 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -63,7 +63,8 @@ obj-$(CONFIG_FB_TCX) += tcx.o sbuslib.o
63obj-$(CONFIG_FB_LEO) += leo.o sbuslib.o 63obj-$(CONFIG_FB_LEO) += leo.o sbuslib.o
64obj-$(CONFIG_FB_SGIVW) += sgivwfb.o 64obj-$(CONFIG_FB_SGIVW) += sgivwfb.o
65obj-$(CONFIG_FB_ACORN) += acornfb.o 65obj-$(CONFIG_FB_ACORN) += acornfb.o
66obj-$(CONFIG_FB_ATARI) += atafb.o 66obj-$(CONFIG_FB_ATARI) += atafb.o c2p.o atafb_mfb.o \
67 atafb_iplan2p2.o atafb_iplan2p4.o atafb_iplan2p8.o
67obj-$(CONFIG_FB_MAC) += macfb.o 68obj-$(CONFIG_FB_MAC) += macfb.o
68obj-$(CONFIG_FB_HGA) += hgafb.o 69obj-$(CONFIG_FB_HGA) += hgafb.o
69obj-$(CONFIG_FB_IGA) += igafb.o 70obj-$(CONFIG_FB_IGA) += igafb.o
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index bffe2b946344..0038a0541c7e 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -2,7 +2,7 @@
2 * linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device 2 * linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device
3 * 3 *
4 * Copyright (C) 1994 Martin Schaller & Roman Hodek 4 * Copyright (C) 1994 Martin Schaller & Roman Hodek
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive 7 * License. See the file COPYING in the main directory of this archive
8 * for more details. 8 * for more details.
@@ -70,14 +70,8 @@
70#include <linux/fb.h> 70#include <linux/fb.h>
71#include <asm/atarikb.h> 71#include <asm/atarikb.h>
72 72
73#include <video/fbcon.h> 73#include "c2p.h"
74#include <video/fbcon-cfb8.h> 74#include "atafb.h"
75#include <video/fbcon-cfb16.h>
76#include <video/fbcon-iplan2p2.h>
77#include <video/fbcon-iplan2p4.h>
78#include <video/fbcon-iplan2p8.h>
79#include <video/fbcon-mfb.h>
80
81 75
82#define SWITCH_ACIA 0x01 /* modes for switch on OverScan */ 76#define SWITCH_ACIA 0x01 /* modes for switch on OverScan */
83#define SWITCH_SND6 0x40 77#define SWITCH_SND6 0x40
@@ -87,22 +81,48 @@
87 81
88#define up(x, r) (((x) + (r) - 1) & ~((r)-1)) 82#define up(x, r) (((x) + (r) - 1) & ~((r)-1))
89 83
84 /*
85 * Interface to the world
86 */
87
88static int atafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
89static int atafb_set_par(struct fb_info *info);
90static int atafb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
91 unsigned int blue, unsigned int transp,
92 struct fb_info *info);
93static int atafb_blank(int blank, struct fb_info *info);
94static int atafb_pan_display(struct fb_var_screeninfo *var,
95 struct fb_info *info);
96static void atafb_fillrect(struct fb_info *info,
97 const struct fb_fillrect *rect);
98static void atafb_copyarea(struct fb_info *info,
99 const struct fb_copyarea *region);
100static void atafb_imageblit(struct fb_info *info, const struct fb_image *image);
101static int atafb_ioctl(struct fb_info *info, unsigned int cmd,
102 unsigned long arg);
103
90 104
91static int default_par=0; /* default resolution (0=none) */ 105static int default_par; /* default resolution (0=none) */
92 106
93static unsigned long default_mem_req=0; 107static unsigned long default_mem_req;
94 108
95static int hwscroll=-1; 109static int hwscroll = -1;
96 110
97static int use_hwscroll = 1; 111static int use_hwscroll = 1;
98 112
99static int sttt_xres=640,st_yres=400,tt_yres=480; 113static int sttt_xres = 640, st_yres = 400, tt_yres = 480;
100static int sttt_xres_virtual=640,sttt_yres_virtual=400; 114static int sttt_xres_virtual = 640, sttt_yres_virtual = 400;
101static int ovsc_offset=0, ovsc_addlen=0; 115static int ovsc_offset, ovsc_addlen;
116
117 /*
118 * Hardware parameters for current mode
119 */
102 120
103static struct atafb_par { 121static struct atafb_par {
104 void *screen_base; 122 void *screen_base;
105 int yres_virtual; 123 int yres_virtual;
124 u_long next_line;
125 u_long next_plane;
106#if defined ATAFB_TT || defined ATAFB_STE 126#if defined ATAFB_TT || defined ATAFB_STE
107 union { 127 union {
108 struct { 128 struct {
@@ -138,7 +158,7 @@ static struct atafb_par {
138/* Don't calculate an own resolution, and thus don't change the one found when 158/* Don't calculate an own resolution, and thus don't change the one found when
139 * booting (currently used for the Falcon to keep settings for internal video 159 * booting (currently used for the Falcon to keep settings for internal video
140 * hardware extensions (e.g. ScreenBlaster) */ 160 * hardware extensions (e.g. ScreenBlaster) */
141static int DontCalcRes = 0; 161static int DontCalcRes = 0;
142 162
143#ifdef ATAFB_FALCON 163#ifdef ATAFB_FALCON
144#define HHT hw.falcon.hht 164#define HHT hw.falcon.hht
@@ -163,83 +183,84 @@ static int DontCalcRes = 0;
163#define VMO_PREMASK 0x0c 183#define VMO_PREMASK 0x0c
164#endif 184#endif
165 185
166static struct fb_info fb_info; 186static struct fb_info fb_info = {
187 .fix = {
188 .id = "Atari ",
189 .visual = FB_VISUAL_PSEUDOCOLOR,
190 .accel = FB_ACCEL_NONE,
191 }
192};
167 193
168static void *screen_base; /* base address of screen */ 194static void *screen_base; /* base address of screen */
169static void *real_screen_base; /* (only for Overscan) */ 195static void *real_screen_base; /* (only for Overscan) */
170 196
171static int screen_len; 197static int screen_len;
172 198
173static int current_par_valid=0; 199static int current_par_valid;
174 200
175static int mono_moni=0; 201static int mono_moni;
176
177static struct display disp;
178 202
179 203
180#ifdef ATAFB_EXT 204#ifdef ATAFB_EXT
181/* external video handling */
182 205
183static unsigned external_xres; 206/* external video handling */
184static unsigned external_xres_virtual; 207static unsigned int external_xres;
185static unsigned external_yres; 208static unsigned int external_xres_virtual;
186/* not needed - atafb will never support panning/hardwarescroll with external 209static unsigned int external_yres;
187 * static unsigned external_yres_virtual;
188*/
189 210
190static unsigned external_depth; 211/*
191static int external_pmode; 212 * not needed - atafb will never support panning/hardwarescroll with external
192static void *external_addr = 0; 213 * static unsigned int external_yres_virtual;
193static unsigned long external_len; 214 */
194static unsigned long external_vgaiobase = 0; 215static unsigned int external_depth;
195static unsigned int external_bitspercol = 6; 216static int external_pmode;
196 217static void *external_addr;
197/* 218static unsigned long external_len;
198JOE <joe@amber.dinoco.de>: 219static unsigned long external_vgaiobase;
199added card type for external driver, is only needed for 220static unsigned int external_bitspercol = 6;
200colormap handling.
201*/
202 221
222/*
223 * JOE <joe@amber.dinoco.de>:
224 * added card type for external driver, is only needed for
225 * colormap handling.
226 */
203enum cardtype { IS_VGA, IS_MV300 }; 227enum cardtype { IS_VGA, IS_MV300 };
204static enum cardtype external_card_type = IS_VGA; 228static enum cardtype external_card_type = IS_VGA;
205 229
206/* 230/*
207The MV300 mixes the color registers. So we need an array of munged 231 * The MV300 mixes the color registers. So we need an array of munged
208indices in order to access the correct reg. 232 * indices in order to access the correct reg.
209*/ 233 */
210static int MV300_reg_1bit[2]={0,1}; 234static int MV300_reg_1bit[2] = {
211static int MV300_reg_4bit[16]={ 235 0, 1
2120, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; 236};
213static int MV300_reg_8bit[256]={ 237static int MV300_reg_4bit[16] = {
2140, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 238 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
2158, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 239};
2164, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 240static int MV300_reg_8bit[256] = {
21712, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 241 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
2182, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 242 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
21910, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 243 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
2206, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 244 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
22114, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 245 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
2221, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 246 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
2239, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 247 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
2245, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 248 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
22513, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 249 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
2263, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 250 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
22711, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 251 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
2287, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 252 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
22915, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 }; 253 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
254 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
255 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
256 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
257};
230 258
231static int *MV300_reg = MV300_reg_8bit; 259static int *MV300_reg = MV300_reg_8bit;
232
233/*
234And on the MV300 it's difficult to read out the hardware palette. So we
235just keep track of the set colors in our own array here, and use that!
236*/
237
238static struct { unsigned char red,green,blue,pad; } ext_color[256];
239#endif /* ATAFB_EXT */ 260#endif /* ATAFB_EXT */
240 261
241 262
242static int inverse=0; 263static int inverse;
243 264
244extern int fontheight_8x8; 265extern int fontheight_8x8;
245extern int fontwidth_8x8; 266extern int fontwidth_8x8;
@@ -249,96 +270,154 @@ extern int fontheight_8x16;
249extern int fontwidth_8x16; 270extern int fontwidth_8x16;
250extern unsigned char fontdata_8x16[]; 271extern unsigned char fontdata_8x16[];
251 272
273/*
274 * struct fb_ops {
275 * * open/release and usage marking
276 * struct module *owner;
277 * int (*fb_open)(struct fb_info *info, int user);
278 * int (*fb_release)(struct fb_info *info, int user);
279 *
280 * * For framebuffers with strange non linear layouts or that do not
281 * * work with normal memory mapped access
282 * ssize_t (*fb_read)(struct file *file, char __user *buf, size_t count, loff_t *ppos);
283 * ssize_t (*fb_write)(struct file *file, const char __user *buf, size_t count, loff_t *ppos);
284 *
285 * * checks var and eventually tweaks it to something supported,
286 * * DOES NOT MODIFY PAR *
287 * int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
288 *
289 * * set the video mode according to info->var *
290 * int (*fb_set_par)(struct fb_info *info);
291 *
292 * * set color register *
293 * int (*fb_setcolreg)(unsigned int regno, unsigned int red, unsigned int green,
294 * unsigned int blue, unsigned int transp, struct fb_info *info);
295 *
296 * * set color registers in batch *
297 * int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
298 *
299 * * blank display *
300 * int (*fb_blank)(int blank, struct fb_info *info);
301 *
302 * * pan display *
303 * int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
304 *
305 * *** The meat of the drawing engine ***
306 * * Draws a rectangle *
307 * void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
308 * * Copy data from area to another *
309 * void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
310 * * Draws a image to the display *
311 * void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
312 *
313 * * Draws cursor *
314 * int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
315 *
316 * * Rotates the display *
317 * void (*fb_rotate)(struct fb_info *info, int angle);
318 *
319 * * wait for blit idle, optional *
320 * int (*fb_sync)(struct fb_info *info);
321 *
322 * * perform fb specific ioctl (optional) *
323 * int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
324 * unsigned long arg);
325 *
326 * * Handle 32bit compat ioctl (optional) *
327 * int (*fb_compat_ioctl)(struct fb_info *info, unsigned int cmd,
328 * unsigned long arg);
329 *
330 * * perform fb specific mmap *
331 * int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
332 *
333 * * save current hardware state *
334 * void (*fb_save_state)(struct fb_info *info);
335 *
336 * * restore saved state *
337 * void (*fb_restore_state)(struct fb_info *info);
338 * } ;
339 */
340
341
252/* ++roman: This structure abstracts from the underlying hardware (ST(e), 342/* ++roman: This structure abstracts from the underlying hardware (ST(e),
253 * TT, or Falcon. 343 * TT, or Falcon.
254 * 344 *
255 * int (*detect)( void ) 345 * int (*detect)(void)
256 * This function should detect the current video mode settings and 346 * This function should detect the current video mode settings and
257 * store them in atafb_predefined[0] for later reference by the 347 * store them in atafb_predefined[0] for later reference by the
258 * user. Return the index+1 of an equivalent predefined mode or 0 348 * user. Return the index+1 of an equivalent predefined mode or 0
259 * if there is no such. 349 * if there is no such.
260 * 350 *
261 * int (*encode_fix)( struct fb_fix_screeninfo *fix, 351 * int (*encode_fix)(struct fb_fix_screeninfo *fix,
262 * struct atafb_par *par ) 352 * struct atafb_par *par)
263 * This function should fill in the 'fix' structure based on the 353 * This function should fill in the 'fix' structure based on the
264 * values in the 'par' structure. 354 * values in the 'par' structure.
265 * 355 * !!! Obsolete, perhaps !!!
266 * int (*decode_var)( struct fb_var_screeninfo *var, 356 *
267 * struct atafb_par *par ) 357 * int (*decode_var)(struct fb_var_screeninfo *var,
358 * struct atafb_par *par)
268 * Get the video params out of 'var'. If a value doesn't fit, round 359 * Get the video params out of 'var'. If a value doesn't fit, round
269 * it up, if it's too big, return EINVAL. 360 * it up, if it's too big, return EINVAL.
270 * Round up in the following order: bits_per_pixel, xres, yres, 361 * Round up in the following order: bits_per_pixel, xres, yres,
271 * xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields, 362 * xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
272 * horizontal timing, vertical timing. 363 * horizontal timing, vertical timing.
273 * 364 *
274 * int (*encode_var)( struct fb_var_screeninfo *var, 365 * int (*encode_var)(struct fb_var_screeninfo *var,
275 * struct atafb_par *par ); 366 * struct atafb_par *par);
276 * Fill the 'var' structure based on the values in 'par' and maybe 367 * Fill the 'var' structure based on the values in 'par' and maybe
277 * other values read out of the hardware. 368 * other values read out of the hardware.
278 * 369 *
279 * void (*get_par)( struct atafb_par *par ) 370 * void (*get_par)(struct atafb_par *par)
280 * Fill the hardware's 'par' structure. 371 * Fill the hardware's 'par' structure.
281 * 372 * !!! Used only by detect() !!!
282 * void (*set_par)( struct atafb_par *par ) 373 *
374 * void (*set_par)(struct atafb_par *par)
283 * Set the hardware according to 'par'. 375 * Set the hardware according to 'par'.
284 *
285 * int (*getcolreg)( unsigned regno, unsigned *red,
286 * unsigned *green, unsigned *blue,
287 * unsigned *transp, struct fb_info *info )
288 * Read a single color register and split it into
289 * colors/transparent. Return != 0 for invalid regno.
290 * 376 *
291 * void (*set_screen_base)(void *s_base) 377 * void (*set_screen_base)(void *s_base)
292 * Set the base address of the displayed frame buffer. Only called 378 * Set the base address of the displayed frame buffer. Only called
293 * if yres_virtual > yres or xres_virtual > xres. 379 * if yres_virtual > yres or xres_virtual > xres.
294 * 380 *
295 * int (*blank)( int blank_mode ) 381 * int (*blank)(int blank_mode)
296 * Blank the screen if blank_mode!=0, else unblank. If blank==NULL then 382 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL then
297 * the caller blanks by setting the CLUT to all black. Return 0 if blanking 383 * the caller blanks by setting the CLUT to all black. Return 0 if blanking
298 * succeeded, !=0 if un-/blanking failed due to e.g. a video mode which 384 * succeeded, !=0 if un-/blanking failed due to e.g. a video mode which
299 * doesn't support it. Implements VESA suspend and powerdown modes on 385 * doesn't support it. Implements VESA suspend and powerdown modes on
300 * hardware that supports disabling hsync/vsync: 386 * hardware that supports disabling hsync/vsync:
301 * blank_mode==2: suspend vsync, 3:suspend hsync, 4: powerdown. 387 * blank_mode == 2: suspend vsync, 3:suspend hsync, 4: powerdown.
302 */ 388 */
303 389
304static struct fb_hwswitch { 390static struct fb_hwswitch {
305 int (*detect)( void ); 391 int (*detect)(void);
306 int (*encode_fix)( struct fb_fix_screeninfo *fix, 392 int (*encode_fix)(struct fb_fix_screeninfo *fix,
307 struct atafb_par *par ); 393 struct atafb_par *par);
308 int (*decode_var)( struct fb_var_screeninfo *var, 394 int (*decode_var)(struct fb_var_screeninfo *var,
309 struct atafb_par *par ); 395 struct atafb_par *par);
310 int (*encode_var)( struct fb_var_screeninfo *var, 396 int (*encode_var)(struct fb_var_screeninfo *var,
311 struct atafb_par *par ); 397 struct atafb_par *par);
312 void (*get_par)( struct atafb_par *par ); 398 void (*get_par)(struct atafb_par *par);
313 void (*set_par)( struct atafb_par *par ); 399 void (*set_par)(struct atafb_par *par);
314 int (*getcolreg)( unsigned regno, unsigned *red,
315 unsigned *green, unsigned *blue,
316 unsigned *transp, struct fb_info *info );
317 void (*set_screen_base)(void *s_base); 400 void (*set_screen_base)(void *s_base);
318 int (*blank)( int blank_mode ); 401 int (*blank)(int blank_mode);
319 int (*pan_display)( struct fb_var_screeninfo *var, 402 int (*pan_display)(struct fb_var_screeninfo *var,
320 struct atafb_par *par); 403 struct fb_info *info);
321} *fbhw; 404} *fbhw;
322 405
323static char *autodetect_names[] = {"autodetect", NULL}; 406static char *autodetect_names[] = { "autodetect", NULL };
324static char *stlow_names[] = {"stlow", NULL}; 407static char *stlow_names[] = { "stlow", NULL };
325static char *stmid_names[] = {"stmid", "default5", NULL}; 408static char *stmid_names[] = { "stmid", "default5", NULL };
326static char *sthigh_names[] = {"sthigh", "default4", NULL}; 409static char *sthigh_names[] = { "sthigh", "default4", NULL };
327static char *ttlow_names[] = {"ttlow", NULL}; 410static char *ttlow_names[] = { "ttlow", NULL };
328static char *ttmid_names[]= {"ttmid", "default1", NULL}; 411static char *ttmid_names[] = { "ttmid", "default1", NULL };
329static char *tthigh_names[]= {"tthigh", "default2", NULL}; 412static char *tthigh_names[] = { "tthigh", "default2", NULL };
330static char *vga2_names[] = {"vga2", NULL}; 413static char *vga2_names[] = { "vga2", NULL };
331static char *vga4_names[] = {"vga4", NULL}; 414static char *vga4_names[] = { "vga4", NULL };
332static char *vga16_names[] = {"vga16", "default3", NULL}; 415static char *vga16_names[] = { "vga16", "default3", NULL };
333static char *vga256_names[] = {"vga256", NULL}; 416static char *vga256_names[] = { "vga256", NULL };
334static char *falh2_names[] = {"falh2", NULL}; 417static char *falh2_names[] = { "falh2", NULL };
335static char *falh16_names[] = {"falh16", NULL}; 418static char *falh16_names[] = { "falh16", NULL };
336 419
337static char **fb_var_names[] = { 420static char **fb_var_names[] = {
338 /* Writing the name arrays directly in this array (via "(char *[]){...}")
339 * crashes gcc 2.5.8 (sigsegv) if the inner array
340 * contains more than two items. I've also seen that all elements
341 * were identical to the last (my cross-gcc) :-(*/
342 autodetect_names, 421 autodetect_names,
343 stlow_names, 422 stlow_names,
344 stmid_names, 423 stmid_names,
@@ -353,18 +432,17 @@ static char **fb_var_names[] = {
353 falh2_names, 432 falh2_names,
354 falh16_names, 433 falh16_names,
355 NULL 434 NULL
356 /* ,NULL */ /* this causes a sigsegv on my gcc-2.5.8 */
357}; 435};
358 436
359static struct fb_var_screeninfo atafb_predefined[] = { 437static struct fb_var_screeninfo atafb_predefined[] = {
360 /* 438 /*
361 * yres_virtual==0 means use hw-scrolling if possible, else yres 439 * yres_virtual == 0 means use hw-scrolling if possible, else yres
362 */ 440 */
363 { /* autodetect */ 441 { /* autodetect */
364 0, 0, 0, 0, 0, 0, 0, 0, /* xres-grayscale */ 442 0, 0, 0, 0, 0, 0, 0, 0, /* xres-grayscale */
365 {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, /* red green blue tran*/ 443 {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, /* red green blue tran*/
366 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 }, 444 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
367 { /* st low */ 445 { /* st low */
368 320, 200, 320, 0, 0, 0, 4, 0, 446 320, 200, 320, 0, 0, 0, 4, 0,
369 {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 447 {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
370 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 }, 448 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -414,27 +492,100 @@ static struct fb_var_screeninfo atafb_predefined[] = {
414 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 }, 492 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
415}; 493};
416 494
417static int num_atafb_predefined=ARRAY_SIZE(atafb_predefined); 495static int num_atafb_predefined = ARRAY_SIZE(atafb_predefined);
418 496
497static struct fb_videomode atafb_modedb[] __initdata = {
498 /*
499 * Atari Video Modes
500 *
501 * If you change these, make sure to update DEFMODE_* as well!
502 */
419 503
420static int 504 /*
421get_video_mode(char *vname) 505 * ST/TT Video Modes
506 */
507
508 {
509 /* 320x200, 15 kHz, 60 Hz (ST low) */
510 "st-low", 60, 320, 200, 32000, 32, 16, 31, 14, 96, 4,
511 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
512 }, {
513 /* 640x200, 15 kHz, 60 Hz (ST medium) */
514 "st-mid", 60, 640, 200, 32000, 32, 16, 31, 14, 96, 4,
515 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
516 }, {
517 /* 640x400, 30.25 kHz, 63.5 Hz (ST high) */
518 "st-high", 63, 640, 400, 32000, 128, 0, 40, 14, 128, 4,
519 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
520 }, {
521 /* 320x480, 15 kHz, 60 Hz (TT low) */
522 "tt-low", 60, 320, 480, 31041, 120, 100, 8, 16, 140, 30,
523 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
524 }, {
525 /* 640x480, 29 kHz, 57 Hz (TT medium) */
526 "tt-mid", 60, 640, 480, 31041, 120, 100, 8, 16, 140, 30,
527 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
528 }, {
529 /* 1280x960, 29 kHz, 60 Hz (TT high) */
530 "tt-high", 57, 640, 960, 31041, 120, 100, 8, 16, 140, 30,
531 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
532 },
533
534 /*
535 * VGA Video Modes
536 */
537
538 {
539 /* 640x480, 31 kHz, 60 Hz (VGA) */
540 "vga", 63.5, 640, 480, 32000, 18, 42, 31, 11, 96, 3,
541 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
542 }, {
543 /* 640x400, 31 kHz, 70 Hz (VGA) */
544 "vga70", 70, 640, 400, 32000, 18, 42, 31, 11, 96, 3,
545 FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
546 },
547
548 /*
549 * Falcon HiRes Video Modes
550 */
551
552 {
553 /* 896x608, 31 kHz, 60 Hz (Falcon High) */
554 "falh", 60, 896, 608, 32000, 18, 42, 31, 1, 96,3,
555 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
556 },
557};
558
559#define NUM_TOTAL_MODES ARRAY_SIZE(atafb_modedb)
560
561static char *mode_option __initdata = NULL;
562
563 /* default modes */
564
565#define DEFMODE_TT 5 /* "tt-high" for TT */
566#define DEFMODE_F30 7 /* "vga70" for Falcon */
567#define DEFMODE_STE 2 /* "st-high" for ST/E */
568#define DEFMODE_EXT 6 /* "vga" for external */
569
570
571static int get_video_mode(char *vname)
422{ 572{
423 char ***name_list; 573 char ***name_list;
424 char **name; 574 char **name;
425 int i; 575 int i;
426 name_list=fb_var_names; 576
427 for (i = 0 ; i < num_atafb_predefined ; i++) { 577 name_list = fb_var_names;
428 name=*(name_list++); 578 for (i = 0; i < num_atafb_predefined; i++) {
429 if (! name || ! *name) 579 name = *name_list++;
430 break; 580 if (!name || !*name)
431 while (*name) { 581 break;
432 if (! strcmp(vname, *name)) 582 while (*name) {
433 return i+1; 583 if (!strcmp(vname, *name))
434 name++; 584 return i + 1;
585 name++;
586 }
435 } 587 }
436 } 588 return 0;
437 return 0;
438} 589}
439 590
440 591
@@ -443,93 +594,84 @@ get_video_mode(char *vname)
443 594
444#ifdef ATAFB_TT 595#ifdef ATAFB_TT
445 596
446static int tt_encode_fix( struct fb_fix_screeninfo *fix, 597static int tt_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
447 struct atafb_par *par )
448
449{ 598{
450 int mode; 599 int mode;
451 600
452 strcpy(fix->id,"Atari Builtin"); 601 strcpy(fix->id, "Atari Builtin");
453 fix->smem_start = (unsigned long)real_screen_base; 602 fix->smem_start = (unsigned long)real_screen_base;
454 fix->smem_len = screen_len; 603 fix->smem_len = screen_len;
455 fix->type=FB_TYPE_INTERLEAVED_PLANES; 604 fix->type = FB_TYPE_INTERLEAVED_PLANES;
456 fix->type_aux=2; 605 fix->type_aux = 2;
457 fix->visual=FB_VISUAL_PSEUDOCOLOR; 606 fix->visual = FB_VISUAL_PSEUDOCOLOR;
458 mode = par->hw.tt.mode & TT_SHIFTER_MODEMASK; 607 mode = par->hw.tt.mode & TT_SHIFTER_MODEMASK;
459 if (mode == TT_SHIFTER_TTHIGH || mode == TT_SHIFTER_STHIGH) { 608 if (mode == TT_SHIFTER_TTHIGH || mode == TT_SHIFTER_STHIGH) {
460 fix->type=FB_TYPE_PACKED_PIXELS; 609 fix->type = FB_TYPE_PACKED_PIXELS;
461 fix->type_aux=0; 610 fix->type_aux = 0;
462 if (mode == TT_SHIFTER_TTHIGH) 611 if (mode == TT_SHIFTER_TTHIGH)
463 fix->visual=FB_VISUAL_MONO01; 612 fix->visual = FB_VISUAL_MONO01;
464 } 613 }
465 fix->xpanstep=0; 614 fix->xpanstep = 0;
466 fix->ypanstep=1; 615 fix->ypanstep = 1;
467 fix->ywrapstep=0; 616 fix->ywrapstep = 0;
468 fix->line_length = 0; 617 fix->line_length = 0;
469 fix->accel = FB_ACCEL_ATARIBLITT; 618 fix->accel = FB_ACCEL_ATARIBLITT;
470 return 0; 619 return 0;
471} 620}
472 621
473 622static int tt_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
474static int tt_decode_var( struct fb_var_screeninfo *var,
475 struct atafb_par *par )
476{ 623{
477 int xres=var->xres; 624 int xres = var->xres;
478 int yres=var->yres; 625 int yres = var->yres;
479 int bpp=var->bits_per_pixel; 626 int bpp = var->bits_per_pixel;
480 int linelen; 627 int linelen;
481 int yres_virtual = var->yres_virtual; 628 int yres_virtual = var->yres_virtual;
482 629
483 if (mono_moni) { 630 if (mono_moni) {
484 if (bpp > 1 || xres > sttt_xres*2 || yres >tt_yres*2) 631 if (bpp > 1 || xres > sttt_xres * 2 || yres > tt_yres * 2)
485 return -EINVAL; 632 return -EINVAL;
486 par->hw.tt.mode=TT_SHIFTER_TTHIGH; 633 par->hw.tt.mode = TT_SHIFTER_TTHIGH;
487 xres=sttt_xres*2; 634 xres = sttt_xres * 2;
488 yres=tt_yres*2; 635 yres = tt_yres * 2;
489 bpp=1; 636 bpp = 1;
490 } else { 637 } else {
491 if (bpp > 8 || xres > sttt_xres || yres > tt_yres) 638 if (bpp > 8 || xres > sttt_xres || yres > tt_yres)
492 return -EINVAL; 639 return -EINVAL;
493 if (bpp > 4) { 640 if (bpp > 4) {
494 if (xres > sttt_xres/2 || yres > tt_yres) 641 if (xres > sttt_xres / 2 || yres > tt_yres)
495 return -EINVAL; 642 return -EINVAL;
496 par->hw.tt.mode=TT_SHIFTER_TTLOW; 643 par->hw.tt.mode = TT_SHIFTER_TTLOW;
497 xres=sttt_xres/2; 644 xres = sttt_xres / 2;
498 yres=tt_yres; 645 yres = tt_yres;
499 bpp=8; 646 bpp = 8;
500 } 647 } else if (bpp > 2) {
501 else if (bpp > 2) {
502 if (xres > sttt_xres || yres > tt_yres) 648 if (xres > sttt_xres || yres > tt_yres)
503 return -EINVAL; 649 return -EINVAL;
504 if (xres > sttt_xres/2 || yres > st_yres/2) { 650 if (xres > sttt_xres / 2 || yres > st_yres / 2) {
505 par->hw.tt.mode=TT_SHIFTER_TTMID; 651 par->hw.tt.mode = TT_SHIFTER_TTMID;
506 xres=sttt_xres; 652 xres = sttt_xres;
507 yres=tt_yres; 653 yres = tt_yres;
508 bpp=4; 654 bpp = 4;
509 } 655 } else {
510 else { 656 par->hw.tt.mode = TT_SHIFTER_STLOW;
511 par->hw.tt.mode=TT_SHIFTER_STLOW; 657 xres = sttt_xres / 2;
512 xres=sttt_xres/2; 658 yres = st_yres / 2;
513 yres=st_yres/2; 659 bpp = 4;
514 bpp=4;
515 } 660 }
516 } 661 } else if (bpp > 1) {
517 else if (bpp > 1) { 662 if (xres > sttt_xres || yres > st_yres / 2)
518 if (xres > sttt_xres || yres > st_yres/2)
519 return -EINVAL; 663 return -EINVAL;
520 par->hw.tt.mode=TT_SHIFTER_STMID; 664 par->hw.tt.mode = TT_SHIFTER_STMID;
521 xres=sttt_xres; 665 xres = sttt_xres;
522 yres=st_yres/2; 666 yres = st_yres / 2;
523 bpp=2; 667 bpp = 2;
524 } 668 } else if (var->xres > sttt_xres || var->yres > st_yres) {
525 else if (var->xres > sttt_xres || var->yres > st_yres) {
526 return -EINVAL; 669 return -EINVAL;
527 } 670 } else {
528 else { 671 par->hw.tt.mode = TT_SHIFTER_STHIGH;
529 par->hw.tt.mode=TT_SHIFTER_STHIGH; 672 xres = sttt_xres;
530 xres=sttt_xres; 673 yres = st_yres;
531 yres=st_yres; 674 bpp = 1;
532 bpp=1;
533 } 675 }
534 } 676 }
535 if (yres_virtual <= 0) 677 if (yres_virtual <= 0)
@@ -537,10 +679,10 @@ static int tt_decode_var( struct fb_var_screeninfo *var,
537 else if (yres_virtual < yres) 679 else if (yres_virtual < yres)
538 yres_virtual = yres; 680 yres_virtual = yres;
539 if (var->sync & FB_SYNC_EXT) 681 if (var->sync & FB_SYNC_EXT)
540 par->hw.tt.sync=0; 682 par->hw.tt.sync = 0;
541 else 683 else
542 par->hw.tt.sync=1; 684 par->hw.tt.sync = 1;
543 linelen=xres*bpp/8; 685 linelen = xres * bpp / 8;
544 if (yres_virtual * linelen > screen_len && screen_len) 686 if (yres_virtual * linelen > screen_len && screen_len)
545 return -EINVAL; 687 return -EINVAL;
546 if (yres * linelen > screen_len && screen_len) 688 if (yres * linelen > screen_len && screen_len)
@@ -552,154 +694,123 @@ static int tt_decode_var( struct fb_var_screeninfo *var,
552 return 0; 694 return 0;
553} 695}
554 696
555static int tt_encode_var( struct fb_var_screeninfo *var, 697static int tt_encode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
556 struct atafb_par *par )
557{ 698{
558 int linelen; 699 int linelen;
559 memset(var, 0, sizeof(struct fb_var_screeninfo)); 700 memset(var, 0, sizeof(struct fb_var_screeninfo));
560 var->red.offset=0; 701 var->red.offset = 0;
561 var->red.length=4; 702 var->red.length = 4;
562 var->red.msb_right=0; 703 var->red.msb_right = 0;
563 var->grayscale=0; 704 var->grayscale = 0;
564 705
565 var->pixclock=31041; 706 var->pixclock = 31041;
566 var->left_margin=120; /* these may be incorrect */ 707 var->left_margin = 120; /* these may be incorrect */
567 var->right_margin=100; 708 var->right_margin = 100;
568 var->upper_margin=8; 709 var->upper_margin = 8;
569 var->lower_margin=16; 710 var->lower_margin = 16;
570 var->hsync_len=140; 711 var->hsync_len = 140;
571 var->vsync_len=30; 712 var->vsync_len = 30;
572 713
573 var->height=-1; 714 var->height = -1;
574 var->width=-1; 715 var->width = -1;
575 716
576 if (par->hw.tt.sync & 1) 717 if (par->hw.tt.sync & 1)
577 var->sync=0; 718 var->sync = 0;
578 else 719 else
579 var->sync=FB_SYNC_EXT; 720 var->sync = FB_SYNC_EXT;
580 721
581 switch (par->hw.tt.mode & TT_SHIFTER_MODEMASK) { 722 switch (par->hw.tt.mode & TT_SHIFTER_MODEMASK) {
582 case TT_SHIFTER_STLOW: 723 case TT_SHIFTER_STLOW:
583 var->xres=sttt_xres/2; 724 var->xres = sttt_xres / 2;
584 var->xres_virtual=sttt_xres_virtual/2; 725 var->xres_virtual = sttt_xres_virtual / 2;
585 var->yres=st_yres/2; 726 var->yres = st_yres / 2;
586 var->bits_per_pixel=4; 727 var->bits_per_pixel = 4;
587 break; 728 break;
588 case TT_SHIFTER_STMID: 729 case TT_SHIFTER_STMID:
589 var->xres=sttt_xres; 730 var->xres = sttt_xres;
590 var->xres_virtual=sttt_xres_virtual; 731 var->xres_virtual = sttt_xres_virtual;
591 var->yres=st_yres/2; 732 var->yres = st_yres / 2;
592 var->bits_per_pixel=2; 733 var->bits_per_pixel = 2;
593 break; 734 break;
594 case TT_SHIFTER_STHIGH: 735 case TT_SHIFTER_STHIGH:
595 var->xres=sttt_xres; 736 var->xres = sttt_xres;
596 var->xres_virtual=sttt_xres_virtual; 737 var->xres_virtual = sttt_xres_virtual;
597 var->yres=st_yres; 738 var->yres = st_yres;
598 var->bits_per_pixel=1; 739 var->bits_per_pixel = 1;
599 break; 740 break;
600 case TT_SHIFTER_TTLOW: 741 case TT_SHIFTER_TTLOW:
601 var->xres=sttt_xres/2; 742 var->xres = sttt_xres / 2;
602 var->xres_virtual=sttt_xres_virtual/2; 743 var->xres_virtual = sttt_xres_virtual / 2;
603 var->yres=tt_yres; 744 var->yres = tt_yres;
604 var->bits_per_pixel=8; 745 var->bits_per_pixel = 8;
605 break; 746 break;
606 case TT_SHIFTER_TTMID: 747 case TT_SHIFTER_TTMID:
607 var->xres=sttt_xres; 748 var->xres = sttt_xres;
608 var->xres_virtual=sttt_xres_virtual; 749 var->xres_virtual = sttt_xres_virtual;
609 var->yres=tt_yres; 750 var->yres = tt_yres;
610 var->bits_per_pixel=4; 751 var->bits_per_pixel = 4;
611 break; 752 break;
612 case TT_SHIFTER_TTHIGH: 753 case TT_SHIFTER_TTHIGH:
613 var->red.length=0; 754 var->red.length = 0;
614 var->xres=sttt_xres*2; 755 var->xres = sttt_xres * 2;
615 var->xres_virtual=sttt_xres_virtual*2; 756 var->xres_virtual = sttt_xres_virtual * 2;
616 var->yres=tt_yres*2; 757 var->yres = tt_yres * 2;
617 var->bits_per_pixel=1; 758 var->bits_per_pixel = 1;
618 break; 759 break;
619 } 760 }
620 var->blue=var->green=var->red; 761 var->blue = var->green = var->red;
621 var->transp.offset=0; 762 var->transp.offset = 0;
622 var->transp.length=0; 763 var->transp.length = 0;
623 var->transp.msb_right=0; 764 var->transp.msb_right = 0;
624 linelen=var->xres_virtual * var->bits_per_pixel / 8; 765 linelen = var->xres_virtual * var->bits_per_pixel / 8;
625 if (! use_hwscroll) 766 if (!use_hwscroll)
626 var->yres_virtual=var->yres; 767 var->yres_virtual = var->yres;
627 else if (screen_len) { 768 else if (screen_len) {
628 if (par->yres_virtual) 769 if (par->yres_virtual)
629 var->yres_virtual = par->yres_virtual; 770 var->yres_virtual = par->yres_virtual;
630 else 771 else
631 /* yres_virtual==0 means use maximum */ 772 /* yres_virtual == 0 means use maximum */
632 var->yres_virtual = screen_len / linelen; 773 var->yres_virtual = screen_len / linelen;
633 } else { 774 } else {
634 if (hwscroll < 0) 775 if (hwscroll < 0)
635 var->yres_virtual = 2 * var->yres; 776 var->yres_virtual = 2 * var->yres;
636 else 777 else
637 var->yres_virtual=var->yres+hwscroll * 16; 778 var->yres_virtual = var->yres + hwscroll * 16;
638 } 779 }
639 var->xoffset=0; 780 var->xoffset = 0;
640 if (screen_base) 781 if (screen_base)
641 var->yoffset=(par->screen_base - screen_base)/linelen; 782 var->yoffset = (par->screen_base - screen_base) / linelen;
642 else 783 else
643 var->yoffset=0; 784 var->yoffset = 0;
644 var->nonstd=0; 785 var->nonstd = 0;
645 var->activate=0; 786 var->activate = 0;
646 var->vmode=FB_VMODE_NONINTERLACED; 787 var->vmode = FB_VMODE_NONINTERLACED;
647 return 0; 788 return 0;
648} 789}
649 790
650 791static void tt_get_par(struct atafb_par *par)
651static void tt_get_par( struct atafb_par *par )
652{ 792{
653 unsigned long addr; 793 unsigned long addr;
654 par->hw.tt.mode=shifter_tt.tt_shiftmode; 794 par->hw.tt.mode = shifter_tt.tt_shiftmode;
655 par->hw.tt.sync=shifter.syncmode; 795 par->hw.tt.sync = shifter.syncmode;
656 addr = ((shifter.bas_hi & 0xff) << 16) | 796 addr = ((shifter.bas_hi & 0xff) << 16) |
657 ((shifter.bas_md & 0xff) << 8) | 797 ((shifter.bas_md & 0xff) << 8) |
658 ((shifter.bas_lo & 0xff)); 798 ((shifter.bas_lo & 0xff));
659 par->screen_base = phys_to_virt(addr); 799 par->screen_base = phys_to_virt(addr);
660} 800}
661 801
662static void tt_set_par( struct atafb_par *par ) 802static void tt_set_par(struct atafb_par *par)
663{ 803{
664 shifter_tt.tt_shiftmode=par->hw.tt.mode; 804 shifter_tt.tt_shiftmode = par->hw.tt.mode;
665 shifter.syncmode=par->hw.tt.sync; 805 shifter.syncmode = par->hw.tt.sync;
666 /* only set screen_base if really necessary */ 806 /* only set screen_base if really necessary */
667 if (current_par.screen_base != par->screen_base) 807 if (current_par.screen_base != par->screen_base)
668 fbhw->set_screen_base(par->screen_base); 808 fbhw->set_screen_base(par->screen_base);
669} 809}
670 810
671 811static int tt_setcolreg(unsigned int regno, unsigned int red,
672static int tt_getcolreg(unsigned regno, unsigned *red, 812 unsigned int green, unsigned int blue,
673 unsigned *green, unsigned *blue, 813 unsigned int transp, struct fb_info *info)
674 unsigned *transp, struct fb_info *info)
675{
676 int t, col;
677
678 if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
679 regno += 254;
680 if (regno > 255)
681 return 1;
682 t = tt_palette[regno];
683 col = t & 15;
684 col |= col << 4;
685 col |= col << 8;
686 *blue = col;
687 col = (t >> 4) & 15;
688 col |= col << 4;
689 col |= col << 8;
690 *green = col;
691 col = (t >> 8) & 15;
692 col |= col << 4;
693 col |= col << 8;
694 *red = col;
695 *transp = 0;
696 return 0;
697}
698
699
700static int tt_setcolreg(unsigned regno, unsigned red,
701 unsigned green, unsigned blue,
702 unsigned transp, struct fb_info *info)
703{ 814{
704 if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH) 815 if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
705 regno += 254; 816 regno += 254;
@@ -708,15 +819,14 @@ static int tt_setcolreg(unsigned regno, unsigned red,
708 tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) | 819 tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) |
709 (blue >> 12)); 820 (blue >> 12));
710 if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == 821 if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) ==
711 TT_SHIFTER_STHIGH && regno == 254) 822 TT_SHIFTER_STHIGH && regno == 254)
712 tt_palette[0] = 0; 823 tt_palette[0] = 0;
713 return 0; 824 return 0;
714} 825}
715 826
716 827static int tt_detect(void)
717static int tt_detect( void ) 828{
718 829 struct atafb_par par;
719{ struct atafb_par par;
720 830
721 /* Determine the connected monitor: The DMA sound must be 831 /* Determine the connected monitor: The DMA sound must be
722 * disabled before reading the MFP GPIP, because the Sound 832 * disabled before reading the MFP GPIP, because the Sound
@@ -726,9 +836,9 @@ static int tt_detect( void )
726 * announced that the Eagle is TT compatible, but only the PCM is 836 * announced that the Eagle is TT compatible, but only the PCM is
727 * missing... 837 * missing...
728 */ 838 */
729 if (ATARIHW_PRESENT(PCM_8BIT)) { 839 if (ATARIHW_PRESENT(PCM_8BIT)) {
730 tt_dmasnd.ctrl = DMASND_CTRL_OFF; 840 tt_dmasnd.ctrl = DMASND_CTRL_OFF;
731 udelay(20); /* wait a while for things to settle down */ 841 udelay(20); /* wait a while for things to settle down */
732 } 842 }
733 mono_moni = (mfp.par_dt_reg & 0x80) == 0; 843 mono_moni = (mfp.par_dt_reg & 0x80) == 0;
734 844
@@ -755,19 +865,24 @@ static struct pixel_clock {
755 unsigned long f; /* f/[Hz] */ 865 unsigned long f; /* f/[Hz] */
756 unsigned long t; /* t/[ps] (=1/f) */ 866 unsigned long t; /* t/[ps] (=1/f) */
757 int right, hsync, left; /* standard timing in clock cycles, not pixel */ 867 int right, hsync, left; /* standard timing in clock cycles, not pixel */
758 /* hsync initialized in falcon_detect() */ 868 /* hsync initialized in falcon_detect() */
759 int sync_mask; /* or-mask for hw.falcon.sync to set this clock */ 869 int sync_mask; /* or-mask for hw.falcon.sync to set this clock */
760 int control_mask; /* ditto, for hw.falcon.vid_control */ 870 int control_mask; /* ditto, for hw.falcon.vid_control */
761} 871} f25 = {
762f25 = {25175000, 39721, 18, 0, 42, 0x0, VCO_CLOCK25}, 872 25175000, 39721, 18, 0, 42, 0x0, VCO_CLOCK25
763f32 = {32000000, 31250, 18, 0, 42, 0x0, 0}, 873}, f32 = {
764fext = { 0, 0, 18, 0, 42, 0x1, 0}; 874 32000000, 31250, 18, 0, 42, 0x0, 0
875}, fext = {
876 0, 0, 18, 0, 42, 0x1, 0
877};
765 878
766/* VIDEL-prescale values [mon_type][pixel_length from VCO] */ 879/* VIDEL-prescale values [mon_type][pixel_length from VCO] */
767static int vdl_prescale[4][3] = {{4,2,1}, {4,2,1}, {4,2,2}, {4,2,1}}; 880static int vdl_prescale[4][3] = {
881 { 4,2,1 }, { 4,2,1 }, { 4,2,2 }, { 4,2,1 }
882};
768 883
769/* Default hsync timing [mon_type] in picoseconds */ 884/* Default hsync timing [mon_type] in picoseconds */
770static long h_syncs[4] = {3000000, 4875000, 4000000, 4875000}; 885static long h_syncs[4] = { 3000000, 4875000, 4000000, 4875000 };
771 886
772#ifdef FBCON_HAS_CFB16 887#ifdef FBCON_HAS_CFB16
773static u16 fbcon_cfb16_cmap[16]; 888static u16 fbcon_cfb16_cmap[16];
@@ -775,12 +890,12 @@ static u16 fbcon_cfb16_cmap[16];
775 890
776static inline int hxx_prescale(struct falcon_hw *hw) 891static inline int hxx_prescale(struct falcon_hw *hw)
777{ 892{
778 return hw->ste_mode ? 16 : 893 return hw->ste_mode ? 16
779 vdl_prescale[mon_type][hw->vid_mode >> 2 & 0x3]; 894 : vdl_prescale[mon_type][hw->vid_mode >> 2 & 0x3];
780} 895}
781 896
782static int falcon_encode_fix( struct fb_fix_screeninfo *fix, 897static int falcon_encode_fix(struct fb_fix_screeninfo *fix,
783 struct atafb_par *par ) 898 struct atafb_par *par)
784{ 899{
785 strcpy(fix->id, "Atari Builtin"); 900 strcpy(fix->id, "Atari Builtin");
786 fix->smem_start = (unsigned long)real_screen_base; 901 fix->smem_start = (unsigned long)real_screen_base;
@@ -796,8 +911,7 @@ static int falcon_encode_fix( struct fb_fix_screeninfo *fix,
796 fix->type_aux = 0; 911 fix->type_aux = 0;
797 /* no smooth scrolling with longword aligned video mem */ 912 /* no smooth scrolling with longword aligned video mem */
798 fix->xpanstep = 32; 913 fix->xpanstep = 32;
799 } 914 } else if (par->hw.falcon.f_shift & 0x100) {
800 else if (par->hw.falcon.f_shift & 0x100) {
801 fix->type = FB_TYPE_PACKED_PIXELS; 915 fix->type = FB_TYPE_PACKED_PIXELS;
802 fix->type_aux = 0; 916 fix->type_aux = 0;
803 /* Is this ok or should it be DIRECTCOLOR? */ 917 /* Is this ok or should it be DIRECTCOLOR? */
@@ -809,9 +923,8 @@ static int falcon_encode_fix( struct fb_fix_screeninfo *fix,
809 return 0; 923 return 0;
810} 924}
811 925
812 926static int falcon_decode_var(struct fb_var_screeninfo *var,
813static int falcon_decode_var( struct fb_var_screeninfo *var, 927 struct atafb_par *par)
814 struct atafb_par *par )
815{ 928{
816 int bpp = var->bits_per_pixel; 929 int bpp = var->bits_per_pixel;
817 int xres = var->xres; 930 int xres = var->xres;
@@ -823,17 +936,19 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
823 int linelen; 936 int linelen;
824 int interlace = 0, doubleline = 0; 937 int interlace = 0, doubleline = 0;
825 struct pixel_clock *pclock; 938 struct pixel_clock *pclock;
826 int plen; /* width of pixel in clock cycles */ 939 int plen; /* width of pixel in clock cycles */
827 int xstretch; 940 int xstretch;
828 int prescale; 941 int prescale;
829 int longoffset = 0; 942 int longoffset = 0;
830 int hfreq, vfreq; 943 int hfreq, vfreq;
944 int hdb_off, hde_off, base_off;
945 int gstart, gend1, gend2, align;
831 946
832/* 947/*
833 Get the video params out of 'var'. If a value doesn't fit, round 948 Get the video params out of 'var'. If a value doesn't fit, round
834 it up, if it's too big, return EINVAL. 949 it up, if it's too big, return EINVAL.
835 Round up in the following order: bits_per_pixel, xres, yres, 950 Round up in the following order: bits_per_pixel, xres, yres,
836 xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields, 951 xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
837 horizontal timing, vertical timing. 952 horizontal timing, vertical timing.
838 953
839 There is a maximum of screen resolution determined by pixelclock 954 There is a maximum of screen resolution determined by pixelclock
@@ -843,11 +958,11 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
843 Frequency range for multisync monitors is given via command line. 958 Frequency range for multisync monitors is given via command line.
844 For TV and SM124 both frequencies are fixed. 959 For TV and SM124 both frequencies are fixed.
845 960
846 X % 16 == 0 to fit 8x?? font (except 1 bitplane modes must use X%32==0) 961 X % 16 == 0 to fit 8x?? font (except 1 bitplane modes must use X%32 == 0)
847 Y % 16 == 0 to fit 8x16 font 962 Y % 16 == 0 to fit 8x16 font
848 Y % 8 == 0 if Y<400 963 Y % 8 == 0 if Y<400
849 964
850 Currently interlace and doubleline mode in var are ignored. 965 Currently interlace and doubleline mode in var are ignored.
851 On SM124 and TV only the standard resolutions can be used. 966 On SM124 and TV only the standard resolutions can be used.
852*/ 967*/
853 968
@@ -855,43 +970,38 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
855 if (!xres || !yres || !bpp) 970 if (!xres || !yres || !bpp)
856 return -EINVAL; 971 return -EINVAL;
857 972
858 if (mon_type == F_MON_SM && bpp != 1) { 973 if (mon_type == F_MON_SM && bpp != 1)
859 return -EINVAL; 974 return -EINVAL;
860 } 975
861 else if (bpp <= 1) { 976 if (bpp <= 1) {
862 bpp = 1; 977 bpp = 1;
863 par->hw.falcon.f_shift = 0x400; 978 par->hw.falcon.f_shift = 0x400;
864 par->hw.falcon.st_shift = 0x200; 979 par->hw.falcon.st_shift = 0x200;
865 } 980 } else if (bpp <= 2) {
866 else if (bpp <= 2) {
867 bpp = 2; 981 bpp = 2;
868 par->hw.falcon.f_shift = 0x000; 982 par->hw.falcon.f_shift = 0x000;
869 par->hw.falcon.st_shift = 0x100; 983 par->hw.falcon.st_shift = 0x100;
870 } 984 } else if (bpp <= 4) {
871 else if (bpp <= 4) {
872 bpp = 4; 985 bpp = 4;
873 par->hw.falcon.f_shift = 0x000; 986 par->hw.falcon.f_shift = 0x000;
874 par->hw.falcon.st_shift = 0x000; 987 par->hw.falcon.st_shift = 0x000;
875 } 988 } else if (bpp <= 8) {
876 else if (bpp <= 8) {
877 bpp = 8; 989 bpp = 8;
878 par->hw.falcon.f_shift = 0x010; 990 par->hw.falcon.f_shift = 0x010;
879 } 991 } else if (bpp <= 16) {
880 else if (bpp <= 16) { 992 bpp = 16; /* packed pixel mode */
881 bpp = 16; /* packed pixel mode */ 993 par->hw.falcon.f_shift = 0x100; /* hicolor, no overlay */
882 par->hw.falcon.f_shift = 0x100; /* hicolor, no overlay */ 994 } else
883 }
884 else
885 return -EINVAL; 995 return -EINVAL;
886 par->hw.falcon.bpp = bpp; 996 par->hw.falcon.bpp = bpp;
887 997
888 if (mon_type == F_MON_SM || DontCalcRes) { 998 if (mon_type == F_MON_SM || DontCalcRes) {
889 /* Skip all calculations. VGA/TV/SC1224 only supported. */ 999 /* Skip all calculations. VGA/TV/SC1224 only supported. */
890 struct fb_var_screeninfo *myvar = &atafb_predefined[0]; 1000 struct fb_var_screeninfo *myvar = &atafb_predefined[0];
891 1001
892 if (bpp > myvar->bits_per_pixel || 1002 if (bpp > myvar->bits_per_pixel ||
893 var->xres > myvar->xres || 1003 var->xres > myvar->xres ||
894 var->yres > myvar->yres) 1004 var->yres > myvar->yres)
895 return -EINVAL; 1005 return -EINVAL;
896 fbhw->get_par(par); /* Current par will be new par */ 1006 fbhw->get_par(par); /* Current par will be new par */
897 goto set_screen_base; /* Don't forget this */ 1007 goto set_screen_base; /* Don't forget this */
@@ -910,8 +1020,8 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
910 yres = 400; 1020 yres = 400;
911 1021
912 /* 2 planes must use STE compatibility mode */ 1022 /* 2 planes must use STE compatibility mode */
913 par->hw.falcon.ste_mode = bpp==2; 1023 par->hw.falcon.ste_mode = bpp == 2;
914 par->hw.falcon.mono = bpp==1; 1024 par->hw.falcon.mono = bpp == 1;
915 1025
916 /* Total and visible scanline length must be a multiple of one longword, 1026 /* Total and visible scanline length must be a multiple of one longword,
917 * this and the console fontwidth yields the alignment for xres and 1027 * this and the console fontwidth yields the alignment for xres and
@@ -967,8 +1077,7 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
967 left_margin = hsync_len = 128 / plen; 1077 left_margin = hsync_len = 128 / plen;
968 right_margin = 0; 1078 right_margin = 0;
969 /* TODO set all margins */ 1079 /* TODO set all margins */
970 } 1080 } else
971 else
972#endif 1081#endif
973 if (mon_type == F_MON_SC || mon_type == F_MON_TV) { 1082 if (mon_type == F_MON_SC || mon_type == F_MON_TV) {
974 plen = 2 * xstretch; 1083 plen = 2 * xstretch;
@@ -1002,26 +1111,24 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1002 vsync_len *= 2; 1111 vsync_len *= 2;
1003 } 1112 }
1004 } 1113 }
1005 } 1114 } else { /* F_MON_VGA */
1006 else
1007 { /* F_MON_VGA */
1008 if (bpp == 16) 1115 if (bpp == 16)
1009 xstretch = 2; /* Double pixel width only for hicolor */ 1116 xstretch = 2; /* Double pixel width only for hicolor */
1010 /* Default values are used for vert./hor. timing if no pixelclock given. */ 1117 /* Default values are used for vert./hor. timing if no pixelclock given. */
1011 if (var->pixclock == 0) { 1118 if (var->pixclock == 0) {
1012 int linesize; 1119 int linesize;
1013 1120
1014 /* Choose master pixelclock depending on hor. timing */ 1121 /* Choose master pixelclock depending on hor. timing */
1015 plen = 1 * xstretch; 1122 plen = 1 * xstretch;
1016 if ((plen * xres + f25.right+f25.hsync+f25.left) * 1123 if ((plen * xres + f25.right + f25.hsync + f25.left) *
1017 fb_info.monspecs.hfmin < f25.f) 1124 fb_info.monspecs.hfmin < f25.f)
1018 pclock = &f25; 1125 pclock = &f25;
1019 else if ((plen * xres + f32.right+f32.hsync+f32.left) * 1126 else if ((plen * xres + f32.right + f32.hsync +
1020 fb_info.monspecs.hfmin < f32.f) 1127 f32.left) * fb_info.monspecs.hfmin < f32.f)
1021 pclock = &f32; 1128 pclock = &f32;
1022 else if ((plen * xres + fext.right+fext.hsync+fext.left) * 1129 else if ((plen * xres + fext.right + fext.hsync +
1023 fb_info.monspecs.hfmin < fext.f 1130 fext.left) * fb_info.monspecs.hfmin < fext.f &&
1024 && fext.f) 1131 fext.f)
1025 pclock = &fext; 1132 pclock = &fext;
1026 else 1133 else
1027 return -EINVAL; 1134 return -EINVAL;
@@ -1033,22 +1140,24 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1033 upper_margin = 31; 1140 upper_margin = 31;
1034 lower_margin = 11; 1141 lower_margin = 11;
1035 vsync_len = 3; 1142 vsync_len = 3;
1036 } 1143 } else {
1037 else {
1038 /* Choose largest pixelclock <= wanted clock */ 1144 /* Choose largest pixelclock <= wanted clock */
1039 int i; 1145 int i;
1040 unsigned long pcl = ULONG_MAX; 1146 unsigned long pcl = ULONG_MAX;
1041 pclock = 0; 1147 pclock = 0;
1042 for (i=1; i <= 4; i *= 2) { 1148 for (i = 1; i <= 4; i *= 2) {
1043 if (f25.t*i >= var->pixclock && f25.t*i < pcl) { 1149 if (f25.t * i >= var->pixclock &&
1150 f25.t * i < pcl) {
1044 pcl = f25.t * i; 1151 pcl = f25.t * i;
1045 pclock = &f25; 1152 pclock = &f25;
1046 } 1153 }
1047 if (f32.t*i >= var->pixclock && f32.t*i < pcl) { 1154 if (f32.t * i >= var->pixclock &&
1155 f32.t * i < pcl) {
1048 pcl = f32.t * i; 1156 pcl = f32.t * i;
1049 pclock = &f32; 1157 pclock = &f32;
1050 } 1158 }
1051 if (fext.t && fext.t*i >= var->pixclock && fext.t*i < pcl) { 1159 if (fext.t && fext.t * i >= var->pixclock &&
1160 fext.t * i < pcl) {
1052 pcl = fext.t * i; 1161 pcl = fext.t * i;
1053 pclock = &fext; 1162 pclock = &fext;
1054 } 1163 }
@@ -1070,8 +1179,7 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1070 upper_margin = (upper_margin + 1) / 2; 1179 upper_margin = (upper_margin + 1) / 2;
1071 lower_margin = (lower_margin + 1) / 2; 1180 lower_margin = (lower_margin + 1) / 2;
1072 vsync_len = (vsync_len + 1) / 2; 1181 vsync_len = (vsync_len + 1) / 2;
1073 } 1182 } else if (var->vmode & FB_VMODE_DOUBLE) {
1074 else if (var->vmode & FB_VMODE_DOUBLE) {
1075 /* External unit is [double lines per frame] */ 1183 /* External unit is [double lines per frame] */
1076 upper_margin *= 2; 1184 upper_margin *= 2;
1077 lower_margin *= 2; 1185 lower_margin *= 2;
@@ -1079,7 +1187,7 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1079 } 1187 }
1080 } 1188 }
1081 if (pclock == &fext) 1189 if (pclock == &fext)
1082 longoffset = 1; /* VIDEL doesn't synchronize on short offset */ 1190 longoffset = 1; /* VIDEL doesn't synchronize on short offset */
1083 } 1191 }
1084 /* Is video bus bandwidth (32MB/s) too low for this resolution? */ 1192 /* Is video bus bandwidth (32MB/s) too low for this resolution? */
1085 /* this is definitely wrong if bus clock != 32MHz */ 1193 /* this is definitely wrong if bus clock != 32MHz */
@@ -1098,7 +1206,7 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1098 * between interlace and non-interlace without messing around 1206 * between interlace and non-interlace without messing around
1099 * with these. 1207 * with these.
1100 */ 1208 */
1101 again: 1209again:
1102 /* Set base_offset 128 and video bus width */ 1210 /* Set base_offset 128 and video bus width */
1103 par->hw.falcon.vid_control = mon_type | f030_bus_width; 1211 par->hw.falcon.vid_control = mon_type | f030_bus_width;
1104 if (!longoffset) 1212 if (!longoffset)
@@ -1112,37 +1220,34 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1112 /* External or internal clock */ 1220 /* External or internal clock */
1113 par->hw.falcon.sync = pclock->sync_mask | 0x2; 1221 par->hw.falcon.sync = pclock->sync_mask | 0x2;
1114 /* Pixellength and prescale */ 1222 /* Pixellength and prescale */
1115 par->hw.falcon.vid_mode = (2/plen) << 2; 1223 par->hw.falcon.vid_mode = (2 / plen) << 2;
1116 if (doubleline) 1224 if (doubleline)
1117 par->hw.falcon.vid_mode |= VMO_DOUBLE; 1225 par->hw.falcon.vid_mode |= VMO_DOUBLE;
1118 if (interlace) 1226 if (interlace)
1119 par->hw.falcon.vid_mode |= VMO_INTER; 1227 par->hw.falcon.vid_mode |= VMO_INTER;
1120 1228
1121 /********************* 1229 /*********************
1122 Horizontal timing: unit = [master clock cycles] 1230 * Horizontal timing: unit = [master clock cycles]
1123 unit of hxx-registers: [master clock cycles * prescale] 1231 * unit of hxx-registers: [master clock cycles * prescale]
1124 Hxx-registers are 9 bit wide 1232 * Hxx-registers are 9 bit wide
1125 1233 *
1126 1 line = ((hht + 2) * 2 * prescale) clock cycles 1234 * 1 line = ((hht + 2) * 2 * prescale) clock cycles
1127 1235 *
1128 graphic output = hdb & 0x200 ? 1236 * graphic output = hdb & 0x200 ?
1129 ((hht+2)*2 - hdb + hde) * prescale - hdboff + hdeoff: 1237 * ((hht + 2) * 2 - hdb + hde) * prescale - hdboff + hdeoff:
1130 ( hht + 2 - hdb + hde) * prescale - hdboff + hdeoff 1238 * (hht + 2 - hdb + hde) * prescale - hdboff + hdeoff
1131 (this must be a multiple of plen*128/bpp, on VGA pixels 1239 * (this must be a multiple of plen*128/bpp, on VGA pixels
1132 to the right may be cut off with a bigger right margin) 1240 * to the right may be cut off with a bigger right margin)
1133 1241 *
1134 start of graphics relative to start of 1st halfline = hdb & 0x200 ? 1242 * start of graphics relative to start of 1st halfline = hdb & 0x200 ?
1135 (hdb - hht - 2) * prescale + hdboff : 1243 * (hdb - hht - 2) * prescale + hdboff :
1136 hdb * prescale + hdboff 1244 * hdb * prescale + hdboff
1137 1245 *
1138 end of graphics relative to start of 1st halfline = 1246 * end of graphics relative to start of 1st halfline =
1139 (hde + hht + 2) * prescale + hdeoff 1247 * (hde + hht + 2) * prescale + hdeoff
1140 *********************/ 1248 *********************/
1141 /* Calculate VIDEL registers */ 1249 /* Calculate VIDEL registers */
1142 { 1250{
1143 int hdb_off, hde_off, base_off;
1144 int gstart, gend1, gend2, align;
1145
1146 prescale = hxx_prescale(&par->hw.falcon); 1251 prescale = hxx_prescale(&par->hw.falcon);
1147 base_off = par->hw.falcon.vid_control & VCO_SHORTOFFS ? 64 : 128; 1252 base_off = par->hw.falcon.vid_control & VCO_SHORTOFFS ? 64 : 128;
1148 1253
@@ -1154,8 +1259,7 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1154 align = 1; 1259 align = 1;
1155 hde_off = 0; 1260 hde_off = 0;
1156 hdb_off = (base_off + 16 * plen) + prescale; 1261 hdb_off = (base_off + 16 * plen) + prescale;
1157 } 1262 } else {
1158 else {
1159 align = 128 / bpp; 1263 align = 128 / bpp;
1160 hde_off = ((128 / bpp + 2) * plen); 1264 hde_off = ((128 / bpp + 2) * plen);
1161 if (par->hw.falcon.ste_mode) 1265 if (par->hw.falcon.ste_mode)
@@ -1164,23 +1268,24 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1164 hdb_off = (base_off + (128 / bpp + 18) * plen) + prescale; 1268 hdb_off = (base_off + (128 / bpp + 18) * plen) + prescale;
1165 } 1269 }
1166 1270
1167 gstart = (prescale/2 + plen * left_margin) / prescale; 1271 gstart = (prescale / 2 + plen * left_margin) / prescale;
1168 /* gend1 is for hde (gend-gstart multiple of align), shifter's xres */ 1272 /* gend1 is for hde (gend-gstart multiple of align), shifter's xres */
1169 gend1 = gstart + ((xres + align-1) / align)*align * plen / prescale; 1273 gend1 = gstart + ((xres + align - 1) / align) * align * plen / prescale;
1170 /* gend2 is for hbb, visible xres (rest to gend1 is cut off by hblank) */ 1274 /* gend2 is for hbb, visible xres (rest to gend1 is cut off by hblank) */
1171 gend2 = gstart + xres * plen / prescale; 1275 gend2 = gstart + xres * plen / prescale;
1172 par->HHT = plen * (left_margin + xres + right_margin) / 1276 par->HHT = plen * (left_margin + xres + right_margin) /
1173 (2 * prescale) - 2; 1277 (2 * prescale) - 2;
1174/* par->HHT = (gend2 + plen * right_margin / prescale) / 2 - 2;*/ 1278/* par->HHT = (gend2 + plen * right_margin / prescale) / 2 - 2;*/
1175 1279
1176 par->HDB = gstart - hdb_off/prescale; 1280 par->HDB = gstart - hdb_off / prescale;
1177 par->HBE = gstart; 1281 par->HBE = gstart;
1178 if (par->HDB < 0) par->HDB += par->HHT + 2 + 0x200; 1282 if (par->HDB < 0)
1179 par->HDE = gend1 - par->HHT - 2 - hde_off/prescale; 1283 par->HDB += par->HHT + 2 + 0x200;
1284 par->HDE = gend1 - par->HHT - 2 - hde_off / prescale;
1180 par->HBB = gend2 - par->HHT - 2; 1285 par->HBB = gend2 - par->HHT - 2;
1181#if 0 1286#if 0
1182 /* One more Videl constraint: data fetch of two lines must not overlap */ 1287 /* One more Videl constraint: data fetch of two lines must not overlap */
1183 if ((par->HDB & 0x200) && (par->HDB & ~0x200) - par->HDE <= 5) { 1288 if ((par->HDB & 0x200) && (par->HDB & ~0x200) - par->HDE <= 5) {
1184 /* if this happens increase margins, decrease hfreq. */ 1289 /* if this happens increase margins, decrease hfreq. */
1185 } 1290 }
1186#endif 1291#endif
@@ -1189,11 +1294,11 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1189 par->HSS = par->HHT + 2 - plen * hsync_len / prescale; 1294 par->HSS = par->HHT + 2 - plen * hsync_len / prescale;
1190 if (par->HSS < par->HBB) 1295 if (par->HSS < par->HBB)
1191 par->HSS = par->HBB; 1296 par->HSS = par->HBB;
1192 } 1297}
1193 1298
1194 /* check hor. frequency */ 1299 /* check hor. frequency */
1195 hfreq = pclock->f / ((par->HHT+2)*prescale*2); 1300 hfreq = pclock->f / ((par->HHT + 2) * prescale * 2);
1196 if (hfreq > fb_info.monspecs.hfmax && mon_type!=F_MON_VGA) { 1301 if (hfreq > fb_info.monspecs.hfmax && mon_type != F_MON_VGA) {
1197 /* ++guenther: ^^^^^^^^^^^^^^^^^^^ can't remember why I did this */ 1302 /* ++guenther: ^^^^^^^^^^^^^^^^^^^ can't remember why I did this */
1198 /* Too high -> enlarge margin */ 1303 /* Too high -> enlarge margin */
1199 left_margin += 1; 1304 left_margin += 1;
@@ -1213,12 +1318,14 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1213 par->VBE = (upper_margin * 2 + 1); /* must begin on odd halfline */ 1318 par->VBE = (upper_margin * 2 + 1); /* must begin on odd halfline */
1214 par->VDB = par->VBE; 1319 par->VDB = par->VBE;
1215 par->VDE = yres; 1320 par->VDE = yres;
1216 if (!interlace) par->VDE <<= 1; 1321 if (!interlace)
1217 if (doubleline) par->VDE <<= 1; /* VDE now half lines per (half-)frame */ 1322 par->VDE <<= 1;
1323 if (doubleline)
1324 par->VDE <<= 1; /* VDE now half lines per (half-)frame */
1218 par->VDE += par->VDB; 1325 par->VDE += par->VDB;
1219 par->VBB = par->VDE; 1326 par->VBB = par->VDE;
1220 par->VFT = par->VBB + (lower_margin * 2 - 1) - 1; 1327 par->VFT = par->VBB + (lower_margin * 2 - 1) - 1;
1221 par->VSS = par->VFT+1 - (vsync_len * 2 - 1); 1328 par->VSS = par->VFT + 1 - (vsync_len * 2 - 1);
1222 /* vbb,vss,vft must be even in interlace mode */ 1329 /* vbb,vss,vft must be even in interlace mode */
1223 if (interlace) { 1330 if (interlace) {
1224 par->VBB++; 1331 par->VBB++;
@@ -1229,55 +1336,53 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1229 /* V-frequency check, hope I didn't create any loop here. */ 1336 /* V-frequency check, hope I didn't create any loop here. */
1230 /* Interlace and doubleline are mutually exclusive. */ 1337 /* Interlace and doubleline are mutually exclusive. */
1231 vfreq = (hfreq * 2) / (par->VFT + 1); 1338 vfreq = (hfreq * 2) / (par->VFT + 1);
1232 if (vfreq > fb_info.monspecs.vfmax && !doubleline && !interlace) { 1339 if (vfreq > fb_info.monspecs.vfmax && !doubleline && !interlace) {
1233 /* Too high -> try again with doubleline */ 1340 /* Too high -> try again with doubleline */
1234 doubleline = 1; 1341 doubleline = 1;
1235 goto again; 1342 goto again;
1236 } 1343 } else if (vfreq < fb_info.monspecs.vfmin && !interlace && !doubleline) {
1237 else if (vfreq < fb_info.monspecs.vfmin && !interlace && !doubleline) {
1238 /* Too low -> try again with interlace */ 1344 /* Too low -> try again with interlace */
1239 interlace = 1; 1345 interlace = 1;
1240 goto again; 1346 goto again;
1241 } 1347 } else if (vfreq < fb_info.monspecs.vfmin && doubleline) {
1242 else if (vfreq < fb_info.monspecs.vfmin && doubleline) {
1243 /* Doubleline too low -> clear doubleline and enlarge margins */ 1348 /* Doubleline too low -> clear doubleline and enlarge margins */
1244 int lines; 1349 int lines;
1245 doubleline = 0; 1350 doubleline = 0;
1246 for (lines=0; 1351 for (lines = 0;
1247 (hfreq*2)/(par->VFT+1+4*lines-2*yres)>fb_info.monspecs.vfmax; 1352 (hfreq * 2) / (par->VFT + 1 + 4 * lines - 2 * yres) >
1353 fb_info.monspecs.vfmax;
1248 lines++) 1354 lines++)
1249 ; 1355 ;
1250 upper_margin += lines; 1356 upper_margin += lines;
1251 lower_margin += lines; 1357 lower_margin += lines;
1252 goto again; 1358 goto again;
1253 } 1359 } else if (vfreq > fb_info.monspecs.vfmax && doubleline) {
1254 else if (vfreq > fb_info.monspecs.vfmax && doubleline) {
1255 /* Doubleline too high -> enlarge margins */ 1360 /* Doubleline too high -> enlarge margins */
1256 int lines; 1361 int lines;
1257 for (lines=0; 1362 for (lines = 0;
1258 (hfreq*2)/(par->VFT+1+4*lines)>fb_info.monspecs.vfmax; 1363 (hfreq * 2) / (par->VFT + 1 + 4 * lines) >
1259 lines+=2) 1364 fb_info.monspecs.vfmax;
1365 lines += 2)
1260 ; 1366 ;
1261 upper_margin += lines; 1367 upper_margin += lines;
1262 lower_margin += lines; 1368 lower_margin += lines;
1263 goto again; 1369 goto again;
1264 } 1370 } else if (vfreq > fb_info.monspecs.vfmax && interlace) {
1265 else if (vfreq > fb_info.monspecs.vfmax && interlace) {
1266 /* Interlace, too high -> enlarge margins */ 1371 /* Interlace, too high -> enlarge margins */
1267 int lines; 1372 int lines;
1268 for (lines=0; 1373 for (lines = 0;
1269 (hfreq*2)/(par->VFT+1+4*lines)>fb_info.monspecs.vfmax; 1374 (hfreq * 2) / (par->VFT + 1 + 4 * lines) >
1375 fb_info.monspecs.vfmax;
1270 lines++) 1376 lines++)
1271 ; 1377 ;
1272 upper_margin += lines; 1378 upper_margin += lines;
1273 lower_margin += lines; 1379 lower_margin += lines;
1274 goto again; 1380 goto again;
1275 } 1381 } else if (vfreq < fb_info.monspecs.vfmin ||
1276 else if (vfreq < fb_info.monspecs.vfmin || 1382 vfreq > fb_info.monspecs.vfmax)
1277 vfreq > fb_info.monspecs.vfmax)
1278 return -EINVAL; 1383 return -EINVAL;
1279 1384
1280 set_screen_base: 1385set_screen_base:
1281 linelen = xres_virtual * bpp / 8; 1386 linelen = xres_virtual * bpp / 8;
1282 if (yres_virtual * linelen > screen_len && screen_len) 1387 if (yres_virtual * linelen > screen_len && screen_len)
1283 return -EINVAL; 1388 return -EINVAL;
@@ -1289,11 +1394,20 @@ static int falcon_decode_var( struct fb_var_screeninfo *var,
1289 par->screen_base = screen_base + var->yoffset * linelen; 1394 par->screen_base = screen_base + var->yoffset * linelen;
1290 par->hw.falcon.xoffset = 0; 1395 par->hw.falcon.xoffset = 0;
1291 1396
1397 // FIXME!!! sort of works, no crash
1398 //par->next_line = linelen;
1399 //par->next_plane = yres_virtual * linelen;
1400 par->next_line = linelen;
1401 par->next_plane = 2;
1402 // crashes
1403 //par->next_plane = linelen;
1404 //par->next_line = yres_virtual * linelen;
1405
1292 return 0; 1406 return 0;
1293} 1407}
1294 1408
1295static int falcon_encode_var( struct fb_var_screeninfo *var, 1409static int falcon_encode_var(struct fb_var_screeninfo *var,
1296 struct atafb_par *par ) 1410 struct atafb_par *par)
1297{ 1411{
1298/* !!! only for VGA !!! */ 1412/* !!! only for VGA !!! */
1299 int linelen; 1413 int linelen;
@@ -1306,10 +1420,10 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1306 var->pixclock = hw->sync & 0x1 ? fext.t : 1420 var->pixclock = hw->sync & 0x1 ? fext.t :
1307 hw->vid_control & VCO_CLOCK25 ? f25.t : f32.t; 1421 hw->vid_control & VCO_CLOCK25 ? f25.t : f32.t;
1308 1422
1309 var->height=-1; 1423 var->height = -1;
1310 var->width=-1; 1424 var->width = -1;
1311 1425
1312 var->sync=0; 1426 var->sync = 0;
1313 if (hw->vid_control & VCO_HSYPOS) 1427 if (hw->vid_control & VCO_HSYPOS)
1314 var->sync |= FB_SYNC_HOR_HIGH_ACT; 1428 var->sync |= FB_SYNC_HOR_HIGH_ACT;
1315 if (hw->vid_control & VCO_VSYPOS) 1429 if (hw->vid_control & VCO_VSYPOS)
@@ -1320,7 +1434,7 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1320 var->vmode |= FB_VMODE_INTERLACED; 1434 var->vmode |= FB_VMODE_INTERLACED;
1321 if (hw->vid_mode & VMO_DOUBLE) 1435 if (hw->vid_mode & VMO_DOUBLE)
1322 var->vmode |= FB_VMODE_DOUBLE; 1436 var->vmode |= FB_VMODE_DOUBLE;
1323 1437
1324 /* visible y resolution: 1438 /* visible y resolution:
1325 * Graphics display starts at line VDB and ends at line 1439 * Graphics display starts at line VDB and ends at line
1326 * VDE. If interlace mode off unit of VC-registers is 1440 * VDE. If interlace mode off unit of VC-registers is
@@ -1332,14 +1446,15 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1332 if (var->vmode & FB_VMODE_DOUBLE) 1446 if (var->vmode & FB_VMODE_DOUBLE)
1333 var->yres >>= 1; 1447 var->yres >>= 1;
1334 1448
1335 /* to get bpp, we must examine f_shift and st_shift. 1449 /*
1450 * to get bpp, we must examine f_shift and st_shift.
1336 * f_shift is valid if any of bits no. 10, 8 or 4 1451 * f_shift is valid if any of bits no. 10, 8 or 4
1337 * is set. Priority in f_shift is: 10 ">" 8 ">" 4, i.e. 1452 * is set. Priority in f_shift is: 10 ">" 8 ">" 4, i.e.
1338 * if bit 10 set then bit 8 and bit 4 don't care... 1453 * if bit 10 set then bit 8 and bit 4 don't care...
1339 * If all these bits are 0 get display depth from st_shift 1454 * If all these bits are 0 get display depth from st_shift
1340 * (as for ST and STE) 1455 * (as for ST and STE)
1341 */ 1456 */
1342 if (hw->f_shift & 0x400) /* 2 colors */ 1457 if (hw->f_shift & 0x400) /* 2 colors */
1343 var->bits_per_pixel = 1; 1458 var->bits_per_pixel = 1;
1344 else if (hw->f_shift & 0x100) /* hicolor */ 1459 else if (hw->f_shift & 0x100) /* hicolor */
1345 var->bits_per_pixel = 16; 1460 var->bits_per_pixel = 16;
@@ -1349,7 +1464,7 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1349 var->bits_per_pixel = 4; 1464 var->bits_per_pixel = 4;
1350 else if (hw->st_shift == 0x100) 1465 else if (hw->st_shift == 0x100)
1351 var->bits_per_pixel = 2; 1466 var->bits_per_pixel = 2;
1352 else /* if (hw->st_shift == 0x200) */ 1467 else /* if (hw->st_shift == 0x200) */
1353 var->bits_per_pixel = 1; 1468 var->bits_per_pixel = 1;
1354 1469
1355 var->xres = hw->line_width * 16 / var->bits_per_pixel; 1470 var->xres = hw->line_width * 16 / var->bits_per_pixel;
@@ -1358,42 +1473,42 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1358 var->xres_virtual += 16; 1473 var->xres_virtual += 16;
1359 1474
1360 if (var->bits_per_pixel == 16) { 1475 if (var->bits_per_pixel == 16) {
1361 var->red.offset=11; 1476 var->red.offset = 11;
1362 var->red.length=5; 1477 var->red.length = 5;
1363 var->red.msb_right=0; 1478 var->red.msb_right = 0;
1364 var->green.offset=5; 1479 var->green.offset = 5;
1365 var->green.length=6; 1480 var->green.length = 6;
1366 var->green.msb_right=0; 1481 var->green.msb_right = 0;
1367 var->blue.offset=0; 1482 var->blue.offset = 0;
1368 var->blue.length=5; 1483 var->blue.length = 5;
1369 var->blue.msb_right=0; 1484 var->blue.msb_right = 0;
1370 } 1485 } else {
1371 else { 1486 var->red.offset = 0;
1372 var->red.offset=0;
1373 var->red.length = hw->ste_mode ? 4 : 6; 1487 var->red.length = hw->ste_mode ? 4 : 6;
1374 var->red.msb_right=0; 1488 if (var->red.length > var->bits_per_pixel)
1375 var->grayscale=0; 1489 var->red.length = var->bits_per_pixel;
1376 var->blue=var->green=var->red; 1490 var->red.msb_right = 0;
1491 var->grayscale = 0;
1492 var->blue = var->green = var->red;
1377 } 1493 }
1378 var->transp.offset=0; 1494 var->transp.offset = 0;
1379 var->transp.length=0; 1495 var->transp.length = 0;
1380 var->transp.msb_right=0; 1496 var->transp.msb_right = 0;
1381 1497
1382 linelen = var->xres_virtual * var->bits_per_pixel / 8; 1498 linelen = var->xres_virtual * var->bits_per_pixel / 8;
1383 if (screen_len) { 1499 if (screen_len) {
1384 if (par->yres_virtual) 1500 if (par->yres_virtual)
1385 var->yres_virtual = par->yres_virtual; 1501 var->yres_virtual = par->yres_virtual;
1386 else 1502 else
1387 /* yres_virtual==0 means use maximum */ 1503 /* yres_virtual == 0 means use maximum */
1388 var->yres_virtual = screen_len / linelen; 1504 var->yres_virtual = screen_len / linelen;
1389 } 1505 } else {
1390 else {
1391 if (hwscroll < 0) 1506 if (hwscroll < 0)
1392 var->yres_virtual = 2 * var->yres; 1507 var->yres_virtual = 2 * var->yres;
1393 else 1508 else
1394 var->yres_virtual=var->yres+hwscroll * 16; 1509 var->yres_virtual = var->yres + hwscroll * 16;
1395 } 1510 }
1396 var->xoffset=0; /* TODO change this */ 1511 var->xoffset = 0; /* TODO change this */
1397 1512
1398 /* hdX-offsets */ 1513 /* hdX-offsets */
1399 prescale = hxx_prescale(hw); 1514 prescale = hxx_prescale(hw);
@@ -1402,8 +1517,7 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1402 if (hw->f_shift & 0x100) { 1517 if (hw->f_shift & 0x100) {
1403 hde_off = 0; 1518 hde_off = 0;
1404 hdb_off = (base_off + 16 * plen) + prescale; 1519 hdb_off = (base_off + 16 * plen) + prescale;
1405 } 1520 } else {
1406 else {
1407 hde_off = ((128 / var->bits_per_pixel + 2) * plen); 1521 hde_off = ((128 / var->bits_per_pixel + 2) * plen);
1408 if (hw->ste_mode) 1522 if (hw->ste_mode)
1409 hdb_off = (64 + base_off + (128 / var->bits_per_pixel + 2) * plen) 1523 hdb_off = (64 + base_off + (128 / var->bits_per_pixel + 2) * plen)
@@ -1415,8 +1529,8 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1415 1529
1416 /* Right margin includes hsync */ 1530 /* Right margin includes hsync */
1417 var->left_margin = hdb_off + prescale * ((hw->hdb & 0x1ff) - 1531 var->left_margin = hdb_off + prescale * ((hw->hdb & 0x1ff) -
1418 (hw->hdb & 0x200 ? 2+hw->hht : 0)); 1532 (hw->hdb & 0x200 ? 2 + hw->hht : 0));
1419 if (hw->ste_mode || mon_type!=F_MON_VGA) 1533 if (hw->ste_mode || mon_type != F_MON_VGA)
1420 var->right_margin = prescale * (hw->hht + 2 - hw->hde) - hde_off; 1534 var->right_margin = prescale * (hw->hht + 2 - hw->hde) - hde_off;
1421 else 1535 else
1422 /* can't use this in ste_mode, because hbb is +1 off */ 1536 /* can't use this in ste_mode, because hbb is +1 off */
@@ -1424,15 +1538,14 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1424 var->hsync_len = prescale * (hw->hht + 2 - hw->hss); 1538 var->hsync_len = prescale * (hw->hht + 2 - hw->hss);
1425 1539
1426 /* Lower margin includes vsync */ 1540 /* Lower margin includes vsync */
1427 var->upper_margin = hw->vdb / 2 ; /* round down to full lines */ 1541 var->upper_margin = hw->vdb / 2; /* round down to full lines */
1428 var->lower_margin = (hw->vft+1 - hw->vde + 1) / 2; /* round up */ 1542 var->lower_margin = (hw->vft + 1 - hw->vde + 1) / 2; /* round up */
1429 var->vsync_len = (hw->vft+1 - hw->vss + 1) / 2; /* round up */ 1543 var->vsync_len = (hw->vft + 1 - hw->vss + 1) / 2; /* round up */
1430 if (var->vmode & FB_VMODE_INTERLACED) { 1544 if (var->vmode & FB_VMODE_INTERLACED) {
1431 var->upper_margin *= 2; 1545 var->upper_margin *= 2;
1432 var->lower_margin *= 2; 1546 var->lower_margin *= 2;
1433 var->vsync_len *= 2; 1547 var->vsync_len *= 2;
1434 } 1548 } else if (var->vmode & FB_VMODE_DOUBLE) {
1435 else if (var->vmode & FB_VMODE_DOUBLE) {
1436 var->upper_margin = (var->upper_margin + 1) / 2; 1549 var->upper_margin = (var->upper_margin + 1) / 2;
1437 var->lower_margin = (var->lower_margin + 1) / 2; 1550 var->lower_margin = (var->lower_margin + 1) / 2;
1438 var->vsync_len = (var->vsync_len + 1) / 2; 1551 var->vsync_len = (var->vsync_len + 1) / 2;
@@ -1447,20 +1560,19 @@ static int falcon_encode_var( struct fb_var_screeninfo *var,
1447 var->lower_margin -= var->vsync_len; 1560 var->lower_margin -= var->vsync_len;
1448 1561
1449 if (screen_base) 1562 if (screen_base)
1450 var->yoffset=(par->screen_base - screen_base)/linelen; 1563 var->yoffset = (par->screen_base - screen_base) / linelen;
1451 else 1564 else
1452 var->yoffset=0; 1565 var->yoffset = 0;
1453 var->nonstd=0; /* what is this for? */ 1566 var->nonstd = 0; /* what is this for? */
1454 var->activate=0; 1567 var->activate = 0;
1455 return 0; 1568 return 0;
1456} 1569}
1457 1570
1458 1571static int f_change_mode;
1459static int f_change_mode = 0;
1460static struct falcon_hw f_new_mode; 1572static struct falcon_hw f_new_mode;
1461static int f_pan_display = 0; 1573static int f_pan_display;
1462 1574
1463static void falcon_get_par( struct atafb_par *par ) 1575static void falcon_get_par(struct atafb_par *par)
1464{ 1576{
1465 unsigned long addr; 1577 unsigned long addr;
1466 struct falcon_hw *hw = &par->hw.falcon; 1578 struct falcon_hw *hw = &par->hw.falcon;
@@ -1492,12 +1604,12 @@ static void falcon_get_par( struct atafb_par *par )
1492 par->screen_base = phys_to_virt(addr); 1604 par->screen_base = phys_to_virt(addr);
1493 1605
1494 /* derived parameters */ 1606 /* derived parameters */
1495 hw->ste_mode = (hw->f_shift & 0x510)==0 && hw->st_shift==0x100; 1607 hw->ste_mode = (hw->f_shift & 0x510) == 0 && hw->st_shift == 0x100;
1496 hw->mono = (hw->f_shift & 0x400) || 1608 hw->mono = (hw->f_shift & 0x400) ||
1497 ((hw->f_shift & 0x510)==0 && hw->st_shift==0x200); 1609 ((hw->f_shift & 0x510) == 0 && hw->st_shift == 0x200);
1498} 1610}
1499 1611
1500static void falcon_set_par( struct atafb_par *par ) 1612static void falcon_set_par(struct atafb_par *par)
1501{ 1613{
1502 f_change_mode = 0; 1614 f_change_mode = 0;
1503 1615
@@ -1519,8 +1631,7 @@ static void falcon_set_par( struct atafb_par *par )
1519 f_change_mode = 1; 1631 f_change_mode = 1;
1520} 1632}
1521 1633
1522 1634static irqreturn_t falcon_vbl_switcher(int irq, void *dummy)
1523static irqreturn_t falcon_vbl_switcher( int irq, void *dummy )
1524{ 1635{
1525 struct falcon_hw *hw = &f_new_mode; 1636 struct falcon_hw *hw = &f_new_mode;
1526 1637
@@ -1529,11 +1640,10 @@ static irqreturn_t falcon_vbl_switcher( int irq, void *dummy )
1529 1640
1530 if (hw->sync & 0x1) { 1641 if (hw->sync & 0x1) {
1531 /* Enable external pixelclock. This code only for ScreenWonder */ 1642 /* Enable external pixelclock. This code only for ScreenWonder */
1532 *(volatile unsigned short*)0xffff9202 = 0xffbf; 1643 *(volatile unsigned short *)0xffff9202 = 0xffbf;
1533 } 1644 } else {
1534 else {
1535 /* Turn off external clocks. Read sets all output bits to 1. */ 1645 /* Turn off external clocks. Read sets all output bits to 1. */
1536 *(volatile unsigned short*)0xffff9202; 1646 *(volatile unsigned short *)0xffff9202;
1537 } 1647 }
1538 shifter.syncmode = hw->sync; 1648 shifter.syncmode = hw->sync;
1539 1649
@@ -1550,15 +1660,14 @@ static irqreturn_t falcon_vbl_switcher( int irq, void *dummy )
1550 videl.vde = hw->vde; 1660 videl.vde = hw->vde;
1551 videl.vss = hw->vss; 1661 videl.vss = hw->vss;
1552 1662
1553 videl.f_shift = 0; /* write enables Falcon palette, 0: 4 planes */ 1663 videl.f_shift = 0; /* write enables Falcon palette, 0: 4 planes */
1554 if (hw->ste_mode) { 1664 if (hw->ste_mode) {
1555 videl.st_shift = hw->st_shift; /* write enables STE palette */ 1665 videl.st_shift = hw->st_shift; /* write enables STE palette */
1556 } 1666 } else {
1557 else {
1558 /* IMPORTANT: 1667 /* IMPORTANT:
1559 * set st_shift 0, so we can tell the screen-depth if f_shift==0. 1668 * set st_shift 0, so we can tell the screen-depth if f_shift == 0.
1560 * Writing 0 to f_shift enables 4 plane Falcon mode but 1669 * Writing 0 to f_shift enables 4 plane Falcon mode but
1561 * doesn't set st_shift. st_shift!=0 (!=4planes) is impossible 1670 * doesn't set st_shift. st_shift != 0 (!= 4planes) is impossible
1562 * with Falcon palette. 1671 * with Falcon palette.
1563 */ 1672 */
1564 videl.st_shift = 0; 1673 videl.st_shift = 0;
@@ -1580,12 +1689,13 @@ static irqreturn_t falcon_vbl_switcher( int irq, void *dummy )
1580 return IRQ_HANDLED; 1689 return IRQ_HANDLED;
1581} 1690}
1582 1691
1583 1692static int falcon_pan_display(struct fb_var_screeninfo *var,
1584static int falcon_pan_display( struct fb_var_screeninfo *var, 1693 struct fb_info *info)
1585 struct atafb_par *par )
1586{ 1694{
1695 struct atafb_par *par = (struct atafb_par *)info->par;
1696
1587 int xoffset; 1697 int xoffset;
1588 int bpp = fb_display[fb_info.currcon].var.bits_per_pixel; 1698 int bpp = info->var.bits_per_pixel;
1589 1699
1590 if (bpp == 1) 1700 if (bpp == 1)
1591 var->xoffset = up(var->xoffset, 32); 1701 var->xoffset = up(var->xoffset, 32);
@@ -1596,45 +1706,24 @@ static int falcon_pan_display( struct fb_var_screeninfo *var,
1596 var->xoffset = up(var->xoffset, 2); 1706 var->xoffset = up(var->xoffset, 2);
1597 } 1707 }
1598 par->hw.falcon.line_offset = bpp * 1708 par->hw.falcon.line_offset = bpp *
1599 (fb_display[fb_info.currcon].var.xres_virtual - fb_display[fb_info.currcon].var.xres) / 16; 1709 (info->var.xres_virtual - info->var.xres) / 16;
1600 if (par->hw.falcon.xoffset) 1710 if (par->hw.falcon.xoffset)
1601 par->hw.falcon.line_offset -= bpp; 1711 par->hw.falcon.line_offset -= bpp;
1602 xoffset = var->xoffset - par->hw.falcon.xoffset; 1712 xoffset = var->xoffset - par->hw.falcon.xoffset;
1603 1713
1604 par->screen_base = screen_base + 1714 par->screen_base = screen_base +
1605 (var->yoffset * fb_display[fb_info.currcon].var.xres_virtual + xoffset) * bpp / 8; 1715 (var->yoffset * info->var.xres_virtual + xoffset) * bpp / 8;
1606 if (fbhw->set_screen_base) 1716 if (fbhw->set_screen_base)
1607 fbhw->set_screen_base (par->screen_base); 1717 fbhw->set_screen_base(par->screen_base);
1608 else 1718 else
1609 return -EINVAL; /* shouldn't happen */ 1719 return -EINVAL; /* shouldn't happen */
1610 f_pan_display = 1; 1720 f_pan_display = 1;
1611 return 0; 1721 return 0;
1612} 1722}
1613 1723
1614 1724static int falcon_setcolreg(unsigned int regno, unsigned int red,
1615static int falcon_getcolreg( unsigned regno, unsigned *red, 1725 unsigned int green, unsigned int blue,
1616 unsigned *green, unsigned *blue, 1726 unsigned int transp, struct fb_info *info)
1617 unsigned *transp, struct fb_info *info )
1618{ unsigned long col;
1619
1620 if (regno > 255)
1621 return 1;
1622 /* This works in STE-mode (with 4bit/color) since f030_col-registers
1623 * hold up to 6bit/color.
1624 * Even with hicolor r/g/b=5/6/5 bit!
1625 */
1626 col = f030_col[regno];
1627 *red = (col >> 16) & 0xff00;
1628 *green = (col >> 8) & 0xff00;
1629 *blue = (col << 8) & 0xff00;
1630 *transp = 0;
1631 return 0;
1632}
1633
1634
1635static int falcon_setcolreg( unsigned regno, unsigned red,
1636 unsigned green, unsigned blue,
1637 unsigned transp, struct fb_info *info )
1638{ 1727{
1639 if (regno > 255) 1728 if (regno > 255)
1640 return 1; 1729 return 1;
@@ -1655,13 +1744,12 @@ static int falcon_setcolreg( unsigned regno, unsigned red,
1655 return 0; 1744 return 0;
1656} 1745}
1657 1746
1658 1747static int falcon_blank(int blank_mode)
1659static int falcon_blank( int blank_mode )
1660{ 1748{
1661/* ++guenther: we can switch off graphics by changing VDB and VDE, 1749 /* ++guenther: we can switch off graphics by changing VDB and VDE,
1662 * so VIDEL doesn't hog the bus while saving. 1750 * so VIDEL doesn't hog the bus while saving.
1663 * (this may affect usleep()). 1751 * (this may affect usleep()).
1664 */ 1752 */
1665 int vdb, vss, hbe, hss; 1753 int vdb, vss, hbe, hss;
1666 1754
1667 if (mon_type == F_MON_SM) /* this doesn't work on SM124 */ 1755 if (mon_type == F_MON_SM) /* this doesn't work on SM124 */
@@ -1694,14 +1782,13 @@ static int falcon_blank( int blank_mode )
1694 return 0; 1782 return 0;
1695} 1783}
1696 1784
1697 1785static int falcon_detect(void)
1698static int falcon_detect( void )
1699{ 1786{
1700 struct atafb_par par; 1787 struct atafb_par par;
1701 unsigned char fhw; 1788 unsigned char fhw;
1702 1789
1703 /* Determine connected monitor and set monitor parameters */ 1790 /* Determine connected monitor and set monitor parameters */
1704 fhw = *(unsigned char*)0xffff8006; 1791 fhw = *(unsigned char *)0xffff8006;
1705 mon_type = fhw >> 6 & 0x3; 1792 mon_type = fhw >> 6 & 0x3;
1706 /* bit 1 of fhw: 1=32 bit ram bus, 0=16 bit */ 1793 /* bit 1 of fhw: 1=32 bit ram bus, 0=16 bit */
1707 f030_bus_width = fhw << 6 & 0x80; 1794 f030_bus_width = fhw << 6 & 0x80;
@@ -1715,7 +1802,7 @@ static int falcon_detect( void )
1715 case F_MON_SC: 1802 case F_MON_SC:
1716 case F_MON_TV: 1803 case F_MON_TV:
1717 /* PAL...NTSC */ 1804 /* PAL...NTSC */
1718 fb_info.monspecs.vfmin = 49; /* not 50, since TOS defaults to 49.9x Hz */ 1805 fb_info.monspecs.vfmin = 49; /* not 50, since TOS defaults to 49.9x Hz */
1719 fb_info.monspecs.vfmax = 60; 1806 fb_info.monspecs.vfmax = 60;
1720 fb_info.monspecs.hfmin = 15620; 1807 fb_info.monspecs.hfmin = 15620;
1721 fb_info.monspecs.hfmax = 15755; 1808 fb_info.monspecs.hfmax = 15755;
@@ -1740,13 +1827,12 @@ static int falcon_detect( void )
1740 1827
1741#ifdef ATAFB_STE 1828#ifdef ATAFB_STE
1742 1829
1743static int stste_encode_fix( struct fb_fix_screeninfo *fix, 1830static int stste_encode_fix(struct fb_fix_screeninfo *fix,
1744 struct atafb_par *par ) 1831 struct atafb_par *par)
1745
1746{ 1832{
1747 int mode; 1833 int mode;
1748 1834
1749 strcpy(fix->id,"Atari Builtin"); 1835 strcpy(fix->id, "Atari Builtin");
1750 fix->smem_start = (unsigned long)real_screen_base; 1836 fix->smem_start = (unsigned long)real_screen_base;
1751 fix->smem_len = screen_len; 1837 fix->smem_len = screen_len;
1752 fix->type = FB_TYPE_INTERLEAVED_PLANES; 1838 fix->type = FB_TYPE_INTERLEAVED_PLANES;
@@ -1771,43 +1857,40 @@ static int stste_encode_fix( struct fb_fix_screeninfo *fix,
1771 return 0; 1857 return 0;
1772} 1858}
1773 1859
1774 1860static int stste_decode_var(struct fb_var_screeninfo *var,
1775static int stste_decode_var( struct fb_var_screeninfo *var, 1861 struct atafb_par *par)
1776 struct atafb_par *par )
1777{ 1862{
1778 int xres=var->xres; 1863 int xres = var->xres;
1779 int yres=var->yres; 1864 int yres = var->yres;
1780 int bpp=var->bits_per_pixel; 1865 int bpp = var->bits_per_pixel;
1781 int linelen; 1866 int linelen;
1782 int yres_virtual = var->yres_virtual; 1867 int yres_virtual = var->yres_virtual;
1783 1868
1784 if (mono_moni) { 1869 if (mono_moni) {
1785 if (bpp > 1 || xres > sttt_xres || yres > st_yres) 1870 if (bpp > 1 || xres > sttt_xres || yres > st_yres)
1786 return -EINVAL; 1871 return -EINVAL;
1787 par->hw.st.mode=ST_HIGH; 1872 par->hw.st.mode = ST_HIGH;
1788 xres=sttt_xres; 1873 xres = sttt_xres;
1789 yres=st_yres; 1874 yres = st_yres;
1790 bpp=1; 1875 bpp = 1;
1791 } else { 1876 } else {
1792 if (bpp > 4 || xres > sttt_xres || yres > st_yres) 1877 if (bpp > 4 || xres > sttt_xres || yres > st_yres)
1793 return -EINVAL; 1878 return -EINVAL;
1794 if (bpp > 2) { 1879 if (bpp > 2) {
1795 if (xres > sttt_xres/2 || yres > st_yres/2) 1880 if (xres > sttt_xres / 2 || yres > st_yres / 2)
1796 return -EINVAL; 1881 return -EINVAL;
1797 par->hw.st.mode=ST_LOW; 1882 par->hw.st.mode = ST_LOW;
1798 xres=sttt_xres/2; 1883 xres = sttt_xres / 2;
1799 yres=st_yres/2; 1884 yres = st_yres / 2;
1800 bpp=4; 1885 bpp = 4;
1801 } 1886 } else if (bpp > 1) {
1802 else if (bpp > 1) { 1887 if (xres > sttt_xres || yres > st_yres / 2)
1803 if (xres > sttt_xres || yres > st_yres/2)
1804 return -EINVAL; 1888 return -EINVAL;
1805 par->hw.st.mode=ST_MID; 1889 par->hw.st.mode = ST_MID;
1806 xres=sttt_xres; 1890 xres = sttt_xres;
1807 yres=st_yres/2; 1891 yres = st_yres / 2;
1808 bpp=2; 1892 bpp = 2;
1809 } 1893 } else
1810 else
1811 return -EINVAL; 1894 return -EINVAL;
1812 } 1895 }
1813 if (yres_virtual <= 0) 1896 if (yres_virtual <= 0)
@@ -1815,10 +1898,10 @@ static int stste_decode_var( struct fb_var_screeninfo *var,
1815 else if (yres_virtual < yres) 1898 else if (yres_virtual < yres)
1816 yres_virtual = yres; 1899 yres_virtual = yres;
1817 if (var->sync & FB_SYNC_EXT) 1900 if (var->sync & FB_SYNC_EXT)
1818 par->hw.st.sync=(par->hw.st.sync & ~1) | 1; 1901 par->hw.st.sync = (par->hw.st.sync & ~1) | 1;
1819 else 1902 else
1820 par->hw.st.sync=(par->hw.st.sync & ~1); 1903 par->hw.st.sync = (par->hw.st.sync & ~1);
1821 linelen=xres*bpp/8; 1904 linelen = xres * bpp / 8;
1822 if (yres_virtual * linelen > screen_len && screen_len) 1905 if (yres_virtual * linelen > screen_len && screen_len)
1823 return -EINVAL; 1906 return -EINVAL;
1824 if (yres * linelen > screen_len && screen_len) 1907 if (yres * linelen > screen_len && screen_len)
@@ -1826,93 +1909,91 @@ static int stste_decode_var( struct fb_var_screeninfo *var,
1826 if (var->yoffset + yres > yres_virtual && yres_virtual) 1909 if (var->yoffset + yres > yres_virtual && yres_virtual)
1827 return -EINVAL; 1910 return -EINVAL;
1828 par->yres_virtual = yres_virtual; 1911 par->yres_virtual = yres_virtual;
1829 par->screen_base=screen_base+ var->yoffset*linelen; 1912 par->screen_base = screen_base + var->yoffset * linelen;
1830 return 0; 1913 return 0;
1831} 1914}
1832 1915
1833static int stste_encode_var( struct fb_var_screeninfo *var, 1916static int stste_encode_var(struct fb_var_screeninfo *var,
1834 struct atafb_par *par ) 1917 struct atafb_par *par)
1835{ 1918{
1836 int linelen; 1919 int linelen;
1837 memset(var, 0, sizeof(struct fb_var_screeninfo)); 1920 memset(var, 0, sizeof(struct fb_var_screeninfo));
1838 var->red.offset=0; 1921 var->red.offset = 0;
1839 var->red.length = ATARIHW_PRESENT(EXTD_SHIFTER) ? 4 : 3; 1922 var->red.length = ATARIHW_PRESENT(EXTD_SHIFTER) ? 4 : 3;
1840 var->red.msb_right=0; 1923 var->red.msb_right = 0;
1841 var->grayscale=0; 1924 var->grayscale = 0;
1842 1925
1843 var->pixclock=31041; 1926 var->pixclock = 31041;
1844 var->left_margin=120; /* these are incorrect */ 1927 var->left_margin = 120; /* these are incorrect */
1845 var->right_margin=100; 1928 var->right_margin = 100;
1846 var->upper_margin=8; 1929 var->upper_margin = 8;
1847 var->lower_margin=16; 1930 var->lower_margin = 16;
1848 var->hsync_len=140; 1931 var->hsync_len = 140;
1849 var->vsync_len=30; 1932 var->vsync_len = 30;
1850 1933
1851 var->height=-1; 1934 var->height = -1;
1852 var->width=-1; 1935 var->width = -1;
1853 1936
1854 if (!(par->hw.st.sync & 1)) 1937 if (!(par->hw.st.sync & 1))
1855 var->sync=0; 1938 var->sync = 0;
1856 else 1939 else
1857 var->sync=FB_SYNC_EXT; 1940 var->sync = FB_SYNC_EXT;
1858 1941
1859 switch (par->hw.st.mode & 3) { 1942 switch (par->hw.st.mode & 3) {
1860 case ST_LOW: 1943 case ST_LOW:
1861 var->xres=sttt_xres/2; 1944 var->xres = sttt_xres / 2;
1862 var->yres=st_yres/2; 1945 var->yres = st_yres / 2;
1863 var->bits_per_pixel=4; 1946 var->bits_per_pixel = 4;
1864 break; 1947 break;
1865 case ST_MID: 1948 case ST_MID:
1866 var->xres=sttt_xres; 1949 var->xres = sttt_xres;
1867 var->yres=st_yres/2; 1950 var->yres = st_yres / 2;
1868 var->bits_per_pixel=2; 1951 var->bits_per_pixel = 2;
1869 break; 1952 break;
1870 case ST_HIGH: 1953 case ST_HIGH:
1871 var->xres=sttt_xres; 1954 var->xres = sttt_xres;
1872 var->yres=st_yres; 1955 var->yres = st_yres;
1873 var->bits_per_pixel=1; 1956 var->bits_per_pixel = 1;
1874 break; 1957 break;
1875 } 1958 }
1876 var->blue=var->green=var->red; 1959 var->blue = var->green = var->red;
1877 var->transp.offset=0; 1960 var->transp.offset = 0;
1878 var->transp.length=0; 1961 var->transp.length = 0;
1879 var->transp.msb_right=0; 1962 var->transp.msb_right = 0;
1880 var->xres_virtual=sttt_xres_virtual; 1963 var->xres_virtual = sttt_xres_virtual;
1881 linelen=var->xres_virtual * var->bits_per_pixel / 8; 1964 linelen = var->xres_virtual * var->bits_per_pixel / 8;
1882 ovsc_addlen=linelen*(sttt_yres_virtual - st_yres); 1965 ovsc_addlen = linelen * (sttt_yres_virtual - st_yres);
1883 1966
1884 if (! use_hwscroll) 1967 if (!use_hwscroll)
1885 var->yres_virtual=var->yres; 1968 var->yres_virtual = var->yres;
1886 else if (screen_len) { 1969 else if (screen_len) {
1887 if (par->yres_virtual) 1970 if (par->yres_virtual)
1888 var->yres_virtual = par->yres_virtual; 1971 var->yres_virtual = par->yres_virtual;
1889 else 1972 else
1890 /* yres_virtual==0 means use maximum */ 1973 /* yres_virtual == 0 means use maximum */
1891 var->yres_virtual = screen_len / linelen; 1974 var->yres_virtual = screen_len / linelen;
1892 } 1975 } else {
1893 else {
1894 if (hwscroll < 0) 1976 if (hwscroll < 0)
1895 var->yres_virtual = 2 * var->yres; 1977 var->yres_virtual = 2 * var->yres;
1896 else 1978 else
1897 var->yres_virtual=var->yres+hwscroll * 16; 1979 var->yres_virtual = var->yres + hwscroll * 16;
1898 } 1980 }
1899 var->xoffset=0; 1981 var->xoffset = 0;
1900 if (screen_base) 1982 if (screen_base)
1901 var->yoffset=(par->screen_base - screen_base)/linelen; 1983 var->yoffset = (par->screen_base - screen_base) / linelen;
1902 else 1984 else
1903 var->yoffset=0; 1985 var->yoffset = 0;
1904 var->nonstd=0; 1986 var->nonstd = 0;
1905 var->activate=0; 1987 var->activate = 0;
1906 var->vmode=FB_VMODE_NONINTERLACED; 1988 var->vmode = FB_VMODE_NONINTERLACED;
1907 return 0; 1989 return 0;
1908} 1990}
1909 1991
1910 1992static void stste_get_par(struct atafb_par *par)
1911static void stste_get_par( struct atafb_par *par )
1912{ 1993{
1913 unsigned long addr; 1994 unsigned long addr;
1914 par->hw.st.mode=shifter_tt.st_shiftmode; 1995 par->hw.st.mode = shifter_tt.st_shiftmode;
1915 par->hw.st.sync=shifter.syncmode; 1996 par->hw.st.sync = shifter.syncmode;
1916 addr = ((shifter.bas_hi & 0xff) << 16) | 1997 addr = ((shifter.bas_hi & 0xff) << 16) |
1917 ((shifter.bas_md & 0xff) << 8); 1998 ((shifter.bas_md & 0xff) << 8);
1918 if (ATARIHW_PRESENT(EXTD_SHIFTER)) 1999 if (ATARIHW_PRESENT(EXTD_SHIFTER))
@@ -1920,55 +2001,18 @@ static void stste_get_par( struct atafb_par *par )
1920 par->screen_base = phys_to_virt(addr); 2001 par->screen_base = phys_to_virt(addr);
1921} 2002}
1922 2003
1923static void stste_set_par( struct atafb_par *par ) 2004static void stste_set_par(struct atafb_par *par)
1924{ 2005{
1925 shifter_tt.st_shiftmode=par->hw.st.mode; 2006 shifter_tt.st_shiftmode = par->hw.st.mode;
1926 shifter.syncmode=par->hw.st.sync; 2007 shifter.syncmode = par->hw.st.sync;
1927 /* only set screen_base if really necessary */ 2008 /* only set screen_base if really necessary */
1928 if (current_par.screen_base != par->screen_base) 2009 if (current_par.screen_base != par->screen_base)
1929 fbhw->set_screen_base(par->screen_base); 2010 fbhw->set_screen_base(par->screen_base);
1930} 2011}
1931 2012
1932 2013static int stste_setcolreg(unsigned int regno, unsigned int red,
1933static int stste_getcolreg(unsigned regno, unsigned *red, 2014 unsigned int green, unsigned int blue,
1934 unsigned *green, unsigned *blue, 2015 unsigned int transp, struct fb_info *info)
1935 unsigned *transp, struct fb_info *info)
1936{
1937 unsigned col, t;
1938
1939 if (regno > 15)
1940 return 1;
1941 col = shifter_tt.color_reg[regno];
1942 if (ATARIHW_PRESENT(EXTD_SHIFTER)) {
1943 t = ((col >> 7) & 0xe) | ((col >> 11) & 1);
1944 t |= t << 4;
1945 *red = t | (t << 8);
1946 t = ((col >> 3) & 0xe) | ((col >> 7) & 1);
1947 t |= t << 4;
1948 *green = t | (t << 8);
1949 t = ((col << 1) & 0xe) | ((col >> 3) & 1);
1950 t |= t << 4;
1951 *blue = t | (t << 8);
1952 }
1953 else {
1954 t = (col >> 7) & 0xe;
1955 t |= t << 4;
1956 *red = t | (t << 8);
1957 t = (col >> 3) & 0xe;
1958 t |= t << 4;
1959 *green = t | (t << 8);
1960 t = (col << 1) & 0xe;
1961 t |= t << 4;
1962 *blue = t | (t << 8);
1963 }
1964 *transp = 0;
1965 return 0;
1966}
1967
1968
1969static int stste_setcolreg(unsigned regno, unsigned red,
1970 unsigned green, unsigned blue,
1971 unsigned transp, struct fb_info *info)
1972{ 2016{
1973 if (regno > 15) 2017 if (regno > 15)
1974 return 1; 2018 return 1;
@@ -1988,10 +2032,9 @@ static int stste_setcolreg(unsigned regno, unsigned red,
1988 return 0; 2032 return 0;
1989} 2033}
1990 2034
1991 2035static int stste_detect(void)
1992static int stste_detect( void ) 2036{
1993 2037 struct atafb_par par;
1994{ struct atafb_par par;
1995 2038
1996 /* Determine the connected monitor: The DMA sound must be 2039 /* Determine the connected monitor: The DMA sound must be
1997 * disabled before reading the MFP GPIP, because the Sound 2040 * disabled before reading the MFP GPIP, because the Sound
@@ -1999,7 +2042,7 @@ static int stste_detect( void )
1999 */ 2042 */
2000 if (ATARIHW_PRESENT(PCM_8BIT)) { 2043 if (ATARIHW_PRESENT(PCM_8BIT)) {
2001 tt_dmasnd.ctrl = DMASND_CTRL_OFF; 2044 tt_dmasnd.ctrl = DMASND_CTRL_OFF;
2002 udelay(20); /* wait a while for things to settle down */ 2045 udelay(20); /* wait a while for things to settle down */
2003 } 2046 }
2004 mono_moni = (mfp.par_dt_reg & 0x80) == 0; 2047 mono_moni = (mfp.par_dt_reg & 0x80) == 0;
2005 2048
@@ -2014,12 +2057,12 @@ static int stste_detect( void )
2014static void stste_set_screen_base(void *s_base) 2057static void stste_set_screen_base(void *s_base)
2015{ 2058{
2016 unsigned long addr; 2059 unsigned long addr;
2017 addr= virt_to_phys(s_base); 2060 addr = virt_to_phys(s_base);
2018 /* Setup Screen Memory */ 2061 /* Setup Screen Memory */
2019 shifter.bas_hi=(unsigned char) ((addr & 0xff0000) >> 16); 2062 shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
2020 shifter.bas_md=(unsigned char) ((addr & 0x00ff00) >> 8); 2063 shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
2021 if (ATARIHW_PRESENT(EXTD_SHIFTER)) 2064 if (ATARIHW_PRESENT(EXTD_SHIFTER))
2022 shifter.bas_lo=(unsigned char) (addr & 0x0000ff); 2065 shifter.bas_lo = (unsigned char)(addr & 0x0000ff);
2023} 2066}
2024 2067
2025#endif /* ATAFB_STE */ 2068#endif /* ATAFB_STE */
@@ -2045,51 +2088,49 @@ static void stste_set_screen_base(void *s_base)
2045/* SWITCH_ACIA may be used for Falcon (ScreenBlaster III internal!) */ 2088/* SWITCH_ACIA may be used for Falcon (ScreenBlaster III internal!) */
2046static void st_ovsc_switch(void) 2089static void st_ovsc_switch(void)
2047{ 2090{
2048 unsigned long flags; 2091 unsigned long flags;
2049 register unsigned char old, new; 2092 register unsigned char old, new;
2050 2093
2051 if (!(atari_switches & ATARI_SWITCH_OVSC_MASK)) 2094 if (!(atari_switches & ATARI_SWITCH_OVSC_MASK))
2052 return; 2095 return;
2053 local_irq_save(flags); 2096 local_irq_save(flags);
2054 2097
2055 mfp.tim_ct_b = 0x10; 2098 mfp.tim_ct_b = 0x10;
2056 mfp.active_edge |= 8; 2099 mfp.active_edge |= 8;
2057 mfp.tim_ct_b = 0; 2100 mfp.tim_ct_b = 0;
2058 mfp.tim_dt_b = 0xf0; 2101 mfp.tim_dt_b = 0xf0;
2059 mfp.tim_ct_b = 8; 2102 mfp.tim_ct_b = 8;
2060 while (mfp.tim_dt_b > 1) /* TOS does it this way, don't ask why */ 2103 while (mfp.tim_dt_b > 1) /* TOS does it this way, don't ask why */
2061 ; 2104 ;
2062 new = mfp.tim_dt_b;
2063 do {
2064 udelay(LINE_DELAY);
2065 old = new;
2066 new = mfp.tim_dt_b; 2105 new = mfp.tim_dt_b;
2067 } while (old != new); 2106 do {
2068 mfp.tim_ct_b = 0x10; 2107 udelay(LINE_DELAY);
2069 udelay(SYNC_DELAY); 2108 old = new;
2070 2109 new = mfp.tim_dt_b;
2071 if (atari_switches & ATARI_SWITCH_OVSC_IKBD) 2110 } while (old != new);
2072 acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID | ACIA_RIE; 2111 mfp.tim_ct_b = 0x10;
2073 if (atari_switches & ATARI_SWITCH_OVSC_MIDI) 2112 udelay(SYNC_DELAY);
2074 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID; 2113
2075 if (atari_switches & (ATARI_SWITCH_OVSC_SND6|ATARI_SWITCH_OVSC_SND7)) { 2114 if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
2076 sound_ym.rd_data_reg_sel = 14; 2115 acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID | ACIA_RIE;
2077 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 2116 if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
2078 ((atari_switches&ATARI_SWITCH_OVSC_SND6) ? 0x40:0) | 2117 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
2079 ((atari_switches&ATARI_SWITCH_OVSC_SND7) ? 0x80:0); 2118 if (atari_switches & (ATARI_SWITCH_OVSC_SND6|ATARI_SWITCH_OVSC_SND7)) {
2080 } 2119 sound_ym.rd_data_reg_sel = 14;
2081 local_irq_restore(flags); 2120 sound_ym.wd_data = sound_ym.rd_data_reg_sel |
2121 ((atari_switches & ATARI_SWITCH_OVSC_SND6) ? 0x40:0) |
2122 ((atari_switches & ATARI_SWITCH_OVSC_SND7) ? 0x80:0);
2123 }
2124 local_irq_restore(flags);
2082} 2125}
2083 2126
2084/* ------------------- External Video ---------------------- */ 2127/* ------------------- External Video ---------------------- */
2085 2128
2086#ifdef ATAFB_EXT 2129#ifdef ATAFB_EXT
2087 2130
2088static int ext_encode_fix( struct fb_fix_screeninfo *fix, 2131static int ext_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
2089 struct atafb_par *par )
2090
2091{ 2132{
2092 strcpy(fix->id,"Unknown Extern"); 2133 strcpy(fix->id, "Unknown Extern");
2093 fix->smem_start = (unsigned long)external_addr; 2134 fix->smem_start = (unsigned long)external_addr;
2094 fix->smem_len = PAGE_ALIGN(external_len); 2135 fix->smem_len = PAGE_ALIGN(external_len);
2095 if (external_depth == 1) { 2136 if (external_depth == 1) {
@@ -2099,31 +2140,29 @@ static int ext_encode_fix( struct fb_fix_screeninfo *fix,
2099 fix->visual = 2140 fix->visual =
2100 (external_pmode == FB_TYPE_INTERLEAVED_PLANES || 2141 (external_pmode == FB_TYPE_INTERLEAVED_PLANES ||
2101 external_pmode == FB_TYPE_PACKED_PIXELS) ? 2142 external_pmode == FB_TYPE_PACKED_PIXELS) ?
2102 FB_VISUAL_MONO10 : 2143 FB_VISUAL_MONO10 : FB_VISUAL_MONO01;
2103 FB_VISUAL_MONO01; 2144 } else {
2104 }
2105 else {
2106 /* Use STATIC if we don't know how to access color registers */ 2145 /* Use STATIC if we don't know how to access color registers */
2107 int visual = external_vgaiobase ? 2146 int visual = external_vgaiobase ?
2108 FB_VISUAL_PSEUDOCOLOR : 2147 FB_VISUAL_PSEUDOCOLOR :
2109 FB_VISUAL_STATIC_PSEUDOCOLOR; 2148 FB_VISUAL_STATIC_PSEUDOCOLOR;
2110 switch (external_pmode) { 2149 switch (external_pmode) {
2111 case -1: /* truecolor */ 2150 case -1: /* truecolor */
2112 fix->type=FB_TYPE_PACKED_PIXELS; 2151 fix->type = FB_TYPE_PACKED_PIXELS;
2113 fix->visual=FB_VISUAL_TRUECOLOR; 2152 fix->visual = FB_VISUAL_TRUECOLOR;
2114 break; 2153 break;
2115 case FB_TYPE_PACKED_PIXELS: 2154 case FB_TYPE_PACKED_PIXELS:
2116 fix->type=FB_TYPE_PACKED_PIXELS; 2155 fix->type = FB_TYPE_PACKED_PIXELS;
2117 fix->visual=visual; 2156 fix->visual = visual;
2118 break; 2157 break;
2119 case FB_TYPE_PLANES: 2158 case FB_TYPE_PLANES:
2120 fix->type=FB_TYPE_PLANES; 2159 fix->type = FB_TYPE_PLANES;
2121 fix->visual=visual; 2160 fix->visual = visual;
2122 break; 2161 break;
2123 case FB_TYPE_INTERLEAVED_PLANES: 2162 case FB_TYPE_INTERLEAVED_PLANES:
2124 fix->type=FB_TYPE_INTERLEAVED_PLANES; 2163 fix->type = FB_TYPE_INTERLEAVED_PLANES;
2125 fix->type_aux=2; 2164 fix->type_aux = 2;
2126 fix->visual=visual; 2165 fix->visual = visual;
2127 break; 2166 break;
2128 } 2167 }
2129 } 2168 }
@@ -2134,137 +2173,112 @@ static int ext_encode_fix( struct fb_fix_screeninfo *fix,
2134 return 0; 2173 return 0;
2135} 2174}
2136 2175
2137 2176static int ext_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
2138static int ext_decode_var( struct fb_var_screeninfo *var,
2139 struct atafb_par *par )
2140{ 2177{
2141 struct fb_var_screeninfo *myvar = &atafb_predefined[0]; 2178 struct fb_var_screeninfo *myvar = &atafb_predefined[0];
2142 2179
2143 if (var->bits_per_pixel > myvar->bits_per_pixel || 2180 if (var->bits_per_pixel > myvar->bits_per_pixel ||
2144 var->xres > myvar->xres || 2181 var->xres > myvar->xres ||
2145 var->xres_virtual > myvar->xres_virtual || 2182 var->xres_virtual > myvar->xres_virtual ||
2146 var->yres > myvar->yres || 2183 var->yres > myvar->yres ||
2147 var->xoffset > 0 || 2184 var->xoffset > 0 ||
2148 var->yoffset > 0) 2185 var->yoffset > 0)
2149 return -EINVAL; 2186 return -EINVAL;
2150 return 0; 2187 return 0;
2151} 2188}
2152 2189
2153 2190static int ext_encode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
2154static int ext_encode_var( struct fb_var_screeninfo *var,
2155 struct atafb_par *par )
2156{ 2191{
2157 memset(var, 0, sizeof(struct fb_var_screeninfo)); 2192 memset(var, 0, sizeof(struct fb_var_screeninfo));
2158 var->red.offset=0; 2193 var->red.offset = 0;
2159 var->red.length=(external_pmode == -1) ? external_depth/3 : 2194 var->red.length = (external_pmode == -1) ? external_depth / 3 :
2160 (external_vgaiobase ? external_bitspercol : 0); 2195 (external_vgaiobase ? external_bitspercol : 0);
2161 var->red.msb_right=0; 2196 var->red.msb_right = 0;
2162 var->grayscale=0; 2197 var->grayscale = 0;
2163 2198
2164 var->pixclock=31041; 2199 var->pixclock = 31041;
2165 var->left_margin=120; /* these are surely incorrect */ 2200 var->left_margin = 120; /* these are surely incorrect */
2166 var->right_margin=100; 2201 var->right_margin = 100;
2167 var->upper_margin=8; 2202 var->upper_margin = 8;
2168 var->lower_margin=16; 2203 var->lower_margin = 16;
2169 var->hsync_len=140; 2204 var->hsync_len = 140;
2170 var->vsync_len=30; 2205 var->vsync_len = 30;
2171 2206
2172 var->height=-1; 2207 var->height = -1;
2173 var->width=-1; 2208 var->width = -1;
2174 2209
2175 var->sync=0; 2210 var->sync = 0;
2176 2211
2177 var->xres = external_xres; 2212 var->xres = external_xres;
2178 var->yres = external_yres; 2213 var->yres = external_yres;
2179 var->xres_virtual = external_xres_virtual; 2214 var->xres_virtual = external_xres_virtual;
2180 var->bits_per_pixel = external_depth; 2215 var->bits_per_pixel = external_depth;
2181 2216
2182 var->blue=var->green=var->red; 2217 var->blue = var->green = var->red;
2183 var->transp.offset=0; 2218 var->transp.offset = 0;
2184 var->transp.length=0; 2219 var->transp.length = 0;
2185 var->transp.msb_right=0; 2220 var->transp.msb_right = 0;
2186 var->yres_virtual=var->yres; 2221 var->yres_virtual = var->yres;
2187 var->xoffset=0; 2222 var->xoffset = 0;
2188 var->yoffset=0; 2223 var->yoffset = 0;
2189 var->nonstd=0; 2224 var->nonstd = 0;
2190 var->activate=0; 2225 var->activate = 0;
2191 var->vmode=FB_VMODE_NONINTERLACED; 2226 var->vmode = FB_VMODE_NONINTERLACED;
2192 return 0; 2227 return 0;
2193} 2228}
2194 2229
2195 2230static void ext_get_par(struct atafb_par *par)
2196static void ext_get_par( struct atafb_par *par )
2197{ 2231{
2198 par->screen_base = external_addr; 2232 par->screen_base = external_addr;
2199} 2233}
2200 2234
2201static void ext_set_par( struct atafb_par *par ) 2235static void ext_set_par(struct atafb_par *par)
2202{ 2236{
2203} 2237}
2204 2238
2205#define OUTB(port,val) \ 2239#define OUTB(port,val) \
2206 *((unsigned volatile char *) ((port)+external_vgaiobase))=(val) 2240 *((unsigned volatile char *) ((port)+external_vgaiobase)) = (val)
2207#define INB(port) \ 2241#define INB(port) \
2208 (*((unsigned volatile char *) ((port)+external_vgaiobase))) 2242 (*((unsigned volatile char *) ((port)+external_vgaiobase)))
2209#define DACDelay \ 2243#define DACDelay \
2210 do { \ 2244 do { \
2211 unsigned char tmp=INB(0x3da); \ 2245 unsigned char tmp = INB(0x3da); \
2212 tmp=INB(0x3da); \ 2246 tmp = INB(0x3da); \
2213 } while (0) 2247 } while (0)
2214 2248
2215static int ext_getcolreg( unsigned regno, unsigned *red, 2249static int ext_setcolreg(unsigned int regno, unsigned int red,
2216 unsigned *green, unsigned *blue, 2250 unsigned int green, unsigned int blue,
2217 unsigned *transp, struct fb_info *info ) 2251 unsigned int transp, struct fb_info *info)
2218{ 2252{
2219 if (! external_vgaiobase) 2253 unsigned char colmask = (1 << external_bitspercol) - 1;
2254
2255 if (!external_vgaiobase)
2220 return 1; 2256 return 1;
2221 2257
2222 *red = ext_color[regno].red; 2258 switch (external_card_type) {
2223 *green = ext_color[regno].green; 2259 case IS_VGA:
2224 *blue = ext_color[regno].blue; 2260 OUTB(0x3c8, regno);
2225 *transp=0; 2261 DACDelay;
2226 return 0; 2262 OUTB(0x3c9, red & colmask);
2227} 2263 DACDelay;
2228 2264 OUTB(0x3c9, green & colmask);
2229static int ext_setcolreg( unsigned regno, unsigned red, 2265 DACDelay;
2230 unsigned green, unsigned blue, 2266 OUTB(0x3c9, blue & colmask);
2231 unsigned transp, struct fb_info *info ) 2267 DACDelay;
2268 return 0;
2232 2269
2233{ unsigned char colmask = (1 << external_bitspercol) - 1; 2270 case IS_MV300:
2271 OUTB((MV300_reg[regno] << 2) + 1, red);
2272 OUTB((MV300_reg[regno] << 2) + 1, green);
2273 OUTB((MV300_reg[regno] << 2) + 1, blue);
2274 return 0;
2234 2275
2235 if (! external_vgaiobase) 2276 default:
2236 return 1; 2277 return 1;
2237 2278 }
2238 ext_color[regno].red = red;
2239 ext_color[regno].green = green;
2240 ext_color[regno].blue = blue;
2241
2242 switch (external_card_type) {
2243 case IS_VGA:
2244 OUTB(0x3c8, regno);
2245 DACDelay;
2246 OUTB(0x3c9, red & colmask);
2247 DACDelay;
2248 OUTB(0x3c9, green & colmask);
2249 DACDelay;
2250 OUTB(0x3c9, blue & colmask);
2251 DACDelay;
2252 return 0;
2253
2254 case IS_MV300:
2255 OUTB((MV300_reg[regno] << 2)+1, red);
2256 OUTB((MV300_reg[regno] << 2)+1, green);
2257 OUTB((MV300_reg[regno] << 2)+1, blue);
2258 return 0;
2259
2260 default:
2261 return 1;
2262 }
2263} 2279}
2264
2265
2266static int ext_detect( void )
2267 2280
2281static int ext_detect(void)
2268{ 2282{
2269 struct fb_var_screeninfo *myvar = &atafb_predefined[0]; 2283 struct fb_var_screeninfo *myvar = &atafb_predefined[0];
2270 struct atafb_par dummy_par; 2284 struct atafb_par dummy_par;
@@ -2284,213 +2298,182 @@ static int ext_detect( void )
2284static void set_screen_base(void *s_base) 2298static void set_screen_base(void *s_base)
2285{ 2299{
2286 unsigned long addr; 2300 unsigned long addr;
2287 addr= virt_to_phys(s_base); 2301
2302 addr = virt_to_phys(s_base);
2288 /* Setup Screen Memory */ 2303 /* Setup Screen Memory */
2289 shifter.bas_hi=(unsigned char) ((addr & 0xff0000) >> 16); 2304 shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
2290 shifter.bas_md=(unsigned char) ((addr & 0x00ff00) >> 8); 2305 shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
2291 shifter.bas_lo=(unsigned char) (addr & 0x0000ff); 2306 shifter.bas_lo = (unsigned char)(addr & 0x0000ff);
2292} 2307}
2293 2308
2294 2309static int pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2295static int pan_display( struct fb_var_screeninfo *var,
2296 struct atafb_par *par )
2297{ 2310{
2311 struct atafb_par *par = (struct atafb_par *)info->par;
2312
2298 if (!fbhw->set_screen_base || 2313 if (!fbhw->set_screen_base ||
2299 (!ATARIHW_PRESENT(EXTD_SHIFTER) && var->xoffset)) 2314 (!ATARIHW_PRESENT(EXTD_SHIFTER) && var->xoffset))
2300 return -EINVAL; 2315 return -EINVAL;
2301 var->xoffset = up(var->xoffset, 16); 2316 var->xoffset = up(var->xoffset, 16);
2302 par->screen_base = screen_base + 2317 par->screen_base = screen_base +
2303 (var->yoffset * fb_display[fb_info.currcon].var.xres_virtual + var->xoffset) 2318 (var->yoffset * info->var.xres_virtual + var->xoffset)
2304 * fb_display[fb_info.currcon].var.bits_per_pixel / 8; 2319 * info->var.bits_per_pixel / 8;
2305 fbhw->set_screen_base (par->screen_base); 2320 fbhw->set_screen_base(par->screen_base);
2306 return 0; 2321 return 0;
2307} 2322}
2308 2323
2309
2310/* ------------ Interfaces to hardware functions ------------ */ 2324/* ------------ Interfaces to hardware functions ------------ */
2311 2325
2312
2313#ifdef ATAFB_TT 2326#ifdef ATAFB_TT
2314static struct fb_hwswitch tt_switch = { 2327static struct fb_hwswitch tt_switch = {
2315 tt_detect, tt_encode_fix, tt_decode_var, tt_encode_var, 2328 .detect = tt_detect,
2316 tt_get_par, tt_set_par, tt_getcolreg, 2329 .encode_fix = tt_encode_fix,
2317 set_screen_base, NULL, pan_display 2330 .decode_var = tt_decode_var,
2331 .encode_var = tt_encode_var,
2332 .get_par = tt_get_par,
2333 .set_par = tt_set_par,
2334 .set_screen_base = set_screen_base,
2335 .pan_display = pan_display,
2318}; 2336};
2319#endif 2337#endif
2320 2338
2321#ifdef ATAFB_FALCON 2339#ifdef ATAFB_FALCON
2322static struct fb_hwswitch falcon_switch = { 2340static struct fb_hwswitch falcon_switch = {
2323 falcon_detect, falcon_encode_fix, falcon_decode_var, falcon_encode_var, 2341 .detect = falcon_detect,
2324 falcon_get_par, falcon_set_par, falcon_getcolreg, 2342 .encode_fix = falcon_encode_fix,
2325 set_screen_base, falcon_blank, falcon_pan_display 2343 .decode_var = falcon_decode_var,
2344 .encode_var = falcon_encode_var,
2345 .get_par = falcon_get_par,
2346 .set_par = falcon_set_par,
2347 .set_screen_base = set_screen_base,
2348 .blank = falcon_blank,
2349 .pan_display = falcon_pan_display,
2326}; 2350};
2327#endif 2351#endif
2328 2352
2329#ifdef ATAFB_STE 2353#ifdef ATAFB_STE
2330static struct fb_hwswitch st_switch = { 2354static struct fb_hwswitch st_switch = {
2331 stste_detect, stste_encode_fix, stste_decode_var, stste_encode_var, 2355 .detect = stste_detect,
2332 stste_get_par, stste_set_par, stste_getcolreg, 2356 .encode_fix = stste_encode_fix,
2333 stste_set_screen_base, NULL, pan_display 2357 .decode_var = stste_decode_var,
2358 .encode_var = stste_encode_var,
2359 .get_par = stste_get_par,
2360 .set_par = stste_set_par,
2361 .set_screen_base = stste_set_screen_base,
2362 .pan_display = pan_display
2334}; 2363};
2335#endif 2364#endif
2336 2365
2337#ifdef ATAFB_EXT 2366#ifdef ATAFB_EXT
2338static struct fb_hwswitch ext_switch = { 2367static struct fb_hwswitch ext_switch = {
2339 ext_detect, ext_encode_fix, ext_decode_var, ext_encode_var, 2368 .detect = ext_detect,
2340 ext_get_par, ext_set_par, ext_getcolreg, NULL, NULL, NULL 2369 .encode_fix = ext_encode_fix,
2370 .decode_var = ext_decode_var,
2371 .encode_var = ext_encode_var,
2372 .get_par = ext_get_par,
2373 .set_par = ext_set_par,
2341}; 2374};
2342#endif 2375#endif
2343 2376
2344 2377static void ata_get_par(struct atafb_par *par)
2345
2346static void atafb_get_par( struct atafb_par *par )
2347{ 2378{
2348 if (current_par_valid) { 2379 if (current_par_valid)
2349 *par=current_par; 2380 *par = current_par;
2350 }
2351 else 2381 else
2352 fbhw->get_par(par); 2382 fbhw->get_par(par);
2353} 2383}
2354 2384
2355 2385static void ata_set_par(struct atafb_par *par)
2356static void atafb_set_par( struct atafb_par *par )
2357{ 2386{
2358 fbhw->set_par(par); 2387 fbhw->set_par(par);
2359 current_par=*par; 2388 current_par = *par;
2360 current_par_valid=1; 2389 current_par_valid = 1;
2361} 2390}
2362 2391
2363 2392
2364
2365/* =========================================================== */ 2393/* =========================================================== */
2366/* ============== Hardware Independent Functions ============= */ 2394/* ============== Hardware Independent Functions ============= */
2367/* =========================================================== */ 2395/* =========================================================== */
2368 2396
2369
2370/* used for hardware scrolling */ 2397/* used for hardware scrolling */
2371 2398
2372static int 2399static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
2373fb_update_var(int con, struct fb_info *info)
2374{
2375 int off=fb_display[con].var.yoffset*fb_display[con].var.xres_virtual*
2376 fb_display[con].var.bits_per_pixel>>3;
2377
2378 current_par.screen_base=screen_base + off;
2379
2380 if (fbhw->set_screen_base)
2381 fbhw->set_screen_base(current_par.screen_base);
2382 return 0;
2383}
2384
2385static int
2386do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
2387{ 2400{
2388 int err,activate; 2401 int err, activate;
2389 struct atafb_par par; 2402 struct atafb_par par;
2390 if ((err=fbhw->decode_var(var, &par))) 2403
2404 err = fbhw->decode_var(var, &par);
2405 if (err)
2391 return err; 2406 return err;
2392 activate=var->activate; 2407 activate = var->activate;
2393 if (((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive) 2408 if (((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive)
2394 atafb_set_par(&par); 2409 ata_set_par(&par);
2395 fbhw->encode_var(var, &par); 2410 fbhw->encode_var(var, &par);
2396 var->activate=activate; 2411 var->activate = activate;
2397 return 0; 2412 return 0;
2398} 2413}
2399 2414
2400static int 2415static int atafb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
2401atafb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
2402{ 2416{
2403 struct atafb_par par; 2417 struct atafb_par par;
2404 if (con == -1) 2418 int err;
2405 atafb_get_par(&par); 2419 // Get fix directly (case con == -1 before)??
2406 else { 2420 err = fbhw->decode_var(&info->var, &par);
2407 int err; 2421 if (err)
2408 if ((err=fbhw->decode_var(&fb_display[con].var,&par))) 2422 return err;
2409 return err;
2410 }
2411 memset(fix, 0, sizeof(struct fb_fix_screeninfo)); 2423 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
2412 return fbhw->encode_fix(fix, &par); 2424 return fbhw->encode_fix(fix, &par);
2413} 2425}
2414 2426
2415static int 2427static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info)
2416atafb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
2417{ 2428{
2418 struct atafb_par par; 2429 struct atafb_par par;
2419 if (con == -1) { 2430
2420 atafb_get_par(&par); 2431 ata_get_par(&par);
2421 fbhw->encode_var(var, &par); 2432 fbhw->encode_var(var, &par);
2422 } 2433
2423 else
2424 *var=fb_display[con].var;
2425 return 0; 2434 return 0;
2426} 2435}
2427 2436
2428static void 2437// No longer called by fbcon!
2429atafb_set_disp(int con, struct fb_info *info) 2438// Still called by set_var internally
2439
2440static void atafb_set_disp(struct fb_info *info)
2430{ 2441{
2431 struct fb_fix_screeninfo fix; 2442 atafb_get_var(&info->var, info);
2432 struct fb_var_screeninfo var; 2443 atafb_get_fix(&info->fix, info);
2433 struct display *display;
2434 2444
2435 if (con >= 0) 2445 info->screen_base = (void *)info->fix.smem_start;
2436 display = &fb_display[con]; 2446
2437 else 2447 switch (info->fix.type) {
2438 display = &disp; /* used during initialization */ 2448 case FB_TYPE_INTERLEAVED_PLANES:
2439 2449 switch (info->var.bits_per_pixel) {
2440 atafb_get_fix(&fix, con, info); 2450 case 2:
2441 atafb_get_var(&var, con, info); 2451 // display->dispsw = &fbcon_iplan2p2;
2442 if (con == -1)
2443 con=0;
2444 info->screen_base = (void *)fix.smem_start;
2445 display->visual = fix.visual;
2446 display->type = fix.type;
2447 display->type_aux = fix.type_aux;
2448 display->ypanstep = fix.ypanstep;
2449 display->ywrapstep = fix.ywrapstep;
2450 display->line_length = fix.line_length;
2451 if (fix.visual != FB_VISUAL_PSEUDOCOLOR &&
2452 fix.visual != FB_VISUAL_DIRECTCOLOR)
2453 display->can_soft_blank = 0;
2454 else
2455 display->can_soft_blank = 1;
2456 display->inverse =
2457 (fix.visual == FB_VISUAL_MONO01 ? !inverse : inverse);
2458 switch (fix.type) {
2459 case FB_TYPE_INTERLEAVED_PLANES:
2460 switch (var.bits_per_pixel) {
2461#ifdef FBCON_HAS_IPLAN2P2
2462 case 2:
2463 display->dispsw = &fbcon_iplan2p2;
2464 break; 2452 break;
2465#endif 2453 case 4:
2466#ifdef FBCON_HAS_IPLAN2P4 2454 // display->dispsw = &fbcon_iplan2p4;
2467 case 4:
2468 display->dispsw = &fbcon_iplan2p4;
2469 break; 2455 break;
2470#endif 2456 case 8:
2471#ifdef FBCON_HAS_IPLAN2P8 2457 // display->dispsw = &fbcon_iplan2p8;
2472 case 8:
2473 display->dispsw = &fbcon_iplan2p8;
2474 break; 2458 break;
2475#endif
2476 } 2459 }
2477 break; 2460 break;
2478 case FB_TYPE_PACKED_PIXELS: 2461 case FB_TYPE_PACKED_PIXELS:
2479 switch (var.bits_per_pixel) { 2462 switch (info->var.bits_per_pixel) {
2480#ifdef FBCON_HAS_MFB 2463#ifdef FBCON_HAS_MFB
2481 case 1: 2464 case 1:
2482 display->dispsw = &fbcon_mfb; 2465 // display->dispsw = &fbcon_mfb;
2483 break; 2466 break;
2484#endif 2467#endif
2485#ifdef FBCON_HAS_CFB8 2468#ifdef FBCON_HAS_CFB8
2486 case 8: 2469 case 8:
2487 display->dispsw = &fbcon_cfb8; 2470 // display->dispsw = &fbcon_cfb8;
2488 break; 2471 break;
2489#endif 2472#endif
2490#ifdef FBCON_HAS_CFB16 2473#ifdef FBCON_HAS_CFB16
2491 case 16: 2474 case 16:
2492 display->dispsw = &fbcon_cfb16; 2475 // display->dispsw = &fbcon_cfb16;
2493 display->dispsw_data = fbcon_cfb16_cmap; 2476 // display->dispsw_data = fbcon_cfb16_cmap;
2494 break; 2477 break;
2495#endif 2478#endif
2496 } 2479 }
@@ -2498,74 +2481,203 @@ atafb_set_disp(int con, struct fb_info *info)
2498 } 2481 }
2499} 2482}
2500 2483
2484static int atafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2485 u_int transp, struct fb_info *info)
2486{
2487 red >>= 8;
2488 green >>= 8;
2489 blue >>= 8;
2490
2491 return info->fbops->fb_setcolreg(regno, red, green, blue, transp, info);
2492}
2493
2501static int 2494static int
2502atafb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) 2495atafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2503{ 2496{
2504 int err,oldxres,oldyres,oldbpp,oldxres_virtual, 2497 int xoffset = var->xoffset;
2505 oldyres_virtual,oldyoffset; 2498 int yoffset = var->yoffset;
2506 if ((err=do_fb_set_var(var, con==info->currcon))) 2499 int err;
2507 return err; 2500
2508 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { 2501 if (var->vmode & FB_VMODE_YWRAP) {
2509 oldxres=fb_display[con].var.xres; 2502 if (yoffset < 0 || yoffset >= info->var.yres_virtual || xoffset)
2510 oldyres=fb_display[con].var.yres; 2503 return -EINVAL;
2511 oldxres_virtual=fb_display[con].var.xres_virtual; 2504 } else {
2512 oldyres_virtual=fb_display[con].var.yres_virtual; 2505 if (xoffset + info->var.xres > info->var.xres_virtual ||
2513 oldbpp=fb_display[con].var.bits_per_pixel; 2506 yoffset + info->var.yres > info->var.yres_virtual)
2514 oldyoffset=fb_display[con].var.yoffset; 2507 return -EINVAL;
2515 fb_display[con].var=*var;
2516 if (oldxres != var->xres || oldyres != var->yres
2517 || oldxres_virtual != var->xres_virtual
2518 || oldyres_virtual != var->yres_virtual
2519 || oldbpp != var->bits_per_pixel
2520 || oldyoffset != var->yoffset) {
2521 atafb_set_disp(con, info);
2522 (*fb_info.changevar)(con);
2523 fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
2524 do_install_cmap(con, info);
2525 }
2526 } 2508 }
2527 var->activate=0; 2509
2510 if (fbhw->pan_display) {
2511 err = fbhw->pan_display(var, info);
2512 if (err)
2513 return err;
2514 } else
2515 return -EINVAL;
2516
2517 info->var.xoffset = xoffset;
2518 info->var.yoffset = yoffset;
2519
2520 if (var->vmode & FB_VMODE_YWRAP)
2521 info->var.vmode |= FB_VMODE_YWRAP;
2522 else
2523 info->var.vmode &= ~FB_VMODE_YWRAP;
2524
2528 return 0; 2525 return 0;
2529} 2526}
2530 2527
2528/*
2529 * generic drawing routines; imageblit needs updating for image depth > 1
2530 */
2531 2531
2532#if BITS_PER_LONG == 32
2533#define BYTES_PER_LONG 4
2534#define SHIFT_PER_LONG 5
2535#elif BITS_PER_LONG == 64
2536#define BYTES_PER_LONG 8
2537#define SHIFT_PER_LONG 6
2538#else
2539#define Please update me
2540#endif
2532 2541
2533static int 2542
2534atafb_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info) 2543static void atafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
2535{ 2544{
2536 if (con == info->currcon) /* current console ? */ 2545 struct atafb_par *par = (struct atafb_par *)info->par;
2537 return fb_get_cmap(cmap, kspc, fbhw->getcolreg, info); 2546 int x2, y2;
2547 u32 width, height;
2548
2549 if (!rect->width || !rect->height)
2550 return;
2551
2552 /*
2553 * We could use hardware clipping but on many cards you get around
2554 * hardware clipping by writing to framebuffer directly.
2555 * */
2556 x2 = rect->dx + rect->width;
2557 y2 = rect->dy + rect->height;
2558 x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
2559 y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
2560 width = x2 - rect->dx;
2561 height = y2 - rect->dy;
2562
2563 if (info->var.bits_per_pixel == 1)
2564 atafb_mfb_fillrect(info, par->next_line, rect->color,
2565 rect->dy, rect->dx, height, width);
2566 else if (info->var.bits_per_pixel == 2)
2567 atafb_iplan2p2_fillrect(info, par->next_line, rect->color,
2568 rect->dy, rect->dx, height, width);
2569 else if (info->var.bits_per_pixel == 4)
2570 atafb_iplan2p4_fillrect(info, par->next_line, rect->color,
2571 rect->dy, rect->dx, height, width);
2538 else 2572 else
2539 if (fb_display[con].cmap.len) /* non default colormap ? */ 2573 atafb_iplan2p8_fillrect(info, par->next_line, rect->color,
2540 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2); 2574 rect->dy, rect->dx, height, width);
2541 else 2575
2542 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), 2576 return;
2543 cmap, kspc ? 0 : 2);
2544 return 0;
2545} 2577}
2546 2578
2547static int 2579static void atafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
2548atafb_pan_display(struct fb_var_screeninfo *var, int con, struct fb_info *info)
2549{ 2580{
2550 int xoffset = var->xoffset; 2581 struct atafb_par *par = (struct atafb_par *)info->par;
2551 int yoffset = var->yoffset; 2582 int x2, y2;
2552 int err; 2583 u32 dx, dy, sx, sy, width, height;
2584 int rev_copy = 0;
2585
2586 /* clip the destination */
2587 x2 = area->dx + area->width;
2588 y2 = area->dy + area->height;
2589 dx = area->dx > 0 ? area->dx : 0;
2590 dy = area->dy > 0 ? area->dy : 0;
2591 x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
2592 y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
2593 width = x2 - dx;
2594 height = y2 - dy;
2595
2596 /* update sx,sy */
2597 sx = area->sx + (dx - area->dx);
2598 sy = area->sy + (dy - area->dy);
2599
2600 /* the source must be completely inside the virtual screen */
2601 if (sx < 0 || sy < 0 || (sx + width) > info->var.xres_virtual ||
2602 (sy + height) > info->var.yres_virtual)
2603 return;
2553 2604
2554 if ( xoffset < 0 || xoffset + fb_display[con].var.xres > fb_display[con].var.xres_virtual 2605 if (dy > sy || (dy == sy && dx > sx)) {
2555 || yoffset < 0 || yoffset + fb_display[con].var.yres > fb_display[con].var.yres_virtual) 2606 dy += height;
2556 return -EINVAL; 2607 sy += height;
2608 rev_copy = 1;
2609 }
2610
2611 if (info->var.bits_per_pixel == 1)
2612 atafb_mfb_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
2613 else if (info->var.bits_per_pixel == 2)
2614 atafb_iplan2p2_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
2615 else if (info->var.bits_per_pixel == 4)
2616 atafb_iplan2p4_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
2617 else
2618 atafb_iplan2p8_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
2557 2619
2558 if (con == info->currcon) { 2620 return;
2559 if (fbhw->pan_display) { 2621}
2560 if ((err = fbhw->pan_display(var, &current_par))) 2622
2561 return err; 2623static void atafb_imageblit(struct fb_info *info, const struct fb_image *image)
2624{
2625 struct atafb_par *par = (struct atafb_par *)info->par;
2626 int x2, y2;
2627 unsigned long *dst;
2628 int dst_idx;
2629 const char *src;
2630 u32 dx, dy, width, height, pitch;
2631
2632 /*
2633 * We could use hardware clipping but on many cards you get around
2634 * hardware clipping by writing to framebuffer directly like we are
2635 * doing here.
2636 */
2637 x2 = image->dx + image->width;
2638 y2 = image->dy + image->height;
2639 dx = image->dx;
2640 dy = image->dy;
2641 x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
2642 y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
2643 width = x2 - dx;
2644 height = y2 - dy;
2645
2646 if (image->depth == 1) {
2647 // used for font data
2648 dst = (unsigned long *)
2649 ((unsigned long)info->screen_base & ~(BYTES_PER_LONG - 1));
2650 dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG - 1)) * 8;
2651 dst_idx += dy * par->next_line * 8 + dx;
2652 src = image->data;
2653 pitch = (image->width + 7) / 8;
2654 while (height--) {
2655
2656 if (info->var.bits_per_pixel == 1)
2657 atafb_mfb_linefill(info, par->next_line,
2658 dy, dx, width, src,
2659 image->bg_color, image->fg_color);
2660 else if (info->var.bits_per_pixel == 2)
2661 atafb_iplan2p2_linefill(info, par->next_line,
2662 dy, dx, width, src,
2663 image->bg_color, image->fg_color);
2664 else if (info->var.bits_per_pixel == 4)
2665 atafb_iplan2p4_linefill(info, par->next_line,
2666 dy, dx, width, src,
2667 image->bg_color, image->fg_color);
2668 else
2669 atafb_iplan2p8_linefill(info, par->next_line,
2670 dy, dx, width, src,
2671 image->bg_color, image->fg_color);
2672 dy++;
2673 src += pitch;
2562 } 2674 }
2563 else 2675 } else {
2564 return -EINVAL; 2676 // only used for logo; broken
2677 c2p(info->screen_base, image->data, dx, dy, width, height,
2678 par->next_line, par->next_plane, image->width,
2679 info->var.bits_per_pixel);
2565 } 2680 }
2566 fb_display[con].var.xoffset = var->xoffset;
2567 fb_display[con].var.yoffset = var->yoffset;
2568 return 0;
2569} 2681}
2570 2682
2571static int 2683static int
@@ -2584,7 +2696,7 @@ atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2584 if (copy_from_user((void *)&current_par, (void *)arg, 2696 if (copy_from_user((void *)&current_par, (void *)arg,
2585 sizeof(struct atafb_par))) 2697 sizeof(struct atafb_par)))
2586 return -EFAULT; 2698 return -EFAULT;
2587 atafb_set_par(&current_par); 2699 ata_set_par(&current_par);
2588 return 0; 2700 return 0;
2589#endif 2701#endif
2590 } 2702 }
@@ -2598,42 +2710,82 @@ atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2598 * 3 = suspend hsync 2710 * 3 = suspend hsync
2599 * 4 = off 2711 * 4 = off
2600 */ 2712 */
2601static int 2713static int atafb_blank(int blank, struct fb_info *info)
2602atafb_blank(int blank, struct fb_info *info)
2603{ 2714{
2604 unsigned short black[16]; 2715 unsigned short black[16];
2605 struct fb_cmap cmap; 2716 struct fb_cmap cmap;
2606 if (fbhw->blank && !fbhw->blank(blank)) 2717 if (fbhw->blank && !fbhw->blank(blank))
2607 return 1; 2718 return 1;
2608 if (blank) { 2719 if (blank) {
2609 memset(black, 0, 16*sizeof(unsigned short)); 2720 memset(black, 0, 16 * sizeof(unsigned short));
2610 cmap.red=black; 2721 cmap.red = black;
2611 cmap.green=black; 2722 cmap.green = black;
2612 cmap.blue=black; 2723 cmap.blue = black;
2613 cmap.transp=NULL; 2724 cmap.transp = NULL;
2614 cmap.start=0; 2725 cmap.start = 0;
2615 cmap.len=16; 2726 cmap.len = 16;
2616 fb_set_cmap(&cmap, 1, info); 2727 fb_set_cmap(&cmap, info);
2617 } 2728 }
2729#if 0
2618 else 2730 else
2619 do_install_cmap(info->currcon, info); 2731 do_install_cmap(info);
2732#endif
2733 return 0;
2734}
2735
2736 /*
2737 * New fbcon interface ...
2738 */
2739
2740 /* check var by decoding var into hw par, rounding if necessary,
2741 * then encoding hw par back into new, validated var */
2742static int atafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
2743{
2744 int err;
2745 struct atafb_par par;
2746
2747 /* Validate wanted screen parameters */
2748 // if ((err = ata_decode_var(var, &par)))
2749 err = fbhw->decode_var(var, &par);
2750 if (err)
2751 return err;
2752
2753 /* Encode (possibly rounded) screen parameters */
2754 fbhw->encode_var(var, &par);
2755 return 0;
2756}
2757
2758 /* actually set hw par by decoding var, then setting hardware from
2759 * hw par just decoded */
2760static int atafb_set_par(struct fb_info *info)
2761{
2762 struct atafb_par *par = (struct atafb_par *)info->par;
2763
2764 /* Decode wanted screen parameters */
2765 fbhw->decode_var(&info->var, par);
2766 fbhw->encode_fix(&info->fix, par);
2767
2768 /* Set new videomode */
2769 ata_set_par(par);
2770
2620 return 0; 2771 return 0;
2621} 2772}
2622 2773
2774
2623static struct fb_ops atafb_ops = { 2775static struct fb_ops atafb_ops = {
2624 .owner = THIS_MODULE, 2776 .owner = THIS_MODULE,
2625 .fb_get_fix = atafb_get_fix, 2777 .fb_check_var = atafb_check_var,
2626 .fb_get_var = atafb_get_var, 2778 .fb_set_par = atafb_set_par,
2627 .fb_set_var = atafb_set_var, 2779 .fb_setcolreg = atafb_setcolreg,
2628 .fb_get_cmap = atafb_get_cmap,
2629 .fb_set_cmap = gen_set_cmap,
2630 .fb_pan_display =atafb_pan_display,
2631 .fb_blank = atafb_blank, 2780 .fb_blank = atafb_blank,
2781 .fb_pan_display = atafb_pan_display,
2782 .fb_fillrect = atafb_fillrect,
2783 .fb_copyarea = atafb_copyarea,
2784 .fb_imageblit = atafb_imageblit,
2632 .fb_ioctl = atafb_ioctl, 2785 .fb_ioctl = atafb_ioctl,
2633}; 2786};
2634 2787
2635static void 2788static void check_default_par(int detected_mode)
2636check_default_par( int detected_mode )
2637{ 2789{
2638 char default_name[10]; 2790 char default_name[10];
2639 int i; 2791 int i;
@@ -2642,199 +2794,41 @@ check_default_par( int detected_mode )
2642 2794
2643 /* First try the user supplied mode */ 2795 /* First try the user supplied mode */
2644 if (default_par) { 2796 if (default_par) {
2645 var=atafb_predefined[default_par-1]; 2797 var = atafb_predefined[default_par - 1];
2646 var.activate = FB_ACTIVATE_TEST; 2798 var.activate = FB_ACTIVATE_TEST;
2647 if (do_fb_set_var(&var,1)) 2799 if (do_fb_set_var(&var, 1))
2648 default_par=0; /* failed */ 2800 default_par = 0; /* failed */
2649 } 2801 }
2650 /* Next is the autodetected one */ 2802 /* Next is the autodetected one */
2651 if (! default_par) { 2803 if (!default_par) {
2652 var=atafb_predefined[detected_mode-1]; /* autodetect */ 2804 var = atafb_predefined[detected_mode - 1]; /* autodetect */
2653 var.activate = FB_ACTIVATE_TEST; 2805 var.activate = FB_ACTIVATE_TEST;
2654 if (!do_fb_set_var(&var,1)) 2806 if (!do_fb_set_var(&var, 1))
2655 default_par=detected_mode; 2807 default_par = detected_mode;
2656 } 2808 }
2657 /* If that also failed, try some default modes... */ 2809 /* If that also failed, try some default modes... */
2658 if (! default_par) { 2810 if (!default_par) {
2659 /* try default1, default2... */ 2811 /* try default1, default2... */
2660 for (i=1 ; i < 10 ; i++) { 2812 for (i = 1; i < 10; i++) {
2661 sprintf(default_name,"default%d",i); 2813 sprintf(default_name,"default%d", i);
2662 default_par=get_video_mode(default_name); 2814 default_par = get_video_mode(default_name);
2663 if (! default_par) 2815 if (!default_par)
2664 panic("can't set default video mode"); 2816 panic("can't set default video mode");
2665 var=atafb_predefined[default_par-1]; 2817 var = atafb_predefined[default_par - 1];
2666 var.activate = FB_ACTIVATE_TEST; 2818 var.activate = FB_ACTIVATE_TEST;
2667 if (! do_fb_set_var(&var,1)) 2819 if (!do_fb_set_var(&var,1))
2668 break; /* ok */ 2820 break; /* ok */
2669 } 2821 }
2670 } 2822 }
2671 min_mem=var.xres_virtual * var.yres_virtual * var.bits_per_pixel/8; 2823 min_mem = var.xres_virtual * var.yres_virtual * var.bits_per_pixel / 8;
2672 if (default_mem_req < min_mem) 2824 if (default_mem_req < min_mem)
2673 default_mem_req=min_mem; 2825 default_mem_req = min_mem;
2674}
2675
2676static int
2677atafb_switch(int con, struct fb_info *info)
2678{
2679 /* Do we have to save the colormap ? */
2680 if (fb_display[info->currcon].cmap.len)
2681 fb_get_cmap(&fb_display[info->currcon].cmap, 1, fbhw->getcolreg,
2682 info);
2683 do_fb_set_var(&fb_display[con].var,1);
2684 info->currcon=con;
2685 /* Install new colormap */
2686 do_install_cmap(con, info);
2687 return 0;
2688}
2689
2690int __init atafb_init(void)
2691{
2692 int pad;
2693 int detected_mode;
2694 unsigned long mem_req;
2695
2696 if (!MACH_IS_ATARI)
2697 return -ENXIO;
2698
2699 do {
2700#ifdef ATAFB_EXT
2701 if (external_addr) {
2702 fbhw = &ext_switch;
2703 atafb_ops.fb_setcolreg = &ext_setcolreg;
2704 break;
2705 }
2706#endif
2707#ifdef ATAFB_TT
2708 if (ATARIHW_PRESENT(TT_SHIFTER)) {
2709 fbhw = &tt_switch;
2710 atafb_ops.fb_setcolreg = &tt_setcolreg;
2711 break;
2712 }
2713#endif
2714#ifdef ATAFB_FALCON
2715 if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
2716 fbhw = &falcon_switch;
2717 atafb_ops.fb_setcolreg = &falcon_setcolreg;
2718 request_irq(IRQ_AUTO_4, falcon_vbl_switcher, IRQ_TYPE_PRIO,
2719 "framebuffer/modeswitch", falcon_vbl_switcher);
2720 break;
2721 }
2722#endif
2723#ifdef ATAFB_STE
2724 if (ATARIHW_PRESENT(STND_SHIFTER) ||
2725 ATARIHW_PRESENT(EXTD_SHIFTER)) {
2726 fbhw = &st_switch;
2727 atafb_ops.fb_setcolreg = &stste_setcolreg;
2728 break;
2729 }
2730 fbhw = &st_switch;
2731 atafb_ops.fb_setcolreg = &stste_setcolreg;
2732 printk("Cannot determine video hardware; defaulting to ST(e)\n");
2733#else /* ATAFB_STE */
2734 /* no default driver included */
2735 /* Nobody will ever see this message :-) */
2736 panic("Cannot initialize video hardware");
2737#endif
2738 } while (0);
2739
2740 /* Multisync monitor capabilities */
2741 /* Atari-TOS defaults if no boot option present */
2742 if (fb_info.monspecs.hfmin == 0) {
2743 fb_info.monspecs.hfmin = 31000;
2744 fb_info.monspecs.hfmax = 32000;
2745 fb_info.monspecs.vfmin = 58;
2746 fb_info.monspecs.vfmax = 62;
2747 }
2748
2749 detected_mode = fbhw->detect();
2750 check_default_par(detected_mode);
2751#ifdef ATAFB_EXT
2752 if (!external_addr) {
2753#endif /* ATAFB_EXT */
2754 mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
2755 mem_req = PAGE_ALIGN(mem_req) + PAGE_SIZE;
2756 screen_base = atari_stram_alloc(mem_req, "atafb");
2757 if (!screen_base)
2758 panic("Cannot allocate screen memory");
2759 memset(screen_base, 0, mem_req);
2760 pad = -(unsigned long)screen_base & (PAGE_SIZE-1);
2761 screen_base+=pad;
2762 real_screen_base=screen_base+ovsc_offset;
2763 screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
2764 st_ovsc_switch();
2765 if (CPU_IS_040_OR_060) {
2766 /* On a '040+, the cache mode of video RAM must be set to
2767 * write-through also for internal video hardware! */
2768 cache_push(virt_to_phys(screen_base), screen_len);
2769 kernel_set_cachemode(screen_base, screen_len,
2770 IOMAP_WRITETHROUGH);
2771 }
2772#ifdef ATAFB_EXT
2773 }
2774 else {
2775 /* Map the video memory (physical address given) to somewhere
2776 * in the kernel address space.
2777 */
2778 external_addr =
2779 ioremap_writethrough((unsigned long)external_addr,
2780 external_len);
2781 if (external_vgaiobase)
2782 external_vgaiobase =
2783 (unsigned long)ioremap(external_vgaiobase, 0x10000);
2784 screen_base =
2785 real_screen_base = external_addr;
2786 screen_len = external_len & PAGE_MASK;
2787 memset (screen_base, 0, external_len);
2788 }
2789#endif /* ATAFB_EXT */
2790
2791 strcpy(fb_info.modename, "Atari Builtin ");
2792 fb_info.changevar = NULL;
2793 fb_info.fbops = &atafb_ops;
2794 fb_info.disp = &disp;
2795 fb_info.currcon = -1;
2796 fb_info.switch_con = &atafb_switch;
2797 fb_info.updatevar = &fb_update_var;
2798 fb_info.flags = FBINFO_FLAG_DEFAULT;
2799 do_fb_set_var(&atafb_predefined[default_par-1], 1);
2800 strcat(fb_info.modename, fb_var_names[default_par-1][0]);
2801
2802 atafb_get_var(&disp.var, -1, &fb_info);
2803 atafb_set_disp(-1, &fb_info);
2804 do_install_cmap(0, &fb_info);
2805
2806 if (register_framebuffer(&fb_info) < 0) {
2807#ifdef ATAFB_EXT
2808 if (external_addr) {
2809 iounmap(external_addr);
2810 external_addr = NULL;
2811 }
2812 if (external_vgaiobase) {
2813 iounmap((void*)external_vgaiobase);
2814 external_vgaiobase = 0;
2815 }
2816#endif
2817 return -EINVAL;
2818 }
2819
2820 printk("Determined %dx%d, depth %d\n",
2821 disp.var.xres, disp.var.yres, disp.var.bits_per_pixel);
2822 if ((disp.var.xres != disp.var.xres_virtual) ||
2823 (disp.var.yres != disp.var.yres_virtual))
2824 printk(" virtual %dx%d\n",
2825 disp.var.xres_virtual, disp.var.yres_virtual);
2826 printk("fb%d: %s frame buffer device, using %dK of video memory\n",
2827 fb_info.node, fb_info.modename, screen_len>>10);
2828
2829 /* TODO: This driver cannot be unloaded yet */
2830 return 0;
2831} 2826}
2832 2827
2833
2834#ifdef ATAFB_EXT 2828#ifdef ATAFB_EXT
2835static void __init atafb_setup_ext(char *spec) 2829static void __init atafb_setup_ext(char *spec)
2836{ 2830{
2837 int xres, xres_virtual, yres, depth, planes; 2831 int xres, xres_virtual, yres, depth, planes;
2838 unsigned long addr, len; 2832 unsigned long addr, len;
2839 char *p; 2833 char *p;
2840 2834
@@ -2848,27 +2842,31 @@ static void __init atafb_setup_ext(char *spec)
2848 * 2842 *
2849 * Even xres_virtual is available, we neither support panning nor hw-scrolling! 2843 * Even xres_virtual is available, we neither support panning nor hw-scrolling!
2850 */ 2844 */
2851 if (!(p = strsep(&spec, ";")) || !*p) 2845 p = strsep(&spec, ";");
2852 return; 2846 if (!p || !*p)
2847 return;
2853 xres_virtual = xres = simple_strtoul(p, NULL, 10); 2848 xres_virtual = xres = simple_strtoul(p, NULL, 10);
2854 if (xres <= 0) 2849 if (xres <= 0)
2855 return; 2850 return;
2856 2851
2857 if (!(p = strsep(&spec, ";")) || !*p) 2852 p = strsep(&spec, ";");
2858 return; 2853 if (!p || !*p)
2854 return;
2859 yres = simple_strtoul(p, NULL, 10); 2855 yres = simple_strtoul(p, NULL, 10);
2860 if (yres <= 0) 2856 if (yres <= 0)
2861 return; 2857 return;
2862 2858
2863 if (!(p = strsep(&spec, ";")) || !*p) 2859 p = strsep(&spec, ";");
2864 return; 2860 if (!p || !*p)
2861 return;
2865 depth = simple_strtoul(p, NULL, 10); 2862 depth = simple_strtoul(p, NULL, 10);
2866 if (depth != 1 && depth != 2 && depth != 4 && depth != 8 && 2863 if (depth != 1 && depth != 2 && depth != 4 && depth != 8 &&
2867 depth != 16 && depth != 24) 2864 depth != 16 && depth != 24)
2868 return; 2865 return;
2869 2866
2870 if (!(p = strsep(&spec, ";")) || !*p) 2867 p = strsep(&spec, ";");
2871 return; 2868 if (!p || !*p)
2869 return;
2872 if (*p == 'i') 2870 if (*p == 'i')
2873 planes = FB_TYPE_INTERLEAVED_PLANES; 2871 planes = FB_TYPE_INTERLEAVED_PLANES;
2874 else if (*p == 'p') 2872 else if (*p == 'p')
@@ -2876,25 +2874,27 @@ static void __init atafb_setup_ext(char *spec)
2876 else if (*p == 'n') 2874 else if (*p == 'n')
2877 planes = FB_TYPE_PLANES; 2875 planes = FB_TYPE_PLANES;
2878 else if (*p == 't') 2876 else if (*p == 't')
2879 planes = -1; /* true color */ 2877 planes = -1; /* true color */
2880 else 2878 else
2881 return; 2879 return;
2882 2880
2883 2881 p = strsep(&spec, ";");
2884 if (!(p = strsep(&spec, ";")) || !*p) 2882 if (!p || !*p)
2885 return; 2883 return;
2886 addr = simple_strtoul(p, NULL, 0); 2884 addr = simple_strtoul(p, NULL, 0);
2887 2885
2888 if (!(p = strsep(&spec, ";")) || !*p) 2886 p = strsep(&spec, ";");
2889 len = xres*yres*depth/8; 2887 if (!p || !*p)
2888 len = xres * yres * depth / 8;
2890 else 2889 else
2891 len = simple_strtoul(p, NULL, 0); 2890 len = simple_strtoul(p, NULL, 0);
2892 2891
2893 if ((p = strsep(&spec, ";")) && *p) { 2892 p = strsep(&spec, ";");
2894 external_vgaiobase=simple_strtoul(p, NULL, 0); 2893 if (p && *p)
2895 } 2894 external_vgaiobase = simple_strtoul(p, NULL, 0);
2896 2895
2897 if ((p = strsep(&spec, ";")) && *p) { 2896 p = strsep(&spec, ";");
2897 if (p && *p) {
2898 external_bitspercol = simple_strtoul(p, NULL, 0); 2898 external_bitspercol = simple_strtoul(p, NULL, 0);
2899 if (external_bitspercol > 8) 2899 if (external_bitspercol > 8)
2900 external_bitspercol = 8; 2900 external_bitspercol = 8;
@@ -2902,59 +2902,61 @@ static void __init atafb_setup_ext(char *spec)
2902 external_bitspercol = 1; 2902 external_bitspercol = 1;
2903 } 2903 }
2904 2904
2905 if ((p = strsep(&spec, ";")) && *p) { 2905 p = strsep(&spec, ";");
2906 if (p && *p) {
2906 if (!strcmp(p, "vga")) 2907 if (!strcmp(p, "vga"))
2907 external_card_type = IS_VGA; 2908 external_card_type = IS_VGA;
2908 if (!strcmp(p, "mv300")) 2909 if (!strcmp(p, "mv300"))
2909 external_card_type = IS_MV300; 2910 external_card_type = IS_MV300;
2910 } 2911 }
2911 2912
2912 if ((p = strsep(&spec, ";")) && *p) { 2913 p = strsep(&spec, ";");
2914 if (p && *p) {
2913 xres_virtual = simple_strtoul(p, NULL, 10); 2915 xres_virtual = simple_strtoul(p, NULL, 10);
2914 if (xres_virtual < xres) 2916 if (xres_virtual < xres)
2915 xres_virtual = xres; 2917 xres_virtual = xres;
2916 if (xres_virtual*yres*depth/8 > len) 2918 if (xres_virtual * yres * depth / 8 > len)
2917 len=xres_virtual*yres*depth/8; 2919 len = xres_virtual * yres * depth / 8;
2918 } 2920 }
2919 2921
2920 external_xres = xres; 2922 external_xres = xres;
2921 external_xres_virtual = xres_virtual; 2923 external_xres_virtual = xres_virtual;
2922 external_yres = yres; 2924 external_yres = yres;
2923 external_depth = depth; 2925 external_depth = depth;
2924 external_pmode = planes; 2926 external_pmode = planes;
2925 external_addr = (void *)addr; 2927 external_addr = (void *)addr;
2926 external_len = len; 2928 external_len = len;
2927 2929
2928 if (external_card_type == IS_MV300) 2930 if (external_card_type == IS_MV300) {
2929 switch (external_depth) { 2931 switch (external_depth) {
2930 case 1: 2932 case 1:
2931 MV300_reg = MV300_reg_1bit; 2933 MV300_reg = MV300_reg_1bit;
2932 break; 2934 break;
2933 case 4: 2935 case 4:
2934 MV300_reg = MV300_reg_4bit; 2936 MV300_reg = MV300_reg_4bit;
2935 break; 2937 break;
2936 case 8: 2938 case 8:
2937 MV300_reg = MV300_reg_8bit; 2939 MV300_reg = MV300_reg_8bit;
2938 break; 2940 break;
2939 } 2941 }
2942 }
2940} 2943}
2941#endif /* ATAFB_EXT */ 2944#endif /* ATAFB_EXT */
2942 2945
2943
2944static void __init atafb_setup_int(char *spec) 2946static void __init atafb_setup_int(char *spec)
2945{ 2947{
2946 /* Format to config extended internal video hardware like OverScan: 2948 /* Format to config extended internal video hardware like OverScan:
2947 "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>" 2949 * "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>"
2948 Explanation: 2950 * Explanation:
2949 <xres>: x-resolution 2951 * <xres>: x-resolution
2950 <yres>: y-resolution 2952 * <yres>: y-resolution
2951 The following are only needed if you have an overscan which 2953 * The following are only needed if you have an overscan which
2952 needs a black border: 2954 * needs a black border:
2953 <xres_max>: max. length of a line in pixels your OverScan hardware would allow 2955 * <xres_max>: max. length of a line in pixels your OverScan hardware would allow
2954 <yres_max>: max. number of lines your OverScan hardware would allow 2956 * <yres_max>: max. number of lines your OverScan hardware would allow
2955 <offset>: Offset from physical beginning to visible beginning 2957 * <offset>: Offset from physical beginning to visible beginning
2956 of screen in bytes 2958 * of screen in bytes
2957 */ 2959 */
2958 int xres; 2960 int xres;
2959 char *p; 2961 char *p;
2960 2962
@@ -2963,23 +2965,19 @@ static void __init atafb_setup_int(char *spec)
2963 xres = simple_strtoul(p, NULL, 10); 2965 xres = simple_strtoul(p, NULL, 10);
2964 if (!(p = strsep(&spec, ";")) || !*p) 2966 if (!(p = strsep(&spec, ";")) || !*p)
2965 return; 2967 return;
2966 sttt_xres=xres; 2968 sttt_xres = xres;
2967 tt_yres=st_yres=simple_strtoul(p, NULL, 10); 2969 tt_yres = st_yres = simple_strtoul(p, NULL, 10);
2968 if ((p=strsep(&spec, ";")) && *p) { 2970 if ((p = strsep(&spec, ";")) && *p)
2969 sttt_xres_virtual=simple_strtoul(p, NULL, 10); 2971 sttt_xres_virtual = simple_strtoul(p, NULL, 10);
2970 } 2972 if ((p = strsep(&spec, ";")) && *p)
2971 if ((p=strsep(&spec, ";")) && *p) { 2973 sttt_yres_virtual = simple_strtoul(p, NULL, 0);
2972 sttt_yres_virtual=simple_strtoul(p, NULL, 0); 2974 if ((p = strsep(&spec, ";")) && *p)
2973 } 2975 ovsc_offset = simple_strtoul(p, NULL, 0);
2974 if ((p=strsep(&spec, ";")) && *p) {
2975 ovsc_offset=simple_strtoul(p, NULL, 0);
2976 }
2977 2976
2978 if (ovsc_offset || (sttt_yres_virtual != st_yres)) 2977 if (ovsc_offset || (sttt_yres_virtual != st_yres))
2979 use_hwscroll=0; 2978 use_hwscroll = 0;
2980} 2979}
2981 2980
2982
2983#ifdef ATAFB_FALCON 2981#ifdef ATAFB_FALCON
2984static void __init atafb_setup_mcap(char *spec) 2982static void __init atafb_setup_mcap(char *spec)
2985{ 2983{
@@ -3018,7 +3016,6 @@ static void __init atafb_setup_mcap(char *spec)
3018} 3016}
3019#endif /* ATAFB_FALCON */ 3017#endif /* ATAFB_FALCON */
3020 3018
3021
3022static void __init atafb_setup_user(char *spec) 3019static void __init atafb_setup_user(char *spec)
3023{ 3020{
3024 /* Format of user defined video mode is: <xres>;<yres>;<depth> 3021 /* Format of user defined video mode is: <xres>;<yres>;<depth>
@@ -3026,81 +3023,257 @@ static void __init atafb_setup_user(char *spec)
3026 char *p; 3023 char *p;
3027 int xres, yres, depth, temp; 3024 int xres, yres, depth, temp;
3028 3025
3029 if (!(p = strsep(&spec, ";")) || !*p) 3026 p = strsep(&spec, ";");
3027 if (!p || !*p)
3030 return; 3028 return;
3031 xres = simple_strtoul(p, NULL, 10); 3029 xres = simple_strtoul(p, NULL, 10);
3032 if (!(p = strsep(&spec, ";")) || !*p) 3030 p = strsep(&spec, ";");
3031 if (!p || !*p)
3033 return; 3032 return;
3034 yres = simple_strtoul(p, NULL, 10); 3033 yres = simple_strtoul(p, NULL, 10);
3035 if (!(p = strsep(&spec, "")) || !*p) 3034 p = strsep(&spec, "");
3035 if (!p || !*p)
3036 return; 3036 return;
3037 depth = simple_strtoul(p, NULL, 10); 3037 depth = simple_strtoul(p, NULL, 10);
3038 if ((temp=get_video_mode("user0"))) { 3038 temp = get_video_mode("user0");
3039 default_par=temp; 3039 if (temp) {
3040 atafb_predefined[default_par-1].xres = xres; 3040 default_par = temp;
3041 atafb_predefined[default_par-1].yres = yres; 3041 atafb_predefined[default_par - 1].xres = xres;
3042 atafb_predefined[default_par-1].bits_per_pixel = depth; 3042 atafb_predefined[default_par - 1].yres = yres;
3043 atafb_predefined[default_par - 1].bits_per_pixel = depth;
3043 } 3044 }
3044} 3045}
3045 3046
3046int __init atafb_setup( char *options ) 3047int __init atafb_setup(char *options)
3047{ 3048{
3048 char *this_opt; 3049 char *this_opt;
3049 int temp; 3050 int temp;
3050
3051 fb_info.fontname[0] = '\0';
3052 3051
3053 if (!options || !*options) 3052 if (!options || !*options)
3054 return 0; 3053 return 0;
3055 3054
3056 while ((this_opt = strsep(&options, ",")) != NULL) { 3055 while ((this_opt = strsep(&options, ",")) != NULL) {
3057 if (!*this_opt) continue; 3056 if (!*this_opt)
3058 if ((temp=get_video_mode(this_opt))) 3057 continue;
3059 default_par=temp; 3058 if ((temp = get_video_mode(this_opt))) {
3060 else if (! strcmp(this_opt, "inverse")) 3059 default_par = temp;
3061 inverse=1; 3060 mode_option = this_opt;
3062 else if (!strncmp(this_opt, "font:", 5)) 3061 } else if (!strcmp(this_opt, "inverse"))
3063 strcpy(fb_info.fontname, this_opt+5); 3062 inverse = 1;
3064 else if (! strncmp(this_opt, "hwscroll_",9)) { 3063 else if (!strncmp(this_opt, "hwscroll_", 9)) {
3065 hwscroll=simple_strtoul(this_opt+9, NULL, 10); 3064 hwscroll = simple_strtoul(this_opt + 9, NULL, 10);
3066 if (hwscroll < 0) 3065 if (hwscroll < 0)
3067 hwscroll = 0; 3066 hwscroll = 0;
3068 if (hwscroll > 200) 3067 if (hwscroll > 200)
3069 hwscroll = 200; 3068 hwscroll = 200;
3070 } 3069 }
3071#ifdef ATAFB_EXT 3070#ifdef ATAFB_EXT
3072 else if (!strcmp(this_opt,"mv300")) { 3071 else if (!strcmp(this_opt, "mv300")) {
3073 external_bitspercol = 8; 3072 external_bitspercol = 8;
3074 external_card_type = IS_MV300; 3073 external_card_type = IS_MV300;
3074 } else if (!strncmp(this_opt, "external:", 9))
3075 atafb_setup_ext(this_opt + 9);
3076#endif
3077 else if (!strncmp(this_opt, "internal:", 9))
3078 atafb_setup_int(this_opt + 9);
3079#ifdef ATAFB_FALCON
3080 else if (!strncmp(this_opt, "eclock:", 7)) {
3081 fext.f = simple_strtoul(this_opt + 7, NULL, 10);
3082 /* external pixelclock in kHz --> ps */
3083 fext.t = 1000000000 / fext.f;
3084 fext.f *= 1000;
3085 } else if (!strncmp(this_opt, "monitorcap:", 11))
3086 atafb_setup_mcap(this_opt + 11);
3087#endif
3088 else if (!strcmp(this_opt, "keep"))
3089 DontCalcRes = 1;
3090 else if (!strncmp(this_opt, "R", 1))
3091 atafb_setup_user(this_opt + 1);
3075 } 3092 }
3076 else if (!strncmp(this_opt,"external:",9)) 3093 return 0;
3077 atafb_setup_ext(this_opt+9); 3094}
3095
3096int __init atafb_init(void)
3097{
3098 int pad;
3099 int detected_mode;
3100 unsigned int defmode = 0;
3101 unsigned long mem_req;
3102
3103#ifndef MODULE
3104 char *option = NULL;
3105
3106 if (fb_get_options("atafb", &option))
3107 return -ENODEV;
3108 atafb_setup(option);
3109#endif
3110 printk("atafb_init: start\n");
3111
3112 if (!MACH_IS_ATARI)
3113 return -ENXIO;
3114
3115 do {
3116#ifdef ATAFB_EXT
3117 if (external_addr) {
3118 printk("atafb_init: initializing external hw\n");
3119 fbhw = &ext_switch;
3120 atafb_ops.fb_setcolreg = &ext_setcolreg;
3121 defmode = DEFMODE_EXT;
3122 break;
3123 }
3124#endif
3125#ifdef ATAFB_TT
3126 if (ATARIHW_PRESENT(TT_SHIFTER)) {
3127 printk("atafb_init: initializing TT hw\n");
3128 fbhw = &tt_switch;
3129 atafb_ops.fb_setcolreg = &tt_setcolreg;
3130 defmode = DEFMODE_TT;
3131 break;
3132 }
3078#endif 3133#endif
3079 else if (!strncmp(this_opt,"internal:",9))
3080 atafb_setup_int(this_opt+9);
3081#ifdef ATAFB_FALCON 3134#ifdef ATAFB_FALCON
3082 else if (!strncmp(this_opt, "eclock:", 7)) { 3135 if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
3083 fext.f = simple_strtoul(this_opt+7, NULL, 10); 3136 printk("atafb_init: initializing Falcon hw\n");
3084 /* external pixelclock in kHz --> ps */ 3137 fbhw = &falcon_switch;
3085 fext.t = 1000000000/fext.f; 3138 atafb_ops.fb_setcolreg = &falcon_setcolreg;
3086 fext.f *= 1000; 3139 request_irq(IRQ_AUTO_4, falcon_vbl_switcher, IRQ_TYPE_PRIO,
3140 "framebuffer/modeswitch", falcon_vbl_switcher);
3141 defmode = DEFMODE_F30;
3142 break;
3143 }
3144#endif
3145#ifdef ATAFB_STE
3146 if (ATARIHW_PRESENT(STND_SHIFTER) ||
3147 ATARIHW_PRESENT(EXTD_SHIFTER)) {
3148 printk("atafb_init: initializing ST/E hw\n");
3149 fbhw = &st_switch;
3150 atafb_ops.fb_setcolreg = &stste_setcolreg;
3151 defmode = DEFMODE_STE;
3152 break;
3153 }
3154 fbhw = &st_switch;
3155 atafb_ops.fb_setcolreg = &stste_setcolreg;
3156 printk("Cannot determine video hardware; defaulting to ST(e)\n");
3157#else /* ATAFB_STE */
3158 /* no default driver included */
3159 /* Nobody will ever see this message :-) */
3160 panic("Cannot initialize video hardware");
3161#endif
3162 } while (0);
3163
3164 /* Multisync monitor capabilities */
3165 /* Atari-TOS defaults if no boot option present */
3166 if (fb_info.monspecs.hfmin == 0) {
3167 fb_info.monspecs.hfmin = 31000;
3168 fb_info.monspecs.hfmax = 32000;
3169 fb_info.monspecs.vfmin = 58;
3170 fb_info.monspecs.vfmax = 62;
3087 } 3171 }
3088 else if (!strncmp(this_opt, "monitorcap:", 11)) 3172
3089 atafb_setup_mcap(this_opt+11); 3173 detected_mode = fbhw->detect();
3174 check_default_par(detected_mode);
3175#ifdef ATAFB_EXT
3176 if (!external_addr) {
3177#endif /* ATAFB_EXT */
3178 mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
3179 mem_req = PAGE_ALIGN(mem_req) + PAGE_SIZE;
3180 screen_base = atari_stram_alloc(mem_req, "atafb");
3181 if (!screen_base)
3182 panic("Cannot allocate screen memory");
3183 memset(screen_base, 0, mem_req);
3184 pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
3185 screen_base += pad;
3186 real_screen_base = screen_base + ovsc_offset;
3187 screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
3188 st_ovsc_switch();
3189 if (CPU_IS_040_OR_060) {
3190 /* On a '040+, the cache mode of video RAM must be set to
3191 * write-through also for internal video hardware! */
3192 cache_push(virt_to_phys(screen_base), screen_len);
3193 kernel_set_cachemode(screen_base, screen_len,
3194 IOMAP_WRITETHROUGH);
3195 }
3196 printk("atafb: screen_base %p real_screen_base %p screen_len %d\n",
3197 screen_base, real_screen_base, screen_len);
3198#ifdef ATAFB_EXT
3199 } else {
3200 /* Map the video memory (physical address given) to somewhere
3201 * in the kernel address space.
3202 */
3203 external_addr = ioremap_writethrough((unsigned long)external_addr,
3204 external_len);
3205 if (external_vgaiobase)
3206 external_vgaiobase =
3207 (unsigned long)ioremap(external_vgaiobase, 0x10000);
3208 screen_base =
3209 real_screen_base = external_addr;
3210 screen_len = external_len & PAGE_MASK;
3211 memset (screen_base, 0, external_len);
3212 }
3213#endif /* ATAFB_EXT */
3214
3215// strcpy(fb_info.mode->name, "Atari Builtin ");
3216 fb_info.fbops = &atafb_ops;
3217 // try to set default (detected; requested) var
3218 do_fb_set_var(&atafb_predefined[default_par - 1], 1);
3219 // reads hw state into current par, which may not be sane yet
3220 ata_get_par(&current_par);
3221 fb_info.par = &current_par;
3222 // tries to read from HW which may not be initialized yet
3223 // so set sane var first, then call atafb_set_par
3224 atafb_get_var(&fb_info.var, &fb_info);
3225 fb_info.flags = FBINFO_FLAG_DEFAULT;
3226
3227 if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, atafb_modedb,
3228 NUM_TOTAL_MODES, &atafb_modedb[defmode],
3229 fb_info.var.bits_per_pixel)) {
3230 return -EINVAL;
3231 }
3232
3233 atafb_set_disp(&fb_info);
3234
3235 fb_alloc_cmap(&(fb_info.cmap), 1 << fb_info.var.bits_per_pixel, 0);
3236
3237
3238 printk("Determined %dx%d, depth %d\n",
3239 fb_info.var.xres, fb_info.var.yres, fb_info.var.bits_per_pixel);
3240 if ((fb_info.var.xres != fb_info.var.xres_virtual) ||
3241 (fb_info.var.yres != fb_info.var.yres_virtual))
3242 printk(" virtual %dx%d\n", fb_info.var.xres_virtual,
3243 fb_info.var.yres_virtual);
3244
3245 if (register_framebuffer(&fb_info) < 0) {
3246#ifdef ATAFB_EXT
3247 if (external_addr) {
3248 iounmap(external_addr);
3249 external_addr = NULL;
3250 }
3251 if (external_vgaiobase) {
3252 iounmap((void*)external_vgaiobase);
3253 external_vgaiobase = 0;
3254 }
3090#endif 3255#endif
3091 else if (!strcmp(this_opt, "keep")) 3256 return -EINVAL;
3092 DontCalcRes = 1; 3257 }
3093 else if (!strncmp(this_opt, "R", 1)) 3258
3094 atafb_setup_user(this_opt+1); 3259 // FIXME: mode needs setting!
3095 } 3260 //printk("fb%d: %s frame buffer device, using %dK of video memory\n",
3096 return 0; 3261 // fb_info.node, fb_info.mode->name, screen_len>>10);
3262 printk("fb%d: frame buffer device, using %dK of video memory\n",
3263 fb_info.node, screen_len >> 10);
3264
3265 /* TODO: This driver cannot be unloaded yet */
3266 return 0;
3097} 3267}
3098 3268
3269module_init(atafb_init);
3270
3099#ifdef MODULE 3271#ifdef MODULE
3100MODULE_LICENSE("GPL"); 3272MODULE_LICENSE("GPL");
3101 3273
3102int init_module(void) 3274int cleanup_module(void)
3103{ 3275{
3104 return atafb_init(); 3276 unregister_framebuffer(&fb_info);
3277 return atafb_deinit();
3105} 3278}
3106#endif /* MODULE */ 3279#endif /* MODULE */
diff --git a/drivers/video/atafb.h b/drivers/video/atafb.h
new file mode 100644
index 000000000000..014e05906cb1
--- /dev/null
+++ b/drivers/video/atafb.h
@@ -0,0 +1,36 @@
1#ifndef _VIDEO_ATAFB_H
2#define _VIDEO_ATAFB_H
3
4void atafb_mfb_copyarea(struct fb_info *info, u_long next_line, int sy, int sx, int dy,
5 int dx, int height, int width);
6void atafb_mfb_fillrect(struct fb_info *info, u_long next_line, u32 color,
7 int sy, int sx, int height, int width);
8void atafb_mfb_linefill(struct fb_info *info, u_long next_line,
9 int dy, int dx, u32 width,
10 const u8 *data, u32 bgcolor, u32 fgcolor);
11
12void atafb_iplan2p2_copyarea(struct fb_info *info, u_long next_line, int sy, int sx, int dy,
13 int dx, int height, int width);
14void atafb_iplan2p2_fillrect(struct fb_info *info, u_long next_line, u32 color,
15 int sy, int sx, int height, int width);
16void atafb_iplan2p2_linefill(struct fb_info *info, u_long next_line,
17 int dy, int dx, u32 width,
18 const u8 *data, u32 bgcolor, u32 fgcolor);
19
20void atafb_iplan2p4_copyarea(struct fb_info *info, u_long next_line, int sy, int sx, int dy,
21 int dx, int height, int width);
22void atafb_iplan2p4_fillrect(struct fb_info *info, u_long next_line, u32 color,
23 int sy, int sx, int height, int width);
24void atafb_iplan2p4_linefill(struct fb_info *info, u_long next_line,
25 int dy, int dx, u32 width,
26 const u8 *data, u32 bgcolor, u32 fgcolor);
27
28void atafb_iplan2p8_copyarea(struct fb_info *info, u_long next_line, int sy, int sx, int dy,
29 int dx, int height, int width);
30void atafb_iplan2p8_fillrect(struct fb_info *info, u_long next_line, u32 color,
31 int sy, int sx, int height, int width);
32void atafb_iplan2p8_linefill(struct fb_info *info, u_long next_line,
33 int dy, int dx, u32 width,
34 const u8 *data, u32 bgcolor, u32 fgcolor);
35
36#endif /* _VIDEO_ATAFB_H */
diff --git a/drivers/video/atafb_iplan2p2.c b/drivers/video/atafb_iplan2p2.c
new file mode 100644
index 000000000000..8cc9c50379d0
--- /dev/null
+++ b/drivers/video/atafb_iplan2p2.c
@@ -0,0 +1,293 @@
1/*
2 * linux/drivers/video/iplan2p2.c -- Low level frame buffer operations for
3 * interleaved bitplanes à la Atari (2
4 * planes, 2 bytes interleave)
5 *
6 * Created 5 Apr 1997 by Geert Uytterhoeven
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
10 * more details.
11 */
12
13#include <linux/module.h>
14#include <linux/string.h>
15#include <linux/fb.h>
16
17#include <asm/setup.h>
18
19#include "atafb.h"
20
21#define BPL 2
22#include "atafb_utils.h"
23
24void atafb_iplan2p2_copyarea(struct fb_info *info, u_long next_line,
25 int sy, int sx, int dy, int dx,
26 int height, int width)
27{
28 /* bmove() has to distinguish two major cases: If both, source and
29 * destination, start at even addresses or both are at odd
30 * addresses, just the first odd and last even column (if present)
31 * require special treatment (memmove_col()). The rest between
32 * then can be copied by normal operations, because all adjacent
33 * bytes are affected and are to be stored in the same order.
34 * The pathological case is when the move should go from an odd
35 * address to an even or vice versa. Since the bytes in the plane
36 * words must be assembled in new order, it seems wisest to make
37 * all movements by memmove_col().
38 */
39
40 u8 *src, *dst;
41 u32 *s, *d;
42 int w, l , i, j;
43 u_int colsize;
44 u_int upwards = (dy < sy) || (dy == sy && dx < sx);
45
46 colsize = height;
47 if (!((sx ^ dx) & 15)) {
48 /* odd->odd or even->even */
49
50 if (upwards) {
51 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
52 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
53 if (sx & 15) {
54 memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
55 src += BPL * 2;
56 dst += BPL * 2;
57 width -= 8;
58 }
59 w = width >> 4;
60 if (w) {
61 s = (u32 *)src;
62 d = (u32 *)dst;
63 w *= BPL / 2;
64 l = next_line - w * 4;
65 for (j = height; j > 0; j--) {
66 for (i = w; i > 0; i--)
67 *d++ = *s++;
68 s = (u32 *)((u8 *)s + l);
69 d = (u32 *)((u8 *)d + l);
70 }
71 }
72 if (width & 15)
73 memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
74 0xff00ff00, height, next_line - BPL * 2);
75 } else {
76 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
77 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
78
79 if ((sx + width) & 15) {
80 src -= BPL * 2;
81 dst -= BPL * 2;
82 memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
83 width -= 8;
84 }
85 w = width >> 4;
86 if (w) {
87 s = (u32 *)src;
88 d = (u32 *)dst;
89 w *= BPL / 2;
90 l = next_line - w * 4;
91 for (j = height; j > 0; j--) {
92 for (i = w; i > 0; i--)
93 *--d = *--s;
94 s = (u32 *)((u8 *)s - l);
95 d = (u32 *)((u8 *)d - l);
96 }
97 }
98 if (sx & 15)
99 memmove32_col(dst - (width - 16) / (8 / BPL),
100 src - (width - 16) / (8 / BPL),
101 0xff00ff, colsize, -next_line - BPL * 2);
102 }
103 } else {
104 /* odd->even or even->odd */
105 if (upwards) {
106 u32 *src32, *dst32;
107 u32 pval[4], v, v1, mask;
108 int i, j, w, f;
109
110 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
111 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
112
113 mask = 0xff00ff00;
114 f = 0;
115 w = width;
116 if (sx & 15) {
117 f = 1;
118 w += 8;
119 }
120 if ((sx + width) & 15)
121 f |= 2;
122 w >>= 4;
123 for (i = height; i; i--) {
124 src32 = (u32 *)src;
125 dst32 = (u32 *)dst;
126
127 if (f & 1) {
128 pval[0] = (*src32++ << 8) & mask;
129 } else {
130 pval[0] = dst32[0] & mask;
131 }
132
133 for (j = w; j > 0; j--) {
134 v = *src32++;
135 v1 = v & mask;
136 *dst32++ = pval[0] | (v1 >> 8);
137 pval[0] = (v ^ v1) << 8;
138 }
139
140 if (f & 2) {
141 dst32[0] = (dst32[0] & mask) | pval[0];
142 }
143
144 src += next_line;
145 dst += next_line;
146 }
147 } else {
148 u32 *src32, *dst32;
149 u32 pval[4], v, v1, mask;
150 int i, j, w, f;
151
152 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
153 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
154
155 mask = 0xff00ff;
156 f = 0;
157 w = width;
158 if ((dx + width) & 15)
159 f = 1;
160 if (sx & 15) {
161 f |= 2;
162 w += 8;
163 }
164 w >>= 4;
165 for (i = height; i; i--) {
166 src32 = (u32 *)src;
167 dst32 = (u32 *)dst;
168
169 if (f & 1) {
170 pval[0] = dst32[-1] & mask;
171 } else {
172 pval[0] = (*--src32 >> 8) & mask;
173 }
174
175 for (j = w; j > 0; j--) {
176 v = *--src32;
177 v1 = v & mask;
178 *--dst32 = pval[0] | (v1 << 8);
179 pval[0] = (v ^ v1) >> 8;
180 }
181
182 if (!(f & 2)) {
183 dst32[-1] = (dst32[-1] & mask) | pval[0];
184 }
185
186 src -= next_line;
187 dst -= next_line;
188 }
189 }
190 }
191}
192
193void atafb_iplan2p2_fillrect(struct fb_info *info, u_long next_line, u32 color,
194 int sy, int sx, int height, int width)
195{
196 u32 *dest;
197 int rows, i;
198 u32 cval[4];
199
200 dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
201 if (sx & 15) {
202 u8 *dest8 = (u8 *)dest + 1;
203
204 expand8_col2mask(color, cval);
205
206 for (i = height; i; i--) {
207 fill8_col(dest8, cval);
208 dest8 += next_line;
209 }
210 dest += BPL / 2;
211 width -= 8;
212 }
213
214 expand16_col2mask(color, cval);
215 rows = width >> 4;
216 if (rows) {
217 u32 *d = dest;
218 u32 off = next_line - rows * BPL * 2;
219 for (i = height; i; i--) {
220 d = fill16_col(d, rows, cval);
221 d = (u32 *)((long)d + off);
222 }
223 dest += rows * BPL / 2;
224 width &= 15;
225 }
226
227 if (width) {
228 u8 *dest8 = (u8 *)dest;
229
230 expand8_col2mask(color, cval);
231
232 for (i = height; i; i--) {
233 fill8_col(dest8, cval);
234 dest8 += next_line;
235 }
236 }
237}
238
239void atafb_iplan2p2_linefill(struct fb_info *info, u_long next_line,
240 int dy, int dx, u32 width,
241 const u8 *data, u32 bgcolor, u32 fgcolor)
242{
243 u32 *dest;
244 const u16 *data16;
245 int rows;
246 u32 fgm[4], bgm[4], m;
247
248 dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
249 if (dx & 15) {
250 fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
251 dest += BPL / 2;
252 width -= 8;
253 }
254
255 if (width >= 16) {
256 data16 = (const u16 *)data;
257 expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
258
259 for (rows = width / 16; rows; rows--) {
260 u16 d = *data16++;
261 m = d | ((u32)d << 16);
262 *dest++ = (m & fgm[0]) ^ bgm[0];
263 }
264
265 data = (const u8 *)data16;
266 width &= 15;
267 }
268
269 if (width)
270 fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
271}
272
273#ifdef MODULE
274MODULE_LICENSE("GPL");
275
276int init_module(void)
277{
278 return 0;
279}
280
281void cleanup_module(void)
282{
283}
284#endif /* MODULE */
285
286
287 /*
288 * Visible symbols for modules
289 */
290
291EXPORT_SYMBOL(atafb_iplan2p2_copyarea);
292EXPORT_SYMBOL(atafb_iplan2p2_fillrect);
293EXPORT_SYMBOL(atafb_iplan2p2_linefill);
diff --git a/drivers/video/atafb_iplan2p4.c b/drivers/video/atafb_iplan2p4.c
new file mode 100644
index 000000000000..bee0d89463f7
--- /dev/null
+++ b/drivers/video/atafb_iplan2p4.c
@@ -0,0 +1,308 @@
1/*
2 * linux/drivers/video/iplan2p4.c -- Low level frame buffer operations for
3 * interleaved bitplanes à la Atari (4
4 * planes, 2 bytes interleave)
5 *
6 * Created 5 Apr 1997 by Geert Uytterhoeven
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
10 * more details.
11 */
12
13#include <linux/module.h>
14#include <linux/string.h>
15#include <linux/fb.h>
16
17#include <asm/setup.h>
18
19#include "atafb.h"
20
21#define BPL 4
22#include "atafb_utils.h"
23
24void atafb_iplan2p4_copyarea(struct fb_info *info, u_long next_line,
25 int sy, int sx, int dy, int dx,
26 int height, int width)
27{
28 /* bmove() has to distinguish two major cases: If both, source and
29 * destination, start at even addresses or both are at odd
30 * addresses, just the first odd and last even column (if present)
31 * require special treatment (memmove_col()). The rest between
32 * then can be copied by normal operations, because all adjacent
33 * bytes are affected and are to be stored in the same order.
34 * The pathological case is when the move should go from an odd
35 * address to an even or vice versa. Since the bytes in the plane
36 * words must be assembled in new order, it seems wisest to make
37 * all movements by memmove_col().
38 */
39
40 u8 *src, *dst;
41 u32 *s, *d;
42 int w, l , i, j;
43 u_int colsize;
44 u_int upwards = (dy < sy) || (dy == sy && dx < sx);
45
46 colsize = height;
47 if (!((sx ^ dx) & 15)) {
48 /* odd->odd or even->even */
49
50 if (upwards) {
51 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
52 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
53 if (sx & 15) {
54 memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
55 src += BPL * 2;
56 dst += BPL * 2;
57 width -= 8;
58 }
59 w = width >> 4;
60 if (w) {
61 s = (u32 *)src;
62 d = (u32 *)dst;
63 w *= BPL / 2;
64 l = next_line - w * 4;
65 for (j = height; j > 0; j--) {
66 for (i = w; i > 0; i--)
67 *d++ = *s++;
68 s = (u32 *)((u8 *)s + l);
69 d = (u32 *)((u8 *)d + l);
70 }
71 }
72 if (width & 15)
73 memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
74 0xff00ff00, height, next_line - BPL * 2);
75 } else {
76 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
77 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
78
79 if ((sx + width) & 15) {
80 src -= BPL * 2;
81 dst -= BPL * 2;
82 memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
83 width -= 8;
84 }
85 w = width >> 4;
86 if (w) {
87 s = (u32 *)src;
88 d = (u32 *)dst;
89 w *= BPL / 2;
90 l = next_line - w * 4;
91 for (j = height; j > 0; j--) {
92 for (i = w; i > 0; i--)
93 *--d = *--s;
94 s = (u32 *)((u8 *)s - l);
95 d = (u32 *)((u8 *)d - l);
96 }
97 }
98 if (sx & 15)
99 memmove32_col(dst - (width - 16) / (8 / BPL),
100 src - (width - 16) / (8 / BPL),
101 0xff00ff, colsize, -next_line - BPL * 2);
102 }
103 } else {
104 /* odd->even or even->odd */
105 if (upwards) {
106 u32 *src32, *dst32;
107 u32 pval[4], v, v1, mask;
108 int i, j, w, f;
109
110 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
111 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
112
113 mask = 0xff00ff00;
114 f = 0;
115 w = width;
116 if (sx & 15) {
117 f = 1;
118 w += 8;
119 }
120 if ((sx + width) & 15)
121 f |= 2;
122 w >>= 4;
123 for (i = height; i; i--) {
124 src32 = (u32 *)src;
125 dst32 = (u32 *)dst;
126
127 if (f & 1) {
128 pval[0] = (*src32++ << 8) & mask;
129 pval[1] = (*src32++ << 8) & mask;
130 } else {
131 pval[0] = dst32[0] & mask;
132 pval[1] = dst32[1] & mask;
133 }
134
135 for (j = w; j > 0; j--) {
136 v = *src32++;
137 v1 = v & mask;
138 *dst32++ = pval[0] | (v1 >> 8);
139 pval[0] = (v ^ v1) << 8;
140 v = *src32++;
141 v1 = v & mask;
142 *dst32++ = pval[1] | (v1 >> 8);
143 pval[1] = (v ^ v1) << 8;
144 }
145
146 if (f & 2) {
147 dst32[0] = (dst32[0] & mask) | pval[0];
148 dst32[1] = (dst32[1] & mask) | pval[1];
149 }
150
151 src += next_line;
152 dst += next_line;
153 }
154 } else {
155 u32 *src32, *dst32;
156 u32 pval[4], v, v1, mask;
157 int i, j, w, f;
158
159 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
160 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
161
162 mask = 0xff00ff;
163 f = 0;
164 w = width;
165 if ((dx + width) & 15)
166 f = 1;
167 if (sx & 15) {
168 f |= 2;
169 w += 8;
170 }
171 w >>= 4;
172 for (i = height; i; i--) {
173 src32 = (u32 *)src;
174 dst32 = (u32 *)dst;
175
176 if (f & 1) {
177 pval[0] = dst32[-1] & mask;
178 pval[1] = dst32[-2] & mask;
179 } else {
180 pval[0] = (*--src32 >> 8) & mask;
181 pval[1] = (*--src32 >> 8) & mask;
182 }
183
184 for (j = w; j > 0; j--) {
185 v = *--src32;
186 v1 = v & mask;
187 *--dst32 = pval[0] | (v1 << 8);
188 pval[0] = (v ^ v1) >> 8;
189 v = *--src32;
190 v1 = v & mask;
191 *--dst32 = pval[1] | (v1 << 8);
192 pval[1] = (v ^ v1) >> 8;
193 }
194
195 if (!(f & 2)) {
196 dst32[-1] = (dst32[-1] & mask) | pval[0];
197 dst32[-2] = (dst32[-2] & mask) | pval[1];
198 }
199
200 src -= next_line;
201 dst -= next_line;
202 }
203 }
204 }
205}
206
207void atafb_iplan2p4_fillrect(struct fb_info *info, u_long next_line, u32 color,
208 int sy, int sx, int height, int width)
209{
210 u32 *dest;
211 int rows, i;
212 u32 cval[4];
213
214 dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
215 if (sx & 15) {
216 u8 *dest8 = (u8 *)dest + 1;
217
218 expand8_col2mask(color, cval);
219
220 for (i = height; i; i--) {
221 fill8_col(dest8, cval);
222 dest8 += next_line;
223 }
224 dest += BPL / 2;
225 width -= 8;
226 }
227
228 expand16_col2mask(color, cval);
229 rows = width >> 4;
230 if (rows) {
231 u32 *d = dest;
232 u32 off = next_line - rows * BPL * 2;
233 for (i = height; i; i--) {
234 d = fill16_col(d, rows, cval);
235 d = (u32 *)((long)d + off);
236 }
237 dest += rows * BPL / 2;
238 width &= 15;
239 }
240
241 if (width) {
242 u8 *dest8 = (u8 *)dest;
243
244 expand8_col2mask(color, cval);
245
246 for (i = height; i; i--) {
247 fill8_col(dest8, cval);
248 dest8 += next_line;
249 }
250 }
251}
252
253void atafb_iplan2p4_linefill(struct fb_info *info, u_long next_line,
254 int dy, int dx, u32 width,
255 const u8 *data, u32 bgcolor, u32 fgcolor)
256{
257 u32 *dest;
258 const u16 *data16;
259 int rows;
260 u32 fgm[4], bgm[4], m;
261
262 dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
263 if (dx & 15) {
264 fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
265 dest += BPL / 2;
266 width -= 8;
267 }
268
269 if (width >= 16) {
270 data16 = (const u16 *)data;
271 expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
272
273 for (rows = width / 16; rows; rows--) {
274 u16 d = *data16++;
275 m = d | ((u32)d << 16);
276 *dest++ = (m & fgm[0]) ^ bgm[0];
277 *dest++ = (m & fgm[1]) ^ bgm[1];
278 }
279
280 data = (const u8 *)data16;
281 width &= 15;
282 }
283
284 if (width)
285 fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
286}
287
288#ifdef MODULE
289MODULE_LICENSE("GPL");
290
291int init_module(void)
292{
293 return 0;
294}
295
296void cleanup_module(void)
297{
298}
299#endif /* MODULE */
300
301
302 /*
303 * Visible symbols for modules
304 */
305
306EXPORT_SYMBOL(atafb_iplan2p4_copyarea);
307EXPORT_SYMBOL(atafb_iplan2p4_fillrect);
308EXPORT_SYMBOL(atafb_iplan2p4_linefill);
diff --git a/drivers/video/atafb_iplan2p8.c b/drivers/video/atafb_iplan2p8.c
new file mode 100644
index 000000000000..356fb52ce443
--- /dev/null
+++ b/drivers/video/atafb_iplan2p8.c
@@ -0,0 +1,345 @@
1/*
2 * linux/drivers/video/iplan2p8.c -- Low level frame buffer operations for
3 * interleaved bitplanes à la Atari (8
4 * planes, 2 bytes interleave)
5 *
6 * Created 5 Apr 1997 by Geert Uytterhoeven
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
10 * more details.
11 */
12
13#include <linux/module.h>
14#include <linux/string.h>
15#include <linux/fb.h>
16
17#include <asm/setup.h>
18
19#include "atafb.h"
20
21#define BPL 8
22#include "atafb_utils.h"
23
24
25/* Copies a 8 plane column from 's', height 'h', to 'd'. */
26
27/* This expands a 8 bit color into two longs for two movepl (8 plane)
28 * operations.
29 */
30
31void atafb_iplan2p8_copyarea(struct fb_info *info, u_long next_line,
32 int sy, int sx, int dy, int dx,
33 int height, int width)
34{
35 /* bmove() has to distinguish two major cases: If both, source and
36 * destination, start at even addresses or both are at odd
37 * addresses, just the first odd and last even column (if present)
38 * require special treatment (memmove_col()). The rest between
39 * then can be copied by normal operations, because all adjacent
40 * bytes are affected and are to be stored in the same order.
41 * The pathological case is when the move should go from an odd
42 * address to an even or vice versa. Since the bytes in the plane
43 * words must be assembled in new order, it seems wisest to make
44 * all movements by memmove_col().
45 */
46
47 u8 *src, *dst;
48 u32 *s, *d;
49 int w, l , i, j;
50 u_int colsize;
51 u_int upwards = (dy < sy) || (dy == sy && dx < sx);
52
53 colsize = height;
54 if (!((sx ^ dx) & 15)) {
55 /* odd->odd or even->even */
56
57 if (upwards) {
58 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
59 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
60 if (sx & 15) {
61 memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
62 src += BPL * 2;
63 dst += BPL * 2;
64 width -= 8;
65 }
66 w = width >> 4;
67 if (w) {
68 s = (u32 *)src;
69 d = (u32 *)dst;
70 w *= BPL / 2;
71 l = next_line - w * 4;
72 for (j = height; j > 0; j--) {
73 for (i = w; i > 0; i--)
74 *d++ = *s++;
75 s = (u32 *)((u8 *)s + l);
76 d = (u32 *)((u8 *)d + l);
77 }
78 }
79 if (width & 15)
80 memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
81 0xff00ff00, height, next_line - BPL * 2);
82 } else {
83 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
84 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
85
86 if ((sx + width) & 15) {
87 src -= BPL * 2;
88 dst -= BPL * 2;
89 memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
90 width -= 8;
91 }
92 w = width >> 4;
93 if (w) {
94 s = (u32 *)src;
95 d = (u32 *)dst;
96 w *= BPL / 2;
97 l = next_line - w * 4;
98 for (j = height; j > 0; j--) {
99 for (i = w; i > 0; i--)
100 *--d = *--s;
101 s = (u32 *)((u8 *)s - l);
102 d = (u32 *)((u8 *)d - l);
103 }
104 }
105 if (sx & 15)
106 memmove32_col(dst - (width - 16) / (8 / BPL),
107 src - (width - 16) / (8 / BPL),
108 0xff00ff, colsize, -next_line - BPL * 2);
109 }
110 } else {
111 /* odd->even or even->odd */
112 if (upwards) {
113 u32 *src32, *dst32;
114 u32 pval[4], v, v1, mask;
115 int i, j, w, f;
116
117 src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
118 dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
119
120 mask = 0xff00ff00;
121 f = 0;
122 w = width;
123 if (sx & 15) {
124 f = 1;
125 w += 8;
126 }
127 if ((sx + width) & 15)
128 f |= 2;
129 w >>= 4;
130 for (i = height; i; i--) {
131 src32 = (u32 *)src;
132 dst32 = (u32 *)dst;
133
134 if (f & 1) {
135 pval[0] = (*src32++ << 8) & mask;
136 pval[1] = (*src32++ << 8) & mask;
137 pval[2] = (*src32++ << 8) & mask;
138 pval[3] = (*src32++ << 8) & mask;
139 } else {
140 pval[0] = dst32[0] & mask;
141 pval[1] = dst32[1] & mask;
142 pval[2] = dst32[2] & mask;
143 pval[3] = dst32[3] & mask;
144 }
145
146 for (j = w; j > 0; j--) {
147 v = *src32++;
148 v1 = v & mask;
149 *dst32++ = pval[0] | (v1 >> 8);
150 pval[0] = (v ^ v1) << 8;
151 v = *src32++;
152 v1 = v & mask;
153 *dst32++ = pval[1] | (v1 >> 8);
154 pval[1] = (v ^ v1) << 8;
155 v = *src32++;
156 v1 = v & mask;
157 *dst32++ = pval[2] | (v1 >> 8);
158 pval[2] = (v ^ v1) << 8;
159 v = *src32++;
160 v1 = v & mask;
161 *dst32++ = pval[3] | (v1 >> 8);
162 pval[3] = (v ^ v1) << 8;
163 }
164
165 if (f & 2) {
166 dst32[0] = (dst32[0] & mask) | pval[0];
167 dst32[1] = (dst32[1] & mask) | pval[1];
168 dst32[2] = (dst32[2] & mask) | pval[2];
169 dst32[3] = (dst32[3] & mask) | pval[3];
170 }
171
172 src += next_line;
173 dst += next_line;
174 }
175 } else {
176 u32 *src32, *dst32;
177 u32 pval[4], v, v1, mask;
178 int i, j, w, f;
179
180 src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
181 dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
182
183 mask = 0xff00ff;
184 f = 0;
185 w = width;
186 if ((dx + width) & 15)
187 f = 1;
188 if (sx & 15) {
189 f |= 2;
190 w += 8;
191 }
192 w >>= 4;
193 for (i = height; i; i--) {
194 src32 = (u32 *)src;
195 dst32 = (u32 *)dst;
196
197 if (f & 1) {
198 pval[0] = dst32[-1] & mask;
199 pval[1] = dst32[-2] & mask;
200 pval[2] = dst32[-3] & mask;
201 pval[3] = dst32[-4] & mask;
202 } else {
203 pval[0] = (*--src32 >> 8) & mask;
204 pval[1] = (*--src32 >> 8) & mask;
205 pval[2] = (*--src32 >> 8) & mask;
206 pval[3] = (*--src32 >> 8) & mask;
207 }
208
209 for (j = w; j > 0; j--) {
210 v = *--src32;
211 v1 = v & mask;
212 *--dst32 = pval[0] | (v1 << 8);
213 pval[0] = (v ^ v1) >> 8;
214 v = *--src32;
215 v1 = v & mask;
216 *--dst32 = pval[1] | (v1 << 8);
217 pval[1] = (v ^ v1) >> 8;
218 v = *--src32;
219 v1 = v & mask;
220 *--dst32 = pval[2] | (v1 << 8);
221 pval[2] = (v ^ v1) >> 8;
222 v = *--src32;
223 v1 = v & mask;
224 *--dst32 = pval[3] | (v1 << 8);
225 pval[3] = (v ^ v1) >> 8;
226 }
227
228 if (!(f & 2)) {
229 dst32[-1] = (dst32[-1] & mask) | pval[0];
230 dst32[-2] = (dst32[-2] & mask) | pval[1];
231 dst32[-3] = (dst32[-3] & mask) | pval[2];
232 dst32[-4] = (dst32[-4] & mask) | pval[3];
233 }
234
235 src -= next_line;
236 dst -= next_line;
237 }
238 }
239 }
240}
241
242void atafb_iplan2p8_fillrect(struct fb_info *info, u_long next_line, u32 color,
243 int sy, int sx, int height, int width)
244{
245 u32 *dest;
246 int rows, i;
247 u32 cval[4];
248
249 dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
250 if (sx & 15) {
251 u8 *dest8 = (u8 *)dest + 1;
252
253 expand8_col2mask(color, cval);
254
255 for (i = height; i; i--) {
256 fill8_col(dest8, cval);
257 dest8 += next_line;
258 }
259 dest += BPL / 2;
260 width -= 8;
261 }
262
263 expand16_col2mask(color, cval);
264 rows = width >> 4;
265 if (rows) {
266 u32 *d = dest;
267 u32 off = next_line - rows * BPL * 2;
268 for (i = height; i; i--) {
269 d = fill16_col(d, rows, cval);
270 d = (u32 *)((long)d + off);
271 }
272 dest += rows * BPL / 2;
273 width &= 15;
274 }
275
276 if (width) {
277 u8 *dest8 = (u8 *)dest;
278
279 expand8_col2mask(color, cval);
280
281 for (i = height; i; i--) {
282 fill8_col(dest8, cval);
283 dest8 += next_line;
284 }
285 }
286}
287
288void atafb_iplan2p8_linefill(struct fb_info *info, u_long next_line,
289 int dy, int dx, u32 width,
290 const u8 *data, u32 bgcolor, u32 fgcolor)
291{
292 u32 *dest;
293 const u16 *data16;
294 int rows;
295 u32 fgm[4], bgm[4], m;
296
297 dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
298 if (dx & 15) {
299 fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
300 dest += BPL / 2;
301 width -= 8;
302 }
303
304 if (width >= 16) {
305 data16 = (const u16 *)data;
306 expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
307
308 for (rows = width / 16; rows; rows--) {
309 u16 d = *data16++;
310 m = d | ((u32)d << 16);
311 *dest++ = (m & fgm[0]) ^ bgm[0];
312 *dest++ = (m & fgm[1]) ^ bgm[1];
313 *dest++ = (m & fgm[2]) ^ bgm[2];
314 *dest++ = (m & fgm[3]) ^ bgm[3];
315 }
316
317 data = (const u8 *)data16;
318 width &= 15;
319 }
320
321 if (width)
322 fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
323}
324
325#ifdef MODULE
326MODULE_LICENSE("GPL");
327
328int init_module(void)
329{
330 return 0;
331}
332
333void cleanup_module(void)
334{
335}
336#endif /* MODULE */
337
338
339 /*
340 * Visible symbols for modules
341 */
342
343EXPORT_SYMBOL(atafb_iplan2p8_copyarea);
344EXPORT_SYMBOL(atafb_iplan2p8_fillrect);
345EXPORT_SYMBOL(atafb_iplan2p8_linefill);
diff --git a/drivers/video/atafb_mfb.c b/drivers/video/atafb_mfb.c
new file mode 100644
index 000000000000..6a352d62eecf
--- /dev/null
+++ b/drivers/video/atafb_mfb.c
@@ -0,0 +1,112 @@
1/*
2 * linux/drivers/video/mfb.c -- Low level frame buffer operations for
3 * monochrome
4 *
5 * Created 5 Apr 1997 by Geert Uytterhoeven
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
10 */
11
12#include <linux/module.h>
13#include <linux/string.h>
14#include <linux/fb.h>
15
16#include "atafb.h"
17#include "atafb_utils.h"
18
19
20 /*
21 * Monochrome
22 */
23
24void atafb_mfb_copyarea(struct fb_info *info, u_long next_line,
25 int sy, int sx, int dy, int dx,
26 int height, int width)
27{
28 u8 *src, *dest;
29 u_int rows;
30
31 if (sx == 0 && dx == 0 && width == next_line) {
32 src = (u8 *)info->screen_base + sy * (width >> 3);
33 dest = (u8 *)info->screen_base + dy * (width >> 3);
34 fb_memmove(dest, src, height * (width >> 3));
35 } else if (dy <= sy) {
36 src = (u8 *)info->screen_base + sy * next_line + (sx >> 3);
37 dest = (u8 *)info->screen_base + dy * next_line + (dx >> 3);
38 for (rows = height; rows--;) {
39 fb_memmove(dest, src, width >> 3);
40 src += next_line;
41 dest += next_line;
42 }
43 } else {
44 src = (u8 *)info->screen_base + (sy + height - 1) * next_line + (sx >> 3);
45 dest = (u8 *)info->screen_base + (dy + height - 1) * next_line + (dx >> 3);
46 for (rows = height; rows--;) {
47 fb_memmove(dest, src, width >> 3);
48 src -= next_line;
49 dest -= next_line;
50 }
51 }
52}
53
54void atafb_mfb_fillrect(struct fb_info *info, u_long next_line, u32 color,
55 int sy, int sx, int height, int width)
56{
57 u8 *dest;
58 u_int rows;
59
60 dest = (u8 *)info->screen_base + sy * next_line + (sx >> 3);
61
62 if (sx == 0 && width == next_line) {
63 if (color)
64 fb_memset255(dest, height * (width >> 3));
65 else
66 fb_memclear(dest, height * (width >> 3));
67 } else {
68 for (rows = height; rows--; dest += next_line) {
69 if (color)
70 fb_memset255(dest, width >> 3);
71 else
72 fb_memclear_small(dest, width >> 3);
73 }
74 }
75}
76
77void atafb_mfb_linefill(struct fb_info *info, u_long next_line,
78 int dy, int dx, u32 width,
79 const u8 *data, u32 bgcolor, u32 fgcolor)
80{
81 u8 *dest;
82 u_int rows;
83
84 dest = (u8 *)info->screen_base + dy * next_line + (dx >> 3);
85
86 for (rows = width / 8; rows--; /* check margins */ ) {
87 // use fast_memmove or fb_memmove
88 *dest++ = *data++;
89 }
90}
91
92#ifdef MODULE
93MODULE_LICENSE("GPL");
94
95int init_module(void)
96{
97 return 0;
98}
99
100void cleanup_module(void)
101{
102}
103#endif /* MODULE */
104
105
106 /*
107 * Visible symbols for modules
108 */
109
110EXPORT_SYMBOL(atafb_mfb_copyarea);
111EXPORT_SYMBOL(atafb_mfb_fillrect);
112EXPORT_SYMBOL(atafb_mfb_linefill);
diff --git a/drivers/video/atafb_utils.h b/drivers/video/atafb_utils.h
new file mode 100644
index 000000000000..ac9e19dc5057
--- /dev/null
+++ b/drivers/video/atafb_utils.h
@@ -0,0 +1,400 @@
1#ifndef _VIDEO_ATAFB_UTILS_H
2#define _VIDEO_ATAFB_UTILS_H
3
4/* ================================================================= */
5/* Utility Assembler Functions */
6/* ================================================================= */
7
8/* ====================================================================== */
9
10/* Those of a delicate disposition might like to skip the next couple of
11 * pages.
12 *
13 * These functions are drop in replacements for memmove and
14 * memset(_, 0, _). However their five instances add at least a kilobyte
15 * to the object file. You have been warned.
16 *
17 * Not a great fan of assembler for the sake of it, but I think
18 * that these routines are at least 10 times faster than their C
19 * equivalents for large blits, and that's important to the lowest level of
20 * a graphics driver. Question is whether some scheme with the blitter
21 * would be faster. I suspect not for simple text system - not much
22 * asynchrony.
23 *
24 * Code is very simple, just gruesome expansion. Basic strategy is to
25 * increase data moved/cleared at each step to 16 bytes to reduce
26 * instruction per data move overhead. movem might be faster still
27 * For more than 15 bytes, we try to align the write direction on a
28 * longword boundary to get maximum speed. This is even more gruesome.
29 * Unaligned read/write used requires 68020+ - think this is a problem?
30 *
31 * Sorry!
32 */
33
34
35/* ++roman: I've optimized Robert's original versions in some minor
36 * aspects, e.g. moveq instead of movel, let gcc choose the registers,
37 * use movem in some places...
38 * For other modes than 1 plane, lots of more such assembler functions
39 * were needed (e.g. the ones using movep or expanding color values).
40 */
41
42/* ++andreas: more optimizations:
43 subl #65536,d0 replaced by clrw d0; subql #1,d0 for dbcc
44 addal is faster than addaw
45 movep is rather expensive compared to ordinary move's
46 some functions rewritten in C for clarity, no speed loss */
47
48static inline void *fb_memclear_small(void *s, size_t count)
49{
50 if (!count)
51 return 0;
52
53 asm volatile ("\n"
54 " lsr.l #1,%1 ; jcc 1f ; move.b %2,-(%0)\n"
55 "1: lsr.l #1,%1 ; jcc 1f ; move.w %2,-(%0)\n"
56 "1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0)\n"
57 "1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0) ; move.l %2,-(%0)\n"
58 "1:"
59 : "=a" (s), "=d" (count)
60 : "d" (0), "0" ((char *)s + count), "1" (count));
61 asm volatile ("\n"
62 " subq.l #1,%1\n"
63 " jcs 3f\n"
64 " move.l %2,%%d4; move.l %2,%%d5; move.l %2,%%d6\n"
65 "2: movem.l %2/%%d4/%%d5/%%d6,-(%0)\n"
66 " dbra %1,2b\n"
67 "3:"
68 : "=a" (s), "=d" (count)
69 : "d" (0), "0" (s), "1" (count)
70 : "d4", "d5", "d6"
71 );
72
73 return 0;
74}
75
76
77static inline void *fb_memclear(void *s, size_t count)
78{
79 if (!count)
80 return 0;
81
82 if (count < 16) {
83 asm volatile ("\n"
84 " lsr.l #1,%1 ; jcc 1f ; clr.b (%0)+\n"
85 "1: lsr.l #1,%1 ; jcc 1f ; clr.w (%0)+\n"
86 "1: lsr.l #1,%1 ; jcc 1f ; clr.l (%0)+\n"
87 "1: lsr.l #1,%1 ; jcc 1f ; clr.l (%0)+ ; clr.l (%0)+\n"
88 "1:"
89 : "=a" (s), "=d" (count)
90 : "0" (s), "1" (count));
91 } else {
92 long tmp;
93 asm volatile ("\n"
94 " move.l %1,%2\n"
95 " lsr.l #1,%2 ; jcc 1f ; clr.b (%0)+ ; subq.w #1,%1\n"
96 " lsr.l #1,%2 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
97 " clr.w (%0)+ ; subq.w #2,%1 ; jra 2f\n"
98 "1: lsr.l #1,%2 ; jcc 2f\n"
99 " clr.w (%0)+ ; subq.w #2,%1\n"
100 "2: move.w %1,%2; lsr.l #2,%1 ; jeq 6f\n"
101 " lsr.l #1,%1 ; jcc 3f ; clr.l (%0)+\n"
102 "3: lsr.l #1,%1 ; jcc 4f ; clr.l (%0)+ ; clr.l (%0)+\n"
103 "4: subq.l #1,%1 ; jcs 6f\n"
104 "5: clr.l (%0)+; clr.l (%0)+ ; clr.l (%0)+ ; clr.l (%0)+\n"
105 " dbra %1,5b ; clr.w %1; subq.l #1,%1; jcc 5b\n"
106 "6: move.w %2,%1; btst #1,%1 ; jeq 7f ; clr.w (%0)+\n"
107 "7: btst #0,%1 ; jeq 8f ; clr.b (%0)+\n"
108 "8:"
109 : "=a" (s), "=d" (count), "=d" (tmp)
110 : "0" (s), "1" (count));
111 }
112
113 return 0;
114}
115
116
117static inline void *fb_memset255(void *s, size_t count)
118{
119 if (!count)
120 return 0;
121
122 asm volatile ("\n"
123 " lsr.l #1,%1 ; jcc 1f ; move.b %2,-(%0)\n"
124 "1: lsr.l #1,%1 ; jcc 1f ; move.w %2,-(%0)\n"
125 "1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0)\n"
126 "1: lsr.l #1,%1 ; jcc 1f ; move.l %2,-(%0) ; move.l %2,-(%0)\n"
127 "1:"
128 : "=a" (s), "=d" (count)
129 : "d" (-1), "0" ((char *)s+count), "1" (count));
130 asm volatile ("\n"
131 " subq.l #1,%1 ; jcs 3f\n"
132 " move.l %2,%%d4; move.l %2,%%d5; move.l %2,%%d6\n"
133 "2: movem.l %2/%%d4/%%d5/%%d6,-(%0)\n"
134 " dbra %1,2b\n"
135 "3:"
136 : "=a" (s), "=d" (count)
137 : "d" (-1), "0" (s), "1" (count)
138 : "d4", "d5", "d6");
139
140 return 0;
141}
142
143
144static inline void *fb_memmove(void *d, const void *s, size_t count)
145{
146 if (d < s) {
147 if (count < 16) {
148 asm volatile ("\n"
149 " lsr.l #1,%2 ; jcc 1f ; move.b (%1)+,(%0)+\n"
150 "1: lsr.l #1,%2 ; jcc 1f ; move.w (%1)+,(%0)+\n"
151 "1: lsr.l #1,%2 ; jcc 1f ; move.l (%1)+,(%0)+\n"
152 "1: lsr.l #1,%2 ; jcc 1f ; move.l (%1)+,(%0)+ ; move.l (%1)+,(%0)+\n"
153 "1:"
154 : "=a" (d), "=a" (s), "=d" (count)
155 : "0" (d), "1" (s), "2" (count));
156 } else {
157 long tmp;
158 asm volatile ("\n"
159 " move.l %0,%3\n"
160 " lsr.l #1,%3 ; jcc 1f ; move.b (%1)+,(%0)+ ; subqw #1,%2\n"
161 " lsr.l #1,%3 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
162 " move.w (%1)+,(%0)+ ; subqw #2,%2 ; jra 2f\n"
163 "1: lsr.l #1,%3 ; jcc 2f\n"
164 " move.w (%1)+,(%0)+ ; subqw #2,%2\n"
165 "2: move.w %2,%-; lsr.l #2,%2 ; jeq 6f\n"
166 " lsr.l #1,%2 ; jcc 3f ; move.l (%1)+,(%0)+\n"
167 "3: lsr.l #1,%2 ; jcc 4f ; move.l (%1)+,(%0)+ ; move.l (%1)+,(%0)+\n"
168 "4: subq.l #1,%2 ; jcs 6f\n"
169 "5: move.l (%1)+,(%0)+; move.l (%1)+,(%0)+\n"
170 " move.l (%1)+,(%0)+; move.l (%1)+,(%0)+\n"
171 " dbra %2,5b ; clr.w %2; subq.l #1,%2; jcc 5b\n"
172 "6: move.w %+,%2; btst #1,%2 ; jeq 7f ; move.w (%1)+,(%0)+\n"
173 "7: btst #0,%2 ; jeq 8f ; move.b (%1)+,(%0)+\n"
174 "8:"
175 : "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
176 : "0" (d), "1" (s), "2" (count));
177 }
178 } else {
179 if (count < 16) {
180 asm volatile ("\n"
181 " lsr.l #1,%2 ; jcc 1f ; move.b -(%1),-(%0)\n"
182 "1: lsr.l #1,%2 ; jcc 1f ; move.w -(%1),-(%0)\n"
183 "1: lsr.l #1,%2 ; jcc 1f ; move.l -(%1),-(%0)\n"
184 "1: lsr.l #1,%2 ; jcc 1f ; move.l -(%1),-(%0) ; move.l -(%1),-(%0)\n"
185 "1:"
186 : "=a" (d), "=a" (s), "=d" (count)
187 : "0" ((char *) d + count), "1" ((char *) s + count), "2" (count));
188 } else {
189 long tmp;
190
191 asm volatile ("\n"
192 " move.l %0,%3\n"
193 " lsr.l #1,%3 ; jcc 1f ; move.b -(%1),-(%0) ; subqw #1,%2\n"
194 " lsr.l #1,%3 ; jcs 2f\n" /* %0 increased=>bit 2 switched*/
195 " move.w -(%1),-(%0) ; subqw #2,%2 ; jra 2f\n"
196 "1: lsr.l #1,%3 ; jcc 2f\n"
197 " move.w -(%1),-(%0) ; subqw #2,%2\n"
198 "2: move.w %2,%-; lsr.l #2,%2 ; jeq 6f\n"
199 " lsr.l #1,%2 ; jcc 3f ; move.l -(%1),-(%0)\n"
200 "3: lsr.l #1,%2 ; jcc 4f ; move.l -(%1),-(%0) ; move.l -(%1),-(%0)\n"
201 "4: subq.l #1,%2 ; jcs 6f\n"
202 "5: move.l -(%1),-(%0); move.l -(%1),-(%0)\n"
203 " move.l -(%1),-(%0); move.l -(%1),-(%0)\n"
204 " dbra %2,5b ; clr.w %2; subq.l #1,%2; jcc 5b\n"
205 "6: move.w %+,%2; btst #1,%2 ; jeq 7f ; move.w -(%1),-(%0)\n"
206 "7: btst #0,%2 ; jeq 8f ; move.b -(%1),-(%0)\n"
207 "8:"
208 : "=a" (d), "=a" (s), "=d" (count), "=d" (tmp)
209 : "0" ((char *) d + count), "1" ((char *) s + count), "2" (count));
210 }
211 }
212
213 return 0;
214}
215
216
217/* ++andreas: Simple and fast version of memmove, assumes size is
218 divisible by 16, suitable for moving the whole screen bitplane */
219static inline void fast_memmove(char *dst, const char *src, size_t size)
220{
221 if (!size)
222 return;
223 if (dst < src)
224 asm volatile ("\n"
225 "1: movem.l (%0)+,%%d0/%%d1/%%a0/%%a1\n"
226 " movem.l %%d0/%%d1/%%a0/%%a1,%1@\n"
227 " addq.l #8,%1; addq.l #8,%1\n"
228 " dbra %2,1b\n"
229 " clr.w %2; subq.l #1,%2\n"
230 " jcc 1b"
231 : "=a" (src), "=a" (dst), "=d" (size)
232 : "0" (src), "1" (dst), "2" (size / 16 - 1)
233 : "d0", "d1", "a0", "a1", "memory");
234 else
235 asm volatile ("\n"
236 "1: subq.l #8,%0; subq.l #8,%0\n"
237 " movem.l %0@,%%d0/%%d1/%%a0/%%a1\n"
238 " movem.l %%d0/%%d1/%%a0/%%a1,-(%1)\n"
239 " dbra %2,1b\n"
240 " clr.w %2; subq.l #1,%2\n"
241 " jcc 1b"
242 : "=a" (src), "=a" (dst), "=d" (size)
243 : "0" (src + size), "1" (dst + size), "2" (size / 16 - 1)
244 : "d0", "d1", "a0", "a1", "memory");
245}
246
247#ifdef BPL
248
249/*
250 * This expands a up to 8 bit color into two longs
251 * for movel operations.
252 */
253static const u32 four2long[] = {
254 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
255 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
256 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
257 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff,
258};
259
260static inline void expand8_col2mask(u8 c, u32 m[])
261{
262 m[0] = four2long[c & 15];
263#if BPL > 4
264 m[1] = four2long[c >> 4];
265#endif
266}
267
268static inline void expand8_2col2mask(u8 fg, u8 bg, u32 fgm[], u32 bgm[])
269{
270 fgm[0] = four2long[fg & 15] ^ (bgm[0] = four2long[bg & 15]);
271#if BPL > 4
272 fgm[1] = four2long[fg >> 4] ^ (bgm[1] = four2long[bg >> 4]);
273#endif
274}
275
276/*
277 * set an 8bit value to a color
278 */
279static inline void fill8_col(u8 *dst, u32 m[])
280{
281 u32 tmp = m[0];
282 dst[0] = tmp;
283 dst[2] = (tmp >>= 8);
284#if BPL > 2
285 dst[4] = (tmp >>= 8);
286 dst[6] = tmp >> 8;
287#endif
288#if BPL > 4
289 tmp = m[1];
290 dst[8] = tmp;
291 dst[10] = (tmp >>= 8);
292 dst[12] = (tmp >>= 8);
293 dst[14] = tmp >> 8;
294#endif
295}
296
297/*
298 * set an 8bit value according to foreground/background color
299 */
300static inline void fill8_2col(u8 *dst, u8 fg, u8 bg, u32 mask)
301{
302 u32 fgm[2], bgm[2], tmp;
303
304 expand8_2col2mask(fg, bg, fgm, bgm);
305
306 mask |= mask << 8;
307#if BPL > 2
308 mask |= mask << 16;
309#endif
310 tmp = (mask & fgm[0]) ^ bgm[0];
311 dst[0] = tmp;
312 dst[2] = (tmp >>= 8);
313#if BPL > 2
314 dst[4] = (tmp >>= 8);
315 dst[6] = tmp >> 8;
316#endif
317#if BPL > 4
318 tmp = (mask & fgm[1]) ^ bgm[1];
319 dst[8] = tmp;
320 dst[10] = (tmp >>= 8);
321 dst[12] = (tmp >>= 8);
322 dst[14] = tmp >> 8;
323#endif
324}
325
326static const u32 two2word[] = {
327 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
328};
329
330static inline void expand16_col2mask(u8 c, u32 m[])
331{
332 m[0] = two2word[c & 3];
333#if BPL > 2
334 m[1] = two2word[(c >> 2) & 3];
335#endif
336#if BPL > 4
337 m[2] = two2word[(c >> 4) & 3];
338 m[3] = two2word[c >> 6];
339#endif
340}
341
342static inline void expand16_2col2mask(u8 fg, u8 bg, u32 fgm[], u32 bgm[])
343{
344 bgm[0] = two2word[bg & 3];
345 fgm[0] = two2word[fg & 3] ^ bgm[0];
346#if BPL > 2
347 bgm[1] = two2word[(bg >> 2) & 3];
348 fgm[1] = two2word[(fg >> 2) & 3] ^ bgm[1];
349#endif
350#if BPL > 4
351 bgm[2] = two2word[(bg >> 4) & 3];
352 fgm[2] = two2word[(fg >> 4) & 3] ^ bgm[2];
353 bgm[3] = two2word[bg >> 6];
354 fgm[3] = two2word[fg >> 6] ^ bgm[3];
355#endif
356}
357
358static inline u32 *fill16_col(u32 *dst, int rows, u32 m[])
359{
360 while (rows) {
361 *dst++ = m[0];
362#if BPL > 2
363 *dst++ = m[1];
364#endif
365#if BPL > 4
366 *dst++ = m[2];
367 *dst++ = m[3];
368#endif
369 rows--;
370 }
371 return dst;
372}
373
374static inline void memmove32_col(void *dst, void *src, u32 mask, u32 h, u32 bytes)
375{
376 u32 *s, *d, v;
377
378 s = src;
379 d = dst;
380 do {
381 v = (*s++ & mask) | (*d & ~mask);
382 *d++ = v;
383#if BPL > 2
384 v = (*s++ & mask) | (*d & ~mask);
385 *d++ = v;
386#endif
387#if BPL > 4
388 v = (*s++ & mask) | (*d & ~mask);
389 *d++ = v;
390 v = (*s++ & mask) | (*d & ~mask);
391 *d++ = v;
392#endif
393 d = (u32 *)((u8 *)d + bytes);
394 s = (u32 *)((u8 *)s + bytes);
395 } while (--h);
396}
397
398#endif
399
400#endif /* _VIDEO_ATAFB_UTILS_H */
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c
index f4ede5f6b588..61e4c8759b23 100644
--- a/drivers/video/intelfb/intelfb_i2c.c
+++ b/drivers/video/intelfb/intelfb_i2c.c
@@ -104,7 +104,8 @@ static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo,
104 104
105 chan->dinfo = dinfo; 105 chan->dinfo = dinfo;
106 chan->reg = reg; 106 chan->reg = reg;
107 snprintf(chan->adapter.name, I2C_NAME_SIZE, "intelfb %s", name); 107 snprintf(chan->adapter.name, sizeof(chan->adapter.name),
108 "intelfb %s", name);
108 chan->adapter.owner = THIS_MODULE; 109 chan->adapter.owner = THIS_MODULE;
109 chan->adapter.id = I2C_HW_B_INTELFB; 110 chan->adapter.id = I2C_HW_B_INTELFB;
110 chan->adapter.algo_data = &chan->algo; 111 chan->adapter.algo_data = &chan->algo;
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 5ec718a5fe22..4baab7be58de 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -111,7 +111,7 @@ static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
111 b->mask.data = data; 111 b->mask.data = data;
112 b->mask.clock = clock; 112 b->mask.clock = clock;
113 b->adapter = matrox_i2c_adapter_template; 113 b->adapter = matrox_i2c_adapter_template;
114 snprintf(b->adapter.name, I2C_NAME_SIZE, name, 114 snprintf(b->adapter.name, sizeof(b->adapter.name), name,
115 minfo->fbcon.node); 115 minfo->fbcon.node);
116 i2c_set_adapdata(&b->adapter, b); 116 i2c_set_adapdata(&b->adapter, b);
117 b->adapter.algo_data = &b->bac; 117 b->adapter.algo_data = &b->bac;
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index 81e43cda7d8b..07d1979bc23e 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -32,6 +32,8 @@
32#include <linux/ioctl.h> 32#include <linux/ioctl.h>
33#include <linux/notifier.h> 33#include <linux/notifier.h>
34#include <linux/reboot.h> 34#include <linux/reboot.h>
35#include <linux/kthread.h>
36#include <linux/freezer.h>
35 37
36#include <asm/uaccess.h> 38#include <asm/uaccess.h>
37#include <linux/fb.h> 39#include <linux/fb.h>
@@ -45,7 +47,7 @@
45#include <asm/ps3.h> 47#include <asm/ps3.h>
46 48
47#ifdef PS3FB_DEBUG 49#ifdef PS3FB_DEBUG
48#define DPRINTK(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ##args) 50#define DPRINTK(fmt, args...) printk("%s: " fmt, __func__ , ##args)
49#else 51#else
50#define DPRINTK(fmt, args...) 52#define DPRINTK(fmt, args...)
51#endif 53#endif
@@ -129,7 +131,6 @@ struct ps3fb_priv {
129 u64 context_handle, memory_handle; 131 u64 context_handle, memory_handle;
130 void *xdr_ea; 132 void *xdr_ea;
131 struct gpu_driver_info *dinfo; 133 struct gpu_driver_info *dinfo;
132 struct semaphore sem;
133 u32 res_index; 134 u32 res_index;
134 135
135 u64 vblank_count; /* frame count */ 136 u64 vblank_count; /* frame count */
@@ -139,6 +140,8 @@ struct ps3fb_priv {
139 atomic_t ext_flip; /* on/off flip with vsync */ 140 atomic_t ext_flip; /* on/off flip with vsync */
140 atomic_t f_count; /* fb_open count */ 141 atomic_t f_count; /* fb_open count */
141 int is_blanked; 142 int is_blanked;
143 int is_kicked;
144 struct task_struct *task;
142}; 145};
143static struct ps3fb_priv ps3fb; 146static struct ps3fb_priv ps3fb;
144 147
@@ -294,10 +297,10 @@ static const struct fb_videomode ps3fb_modedb[] = {
294#define VP_OFF(i) (WIDTH(i) * Y_OFF(i) * BPP + X_OFF(i) * BPP) 297#define VP_OFF(i) (WIDTH(i) * Y_OFF(i) * BPP + X_OFF(i) * BPP)
295#define FB_OFF(i) (GPU_OFFSET - VP_OFF(i) % GPU_OFFSET) 298#define FB_OFF(i) (GPU_OFFSET - VP_OFF(i) % GPU_OFFSET)
296 299
297static int ps3fb_mode = 0; 300static int ps3fb_mode;
298module_param(ps3fb_mode, bool, 0); 301module_param(ps3fb_mode, bool, 0);
299 302
300static char *mode_option __initdata = NULL; 303static char *mode_option __initdata;
301 304
302 305
303static int ps3fb_get_res_table(u32 xres, u32 yres) 306static int ps3fb_get_res_table(u32 xres, u32 yres)
@@ -393,7 +396,7 @@ static int ps3fb_sync(u32 frame)
393 396
394 if (frame > ps3fb.num_frames - 1) { 397 if (frame > ps3fb.num_frames - 1) {
395 printk(KERN_WARNING "%s: invalid frame number (%u)\n", 398 printk(KERN_WARNING "%s: invalid frame number (%u)\n",
396 __FUNCTION__, frame); 399 __func__, frame);
397 return -EINVAL; 400 return -EINVAL;
398 } 401 }
399 offset = xres * yres * BPP * frame; 402 offset = xres * yres * BPP * frame;
@@ -406,23 +409,26 @@ static int ps3fb_sync(u32 frame)
406 (xres << 16) | yres, 409 (xres << 16) | yres,
407 xres * BPP); /* line_length */ 410 xres * BPP); /* line_length */
408 if (status) 411 if (status)
409 printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n", 412 printk(KERN_ERR
410 __FUNCTION__, status); 413 "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
414 __func__, status);
411#ifdef HEAD_A 415#ifdef HEAD_A
412 status = lv1_gpu_context_attribute(ps3fb.context_handle, 416 status = lv1_gpu_context_attribute(ps3fb.context_handle,
413 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 417 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
414 0, offset, 0, 0); 418 0, offset, 0, 0);
415 if (status) 419 if (status)
416 printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n", 420 printk(KERN_ERR
417 __FUNCTION__, status); 421 "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
422 __func__, status);
418#endif 423#endif
419#ifdef HEAD_B 424#ifdef HEAD_B
420 status = lv1_gpu_context_attribute(ps3fb.context_handle, 425 status = lv1_gpu_context_attribute(ps3fb.context_handle,
421 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 426 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
422 1, offset, 0, 0); 427 1, offset, 0, 0);
423 if (status) 428 if (status)
424 printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n", 429 printk(KERN_ERR
425 __FUNCTION__, status); 430 "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
431 __func__, status);
426#endif 432#endif
427 return 0; 433 return 0;
428} 434}
@@ -631,7 +637,7 @@ static int ps3fb_blank(int blank, struct fb_info *info)
631{ 637{
632 int retval; 638 int retval;
633 639
634 DPRINTK("%s: blank:%d\n", __FUNCTION__, blank); 640 DPRINTK("%s: blank:%d\n", __func__, blank);
635 switch (blank) { 641 switch (blank) {
636 case FB_BLANK_POWERDOWN: 642 case FB_BLANK_POWERDOWN:
637 case FB_BLANK_HSYNC_SUSPEND: 643 case FB_BLANK_HSYNC_SUSPEND:
@@ -677,13 +683,10 @@ EXPORT_SYMBOL_GPL(ps3fb_wait_for_vsync);
677 683
678void ps3fb_flip_ctl(int on) 684void ps3fb_flip_ctl(int on)
679{ 685{
680 if (on) { 686 if (on)
681 if (atomic_read(&ps3fb.ext_flip) > 0) { 687 atomic_dec_if_positive(&ps3fb.ext_flip);
682 atomic_dec(&ps3fb.ext_flip); 688 else
683 }
684 } else {
685 atomic_inc(&ps3fb.ext_flip); 689 atomic_inc(&ps3fb.ext_flip);
686 }
687} 690}
688 691
689EXPORT_SYMBOL_GPL(ps3fb_flip_ctl); 692EXPORT_SYMBOL_GPL(ps3fb_flip_ctl);
@@ -732,6 +735,11 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
732 if (copy_from_user(&val, argp, sizeof(val))) 735 if (copy_from_user(&val, argp, sizeof(val)))
733 break; 736 break;
734 737
738 if (!(val & PS3AV_MODE_MASK)) {
739 u32 id = ps3av_get_auto_mode(0);
740 if (id > 0)
741 val = (val & ~PS3AV_MODE_MASK) | id;
742 }
735 DPRINTK("PS3FB_IOCTL_SETMODE:%x\n", val); 743 DPRINTK("PS3FB_IOCTL_SETMODE:%x\n", val);
736 retval = -EINVAL; 744 retval = -EINVAL;
737 old_mode = ps3fb_mode; 745 old_mode = ps3fb_mode;
@@ -783,8 +791,7 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
783 791
784 case PS3FB_IOCTL_OFF: 792 case PS3FB_IOCTL_OFF:
785 DPRINTK("PS3FB_IOCTL_OFF:\n"); 793 DPRINTK("PS3FB_IOCTL_OFF:\n");
786 if (atomic_read(&ps3fb.ext_flip) > 0) 794 atomic_dec_if_positive(&ps3fb.ext_flip);
787 atomic_dec(&ps3fb.ext_flip);
788 retval = 0; 795 retval = 0;
789 break; 796 break;
790 797
@@ -805,11 +812,14 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
805 812
806static int ps3fbd(void *arg) 813static int ps3fbd(void *arg)
807{ 814{
808 daemonize("ps3fbd"); 815 while (!kthread_should_stop()) {
809 for (;;) { 816 try_to_freeze();
810 down(&ps3fb.sem); 817 set_current_state(TASK_INTERRUPTIBLE);
811 if (atomic_read(&ps3fb.ext_flip) == 0) 818 if (ps3fb.is_kicked) {
819 ps3fb.is_kicked = 0;
812 ps3fb_sync(0); /* single buffer */ 820 ps3fb_sync(0); /* single buffer */
821 }
822 schedule();
813 } 823 }
814 return 0; 824 return 0;
815} 825}
@@ -823,15 +833,18 @@ static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
823 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1); 833 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
824 if (status) { 834 if (status) {
825 printk(KERN_ERR "%s: lv1_gpu_context_intr failed: %d\n", 835 printk(KERN_ERR "%s: lv1_gpu_context_intr failed: %d\n",
826 __FUNCTION__, status); 836 __func__, status);
827 return IRQ_NONE; 837 return IRQ_NONE;
828 } 838 }
829 839
830 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) { 840 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
831 /* VSYNC */ 841 /* VSYNC */
832 ps3fb.vblank_count = head->vblank_count; 842 ps3fb.vblank_count = head->vblank_count;
833 if (!ps3fb.is_blanked) 843 if (ps3fb.task && !ps3fb.is_blanked &&
834 up(&ps3fb.sem); 844 !atomic_read(&ps3fb.ext_flip)) {
845 ps3fb.is_kicked = 1;
846 wake_up_process(ps3fb.task);
847 }
835 wake_up_interruptible(&ps3fb.wait_vsync); 848 wake_up_interruptible(&ps3fb.wait_vsync);
836 } 849 }
837 850
@@ -879,7 +892,7 @@ static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
879 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000); 892 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
880 893
881 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) { 894 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
882 printk(KERN_ERR "%s: version_driver err:%x\n", __FUNCTION__, 895 printk(KERN_ERR "%s: version_driver err:%x\n", __func__,
883 dinfo->version_driver); 896 dinfo->version_driver);
884 return -EINVAL; 897 return -EINVAL;
885 } 898 }
@@ -888,7 +901,7 @@ static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
888 error = ps3_alloc_irq(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet, 901 error = ps3_alloc_irq(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
889 &ps3fb.irq_no); 902 &ps3fb.irq_no);
890 if (error) { 903 if (error) {
891 printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __FUNCTION__, 904 printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __func__,
892 error); 905 error);
893 return error; 906 return error;
894 } 907 }
@@ -896,7 +909,7 @@ static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
896 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED, 909 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
897 "ps3fb vsync", ps3fb.dev); 910 "ps3fb vsync", ps3fb.dev);
898 if (error) { 911 if (error) {
899 printk(KERN_ERR "%s: request_irq failed %d\n", __FUNCTION__, 912 printk(KERN_ERR "%s: request_irq failed %d\n", __func__,
900 error); 913 error);
901 ps3_free_irq(ps3fb.irq_no); 914 ps3_free_irq(ps3fb.irq_no);
902 return error; 915 return error;
@@ -915,7 +928,7 @@ static int ps3fb_xdr_settings(u64 xdr_lpar)
915 xdr_lpar, ps3fb_videomemory.size, 0); 928 xdr_lpar, ps3fb_videomemory.size, 0);
916 if (status) { 929 if (status) {
917 printk(KERN_ERR "%s: lv1_gpu_context_iomap failed: %d\n", 930 printk(KERN_ERR "%s: lv1_gpu_context_iomap failed: %d\n",
918 __FUNCTION__, status); 931 __func__, status);
919 return -ENXIO; 932 return -ENXIO;
920 } 933 }
921 DPRINTK("video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n", 934 DPRINTK("video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
@@ -927,8 +940,9 @@ static int ps3fb_xdr_settings(u64 xdr_lpar)
927 xdr_lpar, ps3fb_videomemory.size, 940 xdr_lpar, ps3fb_videomemory.size,
928 GPU_IOIF, 0); 941 GPU_IOIF, 0);
929 if (status) { 942 if (status) {
930 printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n", 943 printk(KERN_ERR
931 __FUNCTION__, status); 944 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
945 __func__, status);
932 return -ENXIO; 946 return -ENXIO;
933 } 947 }
934 return 0; 948 return 0;
@@ -968,13 +982,14 @@ static int __init ps3fb_probe(struct platform_device *dev)
968 u64 xdr_lpar; 982 u64 xdr_lpar;
969 int status; 983 int status;
970 unsigned long offset; 984 unsigned long offset;
985 struct task_struct *task;
971 986
972 /* get gpu context handle */ 987 /* get gpu context handle */
973 status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0, 988 status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
974 &ps3fb.memory_handle, &ddr_lpar); 989 &ps3fb.memory_handle, &ddr_lpar);
975 if (status) { 990 if (status) {
976 printk(KERN_ERR "%s: lv1_gpu_memory_allocate failed: %d\n", 991 printk(KERN_ERR "%s: lv1_gpu_memory_allocate failed: %d\n",
977 __FUNCTION__, status); 992 __func__, status);
978 goto err; 993 goto err;
979 } 994 }
980 DPRINTK("ddr:lpar:0x%lx\n", ddr_lpar); 995 DPRINTK("ddr:lpar:0x%lx\n", ddr_lpar);
@@ -985,14 +1000,14 @@ static int __init ps3fb_probe(struct platform_device *dev)
985 &lpar_reports, &lpar_reports_size); 1000 &lpar_reports, &lpar_reports_size);
986 if (status) { 1001 if (status) {
987 printk(KERN_ERR "%s: lv1_gpu_context_attribute failed: %d\n", 1002 printk(KERN_ERR "%s: lv1_gpu_context_attribute failed: %d\n",
988 __FUNCTION__, status); 1003 __func__, status);
989 goto err_gpu_memory_free; 1004 goto err_gpu_memory_free;
990 } 1005 }
991 1006
992 /* vsync interrupt */ 1007 /* vsync interrupt */
993 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024); 1008 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
994 if (!ps3fb.dinfo) { 1009 if (!ps3fb.dinfo) {
995 printk(KERN_ERR "%s: ioremap failed\n", __FUNCTION__); 1010 printk(KERN_ERR "%s: ioremap failed\n", __func__);
996 goto err_gpu_context_free; 1011 goto err_gpu_context_free;
997 } 1012 }
998 1013
@@ -1050,9 +1065,18 @@ static int __init ps3fb_probe(struct platform_device *dev)
1050 "fb%d: PS3 frame buffer device, using %ld KiB of video memory\n", 1065 "fb%d: PS3 frame buffer device, using %ld KiB of video memory\n",
1051 info->node, ps3fb_videomemory.size >> 10); 1066 info->node, ps3fb_videomemory.size >> 10);
1052 1067
1053 kernel_thread(ps3fbd, info, CLONE_KERNEL); 1068 task = kthread_run(ps3fbd, info, "ps3fbd");
1069 if (IS_ERR(task)) {
1070 retval = PTR_ERR(task);
1071 goto err_unregister_framebuffer;
1072 }
1073
1074 ps3fb.task = task;
1075
1054 return 0; 1076 return 0;
1055 1077
1078err_unregister_framebuffer:
1079 unregister_framebuffer(info);
1056err_fb_dealloc: 1080err_fb_dealloc:
1057 fb_dealloc_cmap(&info->cmap); 1081 fb_dealloc_cmap(&info->cmap);
1058err_framebuffer_release: 1082err_framebuffer_release:
@@ -1083,6 +1107,11 @@ void ps3fb_cleanup(void)
1083{ 1107{
1084 int status; 1108 int status;
1085 1109
1110 if (ps3fb.task) {
1111 struct task_struct *task = ps3fb.task;
1112 ps3fb.task = NULL;
1113 kthread_stop(task);
1114 }
1086 if (ps3fb.irq_no) { 1115 if (ps3fb.irq_no) {
1087 free_irq(ps3fb.irq_no, ps3fb.dev); 1116 free_irq(ps3fb.irq_no, ps3fb.dev);
1088 ps3_free_irq(ps3fb.irq_no); 1117 ps3_free_irq(ps3fb.irq_no);
@@ -1137,8 +1166,9 @@ int ps3fb_set_sync(void)
1137 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC, 1166 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1138 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0); 1167 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1139 if (status) { 1168 if (status) {
1140 printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: %d\n", 1169 printk(KERN_ERR
1141 __FUNCTION__, status); 1170 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: %d\n",
1171 __func__, status);
1142 return -1; 1172 return -1;
1143 } 1173 }
1144#endif 1174#endif
@@ -1148,8 +1178,9 @@ int ps3fb_set_sync(void)
1148 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0); 1178 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1149 1179
1150 if (status) { 1180 if (status) {
1151 printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_MODE failed: %d\n", 1181 printk(KERN_ERR
1152 __FUNCTION__, status); 1182 "%s: lv1_gpu_context_attribute DISPLAY_MODE failed: %d\n",
1183 __func__, status);
1153 return -1; 1184 return -1;
1154 } 1185 }
1155#endif 1186#endif
@@ -1174,7 +1205,7 @@ static int __init ps3fb_init(void)
1174 1205
1175 error = ps3av_dev_open(); 1206 error = ps3av_dev_open();
1176 if (error) { 1207 if (error) {
1177 printk(KERN_ERR "%s: ps3av_dev_open failed\n", __FUNCTION__); 1208 printk(KERN_ERR "%s: ps3av_dev_open failed\n", __func__);
1178 goto err; 1209 goto err;
1179 } 1210 }
1180 1211
@@ -1195,7 +1226,6 @@ static int __init ps3fb_init(void)
1195 1226
1196 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */ 1227 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1197 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */ 1228 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1198 init_MUTEX(&ps3fb.sem);
1199 init_waitqueue_head(&ps3fb.wait_vsync); 1229 init_waitqueue_head(&ps3fb.wait_vsync);
1200 ps3fb.num_frames = 1; 1230 ps3fb.num_frames = 1;
1201 1231
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index b3ce8859a586..2ce4cebc31d9 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -90,8 +90,9 @@ get_zorro_dev_info(char *buf, char **start, off_t pos, int count)
90 for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) { 90 for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
91 struct zorro_dev *z = &zorro_autocon[slot]; 91 struct zorro_dev *z = &zorro_autocon[slot];
92 len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, 92 len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot,
93 z->id, zorro_resource_start(z), 93 z->id, (unsigned long)zorro_resource_start(z),
94 zorro_resource_len(z), z->rom.er_Type); 94 (unsigned long)zorro_resource_len(z),
95 z->rom.er_Type);
95 at += len; 96 at += len;
96 if (at >= pos) { 97 if (at >= pos) {
97 if (!*start) { 98 if (!*start) {
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c
index 87c29d7b6c17..c3ba0ec334c4 100644
--- a/drivers/zorro/zorro-sysfs.c
+++ b/drivers/zorro/zorro-sysfs.c
@@ -42,7 +42,8 @@ static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *
42 struct zorro_dev *z = to_zorro_dev(dev); 42 struct zorro_dev *z = to_zorro_dev(dev);
43 43
44 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n", 44 return sprintf(buf, "0x%08lx 0x%08lx 0x%08lx\n",
45 zorro_resource_start(z), zorro_resource_end(z), 45 (unsigned long)zorro_resource_start(z),
46 (unsigned long)zorro_resource_end(z),
46 zorro_resource_flags(z)); 47 zorro_resource_flags(z));
47} 48}
48 49
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c
index 0f2b40605b06..4cc42b64820c 100644
--- a/drivers/zorro/zorro.c
+++ b/drivers/zorro/zorro.c
@@ -164,7 +164,8 @@ static int __init zorro_init(void)
164 if (request_resource(zorro_find_parent_resource(z), &z->resource)) 164 if (request_resource(zorro_find_parent_resource(z), &z->resource))
165 printk(KERN_ERR "Zorro: Address space collision on device %s " 165 printk(KERN_ERR "Zorro: Address space collision on device %s "
166 "[%lx:%lx]\n", 166 "[%lx:%lx]\n",
167 z->name, zorro_resource_start(z), zorro_resource_end(z)); 167 z->name, (unsigned long)zorro_resource_start(z),
168 (unsigned long)zorro_resource_end(z));
168 sprintf(z->dev.bus_id, "%02x", i); 169 sprintf(z->dev.bus_id, "%02x", i);
169 z->dev.parent = &zorro_bus.dev; 170 z->dev.parent = &zorro_bus.dev;
170 z->dev.bus = &zorro_bus_type; 171 z->dev.bus = &zorro_bus_type;
diff --git a/include/asm-i386/agp.h b/include/asm-i386/agp.h
index 9075083bab76..6af173dbf123 100644
--- a/include/asm-i386/agp.h
+++ b/include/asm-i386/agp.h
@@ -12,8 +12,10 @@
12 * data corruption on some CPUs. 12 * data corruption on some CPUs.
13 */ 13 */
14 14
15int map_page_into_agp(struct page *page); 15/* Caller's responsibility to call global_flush_tlb() for
16int unmap_page_from_agp(struct page *page); 16 * performance reasons */
17#define map_page_into_agp(page) change_page_attr(page, 1, PAGE_KERNEL_NOCACHE)
18#define unmap_page_from_agp(page) change_page_attr(page, 1, PAGE_KERNEL)
17#define flush_agp_mappings() global_flush_tlb() 19#define flush_agp_mappings() global_flush_tlb()
18 20
19/* Could use CLFLUSH here if the cpu supports it. But then it would 21/* Could use CLFLUSH here if the cpu supports it. But then it would
diff --git a/include/asm-m68k/adb.h b/include/asm-m68k/adb.h
deleted file mode 100644
index 9176b55185bb..000000000000
--- a/include/asm-m68k/adb.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 * Definitions for talking to ADB and CUDA. The CUDA is a microcontroller
3 * which controls the ADB, system power, RTC, and various other things on
4 * later Macintoshes
5 *
6 * Copyright (C) 1996 Paul Mackerras.
7 */
8
9/* First byte sent to or received from CUDA */
10#define ADB_PACKET 0
11#define CUDA_PACKET 1
12#define ERROR_PACKET 2
13#define TIMER_PACKET 3
14#define POWER_PACKET 4
15#define MACIIC_PACKET 5
16
17/* ADB commands (2nd byte) */
18#define ADB_BUSRESET 0
19#define ADB_FLUSH(id) (1 + ((id) << 4))
20#define ADB_WRITEREG(id, reg) (8 + (reg) + ((id) << 4))
21#define ADB_READREG(id, reg) (0xc + (reg) + ((id) << 4))
22
23/* ADB default device IDs (upper 4 bits of 2nd byte) */
24#define ADB_DONGLE 1 /* "software execution control" devices */
25#define ADB_KEYBOARD 2
26#define ADB_MOUSE 3
27#define ADB_TABLET 4
28#define ADB_MODEM 5
29#define ADB_MISC 7 /* maybe a monitor */
30
31/* CUDA commands (2nd byte) */
32#define CUDA_WARM_START 0
33#define CUDA_AUTOPOLL 1
34#define CUDA_GET_6805_ADDR 2
35#define CUDA_GET_TIME 3
36#define CUDA_GET_PRAM 7
37#define CUDA_SET_6805_ADDR 8
38#define CUDA_SET_TIME 9
39#define CUDA_POWERDOWN 0xa
40#define CUDA_POWERUP_TIME 0xb
41#define CUDA_SET_PRAM 0xc
42#define CUDA_MS_RESET 0xd
43#define CUDA_SEND_DFAC 0xe
44#define CUDA_RESET_SYSTEM 0x11
45#define CUDA_SET_IPL 0x12
46#define CUDA_SET_AUTO_RATE 0x14
47#define CUDA_GET_AUTO_RATE 0x16
48#define CUDA_SET_DEVICE_LIST 0x19
49#define CUDA_GET_DEVICE_LIST 0x1a
50#define CUDA_GET_SET_IIC 0x22
51
52#ifdef __KERNEL__
53
54struct adb_request {
55 unsigned char data[16];
56 int nbytes;
57 unsigned char reply[16];
58 int reply_len;
59 unsigned char reply_expected;
60 unsigned char sent;
61 unsigned char got_reply;
62 void (*done)(struct adb_request *);
63 void *arg;
64 struct adb_request *next;
65};
66
67void via_adb_init(void);
68int adb_request(struct adb_request *req,
69 void (*done)(struct adb_request *), int nbytes, ...);
70int adb_send_request(struct adb_request *req);
71void adb_poll(void);
72int adb_register(int default_id,
73 void (*handler)(unsigned char *, int, struct pt_regs *));
74
75#endif /* __KERNEL */
diff --git a/include/asm-m68k/atarikb.h b/include/asm-m68k/atarikb.h
index 18926058fde7..546e7da5804f 100644
--- a/include/asm-m68k/atarikb.h
+++ b/include/asm-m68k/atarikb.h
@@ -36,5 +36,11 @@ void ikbd_joystick_disable(void);
36extern void (*atari_MIDI_interrupt_hook) (void); 36extern void (*atari_MIDI_interrupt_hook) (void);
37/* Hook for mouse driver */ 37/* Hook for mouse driver */
38extern void (*atari_mouse_interrupt_hook) (char *); 38extern void (*atari_mouse_interrupt_hook) (char *);
39/* Hook for keyboard inputdev driver */
40extern void (*atari_input_keyboard_interrupt_hook) (unsigned char, char);
41/* Hook for mouse inputdev driver */
42extern void (*atari_input_mouse_interrupt_hook) (char *);
43
44int atari_keyb_init(void);
39 45
40#endif /* _LINUX_ATARIKB_H */ 46#endif /* _LINUX_ATARIKB_H */
diff --git a/include/asm-powerpc/ps3av.h b/include/asm-powerpc/ps3av.h
index 43e90ea96136..9efc40f1c778 100644
--- a/include/asm-powerpc/ps3av.h
+++ b/include/asm-powerpc/ps3av.h
@@ -18,8 +18,6 @@
18#ifndef _ASM_POWERPC_PS3AV_H_ 18#ifndef _ASM_POWERPC_PS3AV_H_
19#define _ASM_POWERPC_PS3AV_H_ 19#define _ASM_POWERPC_PS3AV_H_
20 20
21#include <linux/mutex.h>
22
23/** command for ioctl() **/ 21/** command for ioctl() **/
24#define PS3AV_VERSION 0x205 /* version of ps3av command */ 22#define PS3AV_VERSION 0x205 /* version of ps3av command */
25 23
@@ -643,24 +641,6 @@ struct ps3av_pkt_avb_param {
643 u8 buf[PS3AV_PKT_AVB_PARAM_MAX_BUF_SIZE]; 641 u8 buf[PS3AV_PKT_AVB_PARAM_MAX_BUF_SIZE];
644}; 642};
645 643
646struct ps3av {
647 int available;
648 struct semaphore sem;
649 struct semaphore ping;
650 struct semaphore pong;
651 struct mutex mutex;
652 int open_count;
653 struct ps3_vuart_port_device *dev;
654
655 int region;
656 struct ps3av_pkt_av_get_hw_conf av_hw_conf;
657 u32 av_port[PS3AV_AV_PORT_MAX + PS3AV_OPT_PORT_MAX];
658 u32 opt_port[PS3AV_OPT_PORT_MAX];
659 u32 head[PS3AV_HEAD_MAX];
660 u32 audio_port;
661 int ps3av_mode;
662 int ps3av_mode_old;
663};
664 644
665/** command status **/ 645/** command status **/
666#define PS3AV_STATUS_SUCCESS 0x0000 /* success */ 646#define PS3AV_STATUS_SUCCESS 0x0000 /* success */
@@ -718,6 +698,7 @@ static inline void ps3av_cmd_av_monitor_info_dump(const struct ps3av_pkt_av_get_
718extern int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *, 698extern int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *,
719 u32); 699 u32);
720 700
701struct ps3_vuart_port_device;
721extern int ps3av_vuart_write(struct ps3_vuart_port_device *dev, 702extern int ps3av_vuart_write(struct ps3_vuart_port_device *dev,
722 const void *buf, unsigned long size); 703 const void *buf, unsigned long size);
723extern int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf, 704extern int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
@@ -725,6 +706,7 @@ extern int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
725 706
726extern int ps3av_set_video_mode(u32, int); 707extern int ps3av_set_video_mode(u32, int);
727extern int ps3av_set_audio_mode(u32, u32, u32, u32, u32); 708extern int ps3av_set_audio_mode(u32, u32, u32, u32, u32);
709extern int ps3av_get_auto_mode(int);
728extern int ps3av_set_mode(u32, int); 710extern int ps3av_set_mode(u32, int);
729extern int ps3av_get_mode(void); 711extern int ps3av_get_mode(void);
730extern int ps3av_get_scanmode(int); 712extern int ps3av_get_scanmode(int);
diff --git a/include/asm-s390/ccwdev.h b/include/asm-s390/ccwdev.h
index cfc81533b9ba..6795ecefd15b 100644
--- a/include/asm-s390/ccwdev.h
+++ b/include/asm-s390/ccwdev.h
@@ -164,9 +164,9 @@ extern int ccw_device_resume(struct ccw_device *);
164extern int ccw_device_halt(struct ccw_device *, unsigned long); 164extern int ccw_device_halt(struct ccw_device *, unsigned long);
165extern int ccw_device_clear(struct ccw_device *, unsigned long); 165extern int ccw_device_clear(struct ccw_device *, unsigned long);
166 166
167extern int read_dev_chars(struct ccw_device *cdev, void **buffer, int length); 167extern int __deprecated read_dev_chars(struct ccw_device *cdev, void **buffer, int length);
168extern int read_conf_data(struct ccw_device *cdev, void **buffer, int *length); 168extern int __deprecated read_conf_data(struct ccw_device *cdev, void **buffer, int *length);
169extern int read_conf_data_lpm(struct ccw_device *cdev, void **buffer, 169extern int __deprecated read_conf_data_lpm(struct ccw_device *cdev, void **buffer,
170 int *length, __u8 lpm); 170 int *length, __u8 lpm);
171 171
172extern int ccw_device_set_online(struct ccw_device *cdev); 172extern int ccw_device_set_online(struct ccw_device *cdev);
diff --git a/include/asm-s390/elf.h b/include/asm-s390/elf.h
index c0d629d61d3e..91d06325cc79 100644
--- a/include/asm-s390/elf.h
+++ b/include/asm-s390/elf.h
@@ -188,7 +188,8 @@ static inline int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
188/* This yields a mask that user programs can use to figure out what 188/* This yields a mask that user programs can use to figure out what
189 instruction set this CPU supports. */ 189 instruction set this CPU supports. */
190 190
191#define ELF_HWCAP (0) 191extern unsigned long elf_hwcap;
192#define ELF_HWCAP (elf_hwcap)
192 193
193/* This yields a string that ld.so will use to load implementation 194/* This yields a string that ld.so will use to load implementation
194 specific libraries for optimization. This is more specific in 195 specific libraries for optimization. This is more specific in
@@ -197,7 +198,9 @@ static inline int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
197 For the moment, we have only optimizations for the Intel generations, 198 For the moment, we have only optimizations for the Intel generations,
198 but that could change... */ 199 but that could change... */
199 200
200#define ELF_PLATFORM (NULL) 201#define ELF_PLATFORM_SIZE 8
202extern char elf_platform[];
203#define ELF_PLATFORM (elf_platform)
201 204
202#ifndef __s390x__ 205#ifndef __s390x__
203#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX) 206#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
diff --git a/include/asm-s390/kdebug.h b/include/asm-s390/kdebug.h
index 1b50f89819a4..d2d7ad276148 100644
--- a/include/asm-s390/kdebug.h
+++ b/include/asm-s390/kdebug.h
@@ -22,8 +22,21 @@ struct die_args {
22 */ 22 */
23extern int register_die_notifier(struct notifier_block *); 23extern int register_die_notifier(struct notifier_block *);
24extern int unregister_die_notifier(struct notifier_block *); 24extern int unregister_die_notifier(struct notifier_block *);
25extern int register_page_fault_notifier(struct notifier_block *); 25
26extern int unregister_page_fault_notifier(struct notifier_block *); 26/*
27 * These are only here because kprobes.c wants them to implement a
28 * blatant layering violation. Will hopefully go away soon once all
29 * architectures are updated.
30 */
31static inline int register_page_fault_notifier(struct notifier_block *nb)
32{
33 return 0;
34}
35static inline int unregister_page_fault_notifier(struct notifier_block *nb)
36{
37 return 0;
38}
39
27extern struct atomic_notifier_head s390die_chain; 40extern struct atomic_notifier_head s390die_chain;
28 41
29enum die_val { 42enum die_val {
@@ -39,7 +52,6 @@ enum die_val {
39 DIE_GPF, 52 DIE_GPF,
40 DIE_CALL, 53 DIE_CALL,
41 DIE_NMI_IPI, 54 DIE_NMI_IPI,
42 DIE_PAGE_FAULT,
43}; 55};
44 56
45static inline int notify_die(enum die_val val, const char *str, 57static inline int notify_die(enum die_val val, const char *str,
diff --git a/include/asm-s390/kprobes.h b/include/asm-s390/kprobes.h
index b847ff0ec3fa..830fe4c4eea6 100644
--- a/include/asm-s390/kprobes.h
+++ b/include/asm-s390/kprobes.h
@@ -97,18 +97,10 @@ void kretprobe_trampoline(void);
97int is_prohibited_opcode(kprobe_opcode_t *instruction); 97int is_prohibited_opcode(kprobe_opcode_t *instruction);
98void get_instruction_type(struct arch_specific_insn *ainsn); 98void get_instruction_type(struct arch_specific_insn *ainsn);
99 99
100int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
101int kprobe_exceptions_notify(struct notifier_block *self,
102 unsigned long val, void *data);
103
100#define flush_insn_slot(p) do { } while (0) 104#define flush_insn_slot(p) do { } while (0)
101 105
102#endif /* _ASM_S390_KPROBES_H */ 106#endif /* _ASM_S390_KPROBES_H */
103
104#ifdef CONFIG_KPROBES
105
106extern int kprobe_exceptions_notify(struct notifier_block *self,
107 unsigned long val, void *data);
108#else /* !CONFIG_KPROBES */
109static inline int kprobe_exceptions_notify(struct notifier_block *self,
110 unsigned long val, void *data)
111{
112 return 0;
113}
114#endif
diff --git a/include/asm-s390/lowcore.h b/include/asm-s390/lowcore.h
index ffc9788a21a7..801a6fd35b5b 100644
--- a/include/asm-s390/lowcore.h
+++ b/include/asm-s390/lowcore.h
@@ -229,17 +229,19 @@ struct _lowcore
229 __u16 subchannel_nr; /* 0x0ba */ 229 __u16 subchannel_nr; /* 0x0ba */
230 __u32 io_int_parm; /* 0x0bc */ 230 __u32 io_int_parm; /* 0x0bc */
231 __u32 io_int_word; /* 0x0c0 */ 231 __u32 io_int_word; /* 0x0c0 */
232 __u8 pad3[0xD4-0xC4]; /* 0x0c4 */ 232 __u8 pad3[0xc8-0xc4]; /* 0x0c4 */
233 __u32 stfl_fac_list; /* 0x0c8 */
234 __u8 pad4[0xd4-0xcc]; /* 0x0cc */
233 __u32 extended_save_area_addr; /* 0x0d4 */ 235 __u32 extended_save_area_addr; /* 0x0d4 */
234 __u32 cpu_timer_save_area[2]; /* 0x0d8 */ 236 __u32 cpu_timer_save_area[2]; /* 0x0d8 */
235 __u32 clock_comp_save_area[2]; /* 0x0e0 */ 237 __u32 clock_comp_save_area[2]; /* 0x0e0 */
236 __u32 mcck_interruption_code[2]; /* 0x0e8 */ 238 __u32 mcck_interruption_code[2]; /* 0x0e8 */
237 __u8 pad4[0xf4-0xf0]; /* 0x0f0 */ 239 __u8 pad5[0xf4-0xf0]; /* 0x0f0 */
238 __u32 external_damage_code; /* 0x0f4 */ 240 __u32 external_damage_code; /* 0x0f4 */
239 __u32 failing_storage_address; /* 0x0f8 */ 241 __u32 failing_storage_address; /* 0x0f8 */
240 __u8 pad5[0x100-0xfc]; /* 0x0fc */ 242 __u8 pad6[0x100-0xfc]; /* 0x0fc */
241 __u32 st_status_fixed_logout[4];/* 0x100 */ 243 __u32 st_status_fixed_logout[4];/* 0x100 */
242 __u8 pad6[0x120-0x110]; /* 0x110 */ 244 __u8 pad7[0x120-0x110]; /* 0x110 */
243 __u32 access_regs_save_area[16];/* 0x120 */ 245 __u32 access_regs_save_area[16];/* 0x120 */
244 __u32 floating_pt_save_area[8]; /* 0x160 */ 246 __u32 floating_pt_save_area[8]; /* 0x160 */
245 __u32 gpregs_save_area[16]; /* 0x180 */ 247 __u32 gpregs_save_area[16]; /* 0x180 */
diff --git a/include/asm-x86_64/agp.h b/include/asm-x86_64/agp.h
index 06c52ee9c06b..de338666f3f9 100644
--- a/include/asm-x86_64/agp.h
+++ b/include/asm-x86_64/agp.h
@@ -10,8 +10,10 @@
10 * with different cachability attributes for the same page. 10 * with different cachability attributes for the same page.
11 */ 11 */
12 12
13int map_page_into_agp(struct page *page); 13/* Caller's responsibility to call global_flush_tlb() for
14int unmap_page_from_agp(struct page *page); 14 * performance reasons */
15#define map_page_into_agp(page) change_page_attr(page, 1, PAGE_KERNEL_NOCACHE)
16#define unmap_page_from_agp(page) change_page_attr(page, 1, PAGE_KERNEL)
15#define flush_agp_mappings() global_flush_tlb() 17#define flush_agp_mappings() global_flush_tlb()
16 18
17/* Could use CLFLUSH here if the cpu supports it. But then it would 19/* Could use CLFLUSH here if the cpu supports it. But then it would
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index 4e05e93ff681..b2b1e6efd812 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -13,8 +13,11 @@
13#define _CRYPTO_ALGAPI_H 13#define _CRYPTO_ALGAPI_H
14 14
15#include <linux/crypto.h> 15#include <linux/crypto.h>
16#include <linux/list.h>
17#include <linux/kernel.h>
16 18
17struct module; 19struct module;
20struct rtattr;
18struct seq_file; 21struct seq_file;
19 22
20struct crypto_type { 23struct crypto_type {
@@ -38,7 +41,7 @@ struct crypto_template {
38 struct hlist_head instances; 41 struct hlist_head instances;
39 struct module *module; 42 struct module *module;
40 43
41 struct crypto_instance *(*alloc)(void *param, unsigned int len); 44 struct crypto_instance *(*alloc)(struct rtattr **tb);
42 void (*free)(struct crypto_instance *inst); 45 void (*free)(struct crypto_instance *inst);
43 46
44 char name[CRYPTO_MAX_ALG_NAME]; 47 char name[CRYPTO_MAX_ALG_NAME];
@@ -48,6 +51,15 @@ struct crypto_spawn {
48 struct list_head list; 51 struct list_head list;
49 struct crypto_alg *alg; 52 struct crypto_alg *alg;
50 struct crypto_instance *inst; 53 struct crypto_instance *inst;
54 u32 mask;
55};
56
57struct crypto_queue {
58 struct list_head list;
59 struct list_head *backlog;
60
61 unsigned int qlen;
62 unsigned int max_qlen;
51}; 63};
52 64
53struct scatter_walk { 65struct scatter_walk {
@@ -81,6 +93,7 @@ struct blkcipher_walk {
81 int flags; 93 int flags;
82}; 94};
83 95
96extern const struct crypto_type crypto_ablkcipher_type;
84extern const struct crypto_type crypto_blkcipher_type; 97extern const struct crypto_type crypto_blkcipher_type;
85extern const struct crypto_type crypto_hash_type; 98extern const struct crypto_type crypto_hash_type;
86 99
@@ -91,16 +104,23 @@ void crypto_unregister_template(struct crypto_template *tmpl);
91struct crypto_template *crypto_lookup_template(const char *name); 104struct crypto_template *crypto_lookup_template(const char *name);
92 105
93int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, 106int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
94 struct crypto_instance *inst); 107 struct crypto_instance *inst, u32 mask);
95void crypto_drop_spawn(struct crypto_spawn *spawn); 108void crypto_drop_spawn(struct crypto_spawn *spawn);
96struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, 109struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
97 u32 mask); 110 u32 mask);
98 111
99struct crypto_alg *crypto_get_attr_alg(void *param, unsigned int len, 112struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
100 u32 type, u32 mask); 113int crypto_check_attr_type(struct rtattr **tb, u32 type);
114struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, u32 type, u32 mask);
101struct crypto_instance *crypto_alloc_instance(const char *name, 115struct crypto_instance *crypto_alloc_instance(const char *name,
102 struct crypto_alg *alg); 116 struct crypto_alg *alg);
103 117
118void crypto_init_queue(struct crypto_queue *queue, unsigned int max_qlen);
119int crypto_enqueue_request(struct crypto_queue *queue,
120 struct crypto_async_request *request);
121struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue);
122int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm);
123
104int blkcipher_walk_done(struct blkcipher_desc *desc, 124int blkcipher_walk_done(struct blkcipher_desc *desc,
105 struct blkcipher_walk *walk, int err); 125 struct blkcipher_walk *walk, int err);
106int blkcipher_walk_virt(struct blkcipher_desc *desc, 126int blkcipher_walk_virt(struct blkcipher_desc *desc,
@@ -118,11 +138,37 @@ static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm)
118 return (void *)ALIGN(addr, align); 138 return (void *)ALIGN(addr, align);
119} 139}
120 140
141static inline struct crypto_instance *crypto_tfm_alg_instance(
142 struct crypto_tfm *tfm)
143{
144 return container_of(tfm->__crt_alg, struct crypto_instance, alg);
145}
146
121static inline void *crypto_instance_ctx(struct crypto_instance *inst) 147static inline void *crypto_instance_ctx(struct crypto_instance *inst)
122{ 148{
123 return inst->__ctx; 149 return inst->__ctx;
124} 150}
125 151
152static inline struct ablkcipher_alg *crypto_ablkcipher_alg(
153 struct crypto_ablkcipher *tfm)
154{
155 return &crypto_ablkcipher_tfm(tfm)->__crt_alg->cra_ablkcipher;
156}
157
158static inline void *crypto_ablkcipher_ctx(struct crypto_ablkcipher *tfm)
159{
160 return crypto_tfm_ctx(&tfm->base);
161}
162
163static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
164 struct crypto_spawn *spawn)
165{
166 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
167 u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
168
169 return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
170}
171
126static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm) 172static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm)
127{ 173{
128 return crypto_tfm_ctx(&tfm->base); 174 return crypto_tfm_ctx(&tfm->base);
@@ -170,5 +216,35 @@ static inline void blkcipher_walk_init(struct blkcipher_walk *walk,
170 walk->total = nbytes; 216 walk->total = nbytes;
171} 217}
172 218
219static inline struct crypto_async_request *crypto_get_backlog(
220 struct crypto_queue *queue)
221{
222 return queue->backlog == &queue->list ? NULL :
223 container_of(queue->backlog, struct crypto_async_request, list);
224}
225
226static inline int ablkcipher_enqueue_request(struct ablkcipher_alg *alg,
227 struct ablkcipher_request *request)
228{
229 return crypto_enqueue_request(alg->queue, &request->base);
230}
231
232static inline struct ablkcipher_request *ablkcipher_dequeue_request(
233 struct ablkcipher_alg *alg)
234{
235 return ablkcipher_request_cast(crypto_dequeue_request(alg->queue));
236}
237
238static inline void *ablkcipher_request_ctx(struct ablkcipher_request *req)
239{
240 return req->__ctx;
241}
242
243static inline int ablkcipher_tfm_in_queue(struct crypto_ablkcipher *tfm)
244{
245 return crypto_tfm_in_queue(crypto_ablkcipher_alg(tfm)->queue,
246 crypto_ablkcipher_tfm(tfm));
247}
248
173#endif /* _CRYPTO_ALGAPI_H */ 249#endif /* _CRYPTO_ALGAPI_H */
174 250
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 0899e2cdcdd1..3ec6e7ff5fbd 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -257,7 +257,6 @@ struct freq_attr {
257/********************************************************************* 257/*********************************************************************
258 * CPUFREQ 2.6. INTERFACE * 258 * CPUFREQ 2.6. INTERFACE *
259 *********************************************************************/ 259 *********************************************************************/
260int cpufreq_set_policy(struct cpufreq_policy *policy);
261int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu); 260int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
262int cpufreq_update_policy(unsigned int cpu); 261int cpufreq_update_policy(unsigned int cpu);
263 262
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 779aa78ee643..0de7e2ace822 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -56,6 +56,7 @@
56 56
57#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 57#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
58#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 58#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
59#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
59#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 60#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
60#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 61#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
61#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 62#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
@@ -88,11 +89,38 @@
88#endif 89#endif
89 90
90struct scatterlist; 91struct scatterlist;
92struct crypto_ablkcipher;
93struct crypto_async_request;
91struct crypto_blkcipher; 94struct crypto_blkcipher;
92struct crypto_hash; 95struct crypto_hash;
96struct crypto_queue;
93struct crypto_tfm; 97struct crypto_tfm;
94struct crypto_type; 98struct crypto_type;
95 99
100typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
101
102struct crypto_async_request {
103 struct list_head list;
104 crypto_completion_t complete;
105 void *data;
106 struct crypto_tfm *tfm;
107
108 u32 flags;
109};
110
111struct ablkcipher_request {
112 struct crypto_async_request base;
113
114 unsigned int nbytes;
115
116 void *info;
117
118 struct scatterlist *src;
119 struct scatterlist *dst;
120
121 void *__ctx[] CRYPTO_MINALIGN_ATTR;
122};
123
96struct blkcipher_desc { 124struct blkcipher_desc {
97 struct crypto_blkcipher *tfm; 125 struct crypto_blkcipher *tfm;
98 void *info; 126 void *info;
@@ -116,6 +144,19 @@ struct hash_desc {
116 * Algorithms: modular crypto algorithm implementations, managed 144 * Algorithms: modular crypto algorithm implementations, managed
117 * via crypto_register_alg() and crypto_unregister_alg(). 145 * via crypto_register_alg() and crypto_unregister_alg().
118 */ 146 */
147struct ablkcipher_alg {
148 int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
149 unsigned int keylen);
150 int (*encrypt)(struct ablkcipher_request *req);
151 int (*decrypt)(struct ablkcipher_request *req);
152
153 struct crypto_queue *queue;
154
155 unsigned int min_keysize;
156 unsigned int max_keysize;
157 unsigned int ivsize;
158};
159
119struct blkcipher_alg { 160struct blkcipher_alg {
120 int (*setkey)(struct crypto_tfm *tfm, const u8 *key, 161 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
121 unsigned int keylen); 162 unsigned int keylen);
@@ -170,6 +211,7 @@ struct compress_alg {
170 unsigned int slen, u8 *dst, unsigned int *dlen); 211 unsigned int slen, u8 *dst, unsigned int *dlen);
171}; 212};
172 213
214#define cra_ablkcipher cra_u.ablkcipher
173#define cra_blkcipher cra_u.blkcipher 215#define cra_blkcipher cra_u.blkcipher
174#define cra_cipher cra_u.cipher 216#define cra_cipher cra_u.cipher
175#define cra_digest cra_u.digest 217#define cra_digest cra_u.digest
@@ -194,6 +236,7 @@ struct crypto_alg {
194 const struct crypto_type *cra_type; 236 const struct crypto_type *cra_type;
195 237
196 union { 238 union {
239 struct ablkcipher_alg ablkcipher;
197 struct blkcipher_alg blkcipher; 240 struct blkcipher_alg blkcipher;
198 struct cipher_alg cipher; 241 struct cipher_alg cipher;
199 struct digest_alg digest; 242 struct digest_alg digest;
@@ -232,6 +275,15 @@ static inline int crypto_has_alg(const char *name, u32 type, u32 mask)
232 * crypto_free_*(), as well as the various helpers below. 275 * crypto_free_*(), as well as the various helpers below.
233 */ 276 */
234 277
278struct ablkcipher_tfm {
279 int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
280 unsigned int keylen);
281 int (*encrypt)(struct ablkcipher_request *req);
282 int (*decrypt)(struct ablkcipher_request *req);
283 unsigned int ivsize;
284 unsigned int reqsize;
285};
286
235struct blkcipher_tfm { 287struct blkcipher_tfm {
236 void *iv; 288 void *iv;
237 int (*setkey)(struct crypto_tfm *tfm, const u8 *key, 289 int (*setkey)(struct crypto_tfm *tfm, const u8 *key,
@@ -290,6 +342,7 @@ struct compress_tfm {
290 u8 *dst, unsigned int *dlen); 342 u8 *dst, unsigned int *dlen);
291}; 343};
292 344
345#define crt_ablkcipher crt_u.ablkcipher
293#define crt_blkcipher crt_u.blkcipher 346#define crt_blkcipher crt_u.blkcipher
294#define crt_cipher crt_u.cipher 347#define crt_cipher crt_u.cipher
295#define crt_hash crt_u.hash 348#define crt_hash crt_u.hash
@@ -300,6 +353,7 @@ struct crypto_tfm {
300 u32 crt_flags; 353 u32 crt_flags;
301 354
302 union { 355 union {
356 struct ablkcipher_tfm ablkcipher;
303 struct blkcipher_tfm blkcipher; 357 struct blkcipher_tfm blkcipher;
304 struct cipher_tfm cipher; 358 struct cipher_tfm cipher;
305 struct hash_tfm hash; 359 struct hash_tfm hash;
@@ -311,6 +365,10 @@ struct crypto_tfm {
311 void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; 365 void *__crt_ctx[] CRYPTO_MINALIGN_ATTR;
312}; 366};
313 367
368struct crypto_ablkcipher {
369 struct crypto_tfm base;
370};
371
314struct crypto_blkcipher { 372struct crypto_blkcipher {
315 struct crypto_tfm base; 373 struct crypto_tfm base;
316}; 374};
@@ -330,12 +388,21 @@ struct crypto_hash {
330enum { 388enum {
331 CRYPTOA_UNSPEC, 389 CRYPTOA_UNSPEC,
332 CRYPTOA_ALG, 390 CRYPTOA_ALG,
391 CRYPTOA_TYPE,
392 __CRYPTOA_MAX,
333}; 393};
334 394
395#define CRYPTOA_MAX (__CRYPTOA_MAX - 1)
396
335struct crypto_attr_alg { 397struct crypto_attr_alg {
336 char name[CRYPTO_MAX_ALG_NAME]; 398 char name[CRYPTO_MAX_ALG_NAME];
337}; 399};
338 400
401struct crypto_attr_type {
402 u32 type;
403 u32 mask;
404};
405
339/* 406/*
340 * Transform user interface. 407 * Transform user interface.
341 */ 408 */
@@ -411,6 +478,167 @@ static inline unsigned int crypto_tfm_ctx_alignment(void)
411/* 478/*
412 * API wrappers. 479 * API wrappers.
413 */ 480 */
481static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
482 struct crypto_tfm *tfm)
483{
484 return (struct crypto_ablkcipher *)tfm;
485}
486
487static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
488 const char *alg_name, u32 type, u32 mask)
489{
490 type &= ~CRYPTO_ALG_TYPE_MASK;
491 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
492 mask |= CRYPTO_ALG_TYPE_MASK;
493
494 return __crypto_ablkcipher_cast(
495 crypto_alloc_base(alg_name, type, mask));
496}
497
498static inline struct crypto_tfm *crypto_ablkcipher_tfm(
499 struct crypto_ablkcipher *tfm)
500{
501 return &tfm->base;
502}
503
504static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
505{
506 crypto_free_tfm(crypto_ablkcipher_tfm(tfm));
507}
508
509static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
510 u32 mask)
511{
512 type &= ~CRYPTO_ALG_TYPE_MASK;
513 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
514 mask |= CRYPTO_ALG_TYPE_MASK;
515
516 return crypto_has_alg(alg_name, type, mask);
517}
518
519static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
520 struct crypto_ablkcipher *tfm)
521{
522 return &crypto_ablkcipher_tfm(tfm)->crt_ablkcipher;
523}
524
525static inline unsigned int crypto_ablkcipher_ivsize(
526 struct crypto_ablkcipher *tfm)
527{
528 return crypto_ablkcipher_crt(tfm)->ivsize;
529}
530
531static inline unsigned int crypto_ablkcipher_blocksize(
532 struct crypto_ablkcipher *tfm)
533{
534 return crypto_tfm_alg_blocksize(crypto_ablkcipher_tfm(tfm));
535}
536
537static inline unsigned int crypto_ablkcipher_alignmask(
538 struct crypto_ablkcipher *tfm)
539{
540 return crypto_tfm_alg_alignmask(crypto_ablkcipher_tfm(tfm));
541}
542
543static inline u32 crypto_ablkcipher_get_flags(struct crypto_ablkcipher *tfm)
544{
545 return crypto_tfm_get_flags(crypto_ablkcipher_tfm(tfm));
546}
547
548static inline void crypto_ablkcipher_set_flags(struct crypto_ablkcipher *tfm,
549 u32 flags)
550{
551 crypto_tfm_set_flags(crypto_ablkcipher_tfm(tfm), flags);
552}
553
554static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
555 u32 flags)
556{
557 crypto_tfm_clear_flags(crypto_ablkcipher_tfm(tfm), flags);
558}
559
560static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
561 const u8 *key, unsigned int keylen)
562{
563 return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
564}
565
566static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
567 struct ablkcipher_request *req)
568{
569 return __crypto_ablkcipher_cast(req->base.tfm);
570}
571
572static inline int crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
573{
574 struct ablkcipher_tfm *crt =
575 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
576 return crt->encrypt(req);
577}
578
579static inline int crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
580{
581 struct ablkcipher_tfm *crt =
582 crypto_ablkcipher_crt(crypto_ablkcipher_reqtfm(req));
583 return crt->decrypt(req);
584}
585
586static inline int crypto_ablkcipher_reqsize(struct crypto_ablkcipher *tfm)
587{
588 return crypto_ablkcipher_crt(tfm)->reqsize;
589}
590
591static inline void ablkcipher_request_set_tfm(
592 struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
593{
594 req->base.tfm = crypto_ablkcipher_tfm(tfm);
595}
596
597static inline struct ablkcipher_request *ablkcipher_request_cast(
598 struct crypto_async_request *req)
599{
600 return container_of(req, struct ablkcipher_request, base);
601}
602
603static inline struct ablkcipher_request *ablkcipher_request_alloc(
604 struct crypto_ablkcipher *tfm, gfp_t gfp)
605{
606 struct ablkcipher_request *req;
607
608 req = kmalloc(sizeof(struct ablkcipher_request) +
609 crypto_ablkcipher_reqsize(tfm), gfp);
610
611 if (likely(req))
612 ablkcipher_request_set_tfm(req, tfm);
613
614 return req;
615}
616
617static inline void ablkcipher_request_free(struct ablkcipher_request *req)
618{
619 kfree(req);
620}
621
622static inline void ablkcipher_request_set_callback(
623 struct ablkcipher_request *req,
624 u32 flags, crypto_completion_t complete, void *data)
625{
626 req->base.complete = complete;
627 req->base.data = data;
628 req->base.flags = flags;
629}
630
631static inline void ablkcipher_request_set_crypt(
632 struct ablkcipher_request *req,
633 struct scatterlist *src, struct scatterlist *dst,
634 unsigned int nbytes, void *iv)
635{
636 req->src = src;
637 req->dst = dst;
638 req->nbytes = nbytes;
639 req->info = iv;
640}
641
414static inline struct crypto_blkcipher *__crypto_blkcipher_cast( 642static inline struct crypto_blkcipher *__crypto_blkcipher_cast(
415 struct crypto_tfm *tfm) 643 struct crypto_tfm *tfm)
416{ 644{
@@ -427,9 +655,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast(
427static inline struct crypto_blkcipher *crypto_alloc_blkcipher( 655static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
428 const char *alg_name, u32 type, u32 mask) 656 const char *alg_name, u32 type, u32 mask)
429{ 657{
430 type &= ~CRYPTO_ALG_TYPE_MASK; 658 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
431 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 659 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
432 mask |= CRYPTO_ALG_TYPE_MASK; 660 mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
433 661
434 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); 662 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
435} 663}
@@ -447,9 +675,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
447 675
448static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) 676static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
449{ 677{
450 type &= ~CRYPTO_ALG_TYPE_MASK; 678 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC);
451 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 679 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
452 mask |= CRYPTO_ALG_TYPE_MASK; 680 mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC;
453 681
454 return crypto_has_alg(alg_name, type, mask); 682 return crypto_has_alg(alg_name, type, mask);
455} 683}
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 645d440807c2..7bab8eae2341 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -42,8 +42,14 @@ static inline void *kmap(struct page *page)
42 42
43#define kunmap(page) do { (void) (page); } while (0) 43#define kunmap(page) do { (void) (page); } while (0)
44 44
45#define kmap_atomic(page, idx) \ 45#include <asm/kmap_types.h>
46 ({ pagefault_disable(); page_address(page); }) 46
47static inline void *kmap_atomic(struct page *page, enum km_type idx)
48{
49 pagefault_disable();
50 return page_address(page);
51}
52
47#define kunmap_atomic(addr, idx) do { pagefault_enable(); } while (0) 53#define kunmap_atomic(addr, idx) do { pagefault_enable(); } while (0)
48#define kmap_atomic_pfn(pfn, idx) kmap_atomic(pfn_to_page(pfn), (idx)) 54#define kmap_atomic_pfn(pfn, idx) kmap_atomic(pfn_to_page(pfn), (idx))
49#define kmap_atomic_to_page(ptr) virt_to_page(ptr) 55#define kmap_atomic_to_page(ptr) virt_to_page(ptr)
diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
index 937da70cb4c4..9ee0f800592f 100644
--- a/include/linux/i2c-algo-bit.h
+++ b/include/linux/i2c-algo-bit.h
@@ -38,11 +38,14 @@ struct i2c_algo_bit_data {
38 int (*getscl) (void *data); 38 int (*getscl) (void *data);
39 39
40 /* local settings */ 40 /* local settings */
41 int udelay; /* half-clock-cycle time in microsecs */ 41 int udelay; /* half clock cycle time in us,
42 /* i.e. clock is (500 / udelay) KHz */ 42 minimum 2 us for fast-mode I2C,
43 minimum 5 us for standard-mode I2C and SMBus,
44 maximum 50 us for SMBus */
43 int timeout; /* in jiffies */ 45 int timeout; /* in jiffies */
44}; 46};
45 47
46int i2c_bit_add_bus(struct i2c_adapter *); 48int i2c_bit_add_bus(struct i2c_adapter *);
49int i2c_bit_add_numbered_bus(struct i2c_adapter *);
47 50
48#endif /* _LINUX_I2C_ALGO_BIT_H */ 51#endif /* _LINUX_I2C_ALGO_BIT_H */
diff --git a/include/linux/i2c-gpio.h b/include/linux/i2c-gpio.h
new file mode 100644
index 000000000000..c1bcb1f1d73b
--- /dev/null
+++ b/include/linux/i2c-gpio.h
@@ -0,0 +1,38 @@
1/*
2 * i2c-gpio interface to platform code
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef _LINUX_I2C_GPIO_H
11#define _LINUX_I2C_GPIO_H
12
13/**
14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio
15 * @sda_pin: GPIO pin ID to use for SDA
16 * @scl_pin: GPIO pin ID to use for SCL
17 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
18 * @timeout: clock stretching timeout in jiffies. If the slave keeps
19 * SCL low for longer than this, the transfer will time out.
20 * @sda_is_open_drain: SDA is configured as open drain, i.e. the pin
21 * isn't actively driven high when setting the output value high.
22 * gpio_get_value() must return the actual pin state even if the
23 * pin is configured as an output.
24 * @scl_is_open_drain: SCL is set up as open drain. Same requirements
25 * as for sda_is_open_drain apply.
26 * @scl_is_output_only: SCL output drivers cannot be turned off.
27 */
28struct i2c_gpio_platform_data {
29 unsigned int sda_pin;
30 unsigned int scl_pin;
31 int udelay;
32 int timeout;
33 unsigned int sda_is_open_drain:1;
34 unsigned int scl_is_open_drain:1;
35 unsigned int scl_is_output_only:1;
36};
37
38#endif /* _LINUX_I2C_GPIO_H */
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index 9c21dc793d7b..0e8da684ce68 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -258,8 +258,9 @@
258/* --- MCP107 adapter */ 258/* --- MCP107 adapter */
259#define I2C_HW_MPC107 0x0d0000 259#define I2C_HW_MPC107 0x0d0000
260 260
261/* --- Marvell mv64xxx i2c adapter */ 261/* --- Embedded adapters */
262#define I2C_HW_MV64XXX 0x190000 262#define I2C_HW_MV64XXX 0x190000
263#define I2C_HW_BLACKFIN 0x190001 /* ADI Blackfin I2C TWI driver */
263 264
264/* --- Miscellaneous adapters */ 265/* --- Miscellaneous adapters */
265#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */ 266#define I2C_HW_SAA7146 0x060000 /* SAA7146 video decoder bus */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 9428092017e3..cae7d618030c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -35,11 +35,6 @@
35#include <linux/sched.h> /* for completion */ 35#include <linux/sched.h> /* for completion */
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37 37
38/* --- For i2c-isa ---------------------------------------------------- */
39
40extern void i2c_adapter_dev_release(struct device *dev);
41extern struct device_driver i2c_adapter_driver;
42extern struct class i2c_adapter_class;
43extern struct bus_type i2c_bus_type; 38extern struct bus_type i2c_bus_type;
44 39
45/* --- General options ------------------------------------------------ */ 40/* --- General options ------------------------------------------------ */
@@ -87,6 +82,9 @@ extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,
87extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 82extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
88extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 83extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
89 u8 command, u16 value); 84 u8 command, u16 value);
85/* Returns the number of read bytes */
86extern s32 i2c_smbus_read_block_data(struct i2c_client *client,
87 u8 command, u8 *values);
90extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 88extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
91 u8 command, u8 length, 89 u8 command, u8 length,
92 const u8 *values); 90 const u8 *values);
@@ -114,7 +112,7 @@ struct i2c_driver {
114 * can be used by the driver to test if the bus meets its conditions 112 * can be used by the driver to test if the bus meets its conditions
115 * & seek for the presence of the chip(s) it supports. If found, it 113 * & seek for the presence of the chip(s) it supports. If found, it
116 * registers the client(s) that are on the bus to the i2c admin. via 114 * registers the client(s) that are on the bus to the i2c admin. via
117 * i2c_attach_client. 115 * i2c_attach_client. (LEGACY I2C DRIVERS ONLY)
118 */ 116 */
119 int (*attach_adapter)(struct i2c_adapter *); 117 int (*attach_adapter)(struct i2c_adapter *);
120 int (*detach_adapter)(struct i2c_adapter *); 118 int (*detach_adapter)(struct i2c_adapter *);
@@ -122,10 +120,17 @@ struct i2c_driver {
122 /* tells the driver that a client is about to be deleted & gives it 120 /* tells the driver that a client is about to be deleted & gives it
123 * the chance to remove its private data. Also, if the client struct 121 * the chance to remove its private data. Also, if the client struct
124 * has been dynamically allocated by the driver in the function above, 122 * has been dynamically allocated by the driver in the function above,
125 * it must be freed here. 123 * it must be freed here. (LEGACY I2C DRIVERS ONLY)
126 */ 124 */
127 int (*detach_client)(struct i2c_client *); 125 int (*detach_client)(struct i2c_client *);
128 126
127 /* Standard driver model interfaces, for "new style" i2c drivers.
128 * With the driver model, device enumeration is NEVER done by drivers;
129 * it's done by infrastructure. (NEW STYLE DRIVERS ONLY)
130 */
131 int (*probe)(struct i2c_client *);
132 int (*remove)(struct i2c_client *);
133
129 /* driver model interfaces that don't relate to enumeration */ 134 /* driver model interfaces that don't relate to enumeration */
130 void (*shutdown)(struct i2c_client *); 135 void (*shutdown)(struct i2c_client *);
131 int (*suspend)(struct i2c_client *, pm_message_t mesg); 136 int (*suspend)(struct i2c_client *, pm_message_t mesg);
@@ -141,25 +146,34 @@ struct i2c_driver {
141}; 146};
142#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 147#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
143 148
144#define I2C_NAME_SIZE 50 149#define I2C_NAME_SIZE 20
145 150
146/* 151/**
147 * i2c_client identifies a single device (i.e. chip) that is connected to an 152 * struct i2c_client - represent an I2C slave device
148 * i2c bus. The behaviour is defined by the routines of the driver. This 153 * @addr: Address used on the I2C bus connected to the parent adapter.
149 * function is mainly used for lookup & other admin. functions. 154 * @name: Indicates the type of the device, usually a chip name that's
155 * generic enough to hide second-sourcing and compatible revisions.
156 * @dev: Driver model device node for the slave.
157 * @driver_name: Identifies new-style driver used with this device; also
158 * used as the module name for hotplug/coldplug modprobe support.
159 *
160 * An i2c_client identifies a single device (i.e. chip) connected to an
161 * i2c bus. The behaviour is defined by the routines of the driver.
150 */ 162 */
151struct i2c_client { 163struct i2c_client {
152 unsigned int flags; /* div., see below */ 164 unsigned short flags; /* div., see below */
153 unsigned short addr; /* chip address - NOTE: 7bit */ 165 unsigned short addr; /* chip address - NOTE: 7bit */
154 /* addresses are stored in the */ 166 /* addresses are stored in the */
155 /* _LOWER_ 7 bits */ 167 /* _LOWER_ 7 bits */
168 char name[I2C_NAME_SIZE];
156 struct i2c_adapter *adapter; /* the adapter we sit on */ 169 struct i2c_adapter *adapter; /* the adapter we sit on */
157 struct i2c_driver *driver; /* and our access routines */ 170 struct i2c_driver *driver; /* and our access routines */
158 int usage_count; /* How many accesses currently */ 171 int usage_count; /* How many accesses currently */
159 /* to the client */ 172 /* to the client */
160 struct device dev; /* the device structure */ 173 struct device dev; /* the device structure */
174 int irq; /* irq issued by device (or -1) */
175 char driver_name[KOBJ_NAME_LEN];
161 struct list_head list; 176 struct list_head list;
162 char name[I2C_NAME_SIZE];
163 struct completion released; 177 struct completion released;
164}; 178};
165#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 179#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
@@ -179,6 +193,76 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
179 dev_set_drvdata (&dev->dev, data); 193 dev_set_drvdata (&dev->dev, data);
180} 194}
181 195
196/**
197 * struct i2c_board_info - template for device creation
198 * @driver_name: identifies the driver to be bound to the device
199 * @type: optional chip type information, to initialize i2c_client.name
200 * @flags: to initialize i2c_client.flags
201 * @addr: stored in i2c_client.addr
202 * @platform_data: stored in i2c_client.dev.platform_data
203 * @irq: stored in i2c_client.irq
204
205 * I2C doesn't actually support hardware probing, although controllers and
206 * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's
207 * a device at a given address. Drivers commonly need more information than
208 * that, such as chip type, configuration, associated IRQ, and so on.
209 *
210 * i2c_board_info is used to build tables of information listing I2C devices
211 * that are present. This information is used to grow the driver model tree
212 * for "new style" I2C drivers. For mainboards this is done statically using
213 * i2c_register_board_info(), where @bus_num represents an adapter that isn't
214 * yet available. For add-on boards, i2c_new_device() does this dynamically
215 * with the adapter already known.
216 */
217struct i2c_board_info {
218 char driver_name[KOBJ_NAME_LEN];
219 char type[I2C_NAME_SIZE];
220 unsigned short flags;
221 unsigned short addr;
222 void *platform_data;
223 int irq;
224};
225
226/**
227 * I2C_BOARD_INFO - macro used to list an i2c device and its driver
228 * @driver: identifies the driver to use with the device
229 * @dev_addr: the device's address on the bus.
230 *
231 * This macro initializes essential fields of a struct i2c_board_info,
232 * declaring what has been provided on a particular board. Optional
233 * fields (such as the chip type, its associated irq, or device-specific
234 * platform_data) are provided using conventional syntax.
235 */
236#define I2C_BOARD_INFO(driver,dev_addr) \
237 .driver_name = (driver), .addr = (dev_addr)
238
239
240/* Add-on boards should register/unregister their devices; e.g. a board
241 * with integrated I2C, a config eeprom, sensors, and a codec that's
242 * used in conjunction with the primary hardware.
243 */
244extern struct i2c_client *
245i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
246
247/* If you don't know the exact address of an I2C device, use this variant
248 * instead, which can probe for device presence in a list of possible
249 * addresses.
250 */
251extern struct i2c_client *
252i2c_new_probed_device(struct i2c_adapter *adap,
253 struct i2c_board_info *info,
254 unsigned short const *addr_list);
255
256extern void i2c_unregister_device(struct i2c_client *);
257
258/* Mainboard arch_initcall() code should register all its I2C devices.
259 * This is done at arch_initcall time, before declaring any i2c adapters.
260 * Modules for add-on boards must use other calls.
261 */
262extern int
263i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n);
264
265
182/* 266/*
183 * The following structs are for those who like to implement new bus drivers: 267 * The following structs are for those who like to implement new bus drivers:
184 * i2c_algorithm is the interface to a class of hardware solutions which can 268 * i2c_algorithm is the interface to a class of hardware solutions which can
@@ -228,17 +312,14 @@ struct i2c_adapter {
228 int timeout; 312 int timeout;
229 int retries; 313 int retries;
230 struct device dev; /* the adapter device */ 314 struct device dev; /* the adapter device */
231 struct class_device class_dev; /* the class device */
232 315
233 int nr; 316 int nr;
234 struct list_head clients; 317 struct list_head clients;
235 struct list_head list; 318 struct list_head list;
236 char name[I2C_NAME_SIZE]; 319 char name[48];
237 struct completion dev_released; 320 struct completion dev_released;
238 struct completion class_dev_released;
239}; 321};
240#define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 322#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
241#define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev)
242 323
243static inline void *i2c_get_adapdata (struct i2c_adapter *dev) 324static inline void *i2c_get_adapdata (struct i2c_adapter *dev)
244{ 325{
@@ -290,9 +371,10 @@ struct i2c_client_address_data {
290 */ 371 */
291extern int i2c_add_adapter(struct i2c_adapter *); 372extern int i2c_add_adapter(struct i2c_adapter *);
292extern int i2c_del_adapter(struct i2c_adapter *); 373extern int i2c_del_adapter(struct i2c_adapter *);
374extern int i2c_add_numbered_adapter(struct i2c_adapter *);
293 375
294extern int i2c_register_driver(struct module *, struct i2c_driver *); 376extern int i2c_register_driver(struct module *, struct i2c_driver *);
295extern int i2c_del_driver(struct i2c_driver *); 377extern void i2c_del_driver(struct i2c_driver *);
296 378
297static inline int i2c_add_driver(struct i2c_driver *driver) 379static inline int i2c_add_driver(struct i2c_driver *driver)
298{ 380{
@@ -365,6 +447,7 @@ struct i2c_msg {
365#define I2C_M_REV_DIR_ADDR 0x2000 447#define I2C_M_REV_DIR_ADDR 0x2000
366#define I2C_M_IGNORE_NAK 0x1000 448#define I2C_M_IGNORE_NAK 0x1000
367#define I2C_M_NO_RD_ACK 0x0800 449#define I2C_M_NO_RD_ACK 0x0800
450#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
368 __u16 len; /* msg length */ 451 __u16 len; /* msg length */
369 __u8 *buf; /* pointer to msg data */ 452 __u8 *buf; /* pointer to msg data */
370}; 453};
diff --git a/include/linux/input.h b/include/linux/input.h
index bde65c8a3519..327122548c4d 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -676,6 +676,7 @@ struct input_absinfo {
676#define BUS_I2C 0x18 676#define BUS_I2C 0x18
677#define BUS_HOST 0x19 677#define BUS_HOST 0x19
678#define BUS_GSC 0x1A 678#define BUS_GSC 0x1A
679#define BUS_ATARI 0x1B
679 680
680/* 681/*
681 * Values describing the status of a force-feedback effect 682 * Values describing the status of a force-feedback effect
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 838cf5a5bd7f..0319f665dd3f 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -185,10 +185,14 @@ static inline int disable_irq_wake(unsigned int irq)
185 * validator need to define the methods below in their asm/irq.h 185 * validator need to define the methods below in their asm/irq.h
186 * files, under an #ifdef CONFIG_LOCKDEP section. 186 * files, under an #ifdef CONFIG_LOCKDEP section.
187 */ 187 */
188# ifndef CONFIG_LOCKDEP 188#ifndef CONFIG_LOCKDEP
189# define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq) 189# define disable_irq_nosync_lockdep(irq) disable_irq_nosync(irq)
190# define disable_irq_nosync_lockdep_irqsave(irq, flags) \
191 disable_irq_nosync(irq)
190# define disable_irq_lockdep(irq) disable_irq(irq) 192# define disable_irq_lockdep(irq) disable_irq(irq)
191# define enable_irq_lockdep(irq) enable_irq(irq) 193# define enable_irq_lockdep(irq) enable_irq(irq)
194# define enable_irq_lockdep_irqrestore(irq, flags) \
195 enable_irq(irq)
192# endif 196# endif
193 197
194#endif /* CONFIG_GENERIC_HARDIRQS */ 198#endif /* CONFIG_GENERIC_HARDIRQS */
diff --git a/include/linux/nubus.h b/include/linux/nubus.h
index 870e66a96286..cdb3e9b8db54 100644
--- a/include/linux/nubus.h
+++ b/include/linux/nubus.h
@@ -28,18 +28,18 @@ enum nubus_category {
28}; 28};
29 29
30enum nubus_type_network { 30enum nubus_type_network {
31 NUBUS_TYPE_ETHERNET = 0x0001, 31 NUBUS_TYPE_ETHERNET = 0x0001,
32 NUBUS_TYPE_RS232 = 0x0002 32 NUBUS_TYPE_RS232 = 0x0002
33}; 33};
34 34
35enum nubus_type_display { 35enum nubus_type_display {
36 NUBUS_TYPE_VIDEO = 0x0001 36 NUBUS_TYPE_VIDEO = 0x0001
37}; 37};
38 38
39enum nubus_type_cpu { 39enum nubus_type_cpu {
40 NUBUS_TYPE_68020 = 0x0003, 40 NUBUS_TYPE_68020 = 0x0003,
41 NUBUS_TYPE_68030 = 0x0004, 41 NUBUS_TYPE_68030 = 0x0004,
42 NUBUS_TYPE_68040 = 0x0005 42 NUBUS_TYPE_68040 = 0x0005
43}; 43};
44 44
45/* Known <Cat,Type,SW,HW> tuples: (according to TattleTech and Slots) 45/* Known <Cat,Type,SW,HW> tuples: (according to TattleTech and Slots)
@@ -56,6 +56,7 @@ enum nubus_type_cpu {
56 * 56 *
57 * SONIC comm-slot/on-board and DuoDock Ethernet: <4,1,1,272> 57 * SONIC comm-slot/on-board and DuoDock Ethernet: <4,1,1,272>
58 * SONIC LC-PDS Ethernet (Dayna, but like Apple 16-bit, sort of): <4,1,1,271> 58 * SONIC LC-PDS Ethernet (Dayna, but like Apple 16-bit, sort of): <4,1,1,271>
59 * Apple SONIC LC-PDS Ethernet ("Apple Ethernet LC Twisted-Pair Card"): <4,1,0,281>
59 * Sonic Systems Ethernet A-Series Card: <4,1,268,256> 60 * Sonic Systems Ethernet A-Series Card: <4,1,268,256>
60 * Asante MacCon NuBus-A: <4,1,260,256> (alpha-1.0,1.1 revision) 61 * Asante MacCon NuBus-A: <4,1,260,256> (alpha-1.0,1.1 revision)
61 * ROM on the above card: <2,1,0,0> 62 * ROM on the above card: <2,1,0,0>
@@ -80,24 +81,26 @@ enum nubus_type_cpu {
80/* Add known DrSW values here */ 81/* Add known DrSW values here */
81enum nubus_drsw { 82enum nubus_drsw {
82 /* NUBUS_CAT_DISPLAY */ 83 /* NUBUS_CAT_DISPLAY */
83 NUBUS_DRSW_APPLE = 0x0001, 84 NUBUS_DRSW_APPLE = 0x0001,
84 NUBUS_DRSW_APPLE_HIRES = 0x0013, /* MacII HiRes card driver */ 85 NUBUS_DRSW_APPLE_HIRES = 0x0013, /* MacII HiRes card driver */
85 86
86 /* NUBUS_CAT_NETWORK */ 87 /* NUBUS_CAT_NETWORK */
87 NUBUS_DRSW_CABLETRON = 0x0001, 88 NUBUS_DRSW_3COM = 0x0000,
88 NUBUS_DRSW_SONIC_LC = 0x0001, 89 NUBUS_DRSW_CABLETRON = 0x0001,
89 NUBUS_DRSW_KINETICS = 0x0103, 90 NUBUS_DRSW_SONIC_LC = 0x0001,
90 NUBUS_DRSW_ASANTE = 0x0104, 91 NUBUS_DRSW_KINETICS = 0x0103,
91 NUBUS_DRSW_DAYNA = 0x010b, 92 NUBUS_DRSW_ASANTE = 0x0104,
92 NUBUS_DRSW_FARALLON = 0x010c, 93 NUBUS_DRSW_TECHWORKS = 0x0109,
93 NUBUS_DRSW_APPLE_SN = 0x010f, 94 NUBUS_DRSW_DAYNA = 0x010b,
94 NUBUS_DRSW_DAYNA2 = 0x0115, 95 NUBUS_DRSW_FARALLON = 0x010c,
96 NUBUS_DRSW_APPLE_SN = 0x010f,
97 NUBUS_DRSW_DAYNA2 = 0x0115,
95 NUBUS_DRSW_FOCUS = 0x011a, 98 NUBUS_DRSW_FOCUS = 0x011a,
96 NUBUS_DRSW_ASANTE_CS = 0x011d, /* use asante SMC9194 driver */ 99 NUBUS_DRSW_ASANTE_CS = 0x011d, /* use asante SMC9194 driver */
97 NUBUS_DRSW_DAYNA_LC = 0x011e, 100 NUBUS_DRSW_DAYNA_LC = 0x011e,
98 101
99 /* NUBUS_CAT_CPU */ 102 /* NUBUS_CAT_CPU */
100 NUBUS_DRSW_NONE = 0x0000, 103 NUBUS_DRSW_NONE = 0x0000,
101}; 104};
102 105
103/* DrHW: Uniquely identifies the hardware interface to a board (or at 106/* DrHW: Uniquely identifies the hardware interface to a board (or at
@@ -107,27 +110,48 @@ enum nubus_drsw {
107/* Add known DrHW values here */ 110/* Add known DrHW values here */
108enum nubus_drhw { 111enum nubus_drhw {
109 /* NUBUS_CAT_DISPLAY */ 112 /* NUBUS_CAT_DISPLAY */
110 NUBUS_DRHW_APPLE_TFB = 0x0001, /* Toby frame buffer card */ 113 NUBUS_DRHW_APPLE_TFB = 0x0001, /* Toby frame buffer card */
111 NUBUS_DRHW_APPLE_HRVC = 0x0013, /* Mac II High Res Video card */ 114 NUBUS_DRHW_APPLE_WVC = 0x0006, /* Apple Workstation Video Card */
112 NUBUS_DRHW_APPLE_RBV1 = 0x0018, /* IIci RBV video */ 115 NUBUS_DRHW_SIGMA_CLRMAX = 0x0007, /* Sigma Design ColorMax */
113 NUBUS_DRHW_APPLE_MDC = 0x0019, /* Macintosh Display Card */ 116 NUBUS_DRHW_APPLE_SE30 = 0x0009, /* Apple SE/30 video */
114 NUBUS_DRHW_APPLE_SONORA = 0x0022, /* Sonora built-in video */ 117 NUBUS_DRHW_APPLE_HRVC = 0x0013, /* Mac II High-Res Video Card */
115 NUBUS_DRHW_APPLE_JET = 0x0029, /* Jet framebuffer (DuoDock) */ 118 NUBUS_DRHW_APPLE_PVC = 0x0017, /* Mac II Portrait Video Card */
119 NUBUS_DRHW_APPLE_RBV1 = 0x0018, /* IIci RBV video */
120 NUBUS_DRHW_APPLE_MDC = 0x0019, /* Macintosh Display Card */
121 NUBUS_DRHW_APPLE_SONORA = 0x0022, /* Sonora built-in video */
122 NUBUS_DRHW_APPLE_24AC = 0x002b, /* Mac 24AC Video Card */
116 NUBUS_DRHW_APPLE_VALKYRIE = 0x002e, 123 NUBUS_DRHW_APPLE_VALKYRIE = 0x002e,
117 NUBUS_DRHW_THUNDER24 = 0x02cb, /* SuperMac Thunder/24 */ 124 NUBUS_DRHW_APPLE_JET = 0x0029, /* Jet framebuffer (DuoDock) */
125 NUBUS_DRHW_SMAC_GFX = 0x0105, /* SuperMac GFX */
126 NUBUS_DRHW_RASTER_CB264 = 0x013B, /* RasterOps ColorBoard 264 */
127 NUBUS_DRHW_MICRON_XCEED = 0x0146, /* Micron Exceed color */
128 NUBUS_DRHW_RDIUS_GSC = 0x0153, /* Radius GS/C */
129 NUBUS_DRHW_SMAC_SPEC8 = 0x017B, /* SuperMac Spectrum/8 */
130 NUBUS_DRHW_SMAC_SPEC24 = 0x017C, /* SuperMac Spectrum/24 */
131 NUBUS_DRHW_RASTER_CB364 = 0x026F, /* RasterOps ColorBoard 364 */
132 NUBUS_DRHW_RDIUS_DCGX = 0x027C, /* Radius DirectColor/GX */
133 NUBUS_DRHW_RDIUS_PC8 = 0x0291, /* Radius PrecisionColor 8 */
134 NUBUS_DRHW_LAPIS_PCS8 = 0x0292, /* Lapis ProColorServer 8 */
135 NUBUS_DRHW_RASTER_24LXI = 0x02A0, /* RasterOps 8/24 XLi */
136 NUBUS_DRHW_RASTER_PBPGT = 0x02A5, /* RasterOps PaintBoard Prism GT */
137 NUBUS_DRHW_EMACH_FSX = 0x02AE, /* E-Machines Futura SX */
138 NUBUS_DRHW_SMAC_THUND24 = 0x02CB, /* SuperMac Thunder/24 */
139 NUBUS_DRHW_RDIUS_PC24XP = 0x0406, /* Radius PrecisionColor 24Xp */
140 NUBUS_DRHW_RDIUS_PC24X = 0x040A, /* Radius PrecisionColor 24X */
141 NUBUS_DRHW_RDIUS_PC8XJ = 0x040B, /* Radius PrecisionColor 8XJ */
118 142
119 /* NUBUS_CAT_NETWORK */ 143 /* NUBUS_CAT_NETWORK */
120 NUBUS_DRHW_INTERLAN = 0x0100, 144 NUBUS_DRHW_INTERLAN = 0x0100,
121 NUBUS_DRHW_SMC9194 = 0x0101, 145 NUBUS_DRHW_SMC9194 = 0x0101,
122 NUBUS_DRHW_KINETICS = 0x0106, 146 NUBUS_DRHW_KINETICS = 0x0106,
123 NUBUS_DRHW_CABLETRON = 0x0109, 147 NUBUS_DRHW_CABLETRON = 0x0109,
124 NUBUS_DRHW_ASANTE_LC = 0x010f, 148 NUBUS_DRHW_ASANTE_LC = 0x010f,
125 NUBUS_DRHW_SONIC = 0x0110, 149 NUBUS_DRHW_SONIC = 0x0110,
126 NUBUS_DRHW_SONIC_NB = 0x0118, 150 NUBUS_DRHW_TECHWORKS = 0x0112,
127 NUBUS_DRHW_SONIC_LC = 0x0119, 151 NUBUS_DRHW_APPLE_SONIC_NB = 0x0118,
128 152 NUBUS_DRHW_APPLE_SONIC_LC = 0x0119,
129 /* NUBUS_CAT_COMMUNICATIONS */ 153 NUBUS_DRHW_FOCUS = 0x011c,
130 NUBUS_DRHW_DOVEFAX = 0x0100, 154 NUBUS_DRHW_SONNET = 0x011d,
131}; 155};
132 156
133/* Resource IDs: These are the identifiers for the various weird and 157/* Resource IDs: These are the identifiers for the various weird and
@@ -153,17 +177,17 @@ enum nubus_res_id {
153 177
154/* Category-specific resources. */ 178/* Category-specific resources. */
155enum nubus_board_res_id { 179enum nubus_board_res_id {
156 NUBUS_RESID_BOARDID = 0x0020, 180 NUBUS_RESID_BOARDID = 0x0020,
157 NUBUS_RESID_PRAMINITDATA = 0x0021, 181 NUBUS_RESID_PRAMINITDATA = 0x0021,
158 NUBUS_RESID_PRIMARYINIT = 0x0022, 182 NUBUS_RESID_PRIMARYINIT = 0x0022,
159 NUBUS_RESID_TIMEOUTCONST = 0x0023, 183 NUBUS_RESID_TIMEOUTCONST = 0x0023,
160 NUBUS_RESID_VENDORINFO = 0x0024, 184 NUBUS_RESID_VENDORINFO = 0x0024,
161 NUBUS_RESID_BOARDFLAGS = 0x0025, 185 NUBUS_RESID_BOARDFLAGS = 0x0025,
162 NUBUS_RESID_SECONDINIT = 0x0026, 186 NUBUS_RESID_SECONDINIT = 0x0026,
163 187
164 /* Not sure why Apple put these next two in here */ 188 /* Not sure why Apple put these next two in here */
165 NUBUS_RESID_VIDNAMES = 0x0041, 189 NUBUS_RESID_VIDNAMES = 0x0041,
166 NUBUS_RESID_VIDMODES = 0x007e 190 NUBUS_RESID_VIDMODES = 0x007e
167}; 191};
168 192
169/* Fields within the vendor info directory */ 193/* Fields within the vendor info directory */
@@ -185,13 +209,13 @@ enum nubus_cpu_res_id {
185}; 209};
186 210
187enum nubus_display_res_id { 211enum nubus_display_res_id {
188 NUBUS_RESID_GAMMADIR = 0x0040, 212 NUBUS_RESID_GAMMADIR = 0x0040,
189 NUBUS_RESID_FIRSTMODE = 0x0080, 213 NUBUS_RESID_FIRSTMODE = 0x0080,
190 NUBUS_RESID_SECONDMODE = 0x0081, 214 NUBUS_RESID_SECONDMODE = 0x0081,
191 NUBUS_RESID_THIRDMODE = 0x0082, 215 NUBUS_RESID_THIRDMODE = 0x0082,
192 NUBUS_RESID_FOURTHMODE = 0x0083, 216 NUBUS_RESID_FOURTHMODE = 0x0083,
193 NUBUS_RESID_FIFTHMODE = 0x0084, 217 NUBUS_RESID_FIFTHMODE = 0x0084,
194 NUBUS_RESID_SIXTHMODE = 0x0085 218 NUBUS_RESID_SIXTHMODE = 0x0085
195}; 219};
196 220
197struct nubus_dir 221struct nubus_dir
@@ -214,7 +238,7 @@ struct nubus_board {
214 struct nubus_board* next; 238 struct nubus_board* next;
215 struct nubus_dev* first_dev; 239 struct nubus_dev* first_dev;
216 240
217 /* Only 9-E actually exist, though 0-8 are also theoretically 241 /* Only 9-E actually exist, though 0-8 are also theoretically
218 possible, and 0 is a special case which represents the 242 possible, and 0 is a special case which represents the
219 motherboard and onboard peripherals (Ethernet, video) */ 243 motherboard and onboard peripherals (Ethernet, video) */
220 int slot; 244 int slot;
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 1b0ddbb8a804..5a48e963d06b 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1213,11 +1213,13 @@
1213#define PCI_DEVICE_ID_NVIDIA_NVENET_16 0x03E5 1213#define PCI_DEVICE_ID_NVIDIA_NVENET_16 0x03E5
1214#define PCI_DEVICE_ID_NVIDIA_NVENET_17 0x03E6 1214#define PCI_DEVICE_ID_NVIDIA_NVENET_17 0x03E6
1215#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA 0x03E7 1215#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA 0x03E7
1216#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS 0x03EB
1216#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE 0x03EC 1217#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE 0x03EC
1217#define PCI_DEVICE_ID_NVIDIA_NVENET_18 0x03EE 1218#define PCI_DEVICE_ID_NVIDIA_NVENET_18 0x03EE
1218#define PCI_DEVICE_ID_NVIDIA_NVENET_19 0x03EF 1219#define PCI_DEVICE_ID_NVIDIA_NVENET_19 0x03EF
1219#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2 0x03F6 1220#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2 0x03F6
1220#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3 0x03F7 1221#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3 0x03F7
1222#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS 0x0446
1221#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE 0x0448 1223#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE 0x0448
1222#define PCI_DEVICE_ID_NVIDIA_NVENET_20 0x0450 1224#define PCI_DEVICE_ID_NVIDIA_NVENET_20 0x0450
1223#define PCI_DEVICE_ID_NVIDIA_NVENET_21 0x0451 1225#define PCI_DEVICE_ID_NVIDIA_NVENET_21 0x0451
diff --git a/include/media/ovcamchip.h b/include/media/ovcamchip.h
index 0f43451f8bb3..05b9569ef1c8 100644
--- a/include/media/ovcamchip.h
+++ b/include/media/ovcamchip.h
@@ -16,7 +16,6 @@
16 16
17#include <linux/videodev.h> 17#include <linux/videodev.h>
18#include <media/v4l2-common.h> 18#include <media/v4l2-common.h>
19#include <linux/i2c.h>
20 19
21/* --------------------------------- */ 20/* --------------------------------- */
22/* ENUMERATIONS */ 21/* ENUMERATIONS */
diff --git a/include/media/tuner.h b/include/media/tuner.h
index a41ac41113ac..6dcf3c45707d 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -23,6 +23,7 @@
23#define _TUNER_H 23#define _TUNER_H
24 24
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <linux/i2c.h>
26#include <media/tuner-types.h> 27#include <media/tuner-types.h>
27 28
28extern int tuner_debug; 29extern int tuner_debug;
diff --git a/sound/oss/dmasound/tas_ioctl.h b/sound/oss/dmasound/tas_ioctl.h
index dccae3a40e01..9d12b373b4a9 100644
--- a/sound/oss/dmasound/tas_ioctl.h
+++ b/sound/oss/dmasound/tas_ioctl.h
@@ -1,7 +1,6 @@
1#ifndef _TAS_IOCTL_H_ 1#ifndef _TAS_IOCTL_H_
2#define _TAS_IOCTL_H_ 2#define _TAS_IOCTL_H_
3 3
4#include <linux/i2c.h>
5#include <linux/soundcard.h> 4#include <linux/soundcard.h>
6 5
7 6