aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/kernel-parameters.txt32
-rw-r--r--Documentation/sony-laptop.txt25
-rw-r--r--Documentation/thinkpad-acpi.txt (renamed from Documentation/ibm-acpi.txt)585
-rw-r--r--Documentation/video4linux/meye.txt7
-rw-r--r--MAINTAINERS18
-rw-r--r--arch/i386/defconfig1
-rw-r--r--arch/i386/kernel/acpi/earlyquirk.c5
-rw-r--r--arch/parisc/configs/c3000_defconfig1
-rw-r--r--arch/x86_64/defconfig1
-rw-r--r--drivers/acpi/Kconfig44
-rw-r--r--drivers/acpi/Makefile10
-rw-r--r--drivers/acpi/acpi_memhotplug.c13
-rw-r--r--drivers/acpi/bus.c4
-rw-r--r--drivers/acpi/container.c6
-rw-r--r--drivers/acpi/dock.c25
-rw-r--r--drivers/acpi/ec.c495
-rw-r--r--drivers/acpi/i2c_ec.c403
-rw-r--r--drivers/acpi/i2c_ec.h23
-rw-r--r--drivers/acpi/ibm_acpi.c2798
-rw-r--r--drivers/acpi/processor_core.c4
-rw-r--r--drivers/acpi/processor_idle.c8
-rw-r--r--drivers/acpi/sbs.c1291
-rw-r--r--drivers/acpi/scan.c4
-rw-r--r--drivers/acpi/sleep/proc.c16
-rw-r--r--drivers/acpi/tables/tbfadt.c12
-rw-r--r--drivers/ata/Kconfig43
-rw-r--r--drivers/ata/Makefile1
-rw-r--r--drivers/ata/ahci.c473
-rw-r--r--drivers/ata/ata_generic.c32
-rw-r--r--drivers/ata/ata_piix.c56
-rw-r--r--drivers/ata/libata-core.c1015
-rw-r--r--drivers/ata/libata-eh.c15
-rw-r--r--drivers/ata/libata-scsi.c85
-rw-r--r--drivers/ata/libata-sff.c631
-rw-r--r--drivers/ata/libata.h10
-rw-r--r--drivers/ata/pata_ali.c74
-rw-r--r--drivers/ata/pata_amd.c89
-rw-r--r--drivers/ata/pata_artop.c26
-rw-r--r--drivers/ata/pata_atiixp.c26
-rw-r--r--drivers/ata/pata_cmd640.c312
-rw-r--r--drivers/ata/pata_cmd64x.c34
-rw-r--r--drivers/ata/pata_cs5520.c145
-rw-r--r--drivers/ata/pata_cs5530.c15
-rw-r--r--drivers/ata/pata_cs5535.c24
-rw-r--r--drivers/ata/pata_cypress.c14
-rw-r--r--drivers/ata/pata_efar.c31
-rw-r--r--drivers/ata/pata_hpt366.c26
-rw-r--r--drivers/ata/pata_hpt37x.c381
-rw-r--r--drivers/ata/pata_hpt3x2n.c74
-rw-r--r--drivers/ata/pata_hpt3x3.c22
-rw-r--r--drivers/ata/pata_isapnp.c44
-rw-r--r--drivers/ata/pata_it8213.c36
-rw-r--r--drivers/ata/pata_it821x.c36
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c40
-rw-r--r--drivers/ata/pata_legacy.c45
-rw-r--r--drivers/ata/pata_marvell.c20
-rw-r--r--drivers/ata/pata_mpc52xx.c49
-rw-r--r--drivers/ata/pata_mpiix.c40
-rw-r--r--drivers/ata/pata_netcell.c31
-rw-r--r--drivers/ata/pata_ns87410.c6
-rw-r--r--drivers/ata/pata_oldpiix.c6
-rw-r--r--drivers/ata/pata_opti.c5
-rw-r--r--drivers/ata/pata_optidma.c54
-rw-r--r--drivers/ata/pata_pcmcia.c77
-rw-r--r--drivers/ata/pata_pdc2027x.c158
-rw-r--r--drivers/ata/pata_pdc202xx_old.c45
-rw-r--r--drivers/ata/pata_platform.c44
-rw-r--r--drivers/ata/pata_qdi.c47
-rw-r--r--drivers/ata/pata_radisys.c37
-rw-r--r--drivers/ata/pata_rz1000.c28
-rw-r--r--drivers/ata/pata_sc1200.c1
-rw-r--r--drivers/ata/pata_scc.c51
-rw-r--r--drivers/ata/pata_serverworks.c34
-rw-r--r--drivers/ata/pata_sil680.c11
-rw-r--r--drivers/ata/pata_sis.c109
-rw-r--r--drivers/ata/pata_sl82c105.c2
-rw-r--r--drivers/ata/pata_triflex.c4
-rw-r--r--drivers/ata/pata_via.c27
-rw-r--r--drivers/ata/pata_winbond.c101
-rw-r--r--drivers/ata/pdc_adma.c85
-rw-r--r--drivers/ata/sata_inic162x.c86
-rw-r--r--drivers/ata/sata_mv.c213
-rw-r--r--drivers/ata/sata_nv.c130
-rw-r--r--drivers/ata/sata_promise.c398
-rw-r--r--drivers/ata/sata_qstor.c62
-rw-r--r--drivers/ata/sata_sil.c118
-rw-r--r--drivers/ata/sata_sil24.c122
-rw-r--r--drivers/ata/sata_sis.c50
-rw-r--r--drivers/ata/sata_svw.c107
-rw-r--r--drivers/ata/sata_sx4.c150
-rw-r--r--drivers/ata/sata_uli.c65
-rw-r--r--drivers/ata/sata_via.c217
-rw-r--r--drivers/ata/sata_vsc.c72
-rw-r--r--drivers/char/sonypi.c53
-rw-r--r--drivers/clocksource/acpi_pm.c2
-rw-r--r--drivers/media/video/Kconfig6
-rw-r--r--drivers/media/video/meye.c62
-rw-r--r--drivers/media/video/meye.h2
-rw-r--r--drivers/misc/Kconfig66
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/asus-laptop.c151
-rw-r--r--drivers/misc/sony-laptop.c2131
-rw-r--r--drivers/misc/thinkpad_acpi.c4312
-rw-r--r--drivers/misc/thinkpad_acpi.h572
-rw-r--r--drivers/pci/pci-acpi.c4
-rw-r--r--drivers/pci/quirks.c113
-rw-r--r--drivers/scsi/ipr.c3
-rw-r--r--include/acpi/actbl.h1
-rw-r--r--include/linux/ata.h10
-rw-r--r--include/linux/ioport.h1
-rw-r--r--include/linux/libata.h78
-rw-r--r--include/linux/pci.h1
-rw-r--r--include/linux/pci_ids.h1
-rw-r--r--include/linux/sony-laptop.h34
-rw-r--r--kernel/resource.c21
-rw-r--r--lib/devres.c26
116 files changed, 12152 insertions, 8047 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 2017942e0966..84c3bd05c639 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -181,19 +181,41 @@ and is between 256 and 4096 characters. It is defined in the file
181 that require a timer override, but don't have 181 that require a timer override, but don't have
182 HPET 182 HPET
183 183
184 acpi_dbg_layer= [HW,ACPI] 184 acpi.debug_layer= [HW,ACPI]
185 Format: <int> 185 Format: <int>
186 Each bit of the <int> indicates an ACPI debug layer, 186 Each bit of the <int> indicates an ACPI debug layer,
187 1: enable, 0: disable. It is useful for boot time 187 1: enable, 0: disable. It is useful for boot time
188 debugging. After system has booted up, it can be set 188 debugging. After system has booted up, it can be set
189 via /proc/acpi/debug_layer. 189 via /sys/module/acpi/parameters/debug_layer.
190 190 CONFIG_ACPI_DEBUG must be enabled for this to produce any output.
191 acpi_dbg_level= [HW,ACPI] 191 Available bits (add the numbers together) to enable debug output
192 for specific parts of the ACPI subsystem:
193 0x01 utilities 0x02 hardware 0x04 events 0x08 tables
194 0x10 namespace 0x20 parser 0x40 dispatcher
195 0x80 executer 0x100 resources 0x200 acpica debugger
196 0x400 os services 0x800 acpica disassembler.
197 The number can be in decimal or prefixed with 0x in hex.
198 Warning: Many of these options can produce a lot of
199 output and make your system unusable. Be very careful.
200
201 acpi.debug_level= [HW,ACPI]
192 Format: <int> 202 Format: <int>
193 Each bit of the <int> indicates an ACPI debug level, 203 Each bit of the <int> indicates an ACPI debug level,
194 1: enable, 0: disable. It is useful for boot time 204 1: enable, 0: disable. It is useful for boot time
195 debugging. After system has booted up, it can be set 205 debugging. After system has booted up, it can be set
196 via /proc/acpi/debug_level. 206 via /sys/module/acpi/parameters/debug_level.
207 CONFIG_ACPI_DEBUG must be enabled for this to produce any output.
208 Available bits (add the numbers together) to enable different
209 debug output levels of the ACPI subsystem:
210 0x01 error 0x02 warn 0x04 init 0x08 debug object
211 0x10 info 0x20 init names 0x40 parse 0x80 load
212 0x100 dispatch 0x200 execute 0x400 names 0x800 operation region
213 0x1000 bfield 0x2000 tables 0x4000 values 0x8000 objects
214 0x10000 resources 0x20000 user requests 0x40000 package.
215 The number can be in decimal or prefixed with 0x in hex.
216 Warning: Many of these options can produce a lot of
217 output and make your system unusable. Be very careful.
218
197 219
198 acpi_fake_ecdt [HW,ACPI] Workaround failure due to BIOS lacking ECDT 220 acpi_fake_ecdt [HW,ACPI] Workaround failure due to BIOS lacking ECDT
199 221
diff --git a/Documentation/sony-laptop.txt b/Documentation/sony-laptop.txt
index dfd26df056f4..7a5c1a81905c 100644
--- a/Documentation/sony-laptop.txt
+++ b/Documentation/sony-laptop.txt
@@ -3,12 +3,18 @@ Sony Notebook Control Driver (SNC) Readme
3 Copyright (C) 2004- 2005 Stelian Pop <stelian@popies.net> 3 Copyright (C) 2004- 2005 Stelian Pop <stelian@popies.net>
4 Copyright (C) 2007 Mattia Dongili <malattia@linux.it> 4 Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
5 5
6This mini-driver drives the SNC device present in the ACPI BIOS of 6This mini-driver drives the SNC and SPIC device present in the ACPI BIOS of the
7the Sony Vaio laptops. 7Sony Vaio laptops. This driver mixes both devices functions under the same
8(hopefully consistent) interface. This also means that the sonypi driver is
9obsoleted by sony-laptop now.
8 10
9It gives access to some extra laptop functionalities. In its current 11Fn keys (hotkeys):
10form, this driver let the user set or query the screen brightness 12------------------
11through the backlight subsystem and remove/apply power to some devices. 13Some models report hotkeys through the SNC or SPIC devices, such events are
14reported both through the ACPI subsystem as acpi events and through the INPUT
15subsystem. See the logs of acpid or /proc/acpi/event and
16/proc/bus/input/devices to find out what those events are and which input
17devices are created by the driver.
12 18
13Backlight control: 19Backlight control:
14------------------ 20------------------
@@ -39,6 +45,8 @@ The files are:
39 audiopower power on/off the internal sound card 45 audiopower power on/off the internal sound card
40 lanpower power on/off the internal ethernet card 46 lanpower power on/off the internal ethernet card
41 (only in debug mode) 47 (only in debug mode)
48 bluetoothpower power on/off the internal bluetooth device
49 fanspeed get/set the fan speed
42 50
43Note that some files may be missing if they are not supported 51Note that some files may be missing if they are not supported
44by your particular laptop model. 52by your particular laptop model.
@@ -76,9 +84,9 @@ The sony-laptop driver creates, for some of those methods (the most
76current ones found on several Vaio models), an entry under 84current ones found on several Vaio models), an entry under
77/sys/devices/platform/sony-laptop, just like the 'cdpower' one. 85/sys/devices/platform/sony-laptop, just like the 'cdpower' one.
78You can create other entries corresponding to your own laptop methods by 86You can create other entries corresponding to your own laptop methods by
79further editing the source (see the 'sony_acpi_values' table, and add a new 87further editing the source (see the 'sony_nc_values' table, and add a new
80entry to this table with your get/set method names using the 88entry to this table with your get/set method names using the
81HANDLE_NAMES macro). 89SNC_HANDLE_NAMES macro).
82 90
83Your mission, should you accept it, is to try finding out what 91Your mission, should you accept it, is to try finding out what
84those entries are for, by reading/writing random values from/to those 92those entries are for, by reading/writing random values from/to those
@@ -87,6 +95,9 @@ files and find out what is the impact on your laptop.
87Should you find anything interesting, please report it back to me, 95Should you find anything interesting, please report it back to me,
88I will not disavow all knowledge of your actions :) 96I will not disavow all knowledge of your actions :)
89 97
98See also http://www.linux.it/~malattia/wiki/index.php/Sony_drivers for other
99useful info.
100
90Bugs/Limitations: 101Bugs/Limitations:
91----------------- 102-----------------
92 103
diff --git a/Documentation/ibm-acpi.txt b/Documentation/thinkpad-acpi.txt
index 0132d363feb5..2d4803359a04 100644
--- a/Documentation/ibm-acpi.txt
+++ b/Documentation/thinkpad-acpi.txt
@@ -1,16 +1,22 @@
1 IBM ThinkPad ACPI Extras Driver 1 ThinkPad ACPI Extras Driver
2 2
3 Version 0.12 3 Version 0.14
4 17 August 2005 4 April 21st, 2007
5 5
6 Borislav Deianov <borislav@users.sf.net> 6 Borislav Deianov <borislav@users.sf.net>
7 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
7 http://ibm-acpi.sf.net/ 8 http://ibm-acpi.sf.net/
8 9
9 10
10This is a Linux ACPI driver for the IBM ThinkPad laptops. It supports 11This is a Linux driver for the IBM and Lenovo ThinkPad laptops. It
11various features of these laptops which are accessible through the 12supports various features of these laptops which are accessible
12ACPI framework but not otherwise supported by the generic Linux ACPI 13through the ACPI and ACPI EC framework, but not otherwise fully
13drivers. 14supported by the generic Linux ACPI drivers.
15
16This driver used to be named ibm-acpi until kernel 2.6.21 and release
170.13-20070314. It used to be in the drivers/acpi tree, but it was
18moved to the drivers/misc tree and renamed to thinkpad-acpi for kernel
192.6.22, and release 0.14.
14 20
15 21
16Status 22Status
@@ -21,7 +27,7 @@ detailed description):
21 27
22 - Fn key combinations 28 - Fn key combinations
23 - Bluetooth enable and disable 29 - Bluetooth enable and disable
24 - video output switching, expansion control 30 - video output switching, expansion control
25 - ThinkLight on and off 31 - ThinkLight on and off
26 - limited docking and undocking 32 - limited docking and undocking
27 - UltraBay eject 33 - UltraBay eject
@@ -32,7 +38,7 @@ detailed description):
32 - Experimental: embedded controller register dump 38 - Experimental: embedded controller register dump
33 - LCD brightness control 39 - LCD brightness control
34 - Volume control 40 - Volume control
35 - Experimental: fan speed, fan enable/disable 41 - Fan control and monitoring: fan speed, fan enable/disable
36 - Experimental: WAN enable and disable 42 - Experimental: WAN enable and disable
37 43
38A compatibility table by model and feature is maintained on the web 44A compatibility table by model and feature is maintained on the web
@@ -42,6 +48,8 @@ Please include the following information in your report:
42 48
43 - ThinkPad model name 49 - ThinkPad model name
44 - a copy of your DSDT, from /proc/acpi/dsdt 50 - a copy of your DSDT, from /proc/acpi/dsdt
51 - a copy of the output of dmidecode, with serial numbers
52 and UUIDs masked off
45 - which driver features work and which don't 53 - which driver features work and which don't
46 - the observed behavior of non-working features 54 - the observed behavior of non-working features
47 55
@@ -52,25 +60,85 @@ Installation
52------------ 60------------
53 61
54If you are compiling this driver as included in the Linux kernel 62If you are compiling this driver as included in the Linux kernel
55sources, simply enable the CONFIG_ACPI_IBM option (Power Management / 63sources, simply enable the CONFIG_THINKPAD_ACPI option, and optionally
56ACPI / IBM ThinkPad Laptop Extras). 64enable the CONFIG_THINKPAD_ACPI_BAY option if you want the
65thinkpad-specific bay functionality.
57 66
58Features 67Features
59-------- 68--------
60 69
61The driver creates the /proc/acpi/ibm directory. There is a file under 70The driver exports two different interfaces to userspace, which can be
62that directory for each feature described below. Note that while the 71used to access the features it provides. One is a legacy procfs-based
63driver is still in the alpha stage, the exact proc file format and 72interface, which will be removed at some time in the distant future.
64commands supported by the various features is guaranteed to change 73The other is a new sysfs-based interface which is not complete yet.
65frequently.
66 74
67Driver version -- /proc/acpi/ibm/driver 75The procfs interface creates the /proc/acpi/ibm directory. There is a
68--------------------------------------- 76file under that directory for each feature it supports. The procfs
77interface is mostly frozen, and will change very little if at all: it
78will not be extended to add any new functionality in the driver, instead
79all new functionality will be implemented on the sysfs interface.
80
81The sysfs interface tries to blend in the generic Linux sysfs subsystems
82and classes as much as possible. Since some of these subsystems are not
83yet ready or stabilized, it is expected that this interface will change,
84and any and all userspace programs must deal with it.
85
86
87Notes about the sysfs interface:
88
89Unlike what was done with the procfs interface, correctness when talking
90to the sysfs interfaces will be enforced, as will correctness in the
91thinkpad-acpi's implementation of sysfs interfaces.
92
93Also, any bugs in the thinkpad-acpi sysfs driver code or in the
94thinkpad-acpi's implementation of the sysfs interfaces will be fixed for
95maximum correctness, even if that means changing an interface in
96non-compatible ways. As these interfaces mature both in the kernel and
97in thinkpad-acpi, such changes should become quite rare.
98
99Applications interfacing to the thinkpad-acpi sysfs interfaces must
100follow all sysfs guidelines and correctly process all errors (the sysfs
101interface makes extensive use of errors). File descriptors and open /
102close operations to the sysfs inodes must also be properly implemented.
103
104The version of thinkpad-acpi's sysfs interface is exported by the driver
105as a driver attribute (see below).
106
107Sysfs driver attributes are on the driver's sysfs attribute space,
108for 2.6.20 this is /sys/bus/platform/drivers/thinkpad-acpi/.
109
110Sysfs device attributes are on the driver's sysfs attribute space,
111for 2.6.20 this is /sys/devices/platform/thinkpad-acpi/.
112
113Driver version
114--------------
115
116procfs: /proc/acpi/ibm/driver
117sysfs driver attribute: version
69 118
70The driver name and version. No commands can be written to this file. 119The driver name and version. No commands can be written to this file.
71 120
72Hot keys -- /proc/acpi/ibm/hotkey 121Sysfs interface version
73--------------------------------- 122-----------------------
123
124sysfs driver attribute: interface_version
125
126Version of the thinkpad-acpi sysfs interface, as an unsigned long
127(output in hex format: 0xAAAABBCC), where:
128 AAAA - major revision
129 BB - minor revision
130 CC - bugfix revision
131
132The sysfs interface version changelog for the driver can be found at the
133end of this document. Changes to the sysfs interface done by the kernel
134subsystems are not documented here, nor are they tracked by this
135attribute.
136
137Hot keys
138--------
139
140procfs: /proc/acpi/ibm/hotkey
141sysfs device attribute: hotkey/*
74 142
75Without this driver, only the Fn-F4 key (sleep button) generates an 143Without this driver, only the Fn-F4 key (sleep button) generates an
76ACPI event. With the driver loaded, the hotkey feature enabled and the 144ACPI event. With the driver loaded, the hotkey feature enabled and the
@@ -84,15 +152,6 @@ All labeled Fn-Fx key combinations generate distinct events. In
84addition, the lid microswitch and some docking station buttons may 152addition, the lid microswitch and some docking station buttons may
85also generate such events. 153also generate such events.
86 154
87The following commands can be written to this file:
88
89 echo enable > /proc/acpi/ibm/hotkey -- enable the hot keys feature
90 echo disable > /proc/acpi/ibm/hotkey -- disable the hot keys feature
91 echo 0xffff > /proc/acpi/ibm/hotkey -- enable all possible hot keys
92 echo 0x0000 > /proc/acpi/ibm/hotkey -- disable all possible hot keys
93 ... any other 4-hex-digit mask ...
94 echo reset > /proc/acpi/ibm/hotkey -- restore the original mask
95
96The bit mask allows some control over which hot keys generate ACPI 155The bit mask allows some control over which hot keys generate ACPI
97events. Not all bits in the mask can be modified. Not all bits that 156events. Not all bits in the mask can be modified. Not all bits that
98can be modified do anything. Not all hot keys can be individually 157can be modified do anything. Not all hot keys can be individually
@@ -124,15 +183,77 @@ buttons do not generate ACPI events even with this driver. They *can*
124be used through the "ThinkPad Buttons" utility, see 183be used through the "ThinkPad Buttons" utility, see
125http://www.nongnu.org/tpb/ 184http://www.nongnu.org/tpb/
126 185
127Bluetooth -- /proc/acpi/ibm/bluetooth 186procfs notes:
128------------------------------------- 187
188The following commands can be written to the /proc/acpi/ibm/hotkey file:
189
190 echo enable > /proc/acpi/ibm/hotkey -- enable the hot keys feature
191 echo disable > /proc/acpi/ibm/hotkey -- disable the hot keys feature
192 echo 0xffff > /proc/acpi/ibm/hotkey -- enable all possible hot keys
193 echo 0x0000 > /proc/acpi/ibm/hotkey -- disable all possible hot keys
194 ... any other 4-hex-digit mask ...
195 echo reset > /proc/acpi/ibm/hotkey -- restore the original mask
196
197sysfs notes:
198
199 The hot keys attributes are in a hotkey/ subdirectory off the
200 thinkpad device.
201
202 bios_enabled:
203 Returns the status of the hot keys feature when
204 thinkpad-acpi was loaded. Upon module unload, the hot
205 key feature status will be restored to this value.
206
207 0: hot keys were disabled
208 1: hot keys were enabled
209
210 bios_mask:
211 Returns the hot keys mask when thinkpad-acpi was loaded.
212 Upon module unload, the hot keys mask will be restored
213 to this value.
214
215 enable:
216 Enables/disables the hot keys feature, and reports
217 current status of the hot keys feature.
218
219 0: disables the hot keys feature / feature disabled
220 1: enables the hot keys feature / feature enabled
221
222 mask:
223 bit mask to enable ACPI event generation for each hot
224 key (see above). Returns the current status of the hot
225 keys mask, and allows one to modify it.
226
129 227
130This feature shows the presence and current state of a Bluetooth 228Bluetooth
131device. If Bluetooth is installed, the following commands can be used: 229---------
230
231procfs: /proc/acpi/ibm/bluetooth
232sysfs device attribute: bluetooth/enable
233
234This feature shows the presence and current state of a ThinkPad
235Bluetooth device in the internal ThinkPad CDC slot.
236
237Procfs notes:
238
239If Bluetooth is installed, the following commands can be used:
132 240
133 echo enable > /proc/acpi/ibm/bluetooth 241 echo enable > /proc/acpi/ibm/bluetooth
134 echo disable > /proc/acpi/ibm/bluetooth 242 echo disable > /proc/acpi/ibm/bluetooth
135 243
244Sysfs notes:
245
246 If the Bluetooth CDC card is installed, it can be enabled /
247 disabled through the "bluetooth/enable" thinkpad-acpi device
248 attribute, and its current status can also be queried.
249
250 enable:
251 0: disables Bluetooth / Bluetooth is disabled
252 1: enables Bluetooth / Bluetooth is enabled.
253
254 Note: this interface will be probably be superseeded by the
255 generic rfkill class.
256
136Video output control -- /proc/acpi/ibm/video 257Video output control -- /proc/acpi/ibm/video
137-------------------------------------------- 258--------------------------------------------
138 259
@@ -209,7 +330,7 @@ hot plugging of devices in the Linux ACPI framework. If the laptop was
209booted while not in the dock, the following message is shown in the 330booted while not in the dock, the following message is shown in the
210logs: 331logs:
211 332
212 Mar 17 01:42:34 aero kernel: ibm_acpi: dock device not present 333 Mar 17 01:42:34 aero kernel: thinkpad_acpi: dock device not present
213 334
214In this case, no dock-related events are generated but the dock and 335In this case, no dock-related events are generated but the dock and
215undock commands described below still work. They can be executed 336undock commands described below still work. They can be executed
@@ -269,7 +390,7 @@ This is due to the current lack of support for hot plugging of devices
269in the Linux ACPI framework. If the laptop was booted without the 390in the Linux ACPI framework. If the laptop was booted without the
270UltraBay, the following message is shown in the logs: 391UltraBay, the following message is shown in the logs:
271 392
272 Mar 17 01:42:34 aero kernel: ibm_acpi: bay device not present 393 Mar 17 01:42:34 aero kernel: thinkpad_acpi: bay device not present
273 394
274In this case, no bay-related events are generated but the eject 395In this case, no bay-related events are generated but the eject
275command described below still works. It can be executed manually or 396command described below still works. It can be executed manually or
@@ -313,23 +434,19 @@ supported. Use "eject2" instead of "eject" for the second bay.
313Note: the UltraBay eject support on the 600e/x, A22p and A3x is 434Note: the UltraBay eject support on the 600e/x, A22p and A3x is
314EXPERIMENTAL and may not work as expected. USE WITH CAUTION! 435EXPERIMENTAL and may not work as expected. USE WITH CAUTION!
315 436
316CMOS control -- /proc/acpi/ibm/cmos 437CMOS control
317----------------------------------- 438------------
439
440procfs: /proc/acpi/ibm/cmos
441sysfs device attribute: cmos_command
318 442
319This feature is used internally by the ACPI firmware to control the 443This feature is used internally by the ACPI firmware to control the
320ThinkLight on most newer ThinkPad models. It may also control LCD 444ThinkLight on most newer ThinkPad models. It may also control LCD
321brightness, sounds volume and more, but only on some models. 445brightness, sounds volume and more, but only on some models.
322 446
323The commands are non-negative integer numbers: 447The range of valid cmos command numbers is 0 to 21, but not all have an
324 448effect and the behavior varies from model to model. Here is the behavior
325 echo 0 >/proc/acpi/ibm/cmos 449on the X40 (tpb is the ThinkPad Buttons utility):
326 echo 1 >/proc/acpi/ibm/cmos
327 echo 2 >/proc/acpi/ibm/cmos
328 ...
329
330The range of valid numbers is 0 to 21, but not all have an effect and
331the behavior varies from model to model. Here is the behavior on the
332X40 (tpb is the ThinkPad Buttons utility):
333 450
334 0 - no effect but tpb reports "Volume down" 451 0 - no effect but tpb reports "Volume down"
335 1 - no effect but tpb reports "Volume up" 452 1 - no effect but tpb reports "Volume up"
@@ -342,6 +459,9 @@ X40 (tpb is the ThinkPad Buttons utility):
342 13 - ThinkLight off 459 13 - ThinkLight off
343 14 - no effect but tpb reports ThinkLight status change 460 14 - no effect but tpb reports ThinkLight status change
344 461
462The cmos command interface is prone to firmware split-brain problems, as
463in newer ThinkPads it is just a compatibility layer.
464
345LED control -- /proc/acpi/ibm/led 465LED control -- /proc/acpi/ibm/led
346--------------------------------- 466---------------------------------
347 467
@@ -393,17 +513,17 @@ X40:
393 16 - one medium-pitched beep repeating constantly, stop with 17 513 16 - one medium-pitched beep repeating constantly, stop with 17
394 17 - stop 16 514 17 - stop 16
395 515
396Temperature sensors -- /proc/acpi/ibm/thermal 516Temperature sensors
397--------------------------------------------- 517-------------------
518
519procfs: /proc/acpi/ibm/thermal
520sysfs device attributes: (hwmon) temp*_input
398 521
399Most ThinkPads include six or more separate temperature sensors but 522Most ThinkPads include six or more separate temperature sensors but
400only expose the CPU temperature through the standard ACPI methods. 523only expose the CPU temperature through the standard ACPI methods.
401This feature shows readings from up to eight different sensors on older 524This feature shows readings from up to eight different sensors on older
402ThinkPads, and it has experimental support for up to sixteen different 525ThinkPads, and it has experimental support for up to sixteen different
403sensors on newer ThinkPads. Readings from sensors that are not available 526sensors on newer ThinkPads.
404return -128.
405
406No commands can be written to this file.
407 527
408EXPERIMENTAL: The 16-sensors feature is marked EXPERIMENTAL because the 528EXPERIMENTAL: The 16-sensors feature is marked EXPERIMENTAL because the
409implementation directly accesses hardware registers and may not work as 529implementation directly accesses hardware registers and may not work as
@@ -460,6 +580,20 @@ The A31 has a very atypical layout for the thermal sensors
4608: Bay Battery: secondary sensor 5808: Bay Battery: secondary sensor
461 581
462 582
583Procfs notes:
584 Readings from sensors that are not available return -128.
585 No commands can be written to this file.
586
587Sysfs notes:
588 Sensors that are not available return the ENXIO error. This
589 status may change at runtime, as there are hotplug thermal
590 sensors, like those inside the batteries and docks.
591
592 thinkpad-acpi thermal sensors are reported through the hwmon
593 subsystem, and follow all of the hwmon guidelines at
594 Documentation/hwmon.
595
596
463EXPERIMENTAL: Embedded controller register dump -- /proc/acpi/ibm/ecdump 597EXPERIMENTAL: Embedded controller register dump -- /proc/acpi/ibm/ecdump
464------------------------------------------------------------------------ 598------------------------------------------------------------------------
465 599
@@ -472,7 +606,7 @@ This feature dumps the values of 256 embedded controller
472registers. Values which have changed since the last time the registers 606registers. Values which have changed since the last time the registers
473were dumped are marked with a star: 607were dumped are marked with a star:
474 608
475[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump 609[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump
476EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f 610EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f
477EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00 611EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00
478EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00 612EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00
@@ -503,7 +637,7 @@ vary. The second ensures that the fan-related values do vary, since
503the fan speed fluctuates a bit. The third will (hopefully) mark the 637the fan speed fluctuates a bit. The third will (hopefully) mark the
504fan register with a star: 638fan register with a star:
505 639
506[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump 640[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump
507EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f 641EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f
508EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00 642EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00
509EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00 643EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00
@@ -533,19 +667,59 @@ registers contain the current battery capacity, etc. If you experiment
533with this, do send me your results (including some complete dumps with 667with this, do send me your results (including some complete dumps with
534a description of the conditions when they were taken.) 668a description of the conditions when they were taken.)
535 669
536LCD brightness control -- /proc/acpi/ibm/brightness 670LCD brightness control
537--------------------------------------------------- 671----------------------
672
673procfs: /proc/acpi/ibm/brightness
674sysfs backlight device "thinkpad_screen"
538 675
539This feature allows software control of the LCD brightness on ThinkPad 676This feature allows software control of the LCD brightness on ThinkPad
540models which don't have a hardware brightness slider. The available 677models which don't have a hardware brightness slider.
541commands are: 678
679It has some limitations: the LCD backlight cannot be actually turned on or off
680by this interface, and in many ThinkPad models, the "dim while on battery"
681functionality will be enabled by the BIOS when this interface is used, and
682cannot be controlled.
683
684The backlight control has eight levels, ranging from 0 to 7. Some of the
685levels may not be distinct.
686
687Procfs notes:
688
689 The available commands are:
542 690
543 echo up >/proc/acpi/ibm/brightness 691 echo up >/proc/acpi/ibm/brightness
544 echo down >/proc/acpi/ibm/brightness 692 echo down >/proc/acpi/ibm/brightness
545 echo 'level <level>' >/proc/acpi/ibm/brightness 693 echo 'level <level>' >/proc/acpi/ibm/brightness
546 694
547The <level> number range is 0 to 7, although not all of them may be 695Sysfs notes:
548distinct. The current brightness level is shown in the file. 696
697The interface is implemented through the backlight sysfs class, which is poorly
698documented at this time.
699
700Locate the thinkpad_screen device under /sys/class/backlight, and inside it
701there will be the following attributes:
702
703 max_brightness:
704 Reads the maximum brightness the hardware can be set to.
705 The minimum is always zero.
706
707 actual_brightness:
708 Reads what brightness the screen is set to at this instant.
709
710 brightness:
711 Writes request the driver to change brightness to the given
712 value. Reads will tell you what brightness the driver is trying
713 to set the display to when "power" is set to zero and the display
714 has not been dimmed by a kernel power management event.
715
716 power:
717 power management mode, where 0 is "display on", and 1 to 3 will
718 dim the display backlight to brightness level 0 because
719 thinkpad-acpi cannot really turn the backlight off. Kernel
720 power management events can temporarily increase the current
721 power management level, i.e. they can dim the display.
722
549 723
550Volume control -- /proc/acpi/ibm/volume 724Volume control -- /proc/acpi/ibm/volume
551--------------------------------------- 725---------------------------------------
@@ -563,41 +737,42 @@ distinct. The unmute the volume after the mute command, use either the
563up or down command (the level command will not unmute the volume). 737up or down command (the level command will not unmute the volume).
564The current volume level and mute state is shown in the file. 738The current volume level and mute state is shown in the file.
565 739
566EXPERIMENTAL: fan speed, fan enable/disable -- /proc/acpi/ibm/fan 740Fan control and monitoring: fan speed, fan enable/disable
567----------------------------------------------------------------- 741---------------------------------------------------------
568 742
569This feature is marked EXPERIMENTAL because the implementation 743procfs: /proc/acpi/ibm/fan
570directly accesses hardware registers and may not work as expected. USE 744sysfs device attributes: (hwmon) fan_input, pwm1, pwm1_enable
571WITH CAUTION! To use this feature, you need to supply the 745
572experimental=1 parameter when loading the module. 746NOTE NOTE NOTE: fan control operations are disabled by default for
747safety reasons. To enable them, the module parameter "fan_control=1"
748must be given to thinkpad-acpi.
573 749
574This feature attempts to show the current fan speed, control mode and 750This feature attempts to show the current fan speed, control mode and
575other fan data that might be available. The speed is read directly 751other fan data that might be available. The speed is read directly
576from the hardware registers of the embedded controller. This is known 752from the hardware registers of the embedded controller. This is known
577to work on later R, T and X series ThinkPads but may show a bogus 753to work on later R, T, X and Z series ThinkPads but may show a bogus
578value on other models. 754value on other models.
579 755
580Most ThinkPad fans work in "levels". Level 0 stops the fan. The higher 756Fan levels:
581the level, the higher the fan speed, although adjacent levels often map
582to the same fan speed. 7 is the highest level, where the fan reaches
583the maximum recommended speed. Level "auto" means the EC changes the
584fan level according to some internal algorithm, usually based on
585readings from the thermal sensors. Level "disengaged" means the EC
586disables the speed-locked closed-loop fan control, and drives the fan as
587fast as it can go, which might exceed hardware limits, so use this level
588with caution.
589 757
590The fan usually ramps up or down slowly from one speed to another, 758Most ThinkPad fans work in "levels" at the firmware interface. Level 0
591and it is normal for the EC to take several seconds to react to fan 759stops the fan. The higher the level, the higher the fan speed, although
592commands. 760adjacent levels often map to the same fan speed. 7 is the highest
761level, where the fan reaches the maximum recommended speed.
593 762
594The fan may be enabled or disabled with the following commands: 763Level "auto" means the EC changes the fan level according to some
764internal algorithm, usually based on readings from the thermal sensors.
595 765
596 echo enable >/proc/acpi/ibm/fan 766There is also a "full-speed" level, also known as "disengaged" level.
597 echo disable >/proc/acpi/ibm/fan 767In this level, the EC disables the speed-locked closed-loop fan control,
768and drives the fan as fast as it can go, which might exceed hardware
769limits, so use this level with caution.
598 770
599Placing a fan on level 0 is the same as disabling it. Enabling a fan 771The fan usually ramps up or down slowly from one speed to another, and
600will try to place it in a safe level if it is too slow or disabled. 772it is normal for the EC to take several seconds to react to fan
773commands. The full-speed level may take up to two minutes to ramp up to
774maximum speed, and in some ThinkPads, the tachometer readings go stale
775while the EC is transitioning to the full-speed level.
601 776
602WARNING WARNING WARNING: do not leave the fan disabled unless you are 777WARNING WARNING WARNING: do not leave the fan disabled unless you are
603monitoring all of the temperature sensor readings and you are ready to 778monitoring all of the temperature sensor readings and you are ready to
@@ -615,46 +790,146 @@ fan is turned off when the CPU temperature drops to 49 degrees and the
615HDD temperature drops to 41 degrees. These thresholds cannot 790HDD temperature drops to 41 degrees. These thresholds cannot
616currently be controlled. 791currently be controlled.
617 792
793The ThinkPad's ACPI DSDT code will reprogram the fan on its own when
794certain conditions are met. It will override any fan programming done
795through thinkpad-acpi.
796
797The thinkpad-acpi kernel driver can be programmed to revert the fan
798level to a safe setting if userspace does not issue one of the procfs
799fan commands: "enable", "disable", "level" or "watchdog", or if there
800are no writes to pwm1_enable (or to pwm1 *if and only if* pwm1_enable is
801set to 1, manual mode) within a configurable amount of time of up to
802120 seconds. This functionality is called fan safety watchdog.
803
804Note that the watchdog timer stops after it enables the fan. It will be
805rearmed again automatically (using the same interval) when one of the
806above mentioned fan commands is received. The fan watchdog is,
807therefore, not suitable to protect against fan mode changes made through
808means other than the "enable", "disable", and "level" procfs fan
809commands, or the hwmon fan control sysfs interface.
810
811Procfs notes:
812
813The fan may be enabled or disabled with the following commands:
814
815 echo enable >/proc/acpi/ibm/fan
816 echo disable >/proc/acpi/ibm/fan
817
818Placing a fan on level 0 is the same as disabling it. Enabling a fan
819will try to place it in a safe level if it is too slow or disabled.
820
618The fan level can be controlled with the command: 821The fan level can be controlled with the command:
619 822
620 echo 'level <level>' > /proc/acpi/ibm/thermal 823 echo 'level <level>' > /proc/acpi/ibm/fan
621 824
622Where <level> is an integer from 0 to 7, or one of the words "auto" 825Where <level> is an integer from 0 to 7, or one of the words "auto" or
623or "disengaged" (without the quotes). Not all ThinkPads support the 826"full-speed" (without the quotes). Not all ThinkPads support the "auto"
624"auto" and "disengaged" levels. 827and "full-speed" levels. The driver accepts "disengaged" as an alias for
828"full-speed", and reports it as "disengaged" for backwards
829compatibility.
625 830
626On the X31 and X40 (and ONLY on those models), the fan speed can be 831On the X31 and X40 (and ONLY on those models), the fan speed can be
627controlled to a certain degree. Once the fan is running, it can be 832controlled to a certain degree. Once the fan is running, it can be
628forced to run faster or slower with the following command: 833forced to run faster or slower with the following command:
629 834
630 echo 'speed <speed>' > /proc/acpi/ibm/thermal 835 echo 'speed <speed>' > /proc/acpi/ibm/fan
631 836
632The sustainable range of fan speeds on the X40 appears to be from 837The sustainable range of fan speeds on the X40 appears to be from about
633about 3700 to about 7350. Values outside this range either do not have 8383700 to about 7350. Values outside this range either do not have any
634any effect or the fan speed eventually settles somewhere in that 839effect or the fan speed eventually settles somewhere in that range. The
635range. The fan cannot be stopped or started with this command. 840fan cannot be stopped or started with this command. This functionality
841is incomplete, and not available through the sysfs interface.
636 842
637The ThinkPad's ACPI DSDT code will reprogram the fan on its own when 843To program the safety watchdog, use the "watchdog" command.
638certain conditions are met. It will override any fan programming done
639through ibm-acpi.
640 844
641EXPERIMENTAL: WAN -- /proc/acpi/ibm/wan 845 echo 'watchdog <interval in seconds>' > /proc/acpi/ibm/fan
642--------------------------------------- 846
847If you want to disable the watchdog, use 0 as the interval.
848
849Sysfs notes:
850
851The sysfs interface follows the hwmon subsystem guidelines for the most
852part, and the exception is the fan safety watchdog.
853
854Writes to any of the sysfs attributes may return the EINVAL error if
855that operation is not supported in a given ThinkPad or if the parameter
856is out-of-bounds, and EPERM if it is forbidden. They may also return
857EINTR (interrupted system call), and EIO (I/O error while trying to talk
858to the firmware).
859
860Features not yet implemented by the driver return ENOSYS.
861
862hwmon device attribute pwm1_enable:
863 0: PWM offline (fan is set to full-speed mode)
864 1: Manual PWM control (use pwm1 to set fan level)
865 2: Hardware PWM control (EC "auto" mode)
866 3: reserved (Software PWM control, not implemented yet)
867
868 Modes 0 and 2 are not supported by all ThinkPads, and the
869 driver is not always able to detect this. If it does know a
870 mode is unsupported, it will return -EINVAL.
871
872hwmon device attribute pwm1:
873 Fan level, scaled from the firmware values of 0-7 to the hwmon
874 scale of 0-255. 0 means fan stopped, 255 means highest normal
875 speed (level 7).
876
877 This attribute only commands the fan if pmw1_enable is set to 1
878 (manual PWM control).
879
880hwmon device attribute fan1_input:
881 Fan tachometer reading, in RPM. May go stale on certain
882 ThinkPads while the EC transitions the PWM to offline mode,
883 which can take up to two minutes. May return rubbish on older
884 ThinkPads.
885
886driver attribute fan_watchdog:
887 Fan safety watchdog timer interval, in seconds. Minimum is
888 1 second, maximum is 120 seconds. 0 disables the watchdog.
889
890To stop the fan: set pwm1 to zero, and pwm1_enable to 1.
891
892To start the fan in a safe mode: set pwm1_enable to 2. If that fails
893with EINVAL, try to set pwm1_enable to 1 and pwm1 to at least 128 (255
894would be the safest choice, though).
895
896
897EXPERIMENTAL: WAN
898-----------------
899
900procfs: /proc/acpi/ibm/wan
901sysfs device attribute: wwan/enable
643 902
644This feature is marked EXPERIMENTAL because the implementation 903This feature is marked EXPERIMENTAL because the implementation
645directly accesses hardware registers and may not work as expected. USE 904directly accesses hardware registers and may not work as expected. USE
646WITH CAUTION! To use this feature, you need to supply the 905WITH CAUTION! To use this feature, you need to supply the
647experimental=1 parameter when loading the module. 906experimental=1 parameter when loading the module.
648 907
649This feature shows the presence and current state of a WAN (Sierra 908This feature shows the presence and current state of a W-WAN (Sierra
650Wireless EV-DO) device. If WAN is installed, the following commands can 909Wireless EV-DO) device.
651be used: 910
911It was tested on a Lenovo Thinkpad X60. It should probably work on other
912Thinkpad models which come with this module installed.
913
914Procfs notes:
915
916If the W-WAN card is installed, the following commands can be used:
652 917
653 echo enable > /proc/acpi/ibm/wan 918 echo enable > /proc/acpi/ibm/wan
654 echo disable > /proc/acpi/ibm/wan 919 echo disable > /proc/acpi/ibm/wan
655 920
656It was tested on a Lenovo Thinkpad X60. It should probably work on other 921Sysfs notes:
657Thinkpad models which come with this module installed. 922
923 If the W-WAN card is installed, it can be enabled /
924 disabled through the "wwan/enable" thinkpad-acpi device
925 attribute, and its current status can also be queried.
926
927 enable:
928 0: disables WWAN card / WWAN card is disabled
929 1: enables WWAN card / WWAN card is enabled.
930
931 Note: this interface will be probably be superseeded by the
932 generic rfkill class.
658 933
659Multiple Commands, Module Parameters 934Multiple Commands, Module Parameters
660------------------------------------ 935------------------------------------
@@ -665,64 +940,42 @@ separating them with commas, for example:
665 echo enable,0xffff > /proc/acpi/ibm/hotkey 940 echo enable,0xffff > /proc/acpi/ibm/hotkey
666 echo lcd_disable,crt_enable > /proc/acpi/ibm/video 941 echo lcd_disable,crt_enable > /proc/acpi/ibm/video
667 942
668Commands can also be specified when loading the ibm_acpi module, for 943Commands can also be specified when loading the thinkpad-acpi module,
669example: 944for example:
670 945
671 modprobe ibm_acpi hotkey=enable,0xffff video=auto_disable 946 modprobe thinkpad_acpi hotkey=enable,0xffff video=auto_disable
672 947
673The ibm-acpi kernel driver can be programmed to revert the fan level 948Enabling debugging output
674to a safe setting if userspace does not issue one of the fan commands: 949-------------------------
675"enable", "disable", "level" or "watchdog" within a configurable 950
676ammount of time. To do this, use the "watchdog" command. 951The module takes a debug paramater which can be used to selectively
677 952enable various classes of debugging output, for example:
678 echo 'watchdog <interval>' > /proc/acpi/ibm/fan 953
679 954 modprobe ibm_acpi debug=0xffff
680Interval is the ammount of time in seconds to wait for one of the 955
681above mentioned fan commands before reseting the fan level to a safe 956will enable all debugging output classes. It takes a bitmask, so
682one. If set to zero, the watchdog is disabled (default). When the 957to enable more than one output class, just add their values.
683watchdog timer runs out, it does the exact equivalent of the "enable" 958
684fan command. 959 Debug bitmask Description
685 960 0x0001 Initialization and probing
686Note that the watchdog timer stops after it enables the fan. It will 961 0x0002 Removal
687be rearmed again automatically (using the same interval) when one of 962
688the above mentioned fan commands is received. The fan watchdog is, 963There is also a kernel build option to enable more debugging
689therefore, not suitable to protect against fan mode changes made 964information, which may be necessary to debug driver problems.
690through means other than the "enable", "disable", and "level" fan 965
691commands. 966The level of debugging information output by the driver can be changed
692 967at runtime through sysfs, using the driver attribute debug_level. The
693 968attribute takes the same bitmask as the debug module parameter above.
694Example Configuration 969
695--------------------- 970Force loading of module
696 971-----------------------
697The ACPI support in the kernel is intended to be used in conjunction 972
698with a user-space daemon, acpid. The configuration files for this 973If thinkpad-acpi refuses to detect your ThinkPad, you can try to specify
699daemon control what actions are taken in response to various ACPI 974the module parameter force_load=1. Regardless of whether this works or
700events. An example set of configuration files are included in the 975not, please contact ibm-acpi-devel@lists.sourceforge.net with a report.
701config/ directory of the tarball package available on the web 976
702site. Note that these are provided for illustration purposes only and 977
703may need to be adapted to your particular setup. 978Sysfs interface changelog:
704 979
705The following utility scripts are used by the example action 9800x000100: Initial sysfs support, as a single platform driver and
706scripts (included with ibm-acpi for completeness): 981 device.
707
708 /usr/local/sbin/idectl -- from the hdparm source distribution,
709 see http://www.ibiblio.org/pub/Linux/system/hardware
710 /usr/local/sbin/laptop_mode -- from the Linux kernel source
711 distribution, see Documentation/laptop-mode.txt
712 /sbin/service -- comes with Redhat/Fedora distributions
713 /usr/sbin/hibernate -- from the Software Suspend 2 distribution,
714 see http://softwaresuspend.berlios.de/
715
716Toan T Nguyen <ntt@physics.ucla.edu> notes that Suse uses the
717powersave program to suspend ('powersave --suspend-to-ram') or
718hibernate ('powersave --suspend-to-disk'). This means that the
719hibernate script is not needed on that distribution.
720
721Henrik Brix Andersen <brix@gentoo.org> has written a Gentoo ACPI event
722handler script for the X31. You can get the latest version from
723http://dev.gentoo.org/~brix/files/x31.sh
724
725David Schweikert <dws@ee.eth.ch> has written an alternative blank.sh
726script which works on Debian systems. This scripts has now been
727extended to also work on Fedora systems and included as the default
728blank.sh in the distribution.
diff --git a/Documentation/video4linux/meye.txt b/Documentation/video4linux/meye.txt
index ecb34160e61d..5e51c59bf2b0 100644
--- a/Documentation/video4linux/meye.txt
+++ b/Documentation/video4linux/meye.txt
@@ -5,10 +5,9 @@ Vaio Picturebook Motion Eye Camera Driver Readme
5 Copyright (C) 2000 Andrew Tridgell <tridge@samba.org> 5 Copyright (C) 2000 Andrew Tridgell <tridge@samba.org>
6 6
7This driver enable the use of video4linux compatible applications with the 7This driver enable the use of video4linux compatible applications with the
8Motion Eye camera. This driver requires the "Sony Vaio Programmable I/O 8Motion Eye camera. This driver requires the "Sony Laptop Extras" driver (which
9Control Device" driver (which can be found in the "Character drivers" 9can be found in the "Misc devices" section of the kernel configuration utility)
10section of the kernel configuration utility) to be compiled and installed 10to be compiled and installed (using its "camera=1" parameter).
11(using its "camera=1" parameter).
12 11
13It can do at maximum 30 fps @ 320x240 or 15 fps @ 640x480. 12It can do at maximum 30 fps @ 320x240 or 15 fps @ 640x480.
14 13
diff --git a/MAINTAINERS b/MAINTAINERS
index d4743b4c3f4f..af1c7926c153 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1658,15 +1658,6 @@ W: http://www.ia64-linux.org/
1658T: git kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git 1658T: git kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6.git
1659S: Maintained 1659S: Maintained
1660 1660
1661IBM ACPI EXTRAS DRIVER
1662P: Henrique de Moraes Holschuh
1663M: ibm-acpi@hmh.eng.br
1664L: ibm-acpi-devel@lists.sourceforge.net
1665W: http://ibm-acpi.sourceforge.net
1666W: http://thinkwiki.org/wiki/Ibm-acpi
1667T: git repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
1668S: Maintained
1669
1670SN-IA64 (Itanium) SUB-PLATFORM 1661SN-IA64 (Itanium) SUB-PLATFORM
1671P: Jes Sorensen 1662P: Jes Sorensen
1672M: jes@sgi.com 1663M: jes@sgi.com
@@ -3182,6 +3173,15 @@ P: Chris Zankel
3182M: chris@zankel.net 3173M: chris@zankel.net
3183S: Maintained 3174S: Maintained
3184 3175
3176THINKPAD ACPI EXTRAS DRIVER
3177P: Henrique de Moraes Holschuh
3178M: ibm-acpi@hmh.eng.br
3179L: ibm-acpi-devel@lists.sourceforge.net
3180W: http://ibm-acpi.sourceforge.net
3181W: http://thinkwiki.org/wiki/Ibm-acpi
3182T: git repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
3183S: Maintained
3184
3185UltraSPARC (sparc64): 3185UltraSPARC (sparc64):
3186P: David S. Miller 3186P: David S. Miller
3187M: davem@davemloft.net 3187M: davem@davemloft.net
diff --git a/arch/i386/defconfig b/arch/i386/defconfig
index f4efd66e1ee5..c96911c37aea 100644
--- a/arch/i386/defconfig
+++ b/arch/i386/defconfig
@@ -692,7 +692,6 @@ CONFIG_SATA_SIL=y
692CONFIG_SATA_VIA=y 692CONFIG_SATA_VIA=y
693# CONFIG_SATA_VITESSE is not set 693# CONFIG_SATA_VITESSE is not set
694# CONFIG_SATA_INIC162X is not set 694# CONFIG_SATA_INIC162X is not set
695CONFIG_SATA_INTEL_COMBINED=y
696CONFIG_SATA_ACPI=y 695CONFIG_SATA_ACPI=y
697# CONFIG_PATA_ALI is not set 696# CONFIG_PATA_ALI is not set
698# CONFIG_PATA_AMD is not set 697# CONFIG_PATA_AMD is not set
diff --git a/arch/i386/kernel/acpi/earlyquirk.c b/arch/i386/kernel/acpi/earlyquirk.c
index a7d22d9f3d7e..8f7efd38254d 100644
--- a/arch/i386/kernel/acpi/earlyquirk.c
+++ b/arch/i386/kernel/acpi/earlyquirk.c
@@ -23,10 +23,13 @@ static int __init nvidia_hpet_check(struct acpi_table_header *header)
23static int __init check_bridge(int vendor, int device) 23static int __init check_bridge(int vendor, int device)
24{ 24{
25#ifdef CONFIG_ACPI 25#ifdef CONFIG_ACPI
26 static int warned;
26 /* According to Nvidia all timer overrides are bogus unless HPET 27 /* According to Nvidia all timer overrides are bogus unless HPET
27 is enabled. */ 28 is enabled. */
28 if (!acpi_use_timer_override && vendor == PCI_VENDOR_ID_NVIDIA) { 29 if (!acpi_use_timer_override && vendor == PCI_VENDOR_ID_NVIDIA) {
29 if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) { 30 if (!warned && acpi_table_parse(ACPI_SIG_HPET,
31 nvidia_hpet_check)) {
32 warned = 1;
30 acpi_skip_timer_override = 1; 33 acpi_skip_timer_override = 1;
31 printk(KERN_INFO "Nvidia board " 34 printk(KERN_INFO "Nvidia board "
32 "detected. Ignoring ACPI " 35 "detected. Ignoring ACPI "
diff --git a/arch/parisc/configs/c3000_defconfig b/arch/parisc/configs/c3000_defconfig
index 782906b644dd..eb2f9a3d515c 100644
--- a/arch/parisc/configs/c3000_defconfig
+++ b/arch/parisc/configs/c3000_defconfig
@@ -435,7 +435,6 @@ CONFIG_SCSI_SATA_SIL=m
435# CONFIG_SCSI_SATA_ULI is not set 435# CONFIG_SCSI_SATA_ULI is not set
436CONFIG_SCSI_SATA_VIA=m 436CONFIG_SCSI_SATA_VIA=m
437# CONFIG_SCSI_SATA_VITESSE is not set 437# CONFIG_SCSI_SATA_VITESSE is not set
438CONFIG_SCSI_SATA_INTEL_COMBINED=y
439# CONFIG_SCSI_DMX3191D is not set 438# CONFIG_SCSI_DMX3191D is not set
440# CONFIG_SCSI_FUTURE_DOMAIN is not set 439# CONFIG_SCSI_FUTURE_DOMAIN is not set
441# CONFIG_SCSI_IPS is not set 440# CONFIG_SCSI_IPS is not set
diff --git a/arch/x86_64/defconfig b/arch/x86_64/defconfig
index 7a1e251e333d..b26378815b91 100644
--- a/arch/x86_64/defconfig
+++ b/arch/x86_64/defconfig
@@ -631,7 +631,6 @@ CONFIG_SATA_SIL=y
631CONFIG_SATA_VIA=y 631CONFIG_SATA_VIA=y
632# CONFIG_SATA_VITESSE is not set 632# CONFIG_SATA_VITESSE is not set
633# CONFIG_SATA_INIC162X is not set 633# CONFIG_SATA_INIC162X is not set
634CONFIG_SATA_INTEL_COMBINED=y
635CONFIG_SATA_ACPI=y 634CONFIG_SATA_ACPI=y
636# CONFIG_PATA_ALI is not set 635# CONFIG_PATA_ALI is not set
637# CONFIG_PATA_AMD is not set 636# CONFIG_PATA_AMD is not set
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index e2ce4a9c1c92..139f41f033d8 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -85,8 +85,8 @@ config ACPI_PROCFS
85 depends on ACPI 85 depends on ACPI
86 default y 86 default y
87 ---help--- 87 ---help---
88 Procfs interface for ACPI is made optional for back-compatible. 88 The Procfs interface for ACPI is made optional for backward compatibility.
89 As the same functions are duplicated in sysfs interface 89 As the same functions are duplicated in the sysfs interface
90 and this proc interface will be removed some time later, 90 and this proc interface will be removed some time later,
91 it's marked as deprecated. 91 it's marked as deprecated.
92 ( /proc/acpi/debug_layer && debug_level are deprecated by 92 ( /proc/acpi/debug_layer && debug_level are deprecated by
@@ -218,43 +218,6 @@ config ACPI_ASUS
218 NOTE: This driver is deprecated and will probably be removed soon, 218 NOTE: This driver is deprecated and will probably be removed soon,
219 use asus-laptop instead. 219 use asus-laptop instead.
220 220
221config ACPI_IBM
222 tristate "IBM ThinkPad Laptop Extras"
223 depends on X86
224 select BACKLIGHT_CLASS_DEVICE
225 ---help---
226 This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds
227 support for Fn-Fx key combinations, Bluetooth control, video
228 output switching, ThinkLight control, UltraBay eject and more.
229 For more information about this driver see <file:Documentation/ibm-acpi.txt>
230 and <http://ibm-acpi.sf.net/> .
231
232 If you have an IBM ThinkPad laptop, say Y or M here.
233
234config ACPI_IBM_DOCK
235 bool "Legacy Docking Station Support"
236 depends on ACPI_IBM
237 depends on ACPI_DOCK=n
238 default n
239 ---help---
240 Allows the ibm_acpi driver to handle docking station events.
241 This support is obsoleted by CONFIG_HOTPLUG_PCI_ACPI. It will
242 allow locking and removing the laptop from the docking station,
243 but will not properly connect PCI devices.
244
245 If you are not sure, say N here.
246
247config ACPI_IBM_BAY
248 bool "Legacy Removable Bay Support"
249 depends on ACPI_IBM
250 default y
251 ---help---
252 Allows the ibm_acpi driver to handle removable bays. It will allow
253 disabling the device in the bay, and also generate notifications when
254 the bay lever is ejected or inserted.
255
256 If you are not sure, say Y here.
257
258config ACPI_TOSHIBA 221config ACPI_TOSHIBA
259 tristate "Toshiba Laptop Extras" 222 tristate "Toshiba Laptop Extras"
260 depends on X86 223 depends on X86
@@ -388,11 +351,10 @@ config ACPI_HOTPLUG_MEMORY
388 351
389config ACPI_SBS 352config ACPI_SBS
390 tristate "Smart Battery System (EXPERIMENTAL)" 353 tristate "Smart Battery System (EXPERIMENTAL)"
391 depends on X86 && I2C 354 depends on X86
392 depends on EXPERIMENTAL 355 depends on EXPERIMENTAL
393 help 356 help
394 This driver adds support for the Smart Battery System. 357 This driver adds support for the Smart Battery System.
395 Depends on I2C (Device Drivers ---> I2C support)
396 A "Smart Battery" is quite old and quite rare compared 358 A "Smart Battery" is quite old and quite rare compared
397 to today's ACPI "Control Method" battery. 359 to today's ACPI "Control Method" battery.
398 360
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 5956e9f64a8b..d4336f1730e9 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -1,6 +1,6 @@
1# 1#
2# Makefile for the Linux ACPI interpreter 2# Makefile for the Linux ACPI interpreter
3# 3#
4 4
5export ACPI_CFLAGS 5export ACPI_CFLAGS
6 6
@@ -32,16 +32,17 @@ obj-y += osl.o utils.o \
32processor-objs += processor_core.o processor_throttling.o \ 32processor-objs += processor_core.o processor_throttling.o \
33 processor_idle.o processor_thermal.o 33 processor_idle.o processor_thermal.o
34ifdef CONFIG_CPU_FREQ 34ifdef CONFIG_CPU_FREQ
35processor-objs += processor_perflib.o 35processor-objs += processor_perflib.o
36endif 36endif
37 37
38obj-y += sleep/ 38obj-y += sleep/
39obj-y += bus.o glue.o 39obj-y += bus.o glue.o
40obj-y += scan.o 40obj-y += scan.o
41# Keep EC driver first. Initialization of others depend on it.
42obj-$(CONFIG_ACPI_EC) += ec.o
41obj-$(CONFIG_ACPI_AC) += ac.o 43obj-$(CONFIG_ACPI_AC) += ac.o
42obj-$(CONFIG_ACPI_BATTERY) += battery.o 44obj-$(CONFIG_ACPI_BATTERY) += battery.o
43obj-$(CONFIG_ACPI_BUTTON) += button.o 45obj-$(CONFIG_ACPI_BUTTON) += button.o
44obj-$(CONFIG_ACPI_EC) += ec.o
45obj-$(CONFIG_ACPI_FAN) += fan.o 46obj-$(CONFIG_ACPI_FAN) += fan.o
46obj-$(CONFIG_ACPI_DOCK) += dock.o 47obj-$(CONFIG_ACPI_DOCK) += dock.o
47obj-$(CONFIG_ACPI_BAY) += bay.o 48obj-$(CONFIG_ACPI_BAY) += bay.o
@@ -55,8 +56,7 @@ obj-$(CONFIG_ACPI_SYSTEM) += system.o event.o
55obj-$(CONFIG_ACPI_DEBUG) += debug.o 56obj-$(CONFIG_ACPI_DEBUG) += debug.o
56obj-$(CONFIG_ACPI_NUMA) += numa.o 57obj-$(CONFIG_ACPI_NUMA) += numa.o
57obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o 58obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o
58obj-$(CONFIG_ACPI_IBM) += ibm_acpi.o
59obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 59obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o 60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
61obj-y += cm_sbs.o 61obj-y += cm_sbs.o
62obj-$(CONFIG_ACPI_SBS) += i2c_ec.o sbs.o 62obj-$(CONFIG_ACPI_SBS) += sbs.o
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index c26172671fd8..e65628a03085 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -44,11 +44,6 @@ MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>");
44MODULE_DESCRIPTION("Hotplug Mem Driver"); 44MODULE_DESCRIPTION("Hotplug Mem Driver");
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46 46
47/* ACPI _STA method values */
48#define ACPI_MEMORY_STA_PRESENT (0x00000001UL)
49#define ACPI_MEMORY_STA_ENABLED (0x00000002UL)
50#define ACPI_MEMORY_STA_FUNCTIONAL (0x00000008UL)
51
52/* Memory Device States */ 47/* Memory Device States */
53#define MEMORY_INVALID_STATE 0 48#define MEMORY_INVALID_STATE 0
54#define MEMORY_POWER_ON_STATE 1 49#define MEMORY_POWER_ON_STATE 1
@@ -204,9 +199,9 @@ static int acpi_memory_check_device(struct acpi_memory_device *mem_device)
204 * Check for device status. Device should be 199 * Check for device status. Device should be
205 * present/enabled/functioning. 200 * present/enabled/functioning.
206 */ 201 */
207 if (!((current_status & ACPI_MEMORY_STA_PRESENT) 202 if (!((current_status & ACPI_STA_DEVICE_PRESENT)
208 && (current_status & ACPI_MEMORY_STA_ENABLED) 203 && (current_status & ACPI_STA_DEVICE_ENABLED)
209 && (current_status & ACPI_MEMORY_STA_FUNCTIONAL))) 204 && (current_status & ACPI_STA_DEVICE_FUNCTIONING)))
210 return -ENODEV; 205 return -ENODEV;
211 206
212 return 0; 207 return 0;
@@ -286,7 +281,7 @@ static int acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
286 return -ENODEV; 281 return -ENODEV;
287 282
288 /* Check for device status. Device should be disabled */ 283 /* Check for device status. Device should be disabled */
289 if (current_status & ACPI_MEMORY_STA_ENABLED) 284 if (current_status & ACPI_STA_DEVICE_ENABLED)
290 return -EINVAL; 285 return -EINVAL;
291 286
292 return 0; 287 return 0;
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index dd49ea0d0ed3..e5084ececb6f 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -103,7 +103,9 @@ int acpi_bus_get_status(struct acpi_device *device)
103 else if (device->parent) 103 else if (device->parent)
104 device->status = device->parent->status; 104 device->status = device->parent->status;
105 else 105 else
106 STRUCT_TO_INT(device->status) = 0x0F; 106 STRUCT_TO_INT(device->status) =
107 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
108 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
107 109
108 if (device->status.functional && !device->status.present) { 110 if (device->status.functional && !device->status.present) {
109 printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: " 111 printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 0930d9413dfa..0dd3bf7c0ed1 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -49,8 +49,6 @@ MODULE_AUTHOR("Anil S Keshavamurthy");
49MODULE_DESCRIPTION("ACPI container driver"); 49MODULE_DESCRIPTION("ACPI container driver");
50MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
51 51
52#define ACPI_STA_PRESENT (0x00000001)
53
54static int acpi_container_add(struct acpi_device *device); 52static int acpi_container_add(struct acpi_device *device);
55static int acpi_container_remove(struct acpi_device *device, int type); 53static int acpi_container_remove(struct acpi_device *device, int type);
56 54
@@ -75,13 +73,13 @@ static int is_device_present(acpi_handle handle)
75 73
76 status = acpi_get_handle(handle, "_STA", &temp); 74 status = acpi_get_handle(handle, "_STA", &temp);
77 if (ACPI_FAILURE(status)) 75 if (ACPI_FAILURE(status))
78 return 1; /* _STA not found, assmue device present */ 76 return 1; /* _STA not found, assume device present */
79 77
80 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 78 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
81 if (ACPI_FAILURE(status)) 79 if (ACPI_FAILURE(status))
82 return 0; /* Firmware error */ 80 return 0; /* Firmware error */
83 81
84 return ((sta & ACPI_STA_PRESENT) == ACPI_STA_PRESENT); 82 return ((sta & ACPI_STA_DEVICE_PRESENT) == ACPI_STA_DEVICE_PRESENT);
85} 83}
86 84
87/*******************************************************************/ 85/*******************************************************************/
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 54a697f9aa18..4546bf873aea 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -29,6 +29,7 @@
29#include <linux/notifier.h> 29#include <linux/notifier.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/jiffies.h> 31#include <linux/jiffies.h>
32#include <linux/stddef.h>
32#include <acpi/acpi_bus.h> 33#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 34#include <acpi/acpi_drivers.h>
34 35
@@ -667,6 +668,23 @@ static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
667} 668}
668DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); 669DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
669 670
671/*
672 * show_dock_uid - read method for "uid" file in sysfs
673 */
674static ssize_t show_dock_uid(struct device *dev,
675 struct device_attribute *attr, char *buf)
676{
677 unsigned long lbuf;
678 acpi_status status = acpi_evaluate_integer(dock_station->handle, "_UID", NULL, &lbuf);
679 if(ACPI_FAILURE(status)) {
680 return 0;
681 }
682 return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf);
683}
684DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
685
686
687
670/** 688/**
671 * dock_add - add a new dock station 689 * dock_add - add a new dock station
672 * @handle: the dock station handle 690 * @handle: the dock station handle
@@ -715,6 +733,13 @@ static int dock_add(acpi_handle handle)
715 kfree(dock_station); 733 kfree(dock_station);
716 return ret; 734 return ret;
717 } 735 }
736 ret = device_create_file(&dock_device.dev, &dev_attr_uid);
737 if (ret) {
738 printk("Error %d adding sysfs file\n", ret);
739 platform_device_unregister(&dock_device);
740 kfree(dock_station);
741 return ret;
742 }
718 743
719 /* Find dependent devices */ 744 /* Find dependent devices */
720 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 745 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index a802962ff2b4..e08cf98f504f 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $) 2 * ec.c - ACPI Embedded Controller Driver (v2.0)
3 * 3 *
4 * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> 6 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 7 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 8 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
@@ -91,9 +93,9 @@ static struct acpi_driver acpi_ec_driver = {
91}; 93};
92 94
93/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 95/* If we find an EC via the ECDT, we need to keep a ptr to its context */
96/* External interfaces use first EC only, so remember */
94static struct acpi_ec { 97static struct acpi_ec {
95 acpi_handle handle; 98 acpi_handle handle;
96 unsigned long uid;
97 unsigned long gpe; 99 unsigned long gpe;
98 unsigned long command_addr; 100 unsigned long command_addr;
99 unsigned long data_addr; 101 unsigned long data_addr;
@@ -101,12 +103,8 @@ static struct acpi_ec {
101 struct mutex lock; 103 struct mutex lock;
102 atomic_t query_pending; 104 atomic_t query_pending;
103 atomic_t event_count; 105 atomic_t event_count;
104 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
105 wait_queue_head_t wait; 106 wait_queue_head_t wait;
106} *ec_ecdt; 107} *boot_ec, *first_ec;
107
108/* External interfaces use first EC only, so remember */
109static struct acpi_device *first_ec;
110 108
111/* -------------------------------------------------------------------------- 109/* --------------------------------------------------------------------------
112 Transaction Management 110 Transaction Management
@@ -173,56 +171,6 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, unsigned count)
173 return -ETIME; 171 return -ETIME;
174} 172}
175 173
176#ifdef ACPI_FUTURE_USAGE
177/*
178 * Note: samsung nv5000 doesn't work with ec burst mode.
179 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
180 */
181int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
182{
183 u8 tmp = 0;
184 u8 status = 0;
185
186 status = acpi_ec_read_status(ec);
187 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
188 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
189 if (status)
190 goto end;
191 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
192 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
193 tmp = acpi_ec_read_data(ec);
194 if (tmp != 0x90) { /* Burst ACK byte */
195 return -EINVAL;
196 }
197 }
198
199 atomic_set(&ec->leaving_burst, 0);
200 return 0;
201 end:
202 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
203 return -1;
204}
205
206int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
207{
208 u8 status = 0;
209
210 status = acpi_ec_read_status(ec);
211 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
212 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
213 if (status)
214 goto end;
215 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
216 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
217 }
218 atomic_set(&ec->leaving_burst, 1);
219 return 0;
220 end:
221 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
222 return -1;
223}
224#endif /* ACPI_FUTURE_USAGE */
225
226static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 174static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
227 const u8 * wdata, unsigned wdata_len, 175 const u8 * wdata, unsigned wdata_len,
228 u8 * rdata, unsigned rdata_len) 176 u8 * rdata, unsigned rdata_len)
@@ -312,6 +260,21 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
312 return status; 260 return status;
313} 261}
314 262
263/*
264 * Note: samsung nv5000 doesn't work with ec burst mode.
265 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
266 */
267int acpi_ec_burst_enable(struct acpi_ec *ec)
268{
269 u8 d;
270 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1);
271}
272
273int acpi_ec_burst_disable(struct acpi_ec *ec)
274{
275 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0);
276}
277
315static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) 278static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
316{ 279{
317 int result; 280 int result;
@@ -333,18 +296,33 @@ static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
333/* 296/*
334 * Externally callable EC access functions. For now, assume 1 EC only 297 * Externally callable EC access functions. For now, assume 1 EC only
335 */ 298 */
299int ec_burst_enable(void)
300{
301 if (!first_ec)
302 return -ENODEV;
303 return acpi_ec_burst_enable(first_ec);
304}
305
306EXPORT_SYMBOL(ec_burst_enable);
307
308int ec_burst_disable(void)
309{
310 if (!first_ec)
311 return -ENODEV;
312 return acpi_ec_burst_disable(first_ec);
313}
314
315EXPORT_SYMBOL(ec_burst_disable);
316
336int ec_read(u8 addr, u8 * val) 317int ec_read(u8 addr, u8 * val)
337{ 318{
338 struct acpi_ec *ec;
339 int err; 319 int err;
340 u8 temp_data; 320 u8 temp_data;
341 321
342 if (!first_ec) 322 if (!first_ec)
343 return -ENODEV; 323 return -ENODEV;
344 324
345 ec = acpi_driver_data(first_ec); 325 err = acpi_ec_read(first_ec, addr, &temp_data);
346
347 err = acpi_ec_read(ec, addr, &temp_data);
348 326
349 if (!err) { 327 if (!err) {
350 *val = temp_data; 328 *val = temp_data;
@@ -357,15 +335,12 @@ EXPORT_SYMBOL(ec_read);
357 335
358int ec_write(u8 addr, u8 val) 336int ec_write(u8 addr, u8 val)
359{ 337{
360 struct acpi_ec *ec;
361 int err; 338 int err;
362 339
363 if (!first_ec) 340 if (!first_ec)
364 return -ENODEV; 341 return -ENODEV;
365 342
366 ec = acpi_driver_data(first_ec); 343 err = acpi_ec_write(first_ec, addr, val);
367
368 err = acpi_ec_write(ec, addr, val);
369 344
370 return err; 345 return err;
371} 346}
@@ -376,14 +351,10 @@ int ec_transaction(u8 command,
376 const u8 * wdata, unsigned wdata_len, 351 const u8 * wdata, unsigned wdata_len,
377 u8 * rdata, unsigned rdata_len) 352 u8 * rdata, unsigned rdata_len)
378{ 353{
379 struct acpi_ec *ec;
380
381 if (!first_ec) 354 if (!first_ec)
382 return -ENODEV; 355 return -ENODEV;
383 356
384 ec = acpi_driver_data(first_ec); 357 return acpi_ec_transaction(first_ec, command, wdata,
385
386 return acpi_ec_transaction(ec, command, wdata,
387 wdata_len, rdata, rdata_len); 358 wdata_len, rdata, rdata_len);
388} 359}
389 360
@@ -420,7 +391,7 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
420 391
421static void acpi_ec_gpe_query(void *ec_cxt) 392static void acpi_ec_gpe_query(void *ec_cxt)
422{ 393{
423 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; 394 struct acpi_ec *ec = ec_cxt;
424 u8 value = 0; 395 u8 value = 0;
425 char object_name[8]; 396 char object_name[8];
426 397
@@ -438,8 +409,9 @@ static u32 acpi_ec_gpe_handler(void *data)
438{ 409{
439 acpi_status status = AE_OK; 410 acpi_status status = AE_OK;
440 u8 value; 411 u8 value;
441 struct acpi_ec *ec = (struct acpi_ec *)data; 412 struct acpi_ec *ec = data;
442 atomic_inc(&ec->event_count); 413 atomic_inc(&ec->event_count);
414
443 if (acpi_ec_mode == EC_INTR) { 415 if (acpi_ec_mode == EC_INTR) {
444 wake_up(&ec->wait); 416 wake_up(&ec->wait);
445 } 417 }
@@ -482,7 +454,7 @@ acpi_ec_space_handler(u32 function,
482 void *handler_context, void *region_context) 454 void *handler_context, void *region_context)
483{ 455{
484 int result = 0; 456 int result = 0;
485 struct acpi_ec *ec = NULL; 457 struct acpi_ec *ec = handler_context;
486 u64 temp = *value; 458 u64 temp = *value;
487 acpi_integer f_v = 0; 459 acpi_integer f_v = 0;
488 int i = 0; 460 int i = 0;
@@ -494,8 +466,6 @@ acpi_ec_space_handler(u32 function,
494 return AE_BAD_PARAMETER; 466 return AE_BAD_PARAMETER;
495 } 467 }
496 468
497 ec = (struct acpi_ec *)handler_context;
498
499 next_byte: 469 next_byte:
500 switch (function) { 470 switch (function) {
501 case ACPI_READ: 471 case ACPI_READ:
@@ -551,18 +521,16 @@ static struct proc_dir_entry *acpi_ec_dir;
551 521
552static int acpi_ec_read_info(struct seq_file *seq, void *offset) 522static int acpi_ec_read_info(struct seq_file *seq, void *offset)
553{ 523{
554 struct acpi_ec *ec = (struct acpi_ec *)seq->private; 524 struct acpi_ec *ec = seq->private;
555 525
556 if (!ec) 526 if (!ec)
557 goto end; 527 goto end;
558 528
559 seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe); 529 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
560 seq_printf(seq, "ports: 0x%02x, 0x%02x\n", 530 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
561 (u32) ec->command_addr, (u32) ec->data_addr); 531 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
562 seq_printf(seq, "use global lock: %s\n", 532 seq_printf(seq, "use global lock:\t%s\n",
563 ec->global_lock ? "yes" : "no"); 533 ec->global_lock ? "yes" : "no");
564 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
565
566 end: 534 end:
567 return 0; 535 return 0;
568} 536}
@@ -619,154 +587,122 @@ static int acpi_ec_remove_fs(struct acpi_device *device)
619/* -------------------------------------------------------------------------- 587/* --------------------------------------------------------------------------
620 Driver Interface 588 Driver Interface
621 -------------------------------------------------------------------------- */ 589 -------------------------------------------------------------------------- */
590static acpi_status
591ec_parse_io_ports(struct acpi_resource *resource, void *context);
592
593static acpi_status
594ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval);
595
596static struct acpi_ec *make_acpi_ec(void)
597{
598 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
599 if (!ec)
600 return NULL;
601
602 atomic_set(&ec->query_pending, 1);
603 atomic_set(&ec->event_count, 1);
604 mutex_init(&ec->lock);
605 init_waitqueue_head(&ec->wait);
606
607 return ec;
608}
622 609
623static int acpi_ec_add(struct acpi_device *device) 610static int acpi_ec_add(struct acpi_device *device)
624{ 611{
625 int result = 0;
626 acpi_status status = AE_OK; 612 acpi_status status = AE_OK;
627 struct acpi_ec *ec = NULL; 613 struct acpi_ec *ec = NULL;
628 614
629 if (!device) 615 if (!device)
630 return -EINVAL; 616 return -EINVAL;
631 617
632 ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
633 if (!ec)
634 return -ENOMEM;
635
636 ec->handle = device->handle;
637 ec->uid = -1;
638 mutex_init(&ec->lock);
639 atomic_set(&ec->query_pending, 0);
640 atomic_set(&ec->event_count, 1);
641 if (acpi_ec_mode == EC_INTR) {
642 atomic_set(&ec->leaving_burst, 1);
643 init_waitqueue_head(&ec->wait);
644 }
645 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); 618 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
646 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 619 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
647 acpi_driver_data(device) = ec;
648
649 /* Use the global lock for all EC transactions? */
650 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
651
652 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
653 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
654 if (ec_ecdt) {
655 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
656 ACPI_ADR_SPACE_EC,
657 &acpi_ec_space_handler);
658 620
659 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe, 621 ec = make_acpi_ec();
660 &acpi_ec_gpe_handler); 622 if (!ec)
623 return -ENOMEM;
661 624
662 kfree(ec_ecdt); 625 status = ec_parse_device(device->handle, 0, ec, NULL);
626 if (status != AE_CTRL_TERMINATE) {
627 kfree(ec);
628 return -EINVAL;
663 } 629 }
664 630
665 /* Get GPE bit assignment (EC events). */ 631 /* Check if we found the boot EC */
666 /* TODO: Add support for _GPE returning a package */ 632 if (boot_ec) {
667 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe); 633 if (boot_ec->gpe == ec->gpe) {
668 if (ACPI_FAILURE(status)) { 634 /* We might have incorrect info for GL at boot time */
669 ACPI_EXCEPTION((AE_INFO, status, 635 mutex_lock(&boot_ec->lock);
670 "Obtaining GPE bit assignment")); 636 boot_ec->global_lock = ec->global_lock;
671 result = -ENODEV; 637 mutex_unlock(&boot_ec->lock);
672 goto end; 638 kfree(ec);
673 } 639 ec = boot_ec;
640 }
641 } else
642 first_ec = ec;
643 ec->handle = device->handle;
644 acpi_driver_data(device) = ec;
674 645
675 result = acpi_ec_add_fs(device); 646 acpi_ec_add_fs(device);
676 if (result)
677 goto end;
678 647
679 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", 648 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
680 acpi_device_name(device), acpi_device_bid(device), 649 acpi_device_name(device), acpi_device_bid(device),
681 (u32) ec->gpe)); 650 (u32) ec->gpe));
682 651
683 if (!first_ec) 652 return 0;
684 first_ec = device;
685
686 end:
687 if (result)
688 kfree(ec);
689
690 return result;
691} 653}
692 654
693static int acpi_ec_remove(struct acpi_device *device, int type) 655static int acpi_ec_remove(struct acpi_device *device, int type)
694{ 656{
695 struct acpi_ec *ec = NULL; 657 struct acpi_ec *ec;
696 658
697 if (!device) 659 if (!device)
698 return -EINVAL; 660 return -EINVAL;
699 661
700 ec = acpi_driver_data(device); 662 ec = acpi_driver_data(device);
701
702 acpi_ec_remove_fs(device); 663 acpi_ec_remove_fs(device);
664 acpi_driver_data(device) = NULL;
665 if (ec == first_ec)
666 first_ec = NULL;
703 667
704 kfree(ec); 668 /* Don't touch boot EC */
705 669 if (boot_ec != ec)
670 kfree(ec);
706 return 0; 671 return 0;
707} 672}
708 673
709static acpi_status 674static acpi_status
710acpi_ec_io_ports(struct acpi_resource *resource, void *context) 675ec_parse_io_ports(struct acpi_resource *resource, void *context)
711{ 676{
712 struct acpi_ec *ec = (struct acpi_ec *)context; 677 struct acpi_ec *ec = context;
713 678
714 if (resource->type != ACPI_RESOURCE_TYPE_IO) { 679 if (resource->type != ACPI_RESOURCE_TYPE_IO)
715 return AE_OK; 680 return AE_OK;
716 }
717 681
718 /* 682 /*
719 * The first address region returned is the data port, and 683 * The first address region returned is the data port, and
720 * the second address region returned is the status/command 684 * the second address region returned is the status/command
721 * port. 685 * port.
722 */ 686 */
723 if (ec->data_addr == 0) { 687 if (ec->data_addr == 0)
724 ec->data_addr = resource->data.io.minimum; 688 ec->data_addr = resource->data.io.minimum;
725 } else if (ec->command_addr == 0) { 689 else if (ec->command_addr == 0)
726 ec->command_addr = resource->data.io.minimum; 690 ec->command_addr = resource->data.io.minimum;
727 } else { 691 else
728 return AE_CTRL_TERMINATE; 692 return AE_CTRL_TERMINATE;
729 }
730 693
731 return AE_OK; 694 return AE_OK;
732} 695}
733 696
734static int acpi_ec_start(struct acpi_device *device) 697static int ec_install_handlers(struct acpi_ec *ec)
735{ 698{
736 acpi_status status = AE_OK; 699 acpi_status status;
737 struct acpi_ec *ec = NULL;
738
739 if (!device)
740 return -EINVAL;
741
742 ec = acpi_driver_data(device);
743
744 if (!ec)
745 return -EINVAL;
746
747 /*
748 * Get I/O port addresses. Convert to GAS format.
749 */
750 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
751 acpi_ec_io_ports, ec);
752 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
753 ACPI_EXCEPTION((AE_INFO, status,
754 "Error getting I/O port addresses"));
755 return -ENODEV;
756 }
757
758 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
759 ec->gpe, ec->command_addr, ec->data_addr));
760
761 /*
762 * Install GPE handler
763 */
764 status = acpi_install_gpe_handler(NULL, ec->gpe, 700 status = acpi_install_gpe_handler(NULL, ec->gpe,
765 ACPI_GPE_EDGE_TRIGGERED, 701 ACPI_GPE_EDGE_TRIGGERED,
766 &acpi_ec_gpe_handler, ec); 702 &acpi_ec_gpe_handler, ec);
767 if (ACPI_FAILURE(status)) { 703 if (ACPI_FAILURE(status))
768 return -ENODEV; 704 return -ENODEV;
769 } 705
770 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); 706 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
771 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); 707 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
772 708
@@ -779,18 +715,49 @@ static int acpi_ec_start(struct acpi_device *device)
779 return -ENODEV; 715 return -ENODEV;
780 } 716 }
781 717
782 return AE_OK; 718 /* EC is fully operational, allow queries */
719 atomic_set(&ec->query_pending, 0);
720
721 return 0;
722}
723
724static int acpi_ec_start(struct acpi_device *device)
725{
726 struct acpi_ec *ec;
727
728 if (!device)
729 return -EINVAL;
730
731 ec = acpi_driver_data(device);
732
733 if (!ec)
734 return -EINVAL;
735
736 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
737 ec->gpe, ec->command_addr, ec->data_addr));
738
739 /* Boot EC is already working */
740 if (ec == boot_ec)
741 return 0;
742
743 return ec_install_handlers(ec);
783} 744}
784 745
785static int acpi_ec_stop(struct acpi_device *device, int type) 746static int acpi_ec_stop(struct acpi_device *device, int type)
786{ 747{
787 acpi_status status = AE_OK; 748 acpi_status status;
788 struct acpi_ec *ec = NULL; 749 struct acpi_ec *ec;
789 750
790 if (!device) 751 if (!device)
791 return -EINVAL; 752 return -EINVAL;
792 753
793 ec = acpi_driver_data(device); 754 ec = acpi_driver_data(device);
755 if (!ec)
756 return -EINVAL;
757
758 /* Don't touch boot EC */
759 if (ec == boot_ec)
760 return 0;
794 761
795 status = acpi_remove_address_space_handler(ec->handle, 762 status = acpi_remove_address_space_handler(ec->handle,
796 ACPI_ADR_SPACE_EC, 763 ACPI_ADR_SPACE_EC,
@@ -805,164 +772,67 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
805 return 0; 772 return 0;
806} 773}
807 774
808static acpi_status __init 775static acpi_status
809acpi_fake_ecdt_callback(acpi_handle handle, 776ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
810 u32 Level, void *context, void **retval)
811{ 777{
812 acpi_status status; 778 acpi_status status;
813 779
814 mutex_init(&ec_ecdt->lock); 780 struct acpi_ec *ec = context;
815 atomic_set(&ec_ecdt->event_count, 1);
816 if (acpi_ec_mode == EC_INTR) {
817 init_waitqueue_head(&ec_ecdt->wait);
818 }
819 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 781 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
820 acpi_ec_io_ports, ec_ecdt); 782 ec_parse_io_ports, ec);
821 if (ACPI_FAILURE(status)) 783 if (ACPI_FAILURE(status))
822 return status; 784 return status;
823 785
824 ec_ecdt->uid = -1; 786 /* Get GPE bit assignment (EC events). */
825 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); 787 /* TODO: Add support for _GPE returning a package */
826 788 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
827 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe);
828 if (ACPI_FAILURE(status)) 789 if (ACPI_FAILURE(status))
829 return status; 790 return status;
830 ec_ecdt->global_lock = TRUE;
831 ec_ecdt->handle = handle;
832
833 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
834 ec_ecdt->gpe, ec_ecdt->command_addr,
835 ec_ecdt->data_addr));
836 791
837 return AE_CTRL_TERMINATE; 792 /* Use the global lock for all EC transactions? */
838} 793 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
839
840/*
841 * Some BIOS (such as some from Gateway laptops) access EC region very early
842 * such as in BAT0._INI or EC._INI before an EC device is found and
843 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
844 * required, but if EC regison is accessed early, it is required.
845 * The routine tries to workaround the BIOS bug by pre-scan EC device
846 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
847 * op region (since _REG isn't invoked yet). The assumption is true for
848 * all systems found.
849 */
850static int __init acpi_ec_fake_ecdt(void)
851{
852 acpi_status status;
853 int ret = 0;
854 794
855 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); 795 ec->handle = handle;
856 796
857 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); 797 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
858 if (!ec_ecdt) { 798 ec->gpe, ec->command_addr, ec->data_addr));
859 ret = -ENOMEM;
860 goto error;
861 }
862 799
863 status = acpi_get_devices(ACPI_EC_HID, 800 return AE_CTRL_TERMINATE;
864 acpi_fake_ecdt_callback, NULL, NULL);
865 if (ACPI_FAILURE(status)) {
866 kfree(ec_ecdt);
867 ec_ecdt = NULL;
868 ret = -ENODEV;
869 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
870 goto error;
871 }
872 return 0;
873 error:
874 return ret;
875} 801}
876 802
877static int __init acpi_ec_get_real_ecdt(void) 803int __init acpi_ec_ecdt_probe(void)
878{ 804{
805 int ret;
879 acpi_status status; 806 acpi_status status;
880 struct acpi_table_ecdt *ecdt_ptr; 807 struct acpi_table_ecdt *ecdt_ptr;
881 808
882 status = acpi_get_table(ACPI_SIG_ECDT, 1, 809 boot_ec = make_acpi_ec();
883 (struct acpi_table_header **)&ecdt_ptr); 810 if (!boot_ec)
884 if (ACPI_FAILURE(status)) 811 return -ENOMEM;
885 return -ENODEV;
886
887 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
888
889 /* 812 /*
890 * Generate a temporary ec context to use until the namespace is scanned 813 * Generate a boot ec context
891 */ 814 */
892 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
893 if (!ec_ecdt)
894 return -ENOMEM;
895 815
896 mutex_init(&ec_ecdt->lock); 816 status = acpi_get_table(ACPI_SIG_ECDT, 1,
897 atomic_set(&ec_ecdt->event_count, 1); 817 (struct acpi_table_header **)&ecdt_ptr);
898 if (acpi_ec_mode == EC_INTR) { 818 if (ACPI_FAILURE(status))
899 init_waitqueue_head(&ec_ecdt->wait);
900 }
901 ec_ecdt->command_addr = ecdt_ptr->control.address;
902 ec_ecdt->data_addr = ecdt_ptr->data.address;
903 ec_ecdt->gpe = ecdt_ptr->gpe;
904 /* use the GL just to be safe */
905 ec_ecdt->global_lock = TRUE;
906 ec_ecdt->uid = ecdt_ptr->uid;
907
908 status = acpi_get_handle(NULL, ecdt_ptr->id, &ec_ecdt->handle);
909 if (ACPI_FAILURE(status)) {
910 goto error; 819 goto error;
911 }
912
913 return 0;
914 error:
915 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
916 kfree(ec_ecdt);
917 ec_ecdt = NULL;
918 820
919 return -ENODEV; 821 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
920}
921
922static int __initdata acpi_fake_ecdt_enabled;
923int __init acpi_ec_ecdt_probe(void)
924{
925 acpi_status status;
926 int ret;
927 822
928 ret = acpi_ec_get_real_ecdt(); 823 boot_ec->command_addr = ecdt_ptr->control.address;
929 /* Try to make a fake ECDT */ 824 boot_ec->data_addr = ecdt_ptr->data.address;
930 if (ret && acpi_fake_ecdt_enabled) { 825 boot_ec->gpe = ecdt_ptr->gpe;
931 ret = acpi_ec_fake_ecdt(); 826 boot_ec->handle = ACPI_ROOT_OBJECT;
932 }
933 827
934 if (ret) 828 ret = ec_install_handlers(boot_ec);
829 if (!ret) {
830 first_ec = boot_ec;
935 return 0; 831 return 0;
936
937 /*
938 * Install GPE handler
939 */
940 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe,
941 ACPI_GPE_EDGE_TRIGGERED,
942 &acpi_ec_gpe_handler, ec_ecdt);
943 if (ACPI_FAILURE(status)) {
944 goto error;
945 } 832 }
946 acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME);
947 acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR);
948
949 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
950 ACPI_ADR_SPACE_EC,
951 &acpi_ec_space_handler,
952 &acpi_ec_space_setup,
953 ec_ecdt);
954 if (ACPI_FAILURE(status)) {
955 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
956 &acpi_ec_gpe_handler);
957 goto error;
958 }
959
960 return 0;
961
962 error: 833 error:
963 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); 834 kfree(boot_ec);
964 kfree(ec_ecdt); 835 boot_ec = NULL;
965 ec_ecdt = NULL;
966 836
967 return -ENODEV; 837 return -ENODEV;
968} 838}
@@ -1003,13 +873,6 @@ static void __exit acpi_ec_exit(void)
1003} 873}
1004#endif /* 0 */ 874#endif /* 0 */
1005 875
1006static int __init acpi_fake_ecdt_setup(char *str)
1007{
1008 acpi_fake_ecdt_enabled = 1;
1009 return 1;
1010}
1011
1012__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1013static int __init acpi_ec_set_intr_mode(char *str) 876static int __init acpi_ec_set_intr_mode(char *str)
1014{ 877{
1015 int intr; 878 int intr;
@@ -1017,12 +880,8 @@ static int __init acpi_ec_set_intr_mode(char *str)
1017 if (!get_option(&str, &intr)) 880 if (!get_option(&str, &intr))
1018 return 0; 881 return 0;
1019 882
1020 if (intr) { 883 acpi_ec_mode = (intr) ? EC_INTR : EC_POLL;
1021 acpi_ec_mode = EC_INTR; 884
1022 } else {
1023 acpi_ec_mode = EC_POLL;
1024 }
1025 acpi_ec_driver.ops.add = acpi_ec_add;
1026 printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling"); 885 printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling");
1027 886
1028 return 1; 887 return 1;
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
deleted file mode 100644
index acab4a481897..000000000000
--- a/drivers/acpi/i2c_ec.c
+++ /dev/null
@@ -1,403 +0,0 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.3 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
5 * Copyright (c) 2005 Rich Townsend (tiny hacks & tweaks)
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 version 2.
10 */
11
12#include <linux/version.h>
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/kernel.h>
16#include <linux/stddef.h>
17#include <linux/init.h>
18#include <linux/i2c.h>
19#include <linux/acpi.h>
20#include <linux/delay.h>
21
22#include "i2c_ec.h"
23
24#define xudelay(t) udelay(t)
25#define xmsleep(t) msleep(t)
26
27#define ACPI_EC_HC_COMPONENT 0x00080000
28#define ACPI_EC_HC_CLASS "ec_hc_smbus"
29#define ACPI_EC_HC_HID "ACPI0001"
30#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
31
32#define _COMPONENT ACPI_EC_HC_COMPONENT
33
34ACPI_MODULE_NAME("i2c_ec");
35
36static int acpi_ec_hc_add(struct acpi_device *device);
37static int acpi_ec_hc_remove(struct acpi_device *device, int type);
38
39static struct acpi_driver acpi_ec_hc_driver = {
40 .name = "i2c_ec",
41 .class = ACPI_EC_HC_CLASS,
42 .ids = ACPI_EC_HC_HID,
43 .ops = {
44 .add = acpi_ec_hc_add,
45 .remove = acpi_ec_hc_remove,
46 },
47};
48
49/* Various bit mask for EC_SC (R) */
50#define OBF 0x01
51#define IBF 0x02
52#define CMD 0x08
53#define BURST 0x10
54#define SCI_EVT 0x20
55#define SMI_EVT 0x40
56
57/* Commands for EC_SC (W) */
58#define RD_EC 0x80
59#define WR_EC 0x81
60#define BE_EC 0x82
61#define BD_EC 0x83
62#define QR_EC 0x84
63
64/*
65 * ACPI 2.0 chapter 13 SMBus 2.0 EC register model
66 */
67
68#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
69#define ACPI_EC_SMB_STS 0x01 /* status */
70#define ACPI_EC_SMB_ADDR 0x02 /* address */
71#define ACPI_EC_SMB_CMD 0x03 /* command */
72#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
73#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
74#define ACPI_EC_SMB_ALRM_A 0x25 /* alarm address */
75#define ACPI_EC_SMB_ALRM_D 0x26 /* 2 bytes alarm data */
76
77#define ACPI_EC_SMB_STS_DONE 0x80
78#define ACPI_EC_SMB_STS_ALRM 0x40
79#define ACPI_EC_SMB_STS_RES 0x20
80#define ACPI_EC_SMB_STS_STATUS 0x1f
81
82#define ACPI_EC_SMB_STATUS_OK 0x00
83#define ACPI_EC_SMB_STATUS_FAIL 0x07
84#define ACPI_EC_SMB_STATUS_DNAK 0x10
85#define ACPI_EC_SMB_STATUS_DERR 0x11
86#define ACPI_EC_SMB_STATUS_CMD_DENY 0x12
87#define ACPI_EC_SMB_STATUS_UNKNOWN 0x13
88#define ACPI_EC_SMB_STATUS_ACC_DENY 0x17
89#define ACPI_EC_SMB_STATUS_TIMEOUT 0x18
90#define ACPI_EC_SMB_STATUS_NOTSUP 0x19
91#define ACPI_EC_SMB_STATUS_BUSY 0x1A
92#define ACPI_EC_SMB_STATUS_PEC 0x1F
93
94#define ACPI_EC_SMB_PRTCL_WRITE 0x00
95#define ACPI_EC_SMB_PRTCL_READ 0x01
96#define ACPI_EC_SMB_PRTCL_QUICK 0x02
97#define ACPI_EC_SMB_PRTCL_BYTE 0x04
98#define ACPI_EC_SMB_PRTCL_BYTE_DATA 0x06
99#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
100#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
101#define ACPI_EC_SMB_PRTCL_PROC_CALL 0x0c
102#define ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
103#define ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
104#define ACPI_EC_SMB_PRTCL_PEC 0x80
105
106/* Length of pre/post transaction sleep (msec) */
107#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
108#define ACPI_EC_SMB_ACCESS_SLEEP1 1
109#define ACPI_EC_SMB_ACCESS_SLEEP2 10
110
111static int acpi_ec_smb_read(struct acpi_ec_smbus *smbus, u8 address, u8 * data)
112{
113 u8 val;
114 int err;
115
116 err = ec_read(smbus->base + address, &val);
117 if (!err) {
118 *data = val;
119 }
120 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
121 return (err);
122}
123
124static int acpi_ec_smb_write(struct acpi_ec_smbus *smbus, u8 address, u8 data)
125{
126 int err;
127
128 err = ec_write(smbus->base + address, data);
129 return (err);
130}
131
132static int
133acpi_ec_smb_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
134 char read_write, u8 command, int size,
135 union i2c_smbus_data *data)
136{
137 struct acpi_ec_smbus *smbus = adap->algo_data;
138 unsigned char protocol, len = 0, pec, temp[2] = { 0, 0 };
139 int i;
140
141 if (read_write == I2C_SMBUS_READ) {
142 protocol = ACPI_EC_SMB_PRTCL_READ;
143 } else {
144 protocol = ACPI_EC_SMB_PRTCL_WRITE;
145 }
146 pec = (flags & I2C_CLIENT_PEC) ? ACPI_EC_SMB_PRTCL_PEC : 0;
147
148 switch (size) {
149
150 case I2C_SMBUS_QUICK:
151 protocol |= ACPI_EC_SMB_PRTCL_QUICK;
152 read_write = I2C_SMBUS_WRITE;
153 break;
154
155 case I2C_SMBUS_BYTE:
156 if (read_write == I2C_SMBUS_WRITE) {
157 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
158 }
159 protocol |= ACPI_EC_SMB_PRTCL_BYTE;
160 break;
161
162 case I2C_SMBUS_BYTE_DATA:
163 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
164 if (read_write == I2C_SMBUS_WRITE) {
165 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->byte);
166 }
167 protocol |= ACPI_EC_SMB_PRTCL_BYTE_DATA;
168 break;
169
170 case I2C_SMBUS_WORD_DATA:
171 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
172 if (read_write == I2C_SMBUS_WRITE) {
173 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
174 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1,
175 data->word >> 8);
176 }
177 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA | pec;
178 break;
179
180 case I2C_SMBUS_BLOCK_DATA:
181 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
182 if (read_write == I2C_SMBUS_WRITE) {
183 len = min_t(u8, data->block[0], 32);
184 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
185 for (i = 0; i < len; i++)
186 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
187 data->block[i + 1]);
188 }
189 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA | pec;
190 break;
191
192 case I2C_SMBUS_I2C_BLOCK_DATA:
193 len = min_t(u8, data->block[0], 32);
194 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
195 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
196 if (read_write == I2C_SMBUS_WRITE) {
197 for (i = 0; i < len; i++) {
198 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
199 data->block[i + 1]);
200 }
201 }
202 protocol |= ACPI_EC_SMB_PRTCL_I2C_BLOCK_DATA;
203 break;
204
205 case I2C_SMBUS_PROC_CALL:
206 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
207 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA, data->word);
208 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + 1, data->word >> 8);
209 protocol = ACPI_EC_SMB_PRTCL_PROC_CALL | pec;
210 read_write = I2C_SMBUS_READ;
211 break;
212
213 case I2C_SMBUS_BLOCK_PROC_CALL:
214 protocol |= pec;
215 len = min_t(u8, data->block[0], 31);
216 acpi_ec_smb_write(smbus, ACPI_EC_SMB_CMD, command);
217 acpi_ec_smb_write(smbus, ACPI_EC_SMB_BCNT, len);
218 for (i = 0; i < len; i++)
219 acpi_ec_smb_write(smbus, ACPI_EC_SMB_DATA + i,
220 data->block[i + 1]);
221 protocol = ACPI_EC_SMB_PRTCL_BLOCK_PROC_CALL | pec;
222 read_write = I2C_SMBUS_READ;
223 break;
224
225 default:
226 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "EC SMBus adapter: "
227 "Unsupported transaction %d\n", size));
228 return (-1);
229 }
230
231 acpi_ec_smb_write(smbus, ACPI_EC_SMB_ADDR, addr << 1);
232 acpi_ec_smb_write(smbus, ACPI_EC_SMB_PRTCL, protocol);
233
234 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
235
236 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
237 xudelay(500);
238 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
239 }
240 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
241 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
242 acpi_ec_smb_read(smbus, ACPI_EC_SMB_STS, temp + 0);
243 }
244 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
245 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
246 return (-1);
247 }
248
249 if (read_write == I2C_SMBUS_WRITE) {
250 return (0);
251 }
252
253 switch (size) {
254
255 case I2C_SMBUS_BYTE:
256 case I2C_SMBUS_BYTE_DATA:
257 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, &data->byte);
258 break;
259
260 case I2C_SMBUS_WORD_DATA:
261 case I2C_SMBUS_PROC_CALL:
262 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA, temp + 0);
263 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + 1, temp + 1);
264 data->word = (temp[1] << 8) | temp[0];
265 break;
266
267 case I2C_SMBUS_BLOCK_DATA:
268 case I2C_SMBUS_BLOCK_PROC_CALL:
269 len = 0;
270 acpi_ec_smb_read(smbus, ACPI_EC_SMB_BCNT, &len);
271 len = min_t(u8, len, 32);
272 case I2C_SMBUS_I2C_BLOCK_DATA:
273 for (i = 0; i < len; i++)
274 acpi_ec_smb_read(smbus, ACPI_EC_SMB_DATA + i,
275 data->block + i + 1);
276 data->block[0] = len;
277 break;
278 }
279
280 return (0);
281}
282
283static u32 acpi_ec_smb_func(struct i2c_adapter *adapter)
284{
285
286 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
287 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
288 I2C_FUNC_SMBUS_BLOCK_DATA |
289 I2C_FUNC_SMBUS_PROC_CALL |
290 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
291 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC);
292}
293
294static const struct i2c_algorithm acpi_ec_smbus_algorithm = {
295 .smbus_xfer = acpi_ec_smb_access,
296 .functionality = acpi_ec_smb_func,
297};
298
299static int acpi_ec_hc_add(struct acpi_device *device)
300{
301 int status;
302 unsigned long val;
303 struct acpi_ec_hc *ec_hc;
304 struct acpi_ec_smbus *smbus;
305
306 if (!device) {
307 return -EINVAL;
308 }
309
310 ec_hc = kzalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
311 if (!ec_hc) {
312 return -ENOMEM;
313 }
314
315 smbus = kzalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
316 if (!smbus) {
317 kfree(ec_hc);
318 return -ENOMEM;
319 }
320
321 ec_hc->handle = device->handle;
322 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
323 strcpy(acpi_device_class(device), ACPI_EC_HC_CLASS);
324 acpi_driver_data(device) = ec_hc;
325
326 status = acpi_evaluate_integer(ec_hc->handle, "_EC", NULL, &val);
327 if (ACPI_FAILURE(status)) {
328 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Error obtaining _EC\n"));
329 kfree(ec_hc);
330 kfree(smbus);
331 return -EIO;
332 }
333
334 smbus->ec = acpi_driver_data(device->parent);
335 smbus->base = (val & 0xff00ull) >> 8;
336 smbus->alert = val & 0xffull;
337
338 smbus->adapter.owner = THIS_MODULE;
339 smbus->adapter.algo = &acpi_ec_smbus_algorithm;
340 smbus->adapter.algo_data = smbus;
341 smbus->adapter.dev.parent = &device->dev;
342
343 if (i2c_add_adapter(&smbus->adapter)) {
344 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
345 "EC SMBus adapter: Failed to register adapter\n"));
346 kfree(smbus);
347 kfree(ec_hc);
348 return -EIO;
349 }
350
351 ec_hc->smbus = smbus;
352
353 printk(KERN_INFO PREFIX "%s [%s]\n",
354 acpi_device_name(device), acpi_device_bid(device));
355
356 return AE_OK;
357}
358
359static int acpi_ec_hc_remove(struct acpi_device *device, int type)
360{
361 struct acpi_ec_hc *ec_hc;
362
363 if (!device) {
364 return -EINVAL;
365 }
366 ec_hc = acpi_driver_data(device);
367
368 i2c_del_adapter(&ec_hc->smbus->adapter);
369 kfree(ec_hc->smbus);
370 kfree(ec_hc);
371
372 return AE_OK;
373}
374
375static int __init acpi_ec_hc_init(void)
376{
377 int result;
378
379 result = acpi_bus_register_driver(&acpi_ec_hc_driver);
380 if (result < 0) {
381 return -ENODEV;
382 }
383 return 0;
384}
385
386static void __exit acpi_ec_hc_exit(void)
387{
388 acpi_bus_unregister_driver(&acpi_ec_hc_driver);
389}
390
391struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
392{
393 return acpi_driver_data(device->parent);
394}
395
396EXPORT_SYMBOL(acpi_get_ec_hc);
397
398module_init(acpi_ec_hc_init);
399module_exit(acpi_ec_hc_exit);
400
401MODULE_LICENSE("GPL");
402MODULE_AUTHOR("Ducrot Bruno");
403MODULE_DESCRIPTION("ACPI EC SMBus driver");
diff --git a/drivers/acpi/i2c_ec.h b/drivers/acpi/i2c_ec.h
deleted file mode 100644
index 7c53fb732d61..000000000000
--- a/drivers/acpi/i2c_ec.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 * SMBus driver for ACPI Embedded Controller ($Revision: 1.2 $)
3 *
4 * Copyright (c) 2002, 2005 Ducrot Bruno
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 as published by
8 * the Free Software Foundation version 2.
9 */
10
11struct acpi_ec_smbus {
12 struct i2c_adapter adapter;
13 union acpi_ec *ec;
14 int base;
15 int alert;
16};
17
18struct acpi_ec_hc {
19 acpi_handle handle;
20 struct acpi_ec_smbus *smbus;
21};
22
23struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device);
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
deleted file mode 100644
index dc1096608f43..000000000000
--- a/drivers/acpi/ibm_acpi.c
+++ /dev/null
@@ -1,2798 +0,0 @@
1/*
2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
3 *
4 *
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#define IBM_VERSION "0.13"
24
25/*
26 * Changelog:
27 *
28 * 2006-11-22 0.13 new maintainer
29 * changelog now lives in git commit history, and will
30 * not be updated further in-file.
31 *
32 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
33 * 2005-03-17 0.11 support for 600e, 770x
34 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
35 * support for 770e, G41
36 * G40 and G41 don't have a thinklight
37 * temperatures no longer experimental
38 * experimental brightness control
39 * experimental volume control
40 * experimental fan enable/disable
41 * 2005-01-16 0.10 fix module loading on R30, R31
42 * 2005-01-16 0.9 support for 570, R30, R31
43 * ultrabay support on A22p, A3x
44 * limit arg for cmos, led, beep, drop experimental status
45 * more capable led control on A21e, A22p, T20-22, X20
46 * experimental temperatures and fan speed
47 * experimental embedded controller register dump
48 * mark more functions as __init, drop incorrect __exit
49 * use MODULE_VERSION
50 * thanks to Henrik Brix Andersen <brix@gentoo.org>
51 * fix parameter passing on module loading
52 * thanks to Rusty Russell <rusty@rustcorp.com.au>
53 * thanks to Jim Radford <radford@blackbean.org>
54 * 2004-11-08 0.8 fix init error case, don't return from a macro
55 * thanks to Chris Wright <chrisw@osdl.org>
56 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
57 * fix led control on A21e
58 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
59 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
60 * proc file format changed
61 * video_switch command
62 * experimental cmos control
63 * experimental led control
64 * experimental acpi sounds
65 * 2004-09-16 0.4 support for module parameters
66 * hotkey mask can be prefixed by 0x
67 * video output switching
68 * video expansion control
69 * ultrabay eject support
70 * removed lcd brightness/on/off control, didn't work
71 * 2004-08-17 0.3 support for R40
72 * lcd off, brightness control
73 * thinklight on/off
74 * 2004-08-14 0.2 support for T series, X20
75 * bluetooth enable/disable
76 * hotkey events disabled by default
77 * removed fan control, currently useless
78 * 2004-08-09 0.1 initial release, support for X series
79 */
80
81#include <linux/kernel.h>
82#include <linux/module.h>
83#include <linux/init.h>
84#include <linux/types.h>
85#include <linux/string.h>
86
87#include <linux/proc_fs.h>
88#include <linux/backlight.h>
89#include <linux/fb.h>
90#include <asm/uaccess.h>
91
92#include <linux/dmi.h>
93#include <linux/jiffies.h>
94#include <linux/workqueue.h>
95
96#include <acpi/acpi_drivers.h>
97#include <acpi/acnamesp.h>
98
99#define IBM_NAME "ibm"
100#define IBM_DESC "IBM ThinkPad ACPI Extras"
101#define IBM_FILE "ibm_acpi"
102#define IBM_URL "http://ibm-acpi.sf.net/"
103
104MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
105MODULE_DESCRIPTION(IBM_DESC);
106MODULE_VERSION(IBM_VERSION);
107MODULE_LICENSE("GPL");
108
109#define IBM_DIR IBM_NAME
110
111#define IBM_LOG IBM_FILE ": "
112#define IBM_ERR KERN_ERR IBM_LOG
113#define IBM_NOTICE KERN_NOTICE IBM_LOG
114#define IBM_INFO KERN_INFO IBM_LOG
115#define IBM_DEBUG KERN_DEBUG IBM_LOG
116
117#define IBM_MAX_ACPI_ARGS 3
118
119#define __unused __attribute__ ((unused))
120
121static int experimental;
122module_param(experimental, int, 0);
123
124static acpi_handle root_handle = NULL;
125
126#define IBM_HANDLE(object, parent, paths...) \
127 static acpi_handle object##_handle; \
128 static acpi_handle *object##_parent = &parent##_handle; \
129 static char *object##_path; \
130 static char *object##_paths[] = { paths }
131
132IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
133 "\\_SB.PCI.ISA.EC", /* 570 */
134 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
135 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
136 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
137 "\\_SB.PCI0.ICH3.EC0", /* R31 */
138 "\\_SB.PCI0.LPC.EC", /* all others */
139 );
140
141IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
142 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
143 "\\_SB.PCI0.VID0", /* 770e */
144 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
145 "\\_SB.PCI0.AGP.VID", /* all others */
146 ); /* R30, R31 */
147
148IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
149
150IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
151 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
152 "\\CMS", /* R40, R40e */
153 ); /* all others */
154#ifdef CONFIG_ACPI_IBM_DOCK
155IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
156 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
157 "\\_SB.PCI0.PCI1.DOCK", /* all others */
158 "\\_SB.PCI.ISA.SLCE", /* 570 */
159 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
160#endif
161#ifdef CONFIG_ACPI_IBM_BAY
162IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
163 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
164 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
165 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
166 ); /* A21e, R30, R31 */
167
168IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
169 "_EJ0", /* all others */
170 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
171
172IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
173 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
174 ); /* all others */
175
176IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
177 "_EJ0", /* 770x */
178 ); /* all others */
179#endif /* CONFIG_ACPI_IBM_BAY */
180
181/* don't list other alternatives as we install a notify handler on the 570 */
182IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
183
184IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
185 "^HKEY", /* R30, R31 */
186 "HKEY", /* all others */
187 ); /* 570 */
188
189IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
190IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
191
192IBM_HANDLE(led, ec, "SLED", /* 570 */
193 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
194 "LED", /* all others */
195 ); /* R30, R31 */
196
197IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
198IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
199IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
200IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
201
202IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
203 "\\FSPD", /* 600e/x, 770e, 770x */
204 ); /* all others */
205
206IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
207 "JFNS", /* 770x-JL */
208 ); /* all others */
209
210#define IBM_HKEY_HID "IBM0068"
211#define IBM_PCI_HID "PNP0A03"
212
213enum thermal_access_mode {
214 IBMACPI_THERMAL_NONE = 0, /* No thermal support */
215 IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
216 IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
217 IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
218 IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
219};
220
221#define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
222struct ibm_thermal_sensors_struct {
223 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
224};
225
226/*
227 * FAN ACCESS MODES
228 *
229 * IBMACPI_FAN_RD_ACPI_GFAN:
230 * ACPI GFAN method: returns fan level
231 *
232 * see IBMACPI_FAN_WR_ACPI_SFAN
233 * EC 0x2f not available if GFAN exists
234 *
235 * IBMACPI_FAN_WR_ACPI_SFAN:
236 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
237 *
238 * EC 0x2f might be available *for reading*, but never for writing.
239 *
240 * IBMACPI_FAN_WR_TPEC:
241 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
242 * on almost all ThinkPads
243 *
244 * Fan speed changes of any sort (including those caused by the
245 * disengaged mode) are usually done slowly by the firmware as the
246 * maximum ammount of fan duty cycle change per second seems to be
247 * limited.
248 *
249 * Reading is not available if GFAN exists.
250 * Writing is not available if SFAN exists.
251 *
252 * Bits
253 * 7 automatic mode engaged;
254 * (default operation mode of the ThinkPad)
255 * fan level is ignored in this mode.
256 * 6 disengage mode (takes precedence over bit 7);
257 * not available on all thinkpads. May disable
258 * the tachometer, and speeds up fan to 100% duty-cycle,
259 * which speeds it up far above the standard RPM
260 * levels. It is not impossible that it could cause
261 * hardware damage.
262 * 5-3 unused in some models. Extra bits for fan level
263 * in others, but still useless as all values above
264 * 7 map to the same speed as level 7 in these models.
265 * 2-0 fan level (0..7 usually)
266 * 0x00 = stop
267 * 0x07 = max (set when temperatures critical)
268 * Some ThinkPads may have other levels, see
269 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
270 *
271 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
272 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
273 * does so, its initial value is meaningless (0x07).
274 *
275 * For firmware bugs, refer to:
276 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
277 *
278 * ----
279 *
280 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
281 * Main fan tachometer reading (in RPM)
282 *
283 * This register is present on all ThinkPads with a new-style EC, and
284 * it is known not to be present on the A21m/e, and T22, as there is
285 * something else in offset 0x84 according to the ACPI DSDT. Other
286 * ThinkPads from this same time period (and earlier) probably lack the
287 * tachometer as well.
288 *
289 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
290 * was never fixed by IBM to report the EC firmware version string
291 * probably support the tachometer (like the early X models), so
292 * detecting it is quite hard. We need more data to know for sure.
293 *
294 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
295 * might result.
296 *
297 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
298 * register is not invalidated in ThinkPads that disable tachometer
299 * readings. Thus, the tachometer readings go stale.
300 *
301 * For firmware bugs, refer to:
302 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
303 *
304 * IBMACPI_FAN_WR_ACPI_FANS:
305 * ThinkPad X31, X40, X41. Not available in the X60.
306 *
307 * FANS ACPI handle: takes three arguments: low speed, medium speed,
308 * high speed. ACPI DSDT seems to map these three speeds to levels
309 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
310 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
311 *
312 * The speeds are stored on handles
313 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
314 *
315 * There are three default speed sets, acessible as handles:
316 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
317 *
318 * ACPI DSDT switches which set is in use depending on various
319 * factors.
320 *
321 * IBMACPI_FAN_WR_TPEC is also available and should be used to
322 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
323 * but the ACPI tables just mention level 7.
324 */
325
326enum fan_status_access_mode {
327 IBMACPI_FAN_NONE = 0, /* No fan status or control */
328 IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
329 IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
330};
331
332enum fan_control_access_mode {
333 IBMACPI_FAN_WR_NONE = 0, /* No fan control */
334 IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
335 IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
336 IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
337};
338
339enum fan_control_commands {
340 IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
341 IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
342 IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
343 * and also watchdog cmd */
344};
345
346enum { /* Fan control constants */
347 fan_status_offset = 0x2f, /* EC register 0x2f */
348 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
349 * 0x84 must be read before 0x85 */
350
351 IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
352 * disengaged */
353 IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
354 * control */
355};
356
357static char *ibm_thinkpad_ec_found = NULL;
358
359struct ibm_struct {
360 char *name;
361 char param[32];
362
363 char *hid;
364 struct acpi_driver *driver;
365
366 int (*init) (void);
367 int (*read) (char *);
368 int (*write) (char *);
369 void (*exit) (void);
370
371 void (*notify) (struct ibm_struct *, u32);
372 acpi_handle *handle;
373 int type;
374 struct acpi_device *device;
375
376 int driver_registered;
377 int proc_created;
378 int init_called;
379 int notify_installed;
380
381 int experimental;
382};
383
384static struct proc_dir_entry *proc_dir = NULL;
385
386static struct backlight_device *ibm_backlight_device = NULL;
387
388#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
389#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
390#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
391
392static int acpi_evalf(acpi_handle handle,
393 void *res, char *method, char *fmt, ...)
394{
395 char *fmt0 = fmt;
396 struct acpi_object_list params;
397 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
398 struct acpi_buffer result, *resultp;
399 union acpi_object out_obj;
400 acpi_status status;
401 va_list ap;
402 char res_type;
403 int success;
404 int quiet;
405
406 if (!*fmt) {
407 printk(IBM_ERR "acpi_evalf() called with empty format\n");
408 return 0;
409 }
410
411 if (*fmt == 'q') {
412 quiet = 1;
413 fmt++;
414 } else
415 quiet = 0;
416
417 res_type = *(fmt++);
418
419 params.count = 0;
420 params.pointer = &in_objs[0];
421
422 va_start(ap, fmt);
423 while (*fmt) {
424 char c = *(fmt++);
425 switch (c) {
426 case 'd': /* int */
427 in_objs[params.count].integer.value = va_arg(ap, int);
428 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
429 break;
430 /* add more types as needed */
431 default:
432 printk(IBM_ERR "acpi_evalf() called "
433 "with invalid format character '%c'\n", c);
434 return 0;
435 }
436 }
437 va_end(ap);
438
439 if (res_type != 'v') {
440 result.length = sizeof(out_obj);
441 result.pointer = &out_obj;
442 resultp = &result;
443 } else
444 resultp = NULL;
445
446 status = acpi_evaluate_object(handle, method, &params, resultp);
447
448 switch (res_type) {
449 case 'd': /* int */
450 if (res)
451 *(int *)res = out_obj.integer.value;
452 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
453 break;
454 case 'v': /* void */
455 success = status == AE_OK;
456 break;
457 /* add more types as needed */
458 default:
459 printk(IBM_ERR "acpi_evalf() called "
460 "with invalid format character '%c'\n", res_type);
461 return 0;
462 }
463
464 if (!success && !quiet)
465 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
466 method, fmt0, status);
467
468 return success;
469}
470
471static void __unused acpi_print_int(acpi_handle handle, char *method)
472{
473 int i;
474
475 if (acpi_evalf(handle, &i, method, "d"))
476 printk(IBM_INFO "%s = 0x%x\n", method, i);
477 else
478 printk(IBM_ERR "error calling %s\n", method);
479}
480
481static char *next_cmd(char **cmds)
482{
483 char *start = *cmds;
484 char *end;
485
486 while ((end = strchr(start, ',')) && end == start)
487 start = end + 1;
488
489 if (!end)
490 return NULL;
491
492 *end = 0;
493 *cmds = end + 1;
494 return start;
495}
496
497static int ibm_acpi_driver_init(void)
498{
499 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
500 printk(IBM_INFO "%s\n", IBM_URL);
501
502 if (ibm_thinkpad_ec_found)
503 printk(IBM_INFO "ThinkPad EC firmware %s\n",
504 ibm_thinkpad_ec_found);
505
506 return 0;
507}
508
509static int driver_read(char *p)
510{
511 int len = 0;
512
513 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
514 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
515
516 return len;
517}
518
519static int hotkey_supported;
520static int hotkey_mask_supported;
521static int hotkey_orig_status;
522static int hotkey_orig_mask;
523
524static int hotkey_get(int *status, int *mask)
525{
526 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
527 return 0;
528
529 if (hotkey_mask_supported)
530 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
531 return 0;
532
533 return 1;
534}
535
536static int hotkey_set(int status, int mask)
537{
538 int i;
539
540 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
541 return 0;
542
543 if (hotkey_mask_supported)
544 for (i = 0; i < 32; i++) {
545 int bit = ((1 << i) & mask) != 0;
546 if (!acpi_evalf(hkey_handle,
547 NULL, "MHKM", "vdd", i + 1, bit))
548 return 0;
549 }
550
551 return 1;
552}
553
554static int hotkey_init(void)
555{
556 /* hotkey not supported on 570 */
557 hotkey_supported = hkey_handle != NULL;
558
559 if (hotkey_supported) {
560 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
561 A30, R30, R31, T20-22, X20-21, X22-24 */
562 hotkey_mask_supported =
563 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
564
565 if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
566 return -ENODEV;
567 }
568
569 return 0;
570}
571
572static int hotkey_read(char *p)
573{
574 int status, mask;
575 int len = 0;
576
577 if (!hotkey_supported) {
578 len += sprintf(p + len, "status:\t\tnot supported\n");
579 return len;
580 }
581
582 if (!hotkey_get(&status, &mask))
583 return -EIO;
584
585 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
586 if (hotkey_mask_supported) {
587 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
588 len += sprintf(p + len,
589 "commands:\tenable, disable, reset, <mask>\n");
590 } else {
591 len += sprintf(p + len, "mask:\t\tnot supported\n");
592 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
593 }
594
595 return len;
596}
597
598static int hotkey_write(char *buf)
599{
600 int status, mask;
601 char *cmd;
602 int do_cmd = 0;
603
604 if (!hotkey_supported)
605 return -ENODEV;
606
607 if (!hotkey_get(&status, &mask))
608 return -EIO;
609
610 while ((cmd = next_cmd(&buf))) {
611 if (strlencmp(cmd, "enable") == 0) {
612 status = 1;
613 } else if (strlencmp(cmd, "disable") == 0) {
614 status = 0;
615 } else if (strlencmp(cmd, "reset") == 0) {
616 status = hotkey_orig_status;
617 mask = hotkey_orig_mask;
618 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
619 /* mask set */
620 } else if (sscanf(cmd, "%x", &mask) == 1) {
621 /* mask set */
622 } else
623 return -EINVAL;
624 do_cmd = 1;
625 }
626
627 if (do_cmd && !hotkey_set(status, mask))
628 return -EIO;
629
630 return 0;
631}
632
633static void hotkey_exit(void)
634{
635 if (hotkey_supported)
636 hotkey_set(hotkey_orig_status, hotkey_orig_mask);
637}
638
639static void hotkey_notify(struct ibm_struct *ibm, u32 event)
640{
641 int hkey;
642
643 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
644 acpi_bus_generate_event(ibm->device, event, hkey);
645 else {
646 printk(IBM_ERR "unknown hotkey event %d\n", event);
647 acpi_bus_generate_event(ibm->device, event, 0);
648 }
649}
650
651static int bluetooth_supported;
652
653static int bluetooth_init(void)
654{
655 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
656 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
657 bluetooth_supported = hkey_handle &&
658 acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
659
660 return 0;
661}
662
663static int bluetooth_status(void)
664{
665 int status;
666
667 if (!bluetooth_supported ||
668 !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
669 status = 0;
670
671 return status;
672}
673
674static int bluetooth_read(char *p)
675{
676 int len = 0;
677 int status = bluetooth_status();
678
679 if (!bluetooth_supported)
680 len += sprintf(p + len, "status:\t\tnot supported\n");
681 else if (!(status & 1))
682 len += sprintf(p + len, "status:\t\tnot installed\n");
683 else {
684 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
685 len += sprintf(p + len, "commands:\tenable, disable\n");
686 }
687
688 return len;
689}
690
691static int bluetooth_write(char *buf)
692{
693 int status = bluetooth_status();
694 char *cmd;
695 int do_cmd = 0;
696
697 if (!bluetooth_supported)
698 return -ENODEV;
699
700 while ((cmd = next_cmd(&buf))) {
701 if (strlencmp(cmd, "enable") == 0) {
702 status |= 2;
703 } else if (strlencmp(cmd, "disable") == 0) {
704 status &= ~2;
705 } else
706 return -EINVAL;
707 do_cmd = 1;
708 }
709
710 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
711 return -EIO;
712
713 return 0;
714}
715
716static int wan_supported;
717
718static int wan_init(void)
719{
720 wan_supported = hkey_handle &&
721 acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
722
723 return 0;
724}
725
726static int wan_status(void)
727{
728 int status;
729
730 if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
731 status = 0;
732
733 return status;
734}
735
736static int wan_read(char *p)
737{
738 int len = 0;
739 int status = wan_status();
740
741 if (!wan_supported)
742 len += sprintf(p + len, "status:\t\tnot supported\n");
743 else if (!(status & 1))
744 len += sprintf(p + len, "status:\t\tnot installed\n");
745 else {
746 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
747 len += sprintf(p + len, "commands:\tenable, disable\n");
748 }
749
750 return len;
751}
752
753static int wan_write(char *buf)
754{
755 int status = wan_status();
756 char *cmd;
757 int do_cmd = 0;
758
759 if (!wan_supported)
760 return -ENODEV;
761
762 while ((cmd = next_cmd(&buf))) {
763 if (strlencmp(cmd, "enable") == 0) {
764 status |= 2;
765 } else if (strlencmp(cmd, "disable") == 0) {
766 status &= ~2;
767 } else
768 return -EINVAL;
769 do_cmd = 1;
770 }
771
772 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
773 return -EIO;
774
775 return 0;
776}
777
778enum video_access_mode {
779 IBMACPI_VIDEO_NONE = 0,
780 IBMACPI_VIDEO_570, /* 570 */
781 IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */
782 IBMACPI_VIDEO_NEW, /* all others */
783};
784
785static enum video_access_mode video_supported;
786static int video_orig_autosw;
787
788static int video_init(void)
789{
790 int ivga;
791
792 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
793 /* G41, assume IVGA doesn't change */
794 vid_handle = vid2_handle;
795
796 if (!vid_handle)
797 /* video switching not supported on R30, R31 */
798 video_supported = IBMACPI_VIDEO_NONE;
799 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
800 /* 570 */
801 video_supported = IBMACPI_VIDEO_570;
802 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
803 /* 600e/x, 770e, 770x */
804 video_supported = IBMACPI_VIDEO_770;
805 else
806 /* all others */
807 video_supported = IBMACPI_VIDEO_NEW;
808
809 return 0;
810}
811
812static int video_status(void)
813{
814 int status = 0;
815 int i;
816
817 if (video_supported == IBMACPI_VIDEO_570) {
818 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
819 status = i & 3;
820 } else if (video_supported == IBMACPI_VIDEO_770) {
821 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
822 status |= 0x01 * i;
823 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
824 status |= 0x02 * i;
825 } else if (video_supported == IBMACPI_VIDEO_NEW) {
826 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
827 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
828 status |= 0x02 * i;
829
830 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
831 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
832 status |= 0x01 * i;
833 if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
834 status |= 0x08 * i;
835 }
836
837 return status;
838}
839
840static int video_autosw(void)
841{
842 int autosw = 0;
843
844 if (video_supported == IBMACPI_VIDEO_570)
845 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
846 else if (video_supported == IBMACPI_VIDEO_770 ||
847 video_supported == IBMACPI_VIDEO_NEW)
848 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
849
850 return autosw & 1;
851}
852
853static int video_read(char *p)
854{
855 int status = video_status();
856 int autosw = video_autosw();
857 int len = 0;
858
859 if (!video_supported) {
860 len += sprintf(p + len, "status:\t\tnot supported\n");
861 return len;
862 }
863
864 len += sprintf(p + len, "status:\t\tsupported\n");
865 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
866 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
867 if (video_supported == IBMACPI_VIDEO_NEW)
868 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
869 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
870 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
871 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
872 if (video_supported == IBMACPI_VIDEO_NEW)
873 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
874 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
875 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
876
877 return len;
878}
879
880static int video_switch(void)
881{
882 int autosw = video_autosw();
883 int ret;
884
885 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
886 return -EIO;
887 ret = video_supported == IBMACPI_VIDEO_570 ?
888 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
889 acpi_evalf(vid_handle, NULL, "VSWT", "v");
890 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
891
892 return ret;
893}
894
895static int video_expand(void)
896{
897 if (video_supported == IBMACPI_VIDEO_570)
898 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
899 else if (video_supported == IBMACPI_VIDEO_770)
900 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
901 else
902 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
903}
904
905static int video_switch2(int status)
906{
907 int ret;
908
909 if (video_supported == IBMACPI_VIDEO_570) {
910 ret = acpi_evalf(NULL, NULL,
911 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
912 } else if (video_supported == IBMACPI_VIDEO_770) {
913 int autosw = video_autosw();
914 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
915 return -EIO;
916
917 ret = acpi_evalf(vid_handle, NULL,
918 "ASWT", "vdd", status * 0x100, 0);
919
920 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
921 } else {
922 ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
923 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
924 }
925
926 return ret;
927}
928
929static int video_write(char *buf)
930{
931 char *cmd;
932 int enable, disable, status;
933
934 if (!video_supported)
935 return -ENODEV;
936
937 enable = disable = 0;
938
939 while ((cmd = next_cmd(&buf))) {
940 if (strlencmp(cmd, "lcd_enable") == 0) {
941 enable |= 0x01;
942 } else if (strlencmp(cmd, "lcd_disable") == 0) {
943 disable |= 0x01;
944 } else if (strlencmp(cmd, "crt_enable") == 0) {
945 enable |= 0x02;
946 } else if (strlencmp(cmd, "crt_disable") == 0) {
947 disable |= 0x02;
948 } else if (video_supported == IBMACPI_VIDEO_NEW &&
949 strlencmp(cmd, "dvi_enable") == 0) {
950 enable |= 0x08;
951 } else if (video_supported == IBMACPI_VIDEO_NEW &&
952 strlencmp(cmd, "dvi_disable") == 0) {
953 disable |= 0x08;
954 } else if (strlencmp(cmd, "auto_enable") == 0) {
955 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
956 return -EIO;
957 } else if (strlencmp(cmd, "auto_disable") == 0) {
958 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
959 return -EIO;
960 } else if (strlencmp(cmd, "video_switch") == 0) {
961 if (!video_switch())
962 return -EIO;
963 } else if (strlencmp(cmd, "expand_toggle") == 0) {
964 if (!video_expand())
965 return -EIO;
966 } else
967 return -EINVAL;
968 }
969
970 if (enable || disable) {
971 status = (video_status() & 0x0f & ~disable) | enable;
972 if (!video_switch2(status))
973 return -EIO;
974 }
975
976 return 0;
977}
978
979static void video_exit(void)
980{
981 acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
982}
983
984static int light_supported;
985static int light_status_supported;
986
987static int light_init(void)
988{
989 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
990 light_supported = (cmos_handle || lght_handle) && !ledb_handle;
991
992 if (light_supported)
993 /* light status not supported on
994 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
995 light_status_supported = acpi_evalf(ec_handle, NULL,
996 "KBLT", "qv");
997
998 return 0;
999}
1000
1001static int light_read(char *p)
1002{
1003 int len = 0;
1004 int status = 0;
1005
1006 if (!light_supported) {
1007 len += sprintf(p + len, "status:\t\tnot supported\n");
1008 } else if (!light_status_supported) {
1009 len += sprintf(p + len, "status:\t\tunknown\n");
1010 len += sprintf(p + len, "commands:\ton, off\n");
1011 } else {
1012 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1013 return -EIO;
1014 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1015 len += sprintf(p + len, "commands:\ton, off\n");
1016 }
1017
1018 return len;
1019}
1020
1021static int light_write(char *buf)
1022{
1023 int cmos_cmd, lght_cmd;
1024 char *cmd;
1025 int success;
1026
1027 if (!light_supported)
1028 return -ENODEV;
1029
1030 while ((cmd = next_cmd(&buf))) {
1031 if (strlencmp(cmd, "on") == 0) {
1032 cmos_cmd = 0x0c;
1033 lght_cmd = 1;
1034 } else if (strlencmp(cmd, "off") == 0) {
1035 cmos_cmd = 0x0d;
1036 lght_cmd = 0;
1037 } else
1038 return -EINVAL;
1039
1040 success = cmos_handle ?
1041 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1042 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1043 if (!success)
1044 return -EIO;
1045 }
1046
1047 return 0;
1048}
1049
1050#if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
1051static int _sta(acpi_handle handle)
1052{
1053 int status;
1054
1055 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
1056 status = 0;
1057
1058 return status;
1059}
1060#endif
1061
1062#ifdef CONFIG_ACPI_IBM_DOCK
1063#define dock_docked() (_sta(dock_handle) & 1)
1064
1065static int dock_read(char *p)
1066{
1067 int len = 0;
1068 int docked = dock_docked();
1069
1070 if (!dock_handle)
1071 len += sprintf(p + len, "status:\t\tnot supported\n");
1072 else if (!docked)
1073 len += sprintf(p + len, "status:\t\tundocked\n");
1074 else {
1075 len += sprintf(p + len, "status:\t\tdocked\n");
1076 len += sprintf(p + len, "commands:\tdock, undock\n");
1077 }
1078
1079 return len;
1080}
1081
1082static int dock_write(char *buf)
1083{
1084 char *cmd;
1085
1086 if (!dock_docked())
1087 return -ENODEV;
1088
1089 while ((cmd = next_cmd(&buf))) {
1090 if (strlencmp(cmd, "undock") == 0) {
1091 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1092 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1093 return -EIO;
1094 } else if (strlencmp(cmd, "dock") == 0) {
1095 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1096 return -EIO;
1097 } else
1098 return -EINVAL;
1099 }
1100
1101 return 0;
1102}
1103
1104static void dock_notify(struct ibm_struct *ibm, u32 event)
1105{
1106 int docked = dock_docked();
1107 int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
1108
1109 if (event == 1 && !pci) /* 570 */
1110 acpi_bus_generate_event(ibm->device, event, 1); /* button */
1111 else if (event == 1 && pci) /* 570 */
1112 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
1113 else if (event == 3 && docked)
1114 acpi_bus_generate_event(ibm->device, event, 1); /* button */
1115 else if (event == 3 && !docked)
1116 acpi_bus_generate_event(ibm->device, event, 2); /* undock */
1117 else if (event == 0 && docked)
1118 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
1119 else {
1120 printk(IBM_ERR "unknown dock event %d, status %d\n",
1121 event, _sta(dock_handle));
1122 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
1123 }
1124}
1125#endif
1126
1127#ifdef CONFIG_ACPI_IBM_BAY
1128static int bay_status_supported;
1129static int bay_status2_supported;
1130static int bay_eject_supported;
1131static int bay_eject2_supported;
1132
1133static int bay_init(void)
1134{
1135 bay_status_supported = bay_handle &&
1136 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1137 bay_status2_supported = bay2_handle &&
1138 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1139
1140 bay_eject_supported = bay_handle && bay_ej_handle &&
1141 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1142 bay_eject2_supported = bay2_handle && bay2_ej_handle &&
1143 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1144
1145 return 0;
1146}
1147
1148#define bay_occupied(b) (_sta(b##_handle) & 1)
1149
1150static int bay_read(char *p)
1151{
1152 int len = 0;
1153 int occupied = bay_occupied(bay);
1154 int occupied2 = bay_occupied(bay2);
1155 int eject, eject2;
1156
1157 len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ?
1158 (occupied ? "occupied" : "unoccupied") :
1159 "not supported");
1160 if (bay_status2_supported)
1161 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1162 "occupied" : "unoccupied");
1163
1164 eject = bay_eject_supported && occupied;
1165 eject2 = bay_eject2_supported && occupied2;
1166
1167 if (eject && eject2)
1168 len += sprintf(p + len, "commands:\teject, eject2\n");
1169 else if (eject)
1170 len += sprintf(p + len, "commands:\teject\n");
1171 else if (eject2)
1172 len += sprintf(p + len, "commands:\teject2\n");
1173
1174 return len;
1175}
1176
1177static int bay_write(char *buf)
1178{
1179 char *cmd;
1180
1181 if (!bay_eject_supported && !bay_eject2_supported)
1182 return -ENODEV;
1183
1184 while ((cmd = next_cmd(&buf))) {
1185 if (bay_eject_supported && strlencmp(cmd, "eject") == 0) {
1186 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1187 return -EIO;
1188 } else if (bay_eject2_supported &&
1189 strlencmp(cmd, "eject2") == 0) {
1190 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1191 return -EIO;
1192 } else
1193 return -EINVAL;
1194 }
1195
1196 return 0;
1197}
1198
1199static void bay_notify(struct ibm_struct *ibm, u32 event)
1200{
1201 acpi_bus_generate_event(ibm->device, event, 0);
1202}
1203#endif /* CONFIG_ACPI_IBM_BAY */
1204
1205static int cmos_read(char *p)
1206{
1207 int len = 0;
1208
1209 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1210 R30, R31, T20-22, X20-21 */
1211 if (!cmos_handle)
1212 len += sprintf(p + len, "status:\t\tnot supported\n");
1213 else {
1214 len += sprintf(p + len, "status:\t\tsupported\n");
1215 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
1216 }
1217
1218 return len;
1219}
1220
1221static int cmos_eval(int cmos_cmd)
1222{
1223 if (cmos_handle)
1224 return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
1225 else
1226 return 1;
1227}
1228
1229static int cmos_write(char *buf)
1230{
1231 char *cmd;
1232 int cmos_cmd;
1233
1234 if (!cmos_handle)
1235 return -EINVAL;
1236
1237 while ((cmd = next_cmd(&buf))) {
1238 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1239 cmos_cmd >= 0 && cmos_cmd <= 21) {
1240 /* cmos_cmd set */
1241 } else
1242 return -EINVAL;
1243
1244 if (!cmos_eval(cmos_cmd))
1245 return -EIO;
1246 }
1247
1248 return 0;
1249}
1250
1251enum led_access_mode {
1252 IBMACPI_LED_NONE = 0,
1253 IBMACPI_LED_570, /* 570 */
1254 IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1255 IBMACPI_LED_NEW, /* all others */
1256};
1257static enum led_access_mode led_supported;
1258
1259static int led_init(void)
1260{
1261 if (!led_handle)
1262 /* led not supported on R30, R31 */
1263 led_supported = IBMACPI_LED_NONE;
1264 else if (strlencmp(led_path, "SLED") == 0)
1265 /* 570 */
1266 led_supported = IBMACPI_LED_570;
1267 else if (strlencmp(led_path, "SYSL") == 0)
1268 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1269 led_supported = IBMACPI_LED_OLD;
1270 else
1271 /* all others */
1272 led_supported = IBMACPI_LED_NEW;
1273
1274 return 0;
1275}
1276
1277#define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1278
1279static int led_read(char *p)
1280{
1281 int len = 0;
1282
1283 if (!led_supported) {
1284 len += sprintf(p + len, "status:\t\tnot supported\n");
1285 return len;
1286 }
1287 len += sprintf(p + len, "status:\t\tsupported\n");
1288
1289 if (led_supported == IBMACPI_LED_570) {
1290 /* 570 */
1291 int i, status;
1292 for (i = 0; i < 8; i++) {
1293 if (!acpi_evalf(ec_handle,
1294 &status, "GLED", "dd", 1 << i))
1295 return -EIO;
1296 len += sprintf(p + len, "%d:\t\t%s\n",
1297 i, led_status(status));
1298 }
1299 }
1300
1301 len += sprintf(p + len, "commands:\t"
1302 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1303
1304 return len;
1305}
1306
1307/* off, on, blink */
1308static const int led_sled_arg1[] = { 0, 1, 3 };
1309static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1310static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1311static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1312
1313#define EC_HLCL 0x0c
1314#define EC_HLBL 0x0d
1315#define EC_HLMS 0x0e
1316
1317static int led_write(char *buf)
1318{
1319 char *cmd;
1320 int led, ind, ret;
1321
1322 if (!led_supported)
1323 return -ENODEV;
1324
1325 while ((cmd = next_cmd(&buf))) {
1326 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
1327 return -EINVAL;
1328
1329 if (strstr(cmd, "off")) {
1330 ind = 0;
1331 } else if (strstr(cmd, "on")) {
1332 ind = 1;
1333 } else if (strstr(cmd, "blink")) {
1334 ind = 2;
1335 } else
1336 return -EINVAL;
1337
1338 if (led_supported == IBMACPI_LED_570) {
1339 /* 570 */
1340 led = 1 << led;
1341 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1342 led, led_sled_arg1[ind]))
1343 return -EIO;
1344 } else if (led_supported == IBMACPI_LED_OLD) {
1345 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1346 led = 1 << led;
1347 ret = ec_write(EC_HLMS, led);
1348 if (ret >= 0)
1349 ret =
1350 ec_write(EC_HLBL, led * led_exp_hlbl[ind]);
1351 if (ret >= 0)
1352 ret =
1353 ec_write(EC_HLCL, led * led_exp_hlcl[ind]);
1354 if (ret < 0)
1355 return ret;
1356 } else {
1357 /* all others */
1358 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1359 led, led_led_arg1[ind]))
1360 return -EIO;
1361 }
1362 }
1363
1364 return 0;
1365}
1366
1367static int beep_read(char *p)
1368{
1369 int len = 0;
1370
1371 if (!beep_handle)
1372 len += sprintf(p + len, "status:\t\tnot supported\n");
1373 else {
1374 len += sprintf(p + len, "status:\t\tsupported\n");
1375 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1376 }
1377
1378 return len;
1379}
1380
1381static int beep_write(char *buf)
1382{
1383 char *cmd;
1384 int beep_cmd;
1385
1386 if (!beep_handle)
1387 return -ENODEV;
1388
1389 while ((cmd = next_cmd(&buf))) {
1390 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1391 beep_cmd >= 0 && beep_cmd <= 17) {
1392 /* beep_cmd set */
1393 } else
1394 return -EINVAL;
1395 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
1396 return -EIO;
1397 }
1398
1399 return 0;
1400}
1401
1402static int acpi_ec_read(int i, u8 * p)
1403{
1404 int v;
1405
1406 if (ecrd_handle) {
1407 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
1408 return 0;
1409 *p = v;
1410 } else {
1411 if (ec_read(i, p) < 0)
1412 return 0;
1413 }
1414
1415 return 1;
1416}
1417
1418static int acpi_ec_write(int i, u8 v)
1419{
1420 if (ecwr_handle) {
1421 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
1422 return 0;
1423 } else {
1424 if (ec_write(i, v) < 0)
1425 return 0;
1426 }
1427
1428 return 1;
1429}
1430
1431static enum thermal_access_mode thermal_read_mode;
1432
1433static int thermal_init(void)
1434{
1435 u8 t, ta1, ta2;
1436 int i;
1437 int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1438
1439 if (ibm_thinkpad_ec_found && experimental) {
1440 /*
1441 * Direct EC access mode: sensors at registers
1442 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1443 * non-implemented, thermal sensors return 0x80 when
1444 * not available
1445 */
1446
1447 ta1 = ta2 = 0;
1448 for (i = 0; i < 8; i++) {
1449 if (likely(acpi_ec_read(0x78 + i, &t))) {
1450 ta1 |= t;
1451 } else {
1452 ta1 = 0;
1453 break;
1454 }
1455 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1456 ta2 |= t;
1457 } else {
1458 ta1 = 0;
1459 break;
1460 }
1461 }
1462 if (ta1 == 0) {
1463 /* This is sheer paranoia, but we handle it anyway */
1464 if (acpi_tmp7) {
1465 printk(IBM_ERR
1466 "ThinkPad ACPI EC access misbehaving, "
1467 "falling back to ACPI TMPx access mode\n");
1468 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1469 } else {
1470 printk(IBM_ERR
1471 "ThinkPad ACPI EC access misbehaving, "
1472 "disabling thermal sensors access\n");
1473 thermal_read_mode = IBMACPI_THERMAL_NONE;
1474 }
1475 } else {
1476 thermal_read_mode =
1477 (ta2 != 0) ?
1478 IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
1479 }
1480 } else if (acpi_tmp7) {
1481 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1482 /* 600e/x, 770e, 770x */
1483 thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
1484 } else {
1485 /* Standard ACPI TMPx access, max 8 sensors */
1486 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1487 }
1488 } else {
1489 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1490 thermal_read_mode = IBMACPI_THERMAL_NONE;
1491 }
1492
1493 return 0;
1494}
1495
1496static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1497{
1498 int i, t;
1499 s8 tmp;
1500 char tmpi[] = "TMPi";
1501
1502 if (!s)
1503 return -EINVAL;
1504
1505 switch (thermal_read_mode) {
1506#if IBMACPI_MAX_THERMAL_SENSORS >= 16
1507 case IBMACPI_THERMAL_TPEC_16:
1508 for (i = 0; i < 8; i++) {
1509 if (!acpi_ec_read(0xC0 + i, &tmp))
1510 return -EIO;
1511 s->temp[i + 8] = tmp * 1000;
1512 }
1513 /* fallthrough */
1514#endif
1515 case IBMACPI_THERMAL_TPEC_8:
1516 for (i = 0; i < 8; i++) {
1517 if (!acpi_ec_read(0x78 + i, &tmp))
1518 return -EIO;
1519 s->temp[i] = tmp * 1000;
1520 }
1521 return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
1522
1523 case IBMACPI_THERMAL_ACPI_UPDT:
1524 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1525 return -EIO;
1526 for (i = 0; i < 8; i++) {
1527 tmpi[3] = '0' + i;
1528 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1529 return -EIO;
1530 s->temp[i] = (t - 2732) * 100;
1531 }
1532 return 8;
1533
1534 case IBMACPI_THERMAL_ACPI_TMP07:
1535 for (i = 0; i < 8; i++) {
1536 tmpi[3] = '0' + i;
1537 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1538 return -EIO;
1539 s->temp[i] = t * 1000;
1540 }
1541 return 8;
1542
1543 case IBMACPI_THERMAL_NONE:
1544 default:
1545 return 0;
1546 }
1547}
1548
1549static int thermal_read(char *p)
1550{
1551 int len = 0;
1552 int n, i;
1553 struct ibm_thermal_sensors_struct t;
1554
1555 n = thermal_get_sensors(&t);
1556 if (unlikely(n < 0))
1557 return n;
1558
1559 len += sprintf(p + len, "temperatures:\t");
1560
1561 if (n > 0) {
1562 for (i = 0; i < (n - 1); i++)
1563 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1564 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1565 } else
1566 len += sprintf(p + len, "not supported\n");
1567
1568 return len;
1569}
1570
1571static u8 ecdump_regs[256];
1572
1573static int ecdump_read(char *p)
1574{
1575 int len = 0;
1576 int i, j;
1577 u8 v;
1578
1579 len += sprintf(p + len, "EC "
1580 " +00 +01 +02 +03 +04 +05 +06 +07"
1581 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1582 for (i = 0; i < 256; i += 16) {
1583 len += sprintf(p + len, "EC 0x%02x:", i);
1584 for (j = 0; j < 16; j++) {
1585 if (!acpi_ec_read(i + j, &v))
1586 break;
1587 if (v != ecdump_regs[i + j])
1588 len += sprintf(p + len, " *%02x", v);
1589 else
1590 len += sprintf(p + len, " %02x", v);
1591 ecdump_regs[i + j] = v;
1592 }
1593 len += sprintf(p + len, "\n");
1594 if (j != 16)
1595 break;
1596 }
1597
1598 /* These are way too dangerous to advertise openly... */
1599#if 0
1600 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
1601 " (<offset> is 00-ff, <value> is 00-ff)\n");
1602 len += sprintf(p + len, "commands:\t0x<offset> <value> "
1603 " (<offset> is 00-ff, <value> is 0-255)\n");
1604#endif
1605 return len;
1606}
1607
1608static int ecdump_write(char *buf)
1609{
1610 char *cmd;
1611 int i, v;
1612
1613 while ((cmd = next_cmd(&buf))) {
1614 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
1615 /* i and v set */
1616 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
1617 /* i and v set */
1618 } else
1619 return -EINVAL;
1620 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
1621 if (!acpi_ec_write(i, v))
1622 return -EIO;
1623 } else
1624 return -EINVAL;
1625 }
1626
1627 return 0;
1628}
1629
1630static int brightness_offset = 0x31;
1631
1632static int brightness_get(struct backlight_device *bd)
1633{
1634 u8 level;
1635 if (!acpi_ec_read(brightness_offset, &level))
1636 return -EIO;
1637
1638 level &= 0x7;
1639
1640 return level;
1641}
1642
1643static int brightness_read(char *p)
1644{
1645 int len = 0;
1646 int level;
1647
1648 if ((level = brightness_get(NULL)) < 0) {
1649 len += sprintf(p + len, "level:\t\tunreadable\n");
1650 } else {
1651 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
1652 len += sprintf(p + len, "commands:\tup, down\n");
1653 len += sprintf(p + len, "commands:\tlevel <level>"
1654 " (<level> is 0-7)\n");
1655 }
1656
1657 return len;
1658}
1659
1660#define BRIGHTNESS_UP 4
1661#define BRIGHTNESS_DOWN 5
1662
1663static int brightness_set(int value)
1664{
1665 int cmos_cmd, inc, i;
1666 int current_value = brightness_get(NULL);
1667
1668 value &= 7;
1669
1670 cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
1671 inc = value > current_value ? 1 : -1;
1672 for (i = current_value; i != value; i += inc) {
1673 if (!cmos_eval(cmos_cmd))
1674 return -EIO;
1675 if (!acpi_ec_write(brightness_offset, i + inc))
1676 return -EIO;
1677 }
1678
1679 return 0;
1680}
1681
1682static int brightness_write(char *buf)
1683{
1684 int level;
1685 int new_level;
1686 char *cmd;
1687
1688 while ((cmd = next_cmd(&buf))) {
1689 if ((level = brightness_get(NULL)) < 0)
1690 return level;
1691 level &= 7;
1692
1693 if (strlencmp(cmd, "up") == 0) {
1694 new_level = level == 7 ? 7 : level + 1;
1695 } else if (strlencmp(cmd, "down") == 0) {
1696 new_level = level == 0 ? 0 : level - 1;
1697 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1698 new_level >= 0 && new_level <= 7) {
1699 /* new_level set */
1700 } else
1701 return -EINVAL;
1702
1703 brightness_set(new_level);
1704 }
1705
1706 return 0;
1707}
1708
1709static int brightness_update_status(struct backlight_device *bd)
1710{
1711 return brightness_set(
1712 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
1713 bd->props.power == FB_BLANK_UNBLANK) ?
1714 bd->props.brightness : 0);
1715}
1716
1717static struct backlight_ops ibm_backlight_data = {
1718 .get_brightness = brightness_get,
1719 .update_status = brightness_update_status,
1720};
1721
1722static int brightness_init(void)
1723{
1724 int b;
1725
1726 b = brightness_get(NULL);
1727 if (b < 0)
1728 return b;
1729
1730 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1731 &ibm_backlight_data);
1732 if (IS_ERR(ibm_backlight_device)) {
1733 printk(IBM_ERR "Could not register backlight device\n");
1734 return PTR_ERR(ibm_backlight_device);
1735 }
1736
1737 ibm_backlight_device->props.max_brightness = 7;
1738 ibm_backlight_device->props.brightness = b;
1739 backlight_update_status(ibm_backlight_device);
1740
1741 return 0;
1742}
1743
1744static void brightness_exit(void)
1745{
1746 if (ibm_backlight_device) {
1747 backlight_device_unregister(ibm_backlight_device);
1748 ibm_backlight_device = NULL;
1749 }
1750}
1751
1752static int volume_offset = 0x30;
1753
1754static int volume_read(char *p)
1755{
1756 int len = 0;
1757 u8 level;
1758
1759 if (!acpi_ec_read(volume_offset, &level)) {
1760 len += sprintf(p + len, "level:\t\tunreadable\n");
1761 } else {
1762 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
1763 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
1764 len += sprintf(p + len, "commands:\tup, down, mute\n");
1765 len += sprintf(p + len, "commands:\tlevel <level>"
1766 " (<level> is 0-15)\n");
1767 }
1768
1769 return len;
1770}
1771
1772#define VOLUME_DOWN 0
1773#define VOLUME_UP 1
1774#define VOLUME_MUTE 2
1775
1776static int volume_write(char *buf)
1777{
1778 int cmos_cmd, inc, i;
1779 u8 level, mute;
1780 int new_level, new_mute;
1781 char *cmd;
1782
1783 while ((cmd = next_cmd(&buf))) {
1784 if (!acpi_ec_read(volume_offset, &level))
1785 return -EIO;
1786 new_mute = mute = level & 0x40;
1787 new_level = level = level & 0xf;
1788
1789 if (strlencmp(cmd, "up") == 0) {
1790 if (mute)
1791 new_mute = 0;
1792 else
1793 new_level = level == 15 ? 15 : level + 1;
1794 } else if (strlencmp(cmd, "down") == 0) {
1795 if (mute)
1796 new_mute = 0;
1797 else
1798 new_level = level == 0 ? 0 : level - 1;
1799 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1800 new_level >= 0 && new_level <= 15) {
1801 /* new_level set */
1802 } else if (strlencmp(cmd, "mute") == 0) {
1803 new_mute = 0x40;
1804 } else
1805 return -EINVAL;
1806
1807 if (new_level != level) { /* mute doesn't change */
1808 cmos_cmd = new_level > level ? VOLUME_UP : VOLUME_DOWN;
1809 inc = new_level > level ? 1 : -1;
1810
1811 if (mute && (!cmos_eval(cmos_cmd) ||
1812 !acpi_ec_write(volume_offset, level)))
1813 return -EIO;
1814
1815 for (i = level; i != new_level; i += inc)
1816 if (!cmos_eval(cmos_cmd) ||
1817 !acpi_ec_write(volume_offset, i + inc))
1818 return -EIO;
1819
1820 if (mute && (!cmos_eval(VOLUME_MUTE) ||
1821 !acpi_ec_write(volume_offset,
1822 new_level + mute)))
1823 return -EIO;
1824 }
1825
1826 if (new_mute != mute) { /* level doesn't change */
1827 cmos_cmd = new_mute ? VOLUME_MUTE : VOLUME_UP;
1828
1829 if (!cmos_eval(cmos_cmd) ||
1830 !acpi_ec_write(volume_offset, level + new_mute))
1831 return -EIO;
1832 }
1833 }
1834
1835 return 0;
1836}
1837
1838static enum fan_status_access_mode fan_status_access_mode;
1839static enum fan_control_access_mode fan_control_access_mode;
1840static enum fan_control_commands fan_control_commands;
1841
1842static int fan_control_status_known;
1843static u8 fan_control_initial_status;
1844
1845static void fan_watchdog_fire(struct work_struct *ignored);
1846static int fan_watchdog_maxinterval;
1847static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
1848
1849static int fan_init(void)
1850{
1851 fan_status_access_mode = IBMACPI_FAN_NONE;
1852 fan_control_access_mode = IBMACPI_FAN_WR_NONE;
1853 fan_control_commands = 0;
1854 fan_control_status_known = 1;
1855 fan_watchdog_maxinterval = 0;
1856
1857 if (gfan_handle) {
1858 /* 570, 600e/x, 770e, 770x */
1859 fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
1860 } else {
1861 /* all other ThinkPads: note that even old-style
1862 * ThinkPad ECs supports the fan control register */
1863 if (likely(acpi_ec_read(fan_status_offset,
1864 &fan_control_initial_status))) {
1865 fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
1866
1867 /* In some ThinkPads, neither the EC nor the ACPI
1868 * DSDT initialize the fan status, and it ends up
1869 * being set to 0x07 when it *could* be either
1870 * 0x07 or 0x80.
1871 *
1872 * Enable for TP-1Y (T43), TP-78 (R51e),
1873 * TP-76 (R52), TP-70 (T43, R52), which are known
1874 * to be buggy. */
1875 if (fan_control_initial_status == 0x07 &&
1876 ibm_thinkpad_ec_found &&
1877 ((ibm_thinkpad_ec_found[0] == '1' &&
1878 ibm_thinkpad_ec_found[1] == 'Y') ||
1879 (ibm_thinkpad_ec_found[0] == '7' &&
1880 (ibm_thinkpad_ec_found[1] == '6' ||
1881 ibm_thinkpad_ec_found[1] == '8' ||
1882 ibm_thinkpad_ec_found[1] == '0'))
1883 )) {
1884 printk(IBM_NOTICE
1885 "fan_init: initial fan status is "
1886 "unknown, assuming it is in auto "
1887 "mode\n");
1888 fan_control_status_known = 0;
1889 }
1890 } else {
1891 printk(IBM_ERR
1892 "ThinkPad ACPI EC access misbehaving, "
1893 "fan status and control unavailable\n");
1894 return 0;
1895 }
1896 }
1897
1898 if (sfan_handle) {
1899 /* 570, 770x-JL */
1900 fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
1901 fan_control_commands |=
1902 IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
1903 } else {
1904 if (!gfan_handle) {
1905 /* gfan without sfan means no fan control */
1906 /* all other models implement TP EC 0x2f control */
1907
1908 if (fans_handle) {
1909 /* X31, X40, X41 */
1910 fan_control_access_mode =
1911 IBMACPI_FAN_WR_ACPI_FANS;
1912 fan_control_commands |=
1913 IBMACPI_FAN_CMD_SPEED |
1914 IBMACPI_FAN_CMD_LEVEL |
1915 IBMACPI_FAN_CMD_ENABLE;
1916 } else {
1917 fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
1918 fan_control_commands |=
1919 IBMACPI_FAN_CMD_LEVEL |
1920 IBMACPI_FAN_CMD_ENABLE;
1921 }
1922 }
1923 }
1924
1925 return 0;
1926}
1927
1928static int fan_get_status(u8 *status)
1929{
1930 u8 s;
1931
1932 /* TODO:
1933 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1934
1935 switch (fan_status_access_mode) {
1936 case IBMACPI_FAN_RD_ACPI_GFAN:
1937 /* 570, 600e/x, 770e, 770x */
1938
1939 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
1940 return -EIO;
1941
1942 if (likely(status))
1943 *status = s & 0x07;
1944
1945 break;
1946
1947 case IBMACPI_FAN_RD_TPEC:
1948 /* all except 570, 600e/x, 770e, 770x */
1949 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
1950 return -EIO;
1951
1952 if (likely(status))
1953 *status = s;
1954
1955 break;
1956
1957 default:
1958 return -ENXIO;
1959 }
1960
1961 return 0;
1962}
1963
1964static int fan_get_speed(unsigned int *speed)
1965{
1966 u8 hi, lo;
1967
1968 switch (fan_status_access_mode) {
1969 case IBMACPI_FAN_RD_TPEC:
1970 /* all except 570, 600e/x, 770e, 770x */
1971 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
1972 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
1973 return -EIO;
1974
1975 if (likely(speed))
1976 *speed = (hi << 8) | lo;
1977
1978 break;
1979
1980 default:
1981 return -ENXIO;
1982 }
1983
1984 return 0;
1985}
1986
1987static void fan_exit(void)
1988{
1989 cancel_delayed_work(&fan_watchdog_task);
1990 flush_scheduled_work();
1991}
1992
1993static void fan_watchdog_reset(void)
1994{
1995 static int fan_watchdog_active = 0;
1996
1997 if (fan_watchdog_active)
1998 cancel_delayed_work(&fan_watchdog_task);
1999
2000 if (fan_watchdog_maxinterval > 0) {
2001 fan_watchdog_active = 1;
2002 if (!schedule_delayed_work(&fan_watchdog_task,
2003 msecs_to_jiffies(fan_watchdog_maxinterval
2004 * 1000))) {
2005 printk(IBM_ERR "failed to schedule the fan watchdog, "
2006 "watchdog will not trigger\n");
2007 }
2008 } else
2009 fan_watchdog_active = 0;
2010}
2011
2012static int fan_read(char *p)
2013{
2014 int len = 0;
2015 int rc;
2016 u8 status;
2017 unsigned int speed = 0;
2018
2019 switch (fan_status_access_mode) {
2020 case IBMACPI_FAN_RD_ACPI_GFAN:
2021 /* 570, 600e/x, 770e, 770x */
2022 if ((rc = fan_get_status(&status)) < 0)
2023 return rc;
2024
2025 len += sprintf(p + len, "status:\t\t%s\n"
2026 "level:\t\t%d\n",
2027 (status != 0) ? "enabled" : "disabled", status);
2028 break;
2029
2030 case IBMACPI_FAN_RD_TPEC:
2031 /* all except 570, 600e/x, 770e, 770x */
2032 if ((rc = fan_get_status(&status)) < 0)
2033 return rc;
2034
2035 if (unlikely(!fan_control_status_known)) {
2036 if (status != fan_control_initial_status)
2037 fan_control_status_known = 1;
2038 else
2039 /* Return most likely status. In fact, it
2040 * might be the only possible status */
2041 status = IBMACPI_FAN_EC_AUTO;
2042 }
2043
2044 len += sprintf(p + len, "status:\t\t%s\n",
2045 (status != 0) ? "enabled" : "disabled");
2046
2047 /* No ThinkPad boots on disengaged mode, we can safely
2048 * assume the tachometer is online if fan control status
2049 * was unknown */
2050 if ((rc = fan_get_speed(&speed)) < 0)
2051 return rc;
2052
2053 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2054
2055 if (status & IBMACPI_FAN_EC_DISENGAGED)
2056 /* Disengaged mode takes precedence */
2057 len += sprintf(p + len, "level:\t\tdisengaged\n");
2058 else if (status & IBMACPI_FAN_EC_AUTO)
2059 len += sprintf(p + len, "level:\t\tauto\n");
2060 else
2061 len += sprintf(p + len, "level:\t\t%d\n", status);
2062 break;
2063
2064 case IBMACPI_FAN_NONE:
2065 default:
2066 len += sprintf(p + len, "status:\t\tnot supported\n");
2067 }
2068
2069 if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
2070 len += sprintf(p + len, "commands:\tlevel <level>");
2071
2072 switch (fan_control_access_mode) {
2073 case IBMACPI_FAN_WR_ACPI_SFAN:
2074 len += sprintf(p + len, " (<level> is 0-7)\n");
2075 break;
2076
2077 default:
2078 len += sprintf(p + len, " (<level> is 0-7, "
2079 "auto, disengaged)\n");
2080 break;
2081 }
2082 }
2083
2084 if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
2085 len += sprintf(p + len, "commands:\tenable, disable\n"
2086 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2087 "1-120 (seconds))\n");
2088
2089 if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
2090 len += sprintf(p + len, "commands:\tspeed <speed>"
2091 " (<speed> is 0-65535)\n");
2092
2093 return len;
2094}
2095
2096static int fan_set_level(int level)
2097{
2098 switch (fan_control_access_mode) {
2099 case IBMACPI_FAN_WR_ACPI_SFAN:
2100 if (level >= 0 && level <= 7) {
2101 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
2102 return -EIO;
2103 } else
2104 return -EINVAL;
2105 break;
2106
2107 case IBMACPI_FAN_WR_ACPI_FANS:
2108 case IBMACPI_FAN_WR_TPEC:
2109 if ((level != IBMACPI_FAN_EC_AUTO) &&
2110 (level != IBMACPI_FAN_EC_DISENGAGED) &&
2111 ((level < 0) || (level > 7)))
2112 return -EINVAL;
2113
2114 if (!acpi_ec_write(fan_status_offset, level))
2115 return -EIO;
2116 else
2117 fan_control_status_known = 1;
2118 break;
2119
2120 default:
2121 return -ENXIO;
2122 }
2123 return 0;
2124}
2125
2126static int fan_set_enable(void)
2127{
2128 u8 s;
2129 int rc;
2130
2131 switch (fan_control_access_mode) {
2132 case IBMACPI_FAN_WR_ACPI_FANS:
2133 case IBMACPI_FAN_WR_TPEC:
2134 if ((rc = fan_get_status(&s)) < 0)
2135 return rc;
2136
2137 /* Don't go out of emergency fan mode */
2138 if (s != 7)
2139 s = IBMACPI_FAN_EC_AUTO;
2140
2141 if (!acpi_ec_write(fan_status_offset, s))
2142 return -EIO;
2143 else
2144 fan_control_status_known = 1;
2145 break;
2146
2147 case IBMACPI_FAN_WR_ACPI_SFAN:
2148 if ((rc = fan_get_status(&s)) < 0)
2149 return rc;
2150
2151 s &= 0x07;
2152
2153 /* Set fan to at least level 4 */
2154 if (s < 4)
2155 s = 4;
2156
2157 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2158 return -EIO;
2159 break;
2160
2161 default:
2162 return -ENXIO;
2163 }
2164 return 0;
2165}
2166
2167static int fan_set_disable(void)
2168{
2169 switch (fan_control_access_mode) {
2170 case IBMACPI_FAN_WR_ACPI_FANS:
2171 case IBMACPI_FAN_WR_TPEC:
2172 if (!acpi_ec_write(fan_status_offset, 0x00))
2173 return -EIO;
2174 else
2175 fan_control_status_known = 1;
2176 break;
2177
2178 case IBMACPI_FAN_WR_ACPI_SFAN:
2179 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2180 return -EIO;
2181 break;
2182
2183 default:
2184 return -ENXIO;
2185 }
2186 return 0;
2187}
2188
2189static int fan_set_speed(int speed)
2190{
2191 switch (fan_control_access_mode) {
2192 case IBMACPI_FAN_WR_ACPI_FANS:
2193 if (speed >= 0 && speed <= 65535) {
2194 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2195 speed, speed, speed))
2196 return -EIO;
2197 } else
2198 return -EINVAL;
2199 break;
2200
2201 default:
2202 return -ENXIO;
2203 }
2204 return 0;
2205}
2206
2207static int fan_write_cmd_level(const char *cmd, int *rc)
2208{
2209 int level;
2210
2211 if (strlencmp(cmd, "level auto") == 0)
2212 level = IBMACPI_FAN_EC_AUTO;
2213 else if (strlencmp(cmd, "level disengaged") == 0)
2214 level = IBMACPI_FAN_EC_DISENGAGED;
2215 else if (sscanf(cmd, "level %d", &level) != 1)
2216 return 0;
2217
2218 if ((*rc = fan_set_level(level)) == -ENXIO)
2219 printk(IBM_ERR "level command accepted for unsupported "
2220 "access mode %d", fan_control_access_mode);
2221
2222 return 1;
2223}
2224
2225static int fan_write_cmd_enable(const char *cmd, int *rc)
2226{
2227 if (strlencmp(cmd, "enable") != 0)
2228 return 0;
2229
2230 if ((*rc = fan_set_enable()) == -ENXIO)
2231 printk(IBM_ERR "enable command accepted for unsupported "
2232 "access mode %d", fan_control_access_mode);
2233
2234 return 1;
2235}
2236
2237static int fan_write_cmd_disable(const char *cmd, int *rc)
2238{
2239 if (strlencmp(cmd, "disable") != 0)
2240 return 0;
2241
2242 if ((*rc = fan_set_disable()) == -ENXIO)
2243 printk(IBM_ERR "disable command accepted for unsupported "
2244 "access mode %d", fan_control_access_mode);
2245
2246 return 1;
2247}
2248
2249static int fan_write_cmd_speed(const char *cmd, int *rc)
2250{
2251 int speed;
2252
2253 /* TODO:
2254 * Support speed <low> <medium> <high> ? */
2255
2256 if (sscanf(cmd, "speed %d", &speed) != 1)
2257 return 0;
2258
2259 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2260 printk(IBM_ERR "speed command accepted for unsupported "
2261 "access mode %d", fan_control_access_mode);
2262
2263 return 1;
2264}
2265
2266static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2267{
2268 int interval;
2269
2270 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2271 return 0;
2272
2273 if (interval < 0 || interval > 120)
2274 *rc = -EINVAL;
2275 else
2276 fan_watchdog_maxinterval = interval;
2277
2278 return 1;
2279}
2280
2281static int fan_write(char *buf)
2282{
2283 char *cmd;
2284 int rc = 0;
2285
2286 while (!rc && (cmd = next_cmd(&buf))) {
2287 if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
2288 fan_write_cmd_level(cmd, &rc)) &&
2289 !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
2290 (fan_write_cmd_enable(cmd, &rc) ||
2291 fan_write_cmd_disable(cmd, &rc) ||
2292 fan_write_cmd_watchdog(cmd, &rc))) &&
2293 !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
2294 fan_write_cmd_speed(cmd, &rc))
2295 )
2296 rc = -EINVAL;
2297 else if (!rc)
2298 fan_watchdog_reset();
2299 }
2300
2301 return rc;
2302}
2303
2304static void fan_watchdog_fire(struct work_struct *ignored)
2305{
2306 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2307 if (fan_set_enable()) {
2308 printk(IBM_ERR "fan watchdog: error while enabling fan\n");
2309 /* reschedule for later */
2310 fan_watchdog_reset();
2311 }
2312}
2313
2314static struct ibm_struct ibms[] = {
2315 {
2316 .name = "driver",
2317 .init = ibm_acpi_driver_init,
2318 .read = driver_read,
2319 },
2320 {
2321 .name = "hotkey",
2322 .hid = IBM_HKEY_HID,
2323 .init = hotkey_init,
2324 .read = hotkey_read,
2325 .write = hotkey_write,
2326 .exit = hotkey_exit,
2327 .notify = hotkey_notify,
2328 .handle = &hkey_handle,
2329 .type = ACPI_DEVICE_NOTIFY,
2330 },
2331 {
2332 .name = "bluetooth",
2333 .init = bluetooth_init,
2334 .read = bluetooth_read,
2335 .write = bluetooth_write,
2336 },
2337 {
2338 .name = "wan",
2339 .init = wan_init,
2340 .read = wan_read,
2341 .write = wan_write,
2342 .experimental = 1,
2343 },
2344 {
2345 .name = "video",
2346 .init = video_init,
2347 .read = video_read,
2348 .write = video_write,
2349 .exit = video_exit,
2350 },
2351 {
2352 .name = "light",
2353 .init = light_init,
2354 .read = light_read,
2355 .write = light_write,
2356 },
2357#ifdef CONFIG_ACPI_IBM_DOCK
2358 {
2359 .name = "dock",
2360 .read = dock_read,
2361 .write = dock_write,
2362 .notify = dock_notify,
2363 .handle = &dock_handle,
2364 .type = ACPI_SYSTEM_NOTIFY,
2365 },
2366 {
2367 .name = "dock",
2368 .hid = IBM_PCI_HID,
2369 .notify = dock_notify,
2370 .handle = &pci_handle,
2371 .type = ACPI_SYSTEM_NOTIFY,
2372 },
2373#endif
2374#ifdef CONFIG_ACPI_IBM_BAY
2375 {
2376 .name = "bay",
2377 .init = bay_init,
2378 .read = bay_read,
2379 .write = bay_write,
2380 .notify = bay_notify,
2381 .handle = &bay_handle,
2382 .type = ACPI_SYSTEM_NOTIFY,
2383 },
2384#endif /* CONFIG_ACPI_IBM_BAY */
2385 {
2386 .name = "cmos",
2387 .read = cmos_read,
2388 .write = cmos_write,
2389 },
2390 {
2391 .name = "led",
2392 .init = led_init,
2393 .read = led_read,
2394 .write = led_write,
2395 },
2396 {
2397 .name = "beep",
2398 .read = beep_read,
2399 .write = beep_write,
2400 },
2401 {
2402 .name = "thermal",
2403 .init = thermal_init,
2404 .read = thermal_read,
2405 },
2406 {
2407 .name = "ecdump",
2408 .read = ecdump_read,
2409 .write = ecdump_write,
2410 .experimental = 1,
2411 },
2412 {
2413 .name = "brightness",
2414 .read = brightness_read,
2415 .write = brightness_write,
2416 .init = brightness_init,
2417 .exit = brightness_exit,
2418 },
2419 {
2420 .name = "volume",
2421 .read = volume_read,
2422 .write = volume_write,
2423 },
2424 {
2425 .name = "fan",
2426 .read = fan_read,
2427 .write = fan_write,
2428 .init = fan_init,
2429 .exit = fan_exit,
2430 .experimental = 1,
2431 },
2432};
2433
2434static int dispatch_read(char *page, char **start, off_t off, int count,
2435 int *eof, void *data)
2436{
2437 struct ibm_struct *ibm = data;
2438 int len;
2439
2440 if (!ibm || !ibm->read)
2441 return -EINVAL;
2442
2443 len = ibm->read(page);
2444 if (len < 0)
2445 return len;
2446
2447 if (len <= off + count)
2448 *eof = 1;
2449 *start = page + off;
2450 len -= off;
2451 if (len > count)
2452 len = count;
2453 if (len < 0)
2454 len = 0;
2455
2456 return len;
2457}
2458
2459static int dispatch_write(struct file *file, const char __user * userbuf,
2460 unsigned long count, void *data)
2461{
2462 struct ibm_struct *ibm = data;
2463 char *kernbuf;
2464 int ret;
2465
2466 if (!ibm || !ibm->write)
2467 return -EINVAL;
2468
2469 kernbuf = kmalloc(count + 2, GFP_KERNEL);
2470 if (!kernbuf)
2471 return -ENOMEM;
2472
2473 if (copy_from_user(kernbuf, userbuf, count)) {
2474 kfree(kernbuf);
2475 return -EFAULT;
2476 }
2477
2478 kernbuf[count] = 0;
2479 strcat(kernbuf, ",");
2480 ret = ibm->write(kernbuf);
2481 if (ret == 0)
2482 ret = count;
2483
2484 kfree(kernbuf);
2485
2486 return ret;
2487}
2488
2489static void dispatch_notify(acpi_handle handle, u32 event, void *data)
2490{
2491 struct ibm_struct *ibm = data;
2492
2493 if (!ibm || !ibm->notify)
2494 return;
2495
2496 ibm->notify(ibm, event);
2497}
2498
2499static int __init setup_notify(struct ibm_struct *ibm)
2500{
2501 acpi_status status;
2502 int ret;
2503
2504 if (!*ibm->handle)
2505 return 0;
2506
2507 ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
2508 if (ret < 0) {
2509 printk(IBM_ERR "%s device not present\n", ibm->name);
2510 return -ENODEV;
2511 }
2512
2513 acpi_driver_data(ibm->device) = ibm;
2514 sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
2515
2516 status = acpi_install_notify_handler(*ibm->handle, ibm->type,
2517 dispatch_notify, ibm);
2518 if (ACPI_FAILURE(status)) {
2519 if (status == AE_ALREADY_EXISTS) {
2520 printk(IBM_NOTICE "another device driver is already handling %s events\n",
2521 ibm->name);
2522 } else {
2523 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
2524 ibm->name, status);
2525 }
2526 return -ENODEV;
2527 }
2528 ibm->notify_installed = 1;
2529 return 0;
2530}
2531
2532static int __init ibm_device_add(struct acpi_device *device)
2533{
2534 return 0;
2535}
2536
2537static int __init register_driver(struct ibm_struct *ibm)
2538{
2539 int ret;
2540
2541 ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
2542 if (!ibm->driver) {
2543 printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
2544 return -1;
2545 }
2546
2547 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
2548 ibm->driver->ids = ibm->hid;
2549 ibm->driver->ops.add = &ibm_device_add;
2550
2551 ret = acpi_bus_register_driver(ibm->driver);
2552 if (ret < 0) {
2553 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
2554 ibm->hid, ret);
2555 kfree(ibm->driver);
2556 }
2557
2558 return ret;
2559}
2560
2561static void ibm_exit(struct ibm_struct *ibm);
2562
2563static int __init ibm_init(struct ibm_struct *ibm)
2564{
2565 int ret;
2566 struct proc_dir_entry *entry;
2567
2568 if (ibm->experimental && !experimental)
2569 return 0;
2570
2571 if (ibm->hid) {
2572 ret = register_driver(ibm);
2573 if (ret < 0)
2574 return ret;
2575 ibm->driver_registered = 1;
2576 }
2577
2578 if (ibm->init) {
2579 ret = ibm->init();
2580 if (ret != 0)
2581 return ret;
2582 ibm->init_called = 1;
2583 }
2584
2585 if (ibm->read) {
2586 entry = create_proc_entry(ibm->name,
2587 S_IFREG | S_IRUGO | S_IWUSR,
2588 proc_dir);
2589 if (!entry) {
2590 printk(IBM_ERR "unable to create proc entry %s\n",
2591 ibm->name);
2592 return -ENODEV;
2593 }
2594 entry->owner = THIS_MODULE;
2595 entry->data = ibm;
2596 entry->read_proc = &dispatch_read;
2597 if (ibm->write)
2598 entry->write_proc = &dispatch_write;
2599 ibm->proc_created = 1;
2600 }
2601
2602 if (ibm->notify) {
2603 ret = setup_notify(ibm);
2604 if (ret == -ENODEV) {
2605 printk(IBM_NOTICE "disabling subdriver %s\n",
2606 ibm->name);
2607 ibm_exit(ibm);
2608 return 0;
2609 }
2610 if (ret < 0)
2611 return ret;
2612 }
2613
2614 return 0;
2615}
2616
2617static void ibm_exit(struct ibm_struct *ibm)
2618{
2619 if (ibm->notify_installed)
2620 acpi_remove_notify_handler(*ibm->handle, ibm->type,
2621 dispatch_notify);
2622
2623 if (ibm->proc_created)
2624 remove_proc_entry(ibm->name, proc_dir);
2625
2626 if (ibm->init_called && ibm->exit)
2627 ibm->exit();
2628
2629 if (ibm->driver_registered) {
2630 acpi_bus_unregister_driver(ibm->driver);
2631 kfree(ibm->driver);
2632 }
2633}
2634
2635static void __init ibm_handle_init(char *name,
2636 acpi_handle * handle, acpi_handle parent,
2637 char **paths, int num_paths, char **path)
2638{
2639 int i;
2640 acpi_status status;
2641
2642 for (i = 0; i < num_paths; i++) {
2643 status = acpi_get_handle(parent, paths[i], handle);
2644 if (ACPI_SUCCESS(status)) {
2645 *path = paths[i];
2646 return;
2647 }
2648 }
2649
2650 *handle = NULL;
2651}
2652
2653#define IBM_HANDLE_INIT(object) \
2654 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2655 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2656
2657static int __init set_ibm_param(const char *val, struct kernel_param *kp)
2658{
2659 unsigned int i;
2660
2661 for (i = 0; i < ARRAY_SIZE(ibms); i++)
2662 if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
2663 if (strlen(val) > sizeof(ibms[i].param) - 2)
2664 return -ENOSPC;
2665 strcpy(ibms[i].param, val);
2666 strcat(ibms[i].param, ",");
2667 return 0;
2668 }
2669
2670 return -EINVAL;
2671}
2672
2673#define IBM_PARAM(feature) \
2674 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2675
2676IBM_PARAM(hotkey);
2677IBM_PARAM(bluetooth);
2678IBM_PARAM(video);
2679IBM_PARAM(light);
2680#ifdef CONFIG_ACPI_IBM_DOCK
2681IBM_PARAM(dock);
2682#endif
2683#ifdef CONFIG_ACPI_IBM_BAY
2684IBM_PARAM(bay);
2685#endif /* CONFIG_ACPI_IBM_BAY */
2686IBM_PARAM(cmos);
2687IBM_PARAM(led);
2688IBM_PARAM(beep);
2689IBM_PARAM(ecdump);
2690IBM_PARAM(brightness);
2691IBM_PARAM(volume);
2692IBM_PARAM(fan);
2693
2694static void acpi_ibm_exit(void)
2695{
2696 int i;
2697
2698 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
2699 ibm_exit(&ibms[i]);
2700
2701 if (proc_dir)
2702 remove_proc_entry(IBM_DIR, acpi_root_dir);
2703
2704 if (ibm_thinkpad_ec_found)
2705 kfree(ibm_thinkpad_ec_found);
2706}
2707
2708static char* __init check_dmi_for_ec(void)
2709{
2710 struct dmi_device *dev = NULL;
2711 char ec_fw_string[18];
2712
2713 /*
2714 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2715 * X32 or newer, all Z series; Some models must have an
2716 * up-to-date BIOS or they will not be detected.
2717 *
2718 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2719 */
2720 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2721 if (sscanf(dev->name,
2722 "IBM ThinkPad Embedded Controller -[%17c",
2723 ec_fw_string) == 1) {
2724 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
2725 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
2726 return kstrdup(ec_fw_string, GFP_KERNEL);
2727 }
2728 }
2729 return NULL;
2730}
2731
2732static int __init acpi_ibm_init(void)
2733{
2734 int ret, i;
2735
2736 if (acpi_disabled)
2737 return -ENODEV;
2738
2739 /* ec is required because many other handles are relative to it */
2740 IBM_HANDLE_INIT(ec);
2741 if (!ec_handle) {
2742 printk(IBM_ERR "ec object not found\n");
2743 return -ENODEV;
2744 }
2745
2746 /* Models with newer firmware report the EC in DMI */
2747 ibm_thinkpad_ec_found = check_dmi_for_ec();
2748
2749 /* these handles are not required */
2750 IBM_HANDLE_INIT(vid);
2751 IBM_HANDLE_INIT(vid2);
2752 IBM_HANDLE_INIT(ledb);
2753 IBM_HANDLE_INIT(led);
2754 IBM_HANDLE_INIT(hkey);
2755 IBM_HANDLE_INIT(lght);
2756 IBM_HANDLE_INIT(cmos);
2757#ifdef CONFIG_ACPI_IBM_DOCK
2758 IBM_HANDLE_INIT(dock);
2759#endif
2760 IBM_HANDLE_INIT(pci);
2761#ifdef CONFIG_ACPI_IBM_BAY
2762 IBM_HANDLE_INIT(bay);
2763 if (bay_handle)
2764 IBM_HANDLE_INIT(bay_ej);
2765 IBM_HANDLE_INIT(bay2);
2766 if (bay2_handle)
2767 IBM_HANDLE_INIT(bay2_ej);
2768#endif /* CONFIG_ACPI_IBM_BAY */
2769 IBM_HANDLE_INIT(beep);
2770 IBM_HANDLE_INIT(ecrd);
2771 IBM_HANDLE_INIT(ecwr);
2772 IBM_HANDLE_INIT(fans);
2773 IBM_HANDLE_INIT(gfan);
2774 IBM_HANDLE_INIT(sfan);
2775
2776 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
2777 if (!proc_dir) {
2778 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
2779 acpi_ibm_exit();
2780 return -ENODEV;
2781 }
2782 proc_dir->owner = THIS_MODULE;
2783
2784 for (i = 0; i < ARRAY_SIZE(ibms); i++) {
2785 ret = ibm_init(&ibms[i]);
2786 if (ret >= 0 && *ibms[i].param)
2787 ret = ibms[i].write(ibms[i].param);
2788 if (ret < 0) {
2789 acpi_ibm_exit();
2790 return ret;
2791 }
2792 }
2793
2794 return 0;
2795}
2796
2797module_init(acpi_ibm_init);
2798module_exit(acpi_ibm_exit);
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 99d1516d1e70..f7de02a6f497 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -70,8 +70,6 @@
70#define ACPI_PROCESSOR_LIMIT_USER 0 70#define ACPI_PROCESSOR_LIMIT_USER 0
71#define ACPI_PROCESSOR_LIMIT_THERMAL 1 71#define ACPI_PROCESSOR_LIMIT_THERMAL 1
72 72
73#define ACPI_STA_PRESENT 0x00000001
74
75#define _COMPONENT ACPI_PROCESSOR_COMPONENT 73#define _COMPONENT ACPI_PROCESSOR_COMPONENT
76ACPI_MODULE_NAME("processor_core"); 74ACPI_MODULE_NAME("processor_core");
77 75
@@ -779,7 +777,7 @@ static int is_processor_present(acpi_handle handle)
779 777
780 778
781 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); 779 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
782 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) { 780 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT)) {
783 ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present")); 781 ACPI_EXCEPTION((AE_INFO, status, "Processor Device is not present"));
784 return 0; 782 return 0;
785 } 783 }
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index cdf78943af4d..ae0654cd11ea 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -51,14 +51,6 @@
51#include <asm/apic.h> 51#include <asm/apic.h>
52#endif 52#endif
53 53
54/*
55 * Include the apic definitions for x86 to have the APIC timer related defines
56 * available also for UP (on SMP it gets magically included via linux/smp.h).
57 */
58#ifdef CONFIG_X86
59#include <asm/apic.h>
60#endif
61
62#include <asm/io.h> 54#include <asm/io.h>
63#include <asm/uaccess.h> 55#include <asm/uaccess.h>
64 56
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 59640d9a0acc..c1bae106833c 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -30,30 +30,10 @@
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/acpi.h> 32#include <linux/acpi.h>
33#include <linux/i2c.h> 33#include <linux/timer.h>
34#include <linux/jiffies.h>
34#include <linux/delay.h> 35#include <linux/delay.h>
35 36
36#include "i2c_ec.h"
37
38#define DEF_CAPACITY_UNIT 3
39#define MAH_CAPACITY_UNIT 1
40#define MWH_CAPACITY_UNIT 2
41#define CAPACITY_UNIT DEF_CAPACITY_UNIT
42
43#define REQUEST_UPDATE_MODE 1
44#define QUEUE_UPDATE_MODE 2
45
46#define DATA_TYPE_COMMON 0
47#define DATA_TYPE_INFO 1
48#define DATA_TYPE_STATE 2
49#define DATA_TYPE_ALARM 3
50#define DATA_TYPE_AC_STATE 4
51
52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
53extern struct proc_dir_entry *acpi_lock_battery_dir(void);
54extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
55extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
56
57#define ACPI_SBS_COMPONENT 0x00080000 37#define ACPI_SBS_COMPONENT 0x00080000
58#define ACPI_SBS_CLASS "sbs" 38#define ACPI_SBS_CLASS "sbs"
59#define ACPI_AC_CLASS "ac_adapter" 39#define ACPI_AC_CLASS "ac_adapter"
@@ -74,39 +54,75 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
74 54
75#define _COMPONENT ACPI_SBS_COMPONENT 55#define _COMPONENT ACPI_SBS_COMPONENT
76 56
77#define MAX_SBS_BAT 4
78#define MAX_SMBUS_ERR 1
79
80ACPI_MODULE_NAME("sbs"); 57ACPI_MODULE_NAME("sbs");
81 58
82MODULE_AUTHOR("Rich Townsend"); 59MODULE_AUTHOR("Rich Townsend");
83MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); 60MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
84MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
85 62
86static struct semaphore sbs_sem; 63#define xmsleep(t) msleep(t)
64
65#define ACPI_EC_SMB_PRTCL 0x00 /* protocol, PEC */
66
67#define ACPI_EC_SMB_STS 0x01 /* status */
68#define ACPI_EC_SMB_ADDR 0x02 /* address */
69#define ACPI_EC_SMB_CMD 0x03 /* command */
70#define ACPI_EC_SMB_DATA 0x04 /* 32 data registers */
71#define ACPI_EC_SMB_BCNT 0x24 /* number of data bytes */
87 72
88#define UPDATE_MODE QUEUE_UPDATE_MODE 73#define ACPI_EC_SMB_STS_DONE 0x80
89/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */ 74#define ACPI_EC_SMB_STS_STATUS 0x1f
90#define UPDATE_INFO_MODE 0
91#define UPDATE_TIME 60
92#define UPDATE_TIME2 0
93 75
94static int capacity_mode = CAPACITY_UNIT; 76#define ACPI_EC_SMB_PRTCL_WRITE 0x00
95static int update_mode = UPDATE_MODE; 77#define ACPI_EC_SMB_PRTCL_READ 0x01
96static int update_info_mode = UPDATE_INFO_MODE; 78#define ACPI_EC_SMB_PRTCL_WORD_DATA 0x08
97static int update_time = UPDATE_TIME; 79#define ACPI_EC_SMB_PRTCL_BLOCK_DATA 0x0a
98static int update_time2 = UPDATE_TIME2;
99 80
100module_param(capacity_mode, int, 0); 81#define ACPI_EC_SMB_TRANSACTION_SLEEP 1
101module_param(update_mode, int, 0); 82#define ACPI_EC_SMB_ACCESS_SLEEP1 1
102module_param(update_info_mode, int, 0); 83#define ACPI_EC_SMB_ACCESS_SLEEP2 10
103module_param(update_time, int, 0); 84
104module_param(update_time2, int, 0); 85#define DEF_CAPACITY_UNIT 3
86#define MAH_CAPACITY_UNIT 1
87#define MWH_CAPACITY_UNIT 2
88#define CAPACITY_UNIT DEF_CAPACITY_UNIT
89
90#define REQUEST_UPDATE_MODE 1
91#define QUEUE_UPDATE_MODE 2
92
93#define DATA_TYPE_COMMON 0
94#define DATA_TYPE_INFO 1
95#define DATA_TYPE_STATE 2
96#define DATA_TYPE_ALARM 3
97#define DATA_TYPE_AC_STATE 4
98
99extern struct proc_dir_entry *acpi_lock_ac_dir(void);
100extern struct proc_dir_entry *acpi_lock_battery_dir(void);
101extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
102extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
103
104#define MAX_SBS_BAT 4
105#define ACPI_SBS_BLOCK_MAX 32
106
107#define ACPI_SBS_SMBUS_READ 1
108#define ACPI_SBS_SMBUS_WRITE 2
109
110#define ACPI_SBS_WORD_DATA 1
111#define ACPI_SBS_BLOCK_DATA 2
112
113#define UPDATE_DELAY 10
114
115/* 0 - every time, > 0 - by update_time */
116static unsigned int update_time = 120;
117
118static unsigned int capacity_mode = CAPACITY_UNIT;
119
120module_param(update_time, uint, 0644);
121module_param(capacity_mode, uint, 0444);
105 122
106static int acpi_sbs_add(struct acpi_device *device); 123static int acpi_sbs_add(struct acpi_device *device);
107static int acpi_sbs_remove(struct acpi_device *device, int type); 124static int acpi_sbs_remove(struct acpi_device *device, int type);
108static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus); 125static int acpi_sbs_resume(struct acpi_device *device);
109static void acpi_sbs_update_queue(void *data);
110 126
111static struct acpi_driver acpi_sbs_driver = { 127static struct acpi_driver acpi_sbs_driver = {
112 .name = "sbs", 128 .name = "sbs",
@@ -115,9 +131,14 @@ static struct acpi_driver acpi_sbs_driver = {
115 .ops = { 131 .ops = {
116 .add = acpi_sbs_add, 132 .add = acpi_sbs_add,
117 .remove = acpi_sbs_remove, 133 .remove = acpi_sbs_remove,
134 .resume = acpi_sbs_resume,
118 }, 135 },
119}; 136};
120 137
138struct acpi_ac {
139 int ac_present;
140};
141
121struct acpi_battery_info { 142struct acpi_battery_info {
122 int capacity_mode; 143 int capacity_mode;
123 s16 full_charge_capacity; 144 s16 full_charge_capacity;
@@ -126,18 +147,16 @@ struct acpi_battery_info {
126 int vscale; 147 int vscale;
127 int ipscale; 148 int ipscale;
128 s16 serial_number; 149 s16 serial_number;
129 char manufacturer_name[I2C_SMBUS_BLOCK_MAX + 3]; 150 char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3];
130 char device_name[I2C_SMBUS_BLOCK_MAX + 3]; 151 char device_name[ACPI_SBS_BLOCK_MAX + 3];
131 char device_chemistry[I2C_SMBUS_BLOCK_MAX + 3]; 152 char device_chemistry[ACPI_SBS_BLOCK_MAX + 3];
132}; 153};
133 154
134struct acpi_battery_state { 155struct acpi_battery_state {
135 s16 voltage; 156 s16 voltage;
136 s16 amperage; 157 s16 amperage;
137 s16 remaining_capacity; 158 s16 remaining_capacity;
138 s16 average_time_to_empty; 159 s16 battery_state;
139 s16 average_time_to_full;
140 s16 battery_status;
141}; 160};
142 161
143struct acpi_battery_alarm { 162struct acpi_battery_alarm {
@@ -146,9 +165,9 @@ struct acpi_battery_alarm {
146 165
147struct acpi_battery { 166struct acpi_battery {
148 int alive; 167 int alive;
149 int battery_present;
150 int id; 168 int id;
151 int init_state; 169 int init_state;
170 int battery_present;
152 struct acpi_sbs *sbs; 171 struct acpi_sbs *sbs;
153 struct acpi_battery_info info; 172 struct acpi_battery_info info;
154 struct acpi_battery_state state; 173 struct acpi_battery_state state;
@@ -158,186 +177,251 @@ struct acpi_battery {
158 177
159struct acpi_sbs { 178struct acpi_sbs {
160 acpi_handle handle; 179 acpi_handle handle;
180 int base;
161 struct acpi_device *device; 181 struct acpi_device *device;
162 struct acpi_ec_smbus *smbus; 182 struct acpi_ec_smbus *smbus;
183 struct mutex mutex;
163 int sbsm_present; 184 int sbsm_present;
164 int sbsm_batteries_supported; 185 int sbsm_batteries_supported;
165 int ac_present;
166 struct proc_dir_entry *ac_entry; 186 struct proc_dir_entry *ac_entry;
187 struct acpi_ac ac;
167 struct acpi_battery battery[MAX_SBS_BAT]; 188 struct acpi_battery battery[MAX_SBS_BAT];
168 int update_info_mode;
169 int zombie; 189 int zombie;
170 int update_time;
171 int update_time2;
172 struct timer_list update_timer; 190 struct timer_list update_timer;
191 int run_cnt;
192 int update_proc_flg;
173}; 193};
174 194
175static void acpi_update_delay(struct acpi_sbs *sbs); 195static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
176static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type); 196static void acpi_sbs_update_time(void *data);
197
198union sbs_rw_data {
199 u16 word;
200 u8 block[ACPI_SBS_BLOCK_MAX + 2];
201};
202
203static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
204 char read_write, u8 command, int size,
205 union sbs_rw_data *data);
177 206
178/* -------------------------------------------------------------------------- 207/* --------------------------------------------------------------------------
179 SMBus Communication 208 SMBus Communication
180 -------------------------------------------------------------------------- */ 209 -------------------------------------------------------------------------- */
181 210
182static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus) 211static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data)
183{ 212{
184 union i2c_smbus_data data; 213 u8 val;
185 int result = 0; 214 int err;
186 char *err_str;
187 int err_number;
188 215
189 data.word = 0; 216 err = ec_read(sbs->base + address, &val);
217 if (!err) {
218 *data = val;
219 }
220 xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
221 return (err);
222}
190 223
191 result = smbus->adapter.algo-> 224static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data)
192 smbus_xfer(&smbus->adapter, 225{
193 ACPI_SB_SMBUS_ADDR, 226 int err;
194 0, I2C_SMBUS_READ, 0x16, I2C_SMBUS_BLOCK_DATA, &data);
195 227
196 err_number = (data.word & 0x000f); 228 err = ec_write(sbs->base + address, data);
229 return (err);
230}
197 231
198 switch (data.word & 0x000f) { 232static int
199 case 0x0000: 233acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
200 err_str = "unexpected bus error"; 234 char read_write, u8 command, int size,
201 break; 235 union sbs_rw_data *data)
202 case 0x0001: 236{
203 err_str = "busy"; 237 unsigned char protocol, len = 0, temp[2] = { 0, 0 };
204 break; 238 int i;
205 case 0x0002: 239
206 err_str = "reserved command"; 240 if (read_write == ACPI_SBS_SMBUS_READ) {
207 break; 241 protocol = ACPI_EC_SMB_PRTCL_READ;
208 case 0x0003: 242 } else {
209 err_str = "unsupported command"; 243 protocol = ACPI_EC_SMB_PRTCL_WRITE;
210 break; 244 }
211 case 0x0004: 245
212 err_str = "access denied"; 246 switch (size) {
247
248 case ACPI_SBS_WORD_DATA:
249 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command);
250 if (read_write == ACPI_SBS_SMBUS_WRITE) {
251 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA, data->word);
252 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + 1,
253 data->word >> 8);
254 }
255 protocol |= ACPI_EC_SMB_PRTCL_WORD_DATA;
213 break; 256 break;
214 case 0x0005: 257 case ACPI_SBS_BLOCK_DATA:
215 err_str = "overflow/underflow"; 258 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_CMD, command);
259 if (read_write == ACPI_SBS_SMBUS_WRITE) {
260 len = min_t(u8, data->block[0], 32);
261 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_BCNT, len);
262 for (i = 0; i < len; i++)
263 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_DATA + i,
264 data->block[i + 1]);
265 }
266 protocol |= ACPI_EC_SMB_PRTCL_BLOCK_DATA;
216 break; 267 break;
217 case 0x0006: 268 default:
218 err_str = "bad size"; 269 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
270 "unsupported transaction %d", size));
271 return (-1);
272 }
273
274 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_ADDR, addr << 1);
275 acpi_ec_sbs_write(sbs, ACPI_EC_SMB_PRTCL, protocol);
276
277 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
278
279 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
280 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP1);
281 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
282 }
283 if (~temp[0] & ACPI_EC_SMB_STS_DONE) {
284 xmsleep(ACPI_EC_SMB_ACCESS_SLEEP2);
285 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_STS, temp);
286 }
287 if ((~temp[0] & ACPI_EC_SMB_STS_DONE)
288 || (temp[0] & ACPI_EC_SMB_STS_STATUS)) {
289 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
290 "transaction %d error", size));
291 return (-1);
292 }
293
294 if (read_write == ACPI_SBS_SMBUS_WRITE) {
295 return (0);
296 }
297
298 switch (size) {
299
300 case ACPI_SBS_WORD_DATA:
301 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA, temp);
302 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + 1, temp + 1);
303 data->word = (temp[1] << 8) | temp[0];
219 break; 304 break;
220 case 0x0007: 305
221 err_str = "unknown error"; 306 case ACPI_SBS_BLOCK_DATA:
307 len = 0;
308 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_BCNT, &len);
309 len = min_t(u8, len, 32);
310 for (i = 0; i < len; i++)
311 acpi_ec_sbs_read(sbs, ACPI_EC_SMB_DATA + i,
312 data->block + i + 1);
313 data->block[0] = len;
222 break; 314 break;
223 default: 315 default:
224 err_str = "unrecognized error"; 316 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
317 "unsupported transaction %d", size));
318 return (-1);
225 } 319 }
226 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 320
227 "%s: ret %i, err %i\n", err_str, result, err_number)); 321 return (0);
228} 322}
229 323
230static int 324static int
231acpi_sbs_smbus_read_word(struct acpi_ec_smbus *smbus, int addr, int func, 325acpi_sbs_read_word(struct acpi_sbs *sbs, int addr, int func, u16 * word)
232 u16 * word,
233 void (*err_handler) (struct acpi_ec_smbus * smbus))
234{ 326{
235 union i2c_smbus_data data; 327 union sbs_rw_data data;
236 int result = 0; 328 int result = 0;
237 int i;
238 329
239 if (err_handler == NULL) { 330 result = acpi_ec_sbs_access(sbs, addr,
240 err_handler = acpi_battery_smbus_err_handler; 331 ACPI_SBS_SMBUS_READ, func,
241 } 332 ACPI_SBS_WORD_DATA, &data);
242 333 if (result) {
243 for (i = 0; i < MAX_SMBUS_ERR; i++) { 334 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
244 result = 335 "acpi_ec_sbs_access() failed"));
245 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 336 } else {
246 I2C_SMBUS_READ, func, 337 *word = data.word;
247 I2C_SMBUS_WORD_DATA, &data);
248 if (result) {
249 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
250 "try %i: smbus->adapter.algo->smbus_xfer() failed\n",
251 i));
252 if (err_handler) {
253 err_handler(smbus);
254 }
255 } else {
256 *word = data.word;
257 break;
258 }
259 } 338 }
260 339
261 return result; 340 return result;
262} 341}
263 342
264static int 343static int
265acpi_sbs_smbus_read_str(struct acpi_ec_smbus *smbus, int addr, int func, 344acpi_sbs_read_str(struct acpi_sbs *sbs, int addr, int func, char *str)
266 char *str,
267 void (*err_handler) (struct acpi_ec_smbus * smbus))
268{ 345{
269 union i2c_smbus_data data; 346 union sbs_rw_data data;
270 int result = 0; 347 int result = 0;
271 int i;
272
273 if (err_handler == NULL) {
274 err_handler = acpi_battery_smbus_err_handler;
275 }
276 348
277 for (i = 0; i < MAX_SMBUS_ERR; i++) { 349 result = acpi_ec_sbs_access(sbs, addr,
278 result = 350 ACPI_SBS_SMBUS_READ, func,
279 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 351 ACPI_SBS_BLOCK_DATA, &data);
280 I2C_SMBUS_READ, func, 352 if (result) {
281 I2C_SMBUS_BLOCK_DATA, 353 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
282 &data); 354 "acpi_ec_sbs_access() failed"));
283 if (result) { 355 } else {
284 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 356 strncpy(str, (const char *)data.block + 1, data.block[0]);
285 "try %i: smbus->adapter.algo->smbus_xfer() failed\n", 357 str[data.block[0]] = 0;
286 i));
287 if (err_handler) {
288 err_handler(smbus);
289 }
290 } else {
291 strncpy(str, (const char *)data.block + 1,
292 data.block[0]);
293 str[data.block[0]] = 0;
294 break;
295 }
296 } 358 }
297 359
298 return result; 360 return result;
299} 361}
300 362
301static int 363static int
302acpi_sbs_smbus_write_word(struct acpi_ec_smbus *smbus, int addr, int func, 364acpi_sbs_write_word(struct acpi_sbs *sbs, int addr, int func, int word)
303 int word,
304 void (*err_handler) (struct acpi_ec_smbus * smbus))
305{ 365{
306 union i2c_smbus_data data; 366 union sbs_rw_data data;
307 int result = 0; 367 int result = 0;
308 int i;
309
310 if (err_handler == NULL) {
311 err_handler = acpi_battery_smbus_err_handler;
312 }
313 368
314 data.word = word; 369 data.word = word;
315 370
316 for (i = 0; i < MAX_SMBUS_ERR; i++) { 371 result = acpi_ec_sbs_access(sbs, addr,
317 result = 372 ACPI_SBS_SMBUS_WRITE, func,
318 smbus->adapter.algo->smbus_xfer(&smbus->adapter, addr, 0, 373 ACPI_SBS_WORD_DATA, &data);
319 I2C_SMBUS_WRITE, func, 374 if (result) {
320 I2C_SMBUS_WORD_DATA, &data); 375 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
321 if (result) { 376 "acpi_ec_sbs_access() failed"));
322 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
323 "try %i: smbus->adapter.algo"
324 "->smbus_xfer() failed\n", i));
325 if (err_handler) {
326 err_handler(smbus);
327 }
328 } else {
329 break;
330 }
331 } 377 }
332 378
333 return result; 379 return result;
334} 380}
335 381
382static int sbs_zombie(struct acpi_sbs *sbs)
383{
384 return (sbs->zombie);
385}
386
387static int sbs_mutex_lock(struct acpi_sbs *sbs)
388{
389 if (sbs_zombie(sbs)) {
390 return -ENODEV;
391 }
392 mutex_lock(&sbs->mutex);
393 return 0;
394}
395
396static void sbs_mutex_unlock(struct acpi_sbs *sbs)
397{
398 mutex_unlock(&sbs->mutex);
399}
400
336/* -------------------------------------------------------------------------- 401/* --------------------------------------------------------------------------
337 Smart Battery System Management 402 Smart Battery System Management
338 -------------------------------------------------------------------------- */ 403 -------------------------------------------------------------------------- */
339 404
340/* Smart Battery */ 405static int acpi_check_update_proc(struct acpi_sbs *sbs)
406{
407 acpi_status status = AE_OK;
408
409 if (update_time == 0) {
410 sbs->update_proc_flg = 0;
411 return 0;
412 }
413 if (sbs->update_proc_flg == 0) {
414 status = acpi_os_execute(OSL_GPE_HANDLER,
415 acpi_sbs_update_time, sbs);
416 if (status != AE_OK) {
417 ACPI_EXCEPTION((AE_INFO, status,
418 "acpi_os_execute() failed"));
419 return 1;
420 }
421 sbs->update_proc_flg = 1;
422 }
423 return 0;
424}
341 425
342static int acpi_sbs_generate_event(struct acpi_device *device, 426static int acpi_sbs_generate_event(struct acpi_device *device,
343 int event, int state, char *bid, char *class) 427 int event, int state, char *bid, char *class)
@@ -366,12 +450,11 @@ static int acpi_battery_get_present(struct acpi_battery *battery)
366 int result = 0; 450 int result = 0;
367 int is_present = 0; 451 int is_present = 0;
368 452
369 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 453 result = acpi_sbs_read_word(battery->sbs,
370 ACPI_SBSM_SMBUS_ADDR, 0x01, 454 ACPI_SBSM_SMBUS_ADDR, 0x01, &state);
371 &state, NULL);
372 if (result) { 455 if (result) {
373 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 456 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
374 "acpi_sbs_smbus_read_word() failed")); 457 "acpi_sbs_read_word() failed"));
375 } 458 }
376 if (!result) { 459 if (!result) {
377 is_present = (state & 0x000f) & (1 << battery->id); 460 is_present = (state & 0x000f) & (1 << battery->id);
@@ -381,45 +464,33 @@ static int acpi_battery_get_present(struct acpi_battery *battery)
381 return result; 464 return result;
382} 465}
383 466
384static int acpi_battery_is_present(struct acpi_battery *battery)
385{
386 return (battery->battery_present);
387}
388
389static int acpi_ac_is_present(struct acpi_sbs *sbs)
390{
391 return (sbs->ac_present);
392}
393
394static int acpi_battery_select(struct acpi_battery *battery) 467static int acpi_battery_select(struct acpi_battery *battery)
395{ 468{
396 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 469 struct acpi_sbs *sbs = battery->sbs;
397 int result = 0; 470 int result = 0;
398 s16 state; 471 s16 state;
399 int foo; 472 int foo;
400 473
401 if (battery->sbs->sbsm_present) { 474 if (sbs->sbsm_present) {
402 475
403 /* Take special care not to knobble other nibbles of 476 /* Take special care not to knobble other nibbles of
404 * state (aka selector_state), since 477 * state (aka selector_state), since
405 * it causes charging to halt on SBSELs */ 478 * it causes charging to halt on SBSELs */
406 479
407 result = 480 result =
408 acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, 481 acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, &state);
409 &state, NULL);
410 if (result) { 482 if (result) {
411 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 483 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
412 "acpi_sbs_smbus_read_word() failed\n")); 484 "acpi_sbs_read_word() failed"));
413 goto end; 485 goto end;
414 } 486 }
415 487
416 foo = (state & 0x0fff) | (1 << (battery->id + 12)); 488 foo = (state & 0x0fff) | (1 << (battery->id + 12));
417 result = 489 result =
418 acpi_sbs_smbus_write_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x01, 490 acpi_sbs_write_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x01, foo);
419 foo, NULL);
420 if (result) { 491 if (result) {
421 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 492 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
422 "acpi_sbs_smbus_write_word() failed\n")); 493 "acpi_sbs_write_word() failed"));
423 goto end; 494 goto end;
424 } 495 }
425 } 496 }
@@ -430,15 +501,14 @@ static int acpi_battery_select(struct acpi_battery *battery)
430 501
431static int acpi_sbsm_get_info(struct acpi_sbs *sbs) 502static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
432{ 503{
433 struct acpi_ec_smbus *smbus = sbs->smbus;
434 int result = 0; 504 int result = 0;
435 s16 battery_system_info; 505 s16 battery_system_info;
436 506
437 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBSM_SMBUS_ADDR, 0x04, 507 result = acpi_sbs_read_word(sbs, ACPI_SBSM_SMBUS_ADDR, 0x04,
438 &battery_system_info, NULL); 508 &battery_system_info);
439 if (result) { 509 if (result) {
440 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 510 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
441 "acpi_sbs_smbus_read_word() failed\n")); 511 "acpi_sbs_read_word() failed"));
442 goto end; 512 goto end;
443 } 513 }
444 514
@@ -451,53 +521,50 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
451 521
452static int acpi_battery_get_info(struct acpi_battery *battery) 522static int acpi_battery_get_info(struct acpi_battery *battery)
453{ 523{
454 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 524 struct acpi_sbs *sbs = battery->sbs;
455 int result = 0; 525 int result = 0;
456 s16 battery_mode; 526 s16 battery_mode;
457 s16 specification_info; 527 s16 specification_info;
458 528
459 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, 529 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03,
460 &battery_mode, 530 &battery_mode);
461 &acpi_battery_smbus_err_handler);
462 if (result) { 531 if (result) {
463 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 532 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
464 "acpi_sbs_smbus_read_word() failed\n")); 533 "acpi_sbs_read_word() failed"));
465 goto end; 534 goto end;
466 } 535 }
467 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15; 536 battery->info.capacity_mode = (battery_mode & 0x8000) >> 15;
468 537
469 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x10, 538 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x10,
470 &battery->info.full_charge_capacity, 539 &battery->info.full_charge_capacity);
471 &acpi_battery_smbus_err_handler);
472 if (result) { 540 if (result) {
473 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 541 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
474 "acpi_sbs_smbus_read_word() failed\n")); 542 "acpi_sbs_read_word() failed"));
475 goto end; 543 goto end;
476 } 544 }
477 545
478 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x18, 546 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x18,
479 &battery->info.design_capacity, 547 &battery->info.design_capacity);
480 &acpi_battery_smbus_err_handler);
481 548
482 if (result) { 549 if (result) {
550 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
551 "acpi_sbs_read_word() failed"));
483 goto end; 552 goto end;
484 } 553 }
485 554
486 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x19, 555 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x19,
487 &battery->info.design_voltage, 556 &battery->info.design_voltage);
488 &acpi_battery_smbus_err_handler);
489 if (result) { 557 if (result) {
490 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 558 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
491 "acpi_sbs_smbus_read_word() failed\n")); 559 "acpi_sbs_read_word() failed"));
492 goto end; 560 goto end;
493 } 561 }
494 562
495 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1a, 563 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1a,
496 &specification_info, 564 &specification_info);
497 &acpi_battery_smbus_err_handler);
498 if (result) { 565 if (result) {
499 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 566 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
500 "acpi_sbs_smbus_read_word() failed\n")); 567 "acpi_sbs_read_word() failed"));
501 goto end; 568 goto end;
502 } 569 }
503 570
@@ -529,37 +596,35 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
529 battery->info.ipscale = 1; 596 battery->info.ipscale = 1;
530 } 597 }
531 598
532 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x1c, 599 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x1c,
533 &battery->info.serial_number, 600 &battery->info.serial_number);
534 &acpi_battery_smbus_err_handler);
535 if (result) { 601 if (result) {
602 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
603 "acpi_sbs_read_word() failed"));
536 goto end; 604 goto end;
537 } 605 }
538 606
539 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x20, 607 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x20,
540 battery->info.manufacturer_name, 608 battery->info.manufacturer_name);
541 &acpi_battery_smbus_err_handler);
542 if (result) { 609 if (result) {
543 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 610 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
544 "acpi_sbs_smbus_read_str() failed\n")); 611 "acpi_sbs_read_str() failed"));
545 goto end; 612 goto end;
546 } 613 }
547 614
548 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x21, 615 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x21,
549 battery->info.device_name, 616 battery->info.device_name);
550 &acpi_battery_smbus_err_handler);
551 if (result) { 617 if (result) {
552 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 618 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
553 "acpi_sbs_smbus_read_str() failed\n")); 619 "acpi_sbs_read_str() failed"));
554 goto end; 620 goto end;
555 } 621 }
556 622
557 result = acpi_sbs_smbus_read_str(smbus, ACPI_SB_SMBUS_ADDR, 0x22, 623 result = acpi_sbs_read_str(sbs, ACPI_SB_SMBUS_ADDR, 0x22,
558 battery->info.device_chemistry, 624 battery->info.device_chemistry);
559 &acpi_battery_smbus_err_handler);
560 if (result) { 625 if (result) {
561 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 626 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
562 "acpi_sbs_smbus_read_str() failed\n")); 627 "acpi_sbs_read_str() failed"));
563 goto end; 628 goto end;
564 } 629 }
565 630
@@ -567,103 +632,60 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
567 return result; 632 return result;
568} 633}
569 634
570static void acpi_update_delay(struct acpi_sbs *sbs)
571{
572 if (sbs->zombie) {
573 return;
574 }
575 if (sbs->update_time2 > 0) {
576 msleep(sbs->update_time2 * 1000);
577 }
578}
579
580static int acpi_battery_get_state(struct acpi_battery *battery) 635static int acpi_battery_get_state(struct acpi_battery *battery)
581{ 636{
582 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 637 struct acpi_sbs *sbs = battery->sbs;
583 int result = 0; 638 int result = 0;
584 639
585 acpi_update_delay(battery->sbs); 640 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x09,
586 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x09, 641 &battery->state.voltage);
587 &battery->state.voltage,
588 &acpi_battery_smbus_err_handler);
589 if (result) { 642 if (result) {
590 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 643 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
591 "acpi_sbs_smbus_read_word() failed\n")); 644 "acpi_sbs_read_word() failed"));
592 goto end; 645 goto end;
593 } 646 }
594 647
595 acpi_update_delay(battery->sbs); 648 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0a,
596 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0a, 649 &battery->state.amperage);
597 &battery->state.amperage,
598 &acpi_battery_smbus_err_handler);
599 if (result) { 650 if (result) {
600 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 651 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
601 "acpi_sbs_smbus_read_word() failed\n")); 652 "acpi_sbs_read_word() failed"));
602 goto end; 653 goto end;
603 } 654 }
604 655
605 acpi_update_delay(battery->sbs); 656 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x0f,
606 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x0f, 657 &battery->state.remaining_capacity);
607 &battery->state.remaining_capacity,
608 &acpi_battery_smbus_err_handler);
609 if (result) { 658 if (result) {
610 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 659 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
611 "acpi_sbs_smbus_read_word() failed\n")); 660 "acpi_sbs_read_word() failed"));
612 goto end; 661 goto end;
613 } 662 }
614 663
615 acpi_update_delay(battery->sbs); 664 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x16,
616 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x12, 665 &battery->state.battery_state);
617 &battery->state.average_time_to_empty,
618 &acpi_battery_smbus_err_handler);
619 if (result) { 666 if (result) {
620 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 667 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
621 "acpi_sbs_smbus_read_word() failed\n")); 668 "acpi_sbs_read_word() failed"));
622 goto end; 669 goto end;
623 } 670 }
624 671
625 acpi_update_delay(battery->sbs);
626 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x13,
627 &battery->state.average_time_to_full,
628 &acpi_battery_smbus_err_handler);
629 if (result) {
630 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
631 "acpi_sbs_smbus_read_word() failed\n"));
632 goto end;
633 }
634
635 acpi_update_delay(battery->sbs);
636 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x16,
637 &battery->state.battery_status,
638 &acpi_battery_smbus_err_handler);
639 if (result) {
640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
641 "acpi_sbs_smbus_read_word() failed\n"));
642 goto end;
643 }
644
645 acpi_update_delay(battery->sbs);
646
647 end: 672 end:
648 return result; 673 return result;
649} 674}
650 675
651static int acpi_battery_get_alarm(struct acpi_battery *battery) 676static int acpi_battery_get_alarm(struct acpi_battery *battery)
652{ 677{
653 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 678 struct acpi_sbs *sbs = battery->sbs;
654 int result = 0; 679 int result = 0;
655 680
656 result = acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 681 result = acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01,
657 &battery->alarm.remaining_capacity, 682 &battery->alarm.remaining_capacity);
658 &acpi_battery_smbus_err_handler);
659 if (result) { 683 if (result) {
660 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 684 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
661 "acpi_sbs_smbus_read_word() failed\n")); 685 "acpi_sbs_read_word() failed"));
662 goto end; 686 goto end;
663 } 687 }
664 688
665 acpi_update_delay(battery->sbs);
666
667 end: 689 end:
668 690
669 return result; 691 return result;
@@ -672,15 +694,15 @@ static int acpi_battery_get_alarm(struct acpi_battery *battery)
672static int acpi_battery_set_alarm(struct acpi_battery *battery, 694static int acpi_battery_set_alarm(struct acpi_battery *battery,
673 unsigned long alarm) 695 unsigned long alarm)
674{ 696{
675 struct acpi_ec_smbus *smbus = battery->sbs->smbus; 697 struct acpi_sbs *sbs = battery->sbs;
676 int result = 0; 698 int result = 0;
677 s16 battery_mode; 699 s16 battery_mode;
678 int foo; 700 int foo;
679 701
680 result = acpi_battery_select(battery); 702 result = acpi_battery_select(battery);
681 if (result) { 703 if (result) {
682 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 704 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
683 "acpi_battery_select() failed\n")); 705 "acpi_battery_select() failed"));
684 goto end; 706 goto end;
685 } 707 }
686 708
@@ -688,33 +710,29 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
688 710
689 if (alarm > 0) { 711 if (alarm > 0) {
690 result = 712 result =
691 acpi_sbs_smbus_read_word(smbus, ACPI_SB_SMBUS_ADDR, 0x03, 713 acpi_sbs_read_word(sbs, ACPI_SB_SMBUS_ADDR, 0x03,
692 &battery_mode, 714 &battery_mode);
693 &acpi_battery_smbus_err_handler);
694 if (result) { 715 if (result) {
695 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 716 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
696 "acpi_sbs_smbus_read_word() failed\n")); 717 "acpi_sbs_read_word() failed"));
697 goto end; 718 goto end;
698 } 719 }
699 720
700 result = 721 result =
701 acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 722 acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01,
702 battery_mode & 0xbfff, 723 battery_mode & 0xbfff);
703 &acpi_battery_smbus_err_handler);
704 if (result) { 724 if (result) {
705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 725 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
706 "acpi_sbs_smbus_write_word() failed\n")); 726 "acpi_sbs_write_word() failed"));
707 goto end; 727 goto end;
708 } 728 }
709 } 729 }
710 730
711 foo = alarm / (battery->info.capacity_mode ? 10 : 1); 731 foo = alarm / (battery->info.capacity_mode ? 10 : 1);
712 result = acpi_sbs_smbus_write_word(smbus, ACPI_SB_SMBUS_ADDR, 0x01, 732 result = acpi_sbs_write_word(sbs, ACPI_SB_SMBUS_ADDR, 0x01, foo);
713 foo,
714 &acpi_battery_smbus_err_handler);
715 if (result) { 733 if (result) {
716 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 734 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
717 "acpi_sbs_smbus_write_word() failed\n")); 735 "acpi_sbs_write_word() failed"));
718 goto end; 736 goto end;
719 } 737 }
720 738
@@ -725,6 +743,7 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
725 743
726static int acpi_battery_set_mode(struct acpi_battery *battery) 744static int acpi_battery_set_mode(struct acpi_battery *battery)
727{ 745{
746 struct acpi_sbs *sbs = battery->sbs;
728 int result = 0; 747 int result = 0;
729 s16 battery_mode; 748 s16 battery_mode;
730 749
@@ -732,12 +751,11 @@ static int acpi_battery_set_mode(struct acpi_battery *battery)
732 goto end; 751 goto end;
733 } 752 }
734 753
735 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 754 result = acpi_sbs_read_word(sbs,
736 ACPI_SB_SMBUS_ADDR, 0x03, 755 ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode);
737 &battery_mode, NULL);
738 if (result) { 756 if (result) {
739 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 757 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
740 "acpi_sbs_smbus_read_word() failed\n")); 758 "acpi_sbs_read_word() failed"));
741 goto end; 759 goto end;
742 } 760 }
743 761
@@ -746,21 +764,19 @@ static int acpi_battery_set_mode(struct acpi_battery *battery)
746 } else { 764 } else {
747 battery_mode |= 0x8000; 765 battery_mode |= 0x8000;
748 } 766 }
749 result = acpi_sbs_smbus_write_word(battery->sbs->smbus, 767 result = acpi_sbs_write_word(sbs,
750 ACPI_SB_SMBUS_ADDR, 0x03, 768 ACPI_SB_SMBUS_ADDR, 0x03, battery_mode);
751 battery_mode, NULL);
752 if (result) { 769 if (result) {
753 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 770 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
754 "acpi_sbs_smbus_write_word() failed\n")); 771 "acpi_sbs_write_word() failed"));
755 goto end; 772 goto end;
756 } 773 }
757 774
758 result = acpi_sbs_smbus_read_word(battery->sbs->smbus, 775 result = acpi_sbs_read_word(sbs,
759 ACPI_SB_SMBUS_ADDR, 0x03, 776 ACPI_SB_SMBUS_ADDR, 0x03, &battery_mode);
760 &battery_mode, NULL);
761 if (result) { 777 if (result) {
762 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 778 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
763 "acpi_sbs_smbus_read_word() failed\n")); 779 "acpi_sbs_read_word() failed"));
764 goto end; 780 goto end;
765 } 781 }
766 782
@@ -774,36 +790,36 @@ static int acpi_battery_init(struct acpi_battery *battery)
774 790
775 result = acpi_battery_select(battery); 791 result = acpi_battery_select(battery);
776 if (result) { 792 if (result) {
777 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 793 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
778 "acpi_battery_init() failed\n")); 794 "acpi_battery_select() failed"));
779 goto end; 795 goto end;
780 } 796 }
781 797
782 result = acpi_battery_set_mode(battery); 798 result = acpi_battery_set_mode(battery);
783 if (result) { 799 if (result) {
784 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 800 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
785 "acpi_battery_set_mode() failed\n")); 801 "acpi_battery_set_mode() failed"));
786 goto end; 802 goto end;
787 } 803 }
788 804
789 result = acpi_battery_get_info(battery); 805 result = acpi_battery_get_info(battery);
790 if (result) { 806 if (result) {
791 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 807 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
792 "acpi_battery_get_info() failed\n")); 808 "acpi_battery_get_info() failed"));
793 goto end; 809 goto end;
794 } 810 }
795 811
796 result = acpi_battery_get_state(battery); 812 result = acpi_battery_get_state(battery);
797 if (result) { 813 if (result) {
798 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 814 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
799 "acpi_battery_get_state() failed\n")); 815 "acpi_battery_get_state() failed"));
800 goto end; 816 goto end;
801 } 817 }
802 818
803 result = acpi_battery_get_alarm(battery); 819 result = acpi_battery_get_alarm(battery);
804 if (result) { 820 if (result) {
805 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 821 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
806 "acpi_battery_get_alarm() failed\n")); 822 "acpi_battery_get_alarm() failed"));
807 goto end; 823 goto end;
808 } 824 }
809 825
@@ -813,20 +829,19 @@ static int acpi_battery_init(struct acpi_battery *battery)
813 829
814static int acpi_ac_get_present(struct acpi_sbs *sbs) 830static int acpi_ac_get_present(struct acpi_sbs *sbs)
815{ 831{
816 struct acpi_ec_smbus *smbus = sbs->smbus;
817 int result = 0; 832 int result = 0;
818 s16 charger_status; 833 s16 charger_status;
819 834
820 result = acpi_sbs_smbus_read_word(smbus, ACPI_SBC_SMBUS_ADDR, 0x13, 835 result = acpi_sbs_read_word(sbs, ACPI_SBC_SMBUS_ADDR, 0x13,
821 &charger_status, NULL); 836 &charger_status);
822 837
823 if (result) { 838 if (result) {
824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 839 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
825 "acpi_sbs_smbus_read_word() failed\n")); 840 "acpi_sbs_read_word() failed"));
826 goto end; 841 goto end;
827 } 842 }
828 843
829 sbs->ac_present = (charger_status & 0x8000) >> 15; 844 sbs->ac.ac_present = (charger_status & 0x8000) >> 15;
830 845
831 end: 846 end:
832 847
@@ -852,8 +867,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
852 if (!*dir) { 867 if (!*dir) {
853 *dir = proc_mkdir(dir_name, parent_dir); 868 *dir = proc_mkdir(dir_name, parent_dir);
854 if (!*dir) { 869 if (!*dir) {
855 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 870 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
856 "proc_mkdir() failed\n")); 871 "proc_mkdir() failed"));
857 return -ENODEV; 872 return -ENODEV;
858 } 873 }
859 (*dir)->owner = THIS_MODULE; 874 (*dir)->owner = THIS_MODULE;
@@ -863,8 +878,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
863 if (info_fops) { 878 if (info_fops) {
864 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir); 879 entry = create_proc_entry(ACPI_SBS_FILE_INFO, S_IRUGO, *dir);
865 if (!entry) { 880 if (!entry) {
866 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 881 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
867 "create_proc_entry() failed\n")); 882 "create_proc_entry() failed"));
868 } else { 883 } else {
869 entry->proc_fops = info_fops; 884 entry->proc_fops = info_fops;
870 entry->data = data; 885 entry->data = data;
@@ -876,8 +891,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
876 if (state_fops) { 891 if (state_fops) {
877 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir); 892 entry = create_proc_entry(ACPI_SBS_FILE_STATE, S_IRUGO, *dir);
878 if (!entry) { 893 if (!entry) {
879 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 894 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
880 "create_proc_entry() failed\n")); 895 "create_proc_entry() failed"));
881 } else { 896 } else {
882 entry->proc_fops = state_fops; 897 entry->proc_fops = state_fops;
883 entry->data = data; 898 entry->data = data;
@@ -889,8 +904,8 @@ acpi_sbs_generic_add_fs(struct proc_dir_entry **dir,
889 if (alarm_fops) { 904 if (alarm_fops) {
890 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir); 905 entry = create_proc_entry(ACPI_SBS_FILE_ALARM, S_IRUGO, *dir);
891 if (!entry) { 906 if (!entry) {
892 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 907 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
893 "create_proc_entry() failed\n")); 908 "create_proc_entry() failed"));
894 } else { 909 } else {
895 entry->proc_fops = alarm_fops; 910 entry->proc_fops = alarm_fops;
896 entry->data = data; 911 entry->data = data;
@@ -923,24 +938,27 @@ static struct proc_dir_entry *acpi_battery_dir = NULL;
923static int acpi_battery_read_info(struct seq_file *seq, void *offset) 938static int acpi_battery_read_info(struct seq_file *seq, void *offset)
924{ 939{
925 struct acpi_battery *battery = seq->private; 940 struct acpi_battery *battery = seq->private;
941 struct acpi_sbs *sbs = battery->sbs;
926 int cscale; 942 int cscale;
927 int result = 0; 943 int result = 0;
928 944
929 if (battery->sbs->zombie) { 945 if (sbs_mutex_lock(sbs)) {
930 return -ENODEV; 946 return -ENODEV;
931 } 947 }
932 948
933 down(&sbs_sem); 949 result = acpi_check_update_proc(sbs);
950 if (result)
951 goto end;
934 952
935 if (update_mode == REQUEST_UPDATE_MODE) { 953 if (update_time == 0) {
936 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO); 954 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_INFO);
937 if (result) { 955 if (result) {
938 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 956 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
939 "acpi_sbs_update_run() failed\n")); 957 "acpi_sbs_update_run() failed"));
940 } 958 }
941 } 959 }
942 960
943 if (acpi_battery_is_present(battery)) { 961 if (battery->battery_present) {
944 seq_printf(seq, "present: yes\n"); 962 seq_printf(seq, "present: yes\n");
945 } else { 963 } else {
946 seq_printf(seq, "present: no\n"); 964 seq_printf(seq, "present: no\n");
@@ -952,13 +970,13 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
952 } else { 970 } else {
953 cscale = battery->info.ipscale; 971 cscale = battery->info.ipscale;
954 } 972 }
955 seq_printf(seq, "design capacity: %i%s", 973 seq_printf(seq, "design capacity: %i%s\n",
956 battery->info.design_capacity * cscale, 974 battery->info.design_capacity * cscale,
957 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 975 battery->info.capacity_mode ? "0 mWh" : " mAh");
958 976
959 seq_printf(seq, "last full capacity: %i%s", 977 seq_printf(seq, "last full capacity: %i%s\n",
960 battery->info.full_charge_capacity * cscale, 978 battery->info.full_charge_capacity * cscale,
961 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 979 battery->info.capacity_mode ? "0 mWh" : " mAh");
962 980
963 seq_printf(seq, "battery technology: rechargeable\n"); 981 seq_printf(seq, "battery technology: rechargeable\n");
964 982
@@ -984,7 +1002,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
984 1002
985 end: 1003 end:
986 1004
987 up(&sbs_sem); 1005 sbs_mutex_unlock(sbs);
988 1006
989 return result; 1007 return result;
990} 1008}
@@ -996,26 +1014,29 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
996 1014
997static int acpi_battery_read_state(struct seq_file *seq, void *offset) 1015static int acpi_battery_read_state(struct seq_file *seq, void *offset)
998{ 1016{
999 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1017 struct acpi_battery *battery = seq->private;
1018 struct acpi_sbs *sbs = battery->sbs;
1000 int result = 0; 1019 int result = 0;
1001 int cscale; 1020 int cscale;
1002 int foo; 1021 int foo;
1003 1022
1004 if (battery->sbs->zombie) { 1023 if (sbs_mutex_lock(sbs)) {
1005 return -ENODEV; 1024 return -ENODEV;
1006 } 1025 }
1007 1026
1008 down(&sbs_sem); 1027 result = acpi_check_update_proc(sbs);
1028 if (result)
1029 goto end;
1009 1030
1010 if (update_mode == REQUEST_UPDATE_MODE) { 1031 if (update_time == 0) {
1011 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE); 1032 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_STATE);
1012 if (result) { 1033 if (result) {
1013 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1034 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1014 "acpi_sbs_update_run() failed\n")); 1035 "acpi_sbs_update_run() failed"));
1015 } 1036 }
1016 } 1037 }
1017 1038
1018 if (acpi_battery_is_present(battery)) { 1039 if (battery->battery_present) {
1019 seq_printf(seq, "present: yes\n"); 1040 seq_printf(seq, "present: yes\n");
1020 } else { 1041 } else {
1021 seq_printf(seq, "present: no\n"); 1042 seq_printf(seq, "present: no\n");
@@ -1028,7 +1049,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1028 cscale = battery->info.ipscale; 1049 cscale = battery->info.ipscale;
1029 } 1050 }
1030 1051
1031 if (battery->state.battery_status & 0x0010) { 1052 if (battery->state.battery_state & 0x0010) {
1032 seq_printf(seq, "capacity state: critical\n"); 1053 seq_printf(seq, "capacity state: critical\n");
1033 } else { 1054 } else {
1034 seq_printf(seq, "capacity state: ok\n"); 1055 seq_printf(seq, "capacity state: ok\n");
@@ -1052,16 +1073,16 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1052 battery->info.capacity_mode ? "mW" : "mA"); 1073 battery->info.capacity_mode ? "mW" : "mA");
1053 } 1074 }
1054 1075
1055 seq_printf(seq, "remaining capacity: %i%s", 1076 seq_printf(seq, "remaining capacity: %i%s\n",
1056 battery->state.remaining_capacity * cscale, 1077 battery->state.remaining_capacity * cscale,
1057 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 1078 battery->info.capacity_mode ? "0 mWh" : " mAh");
1058 1079
1059 seq_printf(seq, "present voltage: %i mV\n", 1080 seq_printf(seq, "present voltage: %i mV\n",
1060 battery->state.voltage * battery->info.vscale); 1081 battery->state.voltage * battery->info.vscale);
1061 1082
1062 end: 1083 end:
1063 1084
1064 up(&sbs_sem); 1085 sbs_mutex_unlock(sbs);
1065 1086
1066 return result; 1087 return result;
1067} 1088}
@@ -1074,24 +1095,27 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1074static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 1095static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1075{ 1096{
1076 struct acpi_battery *battery = seq->private; 1097 struct acpi_battery *battery = seq->private;
1098 struct acpi_sbs *sbs = battery->sbs;
1077 int result = 0; 1099 int result = 0;
1078 int cscale; 1100 int cscale;
1079 1101
1080 if (battery->sbs->zombie) { 1102 if (sbs_mutex_lock(sbs)) {
1081 return -ENODEV; 1103 return -ENODEV;
1082 } 1104 }
1083 1105
1084 down(&sbs_sem); 1106 result = acpi_check_update_proc(sbs);
1107 if (result)
1108 goto end;
1085 1109
1086 if (update_mode == REQUEST_UPDATE_MODE) { 1110 if (update_time == 0) {
1087 result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM); 1111 result = acpi_sbs_update_run(sbs, battery->id, DATA_TYPE_ALARM);
1088 if (result) { 1112 if (result) {
1089 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1113 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1090 "acpi_sbs_update_run() failed\n")); 1114 "acpi_sbs_update_run() failed"));
1091 } 1115 }
1092 } 1116 }
1093 1117
1094 if (!acpi_battery_is_present(battery)) { 1118 if (!battery->battery_present) {
1095 seq_printf(seq, "present: no\n"); 1119 seq_printf(seq, "present: no\n");
1096 goto end; 1120 goto end;
1097 } 1121 }
@@ -1104,16 +1128,16 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1104 1128
1105 seq_printf(seq, "alarm: "); 1129 seq_printf(seq, "alarm: ");
1106 if (battery->alarm.remaining_capacity) { 1130 if (battery->alarm.remaining_capacity) {
1107 seq_printf(seq, "%i%s", 1131 seq_printf(seq, "%i%s\n",
1108 battery->alarm.remaining_capacity * cscale, 1132 battery->alarm.remaining_capacity * cscale,
1109 battery->info.capacity_mode ? "0 mWh\n" : " mAh\n"); 1133 battery->info.capacity_mode ? "0 mWh" : " mAh");
1110 } else { 1134 } else {
1111 seq_printf(seq, "disabled\n"); 1135 seq_printf(seq, "disabled\n");
1112 } 1136 }
1113 1137
1114 end: 1138 end:
1115 1139
1116 up(&sbs_sem); 1140 sbs_mutex_unlock(sbs);
1117 1141
1118 return result; 1142 return result;
1119} 1143}
@@ -1124,16 +1148,19 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1124{ 1148{
1125 struct seq_file *seq = file->private_data; 1149 struct seq_file *seq = file->private_data;
1126 struct acpi_battery *battery = seq->private; 1150 struct acpi_battery *battery = seq->private;
1151 struct acpi_sbs *sbs = battery->sbs;
1127 char alarm_string[12] = { '\0' }; 1152 char alarm_string[12] = { '\0' };
1128 int result, old_alarm, new_alarm; 1153 int result, old_alarm, new_alarm;
1129 1154
1130 if (battery->sbs->zombie) { 1155 if (sbs_mutex_lock(sbs)) {
1131 return -ENODEV; 1156 return -ENODEV;
1132 } 1157 }
1133 1158
1134 down(&sbs_sem); 1159 result = acpi_check_update_proc(sbs);
1160 if (result)
1161 goto end;
1135 1162
1136 if (!acpi_battery_is_present(battery)) { 1163 if (!battery->battery_present) {
1137 result = -ENODEV; 1164 result = -ENODEV;
1138 goto end; 1165 goto end;
1139 } 1166 }
@@ -1155,21 +1182,21 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1155 1182
1156 result = acpi_battery_set_alarm(battery, new_alarm); 1183 result = acpi_battery_set_alarm(battery, new_alarm);
1157 if (result) { 1184 if (result) {
1158 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1185 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1159 "acpi_battery_set_alarm() failed\n")); 1186 "acpi_battery_set_alarm() failed"));
1160 acpi_battery_set_alarm(battery, old_alarm); 1187 acpi_battery_set_alarm(battery, old_alarm);
1161 goto end; 1188 goto end;
1162 } 1189 }
1163 result = acpi_battery_get_alarm(battery); 1190 result = acpi_battery_get_alarm(battery);
1164 if (result) { 1191 if (result) {
1165 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1192 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1166 "acpi_battery_get_alarm() failed\n")); 1193 "acpi_battery_get_alarm() failed"));
1167 acpi_battery_set_alarm(battery, old_alarm); 1194 acpi_battery_set_alarm(battery, old_alarm);
1168 goto end; 1195 goto end;
1169 } 1196 }
1170 1197
1171 end: 1198 end:
1172 up(&sbs_sem); 1199 sbs_mutex_unlock(sbs);
1173 1200
1174 if (result) { 1201 if (result) {
1175 return result; 1202 return result;
@@ -1217,24 +1244,22 @@ static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1217 struct acpi_sbs *sbs = seq->private; 1244 struct acpi_sbs *sbs = seq->private;
1218 int result; 1245 int result;
1219 1246
1220 if (sbs->zombie) { 1247 if (sbs_mutex_lock(sbs)) {
1221 return -ENODEV; 1248 return -ENODEV;
1222 } 1249 }
1223 1250
1224 down(&sbs_sem); 1251 if (update_time == 0) {
1225 1252 result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_AC_STATE);
1226 if (update_mode == REQUEST_UPDATE_MODE) {
1227 result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
1228 if (result) { 1253 if (result) {
1229 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1254 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1230 "acpi_sbs_update_run() failed\n")); 1255 "acpi_sbs_update_run() failed"));
1231 } 1256 }
1232 } 1257 }
1233 1258
1234 seq_printf(seq, "state: %s\n", 1259 seq_printf(seq, "state: %s\n",
1235 sbs->ac_present ? "on-line" : "off-line"); 1260 sbs->ac.ac_present ? "on-line" : "off-line");
1236 1261
1237 up(&sbs_sem); 1262 sbs_mutex_unlock(sbs);
1238 1263
1239 return 0; 1264 return 0;
1240} 1265}
@@ -1275,25 +1300,25 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1275 1300
1276 result = acpi_battery_select(battery); 1301 result = acpi_battery_select(battery);
1277 if (result) { 1302 if (result) {
1278 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1303 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1279 "acpi_battery_select() failed\n")); 1304 "acpi_battery_select() failed"));
1280 goto end; 1305 goto end;
1281 } 1306 }
1282 1307
1283 result = acpi_battery_get_present(battery); 1308 result = acpi_battery_get_present(battery);
1284 if (result) { 1309 if (result) {
1285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1310 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1286 "acpi_battery_get_present() failed\n")); 1311 "acpi_battery_get_present() failed"));
1287 goto end; 1312 goto end;
1288 } 1313 }
1289 1314
1290 is_present = acpi_battery_is_present(battery); 1315 is_present = battery->battery_present;
1291 1316
1292 if (is_present) { 1317 if (is_present) {
1293 result = acpi_battery_init(battery); 1318 result = acpi_battery_init(battery);
1294 if (result) { 1319 if (result) {
1295 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1320 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1296 "acpi_battery_init() failed\n")); 1321 "acpi_battery_init() failed"));
1297 goto end; 1322 goto end;
1298 } 1323 }
1299 battery->init_state = 1; 1324 battery->init_state = 1;
@@ -1308,12 +1333,16 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1308 &acpi_battery_state_fops, 1333 &acpi_battery_state_fops,
1309 &acpi_battery_alarm_fops, battery); 1334 &acpi_battery_alarm_fops, battery);
1310 if (result) { 1335 if (result) {
1311 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1336 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1312 "acpi_sbs_generic_add_fs() failed\n")); 1337 "acpi_sbs_generic_add_fs() failed"));
1313 goto end; 1338 goto end;
1314 } 1339 }
1315 battery->alive = 1; 1340 battery->alive = 1;
1316 1341
1342 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
1343 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), dir_name,
1344 sbs->battery->battery_present ? "present" : "absent");
1345
1317 end: 1346 end:
1318 return result; 1347 return result;
1319} 1348}
@@ -1333,8 +1362,8 @@ static int acpi_ac_add(struct acpi_sbs *sbs)
1333 1362
1334 result = acpi_ac_get_present(sbs); 1363 result = acpi_ac_get_present(sbs);
1335 if (result) { 1364 if (result) {
1336 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1365 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1337 "acpi_ac_get_present() failed\n")); 1366 "acpi_ac_get_present() failed"));
1338 goto end; 1367 goto end;
1339 } 1368 }
1340 1369
@@ -1343,11 +1372,15 @@ static int acpi_ac_add(struct acpi_sbs *sbs)
1343 ACPI_AC_DIR_NAME, 1372 ACPI_AC_DIR_NAME,
1344 NULL, &acpi_ac_state_fops, NULL, sbs); 1373 NULL, &acpi_ac_state_fops, NULL, sbs);
1345 if (result) { 1374 if (result) {
1346 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1375 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1347 "acpi_sbs_generic_add_fs() failed\n")); 1376 "acpi_sbs_generic_add_fs() failed"));
1348 goto end; 1377 goto end;
1349 } 1378 }
1350 1379
1380 printk(KERN_INFO PREFIX "%s [%s]: AC Adapter [%s] (%s)\n",
1381 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
1382 ACPI_AC_DIR_NAME, sbs->ac.ac_present ? "on-line" : "off-line");
1383
1351 end: 1384 end:
1352 1385
1353 return result; 1386 return result;
@@ -1361,45 +1394,85 @@ static void acpi_ac_remove(struct acpi_sbs *sbs)
1361 } 1394 }
1362} 1395}
1363 1396
1364static void acpi_sbs_update_queue_run(unsigned long data) 1397static void acpi_sbs_update_time_run(unsigned long data)
1365{ 1398{
1366 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_queue, (void *)data); 1399 acpi_os_execute(OSL_GPE_HANDLER, acpi_sbs_update_time, (void *)data);
1367} 1400}
1368 1401
1369static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type) 1402static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type)
1370{ 1403{
1371 struct acpi_battery *battery; 1404 struct acpi_battery *battery;
1372 int result = 0; 1405 int result = 0, cnt;
1373 int old_ac_present; 1406 int old_ac_present = -1;
1374 int old_battery_present; 1407 int old_battery_present = -1;
1375 int new_ac_present; 1408 int new_ac_present = -1;
1376 int new_battery_present; 1409 int new_battery_present = -1;
1377 int id; 1410 int id_min = 0, id_max = MAX_SBS_BAT - 1;
1378 char dir_name[32]; 1411 char dir_name[32];
1379 int do_battery_init, do_ac_init; 1412 int do_battery_init = 0, do_ac_init = 0;
1380 s16 old_remaining_capacity; 1413 int old_remaining_capacity = 0;
1414 int update_ac = 1, update_battery = 1;
1415 int up_tm = update_time;
1381 1416
1382 if (sbs->zombie) { 1417 if (sbs_zombie(sbs)) {
1383 goto end; 1418 goto end;
1384 } 1419 }
1385 1420
1386 old_ac_present = acpi_ac_is_present(sbs); 1421 if (id >= 0) {
1422 id_min = id_max = id;
1423 }
1424
1425 if (data_type == DATA_TYPE_COMMON && up_tm > 0) {
1426 cnt = up_tm / (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm);
1427 if (sbs->run_cnt % cnt != 0) {
1428 update_battery = 0;
1429 }
1430 }
1431
1432 sbs->run_cnt++;
1433
1434 if (!update_ac && !update_battery) {
1435 goto end;
1436 }
1437
1438 old_ac_present = sbs->ac.ac_present;
1387 1439
1388 result = acpi_ac_get_present(sbs); 1440 result = acpi_ac_get_present(sbs);
1389 if (result) { 1441 if (result) {
1390 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1442 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1391 "acpi_ac_get_present() failed\n")); 1443 "acpi_ac_get_present() failed"));
1392 } 1444 }
1393 1445
1394 new_ac_present = acpi_ac_is_present(sbs); 1446 new_ac_present = sbs->ac.ac_present;
1395 1447
1396 do_ac_init = (old_ac_present != new_ac_present); 1448 do_ac_init = (old_ac_present != new_ac_present);
1449 if (sbs->run_cnt == 1 && data_type == DATA_TYPE_COMMON) {
1450 do_ac_init = 1;
1451 }
1397 1452
1398 if (data_type == DATA_TYPE_AC_STATE) { 1453 if (do_ac_init) {
1454 result = acpi_sbs_generate_event(sbs->device,
1455 ACPI_SBS_AC_NOTIFY_STATUS,
1456 new_ac_present,
1457 ACPI_AC_DIR_NAME,
1458 ACPI_AC_CLASS);
1459 if (result) {
1460 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1461 "acpi_sbs_generate_event() failed"));
1462 }
1463 }
1464
1465 if (data_type == DATA_TYPE_COMMON) {
1466 if (!do_ac_init && !update_battery) {
1467 goto end;
1468 }
1469 }
1470
1471 if (data_type == DATA_TYPE_AC_STATE && !do_ac_init) {
1399 goto end; 1472 goto end;
1400 } 1473 }
1401 1474
1402 for (id = 0; id < MAX_SBS_BAT; id++) { 1475 for (id = id_min; id <= id_max; id++) {
1403 battery = &sbs->battery[id]; 1476 battery = &sbs->battery[id];
1404 if (battery->alive == 0) { 1477 if (battery->alive == 0) {
1405 continue; 1478 continue;
@@ -1407,94 +1480,92 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1407 1480
1408 old_remaining_capacity = battery->state.remaining_capacity; 1481 old_remaining_capacity = battery->state.remaining_capacity;
1409 1482
1410 old_battery_present = acpi_battery_is_present(battery); 1483 old_battery_present = battery->battery_present;
1411 1484
1412 result = acpi_battery_select(battery); 1485 result = acpi_battery_select(battery);
1413 if (result) { 1486 if (result) {
1414 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1487 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1415 "acpi_battery_select() failed\n")); 1488 "acpi_battery_select() failed"));
1416 }
1417 if (sbs->zombie) {
1418 goto end;
1419 } 1489 }
1420 1490
1421 result = acpi_battery_get_present(battery); 1491 result = acpi_battery_get_present(battery);
1422 if (result) { 1492 if (result) {
1423 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1493 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1424 "acpi_battery_get_present() failed\n")); 1494 "acpi_battery_get_present() failed"));
1425 }
1426 if (sbs->zombie) {
1427 goto end;
1428 } 1495 }
1429 1496
1430 new_battery_present = acpi_battery_is_present(battery); 1497 new_battery_present = battery->battery_present;
1431 1498
1432 do_battery_init = ((old_battery_present != new_battery_present) 1499 do_battery_init = ((old_battery_present != new_battery_present)
1433 && new_battery_present); 1500 && new_battery_present);
1434 1501 if (!new_battery_present)
1435 if (sbs->zombie) { 1502 goto event;
1503 if (do_ac_init || do_battery_init) {
1504 result = acpi_battery_init(battery);
1505 if (result) {
1506 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1507 "acpi_battery_init() "
1508 "failed"));
1509 }
1510 }
1511 if (sbs_zombie(sbs)) {
1436 goto end; 1512 goto end;
1437 } 1513 }
1438 if (do_ac_init || do_battery_init || 1514
1439 update_info_mode || sbs->update_info_mode) { 1515 if ((data_type == DATA_TYPE_COMMON
1440 if (sbs->update_info_mode) { 1516 || data_type == DATA_TYPE_INFO)
1441 sbs->update_info_mode = 0; 1517 && new_battery_present) {
1442 } else { 1518 result = acpi_battery_get_info(battery);
1443 sbs->update_info_mode = 1;
1444 }
1445 result = acpi_battery_init(battery);
1446 if (result) { 1519 if (result) {
1447 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1520 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1448 "acpi_battery_init() " 1521 "acpi_battery_get_info() failed"));
1449 "failed\n"));
1450 } 1522 }
1451 } 1523 }
1452 if (data_type == DATA_TYPE_INFO) { 1524 if (data_type == DATA_TYPE_INFO) {
1453 continue; 1525 continue;
1454 } 1526 }
1455 1527 if (sbs_zombie(sbs)) {
1456 if (sbs->zombie) {
1457 goto end; 1528 goto end;
1458 } 1529 }
1459 if (new_battery_present) {
1460 result = acpi_battery_get_alarm(battery);
1461 if (result) {
1462 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1463 "acpi_battery_get_alarm() "
1464 "failed\n"));
1465 }
1466 if (data_type == DATA_TYPE_ALARM) {
1467 continue;
1468 }
1469 1530
1531 if ((data_type == DATA_TYPE_COMMON
1532 || data_type == DATA_TYPE_STATE)
1533 && new_battery_present) {
1470 result = acpi_battery_get_state(battery); 1534 result = acpi_battery_get_state(battery);
1471 if (result) { 1535 if (result) {
1472 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1536 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1473 "acpi_battery_get_state() " 1537 "acpi_battery_get_state() failed"));
1474 "failed\n"));
1475 } 1538 }
1476 } 1539 }
1477 if (sbs->zombie) { 1540 if (data_type == DATA_TYPE_STATE) {
1478 goto end; 1541 goto event;
1479 } 1542 }
1480 if (data_type != DATA_TYPE_COMMON) { 1543 if (sbs_zombie(sbs)) {
1481 continue; 1544 goto end;
1482 } 1545 }
1483 1546
1484 if (old_battery_present != new_battery_present) { 1547 if ((data_type == DATA_TYPE_COMMON
1485 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1548 || data_type == DATA_TYPE_ALARM)
1486 result = acpi_sbs_generate_event(sbs->device, 1549 && new_battery_present) {
1487 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1550 result = acpi_battery_get_alarm(battery);
1488 new_battery_present,
1489 dir_name,
1490 ACPI_BATTERY_CLASS);
1491 if (result) { 1551 if (result) {
1492 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1552 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1493 "acpi_sbs_generate_event() " 1553 "acpi_battery_get_alarm() "
1494 "failed\n")); 1554 "failed"));
1495 } 1555 }
1496 } 1556 }
1497 if (old_remaining_capacity != battery->state.remaining_capacity) { 1557 if (data_type == DATA_TYPE_ALARM) {
1558 continue;
1559 }
1560 if (sbs_zombie(sbs)) {
1561 goto end;
1562 }
1563
1564 event:
1565
1566 if (old_battery_present != new_battery_present || do_ac_init ||
1567 old_remaining_capacity !=
1568 battery->state.remaining_capacity) {
1498 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1569 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1499 result = acpi_sbs_generate_event(sbs->device, 1570 result = acpi_sbs_generate_event(sbs->device,
1500 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1571 ACPI_SBS_BATTERY_NOTIFY_STATUS,
@@ -1502,138 +1573,120 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1502 dir_name, 1573 dir_name,
1503 ACPI_BATTERY_CLASS); 1574 ACPI_BATTERY_CLASS);
1504 if (result) { 1575 if (result) {
1505 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1576 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1506 "acpi_sbs_generate_event() failed\n")); 1577 "acpi_sbs_generate_event() "
1578 "failed"));
1507 } 1579 }
1508 } 1580 }
1509
1510 }
1511 if (sbs->zombie) {
1512 goto end;
1513 }
1514 if (data_type != DATA_TYPE_COMMON) {
1515 goto end;
1516 }
1517
1518 if (old_ac_present != new_ac_present) {
1519 result = acpi_sbs_generate_event(sbs->device,
1520 ACPI_SBS_AC_NOTIFY_STATUS,
1521 new_ac_present,
1522 ACPI_AC_DIR_NAME,
1523 ACPI_AC_CLASS);
1524 if (result) {
1525 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1526 "acpi_sbs_generate_event() failed\n"));
1527 }
1528 } 1581 }
1529 1582
1530 end: 1583 end:
1584
1531 return result; 1585 return result;
1532} 1586}
1533 1587
1534static void acpi_sbs_update_queue(void *data) 1588static void acpi_sbs_update_time(void *data)
1535{ 1589{
1536 struct acpi_sbs *sbs = data; 1590 struct acpi_sbs *sbs = data;
1537 unsigned long delay = -1; 1591 unsigned long delay = -1;
1538 int result; 1592 int result;
1593 unsigned int up_tm = update_time;
1539 1594
1540 if (sbs->zombie) { 1595 if (sbs_mutex_lock(sbs))
1541 goto end; 1596 return;
1542 }
1543 1597
1544 result = acpi_sbs_update_run(sbs, DATA_TYPE_COMMON); 1598 result = acpi_sbs_update_run(sbs, -1, DATA_TYPE_COMMON);
1545 if (result) { 1599 if (result) {
1546 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1600 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1547 "acpi_sbs_update_run() failed\n")); 1601 "acpi_sbs_update_run() failed"));
1548 } 1602 }
1549 1603
1550 if (sbs->zombie) { 1604 if (sbs_zombie(sbs)) {
1551 goto end; 1605 goto end;
1552 } 1606 }
1553 1607
1554 if (update_mode == REQUEST_UPDATE_MODE) { 1608 if (!up_tm) {
1555 goto end; 1609 if (timer_pending(&sbs->update_timer))
1610 del_timer(&sbs->update_timer);
1611 } else {
1612 delay = (up_tm > UPDATE_DELAY ? UPDATE_DELAY : up_tm);
1613 delay = jiffies + HZ * delay;
1614 if (timer_pending(&sbs->update_timer)) {
1615 mod_timer(&sbs->update_timer, delay);
1616 } else {
1617 sbs->update_timer.data = (unsigned long)data;
1618 sbs->update_timer.function = acpi_sbs_update_time_run;
1619 sbs->update_timer.expires = delay;
1620 add_timer(&sbs->update_timer);
1621 }
1556 } 1622 }
1557 1623
1558 delay = jiffies + HZ * update_time;
1559 sbs->update_timer.data = (unsigned long)data;
1560 sbs->update_timer.function = acpi_sbs_update_queue_run;
1561 sbs->update_timer.expires = delay;
1562 add_timer(&sbs->update_timer);
1563 end: 1624 end:
1564 ; 1625
1626 sbs_mutex_unlock(sbs);
1565} 1627}
1566 1628
1567static int acpi_sbs_add(struct acpi_device *device) 1629static int acpi_sbs_add(struct acpi_device *device)
1568{ 1630{
1569 struct acpi_sbs *sbs = NULL; 1631 struct acpi_sbs *sbs = NULL;
1570 struct acpi_ec_hc *ec_hc = NULL; 1632 int result = 0, remove_result = 0;
1571 int result, remove_result = 0;
1572 unsigned long sbs_obj; 1633 unsigned long sbs_obj;
1573 int id, cnt; 1634 int id;
1574 acpi_status status = AE_OK; 1635 acpi_status status = AE_OK;
1636 unsigned long val;
1637
1638 status =
1639 acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val);
1640 if (ACPI_FAILURE(status)) {
1641 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC"));
1642 return -EIO;
1643 }
1575 1644
1576 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); 1645 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1577 if (!sbs) { 1646 if (!sbs) {
1578 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); 1647 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "kzalloc() failed"));
1579 return -ENOMEM; 1648 result = -ENOMEM;
1649 goto end;
1580 } 1650 }
1581 1651
1582 cnt = 0; 1652 mutex_init(&sbs->mutex);
1583 while (cnt < 10) {
1584 cnt++;
1585 ec_hc = acpi_get_ec_hc(device);
1586 if (ec_hc) {
1587 break;
1588 }
1589 msleep(1000);
1590 }
1591 1653
1592 if (!ec_hc) { 1654 sbs_mutex_lock(sbs);
1593 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1594 "acpi_get_ec_hc() failed: "
1595 "NO driver found for EC HC SMBus\n"));
1596 result = -ENODEV;
1597 goto end;
1598 }
1599 1655
1656 sbs->base = (val & 0xff00ull) >> 8;
1600 sbs->device = device; 1657 sbs->device = device;
1601 sbs->smbus = ec_hc->smbus;
1602 1658
1603 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); 1659 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
1604 strcpy(acpi_device_class(device), ACPI_SBS_CLASS); 1660 strcpy(acpi_device_class(device), ACPI_SBS_CLASS);
1605 acpi_driver_data(device) = sbs; 1661 acpi_driver_data(device) = sbs;
1606 1662
1607 sbs->update_time = 0;
1608 sbs->update_time2 = 0;
1609
1610 result = acpi_ac_add(sbs); 1663 result = acpi_ac_add(sbs);
1611 if (result) { 1664 if (result) {
1612 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_ac_add() failed\n")); 1665 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed"));
1613 goto end; 1666 goto end;
1614 } 1667 }
1615 result = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj); 1668 status = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1616 if (ACPI_FAILURE(result)) { 1669 if (status) {
1617 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1670 ACPI_EXCEPTION((AE_INFO, status,
1618 "acpi_evaluate_integer() failed\n")); 1671 "acpi_evaluate_integer() failed"));
1619 result = -EIO; 1672 result = -EIO;
1620 goto end; 1673 goto end;
1621 } 1674 }
1622
1623 if (sbs_obj > 0) { 1675 if (sbs_obj > 0) {
1624 result = acpi_sbsm_get_info(sbs); 1676 result = acpi_sbsm_get_info(sbs);
1625 if (result) { 1677 if (result) {
1626 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1678 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1627 "acpi_sbsm_get_info() failed\n")); 1679 "acpi_sbsm_get_info() failed"));
1628 goto end; 1680 goto end;
1629 } 1681 }
1630 sbs->sbsm_present = 1; 1682 sbs->sbsm_present = 1;
1631 } 1683 }
1684
1632 if (sbs->sbsm_present == 0) { 1685 if (sbs->sbsm_present == 0) {
1633 result = acpi_battery_add(sbs, 0); 1686 result = acpi_battery_add(sbs, 0);
1634 if (result) { 1687 if (result) {
1635 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1688 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1636 "acpi_battery_add() failed\n")); 1689 "acpi_battery_add() failed"));
1637 goto end; 1690 goto end;
1638 } 1691 }
1639 } else { 1692 } else {
@@ -1641,9 +1694,8 @@ static int acpi_sbs_add(struct acpi_device *device)
1641 if ((sbs->sbsm_batteries_supported & (1 << id))) { 1694 if ((sbs->sbsm_batteries_supported & (1 << id))) {
1642 result = acpi_battery_add(sbs, id); 1695 result = acpi_battery_add(sbs, id);
1643 if (result) { 1696 if (result) {
1644 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1697 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1645 "acpi_battery_add() " 1698 "acpi_battery_add() failed"));
1646 "failed\n"));
1647 goto end; 1699 goto end;
1648 } 1700 }
1649 } 1701 }
@@ -1653,33 +1705,26 @@ static int acpi_sbs_add(struct acpi_device *device)
1653 sbs->handle = device->handle; 1705 sbs->handle = device->handle;
1654 1706
1655 init_timer(&sbs->update_timer); 1707 init_timer(&sbs->update_timer);
1656 if (update_mode == QUEUE_UPDATE_MODE) { 1708 result = acpi_check_update_proc(sbs);
1657 status = acpi_os_execute(OSL_GPE_HANDLER, 1709 if (result)
1658 acpi_sbs_update_queue, sbs); 1710 goto end;
1659 if (status != AE_OK) {
1660 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1661 "acpi_os_execute() failed\n"));
1662 }
1663 }
1664 sbs->update_time = update_time;
1665 sbs->update_time2 = update_time2;
1666
1667 printk(KERN_INFO PREFIX "%s [%s]\n",
1668 acpi_device_name(device), acpi_device_bid(device));
1669 1711
1670 end: 1712 end:
1713
1714 sbs_mutex_unlock(sbs);
1715
1671 if (result) { 1716 if (result) {
1672 remove_result = acpi_sbs_remove(device, 0); 1717 remove_result = acpi_sbs_remove(device, 0);
1673 if (remove_result) { 1718 if (remove_result) {
1674 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1719 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1675 "acpi_sbs_remove() failed\n")); 1720 "acpi_sbs_remove() failed"));
1676 } 1721 }
1677 } 1722 }
1678 1723
1679 return result; 1724 return result;
1680} 1725}
1681 1726
1682int acpi_sbs_remove(struct acpi_device *device, int type) 1727static int acpi_sbs_remove(struct acpi_device *device, int type)
1683{ 1728{
1684 struct acpi_sbs *sbs; 1729 struct acpi_sbs *sbs;
1685 int id; 1730 int id;
@@ -1688,15 +1733,14 @@ int acpi_sbs_remove(struct acpi_device *device, int type)
1688 return -EINVAL; 1733 return -EINVAL;
1689 } 1734 }
1690 1735
1691 sbs = (struct acpi_sbs *)acpi_driver_data(device); 1736 sbs = acpi_driver_data(device);
1692
1693 if (!sbs) { 1737 if (!sbs) {
1694 return -EINVAL; 1738 return -EINVAL;
1695 } 1739 }
1696 1740
1741 sbs_mutex_lock(sbs);
1742
1697 sbs->zombie = 1; 1743 sbs->zombie = 1;
1698 sbs->update_time = 0;
1699 sbs->update_time2 = 0;
1700 del_timer_sync(&sbs->update_timer); 1744 del_timer_sync(&sbs->update_timer);
1701 acpi_os_wait_events_complete(NULL); 1745 acpi_os_wait_events_complete(NULL);
1702 del_timer_sync(&sbs->update_timer); 1746 del_timer_sync(&sbs->update_timer);
@@ -1707,11 +1751,41 @@ int acpi_sbs_remove(struct acpi_device *device, int type)
1707 1751
1708 acpi_ac_remove(sbs); 1752 acpi_ac_remove(sbs);
1709 1753
1754 sbs_mutex_unlock(sbs);
1755
1756 mutex_destroy(&sbs->mutex);
1757
1710 kfree(sbs); 1758 kfree(sbs);
1711 1759
1712 return 0; 1760 return 0;
1713} 1761}
1714 1762
1763static void acpi_sbs_rmdirs(void)
1764{
1765 if (acpi_ac_dir) {
1766 acpi_unlock_ac_dir(acpi_ac_dir);
1767 acpi_ac_dir = NULL;
1768 }
1769 if (acpi_battery_dir) {
1770 acpi_unlock_battery_dir(acpi_battery_dir);
1771 acpi_battery_dir = NULL;
1772 }
1773}
1774
1775static int acpi_sbs_resume(struct acpi_device *device)
1776{
1777 struct acpi_sbs *sbs;
1778
1779 if (!device)
1780 return -EINVAL;
1781
1782 sbs = device->driver_data;
1783
1784 sbs->run_cnt = 0;
1785
1786 return 0;
1787}
1788
1715static int __init acpi_sbs_init(void) 1789static int __init acpi_sbs_init(void)
1716{ 1790{
1717 int result = 0; 1791 int result = 0;
@@ -1719,35 +1793,34 @@ static int __init acpi_sbs_init(void)
1719 if (acpi_disabled) 1793 if (acpi_disabled)
1720 return -ENODEV; 1794 return -ENODEV;
1721 1795
1722 init_MUTEX(&sbs_sem);
1723
1724 if (capacity_mode != DEF_CAPACITY_UNIT 1796 if (capacity_mode != DEF_CAPACITY_UNIT
1725 && capacity_mode != MAH_CAPACITY_UNIT 1797 && capacity_mode != MAH_CAPACITY_UNIT
1726 && capacity_mode != MWH_CAPACITY_UNIT) { 1798 && capacity_mode != MWH_CAPACITY_UNIT) {
1727 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "acpi_sbs_init: " 1799 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1728 "invalid capacity_mode = %d\n", 1800 "invalid capacity_mode = %d", capacity_mode));
1729 capacity_mode));
1730 return -EINVAL; 1801 return -EINVAL;
1731 } 1802 }
1732 1803
1733 acpi_ac_dir = acpi_lock_ac_dir(); 1804 acpi_ac_dir = acpi_lock_ac_dir();
1734 if (!acpi_ac_dir) { 1805 if (!acpi_ac_dir) {
1735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1806 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1736 "acpi_lock_ac_dir() failed\n")); 1807 "acpi_lock_ac_dir() failed"));
1737 return -ENODEV; 1808 return -ENODEV;
1738 } 1809 }
1739 1810
1740 acpi_battery_dir = acpi_lock_battery_dir(); 1811 acpi_battery_dir = acpi_lock_battery_dir();
1741 if (!acpi_battery_dir) { 1812 if (!acpi_battery_dir) {
1742 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1813 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1743 "acpi_lock_battery_dir() failed\n")); 1814 "acpi_lock_battery_dir() failed"));
1815 acpi_sbs_rmdirs();
1744 return -ENODEV; 1816 return -ENODEV;
1745 } 1817 }
1746 1818
1747 result = acpi_bus_register_driver(&acpi_sbs_driver); 1819 result = acpi_bus_register_driver(&acpi_sbs_driver);
1748 if (result < 0) { 1820 if (result < 0) {
1749 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1821 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1750 "acpi_bus_register_driver() failed\n")); 1822 "acpi_bus_register_driver() failed"));
1823 acpi_sbs_rmdirs();
1751 return -ENODEV; 1824 return -ENODEV;
1752 } 1825 }
1753 1826
@@ -1756,13 +1829,9 @@ static int __init acpi_sbs_init(void)
1756 1829
1757static void __exit acpi_sbs_exit(void) 1830static void __exit acpi_sbs_exit(void)
1758{ 1831{
1759
1760 acpi_bus_unregister_driver(&acpi_sbs_driver); 1832 acpi_bus_unregister_driver(&acpi_sbs_driver);
1761 1833
1762 acpi_unlock_ac_dir(acpi_ac_dir); 1834 acpi_sbs_rmdirs();
1763 acpi_ac_dir = NULL;
1764 acpi_unlock_battery_dir(acpi_battery_dir);
1765 acpi_battery_dir = NULL;
1766 1835
1767 return; 1836 return;
1768} 1837}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index bb0e0da39fb1..d80dd84e5bfd 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1068,7 +1068,9 @@ acpi_add_single_object(struct acpi_device **child,
1068 } 1068 }
1069 break; 1069 break;
1070 default: 1070 default:
1071 STRUCT_TO_INT(device->status) = 0x0F; 1071 STRUCT_TO_INT(device->status) =
1072 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
1073 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
1072 break; 1074 break;
1073 } 1075 }
1074 1076
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index ccc11b33d89c..2d912b71e543 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -350,21 +350,31 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
350{ 350{
351 struct list_head *node, *next; 351 struct list_head *node, *next;
352 352
353 seq_printf(seq, "Device Sleep state Status\n"); 353 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
354 354
355 spin_lock(&acpi_device_lock); 355 spin_lock(&acpi_device_lock);
356 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 356 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
357 struct acpi_device *dev = 357 struct acpi_device *dev =
358 container_of(node, struct acpi_device, wakeup_list); 358 container_of(node, struct acpi_device, wakeup_list);
359 struct device *ldev;
359 360
360 if (!dev->wakeup.flags.valid) 361 if (!dev->wakeup.flags.valid)
361 continue; 362 continue;
362 spin_unlock(&acpi_device_lock); 363 spin_unlock(&acpi_device_lock);
363 seq_printf(seq, "%4s %4d %s%8s\n", 364
365 ldev = acpi_get_physical_device(dev->handle);
366 seq_printf(seq, "%s\t S%d\t%c%-8s ",
364 dev->pnp.bus_id, 367 dev->pnp.bus_id,
365 (u32) dev->wakeup.sleep_state, 368 (u32) dev->wakeup.sleep_state,
366 dev->wakeup.flags.run_wake ? "*" : "", 369 dev->wakeup.flags.run_wake ? '*' : ' ',
367 dev->wakeup.state.enabled ? "enabled" : "disabled"); 370 dev->wakeup.state.enabled ? "enabled" : "disabled");
371 if (ldev)
372 seq_printf(seq, "%s:%s",
373 ldev->bus ? ldev->bus->name : "no-bus",
374 ldev->bus_id);
375 seq_printf(seq, "\n");
376 put_device(ldev);
377
368 spin_lock(&acpi_device_lock); 378 spin_lock(&acpi_device_lock);
369 } 379 }
370 spin_unlock(&acpi_device_lock); 380 spin_unlock(&acpi_device_lock);
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index 807c7116e94b..1db833eb2417 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -347,6 +347,18 @@ static void acpi_tb_convert_fadt(void)
347 acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id; 347 acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id;
348 348
349 } 349 }
350
351 /*
352 * For ACPI 1.0 FADTs, ensure that reserved fields (which should be zero)
353 * are indeed zero. This will workaround BIOSs that inadvertently placed
354 * values in these fields.
355 */
356 if (acpi_gbl_FADT.header.revision < 3) {
357 acpi_gbl_FADT.preferred_profile = 0;
358 acpi_gbl_FADT.pstate_control = 0;
359 acpi_gbl_FADT.cst_control = 0;
360 acpi_gbl_FADT.boot_flags = 0;
361 }
350} 362}
351 363
352/****************************************************************************** 364/******************************************************************************
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 7bdbe5a914d0..365c306c7cf8 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -156,11 +156,6 @@ config SATA_INIC162X
156 help 156 help
157 This option enables support for Initio 162x Serial ATA. 157 This option enables support for Initio 162x Serial ATA.
158 158
159config SATA_INTEL_COMBINED
160 bool
161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX)
162 default y
163
164config SATA_ACPI 159config SATA_ACPI
165 bool 160 bool
166 depends on ACPI && PCI 161 depends on ACPI && PCI
@@ -184,7 +179,7 @@ config PATA_ALI
184 If unsure, say N. 179 If unsure, say N.
185 180
186config PATA_AMD 181config PATA_AMD
187 tristate "AMD/NVidia PATA support (Experimental)" 182 tristate "AMD/NVidia PATA support"
188 depends on PCI 183 depends on PCI
189 help 184 help
190 This option enables support for the AMD and NVidia PATA 185 This option enables support for the AMD and NVidia PATA
@@ -209,6 +204,16 @@ config PATA_ATIIXP
209 204
210 If unsure, say N. 205 If unsure, say N.
211 206
207config PATA_CMD640_PCI
208 tristate "CMD640 PCI PATA support (Very Experimental)"
209 depends on PCI && EXPERIMENTAL
210 help
211 This option enables support for the CMD640 PCI IDE
212 interface chip. Only the primary channel is currently
213 supported.
214
215 If unsure, say N.
216
212config PATA_CMD64X 217config PATA_CMD64X
213 tristate "CMD64x PATA support (Very Experimental)" 218 tristate "CMD64x PATA support (Very Experimental)"
214 depends on PCI&& EXPERIMENTAL 219 depends on PCI&& EXPERIMENTAL
@@ -273,7 +278,7 @@ config ATA_GENERIC
273 If unsure, say N. 278 If unsure, say N.
274 279
275config PATA_HPT366 280config PATA_HPT366
276 tristate "HPT 366/368 PATA support (Very Experimental)" 281 tristate "HPT 366/368 PATA support (Experimental)"
277 depends on PCI && EXPERIMENTAL 282 depends on PCI && EXPERIMENTAL
278 help 283 help
279 This option enables support for the HPT 366 and 368 284 This option enables support for the HPT 366 and 368
@@ -282,7 +287,7 @@ config PATA_HPT366
282 If unsure, say N. 287 If unsure, say N.
283 288
284config PATA_HPT37X 289config PATA_HPT37X
285 tristate "HPT 370/370A/371/372/374/302 PATA support (Very Experimental)" 290 tristate "HPT 370/370A/371/372/374/302 PATA support (Experimental)"
286 depends on PCI && EXPERIMENTAL 291 depends on PCI && EXPERIMENTAL
287 help 292 help
288 This option enables support for the majority of the later HPT 293 This option enables support for the majority of the later HPT
@@ -309,7 +314,7 @@ config PATA_HPT3X3
309 If unsure, say N. 314 If unsure, say N.
310 315
311config PATA_ISAPNP 316config PATA_ISAPNP
312 tristate "ISA Plug and Play PATA support (Very Experimental)" 317 tristate "ISA Plug and Play PATA support (Experimental)"
313 depends on EXPERIMENTAL && ISAPNP 318 depends on EXPERIMENTAL && ISAPNP
314 help 319 help
315 This option enables support for ISA plug & play ATA 320 This option enables support for ISA plug & play ATA
@@ -318,8 +323,8 @@ config PATA_ISAPNP
318 If unsure, say N. 323 If unsure, say N.
319 324
320config PATA_IT821X 325config PATA_IT821X
321 tristate "IT8211/2 PATA support (Experimental)" 326 tristate "IT8211/2 PATA support"
322 depends on PCI && EXPERIMENTAL 327 depends on PCI
323 help 328 help
324 This option enables support for the ITE 8211 and 8212 329 This option enables support for the ITE 8211 and 8212
325 PATA controllers via the new ATA layer, including RAID 330 PATA controllers via the new ATA layer, including RAID
@@ -390,10 +395,10 @@ config PATA_MPIIX
390 If unsure, say N. 395 If unsure, say N.
391 396
392config PATA_OLDPIIX 397config PATA_OLDPIIX
393 tristate "Intel PATA old PIIX support (Experimental)" 398 tristate "Intel PATA old PIIX support"
394 depends on PCI && EXPERIMENTAL 399 depends on PCI
395 help 400 help
396 This option enables support for old(?) PIIX PATA support. 401 This option enables support for early PIIX PATA support.
397 402
398 If unsure, say N. 403 If unsure, say N.
399 404
@@ -444,7 +449,7 @@ config PATA_PCMCIA
444 If unsure, say N. 449 If unsure, say N.
445 450
446config PATA_PDC_OLD 451config PATA_PDC_OLD
447 tristate "Older Promise PATA controller support (Very Experimental)" 452 tristate "Older Promise PATA controller support (Experimental)"
448 depends on PCI && EXPERIMENTAL 453 depends on PCI && EXPERIMENTAL
449 help 454 help
450 This option enables support for the Promise 20246, 20262, 20263, 455 This option enables support for the Promise 20246, 20262, 20263,
@@ -459,7 +464,7 @@ config PATA_QDI
459 Support for QDI 6500 and 6580 PATA controllers on VESA local bus. 464 Support for QDI 6500 and 6580 PATA controllers on VESA local bus.
460 465
461config PATA_RADISYS 466config PATA_RADISYS
462 tristate "RADISYS 82600 PATA support (Very experimental)" 467 tristate "RADISYS 82600 PATA support (Very Experimental)"
463 depends on PCI && EXPERIMENTAL 468 depends on PCI && EXPERIMENTAL
464 help 469 help
465 This option enables support for the RADISYS 82600 470 This option enables support for the RADISYS 82600
@@ -477,7 +482,7 @@ config PATA_RZ1000
477 If unsure, say N. 482 If unsure, say N.
478 483
479config PATA_SC1200 484config PATA_SC1200
480 tristate "SC1200 PATA support (Raving Lunatic)" 485 tristate "SC1200 PATA support (Very Experimental)"
481 depends on PCI && EXPERIMENTAL 486 depends on PCI && EXPERIMENTAL
482 help 487 help
483 This option enables support for the NatSemi/AMD SC1200 SoC 488 This option enables support for the NatSemi/AMD SC1200 SoC
@@ -486,8 +491,8 @@ config PATA_SC1200
486 If unsure, say N. 491 If unsure, say N.
487 492
488config PATA_SERVERWORKS 493config PATA_SERVERWORKS
489 tristate "SERVERWORKS OSB4/CSB5/CSB6/HT1000 PATA support (Experimental)" 494 tristate "SERVERWORKS OSB4/CSB5/CSB6/HT1000 PATA support"
490 depends on PCI && EXPERIMENTAL 495 depends on PCI
491 help 496 help
492 This option enables support for the Serverworks OSB4/CSB5/CSB6 and 497 This option enables support for the Serverworks OSB4/CSB5/CSB6 and
493 HT1000 PATA controllers, via the new ATA layer. 498 HT1000 PATA controllers, via the new ATA layer.
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 13d7397e0008..b7055e302650 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_PATA_ALI) += pata_ali.o
22obj-$(CONFIG_PATA_AMD) += pata_amd.o 22obj-$(CONFIG_PATA_AMD) += pata_amd.o
23obj-$(CONFIG_PATA_ARTOP) += pata_artop.o 23obj-$(CONFIG_PATA_ARTOP) += pata_artop.o
24obj-$(CONFIG_PATA_ATIIXP) += pata_atiixp.o 24obj-$(CONFIG_PATA_ATIIXP) += pata_atiixp.o
25obj-$(CONFIG_PATA_CMD640_PCI) += pata_cmd640.o
25obj-$(CONFIG_PATA_CMD64X) += pata_cmd64x.o 26obj-$(CONFIG_PATA_CMD64X) += pata_cmd64x.o
26obj-$(CONFIG_PATA_CS5520) += pata_cs5520.o 27obj-$(CONFIG_PATA_CS5520) += pata_cs5520.o
27obj-$(CONFIG_PATA_CS5530) += pata_cs5530.o 28obj-$(CONFIG_PATA_CS5530) += pata_cs5530.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index fd27227771b4..34c5534ed64c 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -170,6 +170,10 @@ enum {
170 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */ 170 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */
171 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */ 171 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */
172 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */ 172 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */
173
174 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
175 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
176 ATA_FLAG_SKIP_D2H_BSY,
173}; 177};
174 178
175struct ahci_cmd_hdr { 179struct ahci_cmd_hdr {
@@ -188,8 +192,10 @@ struct ahci_sg {
188}; 192};
189 193
190struct ahci_host_priv { 194struct ahci_host_priv {
191 u32 cap; /* cache of HOST_CAP register */ 195 u32 cap; /* cap to use */
192 u32 port_map; /* cache of HOST_PORTS_IMPL reg */ 196 u32 port_map; /* port map to use */
197 u32 saved_cap; /* saved initial cap */
198 u32 saved_port_map; /* saved initial port_map */
193}; 199};
194 200
195struct ahci_port_priv { 201struct ahci_port_priv {
@@ -209,7 +215,6 @@ static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
209static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 215static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
210static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 216static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
211static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); 217static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
212static irqreturn_t ahci_interrupt (int irq, void *dev_instance);
213static void ahci_irq_clear(struct ata_port *ap); 218static void ahci_irq_clear(struct ata_port *ap);
214static int ahci_port_start(struct ata_port *ap); 219static int ahci_port_start(struct ata_port *ap);
215static void ahci_port_stop(struct ata_port *ap); 220static void ahci_port_stop(struct ata_port *ap);
@@ -263,7 +268,6 @@ static const struct ata_port_operations ahci_ops = {
263 .qc_prep = ahci_qc_prep, 268 .qc_prep = ahci_qc_prep,
264 .qc_issue = ahci_qc_issue, 269 .qc_issue = ahci_qc_issue,
265 270
266 .irq_handler = ahci_interrupt,
267 .irq_clear = ahci_irq_clear, 271 .irq_clear = ahci_irq_clear,
268 .irq_on = ata_dummy_irq_on, 272 .irq_on = ata_dummy_irq_on,
269 .irq_ack = ata_dummy_irq_ack, 273 .irq_ack = ata_dummy_irq_ack,
@@ -298,7 +302,6 @@ static const struct ata_port_operations ahci_vt8251_ops = {
298 .qc_prep = ahci_qc_prep, 302 .qc_prep = ahci_qc_prep,
299 .qc_issue = ahci_qc_issue, 303 .qc_issue = ahci_qc_issue,
300 304
301 .irq_handler = ahci_interrupt,
302 .irq_clear = ahci_irq_clear, 305 .irq_clear = ahci_irq_clear,
303 .irq_on = ata_dummy_irq_on, 306 .irq_on = ata_dummy_irq_on,
304 .irq_ack = ata_dummy_irq_ack, 307 .irq_ack = ata_dummy_irq_ack,
@@ -324,58 +327,41 @@ static const struct ata_port_operations ahci_vt8251_ops = {
324static const struct ata_port_info ahci_port_info[] = { 327static const struct ata_port_info ahci_port_info[] = {
325 /* board_ahci */ 328 /* board_ahci */
326 { 329 {
327 .sht = &ahci_sht, 330 .flags = AHCI_FLAG_COMMON,
328 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
329 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
330 ATA_FLAG_SKIP_D2H_BSY,
331 .pio_mask = 0x1f, /* pio0-4 */ 331 .pio_mask = 0x1f, /* pio0-4 */
332 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 332 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
333 .port_ops = &ahci_ops, 333 .port_ops = &ahci_ops,
334 }, 334 },
335 /* board_ahci_pi */ 335 /* board_ahci_pi */
336 { 336 {
337 .sht = &ahci_sht, 337 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_HONOR_PI,
338 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
339 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
340 ATA_FLAG_SKIP_D2H_BSY | AHCI_FLAG_HONOR_PI,
341 .pio_mask = 0x1f, /* pio0-4 */ 338 .pio_mask = 0x1f, /* pio0-4 */
342 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 339 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
343 .port_ops = &ahci_ops, 340 .port_ops = &ahci_ops,
344 }, 341 },
345 /* board_ahci_vt8251 */ 342 /* board_ahci_vt8251 */
346 { 343 {
347 .sht = &ahci_sht, 344 .flags = AHCI_FLAG_COMMON | ATA_FLAG_HRST_TO_RESUME |
348 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 345 AHCI_FLAG_NO_NCQ,
349 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
350 ATA_FLAG_SKIP_D2H_BSY |
351 ATA_FLAG_HRST_TO_RESUME | AHCI_FLAG_NO_NCQ,
352 .pio_mask = 0x1f, /* pio0-4 */ 346 .pio_mask = 0x1f, /* pio0-4 */
353 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 347 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
354 .port_ops = &ahci_vt8251_ops, 348 .port_ops = &ahci_vt8251_ops,
355 }, 349 },
356 /* board_ahci_ign_iferr */ 350 /* board_ahci_ign_iferr */
357 { 351 {
358 .sht = &ahci_sht, 352 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_IGN_IRQ_IF_ERR,
359 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
360 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
361 ATA_FLAG_SKIP_D2H_BSY |
362 AHCI_FLAG_IGN_IRQ_IF_ERR,
363 .pio_mask = 0x1f, /* pio0-4 */ 353 .pio_mask = 0x1f, /* pio0-4 */
364 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 354 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
365 .port_ops = &ahci_ops, 355 .port_ops = &ahci_ops,
366 }, 356 },
367 /* board_ahci_sb600 */ 357 /* board_ahci_sb600 */
368 { 358 {
369 .sht = &ahci_sht, 359 .flags = AHCI_FLAG_COMMON |
370 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
371 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
372 ATA_FLAG_SKIP_D2H_BSY |
373 AHCI_FLAG_IGN_SERR_INTERNAL, 360 AHCI_FLAG_IGN_SERR_INTERNAL,
374 .pio_mask = 0x1f, /* pio0-4 */ 361 .pio_mask = 0x1f, /* pio0-4 */
375 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 362 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
376 .port_ops = &ahci_ops, 363 .port_ops = &ahci_ops,
377 }, 364 },
378
379}; 365};
380 366
381static const struct pci_device_id ahci_pci_tbl[] = { 367static const struct pci_device_id ahci_pci_tbl[] = {
@@ -413,11 +399,11 @@ static const struct pci_device_id ahci_pci_tbl[] = {
413 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr }, 399 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },
414 400
415 /* ATI */ 401 /* ATI */
416 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 non-raid */ 402 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
417 { PCI_VDEVICE(ATI, 0x4381), board_ahci }, /* ATI SB600 raid */
418 403
419 /* VIA */ 404 /* VIA */
420 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ 405 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */
406 { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */
421 407
422 /* NVIDIA */ 408 /* NVIDIA */
423 { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci }, /* MCP65 */ 409 { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci }, /* MCP65 */
@@ -471,10 +457,100 @@ static inline int ahci_nr_ports(u32 cap)
471 return (cap & 0x1f) + 1; 457 return (cap & 0x1f) + 1;
472} 458}
473 459
474static inline void __iomem *ahci_port_base(void __iomem *base, 460static inline void __iomem *ahci_port_base(struct ata_port *ap)
475 unsigned int port) 461{
462 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
463
464 return mmio + 0x100 + (ap->port_no * 0x80);
465}
466
467/**
468 * ahci_save_initial_config - Save and fixup initial config values
469 * @pdev: target PCI device
470 * @pi: associated ATA port info
471 * @hpriv: host private area to store config values
472 *
473 * Some registers containing configuration info might be setup by
474 * BIOS and might be cleared on reset. This function saves the
475 * initial values of those registers into @hpriv such that they
476 * can be restored after controller reset.
477 *
478 * If inconsistent, config values are fixed up by this function.
479 *
480 * LOCKING:
481 * None.
482 */
483static void ahci_save_initial_config(struct pci_dev *pdev,
484 const struct ata_port_info *pi,
485 struct ahci_host_priv *hpriv)
476{ 486{
477 return base + 0x100 + (port * 0x80); 487 void __iomem *mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
488 u32 cap, port_map;
489 int i;
490
491 /* Values prefixed with saved_ are written back to host after
492 * reset. Values without are used for driver operation.
493 */
494 hpriv->saved_cap = cap = readl(mmio + HOST_CAP);
495 hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL);
496
497 /* fixup zero port_map */
498 if (!port_map) {
499 port_map = (1 << ahci_nr_ports(hpriv->cap)) - 1;
500 dev_printk(KERN_WARNING, &pdev->dev,
501 "PORTS_IMPL is zero, forcing 0x%x\n", port_map);
502
503 /* write the fixed up value to the PI register */
504 hpriv->saved_port_map = port_map;
505 }
506
507 /* cross check port_map and cap.n_ports */
508 if (pi->flags & AHCI_FLAG_HONOR_PI) {
509 u32 tmp_port_map = port_map;
510 int n_ports = ahci_nr_ports(cap);
511
512 for (i = 0; i < AHCI_MAX_PORTS && n_ports; i++) {
513 if (tmp_port_map & (1 << i)) {
514 n_ports--;
515 tmp_port_map &= ~(1 << i);
516 }
517 }
518
519 /* Whine if inconsistent. No need to update cap.
520 * port_map is used to determine number of ports.
521 */
522 if (n_ports || tmp_port_map)
523 dev_printk(KERN_WARNING, &pdev->dev,
524 "nr_ports (%u) and implemented port map "
525 "(0x%x) don't match\n",
526 ahci_nr_ports(cap), port_map);
527 } else {
528 /* fabricate port_map from cap.nr_ports */
529 port_map = (1 << ahci_nr_ports(cap)) - 1;
530 }
531
532 /* record values to use during operation */
533 hpriv->cap = cap;
534 hpriv->port_map = port_map;
535}
536
537/**
538 * ahci_restore_initial_config - Restore initial config
539 * @host: target ATA host
540 *
541 * Restore initial config stored by ahci_save_initial_config().
542 *
543 * LOCKING:
544 * None.
545 */
546static void ahci_restore_initial_config(struct ata_host *host)
547{
548 struct ahci_host_priv *hpriv = host->private_data;
549 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
550
551 writel(hpriv->saved_cap, mmio + HOST_CAP);
552 writel(hpriv->saved_port_map, mmio + HOST_PORTS_IMPL);
553 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */
478} 554}
479 555
480static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 556static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
@@ -511,8 +587,9 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
511 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 587 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
512} 588}
513 589
514static void ahci_start_engine(void __iomem *port_mmio) 590static void ahci_start_engine(struct ata_port *ap)
515{ 591{
592 void __iomem *port_mmio = ahci_port_base(ap);
516 u32 tmp; 593 u32 tmp;
517 594
518 /* start DMA */ 595 /* start DMA */
@@ -522,8 +599,9 @@ static void ahci_start_engine(void __iomem *port_mmio)
522 readl(port_mmio + PORT_CMD); /* flush */ 599 readl(port_mmio + PORT_CMD); /* flush */
523} 600}
524 601
525static int ahci_stop_engine(void __iomem *port_mmio) 602static int ahci_stop_engine(struct ata_port *ap)
526{ 603{
604 void __iomem *port_mmio = ahci_port_base(ap);
527 u32 tmp; 605 u32 tmp;
528 606
529 tmp = readl(port_mmio + PORT_CMD); 607 tmp = readl(port_mmio + PORT_CMD);
@@ -545,19 +623,23 @@ static int ahci_stop_engine(void __iomem *port_mmio)
545 return 0; 623 return 0;
546} 624}
547 625
548static void ahci_start_fis_rx(void __iomem *port_mmio, u32 cap, 626static void ahci_start_fis_rx(struct ata_port *ap)
549 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma)
550{ 627{
628 void __iomem *port_mmio = ahci_port_base(ap);
629 struct ahci_host_priv *hpriv = ap->host->private_data;
630 struct ahci_port_priv *pp = ap->private_data;
551 u32 tmp; 631 u32 tmp;
552 632
553 /* set FIS registers */ 633 /* set FIS registers */
554 if (cap & HOST_CAP_64) 634 if (hpriv->cap & HOST_CAP_64)
555 writel((cmd_slot_dma >> 16) >> 16, port_mmio + PORT_LST_ADDR_HI); 635 writel((pp->cmd_slot_dma >> 16) >> 16,
556 writel(cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR); 636 port_mmio + PORT_LST_ADDR_HI);
637 writel(pp->cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR);
557 638
558 if (cap & HOST_CAP_64) 639 if (hpriv->cap & HOST_CAP_64)
559 writel((rx_fis_dma >> 16) >> 16, port_mmio + PORT_FIS_ADDR_HI); 640 writel((pp->rx_fis_dma >> 16) >> 16,
560 writel(rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR); 641 port_mmio + PORT_FIS_ADDR_HI);
642 writel(pp->rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
561 643
562 /* enable FIS reception */ 644 /* enable FIS reception */
563 tmp = readl(port_mmio + PORT_CMD); 645 tmp = readl(port_mmio + PORT_CMD);
@@ -568,8 +650,9 @@ static void ahci_start_fis_rx(void __iomem *port_mmio, u32 cap,
568 readl(port_mmio + PORT_CMD); 650 readl(port_mmio + PORT_CMD);
569} 651}
570 652
571static int ahci_stop_fis_rx(void __iomem *port_mmio) 653static int ahci_stop_fis_rx(struct ata_port *ap)
572{ 654{
655 void __iomem *port_mmio = ahci_port_base(ap);
573 u32 tmp; 656 u32 tmp;
574 657
575 /* disable FIS reception */ 658 /* disable FIS reception */
@@ -586,14 +669,16 @@ static int ahci_stop_fis_rx(void __iomem *port_mmio)
586 return 0; 669 return 0;
587} 670}
588 671
589static void ahci_power_up(void __iomem *port_mmio, u32 cap) 672static void ahci_power_up(struct ata_port *ap)
590{ 673{
674 struct ahci_host_priv *hpriv = ap->host->private_data;
675 void __iomem *port_mmio = ahci_port_base(ap);
591 u32 cmd; 676 u32 cmd;
592 677
593 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK; 678 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
594 679
595 /* spin up device */ 680 /* spin up device */
596 if (cap & HOST_CAP_SSS) { 681 if (hpriv->cap & HOST_CAP_SSS) {
597 cmd |= PORT_CMD_SPIN_UP; 682 cmd |= PORT_CMD_SPIN_UP;
598 writel(cmd, port_mmio + PORT_CMD); 683 writel(cmd, port_mmio + PORT_CMD);
599 } 684 }
@@ -603,11 +688,13 @@ static void ahci_power_up(void __iomem *port_mmio, u32 cap)
603} 688}
604 689
605#ifdef CONFIG_PM 690#ifdef CONFIG_PM
606static void ahci_power_down(void __iomem *port_mmio, u32 cap) 691static void ahci_power_down(struct ata_port *ap)
607{ 692{
693 struct ahci_host_priv *hpriv = ap->host->private_data;
694 void __iomem *port_mmio = ahci_port_base(ap);
608 u32 cmd, scontrol; 695 u32 cmd, scontrol;
609 696
610 if (!(cap & HOST_CAP_SSS)) 697 if (!(hpriv->cap & HOST_CAP_SSS))
611 return; 698 return;
612 699
613 /* put device into listen mode, first set PxSCTL.DET to 0 */ 700 /* put device into listen mode, first set PxSCTL.DET to 0 */
@@ -622,29 +709,28 @@ static void ahci_power_down(void __iomem *port_mmio, u32 cap)
622} 709}
623#endif 710#endif
624 711
625static void ahci_init_port(void __iomem *port_mmio, u32 cap, 712static void ahci_init_port(struct ata_port *ap)
626 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma)
627{ 713{
628 /* enable FIS reception */ 714 /* enable FIS reception */
629 ahci_start_fis_rx(port_mmio, cap, cmd_slot_dma, rx_fis_dma); 715 ahci_start_fis_rx(ap);
630 716
631 /* enable DMA */ 717 /* enable DMA */
632 ahci_start_engine(port_mmio); 718 ahci_start_engine(ap);
633} 719}
634 720
635static int ahci_deinit_port(void __iomem *port_mmio, u32 cap, const char **emsg) 721static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
636{ 722{
637 int rc; 723 int rc;
638 724
639 /* disable DMA */ 725 /* disable DMA */
640 rc = ahci_stop_engine(port_mmio); 726 rc = ahci_stop_engine(ap);
641 if (rc) { 727 if (rc) {
642 *emsg = "failed to stop engine"; 728 *emsg = "failed to stop engine";
643 return rc; 729 return rc;
644 } 730 }
645 731
646 /* disable FIS reception */ 732 /* disable FIS reception */
647 rc = ahci_stop_fis_rx(port_mmio); 733 rc = ahci_stop_fis_rx(ap);
648 if (rc) { 734 if (rc) {
649 *emsg = "failed stop FIS RX"; 735 *emsg = "failed stop FIS RX";
650 return rc; 736 return rc;
@@ -653,12 +739,11 @@ static int ahci_deinit_port(void __iomem *port_mmio, u32 cap, const char **emsg)
653 return 0; 739 return 0;
654} 740}
655 741
656static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev) 742static int ahci_reset_controller(struct ata_host *host)
657{ 743{
658 u32 cap_save, impl_save, tmp; 744 struct pci_dev *pdev = to_pci_dev(host->dev);
659 745 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
660 cap_save = readl(mmio + HOST_CAP); 746 u32 tmp;
661 impl_save = readl(mmio + HOST_PORTS_IMPL);
662 747
663 /* global controller reset */ 748 /* global controller reset */
664 tmp = readl(mmio + HOST_CTL); 749 tmp = readl(mmio + HOST_CTL);
@@ -674,7 +759,7 @@ static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
674 759
675 tmp = readl(mmio + HOST_CTL); 760 tmp = readl(mmio + HOST_CTL);
676 if (tmp & HOST_RESET) { 761 if (tmp & HOST_RESET) {
677 dev_printk(KERN_ERR, &pdev->dev, 762 dev_printk(KERN_ERR, host->dev,
678 "controller reset failed (0x%x)\n", tmp); 763 "controller reset failed (0x%x)\n", tmp);
679 return -EIO; 764 return -EIO;
680 } 765 }
@@ -683,18 +768,8 @@ static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
683 writel(HOST_AHCI_EN, mmio + HOST_CTL); 768 writel(HOST_AHCI_EN, mmio + HOST_CTL);
684 (void) readl(mmio + HOST_CTL); /* flush */ 769 (void) readl(mmio + HOST_CTL); /* flush */
685 770
686 /* These write-once registers are normally cleared on reset. 771 /* some registers might be cleared on reset. restore initial values */
687 * Restore BIOS values... which we HOPE were present before 772 ahci_restore_initial_config(host);
688 * reset.
689 */
690 if (!impl_save) {
691 impl_save = (1 << ahci_nr_ports(cap_save)) - 1;
692 dev_printk(KERN_WARNING, &pdev->dev,
693 "PORTS_IMPL is zero, forcing 0x%x\n", impl_save);
694 }
695 writel(cap_save, mmio + HOST_CAP);
696 writel(impl_save, mmio + HOST_PORTS_IMPL);
697 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */
698 773
699 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 774 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
700 u16 tmp16; 775 u16 tmp16;
@@ -708,23 +783,23 @@ static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
708 return 0; 783 return 0;
709} 784}
710 785
711static void ahci_init_controller(void __iomem *mmio, struct pci_dev *pdev, 786static void ahci_init_controller(struct ata_host *host)
712 int n_ports, unsigned int port_flags,
713 struct ahci_host_priv *hpriv)
714{ 787{
788 struct pci_dev *pdev = to_pci_dev(host->dev);
789 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
715 int i, rc; 790 int i, rc;
716 u32 tmp; 791 u32 tmp;
717 792
718 for (i = 0; i < n_ports; i++) { 793 for (i = 0; i < host->n_ports; i++) {
719 void __iomem *port_mmio = ahci_port_base(mmio, i); 794 struct ata_port *ap = host->ports[i];
795 void __iomem *port_mmio = ahci_port_base(ap);
720 const char *emsg = NULL; 796 const char *emsg = NULL;
721 797
722 if ((port_flags & AHCI_FLAG_HONOR_PI) && 798 if (ata_port_is_dummy(ap))
723 !(hpriv->port_map & (1 << i)))
724 continue; 799 continue;
725 800
726 /* make sure port is not active */ 801 /* make sure port is not active */
727 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg); 802 rc = ahci_deinit_port(ap, &emsg);
728 if (rc) 803 if (rc)
729 dev_printk(KERN_WARNING, &pdev->dev, 804 dev_printk(KERN_WARNING, &pdev->dev,
730 "%s (%d)\n", emsg, rc); 805 "%s (%d)\n", emsg, rc);
@@ -752,7 +827,7 @@ static void ahci_init_controller(void __iomem *mmio, struct pci_dev *pdev,
752 827
753static unsigned int ahci_dev_classify(struct ata_port *ap) 828static unsigned int ahci_dev_classify(struct ata_port *ap)
754{ 829{
755 void __iomem *port_mmio = ap->ioaddr.cmd_addr; 830 void __iomem *port_mmio = ahci_port_base(ap);
756 struct ata_taskfile tf; 831 struct ata_taskfile tf;
757 u32 tmp; 832 u32 tmp;
758 833
@@ -802,8 +877,7 @@ static int ahci_clo(struct ata_port *ap)
802static int ahci_softreset(struct ata_port *ap, unsigned int *class) 877static int ahci_softreset(struct ata_port *ap, unsigned int *class)
803{ 878{
804 struct ahci_port_priv *pp = ap->private_data; 879 struct ahci_port_priv *pp = ap->private_data;
805 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 880 void __iomem *port_mmio = ahci_port_base(ap);
806 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
807 const u32 cmd_fis_len = 5; /* five dwords */ 881 const u32 cmd_fis_len = 5; /* five dwords */
808 const char *reason = NULL; 882 const char *reason = NULL;
809 struct ata_taskfile tf; 883 struct ata_taskfile tf;
@@ -820,7 +894,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
820 } 894 }
821 895
822 /* prepare for SRST (AHCI-1.1 10.4.1) */ 896 /* prepare for SRST (AHCI-1.1 10.4.1) */
823 rc = ahci_stop_engine(port_mmio); 897 rc = ahci_stop_engine(ap);
824 if (rc) { 898 if (rc) {
825 reason = "failed to stop engine"; 899 reason = "failed to stop engine";
826 goto fail_restart; 900 goto fail_restart;
@@ -840,7 +914,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
840 } 914 }
841 915
842 /* restart engine */ 916 /* restart engine */
843 ahci_start_engine(port_mmio); 917 ahci_start_engine(ap);
844 918
845 ata_tf_init(ap->device, &tf); 919 ata_tf_init(ap->device, &tf);
846 fis = pp->cmd_tbl; 920 fis = pp->cmd_tbl;
@@ -899,7 +973,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
899 return 0; 973 return 0;
900 974
901 fail_restart: 975 fail_restart:
902 ahci_start_engine(port_mmio); 976 ahci_start_engine(ap);
903 fail: 977 fail:
904 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason); 978 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason);
905 return rc; 979 return rc;
@@ -910,13 +984,11 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
910 struct ahci_port_priv *pp = ap->private_data; 984 struct ahci_port_priv *pp = ap->private_data;
911 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 985 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
912 struct ata_taskfile tf; 986 struct ata_taskfile tf;
913 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
914 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
915 int rc; 987 int rc;
916 988
917 DPRINTK("ENTER\n"); 989 DPRINTK("ENTER\n");
918 990
919 ahci_stop_engine(port_mmio); 991 ahci_stop_engine(ap);
920 992
921 /* clear D2H reception area to properly wait for D2H FIS */ 993 /* clear D2H reception area to properly wait for D2H FIS */
922 ata_tf_init(ap->device, &tf); 994 ata_tf_init(ap->device, &tf);
@@ -925,7 +997,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
925 997
926 rc = sata_std_hardreset(ap, class); 998 rc = sata_std_hardreset(ap, class);
927 999
928 ahci_start_engine(port_mmio); 1000 ahci_start_engine(ap);
929 1001
930 if (rc == 0 && ata_port_online(ap)) 1002 if (rc == 0 && ata_port_online(ap))
931 *class = ahci_dev_classify(ap); 1003 *class = ahci_dev_classify(ap);
@@ -938,20 +1010,18 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
938 1010
939static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class) 1011static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
940{ 1012{
941 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
942 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
943 int rc; 1013 int rc;
944 1014
945 DPRINTK("ENTER\n"); 1015 DPRINTK("ENTER\n");
946 1016
947 ahci_stop_engine(port_mmio); 1017 ahci_stop_engine(ap);
948 1018
949 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context)); 1019 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context));
950 1020
951 /* vt8251 needs SError cleared for the port to operate */ 1021 /* vt8251 needs SError cleared for the port to operate */
952 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR)); 1022 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR));
953 1023
954 ahci_start_engine(port_mmio); 1024 ahci_start_engine(ap);
955 1025
956 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class); 1026 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
957 1027
@@ -963,7 +1033,7 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
963 1033
964static void ahci_postreset(struct ata_port *ap, unsigned int *class) 1034static void ahci_postreset(struct ata_port *ap, unsigned int *class)
965{ 1035{
966 void __iomem *port_mmio = ap->ioaddr.cmd_addr; 1036 void __iomem *port_mmio = ahci_port_base(ap);
967 u32 new_tmp, tmp; 1037 u32 new_tmp, tmp;
968 1038
969 ata_std_postreset(ap, class); 1039 ata_std_postreset(ap, class);
@@ -1131,8 +1201,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1131 1201
1132static void ahci_host_intr(struct ata_port *ap) 1202static void ahci_host_intr(struct ata_port *ap)
1133{ 1203{
1134 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 1204 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
1135 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1136 struct ata_eh_info *ehi = &ap->eh_info; 1205 struct ata_eh_info *ehi = &ap->eh_info;
1137 struct ahci_port_priv *pp = ap->private_data; 1206 struct ahci_port_priv *pp = ap->private_data;
1138 u32 status, qc_active; 1207 u32 status, qc_active;
@@ -1283,7 +1352,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
1283static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc) 1352static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
1284{ 1353{
1285 struct ata_port *ap = qc->ap; 1354 struct ata_port *ap = qc->ap;
1286 void __iomem *port_mmio = ap->ioaddr.cmd_addr; 1355 void __iomem *port_mmio = ahci_port_base(ap);
1287 1356
1288 if (qc->tf.protocol == ATA_PROT_NCQ) 1357 if (qc->tf.protocol == ATA_PROT_NCQ)
1289 writel(1 << qc->tag, port_mmio + PORT_SCR_ACT); 1358 writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
@@ -1295,8 +1364,7 @@ static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
1295 1364
1296static void ahci_freeze(struct ata_port *ap) 1365static void ahci_freeze(struct ata_port *ap)
1297{ 1366{
1298 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 1367 void __iomem *port_mmio = ahci_port_base(ap);
1299 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1300 1368
1301 /* turn IRQ off */ 1369 /* turn IRQ off */
1302 writel(0, port_mmio + PORT_IRQ_MASK); 1370 writel(0, port_mmio + PORT_IRQ_MASK);
@@ -1305,7 +1373,7 @@ static void ahci_freeze(struct ata_port *ap)
1305static void ahci_thaw(struct ata_port *ap) 1373static void ahci_thaw(struct ata_port *ap)
1306{ 1374{
1307 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 1375 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1308 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1376 void __iomem *port_mmio = ahci_port_base(ap);
1309 u32 tmp; 1377 u32 tmp;
1310 1378
1311 /* clear IRQ */ 1379 /* clear IRQ */
@@ -1319,13 +1387,10 @@ static void ahci_thaw(struct ata_port *ap)
1319 1387
1320static void ahci_error_handler(struct ata_port *ap) 1388static void ahci_error_handler(struct ata_port *ap)
1321{ 1389{
1322 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1323 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1324
1325 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 1390 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
1326 /* restart engine */ 1391 /* restart engine */
1327 ahci_stop_engine(port_mmio); 1392 ahci_stop_engine(ap);
1328 ahci_start_engine(port_mmio); 1393 ahci_start_engine(ap);
1329 } 1394 }
1330 1395
1331 /* perform recovery */ 1396 /* perform recovery */
@@ -1335,13 +1400,10 @@ static void ahci_error_handler(struct ata_port *ap)
1335 1400
1336static void ahci_vt8251_error_handler(struct ata_port *ap) 1401static void ahci_vt8251_error_handler(struct ata_port *ap)
1337{ 1402{
1338 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1339 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1340
1341 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 1403 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
1342 /* restart engine */ 1404 /* restart engine */
1343 ahci_stop_engine(port_mmio); 1405 ahci_stop_engine(ap);
1344 ahci_start_engine(port_mmio); 1406 ahci_start_engine(ap);
1345 } 1407 }
1346 1408
1347 /* perform recovery */ 1409 /* perform recovery */
@@ -1352,36 +1414,26 @@ static void ahci_vt8251_error_handler(struct ata_port *ap)
1352static void ahci_post_internal_cmd(struct ata_queued_cmd *qc) 1414static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
1353{ 1415{
1354 struct ata_port *ap = qc->ap; 1416 struct ata_port *ap = qc->ap;
1355 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1356 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1357 1417
1358 if (qc->flags & ATA_QCFLAG_FAILED) 1418 if (qc->flags & ATA_QCFLAG_FAILED) {
1359 qc->err_mask |= AC_ERR_OTHER;
1360
1361 if (qc->err_mask) {
1362 /* make DMA engine forget about the failed command */ 1419 /* make DMA engine forget about the failed command */
1363 ahci_stop_engine(port_mmio); 1420 ahci_stop_engine(ap);
1364 ahci_start_engine(port_mmio); 1421 ahci_start_engine(ap);
1365 } 1422 }
1366} 1423}
1367 1424
1368#ifdef CONFIG_PM 1425#ifdef CONFIG_PM
1369static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg) 1426static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1370{ 1427{
1371 struct ahci_host_priv *hpriv = ap->host->private_data;
1372 struct ahci_port_priv *pp = ap->private_data;
1373 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1374 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1375 const char *emsg = NULL; 1428 const char *emsg = NULL;
1376 int rc; 1429 int rc;
1377 1430
1378 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg); 1431 rc = ahci_deinit_port(ap, &emsg);
1379 if (rc == 0) 1432 if (rc == 0)
1380 ahci_power_down(port_mmio, hpriv->cap); 1433 ahci_power_down(ap);
1381 else { 1434 else {
1382 ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc); 1435 ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc);
1383 ahci_init_port(port_mmio, hpriv->cap, 1436 ahci_init_port(ap);
1384 pp->cmd_slot_dma, pp->rx_fis_dma);
1385 } 1437 }
1386 1438
1387 return rc; 1439 return rc;
@@ -1389,13 +1441,8 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1389 1441
1390static int ahci_port_resume(struct ata_port *ap) 1442static int ahci_port_resume(struct ata_port *ap)
1391{ 1443{
1392 struct ahci_port_priv *pp = ap->private_data; 1444 ahci_power_up(ap);
1393 struct ahci_host_priv *hpriv = ap->host->private_data; 1445 ahci_init_port(ap);
1394 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1395 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1396
1397 ahci_power_up(port_mmio, hpriv->cap);
1398 ahci_init_port(port_mmio, hpriv->cap, pp->cmd_slot_dma, pp->rx_fis_dma);
1399 1446
1400 return 0; 1447 return 0;
1401} 1448}
@@ -1423,8 +1470,6 @@ static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
1423static int ahci_pci_device_resume(struct pci_dev *pdev) 1470static int ahci_pci_device_resume(struct pci_dev *pdev)
1424{ 1471{
1425 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1472 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1426 struct ahci_host_priv *hpriv = host->private_data;
1427 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
1428 int rc; 1473 int rc;
1429 1474
1430 rc = ata_pci_device_do_resume(pdev); 1475 rc = ata_pci_device_do_resume(pdev);
@@ -1432,12 +1477,11 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
1432 return rc; 1477 return rc;
1433 1478
1434 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { 1479 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
1435 rc = ahci_reset_controller(mmio, pdev); 1480 rc = ahci_reset_controller(host);
1436 if (rc) 1481 if (rc)
1437 return rc; 1482 return rc;
1438 1483
1439 ahci_init_controller(mmio, pdev, host->n_ports, 1484 ahci_init_controller(host);
1440 host->ports[0]->flags, hpriv);
1441 } 1485 }
1442 1486
1443 ata_host_resume(host); 1487 ata_host_resume(host);
@@ -1449,10 +1493,7 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
1449static int ahci_port_start(struct ata_port *ap) 1493static int ahci_port_start(struct ata_port *ap)
1450{ 1494{
1451 struct device *dev = ap->host->dev; 1495 struct device *dev = ap->host->dev;
1452 struct ahci_host_priv *hpriv = ap->host->private_data;
1453 struct ahci_port_priv *pp; 1496 struct ahci_port_priv *pp;
1454 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1455 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1456 void *mem; 1497 void *mem;
1457 dma_addr_t mem_dma; 1498 dma_addr_t mem_dma;
1458 int rc; 1499 int rc;
@@ -1500,85 +1541,29 @@ static int ahci_port_start(struct ata_port *ap)
1500 ap->private_data = pp; 1541 ap->private_data = pp;
1501 1542
1502 /* power up port */ 1543 /* power up port */
1503 ahci_power_up(port_mmio, hpriv->cap); 1544 ahci_power_up(ap);
1504 1545
1505 /* initialize port */ 1546 /* initialize port */
1506 ahci_init_port(port_mmio, hpriv->cap, pp->cmd_slot_dma, pp->rx_fis_dma); 1547 ahci_init_port(ap);
1507 1548
1508 return 0; 1549 return 0;
1509} 1550}
1510 1551
1511static void ahci_port_stop(struct ata_port *ap) 1552static void ahci_port_stop(struct ata_port *ap)
1512{ 1553{
1513 struct ahci_host_priv *hpriv = ap->host->private_data;
1514 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1515 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1516 const char *emsg = NULL; 1554 const char *emsg = NULL;
1517 int rc; 1555 int rc;
1518 1556
1519 /* de-initialize port */ 1557 /* de-initialize port */
1520 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg); 1558 rc = ahci_deinit_port(ap, &emsg);
1521 if (rc) 1559 if (rc)
1522 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc); 1560 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
1523} 1561}
1524 1562
1525static void ahci_setup_port(struct ata_ioports *port, void __iomem *base, 1563static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
1526 unsigned int port_idx)
1527{ 1564{
1528 VPRINTK("ENTER, base==0x%lx, port_idx %u\n", base, port_idx);
1529 base = ahci_port_base(base, port_idx);
1530 VPRINTK("base now==0x%lx\n", base);
1531
1532 port->cmd_addr = base;
1533 port->scr_addr = base + PORT_SCR;
1534
1535 VPRINTK("EXIT\n");
1536}
1537
1538static int ahci_host_init(struct ata_probe_ent *probe_ent)
1539{
1540 struct ahci_host_priv *hpriv = probe_ent->private_data;
1541 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1542 void __iomem *mmio = probe_ent->iomap[AHCI_PCI_BAR];
1543 unsigned int i, cap_n_ports, using_dac;
1544 int rc; 1565 int rc;
1545 1566
1546 rc = ahci_reset_controller(mmio, pdev);
1547 if (rc)
1548 return rc;
1549
1550 hpriv->cap = readl(mmio + HOST_CAP);
1551 hpriv->port_map = readl(mmio + HOST_PORTS_IMPL);
1552 cap_n_ports = ahci_nr_ports(hpriv->cap);
1553
1554 VPRINTK("cap 0x%x port_map 0x%x n_ports %d\n",
1555 hpriv->cap, hpriv->port_map, cap_n_ports);
1556
1557 if (probe_ent->port_flags & AHCI_FLAG_HONOR_PI) {
1558 unsigned int n_ports = cap_n_ports;
1559 u32 port_map = hpriv->port_map;
1560 int max_port = 0;
1561
1562 for (i = 0; i < AHCI_MAX_PORTS && n_ports; i++) {
1563 if (port_map & (1 << i)) {
1564 n_ports--;
1565 port_map &= ~(1 << i);
1566 max_port = i;
1567 } else
1568 probe_ent->dummy_port_mask |= 1 << i;
1569 }
1570
1571 if (n_ports || port_map)
1572 dev_printk(KERN_WARNING, &pdev->dev,
1573 "nr_ports (%u) and implemented port map "
1574 "(0x%x) don't match\n",
1575 cap_n_ports, hpriv->port_map);
1576
1577 probe_ent->n_ports = max_port + 1;
1578 } else
1579 probe_ent->n_ports = cap_n_ports;
1580
1581 using_dac = hpriv->cap & HOST_CAP_64;
1582 if (using_dac && 1567 if (using_dac &&
1583 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 1568 !pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1584 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 1569 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
@@ -1604,23 +1589,14 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
1604 return rc; 1589 return rc;
1605 } 1590 }
1606 } 1591 }
1607
1608 for (i = 0; i < probe_ent->n_ports; i++)
1609 ahci_setup_port(&probe_ent->port[i], mmio, i);
1610
1611 ahci_init_controller(mmio, pdev, probe_ent->n_ports,
1612 probe_ent->port_flags, hpriv);
1613
1614 pci_set_master(pdev);
1615
1616 return 0; 1592 return 0;
1617} 1593}
1618 1594
1619static void ahci_print_info(struct ata_probe_ent *probe_ent) 1595static void ahci_print_info(struct ata_host *host)
1620{ 1596{
1621 struct ahci_host_priv *hpriv = probe_ent->private_data; 1597 struct ahci_host_priv *hpriv = host->private_data;
1622 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1598 struct pci_dev *pdev = to_pci_dev(host->dev);
1623 void __iomem *mmio = probe_ent->iomap[AHCI_PCI_BAR]; 1599 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
1624 u32 vers, cap, impl, speed; 1600 u32 vers, cap, impl, speed;
1625 const char *speed_s; 1601 const char *speed_s;
1626 u16 cc; 1602 u16 cc;
@@ -1690,11 +1666,12 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
1690static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1666static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1691{ 1667{
1692 static int printed_version; 1668 static int printed_version;
1693 unsigned int board_idx = (unsigned int) ent->driver_data; 1669 struct ata_port_info pi = ahci_port_info[ent->driver_data];
1670 const struct ata_port_info *ppi[] = { &pi, NULL };
1694 struct device *dev = &pdev->dev; 1671 struct device *dev = &pdev->dev;
1695 struct ata_probe_ent *probe_ent;
1696 struct ahci_host_priv *hpriv; 1672 struct ahci_host_priv *hpriv;
1697 int rc; 1673 struct ata_host *host;
1674 int i, rc;
1698 1675
1699 VPRINTK("ENTER\n"); 1676 VPRINTK("ENTER\n");
1700 1677
@@ -1703,6 +1680,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1703 if (!printed_version++) 1680 if (!printed_version++)
1704 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1681 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1705 1682
1683 /* acquire resources */
1706 rc = pcim_enable_device(pdev); 1684 rc = pcim_enable_device(pdev);
1707 if (rc) 1685 if (rc)
1708 return rc; 1686 return rc;
@@ -1716,44 +1694,49 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1716 if (pci_enable_msi(pdev)) 1694 if (pci_enable_msi(pdev))
1717 pci_intx(pdev, 1); 1695 pci_intx(pdev, 1);
1718 1696
1719 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
1720 if (probe_ent == NULL)
1721 return -ENOMEM;
1722
1723 probe_ent->dev = pci_dev_to_dev(pdev);
1724 INIT_LIST_HEAD(&probe_ent->node);
1725
1726 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); 1697 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1727 if (!hpriv) 1698 if (!hpriv)
1728 return -ENOMEM; 1699 return -ENOMEM;
1729 1700
1730 probe_ent->sht = ahci_port_info[board_idx].sht; 1701 /* save initial config */
1731 probe_ent->port_flags = ahci_port_info[board_idx].flags; 1702 ahci_save_initial_config(pdev, &pi, hpriv);
1732 probe_ent->pio_mask = ahci_port_info[board_idx].pio_mask;
1733 probe_ent->udma_mask = ahci_port_info[board_idx].udma_mask;
1734 probe_ent->port_ops = ahci_port_info[board_idx].port_ops;
1735 1703
1736 probe_ent->irq = pdev->irq; 1704 /* prepare host */
1737 probe_ent->irq_flags = IRQF_SHARED; 1705 if (!(pi.flags & AHCI_FLAG_NO_NCQ) && (hpriv->cap & HOST_CAP_NCQ))
1738 probe_ent->iomap = pcim_iomap_table(pdev); 1706 pi.flags |= ATA_FLAG_NCQ;
1739 probe_ent->private_data = hpriv; 1707
1708 host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map));
1709 if (!host)
1710 return -ENOMEM;
1711 host->iomap = pcim_iomap_table(pdev);
1712 host->private_data = hpriv;
1713
1714 for (i = 0; i < host->n_ports; i++) {
1715 if (hpriv->port_map & (1 << i)) {
1716 struct ata_port *ap = host->ports[i];
1717 void __iomem *port_mmio = ahci_port_base(ap);
1718
1719 ap->ioaddr.cmd_addr = port_mmio;
1720 ap->ioaddr.scr_addr = port_mmio + PORT_SCR;
1721 } else
1722 host->ports[i]->ops = &ata_dummy_port_ops;
1723 }
1740 1724
1741 /* initialize adapter */ 1725 /* initialize adapter */
1742 rc = ahci_host_init(probe_ent); 1726 rc = ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64);
1743 if (rc) 1727 if (rc)
1744 return rc; 1728 return rc;
1745 1729
1746 if (!(probe_ent->port_flags & AHCI_FLAG_NO_NCQ) && 1730 rc = ahci_reset_controller(host);
1747 (hpriv->cap & HOST_CAP_NCQ)) 1731 if (rc)
1748 probe_ent->port_flags |= ATA_FLAG_NCQ; 1732 return rc;
1749
1750 ahci_print_info(probe_ent);
1751 1733
1752 if (!ata_device_add(probe_ent)) 1734 ahci_init_controller(host);
1753 return -ENODEV; 1735 ahci_print_info(host);
1754 1736
1755 devm_kfree(dev, probe_ent); 1737 pci_set_master(pdev);
1756 return 0; 1738 return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
1739 &ahci_sht);
1757} 1740}
1758 1741
1759static int __init ahci_init(void) 1742static int __init ahci_init(void)
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index d8e79882b880..92a491ddd030 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -33,35 +33,6 @@
33 */ 33 */
34 34
35/** 35/**
36 * generic_pre_reset - probe begin
37 * @ap: ATA port
38 *
39 * Set up cable type and use generic probe init
40 */
41
42static int generic_pre_reset(struct ata_port *ap)
43{
44 ap->cbl = ATA_CBL_PATA80;
45 return ata_std_prereset(ap);
46}
47
48
49/**
50 * generic_error_handler - Probe specified port on PATA host controller
51 * @ap: Port to probe
52 * @classes:
53 *
54 * LOCKING:
55 * None (inherited from caller).
56 */
57
58
59static void generic_error_handler(struct ata_port *ap)
60{
61 ata_bmdma_drive_eh(ap, generic_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
62}
63
64/**
65 * generic_set_mode - mode setting 36 * generic_set_mode - mode setting
66 * @ap: interface to set up 37 * @ap: interface to set up
67 * @unused: returned device on error 38 * @unused: returned device on error
@@ -144,8 +115,9 @@ static struct ata_port_operations generic_port_ops = {
144 115
145 .freeze = ata_bmdma_freeze, 116 .freeze = ata_bmdma_freeze,
146 .thaw = ata_bmdma_thaw, 117 .thaw = ata_bmdma_thaw,
147 .error_handler = generic_error_handler, 118 .error_handler = ata_bmdma_error_handler,
148 .post_internal_cmd = ata_bmdma_post_internal_cmd, 119 .post_internal_cmd = ata_bmdma_post_internal_cmd,
120 .cable_detect = ata_cable_unknown,
149 121
150 .qc_prep = ata_qc_prep, 122 .qc_prep = ata_qc_prep,
151 .qc_issue = ata_qc_issue_prot, 123 .qc_issue = ata_qc_issue_prot,
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index b952c584338f..55d306a3e538 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -93,7 +93,7 @@
93#include <linux/libata.h> 93#include <linux/libata.h>
94 94
95#define DRV_NAME "ata_piix" 95#define DRV_NAME "ata_piix"
96#define DRV_VERSION "2.10ac1" 96#define DRV_VERSION "2.11"
97 97
98enum { 98enum {
99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */ 99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
@@ -155,11 +155,11 @@ struct piix_host_priv {
155static int piix_init_one (struct pci_dev *pdev, 155static int piix_init_one (struct pci_dev *pdev,
156 const struct pci_device_id *ent); 156 const struct pci_device_id *ent);
157static void piix_pata_error_handler(struct ata_port *ap); 157static void piix_pata_error_handler(struct ata_port *ap);
158static void ich_pata_error_handler(struct ata_port *ap);
159static void piix_sata_error_handler(struct ata_port *ap); 158static void piix_sata_error_handler(struct ata_port *ap);
160static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev); 159static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
161static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev); 160static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
162static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev); 161static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev);
162static int ich_pata_cable_detect(struct ata_port *ap);
163 163
164static unsigned int in_module_init = 1; 164static unsigned int in_module_init = 1;
165 165
@@ -305,6 +305,7 @@ static const struct ata_port_operations piix_pata_ops = {
305 .thaw = ata_bmdma_thaw, 305 .thaw = ata_bmdma_thaw,
306 .error_handler = piix_pata_error_handler, 306 .error_handler = piix_pata_error_handler,
307 .post_internal_cmd = ata_bmdma_post_internal_cmd, 307 .post_internal_cmd = ata_bmdma_post_internal_cmd,
308 .cable_detect = ata_cable_40wire,
308 309
309 .irq_handler = ata_interrupt, 310 .irq_handler = ata_interrupt,
310 .irq_clear = ata_bmdma_irq_clear, 311 .irq_clear = ata_bmdma_irq_clear,
@@ -336,8 +337,9 @@ static const struct ata_port_operations ich_pata_ops = {
336 337
337 .freeze = ata_bmdma_freeze, 338 .freeze = ata_bmdma_freeze,
338 .thaw = ata_bmdma_thaw, 339 .thaw = ata_bmdma_thaw,
339 .error_handler = ich_pata_error_handler, 340 .error_handler = piix_pata_error_handler,
340 .post_internal_cmd = ata_bmdma_post_internal_cmd, 341 .post_internal_cmd = ata_bmdma_post_internal_cmd,
342 .cable_detect = ich_pata_cable_detect,
341 343
342 .irq_handler = ata_interrupt, 344 .irq_handler = ata_interrupt,
343 .irq_clear = ata_bmdma_irq_clear, 345 .irq_clear = ata_bmdma_irq_clear,
@@ -580,12 +582,13 @@ static const struct ich_laptop ich_laptop[] = {
580 /* devid, subvendor, subdev */ 582 /* devid, subvendor, subdev */
581 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */ 583 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
582 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 584 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
585 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
583 /* end marker */ 586 /* end marker */
584 { 0, } 587 { 0, }
585}; 588};
586 589
587/** 590/**
588 * piix_pata_cbl_detect - Probe host controller cable detect info 591 * ich_pata_cable_detect - Probe host controller cable detect info
589 * @ap: Port for which cable detect info is desired 592 * @ap: Port for which cable detect info is desired
590 * 593 *
591 * Read 80c cable indicator from ATA PCI device's PCI config 594 * Read 80c cable indicator from ATA PCI device's PCI config
@@ -595,23 +598,18 @@ static const struct ich_laptop ich_laptop[] = {
595 * None (inherited from caller). 598 * None (inherited from caller).
596 */ 599 */
597 600
598static void ich_pata_cbl_detect(struct ata_port *ap) 601static int ich_pata_cable_detect(struct ata_port *ap)
599{ 602{
600 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 603 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
601 const struct ich_laptop *lap = &ich_laptop[0]; 604 const struct ich_laptop *lap = &ich_laptop[0];
602 u8 tmp, mask; 605 u8 tmp, mask;
603 606
604 /* no 80c support in host controller? */
605 if ((ap->udma_mask & ~ATA_UDMA_MASK_40C) == 0)
606 goto cbl40;
607
608 /* Check for specials - Acer Aspire 5602WLMi */ 607 /* Check for specials - Acer Aspire 5602WLMi */
609 while (lap->device) { 608 while (lap->device) {
610 if (lap->device == pdev->device && 609 if (lap->device == pdev->device &&
611 lap->subvendor == pdev->subsystem_vendor && 610 lap->subvendor == pdev->subsystem_vendor &&
612 lap->subdevice == pdev->subsystem_device) { 611 lap->subdevice == pdev->subsystem_device) {
613 ap->cbl = ATA_CBL_PATA40_SHORT; 612 return ATA_CBL_PATA40_SHORT;
614 return;
615 } 613 }
616 lap++; 614 lap++;
617 } 615 }
@@ -620,20 +618,14 @@ static void ich_pata_cbl_detect(struct ata_port *ap)
620 mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC; 618 mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
621 pci_read_config_byte(pdev, PIIX_IOCFG, &tmp); 619 pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
622 if ((tmp & mask) == 0) 620 if ((tmp & mask) == 0)
623 goto cbl40; 621 return ATA_CBL_PATA40;
624 622 return ATA_CBL_PATA80;
625 ap->cbl = ATA_CBL_PATA80;
626 return;
627
628cbl40:
629 ap->cbl = ATA_CBL_PATA40;
630} 623}
631 624
632/** 625/**
633 * piix_pata_prereset - prereset for PATA host controller 626 * piix_pata_prereset - prereset for PATA host controller
634 * @ap: Target port 627 * @ap: Target port
635 * 628 *
636 *
637 * LOCKING: 629 * LOCKING:
638 * None (inherited from caller). 630 * None (inherited from caller).
639 */ 631 */
@@ -643,8 +635,6 @@ static int piix_pata_prereset(struct ata_port *ap)
643 635
644 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) 636 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
645 return -ENOENT; 637 return -ENOENT;
646
647 ap->cbl = ATA_CBL_PATA40;
648 return ata_std_prereset(ap); 638 return ata_std_prereset(ap);
649} 639}
650 640
@@ -655,30 +645,6 @@ static void piix_pata_error_handler(struct ata_port *ap)
655} 645}
656 646
657 647
658/**
659 * ich_pata_prereset - prereset for PATA host controller
660 * @ap: Target port
661 *
662 *
663 * LOCKING:
664 * None (inherited from caller).
665 */
666static int ich_pata_prereset(struct ata_port *ap)
667{
668 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
669
670 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
671 return -ENOENT;
672 ich_pata_cbl_detect(ap);
673 return ata_std_prereset(ap);
674}
675
676static void ich_pata_error_handler(struct ata_port *ap)
677{
678 ata_bmdma_drive_eh(ap, ich_pata_prereset, ata_std_softreset, NULL,
679 ata_std_postreset);
680}
681
682static void piix_sata_error_handler(struct ata_port *ap) 648static void piix_sata_error_handler(struct ata_port *ap)
683{ 649{
684 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL, 650 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL,
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 0abd72d0dec2..ca67484af1eb 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -72,7 +72,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
72static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 72static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
73static void ata_dev_xfermask(struct ata_device *dev); 73static void ata_dev_xfermask(struct ata_device *dev);
74 74
75static unsigned int ata_print_id = 1; 75unsigned int ata_print_id = 1;
76static struct workqueue_struct *ata_wq; 76static struct workqueue_struct *ata_wq;
77 77
78struct workqueue_struct *ata_aux_wq; 78struct workqueue_struct *ata_aux_wq;
@@ -89,6 +89,10 @@ int libata_fua = 0;
89module_param_named(fua, libata_fua, int, 0444); 89module_param_named(fua, libata_fua, int, 0444);
90MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); 90MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
91 91
92static int ata_ignore_hpa = 0;
93module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644);
94MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)");
95
92static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ; 96static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
93module_param(ata_probe_timeout, int, 0444); 97module_param(ata_probe_timeout, int, 0444);
94MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); 98MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
@@ -808,6 +812,205 @@ void ata_id_c_string(const u16 *id, unsigned char *s,
808 *p = '\0'; 812 *p = '\0';
809} 813}
810 814
815static u64 ata_tf_to_lba48(struct ata_taskfile *tf)
816{
817 u64 sectors = 0;
818
819 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40;
820 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32;
821 sectors |= (tf->hob_lbal & 0xff) << 24;
822 sectors |= (tf->lbah & 0xff) << 16;
823 sectors |= (tf->lbam & 0xff) << 8;
824 sectors |= (tf->lbal & 0xff);
825
826 return ++sectors;
827}
828
829static u64 ata_tf_to_lba(struct ata_taskfile *tf)
830{
831 u64 sectors = 0;
832
833 sectors |= (tf->device & 0x0f) << 24;
834 sectors |= (tf->lbah & 0xff) << 16;
835 sectors |= (tf->lbam & 0xff) << 8;
836 sectors |= (tf->lbal & 0xff);
837
838 return ++sectors;
839}
840
841/**
842 * ata_read_native_max_address_ext - LBA48 native max query
843 * @dev: Device to query
844 *
845 * Perform an LBA48 size query upon the device in question. Return the
846 * actual LBA48 size or zero if the command fails.
847 */
848
849static u64 ata_read_native_max_address_ext(struct ata_device *dev)
850{
851 unsigned int err;
852 struct ata_taskfile tf;
853
854 ata_tf_init(dev, &tf);
855
856 tf.command = ATA_CMD_READ_NATIVE_MAX_EXT;
857 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | ATA_TFLAG_ISADDR;
858 tf.protocol |= ATA_PROT_NODATA;
859 tf.device |= 0x40;
860
861 err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
862 if (err)
863 return 0;
864
865 return ata_tf_to_lba48(&tf);
866}
867
868/**
869 * ata_read_native_max_address - LBA28 native max query
870 * @dev: Device to query
871 *
872 * Performa an LBA28 size query upon the device in question. Return the
873 * actual LBA28 size or zero if the command fails.
874 */
875
876static u64 ata_read_native_max_address(struct ata_device *dev)
877{
878 unsigned int err;
879 struct ata_taskfile tf;
880
881 ata_tf_init(dev, &tf);
882
883 tf.command = ATA_CMD_READ_NATIVE_MAX;
884 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
885 tf.protocol |= ATA_PROT_NODATA;
886 tf.device |= 0x40;
887
888 err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
889 if (err)
890 return 0;
891
892 return ata_tf_to_lba(&tf);
893}
894
895/**
896 * ata_set_native_max_address_ext - LBA48 native max set
897 * @dev: Device to query
898 *
899 * Perform an LBA48 size set max upon the device in question. Return the
900 * actual LBA48 size or zero if the command fails.
901 */
902
903static u64 ata_set_native_max_address_ext(struct ata_device *dev, u64 new_sectors)
904{
905 unsigned int err;
906 struct ata_taskfile tf;
907
908 new_sectors--;
909
910 ata_tf_init(dev, &tf);
911
912 tf.command = ATA_CMD_SET_MAX_EXT;
913 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | ATA_TFLAG_ISADDR;
914 tf.protocol |= ATA_PROT_NODATA;
915 tf.device |= 0x40;
916
917 tf.lbal = (new_sectors >> 0) & 0xff;
918 tf.lbam = (new_sectors >> 8) & 0xff;
919 tf.lbah = (new_sectors >> 16) & 0xff;
920
921 tf.hob_lbal = (new_sectors >> 24) & 0xff;
922 tf.hob_lbam = (new_sectors >> 32) & 0xff;
923 tf.hob_lbah = (new_sectors >> 40) & 0xff;
924
925 err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
926 if (err)
927 return 0;
928
929 return ata_tf_to_lba48(&tf);
930}
931
932/**
933 * ata_set_native_max_address - LBA28 native max set
934 * @dev: Device to query
935 *
936 * Perform an LBA28 size set max upon the device in question. Return the
937 * actual LBA28 size or zero if the command fails.
938 */
939
940static u64 ata_set_native_max_address(struct ata_device *dev, u64 new_sectors)
941{
942 unsigned int err;
943 struct ata_taskfile tf;
944
945 new_sectors--;
946
947 ata_tf_init(dev, &tf);
948
949 tf.command = ATA_CMD_SET_MAX;
950 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
951 tf.protocol |= ATA_PROT_NODATA;
952
953 tf.lbal = (new_sectors >> 0) & 0xff;
954 tf.lbam = (new_sectors >> 8) & 0xff;
955 tf.lbah = (new_sectors >> 16) & 0xff;
956 tf.device |= ((new_sectors >> 24) & 0x0f) | 0x40;
957
958 err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
959 if (err)
960 return 0;
961
962 return ata_tf_to_lba(&tf);
963}
964
965/**
966 * ata_hpa_resize - Resize a device with an HPA set
967 * @dev: Device to resize
968 *
969 * Read the size of an LBA28 or LBA48 disk with HPA features and resize
970 * it if required to the full size of the media. The caller must check
971 * the drive has the HPA feature set enabled.
972 */
973
974static u64 ata_hpa_resize(struct ata_device *dev)
975{
976 u64 sectors = dev->n_sectors;
977 u64 hpa_sectors;
978
979 if (ata_id_has_lba48(dev->id))
980 hpa_sectors = ata_read_native_max_address_ext(dev);
981 else
982 hpa_sectors = ata_read_native_max_address(dev);
983
984 /* if no hpa, both should be equal */
985 ata_dev_printk(dev, KERN_INFO, "%s 1: sectors = %lld, "
986 "hpa_sectors = %lld\n",
987 __FUNCTION__, (long long)sectors, (long long)hpa_sectors);
988
989 if (hpa_sectors > sectors) {
990 ata_dev_printk(dev, KERN_INFO,
991 "Host Protected Area detected:\n"
992 "\tcurrent size: %lld sectors\n"
993 "\tnative size: %lld sectors\n",
994 (long long)sectors, (long long)hpa_sectors);
995
996 if (ata_ignore_hpa) {
997 if (ata_id_has_lba48(dev->id))
998 hpa_sectors = ata_set_native_max_address_ext(dev, hpa_sectors);
999 else
1000 hpa_sectors = ata_set_native_max_address(dev,
1001 hpa_sectors);
1002
1003 if (hpa_sectors) {
1004 ata_dev_printk(dev, KERN_INFO, "native size "
1005 "increased to %lld sectors\n",
1006 (long long)hpa_sectors);
1007 return hpa_sectors;
1008 }
1009 }
1010 }
1011 return sectors;
1012}
1013
811static u64 ata_id_n_sectors(const u16 *id) 1014static u64 ata_id_n_sectors(const u16 *id)
812{ 1015{
813 if (ata_id_has_lba(id)) { 1016 if (ata_id_has_lba(id)) {
@@ -1270,12 +1473,16 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1270 if (ap->ops->post_internal_cmd) 1473 if (ap->ops->post_internal_cmd)
1271 ap->ops->post_internal_cmd(qc); 1474 ap->ops->post_internal_cmd(qc);
1272 1475
1273 if ((qc->flags & ATA_QCFLAG_FAILED) && !qc->err_mask) { 1476 /* perform minimal error analysis */
1274 if (ata_msg_warn(ap)) 1477 if (qc->flags & ATA_QCFLAG_FAILED) {
1275 ata_dev_printk(dev, KERN_WARNING, 1478 if (qc->result_tf.command & (ATA_ERR | ATA_DF))
1276 "zero err_mask for failed " 1479 qc->err_mask |= AC_ERR_DEV;
1277 "internal command, assuming AC_ERR_OTHER\n"); 1480
1278 qc->err_mask |= AC_ERR_OTHER; 1481 if (!qc->err_mask)
1482 qc->err_mask |= AC_ERR_OTHER;
1483
1484 if (qc->err_mask & ~AC_ERR_OTHER)
1485 qc->err_mask &= ~AC_ERR_OTHER;
1279 } 1486 }
1280 1487
1281 /* finish up */ 1488 /* finish up */
@@ -1379,30 +1586,44 @@ unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
1379 * Check if the current speed of the device requires IORDY. Used 1586 * Check if the current speed of the device requires IORDY. Used
1380 * by various controllers for chip configuration. 1587 * by various controllers for chip configuration.
1381 */ 1588 */
1382 1589
1383unsigned int ata_pio_need_iordy(const struct ata_device *adev) 1590unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1384{ 1591{
1385 int pio; 1592 /* Controller doesn't support IORDY. Probably a pointless check
1386 int speed = adev->pio_mode - XFER_PIO_0; 1593 as the caller should know this */
1387 1594 if (adev->ap->flags & ATA_FLAG_NO_IORDY)
1388 if (speed < 2)
1389 return 0; 1595 return 0;
1390 if (speed > 2) 1596 /* PIO3 and higher it is mandatory */
1597 if (adev->pio_mode > XFER_PIO_2)
1598 return 1;
1599 /* We turn it on when possible */
1600 if (ata_id_has_iordy(adev->id))
1391 return 1; 1601 return 1;
1602 return 0;
1603}
1392 1604
1605/**
1606 * ata_pio_mask_no_iordy - Return the non IORDY mask
1607 * @adev: ATA device
1608 *
1609 * Compute the highest mode possible if we are not using iordy. Return
1610 * -1 if no iordy mode is available.
1611 */
1612
1613static u32 ata_pio_mask_no_iordy(const struct ata_device *adev)
1614{
1393 /* If we have no drive specific rule, then PIO 2 is non IORDY */ 1615 /* If we have no drive specific rule, then PIO 2 is non IORDY */
1394
1395 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ 1616 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
1396 pio = adev->id[ATA_ID_EIDE_PIO]; 1617 u16 pio = adev->id[ATA_ID_EIDE_PIO];
1397 /* Is the speed faster than the drive allows non IORDY ? */ 1618 /* Is the speed faster than the drive allows non IORDY ? */
1398 if (pio) { 1619 if (pio) {
1399 /* This is cycle times not frequency - watch the logic! */ 1620 /* This is cycle times not frequency - watch the logic! */
1400 if (pio > 240) /* PIO2 is 240nS per cycle */ 1621 if (pio > 240) /* PIO2 is 240nS per cycle */
1401 return 1; 1622 return 3 << ATA_SHIFT_PIO;
1402 return 0; 1623 return 7 << ATA_SHIFT_PIO;
1403 } 1624 }
1404 } 1625 }
1405 return 0; 1626 return 3 << ATA_SHIFT_PIO;
1406} 1627}
1407 1628
1408/** 1629/**
@@ -1431,13 +1652,13 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1431 struct ata_taskfile tf; 1652 struct ata_taskfile tf;
1432 unsigned int err_mask = 0; 1653 unsigned int err_mask = 0;
1433 const char *reason; 1654 const char *reason;
1655 int tried_spinup = 0;
1434 int rc; 1656 int rc;
1435 1657
1436 if (ata_msg_ctl(ap)) 1658 if (ata_msg_ctl(ap))
1437 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__); 1659 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
1438 1660
1439 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ 1661 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
1440
1441 retry: 1662 retry:
1442 ata_tf_init(dev, &tf); 1663 ata_tf_init(dev, &tf);
1443 1664
@@ -1494,6 +1715,32 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1494 goto err_out; 1715 goto err_out;
1495 } 1716 }
1496 1717
1718 if (!tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) {
1719 tried_spinup = 1;
1720 /*
1721 * Drive powered-up in standby mode, and requires a specific
1722 * SET_FEATURES spin-up subcommand before it will accept
1723 * anything other than the original IDENTIFY command.
1724 */
1725 ata_tf_init(dev, &tf);
1726 tf.command = ATA_CMD_SET_FEATURES;
1727 tf.feature = SETFEATURES_SPINUP;
1728 tf.protocol = ATA_PROT_NODATA;
1729 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1730 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
1731 if (err_mask) {
1732 rc = -EIO;
1733 reason = "SPINUP failed";
1734 goto err_out;
1735 }
1736 /*
1737 * If the drive initially returned incomplete IDENTIFY info,
1738 * we now must reissue the IDENTIFY command.
1739 */
1740 if (id[2] == 0x37c8)
1741 goto retry;
1742 }
1743
1497 if ((flags & ATA_READID_POSTRESET) && class == ATA_DEV_ATA) { 1744 if ((flags & ATA_READID_POSTRESET) && class == ATA_DEV_ATA) {
1498 /* 1745 /*
1499 * The exact sequence expected by certain pre-ATA4 drives is: 1746 * The exact sequence expected by certain pre-ATA4 drives is:
@@ -1560,20 +1807,6 @@ static void ata_dev_config_ncq(struct ata_device *dev,
1560 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth); 1807 snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
1561} 1808}
1562 1809
1563static void ata_set_port_max_cmd_len(struct ata_port *ap)
1564{
1565 int i;
1566
1567 if (ap->scsi_host) {
1568 unsigned int len = 0;
1569
1570 for (i = 0; i < ATA_MAX_DEVICES; i++)
1571 len = max(len, ap->device[i].cdb_len);
1572
1573 ap->scsi_host->max_cmd_len = len;
1574 }
1575}
1576
1577/** 1810/**
1578 * ata_dev_configure - Configure the specified ATA/ATAPI device 1811 * ata_dev_configure - Configure the specified ATA/ATAPI device
1579 * @dev: Target device to configure 1812 * @dev: Target device to configure
@@ -1658,6 +1891,7 @@ int ata_dev_configure(struct ata_device *dev)
1658 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); 1891 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id));
1659 1892
1660 dev->n_sectors = ata_id_n_sectors(id); 1893 dev->n_sectors = ata_id_n_sectors(id);
1894 dev->n_sectors_boot = dev->n_sectors;
1661 1895
1662 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ 1896 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
1663 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, 1897 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
@@ -1684,6 +1918,9 @@ int ata_dev_configure(struct ata_device *dev)
1684 dev->flags |= ATA_DFLAG_FLUSH_EXT; 1918 dev->flags |= ATA_DFLAG_FLUSH_EXT;
1685 } 1919 }
1686 1920
1921 if (ata_id_hpa_enabled(dev->id))
1922 dev->n_sectors = ata_hpa_resize(dev);
1923
1687 /* config NCQ */ 1924 /* config NCQ */
1688 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); 1925 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
1689 1926
@@ -1773,8 +2010,6 @@ int ata_dev_configure(struct ata_device *dev)
1773 } 2010 }
1774 } 2011 }
1775 2012
1776 ata_set_port_max_cmd_len(ap);
1777
1778 /* limit bridge transfers to udma5, 200 sectors */ 2013 /* limit bridge transfers to udma5, 200 sectors */
1779 if (ata_dev_knobble(dev)) { 2014 if (ata_dev_knobble(dev)) {
1780 if (ata_msg_drv(ap) && print_info) 2015 if (ata_msg_drv(ap) && print_info)
@@ -1785,14 +2020,15 @@ int ata_dev_configure(struct ata_device *dev)
1785 } 2020 }
1786 2021
1787 if (ata_device_blacklisted(dev) & ATA_HORKAGE_MAX_SEC_128) 2022 if (ata_device_blacklisted(dev) & ATA_HORKAGE_MAX_SEC_128)
1788 dev->max_sectors = min(ATA_MAX_SECTORS_128, dev->max_sectors); 2023 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
2024 dev->max_sectors);
1789 2025
1790 /* limit ATAPI DMA to R/W commands only */ 2026 /* limit ATAPI DMA to R/W commands only */
1791 if (ata_device_blacklisted(dev) & ATA_HORKAGE_DMA_RW_ONLY) 2027 if (ata_device_blacklisted(dev) & ATA_HORKAGE_DMA_RW_ONLY)
1792 dev->horkage |= ATA_HORKAGE_DMA_RW_ONLY; 2028 dev->horkage |= ATA_HORKAGE_DMA_RW_ONLY;
1793 2029
1794 if (ap->ops->dev_config) 2030 if (ap->ops->dev_config)
1795 ap->ops->dev_config(ap, dev); 2031 ap->ops->dev_config(dev);
1796 2032
1797 if (ata_msg_probe(ap)) 2033 if (ata_msg_probe(ap))
1798 ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n", 2034 ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n",
@@ -1807,6 +2043,56 @@ err_out_nosup:
1807} 2043}
1808 2044
1809/** 2045/**
2046 * ata_cable_40wire - return 40 wire cable type
2047 * @ap: port
2048 *
2049 * Helper method for drivers which want to hardwire 40 wire cable
2050 * detection.
2051 */
2052
2053int ata_cable_40wire(struct ata_port *ap)
2054{
2055 return ATA_CBL_PATA40;
2056}
2057
2058/**
2059 * ata_cable_80wire - return 80 wire cable type
2060 * @ap: port
2061 *
2062 * Helper method for drivers which want to hardwire 80 wire cable
2063 * detection.
2064 */
2065
2066int ata_cable_80wire(struct ata_port *ap)
2067{
2068 return ATA_CBL_PATA80;
2069}
2070
2071/**
2072 * ata_cable_unknown - return unknown PATA cable.
2073 * @ap: port
2074 *
2075 * Helper method for drivers which have no PATA cable detection.
2076 */
2077
2078int ata_cable_unknown(struct ata_port *ap)
2079{
2080 return ATA_CBL_PATA_UNK;
2081}
2082
2083/**
2084 * ata_cable_sata - return SATA cable type
2085 * @ap: port
2086 *
2087 * Helper method for drivers which have SATA cables
2088 */
2089
2090int ata_cable_sata(struct ata_port *ap)
2091{
2092 return ATA_CBL_SATA;
2093}
2094
2095/**
1810 * ata_bus_probe - Reset and probe ATA bus 2096 * ata_bus_probe - Reset and probe ATA bus
1811 * @ap: Bus to probe 2097 * @ap: Bus to probe
1812 * 2098 *
@@ -1876,6 +2162,10 @@ int ata_bus_probe(struct ata_port *ap)
1876 goto fail; 2162 goto fail;
1877 } 2163 }
1878 2164
2165 /* Now ask for the cable type as PDIAG- should have been released */
2166 if (ap->ops->cable_detect)
2167 ap->cbl = ap->ops->cable_detect(ap);
2168
1879 /* After the identify sequence we can now set up the devices. We do 2169 /* After the identify sequence we can now set up the devices. We do
1880 this in the normal order so that the user doesn't get confused */ 2170 this in the normal order so that the user doesn't get confused */
1881 2171
@@ -1958,7 +2248,7 @@ void ata_port_probe(struct ata_port *ap)
1958 * LOCKING: 2248 * LOCKING:
1959 * None. 2249 * None.
1960 */ 2250 */
1961static void sata_print_link_status(struct ata_port *ap) 2251void sata_print_link_status(struct ata_port *ap)
1962{ 2252{
1963 u32 sstatus, scontrol, tmp; 2253 u32 sstatus, scontrol, tmp;
1964 2254
@@ -2352,6 +2642,12 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
2352 t->active += (t->cycle - (t->active + t->recover)) / 2; 2642 t->active += (t->cycle - (t->active + t->recover)) / 2;
2353 t->recover = t->cycle - t->active; 2643 t->recover = t->cycle - t->active;
2354 } 2644 }
2645
2646 /* In a few cases quantisation may produce enough errors to
2647 leave t->cycle too low for the sum of active and recovery
2648 if so we must correct this */
2649 if (t->active + t->recover > t->cycle)
2650 t->cycle = t->active + t->recover;
2355 2651
2356 return 0; 2652 return 0;
2357} 2653}
@@ -2481,12 +2777,13 @@ static int ata_dev_set_mode(struct ata_device *dev)
2481} 2777}
2482 2778
2483/** 2779/**
2484 * ata_set_mode - Program timings and issue SET FEATURES - XFER 2780 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
2485 * @ap: port on which timings will be programmed 2781 * @ap: port on which timings will be programmed
2486 * @r_failed_dev: out paramter for failed device 2782 * @r_failed_dev: out paramter for failed device
2487 * 2783 *
2488 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If 2784 * Standard implementation of the function used to tune and set
2489 * ata_set_mode() fails, pointer to the failing device is 2785 * ATA device disk transfer mode (PIO3, UDMA6, etc.). If
2786 * ata_dev_set_mode() fails, pointer to the failing device is
2490 * returned in @r_failed_dev. 2787 * returned in @r_failed_dev.
2491 * 2788 *
2492 * LOCKING: 2789 * LOCKING:
@@ -2495,14 +2792,12 @@ static int ata_dev_set_mode(struct ata_device *dev)
2495 * RETURNS: 2792 * RETURNS:
2496 * 0 on success, negative errno otherwise 2793 * 0 on success, negative errno otherwise
2497 */ 2794 */
2498int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) 2795
2796int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2499{ 2797{
2500 struct ata_device *dev; 2798 struct ata_device *dev;
2501 int i, rc = 0, used_dma = 0, found = 0; 2799 int i, rc = 0, used_dma = 0, found = 0;
2502 2800
2503 /* has private set_mode? */
2504 if (ap->ops->set_mode)
2505 return ap->ops->set_mode(ap, r_failed_dev);
2506 2801
2507 /* step 1: calculate xfer_mask */ 2802 /* step 1: calculate xfer_mask */
2508 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2803 for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -2587,6 +2882,29 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2587} 2882}
2588 2883
2589/** 2884/**
2885 * ata_set_mode - Program timings and issue SET FEATURES - XFER
2886 * @ap: port on which timings will be programmed
2887 * @r_failed_dev: out paramter for failed device
2888 *
2889 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If
2890 * ata_set_mode() fails, pointer to the failing device is
2891 * returned in @r_failed_dev.
2892 *
2893 * LOCKING:
2894 * PCI/etc. bus probe sem.
2895 *
2896 * RETURNS:
2897 * 0 on success, negative errno otherwise
2898 */
2899int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2900{
2901 /* has private set_mode? */
2902 if (ap->ops->set_mode)
2903 return ap->ops->set_mode(ap, r_failed_dev);
2904 return ata_do_set_mode(ap, r_failed_dev);
2905}
2906
2907/**
2590 * ata_tf_to_host - issue ATA taskfile to host controller 2908 * ata_tf_to_host - issue ATA taskfile to host controller
2591 * @ap: port to which command is being issued 2909 * @ap: port to which command is being issued
2592 * @tf: ATA taskfile register set 2910 * @tf: ATA taskfile register set
@@ -3267,6 +3585,11 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3267 "%llu != %llu\n", 3585 "%llu != %llu\n",
3268 (unsigned long long)dev->n_sectors, 3586 (unsigned long long)dev->n_sectors,
3269 (unsigned long long)new_n_sectors); 3587 (unsigned long long)new_n_sectors);
3588 /* Are we the boot time size - if so we appear to be the
3589 same disk at this point and our HPA got reapplied */
3590 if (ata_ignore_hpa && dev->n_sectors_boot == new_n_sectors
3591 && ata_id_hpa_enabled(new_id))
3592 return 1;
3270 return 0; 3593 return 0;
3271 } 3594 }
3272 3595
@@ -3441,19 +3764,7 @@ static void ata_dev_xfermask(struct ata_device *dev)
3441 xfer_mask = ata_pack_xfermask(ap->pio_mask, 3764 xfer_mask = ata_pack_xfermask(ap->pio_mask,
3442 ap->mwdma_mask, ap->udma_mask); 3765 ap->mwdma_mask, ap->udma_mask);
3443 3766
3444 /* Apply cable rule here. Don't apply it early because when 3767 /* drive modes available */
3445 * we handle hot plug the cable type can itself change.
3446 */
3447 if (ap->cbl == ATA_CBL_PATA40)
3448 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3449 /* Apply drive side cable rule. Unknown or 80 pin cables reported
3450 * host side are checked drive side as well. Cases where we know a
3451 * 40wire cable is used safely for 80 are not checked here.
3452 */
3453 if (ata_drive_40wire(dev->id) && (ap->cbl == ATA_CBL_PATA_UNK || ap->cbl == ATA_CBL_PATA80))
3454 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3455
3456
3457 xfer_mask &= ata_pack_xfermask(dev->pio_mask, 3768 xfer_mask &= ata_pack_xfermask(dev->pio_mask,
3458 dev->mwdma_mask, dev->udma_mask); 3769 dev->mwdma_mask, dev->udma_mask);
3459 xfer_mask &= ata_id_xfermask(dev->id); 3770 xfer_mask &= ata_id_xfermask(dev->id);
@@ -3482,8 +3793,30 @@ static void ata_dev_xfermask(struct ata_device *dev)
3482 "other device, disabling DMA\n"); 3793 "other device, disabling DMA\n");
3483 } 3794 }
3484 3795
3796 if (ap->flags & ATA_FLAG_NO_IORDY)
3797 xfer_mask &= ata_pio_mask_no_iordy(dev);
3798
3485 if (ap->ops->mode_filter) 3799 if (ap->ops->mode_filter)
3486 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask); 3800 xfer_mask = ap->ops->mode_filter(dev, xfer_mask);
3801
3802 /* Apply cable rule here. Don't apply it early because when
3803 * we handle hot plug the cable type can itself change.
3804 * Check this last so that we know if the transfer rate was
3805 * solely limited by the cable.
3806 * Unknown or 80 wire cables reported host side are checked
3807 * drive side as well. Cases where we know a 40wire cable
3808 * is used safely for 80 are not checked here.
3809 */
3810 if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
3811 /* UDMA/44 or higher would be available */
3812 if((ap->cbl == ATA_CBL_PATA40) ||
3813 (ata_drive_40wire(dev->id) &&
3814 (ap->cbl == ATA_CBL_PATA_UNK ||
3815 ap->cbl == ATA_CBL_PATA80))) {
3816 ata_dev_printk(dev, KERN_WARNING,
3817 "limited to UDMA/33 due to 40-wire cable\n");
3818 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3819 }
3487 3820
3488 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, 3821 ata_unpack_xfermask(xfer_mask, &dev->pio_mask,
3489 &dev->mwdma_mask, &dev->udma_mask); 3822 &dev->mwdma_mask, &dev->udma_mask);
@@ -4022,10 +4355,10 @@ void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
4022 4355
4023 4356
4024/** 4357/**
4025 * ata_pio_sector - Transfer ATA_SECT_SIZE (512 bytes) of data. 4358 * ata_pio_sector - Transfer a sector of data.
4026 * @qc: Command on going 4359 * @qc: Command on going
4027 * 4360 *
4028 * Transfer ATA_SECT_SIZE of data from/to the ATA device. 4361 * Transfer qc->sect_size bytes of data from/to the ATA device.
4029 * 4362 *
4030 * LOCKING: 4363 * LOCKING:
4031 * Inherited from caller. 4364 * Inherited from caller.
@@ -4040,7 +4373,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4040 unsigned int offset; 4373 unsigned int offset;
4041 unsigned char *buf; 4374 unsigned char *buf;
4042 4375
4043 if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE) 4376 if (qc->curbytes == qc->nbytes - qc->sect_size)
4044 ap->hsm_task_state = HSM_ST_LAST; 4377 ap->hsm_task_state = HSM_ST_LAST;
4045 4378
4046 page = sg[qc->cursg].page; 4379 page = sg[qc->cursg].page;
@@ -4060,17 +4393,17 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4060 buf = kmap_atomic(page, KM_IRQ0); 4393 buf = kmap_atomic(page, KM_IRQ0);
4061 4394
4062 /* do the actual data transfer */ 4395 /* do the actual data transfer */
4063 ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write); 4396 ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write);
4064 4397
4065 kunmap_atomic(buf, KM_IRQ0); 4398 kunmap_atomic(buf, KM_IRQ0);
4066 local_irq_restore(flags); 4399 local_irq_restore(flags);
4067 } else { 4400 } else {
4068 buf = page_address(page); 4401 buf = page_address(page);
4069 ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write); 4402 ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write);
4070 } 4403 }
4071 4404
4072 qc->curbytes += ATA_SECT_SIZE; 4405 qc->curbytes += qc->sect_size;
4073 qc->cursg_ofs += ATA_SECT_SIZE; 4406 qc->cursg_ofs += qc->sect_size;
4074 4407
4075 if (qc->cursg_ofs == (&sg[qc->cursg])->length) { 4408 if (qc->cursg_ofs == (&sg[qc->cursg])->length) {
4076 qc->cursg++; 4409 qc->cursg++;
@@ -4079,10 +4412,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4079} 4412}
4080 4413
4081/** 4414/**
4082 * ata_pio_sectors - Transfer one or many 512-byte sectors. 4415 * ata_pio_sectors - Transfer one or many sectors.
4083 * @qc: Command on going 4416 * @qc: Command on going
4084 * 4417 *
4085 * Transfer one or many ATA_SECT_SIZE of data from/to the 4418 * Transfer one or many sectors of data from/to the
4086 * ATA device for the DRQ request. 4419 * ATA device for the DRQ request.
4087 * 4420 *
4088 * LOCKING: 4421 * LOCKING:
@@ -4097,7 +4430,7 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
4097 4430
4098 WARN_ON(qc->dev->multi_count == 0); 4431 WARN_ON(qc->dev->multi_count == 0);
4099 4432
4100 nsect = min((qc->nbytes - qc->curbytes) / ATA_SECT_SIZE, 4433 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size,
4101 qc->dev->multi_count); 4434 qc->dev->multi_count);
4102 while (nsect--) 4435 while (nsect--)
4103 ata_pio_sector(qc); 4436 ata_pio_sector(qc);
@@ -5577,42 +5910,35 @@ void ata_dev_init(struct ata_device *dev)
5577} 5910}
5578 5911
5579/** 5912/**
5580 * ata_port_init - Initialize an ata_port structure 5913 * ata_port_alloc - allocate and initialize basic ATA port resources
5581 * @ap: Structure to initialize 5914 * @host: ATA host this allocated port belongs to
5582 * @host: Collection of hosts to which @ap belongs
5583 * @ent: Probe information provided by low-level driver
5584 * @port_no: Port number associated with this ata_port
5585 * 5915 *
5586 * Initialize a new ata_port structure. 5916 * Allocate and initialize basic ATA port resources.
5917 *
5918 * RETURNS:
5919 * Allocate ATA port on success, NULL on failure.
5587 * 5920 *
5588 * LOCKING: 5921 * LOCKING:
5589 * Inherited from caller. 5922 * Inherited from calling layer (may sleep).
5590 */ 5923 */
5591void ata_port_init(struct ata_port *ap, struct ata_host *host, 5924struct ata_port *ata_port_alloc(struct ata_host *host)
5592 const struct ata_probe_ent *ent, unsigned int port_no)
5593{ 5925{
5926 struct ata_port *ap;
5594 unsigned int i; 5927 unsigned int i;
5595 5928
5929 DPRINTK("ENTER\n");
5930
5931 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
5932 if (!ap)
5933 return NULL;
5934
5596 ap->lock = &host->lock; 5935 ap->lock = &host->lock;
5597 ap->flags = ATA_FLAG_DISABLED; 5936 ap->flags = ATA_FLAG_DISABLED;
5598 ap->print_id = ata_print_id++; 5937 ap->print_id = -1;
5599 ap->ctl = ATA_DEVCTL_OBS; 5938 ap->ctl = ATA_DEVCTL_OBS;
5600 ap->host = host; 5939 ap->host = host;
5601 ap->dev = ent->dev; 5940 ap->dev = host->dev;
5602 ap->port_no = port_no; 5941
5603 if (port_no == 1 && ent->pinfo2) {
5604 ap->pio_mask = ent->pinfo2->pio_mask;
5605 ap->mwdma_mask = ent->pinfo2->mwdma_mask;
5606 ap->udma_mask = ent->pinfo2->udma_mask;
5607 ap->flags |= ent->pinfo2->flags;
5608 ap->ops = ent->pinfo2->port_ops;
5609 } else {
5610 ap->pio_mask = ent->pio_mask;
5611 ap->mwdma_mask = ent->mwdma_mask;
5612 ap->udma_mask = ent->udma_mask;
5613 ap->flags |= ent->port_flags;
5614 ap->ops = ent->port_ops;
5615 }
5616 ap->hw_sata_spd_limit = UINT_MAX; 5942 ap->hw_sata_spd_limit = UINT_MAX;
5617 ap->active_tag = ATA_TAG_POISON; 5943 ap->active_tag = ATA_TAG_POISON;
5618 ap->last_ctl = 0xFF; 5944 ap->last_ctl = 0xFF;
@@ -5632,10 +5958,7 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5632 INIT_LIST_HEAD(&ap->eh_done_q); 5958 INIT_LIST_HEAD(&ap->eh_done_q);
5633 init_waitqueue_head(&ap->eh_wait_q); 5959 init_waitqueue_head(&ap->eh_wait_q);
5634 5960
5635 /* set cable type */
5636 ap->cbl = ATA_CBL_NONE; 5961 ap->cbl = ATA_CBL_NONE;
5637 if (ap->flags & ATA_FLAG_SATA)
5638 ap->cbl = ATA_CBL_SATA;
5639 5962
5640 for (i = 0; i < ATA_MAX_DEVICES; i++) { 5963 for (i = 0; i < ATA_MAX_DEVICES; i++) {
5641 struct ata_device *dev = &ap->device[i]; 5964 struct ata_device *dev = &ap->device[i];
@@ -5648,100 +5971,209 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5648 ap->stats.unhandled_irq = 1; 5971 ap->stats.unhandled_irq = 1;
5649 ap->stats.idle_irq = 1; 5972 ap->stats.idle_irq = 1;
5650#endif 5973#endif
5974 return ap;
5975}
5651 5976
5652 memcpy(&ap->ioaddr, &ent->port[port_no], sizeof(struct ata_ioports)); 5977static void ata_host_release(struct device *gendev, void *res)
5978{
5979 struct ata_host *host = dev_get_drvdata(gendev);
5980 int i;
5981
5982 for (i = 0; i < host->n_ports; i++) {
5983 struct ata_port *ap = host->ports[i];
5984
5985 if (!ap)
5986 continue;
5987
5988 if ((host->flags & ATA_HOST_STARTED) && ap->ops->port_stop)
5989 ap->ops->port_stop(ap);
5990 }
5991
5992 if ((host->flags & ATA_HOST_STARTED) && host->ops->host_stop)
5993 host->ops->host_stop(host);
5994
5995 for (i = 0; i < host->n_ports; i++) {
5996 struct ata_port *ap = host->ports[i];
5997
5998 if (!ap)
5999 continue;
6000
6001 if (ap->scsi_host)
6002 scsi_host_put(ap->scsi_host);
6003
6004 kfree(ap);
6005 host->ports[i] = NULL;
6006 }
6007
6008 dev_set_drvdata(gendev, NULL);
5653} 6009}
5654 6010
5655/** 6011/**
5656 * ata_port_init_shost - Initialize SCSI host associated with ATA port 6012 * ata_host_alloc - allocate and init basic ATA host resources
5657 * @ap: ATA port to initialize SCSI host for 6013 * @dev: generic device this host is associated with
5658 * @shost: SCSI host associated with @ap 6014 * @max_ports: maximum number of ATA ports associated with this host
5659 * 6015 *
5660 * Initialize SCSI host @shost associated with ATA port @ap. 6016 * Allocate and initialize basic ATA host resources. LLD calls
6017 * this function to allocate a host, initializes it fully and
6018 * attaches it using ata_host_register().
6019 *
6020 * @max_ports ports are allocated and host->n_ports is
6021 * initialized to @max_ports. The caller is allowed to decrease
6022 * host->n_ports before calling ata_host_register(). The unused
6023 * ports will be automatically freed on registration.
6024 *
6025 * RETURNS:
6026 * Allocate ATA host on success, NULL on failure.
5661 * 6027 *
5662 * LOCKING: 6028 * LOCKING:
5663 * Inherited from caller. 6029 * Inherited from calling layer (may sleep).
5664 */ 6030 */
5665static void ata_port_init_shost(struct ata_port *ap, struct Scsi_Host *shost) 6031struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5666{ 6032{
5667 ap->scsi_host = shost; 6033 struct ata_host *host;
6034 size_t sz;
6035 int i;
6036
6037 DPRINTK("ENTER\n");
6038
6039 if (!devres_open_group(dev, NULL, GFP_KERNEL))
6040 return NULL;
6041
6042 /* alloc a container for our list of ATA ports (buses) */
6043 sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *);
6044 /* alloc a container for our list of ATA ports (buses) */
6045 host = devres_alloc(ata_host_release, sz, GFP_KERNEL);
6046 if (!host)
6047 goto err_out;
6048
6049 devres_add(dev, host);
6050 dev_set_drvdata(dev, host);
5668 6051
5669 shost->unique_id = ap->print_id; 6052 spin_lock_init(&host->lock);
5670 shost->max_id = 16; 6053 host->dev = dev;
5671 shost->max_lun = 1; 6054 host->n_ports = max_ports;
5672 shost->max_channel = 1; 6055
5673 shost->max_cmd_len = 12; 6056 /* allocate ports bound to this host */
6057 for (i = 0; i < max_ports; i++) {
6058 struct ata_port *ap;
6059
6060 ap = ata_port_alloc(host);
6061 if (!ap)
6062 goto err_out;
6063
6064 ap->port_no = i;
6065 host->ports[i] = ap;
6066 }
6067
6068 devres_remove_group(dev, NULL);
6069 return host;
6070
6071 err_out:
6072 devres_release_group(dev, NULL);
6073 return NULL;
5674} 6074}
5675 6075
5676/** 6076/**
5677 * ata_port_add - Attach low-level ATA driver to system 6077 * ata_host_alloc_pinfo - alloc host and init with port_info array
5678 * @ent: Information provided by low-level driver 6078 * @dev: generic device this host is associated with
5679 * @host: Collections of ports to which we add 6079 * @ppi: array of ATA port_info to initialize host with
5680 * @port_no: Port number associated with this host 6080 * @n_ports: number of ATA ports attached to this host
5681 * 6081 *
5682 * Attach low-level ATA driver to system. 6082 * Allocate ATA host and initialize with info from @ppi. If NULL
5683 * 6083 * terminated, @ppi may contain fewer entries than @n_ports. The
5684 * LOCKING: 6084 * last entry will be used for the remaining ports.
5685 * PCI/etc. bus probe sem.
5686 * 6085 *
5687 * RETURNS: 6086 * RETURNS:
5688 * New ata_port on success, for NULL on error. 6087 * Allocate ATA host on success, NULL on failure.
6088 *
6089 * LOCKING:
6090 * Inherited from calling layer (may sleep).
5689 */ 6091 */
5690static struct ata_port * ata_port_add(const struct ata_probe_ent *ent, 6092struct ata_host *ata_host_alloc_pinfo(struct device *dev,
5691 struct ata_host *host, 6093 const struct ata_port_info * const * ppi,
5692 unsigned int port_no) 6094 int n_ports)
5693{ 6095{
5694 struct Scsi_Host *shost; 6096 const struct ata_port_info *pi;
5695 struct ata_port *ap; 6097 struct ata_host *host;
5696 6098 int i, j;
5697 DPRINTK("ENTER\n");
5698 6099
5699 if (!ent->port_ops->error_handler && 6100 host = ata_host_alloc(dev, n_ports);
5700 !(ent->port_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) { 6101 if (!host)
5701 printk(KERN_ERR "ata%u: no reset mechanism available\n",
5702 port_no);
5703 return NULL; 6102 return NULL;
5704 }
5705 6103
5706 shost = scsi_host_alloc(ent->sht, sizeof(struct ata_port)); 6104 for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) {
5707 if (!shost) 6105 struct ata_port *ap = host->ports[i];
5708 return NULL;
5709 6106
5710 shost->transportt = &ata_scsi_transport_template; 6107 if (ppi[j])
6108 pi = ppi[j++];
5711 6109
5712 ap = ata_shost_to_port(shost); 6110 ap->pio_mask = pi->pio_mask;
6111 ap->mwdma_mask = pi->mwdma_mask;
6112 ap->udma_mask = pi->udma_mask;
6113 ap->flags |= pi->flags;
6114 ap->ops = pi->port_ops;
5713 6115
5714 ata_port_init(ap, host, ent, port_no); 6116 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops))
5715 ata_port_init_shost(ap, shost); 6117 host->ops = pi->port_ops;
6118 if (!host->private_data && pi->private_data)
6119 host->private_data = pi->private_data;
6120 }
5716 6121
5717 return ap; 6122 return host;
5718} 6123}
5719 6124
5720static void ata_host_release(struct device *gendev, void *res) 6125/**
6126 * ata_host_start - start and freeze ports of an ATA host
6127 * @host: ATA host to start ports for
6128 *
6129 * Start and then freeze ports of @host. Started status is
6130 * recorded in host->flags, so this function can be called
6131 * multiple times. Ports are guaranteed to get started only
6132 * once. If host->ops isn't initialized yet, its set to the
6133 * first non-dummy port ops.
6134 *
6135 * LOCKING:
6136 * Inherited from calling layer (may sleep).
6137 *
6138 * RETURNS:
6139 * 0 if all ports are started successfully, -errno otherwise.
6140 */
6141int ata_host_start(struct ata_host *host)
5721{ 6142{
5722 struct ata_host *host = dev_get_drvdata(gendev); 6143 int i, rc;
5723 int i; 6144
6145 if (host->flags & ATA_HOST_STARTED)
6146 return 0;
5724 6147
5725 for (i = 0; i < host->n_ports; i++) { 6148 for (i = 0; i < host->n_ports; i++) {
5726 struct ata_port *ap = host->ports[i]; 6149 struct ata_port *ap = host->ports[i];
5727 6150
5728 if (ap && ap->ops->port_stop) 6151 if (!host->ops && !ata_port_is_dummy(ap))
5729 ap->ops->port_stop(ap); 6152 host->ops = ap->ops;
6153
6154 if (ap->ops->port_start) {
6155 rc = ap->ops->port_start(ap);
6156 if (rc) {
6157 ata_port_printk(ap, KERN_ERR, "failed to "
6158 "start port (errno=%d)\n", rc);
6159 goto err_out;
6160 }
6161 }
6162
6163 ata_eh_freeze_port(ap);
5730 } 6164 }
5731 6165
5732 if (host->ops->host_stop) 6166 host->flags |= ATA_HOST_STARTED;
5733 host->ops->host_stop(host); 6167 return 0;
5734 6168
5735 for (i = 0; i < host->n_ports; i++) { 6169 err_out:
6170 while (--i >= 0) {
5736 struct ata_port *ap = host->ports[i]; 6171 struct ata_port *ap = host->ports[i];
5737 6172
5738 if (ap) 6173 if (ap->ops->port_stop)
5739 scsi_host_put(ap->scsi_host); 6174 ap->ops->port_stop(ap);
5740
5741 host->ports[i] = NULL;
5742 } 6175 }
5743 6176 return rc;
5744 dev_set_drvdata(gendev, NULL);
5745} 6177}
5746 6178
5747/** 6179/**
@@ -5755,7 +6187,7 @@ static void ata_host_release(struct device *gendev, void *res)
5755 * PCI/etc. bus probe sem. 6187 * PCI/etc. bus probe sem.
5756 * 6188 *
5757 */ 6189 */
5758 6190/* KILLME - the only user left is ipr */
5759void ata_host_init(struct ata_host *host, struct device *dev, 6191void ata_host_init(struct ata_host *host, struct device *dev,
5760 unsigned long flags, const struct ata_port_operations *ops) 6192 unsigned long flags, const struct ata_port_operations *ops)
5761{ 6193{
@@ -5766,155 +6198,95 @@ void ata_host_init(struct ata_host *host, struct device *dev,
5766} 6198}
5767 6199
5768/** 6200/**
5769 * ata_device_add - Register hardware device with ATA and SCSI layers 6201 * ata_host_register - register initialized ATA host
5770 * @ent: Probe information describing hardware device to be registered 6202 * @host: ATA host to register
6203 * @sht: template for SCSI host
5771 * 6204 *
5772 * This function processes the information provided in the probe 6205 * Register initialized ATA host. @host is allocated using
5773 * information struct @ent, allocates the necessary ATA and SCSI 6206 * ata_host_alloc() and fully initialized by LLD. This function
5774 * host information structures, initializes them, and registers 6207 * starts ports, registers @host with ATA and SCSI layers and
5775 * everything with requisite kernel subsystems. 6208 * probe registered devices.
5776 *
5777 * This function requests irqs, probes the ATA bus, and probes
5778 * the SCSI bus.
5779 * 6209 *
5780 * LOCKING: 6210 * LOCKING:
5781 * PCI/etc. bus probe sem. 6211 * Inherited from calling layer (may sleep).
5782 * 6212 *
5783 * RETURNS: 6213 * RETURNS:
5784 * Number of ports registered. Zero on error (no ports registered). 6214 * 0 on success, -errno otherwise.
5785 */ 6215 */
5786int ata_device_add(const struct ata_probe_ent *ent) 6216int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
5787{ 6217{
5788 unsigned int i; 6218 int i, rc;
5789 struct device *dev = ent->dev;
5790 struct ata_host *host;
5791 int rc;
5792
5793 DPRINTK("ENTER\n");
5794 6219
5795 if (ent->irq == 0) { 6220 /* host must have been started */
5796 dev_printk(KERN_ERR, dev, "is not available: No interrupt assigned.\n"); 6221 if (!(host->flags & ATA_HOST_STARTED)) {
5797 return 0; 6222 dev_printk(KERN_ERR, host->dev,
6223 "BUG: trying to register unstarted host\n");
6224 WARN_ON(1);
6225 return -EINVAL;
5798 } 6226 }
5799 6227
5800 if (!devres_open_group(dev, ata_device_add, GFP_KERNEL)) 6228 /* Blow away unused ports. This happens when LLD can't
5801 return 0; 6229 * determine the exact number of ports to allocate at
6230 * allocation time.
6231 */
6232 for (i = host->n_ports; host->ports[i]; i++)
6233 kfree(host->ports[i]);
5802 6234
5803 /* alloc a container for our list of ATA ports (buses) */ 6235 /* give ports names and add SCSI hosts */
5804 host = devres_alloc(ata_host_release, sizeof(struct ata_host) + 6236 for (i = 0; i < host->n_ports; i++)
5805 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 6237 host->ports[i]->print_id = ata_print_id++;
5806 if (!host)
5807 goto err_out;
5808 devres_add(dev, host);
5809 dev_set_drvdata(dev, host);
5810 6238
5811 ata_host_init(host, dev, ent->_host_flags, ent->port_ops); 6239 rc = ata_scsi_add_hosts(host, sht);
5812 host->n_ports = ent->n_ports; 6240 if (rc)
5813 host->irq = ent->irq; 6241 return rc;
5814 host->irq2 = ent->irq2;
5815 host->iomap = ent->iomap;
5816 host->private_data = ent->private_data;
5817 6242
5818 /* register each port bound to this device */ 6243 /* set cable, sata_spd_limit and report */
5819 for (i = 0; i < host->n_ports; i++) { 6244 for (i = 0; i < host->n_ports; i++) {
5820 struct ata_port *ap; 6245 struct ata_port *ap = host->ports[i];
5821 unsigned long xfer_mode_mask; 6246 int irq_line;
5822 int irq_line = ent->irq; 6247 u32 scontrol;
6248 unsigned long xfer_mask;
5823 6249
5824 ap = ata_port_add(ent, host, i); 6250 /* set SATA cable type if still unset */
5825 host->ports[i] = ap; 6251 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA))
5826 if (!ap) 6252 ap->cbl = ATA_CBL_SATA;
5827 goto err_out;
5828 6253
5829 /* dummy? */ 6254 /* init sata_spd_limit to the current value */
5830 if (ent->dummy_port_mask & (1 << i)) { 6255 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
5831 ata_port_printk(ap, KERN_INFO, "DUMMY\n"); 6256 int spd = (scontrol >> 4) & 0xf;
5832 ap->ops = &ata_dummy_port_ops; 6257 ap->hw_sata_spd_limit &= (1 << spd) - 1;
5833 continue;
5834 }
5835
5836 /* start port */
5837 rc = ap->ops->port_start(ap);
5838 if (rc) {
5839 host->ports[i] = NULL;
5840 scsi_host_put(ap->scsi_host);
5841 goto err_out;
5842 } 6258 }
6259 ap->sata_spd_limit = ap->hw_sata_spd_limit;
5843 6260
5844 /* Report the secondary IRQ for second channel legacy */ 6261 /* report the secondary IRQ for second channel legacy */
5845 if (i == 1 && ent->irq2) 6262 irq_line = host->irq;
5846 irq_line = ent->irq2; 6263 if (i == 1 && host->irq2)
6264 irq_line = host->irq2;
5847 6265
5848 xfer_mode_mask =(ap->udma_mask << ATA_SHIFT_UDMA) | 6266 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
5849 (ap->mwdma_mask << ATA_SHIFT_MWDMA) | 6267 ap->udma_mask);
5850 (ap->pio_mask << ATA_SHIFT_PIO);
5851 6268
5852 /* print per-port info to dmesg */ 6269 /* print per-port info to dmesg */
5853 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p " 6270 if (!ata_port_is_dummy(ap))
5854 "ctl 0x%p bmdma 0x%p irq %d\n", 6271 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
5855 ap->flags & ATA_FLAG_SATA ? 'S' : 'P', 6272 "ctl 0x%p bmdma 0x%p irq %d\n",
5856 ata_mode_string(xfer_mode_mask), 6273 ap->cbl == ATA_CBL_SATA ? 'S' : 'P',
5857 ap->ioaddr.cmd_addr, 6274 ata_mode_string(xfer_mask),
5858 ap->ioaddr.ctl_addr, 6275 ap->ioaddr.cmd_addr,
5859 ap->ioaddr.bmdma_addr, 6276 ap->ioaddr.ctl_addr,
5860 irq_line); 6277 ap->ioaddr.bmdma_addr,
5861 6278 irq_line);
5862 /* freeze port before requesting IRQ */ 6279 else
5863 ata_eh_freeze_port(ap); 6280 ata_port_printk(ap, KERN_INFO, "DUMMY\n");
5864 }
5865
5866 /* obtain irq, that may be shared between channels */
5867 rc = devm_request_irq(dev, ent->irq, ent->port_ops->irq_handler,
5868 ent->irq_flags, DRV_NAME, host);
5869 if (rc) {
5870 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n",
5871 ent->irq, rc);
5872 goto err_out;
5873 }
5874
5875 /* do we have a second IRQ for the other channel, eg legacy mode */
5876 if (ent->irq2) {
5877 /* We will get weird core code crashes later if this is true
5878 so trap it now */
5879 BUG_ON(ent->irq == ent->irq2);
5880
5881 rc = devm_request_irq(dev, ent->irq2,
5882 ent->port_ops->irq_handler, ent->irq_flags,
5883 DRV_NAME, host);
5884 if (rc) {
5885 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n",
5886 ent->irq2, rc);
5887 goto err_out;
5888 }
5889 } 6281 }
5890 6282
5891 /* resource acquisition complete */
5892 devres_remove_group(dev, ata_device_add);
5893
5894 /* perform each probe synchronously */ 6283 /* perform each probe synchronously */
5895 DPRINTK("probe begin\n"); 6284 DPRINTK("probe begin\n");
5896 for (i = 0; i < host->n_ports; i++) { 6285 for (i = 0; i < host->n_ports; i++) {
5897 struct ata_port *ap = host->ports[i]; 6286 struct ata_port *ap = host->ports[i];
5898 u32 scontrol;
5899 int rc; 6287 int rc;
5900 6288
5901 /* init sata_spd_limit to the current value */ 6289 /* probe */
5902 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
5903 int spd = (scontrol >> 4) & 0xf;
5904 ap->hw_sata_spd_limit &= (1 << spd) - 1;
5905 }
5906 ap->sata_spd_limit = ap->hw_sata_spd_limit;
5907
5908 rc = scsi_add_host(ap->scsi_host, dev);
5909 if (rc) {
5910 ata_port_printk(ap, KERN_ERR, "scsi_add_host failed\n");
5911 /* FIXME: do something useful here */
5912 /* FIXME: handle unconditional calls to
5913 * scsi_scan_host and ata_host_remove, below,
5914 * at the very least
5915 */
5916 }
5917
5918 if (ap->ops->error_handler) { 6290 if (ap->ops->error_handler) {
5919 struct ata_eh_info *ehi = &ap->eh_info; 6291 struct ata_eh_info *ehi = &ap->eh_info;
5920 unsigned long flags; 6292 unsigned long flags;
@@ -5959,16 +6331,52 @@ int ata_device_add(const struct ata_probe_ent *ent)
5959 ata_scsi_scan_host(ap); 6331 ata_scsi_scan_host(ap);
5960 } 6332 }
5961 6333
5962 VPRINTK("EXIT, returning %u\n", ent->n_ports);
5963 return ent->n_ports; /* success */
5964
5965 err_out:
5966 devres_release_group(dev, ata_device_add);
5967 VPRINTK("EXIT, returning %d\n", rc);
5968 return 0; 6334 return 0;
5969} 6335}
5970 6336
5971/** 6337/**
6338 * ata_host_activate - start host, request IRQ and register it
6339 * @host: target ATA host
6340 * @irq: IRQ to request
6341 * @irq_handler: irq_handler used when requesting IRQ
6342 * @irq_flags: irq_flags used when requesting IRQ
6343 * @sht: scsi_host_template to use when registering the host
6344 *
6345 * After allocating an ATA host and initializing it, most libata
6346 * LLDs perform three steps to activate the host - start host,
6347 * request IRQ and register it. This helper takes necessasry
6348 * arguments and performs the three steps in one go.
6349 *
6350 * LOCKING:
6351 * Inherited from calling layer (may sleep).
6352 *
6353 * RETURNS:
6354 * 0 on success, -errno otherwise.
6355 */
6356int ata_host_activate(struct ata_host *host, int irq,
6357 irq_handler_t irq_handler, unsigned long irq_flags,
6358 struct scsi_host_template *sht)
6359{
6360 int rc;
6361
6362 rc = ata_host_start(host);
6363 if (rc)
6364 return rc;
6365
6366 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags,
6367 dev_driver_string(host->dev), host);
6368 if (rc)
6369 return rc;
6370
6371 rc = ata_host_register(host, sht);
6372 /* if failed, just free the IRQ and leave ports alone */
6373 if (rc)
6374 devm_free_irq(host->dev, irq, host);
6375
6376 return rc;
6377}
6378
6379/**
5972 * ata_port_detach - Detach ATA port in prepration of device removal 6380 * ata_port_detach - Detach ATA port in prepration of device removal
5973 * @ap: ATA port to be detached 6381 * @ap: ATA port to be detached
5974 * 6382 *
@@ -6043,32 +6451,6 @@ void ata_host_detach(struct ata_host *host)
6043 ata_port_detach(host->ports[i]); 6451 ata_port_detach(host->ports[i]);
6044} 6452}
6045 6453
6046struct ata_probe_ent *
6047ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
6048{
6049 struct ata_probe_ent *probe_ent;
6050
6051 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
6052 if (!probe_ent) {
6053 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
6054 kobject_name(&(dev->kobj)));
6055 return NULL;
6056 }
6057
6058 INIT_LIST_HEAD(&probe_ent->node);
6059 probe_ent->dev = dev;
6060
6061 probe_ent->sht = port->sht;
6062 probe_ent->port_flags = port->flags;
6063 probe_ent->pio_mask = port->pio_mask;
6064 probe_ent->mwdma_mask = port->mwdma_mask;
6065 probe_ent->udma_mask = port->udma_mask;
6066 probe_ent->port_ops = port->port_ops;
6067 probe_ent->private_data = port->private_data;
6068
6069 return probe_ent;
6070}
6071
6072/** 6454/**
6073 * ata_std_ports - initialize ioaddr with standard port offsets. 6455 * ata_std_ports - initialize ioaddr with standard port offsets.
6074 * @ioaddr: IO address structure to be initialized 6456 * @ioaddr: IO address structure to be initialized
@@ -6334,6 +6716,10 @@ const struct ata_port_operations ata_dummy_port_ops = {
6334 .port_stop = ata_dummy_noret, 6716 .port_stop = ata_dummy_noret,
6335}; 6717};
6336 6718
6719const struct ata_port_info ata_dummy_port_info = {
6720 .port_ops = &ata_dummy_port_ops,
6721};
6722
6337/* 6723/*
6338 * libata is essentially a library of internal helper functions for 6724 * libata is essentially a library of internal helper functions for
6339 * low-level ATA host controller drivers. As such, the API/ABI is 6725 * low-level ATA host controller drivers. As such, the API/ABI is
@@ -6345,10 +6731,15 @@ EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
6345EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); 6731EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
6346EXPORT_SYMBOL_GPL(sata_deb_timing_long); 6732EXPORT_SYMBOL_GPL(sata_deb_timing_long);
6347EXPORT_SYMBOL_GPL(ata_dummy_port_ops); 6733EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6734EXPORT_SYMBOL_GPL(ata_dummy_port_info);
6348EXPORT_SYMBOL_GPL(ata_std_bios_param); 6735EXPORT_SYMBOL_GPL(ata_std_bios_param);
6349EXPORT_SYMBOL_GPL(ata_std_ports); 6736EXPORT_SYMBOL_GPL(ata_std_ports);
6350EXPORT_SYMBOL_GPL(ata_host_init); 6737EXPORT_SYMBOL_GPL(ata_host_init);
6351EXPORT_SYMBOL_GPL(ata_device_add); 6738EXPORT_SYMBOL_GPL(ata_host_alloc);
6739EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
6740EXPORT_SYMBOL_GPL(ata_host_start);
6741EXPORT_SYMBOL_GPL(ata_host_register);
6742EXPORT_SYMBOL_GPL(ata_host_activate);
6352EXPORT_SYMBOL_GPL(ata_host_detach); 6743EXPORT_SYMBOL_GPL(ata_host_detach);
6353EXPORT_SYMBOL_GPL(ata_sg_init); 6744EXPORT_SYMBOL_GPL(ata_sg_init);
6354EXPORT_SYMBOL_GPL(ata_sg_init_one); 6745EXPORT_SYMBOL_GPL(ata_sg_init_one);
@@ -6360,6 +6751,7 @@ EXPORT_SYMBOL_GPL(ata_tf_load);
6360EXPORT_SYMBOL_GPL(ata_tf_read); 6751EXPORT_SYMBOL_GPL(ata_tf_read);
6361EXPORT_SYMBOL_GPL(ata_noop_dev_select); 6752EXPORT_SYMBOL_GPL(ata_noop_dev_select);
6362EXPORT_SYMBOL_GPL(ata_std_dev_select); 6753EXPORT_SYMBOL_GPL(ata_std_dev_select);
6754EXPORT_SYMBOL_GPL(sata_print_link_status);
6363EXPORT_SYMBOL_GPL(ata_tf_to_fis); 6755EXPORT_SYMBOL_GPL(ata_tf_to_fis);
6364EXPORT_SYMBOL_GPL(ata_tf_from_fis); 6756EXPORT_SYMBOL_GPL(ata_tf_from_fis);
6365EXPORT_SYMBOL_GPL(ata_check_status); 6757EXPORT_SYMBOL_GPL(ata_check_status);
@@ -6367,6 +6759,7 @@ EXPORT_SYMBOL_GPL(ata_altstatus);
6367EXPORT_SYMBOL_GPL(ata_exec_command); 6759EXPORT_SYMBOL_GPL(ata_exec_command);
6368EXPORT_SYMBOL_GPL(ata_port_start); 6760EXPORT_SYMBOL_GPL(ata_port_start);
6369EXPORT_SYMBOL_GPL(ata_interrupt); 6761EXPORT_SYMBOL_GPL(ata_interrupt);
6762EXPORT_SYMBOL_GPL(ata_do_set_mode);
6370EXPORT_SYMBOL_GPL(ata_data_xfer); 6763EXPORT_SYMBOL_GPL(ata_data_xfer);
6371EXPORT_SYMBOL_GPL(ata_data_xfer_noirq); 6764EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
6372EXPORT_SYMBOL_GPL(ata_qc_prep); 6765EXPORT_SYMBOL_GPL(ata_qc_prep);
@@ -6429,7 +6822,8 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
6429 6822
6430#ifdef CONFIG_PCI 6823#ifdef CONFIG_PCI
6431EXPORT_SYMBOL_GPL(pci_test_config_bits); 6824EXPORT_SYMBOL_GPL(pci_test_config_bits);
6432EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 6825EXPORT_SYMBOL_GPL(ata_pci_init_native_host);
6826EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host);
6433EXPORT_SYMBOL_GPL(ata_pci_init_one); 6827EXPORT_SYMBOL_GPL(ata_pci_init_one);
6434EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6828EXPORT_SYMBOL_GPL(ata_pci_remove_one);
6435#ifdef CONFIG_PM 6829#ifdef CONFIG_PM
@@ -6461,3 +6855,8 @@ EXPORT_SYMBOL_GPL(ata_dummy_irq_on);
6461EXPORT_SYMBOL_GPL(ata_irq_ack); 6855EXPORT_SYMBOL_GPL(ata_irq_ack);
6462EXPORT_SYMBOL_GPL(ata_dummy_irq_ack); 6856EXPORT_SYMBOL_GPL(ata_dummy_irq_ack);
6463EXPORT_SYMBOL_GPL(ata_dev_try_classify); 6857EXPORT_SYMBOL_GPL(ata_dev_try_classify);
6858
6859EXPORT_SYMBOL_GPL(ata_cable_40wire);
6860EXPORT_SYMBOL_GPL(ata_cable_80wire);
6861EXPORT_SYMBOL_GPL(ata_cable_unknown);
6862EXPORT_SYMBOL_GPL(ata_cable_sata);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 39f556c02992..2bff9adcacf1 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1056,7 +1056,7 @@ static void ata_eh_analyze_serror(struct ata_port *ap)
1056 } 1056 }
1057 if (serror & SERR_INTERNAL) { 1057 if (serror & SERR_INTERNAL) {
1058 err_mask |= AC_ERR_SYSTEM; 1058 err_mask |= AC_ERR_SYSTEM;
1059 action |= ATA_EH_SOFTRESET; 1059 action |= ATA_EH_HARDRESET;
1060 } 1060 }
1061 if (serror & (SERR_PHYRDY_CHG | SERR_DEV_XCHG)) 1061 if (serror & (SERR_PHYRDY_CHG | SERR_DEV_XCHG))
1062 ata_ehi_hotplugged(&ehc->i); 1062 ata_ehi_hotplugged(&ehc->i);
@@ -1151,7 +1151,9 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1151 return ATA_EH_SOFTRESET; 1151 return ATA_EH_SOFTRESET;
1152 } 1152 }
1153 1153
1154 if (!(qc->err_mask & AC_ERR_DEV)) 1154 if (stat & (ATA_ERR | ATA_DF))
1155 qc->err_mask |= AC_ERR_DEV;
1156 else
1155 return 0; 1157 return 0;
1156 1158
1157 switch (qc->dev->class) { 1159 switch (qc->dev->class) {
@@ -1669,7 +1671,10 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1669 reset == softreset ? "soft" : "hard"); 1671 reset == softreset ? "soft" : "hard");
1670 1672
1671 /* mark that this EH session started with reset */ 1673 /* mark that this EH session started with reset */
1672 ehc->i.flags |= ATA_EHI_DID_RESET; 1674 if (reset == hardreset)
1675 ehc->i.flags |= ATA_EHI_DID_HARDRESET;
1676 else
1677 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
1673 1678
1674 rc = ata_do_reset(ap, reset, classes); 1679 rc = ata_do_reset(ap, reset, classes);
1675 1680
@@ -1808,6 +1813,10 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1808 } 1813 }
1809 } 1814 }
1810 1815
1816 /* PDIAG- should have been released, ask cable type if post-reset */
1817 if ((ehc->i.flags & ATA_EHI_DID_RESET) && ap->ops->cable_detect)
1818 ap->cbl = ap->ops->cable_detect(ap);
1819
1811 /* Configure new devices forward such that user doesn't see 1820 /* Configure new devices forward such that user doesn't see
1812 * device detection messages backwards. 1821 * device detection messages backwards.
1813 */ 1822 */
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index e9364434182c..9afba2ba489e 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -104,7 +104,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
104 * libata transport template. libata doesn't do real transport stuff. 104 * libata transport template. libata doesn't do real transport stuff.
105 * It just needs the eh_timed_out hook. 105 * It just needs the eh_timed_out hook.
106 */ 106 */
107struct scsi_transport_template ata_scsi_transport_template = { 107static struct scsi_transport_template ata_scsi_transport_template = {
108 .eh_strategy_handler = ata_scsi_error, 108 .eh_strategy_handler = ata_scsi_error,
109 .eh_timed_out = ata_scsi_timed_out, 109 .eh_timed_out = ata_scsi_timed_out,
110 .user_scan = ata_scsi_user_scan, 110 .user_scan = ata_scsi_user_scan,
@@ -2678,6 +2678,18 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2678 tf->device = qc->dev->devno ? 2678 tf->device = qc->dev->devno ?
2679 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; 2679 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1;
2680 2680
2681 /* READ/WRITE LONG use a non-standard sect_size */
2682 qc->sect_size = ATA_SECT_SIZE;
2683 switch (tf->command) {
2684 case ATA_CMD_READ_LONG:
2685 case ATA_CMD_READ_LONG_ONCE:
2686 case ATA_CMD_WRITE_LONG:
2687 case ATA_CMD_WRITE_LONG_ONCE:
2688 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1)
2689 goto invalid_fld;
2690 qc->sect_size = scmd->request_bufflen;
2691 }
2692
2681 /* 2693 /*
2682 * Filter SET_FEATURES - XFER MODE command -- otherwise, 2694 * Filter SET_FEATURES - XFER MODE command -- otherwise,
2683 * SET_FEATURES - XFER MODE must be preceded/succeeded 2695 * SET_FEATURES - XFER MODE must be preceded/succeeded
@@ -2792,8 +2804,9 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
2792{ 2804{
2793 int rc = 0; 2805 int rc = 0;
2794 2806
2795 if (unlikely(!scmd->cmd_len)) { 2807 if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) {
2796 ata_dev_printk(dev, KERN_WARNING, "WARNING: zero len CDB\n"); 2808 DPRINTK("bad CDB len=%u, max=%u\n",
2809 scmd->cmd_len, dev->cdb_len);
2797 scmd->result = DID_ERROR << 16; 2810 scmd->result = DID_ERROR << 16;
2798 done(scmd); 2811 done(scmd);
2799 return 0; 2812 return 0;
@@ -2948,6 +2961,48 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
2948 } 2961 }
2949} 2962}
2950 2963
2964int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
2965{
2966 int i, rc;
2967
2968 for (i = 0; i < host->n_ports; i++) {
2969 struct ata_port *ap = host->ports[i];
2970 struct Scsi_Host *shost;
2971
2972 rc = -ENOMEM;
2973 shost = scsi_host_alloc(sht, sizeof(struct ata_port *));
2974 if (!shost)
2975 goto err_alloc;
2976
2977 *(struct ata_port **)&shost->hostdata[0] = ap;
2978 ap->scsi_host = shost;
2979
2980 shost->transportt = &ata_scsi_transport_template;
2981 shost->unique_id = ap->print_id;
2982 shost->max_id = 16;
2983 shost->max_lun = 1;
2984 shost->max_channel = 1;
2985 shost->max_cmd_len = 16;
2986
2987 rc = scsi_add_host(ap->scsi_host, ap->host->dev);
2988 if (rc)
2989 goto err_add;
2990 }
2991
2992 return 0;
2993
2994 err_add:
2995 scsi_host_put(host->ports[i]->scsi_host);
2996 err_alloc:
2997 while (--i >= 0) {
2998 struct Scsi_Host *shost = host->ports[i]->scsi_host;
2999
3000 scsi_remove_host(shost);
3001 scsi_host_put(shost);
3002 }
3003 return rc;
3004}
3005
2951void ata_scsi_scan_host(struct ata_port *ap) 3006void ata_scsi_scan_host(struct ata_port *ap)
2952{ 3007{
2953 unsigned int i; 3008 unsigned int i;
@@ -3224,21 +3279,21 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host,
3224 struct ata_port_info *port_info, 3279 struct ata_port_info *port_info,
3225 struct Scsi_Host *shost) 3280 struct Scsi_Host *shost)
3226{ 3281{
3227 struct ata_port *ap = kzalloc(sizeof(*ap), GFP_KERNEL); 3282 struct ata_port *ap;
3228 struct ata_probe_ent *ent;
3229 3283
3284 ap = ata_port_alloc(host);
3230 if (!ap) 3285 if (!ap)
3231 return NULL; 3286 return NULL;
3232 3287
3233 ent = ata_probe_ent_alloc(host->dev, port_info); 3288 ap->port_no = 0;
3234 if (!ent) {
3235 kfree(ap);
3236 return NULL;
3237 }
3238
3239 ata_port_init(ap, host, ent, 0);
3240 ap->lock = shost->host_lock; 3289 ap->lock = shost->host_lock;
3241 devm_kfree(host->dev, ent); 3290 ap->pio_mask = port_info->pio_mask;
3291 ap->mwdma_mask = port_info->mwdma_mask;
3292 ap->udma_mask = port_info->udma_mask;
3293 ap->flags |= port_info->flags;
3294 ap->ops = port_info->port_ops;
3295 ap->cbl = ATA_CBL_SATA;
3296
3242 return ap; 3297 return ap;
3243} 3298}
3244EXPORT_SYMBOL_GPL(ata_sas_port_alloc); 3299EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
@@ -3294,8 +3349,10 @@ int ata_sas_port_init(struct ata_port *ap)
3294{ 3349{
3295 int rc = ap->ops->port_start(ap); 3350 int rc = ap->ops->port_start(ap);
3296 3351
3297 if (!rc) 3352 if (!rc) {
3353 ap->print_id = ata_print_id++;
3298 rc = ata_bus_probe(ap); 3354 rc = ata_bus_probe(ap);
3355 }
3299 3356
3300 return rc; 3357 return rc;
3301} 3358}
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 2ffcca063d80..8af18ad1ca7f 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -526,168 +526,399 @@ static int ata_resources_present(struct pci_dev *pdev, int port)
526 port = port * 2; 526 port = port * 2;
527 for (i = 0; i < 2; i ++) { 527 for (i = 0; i < 2; i ++) {
528 if (pci_resource_start(pdev, port + i) == 0 || 528 if (pci_resource_start(pdev, port + i) == 0 ||
529 pci_resource_len(pdev, port + i) == 0) 529 pci_resource_len(pdev, port + i) == 0)
530 return 0; 530 return 0;
531 } 531 }
532 return 1; 532 return 1;
533} 533}
534 534
535/** 535/**
536 * ata_pci_init_native_mode - Initialize native-mode driver 536 * ata_pci_init_bmdma - acquire PCI BMDMA resources and init ATA host
537 * @pdev: pci device to be initialized 537 * @host: target ATA host
538 * @port: array[2] of pointers to port info structures. 538 *
539 * @ports: bitmap of ports present 539 * Acquire PCI BMDMA resources and initialize @host accordingly.
540 * 540 *
541 * Utility function which allocates and initializes an 541 * LOCKING:
542 * ata_probe_ent structure for a standard dual-port 542 * Inherited from calling layer (may sleep).
543 * PIO-based IDE controller. The returned ata_probe_ent 543 *
544 * structure can be passed to ata_device_add(). The returned 544 * RETURNS:
545 * ata_probe_ent structure should then be freed with kfree(). 545 * 0 on success, -errno otherwise.
546 *
547 * The caller need only pass the address of the primary port, the
548 * secondary will be deduced automatically. If the device has non
549 * standard secondary port mappings this function can be called twice,
550 * once for each interface.
551 */ 546 */
547static int ata_pci_init_bmdma(struct ata_host *host)
548{
549 struct device *gdev = host->dev;
550 struct pci_dev *pdev = to_pci_dev(gdev);
551 int i, rc;
552
553 /* TODO: If we get no DMA mask we should fall back to PIO */
554 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
555 if (rc)
556 return rc;
557 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
558 if (rc)
559 return rc;
560
561 /* request and iomap DMA region */
562 rc = pcim_iomap_regions(pdev, 1 << 4, DRV_NAME);
563 if (rc) {
564 dev_printk(KERN_ERR, gdev, "failed to request/iomap BAR4\n");
565 return -ENOMEM;
566 }
567 host->iomap = pcim_iomap_table(pdev);
568
569 for (i = 0; i < 2; i++) {
570 struct ata_port *ap = host->ports[i];
571 void __iomem *bmdma = host->iomap[4] + 8 * i;
572
573 if (ata_port_is_dummy(ap))
574 continue;
575
576 ap->ioaddr.bmdma_addr = bmdma;
577 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) &&
578 (ioread8(bmdma + 2) & 0x80))
579 host->flags |= ATA_HOST_SIMPLEX;
580 }
581
582 return 0;
583}
552 584
553struct ata_probe_ent * 585/**
554ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports) 586 * ata_pci_init_native_host - acquire native ATA resources and init host
587 * @host: target ATA host
588 * @port_mask: ports to consider
589 *
590 * Acquire native PCI ATA resources for @host and initialize
591 * @host accordoingly.
592 *
593 * LOCKING:
594 * Inherited from calling layer (may sleep).
595 *
596 * RETURNS:
597 * 0 on success, -errno otherwise.
598 */
599int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
555{ 600{
556 struct ata_probe_ent *probe_ent; 601 struct device *gdev = host->dev;
557 int i, p = 0; 602 struct pci_dev *pdev = to_pci_dev(gdev);
558 void __iomem * const *iomap; 603 int i, rc;
559 604
560 /* iomap BARs */ 605 /* Discard disabled ports. Some controllers show their unused
561 for (i = 0; i < 4; i++) { 606 * channels this way. Disabled ports are made dummy.
562 if (pcim_iomap(pdev, i, 0) == NULL) { 607 */
563 dev_printk(KERN_ERR, &pdev->dev, 608 for (i = 0; i < 2; i++) {
564 "failed to iomap PCI BAR %d\n", i); 609 if ((port_mask & (1 << i)) && !ata_resources_present(pdev, i)) {
565 return NULL; 610 host->ports[i]->ops = &ata_dummy_port_ops;
611 port_mask &= ~(1 << i);
566 } 612 }
567 } 613 }
568 614
569 pcim_iomap(pdev, 4, 0); /* may fail */ 615 if (!port_mask) {
570 iomap = pcim_iomap_table(pdev); 616 dev_printk(KERN_ERR, gdev, "no available port\n");
571 617 return -ENODEV;
572 /* alloc and init probe_ent */
573 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
574 if (!probe_ent)
575 return NULL;
576
577 probe_ent->irq = pdev->irq;
578 probe_ent->irq_flags = IRQF_SHARED;
579
580 /* Discard disabled ports. Some controllers show their
581 unused channels this way */
582 if (ata_resources_present(pdev, 0) == 0)
583 ports &= ~ATA_PORT_PRIMARY;
584 if (ata_resources_present(pdev, 1) == 0)
585 ports &= ~ATA_PORT_SECONDARY;
586
587 if (ports & ATA_PORT_PRIMARY) {
588 probe_ent->port[p].cmd_addr = iomap[0];
589 probe_ent->port[p].altstatus_addr =
590 probe_ent->port[p].ctl_addr = (void __iomem *)
591 ((unsigned long)iomap[1] | ATA_PCI_CTL_OFS);
592 if (iomap[4]) {
593 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
594 (ioread8(iomap[4] + 2) & 0x80))
595 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
596 probe_ent->port[p].bmdma_addr = iomap[4];
597 }
598 ata_std_ports(&probe_ent->port[p]);
599 p++;
600 } 618 }
601 619
602 if (ports & ATA_PORT_SECONDARY) { 620 /* request, iomap BARs and init port addresses accordingly */
603 probe_ent->port[p].cmd_addr = iomap[2]; 621 for (i = 0; i < 2; i++) {
604 probe_ent->port[p].altstatus_addr = 622 struct ata_port *ap = host->ports[i];
605 probe_ent->port[p].ctl_addr = (void __iomem *) 623 int base = i * 2;
606 ((unsigned long)iomap[3] | ATA_PCI_CTL_OFS); 624 void __iomem * const *iomap;
607 if (iomap[4]) { 625
608 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) && 626 if (!(port_mask & (1 << i)))
609 (ioread8(iomap[4] + 10) & 0x80)) 627 continue;
610 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 628
611 probe_ent->port[p].bmdma_addr = iomap[4] + 8; 629 rc = pcim_iomap_regions(pdev, 0x3 << base, DRV_NAME);
630 if (rc) {
631 dev_printk(KERN_ERR, gdev, "failed to request/iomap "
632 "BARs for port %d (errno=%d)\n", i, rc);
633 if (rc == -EBUSY)
634 pcim_pin_device(pdev);
635 return rc;
612 } 636 }
613 ata_std_ports(&probe_ent->port[p]); 637 host->iomap = iomap = pcim_iomap_table(pdev);
614 probe_ent->pinfo2 = port[1]; 638
615 p++; 639 ap->ioaddr.cmd_addr = iomap[base];
640 ap->ioaddr.altstatus_addr =
641 ap->ioaddr.ctl_addr = (void __iomem *)
642 ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
643 ata_std_ports(&ap->ioaddr);
616 } 644 }
617 645
618 probe_ent->n_ports = p; 646 return 0;
619 return probe_ent;
620} 647}
621 648
622static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, 649/**
623 struct ata_port_info **port, int port_mask) 650 * ata_pci_prepare_native_host - helper to prepare native PCI ATA host
651 * @pdev: target PCI device
652 * @ppi: array of port_info
653 * @n_ports: number of ports to allocate
654 * @r_host: out argument for the initialized ATA host
655 *
656 * Helper to allocate ATA host for @pdev, acquire all native PCI
657 * resources and initialize it accordingly in one go.
658 *
659 * LOCKING:
660 * Inherited from calling layer (may sleep).
661 *
662 * RETURNS:
663 * 0 on success, -errno otherwise.
664 */
665int ata_pci_prepare_native_host(struct pci_dev *pdev,
666 const struct ata_port_info * const * ppi,
667 int n_ports, struct ata_host **r_host)
668{
669 struct ata_host *host;
670 unsigned int port_mask;
671 int rc;
672
673 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
674 return -ENOMEM;
675
676 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
677 if (!host) {
678 dev_printk(KERN_ERR, &pdev->dev,
679 "failed to allocate ATA host\n");
680 rc = -ENOMEM;
681 goto err_out;
682 }
683
684 port_mask = ATA_PORT_PRIMARY;
685 if (n_ports > 1)
686 port_mask |= ATA_PORT_SECONDARY;
687
688 rc = ata_pci_init_native_host(host, port_mask);
689 if (rc)
690 goto err_out;
691
692 /* init DMA related stuff */
693 rc = ata_pci_init_bmdma(host);
694 if (rc)
695 goto err_bmdma;
696
697 devres_remove_group(&pdev->dev, NULL);
698 *r_host = host;
699 return 0;
700
701 err_bmdma:
702 /* This is necessary because PCI and iomap resources are
703 * merged and releasing the top group won't release the
704 * acquired resources if some of those have been acquired
705 * before entering this function.
706 */
707 pcim_iounmap_regions(pdev, 0xf);
708 err_out:
709 devres_release_group(&pdev->dev, NULL);
710 return rc;
711}
712
713struct ata_legacy_devres {
714 unsigned int mask;
715 unsigned long cmd_port[2];
716 void __iomem * cmd_addr[2];
717 void __iomem * ctl_addr[2];
718 unsigned int irq[2];
719 void * irq_dev_id[2];
720};
721
722static void ata_legacy_free_irqs(struct ata_legacy_devres *legacy_dr)
624{ 723{
625 struct ata_probe_ent *probe_ent; 724 int i;
626 void __iomem *iomap[5] = { }, *bmdma; 725
627 726 for (i = 0; i < 2; i++) {
628 if (port_mask & ATA_PORT_PRIMARY) { 727 if (!legacy_dr->irq[i])
629 iomap[0] = devm_ioport_map(&pdev->dev, ATA_PRIMARY_CMD, 8); 728 continue;
630 iomap[1] = devm_ioport_map(&pdev->dev, ATA_PRIMARY_CTL, 1); 729
631 if (!iomap[0] || !iomap[1]) 730 free_irq(legacy_dr->irq[i], legacy_dr->irq_dev_id[i]);
632 return NULL; 731 legacy_dr->irq[i] = 0;
732 legacy_dr->irq_dev_id[i] = NULL;
633 } 733 }
734}
735
736static void ata_legacy_release(struct device *gdev, void *res)
737{
738 struct ata_legacy_devres *this = res;
739 int i;
634 740
635 if (port_mask & ATA_PORT_SECONDARY) { 741 ata_legacy_free_irqs(this);
636 iomap[2] = devm_ioport_map(&pdev->dev, ATA_SECONDARY_CMD, 8); 742
637 iomap[3] = devm_ioport_map(&pdev->dev, ATA_SECONDARY_CTL, 1); 743 for (i = 0; i < 2; i++) {
638 if (!iomap[2] || !iomap[3]) 744 if (this->cmd_addr[i])
639 return NULL; 745 ioport_unmap(this->cmd_addr[i]);
746 if (this->ctl_addr[i])
747 ioport_unmap(this->ctl_addr[i]);
748 if (this->cmd_port[i])
749 release_region(this->cmd_port[i], 8);
640 } 750 }
751}
641 752
642 bmdma = pcim_iomap(pdev, 4, 16); /* may fail */ 753static int ata_init_legacy_port(struct ata_port *ap,
643 754 struct ata_legacy_devres *legacy_dr)
644 /* alloc and init probe_ent */ 755{
645 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 756 struct ata_host *host = ap->host;
646 if (!probe_ent) 757 int port_no = ap->port_no;
647 return NULL; 758 unsigned long cmd_port, ctl_port;
648 759
649 probe_ent->n_ports = 2; 760 if (port_no == 0) {
650 probe_ent->irq_flags = IRQF_SHARED; 761 cmd_port = ATA_PRIMARY_CMD;
651 762 ctl_port = ATA_PRIMARY_CTL;
652 if (port_mask & ATA_PORT_PRIMARY) { 763 } else {
653 probe_ent->irq = ATA_PRIMARY_IRQ(pdev); 764 cmd_port = ATA_SECONDARY_CMD;
654 probe_ent->port[0].cmd_addr = iomap[0]; 765 ctl_port = ATA_SECONDARY_CTL;
655 probe_ent->port[0].altstatus_addr = 766 }
656 probe_ent->port[0].ctl_addr = iomap[1];
657 if (bmdma) {
658 probe_ent->port[0].bmdma_addr = bmdma;
659 if ((!(port[0]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
660 (ioread8(bmdma + 2) & 0x80))
661 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
662 }
663 ata_std_ports(&probe_ent->port[0]);
664 } else
665 probe_ent->dummy_port_mask |= ATA_PORT_PRIMARY;
666 767
667 if (port_mask & ATA_PORT_SECONDARY) { 768 /* request cmd_port */
668 if (probe_ent->irq) 769 if (request_region(cmd_port, 8, "libata"))
669 probe_ent->irq2 = ATA_SECONDARY_IRQ(pdev); 770 legacy_dr->cmd_port[port_no] = cmd_port;
771 else {
772 dev_printk(KERN_WARNING, host->dev,
773 "0x%0lX IDE port busy\n", cmd_port);
774 return -EBUSY;
775 }
776
777 /* iomap cmd and ctl ports */
778 legacy_dr->cmd_addr[port_no] = ioport_map(cmd_port, 8);
779 legacy_dr->ctl_addr[port_no] = ioport_map(ctl_port, 1);
780 if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no])
781 return -ENOMEM;
782
783 /* init IO addresses */
784 ap->ioaddr.cmd_addr = legacy_dr->cmd_addr[port_no];
785 ap->ioaddr.altstatus_addr = legacy_dr->ctl_addr[port_no];
786 ap->ioaddr.ctl_addr = legacy_dr->ctl_addr[port_no];
787 ata_std_ports(&ap->ioaddr);
788
789 return 0;
790}
791
792/**
793 * ata_init_legacy_host - acquire legacy ATA resources and init ATA host
794 * @host: target ATA host
795 * @legacy_mask: out parameter, mask indicating ports is in legacy mode
796 * @was_busy: out parameter, indicates whether any port was busy
797 *
798 * Acquire legacy ATA resources for ports.
799 *
800 * LOCKING:
801 * Inherited from calling layer (may sleep).
802 *
803 * RETURNS:
804 * 0 on success, -errno otherwise.
805 */
806static int ata_init_legacy_host(struct ata_host *host,
807 unsigned int *legacy_mask, int *was_busy)
808{
809 struct device *gdev = host->dev;
810 struct ata_legacy_devres *legacy_dr;
811 int i, rc;
812
813 if (!devres_open_group(gdev, NULL, GFP_KERNEL))
814 return -ENOMEM;
815
816 rc = -ENOMEM;
817 legacy_dr = devres_alloc(ata_legacy_release, sizeof(*legacy_dr),
818 GFP_KERNEL);
819 if (!legacy_dr)
820 goto err_out;
821 devres_add(gdev, legacy_dr);
822
823 for (i = 0; i < 2; i++) {
824 *legacy_mask &= ~(1 << i);
825 rc = ata_init_legacy_port(host->ports[i], legacy_dr);
826 if (rc == 0)
827 legacy_dr->mask |= 1 << i;
828 else if (rc == -EBUSY)
829 (*was_busy)++;
830 }
831
832 if (!legacy_dr->mask)
833 return -EBUSY;
834
835 for (i = 0; i < 2; i++)
836 if (!(legacy_dr->mask & (1 << i)))
837 host->ports[i]->ops = &ata_dummy_port_ops;
838
839 *legacy_mask |= legacy_dr->mask;
840
841 devres_remove_group(gdev, NULL);
842 return 0;
843
844 err_out:
845 devres_release_group(gdev, NULL);
846 return rc;
847}
848
849/**
850 * ata_request_legacy_irqs - request legacy ATA IRQs
851 * @host: target ATA host
852 * @handler: array of IRQ handlers
853 * @irq_flags: array of IRQ flags
854 * @dev_id: array of IRQ dev_ids
855 *
856 * Request legacy IRQs for non-dummy legacy ports in @host. All
857 * IRQ parameters are passed as array to allow ports to have
858 * separate IRQ handlers.
859 *
860 * LOCKING:
861 * Inherited from calling layer (may sleep).
862 *
863 * RETURNS:
864 * 0 on success, -errno otherwise.
865 */
866static int ata_request_legacy_irqs(struct ata_host *host,
867 irq_handler_t const *handler,
868 const unsigned int *irq_flags,
869 void * const *dev_id)
870{
871 struct device *gdev = host->dev;
872 struct ata_legacy_devres *legacy_dr;
873 int i, rc;
874
875 legacy_dr = devres_find(host->dev, ata_legacy_release, NULL, NULL);
876 BUG_ON(!legacy_dr);
877
878 for (i = 0; i < 2; i++) {
879 unsigned int irq;
880
881 /* FIXME: ATA_*_IRQ() should take generic device not pci_dev */
882 if (i == 0)
883 irq = ATA_PRIMARY_IRQ(to_pci_dev(gdev));
670 else 884 else
671 probe_ent->irq = ATA_SECONDARY_IRQ(pdev); 885 irq = ATA_SECONDARY_IRQ(to_pci_dev(gdev));
672 probe_ent->port[1].cmd_addr = iomap[2]; 886
673 probe_ent->port[1].altstatus_addr = 887 if (!(legacy_dr->mask & (1 << i)))
674 probe_ent->port[1].ctl_addr = iomap[3]; 888 continue;
675 if (bmdma) { 889
676 probe_ent->port[1].bmdma_addr = bmdma + 8; 890 if (!handler[i]) {
677 if ((!(port[1]->flags & ATA_FLAG_IGN_SIMPLEX)) && 891 dev_printk(KERN_ERR, gdev,
678 (ioread8(bmdma + 10) & 0x80)) 892 "NULL handler specified for port %d\n", i);
679 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 893 rc = -EINVAL;
894 goto err_out;
895 }
896
897 rc = request_irq(irq, handler[i], irq_flags[i], DRV_NAME,
898 dev_id[i]);
899 if (rc) {
900 dev_printk(KERN_ERR, gdev,
901 "irq %u request failed (errno=%d)\n", irq, rc);
902 goto err_out;
680 } 903 }
681 ata_std_ports(&probe_ent->port[1]);
682 904
683 /* FIXME: could be pointing to stack area; must copy */ 905 /* record irq allocation in legacy_dr */
684 probe_ent->pinfo2 = port[1]; 906 legacy_dr->irq[i] = irq;
685 } else 907 legacy_dr->irq_dev_id[i] = dev_id[i];
686 probe_ent->dummy_port_mask |= ATA_PORT_SECONDARY;
687 908
688 return probe_ent; 909 /* only used to print info */
689} 910 if (i == 0)
911 host->irq = irq;
912 else
913 host->irq2 = irq;
914 }
690 915
916 return 0;
917
918 err_out:
919 ata_legacy_free_irqs(legacy_dr);
920 return rc;
921}
691 922
692/** 923/**
693 * ata_pci_init_one - Initialize/register PCI IDE host controller 924 * ata_pci_init_one - Initialize/register PCI IDE host controller
@@ -718,8 +949,8 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
718 unsigned int n_ports) 949 unsigned int n_ports)
719{ 950{
720 struct device *dev = &pdev->dev; 951 struct device *dev = &pdev->dev;
721 struct ata_probe_ent *probe_ent = NULL; 952 struct ata_host *host = NULL;
722 struct ata_port_info *port[2]; 953 const struct ata_port_info *port[2];
723 u8 mask; 954 u8 mask;
724 unsigned int legacy_mode = 0; 955 unsigned int legacy_mode = 0;
725 int rc; 956 int rc;
@@ -743,7 +974,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
743 974
744 Checking dev->is_enabled is insufficient as this is not set at 975 Checking dev->is_enabled is insufficient as this is not set at
745 boot for the primary video which is BIOS enabled 976 boot for the primary video which is BIOS enabled
746 */ 977 */
747 978
748 rc = pcim_enable_device(pdev); 979 rc = pcim_enable_device(pdev);
749 if (rc) 980 if (rc)
@@ -769,96 +1000,68 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
769#endif 1000#endif
770 } 1001 }
771 1002
1003 /* alloc and init host */
1004 host = ata_host_alloc_pinfo(dev, port, 2);
1005 if (!host) {
1006 dev_printk(KERN_ERR, &pdev->dev,
1007 "failed to allocate ATA host\n");
1008 rc = -ENOMEM;
1009 goto err_out;
1010 }
1011
772 if (!legacy_mode) { 1012 if (!legacy_mode) {
773 rc = pci_request_regions(pdev, DRV_NAME); 1013 unsigned int port_mask;
774 if (rc) { 1014
775 pcim_pin_device(pdev); 1015 port_mask = ATA_PORT_PRIMARY;
1016 if (n_ports > 1)
1017 port_mask |= ATA_PORT_SECONDARY;
1018
1019 rc = ata_pci_init_native_host(host, port_mask);
1020 if (rc)
776 goto err_out; 1021 goto err_out;
777 }
778 } else { 1022 } else {
779 /* Deal with combined mode hack. This side of the logic all 1023 int was_busy = 0;
780 goes away once the combined mode hack is killed in 2.6.21 */
781 if (!devm_request_region(dev, ATA_PRIMARY_CMD, 8, "libata")) {
782 struct resource *conflict, res;
783 res.start = ATA_PRIMARY_CMD;
784 res.end = ATA_PRIMARY_CMD + 8 - 1;
785 conflict = ____request_resource(&ioport_resource, &res);
786 while (conflict->child)
787 conflict = ____request_resource(conflict, &res);
788 if (!strcmp(conflict->name, "libata"))
789 legacy_mode |= ATA_PORT_PRIMARY;
790 else {
791 pcim_pin_device(pdev);
792 printk(KERN_WARNING "ata: 0x%0X IDE port busy\n" \
793 "ata: conflict with %s\n",
794 ATA_PRIMARY_CMD,
795 conflict->name);
796 }
797 } else
798 legacy_mode |= ATA_PORT_PRIMARY;
799
800 if (!devm_request_region(dev, ATA_SECONDARY_CMD, 8, "libata")) {
801 struct resource *conflict, res;
802 res.start = ATA_SECONDARY_CMD;
803 res.end = ATA_SECONDARY_CMD + 8 - 1;
804 conflict = ____request_resource(&ioport_resource, &res);
805 while (conflict->child)
806 conflict = ____request_resource(conflict, &res);
807 if (!strcmp(conflict->name, "libata"))
808 legacy_mode |= ATA_PORT_SECONDARY;
809 else {
810 pcim_pin_device(pdev);
811 printk(KERN_WARNING "ata: 0x%X IDE port busy\n" \
812 "ata: conflict with %s\n",
813 ATA_SECONDARY_CMD,
814 conflict->name);
815 }
816 } else
817 legacy_mode |= ATA_PORT_SECONDARY;
818
819 if (legacy_mode & ATA_PORT_PRIMARY)
820 pci_request_region(pdev, 1, DRV_NAME);
821 if (legacy_mode & ATA_PORT_SECONDARY)
822 pci_request_region(pdev, 3, DRV_NAME);
823 /* If there is a DMA resource, allocate it */
824 pci_request_region(pdev, 4, DRV_NAME);
825 }
826 1024
827 /* we have legacy mode, but all ports are unavailable */ 1025 rc = ata_init_legacy_host(host, &legacy_mode, &was_busy);
828 if (legacy_mode == (1 << 3)) { 1026 if (was_busy)
829 rc = -EBUSY; 1027 pcim_pin_device(pdev);
830 goto err_out; 1028 if (rc)
1029 goto err_out;
1030
1031 /* request respective PCI regions, may fail */
1032 rc = pci_request_region(pdev, 1, DRV_NAME);
1033 rc = pci_request_region(pdev, 3, DRV_NAME);
831 } 1034 }
832 1035
833 /* TODO: If we get no DMA mask we should fall back to PIO */ 1036 /* init BMDMA, may fail */
834 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1037 ata_pci_init_bmdma(host);
835 if (rc) 1038 pci_set_master(pdev);
836 goto err_out; 1039
837 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 1040 /* start host and request IRQ */
1041 rc = ata_host_start(host);
838 if (rc) 1042 if (rc)
839 goto err_out; 1043 goto err_out;
840 1044
841 if (legacy_mode) { 1045 if (!legacy_mode)
842 probe_ent = ata_pci_init_legacy_port(pdev, port, legacy_mode); 1046 rc = devm_request_irq(dev, pdev->irq,
843 } else { 1047 port_info[0]->port_ops->irq_handler,
844 if (n_ports == 2) 1048 IRQF_SHARED, DRV_NAME, host);
845 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 1049 else {
846 else 1050 irq_handler_t handler[2] = { host->ops->irq_handler,
847 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY); 1051 host->ops->irq_handler };
1052 unsigned int irq_flags[2] = { IRQF_SHARED, IRQF_SHARED };
1053 void *dev_id[2] = { host, host };
1054
1055 rc = ata_request_legacy_irqs(host, handler, irq_flags, dev_id);
848 } 1056 }
849 if (!probe_ent) { 1057 if (rc)
850 rc = -ENOMEM;
851 goto err_out; 1058 goto err_out;
852 }
853
854 pci_set_master(pdev);
855 1059
856 if (!ata_device_add(probe_ent)) { 1060 /* register */
857 rc = -ENODEV; 1061 rc = ata_host_register(host, port_info[0]->sht);
1062 if (rc)
858 goto err_out; 1063 goto err_out;
859 }
860 1064
861 devm_kfree(dev, probe_ent);
862 devres_remove_group(dev, NULL); 1065 devres_remove_group(dev, NULL);
863 return 0; 1066 return 0;
864 1067
@@ -893,12 +1096,12 @@ int ata_pci_clear_simplex(struct pci_dev *pdev)
893 return 0; 1096 return 0;
894} 1097}
895 1098
896unsigned long ata_pci_default_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long xfer_mask) 1099unsigned long ata_pci_default_filter(struct ata_device *adev, unsigned long xfer_mask)
897{ 1100{
898 /* Filter out DMA modes if the device has been configured by 1101 /* Filter out DMA modes if the device has been configured by
899 the BIOS as PIO only */ 1102 the BIOS as PIO only */
900 1103
901 if (ap->ioaddr.bmdma_addr == 0) 1104 if (adev->ap->ioaddr.bmdma_addr == 0)
902 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 1105 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
903 return xfer_mask; 1106 return xfer_mask;
904} 1107}
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 1f1e3a51f859..5f4d40cd3288 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -52,6 +52,7 @@ enum {
52 ATA_DNXFER_QUIET = (1 << 31), 52 ATA_DNXFER_QUIET = (1 << 31),
53}; 53};
54 54
55extern unsigned int ata_print_id;
55extern struct workqueue_struct *ata_aux_wq; 56extern struct workqueue_struct *ata_aux_wq;
56extern int atapi_enabled; 57extern int atapi_enabled;
57extern int atapi_dmadir; 58extern int atapi_dmadir;
@@ -92,10 +93,7 @@ extern int ata_flush_cache(struct ata_device *dev);
92extern void ata_dev_init(struct ata_device *dev); 93extern void ata_dev_init(struct ata_device *dev);
93extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); 94extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
94extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); 95extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
95extern void ata_port_init(struct ata_port *ap, struct ata_host *host, 96extern struct ata_port *ata_port_alloc(struct ata_host *host);
96 const struct ata_probe_ent *ent, unsigned int port_no);
97extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev,
98 const struct ata_port_info *port);
99 97
100/* libata-acpi.c */ 98/* libata-acpi.c */
101#ifdef CONFIG_SATA_ACPI 99#ifdef CONFIG_SATA_ACPI
@@ -113,8 +111,8 @@ static inline int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
113#endif 111#endif
114 112
115/* libata-scsi.c */ 113/* libata-scsi.c */
116extern struct scsi_transport_template ata_scsi_transport_template; 114extern int ata_scsi_add_hosts(struct ata_host *host,
117 115 struct scsi_host_template *sht);
118extern void ata_scsi_scan_host(struct ata_port *ap); 116extern void ata_scsi_scan_host(struct ata_port *ap);
119extern int ata_scsi_offline_dev(struct ata_device *dev); 117extern int ata_scsi_offline_dev(struct ata_device *dev);
120extern void ata_scsi_hotplug(struct work_struct *work); 118extern void ata_scsi_hotplug(struct work_struct *work);
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 11ea552a58ca..d40edebb510a 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -34,7 +34,7 @@
34#include <linux/dmi.h> 34#include <linux/dmi.h>
35 35
36#define DRV_NAME "pata_ali" 36#define DRV_NAME "pata_ali"
37#define DRV_VERSION "0.7.3" 37#define DRV_VERSION "0.7.4"
38 38
39/* 39/*
40 * Cable special cases 40 * Cable special cases
@@ -90,59 +90,6 @@ static int ali_c2_cable_detect(struct ata_port *ap)
90} 90}
91 91
92/** 92/**
93 * ali_early_error_handler - reset for eary chip
94 * @ap: ATA port
95 *
96 * Handle the reset callback for the later chips with cable detect
97 */
98
99static int ali_c2_pre_reset(struct ata_port *ap)
100{
101 ap->cbl = ali_c2_cable_detect(ap);
102 return ata_std_prereset(ap);
103}
104
105static void ali_c2_error_handler(struct ata_port *ap)
106{
107 ata_bmdma_drive_eh(ap, ali_c2_pre_reset,
108 ata_std_softreset, NULL,
109 ata_std_postreset);
110}
111
112/**
113 * ali_early_cable_detect - cable detection
114 * @ap: ATA port
115 *
116 * Perform cable detection for older chipsets. This turns out to be
117 * rather easy to implement
118 */
119
120static int ali_early_cable_detect(struct ata_port *ap)
121{
122 return ATA_CBL_PATA40;
123}
124
125/**
126 * ali_early_probe_init - reset for early chip
127 * @ap: ATA port
128 *
129 * Handle the reset callback for the early (pre cable detect) chips.
130 */
131
132static int ali_early_pre_reset(struct ata_port *ap)
133{
134 ap->cbl = ali_early_cable_detect(ap);
135 return ata_std_prereset(ap);
136}
137
138static void ali_early_error_handler(struct ata_port *ap)
139{
140 return ata_bmdma_drive_eh(ap, ali_early_pre_reset,
141 ata_std_softreset, NULL,
142 ata_std_postreset);
143}
144
145/**
146 * ali_20_filter - filter for earlier ALI DMA 93 * ali_20_filter - filter for earlier ALI DMA
147 * @ap: ALi ATA port 94 * @ap: ALi ATA port
148 * @adev: attached device 95 * @adev: attached device
@@ -151,7 +98,7 @@ static void ali_early_error_handler(struct ata_port *ap)
151 * fix that later on. Also ensure we do not do UDMA on WDC drives 98 * fix that later on. Also ensure we do not do UDMA on WDC drives
152 */ 99 */
153 100
154static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 101static unsigned long ali_20_filter(struct ata_device *adev, unsigned long mask)
155{ 102{
156 char model_num[ATA_ID_PROD_LEN + 1]; 103 char model_num[ATA_ID_PROD_LEN + 1];
157 /* No DMA on anything but a disk for now */ 104 /* No DMA on anything but a disk for now */
@@ -160,7 +107,7 @@ static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device
160 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 107 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
161 if (strstr(model_num, "WDC")) 108 if (strstr(model_num, "WDC"))
162 return mask &= ~ATA_MASK_UDMA; 109 return mask &= ~ATA_MASK_UDMA;
163 return ata_pci_default_filter(ap, adev, mask); 110 return ata_pci_default_filter(adev, mask);
164} 111}
165 112
166/** 113/**
@@ -314,7 +261,6 @@ static void ali_set_dmamode(struct ata_port *ap, struct ata_device *adev)
314 261
315/** 262/**
316 * ali_lock_sectors - Keep older devices to 255 sector mode 263 * ali_lock_sectors - Keep older devices to 255 sector mode
317 * @ap: ATA port
318 * @adev: Device 264 * @adev: Device
319 * 265 *
320 * Called during the bus probe for each device that is found. We use 266 * Called during the bus probe for each device that is found. We use
@@ -324,7 +270,7 @@ static void ali_set_dmamode(struct ata_port *ap, struct ata_device *adev)
324 * slower PIO methods 270 * slower PIO methods
325 */ 271 */
326 272
327static void ali_lock_sectors(struct ata_port *ap, struct ata_device *adev) 273static void ali_lock_sectors(struct ata_device *adev)
328{ 274{
329 adev->max_sectors = 255; 275 adev->max_sectors = 255;
330} 276}
@@ -366,8 +312,9 @@ static struct ata_port_operations ali_early_port_ops = {
366 312
367 .freeze = ata_bmdma_freeze, 313 .freeze = ata_bmdma_freeze,
368 .thaw = ata_bmdma_thaw, 314 .thaw = ata_bmdma_thaw,
369 .error_handler = ali_early_error_handler, 315 .error_handler = ata_bmdma_error_handler,
370 .post_internal_cmd = ata_bmdma_post_internal_cmd, 316 .post_internal_cmd = ata_bmdma_post_internal_cmd,
317 .cable_detect = ata_cable_40wire,
371 318
372 .qc_prep = ata_qc_prep, 319 .qc_prep = ata_qc_prep,
373 .qc_issue = ata_qc_issue_prot, 320 .qc_issue = ata_qc_issue_prot,
@@ -402,8 +349,9 @@ static struct ata_port_operations ali_20_port_ops = {
402 349
403 .freeze = ata_bmdma_freeze, 350 .freeze = ata_bmdma_freeze,
404 .thaw = ata_bmdma_thaw, 351 .thaw = ata_bmdma_thaw,
405 .error_handler = ali_early_error_handler, 352 .error_handler = ata_bmdma_error_handler,
406 .post_internal_cmd = ata_bmdma_post_internal_cmd, 353 .post_internal_cmd = ata_bmdma_post_internal_cmd,
354 .cable_detect = ata_cable_40wire,
407 355
408 .bmdma_setup = ata_bmdma_setup, 356 .bmdma_setup = ata_bmdma_setup,
409 .bmdma_start = ata_bmdma_start, 357 .bmdma_start = ata_bmdma_start,
@@ -440,8 +388,9 @@ static struct ata_port_operations ali_c2_port_ops = {
440 388
441 .freeze = ata_bmdma_freeze, 389 .freeze = ata_bmdma_freeze,
442 .thaw = ata_bmdma_thaw, 390 .thaw = ata_bmdma_thaw,
443 .error_handler = ali_c2_error_handler, 391 .error_handler = ata_bmdma_error_handler,
444 .post_internal_cmd = ata_bmdma_post_internal_cmd, 392 .post_internal_cmd = ata_bmdma_post_internal_cmd,
393 .cable_detect = ali_c2_cable_detect,
445 394
446 .bmdma_setup = ata_bmdma_setup, 395 .bmdma_setup = ata_bmdma_setup,
447 .bmdma_start = ata_bmdma_start, 396 .bmdma_start = ata_bmdma_start,
@@ -477,8 +426,9 @@ static struct ata_port_operations ali_c5_port_ops = {
477 426
478 .freeze = ata_bmdma_freeze, 427 .freeze = ata_bmdma_freeze,
479 .thaw = ata_bmdma_thaw, 428 .thaw = ata_bmdma_thaw,
480 .error_handler = ali_c2_error_handler, 429 .error_handler = ata_bmdma_error_handler,
481 .post_internal_cmd = ata_bmdma_post_internal_cmd, 430 .post_internal_cmd = ata_bmdma_post_internal_cmd,
431 .cable_detect = ali_c2_cable_detect,
482 432
483 .bmdma_setup = ata_bmdma_setup, 433 .bmdma_setup = ata_bmdma_setup,
484 .bmdma_start = ata_bmdma_start, 434 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 18381762908b..536ee892ab72 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_amd" 27#define DRV_NAME "pata_amd"
28#define DRV_VERSION "0.2.8" 28#define DRV_VERSION "0.3.8"
29 29
30/** 30/**
31 * timing_setup - shared timing computation and load 31 * timing_setup - shared timing computation and load
@@ -119,32 +119,25 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
119} 119}
120 120
121/** 121/**
122 * amd_probe_init - cable detection 122 * amd_probe_init - perform reset handling
123 * @ap: ATA port 123 * @ap: ATA port
124 * 124 *
125 * Perform cable detection. The BIOS stores this in PCI config 125 * Reset sequence checking enable bits to see which ports are
126 * space for us. 126 * active.
127 */ 127 */
128 128
129static int amd_pre_reset(struct ata_port *ap) 129static int amd_pre_reset(struct ata_port *ap)
130{ 130{
131 static const u32 bitmask[2] = {0x03, 0x0C};
132 static const struct pci_bits amd_enable_bits[] = { 131 static const struct pci_bits amd_enable_bits[] = {
133 { 0x40, 1, 0x02, 0x02 }, 132 { 0x40, 1, 0x02, 0x02 },
134 { 0x40, 1, 0x01, 0x01 } 133 { 0x40, 1, 0x01, 0x01 }
135 }; 134 };
136 135
137 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 136 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
138 u8 ata66;
139 137
140 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) 138 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
141 return -ENOENT; 139 return -ENOENT;
142 140
143 pci_read_config_byte(pdev, 0x42, &ata66);
144 if (ata66 & bitmask[ap->port_no])
145 ap->cbl = ATA_CBL_PATA80;
146 else
147 ap->cbl = ATA_CBL_PATA40;
148 return ata_std_prereset(ap); 141 return ata_std_prereset(ap);
149 142
150} 143}
@@ -156,28 +149,16 @@ static void amd_error_handler(struct ata_port *ap)
156 ata_std_postreset); 149 ata_std_postreset);
157} 150}
158 151
159static int amd_early_pre_reset(struct ata_port *ap) 152static int amd_cable_detect(struct ata_port *ap)
160{ 153{
154 static const u32 bitmask[2] = {0x03, 0x0C};
161 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 155 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
162 static struct pci_bits amd_enable_bits[] = { 156 u8 ata66;
163 { 0x40, 1, 0x02, 0x02 },
164 { 0x40, 1, 0x01, 0x01 }
165 };
166
167 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
168 return -ENOENT;
169
170 /* No host side cable detection */
171 ap->cbl = ATA_CBL_PATA80;
172 return ata_std_prereset(ap);
173
174}
175 157
176static void amd_early_error_handler(struct ata_port *ap) 158 pci_read_config_byte(pdev, 0x42, &ata66);
177{ 159 if (ata66 & bitmask[ap->port_no])
178 ata_bmdma_drive_eh(ap, amd_early_pre_reset, 160 return ATA_CBL_PATA80;
179 ata_std_softreset, NULL, 161 return ATA_CBL_PATA40;
180 ata_std_postreset);
181} 162}
182 163
183/** 164/**
@@ -247,31 +228,16 @@ static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
247 */ 228 */
248 229
249static int nv_pre_reset(struct ata_port *ap) { 230static int nv_pre_reset(struct ata_port *ap) {
250 static const u8 bitmask[2] = {0x03, 0x0C};
251 static const struct pci_bits nv_enable_bits[] = { 231 static const struct pci_bits nv_enable_bits[] = {
252 { 0x50, 1, 0x02, 0x02 }, 232 { 0x50, 1, 0x02, 0x02 },
253 { 0x50, 1, 0x01, 0x01 } 233 { 0x50, 1, 0x01, 0x01 }
254 }; 234 };
255 235
256 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 236 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
257 u8 ata66;
258 u16 udma;
259 237
260 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) 238 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
261 return -ENOENT; 239 return -ENOENT;
262 240
263 pci_read_config_byte(pdev, 0x52, &ata66);
264 if (ata66 & bitmask[ap->port_no])
265 ap->cbl = ATA_CBL_PATA80;
266 else
267 ap->cbl = ATA_CBL_PATA40;
268
269 /* We now have to double check because the Nvidia boxes BIOS
270 doesn't always set the cable bits but does set mode bits */
271
272 pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
273 if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
274 ap->cbl = ATA_CBL_PATA80;
275 return ata_std_prereset(ap); 241 return ata_std_prereset(ap);
276} 242}
277 243
@@ -281,6 +247,29 @@ static void nv_error_handler(struct ata_port *ap)
281 ata_std_softreset, NULL, 247 ata_std_softreset, NULL,
282 ata_std_postreset); 248 ata_std_postreset);
283} 249}
250
251static int nv_cable_detect(struct ata_port *ap)
252{
253 static const u8 bitmask[2] = {0x03, 0x0C};
254 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
255 u8 ata66;
256 u16 udma;
257 int cbl;
258
259 pci_read_config_byte(pdev, 0x52, &ata66);
260 if (ata66 & bitmask[ap->port_no])
261 cbl = ATA_CBL_PATA80;
262 else
263 cbl = ATA_CBL_PATA40;
264
265 /* We now have to double check because the Nvidia boxes BIOS
266 doesn't always set the cable bits but does set mode bits */
267 pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
268 if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
269 cbl = ATA_CBL_PATA80;
270 return cbl;
271}
272
284/** 273/**
285 * nv100_set_piomode - set initial PIO mode data 274 * nv100_set_piomode - set initial PIO mode data
286 * @ap: ATA interface 275 * @ap: ATA interface
@@ -353,8 +342,9 @@ static struct ata_port_operations amd33_port_ops = {
353 342
354 .freeze = ata_bmdma_freeze, 343 .freeze = ata_bmdma_freeze,
355 .thaw = ata_bmdma_thaw, 344 .thaw = ata_bmdma_thaw,
356 .error_handler = amd_early_error_handler, 345 .error_handler = amd_error_handler,
357 .post_internal_cmd = ata_bmdma_post_internal_cmd, 346 .post_internal_cmd = ata_bmdma_post_internal_cmd,
347 .cable_detect = ata_cable_40wire,
358 348
359 .bmdma_setup = ata_bmdma_setup, 349 .bmdma_setup = ata_bmdma_setup,
360 .bmdma_start = ata_bmdma_start, 350 .bmdma_start = ata_bmdma_start,
@@ -387,8 +377,9 @@ static struct ata_port_operations amd66_port_ops = {
387 377
388 .freeze = ata_bmdma_freeze, 378 .freeze = ata_bmdma_freeze,
389 .thaw = ata_bmdma_thaw, 379 .thaw = ata_bmdma_thaw,
390 .error_handler = amd_early_error_handler, 380 .error_handler = amd_error_handler,
391 .post_internal_cmd = ata_bmdma_post_internal_cmd, 381 .post_internal_cmd = ata_bmdma_post_internal_cmd,
382 .cable_detect = ata_cable_unknown,
392 383
393 .bmdma_setup = ata_bmdma_setup, 384 .bmdma_setup = ata_bmdma_setup,
394 .bmdma_start = ata_bmdma_start, 385 .bmdma_start = ata_bmdma_start,
@@ -423,6 +414,7 @@ static struct ata_port_operations amd100_port_ops = {
423 .thaw = ata_bmdma_thaw, 414 .thaw = ata_bmdma_thaw,
424 .error_handler = amd_error_handler, 415 .error_handler = amd_error_handler,
425 .post_internal_cmd = ata_bmdma_post_internal_cmd, 416 .post_internal_cmd = ata_bmdma_post_internal_cmd,
417 .cable_detect = ata_cable_unknown,
426 418
427 .bmdma_setup = ata_bmdma_setup, 419 .bmdma_setup = ata_bmdma_setup,
428 .bmdma_start = ata_bmdma_start, 420 .bmdma_start = ata_bmdma_start,
@@ -457,6 +449,7 @@ static struct ata_port_operations amd133_port_ops = {
457 .thaw = ata_bmdma_thaw, 449 .thaw = ata_bmdma_thaw,
458 .error_handler = amd_error_handler, 450 .error_handler = amd_error_handler,
459 .post_internal_cmd = ata_bmdma_post_internal_cmd, 451 .post_internal_cmd = ata_bmdma_post_internal_cmd,
452 .cable_detect = amd_cable_detect,
460 453
461 .bmdma_setup = ata_bmdma_setup, 454 .bmdma_setup = ata_bmdma_setup,
462 .bmdma_start = ata_bmdma_start, 455 .bmdma_start = ata_bmdma_start,
@@ -491,6 +484,7 @@ static struct ata_port_operations nv100_port_ops = {
491 .thaw = ata_bmdma_thaw, 484 .thaw = ata_bmdma_thaw,
492 .error_handler = nv_error_handler, 485 .error_handler = nv_error_handler,
493 .post_internal_cmd = ata_bmdma_post_internal_cmd, 486 .post_internal_cmd = ata_bmdma_post_internal_cmd,
487 .cable_detect = nv_cable_detect,
494 488
495 .bmdma_setup = ata_bmdma_setup, 489 .bmdma_setup = ata_bmdma_setup,
496 .bmdma_start = ata_bmdma_start, 490 .bmdma_start = ata_bmdma_start,
@@ -525,6 +519,7 @@ static struct ata_port_operations nv133_port_ops = {
525 .thaw = ata_bmdma_thaw, 519 .thaw = ata_bmdma_thaw,
526 .error_handler = nv_error_handler, 520 .error_handler = nv_error_handler,
527 .post_internal_cmd = ata_bmdma_post_internal_cmd, 521 .post_internal_cmd = ata_bmdma_post_internal_cmd,
522 .cable_detect = nv_cable_detect,
528 523
529 .bmdma_setup = ata_bmdma_setup, 524 .bmdma_setup = ata_bmdma_setup,
530 .bmdma_start = ata_bmdma_start, 525 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 21c30282717c..00e9ec342db0 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -49,8 +49,6 @@ static int artop6210_pre_reset(struct ata_port *ap)
49 49
50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
51 return -ENOENT; 51 return -ENOENT;
52
53 ap->cbl = ATA_CBL_PATA40;
54 return ata_std_prereset(ap); 52 return ata_std_prereset(ap);
55} 53}
56 54
@@ -85,18 +83,28 @@ static int artop6260_pre_reset(struct ata_port *ap)
85 }; 83 };
86 84
87 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 85 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
88 u8 tmp;
89 86
90 /* Odd numbered device ids are the units with enable bits (the -R cards) */ 87 /* Odd numbered device ids are the units with enable bits (the -R cards) */
91 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 88 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
92 return -ENOENT; 89 return -ENOENT;
90 return ata_std_prereset(ap);
91}
93 92
93/**
94 * artop6260_cable_detect - identify cable type
95 * @ap: Port
96 *
97 * Identify the cable type for the ARTOp interface in question
98 */
99
100static int artop6260_cable_detect(struct ata_port *ap)
101{
102 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
103 u8 tmp;
94 pci_read_config_byte(pdev, 0x49, &tmp); 104 pci_read_config_byte(pdev, 0x49, &tmp);
95 if (tmp & (1 << ap->port_no)) 105 if (tmp & (1 << ap->port_no))
96 ap->cbl = ATA_CBL_PATA40; 106 return ATA_CBL_PATA40;
97 else 107 return ATA_CBL_PATA80;
98 ap->cbl = ATA_CBL_PATA80;
99 return ata_std_prereset(ap);
100} 108}
101 109
102/** 110/**
@@ -225,7 +233,7 @@ static void artop6260_set_piomode(struct ata_port *ap, struct ata_device *adev)
225/** 233/**
226 * artop6210_set_dmamode - Initialize host controller PATA PIO timings 234 * artop6210_set_dmamode - Initialize host controller PATA PIO timings
227 * @ap: Port whose timings we are configuring 235 * @ap: Port whose timings we are configuring
228 * @adev: um 236 * @adev: Device whose timings we are configuring
229 * 237 *
230 * Set DMA mode for device, in host controller PCI config space. 238 * Set DMA mode for device, in host controller PCI config space.
231 * 239 *
@@ -333,6 +341,7 @@ static const struct ata_port_operations artop6210_ops = {
333 .thaw = ata_bmdma_thaw, 341 .thaw = ata_bmdma_thaw,
334 .error_handler = artop6210_error_handler, 342 .error_handler = artop6210_error_handler,
335 .post_internal_cmd = ata_bmdma_post_internal_cmd, 343 .post_internal_cmd = ata_bmdma_post_internal_cmd,
344 .cable_detect = ata_cable_40wire,
336 345
337 .bmdma_setup = ata_bmdma_setup, 346 .bmdma_setup = ata_bmdma_setup,
338 .bmdma_start = ata_bmdma_start, 347 .bmdma_start = ata_bmdma_start,
@@ -366,6 +375,7 @@ static const struct ata_port_operations artop6260_ops = {
366 .thaw = ata_bmdma_thaw, 375 .thaw = ata_bmdma_thaw,
367 .error_handler = artop6260_error_handler, 376 .error_handler = artop6260_error_handler,
368 .post_internal_cmd = ata_bmdma_post_internal_cmd, 377 .post_internal_cmd = ata_bmdma_post_internal_cmd,
378 .cable_detect = artop6260_cable_detect,
369 379
370 .bmdma_setup = ata_bmdma_setup, 380 .bmdma_setup = ata_bmdma_setup,
371 .bmdma_start = ata_bmdma_start, 381 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 51d9923be02e..39c871a3ddac 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -22,7 +22,7 @@
22#include <linux/libata.h> 22#include <linux/libata.h>
23 23
24#define DRV_NAME "pata_atiixp" 24#define DRV_NAME "pata_atiixp"
25#define DRV_VERSION "0.4.4" 25#define DRV_VERSION "0.4.5"
26 26
27enum { 27enum {
28 ATIIXP_IDE_PIO_TIMING = 0x40, 28 ATIIXP_IDE_PIO_TIMING = 0x40,
@@ -35,23 +35,15 @@ enum {
35 35
36static int atiixp_pre_reset(struct ata_port *ap) 36static int atiixp_pre_reset(struct ata_port *ap)
37{ 37{
38 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
39 static const struct pci_bits atiixp_enable_bits[] = { 38 static const struct pci_bits atiixp_enable_bits[] = {
40 { 0x48, 1, 0x01, 0x00 }, 39 { 0x48, 1, 0x01, 0x00 },
41 { 0x48, 1, 0x08, 0x00 } 40 { 0x48, 1, 0x08, 0x00 }
42 }; 41 };
43 u8 udma; 42 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
44 43
45 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no])) 44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
46 return -ENOENT; 45 return -ENOENT;
47 46
48 /* Hack from drivers/ide/pci. Really we want to know how to do the
49 raw detection not play follow the bios mode guess */
50 pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ap->port_no, &udma);
51 if ((udma & 0x07) >= 0x04 || (udma & 0x70) >= 0x40)
52 ap->cbl = ATA_CBL_PATA80;
53 else
54 ap->cbl = ATA_CBL_PATA40;
55 return ata_std_prereset(ap); 47 return ata_std_prereset(ap);
56} 48}
57 49
@@ -60,6 +52,19 @@ static void atiixp_error_handler(struct ata_port *ap)
60 ata_bmdma_drive_eh(ap, atiixp_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 52 ata_bmdma_drive_eh(ap, atiixp_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
61} 53}
62 54
55static int atiixp_cable_detect(struct ata_port *ap)
56{
57 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
58 u8 udma;
59
60 /* Hack from drivers/ide/pci. Really we want to know how to do the
61 raw detection not play follow the bios mode guess */
62 pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ap->port_no, &udma);
63 if ((udma & 0x07) >= 0x04 || (udma & 0x70) >= 0x40)
64 return ATA_CBL_PATA80;
65 return ATA_CBL_PATA40;
66}
67
63/** 68/**
64 * atiixp_set_pio_timing - set initial PIO mode data 69 * atiixp_set_pio_timing - set initial PIO mode data
65 * @ap: ATA interface 70 * @ap: ATA interface
@@ -245,6 +250,7 @@ static struct ata_port_operations atiixp_port_ops = {
245 .thaw = ata_bmdma_thaw, 250 .thaw = ata_bmdma_thaw,
246 .error_handler = atiixp_error_handler, 251 .error_handler = atiixp_error_handler,
247 .post_internal_cmd = ata_bmdma_post_internal_cmd, 252 .post_internal_cmd = ata_bmdma_post_internal_cmd,
253 .cable_detect = atiixp_cable_detect,
248 254
249 .bmdma_setup = ata_bmdma_setup, 255 .bmdma_setup = ata_bmdma_setup,
250 .bmdma_start = atiixp_bmdma_start, 256 .bmdma_start = atiixp_bmdma_start,
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
new file mode 100644
index 000000000000..2105985a8013
--- /dev/null
+++ b/drivers/ata/pata_cmd640.c
@@ -0,0 +1,312 @@
1/*
2 * pata_cmd640.c - CMD640 PCI PATA for new ATA layer
3 * (C) 2007 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 *
6 * Based upon
7 * linux/drivers/ide/pci/cmd640.c Version 1.02 Sep 01, 1996
8 *
9 * Copyright (C) 1995-1996 Linus Torvalds & authors (see driver)
10 *
11 * This drives only the PCI version of the controller. If you have a
12 * VLB one then we have enough docs to support it but you can write
13 * your own code.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/pci.h>
19#include <linux/init.h>
20#include <linux/blkdev.h>
21#include <linux/delay.h>
22#include <scsi/scsi_host.h>
23#include <linux/libata.h>
24
25#define DRV_NAME "pata_cmd640"
26#define DRV_VERSION "0.0.5"
27
28struct cmd640_reg {
29 int last;
30 u8 reg58[ATA_MAX_DEVICES];
31};
32
33enum {
34 CFR = 0x50,
35 CNTRL = 0x51,
36 CMDTIM = 0x52,
37 ARTIM0 = 0x53,
38 DRWTIM0 = 0x54,
39 ARTIM23 = 0x57,
40 DRWTIM23 = 0x58,
41 BRST = 0x59
42};
43
44/**
45 * cmd640_set_piomode - set initial PIO mode data
46 * @ap: ATA port
47 * @adev: ATA device
48 *
49 * Called to do the PIO mode setup.
50 */
51
52static void cmd640_set_piomode(struct ata_port *ap, struct ata_device *adev)
53{
54 struct cmd640_reg *timing = ap->private_data;
55 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
56 struct ata_timing t;
57 const unsigned long T = 1000000 / 33;
58 const u8 setup_data[] = { 0x40, 0x40, 0x40, 0x80, 0x00 };
59 u8 reg;
60 int arttim = ARTIM0 + 2 * adev->devno;
61 struct ata_device *pair = ata_dev_pair(adev);
62
63 if (ata_timing_compute(adev, adev->pio_mode, &t, T, 0) < 0) {
64 printk(KERN_ERR DRV_NAME ": mode computation failed.\n");
65 return;
66 }
67
68 /* The second channel has shared timings and the setup timing is
69 messy to switch to merge it for worst case */
70 if (ap->port_no && pair) {
71 struct ata_timing p;
72 ata_timing_compute(pair, pair->pio_mode, &p, T, 1);
73 ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP);
74 }
75
76 /* Make the timings fit */
77 if (t.recover > 16) {
78 t.active += t.recover - 16;
79 t.recover = 16;
80 }
81 if (t.active > 16)
82 t.active = 16;
83
84 /* Now convert the clocks into values we can actually stuff into
85 the chip */
86
87 if (t.recover > 1)
88 t.recover--; /* 640B only */
89 else
90 t.recover = 15;
91
92 if (t.setup > 4)
93 t.setup = 0xC0;
94 else
95 t.setup = setup_data[t.setup];
96
97 if (ap->port_no == 0) {
98 t.active &= 0x0F; /* 0 = 16 */
99
100 /* Load setup timing */
101 pci_read_config_byte(pdev, arttim, &reg);
102 reg &= 0x3F;
103 reg |= t.setup;
104 pci_write_config_byte(pdev, arttim, reg);
105
106 /* Load active/recovery */
107 pci_write_config_byte(pdev, arttim + 1, (t.active << 4) | t.recover);
108 } else {
109 /* Save the shared timings for channel, they will be loaded
110 by qc_issue_prot. Reloading the setup time is expensive
111 so we keep a merged one loaded */
112 pci_read_config_byte(pdev, ARTIM23, &reg);
113 reg &= 0x3F;
114 reg |= t.setup;
115 pci_write_config_byte(pdev, ARTIM23, reg);
116 timing->reg58[adev->devno] = (t.active << 4) | t.recover;
117 }
118}
119
120
121/**
122 * cmd640_qc_issue_prot - command preparation hook
123 * @qc: Command to be issued
124 *
125 * Channel 1 has shared timings. We must reprogram the
126 * clock each drive 2/3 switch we do.
127 */
128
129static unsigned int cmd640_qc_issue_prot(struct ata_queued_cmd *qc)
130{
131 struct ata_port *ap = qc->ap;
132 struct ata_device *adev = qc->dev;
133 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
134 struct cmd640_reg *timing = ap->private_data;
135
136 if (ap->port_no != 0 && adev->devno != timing->last) {
137 pci_write_config_byte(pdev, DRWTIM23, timing->reg58[adev->devno]);
138 timing->last = adev->devno;
139 }
140 return ata_qc_issue_prot(qc);
141}
142
143/**
144 * cmd640_port_start - port setup
145 * @ap: ATA port being set up
146 *
147 * The CMD640 needs to maintain private data structures so we
148 * allocate space here.
149 */
150
151static int cmd640_port_start(struct ata_port *ap)
152{
153 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
154 struct cmd640_reg *timing;
155
156 int ret = ata_port_start(ap);
157 if (ret < 0)
158 return ret;
159
160 timing = devm_kzalloc(&pdev->dev, sizeof(struct cmd640_reg), GFP_KERNEL);
161 if (timing == NULL)
162 return -ENOMEM;
163 timing->last = -1; /* Force a load */
164 ap->private_data = timing;
165 return ret;
166}
167
168static struct scsi_host_template cmd640_sht = {
169 .module = THIS_MODULE,
170 .name = DRV_NAME,
171 .ioctl = ata_scsi_ioctl,
172 .queuecommand = ata_scsi_queuecmd,
173 .can_queue = ATA_DEF_QUEUE,
174 .this_id = ATA_SHT_THIS_ID,
175 .sg_tablesize = LIBATA_MAX_PRD,
176 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
177 .emulated = ATA_SHT_EMULATED,
178 .use_clustering = ATA_SHT_USE_CLUSTERING,
179 .proc_name = DRV_NAME,
180 .dma_boundary = ATA_DMA_BOUNDARY,
181 .slave_configure = ata_scsi_slave_config,
182 .slave_destroy = ata_scsi_slave_destroy,
183 .bios_param = ata_std_bios_param,
184#ifdef CONFIG_PM
185 .resume = ata_scsi_device_resume,
186 .suspend = ata_scsi_device_suspend,
187#endif
188};
189
190static struct ata_port_operations cmd640_port_ops = {
191 .port_disable = ata_port_disable,
192 .set_piomode = cmd640_set_piomode,
193 .mode_filter = ata_pci_default_filter,
194 .tf_load = ata_tf_load,
195 .tf_read = ata_tf_read,
196 .check_status = ata_check_status,
197 .exec_command = ata_exec_command,
198 .dev_select = ata_std_dev_select,
199
200 .freeze = ata_bmdma_freeze,
201 .thaw = ata_bmdma_thaw,
202 .error_handler = ata_bmdma_error_handler,
203 .post_internal_cmd = ata_bmdma_post_internal_cmd,
204 .cable_detect = ata_cable_40wire,
205
206 .bmdma_setup = ata_bmdma_setup,
207 .bmdma_start = ata_bmdma_start,
208 .bmdma_stop = ata_bmdma_stop,
209 .bmdma_status = ata_bmdma_status,
210
211 .qc_prep = ata_qc_prep,
212 .qc_issue = cmd640_qc_issue_prot,
213
214 /* In theory this is not needed once we kill the prefetcher */
215 .data_xfer = ata_data_xfer_noirq,
216
217 .irq_handler = ata_interrupt,
218 .irq_clear = ata_bmdma_irq_clear,
219 .irq_on = ata_irq_on,
220 .irq_ack = ata_irq_ack,
221
222 .port_start = cmd640_port_start,
223};
224
225static void cmd640_hardware_init(struct pci_dev *pdev)
226{
227 u8 r;
228 u8 ctrl;
229
230 /* CMD640 detected, commiserations */
231 pci_write_config_byte(pdev, 0x5B, 0x00);
232 /* Get version info */
233 pci_read_config_byte(pdev, CFR, &r);
234 /* PIO0 command cycles */
235 pci_write_config_byte(pdev, CMDTIM, 0);
236 /* 512 byte bursts (sector) */
237 pci_write_config_byte(pdev, BRST, 0x40);
238 /*
239 * A reporter a long time ago
240 * Had problems with the data fifo
241 * So don't run the risk
242 * Of putting crap on the disk
243 * For its better just to go slow
244 */
245 /* Do channel 0 */
246 pci_read_config_byte(pdev, CNTRL, &ctrl);
247 pci_write_config_byte(pdev, CNTRL, ctrl | 0xC0);
248 /* Ditto for channel 1 */
249 pci_read_config_byte(pdev, ARTIM23, &ctrl);
250 ctrl |= 0x0C;
251 pci_write_config_byte(pdev, ARTIM23, ctrl);
252}
253
254static int cmd640_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
255{
256 static struct ata_port_info info = {
257 .sht = &cmd640_sht,
258 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
259 .pio_mask = 0x1f,
260 .port_ops = &cmd640_port_ops
261 };
262
263 static struct ata_port_info *port_info[2] = { &info, &info };
264
265 cmd640_hardware_init(pdev);
266 return ata_pci_init_one(pdev, port_info, 2);
267}
268
269static int cmd640_reinit_one(struct pci_dev *pdev)
270{
271 cmd640_hardware_init(pdev);
272#ifdef CONFIG_PM
273 return ata_pci_device_resume(pdev);
274#else
275 return 0;
276#endif
277}
278
279static const struct pci_device_id cmd640[] = {
280 { PCI_VDEVICE(CMD, 0x640), 0 },
281 { },
282};
283
284static struct pci_driver cmd640_pci_driver = {
285 .name = DRV_NAME,
286 .id_table = cmd640,
287 .probe = cmd640_init_one,
288 .remove = ata_pci_remove_one,
289#ifdef CONFIG_PM
290 .suspend = ata_pci_device_suspend,
291#endif
292 .resume = cmd640_reinit_one,
293};
294
295static int __init cmd640_init(void)
296{
297 return pci_register_driver(&cmd640_pci_driver);
298}
299
300static void __exit cmd640_exit(void)
301{
302 pci_unregister_driver(&cmd640_pci_driver);
303}
304
305MODULE_AUTHOR("Alan Cox");
306MODULE_DESCRIPTION("low-level driver for CMD640 PATA controllers");
307MODULE_LICENSE("GPL");
308MODULE_DEVICE_TABLE(pci, cmd640);
309MODULE_VERSION(DRV_VERSION);
310
311module_init(cmd640_init);
312module_exit(cmd640_exit);
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 5b13bdd1edc0..3989cc577fcd 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -75,13 +75,7 @@ enum {
75 DTPR1 = 0x7C 75 DTPR1 = 0x7C
76}; 76};
77 77
78static int cmd64x_pre_reset(struct ata_port *ap) 78static int cmd648_cable_detect(struct ata_port *ap)
79{
80 ap->cbl = ATA_CBL_PATA40;
81 return ata_std_prereset(ap);
82}
83
84static int cmd648_pre_reset(struct ata_port *ap)
85{ 79{
86 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 80 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
87 u8 r; 81 u8 r;
@@ -89,21 +83,8 @@ static int cmd648_pre_reset(struct ata_port *ap)
89 /* Check cable detect bits */ 83 /* Check cable detect bits */
90 pci_read_config_byte(pdev, BMIDECSR, &r); 84 pci_read_config_byte(pdev, BMIDECSR, &r);
91 if (r & (1 << ap->port_no)) 85 if (r & (1 << ap->port_no))
92 ap->cbl = ATA_CBL_PATA80; 86 return ATA_CBL_PATA80;
93 else 87 return ATA_CBL_PATA40;
94 ap->cbl = ATA_CBL_PATA40;
95
96 return ata_std_prereset(ap);
97}
98
99static void cmd64x_error_handler(struct ata_port *ap)
100{
101 return ata_bmdma_drive_eh(ap, cmd64x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
102}
103
104static void cmd648_error_handler(struct ata_port *ap)
105{
106 ata_bmdma_drive_eh(ap, cmd648_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
107} 88}
108 89
109/** 90/**
@@ -304,8 +285,9 @@ static struct ata_port_operations cmd64x_port_ops = {
304 285
305 .freeze = ata_bmdma_freeze, 286 .freeze = ata_bmdma_freeze,
306 .thaw = ata_bmdma_thaw, 287 .thaw = ata_bmdma_thaw,
307 .error_handler = cmd64x_error_handler, 288 .error_handler = ata_bmdma_error_handler,
308 .post_internal_cmd = ata_bmdma_post_internal_cmd, 289 .post_internal_cmd = ata_bmdma_post_internal_cmd,
290 .cable_detect = ata_cable_40wire,
309 291
310 .bmdma_setup = ata_bmdma_setup, 292 .bmdma_setup = ata_bmdma_setup,
311 .bmdma_start = ata_bmdma_start, 293 .bmdma_start = ata_bmdma_start,
@@ -338,8 +320,9 @@ static struct ata_port_operations cmd646r1_port_ops = {
338 320
339 .freeze = ata_bmdma_freeze, 321 .freeze = ata_bmdma_freeze,
340 .thaw = ata_bmdma_thaw, 322 .thaw = ata_bmdma_thaw,
341 .error_handler = cmd64x_error_handler, 323 .error_handler = ata_bmdma_error_handler,
342 .post_internal_cmd = ata_bmdma_post_internal_cmd, 324 .post_internal_cmd = ata_bmdma_post_internal_cmd,
325 .cable_detect = ata_cable_40wire,
343 326
344 .bmdma_setup = ata_bmdma_setup, 327 .bmdma_setup = ata_bmdma_setup,
345 .bmdma_start = ata_bmdma_start, 328 .bmdma_start = ata_bmdma_start,
@@ -372,8 +355,9 @@ static struct ata_port_operations cmd648_port_ops = {
372 355
373 .freeze = ata_bmdma_freeze, 356 .freeze = ata_bmdma_freeze,
374 .thaw = ata_bmdma_thaw, 357 .thaw = ata_bmdma_thaw,
375 .error_handler = cmd648_error_handler, 358 .error_handler = ata_bmdma_error_handler,
376 .post_internal_cmd = ata_bmdma_post_internal_cmd, 359 .post_internal_cmd = ata_bmdma_post_internal_cmd,
360 .cable_detect = cmd648_cable_detect,
377 361
378 .bmdma_setup = ata_bmdma_setup, 362 .bmdma_setup = ata_bmdma_setup,
379 .bmdma_start = ata_bmdma_start, 363 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 55cc293e7487..79bef0d1fad3 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -139,18 +139,6 @@ static void cs5520_set_piomode(struct ata_port *ap, struct ata_device *adev)
139 cs5520_set_timings(ap, adev, adev->pio_mode); 139 cs5520_set_timings(ap, adev, adev->pio_mode);
140} 140}
141 141
142
143static int cs5520_pre_reset(struct ata_port *ap)
144{
145 ap->cbl = ATA_CBL_PATA40;
146 return ata_std_prereset(ap);
147}
148
149static void cs5520_error_handler(struct ata_port *ap)
150{
151 return ata_bmdma_drive_eh(ap, cs5520_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
152}
153
154static struct scsi_host_template cs5520_sht = { 142static struct scsi_host_template cs5520_sht = {
155 .module = THIS_MODULE, 143 .module = THIS_MODULE,
156 .name = DRV_NAME, 144 .name = DRV_NAME,
@@ -186,8 +174,9 @@ static struct ata_port_operations cs5520_port_ops = {
186 174
187 .freeze = ata_bmdma_freeze, 175 .freeze = ata_bmdma_freeze,
188 .thaw = ata_bmdma_thaw, 176 .thaw = ata_bmdma_thaw,
189 .error_handler = cs5520_error_handler, 177 .error_handler = ata_bmdma_error_handler,
190 .post_internal_cmd = ata_bmdma_post_internal_cmd, 178 .post_internal_cmd = ata_bmdma_post_internal_cmd,
179 .cable_detect = ata_cable_40wire,
191 180
192 .bmdma_setup = ata_bmdma_setup, 181 .bmdma_setup = ata_bmdma_setup,
193 .bmdma_start = ata_bmdma_start, 182 .bmdma_start = ata_bmdma_start,
@@ -197,7 +186,6 @@ static struct ata_port_operations cs5520_port_ops = {
197 .qc_issue = ata_qc_issue_prot, 186 .qc_issue = ata_qc_issue_prot,
198 .data_xfer = ata_data_xfer, 187 .data_xfer = ata_data_xfer,
199 188
200 .irq_handler = ata_interrupt,
201 .irq_clear = ata_bmdma_irq_clear, 189 .irq_clear = ata_bmdma_irq_clear,
202 .irq_on = ata_irq_on, 190 .irq_on = ata_irq_on,
203 .irq_ack = ata_irq_ack, 191 .irq_ack = ata_irq_ack,
@@ -205,91 +193,104 @@ static struct ata_port_operations cs5520_port_ops = {
205 .port_start = ata_port_start, 193 .port_start = ata_port_start,
206}; 194};
207 195
208static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 196static int __devinit cs5520_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
209{ 197{
198 struct ata_port_info pi = {
199 .flags = ATA_FLAG_SLAVE_POSS,
200 .pio_mask = 0x1f,
201 .port_ops = &cs5520_port_ops,
202 };
203 const struct ata_port_info *ppi[2];
210 u8 pcicfg; 204 u8 pcicfg;
211 void __iomem *iomap[5]; 205 void *iomap[5];
212 static struct ata_probe_ent probe[2]; 206 struct ata_host *host;
213 int ports = 0; 207 struct ata_ioports *ioaddr;
208 int i, rc;
214 209
215 /* IDE port enable bits */ 210 /* IDE port enable bits */
216 pci_read_config_byte(dev, 0x60, &pcicfg); 211 pci_read_config_byte(pdev, 0x60, &pcicfg);
217 212
218 /* Check if the ATA ports are enabled */ 213 /* Check if the ATA ports are enabled */
219 if ((pcicfg & 3) == 0) 214 if ((pcicfg & 3) == 0)
220 return -ENODEV; 215 return -ENODEV;
221 216
217 ppi[0] = ppi[1] = &ata_dummy_port_info;
218 if (pcicfg & 1)
219 ppi[0] = &pi;
220 if (pcicfg & 2)
221 ppi[1] = &pi;
222
222 if ((pcicfg & 0x40) == 0) { 223 if ((pcicfg & 0x40) == 0) {
223 printk(KERN_WARNING DRV_NAME ": DMA mode disabled. Enabling.\n"); 224 dev_printk(KERN_WARNING, &pdev->dev,
224 pci_write_config_byte(dev, 0x60, pcicfg | 0x40); 225 "DMA mode disabled. Enabling.\n");
226 pci_write_config_byte(pdev, 0x60, pcicfg | 0x40);
225 } 227 }
226 228
229 pi.mwdma_mask = id->driver_data;
230
231 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
232 if (!host)
233 return -ENOMEM;
234
227 /* Perform set up for DMA */ 235 /* Perform set up for DMA */
228 if (pci_enable_device_bars(dev, 1<<2)) { 236 if (pci_enable_device_bars(pdev, 1<<2)) {
229 printk(KERN_ERR DRV_NAME ": unable to configure BAR2.\n"); 237 printk(KERN_ERR DRV_NAME ": unable to configure BAR2.\n");
230 return -ENODEV; 238 return -ENODEV;
231 } 239 }
232 pci_set_master(dev); 240
233 if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) { 241 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
234 printk(KERN_ERR DRV_NAME ": unable to configure DMA mask.\n"); 242 printk(KERN_ERR DRV_NAME ": unable to configure DMA mask.\n");
235 return -ENODEV; 243 return -ENODEV;
236 } 244 }
237 if (pci_set_consistent_dma_mask(dev, DMA_32BIT_MASK)) { 245 if (pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) {
238 printk(KERN_ERR DRV_NAME ": unable to configure consistent DMA mask.\n"); 246 printk(KERN_ERR DRV_NAME ": unable to configure consistent DMA mask.\n");
239 return -ENODEV; 247 return -ENODEV;
240 } 248 }
241 249
242 /* Map IO ports */ 250 /* Map IO ports and initialize host accordingly */
243 iomap[0] = devm_ioport_map(&dev->dev, 0x1F0, 8); 251 iomap[0] = devm_ioport_map(&pdev->dev, 0x1F0, 8);
244 iomap[1] = devm_ioport_map(&dev->dev, 0x3F6, 1); 252 iomap[1] = devm_ioport_map(&pdev->dev, 0x3F6, 1);
245 iomap[2] = devm_ioport_map(&dev->dev, 0x170, 8); 253 iomap[2] = devm_ioport_map(&pdev->dev, 0x170, 8);
246 iomap[3] = devm_ioport_map(&dev->dev, 0x376, 1); 254 iomap[3] = devm_ioport_map(&pdev->dev, 0x376, 1);
247 iomap[4] = pcim_iomap(dev, 2, 0); 255 iomap[4] = pcim_iomap(pdev, 2, 0);
248 256
249 if (!iomap[0] || !iomap[1] || !iomap[2] || !iomap[3] || !iomap[4]) 257 if (!iomap[0] || !iomap[1] || !iomap[2] || !iomap[3] || !iomap[4])
250 return -ENOMEM; 258 return -ENOMEM;
251 259
252 /* We have to do our own plumbing as the PCI setup for this 260 ioaddr = &host->ports[0]->ioaddr;
253 chipset is non-standard so we can't punt to the libata code */ 261 ioaddr->cmd_addr = iomap[0];
254 262 ioaddr->ctl_addr = iomap[1];
255 INIT_LIST_HEAD(&probe[0].node); 263 ioaddr->altstatus_addr = iomap[1];
256 probe[0].dev = pci_dev_to_dev(dev); 264 ioaddr->bmdma_addr = iomap[4];
257 probe[0].port_ops = &cs5520_port_ops; 265 ata_std_ports(ioaddr);
258 probe[0].sht = &cs5520_sht; 266
259 probe[0].pio_mask = 0x1F; 267 ioaddr = &host->ports[1]->ioaddr;
260 probe[0].mwdma_mask = id->driver_data; 268 ioaddr->cmd_addr = iomap[2];
261 probe[0].irq = 14; 269 ioaddr->ctl_addr = iomap[3];
262 probe[0].irq_flags = 0; 270 ioaddr->altstatus_addr = iomap[3];
263 probe[0].port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST; 271 ioaddr->bmdma_addr = iomap[4] + 8;
264 probe[0].n_ports = 1; 272 ata_std_ports(ioaddr);
265 probe[0].port[0].cmd_addr = iomap[0]; 273
266 probe[0].port[0].ctl_addr = iomap[1]; 274 /* activate the host */
267 probe[0].port[0].altstatus_addr = iomap[1]; 275 pci_set_master(pdev);
268 probe[0].port[0].bmdma_addr = iomap[4]; 276 rc = ata_host_start(host);
269 277 if (rc)
270 /* The secondary lurks at different addresses but is otherwise 278 return rc;
271 the same beastie */ 279
272 280 for (i = 0; i < 2; i++) {
273 probe[1] = probe[0]; 281 static const int irq[] = { 14, 15 };
274 INIT_LIST_HEAD(&probe[1].node); 282 struct ata_port *ap = host->ports[0];
275 probe[1].irq = 15; 283
276 probe[1].port[0].cmd_addr = iomap[2]; 284 if (ata_port_is_dummy(ap))
277 probe[1].port[0].ctl_addr = iomap[3]; 285 continue;
278 probe[1].port[0].altstatus_addr = iomap[3]; 286
279 probe[1].port[0].bmdma_addr = iomap[4] + 8; 287 rc = devm_request_irq(&pdev->dev, irq[ap->port_no],
280 288 ata_interrupt, 0, DRV_NAME, host);
281 /* Let libata fill in the port details */ 289 if (rc)
282 ata_std_ports(&probe[0].port[0]); 290 return rc;
283 ata_std_ports(&probe[1].port[0]); 291 }
284 292
285 /* Now add the ports that are active */ 293 return ata_host_register(host, &cs5520_sht);
286 if (pcicfg & 1)
287 ports += ata_device_add(&probe[0]);
288 if (pcicfg & 2)
289 ports += ata_device_add(&probe[1]);
290 if (ports)
291 return 0;
292 return -ENODEV;
293} 294}
294 295
295/** 296/**
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index db63e80e608b..29642d5ee189 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -160,18 +160,6 @@ static unsigned int cs5530_qc_issue_prot(struct ata_queued_cmd *qc)
160 return ata_qc_issue_prot(qc); 160 return ata_qc_issue_prot(qc);
161} 161}
162 162
163static int cs5530_pre_reset(struct ata_port *ap)
164{
165 ap->cbl = ATA_CBL_PATA40;
166 return ata_std_prereset(ap);
167}
168
169static void cs5530_error_handler(struct ata_port *ap)
170{
171 return ata_bmdma_drive_eh(ap, cs5530_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
172}
173
174
175static struct scsi_host_template cs5530_sht = { 163static struct scsi_host_template cs5530_sht = {
176 .module = THIS_MODULE, 164 .module = THIS_MODULE,
177 .name = DRV_NAME, 165 .name = DRV_NAME,
@@ -213,8 +201,9 @@ static struct ata_port_operations cs5530_port_ops = {
213 201
214 .freeze = ata_bmdma_freeze, 202 .freeze = ata_bmdma_freeze,
215 .thaw = ata_bmdma_thaw, 203 .thaw = ata_bmdma_thaw,
216 .error_handler = cs5530_error_handler, 204 .error_handler = ata_bmdma_error_handler,
217 .post_internal_cmd = ata_bmdma_post_internal_cmd, 205 .post_internal_cmd = ata_bmdma_post_internal_cmd,
206 .cable_detect = ata_cable_40wire,
218 207
219 .qc_prep = ata_qc_prep, 208 .qc_prep = ata_qc_prep,
220 .qc_issue = cs5530_qc_issue_prot, 209 .qc_issue = cs5530_qc_issue_prot,
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 1572e5c9031a..08cccc9c659b 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -70,36 +70,23 @@
70#define CS5535_BAD_PIO(timings) ( (timings&~0x80000000UL)==0x00009172 ) 70#define CS5535_BAD_PIO(timings) ( (timings&~0x80000000UL)==0x00009172 )
71 71
72/** 72/**
73 * cs5535_pre_reset - detect cable type 73 * cs5535_cable_detect - detect cable type
74 * @ap: Port to detect on 74 * @ap: Port to detect on
75 * 75 *
76 * Perform cable detection for ATA66 capable cable. Return a libata 76 * Perform cable detection for ATA66 capable cable. Return a libata
77 * cable type. 77 * cable type.
78 */ 78 */
79 79
80static int cs5535_pre_reset(struct ata_port *ap) 80static int cs5535_cable_detect(struct ata_port *ap)
81{ 81{
82 u8 cable; 82 u8 cable;
83 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 83 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
84 84
85 pci_read_config_byte(pdev, CS5535_CABLE_DETECT, &cable); 85 pci_read_config_byte(pdev, CS5535_CABLE_DETECT, &cable);
86 if (cable & 1) 86 if (cable & 1)
87 ap->cbl = ATA_CBL_PATA80; 87 return ATA_CBL_PATA80;
88 else 88 else
89 ap->cbl = ATA_CBL_PATA40; 89 return ATA_CBL_PATA40;
90 return ata_std_prereset(ap);
91}
92
93/**
94 * cs5535_error_handler - reset/probe
95 * @ap: Port to reset
96 *
97 * Reset and configure a port
98 */
99
100static void cs5535_error_handler(struct ata_port *ap)
101{
102 ata_bmdma_drive_eh(ap, cs5535_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
103} 90}
104 91
105/** 92/**
@@ -205,8 +192,9 @@ static struct ata_port_operations cs5535_port_ops = {
205 192
206 .freeze = ata_bmdma_freeze, 193 .freeze = ata_bmdma_freeze,
207 .thaw = ata_bmdma_thaw, 194 .thaw = ata_bmdma_thaw,
208 .error_handler = cs5535_error_handler, 195 .error_handler = ata_bmdma_error_handler,
209 .post_internal_cmd = ata_bmdma_post_internal_cmd, 196 .post_internal_cmd = ata_bmdma_post_internal_cmd,
197 .cable_detect = cs5535_cable_detect,
210 198
211 .bmdma_setup = ata_bmdma_setup, 199 .bmdma_setup = ata_bmdma_setup,
212 .bmdma_start = ata_bmdma_start, 200 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index f69dde5f7066..6ec049c3b1dc 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -41,17 +41,6 @@ enum {
41 CY82_INDEX_TIMEOUT = 0x32 41 CY82_INDEX_TIMEOUT = 0x32
42}; 42};
43 43
44static int cy82c693_pre_reset(struct ata_port *ap)
45{
46 ap->cbl = ATA_CBL_PATA40;
47 return ata_std_prereset(ap);
48}
49
50static void cy82c693_error_handler(struct ata_port *ap)
51{
52 ata_bmdma_drive_eh(ap, cy82c693_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
53}
54
55/** 44/**
56 * cy82c693_set_piomode - set initial PIO mode data 45 * cy82c693_set_piomode - set initial PIO mode data
57 * @ap: ATA interface 46 * @ap: ATA interface
@@ -156,8 +145,9 @@ static struct ata_port_operations cy82c693_port_ops = {
156 145
157 .freeze = ata_bmdma_freeze, 146 .freeze = ata_bmdma_freeze,
158 .thaw = ata_bmdma_thaw, 147 .thaw = ata_bmdma_thaw,
159 .error_handler = cy82c693_error_handler, 148 .error_handler = ata_bmdma_error_handler,
160 .post_internal_cmd = ata_bmdma_post_internal_cmd, 149 .post_internal_cmd = ata_bmdma_post_internal_cmd,
150 .cable_detect = ata_cable_40wire,
161 151
162 .bmdma_setup = ata_bmdma_setup, 152 .bmdma_setup = ata_bmdma_setup,
163 .bmdma_start = ata_bmdma_start, 153 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index dac7a6554f6c..a3216850bba1 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -22,10 +22,10 @@
22#include <linux/ata.h> 22#include <linux/ata.h>
23 23
24#define DRV_NAME "pata_efar" 24#define DRV_NAME "pata_efar"
25#define DRV_VERSION "0.4.3" 25#define DRV_VERSION "0.4.4"
26 26
27/** 27/**
28 * efar_pre_reset - check for 40/80 pin 28 * efar_pre_reset - Enable bits
29 * @ap: Port 29 * @ap: Port
30 * 30 *
31 * Perform cable detection for the EFAR ATA interface. This is 31 * Perform cable detection for the EFAR ATA interface. This is
@@ -38,18 +38,11 @@ static int efar_pre_reset(struct ata_port *ap)
38 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 38 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
39 { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */ 39 { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
40 }; 40 };
41
42 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 41 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
43 u8 tmp;
44 42
45 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no])) 43 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no]))
46 return -ENOENT; 44 return -ENOENT;
47 45
48 pci_read_config_byte(pdev, 0x47, &tmp);
49 if (tmp & (2 >> ap->port_no))
50 ap->cbl = ATA_CBL_PATA40;
51 else
52 ap->cbl = ATA_CBL_PATA80;
53 return ata_std_prereset(ap); 46 return ata_std_prereset(ap);
54} 47}
55 48
@@ -67,6 +60,25 @@ static void efar_error_handler(struct ata_port *ap)
67} 60}
68 61
69/** 62/**
63 * efar_cable_detect - check for 40/80 pin
64 * @ap: Port
65 *
66 * Perform cable detection for the EFAR ATA interface. This is
67 * different to the PIIX arrangement
68 */
69
70static int efar_cable_detect(struct ata_port *ap)
71{
72 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
73 u8 tmp;
74
75 pci_read_config_byte(pdev, 0x47, &tmp);
76 if (tmp & (2 >> ap->port_no))
77 return ATA_CBL_PATA40;
78 return ATA_CBL_PATA80;
79}
80
81/**
70 * efar_set_piomode - Initialize host controller PATA PIO timings 82 * efar_set_piomode - Initialize host controller PATA PIO timings
71 * @ap: Port whose timings we are configuring 83 * @ap: Port whose timings we are configuring
72 * @adev: um 84 * @adev: um
@@ -256,6 +268,7 @@ static const struct ata_port_operations efar_ops = {
256 .thaw = ata_bmdma_thaw, 268 .thaw = ata_bmdma_thaw,
257 .error_handler = efar_error_handler, 269 .error_handler = efar_error_handler,
258 .post_internal_cmd = ata_bmdma_post_internal_cmd, 270 .post_internal_cmd = ata_bmdma_post_internal_cmd,
271 .cable_detect = efar_cable_detect,
259 272
260 .bmdma_setup = ata_bmdma_setup, 273 .bmdma_setup = ata_bmdma_setup,
261 .bmdma_start = ata_bmdma_start, 274 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index baf35f876030..93cfa6d300a5 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -27,7 +27,7 @@
27#include <linux/libata.h> 27#include <linux/libata.h>
28 28
29#define DRV_NAME "pata_hpt366" 29#define DRV_NAME "pata_hpt366"
30#define DRV_VERSION "0.6.0" 30#define DRV_VERSION "0.6.1"
31 31
32struct hpt_clock { 32struct hpt_clock {
33 u8 xfer_speed; 33 u8 xfer_speed;
@@ -169,13 +169,12 @@ static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, cons
169 169
170/** 170/**
171 * hpt366_filter - mode selection filter 171 * hpt366_filter - mode selection filter
172 * @ap: ATA interface
173 * @adev: ATA device 172 * @adev: ATA device
174 * 173 *
175 * Block UDMA on devices that cause trouble with this controller. 174 * Block UDMA on devices that cause trouble with this controller.
176 */ 175 */
177 176
178static unsigned long hpt366_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 177static unsigned long hpt366_filter(struct ata_device *adev, unsigned long mask)
179{ 178{
180 if (adev->class == ATA_DEV_ATA) { 179 if (adev->class == ATA_DEV_ATA) {
181 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33)) 180 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
@@ -185,7 +184,7 @@ static unsigned long hpt366_filter(const struct ata_port *ap, struct ata_device
185 if (hpt_dma_blacklisted(adev, "UDMA4", bad_ata66_4)) 184 if (hpt_dma_blacklisted(adev, "UDMA4", bad_ata66_4))
186 mask &= ~(0x0F << ATA_SHIFT_UDMA); 185 mask &= ~(0x0F << ATA_SHIFT_UDMA);
187 } 186 }
188 return ata_pci_default_filter(ap, adev, mask); 187 return ata_pci_default_filter(adev, mask);
189} 188}
190 189
191/** 190/**
@@ -210,24 +209,28 @@ static u32 hpt36x_find_mode(struct ata_port *ap, int speed)
210 return 0xffffffffU; /* silence compiler warning */ 209 return 0xffffffffU; /* silence compiler warning */
211} 210}
212 211
212static int hpt36x_cable_detect(struct ata_port *ap)
213{
214 u8 ata66;
215 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
216
217 pci_read_config_byte(pdev, 0x5A, &ata66);
218 if (ata66 & (1 << ap->port_no))
219 return ATA_CBL_PATA40;
220 return ATA_CBL_PATA80;
221}
222
213static int hpt36x_pre_reset(struct ata_port *ap) 223static int hpt36x_pre_reset(struct ata_port *ap)
214{ 224{
215 static const struct pci_bits hpt36x_enable_bits[] = { 225 static const struct pci_bits hpt36x_enable_bits[] = {
216 { 0x50, 1, 0x04, 0x04 }, 226 { 0x50, 1, 0x04, 0x04 },
217 { 0x54, 1, 0x04, 0x04 } 227 { 0x54, 1, 0x04, 0x04 }
218 }; 228 };
219
220 u8 ata66;
221 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 229 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
222 230
223 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no])) 231 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no]))
224 return -ENOENT; 232 return -ENOENT;
225 233
226 pci_read_config_byte(pdev, 0x5A, &ata66);
227 if (ata66 & (1 << ap->port_no))
228 ap->cbl = ATA_CBL_PATA40;
229 else
230 ap->cbl = ATA_CBL_PATA80;
231 return ata_std_prereset(ap); 234 return ata_std_prereset(ap);
232} 235}
233 236
@@ -354,6 +357,7 @@ static struct ata_port_operations hpt366_port_ops = {
354 .thaw = ata_bmdma_thaw, 357 .thaw = ata_bmdma_thaw,
355 .error_handler = hpt36x_error_handler, 358 .error_handler = hpt36x_error_handler,
356 .post_internal_cmd = ata_bmdma_post_internal_cmd, 359 .post_internal_cmd = ata_bmdma_post_internal_cmd,
360 .cable_detect = hpt36x_cable_detect,
357 361
358 .bmdma_setup = ata_bmdma_setup, 362 .bmdma_setup = ata_bmdma_setup,
359 .bmdma_start = ata_bmdma_start, 363 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index f331eeeafa0f..41d831296347 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -8,6 +8,7 @@
8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
9 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 9 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
10 * Portions Copyright (C) 2003 Red Hat Inc 10 * Portions Copyright (C) 2003 Red Hat Inc
11 * Portions Copyright (C) 2005-2006 MontaVista Software, Inc.
11 * 12 *
12 * TODO 13 * TODO
13 * PLL mode 14 * PLL mode
@@ -25,7 +26,7 @@
25#include <linux/libata.h> 26#include <linux/libata.h>
26 27
27#define DRV_NAME "pata_hpt37x" 28#define DRV_NAME "pata_hpt37x"
28#define DRV_VERSION "0.6.0" 29#define DRV_VERSION "0.6.5"
29 30
30struct hpt_clock { 31struct hpt_clock {
31 u8 xfer_speed; 32 u8 xfer_speed;
@@ -61,201 +62,75 @@ struct hpt_chip {
61 * 31 FIFO enable. 62 * 31 FIFO enable.
62 */ 63 */
63 64
64/* from highpoint documentation. these are old values */ 65static struct hpt_clock hpt37x_timings_33[] = {
65static const struct hpt_clock hpt370_timings_33[] = { 66 { XFER_UDMA_6, 0x12446231 }, /* 0x12646231 ?? */
66/* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */ 67 { XFER_UDMA_5, 0x12446231 },
67 { XFER_UDMA_5, 0x16454e31 }, 68 { XFER_UDMA_4, 0x12446231 },
68 { XFER_UDMA_4, 0x16454e31 }, 69 { XFER_UDMA_3, 0x126c6231 },
69 { XFER_UDMA_3, 0x166d4e31 }, 70 { XFER_UDMA_2, 0x12486231 },
70 { XFER_UDMA_2, 0x16494e31 }, 71 { XFER_UDMA_1, 0x124c6233 },
71 { XFER_UDMA_1, 0x164d4e31 }, 72 { XFER_UDMA_0, 0x12506297 },
72 { XFER_UDMA_0, 0x16514e31 }, 73
73 74 { XFER_MW_DMA_2, 0x22406c31 },
74 { XFER_MW_DMA_2, 0x26514e21 }, 75 { XFER_MW_DMA_1, 0x22406c33 },
75 { XFER_MW_DMA_1, 0x26514e33 }, 76 { XFER_MW_DMA_0, 0x22406c97 },
76 { XFER_MW_DMA_0, 0x26514e97 }, 77
77 78 { XFER_PIO_4, 0x06414e31 },
78 { XFER_PIO_4, 0x06514e21 }, 79 { XFER_PIO_3, 0x06414e42 },
79 { XFER_PIO_3, 0x06514e22 }, 80 { XFER_PIO_2, 0x06414e53 },
80 { XFER_PIO_2, 0x06514e33 }, 81 { XFER_PIO_1, 0x06814e93 },
81 { XFER_PIO_1, 0x06914e43 }, 82 { XFER_PIO_0, 0x06814ea7 }
82 { XFER_PIO_0, 0x06914e57 },
83 { 0, 0x06514e57 }
84}; 83};
85 84
86static const struct hpt_clock hpt370_timings_66[] = { 85static struct hpt_clock hpt37x_timings_50[] = {
87 { XFER_UDMA_5, 0x14846231 }, 86 { XFER_UDMA_6, 0x12848242 },
88 { XFER_UDMA_4, 0x14886231 }, 87 { XFER_UDMA_5, 0x12848242 },
89 { XFER_UDMA_3, 0x148c6231 }, 88 { XFER_UDMA_4, 0x12ac8242 },
90 { XFER_UDMA_2, 0x148c6231 }, 89 { XFER_UDMA_3, 0x128c8242 },
91 { XFER_UDMA_1, 0x14906231 }, 90 { XFER_UDMA_2, 0x120c8242 },
92 { XFER_UDMA_0, 0x14986231 }, 91 { XFER_UDMA_1, 0x12148254 },
93 92 { XFER_UDMA_0, 0x121882ea },
94 { XFER_MW_DMA_2, 0x26514e21 }, 93
95 { XFER_MW_DMA_1, 0x26514e33 }, 94 { XFER_MW_DMA_2, 0x22808242 },
96 { XFER_MW_DMA_0, 0x26514e97 }, 95 { XFER_MW_DMA_1, 0x22808254 },
97 96 { XFER_MW_DMA_0, 0x228082ea },
98 { XFER_PIO_4, 0x06514e21 }, 97
99 { XFER_PIO_3, 0x06514e22 }, 98 { XFER_PIO_4, 0x0a81f442 },
100 { XFER_PIO_2, 0x06514e33 }, 99 { XFER_PIO_3, 0x0a81f443 },
101 { XFER_PIO_1, 0x06914e43 }, 100 { XFER_PIO_2, 0x0a81f454 },
102 { XFER_PIO_0, 0x06914e57 }, 101 { XFER_PIO_1, 0x0ac1f465 },
103 { 0, 0x06514e57 } 102 { XFER_PIO_0, 0x0ac1f48a }
104}; 103};
105 104
106/* these are the current (4 sep 2001) timings from highpoint */ 105static struct hpt_clock hpt37x_timings_66[] = {
107static const struct hpt_clock hpt370a_timings_33[] = { 106 { XFER_UDMA_6, 0x1c869c62 },
108 { XFER_UDMA_5, 0x12446231 }, 107 { XFER_UDMA_5, 0x1cae9c62 }, /* 0x1c8a9c62 */
109 { XFER_UDMA_4, 0x12446231 }, 108 { XFER_UDMA_4, 0x1c8a9c62 },
110 { XFER_UDMA_3, 0x126c6231 }, 109 { XFER_UDMA_3, 0x1c8e9c62 },
111 { XFER_UDMA_2, 0x12486231 }, 110 { XFER_UDMA_2, 0x1c929c62 },
112 { XFER_UDMA_1, 0x124c6233 }, 111 { XFER_UDMA_1, 0x1c9a9c62 },
113 { XFER_UDMA_0, 0x12506297 }, 112 { XFER_UDMA_0, 0x1c829c62 },
114 113
115 { XFER_MW_DMA_2, 0x22406c31 }, 114 { XFER_MW_DMA_2, 0x2c829c62 },
116 { XFER_MW_DMA_1, 0x22406c33 }, 115 { XFER_MW_DMA_1, 0x2c829c66 },
117 { XFER_MW_DMA_0, 0x22406c97 }, 116 { XFER_MW_DMA_0, 0x2c829d2e },
118 117
119 { XFER_PIO_4, 0x06414e31 }, 118 { XFER_PIO_4, 0x0c829c62 },
120 { XFER_PIO_3, 0x06414e42 }, 119 { XFER_PIO_3, 0x0c829c84 },
121 { XFER_PIO_2, 0x06414e53 }, 120 { XFER_PIO_2, 0x0c829ca6 },
122 { XFER_PIO_1, 0x06814e93 }, 121 { XFER_PIO_1, 0x0d029d26 },
123 { XFER_PIO_0, 0x06814ea7 }, 122 { XFER_PIO_0, 0x0d029d5e }
124 { 0, 0x06814ea7 }
125}; 123};
126 124
127/* 2x 33MHz timings */
128static const struct hpt_clock hpt370a_timings_66[] = {
129 { XFER_UDMA_5, 0x1488e673 },
130 { XFER_UDMA_4, 0x1488e673 },
131 { XFER_UDMA_3, 0x1498e673 },
132 { XFER_UDMA_2, 0x1490e673 },
133 { XFER_UDMA_1, 0x1498e677 },
134 { XFER_UDMA_0, 0x14a0e73f },
135
136 { XFER_MW_DMA_2, 0x2480fa73 },
137 { XFER_MW_DMA_1, 0x2480fa77 },
138 { XFER_MW_DMA_0, 0x2480fb3f },
139
140 { XFER_PIO_4, 0x0c82be73 },
141 { XFER_PIO_3, 0x0c82be95 },
142 { XFER_PIO_2, 0x0c82beb7 },
143 { XFER_PIO_1, 0x0d02bf37 },
144 { XFER_PIO_0, 0x0d02bf5f },
145 { 0, 0x0d02bf5f }
146};
147
148static const struct hpt_clock hpt370a_timings_50[] = {
149 { XFER_UDMA_5, 0x12848242 },
150 { XFER_UDMA_4, 0x12ac8242 },
151 { XFER_UDMA_3, 0x128c8242 },
152 { XFER_UDMA_2, 0x120c8242 },
153 { XFER_UDMA_1, 0x12148254 },
154 { XFER_UDMA_0, 0x121882ea },
155
156 { XFER_MW_DMA_2, 0x22808242 },
157 { XFER_MW_DMA_1, 0x22808254 },
158 { XFER_MW_DMA_0, 0x228082ea },
159
160 { XFER_PIO_4, 0x0a81f442 },
161 { XFER_PIO_3, 0x0a81f443 },
162 { XFER_PIO_2, 0x0a81f454 },
163 { XFER_PIO_1, 0x0ac1f465 },
164 { XFER_PIO_0, 0x0ac1f48a },
165 { 0, 0x0ac1f48a }
166};
167
168static const struct hpt_clock hpt372_timings_33[] = {
169 { XFER_UDMA_6, 0x1c81dc62 },
170 { XFER_UDMA_5, 0x1c6ddc62 },
171 { XFER_UDMA_4, 0x1c8ddc62 },
172 { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */
173 { XFER_UDMA_2, 0x1c91dc62 },
174 { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */
175 { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */
176
177 { XFER_MW_DMA_2, 0x2c829262 },
178 { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */
179 { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */
180
181 { XFER_PIO_4, 0x0c829c62 },
182 { XFER_PIO_3, 0x0c829c84 },
183 { XFER_PIO_2, 0x0c829ca6 },
184 { XFER_PIO_1, 0x0d029d26 },
185 { XFER_PIO_0, 0x0d029d5e },
186 { 0, 0x0d029d5e }
187};
188
189static const struct hpt_clock hpt372_timings_50[] = {
190 { XFER_UDMA_5, 0x12848242 },
191 { XFER_UDMA_4, 0x12ac8242 },
192 { XFER_UDMA_3, 0x128c8242 },
193 { XFER_UDMA_2, 0x120c8242 },
194 { XFER_UDMA_1, 0x12148254 },
195 { XFER_UDMA_0, 0x121882ea },
196
197 { XFER_MW_DMA_2, 0x22808242 },
198 { XFER_MW_DMA_1, 0x22808254 },
199 { XFER_MW_DMA_0, 0x228082ea },
200
201 { XFER_PIO_4, 0x0a81f442 },
202 { XFER_PIO_3, 0x0a81f443 },
203 { XFER_PIO_2, 0x0a81f454 },
204 { XFER_PIO_1, 0x0ac1f465 },
205 { XFER_PIO_0, 0x0ac1f48a },
206 { 0, 0x0a81f443 }
207};
208
209static const struct hpt_clock hpt372_timings_66[] = {
210 { XFER_UDMA_6, 0x1c869c62 },
211 { XFER_UDMA_5, 0x1cae9c62 },
212 { XFER_UDMA_4, 0x1c8a9c62 },
213 { XFER_UDMA_3, 0x1c8e9c62 },
214 { XFER_UDMA_2, 0x1c929c62 },
215 { XFER_UDMA_1, 0x1c9a9c62 },
216 { XFER_UDMA_0, 0x1c829c62 },
217
218 { XFER_MW_DMA_2, 0x2c829c62 },
219 { XFER_MW_DMA_1, 0x2c829c66 },
220 { XFER_MW_DMA_0, 0x2c829d2e },
221
222 { XFER_PIO_4, 0x0c829c62 },
223 { XFER_PIO_3, 0x0c829c84 },
224 { XFER_PIO_2, 0x0c829ca6 },
225 { XFER_PIO_1, 0x0d029d26 },
226 { XFER_PIO_0, 0x0d029d5e },
227 { 0, 0x0d029d26 }
228};
229
230static const struct hpt_clock hpt374_timings_33[] = {
231 { XFER_UDMA_6, 0x12808242 },
232 { XFER_UDMA_5, 0x12848242 },
233 { XFER_UDMA_4, 0x12ac8242 },
234 { XFER_UDMA_3, 0x128c8242 },
235 { XFER_UDMA_2, 0x120c8242 },
236 { XFER_UDMA_1, 0x12148254 },
237 { XFER_UDMA_0, 0x121882ea },
238
239 { XFER_MW_DMA_2, 0x22808242 },
240 { XFER_MW_DMA_1, 0x22808254 },
241 { XFER_MW_DMA_0, 0x228082ea },
242
243 { XFER_PIO_4, 0x0a81f442 },
244 { XFER_PIO_3, 0x0a81f443 },
245 { XFER_PIO_2, 0x0a81f454 },
246 { XFER_PIO_1, 0x0ac1f465 },
247 { XFER_PIO_0, 0x0ac1f48a },
248 { 0, 0x06814e93 }
249};
250 125
251static const struct hpt_chip hpt370 = { 126static const struct hpt_chip hpt370 = {
252 "HPT370", 127 "HPT370",
253 48, 128 48,
254 { 129 {
255 hpt370_timings_33, 130 hpt37x_timings_33,
256 NULL, 131 NULL,
257 NULL, 132 NULL,
258 hpt370_timings_66 133 NULL
259 } 134 }
260}; 135};
261 136
@@ -263,10 +138,10 @@ static const struct hpt_chip hpt370a = {
263 "HPT370A", 138 "HPT370A",
264 48, 139 48,
265 { 140 {
266 hpt370a_timings_33, 141 hpt37x_timings_33,
267 NULL, 142 NULL,
268 hpt370a_timings_50, 143 hpt37x_timings_50,
269 hpt370a_timings_66 144 NULL
270 } 145 }
271}; 146};
272 147
@@ -274,10 +149,10 @@ static const struct hpt_chip hpt372 = {
274 "HPT372", 149 "HPT372",
275 55, 150 55,
276 { 151 {
277 hpt372_timings_33, 152 hpt37x_timings_33,
278 NULL, 153 NULL,
279 hpt372_timings_50, 154 hpt37x_timings_50,
280 hpt372_timings_66 155 hpt37x_timings_66
281 } 156 }
282}; 157};
283 158
@@ -285,10 +160,10 @@ static const struct hpt_chip hpt302 = {
285 "HPT302", 160 "HPT302",
286 66, 161 66,
287 { 162 {
288 hpt372_timings_33, 163 hpt37x_timings_33,
289 NULL, 164 NULL,
290 hpt372_timings_50, 165 hpt37x_timings_50,
291 hpt372_timings_66 166 hpt37x_timings_66
292 } 167 }
293}; 168};
294 169
@@ -296,10 +171,10 @@ static const struct hpt_chip hpt371 = {
296 "HPT371", 171 "HPT371",
297 66, 172 66,
298 { 173 {
299 hpt372_timings_33, 174 hpt37x_timings_33,
300 NULL, 175 NULL,
301 hpt372_timings_50, 176 hpt37x_timings_50,
302 hpt372_timings_66 177 hpt37x_timings_66
303 } 178 }
304}; 179};
305 180
@@ -307,10 +182,10 @@ static const struct hpt_chip hpt372a = {
307 "HPT372A", 182 "HPT372A",
308 66, 183 66,
309 { 184 {
310 hpt372_timings_33, 185 hpt37x_timings_33,
311 NULL, 186 NULL,
312 hpt372_timings_50, 187 hpt37x_timings_50,
313 hpt372_timings_66 188 hpt37x_timings_66
314 } 189 }
315}; 190};
316 191
@@ -318,7 +193,7 @@ static const struct hpt_chip hpt374 = {
318 "HPT374", 193 "HPT374",
319 48, 194 48,
320 { 195 {
321 hpt374_timings_33, 196 hpt37x_timings_33,
322 NULL, 197 NULL,
323 NULL, 198 NULL,
324 NULL 199 NULL
@@ -397,13 +272,12 @@ static const char *bad_ata100_5[] = {
397 272
398/** 273/**
399 * hpt370_filter - mode selection filter 274 * hpt370_filter - mode selection filter
400 * @ap: ATA interface
401 * @adev: ATA device 275 * @adev: ATA device
402 * 276 *
403 * Block UDMA on devices that cause trouble with this controller. 277 * Block UDMA on devices that cause trouble with this controller.
404 */ 278 */
405 279
406static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 280static unsigned long hpt370_filter(struct ata_device *adev, unsigned long mask)
407{ 281{
408 if (adev->class == ATA_DEV_ATA) { 282 if (adev->class == ATA_DEV_ATA) {
409 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33)) 283 if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
@@ -411,24 +285,23 @@ static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device
411 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5)) 285 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
412 mask &= ~(0x1F << ATA_SHIFT_UDMA); 286 mask &= ~(0x1F << ATA_SHIFT_UDMA);
413 } 287 }
414 return ata_pci_default_filter(ap, adev, mask); 288 return ata_pci_default_filter(adev, mask);
415} 289}
416 290
417/** 291/**
418 * hpt370a_filter - mode selection filter 292 * hpt370a_filter - mode selection filter
419 * @ap: ATA interface
420 * @adev: ATA device 293 * @adev: ATA device
421 * 294 *
422 * Block UDMA on devices that cause trouble with this controller. 295 * Block UDMA on devices that cause trouble with this controller.
423 */ 296 */
424 297
425static unsigned long hpt370a_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 298static unsigned long hpt370a_filter(struct ata_device *adev, unsigned long mask)
426{ 299{
427 if (adev->class != ATA_DEV_ATA) { 300 if (adev->class != ATA_DEV_ATA) {
428 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5)) 301 if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
429 mask &= ~ (0x1F << ATA_SHIFT_UDMA); 302 mask &= ~ (0x1F << ATA_SHIFT_UDMA);
430 } 303 }
431 return ata_pci_default_filter(ap, adev, mask); 304 return ata_pci_default_filter(adev, mask);
432} 305}
433 306
434/** 307/**
@@ -462,8 +335,7 @@ static int hpt37x_pre_reset(struct ata_port *ap)
462 ap->cbl = ATA_CBL_PATA80; 335 ap->cbl = ATA_CBL_PATA80;
463 336
464 /* Reset the state machine */ 337 /* Reset the state machine */
465 pci_write_config_byte(pdev, 0x50, 0x37); 338 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
466 pci_write_config_byte(pdev, 0x54, 0x37);
467 udelay(100); 339 udelay(100);
468 340
469 return ata_std_prereset(ap); 341 return ata_std_prereset(ap);
@@ -513,8 +385,7 @@ static int hpt374_pre_reset(struct ata_port *ap)
513 ap->cbl = ATA_CBL_PATA80; 385 ap->cbl = ATA_CBL_PATA80;
514 386
515 /* Reset the state machine */ 387 /* Reset the state machine */
516 pci_write_config_byte(pdev, 0x50, 0x37); 388 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
517 pci_write_config_byte(pdev, 0x54, 0x37);
518 udelay(100); 389 udelay(100);
519 390
520 return ata_std_prereset(ap); 391 return ata_std_prereset(ap);
@@ -1032,6 +903,24 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1032 .udma_mask = 0x3f, 903 .udma_mask = 0x3f,
1033 .port_ops = &hpt370a_port_ops 904 .port_ops = &hpt370a_port_ops
1034 }; 905 };
906 /* HPT370 - UDMA100 */
907 static struct ata_port_info info_hpt370_33 = {
908 .sht = &hpt37x_sht,
909 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
910 .pio_mask = 0x1f,
911 .mwdma_mask = 0x07,
912 .udma_mask = 0x0f,
913 .port_ops = &hpt370_port_ops
914 };
915 /* HPT370A - UDMA100 */
916 static struct ata_port_info info_hpt370a_33 = {
917 .sht = &hpt37x_sht,
918 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
919 .pio_mask = 0x1f,
920 .mwdma_mask = 0x07,
921 .udma_mask = 0x0f,
922 .port_ops = &hpt370a_port_ops
923 };
1035 /* HPT371, 372 and friends - UDMA133 */ 924 /* HPT371, 372 and friends - UDMA133 */
1036 static struct ata_port_info info_hpt372 = { 925 static struct ata_port_info info_hpt372 = {
1037 .sht = &hpt37x_sht, 926 .sht = &hpt37x_sht,
@@ -1067,7 +956,11 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1067 956
1068 u8 irqmask; 957 u8 irqmask;
1069 u32 class_rev; 958 u32 class_rev;
959 u8 mcr1;
1070 u32 freq; 960 u32 freq;
961 int prefer_dpll = 1;
962
963 unsigned long iobase = pci_resource_start(dev, 4);
1071 964
1072 const struct hpt_chip *chip_table; 965 const struct hpt_chip *chip_table;
1073 int clock_slot; 966 int clock_slot;
@@ -1088,10 +981,12 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1088 case 3: 981 case 3:
1089 port = &info_hpt370; 982 port = &info_hpt370;
1090 chip_table = &hpt370; 983 chip_table = &hpt370;
984 prefer_dpll = 0;
1091 break; 985 break;
1092 case 4: 986 case 4:
1093 port = &info_hpt370a; 987 port = &info_hpt370a;
1094 chip_table = &hpt370a; 988 chip_table = &hpt370a;
989 prefer_dpll = 0;
1095 break; 990 break;
1096 case 5: 991 case 5:
1097 port = &info_hpt372; 992 port = &info_hpt372;
@@ -1119,8 +1014,16 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1119 chip_table = &hpt302; 1014 chip_table = &hpt302;
1120 break; 1015 break;
1121 case PCI_DEVICE_ID_TTI_HPT371: 1016 case PCI_DEVICE_ID_TTI_HPT371:
1017 if (class_rev > 1)
1018 return -ENODEV;
1122 port = &info_hpt372; 1019 port = &info_hpt372;
1123 chip_table = &hpt371; 1020 chip_table = &hpt371;
1021 /* Single channel device, master is not present
1022 but the BIOS (or us for non x86) must mark it
1023 absent */
1024 pci_read_config_byte(dev, 0x50, &mcr1);
1025 mcr1 &= ~0x04;
1026 pci_write_config_byte(dev, 0x50, mcr1);
1124 break; 1027 break;
1125 case PCI_DEVICE_ID_TTI_HPT374: 1028 case PCI_DEVICE_ID_TTI_HPT374:
1126 chip_table = &hpt374; 1029 chip_table = &hpt374;
@@ -1150,8 +1053,18 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1150 */ 1053 */
1151 1054
1152 pci_write_config_byte(dev, 0x5b, 0x23); 1055 pci_write_config_byte(dev, 0x5b, 0x23);
1056
1057 /*
1058 * HighPoint does this for HPT372A.
1059 * NOTE: This register is only writeable via I/O space.
1060 */
1061 if (chip_table == &hpt372a)
1062 outb(0x0e, iobase + 0x9c);
1153 1063
1154 pci_read_config_dword(dev, 0x70, &freq); 1064 /* Some devices do not let this value be accessed via PCI space
1065 according to the old driver */
1066
1067 freq = inl(iobase + 0x90);
1155 if ((freq >> 12) != 0xABCDE) { 1068 if ((freq >> 12) != 0xABCDE) {
1156 int i; 1069 int i;
1157 u8 sr; 1070 u8 sr;
@@ -1162,7 +1075,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1162 /* This is the process the HPT371 BIOS is reported to use */ 1075 /* This is the process the HPT371 BIOS is reported to use */
1163 for(i = 0; i < 128; i++) { 1076 for(i = 0; i < 128; i++) {
1164 pci_read_config_byte(dev, 0x78, &sr); 1077 pci_read_config_byte(dev, 0x78, &sr);
1165 total += sr; 1078 total += sr & 0x1FF;
1166 udelay(15); 1079 udelay(15);
1167 } 1080 }
1168 freq = total / 128; 1081 freq = total / 128;
@@ -1173,15 +1086,27 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1173 * Turn the frequency check into a band and then find a timing 1086 * Turn the frequency check into a band and then find a timing
1174 * table to match it. 1087 * table to match it.
1175 */ 1088 */
1176 1089
1177 clock_slot = hpt37x_clock_slot(freq, chip_table->base); 1090 clock_slot = hpt37x_clock_slot(freq, chip_table->base);
1178 if (chip_table->clocks[clock_slot] == NULL) { 1091 if (chip_table->clocks[clock_slot] == NULL || prefer_dpll) {
1179 /* 1092 /*
1180 * We need to try PLL mode instead 1093 * We need to try PLL mode instead
1094 *
1095 * For non UDMA133 capable devices we should
1096 * use a 50MHz DPLL by choice
1181 */ 1097 */
1182 unsigned int f_low = (MHz[clock_slot] * chip_table->base) / 192; 1098 unsigned int f_low, f_high;
1183 unsigned int f_high = f_low + 2;
1184 int adjust; 1099 int adjust;
1100
1101 clock_slot = 2;
1102 if (port->udma_mask & 0xE0)
1103 clock_slot = 3;
1104
1105 f_low = (MHz[clock_slot] * chip_table->base) / 192;
1106 f_high = f_low + 2;
1107
1108 /* Select the DPLL clock. */
1109 pci_write_config_byte(dev, 0x5b, 0x21);
1185 1110
1186 for(adjust = 0; adjust < 8; adjust++) { 1111 for(adjust = 0; adjust < 8; adjust++) {
1187 if (hpt37x_calibrate_dpll(dev)) 1112 if (hpt37x_calibrate_dpll(dev))
@@ -1197,25 +1122,27 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1197 printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n"); 1122 printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n");
1198 return -ENODEV; 1123 return -ENODEV;
1199 } 1124 }
1200 /* Check if this works for all cases */ 1125 if (clock_slot == 3)
1201 port->private_data = (void *)hpt370_timings_66; 1126 port->private_data = (void *)hpt37x_timings_66;
1127 else
1128 port->private_data = (void *)hpt37x_timings_50;
1202 1129
1203 printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]); 1130 printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]);
1204 } else { 1131 } else {
1205 port->private_data = (void *)chip_table->clocks[clock_slot]; 1132 port->private_data = (void *)chip_table->clocks[clock_slot];
1206 /* 1133 /*
1207 * Perform a final fixup. The 371 and 372 clock determines 1134 * Perform a final fixup. Note that we will have used the
1208 * if UDMA133 is available. 1135 * DPLL on the HPT372 which means we don't have to worry
1209 */ 1136 * about lack of UDMA133 support on lower clocks
1210 1137 */
1211 if (clock_slot == 2 && chip_table == &hpt372) { /* 50Mhz */ 1138
1212 printk(KERN_WARNING "pata_hpt37x: No UDMA133 support available with 50MHz bus clock.\n"); 1139 if (clock_slot < 2 && port == &info_hpt370)
1213 if (port == &info_hpt372) 1140 port = &info_hpt370_33;
1214 port = &info_hpt372_50; 1141 if (clock_slot < 2 && port == &info_hpt370a)
1215 else BUG(); 1142 port = &info_hpt370a_33;
1216 }
1217 printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]); 1143 printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]);
1218 } 1144 }
1145
1219 port_info[0] = port_info[1] = port; 1146 port_info[0] = port_info[1] = port;
1220 /* Now kick off ATA set up */ 1147 /* Now kick off ATA set up */
1221 return ata_pci_init_one(dev, port_info, 2); 1148 return ata_pci_init_one(dev, port_info, 2);
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 65f2e180e7fa..6a34521b9e01 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -8,10 +8,10 @@
8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 8 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
9 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 9 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
10 * Portions Copyright (C) 2003 Red Hat Inc 10 * Portions Copyright (C) 2003 Red Hat Inc
11 * Portions Copyright (C) 2005-2006 MontaVista Software, Inc.
11 * 12 *
12 * 13 *
13 * TODO 14 * TODO
14 * 371N
15 * Work out best PLL policy 15 * Work out best PLL policy
16 */ 16 */
17 17
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt3x2n" 27#define DRV_NAME "pata_hpt3x2n"
28#define DRV_VERSION "0.3.2" 28#define DRV_VERSION "0.3.3"
29 29
30enum { 30enum {
31 HPT_PCI_FAST = (1 << 31), 31 HPT_PCI_FAST = (1 << 31),
@@ -115,14 +115,13 @@ static u32 hpt3x2n_find_mode(struct ata_port *ap, int speed)
115} 115}
116 116
117/** 117/**
118 * hpt3x2n_pre_reset - reset the hpt3x2n bus 118 * hpt3x2n_cable_detect - Detect the cable type
119 * @ap: ATA port to reset 119 * @ap: ATA port to detect on
120 * 120 *
121 * Perform the initial reset handling for the 3x2n series controllers. 121 * Return the cable type attached to this port
122 * Reset the hardware and state machine, obtain the cable type.
123 */ 122 */
124 123
125static int hpt3xn_pre_reset(struct ata_port *ap) 124static int hpt3x2n_cable_detect(struct ata_port *ap)
126{ 125{
127 u8 scr2, ata66; 126 u8 scr2, ata66;
128 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 127 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -135,15 +134,26 @@ static int hpt3xn_pre_reset(struct ata_port *ap)
135 pci_write_config_byte(pdev, 0x5B, scr2); 134 pci_write_config_byte(pdev, 0x5B, scr2);
136 135
137 if (ata66 & (1 << ap->port_no)) 136 if (ata66 & (1 << ap->port_no))
138 ap->cbl = ATA_CBL_PATA40; 137 return ATA_CBL_PATA40;
139 else 138 else
140 ap->cbl = ATA_CBL_PATA80; 139 return ATA_CBL_PATA80;
140}
141
142/**
143 * hpt3x2n_pre_reset - reset the hpt3x2n bus
144 * @ap: ATA port to reset
145 * @deadline: deadline jiffies for the operation
146 *
147 * Perform the initial reset handling for the 3x2n series controllers.
148 * Reset the hardware and state machine,
149 */
141 150
151static int hpt3xn_pre_reset(struct ata_port *ap)
152{
153 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
142 /* Reset the state machine */ 154 /* Reset the state machine */
143 pci_write_config_byte(pdev, 0x50, 0x37); 155 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
144 pci_write_config_byte(pdev, 0x54, 0x37);
145 udelay(100); 156 udelay(100);
146
147 return ata_std_prereset(ap); 157 return ata_std_prereset(ap);
148} 158}
149 159
@@ -364,6 +374,7 @@ static struct ata_port_operations hpt3x2n_port_ops = {
364 .thaw = ata_bmdma_thaw, 374 .thaw = ata_bmdma_thaw,
365 .error_handler = hpt3x2n_error_handler, 375 .error_handler = hpt3x2n_error_handler,
366 .post_internal_cmd = ata_bmdma_post_internal_cmd, 376 .post_internal_cmd = ata_bmdma_post_internal_cmd,
377 .cable_detect = hpt3x2n_cable_detect,
367 378
368 .bmdma_setup = ata_bmdma_setup, 379 .bmdma_setup = ata_bmdma_setup,
369 .bmdma_start = ata_bmdma_start, 380 .bmdma_start = ata_bmdma_start,
@@ -422,8 +433,9 @@ static int hpt3x2n_pci_clock(struct pci_dev *pdev)
422{ 433{
423 unsigned long freq; 434 unsigned long freq;
424 u32 fcnt; 435 u32 fcnt;
436 unsigned long iobase = pci_resource_start(pdev, 4);
425 437
426 pci_read_config_dword(pdev, 0x70/*CHECKME*/, &fcnt); 438 fcnt = inl(iobase + 0x90); /* Not PCI readable for some chips */
427 if ((fcnt >> 12) != 0xABCDE) { 439 if ((fcnt >> 12) != 0xABCDE) {
428 printk(KERN_WARNING "hpt3xn: BIOS clock data not set.\n"); 440 printk(KERN_WARNING "hpt3xn: BIOS clock data not set.\n");
429 return 33; /* Not BIOS set */ 441 return 33; /* Not BIOS set */
@@ -492,6 +504,7 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
492 unsigned int pci_mhz; 504 unsigned int pci_mhz;
493 unsigned int f_low, f_high; 505 unsigned int f_low, f_high;
494 int adjust; 506 int adjust;
507 unsigned long iobase = pci_resource_start(dev, 4);
495 508
496 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); 509 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
497 class_rev &= 0xFF; 510 class_rev &= 0xFF;
@@ -501,6 +514,11 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
501 if (class_rev < 6) 514 if (class_rev < 6)
502 return -ENODEV; 515 return -ENODEV;
503 break; 516 break;
517 case PCI_DEVICE_ID_TTI_HPT371:
518 if (class_rev < 2)
519 return -ENODEV;
520 /* 371N if rev > 1 */
521 break;
504 case PCI_DEVICE_ID_TTI_HPT372: 522 case PCI_DEVICE_ID_TTI_HPT372:
505 /* 372N if rev >= 1*/ 523 /* 372N if rev >= 1*/
506 if (class_rev == 0) 524 if (class_rev == 0)
@@ -528,6 +546,19 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
528 irqmask &= ~0x10; 546 irqmask &= ~0x10;
529 pci_write_config_byte(dev, 0x5a, irqmask); 547 pci_write_config_byte(dev, 0x5a, irqmask);
530 548
549 /*
550 * HPT371 chips physically have only one channel, the secondary one,
551 * but the primary channel registers do exist! Go figure...
552 * So, we manually disable the non-existing channel here
553 * (if the BIOS hasn't done this already).
554 */
555 if (dev->device == PCI_DEVICE_ID_TTI_HPT371) {
556 u8 mcr1;
557 pci_read_config_byte(dev, 0x50, &mcr1);
558 mcr1 &= ~0x04;
559 pci_write_config_byte(dev, 0x50, mcr1);
560 }
561
531 /* Tune the PLL. HPT recommend using 75 for SATA, 66 for UDMA133 or 562 /* Tune the PLL. HPT recommend using 75 for SATA, 66 for UDMA133 or
532 50 for UDMA100. Right now we always use 66 */ 563 50 for UDMA100. Right now we always use 66 */
533 564
@@ -546,14 +577,24 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
546 break; 577 break;
547 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low); 578 pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
548 } 579 }
549 if (adjust == 8) 580 if (adjust == 8) {
550 printk(KERN_WARNING "hpt3xn: DPLL did not stabilize.\n"); 581 printk(KERN_WARNING "hpt3x2n: DPLL did not stabilize.\n");
582 return -ENODEV;
583 }
551 584
552 /* Set our private data up. We only need a few flags so we use 585 /* Set our private data up. We only need a few flags so we use
553 it directly */ 586 it directly */
554 port->private_data = NULL; 587 port->private_data = NULL;
555 if (pci_mhz > 60) 588 if (pci_mhz > 60) {
556 port->private_data = (void *)PCI66; 589 port->private_data = (void *)PCI66;
590 /*
591 * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in
592 * the MISC. register to stretch the UltraDMA Tss timing.
593 * NOTE: This register is only writeable via I/O space.
594 */
595 if (dev->device == PCI_DEVICE_ID_TTI_HPT371)
596 outb(inb(iobase + 0x9c) | 0x04, iobase + 0x9c);
597 }
557 598
558 /* Now kick off ATA set up */ 599 /* Now kick off ATA set up */
559 port_info[0] = port_info[1] = port; 600 port_info[0] = port_info[1] = port;
@@ -562,6 +603,7 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
562 603
563static const struct pci_device_id hpt3x2n[] = { 604static const struct pci_device_id hpt3x2n[] = {
564 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), }, 605 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
606 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT371), },
565 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372), }, 607 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372), },
566 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT302), }, 608 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT302), },
567 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372N), }, 609 { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372N), },
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index 813485c8526c..ac28ec8c50aa 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -25,25 +25,6 @@
25#define DRV_NAME "pata_hpt3x3" 25#define DRV_NAME "pata_hpt3x3"
26#define DRV_VERSION "0.4.2" 26#define DRV_VERSION "0.4.2"
27 27
28static int hpt3x3_probe_init(struct ata_port *ap)
29{
30 ap->cbl = ATA_CBL_PATA40;
31 return ata_std_prereset(ap);
32}
33
34/**
35 * hpt3x3_probe_reset - reset the hpt3x3 bus
36 * @ap: ATA port to reset
37 *
38 * Perform the housekeeping when doing an ATA bus reeset. We just
39 * need to force the cable type.
40 */
41
42static void hpt3x3_error_handler(struct ata_port *ap)
43{
44 return ata_bmdma_drive_eh(ap, hpt3x3_probe_init, ata_std_softreset, NULL, ata_std_postreset);
45}
46
47/** 28/**
48 * hpt3x3_set_piomode - PIO setup 29 * hpt3x3_set_piomode - PIO setup
49 * @ap: ATA interface 30 * @ap: ATA interface
@@ -139,8 +120,9 @@ static struct ata_port_operations hpt3x3_port_ops = {
139 120
140 .freeze = ata_bmdma_freeze, 121 .freeze = ata_bmdma_freeze,
141 .thaw = ata_bmdma_thaw, 122 .thaw = ata_bmdma_thaw,
142 .error_handler = hpt3x3_error_handler, 123 .error_handler = ata_bmdma_error_handler,
143 .post_internal_cmd = ata_bmdma_post_internal_cmd, 124 .post_internal_cmd = ata_bmdma_post_internal_cmd,
125 .cable_detect = ata_cable_40wire,
144 126
145 .bmdma_setup = ata_bmdma_setup, 127 .bmdma_setup = ata_bmdma_setup,
146 .bmdma_start = ata_bmdma_start, 128 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 1a61cc891741..d042efdfbac4 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -49,13 +49,13 @@ static struct ata_port_operations isapnp_port_ops = {
49 .thaw = ata_bmdma_thaw, 49 .thaw = ata_bmdma_thaw,
50 .error_handler = ata_bmdma_error_handler, 50 .error_handler = ata_bmdma_error_handler,
51 .post_internal_cmd = ata_bmdma_post_internal_cmd, 51 .post_internal_cmd = ata_bmdma_post_internal_cmd,
52 .cable_detect = ata_cable_40wire,
52 53
53 .qc_prep = ata_qc_prep, 54 .qc_prep = ata_qc_prep,
54 .qc_issue = ata_qc_issue_prot, 55 .qc_issue = ata_qc_issue_prot,
55 56
56 .data_xfer = ata_data_xfer, 57 .data_xfer = ata_data_xfer,
57 58
58 .irq_handler = ata_interrupt,
59 .irq_clear = ata_bmdma_irq_clear, 59 .irq_clear = ata_bmdma_irq_clear,
60 .irq_on = ata_irq_on, 60 .irq_on = ata_irq_on,
61 .irq_ack = ata_irq_ack, 61 .irq_ack = ata_irq_ack,
@@ -74,8 +74,10 @@ static struct ata_port_operations isapnp_port_ops = {
74 74
75static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id) 75static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
76{ 76{
77 struct ata_probe_ent ae; 77 struct ata_host *host;
78 struct ata_port *ap;
78 void __iomem *cmd_addr, *ctl_addr; 79 void __iomem *cmd_addr, *ctl_addr;
80 int rc;
79 81
80 if (pnp_port_valid(idev, 0) == 0) 82 if (pnp_port_valid(idev, 0) == 0)
81 return -ENODEV; 83 return -ENODEV;
@@ -84,34 +86,36 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
84 if (pnp_irq_valid(idev, 0) == 0) 86 if (pnp_irq_valid(idev, 0) == 0)
85 return -ENODEV; 87 return -ENODEV;
86 88
89 /* allocate host */
90 host = ata_host_alloc(&idev->dev, 1);
91 if (!host)
92 return -ENOMEM;
93
94 /* acquire resources and fill host */
87 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8); 95 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
88 if (!cmd_addr) 96 if (!cmd_addr)
89 return -ENOMEM; 97 return -ENOMEM;
90 98
91 memset(&ae, 0, sizeof(struct ata_probe_ent)); 99 ap = host->ports[0];
92 INIT_LIST_HEAD(&ae.node); 100
93 ae.dev = &idev->dev; 101 ap->ops = &isapnp_port_ops;
94 ae.port_ops = &isapnp_port_ops; 102 ap->pio_mask = 1;
95 ae.sht = &isapnp_sht; 103 ap->flags |= ATA_FLAG_SLAVE_POSS;
96 ae.n_ports = 1; 104
97 ae.pio_mask = 1; /* ISA so PIO 0 cycles */ 105 ap->ioaddr.cmd_addr = cmd_addr;
98 ae.irq = pnp_irq(idev, 0);
99 ae.irq_flags = 0;
100 ae.port_flags = ATA_FLAG_SLAVE_POSS;
101 ae.port[0].cmd_addr = cmd_addr;
102 106
103 if (pnp_port_valid(idev, 1) == 0) { 107 if (pnp_port_valid(idev, 1) == 0) {
104 ctl_addr = devm_ioport_map(&idev->dev, 108 ctl_addr = devm_ioport_map(&idev->dev,
105 pnp_port_start(idev, 1), 1); 109 pnp_port_start(idev, 1), 1);
106 ae.port[0].altstatus_addr = ctl_addr; 110 ap->ioaddr.altstatus_addr = ctl_addr;
107 ae.port[0].ctl_addr = ctl_addr; 111 ap->ioaddr.ctl_addr = ctl_addr;
108 ae.port_flags |= ATA_FLAG_SRST;
109 } 112 }
110 ata_std_ports(&ae.port[0]);
111 113
112 if (ata_device_add(&ae) == 0) 114 ata_std_ports(&ap->ioaddr);
113 return -ENODEV; 115
114 return 0; 116 /* activate */
117 return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0,
118 &isapnp_sht);
115} 119}
116 120
117/** 121/**
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index ea734701555e..011306ef8334 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -25,8 +25,8 @@
25 * it8213_pre_reset - check for 40/80 pin 25 * it8213_pre_reset - check for 40/80 pin
26 * @ap: Port 26 * @ap: Port
27 * 27 *
28 * Perform cable detection for the 8213 ATA interface. This is 28 * Filter out ports by the enable bits before doing the normal reset
29 * different to the PIIX arrangement 29 * and probe.
30 */ 30 */
31 31
32static int it8213_pre_reset(struct ata_port *ap) 32static int it8213_pre_reset(struct ata_port *ap)
@@ -34,23 +34,14 @@ static int it8213_pre_reset(struct ata_port *ap)
34 static const struct pci_bits it8213_enable_bits[] = { 34 static const struct pci_bits it8213_enable_bits[] = {
35 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 35 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
36 }; 36 };
37
38 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 37 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
39 u8 tmp;
40
41 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no])) 38 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no]))
42 return -ENOENT; 39 return -ENOENT;
43
44 pci_read_config_byte(pdev, 0x42, &tmp);
45 if (tmp & 2) /* The initial docs are incorrect */
46 ap->cbl = ATA_CBL_PATA40;
47 else
48 ap->cbl = ATA_CBL_PATA80;
49 return ata_std_prereset(ap); 40 return ata_std_prereset(ap);
50} 41}
51 42
52/** 43/**
53 * it8213_probe_reset - Probe specified port on PATA host controller 44 * it8213_error_handler - Probe specified port on PATA host controller
54 * @ap: Port to probe 45 * @ap: Port to probe
55 * 46 *
56 * LOCKING: 47 * LOCKING:
@@ -63,9 +54,27 @@ static void it8213_error_handler(struct ata_port *ap)
63} 54}
64 55
65/** 56/**
57 * it8213_cable_detect - check for 40/80 pin
58 * @ap: Port
59 *
60 * Perform cable detection for the 8213 ATA interface. This is
61 * different to the PIIX arrangement
62 */
63
64static int it8213_cable_detect(struct ata_port *ap)
65{
66 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
67 u8 tmp;
68 pci_read_config_byte(pdev, 0x42, &tmp);
69 if (tmp & 2) /* The initial docs are incorrect */
70 return ATA_CBL_PATA40;
71 return ATA_CBL_PATA80;
72}
73
74/**
66 * it8213_set_piomode - Initialize host controller PATA PIO timings 75 * it8213_set_piomode - Initialize host controller PATA PIO timings
67 * @ap: Port whose timings we are configuring 76 * @ap: Port whose timings we are configuring
68 * @adev: um 77 * @adev: Device whose timings we are configuring
69 * 78 *
70 * Set PIO mode for device, in host controller PCI config space. 79 * Set PIO mode for device, in host controller PCI config space.
71 * 80 *
@@ -268,6 +277,7 @@ static const struct ata_port_operations it8213_ops = {
268 .thaw = ata_bmdma_thaw, 277 .thaw = ata_bmdma_thaw,
269 .error_handler = it8213_error_handler, 278 .error_handler = it8213_error_handler,
270 .post_internal_cmd = ata_bmdma_post_internal_cmd, 279 .post_internal_cmd = ata_bmdma_post_internal_cmd,
280 .cable_detect = it8213_cable_detect,
271 281
272 .bmdma_setup = ata_bmdma_setup, 282 .bmdma_setup = ata_bmdma_setup,
273 .bmdma_start = ata_bmdma_start, 283 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 35ecb2ba067b..f1f8cec8c224 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -80,7 +80,7 @@
80 80
81 81
82#define DRV_NAME "pata_it821x" 82#define DRV_NAME "pata_it821x"
83#define DRV_VERSION "0.3.4" 83#define DRV_VERSION "0.3.6"
84 84
85struct it821x_dev 85struct it821x_dev
86{ 86{
@@ -113,31 +113,6 @@ struct it821x_dev
113static int it8212_noraid; 113static int it8212_noraid;
114 114
115/** 115/**
116 * it821x_pre_reset - probe
117 * @ap: ATA port
118 *
119 * Set the cable type
120 */
121
122static int it821x_pre_reset(struct ata_port *ap)
123{
124 ap->cbl = ATA_CBL_PATA80;
125 return ata_std_prereset(ap);
126}
127
128/**
129 * it821x_error_handler - probe/reset
130 * @ap: ATA port
131 *
132 * Set the cable type and trigger a probe
133 */
134
135static void it821x_error_handler(struct ata_port *ap)
136{
137 return ata_bmdma_drive_eh(ap, it821x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
138}
139
140/**
141 * it821x_program - program the PIO/MWDMA registers 116 * it821x_program - program the PIO/MWDMA registers
142 * @ap: ATA port 117 * @ap: ATA port
143 * @adev: Device to program 118 * @adev: Device to program
@@ -520,7 +495,6 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
520 495
521/** 496/**
522 * it821x_dev_config - Called each device identify 497 * it821x_dev_config - Called each device identify
523 * @ap: ATA port
524 * @adev: Device that has just been identified 498 * @adev: Device that has just been identified
525 * 499 *
526 * Perform the initial setup needed for each device that is chip 500 * Perform the initial setup needed for each device that is chip
@@ -531,7 +505,7 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
531 * basically we need to filter commands for this chip. 505 * basically we need to filter commands for this chip.
532 */ 506 */
533 507
534static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev) 508static void it821x_dev_config(struct ata_device *adev)
535{ 509{
536 unsigned char model_num[ATA_ID_PROD_LEN + 1]; 510 unsigned char model_num[ATA_ID_PROD_LEN + 1];
537 511
@@ -667,8 +641,9 @@ static struct ata_port_operations it821x_smart_port_ops = {
667 641
668 .freeze = ata_bmdma_freeze, 642 .freeze = ata_bmdma_freeze,
669 .thaw = ata_bmdma_thaw, 643 .thaw = ata_bmdma_thaw,
670 .error_handler = it821x_error_handler, 644 .error_handler = ata_bmdma_error_handler,
671 .post_internal_cmd = ata_bmdma_post_internal_cmd, 645 .post_internal_cmd = ata_bmdma_post_internal_cmd,
646 .cable_detect = ata_cable_unknown,
672 647
673 .bmdma_setup = ata_bmdma_setup, 648 .bmdma_setup = ata_bmdma_setup,
674 .bmdma_start = ata_bmdma_start, 649 .bmdma_start = ata_bmdma_start,
@@ -703,8 +678,9 @@ static struct ata_port_operations it821x_passthru_port_ops = {
703 678
704 .freeze = ata_bmdma_freeze, 679 .freeze = ata_bmdma_freeze,
705 .thaw = ata_bmdma_thaw, 680 .thaw = ata_bmdma_thaw,
706 .error_handler = it821x_error_handler, 681 .error_handler = ata_bmdma_error_handler,
707 .post_internal_cmd = ata_bmdma_post_internal_cmd, 682 .post_internal_cmd = ata_bmdma_post_internal_cmd,
683 .cable_detect = ata_cable_unknown,
708 684
709 .bmdma_setup = ata_bmdma_setup, 685 .bmdma_setup = ata_bmdma_setup,
710 .bmdma_start = it821x_passthru_bmdma_start, 686 .bmdma_start = it821x_passthru_bmdma_start,
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index c6f0e1927551..420c343e5711 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -129,8 +129,8 @@ static struct ata_port_operations ixp4xx_port_ops = {
129 .qc_issue = ata_qc_issue_prot, 129 .qc_issue = ata_qc_issue_prot,
130 .eng_timeout = ata_eng_timeout, 130 .eng_timeout = ata_eng_timeout,
131 .data_xfer = ixp4xx_mmio_data_xfer, 131 .data_xfer = ixp4xx_mmio_data_xfer,
132 .cable_detect = ata_cable_40wire,
132 133
133 .irq_handler = ata_interrupt,
134 .irq_clear = ixp4xx_irq_clear, 134 .irq_clear = ixp4xx_irq_clear,
135 .irq_on = ata_irq_on, 135 .irq_on = ata_irq_on,
136 .irq_ack = ata_irq_ack, 136 .irq_ack = ata_irq_ack,
@@ -173,12 +173,12 @@ static void ixp4xx_setup_port(struct ata_ioports *ioaddr,
173 173
174static __devinit int ixp4xx_pata_probe(struct platform_device *pdev) 174static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
175{ 175{
176 int ret;
177 unsigned int irq; 176 unsigned int irq;
178 struct resource *cs0, *cs1; 177 struct resource *cs0, *cs1;
179 struct ata_probe_ent ae; 178 struct ata_host *host;
180 179 struct ata_port *ap;
181 struct ixp4xx_pata_data *data = pdev->dev.platform_data; 180 struct ixp4xx_pata_data *data = pdev->dev.platform_data;
181 int rc;
182 182
183 cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 183 cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
184 cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 184 cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -186,6 +186,12 @@ static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
186 if (!cs0 || !cs1) 186 if (!cs0 || !cs1)
187 return -EINVAL; 187 return -EINVAL;
188 188
189 /* allocate host */
190 host = ata_host_alloc(&pdev->dev, 1);
191 if (!host)
192 return -ENOMEM;
193
194 /* acquire resources and fill host */
189 pdev->dev.coherent_dma_mask = DMA_32BIT_MASK; 195 pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
190 196
191 data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000); 197 data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000);
@@ -199,32 +205,22 @@ static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
199 *data->cs0_cfg = data->cs0_bits; 205 *data->cs0_cfg = data->cs0_bits;
200 *data->cs1_cfg = data->cs1_bits; 206 *data->cs1_cfg = data->cs1_bits;
201 207
202 memset(&ae, 0, sizeof(struct ata_probe_ent)); 208 ap = host->ports[0];
203 INIT_LIST_HEAD(&ae.node);
204 209
205 ae.dev = &pdev->dev; 210 ap->ops = &ixp4xx_port_ops;
206 ae.port_ops = &ixp4xx_port_ops; 211 ap->pio_mask = 0x1f; /* PIO4 */
207 ae.sht = &ixp4xx_sht; 212 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY | ATA_FLAG_NO_ATAPI;
208 ae.n_ports = 1;
209 ae.pio_mask = 0x1f; /* PIO4 */
210 ae.irq = irq;
211 ae.irq_flags = 0;
212 ae.port_flags = ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY
213 | ATA_FLAG_NO_ATAPI | ATA_FLAG_SRST;
214 213
215 /* run in polling mode if no irq has been assigned */ 214 /* run in polling mode if no irq has been assigned */
216 if (!irq) 215 if (!irq)
217 ae.port_flags |= ATA_FLAG_PIO_POLLING; 216 ap->flags |= ATA_FLAG_PIO_POLLING;
218 217
219 ixp4xx_setup_port(&ae.port[0], data); 218 ixp4xx_setup_port(&ap->ioaddr, data);
220 219
221 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 220 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
222 221
223 ret = ata_device_add(&ae); 222 /* activate host */
224 if (ret == 0) 223 return ata_host_activate(host, irq, ata_interrupt, 0, &ixp4xx_sht);
225 return -ENODEV;
226
227 return 0;
228} 224}
229 225
230static __devexit int ixp4xx_pata_remove(struct platform_device *dev) 226static __devexit int ixp4xx_pata_remove(struct platform_device *dev)
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 86fbcd6a742b..707099291e01 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -162,6 +162,7 @@ static struct ata_port_operations simple_port_ops = {
162 .thaw = ata_bmdma_thaw, 162 .thaw = ata_bmdma_thaw,
163 .error_handler = ata_bmdma_error_handler, 163 .error_handler = ata_bmdma_error_handler,
164 .post_internal_cmd = ata_bmdma_post_internal_cmd, 164 .post_internal_cmd = ata_bmdma_post_internal_cmd,
165 .cable_detect = ata_cable_40wire,
165 166
166 .qc_prep = ata_qc_prep, 167 .qc_prep = ata_qc_prep,
167 .qc_issue = ata_qc_issue_prot, 168 .qc_issue = ata_qc_issue_prot,
@@ -185,6 +186,7 @@ static struct ata_port_operations legacy_port_ops = {
185 .check_status = ata_check_status, 186 .check_status = ata_check_status,
186 .exec_command = ata_exec_command, 187 .exec_command = ata_exec_command,
187 .dev_select = ata_std_dev_select, 188 .dev_select = ata_std_dev_select,
189 .cable_detect = ata_cable_40wire,
188 190
189 .freeze = ata_bmdma_freeze, 191 .freeze = ata_bmdma_freeze,
190 .thaw = ata_bmdma_thaw, 192 .thaw = ata_bmdma_thaw,
@@ -305,6 +307,7 @@ static struct ata_port_operations pdc20230_port_ops = {
305 .thaw = ata_bmdma_thaw, 307 .thaw = ata_bmdma_thaw,
306 .error_handler = ata_bmdma_error_handler, 308 .error_handler = ata_bmdma_error_handler,
307 .post_internal_cmd = ata_bmdma_post_internal_cmd, 309 .post_internal_cmd = ata_bmdma_post_internal_cmd,
310 .cable_detect = ata_cable_40wire,
308 311
309 .qc_prep = ata_qc_prep, 312 .qc_prep = ata_qc_prep,
310 .qc_issue = ata_qc_issue_prot, 313 .qc_issue = ata_qc_issue_prot,
@@ -360,6 +363,7 @@ static struct ata_port_operations ht6560a_port_ops = {
360 .thaw = ata_bmdma_thaw, 363 .thaw = ata_bmdma_thaw,
361 .error_handler = ata_bmdma_error_handler, 364 .error_handler = ata_bmdma_error_handler,
362 .post_internal_cmd = ata_bmdma_post_internal_cmd, 365 .post_internal_cmd = ata_bmdma_post_internal_cmd,
366 .cable_detect = ata_cable_40wire,
363 367
364 .qc_prep = ata_qc_prep, 368 .qc_prep = ata_qc_prep,
365 .qc_issue = ata_qc_issue_prot, 369 .qc_issue = ata_qc_issue_prot,
@@ -426,6 +430,7 @@ static struct ata_port_operations ht6560b_port_ops = {
426 .thaw = ata_bmdma_thaw, 430 .thaw = ata_bmdma_thaw,
427 .error_handler = ata_bmdma_error_handler, 431 .error_handler = ata_bmdma_error_handler,
428 .post_internal_cmd = ata_bmdma_post_internal_cmd, 432 .post_internal_cmd = ata_bmdma_post_internal_cmd,
433 .cable_detect = ata_cable_40wire,
429 434
430 .qc_prep = ata_qc_prep, 435 .qc_prep = ata_qc_prep,
431 .qc_issue = ata_qc_issue_prot, 436 .qc_issue = ata_qc_issue_prot,
@@ -547,6 +552,7 @@ static struct ata_port_operations opti82c611a_port_ops = {
547 .thaw = ata_bmdma_thaw, 552 .thaw = ata_bmdma_thaw,
548 .error_handler = ata_bmdma_error_handler, 553 .error_handler = ata_bmdma_error_handler,
549 .post_internal_cmd = ata_bmdma_post_internal_cmd, 554 .post_internal_cmd = ata_bmdma_post_internal_cmd,
555 .cable_detect = ata_cable_40wire,
550 556
551 .qc_prep = ata_qc_prep, 557 .qc_prep = ata_qc_prep,
552 .qc_issue = ata_qc_issue_prot, 558 .qc_issue = ata_qc_issue_prot,
@@ -680,6 +686,7 @@ static struct ata_port_operations opti82c46x_port_ops = {
680 .thaw = ata_bmdma_thaw, 686 .thaw = ata_bmdma_thaw,
681 .error_handler = ata_bmdma_error_handler, 687 .error_handler = ata_bmdma_error_handler,
682 .post_internal_cmd = ata_bmdma_post_internal_cmd, 688 .post_internal_cmd = ata_bmdma_post_internal_cmd,
689 .cable_detect = ata_cable_40wire,
683 690
684 .qc_prep = ata_qc_prep, 691 .qc_prep = ata_qc_prep,
685 .qc_issue = opti82c46x_qc_issue_prot, 692 .qc_issue = opti82c46x_qc_issue_prot,
@@ -709,7 +716,8 @@ static struct ata_port_operations opti82c46x_port_ops = {
709static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl, int irq) 716static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl, int irq)
710{ 717{
711 struct legacy_data *ld = &legacy_data[nr_legacy_host]; 718 struct legacy_data *ld = &legacy_data[nr_legacy_host];
712 struct ata_probe_ent ae; 719 struct ata_host *host;
720 struct ata_port *ap;
713 struct platform_device *pdev; 721 struct platform_device *pdev;
714 struct ata_port_operations *ops = &legacy_port_ops; 722 struct ata_port_operations *ops = &legacy_port_ops;
715 void __iomem *io_addr, *ctrl_addr; 723 void __iomem *io_addr, *ctrl_addr;
@@ -791,24 +799,23 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
791 if (ops == &legacy_port_ops && (autospeed & mask)) 799 if (ops == &legacy_port_ops && (autospeed & mask))
792 ops = &simple_port_ops; 800 ops = &simple_port_ops;
793 801
794 memset(&ae, 0, sizeof(struct ata_probe_ent)); 802 ret = -ENOMEM;
795 INIT_LIST_HEAD(&ae.node); 803 host = ata_host_alloc(&pdev->dev, 1);
796 ae.dev = &pdev->dev; 804 if (!host)
797 ae.port_ops = ops; 805 goto fail;
798 ae.sht = &legacy_sht; 806 ap = host->ports[0];
799 ae.n_ports = 1; 807
800 ae.pio_mask = pio_modes; 808 ap->ops = ops;
801 ae.irq = irq; 809 ap->pio_mask = pio_modes;
802 ae.irq_flags = 0; 810 ap->flags |= ATA_FLAG_SLAVE_POSS | iordy;
803 ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST|iordy; 811 ap->ioaddr.cmd_addr = io_addr;
804 ae.port[0].cmd_addr = io_addr; 812 ap->ioaddr.altstatus_addr = ctrl_addr;
805 ae.port[0].altstatus_addr = ctrl_addr; 813 ap->ioaddr.ctl_addr = ctrl_addr;
806 ae.port[0].ctl_addr = ctrl_addr; 814 ata_std_ports(&ap->ioaddr);
807 ata_std_ports(&ae.port[0]); 815 ap->private_data = ld;
808 ae.private_data = ld; 816
809 817 ret = ata_host_activate(host, irq, ata_interrupt, 0, &legacy_sht);
810 ret = -ENODEV; 818 if (ret)
811 if (!ata_device_add(&ae))
812 goto fail; 819 goto fail;
813 820
814 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev); 821 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev);
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index 6dd7c4ef3e66..d9b94a1b6954 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -20,7 +20,7 @@
20#include <linux/ata.h> 20#include <linux/ata.h>
21 21
22#define DRV_NAME "pata_marvell" 22#define DRV_NAME "pata_marvell"
23#define DRV_VERSION "0.1.1" 23#define DRV_VERSION "0.1.4"
24 24
25/** 25/**
26 * marvell_pre_reset - check for 40/80 pin 26 * marvell_pre_reset - check for 40/80 pin
@@ -52,22 +52,23 @@ static int marvell_pre_reset(struct ata_port *ap)
52 if ((pdev->device == 0x6145) && (ap->port_no == 0) && 52 if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
53 (!(devices & 0x10))) /* PATA enable ? */ 53 (!(devices & 0x10))) /* PATA enable ? */
54 return -ENOENT; 54 return -ENOENT;
55 return ata_std_prereset(ap);
56}
55 57
58static int marvell_cable_detect(struct ata_port *ap)
59{
56 /* Cable type */ 60 /* Cable type */
57 switch(ap->port_no) 61 switch(ap->port_no)
58 { 62 {
59 case 0: 63 case 0:
60 if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1) 64 if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
61 ap->cbl = ATA_CBL_PATA40; 65 return ATA_CBL_PATA40;
62 else 66 return ATA_CBL_PATA80;
63 ap->cbl = ATA_CBL_PATA80;
64 break;
65
66 case 1: /* Legacy SATA port */ 67 case 1: /* Legacy SATA port */
67 ap->cbl = ATA_CBL_SATA; 68 return ATA_CBL_SATA;
68 break;
69 } 69 }
70 return ata_std_prereset(ap); 70 BUG();
71 return 0; /* Our BUG macro needs the right markup */
71} 72}
72 73
73/** 74/**
@@ -123,6 +124,7 @@ static const struct ata_port_operations marvell_ops = {
123 .thaw = ata_bmdma_thaw, 124 .thaw = ata_bmdma_thaw,
124 .error_handler = marvell_error_handler, 125 .error_handler = marvell_error_handler,
125 .post_internal_cmd = ata_bmdma_post_internal_cmd, 126 .post_internal_cmd = ata_bmdma_post_internal_cmd,
127 .cable_detect = marvell_cable_detect,
126 128
127 /* BMDMA handling is PCI ATA format, use helpers */ 129 /* BMDMA handling is PCI ATA format, use helpers */
128 .bmdma_setup = ata_bmdma_setup, 130 .bmdma_setup = ata_bmdma_setup,
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 882c36eaf293..9587a89f9683 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -24,7 +24,7 @@
24 24
25 25
26#define DRV_NAME "mpc52xx_ata" 26#define DRV_NAME "mpc52xx_ata"
27#define DRV_VERSION "0.1.0" 27#define DRV_VERSION "0.1.0ac2"
28 28
29 29
30/* Private structures used by the driver */ 30/* Private structures used by the driver */
@@ -297,38 +297,37 @@ static struct ata_port_operations mpc52xx_ata_port_ops = {
297 .freeze = ata_bmdma_freeze, 297 .freeze = ata_bmdma_freeze,
298 .thaw = ata_bmdma_thaw, 298 .thaw = ata_bmdma_thaw,
299 .error_handler = mpc52xx_ata_error_handler, 299 .error_handler = mpc52xx_ata_error_handler,
300 .cable_detect = ata_cable_40wire,
300 .qc_prep = ata_qc_prep, 301 .qc_prep = ata_qc_prep,
301 .qc_issue = ata_qc_issue_prot, 302 .qc_issue = ata_qc_issue_prot,
302 .data_xfer = ata_data_xfer, 303 .data_xfer = ata_data_xfer,
303 .irq_handler = ata_interrupt,
304 .irq_clear = ata_bmdma_irq_clear, 304 .irq_clear = ata_bmdma_irq_clear,
305 .irq_on = ata_irq_on, 305 .irq_on = ata_irq_on,
306 .irq_ack = ata_irq_ack, 306 .irq_ack = ata_irq_ack,
307 .port_start = ata_port_start, 307 .port_start = ata_port_start,
308}; 308};
309 309
310static struct ata_probe_ent mpc52xx_ata_probe_ent = {
311 .port_ops = &mpc52xx_ata_port_ops,
312 .sht = &mpc52xx_ata_sht,
313 .n_ports = 1,
314 .pio_mask = 0x1f, /* Up to PIO4 */
315 .mwdma_mask = 0x00, /* No MWDMA */
316 .udma_mask = 0x00, /* No UDMA */
317 .port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
318 .irq_flags = 0,
319};
320
321static int __devinit 310static int __devinit
322mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv) 311mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv)
323{ 312{
324 struct ata_probe_ent *ae = &mpc52xx_ata_probe_ent; 313 struct ata_host *host;
325 struct ata_ioports *aio = &ae->port[0]; 314 struct ata_port *ap;
326 int rv; 315 struct ata_ioports *aio;
327 316 int rc;
328 INIT_LIST_HEAD(&ae->node); 317
329 ae->dev = dev; 318 host = ata_host_alloc(dev, 1);
330 ae->irq = priv->ata_irq; 319 if (!host)
331 320 return -ENOMEM;
321
322 ap = host->ports[0];
323 ap->flags |= ATA_FLAG_SLAVE_POSS;
324 ap->pio_mask = 0x1f; /* Up to PIO4 */
325 ap->mwdma_mask = 0x00; /* No MWDMA */
326 ap->udma_mask = 0x00; /* No UDMA */
327 ap->ops = &mpc52xx_ata_port_ops;
328 host->private_data = priv;
329
330 aio = &ap->ioaddr;
332 aio->cmd_addr = NULL; /* Don't have a classic reg block */ 331 aio->cmd_addr = NULL; /* Don't have a classic reg block */
333 aio->altstatus_addr = &priv->ata_regs->tf_control; 332 aio->altstatus_addr = &priv->ata_regs->tf_control;
334 aio->ctl_addr = &priv->ata_regs->tf_control; 333 aio->ctl_addr = &priv->ata_regs->tf_control;
@@ -343,11 +342,9 @@ mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv)
343 aio->status_addr = &priv->ata_regs->tf_command; 342 aio->status_addr = &priv->ata_regs->tf_command;
344 aio->command_addr = &priv->ata_regs->tf_command; 343 aio->command_addr = &priv->ata_regs->tf_command;
345 344
346 ae->private_data = priv; 345 /* activate host */
347 346 return ata_host_activate(host, priv->ata_irq, ata_interrupt, 0,
348 rv = ata_device_add(ae); 347 &mpc52xx_ata_sht);
349
350 return rv ? 0 : -EINVAL;
351} 348}
352 349
353static struct mpc52xx_ata_priv * 350static struct mpc52xx_ata_priv *
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 4abe45ac19a2..987c5fafab08 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_mpiix" 37#define DRV_NAME "pata_mpiix"
38#define DRV_VERSION "0.7.5" 38#define DRV_VERSION "0.7.6"
39 39
40enum { 40enum {
41 IDETIM = 0x6C, /* IDE control register */ 41 IDETIM = 0x6C, /* IDE control register */
@@ -53,7 +53,6 @@ static int mpiix_pre_reset(struct ata_port *ap)
53 53
54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits)) 54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits))
55 return -ENOENT; 55 return -ENOENT;
56 ap->cbl = ATA_CBL_PATA40;
57 return ata_std_prereset(ap); 56 return ata_std_prereset(ap);
58} 57}
59 58
@@ -185,12 +184,12 @@ static struct ata_port_operations mpiix_port_ops = {
185 .thaw = ata_bmdma_thaw, 184 .thaw = ata_bmdma_thaw,
186 .error_handler = mpiix_error_handler, 185 .error_handler = mpiix_error_handler,
187 .post_internal_cmd = ata_bmdma_post_internal_cmd, 186 .post_internal_cmd = ata_bmdma_post_internal_cmd,
187 .cable_detect = ata_cable_40wire,
188 188
189 .qc_prep = ata_qc_prep, 189 .qc_prep = ata_qc_prep,
190 .qc_issue = mpiix_qc_issue_prot, 190 .qc_issue = mpiix_qc_issue_prot,
191 .data_xfer = ata_data_xfer, 191 .data_xfer = ata_data_xfer,
192 192
193 .irq_handler = ata_interrupt,
194 .irq_clear = ata_bmdma_irq_clear, 193 .irq_clear = ata_bmdma_irq_clear,
195 .irq_on = ata_irq_on, 194 .irq_on = ata_irq_on,
196 .irq_ack = ata_irq_ack, 195 .irq_ack = ata_irq_ack,
@@ -201,8 +200,9 @@ static struct ata_port_operations mpiix_port_ops = {
201static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id) 200static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
202{ 201{
203 /* Single threaded by the PCI probe logic */ 202 /* Single threaded by the PCI probe logic */
204 static struct ata_probe_ent probe;
205 static int printed_version; 203 static int printed_version;
204 struct ata_host *host;
205 struct ata_port *ap;
206 void __iomem *cmd_addr, *ctl_addr; 206 void __iomem *cmd_addr, *ctl_addr;
207 u16 idetim; 207 u16 idetim;
208 int irq; 208 int irq;
@@ -210,6 +210,10 @@ static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
210 if (!printed_version++) 210 if (!printed_version++)
211 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n"); 211 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
212 212
213 host = ata_host_alloc(&dev->dev, 1);
214 if (!host)
215 return -ENOMEM;
216
213 /* MPIIX has many functions which can be turned on or off according 217 /* MPIIX has many functions which can be turned on or off according
214 to other devices present. Make sure IDE is enabled before we try 218 to other devices present. Make sure IDE is enabled before we try
215 and use it */ 219 and use it */
@@ -238,27 +242,21 @@ static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
238 without BARs set fools the setup. #2 If you pci_disable_device 242 without BARs set fools the setup. #2 If you pci_disable_device
239 the MPIIX your box goes castors up */ 243 the MPIIX your box goes castors up */
240 244
241 INIT_LIST_HEAD(&probe.node); 245 ap = host->ports[0];
242 probe.dev = pci_dev_to_dev(dev); 246 ap->ops = &mpiix_port_ops;
243 probe.port_ops = &mpiix_port_ops; 247 ap->pio_mask = 0x1F;
244 probe.sht = &mpiix_sht; 248 ap->flags |= ATA_FLAG_SLAVE_POSS;
245 probe.pio_mask = 0x1F;
246 probe.irq_flags = IRQF_SHARED;
247 probe.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
248 probe.n_ports = 1;
249 249
250 probe.irq = irq; 250 ap->ioaddr.cmd_addr = cmd_addr;
251 probe.port[0].cmd_addr = cmd_addr; 251 ap->ioaddr.ctl_addr = ctl_addr;
252 probe.port[0].ctl_addr = ctl_addr; 252 ap->ioaddr.altstatus_addr = ctl_addr;
253 probe.port[0].altstatus_addr = ctl_addr;
254 253
255 /* Let libata fill in the port details */ 254 /* Let libata fill in the port details */
256 ata_std_ports(&probe.port[0]); 255 ata_std_ports(&ap->ioaddr);
257 256
258 /* Now add the port that is active */ 257 /* activate host */
259 if (ata_device_add(&probe)) 258 return ata_host_activate(host, irq, ata_interrupt, IRQF_SHARED,
260 return 0; 259 &mpiix_sht);
261 return -ENODEV;
262} 260}
263 261
264static const struct pci_device_id mpiix[] = { 262static const struct pci_device_id mpiix[] = {
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index 38f99b38a5ea..dbba5b77d79c 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -16,33 +16,7 @@
16#include <linux/ata.h> 16#include <linux/ata.h>
17 17
18#define DRV_NAME "pata_netcell" 18#define DRV_NAME "pata_netcell"
19#define DRV_VERSION "0.1.6" 19#define DRV_VERSION "0.1.7"
20
21/**
22 * netcell_probe_init - check for 40/80 pin
23 * @ap: Port
24 *
25 * Cables are handled by the RAID controller. Report 80 pin.
26 */
27
28static int netcell_pre_reset(struct ata_port *ap)
29{
30 ap->cbl = ATA_CBL_PATA80;
31 return ata_std_prereset(ap);
32}
33
34/**
35 * netcell_probe_reset - Probe specified port on PATA host controller
36 * @ap: Port to probe
37 *
38 * LOCKING:
39 * None (inherited from caller).
40 */
41
42static void netcell_error_handler(struct ata_port *ap)
43{
44 return ata_bmdma_drive_eh(ap, netcell_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
45}
46 20
47/* No PIO or DMA methods needed for this device */ 21/* No PIO or DMA methods needed for this device */
48 22
@@ -81,8 +55,9 @@ static const struct ata_port_operations netcell_ops = {
81 55
82 .freeze = ata_bmdma_freeze, 56 .freeze = ata_bmdma_freeze,
83 .thaw = ata_bmdma_thaw, 57 .thaw = ata_bmdma_thaw,
84 .error_handler = netcell_error_handler, 58 .error_handler = ata_bmdma_error_handler,
85 .post_internal_cmd = ata_bmdma_post_internal_cmd, 59 .post_internal_cmd = ata_bmdma_post_internal_cmd,
60 .cable_detect = ata_cable_80wire,
86 61
87 /* BMDMA handling is PCI ATA format, use helpers */ 62 /* BMDMA handling is PCI ATA format, use helpers */
88 .bmdma_setup = ata_bmdma_setup, 63 .bmdma_setup = ata_bmdma_setup,
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 9944a28daa9c..078aeda9cf8d 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -28,13 +28,13 @@
28#include <linux/libata.h> 28#include <linux/libata.h>
29 29
30#define DRV_NAME "pata_ns87410" 30#define DRV_NAME "pata_ns87410"
31#define DRV_VERSION "0.4.3" 31#define DRV_VERSION "0.4.6"
32 32
33/** 33/**
34 * ns87410_pre_reset - probe begin 34 * ns87410_pre_reset - probe begin
35 * @ap: ATA port 35 * @ap: ATA port
36 * 36 *
37 * Set up cable type and use generic probe init 37 * Check enabled ports
38 */ 38 */
39 39
40static int ns87410_pre_reset(struct ata_port *ap) 40static int ns87410_pre_reset(struct ata_port *ap)
@@ -47,7 +47,6 @@ static int ns87410_pre_reset(struct ata_port *ap)
47 47
48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no])) 48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
49 return -ENOENT; 49 return -ENOENT;
50 ap->cbl = ATA_CBL_PATA40;
51 return ata_std_prereset(ap); 50 return ata_std_prereset(ap);
52} 51}
53 52
@@ -177,6 +176,7 @@ static struct ata_port_operations ns87410_port_ops = {
177 .thaw = ata_bmdma_thaw, 176 .thaw = ata_bmdma_thaw,
178 .error_handler = ns87410_error_handler, 177 .error_handler = ns87410_error_handler,
179 .post_internal_cmd = ata_bmdma_post_internal_cmd, 178 .post_internal_cmd = ata_bmdma_post_internal_cmd,
179 .cable_detect = ata_cable_40wire,
180 180
181 .qc_prep = ata_qc_prep, 181 .qc_prep = ata_qc_prep,
182 .qc_issue = ns87410_qc_issue_prot, 182 .qc_issue = ns87410_qc_issue_prot,
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index da68cd19efd6..dea4690340d1 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -25,7 +25,7 @@
25#include <linux/ata.h> 25#include <linux/ata.h>
26 26
27#define DRV_NAME "pata_oldpiix" 27#define DRV_NAME "pata_oldpiix"
28#define DRV_VERSION "0.5.4" 28#define DRV_VERSION "0.5.5"
29 29
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
@@ -44,7 +44,6 @@ static int oldpiix_pre_reset(struct ata_port *ap)
44 44
45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no])) 45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
46 return -ENOENT; 46 return -ENOENT;
47 ap->cbl = ATA_CBL_PATA40;
48 return ata_std_prereset(ap); 47 return ata_std_prereset(ap);
49} 48}
50 49
@@ -65,7 +64,7 @@ static void oldpiix_pata_error_handler(struct ata_port *ap)
65/** 64/**
66 * oldpiix_set_piomode - Initialize host controller PATA PIO timings 65 * oldpiix_set_piomode - Initialize host controller PATA PIO timings
67 * @ap: Port whose timings we are configuring 66 * @ap: Port whose timings we are configuring
68 * @adev: um 67 * @adev: Device whose timings we are configuring
69 * 68 *
70 * Set PIO mode for device, in host controller PCI config space. 69 * Set PIO mode for device, in host controller PCI config space.
71 * 70 *
@@ -255,6 +254,7 @@ static const struct ata_port_operations oldpiix_pata_ops = {
255 .thaw = ata_bmdma_thaw, 254 .thaw = ata_bmdma_thaw,
256 .error_handler = oldpiix_pata_error_handler, 255 .error_handler = oldpiix_pata_error_handler,
257 .post_internal_cmd = ata_bmdma_post_internal_cmd, 256 .post_internal_cmd = ata_bmdma_post_internal_cmd,
257 .cable_detect = ata_cable_40wire,
258 258
259 .bmdma_setup = ata_bmdma_setup, 259 .bmdma_setup = ata_bmdma_setup,
260 .bmdma_start = ata_bmdma_start, 260 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index 3fd3a35c2241..13b63e21838d 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -34,7 +34,7 @@
34#include <linux/libata.h> 34#include <linux/libata.h>
35 35
36#define DRV_NAME "pata_opti" 36#define DRV_NAME "pata_opti"
37#define DRV_VERSION "0.2.8" 37#define DRV_VERSION "0.2.9"
38 38
39enum { 39enum {
40 READ_REG = 0, /* index of Read cycle timing register */ 40 READ_REG = 0, /* index of Read cycle timing register */
@@ -61,8 +61,6 @@ static int opti_pre_reset(struct ata_port *ap)
61 61
62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no])) 62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no]))
63 return -ENOENT; 63 return -ENOENT;
64
65 ap->cbl = ATA_CBL_PATA40;
66 return ata_std_prereset(ap); 64 return ata_std_prereset(ap);
67} 65}
68 66
@@ -198,6 +196,7 @@ static struct ata_port_operations opti_port_ops = {
198 .thaw = ata_bmdma_thaw, 196 .thaw = ata_bmdma_thaw,
199 .error_handler = opti_error_handler, 197 .error_handler = opti_error_handler,
200 .post_internal_cmd = ata_bmdma_post_internal_cmd, 198 .post_internal_cmd = ata_bmdma_post_internal_cmd,
199 .cable_detect = ata_cable_40wire,
201 200
202 .bmdma_setup = ata_bmdma_setup, 201 .bmdma_setup = ata_bmdma_setup,
203 .bmdma_start = ata_bmdma_start, 202 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index 9764907e8a13..b70e04c144df 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_optidma" 35#define DRV_NAME "pata_optidma"
36#define DRV_VERSION "0.2.4" 36#define DRV_VERSION "0.3.2"
37 37
38enum { 38enum {
39 READ_REG = 0, /* index of Read cycle timing register */ 39 READ_REG = 0, /* index of Read cycle timing register */
@@ -62,7 +62,6 @@ static int optidma_pre_reset(struct ata_port *ap)
62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits)) 62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits))
63 return -ENOENT; 63 return -ENOENT;
64 64
65 ap->cbl = ATA_CBL_PATA40;
66 return ata_std_prereset(ap); 65 return ata_std_prereset(ap);
67} 66}
68 67
@@ -115,7 +114,7 @@ static void optidma_lock(struct ata_port *ap)
115} 114}
116 115
117/** 116/**
118 * optidma_set_mode - set mode data 117 * optidma_mode_setup - set mode data
119 * @ap: ATA interface 118 * @ap: ATA interface
120 * @adev: ATA device 119 * @adev: ATA device
121 * @mode: Mode to set 120 * @mode: Mode to set
@@ -128,7 +127,7 @@ static void optidma_lock(struct ata_port *ap)
128 * IRQ here we depend on the host set locking to avoid catastrophe. 127 * IRQ here we depend on the host set locking to avoid catastrophe.
129 */ 128 */
130 129
131static void optidma_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mode) 130static void optidma_mode_setup(struct ata_port *ap, struct ata_device *adev, u8 mode)
132{ 131{
133 struct ata_device *pair = ata_dev_pair(adev); 132 struct ata_device *pair = ata_dev_pair(adev);
134 int pio = adev->pio_mode - XFER_PIO_0; 133 int pio = adev->pio_mode - XFER_PIO_0;
@@ -202,7 +201,7 @@ static void optidma_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mo
202} 201}
203 202
204/** 203/**
205 * optiplus_set_mode - DMA setup for Firestar Plus 204 * optiplus_mode_setup - DMA setup for Firestar Plus
206 * @ap: ATA port 205 * @ap: ATA port
207 * @adev: device 206 * @adev: device
208 * @mode: desired mode 207 * @mode: desired mode
@@ -213,7 +212,7 @@ static void optidma_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mo
213 * one 212 * one
214 */ 213 */
215 214
216static void optiplus_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mode) 215static void optiplus_mode_setup(struct ata_port *ap, struct ata_device *adev, u8 mode)
217{ 216{
218 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 217 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
219 u8 udcfg; 218 u8 udcfg;
@@ -225,7 +224,7 @@ static void optiplus_set_mode(struct ata_port *ap, struct ata_device *adev, u8 m
225 pci_read_config_byte(pdev, 0x44, &udcfg); 224 pci_read_config_byte(pdev, 0x44, &udcfg);
226 if (mode <= XFER_UDMA_0) { 225 if (mode <= XFER_UDMA_0) {
227 udcfg &= ~(1 << unit); 226 udcfg &= ~(1 << unit);
228 optidma_set_mode(ap, adev, adev->dma_mode); 227 optidma_mode_setup(ap, adev, adev->dma_mode);
229 } else { 228 } else {
230 udcfg |= (1 << unit); 229 udcfg |= (1 << unit);
231 if (ap->port_no) { 230 if (ap->port_no) {
@@ -253,7 +252,7 @@ static void optiplus_set_mode(struct ata_port *ap, struct ata_device *adev, u8 m
253 252
254static void optidma_set_pio_mode(struct ata_port *ap, struct ata_device *adev) 253static void optidma_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
255{ 254{
256 optidma_set_mode(ap, adev, adev->pio_mode); 255 optidma_mode_setup(ap, adev, adev->pio_mode);
257} 256}
258 257
259/** 258/**
@@ -268,7 +267,7 @@ static void optidma_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
268 267
269static void optidma_set_dma_mode(struct ata_port *ap, struct ata_device *adev) 268static void optidma_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
270{ 269{
271 optidma_set_mode(ap, adev, adev->dma_mode); 270 optidma_mode_setup(ap, adev, adev->dma_mode);
272} 271}
273 272
274/** 273/**
@@ -283,7 +282,7 @@ static void optidma_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
283 282
284static void optiplus_set_pio_mode(struct ata_port *ap, struct ata_device *adev) 283static void optiplus_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
285{ 284{
286 optiplus_set_mode(ap, adev, adev->pio_mode); 285 optiplus_mode_setup(ap, adev, adev->pio_mode);
287} 286}
288 287
289/** 288/**
@@ -298,7 +297,7 @@ static void optiplus_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
298 297
299static void optiplus_set_dma_mode(struct ata_port *ap, struct ata_device *adev) 298static void optiplus_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
300{ 299{
301 optiplus_set_mode(ap, adev, adev->dma_mode); 300 optiplus_mode_setup(ap, adev, adev->dma_mode);
302} 301}
303 302
304/** 303/**
@@ -322,26 +321,29 @@ static u8 optidma_make_bits43(struct ata_device *adev)
322} 321}
323 322
324/** 323/**
325 * optidma_post_set_mode - finalize PCI setup 324 * optidma_set_mode - mode setup
326 * @ap: port to set up 325 * @ap: port to set up
327 * 326 *
328 * Finalise the configuration by writing the nibble of extra bits 327 * Use the standard setup to tune the chipset and then finalise the
329 * of data into the chip. 328 * configuration by writing the nibble of extra bits of data into
329 * the chip.
330 */ 330 */
331 331
332static void optidma_post_set_mode(struct ata_port *ap) 332static int optidma_set_mode(struct ata_port *ap, struct ata_device **r_failed)
333{ 333{
334 u8 r; 334 u8 r;
335 int nybble = 4 * ap->port_no; 335 int nybble = 4 * ap->port_no;
336 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 336 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
337 337 int rc = ata_do_set_mode(ap, r_failed);
338 pci_read_config_byte(pdev, 0x43, &r); 338 if (rc == 0) {
339 339 pci_read_config_byte(pdev, 0x43, &r);
340 r &= (0x0F << nybble); 340
341 r |= (optidma_make_bits43(&ap->device[0]) + 341 r &= (0x0F << nybble);
342 (optidma_make_bits43(&ap->device[0]) << 2)) << nybble; 342 r |= (optidma_make_bits43(&ap->device[0]) +
343 343 (optidma_make_bits43(&ap->device[0]) << 2)) << nybble;
344 pci_write_config_byte(pdev, 0x43, r); 344 pci_write_config_byte(pdev, 0x43, r);
345 }
346 return rc;
345} 347}
346 348
347static struct scsi_host_template optidma_sht = { 349static struct scsi_host_template optidma_sht = {
@@ -381,7 +383,8 @@ static struct ata_port_operations optidma_port_ops = {
381 .thaw = ata_bmdma_thaw, 383 .thaw = ata_bmdma_thaw,
382 .post_internal_cmd = ata_bmdma_post_internal_cmd, 384 .post_internal_cmd = ata_bmdma_post_internal_cmd,
383 .error_handler = optidma_error_handler, 385 .error_handler = optidma_error_handler,
384 .post_set_mode = optidma_post_set_mode, 386 .set_mode = optidma_set_mode,
387 .cable_detect = ata_cable_40wire,
385 388
386 .bmdma_setup = ata_bmdma_setup, 389 .bmdma_setup = ata_bmdma_setup,
387 .bmdma_start = ata_bmdma_start, 390 .bmdma_start = ata_bmdma_start,
@@ -416,7 +419,8 @@ static struct ata_port_operations optiplus_port_ops = {
416 .thaw = ata_bmdma_thaw, 419 .thaw = ata_bmdma_thaw,
417 .post_internal_cmd = ata_bmdma_post_internal_cmd, 420 .post_internal_cmd = ata_bmdma_post_internal_cmd,
418 .error_handler = optidma_error_handler, 421 .error_handler = optidma_error_handler,
419 .post_set_mode = optidma_post_set_mode, 422 .set_mode = optidma_set_mode,
423 .cable_detect = ata_cable_40wire,
420 424
421 .bmdma_setup = ata_bmdma_setup, 425 .bmdma_setup = ata_bmdma_setup,
422 .bmdma_start = ata_bmdma_start, 426 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 103720f873c8..75dc84797ff3 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -42,7 +42,7 @@
42 42
43 43
44#define DRV_NAME "pata_pcmcia" 44#define DRV_NAME "pata_pcmcia"
45#define DRV_VERSION "0.3.0" 45#define DRV_VERSION "0.3.1"
46 46
47/* 47/*
48 * Private data structure to glue stuff together 48 * Private data structure to glue stuff together
@@ -54,6 +54,39 @@ struct ata_pcmcia_info {
54 dev_node_t node; 54 dev_node_t node;
55}; 55};
56 56
57/**
58 * pcmcia_set_mode - PCMCIA specific mode setup
59 * @ap: Port
60 * @r_failed_dev: Return pointer for failed device
61 *
62 * Perform the tuning and setup of the devices and timings, which
63 * for PCMCIA is the same as any other controller. We wrap it however
64 * as we need to spot hardware with incorrect or missing master/slave
65 * decode, which alas is embarrassingly common in the PC world
66 */
67
68static int pcmcia_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
69{
70 struct ata_device *master = &ap->device[0];
71 struct ata_device *slave = &ap->device[1];
72
73 if (!ata_dev_enabled(master) || !ata_dev_enabled(slave))
74 return ata_do_set_mode(ap, r_failed_dev);
75
76 if (memcmp(master->id + ATA_ID_FW_REV, slave->id + ATA_ID_FW_REV,
77 ATA_ID_FW_REV_LEN + ATA_ID_PROD_LEN) == 0)
78 {
79 /* Suspicious match, but could be two cards from
80 the same vendor - check serial */
81 if (memcmp(master->id + ATA_ID_SERNO, slave->id + ATA_ID_SERNO,
82 ATA_ID_SERNO_LEN) == 0 && master->id[ATA_ID_SERNO] >> 8) {
83 ata_dev_printk(slave, KERN_WARNING, "is a ghost device, ignoring.\n");
84 ata_dev_disable(slave);
85 }
86 }
87 return ata_do_set_mode(ap, r_failed_dev);
88}
89
57static struct scsi_host_template pcmcia_sht = { 90static struct scsi_host_template pcmcia_sht = {
58 .module = THIS_MODULE, 91 .module = THIS_MODULE,
59 .name = DRV_NAME, 92 .name = DRV_NAME,
@@ -73,6 +106,7 @@ static struct scsi_host_template pcmcia_sht = {
73}; 106};
74 107
75static struct ata_port_operations pcmcia_port_ops = { 108static struct ata_port_operations pcmcia_port_ops = {
109 .set_mode = pcmcia_set_mode,
76 .port_disable = ata_port_disable, 110 .port_disable = ata_port_disable,
77 .tf_load = ata_tf_load, 111 .tf_load = ata_tf_load,
78 .tf_read = ata_tf_read, 112 .tf_read = ata_tf_read,
@@ -84,13 +118,13 @@ static struct ata_port_operations pcmcia_port_ops = {
84 .thaw = ata_bmdma_thaw, 118 .thaw = ata_bmdma_thaw,
85 .error_handler = ata_bmdma_error_handler, 119 .error_handler = ata_bmdma_error_handler,
86 .post_internal_cmd = ata_bmdma_post_internal_cmd, 120 .post_internal_cmd = ata_bmdma_post_internal_cmd,
121 .cable_detect = ata_cable_40wire,
87 122
88 .qc_prep = ata_qc_prep, 123 .qc_prep = ata_qc_prep,
89 .qc_issue = ata_qc_issue_prot, 124 .qc_issue = ata_qc_issue_prot,
90 125
91 .data_xfer = ata_data_xfer_noirq, 126 .data_xfer = ata_data_xfer_noirq,
92 127
93 .irq_handler = ata_interrupt,
94 .irq_clear = ata_bmdma_irq_clear, 128 .irq_clear = ata_bmdma_irq_clear,
95 .irq_on = ata_irq_on, 129 .irq_on = ata_irq_on,
96 .irq_ack = ata_irq_ack, 130 .irq_ack = ata_irq_ack,
@@ -111,7 +145,8 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
111 145
112static int pcmcia_init_one(struct pcmcia_device *pdev) 146static int pcmcia_init_one(struct pcmcia_device *pdev)
113{ 147{
114 struct ata_probe_ent ae; 148 struct ata_host *host;
149 struct ata_port *ap;
115 struct ata_pcmcia_info *info; 150 struct ata_pcmcia_info *info;
116 tuple_t tuple; 151 tuple_t tuple;
117 struct { 152 struct {
@@ -255,24 +290,24 @@ next_entry:
255 * Having done the PCMCIA plumbing the ATA side is relatively 290 * Having done the PCMCIA plumbing the ATA side is relatively
256 * sane. 291 * sane.
257 */ 292 */
258 293 ret = -ENOMEM;
259 memset(&ae, 0, sizeof(struct ata_probe_ent)); 294 host = ata_host_alloc(&pdev->dev, 1);
260 INIT_LIST_HEAD(&ae.node); 295 if (!host)
261 ae.dev = &pdev->dev; 296 goto failed;
262 ae.port_ops = &pcmcia_port_ops; 297 ap = host->ports[0];
263 ae.sht = &pcmcia_sht; 298
264 ae.n_ports = 1; 299 ap->ops = &pcmcia_port_ops;
265 ae.pio_mask = 1; /* ISA so PIO 0 cycles */ 300 ap->pio_mask = 1; /* ISA so PIO 0 cycles */
266 ae.irq = pdev->irq.AssignedIRQ; 301 ap->flags |= ATA_FLAG_SLAVE_POSS;
267 ae.irq_flags = IRQF_SHARED; 302 ap->ioaddr.cmd_addr = io_addr;
268 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 303 ap->ioaddr.altstatus_addr = ctl_addr;
269 ae.port[0].cmd_addr = io_addr; 304 ap->ioaddr.ctl_addr = ctl_addr;
270 ae.port[0].altstatus_addr = ctl_addr; 305 ata_std_ports(&ap->ioaddr);
271 ae.port[0].ctl_addr = ctl_addr; 306
272 ata_std_ports(&ae.port[0]); 307 /* activate */
273 308 ret = ata_host_activate(host, pdev->irq.AssignedIRQ, ata_interrupt,
274 ret = -ENODEV; 309 IRQF_SHARED, &pcmcia_sht);
275 if (ata_device_add(&ae) == 0) 310 if (ret)
276 goto failed; 311 goto failed;
277 312
278 info->ndev = 1; 313 info->ndev = 1;
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 93bcdadb7be3..a61cbc110688 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_pdc2027x" 37#define DRV_NAME "pata_pdc2027x"
38#define DRV_VERSION "0.8" 38#define DRV_VERSION "0.9"
39#undef PDC_DEBUG 39#undef PDC_DEBUG
40 40
41#ifdef PDC_DEBUG 41#ifdef PDC_DEBUG
@@ -66,8 +66,10 @@ static int pdc2027x_init_one(struct pci_dev *pdev, const struct pci_device_id *e
66static void pdc2027x_error_handler(struct ata_port *ap); 66static void pdc2027x_error_handler(struct ata_port *ap);
67static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev); 67static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev);
68static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev); 68static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev);
69static void pdc2027x_post_set_mode(struct ata_port *ap);
70static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc); 69static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc);
70static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long mask);
71static int pdc2027x_cable_detect(struct ata_port *ap);
72static int pdc2027x_set_mode(struct ata_port *ap, struct ata_device **r_failed);
71 73
72/* 74/*
73 * ATA Timing Tables based on 133MHz controller clock. 75 * ATA Timing Tables based on 133MHz controller clock.
@@ -146,6 +148,7 @@ static struct scsi_host_template pdc2027x_sht = {
146 148
147static struct ata_port_operations pdc2027x_pata100_ops = { 149static struct ata_port_operations pdc2027x_pata100_ops = {
148 .port_disable = ata_port_disable, 150 .port_disable = ata_port_disable,
151 .mode_filter = ata_pci_default_filter,
149 152
150 .tf_load = ata_tf_load, 153 .tf_load = ata_tf_load,
151 .tf_read = ata_tf_read, 154 .tf_read = ata_tf_read,
@@ -166,8 +169,8 @@ static struct ata_port_operations pdc2027x_pata100_ops = {
166 .thaw = ata_bmdma_thaw, 169 .thaw = ata_bmdma_thaw,
167 .error_handler = pdc2027x_error_handler, 170 .error_handler = pdc2027x_error_handler,
168 .post_internal_cmd = ata_bmdma_post_internal_cmd, 171 .post_internal_cmd = ata_bmdma_post_internal_cmd,
172 .cable_detect = pdc2027x_cable_detect,
169 173
170 .irq_handler = ata_interrupt,
171 .irq_clear = ata_bmdma_irq_clear, 174 .irq_clear = ata_bmdma_irq_clear,
172 .irq_on = ata_irq_on, 175 .irq_on = ata_irq_on,
173 .irq_ack = ata_irq_ack, 176 .irq_ack = ata_irq_ack,
@@ -179,7 +182,8 @@ static struct ata_port_operations pdc2027x_pata133_ops = {
179 .port_disable = ata_port_disable, 182 .port_disable = ata_port_disable,
180 .set_piomode = pdc2027x_set_piomode, 183 .set_piomode = pdc2027x_set_piomode,
181 .set_dmamode = pdc2027x_set_dmamode, 184 .set_dmamode = pdc2027x_set_dmamode,
182 .post_set_mode = pdc2027x_post_set_mode, 185 .set_mode = pdc2027x_set_mode,
186 .mode_filter = pdc2027x_mode_filter,
183 187
184 .tf_load = ata_tf_load, 188 .tf_load = ata_tf_load,
185 .tf_read = ata_tf_read, 189 .tf_read = ata_tf_read,
@@ -200,8 +204,8 @@ static struct ata_port_operations pdc2027x_pata133_ops = {
200 .thaw = ata_bmdma_thaw, 204 .thaw = ata_bmdma_thaw,
201 .error_handler = pdc2027x_error_handler, 205 .error_handler = pdc2027x_error_handler,
202 .post_internal_cmd = ata_bmdma_post_internal_cmd, 206 .post_internal_cmd = ata_bmdma_post_internal_cmd,
207 .cable_detect = pdc2027x_cable_detect,
203 208
204 .irq_handler = ata_interrupt,
205 .irq_clear = ata_bmdma_irq_clear, 209 .irq_clear = ata_bmdma_irq_clear,
206 .irq_on = ata_irq_on, 210 .irq_on = ata_irq_on,
207 .irq_ack = ata_irq_ack, 211 .irq_ack = ata_irq_ack,
@@ -212,7 +216,6 @@ static struct ata_port_operations pdc2027x_pata133_ops = {
212static struct ata_port_info pdc2027x_port_info[] = { 216static struct ata_port_info pdc2027x_port_info[] = {
213 /* PDC_UDMA_100 */ 217 /* PDC_UDMA_100 */
214 { 218 {
215 .sht = &pdc2027x_sht,
216 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS | 219 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS |
217 ATA_FLAG_MMIO, 220 ATA_FLAG_MMIO,
218 .pio_mask = 0x1f, /* pio0-4 */ 221 .pio_mask = 0x1f, /* pio0-4 */
@@ -222,7 +225,6 @@ static struct ata_port_info pdc2027x_port_info[] = {
222 }, 225 },
223 /* PDC_UDMA_133 */ 226 /* PDC_UDMA_133 */
224 { 227 {
225 .sht = &pdc2027x_sht,
226 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS | 228 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS |
227 ATA_FLAG_MMIO, 229 ATA_FLAG_MMIO,
228 .pio_mask = 0x1f, /* pio0-4 */ 230 .pio_mask = 0x1f, /* pio0-4 */
@@ -261,7 +263,7 @@ static inline void __iomem *dev_mmio(struct ata_port *ap, struct ata_device *ade
261} 263}
262 264
263/** 265/**
264 * pdc2027x_pata_cbl_detect - Probe host controller cable detect info 266 * pdc2027x_pata_cable_detect - Probe host controller cable detect info
265 * @ap: Port for which cable detect info is desired 267 * @ap: Port for which cable detect info is desired
266 * 268 *
267 * Read 80c cable indicator from Promise extended register. 269 * Read 80c cable indicator from Promise extended register.
@@ -270,7 +272,7 @@ static inline void __iomem *dev_mmio(struct ata_port *ap, struct ata_device *ade
270 * LOCKING: 272 * LOCKING:
271 * None (inherited from caller). 273 * None (inherited from caller).
272 */ 274 */
273static void pdc2027x_cbl_detect(struct ata_port *ap) 275static int pdc2027x_cable_detect(struct ata_port *ap)
274{ 276{
275 u32 cgcr; 277 u32 cgcr;
276 278
@@ -281,13 +283,10 @@ static void pdc2027x_cbl_detect(struct ata_port *ap)
281 283
282 PDPRINTK("No cable or 80-conductor cable on port %d\n", ap->port_no); 284 PDPRINTK("No cable or 80-conductor cable on port %d\n", ap->port_no);
283 285
284 ap->cbl = ATA_CBL_PATA80; 286 return ATA_CBL_PATA80;
285 return;
286
287cbl40: 287cbl40:
288 printk(KERN_INFO DRV_NAME ": 40-conductor cable detected on port %d\n", ap->port_no); 288 printk(KERN_INFO DRV_NAME ": 40-conductor cable detected on port %d\n", ap->port_no);
289 ap->cbl = ATA_CBL_PATA40; 289 return ATA_CBL_PATA40;
290 ap->udma_mask &= ATA_UDMA_MASK_40C;
291} 290}
292 291
293/** 292/**
@@ -314,7 +313,6 @@ static int pdc2027x_prereset(struct ata_port *ap)
314 /* Check whether port enabled */ 313 /* Check whether port enabled */
315 if (!pdc2027x_port_enabled(ap)) 314 if (!pdc2027x_port_enabled(ap))
316 return -ENOENT; 315 return -ENOENT;
317 pdc2027x_cbl_detect(ap);
318 return ata_std_prereset(ap); 316 return ata_std_prereset(ap);
319} 317}
320 318
@@ -334,6 +332,32 @@ static void pdc2027x_error_handler(struct ata_port *ap)
334} 332}
335 333
336/** 334/**
335 * pdc2720x_mode_filter - mode selection filter
336 * @adev: ATA device
337 * @mask: list of modes proposed
338 *
339 * Block UDMA on devices that cause trouble with this controller.
340 */
341
342static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long mask)
343{
344 unsigned char model_num[ATA_ID_PROD_LEN + 1];
345 struct ata_device *pair = ata_dev_pair(adev);
346
347 if (adev->class != ATA_DEV_ATA || adev->devno == 0 || pair == NULL)
348 return ata_pci_default_filter(adev, mask);
349
350 /* Check for slave of a Maxtor at UDMA6 */
351 ata_id_c_string(pair->id, model_num, ATA_ID_PROD,
352 ATA_ID_PROD_LEN + 1);
353 /* If the master is a maxtor in UDMA6 then the slave should not use UDMA 6 */
354 if(strstr(model_num, "Maxtor") == 0 && pair->dma_mode == XFER_UDMA_6)
355 mask &= ~ (1 << (6 + ATA_SHIFT_UDMA));
356
357 return ata_pci_default_filter(adev, mask);
358}
359
360/**
337 * pdc2027x_set_piomode - Initialize host controller PATA PIO timings 361 * pdc2027x_set_piomode - Initialize host controller PATA PIO timings
338 * @ap: Port to configure 362 * @ap: Port to configure
339 * @adev: um 363 * @adev: um
@@ -444,17 +468,22 @@ static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
444} 468}
445 469
446/** 470/**
447 * pdc2027x_post_set_mode - Set the timing registers back to correct values. 471 * pdc2027x_set_mode - Set the timing registers back to correct values.
448 * @ap: Port to configure 472 * @ap: Port to configure
473 * @r_failed: Returned device for failure
449 * 474 *
450 * The pdc2027x hardware will look at "SET FEATURES" and change the timing registers 475 * The pdc2027x hardware will look at "SET FEATURES" and change the timing registers
451 * automatically. The values set by the hardware might be incorrect, under 133Mhz PLL. 476 * automatically. The values set by the hardware might be incorrect, under 133Mhz PLL.
452 * This function overwrites the possibly incorrect values set by the hardware to be correct. 477 * This function overwrites the possibly incorrect values set by the hardware to be correct.
453 */ 478 */
454static void pdc2027x_post_set_mode(struct ata_port *ap) 479static int pdc2027x_set_mode(struct ata_port *ap, struct ata_device **r_failed)
455{ 480{
456 int i; 481 int i;
457 482
483 i = ata_do_set_mode(ap, r_failed);
484 if (i < 0)
485 return i;
486
458 for (i = 0; i < ATA_MAX_DEVICES; i++) { 487 for (i = 0; i < ATA_MAX_DEVICES; i++) {
459 struct ata_device *dev = &ap->device[i]; 488 struct ata_device *dev = &ap->device[i];
460 489
@@ -476,6 +505,7 @@ static void pdc2027x_post_set_mode(struct ata_port *ap)
476 } 505 }
477 } 506 }
478 } 507 }
508 return 0;
479} 509}
480 510
481/** 511/**
@@ -521,12 +551,12 @@ static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc)
521 551
522/** 552/**
523 * pdc_read_counter - Read the ctr counter 553 * pdc_read_counter - Read the ctr counter
524 * @probe_ent: for the port address 554 * @host: target ATA host
525 */ 555 */
526 556
527static long pdc_read_counter(struct ata_probe_ent *probe_ent) 557static long pdc_read_counter(struct ata_host *host)
528{ 558{
529 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR]; 559 void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
530 long counter; 560 long counter;
531 int retry = 1; 561 int retry = 1;
532 u32 bccrl, bccrh, bccrlv, bccrhv; 562 u32 bccrl, bccrh, bccrlv, bccrhv;
@@ -564,12 +594,12 @@ retry:
564 * adjust_pll - Adjust the PLL input clock in Hz. 594 * adjust_pll - Adjust the PLL input clock in Hz.
565 * 595 *
566 * @pdc_controller: controller specific information 596 * @pdc_controller: controller specific information
567 * @probe_ent: For the port address 597 * @host: target ATA host
568 * @pll_clock: The input of PLL in HZ 598 * @pll_clock: The input of PLL in HZ
569 */ 599 */
570static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsigned int board_idx) 600static void pdc_adjust_pll(struct ata_host *host, long pll_clock, unsigned int board_idx)
571{ 601{
572 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR]; 602 void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
573 u16 pll_ctl; 603 u16 pll_ctl;
574 long pll_clock_khz = pll_clock / 1000; 604 long pll_clock_khz = pll_clock / 1000;
575 long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ; 605 long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ;
@@ -649,19 +679,19 @@ static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsi
649 679
650/** 680/**
651 * detect_pll_input_clock - Detect the PLL input clock in Hz. 681 * detect_pll_input_clock - Detect the PLL input clock in Hz.
652 * @probe_ent: for the port address 682 * @host: target ATA host
653 * Ex. 16949000 on 33MHz PCI bus for pdc20275. 683 * Ex. 16949000 on 33MHz PCI bus for pdc20275.
654 * Half of the PCI clock. 684 * Half of the PCI clock.
655 */ 685 */
656static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent) 686static long pdc_detect_pll_input_clock(struct ata_host *host)
657{ 687{
658 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR]; 688 void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
659 u32 scr; 689 u32 scr;
660 long start_count, end_count; 690 long start_count, end_count;
661 long pll_clock; 691 long pll_clock;
662 692
663 /* Read current counter value */ 693 /* Read current counter value */
664 start_count = pdc_read_counter(probe_ent); 694 start_count = pdc_read_counter(host);
665 695
666 /* Start the test mode */ 696 /* Start the test mode */
667 scr = readl(mmio_base + PDC_SYS_CTL); 697 scr = readl(mmio_base + PDC_SYS_CTL);
@@ -673,7 +703,7 @@ static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent)
673 mdelay(100); 703 mdelay(100);
674 704
675 /* Read the counter values again */ 705 /* Read the counter values again */
676 end_count = pdc_read_counter(probe_ent); 706 end_count = pdc_read_counter(host);
677 707
678 /* Stop the test mode */ 708 /* Stop the test mode */
679 scr = readl(mmio_base + PDC_SYS_CTL); 709 scr = readl(mmio_base + PDC_SYS_CTL);
@@ -692,11 +722,10 @@ static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent)
692 722
693/** 723/**
694 * pdc_hardware_init - Initialize the hardware. 724 * pdc_hardware_init - Initialize the hardware.
695 * @pdev: instance of pci_dev found 725 * @host: target ATA host
696 * @pdc_controller: controller specific information 726 * @board_idx: board identifier
697 * @pe: for the port address
698 */ 727 */
699static int pdc_hardware_init(struct pci_dev *pdev, struct ata_probe_ent *pe, unsigned int board_idx) 728static int pdc_hardware_init(struct ata_host *host, unsigned int board_idx)
700{ 729{
701 long pll_clock; 730 long pll_clock;
702 731
@@ -706,15 +735,15 @@ static int pdc_hardware_init(struct pci_dev *pdev, struct ata_probe_ent *pe, uns
706 * Ex. 25MHz or 40MHz, we have to adjust the cycle_time. 735 * Ex. 25MHz or 40MHz, we have to adjust the cycle_time.
707 * The pdc20275 controller employs PLL circuit to help correct timing registers setting. 736 * The pdc20275 controller employs PLL circuit to help correct timing registers setting.
708 */ 737 */
709 pll_clock = pdc_detect_pll_input_clock(pe); 738 pll_clock = pdc_detect_pll_input_clock(host);
710 739
711 if (pll_clock < 0) /* counter overflow? Try again. */ 740 if (pll_clock < 0) /* counter overflow? Try again. */
712 pll_clock = pdc_detect_pll_input_clock(pe); 741 pll_clock = pdc_detect_pll_input_clock(host);
713 742
714 dev_printk(KERN_INFO, &pdev->dev, "PLL input clock %ld kHz\n", pll_clock/1000); 743 dev_printk(KERN_INFO, host->dev, "PLL input clock %ld kHz\n", pll_clock/1000);
715 744
716 /* Adjust PLL control register */ 745 /* Adjust PLL control register */
717 pdc_adjust_pll(pe, pll_clock, board_idx); 746 pdc_adjust_pll(host, pll_clock, board_idx);
718 747
719 return 0; 748 return 0;
720} 749}
@@ -746,8 +775,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
746 * Called when an instance of PCI adapter is inserted. 775 * Called when an instance of PCI adapter is inserted.
747 * This function checks whether the hardware is supported, 776 * This function checks whether the hardware is supported,
748 * initialize hardware and register an instance of ata_host to 777 * initialize hardware and register an instance of ata_host to
749 * libata by providing struct ata_probe_ent and ata_device_add(). 778 * libata. (implements struct pci_driver.probe() )
750 * (implements struct pci_driver.probe() )
751 * 779 *
752 * @pdev: instance of pci_dev found 780 * @pdev: instance of pci_dev found
753 * @ent: matching entry in the id_tbl[] 781 * @ent: matching entry in the id_tbl[]
@@ -756,14 +784,21 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
756{ 784{
757 static int printed_version; 785 static int printed_version;
758 unsigned int board_idx = (unsigned int) ent->driver_data; 786 unsigned int board_idx = (unsigned int) ent->driver_data;
759 787 const struct ata_port_info *ppi[] =
760 struct ata_probe_ent *probe_ent; 788 { &pdc2027x_port_info[board_idx], NULL };
789 struct ata_host *host;
761 void __iomem *mmio_base; 790 void __iomem *mmio_base;
762 int rc; 791 int rc;
763 792
764 if (!printed_version++) 793 if (!printed_version++)
765 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 794 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
766 795
796 /* alloc host */
797 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
798 if (!host)
799 return -ENOMEM;
800
801 /* acquire resources and fill host */
767 rc = pcim_enable_device(pdev); 802 rc = pcim_enable_device(pdev);
768 if (rc) 803 if (rc)
769 return rc; 804 return rc;
@@ -771,6 +806,7 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
771 rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME); 806 rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
772 if (rc) 807 if (rc)
773 return rc; 808 return rc;
809 host->iomap = pcim_iomap_table(pdev);
774 810
775 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 811 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
776 if (rc) 812 if (rc)
@@ -780,46 +816,22 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
780 if (rc) 816 if (rc)
781 return rc; 817 return rc;
782 818
783 /* Prepare the probe entry */ 819 mmio_base = host->iomap[PDC_MMIO_BAR];
784 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
785 if (probe_ent == NULL)
786 return -ENOMEM;
787
788 probe_ent->dev = pci_dev_to_dev(pdev);
789 INIT_LIST_HEAD(&probe_ent->node);
790
791 probe_ent->sht = pdc2027x_port_info[board_idx].sht;
792 probe_ent->port_flags = pdc2027x_port_info[board_idx].flags;
793 probe_ent->pio_mask = pdc2027x_port_info[board_idx].pio_mask;
794 probe_ent->mwdma_mask = pdc2027x_port_info[board_idx].mwdma_mask;
795 probe_ent->udma_mask = pdc2027x_port_info[board_idx].udma_mask;
796 probe_ent->port_ops = pdc2027x_port_info[board_idx].port_ops;
797 820
798 probe_ent->irq = pdev->irq; 821 pdc_ata_setup_port(&host->ports[0]->ioaddr, mmio_base + 0x17c0);
799 probe_ent->irq_flags = IRQF_SHARED; 822 host->ports[0]->ioaddr.bmdma_addr = mmio_base + 0x1000;
800 probe_ent->iomap = pcim_iomap_table(pdev); 823 pdc_ata_setup_port(&host->ports[1]->ioaddr, mmio_base + 0x15c0);
824 host->ports[1]->ioaddr.bmdma_addr = mmio_base + 0x1008;
801 825
802 mmio_base = probe_ent->iomap[PDC_MMIO_BAR];
803
804 pdc_ata_setup_port(&probe_ent->port[0], mmio_base + 0x17c0);
805 probe_ent->port[0].bmdma_addr = mmio_base + 0x1000;
806 pdc_ata_setup_port(&probe_ent->port[1], mmio_base + 0x15c0);
807 probe_ent->port[1].bmdma_addr = mmio_base + 0x1008;
808
809 probe_ent->n_ports = 2;
810
811 pci_set_master(pdev);
812 //pci_enable_intx(pdev); 826 //pci_enable_intx(pdev);
813 827
814 /* initialize adapter */ 828 /* initialize adapter */
815 if (pdc_hardware_init(pdev, probe_ent, board_idx) != 0) 829 if (pdc_hardware_init(host, board_idx) != 0)
816 return -EIO; 830 return -EIO;
817 831
818 if (!ata_device_add(probe_ent)) 832 pci_set_master(pdev);
819 return -ENODEV; 833 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
820 834 &pdc2027x_sht);
821 devm_kfree(&pdev->dev, probe_ent);
822 return 0;
823} 835}
824 836
825/** 837/**
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index 0a1493398913..ee636beb05e1 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -22,45 +22,17 @@
22#include <linux/libata.h> 22#include <linux/libata.h>
23 23
24#define DRV_NAME "pata_pdc202xx_old" 24#define DRV_NAME "pata_pdc202xx_old"
25#define DRV_VERSION "0.4.0" 25#define DRV_VERSION "0.4.2"
26 26
27/** 27static int pdc2026x_cable_detect(struct ata_port *ap)
28 * pdc2024x_pre_reset - probe begin
29 * @ap: ATA port
30 *
31 * Set up cable type and use generic probe init
32 */
33
34static int pdc2024x_pre_reset(struct ata_port *ap)
35{
36 ap->cbl = ATA_CBL_PATA40;
37 return ata_std_prereset(ap);
38}
39
40
41static void pdc2024x_error_handler(struct ata_port *ap)
42{
43 ata_bmdma_drive_eh(ap, pdc2024x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
44}
45
46
47static int pdc2026x_pre_reset(struct ata_port *ap)
48{ 28{
49 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 29 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
50 u16 cis; 30 u16 cis;
51 31
52 pci_read_config_word(pdev, 0x50, &cis); 32 pci_read_config_word(pdev, 0x50, &cis);
53 if (cis & (1 << (10 + ap->port_no))) 33 if (cis & (1 << (10 + ap->port_no)))
54 ap->cbl = ATA_CBL_PATA80; 34 return ATA_CBL_PATA80;
55 else 35 return ATA_CBL_PATA40;
56 ap->cbl = ATA_CBL_PATA40;
57
58 return ata_std_prereset(ap);
59}
60
61static void pdc2026x_error_handler(struct ata_port *ap)
62{
63 ata_bmdma_drive_eh(ap, pdc2026x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
64} 36}
65 37
66/** 38/**
@@ -244,7 +216,6 @@ static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
244 216
245/** 217/**
246 * pdc2026x_dev_config - device setup hook 218 * pdc2026x_dev_config - device setup hook
247 * @ap: ATA port
248 * @adev: newly found device 219 * @adev: newly found device
249 * 220 *
250 * Perform chip specific early setup. We need to lock the transfer 221 * Perform chip specific early setup. We need to lock the transfer
@@ -252,7 +223,7 @@ static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
252 * barf. 223 * barf.
253 */ 224 */
254 225
255static void pdc2026x_dev_config(struct ata_port *ap, struct ata_device *adev) 226static void pdc2026x_dev_config(struct ata_device *adev)
256{ 227{
257 adev->max_sectors = 256; 228 adev->max_sectors = 256;
258} 229}
@@ -292,8 +263,9 @@ static struct ata_port_operations pdc2024x_port_ops = {
292 263
293 .freeze = ata_bmdma_freeze, 264 .freeze = ata_bmdma_freeze,
294 .thaw = ata_bmdma_thaw, 265 .thaw = ata_bmdma_thaw,
295 .error_handler = pdc2024x_error_handler, 266 .error_handler = ata_bmdma_error_handler,
296 .post_internal_cmd = ata_bmdma_post_internal_cmd, 267 .post_internal_cmd = ata_bmdma_post_internal_cmd,
268 .cable_detect = ata_cable_40wire,
297 269
298 .bmdma_setup = ata_bmdma_setup, 270 .bmdma_setup = ata_bmdma_setup,
299 .bmdma_start = ata_bmdma_start, 271 .bmdma_start = ata_bmdma_start,
@@ -326,8 +298,9 @@ static struct ata_port_operations pdc2026x_port_ops = {
326 298
327 .freeze = ata_bmdma_freeze, 299 .freeze = ata_bmdma_freeze,
328 .thaw = ata_bmdma_thaw, 300 .thaw = ata_bmdma_thaw,
329 .error_handler = pdc2026x_error_handler, 301 .error_handler = ata_bmdma_error_handler,
330 .post_internal_cmd = ata_bmdma_post_internal_cmd, 302 .post_internal_cmd = ata_bmdma_post_internal_cmd,
303 .cable_detect = pdc2026x_cable_detect,
331 304
332 .bmdma_setup = ata_bmdma_setup, 305 .bmdma_setup = ata_bmdma_setup,
333 .bmdma_start = pdc2026x_bmdma_start, 306 .bmdma_start = pdc2026x_bmdma_start,
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 4b82a5435a4e..a0a650c7f272 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -80,13 +80,13 @@ static struct ata_port_operations pata_platform_port_ops = {
80 .thaw = ata_bmdma_thaw, 80 .thaw = ata_bmdma_thaw,
81 .error_handler = ata_bmdma_error_handler, 81 .error_handler = ata_bmdma_error_handler,
82 .post_internal_cmd = ata_bmdma_post_internal_cmd, 82 .post_internal_cmd = ata_bmdma_post_internal_cmd,
83 .cable_detect = ata_cable_unknown,
83 84
84 .qc_prep = ata_qc_prep, 85 .qc_prep = ata_qc_prep,
85 .qc_issue = ata_qc_issue_prot, 86 .qc_issue = ata_qc_issue_prot,
86 87
87 .data_xfer = ata_data_xfer_noirq, 88 .data_xfer = ata_data_xfer_noirq,
88 89
89 .irq_handler = ata_interrupt,
90 .irq_clear = ata_bmdma_irq_clear, 90 .irq_clear = ata_bmdma_irq_clear,
91 .irq_on = ata_irq_on, 91 .irq_on = ata_irq_on,
92 .irq_ack = ata_irq_ack, 92 .irq_ack = ata_irq_ack,
@@ -135,7 +135,8 @@ static void pata_platform_setup_port(struct ata_ioports *ioaddr,
135static int __devinit pata_platform_probe(struct platform_device *pdev) 135static int __devinit pata_platform_probe(struct platform_device *pdev)
136{ 136{
137 struct resource *io_res, *ctl_res; 137 struct resource *io_res, *ctl_res;
138 struct ata_probe_ent ae; 138 struct ata_host *host;
139 struct ata_port *ap;
139 unsigned int mmio; 140 unsigned int mmio;
140 141
141 /* 142 /*
@@ -175,44 +176,41 @@ static int __devinit pata_platform_probe(struct platform_device *pdev)
175 /* 176 /*
176 * Now that that's out of the way, wire up the port.. 177 * Now that that's out of the way, wire up the port..
177 */ 178 */
178 memset(&ae, 0, sizeof(struct ata_probe_ent)); 179 host = ata_host_alloc(&pdev->dev, 1);
179 INIT_LIST_HEAD(&ae.node); 180 if (!host)
180 ae.dev = &pdev->dev; 181 return -ENOMEM;
181 ae.port_ops = &pata_platform_port_ops; 182 ap = host->ports[0];
182 ae.sht = &pata_platform_sht; 183
183 ae.n_ports = 1; 184 ap->ops = &pata_platform_port_ops;
184 ae.pio_mask = pio_mask; 185 ap->pio_mask = pio_mask;
185 ae.irq = platform_get_irq(pdev, 0); 186 ap->flags |= ATA_FLAG_SLAVE_POSS;
186 ae.irq_flags = 0;
187 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
188 187
189 /* 188 /*
190 * Handle the MMIO case 189 * Handle the MMIO case
191 */ 190 */
192 if (mmio) { 191 if (mmio) {
193 ae.port[0].cmd_addr = devm_ioremap(&pdev->dev, io_res->start, 192 ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, io_res->start,
194 io_res->end - io_res->start + 1); 193 io_res->end - io_res->start + 1);
195 ae.port[0].ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start, 194 ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
196 ctl_res->end - ctl_res->start + 1); 195 ctl_res->end - ctl_res->start + 1);
197 } else { 196 } else {
198 ae.port[0].cmd_addr = devm_ioport_map(&pdev->dev, io_res->start, 197 ap->ioaddr.cmd_addr = devm_ioport_map(&pdev->dev, io_res->start,
199 io_res->end - io_res->start + 1); 198 io_res->end - io_res->start + 1);
200 ae.port[0].ctl_addr = devm_ioport_map(&pdev->dev, ctl_res->start, 199 ap->ioaddr.ctl_addr = devm_ioport_map(&pdev->dev, ctl_res->start,
201 ctl_res->end - ctl_res->start + 1); 200 ctl_res->end - ctl_res->start + 1);
202 } 201 }
203 if (!ae.port[0].cmd_addr || !ae.port[0].ctl_addr) { 202 if (!ap->ioaddr.cmd_addr || !ap->ioaddr.ctl_addr) {
204 dev_err(&pdev->dev, "failed to map IO/CTL base\n"); 203 dev_err(&pdev->dev, "failed to map IO/CTL base\n");
205 return -ENOMEM; 204 return -ENOMEM;
206 } 205 }
207 206
208 ae.port[0].altstatus_addr = ae.port[0].ctl_addr; 207 ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;
209 208
210 pata_platform_setup_port(&ae.port[0], pdev->dev.platform_data); 209 pata_platform_setup_port(&ap->ioaddr, pdev->dev.platform_data);
211 210
212 if (unlikely(ata_device_add(&ae) == 0)) 211 /* activate */
213 return -ENODEV; 212 return ata_host_activate(host, platform_get_irq(pdev, 0), ata_interrupt,
214 213 0, &pata_platform_sht);
215 return 0;
216} 214}
217 215
218/** 216/**
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index c3810012f3f4..27685ce63ceb 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -183,13 +183,13 @@ static struct ata_port_operations qdi6500_port_ops = {
183 .thaw = ata_bmdma_thaw, 183 .thaw = ata_bmdma_thaw,
184 .error_handler = ata_bmdma_error_handler, 184 .error_handler = ata_bmdma_error_handler,
185 .post_internal_cmd = ata_bmdma_post_internal_cmd, 185 .post_internal_cmd = ata_bmdma_post_internal_cmd,
186 .cable_detect = ata_cable_40wire,
186 187
187 .qc_prep = ata_qc_prep, 188 .qc_prep = ata_qc_prep,
188 .qc_issue = qdi_qc_issue_prot, 189 .qc_issue = qdi_qc_issue_prot,
189 190
190 .data_xfer = qdi_data_xfer, 191 .data_xfer = qdi_data_xfer,
191 192
192 .irq_handler = ata_interrupt,
193 .irq_clear = ata_bmdma_irq_clear, 193 .irq_clear = ata_bmdma_irq_clear,
194 .irq_on = ata_irq_on, 194 .irq_on = ata_irq_on,
195 .irq_ack = ata_irq_ack, 195 .irq_ack = ata_irq_ack,
@@ -211,13 +211,13 @@ static struct ata_port_operations qdi6580_port_ops = {
211 .thaw = ata_bmdma_thaw, 211 .thaw = ata_bmdma_thaw,
212 .error_handler = ata_bmdma_error_handler, 212 .error_handler = ata_bmdma_error_handler,
213 .post_internal_cmd = ata_bmdma_post_internal_cmd, 213 .post_internal_cmd = ata_bmdma_post_internal_cmd,
214 .cable_detect = ata_cable_40wire,
214 215
215 .qc_prep = ata_qc_prep, 216 .qc_prep = ata_qc_prep,
216 .qc_issue = qdi_qc_issue_prot, 217 .qc_issue = qdi_qc_issue_prot,
217 218
218 .data_xfer = qdi_data_xfer, 219 .data_xfer = qdi_data_xfer,
219 220
220 .irq_handler = ata_interrupt,
221 .irq_clear = ata_bmdma_irq_clear, 221 .irq_clear = ata_bmdma_irq_clear,
222 .irq_on = ata_irq_on, 222 .irq_on = ata_irq_on,
223 .irq_ack = ata_irq_ack, 223 .irq_ack = ata_irq_ack,
@@ -238,8 +238,9 @@ static struct ata_port_operations qdi6580_port_ops = {
238 238
239static __init int qdi_init_one(unsigned long port, int type, unsigned long io, int irq, int fast) 239static __init int qdi_init_one(unsigned long port, int type, unsigned long io, int irq, int fast)
240{ 240{
241 struct ata_probe_ent ae;
242 struct platform_device *pdev; 241 struct platform_device *pdev;
242 struct ata_host *host;
243 struct ata_port *ap;
243 void __iomem *io_addr, *ctl_addr; 244 void __iomem *io_addr, *ctl_addr;
244 int ret; 245 int ret;
245 246
@@ -257,34 +258,31 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
257 if (!io_addr || !ctl_addr) 258 if (!io_addr || !ctl_addr)
258 goto fail; 259 goto fail;
259 260
260 memset(&ae, 0, sizeof(struct ata_probe_ent)); 261 ret = -ENOMEM;
261 INIT_LIST_HEAD(&ae.node); 262 host = ata_host_alloc(&pdev->dev, 1);
262 ae.dev = &pdev->dev; 263 if (!host)
264 goto fail;
265 ap = host->ports[0];
263 266
264 if (type == 6580) { 267 if (type == 6580) {
265 ae.port_ops = &qdi6580_port_ops; 268 ap->ops = &qdi6580_port_ops;
266 ae.pio_mask = 0x1F; 269 ap->pio_mask = 0x1F;
267 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 270 ap->flags |= ATA_FLAG_SLAVE_POSS;
268 } else { 271 } else {
269 ae.port_ops = &qdi6500_port_ops; 272 ap->ops = &qdi6500_port_ops;
270 ae.pio_mask = 0x07; /* Actually PIO3 !IORDY is possible */ 273 ap->pio_mask = 0x07; /* Actually PIO3 !IORDY is possible */
271 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | 274 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
272 ATA_FLAG_NO_IORDY;
273 } 275 }
274 276
275 ae.sht = &qdi_sht; 277 ap->ioaddr.cmd_addr = io_addr;
276 ae.n_ports = 1; 278 ap->ioaddr.altstatus_addr = ctl_addr;
277 ae.irq = irq; 279 ap->ioaddr.ctl_addr = ctl_addr;
278 ae.irq_flags = 0; 280 ata_std_ports(&ap->ioaddr);
279 ae.port[0].cmd_addr = io_addr;
280 ae.port[0].altstatus_addr = ctl_addr;
281 ae.port[0].ctl_addr = ctl_addr;
282 ata_std_ports(&ae.port[0]);
283 281
284 /* 282 /*
285 * Hook in a private data structure per channel 283 * Hook in a private data structure per channel
286 */ 284 */
287 ae.private_data = &qdi_data[nr_qdi_host]; 285 ap->private_data = &qdi_data[nr_qdi_host];
288 286
289 qdi_data[nr_qdi_host].timing = port; 287 qdi_data[nr_qdi_host].timing = port;
290 qdi_data[nr_qdi_host].fast = fast; 288 qdi_data[nr_qdi_host].fast = fast;
@@ -292,8 +290,9 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
292 290
293 printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io); 291 printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io);
294 292
295 ret = -ENODEV; 293 /* activate */
296 if (!ata_device_add(&ae)) 294 ret = ata_host_activate(host, irq, ata_interrupt, 0, &qdi_sht);
295 if (ret)
297 goto fail; 296 goto fail;
298 297
299 qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev); 298 qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev);
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 9a9132c9e331..1c54673e008d 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -24,40 +24,12 @@
24#include <linux/ata.h> 24#include <linux/ata.h>
25 25
26#define DRV_NAME "pata_radisys" 26#define DRV_NAME "pata_radisys"
27#define DRV_VERSION "0.4.1" 27#define DRV_VERSION "0.4.4"
28
29/**
30 * radisys_probe_init - probe begin
31 * @ap: ATA port
32 *
33 * Set up cable type and use generic probe init
34 */
35
36static int radisys_pre_reset(struct ata_port *ap)
37{
38 ap->cbl = ATA_CBL_PATA80;
39 return ata_std_prereset(ap);
40}
41
42
43/**
44 * radisys_pata_error_handler - Probe specified port on PATA host controller
45 * @ap: Port to probe
46 * @classes:
47 *
48 * LOCKING:
49 * None (inherited from caller).
50 */
51
52static void radisys_pata_error_handler(struct ata_port *ap)
53{
54 ata_bmdma_drive_eh(ap, radisys_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
55}
56 28
57/** 29/**
58 * radisys_set_piomode - Initialize host controller PATA PIO timings 30 * radisys_set_piomode - Initialize host controller PATA PIO timings
59 * @ap: Port whose timings we are configuring 31 * @ap: ATA port
60 * @adev: um 32 * @adev: Device whose timings we are configuring
61 * 33 *
62 * Set PIO mode for device, in host controller PCI config space. 34 * Set PIO mode for device, in host controller PCI config space.
63 * 35 *
@@ -248,8 +220,9 @@ static const struct ata_port_operations radisys_pata_ops = {
248 220
249 .freeze = ata_bmdma_freeze, 221 .freeze = ata_bmdma_freeze,
250 .thaw = ata_bmdma_thaw, 222 .thaw = ata_bmdma_thaw,
251 .error_handler = radisys_pata_error_handler, 223 .error_handler = ata_bmdma_error_handler,
252 .post_internal_cmd = ata_bmdma_post_internal_cmd, 224 .post_internal_cmd = ata_bmdma_post_internal_cmd,
225 .cable_detect = ata_cable_unknown,
253 226
254 .bmdma_setup = ata_bmdma_setup, 227 .bmdma_setup = ata_bmdma_setup,
255 .bmdma_start = ata_bmdma_start, 228 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index f522daa2a6aa..85c45290eeee 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -25,31 +25,6 @@
25 25
26 26
27/** 27/**
28 * rz1000_prereset - probe begin
29 * @ap: ATA port
30 *
31 * Set up cable type and use generics
32 */
33
34static int rz1000_prereset(struct ata_port *ap)
35{
36 ap->cbl = ATA_CBL_PATA40;
37 return ata_std_prereset(ap);
38}
39
40/**
41 * rz1000_error_handler - probe reset
42 * @ap: ATA port
43 *
44 * Perform the ATA standard reset sequence
45 */
46
47static void rz1000_error_handler(struct ata_port *ap)
48{
49 ata_bmdma_drive_eh(ap, rz1000_prereset, ata_std_softreset, NULL, ata_std_postreset);
50}
51
52/**
53 * rz1000_set_mode - mode setting function 28 * rz1000_set_mode - mode setting function
54 * @ap: ATA interface 29 * @ap: ATA interface
55 * @unused: returned device on set_mode failure 30 * @unused: returned device on set_mode failure
@@ -122,8 +97,9 @@ static struct ata_port_operations rz1000_port_ops = {
122 97
123 .freeze = ata_bmdma_freeze, 98 .freeze = ata_bmdma_freeze,
124 .thaw = ata_bmdma_thaw, 99 .thaw = ata_bmdma_thaw,
125 .error_handler = rz1000_error_handler, 100 .error_handler = ata_bmdma_error_handler,
126 .post_internal_cmd = ata_bmdma_post_internal_cmd, 101 .post_internal_cmd = ata_bmdma_post_internal_cmd,
102 .cable_detect = ata_cable_40wire,
127 103
128 .irq_handler = ata_interrupt, 104 .irq_handler = ata_interrupt,
129 .irq_clear = ata_bmdma_irq_clear, 105 .irq_clear = ata_bmdma_irq_clear,
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index 93b3ed0f9e8a..66e8ff467c8d 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -216,6 +216,7 @@ static struct ata_port_operations sc1200_port_ops = {
216 .thaw = ata_bmdma_thaw, 216 .thaw = ata_bmdma_thaw,
217 .error_handler = ata_bmdma_error_handler, 217 .error_handler = ata_bmdma_error_handler,
218 .post_internal_cmd = ata_bmdma_post_internal_cmd, 218 .post_internal_cmd = ata_bmdma_post_internal_cmd,
219 .cable_detect = ata_cable_40wire,
219 220
220 .bmdma_setup = ata_bmdma_setup, 221 .bmdma_setup = ata_bmdma_setup,
221 .bmdma_start = ata_bmdma_start, 222 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index f3ed141fdc0e..5df354d573e8 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -1016,7 +1016,6 @@ static const struct ata_port_operations scc_pata_ops = {
1016 .error_handler = scc_error_handler, 1016 .error_handler = scc_error_handler,
1017 .post_internal_cmd = scc_bmdma_stop, 1017 .post_internal_cmd = scc_bmdma_stop,
1018 1018
1019 .irq_handler = ata_interrupt,
1020 .irq_clear = scc_bmdma_irq_clear, 1019 .irq_clear = scc_bmdma_irq_clear,
1021 .irq_on = scc_irq_on, 1020 .irq_on = scc_irq_on,
1022 .irq_ack = scc_irq_ack, 1021 .irq_ack = scc_irq_ack,
@@ -1027,7 +1026,6 @@ static const struct ata_port_operations scc_pata_ops = {
1027 1026
1028static struct ata_port_info scc_port_info[] = { 1027static struct ata_port_info scc_port_info[] = {
1029 { 1028 {
1030 .sht = &scc_sht,
1031 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY, 1029 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY,
1032 .pio_mask = 0x1f, /* pio0-4 */ 1030 .pio_mask = 0x1f, /* pio0-4 */
1033 .mwdma_mask = 0x00, 1031 .mwdma_mask = 0x00,
@@ -1040,10 +1038,10 @@ static struct ata_port_info scc_port_info[] = {
1040 * scc_reset_controller - initialize SCC PATA controller. 1038 * scc_reset_controller - initialize SCC PATA controller.
1041 */ 1039 */
1042 1040
1043static int scc_reset_controller(struct ata_probe_ent *probe_ent) 1041static int scc_reset_controller(struct ata_host *host)
1044{ 1042{
1045 void __iomem *ctrl_base = probe_ent->iomap[SCC_CTRL_BAR]; 1043 void __iomem *ctrl_base = host->iomap[SCC_CTRL_BAR];
1046 void __iomem *bmid_base = probe_ent->iomap[SCC_BMID_BAR]; 1044 void __iomem *bmid_base = host->iomap[SCC_BMID_BAR];
1047 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL; 1045 void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
1048 void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG; 1046 void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG;
1049 void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE; 1047 void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE;
@@ -1104,17 +1102,15 @@ static void scc_setup_ports (struct ata_ioports *ioaddr, void __iomem *base)
1104 ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD; 1102 ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD;
1105} 1103}
1106 1104
1107static int scc_host_init(struct ata_probe_ent *probe_ent) 1105static int scc_host_init(struct ata_host *host)
1108{ 1106{
1109 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1107 struct pci_dev *pdev = to_pci_dev(host->dev);
1110 int rc; 1108 int rc;
1111 1109
1112 rc = scc_reset_controller(probe_ent); 1110 rc = scc_reset_controller(host);
1113 if (rc) 1111 if (rc)
1114 return rc; 1112 return rc;
1115 1113
1116 probe_ent->n_ports = 1;
1117
1118 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1114 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1119 if (rc) 1115 if (rc)
1120 return rc; 1116 return rc;
@@ -1122,7 +1118,7 @@ static int scc_host_init(struct ata_probe_ent *probe_ent)
1122 if (rc) 1118 if (rc)
1123 return rc; 1119 return rc;
1124 1120
1125 scc_setup_ports(&probe_ent->port[0], probe_ent->iomap[SCC_BMID_BAR]); 1121 scc_setup_ports(&host->ports[0]->ioaddr, host->iomap[SCC_BMID_BAR]);
1126 1122
1127 pci_set_master(pdev); 1123 pci_set_master(pdev);
1128 1124
@@ -1145,14 +1141,18 @@ static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1145{ 1141{
1146 static int printed_version; 1142 static int printed_version;
1147 unsigned int board_idx = (unsigned int) ent->driver_data; 1143 unsigned int board_idx = (unsigned int) ent->driver_data;
1144 const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL };
1148 struct device *dev = &pdev->dev; 1145 struct device *dev = &pdev->dev;
1149 struct ata_probe_ent *probe_ent;
1150 int rc; 1146 int rc;
1151 1147
1152 if (!printed_version++) 1148 if (!printed_version++)
1153 dev_printk(KERN_DEBUG, &pdev->dev, 1149 dev_printk(KERN_DEBUG, &pdev->dev,
1154 "version " DRV_VERSION "\n"); 1150 "version " DRV_VERSION "\n");
1155 1151
1152 host = ata_port_alloc_pinfo(&pdev->dev, ppi, 1);
1153 if (!host)
1154 return -ENOMEM;
1155
1156 rc = pcim_enable_device(pdev); 1156 rc = pcim_enable_device(pdev);
1157 if (rc) 1157 if (rc)
1158 return rc; 1158 return rc;
@@ -1162,33 +1162,14 @@ static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1162 pcim_pin_device(pdev); 1162 pcim_pin_device(pdev);
1163 if (rc) 1163 if (rc)
1164 return rc; 1164 return rc;
1165 host->iomap = pcim_iomap_table(pdev);
1165 1166
1166 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL); 1167 rc = scc_host_init(host);
1167 if (!probe_ent)
1168 return -ENOMEM;
1169
1170 probe_ent->dev = dev;
1171 INIT_LIST_HEAD(&probe_ent->node);
1172
1173 probe_ent->sht = scc_port_info[board_idx].sht;
1174 probe_ent->port_flags = scc_port_info[board_idx].flags;
1175 probe_ent->pio_mask = scc_port_info[board_idx].pio_mask;
1176 probe_ent->udma_mask = scc_port_info[board_idx].udma_mask;
1177 probe_ent->port_ops = scc_port_info[board_idx].port_ops;
1178
1179 probe_ent->irq = pdev->irq;
1180 probe_ent->irq_flags = IRQF_SHARED;
1181 probe_ent->iomap = pcim_iomap_table(pdev);
1182
1183 rc = scc_host_init(probe_ent);
1184 if (rc) 1168 if (rc)
1185 return rc; 1169 return rc;
1186 1170
1187 if (!ata_device_add(probe_ent)) 1171 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
1188 return -ENODEV; 1172 &scc_sht);
1189
1190 devm_kfree(dev, probe_ent);
1191 return 0;
1192} 1173}
1193 1174
1194static struct pci_driver scc_pci_driver = { 1175static struct pci_driver scc_pci_driver = {
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 598eef810a74..3956ef26936d 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ata-serverworks.c - Serverworks PATA for new ATA layer 2 * pata_serverworks.c - Serverworks PATA for new ATA layer
3 * (C) 2005 Red Hat Inc 3 * (C) 2005 Red Hat Inc
4 * Alan Cox <alan@redhat.com> 4 * Alan Cox <alan@redhat.com>
5 * 5 *
@@ -137,14 +137,14 @@ static struct sv_cable_table cable_detect[] = {
137}; 137};
138 138
139/** 139/**
140 * serverworks_pre_reset - cable detection 140 * serverworks_cable_detect - cable detection
141 * @ap: ATA port 141 * @ap: ATA port
142 * 142 *
143 * Perform cable detection according to the device and subvendor 143 * Perform cable detection according to the device and subvendor
144 * identifications 144 * identifications
145 */ 145 */
146 146
147static int serverworks_pre_reset(struct ata_port *ap) { 147static int serverworks_cable_detect(struct ata_port *ap) {
148 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 148 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
149 struct sv_cable_table *cb = cable_detect; 149 struct sv_cable_table *cb = cable_detect;
150 150
@@ -152,8 +152,7 @@ static int serverworks_pre_reset(struct ata_port *ap) {
152 if (cb->device == pdev->device && 152 if (cb->device == pdev->device &&
153 (cb->subvendor == pdev->subsystem_vendor || 153 (cb->subvendor == pdev->subsystem_vendor ||
154 cb->subvendor == PCI_ANY_ID)) { 154 cb->subvendor == PCI_ANY_ID)) {
155 ap->cbl = cb->cable_detect(ap); 155 return cb->cable_detect(ap);
156 return ata_std_prereset(ap);
157 } 156 }
158 cb++; 157 cb++;
159 } 158 }
@@ -162,11 +161,6 @@ static int serverworks_pre_reset(struct ata_port *ap) {
162 return -1; /* kill compiler warning */ 161 return -1; /* kill compiler warning */
163} 162}
164 163
165static void serverworks_error_handler(struct ata_port *ap)
166{
167 return ata_bmdma_drive_eh(ap, serverworks_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
168}
169
170/** 164/**
171 * serverworks_is_csb - Check for CSB or OSB 165 * serverworks_is_csb - Check for CSB or OSB
172 * @pdev: PCI device to check 166 * @pdev: PCI device to check
@@ -191,31 +185,31 @@ static u8 serverworks_is_csb(struct pci_dev *pdev)
191 185
192/** 186/**
193 * serverworks_osb4_filter - mode selection filter 187 * serverworks_osb4_filter - mode selection filter
194 * @ap: ATA interface
195 * @adev: ATA device 188 * @adev: ATA device
189 * @mask: Mask of proposed modes
196 * 190 *
197 * Filter the offered modes for the device to apply controller 191 * Filter the offered modes for the device to apply controller
198 * specific rules. OSB4 requires no UDMA for disks due to a FIFO 192 * specific rules. OSB4 requires no UDMA for disks due to a FIFO
199 * bug we hit. 193 * bug we hit.
200 */ 194 */
201 195
202static unsigned long serverworks_osb4_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 196static unsigned long serverworks_osb4_filter(struct ata_device *adev, unsigned long mask)
203{ 197{
204 if (adev->class == ATA_DEV_ATA) 198 if (adev->class == ATA_DEV_ATA)
205 mask &= ~ATA_MASK_UDMA; 199 mask &= ~ATA_MASK_UDMA;
206 return ata_pci_default_filter(ap, adev, mask); 200 return ata_pci_default_filter(adev, mask);
207} 201}
208 202
209 203
210/** 204/**
211 * serverworks_csb_filter - mode selection filter 205 * serverworks_csb_filter - mode selection filter
212 * @ap: ATA interface
213 * @adev: ATA device 206 * @adev: ATA device
207 * @mask: Mask of proposed modes
214 * 208 *
215 * Check the blacklist and disable UDMA5 if matched 209 * Check the blacklist and disable UDMA5 if matched
216 */ 210 */
217 211
218static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 212static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned long mask)
219{ 213{
220 const char *p; 214 const char *p;
221 char model_num[ATA_ID_PROD_LEN + 1]; 215 char model_num[ATA_ID_PROD_LEN + 1];
@@ -223,7 +217,7 @@ static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct at
223 217
224 /* Disk, UDMA */ 218 /* Disk, UDMA */
225 if (adev->class != ATA_DEV_ATA) 219 if (adev->class != ATA_DEV_ATA)
226 return ata_pci_default_filter(ap, adev, mask); 220 return ata_pci_default_filter(adev, mask);
227 221
228 /* Actually do need to check */ 222 /* Actually do need to check */
229 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 223 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
@@ -232,7 +226,7 @@ static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct at
232 if (!strcmp(p, model_num)) 226 if (!strcmp(p, model_num))
233 mask &= ~(0x1F << ATA_SHIFT_UDMA); 227 mask &= ~(0x1F << ATA_SHIFT_UDMA);
234 } 228 }
235 return ata_pci_default_filter(ap, adev, mask); 229 return ata_pci_default_filter(adev, mask);
236} 230}
237 231
238 232
@@ -339,8 +333,9 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
339 333
340 .freeze = ata_bmdma_freeze, 334 .freeze = ata_bmdma_freeze,
341 .thaw = ata_bmdma_thaw, 335 .thaw = ata_bmdma_thaw,
342 .error_handler = serverworks_error_handler, 336 .error_handler = ata_bmdma_error_handler,
343 .post_internal_cmd = ata_bmdma_post_internal_cmd, 337 .post_internal_cmd = ata_bmdma_post_internal_cmd,
338 .cable_detect = serverworks_cable_detect,
344 339
345 .bmdma_setup = ata_bmdma_setup, 340 .bmdma_setup = ata_bmdma_setup,
346 .bmdma_start = ata_bmdma_start, 341 .bmdma_start = ata_bmdma_start,
@@ -374,8 +369,9 @@ static struct ata_port_operations serverworks_csb_port_ops = {
374 369
375 .freeze = ata_bmdma_freeze, 370 .freeze = ata_bmdma_freeze,
376 .thaw = ata_bmdma_thaw, 371 .thaw = ata_bmdma_thaw,
377 .error_handler = serverworks_error_handler, 372 .error_handler = ata_bmdma_error_handler,
378 .post_internal_cmd = ata_bmdma_post_internal_cmd, 373 .post_internal_cmd = ata_bmdma_post_internal_cmd,
374 .cable_detect = serverworks_cable_detect,
379 375
380 .bmdma_setup = ata_bmdma_setup, 376 .bmdma_setup = ata_bmdma_setup,
381 .bmdma_start = ata_bmdma_start, 377 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index dab2889a556f..6770820cfca9 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_sil680" 35#define DRV_NAME "pata_sil680"
36#define DRV_VERSION "0.4.5" 36#define DRV_VERSION "0.4.6"
37 37
38/** 38/**
39 * sil680_selreg - return register base 39 * sil680_selreg - return register base
@@ -91,12 +91,6 @@ static int sil680_cable_detect(struct ata_port *ap) {
91 return ATA_CBL_PATA40; 91 return ATA_CBL_PATA40;
92} 92}
93 93
94static int sil680_pre_reset(struct ata_port *ap)
95{
96 ap->cbl = sil680_cable_detect(ap);
97 return ata_std_prereset(ap);
98}
99
100/** 94/**
101 * sil680_bus_reset - reset the SIL680 bus 95 * sil680_bus_reset - reset the SIL680 bus
102 * @ap: ATA port to reset 96 * @ap: ATA port to reset
@@ -119,7 +113,7 @@ static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes)
119 113
120static void sil680_error_handler(struct ata_port *ap) 114static void sil680_error_handler(struct ata_port *ap)
121{ 115{
122 ata_bmdma_drive_eh(ap, sil680_pre_reset, sil680_bus_reset, NULL, ata_std_postreset); 116 ata_bmdma_drive_eh(ap, ata_std_prereset, sil680_bus_reset, NULL, ata_std_postreset);
123} 117}
124 118
125/** 119/**
@@ -257,6 +251,7 @@ static struct ata_port_operations sil680_port_ops = {
257 .thaw = ata_bmdma_thaw, 251 .thaw = ata_bmdma_thaw,
258 .error_handler = sil680_error_handler, 252 .error_handler = sil680_error_handler,
259 .post_internal_cmd = ata_bmdma_post_internal_cmd, 253 .post_internal_cmd = ata_bmdma_post_internal_cmd,
254 .cable_detect = sil680_cable_detect,
260 255
261 .bmdma_setup = ata_bmdma_setup, 256 .bmdma_setup = ata_bmdma_setup,
262 .bmdma_start = ata_bmdma_start, 257 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 8dc3bc4f5863..a3fbcee6fb33 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -35,7 +35,7 @@
35#include "sis.h" 35#include "sis.h"
36 36
37#define DRV_NAME "pata_sis" 37#define DRV_NAME "pata_sis"
38#define DRV_VERSION "0.5.0" 38#define DRV_VERSION "0.5.1"
39 39
40struct sis_chipset { 40struct sis_chipset {
41 u16 device; /* PCI host ID */ 41 u16 device; /* PCI host ID */
@@ -86,106 +86,55 @@ static int sis_port_base(struct ata_device *adev)
86} 86}
87 87
88/** 88/**
89 * sis_133_pre_reset - check for 40/80 pin 89 * sis_133_cable_detect - check for 40/80 pin
90 * @ap: Port 90 * @ap: Port
91 * 91 *
92 * Perform cable detection for the later UDMA133 capable 92 * Perform cable detection for the later UDMA133 capable
93 * SiS chipset. 93 * SiS chipset.
94 */ 94 */
95 95
96static int sis_133_pre_reset(struct ata_port *ap) 96static int sis_133_cable_detect(struct ata_port *ap)
97{ 97{
98 static const struct pci_bits sis_enable_bits[] = {
99 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
100 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
101 };
102
103 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 98 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
104 u16 tmp; 99 u16 tmp;
105 100
106 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
107 return -ENOENT;
108
109 /* The top bit of this register is the cable detect bit */ 101 /* The top bit of this register is the cable detect bit */
110 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp); 102 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
111 if ((tmp & 0x8000) && !sis_short_ata40(pdev)) 103 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
112 ap->cbl = ATA_CBL_PATA40; 104 return ATA_CBL_PATA40;
113 else 105 return ATA_CBL_PATA80;
114 ap->cbl = ATA_CBL_PATA80;
115
116 return ata_std_prereset(ap);
117} 106}
118 107
119/** 108/**
120 * sis_error_handler - Probe specified port on PATA host controller 109 * sis_66_cable_detect - check for 40/80 pin
121 * @ap: Port to probe
122 *
123 * LOCKING:
124 * None (inherited from caller).
125 */
126
127static void sis_133_error_handler(struct ata_port *ap)
128{
129 ata_bmdma_drive_eh(ap, sis_133_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
130}
131
132
133/**
134 * sis_66_pre_reset - check for 40/80 pin
135 * @ap: Port 110 * @ap: Port
136 * 111 *
137 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133 112 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
138 * SiS IDE controllers. 113 * SiS IDE controllers.
139 */ 114 */
140 115
141static int sis_66_pre_reset(struct ata_port *ap) 116static int sis_66_cable_detect(struct ata_port *ap)
142{ 117{
143 static const struct pci_bits sis_enable_bits[] = {
144 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
145 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
146 };
147
148 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 118 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
149 u8 tmp; 119 u8 tmp;
150 120
151 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) {
152 ata_port_disable(ap);
153 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
154 return 0;
155 }
156 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */ 121 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
157 pci_read_config_byte(pdev, 0x48, &tmp); 122 pci_read_config_byte(pdev, 0x48, &tmp);
158 tmp >>= ap->port_no; 123 tmp >>= ap->port_no;
159 if ((tmp & 0x10) && !sis_short_ata40(pdev)) 124 if ((tmp & 0x10) && !sis_short_ata40(pdev))
160 ap->cbl = ATA_CBL_PATA40; 125 return ATA_CBL_PATA40;
161 else 126 return ATA_CBL_PATA80;
162 ap->cbl = ATA_CBL_PATA80;
163
164 return ata_std_prereset(ap);
165} 127}
166 128
167/**
168 * sis_66_error_handler - Probe specified port on PATA host controller
169 * @ap: Port to probe
170 * @classes:
171 *
172 * LOCKING:
173 * None (inherited from caller).
174 */
175
176static void sis_66_error_handler(struct ata_port *ap)
177{
178 ata_bmdma_drive_eh(ap, sis_66_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
179}
180 129
181/** 130/**
182 * sis_old_pre_reset - probe begin 131 * sis_pre_reset - probe begin
183 * @ap: ATA port 132 * @ap: ATA port
184 * 133 *
185 * Set up cable type and use generic probe init 134 * Set up cable type and use generic probe init
186 */ 135 */
187 136
188static int sis_old_pre_reset(struct ata_port *ap) 137static int sis_pre_reset(struct ata_port *ap)
189{ 138{
190 static const struct pci_bits sis_enable_bits[] = { 139 static const struct pci_bits sis_enable_bits[] = {
191 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */ 140 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
@@ -194,27 +143,23 @@ static int sis_old_pre_reset(struct ata_port *ap)
194 143
195 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 144 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
196 145
197 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) { 146 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
198 ata_port_disable(ap); 147 return -ENOENT;
199 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
200 return 0;
201 }
202 ap->cbl = ATA_CBL_PATA40;
203 return ata_std_prereset(ap); 148 return ata_std_prereset(ap);
204} 149}
205 150
206 151
207/** 152/**
208 * sis_old_error_handler - Probe specified port on PATA host controller 153 * sis_error_handler - Probe specified port on PATA host controller
209 * @ap: Port to probe 154 * @ap: Port to probe
210 * 155 *
211 * LOCKING: 156 * LOCKING:
212 * None (inherited from caller). 157 * None (inherited from caller).
213 */ 158 */
214 159
215static void sis_old_error_handler(struct ata_port *ap) 160static void sis_error_handler(struct ata_port *ap)
216{ 161{
217 ata_bmdma_drive_eh(ap, sis_old_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 162 ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
218} 163}
219 164
220/** 165/**
@@ -494,7 +439,7 @@ static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *a
494 int drive_pci = sis_port_base(adev); 439 int drive_pci = sis_port_base(adev);
495 u16 timing; 440 u16 timing;
496 441
497 const u16 udma_bits[] = { 0x8F00, 0x8A00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100}; 442 static const u16 udma_bits[] = { 0x8F00, 0x8A00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
498 443
499 pci_read_config_word(pdev, drive_pci, &timing); 444 pci_read_config_word(pdev, drive_pci, &timing);
500 445
@@ -531,8 +476,8 @@ static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
531 u32 reg54; 476 u32 reg54;
532 477
533 /* bits 4- cycle time 8 - cvs time */ 478 /* bits 4- cycle time 8 - cvs time */
534 const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 }; 479 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
535 const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 }; 480 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
536 481
537 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ 482 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
538 pci_read_config_dword(pdev, 0x54, &reg54); 483 pci_read_config_dword(pdev, 0x54, &reg54);
@@ -595,8 +540,9 @@ static const struct ata_port_operations sis_133_ops = {
595 540
596 .freeze = ata_bmdma_freeze, 541 .freeze = ata_bmdma_freeze,
597 .thaw = ata_bmdma_thaw, 542 .thaw = ata_bmdma_thaw,
598 .error_handler = sis_133_error_handler, 543 .error_handler = sis_error_handler,
599 .post_internal_cmd = ata_bmdma_post_internal_cmd, 544 .post_internal_cmd = ata_bmdma_post_internal_cmd,
545 .cable_detect = sis_133_cable_detect,
600 546
601 .bmdma_setup = ata_bmdma_setup, 547 .bmdma_setup = ata_bmdma_setup,
602 .bmdma_start = ata_bmdma_start, 548 .bmdma_start = ata_bmdma_start,
@@ -628,8 +574,9 @@ static const struct ata_port_operations sis_133_early_ops = {
628 574
629 .freeze = ata_bmdma_freeze, 575 .freeze = ata_bmdma_freeze,
630 .thaw = ata_bmdma_thaw, 576 .thaw = ata_bmdma_thaw,
631 .error_handler = sis_66_error_handler, 577 .error_handler = sis_error_handler,
632 .post_internal_cmd = ata_bmdma_post_internal_cmd, 578 .post_internal_cmd = ata_bmdma_post_internal_cmd,
579 .cable_detect = sis_66_cable_detect,
633 580
634 .bmdma_setup = ata_bmdma_setup, 581 .bmdma_setup = ata_bmdma_setup,
635 .bmdma_start = ata_bmdma_start, 582 .bmdma_start = ata_bmdma_start,
@@ -661,9 +608,9 @@ static const struct ata_port_operations sis_100_ops = {
661 608
662 .freeze = ata_bmdma_freeze, 609 .freeze = ata_bmdma_freeze,
663 .thaw = ata_bmdma_thaw, 610 .thaw = ata_bmdma_thaw,
664 .error_handler = sis_66_error_handler, 611 .error_handler = sis_error_handler,
665 .post_internal_cmd = ata_bmdma_post_internal_cmd, 612 .post_internal_cmd = ata_bmdma_post_internal_cmd,
666 613 .cable_detect = sis_66_cable_detect,
667 614
668 .bmdma_setup = ata_bmdma_setup, 615 .bmdma_setup = ata_bmdma_setup,
669 .bmdma_start = ata_bmdma_start, 616 .bmdma_start = ata_bmdma_start,
@@ -692,10 +639,11 @@ static const struct ata_port_operations sis_66_ops = {
692 .check_status = ata_check_status, 639 .check_status = ata_check_status,
693 .exec_command = ata_exec_command, 640 .exec_command = ata_exec_command,
694 .dev_select = ata_std_dev_select, 641 .dev_select = ata_std_dev_select,
642 .cable_detect = sis_66_cable_detect,
695 643
696 .freeze = ata_bmdma_freeze, 644 .freeze = ata_bmdma_freeze,
697 .thaw = ata_bmdma_thaw, 645 .thaw = ata_bmdma_thaw,
698 .error_handler = sis_66_error_handler, 646 .error_handler = sis_error_handler,
699 .post_internal_cmd = ata_bmdma_post_internal_cmd, 647 .post_internal_cmd = ata_bmdma_post_internal_cmd,
700 648
701 .bmdma_setup = ata_bmdma_setup, 649 .bmdma_setup = ata_bmdma_setup,
@@ -728,8 +676,9 @@ static const struct ata_port_operations sis_old_ops = {
728 676
729 .freeze = ata_bmdma_freeze, 677 .freeze = ata_bmdma_freeze,
730 .thaw = ata_bmdma_thaw, 678 .thaw = ata_bmdma_thaw,
731 .error_handler = sis_old_error_handler, 679 .error_handler = sis_error_handler,
732 .post_internal_cmd = ata_bmdma_post_internal_cmd, 680 .post_internal_cmd = ata_bmdma_post_internal_cmd,
681 .cable_detect = ata_cable_40wire,
733 682
734 .bmdma_setup = ata_bmdma_setup, 683 .bmdma_setup = ata_bmdma_setup,
735 .bmdma_start = ata_bmdma_start, 684 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index b681441cfcb9..da9e22b25753 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -58,7 +58,6 @@ static int sl82c105_pre_reset(struct ata_port *ap)
58 58
59 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no])) 59 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no]))
60 return -ENOENT; 60 return -ENOENT;
61 ap->cbl = ATA_CBL_PATA40;
62 return ata_std_prereset(ap); 61 return ata_std_prereset(ap);
63} 62}
64 63
@@ -238,6 +237,7 @@ static struct ata_port_operations sl82c105_port_ops = {
238 .thaw = ata_bmdma_thaw, 237 .thaw = ata_bmdma_thaw,
239 .error_handler = sl82c105_error_handler, 238 .error_handler = sl82c105_error_handler,
240 .post_internal_cmd = ata_bmdma_post_internal_cmd, 239 .post_internal_cmd = ata_bmdma_post_internal_cmd,
240 .cable_detect = ata_cable_40wire,
241 241
242 .bmdma_setup = ata_bmdma_setup, 242 .bmdma_setup = ata_bmdma_setup,
243 .bmdma_start = sl82c105_bmdma_start, 243 .bmdma_start = sl82c105_bmdma_start,
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index 71418f2a0cdb..e618ffd6e944 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -43,7 +43,7 @@
43#include <linux/libata.h> 43#include <linux/libata.h>
44 44
45#define DRV_NAME "pata_triflex" 45#define DRV_NAME "pata_triflex"
46#define DRV_VERSION "0.2.7" 46#define DRV_VERSION "0.2.8"
47 47
48/** 48/**
49 * triflex_prereset - probe begin 49 * triflex_prereset - probe begin
@@ -63,7 +63,6 @@ static int triflex_prereset(struct ata_port *ap)
63 63
64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) 64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 return -ENOENT; 65 return -ENOENT;
66 ap->cbl = ATA_CBL_PATA40;
67 return ata_std_prereset(ap); 66 return ata_std_prereset(ap);
68} 67}
69 68
@@ -214,6 +213,7 @@ static struct ata_port_operations triflex_port_ops = {
214 .thaw = ata_bmdma_thaw, 213 .thaw = ata_bmdma_thaw,
215 .error_handler = triflex_error_handler, 214 .error_handler = triflex_error_handler,
216 .post_internal_cmd = ata_bmdma_post_internal_cmd, 215 .post_internal_cmd = ata_bmdma_post_internal_cmd,
216 .cable_detect = ata_cable_40wire,
217 217
218 .bmdma_setup = ata_bmdma_setup, 218 .bmdma_setup = ata_bmdma_setup,
219 .bmdma_start = triflex_bmdma_start, 219 .bmdma_start = triflex_bmdma_start,
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 946ade0e1f1b..96b71791d2f4 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -62,7 +62,7 @@
62#include <linux/libata.h> 62#include <linux/libata.h>
63 63
64#define DRV_NAME "pata_via" 64#define DRV_NAME "pata_via"
65#define DRV_VERSION "0.2.1" 65#define DRV_VERSION "0.3.1"
66 66
67/* 67/*
68 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx 68 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
@@ -135,16 +135,23 @@ static const struct via_isa_bridge {
135 */ 135 */
136 136
137static int via_cable_detect(struct ata_port *ap) { 137static int via_cable_detect(struct ata_port *ap) {
138 const struct via_isa_bridge *config = ap->host->private_data;
138 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 139 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
139 u32 ata66; 140 u32 ata66;
140 141
142 /* Early chips are 40 wire */
143 if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
144 return ATA_CBL_PATA40;
145 /* UDMA 66 chips have only drive side logic */
146 else if((config->flags & VIA_UDMA) < VIA_UDMA_100)
147 return ATA_CBL_PATA_UNK;
148 /* UDMA 100 or later */
141 pci_read_config_dword(pdev, 0x50, &ata66); 149 pci_read_config_dword(pdev, 0x50, &ata66);
142 /* Check both the drive cable reporting bits, we might not have 150 /* Check both the drive cable reporting bits, we might not have
143 two drives */ 151 two drives */
144 if (ata66 & (0x10100000 >> (16 * ap->port_no))) 152 if (ata66 & (0x10100000 >> (16 * ap->port_no)))
145 return ATA_CBL_PATA80; 153 return ATA_CBL_PATA80;
146 else 154 return ATA_CBL_PATA40;
147 return ATA_CBL_PATA40;
148} 155}
149 156
150static int via_pre_reset(struct ata_port *ap) 157static int via_pre_reset(struct ata_port *ap)
@@ -156,22 +163,10 @@ static int via_pre_reset(struct ata_port *ap)
156 { 0x40, 1, 0x02, 0x02 }, 163 { 0x40, 1, 0x02, 0x02 },
157 { 0x40, 1, 0x01, 0x01 } 164 { 0x40, 1, 0x01, 0x01 }
158 }; 165 };
159
160 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 166 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
161
162 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no])) 167 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
163 return -ENOENT; 168 return -ENOENT;
164 } 169 }
165
166 if ((config->flags & VIA_UDMA) >= VIA_UDMA_100)
167 ap->cbl = via_cable_detect(ap);
168 /* The UDMA66 series has no cable detect so do drive side detect */
169 else if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
170 ap->cbl = ATA_CBL_PATA40;
171 else
172 ap->cbl = ATA_CBL_PATA_UNK;
173
174
175 return ata_std_prereset(ap); 170 return ata_std_prereset(ap);
176} 171}
177 172
@@ -327,6 +322,7 @@ static struct ata_port_operations via_port_ops = {
327 .thaw = ata_bmdma_thaw, 322 .thaw = ata_bmdma_thaw,
328 .error_handler = via_error_handler, 323 .error_handler = via_error_handler,
329 .post_internal_cmd = ata_bmdma_post_internal_cmd, 324 .post_internal_cmd = ata_bmdma_post_internal_cmd,
325 .cable_detect = via_cable_detect,
330 326
331 .bmdma_setup = ata_bmdma_setup, 327 .bmdma_setup = ata_bmdma_setup,
332 .bmdma_start = ata_bmdma_start, 328 .bmdma_start = ata_bmdma_start,
@@ -362,6 +358,7 @@ static struct ata_port_operations via_port_ops_noirq = {
362 .thaw = ata_bmdma_thaw, 358 .thaw = ata_bmdma_thaw,
363 .error_handler = via_error_handler, 359 .error_handler = via_error_handler,
364 .post_internal_cmd = ata_bmdma_post_internal_cmd, 360 .post_internal_cmd = ata_bmdma_post_internal_cmd,
361 .cable_detect = via_cable_detect,
365 362
366 .bmdma_setup = ata_bmdma_setup, 363 .bmdma_setup = ata_bmdma_setup,
367 .bmdma_start = ata_bmdma_start, 364 .bmdma_start = ata_bmdma_start,
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 6c111035fc84..cc4ad271afb5 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -8,7 +8,6 @@
8 8
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/pci.h>
12#include <linux/init.h> 11#include <linux/init.h>
13#include <linux/blkdev.h> 12#include <linux/blkdev.h>
14#include <linux/delay.h> 13#include <linux/delay.h>
@@ -36,7 +35,7 @@ static int probe_winbond = 1;
36static int probe_winbond; 35static int probe_winbond;
37#endif 36#endif
38 37
39static spinlock_t winbond_lock = SPIN_LOCK_UNLOCKED; 38static DEFINE_SPINLOCK(winbond_lock);
40 39
41static void winbond_writecfg(unsigned long port, u8 reg, u8 val) 40static void winbond_writecfg(unsigned long port, u8 reg, u8 val)
42{ 41{
@@ -152,13 +151,13 @@ static struct ata_port_operations winbond_port_ops = {
152 .thaw = ata_bmdma_thaw, 151 .thaw = ata_bmdma_thaw,
153 .error_handler = ata_bmdma_error_handler, 152 .error_handler = ata_bmdma_error_handler,
154 .post_internal_cmd = ata_bmdma_post_internal_cmd, 153 .post_internal_cmd = ata_bmdma_post_internal_cmd,
154 .cable_detect = ata_cable_40wire,
155 155
156 .qc_prep = ata_qc_prep, 156 .qc_prep = ata_qc_prep,
157 .qc_issue = ata_qc_issue_prot, 157 .qc_issue = ata_qc_issue_prot,
158 158
159 .data_xfer = winbond_data_xfer, 159 .data_xfer = winbond_data_xfer,
160 160
161 .irq_handler = ata_interrupt,
162 .irq_clear = ata_bmdma_irq_clear, 161 .irq_clear = ata_bmdma_irq_clear,
163 .irq_on = ata_irq_on, 162 .irq_on = ata_irq_on,
164 .irq_ack = ata_irq_ack, 163 .irq_ack = ata_irq_ack,
@@ -179,11 +178,9 @@ static struct ata_port_operations winbond_port_ops = {
179 178
180static __init int winbond_init_one(unsigned long port) 179static __init int winbond_init_one(unsigned long port)
181{ 180{
182 struct ata_probe_ent ae;
183 struct platform_device *pdev; 181 struct platform_device *pdev;
184 int ret;
185 u8 reg; 182 u8 reg;
186 int i; 183 int i, rc;
187 184
188 reg = winbond_readcfg(port, 0x81); 185 reg = winbond_readcfg(port, 0x81);
189 reg |= 0x80; /* jumpered mode off */ 186 reg |= 0x80; /* jumpered mode off */
@@ -202,58 +199,56 @@ static __init int winbond_init_one(unsigned long port)
202 199
203 for (i = 0; i < 2 ; i ++) { 200 for (i = 0; i < 2 ; i ++) {
204 unsigned long cmd_port = 0x1F0 - (0x80 * i); 201 unsigned long cmd_port = 0x1F0 - (0x80 * i);
202 struct ata_host *host;
203 struct ata_port *ap;
205 void __iomem *cmd_addr, *ctl_addr; 204 void __iomem *cmd_addr, *ctl_addr;
206 205
207 if (reg & (1 << i)) { 206 if (!(reg & (1 << i)))
208 /* 207 continue;
209 * Fill in a probe structure first of all 208
210 */ 209 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0);
211 210 if (IS_ERR(pdev))
212 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0); 211 return PTR_ERR(pdev);
213 if (IS_ERR(pdev)) 212
214 return PTR_ERR(pdev); 213 rc = -ENOMEM;
215 214 host = ata_host_alloc(&pdev->dev, 1);
216 cmd_addr = devm_ioport_map(&pdev->dev, cmd_port, 8); 215 if (!host)
217 ctl_addr = devm_ioport_map(&pdev->dev, cmd_port + 0x0206, 1); 216 goto err_unregister;
218 if (!cmd_addr || !ctl_addr) { 217
219 platform_device_unregister(pdev); 218 rc = -ENOMEM;
220 return -ENOMEM; 219 cmd_addr = devm_ioport_map(&pdev->dev, cmd_port, 8);
221 } 220 ctl_addr = devm_ioport_map(&pdev->dev, cmd_port + 0x0206, 1);
222 221 if (!cmd_addr || !ctl_addr)
223 memset(&ae, 0, sizeof(struct ata_probe_ent)); 222 goto err_unregister;
224 INIT_LIST_HEAD(&ae.node); 223
225 ae.dev = &pdev->dev; 224 ap = host->ports[0];
226 225 ap->ops = &winbond_port_ops;
227 ae.port_ops = &winbond_port_ops; 226 ap->pio_mask = 0x1F;
228 ae.pio_mask = 0x1F; 227 ap->flags |= ATA_FLAG_SLAVE_POSS;
229 228 ap->ioaddr.cmd_addr = cmd_addr;
230 ae.sht = &winbond_sht; 229 ap->ioaddr.altstatus_addr = ctl_addr;
231 230 ap->ioaddr.ctl_addr = ctl_addr;
232 ae.n_ports = 1; 231 ata_std_ports(&ap->ioaddr);
233 ae.irq = 14 + i; 232
234 ae.irq_flags = 0; 233 /* hook in a private data structure per channel */
235 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 234 host->private_data = &winbond_data[nr_winbond_host];
236 ae.port[0].cmd_addr = cmd_addr; 235 winbond_data[nr_winbond_host].config = port;
237 ae.port[0].altstatus_addr = ctl_addr; 236 winbond_data[nr_winbond_host].platform_dev = pdev;
238 ae.port[0].ctl_addr = ctl_addr; 237
239 ata_std_ports(&ae.port[0]); 238 /* activate */
240 /* 239 rc = ata_host_activate(host, 14 + i, ata_interrupt, 0,
241 * Hook in a private data structure per channel 240 &winbond_sht);
242 */ 241 if (rc)
243 ae.private_data = &winbond_data[nr_winbond_host]; 242 goto err_unregister;
244 winbond_data[nr_winbond_host].config = port; 243
245 winbond_data[nr_winbond_host].platform_dev = pdev; 244 winbond_host[nr_winbond_host++] = dev_get_drvdata(&pdev->dev);
246
247 ret = ata_device_add(&ae);
248 if (ret == 0) {
249 platform_device_unregister(pdev);
250 return -ENODEV;
251 }
252 winbond_host[nr_winbond_host++] = dev_get_drvdata(&pdev->dev);
253 }
254 } 245 }
255 246
256 return 0; 247 return 0;
248
249 err_unregister:
250 platform_device_unregister(pdev);
251 return rc;
257} 252}
258 253
259/** 254/**
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 5dd3ca8b5f29..52b69530ab29 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -52,9 +52,9 @@
52/* macro to calculate base address for ADMA regs */ 52/* macro to calculate base address for ADMA regs */
53#define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20)) 53#define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20))
54 54
55/* macro to obtain addresses from ata_host */ 55/* macro to obtain addresses from ata_port */
56#define ADMA_HOST_REGS(host,port_no) \ 56#define ADMA_PORT_REGS(ap) \
57 ADMA_REGS((host)->iomap[ADMA_MMIO_BAR], port_no) 57 ADMA_REGS((ap)->host->iomap[ADMA_MMIO_BAR], ap->port_no)
58 58
59enum { 59enum {
60 ADMA_MMIO_BAR = 4, 60 ADMA_MMIO_BAR = 4,
@@ -128,7 +128,6 @@ struct adma_port_priv {
128 128
129static int adma_ata_init_one (struct pci_dev *pdev, 129static int adma_ata_init_one (struct pci_dev *pdev,
130 const struct pci_device_id *ent); 130 const struct pci_device_id *ent);
131static irqreturn_t adma_intr (int irq, void *dev_instance);
132static int adma_port_start(struct ata_port *ap); 131static int adma_port_start(struct ata_port *ap);
133static void adma_host_stop(struct ata_host *host); 132static void adma_host_stop(struct ata_host *host);
134static void adma_port_stop(struct ata_port *ap); 133static void adma_port_stop(struct ata_port *ap);
@@ -172,7 +171,6 @@ static const struct ata_port_operations adma_ata_ops = {
172 .qc_issue = adma_qc_issue, 171 .qc_issue = adma_qc_issue,
173 .eng_timeout = adma_eng_timeout, 172 .eng_timeout = adma_eng_timeout,
174 .data_xfer = ata_data_xfer, 173 .data_xfer = ata_data_xfer,
175 .irq_handler = adma_intr,
176 .irq_clear = adma_irq_clear, 174 .irq_clear = adma_irq_clear,
177 .irq_on = ata_irq_on, 175 .irq_on = ata_irq_on,
178 .irq_ack = ata_irq_ack, 176 .irq_ack = ata_irq_ack,
@@ -186,7 +184,6 @@ static const struct ata_port_operations adma_ata_ops = {
186static struct ata_port_info adma_port_info[] = { 184static struct ata_port_info adma_port_info[] = {
187 /* board_1841_idx */ 185 /* board_1841_idx */
188 { 186 {
189 .sht = &adma_ata_sht,
190 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | 187 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
191 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO | 188 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
192 ATA_FLAG_PIO_POLLING, 189 ATA_FLAG_PIO_POLLING,
@@ -229,8 +226,10 @@ static void adma_irq_clear(struct ata_port *ap)
229 /* nothing */ 226 /* nothing */
230} 227}
231 228
232static void adma_reset_engine(void __iomem *chan) 229static void adma_reset_engine(struct ata_port *ap)
233{ 230{
231 void __iomem *chan = ADMA_PORT_REGS(ap);
232
234 /* reset ADMA to idle state */ 233 /* reset ADMA to idle state */
235 writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL); 234 writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL);
236 udelay(2); 235 udelay(2);
@@ -241,14 +240,14 @@ static void adma_reset_engine(void __iomem *chan)
241static void adma_reinit_engine(struct ata_port *ap) 240static void adma_reinit_engine(struct ata_port *ap)
242{ 241{
243 struct adma_port_priv *pp = ap->private_data; 242 struct adma_port_priv *pp = ap->private_data;
244 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no); 243 void __iomem *chan = ADMA_PORT_REGS(ap);
245 244
246 /* mask/clear ATA interrupts */ 245 /* mask/clear ATA interrupts */
247 writeb(ATA_NIEN, ap->ioaddr.ctl_addr); 246 writeb(ATA_NIEN, ap->ioaddr.ctl_addr);
248 ata_check_status(ap); 247 ata_check_status(ap);
249 248
250 /* reset the ADMA engine */ 249 /* reset the ADMA engine */
251 adma_reset_engine(chan); 250 adma_reset_engine(ap);
252 251
253 /* set in-FIFO threshold to 0x100 */ 252 /* set in-FIFO threshold to 0x100 */
254 writew(0x100, chan + ADMA_FIFO_IN); 253 writew(0x100, chan + ADMA_FIFO_IN);
@@ -268,7 +267,7 @@ static void adma_reinit_engine(struct ata_port *ap)
268 267
269static inline void adma_enter_reg_mode(struct ata_port *ap) 268static inline void adma_enter_reg_mode(struct ata_port *ap)
270{ 269{
271 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no); 270 void __iomem *chan = ADMA_PORT_REGS(ap);
272 271
273 writew(aPIOMD4, chan + ADMA_CONTROL); 272 writew(aPIOMD4, chan + ADMA_CONTROL);
274 readb(chan + ADMA_STATUS); /* flush */ 273 readb(chan + ADMA_STATUS); /* flush */
@@ -415,7 +414,7 @@ static void adma_qc_prep(struct ata_queued_cmd *qc)
415static inline void adma_packet_start(struct ata_queued_cmd *qc) 414static inline void adma_packet_start(struct ata_queued_cmd *qc)
416{ 415{
417 struct ata_port *ap = qc->ap; 416 struct ata_port *ap = qc->ap;
418 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no); 417 void __iomem *chan = ADMA_PORT_REGS(ap);
419 418
420 VPRINTK("ENTER, ap %p\n", ap); 419 VPRINTK("ENTER, ap %p\n", ap);
421 420
@@ -453,7 +452,7 @@ static inline unsigned int adma_intr_pkt(struct ata_host *host)
453 struct ata_port *ap = host->ports[port_no]; 452 struct ata_port *ap = host->ports[port_no];
454 struct adma_port_priv *pp; 453 struct adma_port_priv *pp;
455 struct ata_queued_cmd *qc; 454 struct ata_queued_cmd *qc;
456 void __iomem *chan = ADMA_HOST_REGS(host, port_no); 455 void __iomem *chan = ADMA_PORT_REGS(ap);
457 u8 status = readb(chan + ADMA_STATUS); 456 u8 status = readb(chan + ADMA_STATUS);
458 457
459 if (status == 0) 458 if (status == 0)
@@ -575,7 +574,7 @@ static int adma_port_start(struct ata_port *ap)
575 574
576static void adma_port_stop(struct ata_port *ap) 575static void adma_port_stop(struct ata_port *ap)
577{ 576{
578 adma_reset_engine(ADMA_HOST_REGS(ap->host, ap->port_no)); 577 adma_reset_engine(ap);
579} 578}
580 579
581static void adma_host_stop(struct ata_host *host) 580static void adma_host_stop(struct ata_host *host)
@@ -583,21 +582,19 @@ static void adma_host_stop(struct ata_host *host)
583 unsigned int port_no; 582 unsigned int port_no;
584 583
585 for (port_no = 0; port_no < ADMA_PORTS; ++port_no) 584 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
586 adma_reset_engine(ADMA_HOST_REGS(host, port_no)); 585 adma_reset_engine(host->ports[port_no]);
587} 586}
588 587
589static void adma_host_init(unsigned int chip_id, 588static void adma_host_init(struct ata_host *host, unsigned int chip_id)
590 struct ata_probe_ent *probe_ent)
591{ 589{
592 unsigned int port_no; 590 unsigned int port_no;
593 void __iomem *mmio_base = probe_ent->iomap[ADMA_MMIO_BAR];
594 591
595 /* enable/lock aGO operation */ 592 /* enable/lock aGO operation */
596 writeb(7, mmio_base + ADMA_MODE_LOCK); 593 writeb(7, host->iomap[ADMA_MMIO_BAR] + ADMA_MODE_LOCK);
597 594
598 /* reset the ADMA logic */ 595 /* reset the ADMA logic */
599 for (port_no = 0; port_no < ADMA_PORTS; ++port_no) 596 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
600 adma_reset_engine(ADMA_REGS(mmio_base, port_no)); 597 adma_reset_engine(host->ports[port_no]);
601} 598}
602 599
603static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base) 600static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
@@ -623,14 +620,21 @@ static int adma_ata_init_one(struct pci_dev *pdev,
623 const struct pci_device_id *ent) 620 const struct pci_device_id *ent)
624{ 621{
625 static int printed_version; 622 static int printed_version;
626 struct ata_probe_ent *probe_ent = NULL;
627 void __iomem *mmio_base;
628 unsigned int board_idx = (unsigned int) ent->driver_data; 623 unsigned int board_idx = (unsigned int) ent->driver_data;
624 const struct ata_port_info *ppi[] = { &adma_port_info[board_idx], NULL };
625 struct ata_host *host;
626 void __iomem *mmio_base;
629 int rc, port_no; 627 int rc, port_no;
630 628
631 if (!printed_version++) 629 if (!printed_version++)
632 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 630 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
633 631
632 /* alloc host */
633 host = ata_host_alloc_pinfo(&pdev->dev, ppi, ADMA_PORTS);
634 if (!host)
635 return -ENOMEM;
636
637 /* acquire resources and fill host */
634 rc = pcim_enable_device(pdev); 638 rc = pcim_enable_device(pdev);
635 if (rc) 639 if (rc)
636 return rc; 640 return rc;
@@ -641,46 +645,23 @@ static int adma_ata_init_one(struct pci_dev *pdev,
641 rc = pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME); 645 rc = pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME);
642 if (rc) 646 if (rc)
643 return rc; 647 return rc;
644 mmio_base = pcim_iomap_table(pdev)[ADMA_MMIO_BAR]; 648 host->iomap = pcim_iomap_table(pdev);
649 mmio_base = host->iomap[ADMA_MMIO_BAR];
645 650
646 rc = adma_set_dma_masks(pdev, mmio_base); 651 rc = adma_set_dma_masks(pdev, mmio_base);
647 if (rc) 652 if (rc)
648 return rc; 653 return rc;
649 654
650 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); 655 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
651 if (probe_ent == NULL) 656 adma_ata_setup_port(&host->ports[port_no]->ioaddr,
652 return -ENOMEM;
653
654 probe_ent->dev = pci_dev_to_dev(pdev);
655 INIT_LIST_HEAD(&probe_ent->node);
656
657 probe_ent->sht = adma_port_info[board_idx].sht;
658 probe_ent->port_flags = adma_port_info[board_idx].flags;
659 probe_ent->pio_mask = adma_port_info[board_idx].pio_mask;
660 probe_ent->mwdma_mask = adma_port_info[board_idx].mwdma_mask;
661 probe_ent->udma_mask = adma_port_info[board_idx].udma_mask;
662 probe_ent->port_ops = adma_port_info[board_idx].port_ops;
663
664 probe_ent->irq = pdev->irq;
665 probe_ent->irq_flags = IRQF_SHARED;
666 probe_ent->n_ports = ADMA_PORTS;
667 probe_ent->iomap = pcim_iomap_table(pdev);
668
669 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
670 adma_ata_setup_port(&probe_ent->port[port_no],
671 ADMA_ATA_REGS(mmio_base, port_no)); 657 ADMA_ATA_REGS(mmio_base, port_no));
672 }
673
674 pci_set_master(pdev);
675 658
676 /* initialize adapter */ 659 /* initialize adapter */
677 adma_host_init(board_idx, probe_ent); 660 adma_host_init(host, board_idx);
678 661
679 if (!ata_device_add(probe_ent)) 662 pci_set_master(pdev);
680 return -ENODEV; 663 return ata_host_activate(host, pdev->irq, adma_intr, IRQF_SHARED,
681 664 &adma_ata_sht);
682 devm_kfree(&pdev->dev, probe_ent);
683 return 0;
684} 665}
685 666
686static int __init adma_ata_init(void) 667static int __init adma_ata_init(void)
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index 1e21688bfcf2..f099a1d83a00 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -488,11 +488,11 @@ static void inic_error_handler(struct ata_port *ap)
488static void inic_post_internal_cmd(struct ata_queued_cmd *qc) 488static void inic_post_internal_cmd(struct ata_queued_cmd *qc)
489{ 489{
490 /* make DMA engine forget about the failed command */ 490 /* make DMA engine forget about the failed command */
491 if (qc->err_mask) 491 if (qc->flags & ATA_QCFLAG_FAILED)
492 inic_reset_port(inic_port_base(qc->ap)); 492 inic_reset_port(inic_port_base(qc->ap));
493} 493}
494 494
495static void inic_dev_config(struct ata_port *ap, struct ata_device *dev) 495static void inic_dev_config(struct ata_device *dev)
496{ 496{
497 /* inic can only handle upto LBA28 max sectors */ 497 /* inic can only handle upto LBA28 max sectors */
498 if (dev->max_sectors > ATA_MAX_SECTORS) 498 if (dev->max_sectors > ATA_MAX_SECTORS)
@@ -559,7 +559,6 @@ static struct ata_port_operations inic_port_ops = {
559 .bmdma_stop = inic_bmdma_stop, 559 .bmdma_stop = inic_bmdma_stop,
560 .bmdma_status = inic_bmdma_status, 560 .bmdma_status = inic_bmdma_status,
561 561
562 .irq_handler = inic_interrupt,
563 .irq_clear = inic_irq_clear, 562 .irq_clear = inic_irq_clear,
564 .irq_on = ata_irq_on, 563 .irq_on = ata_irq_on,
565 .irq_ack = ata_irq_ack, 564 .irq_ack = ata_irq_ack,
@@ -580,7 +579,6 @@ static struct ata_port_operations inic_port_ops = {
580}; 579};
581 580
582static struct ata_port_info inic_port_info = { 581static struct ata_port_info inic_port_info = {
583 .sht = &inic_sht,
584 /* For some reason, ATA_PROT_ATAPI is broken on this 582 /* For some reason, ATA_PROT_ATAPI is broken on this
585 * controller, and no, PIO_POLLING does't fix it. It somehow 583 * controller, and no, PIO_POLLING does't fix it. It somehow
586 * manages to report the wrong ireason and ignoring ireason 584 * manages to report the wrong ireason and ignoring ireason
@@ -642,7 +640,9 @@ static int inic_pci_device_resume(struct pci_dev *pdev)
642 void __iomem *mmio_base = host->iomap[MMIO_BAR]; 640 void __iomem *mmio_base = host->iomap[MMIO_BAR];
643 int rc; 641 int rc;
644 642
645 ata_pci_device_do_resume(pdev); 643 rc = ata_pci_device_do_resume(pdev);
644 if (rc)
645 return rc;
646 646
647 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { 647 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
648 rc = init_controller(mmio_base, hpriv->cached_hctl); 648 rc = init_controller(mmio_base, hpriv->cached_hctl);
@@ -659,8 +659,8 @@ static int inic_pci_device_resume(struct pci_dev *pdev)
659static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 659static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
660{ 660{
661 static int printed_version; 661 static int printed_version;
662 struct ata_port_info *pinfo = &inic_port_info; 662 const struct ata_port_info *ppi[] = { &inic_port_info, NULL };
663 struct ata_probe_ent *probe_ent; 663 struct ata_host *host;
664 struct inic_host_priv *hpriv; 664 struct inic_host_priv *hpriv;
665 void __iomem * const *iomap; 665 void __iomem * const *iomap;
666 int i, rc; 666 int i, rc;
@@ -668,6 +668,15 @@ static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
668 if (!printed_version++) 668 if (!printed_version++)
669 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 669 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
670 670
671 /* alloc host */
672 host = ata_host_alloc_pinfo(&pdev->dev, ppi, NR_PORTS);
673 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
674 if (!host || !hpriv)
675 return -ENOMEM;
676
677 host->private_data = hpriv;
678
679 /* acquire resources and fill host */
671 rc = pcim_enable_device(pdev); 680 rc = pcim_enable_device(pdev);
672 if (rc) 681 if (rc)
673 return rc; 682 return rc;
@@ -675,7 +684,22 @@ static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
675 rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME); 684 rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME);
676 if (rc) 685 if (rc)
677 return rc; 686 return rc;
678 iomap = pcim_iomap_table(pdev); 687 host->iomap = iomap = pcim_iomap_table(pdev);
688
689 for (i = 0; i < NR_PORTS; i++) {
690 struct ata_ioports *port = &host->ports[i]->ioaddr;
691 void __iomem *port_base = iomap[MMIO_BAR] + i * PORT_SIZE;
692
693 port->cmd_addr = iomap[2 * i];
694 port->altstatus_addr =
695 port->ctl_addr = (void __iomem *)
696 ((unsigned long)iomap[2 * i + 1] | ATA_PCI_CTL_OFS);
697 port->scr_addr = port_base + PORT_SCR;
698
699 ata_std_ports(port);
700 }
701
702 hpriv->cached_hctl = readw(iomap[MMIO_BAR] + HOST_CTL);
679 703
680 /* Set dma_mask. This devices doesn't support 64bit addressing. */ 704 /* Set dma_mask. This devices doesn't support 64bit addressing. */
681 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 705 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
@@ -692,43 +716,6 @@ static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
692 return rc; 716 return rc;
693 } 717 }
694 718
695 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
696 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
697 if (!probe_ent || !hpriv)
698 return -ENOMEM;
699
700 probe_ent->dev = &pdev->dev;
701 INIT_LIST_HEAD(&probe_ent->node);
702
703 probe_ent->sht = pinfo->sht;
704 probe_ent->port_flags = pinfo->flags;
705 probe_ent->pio_mask = pinfo->pio_mask;
706 probe_ent->mwdma_mask = pinfo->mwdma_mask;
707 probe_ent->udma_mask = pinfo->udma_mask;
708 probe_ent->port_ops = pinfo->port_ops;
709 probe_ent->n_ports = NR_PORTS;
710
711 probe_ent->irq = pdev->irq;
712 probe_ent->irq_flags = IRQF_SHARED;
713
714 probe_ent->iomap = iomap;
715
716 for (i = 0; i < NR_PORTS; i++) {
717 struct ata_ioports *port = &probe_ent->port[i];
718 void __iomem *port_base = iomap[MMIO_BAR] + i * PORT_SIZE;
719
720 port->cmd_addr = iomap[2 * i];
721 port->altstatus_addr =
722 port->ctl_addr = (void __iomem *)
723 ((unsigned long)iomap[2 * i + 1] | ATA_PCI_CTL_OFS);
724 port->scr_addr = port_base + PORT_SCR;
725
726 ata_std_ports(port);
727 }
728
729 probe_ent->private_data = hpriv;
730 hpriv->cached_hctl = readw(iomap[MMIO_BAR] + HOST_CTL);
731
732 rc = init_controller(iomap[MMIO_BAR], hpriv->cached_hctl); 719 rc = init_controller(iomap[MMIO_BAR], hpriv->cached_hctl);
733 if (rc) { 720 if (rc) {
734 dev_printk(KERN_ERR, &pdev->dev, 721 dev_printk(KERN_ERR, &pdev->dev,
@@ -737,13 +724,8 @@ static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
737 } 724 }
738 725
739 pci_set_master(pdev); 726 pci_set_master(pdev);
740 727 return ata_host_activate(host, pdev->irq, inic_interrupt, IRQF_SHARED,
741 if (!ata_device_add(probe_ent)) 728 &inic_sht);
742 return -ENODEV;
743
744 devm_kfree(&pdev->dev, probe_ent);
745
746 return 0;
747} 729}
748 730
749static const struct pci_device_id inic_pci_tbl[] = { 731static const struct pci_device_id inic_pci_tbl[] = {
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index a65ba636aaa8..cb9b9ac12b4c 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -253,10 +253,7 @@ enum {
253#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 253#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
254 254
255enum { 255enum {
256 /* Our DMA boundary is determined by an ePRD being unable to handle 256 MV_DMA_BOUNDARY = 0xffffffffU,
257 * anything larger than 64KB
258 */
259 MV_DMA_BOUNDARY = 0xffffU,
260 257
261 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 258 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
262 259
@@ -350,7 +347,6 @@ static void mv_port_stop(struct ata_port *ap);
350static void mv_qc_prep(struct ata_queued_cmd *qc); 347static void mv_qc_prep(struct ata_queued_cmd *qc);
351static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 348static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
352static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 349static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
353static irqreturn_t mv_interrupt(int irq, void *dev_instance);
354static void mv_eng_timeout(struct ata_port *ap); 350static void mv_eng_timeout(struct ata_port *ap);
355static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 351static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
356 352
@@ -384,10 +380,10 @@ static struct scsi_host_template mv_sht = {
384 .queuecommand = ata_scsi_queuecmd, 380 .queuecommand = ata_scsi_queuecmd,
385 .can_queue = MV_USE_Q_DEPTH, 381 .can_queue = MV_USE_Q_DEPTH,
386 .this_id = ATA_SHT_THIS_ID, 382 .this_id = ATA_SHT_THIS_ID,
387 .sg_tablesize = MV_MAX_SG_CT / 2, 383 .sg_tablesize = MV_MAX_SG_CT,
388 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 384 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
389 .emulated = ATA_SHT_EMULATED, 385 .emulated = ATA_SHT_EMULATED,
390 .use_clustering = ATA_SHT_USE_CLUSTERING, 386 .use_clustering = 1,
391 .proc_name = DRV_NAME, 387 .proc_name = DRV_NAME,
392 .dma_boundary = MV_DMA_BOUNDARY, 388 .dma_boundary = MV_DMA_BOUNDARY,
393 .slave_configure = ata_scsi_slave_config, 389 .slave_configure = ata_scsi_slave_config,
@@ -405,6 +401,7 @@ static const struct ata_port_operations mv5_ops = {
405 .dev_select = ata_std_dev_select, 401 .dev_select = ata_std_dev_select,
406 402
407 .phy_reset = mv_phy_reset, 403 .phy_reset = mv_phy_reset,
404 .cable_detect = ata_cable_sata,
408 405
409 .qc_prep = mv_qc_prep, 406 .qc_prep = mv_qc_prep,
410 .qc_issue = mv_qc_issue, 407 .qc_issue = mv_qc_issue,
@@ -412,7 +409,6 @@ static const struct ata_port_operations mv5_ops = {
412 409
413 .eng_timeout = mv_eng_timeout, 410 .eng_timeout = mv_eng_timeout,
414 411
415 .irq_handler = mv_interrupt,
416 .irq_clear = mv_irq_clear, 412 .irq_clear = mv_irq_clear,
417 .irq_on = ata_irq_on, 413 .irq_on = ata_irq_on,
418 .irq_ack = ata_irq_ack, 414 .irq_ack = ata_irq_ack,
@@ -434,6 +430,7 @@ static const struct ata_port_operations mv6_ops = {
434 .dev_select = ata_std_dev_select, 430 .dev_select = ata_std_dev_select,
435 431
436 .phy_reset = mv_phy_reset, 432 .phy_reset = mv_phy_reset,
433 .cable_detect = ata_cable_sata,
437 434
438 .qc_prep = mv_qc_prep, 435 .qc_prep = mv_qc_prep,
439 .qc_issue = mv_qc_issue, 436 .qc_issue = mv_qc_issue,
@@ -441,7 +438,6 @@ static const struct ata_port_operations mv6_ops = {
441 438
442 .eng_timeout = mv_eng_timeout, 439 .eng_timeout = mv_eng_timeout,
443 440
444 .irq_handler = mv_interrupt,
445 .irq_clear = mv_irq_clear, 441 .irq_clear = mv_irq_clear,
446 .irq_on = ata_irq_on, 442 .irq_on = ata_irq_on,
447 .irq_ack = ata_irq_ack, 443 .irq_ack = ata_irq_ack,
@@ -463,6 +459,7 @@ static const struct ata_port_operations mv_iie_ops = {
463 .dev_select = ata_std_dev_select, 459 .dev_select = ata_std_dev_select,
464 460
465 .phy_reset = mv_phy_reset, 461 .phy_reset = mv_phy_reset,
462 .cable_detect = ata_cable_sata,
466 463
467 .qc_prep = mv_qc_prep_iie, 464 .qc_prep = mv_qc_prep_iie,
468 .qc_issue = mv_qc_issue, 465 .qc_issue = mv_qc_issue,
@@ -470,7 +467,6 @@ static const struct ata_port_operations mv_iie_ops = {
470 467
471 .eng_timeout = mv_eng_timeout, 468 .eng_timeout = mv_eng_timeout,
472 469
473 .irq_handler = mv_interrupt,
474 .irq_clear = mv_irq_clear, 470 .irq_clear = mv_irq_clear,
475 .irq_on = ata_irq_on, 471 .irq_on = ata_irq_on,
476 .irq_ack = ata_irq_ack, 472 .irq_ack = ata_irq_ack,
@@ -484,35 +480,30 @@ static const struct ata_port_operations mv_iie_ops = {
484 480
485static const struct ata_port_info mv_port_info[] = { 481static const struct ata_port_info mv_port_info[] = {
486 { /* chip_504x */ 482 { /* chip_504x */
487 .sht = &mv_sht,
488 .flags = MV_COMMON_FLAGS, 483 .flags = MV_COMMON_FLAGS,
489 .pio_mask = 0x1f, /* pio0-4 */ 484 .pio_mask = 0x1f, /* pio0-4 */
490 .udma_mask = 0x7f, /* udma0-6 */ 485 .udma_mask = 0x7f, /* udma0-6 */
491 .port_ops = &mv5_ops, 486 .port_ops = &mv5_ops,
492 }, 487 },
493 { /* chip_508x */ 488 { /* chip_508x */
494 .sht = &mv_sht,
495 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 489 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
496 .pio_mask = 0x1f, /* pio0-4 */ 490 .pio_mask = 0x1f, /* pio0-4 */
497 .udma_mask = 0x7f, /* udma0-6 */ 491 .udma_mask = 0x7f, /* udma0-6 */
498 .port_ops = &mv5_ops, 492 .port_ops = &mv5_ops,
499 }, 493 },
500 { /* chip_5080 */ 494 { /* chip_5080 */
501 .sht = &mv_sht,
502 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 495 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
503 .pio_mask = 0x1f, /* pio0-4 */ 496 .pio_mask = 0x1f, /* pio0-4 */
504 .udma_mask = 0x7f, /* udma0-6 */ 497 .udma_mask = 0x7f, /* udma0-6 */
505 .port_ops = &mv5_ops, 498 .port_ops = &mv5_ops,
506 }, 499 },
507 { /* chip_604x */ 500 { /* chip_604x */
508 .sht = &mv_sht,
509 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 501 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
510 .pio_mask = 0x1f, /* pio0-4 */ 502 .pio_mask = 0x1f, /* pio0-4 */
511 .udma_mask = 0x7f, /* udma0-6 */ 503 .udma_mask = 0x7f, /* udma0-6 */
512 .port_ops = &mv6_ops, 504 .port_ops = &mv6_ops,
513 }, 505 },
514 { /* chip_608x */ 506 { /* chip_608x */
515 .sht = &mv_sht,
516 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | 507 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
517 MV_FLAG_DUAL_HC), 508 MV_FLAG_DUAL_HC),
518 .pio_mask = 0x1f, /* pio0-4 */ 509 .pio_mask = 0x1f, /* pio0-4 */
@@ -520,14 +511,12 @@ static const struct ata_port_info mv_port_info[] = {
520 .port_ops = &mv6_ops, 511 .port_ops = &mv6_ops,
521 }, 512 },
522 { /* chip_6042 */ 513 { /* chip_6042 */
523 .sht = &mv_sht,
524 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 514 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
525 .pio_mask = 0x1f, /* pio0-4 */ 515 .pio_mask = 0x1f, /* pio0-4 */
526 .udma_mask = 0x7f, /* udma0-6 */ 516 .udma_mask = 0x7f, /* udma0-6 */
527 .port_ops = &mv_iie_ops, 517 .port_ops = &mv_iie_ops,
528 }, 518 },
529 { /* chip_7042 */ 519 { /* chip_7042 */
530 .sht = &mv_sht,
531 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 520 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
532 .pio_mask = 0x1f, /* pio0-4 */ 521 .pio_mask = 0x1f, /* pio0-4 */
533 .udma_mask = 0x7f, /* udma0-6 */ 522 .udma_mask = 0x7f, /* udma0-6 */
@@ -551,6 +540,9 @@ static const struct pci_device_id mv_pci_tbl[] = {
551 540
552 { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 541 { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
553 542
543 /* add Marvell 7042 support */
544 { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 },
545
554 { } /* terminate list */ 546 { } /* terminate list */
555}; 547};
556 548
@@ -585,6 +577,39 @@ static const struct mv_hw_ops mv6xxx_ops = {
585static int msi; /* Use PCI msi; either zero (off, default) or non-zero */ 577static int msi; /* Use PCI msi; either zero (off, default) or non-zero */
586 578
587 579
580/* move to PCI layer or libata core? */
581static int pci_go_64(struct pci_dev *pdev)
582{
583 int rc;
584
585 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
586 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
587 if (rc) {
588 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
589 if (rc) {
590 dev_printk(KERN_ERR, &pdev->dev,
591 "64-bit DMA enable failed\n");
592 return rc;
593 }
594 }
595 } else {
596 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
597 if (rc) {
598 dev_printk(KERN_ERR, &pdev->dev,
599 "32-bit DMA enable failed\n");
600 return rc;
601 }
602 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
603 if (rc) {
604 dev_printk(KERN_ERR, &pdev->dev,
605 "32-bit consistent DMA enable failed\n");
606 return rc;
607 }
608 }
609
610 return rc;
611}
612
588/* 613/*
589 * Functions 614 * Functions
590 */ 615 */
@@ -798,20 +823,18 @@ static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
798{ 823{
799 unsigned int ofs = mv_scr_offset(sc_reg_in); 824 unsigned int ofs = mv_scr_offset(sc_reg_in);
800 825
801 if (0xffffffffU != ofs) { 826 if (0xffffffffU != ofs)
802 return readl(mv_ap_base(ap) + ofs); 827 return readl(mv_ap_base(ap) + ofs);
803 } else { 828 else
804 return (u32) ofs; 829 return (u32) ofs;
805 }
806} 830}
807 831
808static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 832static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
809{ 833{
810 unsigned int ofs = mv_scr_offset(sc_reg_in); 834 unsigned int ofs = mv_scr_offset(sc_reg_in);
811 835
812 if (0xffffffffU != ofs) { 836 if (0xffffffffU != ofs)
813 writelfl(val, mv_ap_base(ap) + ofs); 837 writelfl(val, mv_ap_base(ap) + ofs);
814 }
815} 838}
816 839
817static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) 840static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
@@ -959,38 +982,30 @@ static void mv_port_stop(struct ata_port *ap)
959 * LOCKING: 982 * LOCKING:
960 * Inherited from caller. 983 * Inherited from caller.
961 */ 984 */
962static void mv_fill_sg(struct ata_queued_cmd *qc) 985static unsigned int mv_fill_sg(struct ata_queued_cmd *qc)
963{ 986{
964 struct mv_port_priv *pp = qc->ap->private_data; 987 struct mv_port_priv *pp = qc->ap->private_data;
965 unsigned int i = 0; 988 unsigned int n_sg = 0;
966 struct scatterlist *sg; 989 struct scatterlist *sg;
990 struct mv_sg *mv_sg;
967 991
992 mv_sg = pp->sg_tbl;
968 ata_for_each_sg(sg, qc) { 993 ata_for_each_sg(sg, qc) {
969 dma_addr_t addr; 994 dma_addr_t addr = sg_dma_address(sg);
970 u32 sg_len, len, offset; 995 u32 sg_len = sg_dma_len(sg);
971
972 addr = sg_dma_address(sg);
973 sg_len = sg_dma_len(sg);
974
975 while (sg_len) {
976 offset = addr & MV_DMA_BOUNDARY;
977 len = sg_len;
978 if ((offset + sg_len) > 0x10000)
979 len = 0x10000 - offset;
980 996
981 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff); 997 mv_sg->addr = cpu_to_le32(addr & 0xffffffff);
982 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16); 998 mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
983 pp->sg_tbl[i].flags_size = cpu_to_le32(len & 0xffff); 999 mv_sg->flags_size = cpu_to_le32(sg_len & 0xffff);
984 1000
985 sg_len -= len; 1001 if (ata_sg_is_last(sg, qc))
986 addr += len; 1002 mv_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
987 1003
988 if (!sg_len && ata_sg_is_last(sg, qc)) 1004 mv_sg++;
989 pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 1005 n_sg++;
990
991 i++;
992 }
993 } 1006 }
1007
1008 return n_sg;
994} 1009}
995 1010
996static inline unsigned mv_inc_q_index(unsigned index) 1011static inline unsigned mv_inc_q_index(unsigned index)
@@ -1320,17 +1335,15 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1320 int shift, port, port0, hard_port, handled; 1335 int shift, port, port0, hard_port, handled;
1321 unsigned int err_mask; 1336 unsigned int err_mask;
1322 1337
1323 if (hc == 0) { 1338 if (hc == 0)
1324 port0 = 0; 1339 port0 = 0;
1325 } else { 1340 else
1326 port0 = MV_PORTS_PER_HC; 1341 port0 = MV_PORTS_PER_HC;
1327 }
1328 1342
1329 /* we'll need the HC success int register in most cases */ 1343 /* we'll need the HC success int register in most cases */
1330 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1344 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1331 if (hc_irq_cause) { 1345 if (hc_irq_cause)
1332 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1346 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
1333 }
1334 1347
1335 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1348 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1336 hc,relevant,hc_irq_cause); 1349 hc,relevant,hc_irq_cause);
@@ -1425,9 +1438,8 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
1425 /* check the cases where we either have nothing pending or have read 1438 /* check the cases where we either have nothing pending or have read
1426 * a bogus register value which can indicate HW removal or PCI fault 1439 * a bogus register value which can indicate HW removal or PCI fault
1427 */ 1440 */
1428 if (!irq_stat || (0xffffffffU == irq_stat)) { 1441 if (!irq_stat || (0xffffffffU == irq_stat))
1429 return IRQ_NONE; 1442 return IRQ_NONE;
1430 }
1431 1443
1432 n_hcs = mv_get_hc_count(host->ports[0]->flags); 1444 n_hcs = mv_get_hc_count(host->ports[0]->flags);
1433 spin_lock(&host->lock); 1445 spin_lock(&host->lock);
@@ -1952,7 +1964,6 @@ comreset_retry:
1952 ata_port_disable(ap); 1964 ata_port_disable(ap);
1953 return; 1965 return;
1954 } 1966 }
1955 ap->cbl = ATA_CBL_SATA;
1956 1967
1957 /* even after SStatus reflects that device is ready, 1968 /* even after SStatus reflects that device is ready,
1958 * it seems to take a while for link to be fully 1969 * it seems to take a while for link to be fully
@@ -2077,9 +2088,10 @@ static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
2077 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); 2088 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
2078} 2089}
2079 2090
2080static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv, 2091static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2081 unsigned int board_idx)
2082{ 2092{
2093 struct pci_dev *pdev = to_pci_dev(host->dev);
2094 struct mv_host_priv *hpriv = host->private_data;
2083 u8 rev_id; 2095 u8 rev_id;
2084 u32 hp_flags = hpriv->hp_flags; 2096 u32 hp_flags = hpriv->hp_flags;
2085 2097
@@ -2177,8 +2189,8 @@ static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
2177 2189
2178/** 2190/**
2179 * mv_init_host - Perform some early initialization of the host. 2191 * mv_init_host - Perform some early initialization of the host.
2180 * @pdev: host PCI device 2192 * @host: ATA host to initialize
2181 * @probe_ent: early data struct representing the host 2193 * @board_idx: controller index
2182 * 2194 *
2183 * If possible, do an early global reset of the host. Then do 2195 * If possible, do an early global reset of the host. Then do
2184 * our port init and clear/unmask all/relevant host interrupts. 2196 * our port init and clear/unmask all/relevant host interrupts.
@@ -2186,24 +2198,23 @@ static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
2186 * LOCKING: 2198 * LOCKING:
2187 * Inherited from caller. 2199 * Inherited from caller.
2188 */ 2200 */
2189static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent, 2201static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2190 unsigned int board_idx)
2191{ 2202{
2192 int rc = 0, n_hc, port, hc; 2203 int rc = 0, n_hc, port, hc;
2193 void __iomem *mmio = probe_ent->iomap[MV_PRIMARY_BAR]; 2204 struct pci_dev *pdev = to_pci_dev(host->dev);
2194 struct mv_host_priv *hpriv = probe_ent->private_data; 2205 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
2206 struct mv_host_priv *hpriv = host->private_data;
2195 2207
2196 /* global interrupt mask */ 2208 /* global interrupt mask */
2197 writel(0, mmio + HC_MAIN_IRQ_MASK_OFS); 2209 writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
2198 2210
2199 rc = mv_chip_id(pdev, hpriv, board_idx); 2211 rc = mv_chip_id(host, board_idx);
2200 if (rc) 2212 if (rc)
2201 goto done; 2213 goto done;
2202 2214
2203 n_hc = mv_get_hc_count(probe_ent->port_flags); 2215 n_hc = mv_get_hc_count(host->ports[0]->flags);
2204 probe_ent->n_ports = MV_PORTS_PER_HC * n_hc;
2205 2216
2206 for (port = 0; port < probe_ent->n_ports; port++) 2217 for (port = 0; port < host->n_ports; port++)
2207 hpriv->ops->read_preamp(hpriv, port, mmio); 2218 hpriv->ops->read_preamp(hpriv, port, mmio);
2208 2219
2209 rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 2220 rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
@@ -2214,7 +2225,7 @@ static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
2214 hpriv->ops->reset_bus(pdev, mmio); 2225 hpriv->ops->reset_bus(pdev, mmio);
2215 hpriv->ops->enable_leds(hpriv, mmio); 2226 hpriv->ops->enable_leds(hpriv, mmio);
2216 2227
2217 for (port = 0; port < probe_ent->n_ports; port++) { 2228 for (port = 0; port < host->n_ports; port++) {
2218 if (IS_60XX(hpriv)) { 2229 if (IS_60XX(hpriv)) {
2219 void __iomem *port_mmio = mv_port_base(mmio, port); 2230 void __iomem *port_mmio = mv_port_base(mmio, port);
2220 2231
@@ -2227,9 +2238,9 @@ static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
2227 hpriv->ops->phy_errata(hpriv, mmio, port); 2238 hpriv->ops->phy_errata(hpriv, mmio, port);
2228 } 2239 }
2229 2240
2230 for (port = 0; port < probe_ent->n_ports; port++) { 2241 for (port = 0; port < host->n_ports; port++) {
2231 void __iomem *port_mmio = mv_port_base(mmio, port); 2242 void __iomem *port_mmio = mv_port_base(mmio, port);
2232 mv_port_init(&probe_ent->port[port], port_mmio); 2243 mv_port_init(&host->ports[port]->ioaddr, port_mmio);
2233 } 2244 }
2234 2245
2235 for (hc = 0; hc < n_hc; hc++) { 2246 for (hc = 0; hc < n_hc; hc++) {
@@ -2268,17 +2279,17 @@ done:
2268 2279
2269/** 2280/**
2270 * mv_print_info - Dump key info to kernel log for perusal. 2281 * mv_print_info - Dump key info to kernel log for perusal.
2271 * @probe_ent: early data struct representing the host 2282 * @host: ATA host to print info about
2272 * 2283 *
2273 * FIXME: complete this. 2284 * FIXME: complete this.
2274 * 2285 *
2275 * LOCKING: 2286 * LOCKING:
2276 * Inherited from caller. 2287 * Inherited from caller.
2277 */ 2288 */
2278static void mv_print_info(struct ata_probe_ent *probe_ent) 2289static void mv_print_info(struct ata_host *host)
2279{ 2290{
2280 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 2291 struct pci_dev *pdev = to_pci_dev(host->dev);
2281 struct mv_host_priv *hpriv = probe_ent->private_data; 2292 struct mv_host_priv *hpriv = host->private_data;
2282 u8 rev_id, scc; 2293 u8 rev_id, scc;
2283 const char *scc_s; 2294 const char *scc_s;
2284 2295
@@ -2297,7 +2308,7 @@ static void mv_print_info(struct ata_probe_ent *probe_ent)
2297 2308
2298 dev_printk(KERN_INFO, &pdev->dev, 2309 dev_printk(KERN_INFO, &pdev->dev,
2299 "%u slots %u ports %s mode IRQ via %s\n", 2310 "%u slots %u ports %s mode IRQ via %s\n",
2300 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, 2311 (unsigned)MV_MAX_Q_DEPTH, host->n_ports,
2301 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 2312 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
2302} 2313}
2303 2314
@@ -2312,50 +2323,42 @@ static void mv_print_info(struct ata_probe_ent *probe_ent)
2312static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 2323static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2313{ 2324{
2314 static int printed_version = 0; 2325 static int printed_version = 0;
2315 struct device *dev = &pdev->dev;
2316 struct ata_probe_ent *probe_ent;
2317 struct mv_host_priv *hpriv;
2318 unsigned int board_idx = (unsigned int)ent->driver_data; 2326 unsigned int board_idx = (unsigned int)ent->driver_data;
2319 int rc; 2327 const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL };
2328 struct ata_host *host;
2329 struct mv_host_priv *hpriv;
2330 int n_ports, rc;
2320 2331
2321 if (!printed_version++) 2332 if (!printed_version++)
2322 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2333 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
2323 2334
2335 /* allocate host */
2336 n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC;
2337
2338 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
2339 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
2340 if (!host || !hpriv)
2341 return -ENOMEM;
2342 host->private_data = hpriv;
2343
2344 /* acquire resources */
2324 rc = pcim_enable_device(pdev); 2345 rc = pcim_enable_device(pdev);
2325 if (rc) 2346 if (rc)
2326 return rc; 2347 return rc;
2327 pci_set_master(pdev);
2328 2348
2329 rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 2349 rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME);
2330 if (rc == -EBUSY) 2350 if (rc == -EBUSY)
2331 pcim_pin_device(pdev); 2351 pcim_pin_device(pdev);
2332 if (rc) 2352 if (rc)
2333 return rc; 2353 return rc;
2354 host->iomap = pcim_iomap_table(pdev);
2334 2355
2335 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL); 2356 rc = pci_go_64(pdev);
2336 if (probe_ent == NULL) 2357 if (rc)
2337 return -ENOMEM; 2358 return rc;
2338
2339 probe_ent->dev = pci_dev_to_dev(pdev);
2340 INIT_LIST_HEAD(&probe_ent->node);
2341
2342 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
2343 if (!hpriv)
2344 return -ENOMEM;
2345
2346 probe_ent->sht = mv_port_info[board_idx].sht;
2347 probe_ent->port_flags = mv_port_info[board_idx].flags;
2348 probe_ent->pio_mask = mv_port_info[board_idx].pio_mask;
2349 probe_ent->udma_mask = mv_port_info[board_idx].udma_mask;
2350 probe_ent->port_ops = mv_port_info[board_idx].port_ops;
2351
2352 probe_ent->irq = pdev->irq;
2353 probe_ent->irq_flags = IRQF_SHARED;
2354 probe_ent->iomap = pcim_iomap_table(pdev);
2355 probe_ent->private_data = hpriv;
2356 2359
2357 /* initialize adapter */ 2360 /* initialize adapter */
2358 rc = mv_init_host(pdev, probe_ent, board_idx); 2361 rc = mv_init_host(host, board_idx);
2359 if (rc) 2362 if (rc)
2360 return rc; 2363 return rc;
2361 2364
@@ -2364,13 +2367,11 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2364 pci_intx(pdev, 1); 2367 pci_intx(pdev, 1);
2365 2368
2366 mv_dump_pci_cfg(pdev, 0x68); 2369 mv_dump_pci_cfg(pdev, 0x68);
2367 mv_print_info(probe_ent); 2370 mv_print_info(host);
2368 2371
2369 if (ata_device_add(probe_ent) == 0) 2372 pci_set_master(pdev);
2370 return -ENODEV; 2373 return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED,
2371 2374 &mv_sht);
2372 devm_kfree(dev, probe_ent);
2373 return 0;
2374} 2375}
2375 2376
2376static int __init mv_init(void) 2377static int __init mv_init(void)
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 9d9670a9b117..02169740ed24 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -260,6 +260,7 @@ static int nv_adma_port_resume(struct ata_port *ap);
260static void nv_adma_error_handler(struct ata_port *ap); 260static void nv_adma_error_handler(struct ata_port *ap);
261static void nv_adma_host_stop(struct ata_host *host); 261static void nv_adma_host_stop(struct ata_host *host);
262static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc); 262static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc);
263static void nv_adma_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
263 264
264enum nv_host_type 265enum nv_host_type
265{ 266{
@@ -368,7 +369,6 @@ static const struct ata_port_operations nv_generic_ops = {
368 .error_handler = nv_error_handler, 369 .error_handler = nv_error_handler,
369 .post_internal_cmd = ata_bmdma_post_internal_cmd, 370 .post_internal_cmd = ata_bmdma_post_internal_cmd,
370 .data_xfer = ata_data_xfer, 371 .data_xfer = ata_data_xfer,
371 .irq_handler = nv_generic_interrupt,
372 .irq_clear = ata_bmdma_irq_clear, 372 .irq_clear = ata_bmdma_irq_clear,
373 .irq_on = ata_irq_on, 373 .irq_on = ata_irq_on,
374 .irq_ack = ata_irq_ack, 374 .irq_ack = ata_irq_ack,
@@ -395,7 +395,6 @@ static const struct ata_port_operations nv_nf2_ops = {
395 .error_handler = nv_error_handler, 395 .error_handler = nv_error_handler,
396 .post_internal_cmd = ata_bmdma_post_internal_cmd, 396 .post_internal_cmd = ata_bmdma_post_internal_cmd,
397 .data_xfer = ata_data_xfer, 397 .data_xfer = ata_data_xfer,
398 .irq_handler = nv_nf2_interrupt,
399 .irq_clear = ata_bmdma_irq_clear, 398 .irq_clear = ata_bmdma_irq_clear,
400 .irq_on = ata_irq_on, 399 .irq_on = ata_irq_on,
401 .irq_ack = ata_irq_ack, 400 .irq_ack = ata_irq_ack,
@@ -422,7 +421,6 @@ static const struct ata_port_operations nv_ck804_ops = {
422 .error_handler = nv_error_handler, 421 .error_handler = nv_error_handler,
423 .post_internal_cmd = ata_bmdma_post_internal_cmd, 422 .post_internal_cmd = ata_bmdma_post_internal_cmd,
424 .data_xfer = ata_data_xfer, 423 .data_xfer = ata_data_xfer,
425 .irq_handler = nv_ck804_interrupt,
426 .irq_clear = ata_bmdma_irq_clear, 424 .irq_clear = ata_bmdma_irq_clear,
427 .irq_on = ata_irq_on, 425 .irq_on = ata_irq_on,
428 .irq_ack = ata_irq_ack, 426 .irq_ack = ata_irq_ack,
@@ -435,7 +433,7 @@ static const struct ata_port_operations nv_ck804_ops = {
435static const struct ata_port_operations nv_adma_ops = { 433static const struct ata_port_operations nv_adma_ops = {
436 .port_disable = ata_port_disable, 434 .port_disable = ata_port_disable,
437 .tf_load = ata_tf_load, 435 .tf_load = ata_tf_load,
438 .tf_read = ata_tf_read, 436 .tf_read = nv_adma_tf_read,
439 .check_atapi_dma = nv_adma_check_atapi_dma, 437 .check_atapi_dma = nv_adma_check_atapi_dma,
440 .exec_command = ata_exec_command, 438 .exec_command = ata_exec_command,
441 .check_status = ata_check_status, 439 .check_status = ata_check_status,
@@ -451,7 +449,6 @@ static const struct ata_port_operations nv_adma_ops = {
451 .error_handler = nv_adma_error_handler, 449 .error_handler = nv_adma_error_handler,
452 .post_internal_cmd = nv_adma_post_internal_cmd, 450 .post_internal_cmd = nv_adma_post_internal_cmd,
453 .data_xfer = ata_data_xfer, 451 .data_xfer = ata_data_xfer,
454 .irq_handler = nv_adma_interrupt,
455 .irq_clear = nv_adma_irq_clear, 452 .irq_clear = nv_adma_irq_clear,
456 .irq_on = ata_irq_on, 453 .irq_on = ata_irq_on,
457 .irq_ack = ata_irq_ack, 454 .irq_ack = ata_irq_ack,
@@ -476,6 +473,7 @@ static struct ata_port_info nv_port_info[] = {
476 .mwdma_mask = NV_MWDMA_MASK, 473 .mwdma_mask = NV_MWDMA_MASK,
477 .udma_mask = NV_UDMA_MASK, 474 .udma_mask = NV_UDMA_MASK,
478 .port_ops = &nv_generic_ops, 475 .port_ops = &nv_generic_ops,
476 .irq_handler = nv_generic_interrupt,
479 }, 477 },
480 /* nforce2/3 */ 478 /* nforce2/3 */
481 { 479 {
@@ -486,6 +484,7 @@ static struct ata_port_info nv_port_info[] = {
486 .mwdma_mask = NV_MWDMA_MASK, 484 .mwdma_mask = NV_MWDMA_MASK,
487 .udma_mask = NV_UDMA_MASK, 485 .udma_mask = NV_UDMA_MASK,
488 .port_ops = &nv_nf2_ops, 486 .port_ops = &nv_nf2_ops,
487 .irq_handler = nv_nf2_interrupt,
489 }, 488 },
490 /* ck804 */ 489 /* ck804 */
491 { 490 {
@@ -496,6 +495,7 @@ static struct ata_port_info nv_port_info[] = {
496 .mwdma_mask = NV_MWDMA_MASK, 495 .mwdma_mask = NV_MWDMA_MASK,
497 .udma_mask = NV_UDMA_MASK, 496 .udma_mask = NV_UDMA_MASK,
498 .port_ops = &nv_ck804_ops, 497 .port_ops = &nv_ck804_ops,
498 .irq_handler = nv_ck804_interrupt,
499 }, 499 },
500 /* ADMA */ 500 /* ADMA */
501 { 501 {
@@ -507,6 +507,7 @@ static struct ata_port_info nv_port_info[] = {
507 .mwdma_mask = NV_MWDMA_MASK, 507 .mwdma_mask = NV_MWDMA_MASK,
508 .udma_mask = NV_UDMA_MASK, 508 .udma_mask = NV_UDMA_MASK,
509 .port_ops = &nv_adma_ops, 509 .port_ops = &nv_adma_ops,
510 .irq_handler = nv_adma_interrupt,
510 }, 511 },
511}; 512};
512 513
@@ -667,6 +668,18 @@ static int nv_adma_check_atapi_dma(struct ata_queued_cmd *qc)
667 return !(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE); 668 return !(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE);
668} 669}
669 670
671static void nv_adma_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
672{
673 /* Since commands where a result TF is requested are not
674 executed in ADMA mode, the only time this function will be called
675 in ADMA mode will be if a command fails. In this case we
676 don't care about going into register mode with ADMA commands
677 pending, as the commands will all shortly be aborted anyway. */
678 nv_adma_register_mode(ap);
679
680 ata_tf_read(ap, tf);
681}
682
670static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb) 683static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb)
671{ 684{
672 unsigned int idx = 0; 685 unsigned int idx = 0;
@@ -738,19 +751,11 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
738 return 1; 751 return 1;
739 } 752 }
740 753
741 if (flags & NV_CPB_RESP_DONE) { 754 if (likely(flags & NV_CPB_RESP_DONE)) {
742 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num); 755 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num);
743 VPRINTK("CPB flags done, flags=0x%x\n", flags); 756 VPRINTK("CPB flags done, flags=0x%x\n", flags);
744 if (likely(qc)) { 757 if (likely(qc)) {
745 /* Grab the ATA port status for non-NCQ commands. 758 DPRINTK("Completing qc from tag %d\n",cpb_num);
746 For NCQ commands the current status may have nothing to do with
747 the command just completed. */
748 if (qc->tf.protocol != ATA_PROT_NCQ) {
749 u8 ata_status = readb(pp->ctl_block + (ATA_REG_STATUS * 4));
750 qc->err_mask |= ac_err_mask(ata_status);
751 }
752 DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num,
753 qc->err_mask);
754 ata_qc_complete(qc); 759 ata_qc_complete(qc);
755 } else { 760 } else {
756 struct ata_eh_info *ehi = &ap->eh_info; 761 struct ata_eh_info *ehi = &ap->eh_info;
@@ -1074,14 +1079,14 @@ static int nv_adma_port_resume(struct ata_port *ap)
1074} 1079}
1075#endif 1080#endif
1076 1081
1077static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port) 1082static void nv_adma_setup_port(struct ata_port *ap)
1078{ 1083{
1079 void __iomem *mmio = probe_ent->iomap[NV_MMIO_BAR]; 1084 void __iomem *mmio = ap->host->iomap[NV_MMIO_BAR];
1080 struct ata_ioports *ioport = &probe_ent->port[port]; 1085 struct ata_ioports *ioport = &ap->ioaddr;
1081 1086
1082 VPRINTK("ENTER\n"); 1087 VPRINTK("ENTER\n");
1083 1088
1084 mmio += NV_ADMA_PORT + port * NV_ADMA_PORT_SIZE; 1089 mmio += NV_ADMA_PORT + ap->port_no * NV_ADMA_PORT_SIZE;
1085 1090
1086 ioport->cmd_addr = mmio; 1091 ioport->cmd_addr = mmio;
1087 ioport->data_addr = mmio + (ATA_REG_DATA * 4); 1092 ioport->data_addr = mmio + (ATA_REG_DATA * 4);
@@ -1098,9 +1103,9 @@ static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int por
1098 ioport->ctl_addr = mmio + 0x20; 1103 ioport->ctl_addr = mmio + 0x20;
1099} 1104}
1100 1105
1101static int nv_adma_host_init(struct ata_probe_ent *probe_ent) 1106static int nv_adma_host_init(struct ata_host *host)
1102{ 1107{
1103 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1108 struct pci_dev *pdev = to_pci_dev(host->dev);
1104 unsigned int i; 1109 unsigned int i;
1105 u32 tmp32; 1110 u32 tmp32;
1106 1111
@@ -1115,8 +1120,8 @@ static int nv_adma_host_init(struct ata_probe_ent *probe_ent)
1115 1120
1116 pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, tmp32); 1121 pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, tmp32);
1117 1122
1118 for (i = 0; i < probe_ent->n_ports; i++) 1123 for (i = 0; i < host->n_ports; i++)
1119 nv_adma_setup_port(probe_ent, i); 1124 nv_adma_setup_port(host->ports[i]);
1120 1125
1121 return 0; 1126 return 0;
1122} 1127}
@@ -1167,9 +1172,11 @@ static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc)
1167 struct nv_adma_port_priv *pp = qc->ap->private_data; 1172 struct nv_adma_port_priv *pp = qc->ap->private_data;
1168 1173
1169 /* ADMA engine can only be used for non-ATAPI DMA commands, 1174 /* ADMA engine can only be used for non-ATAPI DMA commands,
1170 or interrupt-driven no-data commands. */ 1175 or interrupt-driven no-data commands, where a result taskfile
1176 is not required. */
1171 if((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) || 1177 if((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) ||
1172 (qc->tf.flags & ATA_TFLAG_POLLING)) 1178 (qc->tf.flags & ATA_TFLAG_POLLING) ||
1179 (qc->flags & ATA_QCFLAG_RESULT_TF))
1173 return 1; 1180 return 1;
1174 1181
1175 if((qc->flags & ATA_QCFLAG_DMAMAP) || 1182 if((qc->flags & ATA_QCFLAG_DMAMAP) ||
@@ -1473,14 +1480,13 @@ static void nv_adma_error_handler(struct ata_port *ap)
1473static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1480static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1474{ 1481{
1475 static int printed_version = 0; 1482 static int printed_version = 0;
1476 struct ata_port_info *ppi[2]; 1483 const struct ata_port_info *ppi[2];
1477 struct ata_probe_ent *probe_ent; 1484 struct ata_host *host;
1478 struct nv_host_priv *hpriv; 1485 struct nv_host_priv *hpriv;
1479 int rc; 1486 int rc;
1480 u32 bar; 1487 u32 bar;
1481 void __iomem *base; 1488 void __iomem *base;
1482 unsigned long type = ent->driver_data; 1489 unsigned long type = ent->driver_data;
1483 int mask_set = 0;
1484 1490
1485 // Make sure this is a SATA controller by counting the number of bars 1491 // Make sure this is a SATA controller by counting the number of bars
1486 // (NVIDIA SATA controllers will always have six bars). Otherwise, 1492 // (NVIDIA SATA controllers will always have six bars). Otherwise,
@@ -1496,50 +1502,38 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1496 if (rc) 1502 if (rc)
1497 return rc; 1503 return rc;
1498 1504
1499 rc = pci_request_regions(pdev, DRV_NAME); 1505 /* determine type and allocate host */
1500 if (rc) { 1506 if (type >= CK804 && adma_enabled) {
1501 pcim_pin_device(pdev);
1502 return rc;
1503 }
1504
1505 if(type >= CK804 && adma_enabled) {
1506 dev_printk(KERN_NOTICE, &pdev->dev, "Using ADMA mode\n"); 1507 dev_printk(KERN_NOTICE, &pdev->dev, "Using ADMA mode\n");
1507 type = ADMA; 1508 type = ADMA;
1508 if(!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
1509 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
1510 mask_set = 1;
1511 }
1512
1513 if(!mask_set) {
1514 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1515 if (rc)
1516 return rc;
1517 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1518 if (rc)
1519 return rc;
1520 } 1509 }
1521 1510
1522 rc = -ENOMEM; 1511 ppi[0] = ppi[1] = &nv_port_info[type];
1512 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host);
1513 if (rc)
1514 return rc;
1523 1515
1524 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 1516 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1525 if (!hpriv) 1517 if (!hpriv)
1526 return -ENOMEM; 1518 return -ENOMEM;
1519 hpriv->type = type;
1520 host->private_data = hpriv;
1527 1521
1528 ppi[0] = ppi[1] = &nv_port_info[type]; 1522 /* set 64bit dma masks, may fail */
1529 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 1523 if (type == ADMA) {
1530 if (!probe_ent) 1524 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0)
1531 return -ENOMEM; 1525 pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1532 1526 }
1533 if (!pcim_iomap(pdev, NV_MMIO_BAR, 0))
1534 return -EIO;
1535 probe_ent->iomap = pcim_iomap_table(pdev);
1536 1527
1537 probe_ent->private_data = hpriv; 1528 /* request and iomap NV_MMIO_BAR */
1538 hpriv->type = type; 1529 rc = pcim_iomap_regions(pdev, 1 << NV_MMIO_BAR, DRV_NAME);
1530 if (rc)
1531 return rc;
1539 1532
1540 base = probe_ent->iomap[NV_MMIO_BAR]; 1533 /* configure SCR access */
1541 probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET; 1534 base = host->iomap[NV_MMIO_BAR];
1542 probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET; 1535 host->ports[0]->ioaddr.scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
1536 host->ports[1]->ioaddr.scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
1543 1537
1544 /* enable SATA space for CK804 */ 1538 /* enable SATA space for CK804 */
1545 if (type >= CK804) { 1539 if (type >= CK804) {
@@ -1550,20 +1544,16 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1550 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); 1544 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
1551 } 1545 }
1552 1546
1553 pci_set_master(pdev); 1547 /* init ADMA */
1554
1555 if (type == ADMA) { 1548 if (type == ADMA) {
1556 rc = nv_adma_host_init(probe_ent); 1549 rc = nv_adma_host_init(host);
1557 if (rc) 1550 if (rc)
1558 return rc; 1551 return rc;
1559 } 1552 }
1560 1553
1561 rc = ata_device_add(probe_ent); 1554 pci_set_master(pdev);
1562 if (rc != NV_PORTS) 1555 return ata_host_activate(host, pdev->irq, ppi[0]->irq_handler,
1563 return -ENODEV; 1556 IRQF_SHARED, ppi[0]->sht);
1564
1565 devm_kfree(&pdev->dev, probe_ent);
1566 return 0;
1567} 1557}
1568 1558
1569static void nv_remove_one (struct pci_dev *pdev) 1559static void nv_remove_one (struct pci_dev *pdev)
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 2339813ce9f6..f56549b90aa6 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -45,10 +45,11 @@
45#include "sata_promise.h" 45#include "sata_promise.h"
46 46
47#define DRV_NAME "sata_promise" 47#define DRV_NAME "sata_promise"
48#define DRV_VERSION "2.00" 48#define DRV_VERSION "2.05"
49 49
50 50
51enum { 51enum {
52 PDC_MAX_PORTS = 4,
52 PDC_MMIO_BAR = 3, 53 PDC_MMIO_BAR = 3,
53 54
54 /* register offsets */ 55 /* register offsets */
@@ -70,14 +71,31 @@ enum {
70 PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */ 71 PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */
71 PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */ 72 PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */
72 73
73 PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) | 74 /* PDC_GLOBAL_CTL bit definitions */
74 (1<<8) | (1<<9) | (1<<10), 75 PDC_PH_ERR = (1 << 8), /* PCI error while loading packet */
76 PDC_SH_ERR = (1 << 9), /* PCI error while loading S/G table */
77 PDC_DH_ERR = (1 << 10), /* PCI error while loading data */
78 PDC2_HTO_ERR = (1 << 12), /* host bus timeout */
79 PDC2_ATA_HBA_ERR = (1 << 13), /* error during SATA DATA FIS transmission */
80 PDC2_ATA_DMA_CNT_ERR = (1 << 14), /* DMA DATA FIS size differs from S/G count */
81 PDC_OVERRUN_ERR = (1 << 19), /* S/G byte count larger than HD requires */
82 PDC_UNDERRUN_ERR = (1 << 20), /* S/G byte count less than HD requires */
83 PDC_DRIVE_ERR = (1 << 21), /* drive error */
84 PDC_PCI_SYS_ERR = (1 << 22), /* PCI system error */
85 PDC1_PCI_PARITY_ERR = (1 << 23), /* PCI parity error (from SATA150 driver) */
86 PDC1_ERR_MASK = PDC1_PCI_PARITY_ERR,
87 PDC2_ERR_MASK = PDC2_HTO_ERR | PDC2_ATA_HBA_ERR | PDC2_ATA_DMA_CNT_ERR,
88 PDC_ERR_MASK = (PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR | PDC_OVERRUN_ERR
89 | PDC_UNDERRUN_ERR | PDC_DRIVE_ERR | PDC_PCI_SYS_ERR
90 | PDC1_ERR_MASK | PDC2_ERR_MASK),
75 91
76 board_2037x = 0, /* FastTrak S150 TX2plus */ 92 board_2037x = 0, /* FastTrak S150 TX2plus */
77 board_20319 = 1, /* FastTrak S150 TX4 */ 93 board_2037x_pata = 1, /* FastTrak S150 TX2plus PATA port */
78 board_20619 = 2, /* FastTrak TX4000 */ 94 board_20319 = 2, /* FastTrak S150 TX4 */
79 board_2057x = 3, /* SATAII150 Tx2plus */ 95 board_20619 = 3, /* FastTrak TX4000 */
80 board_40518 = 4, /* SATAII150 Tx4 */ 96 board_2057x = 4, /* SATAII150 Tx2plus */
97 board_2057x_pata = 5, /* SATAII150 Tx2plus */
98 board_40518 = 6, /* SATAII150 Tx4 */
81 99
82 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */ 100 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
83 101
@@ -100,8 +118,10 @@ enum {
100 ATA_FLAG_MMIO | 118 ATA_FLAG_MMIO |
101 ATA_FLAG_PIO_POLLING, 119 ATA_FLAG_PIO_POLLING,
102 120
103 /* hp->flags bits */ 121 /* ap->flags bits */
104 PDC_FLAG_GEN_II = (1 << 0), 122 PDC_FLAG_GEN_II = (1 << 24),
123 PDC_FLAG_SATA_PATA = (1 << 25), /* supports SATA + PATA */
124 PDC_FLAG_4_PORTS = (1 << 26), /* 4 ports */
105}; 125};
106 126
107 127
@@ -110,28 +130,25 @@ struct pdc_port_priv {
110 dma_addr_t pkt_dma; 130 dma_addr_t pkt_dma;
111}; 131};
112 132
113struct pdc_host_priv {
114 unsigned long flags;
115 unsigned long port_flags[ATA_MAX_PORTS];
116};
117
118static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 133static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
119static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 134static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
120static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 135static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
121static irqreturn_t pdc_interrupt (int irq, void *dev_instance); 136static int pdc_common_port_start(struct ata_port *ap);
122static int pdc_port_start(struct ata_port *ap); 137static int pdc_sata_port_start(struct ata_port *ap);
123static void pdc_qc_prep(struct ata_queued_cmd *qc); 138static void pdc_qc_prep(struct ata_queued_cmd *qc);
124static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 139static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
125static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 140static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
126static int pdc_check_atapi_dma(struct ata_queued_cmd *qc); 141static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
127static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc); 142static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc);
128static void pdc_irq_clear(struct ata_port *ap); 143static void pdc_irq_clear(struct ata_port *ap);
129static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 144static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
130static void pdc_freeze(struct ata_port *ap); 145static void pdc_freeze(struct ata_port *ap);
131static void pdc_thaw(struct ata_port *ap); 146static void pdc_thaw(struct ata_port *ap);
132static void pdc_error_handler(struct ata_port *ap); 147static void pdc_pata_error_handler(struct ata_port *ap);
148static void pdc_sata_error_handler(struct ata_port *ap);
133static void pdc_post_internal_cmd(struct ata_queued_cmd *qc); 149static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
134 150static int pdc_pata_cable_detect(struct ata_port *ap);
151static int pdc_sata_cable_detect(struct ata_port *ap);
135 152
136static struct scsi_host_template pdc_ata_sht = { 153static struct scsi_host_template pdc_ata_sht = {
137 .module = THIS_MODULE, 154 .module = THIS_MODULE,
@@ -164,17 +181,17 @@ static const struct ata_port_operations pdc_sata_ops = {
164 .qc_issue = pdc_qc_issue_prot, 181 .qc_issue = pdc_qc_issue_prot,
165 .freeze = pdc_freeze, 182 .freeze = pdc_freeze,
166 .thaw = pdc_thaw, 183 .thaw = pdc_thaw,
167 .error_handler = pdc_error_handler, 184 .error_handler = pdc_sata_error_handler,
168 .post_internal_cmd = pdc_post_internal_cmd, 185 .post_internal_cmd = pdc_post_internal_cmd,
186 .cable_detect = pdc_sata_cable_detect,
169 .data_xfer = ata_data_xfer, 187 .data_xfer = ata_data_xfer,
170 .irq_handler = pdc_interrupt,
171 .irq_clear = pdc_irq_clear, 188 .irq_clear = pdc_irq_clear,
172 .irq_on = ata_irq_on, 189 .irq_on = ata_irq_on,
173 .irq_ack = ata_irq_ack, 190 .irq_ack = ata_irq_ack,
174 191
175 .scr_read = pdc_sata_scr_read, 192 .scr_read = pdc_sata_scr_read,
176 .scr_write = pdc_sata_scr_write, 193 .scr_write = pdc_sata_scr_write,
177 .port_start = pdc_port_start, 194 .port_start = pdc_sata_port_start,
178}; 195};
179 196
180/* First-generation chips need a more restrictive ->check_atapi_dma op */ 197/* First-generation chips need a more restrictive ->check_atapi_dma op */
@@ -185,23 +202,23 @@ static const struct ata_port_operations pdc_old_sata_ops = {
185 .check_status = ata_check_status, 202 .check_status = ata_check_status,
186 .exec_command = pdc_exec_command_mmio, 203 .exec_command = pdc_exec_command_mmio,
187 .dev_select = ata_std_dev_select, 204 .dev_select = ata_std_dev_select,
188 .check_atapi_dma = pdc_old_check_atapi_dma, 205 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
189 206
190 .qc_prep = pdc_qc_prep, 207 .qc_prep = pdc_qc_prep,
191 .qc_issue = pdc_qc_issue_prot, 208 .qc_issue = pdc_qc_issue_prot,
192 .freeze = pdc_freeze, 209 .freeze = pdc_freeze,
193 .thaw = pdc_thaw, 210 .thaw = pdc_thaw,
194 .error_handler = pdc_error_handler, 211 .error_handler = pdc_sata_error_handler,
195 .post_internal_cmd = pdc_post_internal_cmd, 212 .post_internal_cmd = pdc_post_internal_cmd,
213 .cable_detect = pdc_sata_cable_detect,
196 .data_xfer = ata_data_xfer, 214 .data_xfer = ata_data_xfer,
197 .irq_handler = pdc_interrupt,
198 .irq_clear = pdc_irq_clear, 215 .irq_clear = pdc_irq_clear,
199 .irq_on = ata_irq_on, 216 .irq_on = ata_irq_on,
200 .irq_ack = ata_irq_ack, 217 .irq_ack = ata_irq_ack,
201 218
202 .scr_read = pdc_sata_scr_read, 219 .scr_read = pdc_sata_scr_read,
203 .scr_write = pdc_sata_scr_write, 220 .scr_write = pdc_sata_scr_write,
204 .port_start = pdc_port_start, 221 .port_start = pdc_sata_port_start,
205}; 222};
206 223
207static const struct ata_port_operations pdc_pata_ops = { 224static const struct ata_port_operations pdc_pata_ops = {
@@ -217,32 +234,41 @@ static const struct ata_port_operations pdc_pata_ops = {
217 .qc_issue = pdc_qc_issue_prot, 234 .qc_issue = pdc_qc_issue_prot,
218 .freeze = pdc_freeze, 235 .freeze = pdc_freeze,
219 .thaw = pdc_thaw, 236 .thaw = pdc_thaw,
220 .error_handler = pdc_error_handler, 237 .error_handler = pdc_pata_error_handler,
221 .post_internal_cmd = pdc_post_internal_cmd, 238 .post_internal_cmd = pdc_post_internal_cmd,
239 .cable_detect = pdc_pata_cable_detect,
222 .data_xfer = ata_data_xfer, 240 .data_xfer = ata_data_xfer,
223 .irq_handler = pdc_interrupt,
224 .irq_clear = pdc_irq_clear, 241 .irq_clear = pdc_irq_clear,
225 .irq_on = ata_irq_on, 242 .irq_on = ata_irq_on,
226 .irq_ack = ata_irq_ack, 243 .irq_ack = ata_irq_ack,
227 244
228 .port_start = pdc_port_start, 245 .port_start = pdc_common_port_start,
229}; 246};
230 247
231static const struct ata_port_info pdc_port_info[] = { 248static const struct ata_port_info pdc_port_info[] = {
232 /* board_2037x */ 249 /* board_2037x */
233 { 250 {
234 .sht = &pdc_ata_sht, 251 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
235 .flags = PDC_COMMON_FLAGS, 252 PDC_FLAG_SATA_PATA,
236 .pio_mask = 0x1f, /* pio0-4 */ 253 .pio_mask = 0x1f, /* pio0-4 */
237 .mwdma_mask = 0x07, /* mwdma0-2 */ 254 .mwdma_mask = 0x07, /* mwdma0-2 */
238 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 255 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
239 .port_ops = &pdc_old_sata_ops, 256 .port_ops = &pdc_old_sata_ops,
240 }, 257 },
241 258
259 /* board_2037x_pata */
260 {
261 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
262 .pio_mask = 0x1f, /* pio0-4 */
263 .mwdma_mask = 0x07, /* mwdma0-2 */
264 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
265 .port_ops = &pdc_pata_ops,
266 },
267
242 /* board_20319 */ 268 /* board_20319 */
243 { 269 {
244 .sht = &pdc_ata_sht, 270 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
245 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 271 PDC_FLAG_4_PORTS,
246 .pio_mask = 0x1f, /* pio0-4 */ 272 .pio_mask = 0x1f, /* pio0-4 */
247 .mwdma_mask = 0x07, /* mwdma0-2 */ 273 .mwdma_mask = 0x07, /* mwdma0-2 */
248 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 274 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -251,8 +277,8 @@ static const struct ata_port_info pdc_port_info[] = {
251 277
252 /* board_20619 */ 278 /* board_20619 */
253 { 279 {
254 .sht = &pdc_ata_sht, 280 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
255 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS, 281 PDC_FLAG_4_PORTS,
256 .pio_mask = 0x1f, /* pio0-4 */ 282 .pio_mask = 0x1f, /* pio0-4 */
257 .mwdma_mask = 0x07, /* mwdma0-2 */ 283 .mwdma_mask = 0x07, /* mwdma0-2 */
258 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 284 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -261,18 +287,28 @@ static const struct ata_port_info pdc_port_info[] = {
261 287
262 /* board_2057x */ 288 /* board_2057x */
263 { 289 {
264 .sht = &pdc_ata_sht, 290 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
265 .flags = PDC_COMMON_FLAGS, 291 PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA,
266 .pio_mask = 0x1f, /* pio0-4 */ 292 .pio_mask = 0x1f, /* pio0-4 */
267 .mwdma_mask = 0x07, /* mwdma0-2 */ 293 .mwdma_mask = 0x07, /* mwdma0-2 */
268 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 294 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
269 .port_ops = &pdc_sata_ops, 295 .port_ops = &pdc_sata_ops,
270 }, 296 },
271 297
298 /* board_2057x_pata */
299 {
300 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
301 PDC_FLAG_GEN_II,
302 .pio_mask = 0x1f, /* pio0-4 */
303 .mwdma_mask = 0x07, /* mwdma0-2 */
304 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
305 .port_ops = &pdc_pata_ops,
306 },
307
272 /* board_40518 */ 308 /* board_40518 */
273 { 309 {
274 .sht = &pdc_ata_sht, 310 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
275 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 311 PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS,
276 .pio_mask = 0x1f, /* pio0-4 */ 312 .pio_mask = 0x1f, /* pio0-4 */
277 .mwdma_mask = 0x07, /* mwdma0-2 */ 313 .mwdma_mask = 0x07, /* mwdma0-2 */
278 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 314 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -313,18 +349,12 @@ static struct pci_driver pdc_ata_pci_driver = {
313}; 349};
314 350
315 351
316static int pdc_port_start(struct ata_port *ap) 352static int pdc_common_port_start(struct ata_port *ap)
317{ 353{
318 struct device *dev = ap->host->dev; 354 struct device *dev = ap->host->dev;
319 struct pdc_host_priv *hp = ap->host->private_data;
320 struct pdc_port_priv *pp; 355 struct pdc_port_priv *pp;
321 int rc; 356 int rc;
322 357
323 /* fix up port flags and cable type for SATA+PATA chips */
324 ap->flags |= hp->port_flags[ap->port_no];
325 if (ap->flags & ATA_FLAG_SATA)
326 ap->cbl = ATA_CBL_SATA;
327
328 rc = ata_port_start(ap); 358 rc = ata_port_start(ap);
329 if (rc) 359 if (rc)
330 return rc; 360 return rc;
@@ -339,8 +369,19 @@ static int pdc_port_start(struct ata_port *ap)
339 369
340 ap->private_data = pp; 370 ap->private_data = pp;
341 371
372 return 0;
373}
374
375static int pdc_sata_port_start(struct ata_port *ap)
376{
377 int rc;
378
379 rc = pdc_common_port_start(ap);
380 if (rc)
381 return rc;
382
342 /* fix up PHYMODE4 align timing */ 383 /* fix up PHYMODE4 align timing */
343 if ((hp->flags & PDC_FLAG_GEN_II) && sata_scr_valid(ap)) { 384 if (ap->flags & PDC_FLAG_GEN_II) {
344 void __iomem *mmio = (void __iomem *) ap->ioaddr.scr_addr; 385 void __iomem *mmio = (void __iomem *) ap->ioaddr.scr_addr;
345 unsigned int tmp; 386 unsigned int tmp;
346 387
@@ -374,23 +415,25 @@ static void pdc_reset_port(struct ata_port *ap)
374 readl(mmio); /* flush */ 415 readl(mmio); /* flush */
375} 416}
376 417
377static void pdc_pata_cbl_detect(struct ata_port *ap) 418static int pdc_pata_cable_detect(struct ata_port *ap)
378{ 419{
379 u8 tmp; 420 u8 tmp;
380 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03; 421 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03;
381 422
382 tmp = readb(mmio); 423 tmp = readb(mmio);
424 if (tmp & 0x01)
425 return ATA_CBL_PATA40;
426 return ATA_CBL_PATA80;
427}
383 428
384 if (tmp & 0x01) { 429static int pdc_sata_cable_detect(struct ata_port *ap)
385 ap->cbl = ATA_CBL_PATA40; 430{
386 ap->udma_mask &= ATA_UDMA_MASK_40C; 431 return ATA_CBL_SATA;
387 } else
388 ap->cbl = ATA_CBL_PATA80;
389} 432}
390 433
391static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 434static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
392{ 435{
393 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA) 436 if (sc_reg > SCR_CONTROL)
394 return 0xffffffffU; 437 return 0xffffffffU;
395 return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 438 return readl(ap->ioaddr.scr_addr + (sc_reg * 4));
396} 439}
@@ -399,7 +442,7 @@ static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
399static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 442static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
400 u32 val) 443 u32 val)
401{ 444{
402 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA) 445 if (sc_reg > SCR_CONTROL)
403 return; 446 return;
404 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 447 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
405} 448}
@@ -555,52 +598,79 @@ static void pdc_thaw(struct ata_port *ap)
555 readl(mmio + PDC_CTLSTAT); /* flush */ 598 readl(mmio + PDC_CTLSTAT); /* flush */
556} 599}
557 600
558static int pdc_pre_reset(struct ata_port *ap) 601static void pdc_common_error_handler(struct ata_port *ap, ata_reset_fn_t hardreset)
559{
560 if (!sata_scr_valid(ap))
561 pdc_pata_cbl_detect(ap);
562 return ata_std_prereset(ap);
563}
564
565static void pdc_error_handler(struct ata_port *ap)
566{ 602{
567 ata_reset_fn_t hardreset;
568
569 if (!(ap->pflags & ATA_PFLAG_FROZEN)) 603 if (!(ap->pflags & ATA_PFLAG_FROZEN))
570 pdc_reset_port(ap); 604 pdc_reset_port(ap);
571 605
572 hardreset = NULL;
573 if (sata_scr_valid(ap))
574 hardreset = sata_std_hardreset;
575
576 /* perform recovery */ 606 /* perform recovery */
577 ata_do_eh(ap, pdc_pre_reset, ata_std_softreset, hardreset, 607 ata_do_eh(ap, ata_std_prereset, ata_std_softreset, hardreset,
578 ata_std_postreset); 608 ata_std_postreset);
579} 609}
580 610
611static void pdc_pata_error_handler(struct ata_port *ap)
612{
613 pdc_common_error_handler(ap, NULL);
614}
615
616static void pdc_sata_error_handler(struct ata_port *ap)
617{
618 pdc_common_error_handler(ap, sata_std_hardreset);
619}
620
581static void pdc_post_internal_cmd(struct ata_queued_cmd *qc) 621static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
582{ 622{
583 struct ata_port *ap = qc->ap; 623 struct ata_port *ap = qc->ap;
584 624
585 if (qc->flags & ATA_QCFLAG_FAILED)
586 qc->err_mask |= AC_ERR_OTHER;
587
588 /* make DMA engine forget about the failed command */ 625 /* make DMA engine forget about the failed command */
589 if (qc->err_mask) 626 if (qc->flags & ATA_QCFLAG_FAILED)
590 pdc_reset_port(ap); 627 pdc_reset_port(ap);
591} 628}
592 629
630static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
631 u32 port_status, u32 err_mask)
632{
633 struct ata_eh_info *ehi = &ap->eh_info;
634 unsigned int ac_err_mask = 0;
635
636 ata_ehi_clear_desc(ehi);
637 ata_ehi_push_desc(ehi, "port_status 0x%08x", port_status);
638 port_status &= err_mask;
639
640 if (port_status & PDC_DRIVE_ERR)
641 ac_err_mask |= AC_ERR_DEV;
642 if (port_status & (PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR))
643 ac_err_mask |= AC_ERR_HSM;
644 if (port_status & (PDC2_ATA_HBA_ERR | PDC2_ATA_DMA_CNT_ERR))
645 ac_err_mask |= AC_ERR_ATA_BUS;
646 if (port_status & (PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR | PDC2_HTO_ERR
647 | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
648 ac_err_mask |= AC_ERR_HOST_BUS;
649
650 if (sata_scr_valid(ap))
651 ehi->serror |= pdc_sata_scr_read(ap, SCR_ERROR);
652
653 qc->err_mask |= ac_err_mask;
654
655 pdc_reset_port(ap);
656}
657
593static inline unsigned int pdc_host_intr( struct ata_port *ap, 658static inline unsigned int pdc_host_intr( struct ata_port *ap,
594 struct ata_queued_cmd *qc) 659 struct ata_queued_cmd *qc)
595{ 660{
596 unsigned int handled = 0; 661 unsigned int handled = 0;
597 u32 tmp; 662 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
598 void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 663 u32 port_status, err_mask;
599 664
600 tmp = readl(mmio); 665 err_mask = PDC_ERR_MASK;
601 if (tmp & PDC_ERR_MASK) { 666 if (ap->flags & PDC_FLAG_GEN_II)
602 qc->err_mask |= AC_ERR_DEV; 667 err_mask &= ~PDC1_ERR_MASK;
603 pdc_reset_port(ap); 668 else
669 err_mask &= ~PDC2_ERR_MASK;
670 port_status = readl(port_mmio + PDC_GLOBAL_CTL);
671 if (unlikely(port_status & err_mask)) {
672 pdc_error_intr(ap, qc, port_status, err_mask);
673 return 1;
604 } 674 }
605 675
606 switch (qc->tf.protocol) { 676 switch (qc->tf.protocol) {
@@ -767,44 +837,40 @@ static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
767 return pio; 837 return pio;
768} 838}
769 839
770static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc) 840static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc)
771{ 841{
772 struct ata_port *ap = qc->ap;
773
774 /* First generation chips cannot use ATAPI DMA on SATA ports */ 842 /* First generation chips cannot use ATAPI DMA on SATA ports */
775 if (sata_scr_valid(ap)) 843 return 1;
776 return 1;
777 return pdc_check_atapi_dma(qc);
778} 844}
779 845
780static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base, 846static void pdc_ata_setup_port(struct ata_port *ap,
781 void __iomem *scr_addr) 847 void __iomem *base, void __iomem *scr_addr)
782{ 848{
783 port->cmd_addr = base; 849 ap->ioaddr.cmd_addr = base;
784 port->data_addr = base; 850 ap->ioaddr.data_addr = base;
785 port->feature_addr = 851 ap->ioaddr.feature_addr =
786 port->error_addr = base + 0x4; 852 ap->ioaddr.error_addr = base + 0x4;
787 port->nsect_addr = base + 0x8; 853 ap->ioaddr.nsect_addr = base + 0x8;
788 port->lbal_addr = base + 0xc; 854 ap->ioaddr.lbal_addr = base + 0xc;
789 port->lbam_addr = base + 0x10; 855 ap->ioaddr.lbam_addr = base + 0x10;
790 port->lbah_addr = base + 0x14; 856 ap->ioaddr.lbah_addr = base + 0x14;
791 port->device_addr = base + 0x18; 857 ap->ioaddr.device_addr = base + 0x18;
792 port->command_addr = 858 ap->ioaddr.command_addr =
793 port->status_addr = base + 0x1c; 859 ap->ioaddr.status_addr = base + 0x1c;
794 port->altstatus_addr = 860 ap->ioaddr.altstatus_addr =
795 port->ctl_addr = base + 0x38; 861 ap->ioaddr.ctl_addr = base + 0x38;
796 port->scr_addr = scr_addr; 862 ap->ioaddr.scr_addr = scr_addr;
797} 863}
798 864
799 865
800static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 866static void pdc_host_init(struct ata_host *host)
801{ 867{
802 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 868 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
803 struct pdc_host_priv *hp = pe->private_data; 869 int is_gen2 = host->ports[0]->flags & PDC_FLAG_GEN_II;
804 int hotplug_offset; 870 int hotplug_offset;
805 u32 tmp; 871 u32 tmp;
806 872
807 if (hp->flags & PDC_FLAG_GEN_II) 873 if (is_gen2)
808 hotplug_offset = PDC2_SATA_PLUG_CSR; 874 hotplug_offset = PDC2_SATA_PLUG_CSR;
809 else 875 else
810 hotplug_offset = PDC_SATA_PLUG_CSR; 876 hotplug_offset = PDC_SATA_PLUG_CSR;
@@ -818,7 +884,7 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
818 /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */ 884 /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
819 tmp = readl(mmio + PDC_FLASH_CTL); 885 tmp = readl(mmio + PDC_FLASH_CTL);
820 tmp |= 0x02000; /* bit 13 (enable bmr burst) */ 886 tmp |= 0x02000; /* bit 13 (enable bmr burst) */
821 if (!(hp->flags & PDC_FLAG_GEN_II)) 887 if (!is_gen2)
822 tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */ 888 tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
823 writel(tmp, mmio + PDC_FLASH_CTL); 889 writel(tmp, mmio + PDC_FLASH_CTL);
824 890
@@ -831,7 +897,7 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
831 writel(tmp | 0xff0000, mmio + hotplug_offset); 897 writel(tmp | 0xff0000, mmio + hotplug_offset);
832 898
833 /* don't initialise TBG or SLEW on 2nd generation chips */ 899 /* don't initialise TBG or SLEW on 2nd generation chips */
834 if (hp->flags & PDC_FLAG_GEN_II) 900 if (is_gen2)
835 return; 901 return;
836 902
837 /* reduce TBG clock to 133 Mhz. */ 903 /* reduce TBG clock to 133 Mhz. */
@@ -853,16 +919,16 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
853static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 919static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
854{ 920{
855 static int printed_version; 921 static int printed_version;
856 struct ata_probe_ent *probe_ent; 922 const struct ata_port_info *pi = &pdc_port_info[ent->driver_data];
857 struct pdc_host_priv *hp; 923 const struct ata_port_info *ppi[PDC_MAX_PORTS];
924 struct ata_host *host;
858 void __iomem *base; 925 void __iomem *base;
859 unsigned int board_idx = (unsigned int) ent->driver_data; 926 int n_ports, i, rc;
860 int rc;
861 u8 tmp;
862 927
863 if (!printed_version++) 928 if (!printed_version++)
864 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 929 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
865 930
931 /* enable and acquire resources */
866 rc = pcim_enable_device(pdev); 932 rc = pcim_enable_device(pdev);
867 if (rc) 933 if (rc)
868 return rc; 934 return rc;
@@ -872,89 +938,49 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
872 pcim_pin_device(pdev); 938 pcim_pin_device(pdev);
873 if (rc) 939 if (rc)
874 return rc; 940 return rc;
941 base = pcim_iomap_table(pdev)[PDC_MMIO_BAR];
875 942
876 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 943 /* determine port configuration and setup host */
877 if (rc) 944 n_ports = 2;
878 return rc; 945 if (pi->flags & PDC_FLAG_4_PORTS)
879 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 946 n_ports = 4;
880 if (rc) 947 for (i = 0; i < n_ports; i++)
881 return rc; 948 ppi[i] = pi;
882
883 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
884 if (probe_ent == NULL)
885 return -ENOMEM;
886 949
887 probe_ent->dev = pci_dev_to_dev(pdev); 950 if (pi->flags & PDC_FLAG_SATA_PATA) {
888 INIT_LIST_HEAD(&probe_ent->node); 951 u8 tmp = readb(base + PDC_FLASH_CTL+1);
952 if (!(tmp & 0x80)) {
953 ppi[n_ports++] = pi + 1;
954 dev_printk(KERN_INFO, &pdev->dev, "PATA port found\n");
955 }
956 }
889 957
890 hp = devm_kzalloc(&pdev->dev, sizeof(*hp), GFP_KERNEL); 958 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
891 if (hp == NULL) 959 if (!host) {
960 dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
892 return -ENOMEM; 961 return -ENOMEM;
893
894 probe_ent->private_data = hp;
895
896 probe_ent->sht = pdc_port_info[board_idx].sht;
897 probe_ent->port_flags = pdc_port_info[board_idx].flags;
898 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
899 probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
900 probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
901 probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
902
903 probe_ent->irq = pdev->irq;
904 probe_ent->irq_flags = IRQF_SHARED;
905 probe_ent->iomap = pcim_iomap_table(pdev);
906
907 base = probe_ent->iomap[PDC_MMIO_BAR];
908
909 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200, base + 0x400);
910 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280, base + 0x500);
911
912 /* notice 4-port boards */
913 switch (board_idx) {
914 case board_40518:
915 hp->flags |= PDC_FLAG_GEN_II;
916 /* Fall through */
917 case board_20319:
918 probe_ent->n_ports = 4;
919 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, base + 0x600);
920 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380, base + 0x700);
921 break;
922 case board_2057x:
923 hp->flags |= PDC_FLAG_GEN_II;
924 /* Fall through */
925 case board_2037x:
926 /* TX2plus boards also have a PATA port */
927 tmp = readb(base + PDC_FLASH_CTL+1);
928 if (!(tmp & 0x80)) {
929 probe_ent->n_ports = 3;
930 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, NULL);
931 hp->port_flags[2] = ATA_FLAG_SLAVE_POSS;
932 printk(KERN_INFO DRV_NAME " PATA port found\n");
933 } else
934 probe_ent->n_ports = 2;
935 hp->port_flags[0] = ATA_FLAG_SATA;
936 hp->port_flags[1] = ATA_FLAG_SATA;
937 break;
938 case board_20619:
939 probe_ent->n_ports = 4;
940 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300, NULL);
941 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380, NULL);
942 break;
943 default:
944 BUG();
945 break;
946 } 962 }
963 host->iomap = pcim_iomap_table(pdev);
947 964
948 pci_set_master(pdev); 965 for (i = 0; i < host->n_ports; i++)
966 pdc_ata_setup_port(host->ports[i],
967 base + 0x200 + i * 0x80,
968 base + 0x400 + i * 0x100);
949 969
950 /* initialize adapter */ 970 /* initialize adapter */
951 pdc_host_init(board_idx, probe_ent); 971 pdc_host_init(host);
952 972
953 if (!ata_device_add(probe_ent)) 973 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
954 return -ENODEV; 974 if (rc)
975 return rc;
976 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
977 if (rc)
978 return rc;
955 979
956 devm_kfree(&pdev->dev, probe_ent); 980 /* start host, request IRQ and attach */
957 return 0; 981 pci_set_master(pdev);
982 return ata_host_activate(host, pdev->irq, pdc_interrupt, IRQF_SHARED,
983 &pdc_ata_sht);
958} 984}
959 985
960 986
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 8786b45f291b..f5a05de0093d 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -114,7 +114,6 @@ struct qs_port_priv {
114static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg); 114static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg);
115static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 115static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
116static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 116static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
117static irqreturn_t qs_intr (int irq, void *dev_instance);
118static int qs_port_start(struct ata_port *ap); 117static int qs_port_start(struct ata_port *ap);
119static void qs_host_stop(struct ata_host *host); 118static void qs_host_stop(struct ata_host *host);
120static void qs_phy_reset(struct ata_port *ap); 119static void qs_phy_reset(struct ata_port *ap);
@@ -158,7 +157,6 @@ static const struct ata_port_operations qs_ata_ops = {
158 .qc_issue = qs_qc_issue, 157 .qc_issue = qs_qc_issue,
159 .data_xfer = ata_data_xfer, 158 .data_xfer = ata_data_xfer,
160 .eng_timeout = qs_eng_timeout, 159 .eng_timeout = qs_eng_timeout,
161 .irq_handler = qs_intr,
162 .irq_clear = qs_irq_clear, 160 .irq_clear = qs_irq_clear,
163 .irq_on = ata_irq_on, 161 .irq_on = ata_irq_on,
164 .irq_ack = ata_irq_ack, 162 .irq_ack = ata_irq_ack,
@@ -173,7 +171,6 @@ static const struct ata_port_operations qs_ata_ops = {
173static const struct ata_port_info qs_port_info[] = { 171static const struct ata_port_info qs_port_info[] = {
174 /* board_2068_idx */ 172 /* board_2068_idx */
175 { 173 {
176 .sht = &qs_ata_sht,
177 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 174 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
178 ATA_FLAG_SATA_RESET | 175 ATA_FLAG_SATA_RESET |
179 //FIXME ATA_FLAG_SRST | 176 //FIXME ATA_FLAG_SRST |
@@ -530,16 +527,16 @@ static void qs_host_stop(struct ata_host *host)
530 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 527 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
531} 528}
532 529
533static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 530static void qs_host_init(struct ata_host *host, unsigned int chip_id)
534{ 531{
535 void __iomem *mmio_base = pe->iomap[QS_MMIO_BAR]; 532 void __iomem *mmio_base = host->iomap[QS_MMIO_BAR];
536 unsigned int port_no; 533 unsigned int port_no;
537 534
538 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 535 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
539 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 536 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
540 537
541 /* reset each channel in turn */ 538 /* reset each channel in turn */
542 for (port_no = 0; port_no < pe->n_ports; ++port_no) { 539 for (port_no = 0; port_no < host->n_ports; ++port_no) {
543 u8 __iomem *chan = mmio_base + (port_no * 0x4000); 540 u8 __iomem *chan = mmio_base + (port_no * 0x4000);
544 writeb(QS_CTR1_RDEV|QS_CTR1_RCHN, chan + QS_CCT_CTR1); 541 writeb(QS_CTR1_RDEV|QS_CTR1_RCHN, chan + QS_CCT_CTR1);
545 writeb(QS_CTR0_REG, chan + QS_CCT_CTR0); 542 writeb(QS_CTR0_REG, chan + QS_CCT_CTR0);
@@ -547,7 +544,7 @@ static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
547 } 544 }
548 writeb(QS_SERD3_PHY_ENA, mmio_base + QS_HVS_SERD3); /* enable phy */ 545 writeb(QS_SERD3_PHY_ENA, mmio_base + QS_HVS_SERD3); /* enable phy */
549 546
550 for (port_no = 0; port_no < pe->n_ports; ++port_no) { 547 for (port_no = 0; port_no < host->n_ports; ++port_no) {
551 u8 __iomem *chan = mmio_base + (port_no * 0x4000); 548 u8 __iomem *chan = mmio_base + (port_no * 0x4000);
552 /* set FIFO depths to same settings as Windows driver */ 549 /* set FIFO depths to same settings as Windows driver */
553 writew(32, chan + QS_CFC_HUFT); 550 writew(32, chan + QS_CFC_HUFT);
@@ -607,14 +604,20 @@ static int qs_ata_init_one(struct pci_dev *pdev,
607 const struct pci_device_id *ent) 604 const struct pci_device_id *ent)
608{ 605{
609 static int printed_version; 606 static int printed_version;
610 struct ata_probe_ent *probe_ent;
611 void __iomem * const *iomap;
612 unsigned int board_idx = (unsigned int) ent->driver_data; 607 unsigned int board_idx = (unsigned int) ent->driver_data;
608 const struct ata_port_info *ppi[] = { &qs_port_info[board_idx], NULL };
609 struct ata_host *host;
613 int rc, port_no; 610 int rc, port_no;
614 611
615 if (!printed_version++) 612 if (!printed_version++)
616 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 613 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
617 614
615 /* alloc host */
616 host = ata_host_alloc_pinfo(&pdev->dev, ppi, QS_PORTS);
617 if (!host)
618 return -ENOMEM;
619
620 /* acquire resources and fill host */
618 rc = pcim_enable_device(pdev); 621 rc = pcim_enable_device(pdev);
619 if (rc) 622 if (rc)
620 return rc; 623 return rc;
@@ -625,47 +628,24 @@ static int qs_ata_init_one(struct pci_dev *pdev,
625 rc = pcim_iomap_regions(pdev, 1 << QS_MMIO_BAR, DRV_NAME); 628 rc = pcim_iomap_regions(pdev, 1 << QS_MMIO_BAR, DRV_NAME);
626 if (rc) 629 if (rc)
627 return rc; 630 return rc;
628 iomap = pcim_iomap_table(pdev); 631 host->iomap = pcim_iomap_table(pdev);
629 632
630 rc = qs_set_dma_masks(pdev, iomap[QS_MMIO_BAR]); 633 rc = qs_set_dma_masks(pdev, host->iomap[QS_MMIO_BAR]);
631 if (rc) 634 if (rc)
632 return rc; 635 return rc;
633 636
634 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); 637 for (port_no = 0; port_no < host->n_ports; ++port_no) {
635 if (probe_ent == NULL)
636 return -ENOMEM;
637
638 probe_ent->dev = pci_dev_to_dev(pdev);
639 INIT_LIST_HEAD(&probe_ent->node);
640
641 probe_ent->sht = qs_port_info[board_idx].sht;
642 probe_ent->port_flags = qs_port_info[board_idx].flags;
643 probe_ent->pio_mask = qs_port_info[board_idx].pio_mask;
644 probe_ent->mwdma_mask = qs_port_info[board_idx].mwdma_mask;
645 probe_ent->udma_mask = qs_port_info[board_idx].udma_mask;
646 probe_ent->port_ops = qs_port_info[board_idx].port_ops;
647
648 probe_ent->irq = pdev->irq;
649 probe_ent->irq_flags = IRQF_SHARED;
650 probe_ent->iomap = iomap;
651 probe_ent->n_ports = QS_PORTS;
652
653 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
654 void __iomem *chan = 638 void __iomem *chan =
655 probe_ent->iomap[QS_MMIO_BAR] + (port_no * 0x4000); 639 host->iomap[QS_MMIO_BAR] + (port_no * 0x4000);
656 qs_ata_setup_port(&probe_ent->port[port_no], chan); 640 qs_ata_setup_port(&host->ports[port_no]->ioaddr, chan);
657 } 641 }
658 642
659 pci_set_master(pdev);
660
661 /* initialize adapter */ 643 /* initialize adapter */
662 qs_host_init(board_idx, probe_ent); 644 qs_host_init(host, board_idx);
663 645
664 if (ata_device_add(probe_ent) != QS_PORTS) 646 pci_set_master(pdev);
665 return -EIO; 647 return ata_host_activate(host, pdev->irq, qs_intr, IRQF_SHARED,
666 648 &qs_ata_sht);
667 devm_kfree(&pdev->dev, probe_ent);
668 return 0;
669} 649}
670 650
671static int __init qs_ata_init(void) 651static int __init qs_ata_init(void)
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 917b7ea4ef7c..0a1e417f309c 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_sil" 48#define DRV_NAME "sata_sil"
49#define DRV_VERSION "2.1" 49#define DRV_VERSION "2.2"
50 50
51enum { 51enum {
52 SIL_MMIO_BAR = 5, 52 SIL_MMIO_BAR = 5,
@@ -114,11 +114,10 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
114#ifdef CONFIG_PM 114#ifdef CONFIG_PM
115static int sil_pci_device_resume(struct pci_dev *pdev); 115static int sil_pci_device_resume(struct pci_dev *pdev);
116#endif 116#endif
117static void sil_dev_config(struct ata_port *ap, struct ata_device *dev); 117static void sil_dev_config(struct ata_device *dev);
118static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); 118static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
119static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 119static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
120static void sil_post_set_mode (struct ata_port *ap); 120static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed);
121static irqreturn_t sil_interrupt(int irq, void *dev_instance);
122static void sil_freeze(struct ata_port *ap); 121static void sil_freeze(struct ata_port *ap);
123static void sil_thaw(struct ata_port *ap); 122static void sil_thaw(struct ata_port *ap);
124 123
@@ -197,7 +196,7 @@ static const struct ata_port_operations sil_ops = {
197 .check_status = ata_check_status, 196 .check_status = ata_check_status,
198 .exec_command = ata_exec_command, 197 .exec_command = ata_exec_command,
199 .dev_select = ata_std_dev_select, 198 .dev_select = ata_std_dev_select,
200 .post_set_mode = sil_post_set_mode, 199 .set_mode = sil_set_mode,
201 .bmdma_setup = ata_bmdma_setup, 200 .bmdma_setup = ata_bmdma_setup,
202 .bmdma_start = ata_bmdma_start, 201 .bmdma_start = ata_bmdma_start,
203 .bmdma_stop = ata_bmdma_stop, 202 .bmdma_stop = ata_bmdma_stop,
@@ -209,7 +208,6 @@ static const struct ata_port_operations sil_ops = {
209 .thaw = sil_thaw, 208 .thaw = sil_thaw,
210 .error_handler = ata_bmdma_error_handler, 209 .error_handler = ata_bmdma_error_handler,
211 .post_internal_cmd = ata_bmdma_post_internal_cmd, 210 .post_internal_cmd = ata_bmdma_post_internal_cmd,
212 .irq_handler = sil_interrupt,
213 .irq_clear = ata_bmdma_irq_clear, 211 .irq_clear = ata_bmdma_irq_clear,
214 .irq_on = ata_irq_on, 212 .irq_on = ata_irq_on,
215 .irq_ack = ata_irq_ack, 213 .irq_ack = ata_irq_ack,
@@ -221,7 +219,6 @@ static const struct ata_port_operations sil_ops = {
221static const struct ata_port_info sil_port_info[] = { 219static const struct ata_port_info sil_port_info[] = {
222 /* sil_3112 */ 220 /* sil_3112 */
223 { 221 {
224 .sht = &sil_sht,
225 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE, 222 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE,
226 .pio_mask = 0x1f, /* pio0-4 */ 223 .pio_mask = 0x1f, /* pio0-4 */
227 .mwdma_mask = 0x07, /* mwdma0-2 */ 224 .mwdma_mask = 0x07, /* mwdma0-2 */
@@ -230,7 +227,6 @@ static const struct ata_port_info sil_port_info[] = {
230 }, 227 },
231 /* sil_3112_no_sata_irq */ 228 /* sil_3112_no_sata_irq */
232 { 229 {
233 .sht = &sil_sht,
234 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE | 230 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE |
235 SIL_FLAG_NO_SATA_IRQ, 231 SIL_FLAG_NO_SATA_IRQ,
236 .pio_mask = 0x1f, /* pio0-4 */ 232 .pio_mask = 0x1f, /* pio0-4 */
@@ -240,7 +236,6 @@ static const struct ata_port_info sil_port_info[] = {
240 }, 236 },
241 /* sil_3512 */ 237 /* sil_3512 */
242 { 238 {
243 .sht = &sil_sht,
244 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, 239 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
245 .pio_mask = 0x1f, /* pio0-4 */ 240 .pio_mask = 0x1f, /* pio0-4 */
246 .mwdma_mask = 0x07, /* mwdma0-2 */ 241 .mwdma_mask = 0x07, /* mwdma0-2 */
@@ -249,7 +244,6 @@ static const struct ata_port_info sil_port_info[] = {
249 }, 244 },
250 /* sil_3114 */ 245 /* sil_3114 */
251 { 246 {
252 .sht = &sil_sht,
253 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, 247 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
254 .pio_mask = 0x1f, /* pio0-4 */ 248 .pio_mask = 0x1f, /* pio0-4 */
255 .mwdma_mask = 0x07, /* mwdma0-2 */ 249 .mwdma_mask = 0x07, /* mwdma0-2 */
@@ -297,7 +291,16 @@ static unsigned char sil_get_device_cache_line(struct pci_dev *pdev)
297 return cache_line; 291 return cache_line;
298} 292}
299 293
300static void sil_post_set_mode (struct ata_port *ap) 294/**
295 * sil_set_mode - wrap set_mode functions
296 * @ap: port to set up
297 * @r_failed: returned device when we fail
298 *
299 * Wrap the libata method for device setup as after the setup we need
300 * to inspect the results and do some configuration work
301 */
302
303static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed)
301{ 304{
302 struct ata_host *host = ap->host; 305 struct ata_host *host = ap->host;
303 struct ata_device *dev; 306 struct ata_device *dev;
@@ -305,6 +308,11 @@ static void sil_post_set_mode (struct ata_port *ap)
305 void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode; 308 void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode;
306 u32 tmp, dev_mode[2]; 309 u32 tmp, dev_mode[2];
307 unsigned int i; 310 unsigned int i;
311 int rc;
312
313 rc = ata_do_set_mode(ap, r_failed);
314 if (rc)
315 return rc;
308 316
309 for (i = 0; i < 2; i++) { 317 for (i = 0; i < 2; i++) {
310 dev = &ap->device[i]; 318 dev = &ap->device[i];
@@ -323,6 +331,7 @@ static void sil_post_set_mode (struct ata_port *ap)
323 tmp |= (dev_mode[1] << 4); 331 tmp |= (dev_mode[1] << 4);
324 writel(tmp, addr); 332 writel(tmp, addr);
325 readl(addr); /* flush */ 333 readl(addr); /* flush */
334 return 0;
326} 335}
327 336
328static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_reg) 337static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_reg)
@@ -521,7 +530,6 @@ static void sil_thaw(struct ata_port *ap)
521 530
522/** 531/**
523 * sil_dev_config - Apply device/host-specific errata fixups 532 * sil_dev_config - Apply device/host-specific errata fixups
524 * @ap: Port containing device to be examined
525 * @dev: Device to be examined 533 * @dev: Device to be examined
526 * 534 *
527 * After the IDENTIFY [PACKET] DEVICE step is complete, and a 535 * After the IDENTIFY [PACKET] DEVICE step is complete, and a
@@ -548,8 +556,9 @@ static void sil_thaw(struct ata_port *ap)
548 * appreciated. 556 * appreciated.
549 * - But then again UDMA5 is hardly anything to complain about 557 * - But then again UDMA5 is hardly anything to complain about
550 */ 558 */
551static void sil_dev_config(struct ata_port *ap, struct ata_device *dev) 559static void sil_dev_config(struct ata_device *dev)
552{ 560{
561 struct ata_port *ap = dev->ap;
553 int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO; 562 int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO;
554 unsigned int n, quirks = 0; 563 unsigned int n, quirks = 0;
555 unsigned char model_num[ATA_ID_PROD_LEN + 1]; 564 unsigned char model_num[ATA_ID_PROD_LEN + 1];
@@ -583,10 +592,10 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
583 } 592 }
584} 593}
585 594
586static void sil_init_controller(struct pci_dev *pdev, 595static void sil_init_controller(struct ata_host *host)
587 int n_ports, unsigned long port_flags,
588 void __iomem *mmio_base)
589{ 596{
597 struct pci_dev *pdev = to_pci_dev(host->dev);
598 void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR];
590 u8 cls; 599 u8 cls;
591 u32 tmp; 600 u32 tmp;
592 int i; 601 int i;
@@ -596,7 +605,7 @@ static void sil_init_controller(struct pci_dev *pdev,
596 if (cls) { 605 if (cls) {
597 cls >>= 3; 606 cls >>= 3;
598 cls++; /* cls = (line_size/8)+1 */ 607 cls++; /* cls = (line_size/8)+1 */
599 for (i = 0; i < n_ports; i++) 608 for (i = 0; i < host->n_ports; i++)
600 writew(cls << 8 | cls, 609 writew(cls << 8 | cls,
601 mmio_base + sil_port[i].fifo_cfg); 610 mmio_base + sil_port[i].fifo_cfg);
602 } else 611 } else
@@ -604,10 +613,10 @@ static void sil_init_controller(struct pci_dev *pdev,
604 "cache line size not set. Driver may not function\n"); 613 "cache line size not set. Driver may not function\n");
605 614
606 /* Apply R_ERR on DMA activate FIS errata workaround */ 615 /* Apply R_ERR on DMA activate FIS errata workaround */
607 if (port_flags & SIL_FLAG_RERR_ON_DMA_ACT) { 616 if (host->ports[0]->flags & SIL_FLAG_RERR_ON_DMA_ACT) {
608 int cnt; 617 int cnt;
609 618
610 for (i = 0, cnt = 0; i < n_ports; i++) { 619 for (i = 0, cnt = 0; i < host->n_ports; i++) {
611 tmp = readl(mmio_base + sil_port[i].sfis_cfg); 620 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
612 if ((tmp & 0x3) != 0x01) 621 if ((tmp & 0x3) != 0x01)
613 continue; 622 continue;
@@ -620,7 +629,7 @@ static void sil_init_controller(struct pci_dev *pdev,
620 } 629 }
621 } 630 }
622 631
623 if (n_ports == 4) { 632 if (host->n_ports == 4) {
624 /* flip the magic "make 4 ports work" bit */ 633 /* flip the magic "make 4 ports work" bit */
625 tmp = readl(mmio_base + sil_port[2].bmdma); 634 tmp = readl(mmio_base + sil_port[2].bmdma);
626 if ((tmp & SIL_INTR_STEERING) == 0) 635 if ((tmp & SIL_INTR_STEERING) == 0)
@@ -632,15 +641,26 @@ static void sil_init_controller(struct pci_dev *pdev,
632static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 641static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
633{ 642{
634 static int printed_version; 643 static int printed_version;
635 struct device *dev = &pdev->dev; 644 int board_id = ent->driver_data;
636 struct ata_probe_ent *probe_ent; 645 const struct ata_port_info *ppi[] = { &sil_port_info[board_id], NULL };
646 struct ata_host *host;
637 void __iomem *mmio_base; 647 void __iomem *mmio_base;
638 int rc; 648 int n_ports, rc;
639 unsigned int i; 649 unsigned int i;
640 650
641 if (!printed_version++) 651 if (!printed_version++)
642 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 652 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
643 653
654 /* allocate host */
655 n_ports = 2;
656 if (board_id == sil_3114)
657 n_ports = 4;
658
659 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
660 if (!host)
661 return -ENOMEM;
662
663 /* acquire resources and fill host */
644 rc = pcim_enable_device(pdev); 664 rc = pcim_enable_device(pdev);
645 if (rc) 665 if (rc)
646 return rc; 666 return rc;
@@ -650,6 +670,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
650 pcim_pin_device(pdev); 670 pcim_pin_device(pdev);
651 if (rc) 671 if (rc)
652 return rc; 672 return rc;
673 host->iomap = pcim_iomap_table(pdev);
653 674
654 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 675 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
655 if (rc) 676 if (rc)
@@ -658,45 +679,25 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
658 if (rc) 679 if (rc)
659 return rc; 680 return rc;
660 681
661 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL); 682 mmio_base = host->iomap[SIL_MMIO_BAR];
662 if (probe_ent == NULL)
663 return -ENOMEM;
664 683
665 INIT_LIST_HEAD(&probe_ent->node); 684 for (i = 0; i < host->n_ports; i++) {
666 probe_ent->dev = pci_dev_to_dev(pdev); 685 struct ata_ioports *ioaddr = &host->ports[i]->ioaddr;
667 probe_ent->port_ops = sil_port_info[ent->driver_data].port_ops; 686
668 probe_ent->sht = sil_port_info[ent->driver_data].sht; 687 ioaddr->cmd_addr = mmio_base + sil_port[i].tf;
669 probe_ent->n_ports = (ent->driver_data == sil_3114) ? 4 : 2; 688 ioaddr->altstatus_addr =
670 probe_ent->pio_mask = sil_port_info[ent->driver_data].pio_mask; 689 ioaddr->ctl_addr = mmio_base + sil_port[i].ctl;
671 probe_ent->mwdma_mask = sil_port_info[ent->driver_data].mwdma_mask; 690 ioaddr->bmdma_addr = mmio_base + sil_port[i].bmdma;
672 probe_ent->udma_mask = sil_port_info[ent->driver_data].udma_mask; 691 ioaddr->scr_addr = mmio_base + sil_port[i].scr;
673 probe_ent->irq = pdev->irq; 692 ata_std_ports(ioaddr);
674 probe_ent->irq_flags = IRQF_SHARED;
675 probe_ent->port_flags = sil_port_info[ent->driver_data].flags;
676
677 probe_ent->iomap = pcim_iomap_table(pdev);
678
679 mmio_base = probe_ent->iomap[SIL_MMIO_BAR];
680
681 for (i = 0; i < probe_ent->n_ports; i++) {
682 probe_ent->port[i].cmd_addr = mmio_base + sil_port[i].tf;
683 probe_ent->port[i].altstatus_addr =
684 probe_ent->port[i].ctl_addr = mmio_base + sil_port[i].ctl;
685 probe_ent->port[i].bmdma_addr = mmio_base + sil_port[i].bmdma;
686 probe_ent->port[i].scr_addr = mmio_base + sil_port[i].scr;
687 ata_std_ports(&probe_ent->port[i]);
688 } 693 }
689 694
690 sil_init_controller(pdev, probe_ent->n_ports, probe_ent->port_flags, 695 /* initialize and activate */
691 mmio_base); 696 sil_init_controller(host);
692 697
693 pci_set_master(pdev); 698 pci_set_master(pdev);
694 699 return ata_host_activate(host, pdev->irq, sil_interrupt, IRQF_SHARED,
695 if (!ata_device_add(probe_ent)) 700 &sil_sht);
696 return -ENODEV;
697
698 devm_kfree(dev, probe_ent);
699 return 0;
700} 701}
701 702
702#ifdef CONFIG_PM 703#ifdef CONFIG_PM
@@ -709,8 +710,7 @@ static int sil_pci_device_resume(struct pci_dev *pdev)
709 if (rc) 710 if (rc)
710 return rc; 711 return rc;
711 712
712 sil_init_controller(pdev, host->n_ports, host->ports[0]->flags, 713 sil_init_controller(host);
713 host->iomap[SIL_MMIO_BAR]);
714 ata_host_resume(host); 714 ata_host_resume(host);
715 715
716 return 0; 716 return 0;
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 5614df8c1ce2..e6223ba667da 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -323,7 +323,7 @@ struct sil24_port_priv {
323 struct ata_taskfile tf; /* Cached taskfile registers */ 323 struct ata_taskfile tf; /* Cached taskfile registers */
324}; 324};
325 325
326static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev); 326static void sil24_dev_config(struct ata_device *dev);
327static u8 sil24_check_status(struct ata_port *ap); 327static u8 sil24_check_status(struct ata_port *ap);
328static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 328static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
329static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 329static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
@@ -331,7 +331,6 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
331static void sil24_qc_prep(struct ata_queued_cmd *qc); 331static void sil24_qc_prep(struct ata_queued_cmd *qc);
332static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); 332static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
333static void sil24_irq_clear(struct ata_port *ap); 333static void sil24_irq_clear(struct ata_port *ap);
334static irqreturn_t sil24_interrupt(int irq, void *dev_instance);
335static void sil24_freeze(struct ata_port *ap); 334static void sil24_freeze(struct ata_port *ap);
336static void sil24_thaw(struct ata_port *ap); 335static void sil24_thaw(struct ata_port *ap);
337static void sil24_error_handler(struct ata_port *ap); 336static void sil24_error_handler(struct ata_port *ap);
@@ -401,7 +400,6 @@ static const struct ata_port_operations sil24_ops = {
401 .qc_prep = sil24_qc_prep, 400 .qc_prep = sil24_qc_prep,
402 .qc_issue = sil24_qc_issue, 401 .qc_issue = sil24_qc_issue,
403 402
404 .irq_handler = sil24_interrupt,
405 .irq_clear = sil24_irq_clear, 403 .irq_clear = sil24_irq_clear,
406 .irq_on = ata_dummy_irq_on, 404 .irq_on = ata_dummy_irq_on,
407 .irq_ack = ata_dummy_irq_ack, 405 .irq_ack = ata_dummy_irq_ack,
@@ -424,10 +422,9 @@ static const struct ata_port_operations sil24_ops = {
424#define SIL24_NPORTS2FLAG(nports) ((((unsigned)(nports) - 1) & 0x3) << 30) 422#define SIL24_NPORTS2FLAG(nports) ((((unsigned)(nports) - 1) & 0x3) << 30)
425#define SIL24_FLAG2NPORTS(flag) ((((flag) >> 30) & 0x3) + 1) 423#define SIL24_FLAG2NPORTS(flag) ((((flag) >> 30) & 0x3) + 1)
426 424
427static struct ata_port_info sil24_port_info[] = { 425static const struct ata_port_info sil24_port_info[] = {
428 /* sil_3124 */ 426 /* sil_3124 */
429 { 427 {
430 .sht = &sil24_sht,
431 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) | 428 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) |
432 SIL24_FLAG_PCIX_IRQ_WOC, 429 SIL24_FLAG_PCIX_IRQ_WOC,
433 .pio_mask = 0x1f, /* pio0-4 */ 430 .pio_mask = 0x1f, /* pio0-4 */
@@ -437,7 +434,6 @@ static struct ata_port_info sil24_port_info[] = {
437 }, 434 },
438 /* sil_3132 */ 435 /* sil_3132 */
439 { 436 {
440 .sht = &sil24_sht,
441 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2), 437 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2),
442 .pio_mask = 0x1f, /* pio0-4 */ 438 .pio_mask = 0x1f, /* pio0-4 */
443 .mwdma_mask = 0x07, /* mwdma0-2 */ 439 .mwdma_mask = 0x07, /* mwdma0-2 */
@@ -446,7 +442,6 @@ static struct ata_port_info sil24_port_info[] = {
446 }, 442 },
447 /* sil_3131/sil_3531 */ 443 /* sil_3131/sil_3531 */
448 { 444 {
449 .sht = &sil24_sht,
450 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1), 445 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1),
451 .pio_mask = 0x1f, /* pio0-4 */ 446 .pio_mask = 0x1f, /* pio0-4 */
452 .mwdma_mask = 0x07, /* mwdma0-2 */ 447 .mwdma_mask = 0x07, /* mwdma0-2 */
@@ -462,9 +457,9 @@ static int sil24_tag(int tag)
462 return tag; 457 return tag;
463} 458}
464 459
465static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev) 460static void sil24_dev_config(struct ata_device *dev)
466{ 461{
467 void __iomem *port = ap->ioaddr.cmd_addr; 462 void __iomem *port = dev->ap->ioaddr.cmd_addr;
468 463
469 if (dev->cdb_len == 16) 464 if (dev->cdb_len == 16)
470 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT); 465 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT);
@@ -924,11 +919,8 @@ static void sil24_post_internal_cmd(struct ata_queued_cmd *qc)
924{ 919{
925 struct ata_port *ap = qc->ap; 920 struct ata_port *ap = qc->ap;
926 921
927 if (qc->flags & ATA_QCFLAG_FAILED)
928 qc->err_mask |= AC_ERR_OTHER;
929
930 /* make DMA engine forget about the failed command */ 922 /* make DMA engine forget about the failed command */
931 if (qc->err_mask) 923 if (qc->flags & ATA_QCFLAG_FAILED)
932 sil24_init_port(ap); 924 sil24_init_port(ap);
933} 925}
934 926
@@ -964,11 +956,10 @@ static int sil24_port_start(struct ata_port *ap)
964 return 0; 956 return 0;
965} 957}
966 958
967static void sil24_init_controller(struct pci_dev *pdev, int n_ports, 959static void sil24_init_controller(struct ata_host *host)
968 unsigned long port_flags,
969 void __iomem *host_base,
970 void __iomem *port_base)
971{ 960{
961 void __iomem *host_base = host->iomap[SIL24_HOST_BAR];
962 void __iomem *port_base = host->iomap[SIL24_PORT_BAR];
972 u32 tmp; 963 u32 tmp;
973 int i; 964 int i;
974 965
@@ -979,7 +970,7 @@ static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
979 writel(0, host_base + HOST_CTRL); 970 writel(0, host_base + HOST_CTRL);
980 971
981 /* init ports */ 972 /* init ports */
982 for (i = 0; i < n_ports; i++) { 973 for (i = 0; i < host->n_ports; i++) {
983 void __iomem *port = port_base + i * PORT_REGS_SIZE; 974 void __iomem *port = port_base + i * PORT_REGS_SIZE;
984 975
985 /* Initial PHY setting */ 976 /* Initial PHY setting */
@@ -993,12 +984,12 @@ static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
993 PORT_CS_PORT_RST, 984 PORT_CS_PORT_RST,
994 PORT_CS_PORT_RST, 10, 100); 985 PORT_CS_PORT_RST, 10, 100);
995 if (tmp & PORT_CS_PORT_RST) 986 if (tmp & PORT_CS_PORT_RST)
996 dev_printk(KERN_ERR, &pdev->dev, 987 dev_printk(KERN_ERR, host->dev,
997 "failed to clear port RST\n"); 988 "failed to clear port RST\n");
998 } 989 }
999 990
1000 /* Configure IRQ WoC */ 991 /* Configure IRQ WoC */
1001 if (port_flags & SIL24_FLAG_PCIX_IRQ_WOC) 992 if (host->ports[0]->flags & SIL24_FLAG_PCIX_IRQ_WOC)
1002 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT); 993 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1003 else 994 else
1004 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR); 995 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
@@ -1026,18 +1017,17 @@ static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
1026static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1017static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1027{ 1018{
1028 static int printed_version = 0; 1019 static int printed_version = 0;
1029 struct device *dev = &pdev->dev; 1020 struct ata_port_info pi = sil24_port_info[ent->driver_data];
1030 unsigned int board_id = (unsigned int)ent->driver_data; 1021 const struct ata_port_info *ppi[] = { &pi, NULL };
1031 struct ata_port_info *pinfo = &sil24_port_info[board_id]; 1022 void __iomem * const *iomap;
1032 struct ata_probe_ent *probe_ent; 1023 struct ata_host *host;
1033 void __iomem *host_base;
1034 void __iomem *port_base;
1035 int i, rc; 1024 int i, rc;
1036 u32 tmp; 1025 u32 tmp;
1037 1026
1038 if (!printed_version++) 1027 if (!printed_version++)
1039 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1028 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1040 1029
1030 /* acquire resources */
1041 rc = pcim_enable_device(pdev); 1031 rc = pcim_enable_device(pdev);
1042 if (rc) 1032 if (rc)
1043 return rc; 1033 return rc;
@@ -1047,33 +1037,36 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1047 DRV_NAME); 1037 DRV_NAME);
1048 if (rc) 1038 if (rc)
1049 return rc; 1039 return rc;
1040 iomap = pcim_iomap_table(pdev);
1050 1041
1051 /* allocate & init probe_ent */ 1042 /* apply workaround for completion IRQ loss on PCI-X errata */
1052 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL); 1043 if (pi.flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1053 if (!probe_ent) 1044 tmp = readl(iomap[SIL24_HOST_BAR] + HOST_CTRL);
1054 return -ENOMEM; 1045 if (tmp & (HOST_CTRL_TRDY | HOST_CTRL_STOP | HOST_CTRL_DEVSEL))
1046 dev_printk(KERN_INFO, &pdev->dev,
1047 "Applying completion IRQ loss on PCI-X "
1048 "errata fix\n");
1049 else
1050 pi.flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1051 }
1055 1052
1056 probe_ent->dev = pci_dev_to_dev(pdev); 1053 /* allocate and fill host */
1057 INIT_LIST_HEAD(&probe_ent->node); 1054 host = ata_host_alloc_pinfo(&pdev->dev, ppi,
1055 SIL24_FLAG2NPORTS(ppi[0]->flags));
1056 if (!host)
1057 return -ENOMEM;
1058 host->iomap = iomap;
1058 1059
1059 probe_ent->sht = pinfo->sht; 1060 for (i = 0; i < host->n_ports; i++) {
1060 probe_ent->port_flags = pinfo->flags; 1061 void __iomem *port = iomap[SIL24_PORT_BAR] + i * PORT_REGS_SIZE;
1061 probe_ent->pio_mask = pinfo->pio_mask;
1062 probe_ent->mwdma_mask = pinfo->mwdma_mask;
1063 probe_ent->udma_mask = pinfo->udma_mask;
1064 probe_ent->port_ops = pinfo->port_ops;
1065 probe_ent->n_ports = SIL24_FLAG2NPORTS(pinfo->flags);
1066 1062
1067 probe_ent->irq = pdev->irq; 1063 host->ports[i]->ioaddr.cmd_addr = port;
1068 probe_ent->irq_flags = IRQF_SHARED; 1064 host->ports[i]->ioaddr.scr_addr = port + PORT_SCONTROL;
1069 probe_ent->iomap = pcim_iomap_table(pdev);
1070 1065
1071 host_base = probe_ent->iomap[SIL24_HOST_BAR]; 1066 ata_std_ports(&host->ports[i]->ioaddr);
1072 port_base = probe_ent->iomap[SIL24_PORT_BAR]; 1067 }
1073 1068
1074 /* 1069 /* configure and activate the device */
1075 * Configure the device
1076 */
1077 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 1070 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1078 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 1071 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1079 if (rc) { 1072 if (rc) {
@@ -1099,36 +1092,11 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1099 } 1092 }
1100 } 1093 }
1101 1094
1102 /* Apply workaround for completion IRQ loss on PCI-X errata */ 1095 sil24_init_controller(host);
1103 if (probe_ent->port_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1104 tmp = readl(host_base + HOST_CTRL);
1105 if (tmp & (HOST_CTRL_TRDY | HOST_CTRL_STOP | HOST_CTRL_DEVSEL))
1106 dev_printk(KERN_INFO, &pdev->dev,
1107 "Applying completion IRQ loss on PCI-X "
1108 "errata fix\n");
1109 else
1110 probe_ent->port_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1111 }
1112
1113 for (i = 0; i < probe_ent->n_ports; i++) {
1114 void __iomem *port = port_base + i * PORT_REGS_SIZE;
1115
1116 probe_ent->port[i].cmd_addr = port;
1117 probe_ent->port[i].scr_addr = port + PORT_SCONTROL;
1118
1119 ata_std_ports(&probe_ent->port[i]);
1120 }
1121
1122 sil24_init_controller(pdev, probe_ent->n_ports, probe_ent->port_flags,
1123 host_base, port_base);
1124 1096
1125 pci_set_master(pdev); 1097 pci_set_master(pdev);
1126 1098 return ata_host_activate(host, pdev->irq, sil24_interrupt, IRQF_SHARED,
1127 if (!ata_device_add(probe_ent)) 1099 &sil24_sht);
1128 return -ENODEV;
1129
1130 devm_kfree(dev, probe_ent);
1131 return 0;
1132} 1100}
1133 1101
1134#ifdef CONFIG_PM 1102#ifdef CONFIG_PM
@@ -1136,7 +1104,6 @@ static int sil24_pci_device_resume(struct pci_dev *pdev)
1136{ 1104{
1137 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1105 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1138 void __iomem *host_base = host->iomap[SIL24_HOST_BAR]; 1106 void __iomem *host_base = host->iomap[SIL24_HOST_BAR];
1139 void __iomem *port_base = host->iomap[SIL24_PORT_BAR];
1140 int rc; 1107 int rc;
1141 1108
1142 rc = ata_pci_device_do_resume(pdev); 1109 rc = ata_pci_device_do_resume(pdev);
@@ -1146,8 +1113,7 @@ static int sil24_pci_device_resume(struct pci_dev *pdev)
1146 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) 1113 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
1147 writel(HOST_CTRL_GLOBAL_RST, host_base + HOST_CTRL); 1114 writel(HOST_CTRL_GLOBAL_RST, host_base + HOST_CTRL);
1148 1115
1149 sil24_init_controller(pdev, host->n_ports, host->ports[0]->flags, 1116 sil24_init_controller(host);
1150 host_base, port_base);
1151 1117
1152 ata_host_resume(host); 1118 ata_host_resume(host);
1153 1119
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index a787f0d4a5ba..d8ee062e82fc 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -121,7 +121,6 @@ static const struct ata_port_operations sis_ops = {
121 .thaw = ata_bmdma_thaw, 121 .thaw = ata_bmdma_thaw,
122 .error_handler = ata_bmdma_error_handler, 122 .error_handler = ata_bmdma_error_handler,
123 .post_internal_cmd = ata_bmdma_post_internal_cmd, 123 .post_internal_cmd = ata_bmdma_post_internal_cmd,
124 .irq_handler = ata_interrupt,
125 .irq_clear = ata_bmdma_irq_clear, 124 .irq_clear = ata_bmdma_irq_clear,
126 .irq_on = ata_irq_on, 125 .irq_on = ata_irq_on,
127 .irq_ack = ata_irq_ack, 126 .irq_ack = ata_irq_ack,
@@ -131,7 +130,6 @@ static const struct ata_port_operations sis_ops = {
131}; 130};
132 131
133static struct ata_port_info sis_port_info = { 132static struct ata_port_info sis_port_info = {
134 .sht = &sis_sht,
135 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 133 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
136 .pio_mask = 0x1f, 134 .pio_mask = 0x1f,
137 .mwdma_mask = 0x7, 135 .mwdma_mask = 0x7,
@@ -256,12 +254,13 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
256static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 254static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
257{ 255{
258 static int printed_version; 256 static int printed_version;
259 struct ata_probe_ent *probe_ent = NULL; 257 struct ata_port_info pi = sis_port_info;
260 int rc; 258 const struct ata_port_info *ppi[2] = { &pi, &pi };
259 struct ata_host *host;
261 u32 genctl, val; 260 u32 genctl, val;
262 struct ata_port_info pi = sis_port_info, *ppi[2] = { &pi, &pi };
263 u8 pmr; 261 u8 pmr;
264 u8 port2_start = 0x20; 262 u8 port2_start = 0x20;
263 int rc;
265 264
266 if (!printed_version++) 265 if (!printed_version++)
267 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 266 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
@@ -270,19 +269,6 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
270 if (rc) 269 if (rc)
271 return rc; 270 return rc;
272 271
273 rc = pci_request_regions(pdev, DRV_NAME);
274 if (rc) {
275 pcim_pin_device(pdev);
276 return rc;
277 }
278
279 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
280 if (rc)
281 return rc;
282 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
283 if (rc)
284 return rc;
285
286 /* check and see if the SCRs are in IO space or PCI cfg space */ 272 /* check and see if the SCRs are in IO space or PCI cfg space */
287 pci_read_config_dword(pdev, SIS_GENCTL, &genctl); 273 pci_read_config_dword(pdev, SIS_GENCTL, &genctl);
288 if ((genctl & GENCTL_IOMAPPED_SCR) == 0) 274 if ((genctl & GENCTL_IOMAPPED_SCR) == 0)
@@ -349,30 +335,26 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
349 break; 335 break;
350 } 336 }
351 337
352 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 338 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host);
353 if (!probe_ent) 339 if (rc)
354 return -ENOMEM; 340 return rc;
355 341
356 if (!(probe_ent->port_flags & SIS_FLAG_CFGSCR)) { 342 if (!(pi.flags & SIS_FLAG_CFGSCR)) {
357 void __iomem *mmio; 343 void __iomem *mmio;
358 344
359 mmio = pcim_iomap(pdev, SIS_SCR_PCI_BAR, 0); 345 rc = pcim_iomap_regions(pdev, 1 << SIS_SCR_PCI_BAR, DRV_NAME);
360 if (!mmio) 346 if (rc)
361 return -ENOMEM; 347 return rc;
348 mmio = host->iomap[SIS_SCR_PCI_BAR];
362 349
363 probe_ent->port[0].scr_addr = mmio; 350 host->ports[0]->ioaddr.scr_addr = mmio;
364 probe_ent->port[1].scr_addr = mmio + port2_start; 351 host->ports[1]->ioaddr.scr_addr = mmio + port2_start;
365 } 352 }
366 353
367 pci_set_master(pdev); 354 pci_set_master(pdev);
368 pci_intx(pdev, 1); 355 pci_intx(pdev, 1);
369 356 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
370 if (!ata_device_add(probe_ent)) 357 &sis_sht);
371 return -EIO;
372
373 devm_kfree(&pdev->dev, probe_ent);
374 return 0;
375
376} 358}
377 359
378static int __init sis_init(void) 360static int __init sis_init(void)
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index b121195cc598..cc07aac10e8c 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -56,7 +56,9 @@
56#define DRV_VERSION "2.1" 56#define DRV_VERSION "2.1"
57 57
58enum { 58enum {
59 K2_FLAG_NO_ATAPI_DMA = (1 << 29), 59 /* ap->flags bits */
60 K2_FLAG_SATA_8_PORTS = (1 << 24),
61 K2_FLAG_NO_ATAPI_DMA = (1 << 25),
60 62
61 /* Taskfile registers offsets */ 63 /* Taskfile registers offsets */
62 K2_SATA_TF_CMD_OFFSET = 0x00, 64 K2_SATA_TF_CMD_OFFSET = 0x00,
@@ -90,17 +92,6 @@ enum {
90 board_svw8 = 1, 92 board_svw8 = 1,
91}; 93};
92 94
93static const struct k2_board_info {
94 unsigned int n_ports;
95 unsigned long port_flags;
96} k2_board_info[] = {
97 /* board_svw4 */
98 { 4, K2_FLAG_NO_ATAPI_DMA },
99
100 /* board_svw8 */
101 { 8, K2_FLAG_NO_ATAPI_DMA },
102};
103
104static u8 k2_stat_check_status(struct ata_port *ap); 95static u8 k2_stat_check_status(struct ata_port *ap);
105 96
106 97
@@ -354,7 +345,6 @@ static const struct ata_port_operations k2_sata_ops = {
354 .thaw = ata_bmdma_thaw, 345 .thaw = ata_bmdma_thaw,
355 .error_handler = ata_bmdma_error_handler, 346 .error_handler = ata_bmdma_error_handler,
356 .post_internal_cmd = ata_bmdma_post_internal_cmd, 347 .post_internal_cmd = ata_bmdma_post_internal_cmd,
357 .irq_handler = ata_interrupt,
358 .irq_clear = ata_bmdma_irq_clear, 348 .irq_clear = ata_bmdma_irq_clear,
359 .irq_on = ata_irq_on, 349 .irq_on = ata_irq_on,
360 .irq_ack = ata_irq_ack, 350 .irq_ack = ata_irq_ack,
@@ -363,6 +353,28 @@ static const struct ata_port_operations k2_sata_ops = {
363 .port_start = ata_port_start, 353 .port_start = ata_port_start,
364}; 354};
365 355
356static const struct ata_port_info k2_port_info[] = {
357 /* board_svw4 */
358 {
359 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
360 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA,
361 .pio_mask = 0x1f,
362 .mwdma_mask = 0x07,
363 .udma_mask = 0x7f,
364 .port_ops = &k2_sata_ops,
365 },
366 /* board_svw8 */
367 {
368 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
369 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA |
370 K2_FLAG_SATA_8_PORTS,
371 .pio_mask = 0x1f,
372 .mwdma_mask = 0x07,
373 .udma_mask = 0x7f,
374 .port_ops = &k2_sata_ops,
375 },
376};
377
366static void k2_sata_setup_port(struct ata_ioports *port, void __iomem *base) 378static void k2_sata_setup_port(struct ata_ioports *port, void __iomem *base)
367{ 379{
368 port->cmd_addr = base + K2_SATA_TF_CMD_OFFSET; 380 port->cmd_addr = base + K2_SATA_TF_CMD_OFFSET;
@@ -386,17 +398,24 @@ static void k2_sata_setup_port(struct ata_ioports *port, void __iomem *base)
386static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 398static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
387{ 399{
388 static int printed_version; 400 static int printed_version;
389 struct device *dev = &pdev->dev; 401 const struct ata_port_info *ppi[] =
390 struct ata_probe_ent *probe_ent; 402 { &k2_port_info[ent->driver_data], NULL };
403 struct ata_host *host;
391 void __iomem *mmio_base; 404 void __iomem *mmio_base;
392 const struct k2_board_info *board_info = 405 int n_ports, i, rc;
393 &k2_board_info[ent->driver_data];
394 int rc;
395 int i;
396 406
397 if (!printed_version++) 407 if (!printed_version++)
398 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 408 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
399 409
410 /* allocate host */
411 n_ports = 4;
412 if (ppi[0]->flags & K2_FLAG_SATA_8_PORTS)
413 n_ports = 8;
414
415 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
416 if (!host)
417 return -ENOMEM;
418
400 /* 419 /*
401 * If this driver happens to only be useful on Apple's K2, then 420 * If this driver happens to only be useful on Apple's K2, then
402 * we should check that here as it has a normal Serverworks ID 421 * we should check that here as it has a normal Serverworks ID
@@ -404,6 +423,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
404 rc = pcim_enable_device(pdev); 423 rc = pcim_enable_device(pdev);
405 if (rc) 424 if (rc)
406 return rc; 425 return rc;
426
407 /* 427 /*
408 * Check if we have resources mapped at all (second function may 428 * Check if we have resources mapped at all (second function may
409 * have been disabled by firmware) 429 * have been disabled by firmware)
@@ -417,6 +437,15 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
417 pcim_pin_device(pdev); 437 pcim_pin_device(pdev);
418 if (rc) 438 if (rc)
419 return rc; 439 return rc;
440 host->iomap = pcim_iomap_table(pdev);
441 mmio_base = host->iomap[5];
442
443 /* different controllers have different number of ports - currently 4 or 8 */
444 /* All ports are on the same function. Multi-function device is no
445 * longer available. This should not be seen in any system. */
446 for (i = 0; i < host->n_ports; i++)
447 k2_sata_setup_port(&host->ports[i]->ioaddr,
448 mmio_base + i * K2_SATA_PORT_OFFSET);
420 449
421 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 450 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
422 if (rc) 451 if (rc)
@@ -425,38 +454,6 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
425 if (rc) 454 if (rc)
426 return rc; 455 return rc;
427 456
428 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
429 if (probe_ent == NULL)
430 return -ENOMEM;
431
432 probe_ent->dev = pci_dev_to_dev(pdev);
433 INIT_LIST_HEAD(&probe_ent->node);
434
435 probe_ent->sht = &k2_sata_sht;
436 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
437 ATA_FLAG_MMIO | board_info->port_flags;
438 probe_ent->port_ops = &k2_sata_ops;
439 probe_ent->n_ports = 4;
440 probe_ent->irq = pdev->irq;
441 probe_ent->irq_flags = IRQF_SHARED;
442 probe_ent->iomap = pcim_iomap_table(pdev);
443
444 /* We don't care much about the PIO/UDMA masks, but the core won't like us
445 * if we don't fill these
446 */
447 probe_ent->pio_mask = 0x1f;
448 probe_ent->mwdma_mask = 0x7;
449 probe_ent->udma_mask = 0x7f;
450
451 mmio_base = probe_ent->iomap[5];
452
453 /* different controllers have different number of ports - currently 4 or 8 */
454 /* All ports are on the same function. Multi-function device is no
455 * longer available. This should not be seen in any system. */
456 for (i = 0; i < board_info->n_ports; i++)
457 k2_sata_setup_port(&probe_ent->port[i],
458 mmio_base + i * K2_SATA_PORT_OFFSET);
459
460 /* Clear a magic bit in SCR1 according to Darwin, those help 457 /* Clear a magic bit in SCR1 according to Darwin, those help
461 * some funky seagate drives (though so far, those were already 458 * some funky seagate drives (though so far, those were already
462 * set by the firmware on the machines I had access to) 459 * set by the firmware on the machines I had access to)
@@ -469,12 +466,8 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
469 writel(0x0, mmio_base + K2_SATA_SIM_OFFSET); 466 writel(0x0, mmio_base + K2_SATA_SIM_OFFSET);
470 467
471 pci_set_master(pdev); 468 pci_set_master(pdev);
472 469 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
473 if (!ata_device_add(probe_ent)) 470 &k2_sata_sht);
474 return -ENODEV;
475
476 devm_kfree(dev, probe_ent);
477 return 0;
478} 471}
479 472
480/* 0x240 is device ID for Apple K2 device 473/* 0x240 is device ID for Apple K2 device
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index 1a081c3a8c06..3a4f44559d0a 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -151,24 +151,23 @@ struct pdc_host_priv {
151 151
152 152
153static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 153static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
154static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance);
155static void pdc_eng_timeout(struct ata_port *ap); 154static void pdc_eng_timeout(struct ata_port *ap);
156static void pdc_20621_phy_reset (struct ata_port *ap); 155static void pdc_20621_phy_reset (struct ata_port *ap);
157static int pdc_port_start(struct ata_port *ap); 156static int pdc_port_start(struct ata_port *ap);
158static void pdc20621_qc_prep(struct ata_queued_cmd *qc); 157static void pdc20621_qc_prep(struct ata_queued_cmd *qc);
159static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 158static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
160static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 159static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
161static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe); 160static unsigned int pdc20621_dimm_init(struct ata_host *host);
162static int pdc20621_detect_dimm(struct ata_probe_ent *pe); 161static int pdc20621_detect_dimm(struct ata_host *host);
163static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, 162static unsigned int pdc20621_i2c_read(struct ata_host *host,
164 u32 device, u32 subaddr, u32 *pdata); 163 u32 device, u32 subaddr, u32 *pdata);
165static int pdc20621_prog_dimm0(struct ata_probe_ent *pe); 164static int pdc20621_prog_dimm0(struct ata_host *host);
166static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe); 165static unsigned int pdc20621_prog_dimm_global(struct ata_host *host);
167#ifdef ATA_VERBOSE_DEBUG 166#ifdef ATA_VERBOSE_DEBUG
168static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, 167static void pdc20621_get_from_dimm(struct ata_host *host,
169 void *psource, u32 offset, u32 size); 168 void *psource, u32 offset, u32 size);
170#endif 169#endif
171static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, 170static void pdc20621_put_to_dimm(struct ata_host *host,
172 void *psource, u32 offset, u32 size); 171 void *psource, u32 offset, u32 size);
173static void pdc20621_irq_clear(struct ata_port *ap); 172static void pdc20621_irq_clear(struct ata_port *ap);
174static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc); 173static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
@@ -204,7 +203,6 @@ static const struct ata_port_operations pdc_20621_ops = {
204 .qc_issue = pdc20621_qc_issue_prot, 203 .qc_issue = pdc20621_qc_issue_prot,
205 .data_xfer = ata_data_xfer, 204 .data_xfer = ata_data_xfer,
206 .eng_timeout = pdc_eng_timeout, 205 .eng_timeout = pdc_eng_timeout,
207 .irq_handler = pdc20621_interrupt,
208 .irq_clear = pdc20621_irq_clear, 206 .irq_clear = pdc20621_irq_clear,
209 .irq_on = ata_irq_on, 207 .irq_on = ata_irq_on,
210 .irq_ack = ata_irq_ack, 208 .irq_ack = ata_irq_ack,
@@ -214,7 +212,6 @@ static const struct ata_port_operations pdc_20621_ops = {
214static const struct ata_port_info pdc_port_info[] = { 212static const struct ata_port_info pdc_port_info[] = {
215 /* board_20621 */ 213 /* board_20621 */
216 { 214 {
217 .sht = &pdc_sata_sht,
218 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 215 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
219 ATA_FLAG_SRST | ATA_FLAG_MMIO | 216 ATA_FLAG_SRST | ATA_FLAG_MMIO |
220 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING, 217 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
@@ -882,15 +879,15 @@ static void pdc_sata_setup_port(struct ata_ioports *port, void __iomem *base)
882 879
883 880
884#ifdef ATA_VERBOSE_DEBUG 881#ifdef ATA_VERBOSE_DEBUG
885static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, void *psource, 882static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
886 u32 offset, u32 size) 883 u32 offset, u32 size)
887{ 884{
888 u32 window_size; 885 u32 window_size;
889 u16 idx; 886 u16 idx;
890 u8 page_mask; 887 u8 page_mask;
891 long dist; 888 long dist;
892 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 889 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
893 void __iomem *dimm_mmio = pe->iomap[PDC_DIMM_BAR]; 890 void __iomem *dimm_mmio = host->iomap[PDC_DIMM_BAR];
894 891
895 /* hard-code chip #0 */ 892 /* hard-code chip #0 */
896 mmio += PDC_CHIP0_OFS; 893 mmio += PDC_CHIP0_OFS;
@@ -937,15 +934,15 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, void *psource,
937#endif 934#endif
938 935
939 936
940static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource, 937static void pdc20621_put_to_dimm(struct ata_host *host, void *psource,
941 u32 offset, u32 size) 938 u32 offset, u32 size)
942{ 939{
943 u32 window_size; 940 u32 window_size;
944 u16 idx; 941 u16 idx;
945 u8 page_mask; 942 u8 page_mask;
946 long dist; 943 long dist;
947 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 944 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
948 void __iomem *dimm_mmio = pe->iomap[PDC_DIMM_BAR]; 945 void __iomem *dimm_mmio = host->iomap[PDC_DIMM_BAR];
949 946
950 /* hard-code chip #0 */ 947 /* hard-code chip #0 */
951 mmio += PDC_CHIP0_OFS; 948 mmio += PDC_CHIP0_OFS;
@@ -987,10 +984,10 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
987} 984}
988 985
989 986
990static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device, 987static unsigned int pdc20621_i2c_read(struct ata_host *host, u32 device,
991 u32 subaddr, u32 *pdata) 988 u32 subaddr, u32 *pdata)
992{ 989{
993 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 990 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
994 u32 i2creg = 0; 991 u32 i2creg = 0;
995 u32 status; 992 u32 status;
996 u32 count =0; 993 u32 count =0;
@@ -1023,17 +1020,17 @@ static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device,
1023} 1020}
1024 1021
1025 1022
1026static int pdc20621_detect_dimm(struct ata_probe_ent *pe) 1023static int pdc20621_detect_dimm(struct ata_host *host)
1027{ 1024{
1028 u32 data=0 ; 1025 u32 data=0 ;
1029 if (pdc20621_i2c_read(pe, PDC_DIMM0_SPD_DEV_ADDRESS, 1026 if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1030 PDC_DIMM_SPD_SYSTEM_FREQ, &data)) { 1027 PDC_DIMM_SPD_SYSTEM_FREQ, &data)) {
1031 if (data == 100) 1028 if (data == 100)
1032 return 100; 1029 return 100;
1033 } else 1030 } else
1034 return 0; 1031 return 0;
1035 1032
1036 if (pdc20621_i2c_read(pe, PDC_DIMM0_SPD_DEV_ADDRESS, 9, &data)) { 1033 if (pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS, 9, &data)) {
1037 if(data <= 0x75) 1034 if(data <= 0x75)
1038 return 133; 1035 return 133;
1039 } else 1036 } else
@@ -1043,13 +1040,13 @@ static int pdc20621_detect_dimm(struct ata_probe_ent *pe)
1043} 1040}
1044 1041
1045 1042
1046static int pdc20621_prog_dimm0(struct ata_probe_ent *pe) 1043static int pdc20621_prog_dimm0(struct ata_host *host)
1047{ 1044{
1048 u32 spd0[50]; 1045 u32 spd0[50];
1049 u32 data = 0; 1046 u32 data = 0;
1050 int size, i; 1047 int size, i;
1051 u8 bdimmsize; 1048 u8 bdimmsize;
1052 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 1049 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
1053 static const struct { 1050 static const struct {
1054 unsigned int reg; 1051 unsigned int reg;
1055 unsigned int ofs; 1052 unsigned int ofs;
@@ -1072,7 +1069,7 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe)
1072 mmio += PDC_CHIP0_OFS; 1069 mmio += PDC_CHIP0_OFS;
1073 1070
1074 for(i=0; i<ARRAY_SIZE(pdc_i2c_read_data); i++) 1071 for(i=0; i<ARRAY_SIZE(pdc_i2c_read_data); i++)
1075 pdc20621_i2c_read(pe, PDC_DIMM0_SPD_DEV_ADDRESS, 1072 pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1076 pdc_i2c_read_data[i].reg, 1073 pdc_i2c_read_data[i].reg,
1077 &spd0[pdc_i2c_read_data[i].ofs]); 1074 &spd0[pdc_i2c_read_data[i].ofs]);
1078 1075
@@ -1108,11 +1105,11 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe)
1108} 1105}
1109 1106
1110 1107
1111static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe) 1108static unsigned int pdc20621_prog_dimm_global(struct ata_host *host)
1112{ 1109{
1113 u32 data, spd0; 1110 u32 data, spd0;
1114 int error, i; 1111 int error, i;
1115 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 1112 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
1116 1113
1117 /* hard-code chip #0 */ 1114 /* hard-code chip #0 */
1118 mmio += PDC_CHIP0_OFS; 1115 mmio += PDC_CHIP0_OFS;
@@ -1129,7 +1126,7 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe)
1129 readl(mmio + PDC_SDRAM_CONTROL_OFFSET); 1126 readl(mmio + PDC_SDRAM_CONTROL_OFFSET);
1130 1127
1131 /* Turn on for ECC */ 1128 /* Turn on for ECC */
1132 pdc20621_i2c_read(pe, PDC_DIMM0_SPD_DEV_ADDRESS, 1129 pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1133 PDC_DIMM_SPD_TYPE, &spd0); 1130 PDC_DIMM_SPD_TYPE, &spd0);
1134 if (spd0 == 0x02) { 1131 if (spd0 == 0x02) {
1135 data |= (0x01 << 16); 1132 data |= (0x01 << 16);
@@ -1156,7 +1153,7 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe)
1156} 1153}
1157 1154
1158 1155
1159static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe) 1156static unsigned int pdc20621_dimm_init(struct ata_host *host)
1160{ 1157{
1161 int speed, size, length; 1158 int speed, size, length;
1162 u32 addr,spd0,pci_status; 1159 u32 addr,spd0,pci_status;
@@ -1166,7 +1163,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1166 u32 ticks=0; 1163 u32 ticks=0;
1167 u32 clock=0; 1164 u32 clock=0;
1168 u32 fparam=0; 1165 u32 fparam=0;
1169 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 1166 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
1170 1167
1171 /* hard-code chip #0 */ 1168 /* hard-code chip #0 */
1172 mmio += PDC_CHIP0_OFS; 1169 mmio += PDC_CHIP0_OFS;
@@ -1225,18 +1222,18 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1225 Read SPD of DIMM by I2C interface, 1222 Read SPD of DIMM by I2C interface,
1226 and program the DIMM Module Controller. 1223 and program the DIMM Module Controller.
1227 */ 1224 */
1228 if (!(speed = pdc20621_detect_dimm(pe))) { 1225 if (!(speed = pdc20621_detect_dimm(host))) {
1229 printk(KERN_ERR "Detect Local DIMM Fail\n"); 1226 printk(KERN_ERR "Detect Local DIMM Fail\n");
1230 return 1; /* DIMM error */ 1227 return 1; /* DIMM error */
1231 } 1228 }
1232 VPRINTK("Local DIMM Speed = %d\n", speed); 1229 VPRINTK("Local DIMM Speed = %d\n", speed);
1233 1230
1234 /* Programming DIMM0 Module Control Register (index_CID0:80h) */ 1231 /* Programming DIMM0 Module Control Register (index_CID0:80h) */
1235 size = pdc20621_prog_dimm0(pe); 1232 size = pdc20621_prog_dimm0(host);
1236 VPRINTK("Local DIMM Size = %dMB\n",size); 1233 VPRINTK("Local DIMM Size = %dMB\n",size);
1237 1234
1238 /* Programming DIMM Module Global Control Register (index_CID0:88h) */ 1235 /* Programming DIMM Module Global Control Register (index_CID0:88h) */
1239 if (pdc20621_prog_dimm_global(pe)) { 1236 if (pdc20621_prog_dimm_global(host)) {
1240 printk(KERN_ERR "Programming DIMM Module Global Control Register Fail\n"); 1237 printk(KERN_ERR "Programming DIMM Module Global Control Register Fail\n");
1241 return 1; 1238 return 1;
1242 } 1239 }
@@ -1249,20 +1246,20 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1249 '9','8','0','3','1','6','1','2',0,0}; 1246 '9','8','0','3','1','6','1','2',0,0};
1250 u8 test_parttern2[40] = {0}; 1247 u8 test_parttern2[40] = {0};
1251 1248
1252 pdc20621_put_to_dimm(pe, (void *) test_parttern2, 0x10040, 40); 1249 pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x10040, 40);
1253 pdc20621_put_to_dimm(pe, (void *) test_parttern2, 0x40, 40); 1250 pdc20621_put_to_dimm(host, (void *) test_parttern2, 0x40, 40);
1254 1251
1255 pdc20621_put_to_dimm(pe, (void *) test_parttern1, 0x10040, 40); 1252 pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x10040, 40);
1256 pdc20621_get_from_dimm(pe, (void *) test_parttern2, 0x40, 40); 1253 pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
1257 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0], 1254 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
1258 test_parttern2[1], &(test_parttern2[2])); 1255 test_parttern2[1], &(test_parttern2[2]));
1259 pdc20621_get_from_dimm(pe, (void *) test_parttern2, 0x10040, 1256 pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x10040,
1260 40); 1257 40);
1261 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0], 1258 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
1262 test_parttern2[1], &(test_parttern2[2])); 1259 test_parttern2[1], &(test_parttern2[2]));
1263 1260
1264 pdc20621_put_to_dimm(pe, (void *) test_parttern1, 0x40, 40); 1261 pdc20621_put_to_dimm(host, (void *) test_parttern1, 0x40, 40);
1265 pdc20621_get_from_dimm(pe, (void *) test_parttern2, 0x40, 40); 1262 pdc20621_get_from_dimm(host, (void *) test_parttern2, 0x40, 40);
1266 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0], 1263 printk(KERN_ERR "%x, %x, %s\n", test_parttern2[0],
1267 test_parttern2[1], &(test_parttern2[2])); 1264 test_parttern2[1], &(test_parttern2[2]));
1268 } 1265 }
@@ -1270,14 +1267,14 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1270 1267
1271 /* ECC initiliazation. */ 1268 /* ECC initiliazation. */
1272 1269
1273 pdc20621_i2c_read(pe, PDC_DIMM0_SPD_DEV_ADDRESS, 1270 pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1274 PDC_DIMM_SPD_TYPE, &spd0); 1271 PDC_DIMM_SPD_TYPE, &spd0);
1275 if (spd0 == 0x02) { 1272 if (spd0 == 0x02) {
1276 VPRINTK("Start ECC initialization\n"); 1273 VPRINTK("Start ECC initialization\n");
1277 addr = 0; 1274 addr = 0;
1278 length = size * 1024 * 1024; 1275 length = size * 1024 * 1024;
1279 while (addr < length) { 1276 while (addr < length) {
1280 pdc20621_put_to_dimm(pe, (void *) &tmp, addr, 1277 pdc20621_put_to_dimm(host, (void *) &tmp, addr,
1281 sizeof(u32)); 1278 sizeof(u32));
1282 addr += sizeof(u32); 1279 addr += sizeof(u32);
1283 } 1280 }
@@ -1287,10 +1284,10 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1287} 1284}
1288 1285
1289 1286
1290static void pdc_20621_init(struct ata_probe_ent *pe) 1287static void pdc_20621_init(struct ata_host *host)
1291{ 1288{
1292 u32 tmp; 1289 u32 tmp;
1293 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR]; 1290 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
1294 1291
1295 /* hard-code chip #0 */ 1292 /* hard-code chip #0 */
1296 mmio += PDC_CHIP0_OFS; 1293 mmio += PDC_CHIP0_OFS;
@@ -1321,15 +1318,25 @@ static void pdc_20621_init(struct ata_probe_ent *pe)
1321static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1318static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1322{ 1319{
1323 static int printed_version; 1320 static int printed_version;
1324 struct ata_probe_ent *probe_ent; 1321 const struct ata_port_info *ppi[] =
1322 { &pdc_port_info[ent->driver_data], NULL };
1323 struct ata_host *host;
1325 void __iomem *base; 1324 void __iomem *base;
1326 struct pdc_host_priv *hpriv; 1325 struct pdc_host_priv *hpriv;
1327 unsigned int board_idx = (unsigned int) ent->driver_data;
1328 int rc; 1326 int rc;
1329 1327
1330 if (!printed_version++) 1328 if (!printed_version++)
1331 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1329 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1332 1330
1331 /* allocate host */
1332 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 4);
1333 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1334 if (!host || !hpriv)
1335 return -ENOMEM;
1336
1337 host->private_data = hpriv;
1338
1339 /* acquire resources and fill host */
1333 rc = pcim_enable_device(pdev); 1340 rc = pcim_enable_device(pdev);
1334 if (rc) 1341 if (rc)
1335 return rc; 1342 return rc;
@@ -1340,7 +1347,15 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1340 pcim_pin_device(pdev); 1347 pcim_pin_device(pdev);
1341 if (rc) 1348 if (rc)
1342 return rc; 1349 return rc;
1350 host->iomap = pcim_iomap_table(pdev);
1351
1352 base = host->iomap[PDC_MMIO_BAR] + PDC_CHIP0_OFS;
1353 pdc_sata_setup_port(&host->ports[0]->ioaddr, base + 0x200);
1354 pdc_sata_setup_port(&host->ports[1]->ioaddr, base + 0x280);
1355 pdc_sata_setup_port(&host->ports[2]->ioaddr, base + 0x300);
1356 pdc_sata_setup_port(&host->ports[3]->ioaddr, base + 0x380);
1343 1357
1358 /* configure and activate */
1344 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1359 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1345 if (rc) 1360 if (rc)
1346 return rc; 1361 return rc;
@@ -1348,50 +1363,13 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1348 if (rc) 1363 if (rc)
1349 return rc; 1364 return rc;
1350 1365
1351 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); 1366 if (pdc20621_dimm_init(host))
1352 if (probe_ent == NULL)
1353 return -ENOMEM; 1367 return -ENOMEM;
1354 1368 pdc_20621_init(host);
1355 probe_ent->dev = pci_dev_to_dev(pdev);
1356 INIT_LIST_HEAD(&probe_ent->node);
1357
1358 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1359 if (!hpriv)
1360 return -ENOMEM;
1361
1362 probe_ent->sht = pdc_port_info[board_idx].sht;
1363 probe_ent->port_flags = pdc_port_info[board_idx].flags;
1364 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
1365 probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
1366 probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
1367 probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
1368
1369 probe_ent->irq = pdev->irq;
1370 probe_ent->irq_flags = IRQF_SHARED;
1371 probe_ent->iomap = pcim_iomap_table(pdev);
1372
1373 probe_ent->private_data = hpriv;
1374 base = probe_ent->iomap[PDC_MMIO_BAR] + PDC_CHIP0_OFS;
1375
1376 probe_ent->n_ports = 4;
1377 pdc_sata_setup_port(&probe_ent->port[0], base + 0x200);
1378 pdc_sata_setup_port(&probe_ent->port[1], base + 0x280);
1379 pdc_sata_setup_port(&probe_ent->port[2], base + 0x300);
1380 pdc_sata_setup_port(&probe_ent->port[3], base + 0x380);
1381 1369
1382 pci_set_master(pdev); 1370 pci_set_master(pdev);
1383 1371 return ata_host_activate(host, pdev->irq, pdc20621_interrupt,
1384 /* initialize adapter */ 1372 IRQF_SHARED, &pdc_sata_sht);
1385 /* initialize local dimm */
1386 if (pdc20621_dimm_init(probe_ent))
1387 return -ENOMEM;
1388 pdc_20621_init(probe_ent);
1389
1390 if (!ata_device_add(probe_ent))
1391 return -ENODEV;
1392
1393 devm_kfree(&pdev->dev, probe_ent);
1394 return 0;
1395} 1373}
1396 1374
1397 1375
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index d659ace80f4f..f74e383de083 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -115,7 +115,6 @@ static const struct ata_port_operations uli_ops = {
115 .error_handler = ata_bmdma_error_handler, 115 .error_handler = ata_bmdma_error_handler,
116 .post_internal_cmd = ata_bmdma_post_internal_cmd, 116 .post_internal_cmd = ata_bmdma_post_internal_cmd,
117 117
118 .irq_handler = ata_interrupt,
119 .irq_clear = ata_bmdma_irq_clear, 118 .irq_clear = ata_bmdma_irq_clear,
120 .irq_on = ata_irq_on, 119 .irq_on = ata_irq_on,
121 .irq_ack = ata_irq_ack, 120 .irq_ack = ata_irq_ack,
@@ -127,7 +126,6 @@ static const struct ata_port_operations uli_ops = {
127}; 126};
128 127
129static struct ata_port_info uli_port_info = { 128static struct ata_port_info uli_port_info = {
130 .sht = &uli_sht,
131 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 129 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
132 ATA_FLAG_IGN_SIMPLEX, 130 ATA_FLAG_IGN_SIMPLEX,
133 .pio_mask = 0x1f, /* pio0-4 */ 131 .pio_mask = 0x1f, /* pio0-4 */
@@ -185,12 +183,13 @@ static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
185static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 183static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
186{ 184{
187 static int printed_version; 185 static int printed_version;
188 struct ata_probe_ent *probe_ent; 186 const struct ata_port_info *ppi[] = { &uli_port_info, NULL };
189 struct ata_port_info *ppi[2];
190 int rc;
191 unsigned int board_idx = (unsigned int) ent->driver_data; 187 unsigned int board_idx = (unsigned int) ent->driver_data;
188 struct ata_host *host;
192 struct uli_priv *hpriv; 189 struct uli_priv *hpriv;
193 void __iomem * const *iomap; 190 void __iomem * const *iomap;
191 struct ata_ioports *ioaddr;
192 int n_ports, rc;
194 193
195 if (!printed_version++) 194 if (!printed_version++)
196 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 195 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
@@ -199,54 +198,42 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
199 if (rc) 198 if (rc)
200 return rc; 199 return rc;
201 200
202 rc = pci_request_regions(pdev, DRV_NAME); 201 n_ports = 2;
203 if (rc) { 202 if (board_idx == uli_5287)
204 pcim_pin_device(pdev); 203 n_ports = 4;
205 return rc; 204 rc = ata_pci_prepare_native_host(pdev, ppi, n_ports, &host);
206 }
207
208 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
209 if (rc)
210 return rc;
211 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
212 if (rc) 205 if (rc)
213 return rc; 206 return rc;
214 207
215 ppi[0] = ppi[1] = &uli_port_info;
216 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
217 if (!probe_ent)
218 return -ENOMEM;
219
220 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 208 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
221 if (!hpriv) 209 if (!hpriv)
222 return -ENOMEM; 210 return -ENOMEM;
211 host->private_data = hpriv;
223 212
224 probe_ent->private_data = hpriv; 213 iomap = host->iomap;
225
226 iomap = pcim_iomap_table(pdev);
227 214
228 switch (board_idx) { 215 switch (board_idx) {
229 case uli_5287: 216 case uli_5287:
230 hpriv->scr_cfg_addr[0] = ULI5287_BASE; 217 hpriv->scr_cfg_addr[0] = ULI5287_BASE;
231 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS; 218 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS;
232 probe_ent->n_ports = 4;
233 219
234 probe_ent->port[2].cmd_addr = iomap[0] + 8; 220 ioaddr = &host->ports[2]->ioaddr;
235 probe_ent->port[2].altstatus_addr = 221 ioaddr->cmd_addr = iomap[0] + 8;
236 probe_ent->port[2].ctl_addr = (void __iomem *) 222 ioaddr->altstatus_addr =
223 ioaddr->ctl_addr = (void __iomem *)
237 ((unsigned long)iomap[1] | ATA_PCI_CTL_OFS) + 4; 224 ((unsigned long)iomap[1] | ATA_PCI_CTL_OFS) + 4;
238 probe_ent->port[2].bmdma_addr = iomap[4] + 16; 225 ioaddr->bmdma_addr = iomap[4] + 16;
239 hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4; 226 hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4;
227 ata_std_ports(ioaddr);
240 228
241 probe_ent->port[3].cmd_addr = iomap[2] + 8; 229 ioaddr = &host->ports[3]->ioaddr;
242 probe_ent->port[3].altstatus_addr = 230 ioaddr->cmd_addr = iomap[2] + 8;
243 probe_ent->port[3].ctl_addr = (void __iomem *) 231 ioaddr->altstatus_addr =
232 ioaddr->ctl_addr = (void __iomem *)
244 ((unsigned long)iomap[3] | ATA_PCI_CTL_OFS) + 4; 233 ((unsigned long)iomap[3] | ATA_PCI_CTL_OFS) + 4;
245 probe_ent->port[3].bmdma_addr = iomap[4] + 24; 234 ioaddr->bmdma_addr = iomap[4] + 24;
246 hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5; 235 hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5;
247 236 ata_std_ports(ioaddr);
248 ata_std_ports(&probe_ent->port[2]);
249 ata_std_ports(&probe_ent->port[3]);
250 break; 237 break;
251 238
252 case uli_5289: 239 case uli_5289:
@@ -266,12 +253,8 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
266 253
267 pci_set_master(pdev); 254 pci_set_master(pdev);
268 pci_intx(pdev, 1); 255 pci_intx(pdev, 1);
269 256 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
270 if (!ata_device_add(probe_ent)) 257 &uli_sht);
271 return -ENODEV;
272
273 devm_kfree(&pdev->dev, probe_ent);
274 return 0;
275} 258}
276 259
277static int __init uli_init(void) 260static int __init uli_init(void)
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 598e6a26a481..1d855f55f5f7 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -64,8 +64,6 @@ enum {
64 PORT0 = (1 << 1), 64 PORT0 = (1 << 1),
65 PORT1 = (1 << 0), 65 PORT1 = (1 << 0),
66 ALL_PORTS = PORT0 | PORT1, 66 ALL_PORTS = PORT0 | PORT1,
67 PATA_PORT = 2, /* PATA is port 2 */
68 N_PORTS = 3,
69 67
70 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4), 68 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
71 69
@@ -78,11 +76,9 @@ static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
78static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
79static void svia_noop_freeze(struct ata_port *ap); 77static void svia_noop_freeze(struct ata_port *ap);
80static void vt6420_error_handler(struct ata_port *ap); 78static void vt6420_error_handler(struct ata_port *ap);
81static void vt6421_sata_error_handler(struct ata_port *ap); 79static int vt6421_pata_cable_detect(struct ata_port *ap);
82static void vt6421_pata_error_handler(struct ata_port *ap);
83static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev); 80static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
84static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev); 81static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
85static int vt6421_port_start(struct ata_port *ap);
86 82
87static const struct pci_device_id svia_pci_tbl[] = { 83static const struct pci_device_id svia_pci_tbl[] = {
88 { PCI_VDEVICE(VIA, 0x5337), vt6420 }, 84 { PCI_VDEVICE(VIA, 0x5337), vt6420 },
@@ -141,7 +137,6 @@ static const struct ata_port_operations vt6420_sata_ops = {
141 .error_handler = vt6420_error_handler, 137 .error_handler = vt6420_error_handler,
142 .post_internal_cmd = ata_bmdma_post_internal_cmd, 138 .post_internal_cmd = ata_bmdma_post_internal_cmd,
143 139
144 .irq_handler = ata_interrupt,
145 .irq_clear = ata_bmdma_irq_clear, 140 .irq_clear = ata_bmdma_irq_clear,
146 .irq_on = ata_irq_on, 141 .irq_on = ata_irq_on,
147 .irq_ack = ata_irq_ack, 142 .irq_ack = ata_irq_ack,
@@ -172,15 +167,15 @@ static const struct ata_port_operations vt6421_pata_ops = {
172 167
173 .freeze = ata_bmdma_freeze, 168 .freeze = ata_bmdma_freeze,
174 .thaw = ata_bmdma_thaw, 169 .thaw = ata_bmdma_thaw,
175 .error_handler = vt6421_pata_error_handler, 170 .error_handler = ata_bmdma_error_handler,
176 .post_internal_cmd = ata_bmdma_post_internal_cmd, 171 .post_internal_cmd = ata_bmdma_post_internal_cmd,
172 .cable_detect = vt6421_pata_cable_detect,
177 173
178 .irq_handler = ata_interrupt,
179 .irq_clear = ata_bmdma_irq_clear, 174 .irq_clear = ata_bmdma_irq_clear,
180 .irq_on = ata_irq_on, 175 .irq_on = ata_irq_on,
181 .irq_ack = ata_irq_ack, 176 .irq_ack = ata_irq_ack,
182 177
183 .port_start = vt6421_port_start, 178 .port_start = ata_port_start,
184}; 179};
185 180
186static const struct ata_port_operations vt6421_sata_ops = { 181static const struct ata_port_operations vt6421_sata_ops = {
@@ -203,10 +198,10 @@ static const struct ata_port_operations vt6421_sata_ops = {
203 198
204 .freeze = ata_bmdma_freeze, 199 .freeze = ata_bmdma_freeze,
205 .thaw = ata_bmdma_thaw, 200 .thaw = ata_bmdma_thaw,
206 .error_handler = vt6421_sata_error_handler, 201 .error_handler = ata_bmdma_error_handler,
207 .post_internal_cmd = ata_bmdma_post_internal_cmd, 202 .post_internal_cmd = ata_bmdma_post_internal_cmd,
203 .cable_detect = ata_cable_sata,
208 204
209 .irq_handler = ata_interrupt,
210 .irq_clear = ata_bmdma_irq_clear, 205 .irq_clear = ata_bmdma_irq_clear,
211 .irq_on = ata_irq_on, 206 .irq_on = ata_irq_on,
212 .irq_ack = ata_irq_ack, 207 .irq_ack = ata_irq_ack,
@@ -214,11 +209,10 @@ static const struct ata_port_operations vt6421_sata_ops = {
214 .scr_read = svia_scr_read, 209 .scr_read = svia_scr_read,
215 .scr_write = svia_scr_write, 210 .scr_write = svia_scr_write,
216 211
217 .port_start = vt6421_port_start, 212 .port_start = ata_port_start,
218}; 213};
219 214
220static struct ata_port_info vt6420_port_info = { 215static const struct ata_port_info vt6420_port_info = {
221 .sht = &svia_sht,
222 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 216 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
223 .pio_mask = 0x1f, 217 .pio_mask = 0x1f,
224 .mwdma_mask = 0x07, 218 .mwdma_mask = 0x07,
@@ -226,6 +220,22 @@ static struct ata_port_info vt6420_port_info = {
226 .port_ops = &vt6420_sata_ops, 220 .port_ops = &vt6420_sata_ops,
227}; 221};
228 222
223static struct ata_port_info vt6421_sport_info = {
224 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
225 .pio_mask = 0x1f,
226 .mwdma_mask = 0x07,
227 .udma_mask = 0x7f,
228 .port_ops = &vt6421_sata_ops,
229};
230
231static struct ata_port_info vt6421_pport_info = {
232 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
233 .pio_mask = 0x1f,
234 .mwdma_mask = 0,
235 .udma_mask = 0x7f,
236 .port_ops = &vt6421_pata_ops,
237};
238
229MODULE_AUTHOR("Jeff Garzik"); 239MODULE_AUTHOR("Jeff Garzik");
230MODULE_DESCRIPTION("SCSI low-level driver for VIA SATA controllers"); 240MODULE_DESCRIPTION("SCSI low-level driver for VIA SATA controllers");
231MODULE_LICENSE("GPL"); 241MODULE_LICENSE("GPL");
@@ -330,35 +340,15 @@ static void vt6420_error_handler(struct ata_port *ap)
330 NULL, ata_std_postreset); 340 NULL, ata_std_postreset);
331} 341}
332 342
333static int vt6421_pata_prereset(struct ata_port *ap) 343static int vt6421_pata_cable_detect(struct ata_port *ap)
334{ 344{
335 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 345 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
336 u8 tmp; 346 u8 tmp;
337 347
338 pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp); 348 pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp);
339 if (tmp & 0x10) 349 if (tmp & 0x10)
340 ap->cbl = ATA_CBL_PATA40; 350 return ATA_CBL_PATA40;
341 else 351 return ATA_CBL_PATA80;
342 ap->cbl = ATA_CBL_PATA80;
343 return 0;
344}
345
346static void vt6421_pata_error_handler(struct ata_port *ap)
347{
348 return ata_bmdma_drive_eh(ap, vt6421_pata_prereset, ata_std_softreset,
349 NULL, ata_std_postreset);
350}
351
352static int vt6421_sata_prereset(struct ata_port *ap)
353{
354 ap->cbl = ATA_CBL_SATA;
355 return 0;
356}
357
358static void vt6421_sata_error_handler(struct ata_port *ap)
359{
360 return ata_bmdma_drive_eh(ap, vt6421_sata_prereset, ata_std_softreset,
361 NULL, ata_std_postreset);
362} 352}
363 353
364static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev) 354static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
@@ -375,16 +365,6 @@ static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
375 pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->pio_mode - XFER_UDMA_0]); 365 pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->pio_mode - XFER_UDMA_0]);
376} 366}
377 367
378static int vt6421_port_start(struct ata_port *ap)
379{
380 if (ap->port_no == PATA_PORT) {
381 ap->ops = &vt6421_pata_ops;
382 ap->mwdma_mask = 0;
383 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST;
384 }
385 return ata_port_start(ap);
386}
387
388static const unsigned int svia_bar_sizes[] = { 368static const unsigned int svia_bar_sizes[] = {
389 8, 4, 8, 4, 16, 256 369 8, 4, 8, 4, 16, 256
390}; 370};
@@ -403,79 +383,78 @@ static void __iomem * vt6421_scr_addr(void __iomem *addr, unsigned int port)
403 return addr + (port * 64); 383 return addr + (port * 64);
404} 384}
405 385
406static void vt6421_init_addrs(struct ata_probe_ent *probe_ent, 386static void vt6421_init_addrs(struct ata_port *ap)
407 void __iomem * const *iomap, unsigned int port)
408{ 387{
409 void __iomem *reg_addr = iomap[port]; 388 void __iomem * const * iomap = ap->host->iomap;
410 void __iomem *bmdma_addr = iomap[4] + (port * 8); 389 void __iomem *reg_addr = iomap[ap->port_no];
411 390 void __iomem *bmdma_addr = iomap[4] + (ap->port_no * 8);
412 probe_ent->port[port].cmd_addr = reg_addr; 391 struct ata_ioports *ioaddr = &ap->ioaddr;
413 probe_ent->port[port].altstatus_addr = 392
414 probe_ent->port[port].ctl_addr = (void __iomem *) 393 ioaddr->cmd_addr = reg_addr;
394 ioaddr->altstatus_addr =
395 ioaddr->ctl_addr = (void __iomem *)
415 ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS); 396 ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS);
416 probe_ent->port[port].bmdma_addr = bmdma_addr; 397 ioaddr->bmdma_addr = bmdma_addr;
417 probe_ent->port[port].scr_addr = vt6421_scr_addr(iomap[5], port); 398 ioaddr->scr_addr = vt6421_scr_addr(iomap[5], ap->port_no);
418 399
419 ata_std_ports(&probe_ent->port[port]); 400 ata_std_ports(ioaddr);
420} 401}
421 402
422static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev) 403static int vt6420_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
423{ 404{
424 struct ata_probe_ent *probe_ent; 405 const struct ata_port_info *ppi[] = { &vt6420_port_info, NULL };
425 struct ata_port_info *ppi[2]; 406 struct ata_host *host;
426 void __iomem *bar5; 407 int rc;
427 408
428 ppi[0] = ppi[1] = &vt6420_port_info; 409 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host);
429 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 410 if (rc)
430 if (!probe_ent) 411 return rc;
431 return NULL; 412 *r_host = host;
432 413
433 bar5 = pcim_iomap(pdev, 5, 0); 414 rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
434 if (!bar5) { 415 if (rc) {
435 dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n"); 416 dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
436 return NULL; 417 return rc;
437 } 418 }
438 419
439 probe_ent->port[0].scr_addr = svia_scr_addr(bar5, 0); 420 host->ports[0]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 0);
440 probe_ent->port[1].scr_addr = svia_scr_addr(bar5, 1); 421 host->ports[1]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 1);
441 422
442 return probe_ent; 423 return 0;
443} 424}
444 425
445static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev) 426static int vt6421_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
446{ 427{
447 struct ata_probe_ent *probe_ent; 428 const struct ata_port_info *ppi[] =
448 unsigned int i; 429 { &vt6421_sport_info, &vt6421_sport_info, &vt6421_pport_info };
430 struct ata_host *host;
431 int i, rc;
432
433 *r_host = host = ata_host_alloc_pinfo(&pdev->dev, ppi, ARRAY_SIZE(ppi));
434 if (!host) {
435 dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
436 return -ENOMEM;
437 }
449 438
450 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL); 439 rc = pcim_iomap_regions(pdev, 0x1f, DRV_NAME);
451 if (!probe_ent) 440 if (rc) {
452 return NULL; 441 dev_printk(KERN_ERR, &pdev->dev, "failed to request/iomap "
453 442 "PCI BARs (errno=%d)\n", rc);
454 memset(probe_ent, 0, sizeof(*probe_ent)); 443 return rc;
455 probe_ent->dev = pci_dev_to_dev(pdev); 444 }
456 INIT_LIST_HEAD(&probe_ent->node); 445 host->iomap = pcim_iomap_table(pdev);
457
458 probe_ent->sht = &svia_sht;
459 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY;
460 probe_ent->port_ops = &vt6421_sata_ops;
461 probe_ent->n_ports = N_PORTS;
462 probe_ent->irq = pdev->irq;
463 probe_ent->irq_flags = IRQF_SHARED;
464 probe_ent->pio_mask = 0x1f;
465 probe_ent->mwdma_mask = 0x07;
466 probe_ent->udma_mask = 0x7f;
467
468 for (i = 0; i < 6; i++)
469 if (!pcim_iomap(pdev, i, 0)) {
470 dev_printk(KERN_ERR, &pdev->dev,
471 "failed to iomap PCI BAR %d\n", i);
472 return NULL;
473 }
474 446
475 for (i = 0; i < N_PORTS; i++) 447 for (i = 0; i < host->n_ports; i++)
476 vt6421_init_addrs(probe_ent, pcim_iomap_table(pdev), i); 448 vt6421_init_addrs(host->ports[i]);
477 449
478 return probe_ent; 450 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
451 if (rc)
452 return rc;
453 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
454 if (rc)
455 return rc;
456
457 return 0;
479} 458}
480 459
481static void svia_configure(struct pci_dev *pdev) 460static void svia_configure(struct pci_dev *pdev)
@@ -522,7 +501,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
522 static int printed_version; 501 static int printed_version;
523 unsigned int i; 502 unsigned int i;
524 int rc; 503 int rc;
525 struct ata_probe_ent *probe_ent; 504 struct ata_host *host;
526 int board_id = (int) ent->driver_data; 505 int board_id = (int) ent->driver_data;
527 const int *bar_sizes; 506 const int *bar_sizes;
528 u8 tmp8; 507 u8 tmp8;
@@ -534,12 +513,6 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
534 if (rc) 513 if (rc)
535 return rc; 514 return rc;
536 515
537 rc = pci_request_regions(pdev, DRV_NAME);
538 if (rc) {
539 pcim_pin_device(pdev);
540 return rc;
541 }
542
543 if (board_id == vt6420) { 516 if (board_id == vt6420) {
544 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8); 517 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8);
545 if (tmp8 & SATA_2DEV) { 518 if (tmp8 & SATA_2DEV) {
@@ -565,32 +538,18 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
565 return -ENODEV; 538 return -ENODEV;
566 } 539 }
567 540
568 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
569 if (rc)
570 return rc;
571 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
572 if (rc)
573 return rc;
574
575 if (board_id == vt6420) 541 if (board_id == vt6420)
576 probe_ent = vt6420_init_probe_ent(pdev); 542 rc = vt6420_prepare_host(pdev, &host);
577 else 543 else
578 probe_ent = vt6421_init_probe_ent(pdev); 544 rc = vt6421_prepare_host(pdev, &host);
579 545 if (rc)
580 if (!probe_ent) { 546 return rc;
581 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n");
582 return -ENOMEM;
583 }
584 547
585 svia_configure(pdev); 548 svia_configure(pdev);
586 549
587 pci_set_master(pdev); 550 pci_set_master(pdev);
588 551 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
589 if (!ata_device_add(probe_ent)) 552 &svia_sht);
590 return -ENODEV;
591
592 devm_kfree(&pdev->dev, probe_ent);
593 return 0;
594} 553}
595 554
596static int __init svia_init(void) 555static int __init svia_init(void)
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 170bad1b415b..80126f835d32 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -333,7 +333,6 @@ static const struct ata_port_operations vsc_sata_ops = {
333 .thaw = vsc_thaw, 333 .thaw = vsc_thaw,
334 .error_handler = ata_bmdma_error_handler, 334 .error_handler = ata_bmdma_error_handler,
335 .post_internal_cmd = ata_bmdma_post_internal_cmd, 335 .post_internal_cmd = ata_bmdma_post_internal_cmd,
336 .irq_handler = vsc_sata_interrupt,
337 .irq_clear = ata_bmdma_irq_clear, 336 .irq_clear = ata_bmdma_irq_clear,
338 .irq_on = ata_irq_on, 337 .irq_on = ata_irq_on,
339 .irq_ack = ata_irq_ack, 338 .irq_ack = ata_irq_ack,
@@ -367,30 +366,50 @@ static void __devinit vsc_sata_setup_port(struct ata_ioports *port,
367 366
368static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 367static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
369{ 368{
369 static const struct ata_port_info pi = {
370 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
371 ATA_FLAG_MMIO,
372 .pio_mask = 0x1f,
373 .mwdma_mask = 0x07,
374 .udma_mask = 0x7f,
375 .port_ops = &vsc_sata_ops,
376 };
377 const struct ata_port_info *ppi[] = { &pi, NULL };
370 static int printed_version; 378 static int printed_version;
371 struct ata_probe_ent *probe_ent; 379 struct ata_host *host;
372 void __iomem *mmio_base; 380 void __iomem *mmio_base;
373 int rc; 381 int i, rc;
374 u8 cls; 382 u8 cls;
375 383
376 if (!printed_version++) 384 if (!printed_version++)
377 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 385 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
378 386
387 /* allocate host */
388 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 4);
389 if (!host)
390 return -ENOMEM;
391
379 rc = pcim_enable_device(pdev); 392 rc = pcim_enable_device(pdev);
380 if (rc) 393 if (rc)
381 return rc; 394 return rc;
382 395
383 /* 396 /* check if we have needed resource mapped */
384 * Check if we have needed resource mapped.
385 */
386 if (pci_resource_len(pdev, 0) == 0) 397 if (pci_resource_len(pdev, 0) == 0)
387 return -ENODEV; 398 return -ENODEV;
388 399
400 /* map IO regions and intialize host accordingly */
389 rc = pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME); 401 rc = pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME);
390 if (rc == -EBUSY) 402 if (rc == -EBUSY)
391 pcim_pin_device(pdev); 403 pcim_pin_device(pdev);
392 if (rc) 404 if (rc)
393 return rc; 405 return rc;
406 host->iomap = pcim_iomap_table(pdev);
407
408 mmio_base = host->iomap[VSC_MMIO_BAR];
409
410 for (i = 0; i < host->n_ports; i++)
411 vsc_sata_setup_port(&host->ports[i]->ioaddr,
412 mmio_base + (i + 1) * VSC_SATA_PORT_OFFSET);
394 413
395 /* 414 /*
396 * Use 32 bit DMA mask, because 64 bit address support is poor. 415 * Use 32 bit DMA mask, because 64 bit address support is poor.
@@ -402,12 +421,6 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
402 if (rc) 421 if (rc)
403 return rc; 422 return rc;
404 423
405 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
406 if (probe_ent == NULL)
407 return -ENOMEM;
408 probe_ent->dev = pci_dev_to_dev(pdev);
409 INIT_LIST_HEAD(&probe_ent->node);
410
411 /* 424 /*
412 * Due to a bug in the chip, the default cache line size can't be 425 * Due to a bug in the chip, the default cache line size can't be
413 * used (unless the default is non-zero). 426 * used (unless the default is non-zero).
@@ -418,33 +431,6 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
418 431
419 if (pci_enable_msi(pdev) == 0) 432 if (pci_enable_msi(pdev) == 0)
420 pci_intx(pdev, 0); 433 pci_intx(pdev, 0);
421 else
422 probe_ent->irq_flags = IRQF_SHARED;
423
424 probe_ent->sht = &vsc_sata_sht;
425 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
426 ATA_FLAG_MMIO;
427 probe_ent->port_ops = &vsc_sata_ops;
428 probe_ent->n_ports = 4;
429 probe_ent->irq = pdev->irq;
430 probe_ent->iomap = pcim_iomap_table(pdev);
431
432 /* We don't care much about the PIO/UDMA masks, but the core won't like us
433 * if we don't fill these
434 */
435 probe_ent->pio_mask = 0x1f;
436 probe_ent->mwdma_mask = 0x07;
437 probe_ent->udma_mask = 0x7f;
438
439 mmio_base = probe_ent->iomap[VSC_MMIO_BAR];
440
441 /* We have 4 ports per PCI function */
442 vsc_sata_setup_port(&probe_ent->port[0], mmio_base + 1 * VSC_SATA_PORT_OFFSET);
443 vsc_sata_setup_port(&probe_ent->port[1], mmio_base + 2 * VSC_SATA_PORT_OFFSET);
444 vsc_sata_setup_port(&probe_ent->port[2], mmio_base + 3 * VSC_SATA_PORT_OFFSET);
445 vsc_sata_setup_port(&probe_ent->port[3], mmio_base + 4 * VSC_SATA_PORT_OFFSET);
446
447 pci_set_master(pdev);
448 434
449 /* 435 /*
450 * Config offset 0x98 is "Extended Control and Status Register 0" 436 * Config offset 0x98 is "Extended Control and Status Register 0"
@@ -454,11 +440,9 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
454 */ 440 */
455 pci_write_config_dword(pdev, 0x98, 0); 441 pci_write_config_dword(pdev, 0x98, 0);
456 442
457 if (!ata_device_add(probe_ent)) 443 pci_set_master(pdev);
458 return -ENODEV; 444 return ata_host_activate(host, pdev->irq, vsc_sata_interrupt,
459 445 IRQF_SHARED, &vsc_sata_sht);
460 devm_kfree(&pdev->dev, probe_ent);
461 return 0;
462} 446}
463 447
464static const struct pci_device_id vsc_sata_pci_tbl[] = { 448static const struct pci_device_id vsc_sata_pci_tbl[] = {
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 78237577b05a..3ef593a9015f 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * Sony Programmable I/O Control Device driver for VAIO 2 * Sony Programmable I/O Control Device driver for VAIO
3 * 3 *
4 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
5 *
4 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net> 6 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
5 * 7 *
6 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org> 8 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
@@ -95,6 +97,11 @@ module_param(useinput, int, 0444);
95MODULE_PARM_DESC(useinput, 97MODULE_PARM_DESC(useinput,
96 "set this if you would like sonypi to feed events to the input subsystem"); 98 "set this if you would like sonypi to feed events to the input subsystem");
97 99
100static int check_ioport = 1;
101module_param(check_ioport, int, 0444);
102MODULE_PARM_DESC(check_ioport,
103 "set this to 0 if you think the automatic ioport check for sony-laptop is wrong");
104
98#define SONYPI_DEVICE_MODEL_TYPE1 1 105#define SONYPI_DEVICE_MODEL_TYPE1 1
99#define SONYPI_DEVICE_MODEL_TYPE2 2 106#define SONYPI_DEVICE_MODEL_TYPE2 2
100#define SONYPI_DEVICE_MODEL_TYPE3 3 107#define SONYPI_DEVICE_MODEL_TYPE3 3
@@ -477,7 +484,7 @@ static struct sonypi_device {
477 u16 evtype_offset; 484 u16 evtype_offset;
478 int camera_power; 485 int camera_power;
479 int bluetooth_power; 486 int bluetooth_power;
480 struct semaphore lock; 487 struct mutex lock;
481 struct kfifo *fifo; 488 struct kfifo *fifo;
482 spinlock_t fifo_lock; 489 spinlock_t fifo_lock;
483 wait_queue_head_t fifo_proc_list; 490 wait_queue_head_t fifo_proc_list;
@@ -884,7 +891,7 @@ int sonypi_camera_command(int command, u8 value)
884 if (!camera) 891 if (!camera)
885 return -EIO; 892 return -EIO;
886 893
887 down(&sonypi_device.lock); 894 mutex_lock(&sonypi_device.lock);
888 895
889 switch (command) { 896 switch (command) {
890 case SONYPI_COMMAND_SETCAMERA: 897 case SONYPI_COMMAND_SETCAMERA:
@@ -919,7 +926,7 @@ int sonypi_camera_command(int command, u8 value)
919 command); 926 command);
920 break; 927 break;
921 } 928 }
922 up(&sonypi_device.lock); 929 mutex_unlock(&sonypi_device.lock);
923 return 0; 930 return 0;
924} 931}
925 932
@@ -938,20 +945,20 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
938static int sonypi_misc_release(struct inode *inode, struct file *file) 945static int sonypi_misc_release(struct inode *inode, struct file *file)
939{ 946{
940 sonypi_misc_fasync(-1, file, 0); 947 sonypi_misc_fasync(-1, file, 0);
941 down(&sonypi_device.lock); 948 mutex_lock(&sonypi_device.lock);
942 sonypi_device.open_count--; 949 sonypi_device.open_count--;
943 up(&sonypi_device.lock); 950 mutex_unlock(&sonypi_device.lock);
944 return 0; 951 return 0;
945} 952}
946 953
947static int sonypi_misc_open(struct inode *inode, struct file *file) 954static int sonypi_misc_open(struct inode *inode, struct file *file)
948{ 955{
949 down(&sonypi_device.lock); 956 mutex_lock(&sonypi_device.lock);
950 /* Flush input queue on first open */ 957 /* Flush input queue on first open */
951 if (!sonypi_device.open_count) 958 if (!sonypi_device.open_count)
952 kfifo_reset(sonypi_device.fifo); 959 kfifo_reset(sonypi_device.fifo);
953 sonypi_device.open_count++; 960 sonypi_device.open_count++;
954 up(&sonypi_device.lock); 961 mutex_unlock(&sonypi_device.lock);
955 return 0; 962 return 0;
956} 963}
957 964
@@ -1001,7 +1008,7 @@ static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1001 u8 val8; 1008 u8 val8;
1002 u16 val16; 1009 u16 val16;
1003 1010
1004 down(&sonypi_device.lock); 1011 mutex_lock(&sonypi_device.lock);
1005 switch (cmd) { 1012 switch (cmd) {
1006 case SONYPI_IOCGBRT: 1013 case SONYPI_IOCGBRT:
1007 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) { 1014 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
@@ -1101,7 +1108,7 @@ static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1101 default: 1108 default:
1102 ret = -EINVAL; 1109 ret = -EINVAL;
1103 } 1110 }
1104 up(&sonypi_device.lock); 1111 mutex_unlock(&sonypi_device.lock);
1105 return ret; 1112 return ret;
1106} 1113}
1107 1114
@@ -1260,6 +1267,28 @@ static int __devinit sonypi_create_input_devices(void)
1260static int __devinit sonypi_setup_ioports(struct sonypi_device *dev, 1267static int __devinit sonypi_setup_ioports(struct sonypi_device *dev,
1261 const struct sonypi_ioport_list *ioport_list) 1268 const struct sonypi_ioport_list *ioport_list)
1262{ 1269{
1270 /* try to detect if sony-laptop is being used and thus
1271 * has already requested one of the known ioports.
1272 * As in the deprecated check_region this is racy has we have
1273 * multiple ioports available and one of them can be requested
1274 * between this check and the subsequent request. Anyway, as an
1275 * attempt to be some more user-friendly as we currently are,
1276 * this is enough.
1277 */
1278 const struct sonypi_ioport_list *check = ioport_list;
1279 while (check_ioport && check->port1) {
1280 if (!request_region(check->port1,
1281 sonypi_device.region_size,
1282 "Sony Programable I/O Device Check")) {
1283 printk(KERN_ERR "sonypi: ioport 0x%.4x busy, using sony-laptop? "
1284 "if not use check_ioport=0\n",
1285 check->port1);
1286 return -EBUSY;
1287 }
1288 release_region(check->port1, sonypi_device.region_size);
1289 check++;
1290 }
1291
1263 while (ioport_list->port1) { 1292 while (ioport_list->port1) {
1264 1293
1265 if (request_region(ioport_list->port1, 1294 if (request_region(ioport_list->port1,
@@ -1321,6 +1350,10 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1321 struct pci_dev *pcidev; 1350 struct pci_dev *pcidev;
1322 int error; 1351 int error;
1323 1352
1353 printk(KERN_WARNING "sonypi: please try the sony-laptop module instead "
1354 "and report failures, see also "
1355 "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");
1356
1324 spin_lock_init(&sonypi_device.fifo_lock); 1357 spin_lock_init(&sonypi_device.fifo_lock);
1325 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL, 1358 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
1326 &sonypi_device.fifo_lock); 1359 &sonypi_device.fifo_lock);
@@ -1330,7 +1363,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1330 } 1363 }
1331 1364
1332 init_waitqueue_head(&sonypi_device.fifo_proc_list); 1365 init_waitqueue_head(&sonypi_device.fifo_proc_list);
1333 init_MUTEX(&sonypi_device.lock); 1366 mutex_init(&sonypi_device.lock);
1334 sonypi_device.bluetooth_power = -1; 1367 sonypi_device.bluetooth_power = -1;
1335 1368
1336 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, 1369 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index 5ac309ee7f05..5cfcff532545 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -26,7 +26,7 @@
26/* 26/*
27 * The I/O port the PMTMR resides at. 27 * The I/O port the PMTMR resides at.
28 * The location is detected during setup_arch(), 28 * The location is detected during setup_arch(),
29 * in arch/i386/acpi/boot.c 29 * in arch/i386/kernel/acpi/boot.c
30 */ 30 */
31u32 pmtmr_ioport __read_mostly; 31u32 pmtmr_ioport __read_mostly;
32 32
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 639e8b6c35b1..bc773781993a 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -577,14 +577,14 @@ config VIDEO_ZORAN_AVS6EYES
577 577
578config VIDEO_MEYE 578config VIDEO_MEYE
579 tristate "Sony Vaio Picturebook Motion Eye Video For Linux" 579 tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
580 depends on PCI && SONYPI && VIDEO_V4L1 580 depends on PCI && SONY_LAPTOP && VIDEO_V4L1
581 ---help--- 581 ---help---
582 This is the video4linux driver for the Motion Eye camera found 582 This is the video4linux driver for the Motion Eye camera found
583 in the Vaio Picturebook laptops. Please read the material in 583 in the Vaio Picturebook laptops. Please read the material in
584 <file:Documentation/video4linux/meye.txt> for more information. 584 <file:Documentation/video4linux/meye.txt> for more information.
585 585
586 If you say Y or M here, you need to say Y or M to "Sony Programmable 586 If you say Y or M here, you need to say Y or M to "Sony Laptop
587 I/O Control Device" in the character device section. 587 Extras" in the misc device section.
588 588
589 To compile this driver as a module, choose M here: the 589 To compile this driver as a module, choose M here: the
590 module will be called meye. 590 module will be called meye.
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 98681da5e3b9..664aba8b4d85 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -925,13 +925,13 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV) 925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
926 return -EINVAL; 926 return -EINVAL;
927 mutex_lock(&meye.lock); 927 mutex_lock(&meye.lock);
928 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 928 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS,
929 p->brightness >> 10); 929 p->brightness >> 10);
930 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 930 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE,
931 p->hue >> 10); 931 p->hue >> 10);
932 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR,
933 p->colour >> 10); 933 p->colour >> 10);
934 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST,
935 p->contrast >> 10); 935 p->contrast >> 10);
936 meye.picture = *p; 936 meye.picture = *p;
937 mutex_unlock(&meye.lock); 937 mutex_unlock(&meye.lock);
@@ -1043,11 +1043,11 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1043 meye.params.quality != jp->quality) 1043 meye.params.quality != jp->quality)
1044 mchip_hic_stop(); /* need restart */ 1044 mchip_hic_stop(); /* need restart */
1045 meye.params = *jp; 1045 meye.params = *jp;
1046 sonypi_camera_command(SONYPI_COMMAND_SETCAMERASHARPNESS, 1046 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
1047 meye.params.sharpness); 1047 meye.params.sharpness);
1048 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 1048 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
1049 meye.params.agc); 1049 meye.params.agc);
1050 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 1050 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
1051 meye.params.picture); 1051 meye.params.picture);
1052 mutex_unlock(&meye.lock); 1052 mutex_unlock(&meye.lock);
1053 break; 1053 break;
@@ -1287,38 +1287,38 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1287 mutex_lock(&meye.lock); 1287 mutex_lock(&meye.lock);
1288 switch (c->id) { 1288 switch (c->id) {
1289 case V4L2_CID_BRIGHTNESS: 1289 case V4L2_CID_BRIGHTNESS:
1290 sonypi_camera_command( 1290 sony_pic_camera_command(
1291 SONYPI_COMMAND_SETCAMERABRIGHTNESS, c->value); 1291 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value);
1292 meye.picture.brightness = c->value << 10; 1292 meye.picture.brightness = c->value << 10;
1293 break; 1293 break;
1294 case V4L2_CID_HUE: 1294 case V4L2_CID_HUE:
1295 sonypi_camera_command( 1295 sony_pic_camera_command(
1296 SONYPI_COMMAND_SETCAMERAHUE, c->value); 1296 SONY_PIC_COMMAND_SETCAMERAHUE, c->value);
1297 meye.picture.hue = c->value << 10; 1297 meye.picture.hue = c->value << 10;
1298 break; 1298 break;
1299 case V4L2_CID_CONTRAST: 1299 case V4L2_CID_CONTRAST:
1300 sonypi_camera_command( 1300 sony_pic_camera_command(
1301 SONYPI_COMMAND_SETCAMERACONTRAST, c->value); 1301 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value);
1302 meye.picture.contrast = c->value << 10; 1302 meye.picture.contrast = c->value << 10;
1303 break; 1303 break;
1304 case V4L2_CID_SATURATION: 1304 case V4L2_CID_SATURATION:
1305 sonypi_camera_command( 1305 sony_pic_camera_command(
1306 SONYPI_COMMAND_SETCAMERACOLOR, c->value); 1306 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value);
1307 meye.picture.colour = c->value << 10; 1307 meye.picture.colour = c->value << 10;
1308 break; 1308 break;
1309 case V4L2_CID_AGC: 1309 case V4L2_CID_AGC:
1310 sonypi_camera_command( 1310 sony_pic_camera_command(
1311 SONYPI_COMMAND_SETCAMERAAGC, c->value); 1311 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1312 meye.params.agc = c->value; 1312 meye.params.agc = c->value;
1313 break; 1313 break;
1314 case V4L2_CID_SHARPNESS: 1314 case V4L2_CID_SHARPNESS:
1315 sonypi_camera_command( 1315 sony_pic_camera_command(
1316 SONYPI_COMMAND_SETCAMERASHARPNESS, c->value); 1316 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1317 meye.params.sharpness = c->value; 1317 meye.params.sharpness = c->value;
1318 break; 1318 break;
1319 case V4L2_CID_PICTURE: 1319 case V4L2_CID_PICTURE:
1320 sonypi_camera_command( 1320 sony_pic_camera_command(
1321 SONYPI_COMMAND_SETCAMERAPICTURE, c->value); 1321 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1322 meye.params.picture = c->value; 1322 meye.params.picture = c->value;
1323 break; 1323 break;
1324 case V4L2_CID_JPEGQUAL: 1324 case V4L2_CID_JPEGQUAL:
@@ -1848,7 +1848,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1848 memcpy(meye.video_dev, &meye_template, sizeof(meye_template)); 1848 memcpy(meye.video_dev, &meye_template, sizeof(meye_template));
1849 meye.video_dev->dev = &meye.mchip_dev->dev; 1849 meye.video_dev->dev = &meye.mchip_dev->dev;
1850 1850
1851 if ((ret = sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 1))) { 1851 if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) {
1852 printk(KERN_ERR "meye: unable to power on the camera\n"); 1852 printk(KERN_ERR "meye: unable to power on the camera\n");
1853 printk(KERN_ERR "meye: did you enable the camera in " 1853 printk(KERN_ERR "meye: did you enable the camera in "
1854 "sonypi using the module options ?\n"); 1854 "sonypi using the module options ?\n");
@@ -1928,13 +1928,13 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1928 meye.params.picture = 0; 1928 meye.params.picture = 0;
1929 meye.params.framerate = 0; 1929 meye.params.framerate = 0;
1930 1930
1931 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 32); 1931 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, 32);
1932 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 32); 1932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE, 32);
1933 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 32); 1933 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR, 32);
1934 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 32); 1934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST, 32);
1935 sonypi_camera_command(SONYPI_COMMAND_SETCAMERASHARPNESS, 32); 1935 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS, 32);
1936 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 0); 1936 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0);
1937 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 48); 1937 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48);
1938 1938
1939 printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n", 1939 printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n",
1940 MEYE_DRIVER_VERSION); 1940 MEYE_DRIVER_VERSION);
@@ -1953,7 +1953,7 @@ outremap:
1953outregions: 1953outregions:
1954 pci_disable_device(meye.mchip_dev); 1954 pci_disable_device(meye.mchip_dev);
1955outenabledev: 1955outenabledev:
1956 sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); 1956 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1957outsonypienable: 1957outsonypienable:
1958 kfifo_free(meye.doneq); 1958 kfifo_free(meye.doneq);
1959outkfifoalloc2: 1959outkfifoalloc2:
@@ -1986,7 +1986,7 @@ static void __devexit meye_remove(struct pci_dev *pcidev)
1986 1986
1987 pci_disable_device(meye.mchip_dev); 1987 pci_disable_device(meye.mchip_dev);
1988 1988
1989 sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); 1989 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1990 1990
1991 kfifo_free(meye.doneq); 1991 kfifo_free(meye.doneq);
1992 kfifo_free(meye.grabq); 1992 kfifo_free(meye.grabq);
diff --git a/drivers/media/video/meye.h b/drivers/media/video/meye.h
index ea107cb5c845..323d0074120d 100644
--- a/drivers/media/video/meye.h
+++ b/drivers/media/video/meye.h
@@ -255,7 +255,7 @@
255/****************************************************************************/ 255/****************************************************************************/
256 256
257/* Sony Programmable I/O Controller for accessing the camera commands */ 257/* Sony Programmable I/O Controller for accessing the camera commands */
258#include <linux/sonypi.h> 258#include <linux/sony-laptop.h>
259 259
260/* private API definitions */ 260/* private API definitions */
261#include <linux/meye.h> 261#include <linux/meye.h>
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 80b199fa0aa9..a3c525b2616a 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -112,14 +112,70 @@ config SONY_LAPTOP
112 depends on X86 && ACPI 112 depends on X86 && ACPI
113 select BACKLIGHT_CLASS_DEVICE 113 select BACKLIGHT_CLASS_DEVICE
114 ---help--- 114 ---help---
115 This mini-driver drives the SNC device present in the ACPI BIOS of 115 This mini-driver drives the SNC and SPIC devices present in the ACPI
116 the Sony Vaio laptops. 116 BIOS of the Sony Vaio laptops.
117 117
118 It gives access to some extra laptop functionalities. In its current 118 It gives access to some extra laptop functionalities like Bluetooth,
119 form, this driver let the user set or query the screen brightness 119 screen brightness control, Fn keys and allows powering on/off some
120 through the backlight subsystem and remove/apply power to some
121 devices. 120 devices.
122 121
123 Read <file:Documentation/sony-laptop.txt> for more information. 122 Read <file:Documentation/sony-laptop.txt> for more information.
124 123
124config SONY_LAPTOP_OLD
125 bool "Sonypi compatibility"
126 depends on SONY_LAPTOP
127 ---help---
128 Build the sonypi driver compatibility code into the sony-laptop driver.
129
130config THINKPAD_ACPI
131 tristate "ThinkPad ACPI Laptop Extras"
132 depends on X86 && ACPI
133 select BACKLIGHT_CLASS_DEVICE
134 select HWMON
135 ---help---
136 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
137 support for Fn-Fx key combinations, Bluetooth control, video
138 output switching, ThinkLight control, UltraBay eject and more.
139 For more information about this driver see
140 <file:Documentation/thinkpad-acpi.txt> and <http://ibm-acpi.sf.net/> .
141
142 This driver was formely known as ibm-acpi.
143
144 If you have an IBM or Lenovo ThinkPad laptop, say Y or M here.
145
146config THINKPAD_ACPI_DEBUG
147 bool "Verbose debug mode"
148 depends on THINKPAD_ACPI
149 default n
150 ---help---
151 Enables extra debugging information, at the expense of a slightly
152 increase in driver size.
153
154 If you are not sure, say N here.
155
156config THINKPAD_ACPI_DOCK
157 bool "Legacy Docking Station Support"
158 depends on THINKPAD_ACPI
159 depends on ACPI_DOCK=n
160 default n
161 ---help---
162 Allows the thinkpad_acpi driver to handle docking station events.
163 This support was made obsolete by the generic ACPI docking station
164 support (CONFIG_ACPI_DOCK). It will allow locking and removing the
165 laptop from the docking station, but will not properly connect PCI
166 devices.
167
168 If you are not sure, say N here.
169
170config THINKPAD_ACPI_BAY
171 bool "Legacy Removable Bay Support"
172 depends on THINKPAD_ACPI
173 default y
174 ---help---
175 Allows the thinkpad_acpi driver to handle removable bays. It will
176 eletrically disable the device in the bay, and also generate
177 notifications when the bay lever is ejected or inserted.
178
179 If you are not sure, say Y here.
180
125endmenu 181endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 7793ccd79049..e32516459138 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_TIFM_CORE) += tifm_core.o
12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
13obj-$(CONFIG_SGI_IOC4) += ioc4.o 13obj-$(CONFIG_SGI_IOC4) += ioc4.o
14obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o 14obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
15obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index 4b232124a1ab..65c32a95e121 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * 4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor 5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * Copyright (C) 2006 Corentin Chary 6 * Copyright (C) 2006-2007 Corentin Chary
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@
48#include <acpi/acpi_bus.h> 48#include <acpi/acpi_bus.h>
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
50 50
51#define ASUS_LAPTOP_VERSION "0.40" 51#define ASUS_LAPTOP_VERSION "0.41"
52 52
53#define ASUS_HOTK_NAME "Asus Laptop Support" 53#define ASUS_HOTK_NAME "Asus Laptop Support"
54#define ASUS_HOTK_CLASS "hotkey" 54#define ASUS_HOTK_CLASS "hotkey"
@@ -81,7 +81,8 @@
81#define TLED_ON 0x08 //touchpad LED 81#define TLED_ON 0x08 //touchpad LED
82#define RLED_ON 0x10 //Record LED 82#define RLED_ON 0x10 //Record LED
83#define PLED_ON 0x20 //Phone LED 83#define PLED_ON 0x20 //Phone LED
84#define LCD_ON 0x40 //LCD backlight 84#define GLED_ON 0x40 //Gaming LED
85#define LCD_ON 0x80 //LCD backlight
85 86
86#define ASUS_LOG ASUS_HOTK_FILE ": " 87#define ASUS_LOG ASUS_HOTK_FILE ": "
87#define ASUS_ERR KERN_ERR ASUS_LOG 88#define ASUS_ERR KERN_ERR ASUS_LOG
@@ -94,6 +95,19 @@ MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
94MODULE_DESCRIPTION(ASUS_HOTK_NAME); 95MODULE_DESCRIPTION(ASUS_HOTK_NAME);
95MODULE_LICENSE("GPL"); 96MODULE_LICENSE("GPL");
96 97
98/* WAPF defines the behavior of the Fn+Fx wlan key
99 * The significance of values is yet to be found, but
100 * most of the time:
101 * 0x0 will do nothing
102 * 0x1 will allow to control the device with Fn+Fx key.
103 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
104 * 0x5 like 0x1 or 0x4
105 * So, if something doesn't work as you want, just try other values =)
106 */
107static uint wapf = 1;
108module_param(wapf, uint, 0644);
109MODULE_PARM_DESC(wapf, "WAPF value");
110
97#define ASUS_HANDLE(object, paths...) \ 111#define ASUS_HANDLE(object, paths...) \
98 static acpi_handle object##_handle = NULL; \ 112 static acpi_handle object##_handle = NULL; \
99 static char *object##_paths[] = { paths } 113 static char *object##_paths[] = { paths }
@@ -103,6 +117,7 @@ ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
103ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED"); 117ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
104ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ 118ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
105ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ 119ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
120ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
106 121
107/* LEDD */ 122/* LEDD */
108ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM"); 123ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
@@ -221,6 +236,7 @@ ASUS_LED(mled, "mail");
221ASUS_LED(tled, "touchpad"); 236ASUS_LED(tled, "touchpad");
222ASUS_LED(rled, "record"); 237ASUS_LED(rled, "record");
223ASUS_LED(pled, "phone"); 238ASUS_LED(pled, "phone");
239ASUS_LED(gled, "gaming");
224 240
225/* 241/*
226 * This function evaluates an ACPI method, given an int as parameter, the 242 * This function evaluates an ACPI method, given an int as parameter, the
@@ -245,32 +261,19 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
245 return (status == AE_OK); 261 return (status == AE_OK);
246} 262}
247 263
248static int read_acpi_int(acpi_handle handle, const char *method, int *val,
249 struct acpi_object_list *params)
250{
251 struct acpi_buffer output;
252 union acpi_object out_obj;
253 acpi_status status;
254
255 output.length = sizeof(out_obj);
256 output.pointer = &out_obj;
257
258 status = acpi_evaluate_object(handle, (char *)method, params, &output);
259 *val = out_obj.integer.value;
260 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
261}
262
263static int read_wireless_status(int mask) 264static int read_wireless_status(int mask)
264{ 265{
265 int status; 266 ulong status;
267 acpi_status rv = AE_OK;
266 268
267 if (!wireless_status_handle) 269 if (!wireless_status_handle)
268 return (hotk->status & mask) ? 1 : 0; 270 return (hotk->status & mask) ? 1 : 0;
269 271
270 if (read_acpi_int(wireless_status_handle, NULL, &status, NULL)) { 272 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
271 return (status & mask) ? 1 : 0; 273 if (ACPI_FAILURE(rv))
272 } else
273 printk(ASUS_WARNING "Error reading Wireless status\n"); 274 printk(ASUS_WARNING "Error reading Wireless status\n");
275 else
276 return (status & mask) ? 1 : 0;
274 277
275 return (hotk->status & mask) ? 1 : 0; 278 return (hotk->status & mask) ? 1 : 0;
276} 279}
@@ -285,19 +288,28 @@ static int read_status(int mask)
285 return (hotk->status & mask) ? 1 : 0; 288 return (hotk->status & mask) ? 1 : 0;
286} 289}
287 290
288static void write_status(acpi_handle handle, int out, int mask, int invert) 291static void write_status(acpi_handle handle, int out, int mask)
289{ 292{
290 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask); 293 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
291 294
292 if (invert) /* invert target value */ 295 switch (mask) {
296 case MLED_ON:
293 out = !out & 0x1; 297 out = !out & 0x1;
298 break;
299 case GLED_ON:
300 out = (out & 0x1) + 1;
301 break;
302 default:
303 out &= 0x1;
304 break;
305 }
294 306
295 if (handle && !write_acpi_int(handle, NULL, out, NULL)) 307 if (handle && !write_acpi_int(handle, NULL, out, NULL))
296 printk(ASUS_WARNING " write failed\n"); 308 printk(ASUS_WARNING " write failed %x\n", mask);
297} 309}
298 310
299/* /sys/class/led handlers */ 311/* /sys/class/led handlers */
300#define ASUS_LED_HANDLER(object, mask, invert) \ 312#define ASUS_LED_HANDLER(object, mask) \
301 static void object##_led_set(struct led_classdev *led_cdev, \ 313 static void object##_led_set(struct led_classdev *led_cdev, \
302 enum led_brightness value) \ 314 enum led_brightness value) \
303 { \ 315 { \
@@ -307,13 +319,14 @@ static void write_status(acpi_handle handle, int out, int mask, int invert)
307 static void object##_led_update(struct work_struct *ignored) \ 319 static void object##_led_update(struct work_struct *ignored) \
308 { \ 320 { \
309 int value = object##_led_wk; \ 321 int value = object##_led_wk; \
310 write_status(object##_set_handle, value, (mask), (invert)); \ 322 write_status(object##_set_handle, value, (mask)); \
311 } 323 }
312 324
313ASUS_LED_HANDLER(mled, MLED_ON, 1); 325ASUS_LED_HANDLER(mled, MLED_ON);
314ASUS_LED_HANDLER(pled, PLED_ON, 0); 326ASUS_LED_HANDLER(pled, PLED_ON);
315ASUS_LED_HANDLER(rled, RLED_ON, 0); 327ASUS_LED_HANDLER(rled, RLED_ON);
316ASUS_LED_HANDLER(tled, TLED_ON, 0); 328ASUS_LED_HANDLER(tled, TLED_ON);
329ASUS_LED_HANDLER(gled, GLED_ON);
317 330
318static int get_lcd_state(void) 331static int get_lcd_state(void)
319{ 332{
@@ -338,7 +351,7 @@ static int set_lcd_state(int value)
338 printk(ASUS_WARNING "Error switching LCD\n"); 351 printk(ASUS_WARNING "Error switching LCD\n");
339 } 352 }
340 353
341 write_status(NULL, lcd, LCD_ON, 0); 354 write_status(NULL, lcd, LCD_ON);
342 return 0; 355 return 0;
343} 356}
344 357
@@ -354,9 +367,11 @@ static void lcd_blank(int blank)
354 367
355static int read_brightness(struct backlight_device *bd) 368static int read_brightness(struct backlight_device *bd)
356{ 369{
357 int value; 370 ulong value;
371 acpi_status rv = AE_OK;
358 372
359 if (!read_acpi_int(brightness_get_handle, NULL, &value, NULL)) 373 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
374 if (ACPI_FAILURE(rv))
360 printk(ASUS_WARNING "Error reading brightness\n"); 375 printk(ASUS_WARNING "Error reading brightness\n");
361 376
362 return value; 377 return value;
@@ -403,8 +418,10 @@ static ssize_t show_infos(struct device *dev,
403 struct device_attribute *attr, char *page) 418 struct device_attribute *attr, char *page)
404{ 419{
405 int len = 0; 420 int len = 0;
406 int temp; 421 ulong temp;
407 char buf[16]; //enough for all info 422 char buf[16]; //enough for all info
423 acpi_status rv = AE_OK;
424
408 /* 425 /*
409 * We use the easy way, we don't care of off and count, so we don't set eof 426 * We use the easy way, we don't care of off and count, so we don't set eof
410 * to 1 427 * to 1
@@ -418,9 +435,10 @@ static ssize_t show_infos(struct device *dev,
418 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. 435 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
419 * The significance of others is yet to be found. 436 * The significance of others is yet to be found.
420 */ 437 */
421 if (read_acpi_int(hotk->handle, "SFUN", &temp, NULL)) 438 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
422 len += 439 if (!ACPI_FAILURE(rv))
423 sprintf(page + len, "SFUN value : 0x%04x\n", temp); 440 len += sprintf(page + len, "SFUN value : 0x%04x\n",
441 (uint) temp);
424 /* 442 /*
425 * Another value for userspace: the ASYM method returns 0x02 for 443 * Another value for userspace: the ASYM method returns 0x02 for
426 * battery low and 0x04 for battery critical, its readings tend to be 444 * battery low and 0x04 for battery critical, its readings tend to be
@@ -428,9 +446,10 @@ static ssize_t show_infos(struct device *dev,
428 * Note: since not all the laptops provide this method, errors are 446 * Note: since not all the laptops provide this method, errors are
429 * silently ignored. 447 * silently ignored.
430 */ 448 */
431 if (read_acpi_int(hotk->handle, "ASYM", &temp, NULL)) 449 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
432 len += 450 if (!ACPI_FAILURE(rv))
433 sprintf(page + len, "ASYM value : 0x%04x\n", temp); 451 len += sprintf(page + len, "ASYM value : 0x%04x\n",
452 (uint) temp);
434 if (asus_info) { 453 if (asus_info) {
435 snprintf(buf, 16, "%d", asus_info->length); 454 snprintf(buf, 16, "%d", asus_info->length);
436 len += sprintf(page + len, "DSDT length : %s\n", buf); 455 len += sprintf(page + len, "DSDT length : %s\n", buf);
@@ -465,7 +484,7 @@ static int parse_arg(const char *buf, unsigned long count, int *val)
465} 484}
466 485
467static ssize_t store_status(const char *buf, size_t count, 486static ssize_t store_status(const char *buf, size_t count,
468 acpi_handle handle, int mask, int invert) 487 acpi_handle handle, int mask)
469{ 488{
470 int rv, value; 489 int rv, value;
471 int out = 0; 490 int out = 0;
@@ -474,7 +493,7 @@ static ssize_t store_status(const char *buf, size_t count,
474 if (rv > 0) 493 if (rv > 0)
475 out = value ? 1 : 0; 494 out = value ? 1 : 0;
476 495
477 write_status(handle, out, mask, invert); 496 write_status(handle, out, mask);
478 497
479 return rv; 498 return rv;
480} 499}
@@ -515,7 +534,7 @@ static ssize_t show_wlan(struct device *dev,
515static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, 534static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
516 const char *buf, size_t count) 535 const char *buf, size_t count)
517{ 536{
518 return store_status(buf, count, wl_switch_handle, WL_ON, 0); 537 return store_status(buf, count, wl_switch_handle, WL_ON);
519} 538}
520 539
521/* 540/*
@@ -531,7 +550,7 @@ static ssize_t store_bluetooth(struct device *dev,
531 struct device_attribute *attr, const char *buf, 550 struct device_attribute *attr, const char *buf,
532 size_t count) 551 size_t count)
533{ 552{
534 return store_status(buf, count, bt_switch_handle, BT_ON, 0); 553 return store_status(buf, count, bt_switch_handle, BT_ON);
535} 554}
536 555
537/* 556/*
@@ -547,12 +566,15 @@ static void set_display(int value)
547 566
548static int read_display(void) 567static int read_display(void)
549{ 568{
550 int value = 0; 569 ulong value = 0;
570 acpi_status rv = AE_OK;
551 571
552 /* In most of the case, we know how to set the display, but sometime 572 /* In most of the case, we know how to set the display, but sometime
553 we can't read it */ 573 we can't read it */
554 if (display_get_handle) { 574 if (display_get_handle) {
555 if (!read_acpi_int(display_get_handle, NULL, &value, NULL)) 575 rv = acpi_evaluate_integer(display_get_handle, NULL,
576 NULL, &value);
577 if (ACPI_FAILURE(rv))
556 printk(ASUS_WARNING "Error reading display status\n"); 578 printk(ASUS_WARNING "Error reading display status\n");
557 } 579 }
558 580
@@ -656,10 +678,10 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
656 * switched 678 * switched
657 */ 679 */
658 if (event == ATKD_LCD_ON) { 680 if (event == ATKD_LCD_ON) {
659 write_status(NULL, 1, LCD_ON, 0); 681 write_status(NULL, 1, LCD_ON);
660 lcd_blank(FB_BLANK_UNBLANK); 682 lcd_blank(FB_BLANK_UNBLANK);
661 } else if (event == ATKD_LCD_OFF) { 683 } else if (event == ATKD_LCD_OFF) {
662 write_status(NULL, 0, LCD_ON, 0); 684 write_status(NULL, 0, LCD_ON);
663 lcd_blank(FB_BLANK_POWERDOWN); 685 lcd_blank(FB_BLANK_POWERDOWN);
664 } 686 }
665 687
@@ -771,7 +793,7 @@ static int asus_hotk_get_info(void)
771{ 793{
772 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 794 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
773 union acpi_object *model = NULL; 795 union acpi_object *model = NULL;
774 int bsts_result, hwrs_result; 796 ulong bsts_result, hwrs_result;
775 char *string = NULL; 797 char *string = NULL;
776 acpi_status status; 798 acpi_status status;
777 799
@@ -794,11 +816,16 @@ static int asus_hotk_get_info(void)
794 } 816 }
795 817
796 /* This needs to be called for some laptops to init properly */ 818 /* This needs to be called for some laptops to init properly */
797 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result, NULL)) 819 status =
820 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
821 if (ACPI_FAILURE(status))
798 printk(ASUS_WARNING "Error calling BSTS\n"); 822 printk(ASUS_WARNING "Error calling BSTS\n");
799 else if (bsts_result) 823 else if (bsts_result)
800 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n", 824 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
801 bsts_result); 825 (uint) bsts_result);
826
827 /* This too ... */
828 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
802 829
803 /* 830 /*
804 * Try to match the object returned by INIT to the specific model. 831 * Try to match the object returned by INIT to the specific model.
@@ -831,6 +858,7 @@ static int asus_hotk_get_info(void)
831 ASUS_HANDLE_INIT(tled_set); 858 ASUS_HANDLE_INIT(tled_set);
832 ASUS_HANDLE_INIT(rled_set); 859 ASUS_HANDLE_INIT(rled_set);
833 ASUS_HANDLE_INIT(pled_set); 860 ASUS_HANDLE_INIT(pled_set);
861 ASUS_HANDLE_INIT(gled_set);
834 862
835 ASUS_HANDLE_INIT(ledd_set); 863 ASUS_HANDLE_INIT(ledd_set);
836 864
@@ -840,7 +868,9 @@ static int asus_hotk_get_info(void)
840 * The significance of others is yet to be found. 868 * The significance of others is yet to be found.
841 * If we don't find the method, we assume the device are present. 869 * If we don't find the method, we assume the device are present.
842 */ 870 */
843 if (!read_acpi_int(hotk->handle, "HRWS", &hwrs_result, NULL)) 871 status =
872 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
873 if (ACPI_FAILURE(status))
844 hwrs_result = WL_HWRS | BT_HWRS; 874 hwrs_result = WL_HWRS | BT_HWRS;
845 875
846 if (hwrs_result & WL_HWRS) 876 if (hwrs_result & WL_HWRS)
@@ -928,11 +958,15 @@ static int asus_hotk_add(struct acpi_device *device)
928 asus_hotk_found = 1; 958 asus_hotk_found = 1;
929 959
930 /* WLED and BLED are on by default */ 960 /* WLED and BLED are on by default */
931 write_status(bt_switch_handle, 1, BT_ON, 0); 961 write_status(bt_switch_handle, 1, BT_ON);
932 write_status(wl_switch_handle, 1, WL_ON, 0); 962 write_status(wl_switch_handle, 1, WL_ON);
963
964 /* If the h/w switch is off, we need to check the real status */
965 write_status(NULL, read_status(BT_ON), BT_ON);
966 write_status(NULL, read_status(WL_ON), WL_ON);
933 967
934 /* LCD Backlight is on by default */ 968 /* LCD Backlight is on by default */
935 write_status(NULL, 1, LCD_ON, 0); 969 write_status(NULL, 1, LCD_ON);
936 970
937 /* LED display is off by default */ 971 /* LED display is off by default */
938 hotk->ledd_status = 0xFFF; 972 hotk->ledd_status = 0xFFF;
@@ -991,6 +1025,7 @@ static void asus_led_exit(void)
991 ASUS_LED_UNREGISTER(tled); 1025 ASUS_LED_UNREGISTER(tled);
992 ASUS_LED_UNREGISTER(pled); 1026 ASUS_LED_UNREGISTER(pled);
993 ASUS_LED_UNREGISTER(rled); 1027 ASUS_LED_UNREGISTER(rled);
1028 ASUS_LED_UNREGISTER(gled);
994 1029
995 destroy_workqueue(led_workqueue); 1030 destroy_workqueue(led_workqueue);
996} 1031}
@@ -1062,6 +1097,10 @@ static int asus_led_init(struct device *dev)
1062 if (rv) 1097 if (rv)
1063 return rv; 1098 return rv;
1064 1099
1100 rv = ASUS_LED_REGISTER(gled, dev);
1101 if (rv)
1102 return rv;
1103
1065 led_workqueue = create_singlethread_workqueue("led_workqueue"); 1104 led_workqueue = create_singlethread_workqueue("led_workqueue");
1066 if (!led_workqueue) 1105 if (!led_workqueue)
1067 return -ENOMEM; 1106 return -ENOMEM;
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index ac708bc2f9f3..c15c1f61bd1b 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ACPI Sony Notebook Control Driver (SNC) 2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
3 * 3 *
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net> 4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it> 5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
@@ -7,6 +7,25 @@
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c 7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors. 8 * which are copyrighted by their respective authors.
9 * 9 *
10 * The SNY6001 driver part is based on the sonypi driver which includes
11 * material from:
12 *
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
14 *
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
16 *
17 * Copyright (C) 2001-2002 Alcôve <www.alcove.com>
18 *
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
20 *
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
22 *
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
24 *
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
26 *
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
28 *
10 * This program is free software; you can redistribute it and/or modify 29 * 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 30 * 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 31 * the Free Software Foundation; either version 2 of the License, or
@@ -31,40 +50,404 @@
31#include <linux/backlight.h> 50#include <linux/backlight.h>
32#include <linux/platform_device.h> 51#include <linux/platform_device.h>
33#include <linux/err.h> 52#include <linux/err.h>
53#include <linux/dmi.h>
54#include <linux/pci.h>
55#include <linux/interrupt.h>
56#include <linux/delay.h>
57#include <linux/input.h>
58#include <linux/kfifo.h>
59#include <linux/workqueue.h>
60#include <linux/acpi.h>
34#include <acpi/acpi_drivers.h> 61#include <acpi/acpi_drivers.h>
35#include <acpi/acpi_bus.h> 62#include <acpi/acpi_bus.h>
36#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/sonypi.h>
65#include <linux/sony-laptop.h>
66#ifdef CONFIG_SONY_LAPTOP_OLD
67#include <linux/poll.h>
68#include <linux/miscdevice.h>
69#endif
37 70
38#define ACPI_SNC_CLASS "sony" 71#define DRV_PFX "sony-laptop: "
39#define ACPI_SNC_HID "SNY5001" 72#define dprintk(msg...) do { \
40#define ACPI_SNC_DRIVER_NAME "ACPI Sony Notebook Control Driver v0.4" 73 if (debug) printk(KERN_WARNING DRV_PFX msg); \
74} while (0)
41 75
42/* the device uses 1-based values, while the backlight subsystem uses 76#define SONY_LAPTOP_DRIVER_VERSION "0.5"
43 0-based values */ 77
44#define SONY_MAX_BRIGHTNESS 8 78#define SONY_NC_CLASS "sony-nc"
79#define SONY_NC_HID "SNY5001"
80#define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
45 81
46#define LOG_PFX KERN_WARNING "sony-laptop: " 82#define SONY_PIC_CLASS "sony-pic"
83#define SONY_PIC_HID "SNY6001"
84#define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
47 85
48MODULE_AUTHOR("Stelian Pop, Mattia Dongili"); 86MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
49MODULE_DESCRIPTION(ACPI_SNC_DRIVER_NAME); 87MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
50MODULE_LICENSE("GPL"); 88MODULE_LICENSE("GPL");
89MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
51 90
52static int debug; 91static int debug;
53module_param(debug, int, 0); 92module_param(debug, int, 0);
54MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help " 93MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
55 "the development of this driver"); 94 "the development of this driver");
56 95
57static ssize_t sony_acpi_show(struct device *, struct device_attribute *, 96static int no_spic; /* = 0 */
97module_param(no_spic, int, 0444);
98MODULE_PARM_DESC(no_spic,
99 "set this if you don't want to enable the SPIC device");
100
101static int compat; /* = 0 */
102module_param(compat, int, 0444);
103MODULE_PARM_DESC(compat,
104 "set this if you want to enable backward compatibility mode");
105
106static unsigned long mask = 0xffffffff;
107module_param(mask, ulong, 0644);
108MODULE_PARM_DESC(mask,
109 "set this to the mask of event you want to enable (see doc)");
110
111static int camera; /* = 0 */
112module_param(camera, int, 0444);
113MODULE_PARM_DESC(camera,
114 "set this to 1 to enable Motion Eye camera controls "
115 "(only use it if you have a C1VE or C1VN model)");
116
117#ifdef CONFIG_SONY_LAPTOP_OLD
118static int minor = -1;
119module_param(minor, int, 0);
120MODULE_PARM_DESC(minor,
121 "minor number of the misc device for the SPIC compatibility code, "
122 "default is -1 (automatic)");
123#endif
124
125/*********** Input Devices ***********/
126
127#define SONY_LAPTOP_BUF_SIZE 128
128struct sony_laptop_input_s {
129 atomic_t users;
130 struct input_dev *jog_dev;
131 struct input_dev *key_dev;
132 struct kfifo *fifo;
133 spinlock_t fifo_lock;
134 struct workqueue_struct *wq;
135};
136static struct sony_laptop_input_s sony_laptop_input = {
137 .users = ATOMIC_INIT(0),
138};
139
140struct sony_laptop_keypress {
141 struct input_dev *dev;
142 int key;
143};
144
145/* Correspondance table between sonypi events and input layer events */
146static struct {
147 int sonypiev;
148 int inputev;
149} sony_laptop_inputkeys[] = {
150 { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA },
151 { SONYPI_EVENT_FNKEY_ONLY, KEY_FN },
152 { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC },
153 { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 },
154 { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 },
155 { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 },
156 { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 },
157 { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 },
158 { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 },
159 { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 },
160 { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 },
161 { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 },
162 { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 },
163 { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 },
164 { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 },
165 { SONYPI_EVENT_FNKEY_1, KEY_FN_1 },
166 { SONYPI_EVENT_FNKEY_2, KEY_FN_2 },
167 { SONYPI_EVENT_FNKEY_D, KEY_FN_D },
168 { SONYPI_EVENT_FNKEY_E, KEY_FN_E },
169 { SONYPI_EVENT_FNKEY_F, KEY_FN_F },
170 { SONYPI_EVENT_FNKEY_S, KEY_FN_S },
171 { SONYPI_EVENT_FNKEY_B, KEY_FN_B },
172 { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE },
173 { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE },
174 { SONYPI_EVENT_PKEY_P1, KEY_PROG1 },
175 { SONYPI_EVENT_PKEY_P2, KEY_PROG2 },
176 { SONYPI_EVENT_PKEY_P3, KEY_PROG3 },
177 { SONYPI_EVENT_BACK_PRESSED, KEY_BACK },
178 { SONYPI_EVENT_HELP_PRESSED, KEY_HELP },
179 { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM },
180 { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB },
181 { 0, 0 },
182};
183
184/* release buttons after a short delay if pressed */
185static void do_sony_laptop_release_key(struct work_struct *work)
186{
187 struct sony_laptop_keypress kp;
188
189 while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
190 sizeof(kp)) == sizeof(kp)) {
191 msleep(10);
192 input_report_key(kp.dev, kp.key, 0);
193 input_sync(kp.dev);
194 }
195}
196static DECLARE_WORK(sony_laptop_release_key_work,
197 do_sony_laptop_release_key);
198
199/* forward event to the input subsytem */
200static void sony_laptop_report_input_event(u8 event)
201{
202 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
203 struct input_dev *key_dev = sony_laptop_input.key_dev;
204 struct sony_laptop_keypress kp = { NULL };
205 int i;
206
207 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
208 /* Nothing, not all VAIOs generate this event */
209 return;
210 }
211
212 /* report events */
213 switch (event) {
214 /* jog_dev events */
215 case SONYPI_EVENT_JOGDIAL_UP:
216 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
217 input_report_rel(jog_dev, REL_WHEEL, 1);
218 input_sync(jog_dev);
219 return;
220
221 case SONYPI_EVENT_JOGDIAL_DOWN:
222 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
223 input_report_rel(jog_dev, REL_WHEEL, -1);
224 input_sync(jog_dev);
225 return;
226
227 /* key_dev events */
228 case SONYPI_EVENT_JOGDIAL_PRESSED:
229 kp.key = BTN_MIDDLE;
230 kp.dev = jog_dev;
231 break;
232
233 default:
234 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
235 if (event == sony_laptop_inputkeys[i].sonypiev) {
236 kp.dev = key_dev;
237 kp.key = sony_laptop_inputkeys[i].inputev;
238 break;
239 }
240 break;
241 }
242
243 if (kp.dev) {
244 input_report_key(kp.dev, kp.key, 1);
245 input_sync(kp.dev);
246 kfifo_put(sony_laptop_input.fifo,
247 (unsigned char *)&kp, sizeof(kp));
248
249 if (!work_pending(&sony_laptop_release_key_work))
250 queue_work(sony_laptop_input.wq,
251 &sony_laptop_release_key_work);
252 } else
253 dprintk("unknown input event %.2x\n", event);
254}
255
256static int sony_laptop_setup_input(void)
257{
258 struct input_dev *jog_dev;
259 struct input_dev *key_dev;
260 int i;
261 int error;
262
263 /* don't run again if already initialized */
264 if (atomic_add_return(1, &sony_laptop_input.users) > 1)
265 return 0;
266
267 /* kfifo */
268 spin_lock_init(&sony_laptop_input.fifo_lock);
269 sony_laptop_input.fifo =
270 kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
271 &sony_laptop_input.fifo_lock);
272 if (IS_ERR(sony_laptop_input.fifo)) {
273 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
274 error = PTR_ERR(sony_laptop_input.fifo);
275 goto err_dec_users;
276 }
277
278 /* init workqueue */
279 sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
280 if (!sony_laptop_input.wq) {
281 printk(KERN_ERR DRV_PFX
282 "Unabe to create workqueue.\n");
283 error = -ENXIO;
284 goto err_free_kfifo;
285 }
286
287 /* input keys */
288 key_dev = input_allocate_device();
289 if (!key_dev) {
290 error = -ENOMEM;
291 goto err_destroy_wq;
292 }
293
294 key_dev->name = "Sony Vaio Keys";
295 key_dev->id.bustype = BUS_ISA;
296 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
297
298 /* Initialize the Input Drivers: special keys */
299 key_dev->evbit[0] = BIT(EV_KEY);
300 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
301 if (sony_laptop_inputkeys[i].inputev)
302 set_bit(sony_laptop_inputkeys[i].inputev,
303 key_dev->keybit);
304
305 error = input_register_device(key_dev);
306 if (error)
307 goto err_free_keydev;
308
309 sony_laptop_input.key_dev = key_dev;
310
311 /* jogdial */
312 jog_dev = input_allocate_device();
313 if (!jog_dev) {
314 error = -ENOMEM;
315 goto err_unregister_keydev;
316 }
317
318 jog_dev->name = "Sony Vaio Jogdial";
319 jog_dev->id.bustype = BUS_ISA;
320 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
321
322 jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
323 jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
324 jog_dev->relbit[0] = BIT(REL_WHEEL);
325
326 error = input_register_device(jog_dev);
327 if (error)
328 goto err_free_jogdev;
329
330 sony_laptop_input.jog_dev = jog_dev;
331
332 return 0;
333
334err_free_jogdev:
335 input_free_device(jog_dev);
336
337err_unregister_keydev:
338 input_unregister_device(key_dev);
339 /* to avoid kref underflow below at input_free_device */
340 key_dev = NULL;
341
342err_free_keydev:
343 input_free_device(key_dev);
344
345err_destroy_wq:
346 destroy_workqueue(sony_laptop_input.wq);
347
348err_free_kfifo:
349 kfifo_free(sony_laptop_input.fifo);
350
351err_dec_users:
352 atomic_dec(&sony_laptop_input.users);
353 return error;
354}
355
356static void sony_laptop_remove_input(void)
357{
358 /* cleanup only after the last user has gone */
359 if (!atomic_dec_and_test(&sony_laptop_input.users))
360 return;
361
362 /* flush workqueue first */
363 flush_workqueue(sony_laptop_input.wq);
364
365 /* destroy input devs */
366 input_unregister_device(sony_laptop_input.key_dev);
367 sony_laptop_input.key_dev = NULL;
368
369 if (sony_laptop_input.jog_dev) {
370 input_unregister_device(sony_laptop_input.jog_dev);
371 sony_laptop_input.jog_dev = NULL;
372 }
373
374 destroy_workqueue(sony_laptop_input.wq);
375 kfifo_free(sony_laptop_input.fifo);
376}
377
378/*********** Platform Device ***********/
379
380static atomic_t sony_pf_users = ATOMIC_INIT(0);
381static struct platform_driver sony_pf_driver = {
382 .driver = {
383 .name = "sony-laptop",
384 .owner = THIS_MODULE,
385 }
386};
387static struct platform_device *sony_pf_device;
388
389static int sony_pf_add(void)
390{
391 int ret = 0;
392
393 /* don't run again if already initialized */
394 if (atomic_add_return(1, &sony_pf_users) > 1)
395 return 0;
396
397 ret = platform_driver_register(&sony_pf_driver);
398 if (ret)
399 goto out;
400
401 sony_pf_device = platform_device_alloc("sony-laptop", -1);
402 if (!sony_pf_device) {
403 ret = -ENOMEM;
404 goto out_platform_registered;
405 }
406
407 ret = platform_device_add(sony_pf_device);
408 if (ret)
409 goto out_platform_alloced;
410
411 return 0;
412
413 out_platform_alloced:
414 platform_device_put(sony_pf_device);
415 sony_pf_device = NULL;
416 out_platform_registered:
417 platform_driver_unregister(&sony_pf_driver);
418 out:
419 atomic_dec(&sony_pf_users);
420 return ret;
421}
422
423static void sony_pf_remove(void)
424{
425 /* deregister only after the last user has gone */
426 if (!atomic_dec_and_test(&sony_pf_users))
427 return;
428
429 platform_device_del(sony_pf_device);
430 platform_device_put(sony_pf_device);
431 platform_driver_unregister(&sony_pf_driver);
432}
433
434/*********** SNC (SNY5001) Device ***********/
435
436/* the device uses 1-based values, while the backlight subsystem uses
437 0-based values */
438#define SONY_MAX_BRIGHTNESS 8
439
440#define SNC_VALIDATE_IN 0
441#define SNC_VALIDATE_OUT 1
442
443static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
58 char *); 444 char *);
59static ssize_t sony_acpi_store(struct device *, struct device_attribute *, 445static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
60 const char *, size_t); 446 const char *, size_t);
61static int boolean_validate(const int, const int); 447static int boolean_validate(const int, const int);
62static int brightness_default_validate(const int, const int); 448static int brightness_default_validate(const int, const int);
63 449
64#define SNC_VALIDATE_IN 0 450struct sony_nc_value {
65#define SNC_VALIDATE_OUT 1
66
67struct sony_acpi_value {
68 char *name; /* name of the entry */ 451 char *name; /* name of the entry */
69 char **acpiget; /* names of the ACPI get function */ 452 char **acpiget; /* names of the ACPI get function */
70 char **acpiset; /* names of the ACPI set function */ 453 char **acpiset; /* names of the ACPI set function */
@@ -75,65 +458,65 @@ struct sony_acpi_value {
75 struct device_attribute devattr; /* sysfs atribute */ 458 struct device_attribute devattr; /* sysfs atribute */
76}; 459};
77 460
78#define HANDLE_NAMES(_name, _values...) \ 461#define SNC_HANDLE_NAMES(_name, _values...) \
79 static char *snc_##_name[] = { _values, NULL } 462 static char *snc_##_name[] = { _values, NULL }
80 463
81#define SONY_ACPI_VALUE(_name, _getters, _setters, _validate, _debug) \ 464#define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
82 { \ 465 { \
83 .name = __stringify(_name), \ 466 .name = __stringify(_name), \
84 .acpiget = _getters, \ 467 .acpiget = _getters, \
85 .acpiset = _setters, \ 468 .acpiset = _setters, \
86 .validate = _validate, \ 469 .validate = _validate, \
87 .debug = _debug, \ 470 .debug = _debug, \
88 .devattr = __ATTR(_name, 0, sony_acpi_show, sony_acpi_store), \ 471 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
89 } 472 }
90 473
91#define SONY_ACPI_VALUE_NULL { .name = NULL } 474#define SNC_HANDLE_NULL { .name = NULL }
92 475
93HANDLE_NAMES(fnkey_get, "GHKE"); 476SNC_HANDLE_NAMES(fnkey_get, "GHKE");
94 477
95HANDLE_NAMES(brightness_def_get, "GPBR"); 478SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
96HANDLE_NAMES(brightness_def_set, "SPBR"); 479SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
97 480
98HANDLE_NAMES(cdpower_get, "GCDP"); 481SNC_HANDLE_NAMES(cdpower_get, "GCDP");
99HANDLE_NAMES(cdpower_set, "SCDP", "CDPW"); 482SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
100 483
101HANDLE_NAMES(audiopower_get, "GAZP"); 484SNC_HANDLE_NAMES(audiopower_get, "GAZP");
102HANDLE_NAMES(audiopower_set, "AZPW"); 485SNC_HANDLE_NAMES(audiopower_set, "AZPW");
103 486
104HANDLE_NAMES(lanpower_get, "GLNP"); 487SNC_HANDLE_NAMES(lanpower_get, "GLNP");
105HANDLE_NAMES(lanpower_set, "LNPW"); 488SNC_HANDLE_NAMES(lanpower_set, "LNPW");
106 489
107HANDLE_NAMES(PID_get, "GPID"); 490SNC_HANDLE_NAMES(PID_get, "GPID");
108 491
109HANDLE_NAMES(CTR_get, "GCTR"); 492SNC_HANDLE_NAMES(CTR_get, "GCTR");
110HANDLE_NAMES(CTR_set, "SCTR"); 493SNC_HANDLE_NAMES(CTR_set, "SCTR");
111 494
112HANDLE_NAMES(PCR_get, "GPCR"); 495SNC_HANDLE_NAMES(PCR_get, "GPCR");
113HANDLE_NAMES(PCR_set, "SPCR"); 496SNC_HANDLE_NAMES(PCR_set, "SPCR");
114 497
115HANDLE_NAMES(CMI_get, "GCMI"); 498SNC_HANDLE_NAMES(CMI_get, "GCMI");
116HANDLE_NAMES(CMI_set, "SCMI"); 499SNC_HANDLE_NAMES(CMI_set, "SCMI");
117 500
118static struct sony_acpi_value sony_acpi_values[] = { 501static struct sony_nc_value sony_nc_values[] = {
119 SONY_ACPI_VALUE(brightness_default, snc_brightness_def_get, 502 SNC_HANDLE(brightness_default, snc_brightness_def_get,
120 snc_brightness_def_set, brightness_default_validate, 0), 503 snc_brightness_def_set, brightness_default_validate, 0),
121 SONY_ACPI_VALUE(fnkey, snc_fnkey_get, NULL, NULL, 0), 504 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
122 SONY_ACPI_VALUE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0), 505 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
123 SONY_ACPI_VALUE(audiopower, snc_audiopower_get, snc_audiopower_set, 506 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
124 boolean_validate, 0), 507 boolean_validate, 0),
125 SONY_ACPI_VALUE(lanpower, snc_lanpower_get, snc_lanpower_set, 508 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
126 boolean_validate, 1), 509 boolean_validate, 1),
127 /* unknown methods */ 510 /* unknown methods */
128 SONY_ACPI_VALUE(PID, snc_PID_get, NULL, NULL, 1), 511 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
129 SONY_ACPI_VALUE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), 512 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
130 SONY_ACPI_VALUE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1), 513 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
131 SONY_ACPI_VALUE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1), 514 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
132 SONY_ACPI_VALUE_NULL 515 SNC_HANDLE_NULL
133}; 516};
134 517
135static acpi_handle sony_acpi_handle; 518static acpi_handle sony_nc_acpi_handle;
136static struct acpi_device *sony_acpi_acpi_device = NULL; 519static struct acpi_device *sony_nc_acpi_device = NULL;
137 520
138/* 521/*
139 * acpi_evaluate_object wrappers 522 * acpi_evaluate_object wrappers
@@ -153,7 +536,7 @@ static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
153 return 0; 536 return 0;
154 } 537 }
155 538
156 printk(LOG_PFX "acpi_callreadfunc failed\n"); 539 printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
157 540
158 return -1; 541 return -1;
159} 542}
@@ -179,7 +562,7 @@ static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
179 if (status == AE_OK) { 562 if (status == AE_OK) {
180 if (result != NULL) { 563 if (result != NULL) {
181 if (out_obj.type != ACPI_TYPE_INTEGER) { 564 if (out_obj.type != ACPI_TYPE_INTEGER) {
182 printk(LOG_PFX "acpi_evaluate_object bad " 565 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
183 "return type\n"); 566 "return type\n");
184 return -1; 567 return -1;
185 } 568 }
@@ -188,13 +571,13 @@ static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
188 return 0; 571 return 0;
189 } 572 }
190 573
191 printk(LOG_PFX "acpi_evaluate_object failed\n"); 574 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
192 575
193 return -1; 576 return -1;
194} 577}
195 578
196/* 579/*
197 * sony_acpi_values input/output validate functions 580 * sony_nc_values input/output validate functions
198 */ 581 */
199 582
200/* brightness_default_validate: 583/* brightness_default_validate:
@@ -229,19 +612,19 @@ static int boolean_validate(const int direction, const int value)
229} 612}
230 613
231/* 614/*
232 * Sysfs show/store common to all sony_acpi_values 615 * Sysfs show/store common to all sony_nc_values
233 */ 616 */
234static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr, 617static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
235 char *buffer) 618 char *buffer)
236{ 619{
237 int value; 620 int value;
238 struct sony_acpi_value *item = 621 struct sony_nc_value *item =
239 container_of(attr, struct sony_acpi_value, devattr); 622 container_of(attr, struct sony_nc_value, devattr);
240 623
241 if (!*item->acpiget) 624 if (!*item->acpiget)
242 return -EIO; 625 return -EIO;
243 626
244 if (acpi_callgetfunc(sony_acpi_handle, *item->acpiget, &value) < 0) 627 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
245 return -EIO; 628 return -EIO;
246 629
247 if (item->validate) 630 if (item->validate)
@@ -250,13 +633,13 @@ static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr,
250 return snprintf(buffer, PAGE_SIZE, "%d\n", value); 633 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
251} 634}
252 635
253static ssize_t sony_acpi_store(struct device *dev, 636static ssize_t sony_nc_sysfs_store(struct device *dev,
254 struct device_attribute *attr, 637 struct device_attribute *attr,
255 const char *buffer, size_t count) 638 const char *buffer, size_t count)
256{ 639{
257 int value; 640 int value;
258 struct sony_acpi_value *item = 641 struct sony_nc_value *item =
259 container_of(attr, struct sony_acpi_value, devattr); 642 container_of(attr, struct sony_nc_value, devattr);
260 643
261 if (!item->acpiset) 644 if (!item->acpiset)
262 return -EIO; 645 return -EIO;
@@ -272,118 +655,20 @@ static ssize_t sony_acpi_store(struct device *dev,
272 if (value < 0) 655 if (value < 0)
273 return value; 656 return value;
274 657
275 if (acpi_callsetfunc(sony_acpi_handle, *item->acpiset, value, NULL) < 0) 658 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
276 return -EIO; 659 return -EIO;
277 item->value = value; 660 item->value = value;
278 item->valid = 1; 661 item->valid = 1;
279 return count; 662 return count;
280} 663}
281 664
282/*
283 * Platform device
284 */
285static struct platform_driver sncpf_driver = {
286 .driver = {
287 .name = "sony-laptop",
288 .owner = THIS_MODULE,
289 }
290};
291static struct platform_device *sncpf_device;
292
293static int sony_snc_pf_add(void)
294{
295 acpi_handle handle;
296 struct sony_acpi_value *item;
297 int ret = 0;
298
299 ret = platform_driver_register(&sncpf_driver);
300 if (ret)
301 goto out;
302
303 sncpf_device = platform_device_alloc("sony-laptop", -1);
304 if (!sncpf_device) {
305 ret = -ENOMEM;
306 goto out_platform_registered;
307 }
308
309 ret = platform_device_add(sncpf_device);
310 if (ret)
311 goto out_platform_alloced;
312
313 for (item = sony_acpi_values; item->name; ++item) {
314
315 if (!debug && item->debug)
316 continue;
317
318 /* find the available acpiget as described in the DSDT */
319 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
320 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
321 *item->acpiget,
322 &handle))) {
323 if (debug)
324 printk(LOG_PFX "Found %s getter: %s\n",
325 item->name, *item->acpiget);
326 item->devattr.attr.mode |= S_IRUGO;
327 break;
328 }
329 }
330
331 /* find the available acpiset as described in the DSDT */
332 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
333 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
334 *item->acpiset,
335 &handle))) {
336 if (debug)
337 printk(LOG_PFX "Found %s setter: %s\n",
338 item->name, *item->acpiset);
339 item->devattr.attr.mode |= S_IWUSR;
340 break;
341 }
342 }
343
344 if (item->devattr.attr.mode != 0) {
345 ret =
346 device_create_file(&sncpf_device->dev,
347 &item->devattr);
348 if (ret)
349 goto out_sysfs;
350 }
351 }
352
353 return 0;
354
355 out_sysfs:
356 for (item = sony_acpi_values; item->name; ++item) {
357 device_remove_file(&sncpf_device->dev, &item->devattr);
358 }
359 platform_device_del(sncpf_device);
360 out_platform_alloced:
361 platform_device_put(sncpf_device);
362 out_platform_registered:
363 platform_driver_unregister(&sncpf_driver);
364 out:
365 return ret;
366}
367
368static void sony_snc_pf_remove(void)
369{
370 struct sony_acpi_value *item;
371
372 for (item = sony_acpi_values; item->name; ++item) {
373 device_remove_file(&sncpf_device->dev, &item->devattr);
374 }
375
376 platform_device_del(sncpf_device);
377 platform_device_put(sncpf_device);
378 platform_driver_unregister(&sncpf_driver);
379}
380 665
381/* 666/*
382 * Backlight device 667 * Backlight device
383 */ 668 */
384static int sony_backlight_update_status(struct backlight_device *bd) 669static int sony_backlight_update_status(struct backlight_device *bd)
385{ 670{
386 return acpi_callsetfunc(sony_acpi_handle, "SBRT", 671 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
387 bd->props.brightness + 1, NULL); 672 bd->props.brightness + 1, NULL);
388} 673}
389 674
@@ -391,7 +676,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
391{ 676{
392 int value; 677 int value;
393 678
394 if (acpi_callgetfunc(sony_acpi_handle, "GBRT", &value)) 679 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
395 return 0; 680 return 0;
396 /* brightness levels are 1-based, while backlight ones are 0-based */ 681 /* brightness levels are 1-based, while backlight ones are 0-based */
397 return value - 1; 682 return value - 1;
@@ -408,9 +693,9 @@ static struct backlight_ops sony_backlight_ops = {
408 */ 693 */
409static void sony_acpi_notify(acpi_handle handle, u32 event, void *data) 694static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
410{ 695{
411 if (debug) 696 dprintk("sony_acpi_notify, event: %d\n", event);
412 printk(LOG_PFX "sony_acpi_notify, event: %d\n", event); 697 sony_laptop_report_input_event(event);
413 acpi_bus_generate_event(sony_acpi_acpi_device, 1, event); 698 acpi_bus_generate_event(sony_nc_acpi_device, 1, event);
414} 699}
415 700
416static acpi_status sony_walk_callback(acpi_handle handle, u32 level, 701static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
@@ -422,7 +707,7 @@ static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
422 node = (struct acpi_namespace_node *)handle; 707 node = (struct acpi_namespace_node *)handle;
423 operand = (union acpi_operand_object *)node->object; 708 operand = (union acpi_operand_object *)node->object;
424 709
425 printk(LOG_PFX "method: name: %4.4s, args %X\n", node->name.ascii, 710 printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
426 (u32) operand->method.param_count); 711 (u32) operand->method.param_count);
427 712
428 return AE_OK; 713 return AE_OK;
@@ -431,16 +716,16 @@ static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
431/* 716/*
432 * ACPI device 717 * ACPI device
433 */ 718 */
434static int sony_acpi_resume(struct acpi_device *device) 719static int sony_nc_resume(struct acpi_device *device)
435{ 720{
436 struct sony_acpi_value *item; 721 struct sony_nc_value *item;
437 722
438 for (item = sony_acpi_values; item->name; item++) { 723 for (item = sony_nc_values; item->name; item++) {
439 int ret; 724 int ret;
440 725
441 if (!item->valid) 726 if (!item->valid)
442 continue; 727 continue;
443 ret = acpi_callsetfunc(sony_acpi_handle, *item->acpiset, 728 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
444 item->value, NULL); 729 item->value, NULL);
445 if (ret < 0) { 730 if (ret < 0) {
446 printk("%s: %d\n", __FUNCTION__, ret); 731 printk("%s: %d\n", __FUNCTION__, ret);
@@ -450,42 +735,55 @@ static int sony_acpi_resume(struct acpi_device *device)
450 return 0; 735 return 0;
451} 736}
452 737
453static int sony_acpi_add(struct acpi_device *device) 738static int sony_nc_add(struct acpi_device *device)
454{ 739{
455 acpi_status status; 740 acpi_status status;
456 int result = 0; 741 int result = 0;
457 acpi_handle handle; 742 acpi_handle handle;
743 struct sony_nc_value *item;
744
745 printk(KERN_INFO DRV_PFX "%s v%s.\n",
746 SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
458 747
459 sony_acpi_acpi_device = device; 748 sony_nc_acpi_device = device;
749 strcpy(acpi_device_class(device), "sony/hotkey");
460 750
461 sony_acpi_handle = device->handle; 751 sony_nc_acpi_handle = device->handle;
462 752
463 if (debug) { 753 if (debug) {
464 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_acpi_handle, 754 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
465 1, sony_walk_callback, NULL, NULL); 755 1, sony_walk_callback, NULL, NULL);
466 if (ACPI_FAILURE(status)) { 756 if (ACPI_FAILURE(status)) {
467 printk(LOG_PFX "unable to walk acpi resources\n"); 757 printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
468 result = -ENODEV; 758 result = -ENODEV;
469 goto outwalk; 759 goto outwalk;
470 } 760 }
471 } 761 }
472 762
473 status = acpi_install_notify_handler(sony_acpi_handle, 763 /* setup input devices and helper fifo */
764 result = sony_laptop_setup_input();
765 if (result) {
766 printk(KERN_ERR DRV_PFX
767 "Unabe to create input devices.\n");
768 goto outwalk;
769 }
770
771 status = acpi_install_notify_handler(sony_nc_acpi_handle,
474 ACPI_DEVICE_NOTIFY, 772 ACPI_DEVICE_NOTIFY,
475 sony_acpi_notify, NULL); 773 sony_acpi_notify, NULL);
476 if (ACPI_FAILURE(status)) { 774 if (ACPI_FAILURE(status)) {
477 printk(LOG_PFX "unable to install notify handler\n"); 775 printk(KERN_WARNING DRV_PFX "unable to install notify handler\n");
478 result = -ENODEV; 776 result = -ENODEV;
479 goto outwalk; 777 goto outinput;
480 } 778 }
481 779
482 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) { 780 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", &handle))) {
483 sony_backlight_device = backlight_device_register("sony", NULL, 781 sony_backlight_device = backlight_device_register("sony", NULL,
484 NULL, 782 NULL,
485 &sony_backlight_ops); 783 &sony_backlight_ops);
486 784
487 if (IS_ERR(sony_backlight_device)) { 785 if (IS_ERR(sony_backlight_device)) {
488 printk(LOG_PFX "unable to register backlight device\n"); 786 printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
489 sony_backlight_device = NULL; 787 sony_backlight_device = NULL;
490 } else { 788 } else {
491 sony_backlight_device->props.brightness = 789 sony_backlight_device->props.brightness =
@@ -497,68 +795,1497 @@ static int sony_acpi_add(struct acpi_device *device)
497 795
498 } 796 }
499 797
500 if (sony_snc_pf_add()) 798 result = sony_pf_add();
799 if (result)
501 goto outbacklight; 800 goto outbacklight;
502 801
503 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully installed\n"); 802 /* create sony_pf sysfs attributes related to the SNC device */
803 for (item = sony_nc_values; item->name; ++item) {
804
805 if (!debug && item->debug)
806 continue;
807
808 /* find the available acpiget as described in the DSDT */
809 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
810 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
811 *item->acpiget,
812 &handle))) {
813 dprintk("Found %s getter: %s\n",
814 item->name, *item->acpiget);
815 item->devattr.attr.mode |= S_IRUGO;
816 break;
817 }
818 }
819
820 /* find the available acpiset as described in the DSDT */
821 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
822 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
823 *item->acpiset,
824 &handle))) {
825 dprintk("Found %s setter: %s\n",
826 item->name, *item->acpiset);
827 item->devattr.attr.mode |= S_IWUSR;
828 break;
829 }
830 }
831
832 if (item->devattr.attr.mode != 0) {
833 result =
834 device_create_file(&sony_pf_device->dev,
835 &item->devattr);
836 if (result)
837 goto out_sysfs;
838 }
839 }
504 840
505 return 0; 841 return 0;
506 842
843 out_sysfs:
844 for (item = sony_nc_values; item->name; ++item) {
845 device_remove_file(&sony_pf_device->dev, &item->devattr);
846 }
847 sony_pf_remove();
848
507 outbacklight: 849 outbacklight:
508 if (sony_backlight_device) 850 if (sony_backlight_device)
509 backlight_device_unregister(sony_backlight_device); 851 backlight_device_unregister(sony_backlight_device);
510 852
511 status = acpi_remove_notify_handler(sony_acpi_handle, 853 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
512 ACPI_DEVICE_NOTIFY, 854 ACPI_DEVICE_NOTIFY,
513 sony_acpi_notify); 855 sony_acpi_notify);
514 if (ACPI_FAILURE(status)) 856 if (ACPI_FAILURE(status))
515 printk(LOG_PFX "unable to remove notify handler\n"); 857 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
858
859 outinput:
860 sony_laptop_remove_input();
861
516 outwalk: 862 outwalk:
517 return result; 863 return result;
518} 864}
519 865
520static int sony_acpi_remove(struct acpi_device *device, int type) 866static int sony_nc_remove(struct acpi_device *device, int type)
521{ 867{
522 acpi_status status; 868 acpi_status status;
869 struct sony_nc_value *item;
523 870
524 if (sony_backlight_device) 871 if (sony_backlight_device)
525 backlight_device_unregister(sony_backlight_device); 872 backlight_device_unregister(sony_backlight_device);
526 873
527 sony_acpi_acpi_device = NULL; 874 sony_nc_acpi_device = NULL;
528 875
529 status = acpi_remove_notify_handler(sony_acpi_handle, 876 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
530 ACPI_DEVICE_NOTIFY, 877 ACPI_DEVICE_NOTIFY,
531 sony_acpi_notify); 878 sony_acpi_notify);
532 if (ACPI_FAILURE(status)) 879 if (ACPI_FAILURE(status))
533 printk(LOG_PFX "unable to remove notify handler\n"); 880 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
534 881
535 sony_snc_pf_remove(); 882 for (item = sony_nc_values; item->name; ++item) {
883 device_remove_file(&sony_pf_device->dev, &item->devattr);
884 }
536 885
537 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully removed\n"); 886 sony_pf_remove();
887 sony_laptop_remove_input();
888 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
538 889
539 return 0; 890 return 0;
540} 891}
541 892
542static struct acpi_driver sony_acpi_driver = { 893static struct acpi_driver sony_nc_driver = {
543 .name = ACPI_SNC_DRIVER_NAME, 894 .name = SONY_NC_DRIVER_NAME,
544 .class = ACPI_SNC_CLASS, 895 .class = SONY_NC_CLASS,
545 .ids = ACPI_SNC_HID, 896 .ids = SONY_NC_HID,
897 .owner = THIS_MODULE,
546 .ops = { 898 .ops = {
547 .add = sony_acpi_add, 899 .add = sony_nc_add,
548 .remove = sony_acpi_remove, 900 .remove = sony_nc_remove,
549 .resume = sony_acpi_resume, 901 .resume = sony_nc_resume,
550 }, 902 },
551}; 903};
552 904
553static int __init sony_acpi_init(void) 905/*********** SPIC (SNY6001) Device ***********/
906
907#define SONYPI_DEVICE_TYPE1 0x00000001
908#define SONYPI_DEVICE_TYPE2 0x00000002
909#define SONYPI_DEVICE_TYPE3 0x00000004
910
911#define SONY_PIC_EV_MASK 0xff
912
913struct sony_pic_ioport {
914 struct acpi_resource_io io;
915 struct list_head list;
916};
917
918struct sony_pic_irq {
919 struct acpi_resource_irq irq;
920 struct list_head list;
921};
922
923struct sony_pic_dev {
924 int model;
925 u8 camera_power;
926 u8 bluetooth_power;
927 u8 wwan_power;
928 struct acpi_device *acpi_dev;
929 struct sony_pic_irq *cur_irq;
930 struct sony_pic_ioport *cur_ioport;
931 struct list_head interrupts;
932 struct list_head ioports;
933 struct mutex lock;
934};
935
936static struct sony_pic_dev spic_dev = {
937 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
938 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
939};
940
941/* Event masks */
942#define SONYPI_JOGGER_MASK 0x00000001
943#define SONYPI_CAPTURE_MASK 0x00000002
944#define SONYPI_FNKEY_MASK 0x00000004
945#define SONYPI_BLUETOOTH_MASK 0x00000008
946#define SONYPI_PKEY_MASK 0x00000010
947#define SONYPI_BACK_MASK 0x00000020
948#define SONYPI_HELP_MASK 0x00000040
949#define SONYPI_LID_MASK 0x00000080
950#define SONYPI_ZOOM_MASK 0x00000100
951#define SONYPI_THUMBPHRASE_MASK 0x00000200
952#define SONYPI_MEYE_MASK 0x00000400
953#define SONYPI_MEMORYSTICK_MASK 0x00000800
954#define SONYPI_BATTERY_MASK 0x00001000
955#define SONYPI_WIRELESS_MASK 0x00002000
956
957struct sonypi_event {
958 u8 data;
959 u8 event;
960};
961
962/* The set of possible button release events */
963static struct sonypi_event sonypi_releaseev[] = {
964 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
965 { 0, 0 }
966};
967
968/* The set of possible jogger events */
969static struct sonypi_event sonypi_joggerev[] = {
970 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
971 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
972 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
973 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
974 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
975 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
976 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
977 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
978 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
979 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
980 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
981 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
982 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
983 { 0, 0 }
984};
985
986/* The set of possible capture button events */
987static struct sonypi_event sonypi_captureev[] = {
988 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
989 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
990 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
991 { 0, 0 }
992};
993
994/* The set of possible fnkeys events */
995static struct sonypi_event sonypi_fnkeyev[] = {
996 { 0x10, SONYPI_EVENT_FNKEY_ESC },
997 { 0x11, SONYPI_EVENT_FNKEY_F1 },
998 { 0x12, SONYPI_EVENT_FNKEY_F2 },
999 { 0x13, SONYPI_EVENT_FNKEY_F3 },
1000 { 0x14, SONYPI_EVENT_FNKEY_F4 },
1001 { 0x15, SONYPI_EVENT_FNKEY_F5 },
1002 { 0x16, SONYPI_EVENT_FNKEY_F6 },
1003 { 0x17, SONYPI_EVENT_FNKEY_F7 },
1004 { 0x18, SONYPI_EVENT_FNKEY_F8 },
1005 { 0x19, SONYPI_EVENT_FNKEY_F9 },
1006 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
1007 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
1008 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
1009 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
1010 { 0x21, SONYPI_EVENT_FNKEY_1 },
1011 { 0x22, SONYPI_EVENT_FNKEY_2 },
1012 { 0x31, SONYPI_EVENT_FNKEY_D },
1013 { 0x32, SONYPI_EVENT_FNKEY_E },
1014 { 0x33, SONYPI_EVENT_FNKEY_F },
1015 { 0x34, SONYPI_EVENT_FNKEY_S },
1016 { 0x35, SONYPI_EVENT_FNKEY_B },
1017 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
1018 { 0, 0 }
1019};
1020
1021/* The set of possible program key events */
1022static struct sonypi_event sonypi_pkeyev[] = {
1023 { 0x01, SONYPI_EVENT_PKEY_P1 },
1024 { 0x02, SONYPI_EVENT_PKEY_P2 },
1025 { 0x04, SONYPI_EVENT_PKEY_P3 },
1026 { 0x5c, SONYPI_EVENT_PKEY_P1 },
1027 { 0, 0 }
1028};
1029
1030/* The set of possible bluetooth events */
1031static struct sonypi_event sonypi_blueev[] = {
1032 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
1033 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
1034 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
1035 { 0, 0 }
1036};
1037
1038/* The set of possible wireless events */
1039static struct sonypi_event sonypi_wlessev[] = {
1040 { 0x59, SONYPI_EVENT_WIRELESS_ON },
1041 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
1042 { 0, 0 }
1043};
1044
1045/* The set of possible back button events */
1046static struct sonypi_event sonypi_backev[] = {
1047 { 0x20, SONYPI_EVENT_BACK_PRESSED },
1048 { 0, 0 }
1049};
1050
1051/* The set of possible help button events */
1052static struct sonypi_event sonypi_helpev[] = {
1053 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
1054 { 0, 0 }
1055};
1056
1057
1058/* The set of possible lid events */
1059static struct sonypi_event sonypi_lidev[] = {
1060 { 0x51, SONYPI_EVENT_LID_CLOSED },
1061 { 0x50, SONYPI_EVENT_LID_OPENED },
1062 { 0, 0 }
1063};
1064
1065/* The set of possible zoom events */
1066static struct sonypi_event sonypi_zoomev[] = {
1067 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
1068 { 0, 0 }
1069};
1070
1071/* The set of possible thumbphrase events */
1072static struct sonypi_event sonypi_thumbphraseev[] = {
1073 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
1074 { 0, 0 }
1075};
1076
1077/* The set of possible motioneye camera events */
1078static struct sonypi_event sonypi_meyeev[] = {
1079 { 0x00, SONYPI_EVENT_MEYE_FACE },
1080 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
1081 { 0, 0 }
1082};
1083
1084/* The set of possible memorystick events */
1085static struct sonypi_event sonypi_memorystickev[] = {
1086 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
1087 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
1088 { 0, 0 }
1089};
1090
1091/* The set of possible battery events */
1092static struct sonypi_event sonypi_batteryev[] = {
1093 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
1094 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
1095 { 0, 0 }
1096};
1097
1098static struct sonypi_eventtypes {
1099 int model;
1100 u8 data;
1101 unsigned long mask;
1102 struct sonypi_event * events;
1103} sony_pic_eventtypes[] = {
1104 { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
1105 { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
1106 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
1107 { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
1108 { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
1109 { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1110 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1111 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
1112 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1113 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
1114
1115 { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
1116 { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
1117 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
1118 { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
1119 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1120 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1121 { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
1122 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
1123 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
1124 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
1125 { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
1126 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1127 { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1128 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1129
1130 { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
1131 { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1132 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
1133 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1134 { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1135 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1136 { 0 }
1137};
1138
1139static int sony_pic_detect_device_type(void)
1140{
1141 struct pci_dev *pcidev;
1142 int model = 0;
1143
1144 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1145 PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
1146 model = SONYPI_DEVICE_TYPE1;
1147
1148 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1149 PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
1150 model = SONYPI_DEVICE_TYPE3;
1151
1152 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1153 PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
1154 model = SONYPI_DEVICE_TYPE3;
1155
1156 else
1157 model = SONYPI_DEVICE_TYPE2;
1158
1159 if (pcidev)
1160 pci_dev_put(pcidev);
1161
1162 printk(KERN_INFO DRV_PFX "detected Type%d model\n",
1163 model == SONYPI_DEVICE_TYPE1 ? 1 :
1164 model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
1165 return model;
1166}
1167
1168#define ITERATIONS_LONG 10000
1169#define ITERATIONS_SHORT 10
1170#define wait_on_command(command, iterations) { \
1171 unsigned int n = iterations; \
1172 while (--n && (command)) \
1173 udelay(1); \
1174 if (!n) \
1175 dprintk("command failed at %s : %s (line %d)\n", \
1176 __FILE__, __FUNCTION__, __LINE__); \
1177}
1178
1179static u8 sony_pic_call1(u8 dev)
1180{
1181 u8 v1, v2;
1182
1183 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1184 ITERATIONS_LONG);
1185 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1186 v1 = inb_p(spic_dev.cur_ioport->io.minimum + 4);
1187 v2 = inb_p(spic_dev.cur_ioport->io.minimum);
1188 dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
1189 return v2;
1190}
1191
1192static u8 sony_pic_call2(u8 dev, u8 fn)
1193{
1194 u8 v1;
1195
1196 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1197 ITERATIONS_LONG);
1198 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1199 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1200 ITERATIONS_LONG);
1201 outb(fn, spic_dev.cur_ioport->io.minimum);
1202 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1203 dprintk("sony_pic_call2: 0x%.4x\n", v1);
1204 return v1;
1205}
1206
1207static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
1208{
1209 u8 v1;
1210
1211 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1212 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1213 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1214 outb(fn, spic_dev.cur_ioport->io.minimum);
1215 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1216 outb(v, spic_dev.cur_ioport->io.minimum);
1217 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1218 dprintk("sony_pic_call3: 0x%.4x\n", v1);
1219 return v1;
1220}
1221
1222/* camera tests and poweron/poweroff */
1223#define SONYPI_CAMERA_PICTURE 5
1224#define SONYPI_CAMERA_CONTROL 0x10
1225
1226#define SONYPI_CAMERA_BRIGHTNESS 0
1227#define SONYPI_CAMERA_CONTRAST 1
1228#define SONYPI_CAMERA_HUE 2
1229#define SONYPI_CAMERA_COLOR 3
1230#define SONYPI_CAMERA_SHARPNESS 4
1231
1232#define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1233#define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1234#define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1235#define SONYPI_CAMERA_MUTE_MASK 0x40
1236
1237/* the rest don't need a loop until not 0xff */
1238#define SONYPI_CAMERA_AGC 6
1239#define SONYPI_CAMERA_AGC_MASK 0x30
1240#define SONYPI_CAMERA_SHUTTER_MASK 0x7
1241
1242#define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1243#define SONYPI_CAMERA_CONTROL 0x10
1244
1245#define SONYPI_CAMERA_STATUS 7
1246#define SONYPI_CAMERA_STATUS_READY 0x2
1247#define SONYPI_CAMERA_STATUS_POSITION 0x4
1248
1249#define SONYPI_DIRECTION_BACKWARDS 0x4
1250
1251#define SONYPI_CAMERA_REVISION 8
1252#define SONYPI_CAMERA_ROMVERSION 9
1253
1254static int __sony_pic_camera_ready(void)
1255{
1256 u8 v;
1257
1258 v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
1259 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
1260}
1261
1262static int __sony_pic_camera_off(void)
1263{
1264 if (!camera) {
1265 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1266 return -ENODEV;
1267 }
1268
1269 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
1270 SONYPI_CAMERA_MUTE_MASK),
1271 ITERATIONS_SHORT);
1272
1273 if (spic_dev.camera_power) {
1274 sony_pic_call2(0x91, 0);
1275 spic_dev.camera_power = 0;
1276 }
1277 return 0;
1278}
1279
1280static int __sony_pic_camera_on(void)
554{ 1281{
555 return acpi_bus_register_driver(&sony_acpi_driver); 1282 int i, j, x;
1283
1284 if (!camera) {
1285 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1286 return -ENODEV;
1287 }
1288
1289 if (spic_dev.camera_power)
1290 return 0;
1291
1292 for (j = 5; j > 0; j--) {
1293
1294 for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
1295 msleep(10);
1296 sony_pic_call1(0x93);
1297
1298 for (i = 400; i > 0; i--) {
1299 if (__sony_pic_camera_ready())
1300 break;
1301 msleep(10);
1302 }
1303 if (i)
1304 break;
1305 }
1306
1307 if (j == 0) {
1308 printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
1309 return -ENODEV;
1310 }
1311
1312 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
1313 0x5a),
1314 ITERATIONS_SHORT);
1315
1316 spic_dev.camera_power = 1;
1317 return 0;
1318}
1319
1320/* External camera command (exported to the motion eye v4l driver) */
1321int sony_pic_camera_command(int command, u8 value)
1322{
1323 if (!camera)
1324 return -EIO;
1325
1326 mutex_lock(&spic_dev.lock);
1327
1328 switch (command) {
1329 case SONY_PIC_COMMAND_SETCAMERA:
1330 if (value)
1331 __sony_pic_camera_on();
1332 else
1333 __sony_pic_camera_off();
1334 break;
1335 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
1336 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
1337 ITERATIONS_SHORT);
1338 break;
1339 case SONY_PIC_COMMAND_SETCAMERACONTRAST:
1340 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
1341 ITERATIONS_SHORT);
1342 break;
1343 case SONY_PIC_COMMAND_SETCAMERAHUE:
1344 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
1345 ITERATIONS_SHORT);
1346 break;
1347 case SONY_PIC_COMMAND_SETCAMERACOLOR:
1348 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
1349 ITERATIONS_SHORT);
1350 break;
1351 case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
1352 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
1353 ITERATIONS_SHORT);
1354 break;
1355 case SONY_PIC_COMMAND_SETCAMERAPICTURE:
1356 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
1357 ITERATIONS_SHORT);
1358 break;
1359 case SONY_PIC_COMMAND_SETCAMERAAGC:
1360 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
1361 ITERATIONS_SHORT);
1362 break;
1363 default:
1364 printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
1365 command);
1366 break;
1367 }
1368 mutex_unlock(&spic_dev.lock);
1369 return 0;
1370}
1371EXPORT_SYMBOL(sony_pic_camera_command);
1372
1373/* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
1374static void sony_pic_set_wwanpower(u8 state)
1375{
1376 state = !!state;
1377 mutex_lock(&spic_dev.lock);
1378 if (spic_dev.wwan_power == state) {
1379 mutex_unlock(&spic_dev.lock);
1380 return;
1381 }
1382 sony_pic_call2(0xB0, state);
1383 spic_dev.wwan_power = state;
1384 mutex_unlock(&spic_dev.lock);
1385}
1386
1387static ssize_t sony_pic_wwanpower_store(struct device *dev,
1388 struct device_attribute *attr,
1389 const char *buffer, size_t count)
1390{
1391 unsigned long value;
1392 if (count > 31)
1393 return -EINVAL;
1394
1395 value = simple_strtoul(buffer, NULL, 10);
1396 sony_pic_set_wwanpower(value);
1397
1398 return count;
1399}
1400
1401static ssize_t sony_pic_wwanpower_show(struct device *dev,
1402 struct device_attribute *attr, char *buffer)
1403{
1404 ssize_t count;
1405 mutex_lock(&spic_dev.lock);
1406 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
1407 mutex_unlock(&spic_dev.lock);
1408 return count;
1409}
1410
1411/* bluetooth subsystem power state */
1412static void __sony_pic_set_bluetoothpower(u8 state)
1413{
1414 state = !!state;
1415 if (spic_dev.bluetooth_power == state)
1416 return;
1417 sony_pic_call2(0x96, state);
1418 sony_pic_call1(0x82);
1419 spic_dev.bluetooth_power = state;
1420}
1421
1422static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
1423 struct device_attribute *attr,
1424 const char *buffer, size_t count)
1425{
1426 unsigned long value;
1427 if (count > 31)
1428 return -EINVAL;
1429
1430 value = simple_strtoul(buffer, NULL, 10);
1431 mutex_lock(&spic_dev.lock);
1432 __sony_pic_set_bluetoothpower(value);
1433 mutex_unlock(&spic_dev.lock);
1434
1435 return count;
1436}
1437
1438static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
1439 struct device_attribute *attr, char *buffer)
1440{
1441 ssize_t count = 0;
1442 mutex_lock(&spic_dev.lock);
1443 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
1444 mutex_unlock(&spic_dev.lock);
1445 return count;
1446}
1447
1448/* fan speed */
1449/* FAN0 information (reverse engineered from ACPI tables) */
1450#define SONY_PIC_FAN0_STATUS 0x93
1451static int sony_pic_set_fanspeed(unsigned long value)
1452{
1453 return ec_write(SONY_PIC_FAN0_STATUS, value);
1454}
1455
1456static int sony_pic_get_fanspeed(u8 *value)
1457{
1458 return ec_read(SONY_PIC_FAN0_STATUS, value);
1459}
1460
1461static ssize_t sony_pic_fanspeed_store(struct device *dev,
1462 struct device_attribute *attr,
1463 const char *buffer, size_t count)
1464{
1465 unsigned long value;
1466 if (count > 31)
1467 return -EINVAL;
1468
1469 value = simple_strtoul(buffer, NULL, 10);
1470 if (sony_pic_set_fanspeed(value))
1471 return -EIO;
1472
1473 return count;
1474}
1475
1476static ssize_t sony_pic_fanspeed_show(struct device *dev,
1477 struct device_attribute *attr, char *buffer)
1478{
1479 u8 value = 0;
1480 if (sony_pic_get_fanspeed(&value))
1481 return -EIO;
1482
1483 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
1484}
1485
1486#define SPIC_ATTR(_name, _mode) \
1487struct device_attribute spic_attr_##_name = __ATTR(_name, \
1488 _mode, sony_pic_## _name ##_show, \
1489 sony_pic_## _name ##_store)
1490
1491static SPIC_ATTR(bluetoothpower, 0644);
1492static SPIC_ATTR(wwanpower, 0644);
1493static SPIC_ATTR(fanspeed, 0644);
1494
1495static struct attribute *spic_attributes[] = {
1496 &spic_attr_bluetoothpower.attr,
1497 &spic_attr_wwanpower.attr,
1498 &spic_attr_fanspeed.attr,
1499 NULL
1500};
1501
1502static struct attribute_group spic_attribute_group = {
1503 .attrs = spic_attributes
1504};
1505
1506/******** SONYPI compatibility **********/
1507#ifdef CONFIG_SONY_LAPTOP_OLD
1508
1509/* battery / brightness / temperature addresses */
1510#define SONYPI_BAT_FLAGS 0x81
1511#define SONYPI_LCD_LIGHT 0x96
1512#define SONYPI_BAT1_PCTRM 0xa0
1513#define SONYPI_BAT1_LEFT 0xa2
1514#define SONYPI_BAT1_MAXRT 0xa4
1515#define SONYPI_BAT2_PCTRM 0xa8
1516#define SONYPI_BAT2_LEFT 0xaa
1517#define SONYPI_BAT2_MAXRT 0xac
1518#define SONYPI_BAT1_MAXTK 0xb0
1519#define SONYPI_BAT1_FULL 0xb2
1520#define SONYPI_BAT2_MAXTK 0xb8
1521#define SONYPI_BAT2_FULL 0xba
1522#define SONYPI_TEMP_STATUS 0xC1
1523
1524struct sonypi_compat_s {
1525 struct fasync_struct *fifo_async;
1526 struct kfifo *fifo;
1527 spinlock_t fifo_lock;
1528 wait_queue_head_t fifo_proc_list;
1529 atomic_t open_count;
1530};
1531static struct sonypi_compat_s sonypi_compat = {
1532 .open_count = ATOMIC_INIT(0),
1533};
1534
1535static int sonypi_misc_fasync(int fd, struct file *filp, int on)
1536{
1537 int retval;
1538
1539 retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
1540 if (retval < 0)
1541 return retval;
1542 return 0;
1543}
1544
1545static int sonypi_misc_release(struct inode *inode, struct file *file)
1546{
1547 sonypi_misc_fasync(-1, file, 0);
1548 atomic_dec(&sonypi_compat.open_count);
1549 return 0;
1550}
1551
1552static int sonypi_misc_open(struct inode *inode, struct file *file)
1553{
1554 /* Flush input queue on first open */
1555 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
1556 kfifo_reset(sonypi_compat.fifo);
1557 return 0;
1558}
1559
1560static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
1561 size_t count, loff_t *pos)
1562{
1563 ssize_t ret;
1564 unsigned char c;
1565
1566 if ((kfifo_len(sonypi_compat.fifo) == 0) &&
1567 (file->f_flags & O_NONBLOCK))
1568 return -EAGAIN;
1569
1570 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
1571 kfifo_len(sonypi_compat.fifo) != 0);
1572 if (ret)
1573 return ret;
1574
1575 while (ret < count &&
1576 (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
1577 if (put_user(c, buf++))
1578 return -EFAULT;
1579 ret++;
1580 }
1581
1582 if (ret > 0) {
1583 struct inode *inode = file->f_path.dentry->d_inode;
1584 inode->i_atime = current_fs_time(inode->i_sb);
1585 }
1586
1587 return ret;
1588}
1589
1590static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
1591{
1592 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
1593 if (kfifo_len(sonypi_compat.fifo))
1594 return POLLIN | POLLRDNORM;
1595 return 0;
1596}
1597
1598static int ec_read16(u8 addr, u16 *value)
1599{
1600 u8 val_lb, val_hb;
1601 if (ec_read(addr, &val_lb))
1602 return -1;
1603 if (ec_read(addr + 1, &val_hb))
1604 return -1;
1605 *value = val_lb | (val_hb << 8);
1606 return 0;
1607}
1608
1609static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1610 unsigned int cmd, unsigned long arg)
1611{
1612 int ret = 0;
1613 void __user *argp = (void __user *)arg;
1614 u8 val8;
1615 u16 val16;
1616 int value;
1617
1618 mutex_lock(&spic_dev.lock);
1619 switch (cmd) {
1620 case SONYPI_IOCGBRT:
1621 if (sony_backlight_device == NULL) {
1622 ret = -EIO;
1623 break;
1624 }
1625 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
1626 ret = -EIO;
1627 break;
1628 }
1629 val8 = ((value & 0xff) - 1) << 5;
1630 if (copy_to_user(argp, &val8, sizeof(val8)))
1631 ret = -EFAULT;
1632 break;
1633 case SONYPI_IOCSBRT:
1634 if (sony_backlight_device == NULL) {
1635 ret = -EIO;
1636 break;
1637 }
1638 if (copy_from_user(&val8, argp, sizeof(val8))) {
1639 ret = -EFAULT;
1640 break;
1641 }
1642 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
1643 (val8 >> 5) + 1, NULL)) {
1644 ret = -EIO;
1645 break;
1646 }
1647 /* sync the backlight device status */
1648 sony_backlight_device->props.brightness =
1649 sony_backlight_get_brightness(sony_backlight_device);
1650 break;
1651 case SONYPI_IOCGBAT1CAP:
1652 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
1653 ret = -EIO;
1654 break;
1655 }
1656 if (copy_to_user(argp, &val16, sizeof(val16)))
1657 ret = -EFAULT;
1658 break;
1659 case SONYPI_IOCGBAT1REM:
1660 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
1661 ret = -EIO;
1662 break;
1663 }
1664 if (copy_to_user(argp, &val16, sizeof(val16)))
1665 ret = -EFAULT;
1666 break;
1667 case SONYPI_IOCGBAT2CAP:
1668 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
1669 ret = -EIO;
1670 break;
1671 }
1672 if (copy_to_user(argp, &val16, sizeof(val16)))
1673 ret = -EFAULT;
1674 break;
1675 case SONYPI_IOCGBAT2REM:
1676 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
1677 ret = -EIO;
1678 break;
1679 }
1680 if (copy_to_user(argp, &val16, sizeof(val16)))
1681 ret = -EFAULT;
1682 break;
1683 case SONYPI_IOCGBATFLAGS:
1684 if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
1685 ret = -EIO;
1686 break;
1687 }
1688 val8 &= 0x07;
1689 if (copy_to_user(argp, &val8, sizeof(val8)))
1690 ret = -EFAULT;
1691 break;
1692 case SONYPI_IOCGBLUE:
1693 val8 = spic_dev.bluetooth_power;
1694 if (copy_to_user(argp, &val8, sizeof(val8)))
1695 ret = -EFAULT;
1696 break;
1697 case SONYPI_IOCSBLUE:
1698 if (copy_from_user(&val8, argp, sizeof(val8))) {
1699 ret = -EFAULT;
1700 break;
1701 }
1702 __sony_pic_set_bluetoothpower(val8);
1703 break;
1704 /* FAN Controls */
1705 case SONYPI_IOCGFAN:
1706 if (sony_pic_get_fanspeed(&val8)) {
1707 ret = -EIO;
1708 break;
1709 }
1710 if (copy_to_user(argp, &val8, sizeof(val8)))
1711 ret = -EFAULT;
1712 break;
1713 case SONYPI_IOCSFAN:
1714 if (copy_from_user(&val8, argp, sizeof(val8))) {
1715 ret = -EFAULT;
1716 break;
1717 }
1718 if (sony_pic_set_fanspeed(val8))
1719 ret = -EIO;
1720 break;
1721 /* GET Temperature (useful under APM) */
1722 case SONYPI_IOCGTEMP:
1723 if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
1724 ret = -EIO;
1725 break;
1726 }
1727 if (copy_to_user(argp, &val8, sizeof(val8)))
1728 ret = -EFAULT;
1729 break;
1730 default:
1731 ret = -EINVAL;
1732 }
1733 mutex_unlock(&spic_dev.lock);
1734 return ret;
1735}
1736
1737static const struct file_operations sonypi_misc_fops = {
1738 .owner = THIS_MODULE,
1739 .read = sonypi_misc_read,
1740 .poll = sonypi_misc_poll,
1741 .open = sonypi_misc_open,
1742 .release = sonypi_misc_release,
1743 .fasync = sonypi_misc_fasync,
1744 .ioctl = sonypi_misc_ioctl,
1745};
1746
1747static struct miscdevice sonypi_misc_device = {
1748 .minor = MISC_DYNAMIC_MINOR,
1749 .name = "sonypi",
1750 .fops = &sonypi_misc_fops,
1751};
1752
1753static void sonypi_compat_report_event(u8 event)
1754{
1755 kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
1756 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
1757 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
1758}
1759
1760static int sonypi_compat_init(void)
1761{
1762 int error;
1763
1764 spin_lock_init(&sonypi_compat.fifo_lock);
1765 sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
1766 &sonypi_compat.fifo_lock);
1767 if (IS_ERR(sonypi_compat.fifo)) {
1768 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
1769 return PTR_ERR(sonypi_compat.fifo);
1770 }
1771
1772 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
1773
1774 if (minor != -1)
1775 sonypi_misc_device.minor = minor;
1776 error = misc_register(&sonypi_misc_device);
1777 if (error) {
1778 printk(KERN_ERR DRV_PFX "misc_register failed\n");
1779 goto err_free_kfifo;
1780 }
1781 if (minor == -1)
1782 printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
1783 sonypi_misc_device.minor);
1784
1785 return 0;
1786
1787err_free_kfifo:
1788 kfifo_free(sonypi_compat.fifo);
1789 return error;
1790}
1791
1792static void sonypi_compat_exit(void)
1793{
1794 misc_deregister(&sonypi_misc_device);
1795 kfifo_free(sonypi_compat.fifo);
1796}
1797#else
1798static int sonypi_compat_init(void) { return 0; }
1799static void sonypi_compat_exit(void) { }
1800static void sonypi_compat_report_event(u8 event) { }
1801#endif /* CONFIG_SONY_LAPTOP_OLD */
1802
1803/*
1804 * ACPI callbacks
1805 */
1806static acpi_status
1807sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
1808{
1809 u32 i;
1810 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
1811
1812 switch (resource->type) {
1813 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1814 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1815 return AE_OK;
1816
1817 case ACPI_RESOURCE_TYPE_IRQ:
1818 {
1819 struct acpi_resource_irq *p = &resource->data.irq;
1820 struct sony_pic_irq *interrupt = NULL;
1821 if (!p || !p->interrupt_count) {
1822 /*
1823 * IRQ descriptors may have no IRQ# bits set,
1824 * particularly those those w/ _STA disabled
1825 */
1826 dprintk("Blank IRQ resource\n");
1827 return AE_OK;
1828 }
1829 for (i = 0; i < p->interrupt_count; i++) {
1830 if (!p->interrupts[i]) {
1831 printk(KERN_WARNING DRV_PFX
1832 "Invalid IRQ %d\n",
1833 p->interrupts[i]);
1834 continue;
1835 }
1836 interrupt = kzalloc(sizeof(*interrupt),
1837 GFP_KERNEL);
1838 if (!interrupt)
1839 return AE_ERROR;
1840
1841 list_add_tail(&interrupt->list, &dev->interrupts);
1842 interrupt->irq.triggering = p->triggering;
1843 interrupt->irq.polarity = p->polarity;
1844 interrupt->irq.sharable = p->sharable;
1845 interrupt->irq.interrupt_count = 1;
1846 interrupt->irq.interrupts[0] = p->interrupts[i];
1847 }
1848 return AE_OK;
1849 }
1850 case ACPI_RESOURCE_TYPE_IO:
1851 {
1852 struct acpi_resource_io *io = &resource->data.io;
1853 struct sony_pic_ioport *ioport = NULL;
1854 if (!io) {
1855 dprintk("Blank IO resource\n");
1856 return AE_OK;
1857 }
1858
1859 ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
1860 if (!ioport)
1861 return AE_ERROR;
1862
1863 list_add_tail(&ioport->list, &dev->ioports);
1864 memcpy(&ioport->io, io, sizeof(*io));
1865 return AE_OK;
1866 }
1867 default:
1868 dprintk("Resource %d isn't an IRQ nor an IO port\n",
1869 resource->type);
1870
1871 case ACPI_RESOURCE_TYPE_END_TAG:
1872 return AE_OK;
1873 }
1874 return AE_CTRL_TERMINATE;
1875}
1876
1877static int sony_pic_possible_resources(struct acpi_device *device)
1878{
1879 int result = 0;
1880 acpi_status status = AE_OK;
1881
1882 if (!device)
1883 return -EINVAL;
1884
1885 /* get device status */
1886 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
1887 dprintk("Evaluating _STA\n");
1888 result = acpi_bus_get_status(device);
1889 if (result) {
1890 printk(KERN_WARNING DRV_PFX "Unable to read status\n");
1891 goto end;
1892 }
1893
1894 if (!device->status.enabled)
1895 dprintk("Device disabled\n");
1896 else
1897 dprintk("Device enabled\n");
1898
1899 /*
1900 * Query and parse 'method'
1901 */
1902 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
1903 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
1904 sony_pic_read_possible_resource, &spic_dev);
1905 if (ACPI_FAILURE(status)) {
1906 printk(KERN_WARNING DRV_PFX
1907 "Failure evaluating %s\n",
1908 METHOD_NAME__PRS);
1909 result = -ENODEV;
1910 }
1911end:
1912 return result;
1913}
1914
1915/*
1916 * Disable the spic device by calling its _DIS method
1917 */
1918static int sony_pic_disable(struct acpi_device *device)
1919{
1920 if (ACPI_FAILURE(acpi_evaluate_object(device->handle, "_DIS", 0, NULL)))
1921 return -ENXIO;
1922
1923 dprintk("Device disabled\n");
1924 return 0;
1925}
1926
1927
1928/*
1929 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
1930 *
1931 * Call _SRS to set current resources
1932 */
1933static int sony_pic_enable(struct acpi_device *device,
1934 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
1935{
1936 acpi_status status;
1937 int result = 0;
1938 struct {
1939 struct acpi_resource io_res;
1940 struct acpi_resource irq_res;
1941 struct acpi_resource end;
1942 } *resource;
1943 struct acpi_buffer buffer = { 0, NULL };
1944
1945 if (!ioport || !irq)
1946 return -EINVAL;
1947
1948 /* init acpi_buffer */
1949 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
1950 if (!resource)
1951 return -ENOMEM;
1952
1953 buffer.length = sizeof(*resource) + 1;
1954 buffer.pointer = resource;
1955
1956 /* setup io resource */
1957 resource->io_res.type = ACPI_RESOURCE_TYPE_IO;
1958 resource->io_res.length = sizeof(struct acpi_resource);
1959 memcpy(&resource->io_res.data.io, &ioport->io,
1960 sizeof(struct acpi_resource_io));
1961
1962 /* setup irq resource */
1963 resource->irq_res.type = ACPI_RESOURCE_TYPE_IRQ;
1964 resource->irq_res.length = sizeof(struct acpi_resource);
1965 memcpy(&resource->irq_res.data.irq, &irq->irq,
1966 sizeof(struct acpi_resource_irq));
1967 /* we requested a shared irq */
1968 resource->irq_res.data.irq.sharable = ACPI_SHARED;
1969
1970 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
1971
1972 /* Attempt to set the resource */
1973 dprintk("Evaluating _SRS\n");
1974 status = acpi_set_current_resources(device->handle, &buffer);
1975
1976 /* check for total failure */
1977 if (ACPI_FAILURE(status)) {
1978 printk(KERN_ERR DRV_PFX "Error evaluating _SRS");
1979 result = -ENODEV;
1980 goto end;
1981 }
1982
1983 /* Necessary device initializations calls (from sonypi) */
1984 sony_pic_call1(0x82);
1985 sony_pic_call2(0x81, 0xff);
1986 sony_pic_call1(compat ? 0x92 : 0x82);
1987
1988end:
1989 kfree(resource);
1990 return result;
1991}
1992
1993/*****************
1994 *
1995 * ISR: some event is available
1996 *
1997 *****************/
1998static irqreturn_t sony_pic_irq(int irq, void *dev_id)
1999{
2000 int i, j;
2001 u32 port_val = 0;
2002 u8 ev = 0;
2003 u8 data_mask = 0;
2004 u8 device_event = 0;
2005
2006 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
2007
2008 acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val,
2009 dev->cur_ioport->io.address_length);
2010 ev = port_val & SONY_PIC_EV_MASK;
2011 data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
2012
2013 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
2014 port_val, ev, data_mask, dev->cur_ioport->io.minimum);
2015
2016 if (ev == 0x00 || ev == 0xff)
2017 return IRQ_HANDLED;
2018
2019 for (i = 0; sony_pic_eventtypes[i].model; i++) {
2020
2021 if (spic_dev.model != sony_pic_eventtypes[i].model)
2022 continue;
2023
2024 if ((data_mask & sony_pic_eventtypes[i].data) !=
2025 sony_pic_eventtypes[i].data)
2026 continue;
2027
2028 if (!(mask & sony_pic_eventtypes[i].mask))
2029 continue;
2030
2031 for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
2032 if (ev == sony_pic_eventtypes[i].events[j].data) {
2033 device_event =
2034 sony_pic_eventtypes[i].events[j].event;
2035 goto found;
2036 }
2037 }
2038 }
2039 return IRQ_HANDLED;
2040
2041found:
2042 sony_laptop_report_input_event(device_event);
2043 acpi_bus_generate_event(spic_dev.acpi_dev, 1, device_event);
2044 sonypi_compat_report_event(device_event);
2045
2046 return IRQ_HANDLED;
2047}
2048
2049/*****************
2050 *
2051 * ACPI driver
2052 *
2053 *****************/
2054static int sony_pic_remove(struct acpi_device *device, int type)
2055{
2056 struct sony_pic_ioport *io, *tmp_io;
2057 struct sony_pic_irq *irq, *tmp_irq;
2058
2059 sonypi_compat_exit();
2060
2061 if (sony_pic_disable(device)) {
2062 printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
2063 return -ENXIO;
2064 }
2065
2066 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2067 release_region(spic_dev.cur_ioport->io.minimum,
2068 spic_dev.cur_ioport->io.address_length);
2069
2070 sony_laptop_remove_input();
2071
2072 /* pf attrs */
2073 sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2074 sony_pf_remove();
2075
2076 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2077 list_del(&io->list);
2078 kfree(io);
2079 }
2080 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2081 list_del(&irq->list);
2082 kfree(irq);
2083 }
2084 spic_dev.cur_ioport = NULL;
2085 spic_dev.cur_irq = NULL;
2086
2087 dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
2088 return 0;
2089}
2090
2091static int sony_pic_add(struct acpi_device *device)
2092{
2093 int result;
2094 struct sony_pic_ioport *io, *tmp_io;
2095 struct sony_pic_irq *irq, *tmp_irq;
2096
2097 printk(KERN_INFO DRV_PFX "%s v%s.\n",
2098 SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
2099
2100 spic_dev.acpi_dev = device;
2101 strcpy(acpi_device_class(device), "sony/hotkey");
2102 spic_dev.model = sony_pic_detect_device_type();
2103 mutex_init(&spic_dev.lock);
2104
2105 /* read _PRS resources */
2106 result = sony_pic_possible_resources(device);
2107 if (result) {
2108 printk(KERN_ERR DRV_PFX
2109 "Unabe to read possible resources.\n");
2110 goto err_free_resources;
2111 }
2112
2113 /* setup input devices and helper fifo */
2114 result = sony_laptop_setup_input();
2115 if (result) {
2116 printk(KERN_ERR DRV_PFX
2117 "Unabe to create input devices.\n");
2118 goto err_free_resources;
2119 }
2120
2121 /* request io port */
2122 list_for_each_entry(io, &spic_dev.ioports, list) {
2123 if (request_region(io->io.minimum, io->io.address_length,
2124 "Sony Programable I/O Device")) {
2125 dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
2126 io->io.minimum, io->io.maximum,
2127 io->io.address_length);
2128 spic_dev.cur_ioport = io;
2129 break;
2130 }
2131 }
2132 if (!spic_dev.cur_ioport) {
2133 printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
2134 result = -ENODEV;
2135 goto err_remove_input;
2136 }
2137
2138 /* request IRQ */
2139 list_for_each_entry(irq, &spic_dev.interrupts, list) {
2140 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
2141 IRQF_SHARED, "sony-laptop", &spic_dev)) {
2142 dprintk("IRQ: %d - triggering: %d - "
2143 "polarity: %d - shr: %d\n",
2144 irq->irq.interrupts[0],
2145 irq->irq.triggering,
2146 irq->irq.polarity,
2147 irq->irq.sharable);
2148 spic_dev.cur_irq = irq;
2149 break;
2150 }
2151 }
2152 if (!spic_dev.cur_irq) {
2153 printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
2154 result = -ENODEV;
2155 goto err_release_region;
2156 }
2157
2158 /* set resource status _SRS */
2159 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2160 if (result) {
2161 printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
2162 goto err_free_irq;
2163 }
2164
2165 spic_dev.bluetooth_power = -1;
2166 /* create device attributes */
2167 result = sony_pf_add();
2168 if (result)
2169 goto err_disable_device;
2170
2171 result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2172 if (result)
2173 goto err_remove_pf;
2174
2175 if (sonypi_compat_init())
2176 goto err_remove_pf;
2177
2178 return 0;
2179
2180err_remove_pf:
2181 sony_pf_remove();
2182
2183err_disable_device:
2184 sony_pic_disable(device);
2185
2186err_free_irq:
2187 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2188
2189err_release_region:
2190 release_region(spic_dev.cur_ioport->io.minimum,
2191 spic_dev.cur_ioport->io.address_length);
2192
2193err_remove_input:
2194 sony_laptop_remove_input();
2195
2196err_free_resources:
2197 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2198 list_del(&io->list);
2199 kfree(io);
2200 }
2201 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2202 list_del(&irq->list);
2203 kfree(irq);
2204 }
2205 spic_dev.cur_ioport = NULL;
2206 spic_dev.cur_irq = NULL;
2207
2208 return result;
2209}
2210
2211static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
2212{
2213 if (sony_pic_disable(device))
2214 return -ENXIO;
2215 return 0;
2216}
2217
2218static int sony_pic_resume(struct acpi_device *device)
2219{
2220 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2221 return 0;
2222}
2223
2224static struct acpi_driver sony_pic_driver = {
2225 .name = SONY_PIC_DRIVER_NAME,
2226 .class = SONY_PIC_CLASS,
2227 .ids = SONY_PIC_HID,
2228 .owner = THIS_MODULE,
2229 .ops = {
2230 .add = sony_pic_add,
2231 .remove = sony_pic_remove,
2232 .suspend = sony_pic_suspend,
2233 .resume = sony_pic_resume,
2234 },
2235};
2236
2237static struct dmi_system_id __initdata sonypi_dmi_table[] = {
2238 {
2239 .ident = "Sony Vaio",
2240 .matches = {
2241 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2242 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
2243 },
2244 },
2245 {
2246 .ident = "Sony Vaio",
2247 .matches = {
2248 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2249 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
2250 },
2251 },
2252 { }
2253};
2254
2255static int __init sony_laptop_init(void)
2256{
2257 int result;
2258
2259 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
2260 result = acpi_bus_register_driver(&sony_pic_driver);
2261 if (result) {
2262 printk(KERN_ERR DRV_PFX
2263 "Unable to register SPIC driver.");
2264 goto out;
2265 }
2266 }
2267
2268 result = acpi_bus_register_driver(&sony_nc_driver);
2269 if (result) {
2270 printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
2271 goto out_unregister_pic;
2272 }
2273
2274 return 0;
2275
2276out_unregister_pic:
2277 if (!no_spic)
2278 acpi_bus_unregister_driver(&sony_pic_driver);
2279out:
2280 return result;
556} 2281}
557 2282
558static void __exit sony_acpi_exit(void) 2283static void __exit sony_laptop_exit(void)
559{ 2284{
560 acpi_bus_unregister_driver(&sony_acpi_driver); 2285 acpi_bus_unregister_driver(&sony_nc_driver);
2286 if (!no_spic)
2287 acpi_bus_unregister_driver(&sony_pic_driver);
561} 2288}
562 2289
563module_init(sony_acpi_init); 2290module_init(sony_laptop_init);
564module_exit(sony_acpi_exit); 2291module_exit(sony_laptop_exit);
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
new file mode 100644
index 000000000000..6c36a55cb3d1
--- /dev/null
+++ b/drivers/misc/thinkpad_acpi.c
@@ -0,0 +1,4312 @@
1/*
2 * thinkpad_acpi.c - ThinkPad ACPI Extras
3 *
4 *
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24#define IBM_VERSION "0.14"
25#define TPACPI_SYSFS_VERSION 0x000100
26
27/*
28 * Changelog:
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
30 * drivers/misc.
31 *
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
35 *
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
53 * use MODULE_VERSION
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
77 * thinklight on/off
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
83 */
84
85#include "thinkpad_acpi.h"
86
87MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88MODULE_DESCRIPTION(IBM_DESC);
89MODULE_VERSION(IBM_VERSION);
90MODULE_LICENSE("GPL");
91
92/* Please remove this in year 2009 */
93MODULE_ALIAS("ibm_acpi");
94
95#define __unused __attribute__ ((unused))
96
97/****************************************************************************
98 ****************************************************************************
99 *
100 * ACPI Helpers and device model
101 *
102 ****************************************************************************
103 ****************************************************************************/
104
105/*************************************************************************
106 * ACPI basic handles
107 */
108
109static acpi_handle root_handle = NULL;
110
111#define IBM_HANDLE(object, parent, paths...) \
112 static acpi_handle object##_handle; \
113 static acpi_handle *object##_parent = &parent##_handle; \
114 static char *object##_path; \
115 static char *object##_paths[] = { paths }
116
117IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
118 "\\_SB.PCI.ISA.EC", /* 570 */
119 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
120 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
121 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
122 "\\_SB.PCI0.ICH3.EC0", /* R31 */
123 "\\_SB.PCI0.LPC.EC", /* all others */
124 );
125
126IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
127IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
128
129
130/*************************************************************************
131 * Misc ACPI handles
132 */
133
134IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
135 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
136 "\\CMS", /* R40, R40e */
137 ); /* all others */
138
139IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
140 "^HKEY", /* R30, R31 */
141 "HKEY", /* all others */
142 ); /* 570 */
143
144
145/*************************************************************************
146 * ACPI helpers
147 */
148
149static int acpi_evalf(acpi_handle handle,
150 void *res, char *method, char *fmt, ...)
151{
152 char *fmt0 = fmt;
153 struct acpi_object_list params;
154 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
155 struct acpi_buffer result, *resultp;
156 union acpi_object out_obj;
157 acpi_status status;
158 va_list ap;
159 char res_type;
160 int success;
161 int quiet;
162
163 if (!*fmt) {
164 printk(IBM_ERR "acpi_evalf() called with empty format\n");
165 return 0;
166 }
167
168 if (*fmt == 'q') {
169 quiet = 1;
170 fmt++;
171 } else
172 quiet = 0;
173
174 res_type = *(fmt++);
175
176 params.count = 0;
177 params.pointer = &in_objs[0];
178
179 va_start(ap, fmt);
180 while (*fmt) {
181 char c = *(fmt++);
182 switch (c) {
183 case 'd': /* int */
184 in_objs[params.count].integer.value = va_arg(ap, int);
185 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
186 break;
187 /* add more types as needed */
188 default:
189 printk(IBM_ERR "acpi_evalf() called "
190 "with invalid format character '%c'\n", c);
191 return 0;
192 }
193 }
194 va_end(ap);
195
196 if (res_type != 'v') {
197 result.length = sizeof(out_obj);
198 result.pointer = &out_obj;
199 resultp = &result;
200 } else
201 resultp = NULL;
202
203 status = acpi_evaluate_object(handle, method, &params, resultp);
204
205 switch (res_type) {
206 case 'd': /* int */
207 if (res)
208 *(int *)res = out_obj.integer.value;
209 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
210 break;
211 case 'v': /* void */
212 success = status == AE_OK;
213 break;
214 /* add more types as needed */
215 default:
216 printk(IBM_ERR "acpi_evalf() called "
217 "with invalid format character '%c'\n", res_type);
218 return 0;
219 }
220
221 if (!success && !quiet)
222 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
223 method, fmt0, status);
224
225 return success;
226}
227
228static void __unused acpi_print_int(acpi_handle handle, char *method)
229{
230 int i;
231
232 if (acpi_evalf(handle, &i, method, "d"))
233 printk(IBM_INFO "%s = 0x%x\n", method, i);
234 else
235 printk(IBM_ERR "error calling %s\n", method);
236}
237
238static int acpi_ec_read(int i, u8 * p)
239{
240 int v;
241
242 if (ecrd_handle) {
243 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
244 return 0;
245 *p = v;
246 } else {
247 if (ec_read(i, p) < 0)
248 return 0;
249 }
250
251 return 1;
252}
253
254static int acpi_ec_write(int i, u8 v)
255{
256 if (ecwr_handle) {
257 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
258 return 0;
259 } else {
260 if (ec_write(i, v) < 0)
261 return 0;
262 }
263
264 return 1;
265}
266
267static int _sta(acpi_handle handle)
268{
269 int status;
270
271 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
272 status = 0;
273
274 return status;
275}
276
277static int issue_thinkpad_cmos_command(int cmos_cmd)
278{
279 if (!cmos_handle)
280 return -ENXIO;
281
282 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
283 return -EIO;
284
285 return 0;
286}
287
288/*************************************************************************
289 * ACPI device model
290 */
291
292static void drv_acpi_handle_init(char *name,
293 acpi_handle *handle, acpi_handle parent,
294 char **paths, int num_paths, char **path)
295{
296 int i;
297 acpi_status status;
298
299 vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
300 name);
301
302 for (i = 0; i < num_paths; i++) {
303 status = acpi_get_handle(parent, paths[i], handle);
304 if (ACPI_SUCCESS(status)) {
305 *path = paths[i];
306 dbg_printk(TPACPI_DBG_INIT,
307 "Found ACPI handle %s for %s\n",
308 *path, name);
309 return;
310 }
311 }
312
313 vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
314 name);
315 *handle = NULL;
316}
317
318static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
319{
320 struct ibm_struct *ibm = data;
321
322 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
323 return;
324
325 ibm->acpi->notify(ibm, event);
326}
327
328static int __init setup_acpi_notify(struct ibm_struct *ibm)
329{
330 acpi_status status;
331 int rc;
332
333 BUG_ON(!ibm->acpi);
334
335 if (!*ibm->acpi->handle)
336 return 0;
337
338 vdbg_printk(TPACPI_DBG_INIT,
339 "setting up ACPI notify for %s\n", ibm->name);
340
341 rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
342 if (rc < 0) {
343 printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n",
344 ibm->name, rc);
345 return -ENODEV;
346 }
347
348 acpi_driver_data(ibm->acpi->device) = ibm;
349 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
350 IBM_ACPI_EVENT_PREFIX,
351 ibm->name);
352
353 status = acpi_install_notify_handler(*ibm->acpi->handle,
354 ibm->acpi->type, dispatch_acpi_notify, ibm);
355 if (ACPI_FAILURE(status)) {
356 if (status == AE_ALREADY_EXISTS) {
357 printk(IBM_NOTICE "another device driver is already handling %s events\n",
358 ibm->name);
359 } else {
360 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
361 ibm->name, status);
362 }
363 return -ENODEV;
364 }
365 ibm->flags.acpi_notify_installed = 1;
366 return 0;
367}
368
369static int __init tpacpi_device_add(struct acpi_device *device)
370{
371 return 0;
372}
373
374static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
375{
376 int rc;
377
378 dbg_printk(TPACPI_DBG_INIT,
379 "registering %s as an ACPI driver\n", ibm->name);
380
381 BUG_ON(!ibm->acpi);
382
383 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
384 if (!ibm->acpi->driver) {
385 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
386 return -ENOMEM;
387 }
388
389 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
390 ibm->acpi->driver->ids = ibm->acpi->hid;
391 ibm->acpi->driver->ops.add = &tpacpi_device_add;
392
393 rc = acpi_bus_register_driver(ibm->acpi->driver);
394 if (rc < 0) {
395 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
396 ibm->acpi->hid, rc);
397 kfree(ibm->acpi->driver);
398 ibm->acpi->driver = NULL;
399 } else if (!rc)
400 ibm->flags.acpi_driver_registered = 1;
401
402 return rc;
403}
404
405
406/****************************************************************************
407 ****************************************************************************
408 *
409 * Procfs Helpers
410 *
411 ****************************************************************************
412 ****************************************************************************/
413
414static int dispatch_procfs_read(char *page, char **start, off_t off,
415 int count, int *eof, void *data)
416{
417 struct ibm_struct *ibm = data;
418 int len;
419
420 if (!ibm || !ibm->read)
421 return -EINVAL;
422
423 len = ibm->read(page);
424 if (len < 0)
425 return len;
426
427 if (len <= off + count)
428 *eof = 1;
429 *start = page + off;
430 len -= off;
431 if (len > count)
432 len = count;
433 if (len < 0)
434 len = 0;
435
436 return len;
437}
438
439static int dispatch_procfs_write(struct file *file,
440 const char __user * userbuf,
441 unsigned long count, void *data)
442{
443 struct ibm_struct *ibm = data;
444 char *kernbuf;
445 int ret;
446
447 if (!ibm || !ibm->write)
448 return -EINVAL;
449
450 kernbuf = kmalloc(count + 2, GFP_KERNEL);
451 if (!kernbuf)
452 return -ENOMEM;
453
454 if (copy_from_user(kernbuf, userbuf, count)) {
455 kfree(kernbuf);
456 return -EFAULT;
457 }
458
459 kernbuf[count] = 0;
460 strcat(kernbuf, ",");
461 ret = ibm->write(kernbuf);
462 if (ret == 0)
463 ret = count;
464
465 kfree(kernbuf);
466
467 return ret;
468}
469
470static char *next_cmd(char **cmds)
471{
472 char *start = *cmds;
473 char *end;
474
475 while ((end = strchr(start, ',')) && end == start)
476 start = end + 1;
477
478 if (!end)
479 return NULL;
480
481 *end = 0;
482 *cmds = end + 1;
483 return start;
484}
485
486
487/****************************************************************************
488 ****************************************************************************
489 *
490 * Device model: hwmon and platform
491 *
492 ****************************************************************************
493 ****************************************************************************/
494
495static struct platform_device *tpacpi_pdev = NULL;
496static struct class_device *tpacpi_hwmon = NULL;
497
498static struct platform_driver tpacpi_pdriver = {
499 .driver = {
500 .name = IBM_DRVR_NAME,
501 .owner = THIS_MODULE,
502 },
503};
504
505
506/*************************************************************************
507 * thinkpad-acpi driver attributes
508 */
509
510/* interface_version --------------------------------------------------- */
511static ssize_t tpacpi_driver_interface_version_show(
512 struct device_driver *drv,
513 char *buf)
514{
515 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
516}
517
518static DRIVER_ATTR(interface_version, S_IRUGO,
519 tpacpi_driver_interface_version_show, NULL);
520
521/* debug_level --------------------------------------------------------- */
522static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
523 char *buf)
524{
525 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
526}
527
528static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
529 const char *buf, size_t count)
530{
531 unsigned long t;
532
533 if (parse_strtoul(buf, 0xffff, &t))
534 return -EINVAL;
535
536 dbg_level = t;
537
538 return count;
539}
540
541static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
542 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
543
544/* version ------------------------------------------------------------- */
545static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
546 char *buf)
547{
548 return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION);
549}
550
551static DRIVER_ATTR(version, S_IRUGO,
552 tpacpi_driver_version_show, NULL);
553
554/* --------------------------------------------------------------------- */
555
556static struct driver_attribute* tpacpi_driver_attributes[] = {
557 &driver_attr_debug_level, &driver_attr_version,
558 &driver_attr_interface_version,
559};
560
561static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
562{
563 int i, res;
564
565 i = 0;
566 res = 0;
567 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
568 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
569 i++;
570 }
571
572 return res;
573}
574
575static void tpacpi_remove_driver_attributes(struct device_driver *drv)
576{
577 int i;
578
579 for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
580 driver_remove_file(drv, tpacpi_driver_attributes[i]);
581}
582
583/*************************************************************************
584 * sysfs support helpers
585 */
586
587struct attribute_set_obj {
588 struct attribute_set s;
589 struct attribute *a;
590} __attribute__((packed));
591
592static struct attribute_set *create_attr_set(unsigned int max_members,
593 const char* name)
594{
595 struct attribute_set_obj *sobj;
596
597 if (max_members == 0)
598 return NULL;
599
600 /* Allocates space for implicit NULL at the end too */
601 sobj = kzalloc(sizeof(struct attribute_set_obj) +
602 max_members * sizeof(struct attribute *),
603 GFP_KERNEL);
604 if (!sobj)
605 return NULL;
606 sobj->s.max_members = max_members;
607 sobj->s.group.attrs = &sobj->a;
608 sobj->s.group.name = name;
609
610 return &sobj->s;
611}
612
613/* not multi-threaded safe, use it in a single thread per set */
614static int add_to_attr_set(struct attribute_set* s, struct attribute *attr)
615{
616 if (!s || !attr)
617 return -EINVAL;
618
619 if (s->members >= s->max_members)
620 return -ENOMEM;
621
622 s->group.attrs[s->members] = attr;
623 s->members++;
624
625 return 0;
626}
627
628static int add_many_to_attr_set(struct attribute_set* s,
629 struct attribute **attr,
630 unsigned int count)
631{
632 int i, res;
633
634 for (i = 0; i < count; i++) {
635 res = add_to_attr_set(s, attr[i]);
636 if (res)
637 return res;
638 }
639
640 return 0;
641}
642
643static void delete_attr_set(struct attribute_set* s, struct kobject *kobj)
644{
645 sysfs_remove_group(kobj, &s->group);
646 destroy_attr_set(s);
647}
648
649static int parse_strtoul(const char *buf,
650 unsigned long max, unsigned long *value)
651{
652 char *endp;
653
654 *value = simple_strtoul(buf, &endp, 0);
655 while (*endp && isspace(*endp))
656 endp++;
657 if (*endp || *value > max)
658 return -EINVAL;
659
660 return 0;
661}
662
663/****************************************************************************
664 ****************************************************************************
665 *
666 * Subdrivers
667 *
668 ****************************************************************************
669 ****************************************************************************/
670
671/*************************************************************************
672 * thinkpad-acpi init subdriver
673 */
674
675static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
676{
677 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
678 printk(IBM_INFO "%s\n", IBM_URL);
679
680 if (ibm_thinkpad_ec_found)
681 printk(IBM_INFO "ThinkPad EC firmware %s\n",
682 ibm_thinkpad_ec_found);
683
684 return 0;
685}
686
687static int thinkpad_acpi_driver_read(char *p)
688{
689 int len = 0;
690
691 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
692 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
693
694 return len;
695}
696
697static struct ibm_struct thinkpad_acpi_driver_data = {
698 .name = "driver",
699 .read = thinkpad_acpi_driver_read,
700};
701
702/*************************************************************************
703 * Hotkey subdriver
704 */
705
706static int hotkey_orig_status;
707static int hotkey_orig_mask;
708
709static struct attribute_set *hotkey_dev_attributes = NULL;
710
711/* sysfs hotkey enable ------------------------------------------------- */
712static ssize_t hotkey_enable_show(struct device *dev,
713 struct device_attribute *attr,
714 char *buf)
715{
716 int res, status, mask;
717
718 res = hotkey_get(&status, &mask);
719 if (res)
720 return res;
721
722 return snprintf(buf, PAGE_SIZE, "%d\n", status);
723}
724
725static ssize_t hotkey_enable_store(struct device *dev,
726 struct device_attribute *attr,
727 const char *buf, size_t count)
728{
729 unsigned long t;
730 int res, status, mask;
731
732 if (parse_strtoul(buf, 1, &t))
733 return -EINVAL;
734
735 res = hotkey_get(&status, &mask);
736 if (!res)
737 res = hotkey_set(t, mask);
738
739 return (res) ? res : count;
740}
741
742static struct device_attribute dev_attr_hotkey_enable =
743 __ATTR(enable, S_IWUSR | S_IRUGO,
744 hotkey_enable_show, hotkey_enable_store);
745
746/* sysfs hotkey mask --------------------------------------------------- */
747static ssize_t hotkey_mask_show(struct device *dev,
748 struct device_attribute *attr,
749 char *buf)
750{
751 int res, status, mask;
752
753 res = hotkey_get(&status, &mask);
754 if (res)
755 return res;
756
757 return snprintf(buf, PAGE_SIZE, "0x%04x\n", mask);
758}
759
760static ssize_t hotkey_mask_store(struct device *dev,
761 struct device_attribute *attr,
762 const char *buf, size_t count)
763{
764 unsigned long t;
765 int res, status, mask;
766
767 if (parse_strtoul(buf, 0xffff, &t))
768 return -EINVAL;
769
770 res = hotkey_get(&status, &mask);
771 if (!res)
772 hotkey_set(status, t);
773
774 return (res) ? res : count;
775}
776
777static struct device_attribute dev_attr_hotkey_mask =
778 __ATTR(mask, S_IWUSR | S_IRUGO,
779 hotkey_mask_show, hotkey_mask_store);
780
781/* sysfs hotkey bios_enabled ------------------------------------------- */
782static ssize_t hotkey_bios_enabled_show(struct device *dev,
783 struct device_attribute *attr,
784 char *buf)
785{
786 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
787}
788
789static struct device_attribute dev_attr_hotkey_bios_enabled =
790 __ATTR(bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
791
792/* sysfs hotkey bios_mask ---------------------------------------------- */
793static ssize_t hotkey_bios_mask_show(struct device *dev,
794 struct device_attribute *attr,
795 char *buf)
796{
797 return snprintf(buf, PAGE_SIZE, "0x%04x\n", hotkey_orig_mask);
798}
799
800static struct device_attribute dev_attr_hotkey_bios_mask =
801 __ATTR(bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
802
803/* --------------------------------------------------------------------- */
804
805static struct attribute *hotkey_mask_attributes[] = {
806 &dev_attr_hotkey_mask.attr,
807 &dev_attr_hotkey_bios_enabled.attr,
808 &dev_attr_hotkey_bios_mask.attr,
809};
810
811static int __init hotkey_init(struct ibm_init_struct *iibm)
812{
813 int res;
814
815 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
816
817 IBM_ACPIHANDLE_INIT(hkey);
818 mutex_init(&hotkey_mutex);
819
820 /* hotkey not supported on 570 */
821 tp_features.hotkey = hkey_handle != NULL;
822
823 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
824 str_supported(tp_features.hotkey));
825
826 if (tp_features.hotkey) {
827 hotkey_dev_attributes = create_attr_set(4,
828 TPACPI_HOTKEY_SYSFS_GROUP);
829 if (!hotkey_dev_attributes)
830 return -ENOMEM;
831 res = add_to_attr_set(hotkey_dev_attributes,
832 &dev_attr_hotkey_enable.attr);
833 if (res)
834 return res;
835
836 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
837 A30, R30, R31, T20-22, X20-21, X22-24 */
838 tp_features.hotkey_mask =
839 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
840
841 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
842 str_supported(tp_features.hotkey_mask));
843
844 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
845 if (!res && tp_features.hotkey_mask) {
846 res = add_many_to_attr_set(hotkey_dev_attributes,
847 hotkey_mask_attributes,
848 ARRAY_SIZE(hotkey_mask_attributes));
849 }
850 if (!res)
851 res = register_attr_set_with_sysfs(
852 hotkey_dev_attributes,
853 &tpacpi_pdev->dev.kobj);
854
855 if (res)
856 return res;
857 }
858
859 return (tp_features.hotkey)? 0 : 1;
860}
861
862static void hotkey_exit(void)
863{
864 int res;
865
866 if (tp_features.hotkey) {
867 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
868 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
869 if (res)
870 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
871 }
872
873 if (hotkey_dev_attributes) {
874 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
875 hotkey_dev_attributes = NULL;
876 }
877}
878
879static void hotkey_notify(struct ibm_struct *ibm, u32 event)
880{
881 int hkey;
882
883 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
884 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
885 else {
886 printk(IBM_ERR "unknown hotkey event %d\n", event);
887 acpi_bus_generate_event(ibm->acpi->device, event, 0);
888 }
889}
890
891/*
892 * Call with hotkey_mutex held
893 */
894static int hotkey_get(int *status, int *mask)
895{
896 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
897 return -EIO;
898
899 if (tp_features.hotkey_mask)
900 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
901 return -EIO;
902
903 return 0;
904}
905
906/*
907 * Call with hotkey_mutex held
908 */
909static int hotkey_set(int status, int mask)
910{
911 int i;
912
913 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
914 return -EIO;
915
916 if (tp_features.hotkey_mask)
917 for (i = 0; i < 32; i++) {
918 int bit = ((1 << i) & mask) != 0;
919 if (!acpi_evalf(hkey_handle,
920 NULL, "MHKM", "vdd", i + 1, bit))
921 return -EIO;
922 }
923
924 return 0;
925}
926
927/* procfs -------------------------------------------------------------- */
928static int hotkey_read(char *p)
929{
930 int res, status, mask;
931 int len = 0;
932
933 if (!tp_features.hotkey) {
934 len += sprintf(p + len, "status:\t\tnot supported\n");
935 return len;
936 }
937
938 res = mutex_lock_interruptible(&hotkey_mutex);
939 if (res < 0)
940 return res;
941 res = hotkey_get(&status, &mask);
942 mutex_unlock(&hotkey_mutex);
943 if (res)
944 return res;
945
946 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
947 if (tp_features.hotkey_mask) {
948 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
949 len += sprintf(p + len,
950 "commands:\tenable, disable, reset, <mask>\n");
951 } else {
952 len += sprintf(p + len, "mask:\t\tnot supported\n");
953 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
954 }
955
956 return len;
957}
958
959static int hotkey_write(char *buf)
960{
961 int res, status, mask;
962 char *cmd;
963 int do_cmd = 0;
964
965 if (!tp_features.hotkey)
966 return -ENODEV;
967
968 res = mutex_lock_interruptible(&hotkey_mutex);
969 if (res < 0)
970 return res;
971
972 res = hotkey_get(&status, &mask);
973 if (res)
974 goto errexit;
975
976 res = 0;
977 while ((cmd = next_cmd(&buf))) {
978 if (strlencmp(cmd, "enable") == 0) {
979 status = 1;
980 } else if (strlencmp(cmd, "disable") == 0) {
981 status = 0;
982 } else if (strlencmp(cmd, "reset") == 0) {
983 status = hotkey_orig_status;
984 mask = hotkey_orig_mask;
985 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
986 /* mask set */
987 } else if (sscanf(cmd, "%x", &mask) == 1) {
988 /* mask set */
989 } else {
990 res = -EINVAL;
991 goto errexit;
992 }
993 do_cmd = 1;
994 }
995
996 if (do_cmd)
997 res = hotkey_set(status, mask);
998
999errexit:
1000 mutex_unlock(&hotkey_mutex);
1001 return res;
1002}
1003
1004static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
1005 .hid = IBM_HKEY_HID,
1006 .notify = hotkey_notify,
1007 .handle = &hkey_handle,
1008 .type = ACPI_DEVICE_NOTIFY,
1009};
1010
1011static struct ibm_struct hotkey_driver_data = {
1012 .name = "hotkey",
1013 .read = hotkey_read,
1014 .write = hotkey_write,
1015 .exit = hotkey_exit,
1016 .acpi = &ibm_hotkey_acpidriver,
1017};
1018
1019/*************************************************************************
1020 * Bluetooth subdriver
1021 */
1022
1023/* sysfs bluetooth enable ---------------------------------------------- */
1024static ssize_t bluetooth_enable_show(struct device *dev,
1025 struct device_attribute *attr,
1026 char *buf)
1027{
1028 int status;
1029
1030 status = bluetooth_get_radiosw();
1031 if (status < 0)
1032 return status;
1033
1034 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1035}
1036
1037static ssize_t bluetooth_enable_store(struct device *dev,
1038 struct device_attribute *attr,
1039 const char *buf, size_t count)
1040{
1041 unsigned long t;
1042 int res;
1043
1044 if (parse_strtoul(buf, 1, &t))
1045 return -EINVAL;
1046
1047 res = bluetooth_set_radiosw(t);
1048
1049 return (res) ? res : count;
1050}
1051
1052static struct device_attribute dev_attr_bluetooth_enable =
1053 __ATTR(enable, S_IWUSR | S_IRUGO,
1054 bluetooth_enable_show, bluetooth_enable_store);
1055
1056/* --------------------------------------------------------------------- */
1057
1058static struct attribute *bluetooth_attributes[] = {
1059 &dev_attr_bluetooth_enable.attr,
1060 NULL
1061};
1062
1063static const struct attribute_group bluetooth_attr_group = {
1064 .name = TPACPI_BLUETH_SYSFS_GROUP,
1065 .attrs = bluetooth_attributes,
1066};
1067
1068static int __init bluetooth_init(struct ibm_init_struct *iibm)
1069{
1070 int res;
1071 int status = 0;
1072
1073 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
1074
1075 IBM_ACPIHANDLE_INIT(hkey);
1076
1077 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1078 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1079 tp_features.bluetooth = hkey_handle &&
1080 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
1081
1082 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
1083 str_supported(tp_features.bluetooth),
1084 status);
1085
1086 if (tp_features.bluetooth) {
1087 if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
1088 /* no bluetooth hardware present in system */
1089 tp_features.bluetooth = 0;
1090 dbg_printk(TPACPI_DBG_INIT,
1091 "bluetooth hardware not installed\n");
1092 } else {
1093 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1094 &bluetooth_attr_group);
1095 if (res)
1096 return res;
1097 }
1098 }
1099
1100 return (tp_features.bluetooth)? 0 : 1;
1101}
1102
1103static void bluetooth_exit(void)
1104{
1105 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1106 &bluetooth_attr_group);
1107}
1108
1109static int bluetooth_get_radiosw(void)
1110{
1111 int status;
1112
1113 if (!tp_features.bluetooth)
1114 return -ENODEV;
1115
1116 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1117 return -EIO;
1118
1119 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
1120}
1121
1122static int bluetooth_set_radiosw(int radio_on)
1123{
1124 int status;
1125
1126 if (!tp_features.bluetooth)
1127 return -ENODEV;
1128
1129 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
1130 return -EIO;
1131 if (radio_on)
1132 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
1133 else
1134 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
1135 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
1136 return -EIO;
1137
1138 return 0;
1139}
1140
1141/* procfs -------------------------------------------------------------- */
1142static int bluetooth_read(char *p)
1143{
1144 int len = 0;
1145 int status = bluetooth_get_radiosw();
1146
1147 if (!tp_features.bluetooth)
1148 len += sprintf(p + len, "status:\t\tnot supported\n");
1149 else {
1150 len += sprintf(p + len, "status:\t\t%s\n",
1151 (status)? "enabled" : "disabled");
1152 len += sprintf(p + len, "commands:\tenable, disable\n");
1153 }
1154
1155 return len;
1156}
1157
1158static int bluetooth_write(char *buf)
1159{
1160 char *cmd;
1161
1162 if (!tp_features.bluetooth)
1163 return -ENODEV;
1164
1165 while ((cmd = next_cmd(&buf))) {
1166 if (strlencmp(cmd, "enable") == 0) {
1167 bluetooth_set_radiosw(1);
1168 } else if (strlencmp(cmd, "disable") == 0) {
1169 bluetooth_set_radiosw(0);
1170 } else
1171 return -EINVAL;
1172 }
1173
1174 return 0;
1175}
1176
1177static struct ibm_struct bluetooth_driver_data = {
1178 .name = "bluetooth",
1179 .read = bluetooth_read,
1180 .write = bluetooth_write,
1181 .exit = bluetooth_exit,
1182};
1183
1184/*************************************************************************
1185 * Wan subdriver
1186 */
1187
1188/* sysfs wan enable ---------------------------------------------------- */
1189static ssize_t wan_enable_show(struct device *dev,
1190 struct device_attribute *attr,
1191 char *buf)
1192{
1193 int status;
1194
1195 status = wan_get_radiosw();
1196 if (status < 0)
1197 return status;
1198
1199 return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0);
1200}
1201
1202static ssize_t wan_enable_store(struct device *dev,
1203 struct device_attribute *attr,
1204 const char *buf, size_t count)
1205{
1206 unsigned long t;
1207 int res;
1208
1209 if (parse_strtoul(buf, 1, &t))
1210 return -EINVAL;
1211
1212 res = wan_set_radiosw(t);
1213
1214 return (res) ? res : count;
1215}
1216
1217static struct device_attribute dev_attr_wan_enable =
1218 __ATTR(enable, S_IWUSR | S_IRUGO,
1219 wan_enable_show, wan_enable_store);
1220
1221/* --------------------------------------------------------------------- */
1222
1223static struct attribute *wan_attributes[] = {
1224 &dev_attr_wan_enable.attr,
1225 NULL
1226};
1227
1228static const struct attribute_group wan_attr_group = {
1229 .name = TPACPI_WAN_SYSFS_GROUP,
1230 .attrs = wan_attributes,
1231};
1232
1233static int __init wan_init(struct ibm_init_struct *iibm)
1234{
1235 int res;
1236 int status = 0;
1237
1238 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
1239
1240 IBM_ACPIHANDLE_INIT(hkey);
1241
1242 tp_features.wan = hkey_handle &&
1243 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
1244
1245 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
1246 str_supported(tp_features.wan),
1247 status);
1248
1249 if (tp_features.wan) {
1250 if (!(status & TP_ACPI_WANCARD_HWPRESENT)) {
1251 /* no wan hardware present in system */
1252 tp_features.wan = 0;
1253 dbg_printk(TPACPI_DBG_INIT,
1254 "wan hardware not installed\n");
1255 } else {
1256 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
1257 &wan_attr_group);
1258 if (res)
1259 return res;
1260 }
1261 }
1262
1263 return (tp_features.wan)? 0 : 1;
1264}
1265
1266static void wan_exit(void)
1267{
1268 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
1269 &wan_attr_group);
1270}
1271
1272static int wan_get_radiosw(void)
1273{
1274 int status;
1275
1276 if (!tp_features.wan)
1277 return -ENODEV;
1278
1279 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1280 return -EIO;
1281
1282 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
1283}
1284
1285static int wan_set_radiosw(int radio_on)
1286{
1287 int status;
1288
1289 if (!tp_features.wan)
1290 return -ENODEV;
1291
1292 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
1293 return -EIO;
1294 if (radio_on)
1295 status |= TP_ACPI_WANCARD_RADIOSSW;
1296 else
1297 status &= ~TP_ACPI_WANCARD_RADIOSSW;
1298 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
1299 return -EIO;
1300
1301 return 0;
1302}
1303
1304/* procfs -------------------------------------------------------------- */
1305static int wan_read(char *p)
1306{
1307 int len = 0;
1308 int status = wan_get_radiosw();
1309
1310 if (!tp_features.wan)
1311 len += sprintf(p + len, "status:\t\tnot supported\n");
1312 else {
1313 len += sprintf(p + len, "status:\t\t%s\n",
1314 (status)? "enabled" : "disabled");
1315 len += sprintf(p + len, "commands:\tenable, disable\n");
1316 }
1317
1318 return len;
1319}
1320
1321static int wan_write(char *buf)
1322{
1323 char *cmd;
1324
1325 if (!tp_features.wan)
1326 return -ENODEV;
1327
1328 while ((cmd = next_cmd(&buf))) {
1329 if (strlencmp(cmd, "enable") == 0) {
1330 wan_set_radiosw(1);
1331 } else if (strlencmp(cmd, "disable") == 0) {
1332 wan_set_radiosw(0);
1333 } else
1334 return -EINVAL;
1335 }
1336
1337 return 0;
1338}
1339
1340static struct ibm_struct wan_driver_data = {
1341 .name = "wan",
1342 .read = wan_read,
1343 .write = wan_write,
1344 .exit = wan_exit,
1345 .flags.experimental = 1,
1346};
1347
1348/*************************************************************************
1349 * Video subdriver
1350 */
1351
1352static enum video_access_mode video_supported;
1353static int video_orig_autosw;
1354
1355IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
1356 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1357 "\\_SB.PCI0.VID0", /* 770e */
1358 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1359 "\\_SB.PCI0.AGP.VID", /* all others */
1360 ); /* R30, R31 */
1361
1362IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1363
1364static int __init video_init(struct ibm_init_struct *iibm)
1365{
1366 int ivga;
1367
1368 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
1369
1370 IBM_ACPIHANDLE_INIT(vid);
1371 IBM_ACPIHANDLE_INIT(vid2);
1372
1373 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
1374 /* G41, assume IVGA doesn't change */
1375 vid_handle = vid2_handle;
1376
1377 if (!vid_handle)
1378 /* video switching not supported on R30, R31 */
1379 video_supported = TPACPI_VIDEO_NONE;
1380 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
1381 /* 570 */
1382 video_supported = TPACPI_VIDEO_570;
1383 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
1384 /* 600e/x, 770e, 770x */
1385 video_supported = TPACPI_VIDEO_770;
1386 else
1387 /* all others */
1388 video_supported = TPACPI_VIDEO_NEW;
1389
1390 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
1391 str_supported(video_supported != TPACPI_VIDEO_NONE),
1392 video_supported);
1393
1394 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
1395}
1396
1397static void video_exit(void)
1398{
1399 dbg_printk(TPACPI_DBG_EXIT,
1400 "restoring original video autoswitch mode\n");
1401 if (video_autosw_set(video_orig_autosw))
1402 printk(IBM_ERR "error while trying to restore original "
1403 "video autoswitch mode\n");
1404}
1405
1406static int video_outputsw_get(void)
1407{
1408 int status = 0;
1409 int i;
1410
1411 switch (video_supported) {
1412 case TPACPI_VIDEO_570:
1413 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
1414 TP_ACPI_VIDEO_570_PHSCMD))
1415 return -EIO;
1416 status = i & TP_ACPI_VIDEO_570_PHSMASK;
1417 break;
1418 case TPACPI_VIDEO_770:
1419 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
1420 return -EIO;
1421 if (i)
1422 status |= TP_ACPI_VIDEO_S_LCD;
1423 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
1424 return -EIO;
1425 if (i)
1426 status |= TP_ACPI_VIDEO_S_CRT;
1427 break;
1428 case TPACPI_VIDEO_NEW:
1429 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
1430 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1431 return -EIO;
1432 if (i)
1433 status |= TP_ACPI_VIDEO_S_CRT;
1434
1435 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1436 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1437 return -EIO;
1438 if (i)
1439 status |= TP_ACPI_VIDEO_S_LCD;
1440 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1441 return -EIO;
1442 if (i)
1443 status |= TP_ACPI_VIDEO_S_DVI;
1444 break;
1445 default:
1446 return -ENOSYS;
1447 }
1448
1449 return status;
1450}
1451
1452static int video_outputsw_set(int status)
1453{
1454 int autosw;
1455 int res = 0;
1456
1457 switch (video_supported) {
1458 case TPACPI_VIDEO_570:
1459 res = acpi_evalf(NULL, NULL,
1460 "\\_SB.PHS2", "vdd",
1461 TP_ACPI_VIDEO_570_PHS2CMD,
1462 status | TP_ACPI_VIDEO_570_PHS2SET);
1463 break;
1464 case TPACPI_VIDEO_770:
1465 autosw = video_autosw_get();
1466 if (autosw < 0)
1467 return autosw;
1468
1469 res = video_autosw_set(1);
1470 if (res)
1471 return res;
1472 res = acpi_evalf(vid_handle, NULL,
1473 "ASWT", "vdd", status * 0x100, 0);
1474 if (!autosw && video_autosw_set(autosw)) {
1475 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1476 return -EIO;
1477 }
1478 break;
1479 case TPACPI_VIDEO_NEW:
1480 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1481 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1482 break;
1483 default:
1484 return -ENOSYS;
1485 }
1486
1487 return (res)? 0 : -EIO;
1488}
1489
1490static int video_autosw_get(void)
1491{
1492 int autosw = 0;
1493
1494 switch (video_supported) {
1495 case TPACPI_VIDEO_570:
1496 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1497 return -EIO;
1498 break;
1499 case TPACPI_VIDEO_770:
1500 case TPACPI_VIDEO_NEW:
1501 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1502 return -EIO;
1503 break;
1504 default:
1505 return -ENOSYS;
1506 }
1507
1508 return autosw & 1;
1509}
1510
1511static int video_autosw_set(int enable)
1512{
1513 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
1514 return -EIO;
1515 return 0;
1516}
1517
1518static int video_outputsw_cycle(void)
1519{
1520 int autosw = video_autosw_get();
1521 int res;
1522
1523 if (autosw < 0)
1524 return autosw;
1525
1526 switch (video_supported) {
1527 case TPACPI_VIDEO_570:
1528 res = video_autosw_set(1);
1529 if (res)
1530 return res;
1531 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1532 break;
1533 case TPACPI_VIDEO_770:
1534 case TPACPI_VIDEO_NEW:
1535 res = video_autosw_set(1);
1536 if (res)
1537 return res;
1538 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1539 break;
1540 default:
1541 return -ENOSYS;
1542 }
1543 if (!autosw && video_autosw_set(autosw)) {
1544 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1545 return -EIO;
1546 }
1547
1548 return (res)? 0 : -EIO;
1549}
1550
1551static int video_expand_toggle(void)
1552{
1553 switch (video_supported) {
1554 case TPACPI_VIDEO_570:
1555 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1556 0 : -EIO;
1557 case TPACPI_VIDEO_770:
1558 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1559 0 : -EIO;
1560 case TPACPI_VIDEO_NEW:
1561 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1562 0 : -EIO;
1563 default:
1564 return -ENOSYS;
1565 }
1566 /* not reached */
1567}
1568
1569static int video_read(char *p)
1570{
1571 int status, autosw;
1572 int len = 0;
1573
1574 if (video_supported == TPACPI_VIDEO_NONE) {
1575 len += sprintf(p + len, "status:\t\tnot supported\n");
1576 return len;
1577 }
1578
1579 status = video_outputsw_get();
1580 if (status < 0)
1581 return status;
1582
1583 autosw = video_autosw_get();
1584 if (autosw < 0)
1585 return autosw;
1586
1587 len += sprintf(p + len, "status:\t\tsupported\n");
1588 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1589 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
1590 if (video_supported == TPACPI_VIDEO_NEW)
1591 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1592 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1593 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1594 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
1595 if (video_supported == TPACPI_VIDEO_NEW)
1596 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1597 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1598 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1599
1600 return len;
1601}
1602
1603static int video_write(char *buf)
1604{
1605 char *cmd;
1606 int enable, disable, status;
1607 int res;
1608
1609 if (video_supported == TPACPI_VIDEO_NONE)
1610 return -ENODEV;
1611
1612 enable = 0;
1613 disable = 0;
1614
1615 while ((cmd = next_cmd(&buf))) {
1616 if (strlencmp(cmd, "lcd_enable") == 0) {
1617 enable |= TP_ACPI_VIDEO_S_LCD;
1618 } else if (strlencmp(cmd, "lcd_disable") == 0) {
1619 disable |= TP_ACPI_VIDEO_S_LCD;
1620 } else if (strlencmp(cmd, "crt_enable") == 0) {
1621 enable |= TP_ACPI_VIDEO_S_CRT;
1622 } else if (strlencmp(cmd, "crt_disable") == 0) {
1623 disable |= TP_ACPI_VIDEO_S_CRT;
1624 } else if (video_supported == TPACPI_VIDEO_NEW &&
1625 strlencmp(cmd, "dvi_enable") == 0) {
1626 enable |= TP_ACPI_VIDEO_S_DVI;
1627 } else if (video_supported == TPACPI_VIDEO_NEW &&
1628 strlencmp(cmd, "dvi_disable") == 0) {
1629 disable |= TP_ACPI_VIDEO_S_DVI;
1630 } else if (strlencmp(cmd, "auto_enable") == 0) {
1631 res = video_autosw_set(1);
1632 if (res)
1633 return res;
1634 } else if (strlencmp(cmd, "auto_disable") == 0) {
1635 res = video_autosw_set(0);
1636 if (res)
1637 return res;
1638 } else if (strlencmp(cmd, "video_switch") == 0) {
1639 res = video_outputsw_cycle();
1640 if (res)
1641 return res;
1642 } else if (strlencmp(cmd, "expand_toggle") == 0) {
1643 res = video_expand_toggle();
1644 if (res)
1645 return res;
1646 } else
1647 return -EINVAL;
1648 }
1649
1650 if (enable || disable) {
1651 status = video_outputsw_get();
1652 if (status < 0)
1653 return status;
1654 res = video_outputsw_set((status & ~disable) | enable);
1655 if (res)
1656 return res;
1657 }
1658
1659 return 0;
1660}
1661
1662static struct ibm_struct video_driver_data = {
1663 .name = "video",
1664 .read = video_read,
1665 .write = video_write,
1666 .exit = video_exit,
1667};
1668
1669/*************************************************************************
1670 * Light (thinklight) subdriver
1671 */
1672
1673IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1674IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1675
1676static int __init light_init(struct ibm_init_struct *iibm)
1677{
1678 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1679
1680 IBM_ACPIHANDLE_INIT(ledb);
1681 IBM_ACPIHANDLE_INIT(lght);
1682 IBM_ACPIHANDLE_INIT(cmos);
1683
1684 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1685 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
1686
1687 if (tp_features.light)
1688 /* light status not supported on
1689 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1690 tp_features.light_status =
1691 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
1692
1693 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
1694 str_supported(tp_features.light));
1695
1696 return (tp_features.light)? 0 : 1;
1697}
1698
1699static int light_read(char *p)
1700{
1701 int len = 0;
1702 int status = 0;
1703
1704 if (!tp_features.light) {
1705 len += sprintf(p + len, "status:\t\tnot supported\n");
1706 } else if (!tp_features.light_status) {
1707 len += sprintf(p + len, "status:\t\tunknown\n");
1708 len += sprintf(p + len, "commands:\ton, off\n");
1709 } else {
1710 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1711 return -EIO;
1712 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
1713 len += sprintf(p + len, "commands:\ton, off\n");
1714 }
1715
1716 return len;
1717}
1718
1719static int light_write(char *buf)
1720{
1721 int cmos_cmd, lght_cmd;
1722 char *cmd;
1723 int success;
1724
1725 if (!tp_features.light)
1726 return -ENODEV;
1727
1728 while ((cmd = next_cmd(&buf))) {
1729 if (strlencmp(cmd, "on") == 0) {
1730 cmos_cmd = 0x0c;
1731 lght_cmd = 1;
1732 } else if (strlencmp(cmd, "off") == 0) {
1733 cmos_cmd = 0x0d;
1734 lght_cmd = 0;
1735 } else
1736 return -EINVAL;
1737
1738 success = cmos_handle ?
1739 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1740 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
1741 if (!success)
1742 return -EIO;
1743 }
1744
1745 return 0;
1746}
1747
1748static struct ibm_struct light_driver_data = {
1749 .name = "light",
1750 .read = light_read,
1751 .write = light_write,
1752};
1753
1754/*************************************************************************
1755 * Dock subdriver
1756 */
1757
1758#ifdef CONFIG_THINKPAD_ACPI_DOCK
1759
1760IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1761 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1762 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1763 "\\_SB.PCI.ISA.SLCE", /* 570 */
1764 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1765
1766/* don't list other alternatives as we install a notify handler on the 570 */
1767IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1768
1769static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
1770 {
1771 .notify = dock_notify,
1772 .handle = &dock_handle,
1773 .type = ACPI_SYSTEM_NOTIFY,
1774 },
1775 {
1776 .hid = IBM_PCI_HID,
1777 .notify = dock_notify,
1778 .handle = &pci_handle,
1779 .type = ACPI_SYSTEM_NOTIFY,
1780 },
1781};
1782
1783static struct ibm_struct dock_driver_data[2] = {
1784 {
1785 .name = "dock",
1786 .read = dock_read,
1787 .write = dock_write,
1788 .acpi = &ibm_dock_acpidriver[0],
1789 },
1790 {
1791 .name = "dock",
1792 .acpi = &ibm_dock_acpidriver[1],
1793 },
1794};
1795
1796#define dock_docked() (_sta(dock_handle) & 1)
1797
1798static int __init dock_init(struct ibm_init_struct *iibm)
1799{
1800 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1801
1802 IBM_ACPIHANDLE_INIT(dock);
1803
1804 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1805 str_supported(dock_handle != NULL));
1806
1807 return (dock_handle)? 0 : 1;
1808}
1809
1810static int __init dock_init2(struct ibm_init_struct *iibm)
1811{
1812 int dock2_needed;
1813
1814 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
1815
1816 if (dock_driver_data[0].flags.acpi_driver_registered &&
1817 dock_driver_data[0].flags.acpi_notify_installed) {
1818 IBM_ACPIHANDLE_INIT(pci);
1819 dock2_needed = (pci_handle != NULL);
1820 vdbg_printk(TPACPI_DBG_INIT,
1821 "dock PCI handler for the TP 570 is %s\n",
1822 str_supported(dock2_needed));
1823 } else {
1824 vdbg_printk(TPACPI_DBG_INIT,
1825 "dock subdriver part 2 not required\n");
1826 dock2_needed = 0;
1827 }
1828
1829 return (dock2_needed)? 0 : 1;
1830}
1831
1832static void dock_notify(struct ibm_struct *ibm, u32 event)
1833{
1834 int docked = dock_docked();
1835 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
1836
1837 if (event == 1 && !pci) /* 570 */
1838 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1839 else if (event == 1 && pci) /* 570 */
1840 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1841 else if (event == 3 && docked)
1842 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
1843 else if (event == 3 && !docked)
1844 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
1845 else if (event == 0 && docked)
1846 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
1847 else {
1848 printk(IBM_ERR "unknown dock event %d, status %d\n",
1849 event, _sta(dock_handle));
1850 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
1851 }
1852}
1853
1854static int dock_read(char *p)
1855{
1856 int len = 0;
1857 int docked = dock_docked();
1858
1859 if (!dock_handle)
1860 len += sprintf(p + len, "status:\t\tnot supported\n");
1861 else if (!docked)
1862 len += sprintf(p + len, "status:\t\tundocked\n");
1863 else {
1864 len += sprintf(p + len, "status:\t\tdocked\n");
1865 len += sprintf(p + len, "commands:\tdock, undock\n");
1866 }
1867
1868 return len;
1869}
1870
1871static int dock_write(char *buf)
1872{
1873 char *cmd;
1874
1875 if (!dock_docked())
1876 return -ENODEV;
1877
1878 while ((cmd = next_cmd(&buf))) {
1879 if (strlencmp(cmd, "undock") == 0) {
1880 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1881 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
1882 return -EIO;
1883 } else if (strlencmp(cmd, "dock") == 0) {
1884 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1885 return -EIO;
1886 } else
1887 return -EINVAL;
1888 }
1889
1890 return 0;
1891}
1892
1893#endif /* CONFIG_THINKPAD_ACPI_DOCK */
1894
1895/*************************************************************************
1896 * Bay subdriver
1897 */
1898
1899#ifdef CONFIG_THINKPAD_ACPI_BAY
1900IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1901 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1902 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1903 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1904 ); /* A21e, R30, R31 */
1905IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1906 "_EJ0", /* all others */
1907 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1908IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1909 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1910 ); /* all others */
1911IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1912 "_EJ0", /* 770x */
1913 ); /* all others */
1914
1915static int __init bay_init(struct ibm_init_struct *iibm)
1916{
1917 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1918
1919 IBM_ACPIHANDLE_INIT(bay);
1920 if (bay_handle)
1921 IBM_ACPIHANDLE_INIT(bay_ej);
1922 IBM_ACPIHANDLE_INIT(bay2);
1923 if (bay2_handle)
1924 IBM_ACPIHANDLE_INIT(bay2_ej);
1925
1926 tp_features.bay_status = bay_handle &&
1927 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1928 tp_features.bay_status2 = bay2_handle &&
1929 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1930
1931 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1932 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1933 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1934 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
1935
1936 vdbg_printk(TPACPI_DBG_INIT,
1937 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1938 str_supported(tp_features.bay_status),
1939 str_supported(tp_features.bay_eject),
1940 str_supported(tp_features.bay_status2),
1941 str_supported(tp_features.bay_eject2));
1942
1943 return (tp_features.bay_status || tp_features.bay_eject ||
1944 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
1945}
1946
1947static void bay_notify(struct ibm_struct *ibm, u32 event)
1948{
1949 acpi_bus_generate_event(ibm->acpi->device, event, 0);
1950}
1951
1952#define bay_occupied(b) (_sta(b##_handle) & 1)
1953
1954static int bay_read(char *p)
1955{
1956 int len = 0;
1957 int occupied = bay_occupied(bay);
1958 int occupied2 = bay_occupied(bay2);
1959 int eject, eject2;
1960
1961 len += sprintf(p + len, "status:\t\t%s\n",
1962 tp_features.bay_status ?
1963 (occupied ? "occupied" : "unoccupied") :
1964 "not supported");
1965 if (tp_features.bay_status2)
1966 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1967 "occupied" : "unoccupied");
1968
1969 eject = tp_features.bay_eject && occupied;
1970 eject2 = tp_features.bay_eject2 && occupied2;
1971
1972 if (eject && eject2)
1973 len += sprintf(p + len, "commands:\teject, eject2\n");
1974 else if (eject)
1975 len += sprintf(p + len, "commands:\teject\n");
1976 else if (eject2)
1977 len += sprintf(p + len, "commands:\teject2\n");
1978
1979 return len;
1980}
1981
1982static int bay_write(char *buf)
1983{
1984 char *cmd;
1985
1986 if (!tp_features.bay_eject && !tp_features.bay_eject2)
1987 return -ENODEV;
1988
1989 while ((cmd = next_cmd(&buf))) {
1990 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
1991 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1992 return -EIO;
1993 } else if (tp_features.bay_eject2 &&
1994 strlencmp(cmd, "eject2") == 0) {
1995 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
1996 return -EIO;
1997 } else
1998 return -EINVAL;
1999 }
2000
2001 return 0;
2002}
2003
2004static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
2005 .notify = bay_notify,
2006 .handle = &bay_handle,
2007 .type = ACPI_SYSTEM_NOTIFY,
2008};
2009
2010static struct ibm_struct bay_driver_data = {
2011 .name = "bay",
2012 .read = bay_read,
2013 .write = bay_write,
2014 .acpi = &ibm_bay_acpidriver,
2015};
2016
2017#endif /* CONFIG_THINKPAD_ACPI_BAY */
2018
2019/*************************************************************************
2020 * CMOS subdriver
2021 */
2022
2023/* sysfs cmos_command -------------------------------------------------- */
2024static ssize_t cmos_command_store(struct device *dev,
2025 struct device_attribute *attr,
2026 const char *buf, size_t count)
2027{
2028 unsigned long cmos_cmd;
2029 int res;
2030
2031 if (parse_strtoul(buf, 21, &cmos_cmd))
2032 return -EINVAL;
2033
2034 res = issue_thinkpad_cmos_command(cmos_cmd);
2035 return (res)? res : count;
2036}
2037
2038static struct device_attribute dev_attr_cmos_command =
2039 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
2040
2041/* --------------------------------------------------------------------- */
2042
2043static int __init cmos_init(struct ibm_init_struct *iibm)
2044{
2045 int res;
2046
2047 vdbg_printk(TPACPI_DBG_INIT,
2048 "initializing cmos commands subdriver\n");
2049
2050 IBM_ACPIHANDLE_INIT(cmos);
2051
2052 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
2053 str_supported(cmos_handle != NULL));
2054
2055 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2056 if (res)
2057 return res;
2058
2059 return (cmos_handle)? 0 : 1;
2060}
2061
2062static void cmos_exit(void)
2063{
2064 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
2065}
2066
2067static int cmos_read(char *p)
2068{
2069 int len = 0;
2070
2071 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2072 R30, R31, T20-22, X20-21 */
2073 if (!cmos_handle)
2074 len += sprintf(p + len, "status:\t\tnot supported\n");
2075 else {
2076 len += sprintf(p + len, "status:\t\tsupported\n");
2077 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
2078 }
2079
2080 return len;
2081}
2082
2083static int cmos_write(char *buf)
2084{
2085 char *cmd;
2086 int cmos_cmd, res;
2087
2088 while ((cmd = next_cmd(&buf))) {
2089 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
2090 cmos_cmd >= 0 && cmos_cmd <= 21) {
2091 /* cmos_cmd set */
2092 } else
2093 return -EINVAL;
2094
2095 res = issue_thinkpad_cmos_command(cmos_cmd);
2096 if (res)
2097 return res;
2098 }
2099
2100 return 0;
2101}
2102
2103static struct ibm_struct cmos_driver_data = {
2104 .name = "cmos",
2105 .read = cmos_read,
2106 .write = cmos_write,
2107 .exit = cmos_exit,
2108};
2109
2110/*************************************************************************
2111 * LED subdriver
2112 */
2113
2114static enum led_access_mode led_supported;
2115
2116IBM_HANDLE(led, ec, "SLED", /* 570 */
2117 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2118 "LED", /* all others */
2119 ); /* R30, R31 */
2120
2121static int __init led_init(struct ibm_init_struct *iibm)
2122{
2123 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
2124
2125 IBM_ACPIHANDLE_INIT(led);
2126
2127 if (!led_handle)
2128 /* led not supported on R30, R31 */
2129 led_supported = TPACPI_LED_NONE;
2130 else if (strlencmp(led_path, "SLED") == 0)
2131 /* 570 */
2132 led_supported = TPACPI_LED_570;
2133 else if (strlencmp(led_path, "SYSL") == 0)
2134 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2135 led_supported = TPACPI_LED_OLD;
2136 else
2137 /* all others */
2138 led_supported = TPACPI_LED_NEW;
2139
2140 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
2141 str_supported(led_supported), led_supported);
2142
2143 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
2144}
2145
2146#define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2147
2148static int led_read(char *p)
2149{
2150 int len = 0;
2151
2152 if (!led_supported) {
2153 len += sprintf(p + len, "status:\t\tnot supported\n");
2154 return len;
2155 }
2156 len += sprintf(p + len, "status:\t\tsupported\n");
2157
2158 if (led_supported == TPACPI_LED_570) {
2159 /* 570 */
2160 int i, status;
2161 for (i = 0; i < 8; i++) {
2162 if (!acpi_evalf(ec_handle,
2163 &status, "GLED", "dd", 1 << i))
2164 return -EIO;
2165 len += sprintf(p + len, "%d:\t\t%s\n",
2166 i, led_status(status));
2167 }
2168 }
2169
2170 len += sprintf(p + len, "commands:\t"
2171 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2172
2173 return len;
2174}
2175
2176/* off, on, blink */
2177static const int led_sled_arg1[] = { 0, 1, 3 };
2178static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
2179static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
2180static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
2181
2182static int led_write(char *buf)
2183{
2184 char *cmd;
2185 int led, ind, ret;
2186
2187 if (!led_supported)
2188 return -ENODEV;
2189
2190 while ((cmd = next_cmd(&buf))) {
2191 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
2192 return -EINVAL;
2193
2194 if (strstr(cmd, "off")) {
2195 ind = 0;
2196 } else if (strstr(cmd, "on")) {
2197 ind = 1;
2198 } else if (strstr(cmd, "blink")) {
2199 ind = 2;
2200 } else
2201 return -EINVAL;
2202
2203 if (led_supported == TPACPI_LED_570) {
2204 /* 570 */
2205 led = 1 << led;
2206 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2207 led, led_sled_arg1[ind]))
2208 return -EIO;
2209 } else if (led_supported == TPACPI_LED_OLD) {
2210 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2211 led = 1 << led;
2212 ret = ec_write(TPACPI_LED_EC_HLMS, led);
2213 if (ret >= 0)
2214 ret =
2215 ec_write(TPACPI_LED_EC_HLBL,
2216 led * led_exp_hlbl[ind]);
2217 if (ret >= 0)
2218 ret =
2219 ec_write(TPACPI_LED_EC_HLCL,
2220 led * led_exp_hlcl[ind]);
2221 if (ret < 0)
2222 return ret;
2223 } else {
2224 /* all others */
2225 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
2226 led, led_led_arg1[ind]))
2227 return -EIO;
2228 }
2229 }
2230
2231 return 0;
2232}
2233
2234static struct ibm_struct led_driver_data = {
2235 .name = "led",
2236 .read = led_read,
2237 .write = led_write,
2238};
2239
2240/*************************************************************************
2241 * Beep subdriver
2242 */
2243
2244IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
2245
2246static int __init beep_init(struct ibm_init_struct *iibm)
2247{
2248 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
2249
2250 IBM_ACPIHANDLE_INIT(beep);
2251
2252 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
2253 str_supported(beep_handle != NULL));
2254
2255 return (beep_handle)? 0 : 1;
2256}
2257
2258static int beep_read(char *p)
2259{
2260 int len = 0;
2261
2262 if (!beep_handle)
2263 len += sprintf(p + len, "status:\t\tnot supported\n");
2264 else {
2265 len += sprintf(p + len, "status:\t\tsupported\n");
2266 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
2267 }
2268
2269 return len;
2270}
2271
2272static int beep_write(char *buf)
2273{
2274 char *cmd;
2275 int beep_cmd;
2276
2277 if (!beep_handle)
2278 return -ENODEV;
2279
2280 while ((cmd = next_cmd(&buf))) {
2281 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
2282 beep_cmd >= 0 && beep_cmd <= 17) {
2283 /* beep_cmd set */
2284 } else
2285 return -EINVAL;
2286 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
2287 return -EIO;
2288 }
2289
2290 return 0;
2291}
2292
2293static struct ibm_struct beep_driver_data = {
2294 .name = "beep",
2295 .read = beep_read,
2296 .write = beep_write,
2297};
2298
2299/*************************************************************************
2300 * Thermal subdriver
2301 */
2302
2303static enum thermal_access_mode thermal_read_mode;
2304
2305/* sysfs temp##_input -------------------------------------------------- */
2306
2307static ssize_t thermal_temp_input_show(struct device *dev,
2308 struct device_attribute *attr,
2309 char *buf)
2310{
2311 struct sensor_device_attribute *sensor_attr =
2312 to_sensor_dev_attr(attr);
2313 int idx = sensor_attr->index;
2314 s32 value;
2315 int res;
2316
2317 res = thermal_get_sensor(idx, &value);
2318 if (res)
2319 return res;
2320 if (value == TP_EC_THERMAL_TMP_NA * 1000)
2321 return -ENXIO;
2322
2323 return snprintf(buf, PAGE_SIZE, "%d\n", value);
2324}
2325
2326#define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2327 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2328
2329static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
2330 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2331 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2332 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2333 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2334 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2335 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2336 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2337 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2338 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2339 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2340 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2341 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2342 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2343 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2344 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2345 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2346};
2347
2348#define THERMAL_ATTRS(X) \
2349 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2350
2351static struct attribute *thermal_temp_input_attr[] = {
2352 THERMAL_ATTRS(8),
2353 THERMAL_ATTRS(9),
2354 THERMAL_ATTRS(10),
2355 THERMAL_ATTRS(11),
2356 THERMAL_ATTRS(12),
2357 THERMAL_ATTRS(13),
2358 THERMAL_ATTRS(14),
2359 THERMAL_ATTRS(15),
2360 THERMAL_ATTRS(0),
2361 THERMAL_ATTRS(1),
2362 THERMAL_ATTRS(2),
2363 THERMAL_ATTRS(3),
2364 THERMAL_ATTRS(4),
2365 THERMAL_ATTRS(5),
2366 THERMAL_ATTRS(6),
2367 THERMAL_ATTRS(7),
2368 NULL
2369};
2370
2371static const struct attribute_group thermal_temp_input16_group = {
2372 .attrs = thermal_temp_input_attr
2373};
2374
2375static const struct attribute_group thermal_temp_input8_group = {
2376 .attrs = &thermal_temp_input_attr[8]
2377};
2378
2379#undef THERMAL_SENSOR_ATTR_TEMP
2380#undef THERMAL_ATTRS
2381
2382/* --------------------------------------------------------------------- */
2383
2384static int __init thermal_init(struct ibm_init_struct *iibm)
2385{
2386 u8 t, ta1, ta2;
2387 int i;
2388 int acpi_tmp7;
2389 int res;
2390
2391 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
2392
2393 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
2394
2395 if (ibm_thinkpad_ec_found && experimental) {
2396 /*
2397 * Direct EC access mode: sensors at registers
2398 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2399 * non-implemented, thermal sensors return 0x80 when
2400 * not available
2401 */
2402
2403 ta1 = ta2 = 0;
2404 for (i = 0; i < 8; i++) {
2405 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
2406 ta1 |= t;
2407 } else {
2408 ta1 = 0;
2409 break;
2410 }
2411 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
2412 ta2 |= t;
2413 } else {
2414 ta1 = 0;
2415 break;
2416 }
2417 }
2418 if (ta1 == 0) {
2419 /* This is sheer paranoia, but we handle it anyway */
2420 if (acpi_tmp7) {
2421 printk(IBM_ERR
2422 "ThinkPad ACPI EC access misbehaving, "
2423 "falling back to ACPI TMPx access mode\n");
2424 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2425 } else {
2426 printk(IBM_ERR
2427 "ThinkPad ACPI EC access misbehaving, "
2428 "disabling thermal sensors access\n");
2429 thermal_read_mode = TPACPI_THERMAL_NONE;
2430 }
2431 } else {
2432 thermal_read_mode =
2433 (ta2 != 0) ?
2434 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
2435 }
2436 } else if (acpi_tmp7) {
2437 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
2438 /* 600e/x, 770e, 770x */
2439 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
2440 } else {
2441 /* Standard ACPI TMPx access, max 8 sensors */
2442 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
2443 }
2444 } else {
2445 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2446 thermal_read_mode = TPACPI_THERMAL_NONE;
2447 }
2448
2449 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
2450 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
2451 thermal_read_mode);
2452
2453 switch(thermal_read_mode) {
2454 case TPACPI_THERMAL_TPEC_16:
2455 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2456 &thermal_temp_input16_group);
2457 if (res)
2458 return res;
2459 break;
2460 case TPACPI_THERMAL_TPEC_8:
2461 case TPACPI_THERMAL_ACPI_TMP07:
2462 case TPACPI_THERMAL_ACPI_UPDT:
2463 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
2464 &thermal_temp_input8_group);
2465 if (res)
2466 return res;
2467 break;
2468 case TPACPI_THERMAL_NONE:
2469 default:
2470 return 1;
2471 }
2472
2473 return 0;
2474}
2475
2476static void thermal_exit(void)
2477{
2478 switch(thermal_read_mode) {
2479 case TPACPI_THERMAL_TPEC_16:
2480 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2481 &thermal_temp_input16_group);
2482 break;
2483 case TPACPI_THERMAL_TPEC_8:
2484 case TPACPI_THERMAL_ACPI_TMP07:
2485 case TPACPI_THERMAL_ACPI_UPDT:
2486 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
2487 &thermal_temp_input16_group);
2488 break;
2489 case TPACPI_THERMAL_NONE:
2490 default:
2491 break;
2492 }
2493}
2494
2495/* idx is zero-based */
2496static int thermal_get_sensor(int idx, s32 *value)
2497{
2498 int t;
2499 s8 tmp;
2500 char tmpi[5];
2501
2502 t = TP_EC_THERMAL_TMP0;
2503
2504 switch (thermal_read_mode) {
2505#if TPACPI_MAX_THERMAL_SENSORS >= 16
2506 case TPACPI_THERMAL_TPEC_16:
2507 if (idx >= 8 && idx <= 15) {
2508 t = TP_EC_THERMAL_TMP8;
2509 idx -= 8;
2510 }
2511 /* fallthrough */
2512#endif
2513 case TPACPI_THERMAL_TPEC_8:
2514 if (idx <= 7) {
2515 if (!acpi_ec_read(t + idx, &tmp))
2516 return -EIO;
2517 *value = tmp * 1000;
2518 return 0;
2519 }
2520 break;
2521
2522 case TPACPI_THERMAL_ACPI_UPDT:
2523 if (idx <= 7) {
2524 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2525 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
2526 return -EIO;
2527 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2528 return -EIO;
2529 *value = (t - 2732) * 100;
2530 return 0;
2531 }
2532 break;
2533
2534 case TPACPI_THERMAL_ACPI_TMP07:
2535 if (idx <= 7) {
2536 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2537 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2538 return -EIO;
2539 *value = t * 1000;
2540 return 0;
2541 }
2542 break;
2543
2544 case TPACPI_THERMAL_NONE:
2545 default:
2546 return -ENOSYS;
2547 }
2548
2549 return -EINVAL;
2550}
2551
2552static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
2553{
2554 int res, i;
2555 int n;
2556
2557 n = 8;
2558 i = 0;
2559
2560 if (!s)
2561 return -EINVAL;
2562
2563 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
2564 n = 16;
2565
2566 for(i = 0 ; i < n; i++) {
2567 res = thermal_get_sensor(i, &s->temp[i]);
2568 if (res)
2569 return res;
2570 }
2571
2572 return n;
2573}
2574
2575static int thermal_read(char *p)
2576{
2577 int len = 0;
2578 int n, i;
2579 struct ibm_thermal_sensors_struct t;
2580
2581 n = thermal_get_sensors(&t);
2582 if (unlikely(n < 0))
2583 return n;
2584
2585 len += sprintf(p + len, "temperatures:\t");
2586
2587 if (n > 0) {
2588 for (i = 0; i < (n - 1); i++)
2589 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
2590 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
2591 } else
2592 len += sprintf(p + len, "not supported\n");
2593
2594 return len;
2595}
2596
2597static struct ibm_struct thermal_driver_data = {
2598 .name = "thermal",
2599 .read = thermal_read,
2600 .exit = thermal_exit,
2601};
2602
2603/*************************************************************************
2604 * EC Dump subdriver
2605 */
2606
2607static u8 ecdump_regs[256];
2608
2609static int ecdump_read(char *p)
2610{
2611 int len = 0;
2612 int i, j;
2613 u8 v;
2614
2615 len += sprintf(p + len, "EC "
2616 " +00 +01 +02 +03 +04 +05 +06 +07"
2617 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2618 for (i = 0; i < 256; i += 16) {
2619 len += sprintf(p + len, "EC 0x%02x:", i);
2620 for (j = 0; j < 16; j++) {
2621 if (!acpi_ec_read(i + j, &v))
2622 break;
2623 if (v != ecdump_regs[i + j])
2624 len += sprintf(p + len, " *%02x", v);
2625 else
2626 len += sprintf(p + len, " %02x", v);
2627 ecdump_regs[i + j] = v;
2628 }
2629 len += sprintf(p + len, "\n");
2630 if (j != 16)
2631 break;
2632 }
2633
2634 /* These are way too dangerous to advertise openly... */
2635#if 0
2636 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2637 " (<offset> is 00-ff, <value> is 00-ff)\n");
2638 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2639 " (<offset> is 00-ff, <value> is 0-255)\n");
2640#endif
2641 return len;
2642}
2643
2644static int ecdump_write(char *buf)
2645{
2646 char *cmd;
2647 int i, v;
2648
2649 while ((cmd = next_cmd(&buf))) {
2650 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2651 /* i and v set */
2652 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2653 /* i and v set */
2654 } else
2655 return -EINVAL;
2656 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2657 if (!acpi_ec_write(i, v))
2658 return -EIO;
2659 } else
2660 return -EINVAL;
2661 }
2662
2663 return 0;
2664}
2665
2666static struct ibm_struct ecdump_driver_data = {
2667 .name = "ecdump",
2668 .read = ecdump_read,
2669 .write = ecdump_write,
2670 .flags.experimental = 1,
2671};
2672
2673/*************************************************************************
2674 * Backlight/brightness subdriver
2675 */
2676
2677static struct backlight_device *ibm_backlight_device = NULL;
2678
2679static struct backlight_ops ibm_backlight_data = {
2680 .get_brightness = brightness_get,
2681 .update_status = brightness_update_status,
2682};
2683
2684static int __init brightness_init(struct ibm_init_struct *iibm)
2685{
2686 int b;
2687
2688 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2689
2690 b = brightness_get(NULL);
2691 if (b < 0)
2692 return b;
2693
2694 ibm_backlight_device = backlight_device_register(
2695 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
2696 &ibm_backlight_data);
2697 if (IS_ERR(ibm_backlight_device)) {
2698 printk(IBM_ERR "Could not register backlight device\n");
2699 return PTR_ERR(ibm_backlight_device);
2700 }
2701 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
2702
2703 ibm_backlight_device->props.max_brightness = 7;
2704 ibm_backlight_device->props.brightness = b;
2705 backlight_update_status(ibm_backlight_device);
2706
2707 return 0;
2708}
2709
2710static void brightness_exit(void)
2711{
2712 if (ibm_backlight_device) {
2713 vdbg_printk(TPACPI_DBG_EXIT,
2714 "calling backlight_device_unregister()\n");
2715 backlight_device_unregister(ibm_backlight_device);
2716 ibm_backlight_device = NULL;
2717 }
2718}
2719
2720static int brightness_update_status(struct backlight_device *bd)
2721{
2722 return brightness_set(
2723 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
2724 bd->props.power == FB_BLANK_UNBLANK) ?
2725 bd->props.brightness : 0);
2726}
2727
2728static int brightness_get(struct backlight_device *bd)
2729{
2730 u8 level;
2731 if (!acpi_ec_read(brightness_offset, &level))
2732 return -EIO;
2733
2734 level &= 0x7;
2735
2736 return level;
2737}
2738
2739static int brightness_set(int value)
2740{
2741 int cmos_cmd, inc, i;
2742 int current_value = brightness_get(NULL);
2743
2744 value &= 7;
2745
2746 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
2747 inc = value > current_value ? 1 : -1;
2748 for (i = current_value; i != value; i += inc) {
2749 if (issue_thinkpad_cmos_command(cmos_cmd))
2750 return -EIO;
2751 if (!acpi_ec_write(brightness_offset, i + inc))
2752 return -EIO;
2753 }
2754
2755 return 0;
2756}
2757
2758static int brightness_read(char *p)
2759{
2760 int len = 0;
2761 int level;
2762
2763 if ((level = brightness_get(NULL)) < 0) {
2764 len += sprintf(p + len, "level:\t\tunreadable\n");
2765 } else {
2766 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
2767 len += sprintf(p + len, "commands:\tup, down\n");
2768 len += sprintf(p + len, "commands:\tlevel <level>"
2769 " (<level> is 0-7)\n");
2770 }
2771
2772 return len;
2773}
2774
2775static int brightness_write(char *buf)
2776{
2777 int level;
2778 int new_level;
2779 char *cmd;
2780
2781 while ((cmd = next_cmd(&buf))) {
2782 if ((level = brightness_get(NULL)) < 0)
2783 return level;
2784 level &= 7;
2785
2786 if (strlencmp(cmd, "up") == 0) {
2787 new_level = level == 7 ? 7 : level + 1;
2788 } else if (strlencmp(cmd, "down") == 0) {
2789 new_level = level == 0 ? 0 : level - 1;
2790 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2791 new_level >= 0 && new_level <= 7) {
2792 /* new_level set */
2793 } else
2794 return -EINVAL;
2795
2796 brightness_set(new_level);
2797 }
2798
2799 return 0;
2800}
2801
2802static struct ibm_struct brightness_driver_data = {
2803 .name = "brightness",
2804 .read = brightness_read,
2805 .write = brightness_write,
2806 .exit = brightness_exit,
2807};
2808
2809/*************************************************************************
2810 * Volume subdriver
2811 */
2812
2813static int volume_read(char *p)
2814{
2815 int len = 0;
2816 u8 level;
2817
2818 if (!acpi_ec_read(volume_offset, &level)) {
2819 len += sprintf(p + len, "level:\t\tunreadable\n");
2820 } else {
2821 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
2822 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
2823 len += sprintf(p + len, "commands:\tup, down, mute\n");
2824 len += sprintf(p + len, "commands:\tlevel <level>"
2825 " (<level> is 0-15)\n");
2826 }
2827
2828 return len;
2829}
2830
2831static int volume_write(char *buf)
2832{
2833 int cmos_cmd, inc, i;
2834 u8 level, mute;
2835 int new_level, new_mute;
2836 char *cmd;
2837
2838 while ((cmd = next_cmd(&buf))) {
2839 if (!acpi_ec_read(volume_offset, &level))
2840 return -EIO;
2841 new_mute = mute = level & 0x40;
2842 new_level = level = level & 0xf;
2843
2844 if (strlencmp(cmd, "up") == 0) {
2845 if (mute)
2846 new_mute = 0;
2847 else
2848 new_level = level == 15 ? 15 : level + 1;
2849 } else if (strlencmp(cmd, "down") == 0) {
2850 if (mute)
2851 new_mute = 0;
2852 else
2853 new_level = level == 0 ? 0 : level - 1;
2854 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2855 new_level >= 0 && new_level <= 15) {
2856 /* new_level set */
2857 } else if (strlencmp(cmd, "mute") == 0) {
2858 new_mute = 0x40;
2859 } else
2860 return -EINVAL;
2861
2862 if (new_level != level) { /* mute doesn't change */
2863 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
2864 inc = new_level > level ? 1 : -1;
2865
2866 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
2867 !acpi_ec_write(volume_offset, level)))
2868 return -EIO;
2869
2870 for (i = level; i != new_level; i += inc)
2871 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2872 !acpi_ec_write(volume_offset, i + inc))
2873 return -EIO;
2874
2875 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
2876 !acpi_ec_write(volume_offset,
2877 new_level + mute)))
2878 return -EIO;
2879 }
2880
2881 if (new_mute != mute) { /* level doesn't change */
2882 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
2883
2884 if (issue_thinkpad_cmos_command(cmos_cmd) ||
2885 !acpi_ec_write(volume_offset, level + new_mute))
2886 return -EIO;
2887 }
2888 }
2889
2890 return 0;
2891}
2892
2893static struct ibm_struct volume_driver_data = {
2894 .name = "volume",
2895 .read = volume_read,
2896 .write = volume_write,
2897};
2898
2899/*************************************************************************
2900 * Fan subdriver
2901 */
2902
2903/*
2904 * FAN ACCESS MODES
2905 *
2906 * TPACPI_FAN_RD_ACPI_GFAN:
2907 * ACPI GFAN method: returns fan level
2908 *
2909 * see TPACPI_FAN_WR_ACPI_SFAN
2910 * EC 0x2f (HFSP) not available if GFAN exists
2911 *
2912 * TPACPI_FAN_WR_ACPI_SFAN:
2913 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2914 *
2915 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2916 * it for writing.
2917 *
2918 * TPACPI_FAN_WR_TPEC:
2919 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2920 * Supported on almost all ThinkPads
2921 *
2922 * Fan speed changes of any sort (including those caused by the
2923 * disengaged mode) are usually done slowly by the firmware as the
2924 * maximum ammount of fan duty cycle change per second seems to be
2925 * limited.
2926 *
2927 * Reading is not available if GFAN exists.
2928 * Writing is not available if SFAN exists.
2929 *
2930 * Bits
2931 * 7 automatic mode engaged;
2932 * (default operation mode of the ThinkPad)
2933 * fan level is ignored in this mode.
2934 * 6 full speed mode (takes precedence over bit 7);
2935 * not available on all thinkpads. May disable
2936 * the tachometer while the fan controller ramps up
2937 * the speed (which can take up to a few *minutes*).
2938 * Speeds up fan to 100% duty-cycle, which is far above
2939 * the standard RPM levels. It is not impossible that
2940 * it could cause hardware damage.
2941 * 5-3 unused in some models. Extra bits for fan level
2942 * in others, but still useless as all values above
2943 * 7 map to the same speed as level 7 in these models.
2944 * 2-0 fan level (0..7 usually)
2945 * 0x00 = stop
2946 * 0x07 = max (set when temperatures critical)
2947 * Some ThinkPads may have other levels, see
2948 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2949 *
2950 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2951 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2952 * does so, its initial value is meaningless (0x07).
2953 *
2954 * For firmware bugs, refer to:
2955 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2956 *
2957 * ----
2958 *
2959 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2960 * Main fan tachometer reading (in RPM)
2961 *
2962 * This register is present on all ThinkPads with a new-style EC, and
2963 * it is known not to be present on the A21m/e, and T22, as there is
2964 * something else in offset 0x84 according to the ACPI DSDT. Other
2965 * ThinkPads from this same time period (and earlier) probably lack the
2966 * tachometer as well.
2967 *
2968 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2969 * was never fixed by IBM to report the EC firmware version string
2970 * probably support the tachometer (like the early X models), so
2971 * detecting it is quite hard. We need more data to know for sure.
2972 *
2973 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2974 * might result.
2975 *
2976 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2977 * mode.
2978 *
2979 * For firmware bugs, refer to:
2980 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2981 *
2982 * TPACPI_FAN_WR_ACPI_FANS:
2983 * ThinkPad X31, X40, X41. Not available in the X60.
2984 *
2985 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2986 * high speed. ACPI DSDT seems to map these three speeds to levels
2987 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2988 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2989 *
2990 * The speeds are stored on handles
2991 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2992 *
2993 * There are three default speed sets, acessible as handles:
2994 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2995 *
2996 * ACPI DSDT switches which set is in use depending on various
2997 * factors.
2998 *
2999 * TPACPI_FAN_WR_TPEC is also available and should be used to
3000 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3001 * but the ACPI tables just mention level 7.
3002 */
3003
3004static enum fan_status_access_mode fan_status_access_mode;
3005static enum fan_control_access_mode fan_control_access_mode;
3006static enum fan_control_commands fan_control_commands;
3007
3008static u8 fan_control_initial_status;
3009static u8 fan_control_desired_level;
3010
3011static void fan_watchdog_fire(struct work_struct *ignored);
3012static int fan_watchdog_maxinterval;
3013static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
3014
3015IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
3016IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
3017 "\\FSPD", /* 600e/x, 770e, 770x */
3018 ); /* all others */
3019IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
3020 "JFNS", /* 770x-JL */
3021 ); /* all others */
3022
3023/*
3024 * SYSFS fan layout: hwmon compatible (device)
3025 *
3026 * pwm*_enable:
3027 * 0: "disengaged" mode
3028 * 1: manual mode
3029 * 2: native EC "auto" mode (recommended, hardware default)
3030 *
3031 * pwm*: set speed in manual mode, ignored otherwise.
3032 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3033 * interpolation.
3034 *
3035 * fan*_input: tachometer reading, RPM
3036 *
3037 *
3038 * SYSFS fan layout: extensions
3039 *
3040 * fan_watchdog (driver):
3041 * fan watchdog interval in seconds, 0 disables (default), max 120
3042 */
3043
3044/* sysfs fan pwm1_enable ----------------------------------------------- */
3045static ssize_t fan_pwm1_enable_show(struct device *dev,
3046 struct device_attribute *attr,
3047 char *buf)
3048{
3049 int res, mode;
3050 u8 status;
3051
3052 res = fan_get_status_safe(&status);
3053 if (res)
3054 return res;
3055
3056 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3057 if (status != fan_control_initial_status) {
3058 tp_features.fan_ctrl_status_undef = 0;
3059 } else {
3060 /* Return most likely status. In fact, it
3061 * might be the only possible status */
3062 status = TP_EC_FAN_AUTO;
3063 }
3064 }
3065
3066 if (status & TP_EC_FAN_FULLSPEED) {
3067 mode = 0;
3068 } else if (status & TP_EC_FAN_AUTO) {
3069 mode = 2;
3070 } else
3071 mode = 1;
3072
3073 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
3074}
3075
3076static ssize_t fan_pwm1_enable_store(struct device *dev,
3077 struct device_attribute *attr,
3078 const char *buf, size_t count)
3079{
3080 unsigned long t;
3081 int res, level;
3082
3083 if (parse_strtoul(buf, 2, &t))
3084 return -EINVAL;
3085
3086 switch (t) {
3087 case 0:
3088 level = TP_EC_FAN_FULLSPEED;
3089 break;
3090 case 1:
3091 level = TPACPI_FAN_LAST_LEVEL;
3092 break;
3093 case 2:
3094 level = TP_EC_FAN_AUTO;
3095 break;
3096 case 3:
3097 /* reserved for software-controlled auto mode */
3098 return -ENOSYS;
3099 default:
3100 return -EINVAL;
3101 }
3102
3103 res = fan_set_level_safe(level);
3104 if (res == -ENXIO)
3105 return -EINVAL;
3106 else if (res < 0)
3107 return res;
3108
3109 fan_watchdog_reset();
3110
3111 return count;
3112}
3113
3114static struct device_attribute dev_attr_fan_pwm1_enable =
3115 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
3116 fan_pwm1_enable_show, fan_pwm1_enable_store);
3117
3118/* sysfs fan pwm1 ------------------------------------------------------ */
3119static ssize_t fan_pwm1_show(struct device *dev,
3120 struct device_attribute *attr,
3121 char *buf)
3122{
3123 int res;
3124 u8 status;
3125
3126 res = fan_get_status_safe(&status);
3127 if (res)
3128 return res;
3129
3130 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3131 if (status != fan_control_initial_status) {
3132 tp_features.fan_ctrl_status_undef = 0;
3133 } else {
3134 status = TP_EC_FAN_AUTO;
3135 }
3136 }
3137
3138 if ((status &
3139 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
3140 status = fan_control_desired_level;
3141
3142 if (status > 7)
3143 status = 7;
3144
3145 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
3146}
3147
3148static ssize_t fan_pwm1_store(struct device *dev,
3149 struct device_attribute *attr,
3150 const char *buf, size_t count)
3151{
3152 unsigned long s;
3153 int rc;
3154 u8 status, newlevel;
3155
3156 if (parse_strtoul(buf, 255, &s))
3157 return -EINVAL;
3158
3159 /* scale down from 0-255 to 0-7 */
3160 newlevel = (s >> 5) & 0x07;
3161
3162 rc = mutex_lock_interruptible(&fan_mutex);
3163 if (rc < 0)
3164 return rc;
3165
3166 rc = fan_get_status(&status);
3167 if (!rc && (status &
3168 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3169 rc = fan_set_level(newlevel);
3170 if (rc == -ENXIO)
3171 rc = -EINVAL;
3172 else if (!rc) {
3173 fan_update_desired_level(newlevel);
3174 fan_watchdog_reset();
3175 }
3176 }
3177
3178 mutex_unlock(&fan_mutex);
3179 return (rc)? rc : count;
3180}
3181
3182static struct device_attribute dev_attr_fan_pwm1 =
3183 __ATTR(pwm1, S_IWUSR | S_IRUGO,
3184 fan_pwm1_show, fan_pwm1_store);
3185
3186/* sysfs fan fan1_input ------------------------------------------------ */
3187static ssize_t fan_fan1_input_show(struct device *dev,
3188 struct device_attribute *attr,
3189 char *buf)
3190{
3191 int res;
3192 unsigned int speed;
3193
3194 res = fan_get_speed(&speed);
3195 if (res < 0)
3196 return res;
3197
3198 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
3199}
3200
3201static struct device_attribute dev_attr_fan_fan1_input =
3202 __ATTR(fan1_input, S_IRUGO,
3203 fan_fan1_input_show, NULL);
3204
3205/* sysfs fan fan_watchdog (driver) ------------------------------------- */
3206static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
3207 char *buf)
3208{
3209 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
3210}
3211
3212static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
3213 const char *buf, size_t count)
3214{
3215 unsigned long t;
3216
3217 if (parse_strtoul(buf, 120, &t))
3218 return -EINVAL;
3219
3220 if (!fan_control_allowed)
3221 return -EPERM;
3222
3223 fan_watchdog_maxinterval = t;
3224 fan_watchdog_reset();
3225
3226 return count;
3227}
3228
3229static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
3230 fan_fan_watchdog_show, fan_fan_watchdog_store);
3231
3232/* --------------------------------------------------------------------- */
3233static struct attribute *fan_attributes[] = {
3234 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
3235 &dev_attr_fan_fan1_input.attr,
3236 NULL
3237};
3238
3239static const struct attribute_group fan_attr_group = {
3240 .attrs = fan_attributes,
3241};
3242
3243static int __init fan_init(struct ibm_init_struct *iibm)
3244{
3245 int rc;
3246
3247 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
3248
3249 mutex_init(&fan_mutex);
3250 fan_status_access_mode = TPACPI_FAN_NONE;
3251 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3252 fan_control_commands = 0;
3253 fan_watchdog_maxinterval = 0;
3254 tp_features.fan_ctrl_status_undef = 0;
3255 fan_control_desired_level = 7;
3256
3257 IBM_ACPIHANDLE_INIT(fans);
3258 IBM_ACPIHANDLE_INIT(gfan);
3259 IBM_ACPIHANDLE_INIT(sfan);
3260
3261 if (gfan_handle) {
3262 /* 570, 600e/x, 770e, 770x */
3263 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
3264 } else {
3265 /* all other ThinkPads: note that even old-style
3266 * ThinkPad ECs supports the fan control register */
3267 if (likely(acpi_ec_read(fan_status_offset,
3268 &fan_control_initial_status))) {
3269 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
3270
3271 /* In some ThinkPads, neither the EC nor the ACPI
3272 * DSDT initialize the fan status, and it ends up
3273 * being set to 0x07 when it *could* be either
3274 * 0x07 or 0x80.
3275 *
3276 * Enable for TP-1Y (T43), TP-78 (R51e),
3277 * TP-76 (R52), TP-70 (T43, R52), which are known
3278 * to be buggy. */
3279 if (fan_control_initial_status == 0x07 &&
3280 ibm_thinkpad_ec_found &&
3281 ((ibm_thinkpad_ec_found[0] == '1' &&
3282 ibm_thinkpad_ec_found[1] == 'Y') ||
3283 (ibm_thinkpad_ec_found[0] == '7' &&
3284 (ibm_thinkpad_ec_found[1] == '6' ||
3285 ibm_thinkpad_ec_found[1] == '8' ||
3286 ibm_thinkpad_ec_found[1] == '0'))
3287 )) {
3288 printk(IBM_NOTICE
3289 "fan_init: initial fan status is "
3290 "unknown, assuming it is in auto "
3291 "mode\n");
3292 tp_features.fan_ctrl_status_undef = 1;
3293 }
3294 } else {
3295 printk(IBM_ERR
3296 "ThinkPad ACPI EC access misbehaving, "
3297 "fan status and control unavailable\n");
3298 return 1;
3299 }
3300 }
3301
3302 if (sfan_handle) {
3303 /* 570, 770x-JL */
3304 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
3305 fan_control_commands |=
3306 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
3307 } else {
3308 if (!gfan_handle) {
3309 /* gfan without sfan means no fan control */
3310 /* all other models implement TP EC 0x2f control */
3311
3312 if (fans_handle) {
3313 /* X31, X40, X41 */
3314 fan_control_access_mode =
3315 TPACPI_FAN_WR_ACPI_FANS;
3316 fan_control_commands |=
3317 TPACPI_FAN_CMD_SPEED |
3318 TPACPI_FAN_CMD_LEVEL |
3319 TPACPI_FAN_CMD_ENABLE;
3320 } else {
3321 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
3322 fan_control_commands |=
3323 TPACPI_FAN_CMD_LEVEL |
3324 TPACPI_FAN_CMD_ENABLE;
3325 }
3326 }
3327 }
3328
3329 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
3330 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
3331 fan_control_access_mode != TPACPI_FAN_WR_NONE),
3332 fan_status_access_mode, fan_control_access_mode);
3333
3334 /* fan control master switch */
3335 if (!fan_control_allowed) {
3336 fan_control_access_mode = TPACPI_FAN_WR_NONE;
3337 fan_control_commands = 0;
3338 dbg_printk(TPACPI_DBG_INIT,
3339 "fan control features disabled by parameter\n");
3340 }
3341
3342 /* update fan_control_desired_level */
3343 if (fan_status_access_mode != TPACPI_FAN_NONE)
3344 fan_get_status_safe(NULL);
3345
3346 if (fan_status_access_mode != TPACPI_FAN_NONE ||
3347 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
3348 rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3349 &fan_attr_group);
3350 if (!(rc < 0))
3351 rc = driver_create_file(&tpacpi_pdriver.driver,
3352 &driver_attr_fan_watchdog);
3353 if (rc < 0)
3354 return rc;
3355 return 0;
3356 } else
3357 return 1;
3358}
3359
3360/*
3361 * Call with fan_mutex held
3362 */
3363static void fan_update_desired_level(u8 status)
3364{
3365 if ((status &
3366 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
3367 if (status > 7)
3368 fan_control_desired_level = 7;
3369 else
3370 fan_control_desired_level = status;
3371 }
3372}
3373
3374static int fan_get_status(u8 *status)
3375{
3376 u8 s;
3377
3378 /* TODO:
3379 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3380
3381 switch (fan_status_access_mode) {
3382 case TPACPI_FAN_RD_ACPI_GFAN:
3383 /* 570, 600e/x, 770e, 770x */
3384
3385 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
3386 return -EIO;
3387
3388 if (likely(status))
3389 *status = s & 0x07;
3390
3391 break;
3392
3393 case TPACPI_FAN_RD_TPEC:
3394 /* all except 570, 600e/x, 770e, 770x */
3395 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
3396 return -EIO;
3397
3398 if (likely(status))
3399 *status = s;
3400
3401 break;
3402
3403 default:
3404 return -ENXIO;
3405 }
3406
3407 return 0;
3408}
3409
3410static int fan_get_status_safe(u8 *status)
3411{
3412 int rc;
3413 u8 s;
3414
3415 rc = mutex_lock_interruptible(&fan_mutex);
3416 if (rc < 0)
3417 return rc;
3418 rc = fan_get_status(&s);
3419 if (!rc)
3420 fan_update_desired_level(s);
3421 mutex_unlock(&fan_mutex);
3422
3423 if (status)
3424 *status = s;
3425
3426 return rc;
3427}
3428
3429static void fan_exit(void)
3430{
3431 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
3432
3433 /* FIXME: can we really do this unconditionally? */
3434 sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
3435 driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
3436
3437 cancel_delayed_work(&fan_watchdog_task);
3438 flush_scheduled_work();
3439}
3440
3441static int fan_get_speed(unsigned int *speed)
3442{
3443 u8 hi, lo;
3444
3445 switch (fan_status_access_mode) {
3446 case TPACPI_FAN_RD_TPEC:
3447 /* all except 570, 600e/x, 770e, 770x */
3448 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
3449 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
3450 return -EIO;
3451
3452 if (likely(speed))
3453 *speed = (hi << 8) | lo;
3454
3455 break;
3456
3457 default:
3458 return -ENXIO;
3459 }
3460
3461 return 0;
3462}
3463
3464static void fan_watchdog_fire(struct work_struct *ignored)
3465{
3466 int rc;
3467
3468 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
3469 rc = fan_set_enable();
3470 if (rc < 0) {
3471 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
3472 "will try again later...\n", -rc);
3473 /* reschedule for later */
3474 fan_watchdog_reset();
3475 }
3476}
3477
3478static void fan_watchdog_reset(void)
3479{
3480 static int fan_watchdog_active = 0;
3481
3482 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
3483 return;
3484
3485 if (fan_watchdog_active)
3486 cancel_delayed_work(&fan_watchdog_task);
3487
3488 if (fan_watchdog_maxinterval > 0) {
3489 fan_watchdog_active = 1;
3490 if (!schedule_delayed_work(&fan_watchdog_task,
3491 msecs_to_jiffies(fan_watchdog_maxinterval
3492 * 1000))) {
3493 printk(IBM_ERR "failed to schedule the fan watchdog, "
3494 "watchdog will not trigger\n");
3495 }
3496 } else
3497 fan_watchdog_active = 0;
3498}
3499
3500static int fan_set_level(int level)
3501{
3502 if (!fan_control_allowed)
3503 return -EPERM;
3504
3505 switch (fan_control_access_mode) {
3506 case TPACPI_FAN_WR_ACPI_SFAN:
3507 if (level >= 0 && level <= 7) {
3508 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
3509 return -EIO;
3510 } else
3511 return -EINVAL;
3512 break;
3513
3514 case TPACPI_FAN_WR_ACPI_FANS:
3515 case TPACPI_FAN_WR_TPEC:
3516 if ((level != TP_EC_FAN_AUTO) &&
3517 (level != TP_EC_FAN_FULLSPEED) &&
3518 ((level < 0) || (level > 7)))
3519 return -EINVAL;
3520
3521 /* safety net should the EC not support AUTO
3522 * or FULLSPEED mode bits and just ignore them */
3523 if (level & TP_EC_FAN_FULLSPEED)
3524 level |= 7; /* safety min speed 7 */
3525 else if (level & TP_EC_FAN_FULLSPEED)
3526 level |= 4; /* safety min speed 4 */
3527
3528 if (!acpi_ec_write(fan_status_offset, level))
3529 return -EIO;
3530 else
3531 tp_features.fan_ctrl_status_undef = 0;
3532 break;
3533
3534 default:
3535 return -ENXIO;
3536 }
3537 return 0;
3538}
3539
3540static int fan_set_level_safe(int level)
3541{
3542 int rc;
3543
3544 if (!fan_control_allowed)
3545 return -EPERM;
3546
3547 rc = mutex_lock_interruptible(&fan_mutex);
3548 if (rc < 0)
3549 return rc;
3550
3551 if (level == TPACPI_FAN_LAST_LEVEL)
3552 level = fan_control_desired_level;
3553
3554 rc = fan_set_level(level);
3555 if (!rc)
3556 fan_update_desired_level(level);
3557
3558 mutex_unlock(&fan_mutex);
3559 return rc;
3560}
3561
3562static int fan_set_enable(void)
3563{
3564 u8 s;
3565 int rc;
3566
3567 if (!fan_control_allowed)
3568 return -EPERM;
3569
3570 rc = mutex_lock_interruptible(&fan_mutex);
3571 if (rc < 0)
3572 return rc;
3573
3574 switch (fan_control_access_mode) {
3575 case TPACPI_FAN_WR_ACPI_FANS:
3576 case TPACPI_FAN_WR_TPEC:
3577 rc = fan_get_status(&s);
3578 if (rc < 0)
3579 break;
3580
3581 /* Don't go out of emergency fan mode */
3582 if (s != 7) {
3583 s &= 0x07;
3584 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
3585 }
3586
3587 if (!acpi_ec_write(fan_status_offset, s))
3588 rc = -EIO;
3589 else {
3590 tp_features.fan_ctrl_status_undef = 0;
3591 rc = 0;
3592 }
3593 break;
3594
3595 case TPACPI_FAN_WR_ACPI_SFAN:
3596 rc = fan_get_status(&s);
3597 if (rc < 0)
3598 break;
3599
3600 s &= 0x07;
3601
3602 /* Set fan to at least level 4 */
3603 s |= 4;
3604
3605 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
3606 rc= -EIO;
3607 else
3608 rc = 0;
3609 break;
3610
3611 default:
3612 rc = -ENXIO;
3613 }
3614
3615 mutex_unlock(&fan_mutex);
3616 return rc;
3617}
3618
3619static int fan_set_disable(void)
3620{
3621 int rc;
3622
3623 if (!fan_control_allowed)
3624 return -EPERM;
3625
3626 rc = mutex_lock_interruptible(&fan_mutex);
3627 if (rc < 0)
3628 return rc;
3629
3630 rc = 0;
3631 switch (fan_control_access_mode) {
3632 case TPACPI_FAN_WR_ACPI_FANS:
3633 case TPACPI_FAN_WR_TPEC:
3634 if (!acpi_ec_write(fan_status_offset, 0x00))
3635 rc = -EIO;
3636 else {
3637 fan_control_desired_level = 0;
3638 tp_features.fan_ctrl_status_undef = 0;
3639 }
3640 break;
3641
3642 case TPACPI_FAN_WR_ACPI_SFAN:
3643 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
3644 rc = -EIO;
3645 else
3646 fan_control_desired_level = 0;
3647 break;
3648
3649 default:
3650 rc = -ENXIO;
3651 }
3652
3653
3654 mutex_unlock(&fan_mutex);
3655 return rc;
3656}
3657
3658static int fan_set_speed(int speed)
3659{
3660 int rc;
3661
3662 if (!fan_control_allowed)
3663 return -EPERM;
3664
3665 rc = mutex_lock_interruptible(&fan_mutex);
3666 if (rc < 0)
3667 return rc;
3668
3669 rc = 0;
3670 switch (fan_control_access_mode) {
3671 case TPACPI_FAN_WR_ACPI_FANS:
3672 if (speed >= 0 && speed <= 65535) {
3673 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
3674 speed, speed, speed))
3675 rc = -EIO;
3676 } else
3677 rc = -EINVAL;
3678 break;
3679
3680 default:
3681 rc = -ENXIO;
3682 }
3683
3684 mutex_unlock(&fan_mutex);
3685 return rc;
3686}
3687
3688static int fan_read(char *p)
3689{
3690 int len = 0;
3691 int rc;
3692 u8 status;
3693 unsigned int speed = 0;
3694
3695 switch (fan_status_access_mode) {
3696 case TPACPI_FAN_RD_ACPI_GFAN:
3697 /* 570, 600e/x, 770e, 770x */
3698 if ((rc = fan_get_status_safe(&status)) < 0)
3699 return rc;
3700
3701 len += sprintf(p + len, "status:\t\t%s\n"
3702 "level:\t\t%d\n",
3703 (status != 0) ? "enabled" : "disabled", status);
3704 break;
3705
3706 case TPACPI_FAN_RD_TPEC:
3707 /* all except 570, 600e/x, 770e, 770x */
3708 if ((rc = fan_get_status_safe(&status)) < 0)
3709 return rc;
3710
3711 if (unlikely(tp_features.fan_ctrl_status_undef)) {
3712 if (status != fan_control_initial_status)
3713 tp_features.fan_ctrl_status_undef = 0;
3714 else
3715 /* Return most likely status. In fact, it
3716 * might be the only possible status */
3717 status = TP_EC_FAN_AUTO;
3718 }
3719
3720 len += sprintf(p + len, "status:\t\t%s\n",
3721 (status != 0) ? "enabled" : "disabled");
3722
3723 if ((rc = fan_get_speed(&speed)) < 0)
3724 return rc;
3725
3726 len += sprintf(p + len, "speed:\t\t%d\n", speed);
3727
3728 if (status & TP_EC_FAN_FULLSPEED)
3729 /* Disengaged mode takes precedence */
3730 len += sprintf(p + len, "level:\t\tdisengaged\n");
3731 else if (status & TP_EC_FAN_AUTO)
3732 len += sprintf(p + len, "level:\t\tauto\n");
3733 else
3734 len += sprintf(p + len, "level:\t\t%d\n", status);
3735 break;
3736
3737 case TPACPI_FAN_NONE:
3738 default:
3739 len += sprintf(p + len, "status:\t\tnot supported\n");
3740 }
3741
3742 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
3743 len += sprintf(p + len, "commands:\tlevel <level>");
3744
3745 switch (fan_control_access_mode) {
3746 case TPACPI_FAN_WR_ACPI_SFAN:
3747 len += sprintf(p + len, " (<level> is 0-7)\n");
3748 break;
3749
3750 default:
3751 len += sprintf(p + len, " (<level> is 0-7, "
3752 "auto, disengaged, full-speed)\n");
3753 break;
3754 }
3755 }
3756
3757 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
3758 len += sprintf(p + len, "commands:\tenable, disable\n"
3759 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3760 "1-120 (seconds))\n");
3761
3762 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
3763 len += sprintf(p + len, "commands:\tspeed <speed>"
3764 " (<speed> is 0-65535)\n");
3765
3766 return len;
3767}
3768
3769static int fan_write_cmd_level(const char *cmd, int *rc)
3770{
3771 int level;
3772
3773 if (strlencmp(cmd, "level auto") == 0)
3774 level = TP_EC_FAN_AUTO;
3775 else if ((strlencmp(cmd, "level disengaged") == 0) |
3776 (strlencmp(cmd, "level full-speed") == 0))
3777 level = TP_EC_FAN_FULLSPEED;
3778 else if (sscanf(cmd, "level %d", &level) != 1)
3779 return 0;
3780
3781 if ((*rc = fan_set_level_safe(level)) == -ENXIO)
3782 printk(IBM_ERR "level command accepted for unsupported "
3783 "access mode %d", fan_control_access_mode);
3784
3785 return 1;
3786}
3787
3788static int fan_write_cmd_enable(const char *cmd, int *rc)
3789{
3790 if (strlencmp(cmd, "enable") != 0)
3791 return 0;
3792
3793 if ((*rc = fan_set_enable()) == -ENXIO)
3794 printk(IBM_ERR "enable command accepted for unsupported "
3795 "access mode %d", fan_control_access_mode);
3796
3797 return 1;
3798}
3799
3800static int fan_write_cmd_disable(const char *cmd, int *rc)
3801{
3802 if (strlencmp(cmd, "disable") != 0)
3803 return 0;
3804
3805 if ((*rc = fan_set_disable()) == -ENXIO)
3806 printk(IBM_ERR "disable command accepted for unsupported "
3807 "access mode %d", fan_control_access_mode);
3808
3809 return 1;
3810}
3811
3812static int fan_write_cmd_speed(const char *cmd, int *rc)
3813{
3814 int speed;
3815
3816 /* TODO:
3817 * Support speed <low> <medium> <high> ? */
3818
3819 if (sscanf(cmd, "speed %d", &speed) != 1)
3820 return 0;
3821
3822 if ((*rc = fan_set_speed(speed)) == -ENXIO)
3823 printk(IBM_ERR "speed command accepted for unsupported "
3824 "access mode %d", fan_control_access_mode);
3825
3826 return 1;
3827}
3828
3829static int fan_write_cmd_watchdog(const char *cmd, int *rc)
3830{
3831 int interval;
3832
3833 if (sscanf(cmd, "watchdog %d", &interval) != 1)
3834 return 0;
3835
3836 if (interval < 0 || interval > 120)
3837 *rc = -EINVAL;
3838 else
3839 fan_watchdog_maxinterval = interval;
3840
3841 return 1;
3842}
3843
3844static int fan_write(char *buf)
3845{
3846 char *cmd;
3847 int rc = 0;
3848
3849 while (!rc && (cmd = next_cmd(&buf))) {
3850 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
3851 fan_write_cmd_level(cmd, &rc)) &&
3852 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
3853 (fan_write_cmd_enable(cmd, &rc) ||
3854 fan_write_cmd_disable(cmd, &rc) ||
3855 fan_write_cmd_watchdog(cmd, &rc))) &&
3856 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
3857 fan_write_cmd_speed(cmd, &rc))
3858 )
3859 rc = -EINVAL;
3860 else if (!rc)
3861 fan_watchdog_reset();
3862 }
3863
3864 return rc;
3865}
3866
3867static struct ibm_struct fan_driver_data = {
3868 .name = "fan",
3869 .read = fan_read,
3870 .write = fan_write,
3871 .exit = fan_exit,
3872};
3873
3874/****************************************************************************
3875 ****************************************************************************
3876 *
3877 * Infrastructure
3878 *
3879 ****************************************************************************
3880 ****************************************************************************/
3881
3882/* /proc support */
3883static struct proc_dir_entry *proc_dir = NULL;
3884
3885/* Subdriver registry */
3886static LIST_HEAD(tpacpi_all_drivers);
3887
3888
3889/*
3890 * Module and infrastructure proble, init and exit handling
3891 */
3892
3893#ifdef CONFIG_THINKPAD_ACPI_DEBUG
3894static const char * __init str_supported(int is_supported)
3895{
3896 static char text_unsupported[] __initdata = "not supported";
3897
3898 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
3899}
3900#endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3901
3902static int __init ibm_init(struct ibm_init_struct *iibm)
3903{
3904 int ret;
3905 struct ibm_struct *ibm = iibm->data;
3906 struct proc_dir_entry *entry;
3907
3908 BUG_ON(ibm == NULL);
3909
3910 INIT_LIST_HEAD(&ibm->all_drivers);
3911
3912 if (ibm->flags.experimental && !experimental)
3913 return 0;
3914
3915 dbg_printk(TPACPI_DBG_INIT,
3916 "probing for %s\n", ibm->name);
3917
3918 if (iibm->init) {
3919 ret = iibm->init(iibm);
3920 if (ret > 0)
3921 return 0; /* probe failed */
3922 if (ret)
3923 return ret;
3924
3925 ibm->flags.init_called = 1;
3926 }
3927
3928 if (ibm->acpi) {
3929 if (ibm->acpi->hid) {
3930 ret = register_tpacpi_subdriver(ibm);
3931 if (ret)
3932 goto err_out;
3933 }
3934
3935 if (ibm->acpi->notify) {
3936 ret = setup_acpi_notify(ibm);
3937 if (ret == -ENODEV) {
3938 printk(IBM_NOTICE "disabling subdriver %s\n",
3939 ibm->name);
3940 ret = 0;
3941 goto err_out;
3942 }
3943 if (ret < 0)
3944 goto err_out;
3945 }
3946 }
3947
3948 dbg_printk(TPACPI_DBG_INIT,
3949 "%s installed\n", ibm->name);
3950
3951 if (ibm->read) {
3952 entry = create_proc_entry(ibm->name,
3953 S_IFREG | S_IRUGO | S_IWUSR,
3954 proc_dir);
3955 if (!entry) {
3956 printk(IBM_ERR "unable to create proc entry %s\n",
3957 ibm->name);
3958 ret = -ENODEV;
3959 goto err_out;
3960 }
3961 entry->owner = THIS_MODULE;
3962 entry->data = ibm;
3963 entry->read_proc = &dispatch_procfs_read;
3964 if (ibm->write)
3965 entry->write_proc = &dispatch_procfs_write;
3966 ibm->flags.proc_created = 1;
3967 }
3968
3969 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
3970
3971 return 0;
3972
3973err_out:
3974 dbg_printk(TPACPI_DBG_INIT,
3975 "%s: at error exit path with result %d\n",
3976 ibm->name, ret);
3977
3978 ibm_exit(ibm);
3979 return (ret < 0)? ret : 0;
3980}
3981
3982static void ibm_exit(struct ibm_struct *ibm)
3983{
3984 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
3985
3986 list_del_init(&ibm->all_drivers);
3987
3988 if (ibm->flags.acpi_notify_installed) {
3989 dbg_printk(TPACPI_DBG_EXIT,
3990 "%s: acpi_remove_notify_handler\n", ibm->name);
3991 BUG_ON(!ibm->acpi);
3992 acpi_remove_notify_handler(*ibm->acpi->handle,
3993 ibm->acpi->type,
3994 dispatch_acpi_notify);
3995 ibm->flags.acpi_notify_installed = 0;
3996 ibm->flags.acpi_notify_installed = 0;
3997 }
3998
3999 if (ibm->flags.proc_created) {
4000 dbg_printk(TPACPI_DBG_EXIT,
4001 "%s: remove_proc_entry\n", ibm->name);
4002 remove_proc_entry(ibm->name, proc_dir);
4003 ibm->flags.proc_created = 0;
4004 }
4005
4006 if (ibm->flags.acpi_driver_registered) {
4007 dbg_printk(TPACPI_DBG_EXIT,
4008 "%s: acpi_bus_unregister_driver\n", ibm->name);
4009 BUG_ON(!ibm->acpi);
4010 acpi_bus_unregister_driver(ibm->acpi->driver);
4011 kfree(ibm->acpi->driver);
4012 ibm->acpi->driver = NULL;
4013 ibm->flags.acpi_driver_registered = 0;
4014 }
4015
4016 if (ibm->flags.init_called && ibm->exit) {
4017 ibm->exit();
4018 ibm->flags.init_called = 0;
4019 }
4020
4021 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
4022}
4023
4024/* Probing */
4025
4026static char *ibm_thinkpad_ec_found = NULL;
4027
4028static char* __init check_dmi_for_ec(void)
4029{
4030 struct dmi_device *dev = NULL;
4031 char ec_fw_string[18];
4032
4033 /*
4034 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4035 * X32 or newer, all Z series; Some models must have an
4036 * up-to-date BIOS or they will not be detected.
4037 *
4038 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4039 */
4040 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
4041 if (sscanf(dev->name,
4042 "IBM ThinkPad Embedded Controller -[%17c",
4043 ec_fw_string) == 1) {
4044 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
4045 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
4046 return kstrdup(ec_fw_string, GFP_KERNEL);
4047 }
4048 }
4049 return NULL;
4050}
4051
4052static int __init probe_for_thinkpad(void)
4053{
4054 int is_thinkpad;
4055
4056 if (acpi_disabled)
4057 return -ENODEV;
4058
4059 /*
4060 * Non-ancient models have better DMI tagging, but very old models
4061 * don't.
4062 */
4063 is_thinkpad = dmi_name_in_vendors("ThinkPad");
4064
4065 /* ec is required because many other handles are relative to it */
4066 IBM_ACPIHANDLE_INIT(ec);
4067 if (!ec_handle) {
4068 if (is_thinkpad)
4069 printk(IBM_ERR
4070 "Not yet supported ThinkPad detected!\n");
4071 return -ENODEV;
4072 }
4073
4074 /*
4075 * Risks a regression on very old machines, but reduces potential
4076 * false positives a damn great deal
4077 */
4078 if (!is_thinkpad)
4079 is_thinkpad = dmi_name_in_vendors("IBM");
4080
4081 if (!is_thinkpad && !force_load)
4082 return -ENODEV;
4083
4084 return 0;
4085}
4086
4087
4088/* Module init, exit, parameters */
4089
4090static struct ibm_init_struct ibms_init[] __initdata = {
4091 {
4092 .init = thinkpad_acpi_driver_init,
4093 .data = &thinkpad_acpi_driver_data,
4094 },
4095 {
4096 .init = hotkey_init,
4097 .data = &hotkey_driver_data,
4098 },
4099 {
4100 .init = bluetooth_init,
4101 .data = &bluetooth_driver_data,
4102 },
4103 {
4104 .init = wan_init,
4105 .data = &wan_driver_data,
4106 },
4107 {
4108 .init = video_init,
4109 .data = &video_driver_data,
4110 },
4111 {
4112 .init = light_init,
4113 .data = &light_driver_data,
4114 },
4115#ifdef CONFIG_THINKPAD_ACPI_DOCK
4116 {
4117 .init = dock_init,
4118 .data = &dock_driver_data[0],
4119 },
4120 {
4121 .init = dock_init2,
4122 .data = &dock_driver_data[1],
4123 },
4124#endif
4125#ifdef CONFIG_THINKPAD_ACPI_BAY
4126 {
4127 .init = bay_init,
4128 .data = &bay_driver_data,
4129 },
4130#endif
4131 {
4132 .init = cmos_init,
4133 .data = &cmos_driver_data,
4134 },
4135 {
4136 .init = led_init,
4137 .data = &led_driver_data,
4138 },
4139 {
4140 .init = beep_init,
4141 .data = &beep_driver_data,
4142 },
4143 {
4144 .init = thermal_init,
4145 .data = &thermal_driver_data,
4146 },
4147 {
4148 .data = &ecdump_driver_data,
4149 },
4150 {
4151 .init = brightness_init,
4152 .data = &brightness_driver_data,
4153 },
4154 {
4155 .data = &volume_driver_data,
4156 },
4157 {
4158 .init = fan_init,
4159 .data = &fan_driver_data,
4160 },
4161};
4162
4163static int __init set_ibm_param(const char *val, struct kernel_param *kp)
4164{
4165 unsigned int i;
4166 struct ibm_struct *ibm;
4167
4168 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4169 ibm = ibms_init[i].data;
4170 BUG_ON(ibm == NULL);
4171
4172 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
4173 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
4174 return -ENOSPC;
4175 strcpy(ibms_init[i].param, val);
4176 strcat(ibms_init[i].param, ",");
4177 return 0;
4178 }
4179 }
4180
4181 return -EINVAL;
4182}
4183
4184static int experimental;
4185module_param(experimental, int, 0);
4186
4187static u32 dbg_level;
4188module_param_named(debug, dbg_level, uint, 0);
4189
4190static int force_load;
4191module_param(force_load, int, 0);
4192
4193static int fan_control_allowed;
4194module_param_named(fan_control, fan_control_allowed, int, 0);
4195
4196#define IBM_PARAM(feature) \
4197 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4198
4199IBM_PARAM(hotkey);
4200IBM_PARAM(bluetooth);
4201IBM_PARAM(video);
4202IBM_PARAM(light);
4203#ifdef CONFIG_THINKPAD_ACPI_DOCK
4204IBM_PARAM(dock);
4205#endif
4206#ifdef CONFIG_THINKPAD_ACPI_BAY
4207IBM_PARAM(bay);
4208#endif /* CONFIG_THINKPAD_ACPI_BAY */
4209IBM_PARAM(cmos);
4210IBM_PARAM(led);
4211IBM_PARAM(beep);
4212IBM_PARAM(ecdump);
4213IBM_PARAM(brightness);
4214IBM_PARAM(volume);
4215IBM_PARAM(fan);
4216
4217static int __init thinkpad_acpi_module_init(void)
4218{
4219 int ret, i;
4220
4221 /* Driver-level probe */
4222 ret = probe_for_thinkpad();
4223 if (ret)
4224 return ret;
4225
4226 /* Driver initialization */
4227 ibm_thinkpad_ec_found = check_dmi_for_ec();
4228 IBM_ACPIHANDLE_INIT(ecrd);
4229 IBM_ACPIHANDLE_INIT(ecwr);
4230
4231 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
4232 if (!proc_dir) {
4233 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
4234 thinkpad_acpi_module_exit();
4235 return -ENODEV;
4236 }
4237 proc_dir->owner = THIS_MODULE;
4238
4239 ret = platform_driver_register(&tpacpi_pdriver);
4240 if (ret) {
4241 printk(IBM_ERR "unable to register platform driver\n");
4242 thinkpad_acpi_module_exit();
4243 return ret;
4244 }
4245 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
4246 if (ret) {
4247 printk(IBM_ERR "unable to create sysfs driver attributes\n");
4248 thinkpad_acpi_module_exit();
4249 return ret;
4250 }
4251
4252
4253 /* Device initialization */
4254 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
4255 NULL, 0);
4256 if (IS_ERR(tpacpi_pdev)) {
4257 ret = PTR_ERR(tpacpi_pdev);
4258 tpacpi_pdev = NULL;
4259 printk(IBM_ERR "unable to register platform device\n");
4260 thinkpad_acpi_module_exit();
4261 return ret;
4262 }
4263 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
4264 if (IS_ERR(tpacpi_hwmon)) {
4265 ret = PTR_ERR(tpacpi_hwmon);
4266 tpacpi_hwmon = NULL;
4267 printk(IBM_ERR "unable to register hwmon device\n");
4268 thinkpad_acpi_module_exit();
4269 return ret;
4270 }
4271 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4272 ret = ibm_init(&ibms_init[i]);
4273 if (ret >= 0 && *ibms_init[i].param)
4274 ret = ibms_init[i].data->write(ibms_init[i].param);
4275 if (ret < 0) {
4276 thinkpad_acpi_module_exit();
4277 return ret;
4278 }
4279 }
4280
4281 return 0;
4282}
4283
4284static void thinkpad_acpi_module_exit(void)
4285{
4286 struct ibm_struct *ibm, *itmp;
4287
4288 list_for_each_entry_safe_reverse(ibm, itmp,
4289 &tpacpi_all_drivers,
4290 all_drivers) {
4291 ibm_exit(ibm);
4292 }
4293
4294 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
4295
4296 if (tpacpi_hwmon)
4297 hwmon_device_unregister(tpacpi_hwmon);
4298
4299 if (tpacpi_pdev)
4300 platform_device_unregister(tpacpi_pdev);
4301
4302 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
4303 platform_driver_unregister(&tpacpi_pdriver);
4304
4305 if (proc_dir)
4306 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
4307
4308 kfree(ibm_thinkpad_ec_found);
4309}
4310
4311module_init(thinkpad_acpi_module_init);
4312module_exit(thinkpad_acpi_module_exit);
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
new file mode 100644
index 000000000000..440145a02617
--- /dev/null
+++ b/drivers/misc/thinkpad_acpi.h
@@ -0,0 +1,572 @@
1/*
2 * thinkpad_acpi.h - ThinkPad ACPI Extras
3 *
4 *
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24#ifndef __THINKPAD_ACPI_H__
25#define __THINKPAD_ACPI_H__
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/string.h>
32#include <linux/list.h>
33#include <linux/mutex.h>
34
35#include <linux/proc_fs.h>
36#include <linux/sysfs.h>
37#include <linux/backlight.h>
38#include <linux/fb.h>
39#include <linux/platform_device.h>
40#include <linux/hwmon.h>
41#include <linux/hwmon-sysfs.h>
42#include <asm/uaccess.h>
43
44#include <linux/dmi.h>
45#include <linux/jiffies.h>
46#include <linux/workqueue.h>
47
48#include <acpi/acpi_drivers.h>
49#include <acpi/acnamesp.h>
50
51
52/****************************************************************************
53 * Main driver
54 */
55
56#define IBM_NAME "thinkpad"
57#define IBM_DESC "ThinkPad ACPI Extras"
58#define IBM_FILE "thinkpad_acpi"
59#define IBM_URL "http://ibm-acpi.sf.net/"
60#define IBM_MAIL "ibm-acpi-devel@lists.sourceforge.net"
61
62#define IBM_PROC_DIR "ibm"
63#define IBM_ACPI_EVENT_PREFIX "ibm"
64#define IBM_DRVR_NAME IBM_FILE
65
66#define IBM_LOG IBM_FILE ": "
67#define IBM_ERR KERN_ERR IBM_LOG
68#define IBM_NOTICE KERN_NOTICE IBM_LOG
69#define IBM_INFO KERN_INFO IBM_LOG
70#define IBM_DEBUG KERN_DEBUG IBM_LOG
71
72#define IBM_MAX_ACPI_ARGS 3
73
74/* ThinkPad CMOS commands */
75#define TP_CMOS_VOLUME_DOWN 0
76#define TP_CMOS_VOLUME_UP 1
77#define TP_CMOS_VOLUME_MUTE 2
78#define TP_CMOS_BRIGHTNESS_UP 4
79#define TP_CMOS_BRIGHTNESS_DOWN 5
80
81#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
82#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
83#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
84
85/* Debugging */
86#define TPACPI_DBG_ALL 0xffff
87#define TPACPI_DBG_ALL 0xffff
88#define TPACPI_DBG_INIT 0x0001
89#define TPACPI_DBG_EXIT 0x0002
90#define dbg_printk(a_dbg_level, format, arg...) \
91 do { if (dbg_level & a_dbg_level) \
92 printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
93#ifdef CONFIG_THINKPAD_ACPI_DEBUG
94#define vdbg_printk(a_dbg_level, format, arg...) \
95 dbg_printk(a_dbg_level, format, ## arg)
96static const char *str_supported(int is_supported);
97#else
98#define vdbg_printk(a_dbg_level, format, arg...)
99#endif
100
101/* ACPI HIDs */
102#define IBM_HKEY_HID "IBM0068"
103#define IBM_PCI_HID "PNP0A03"
104
105/* ACPI helpers */
106static int __must_check acpi_evalf(acpi_handle handle,
107 void *res, char *method, char *fmt, ...);
108static int __must_check acpi_ec_read(int i, u8 * p);
109static int __must_check acpi_ec_write(int i, u8 v);
110static int __must_check _sta(acpi_handle handle);
111
112/* ACPI handles */
113static acpi_handle root_handle; /* root namespace */
114static acpi_handle ec_handle; /* EC */
115static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
116static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
117
118static void drv_acpi_handle_init(char *name,
119 acpi_handle *handle, acpi_handle parent,
120 char **paths, int num_paths, char **path);
121#define IBM_ACPIHANDLE_INIT(object) \
122 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
123 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
124
125/* ThinkPad ACPI helpers */
126static int issue_thinkpad_cmos_command(int cmos_cmd);
127
128/* procfs support */
129static struct proc_dir_entry *proc_dir;
130
131/* procfs helpers */
132static int dispatch_procfs_read(char *page, char **start, off_t off,
133 int count, int *eof, void *data);
134static int dispatch_procfs_write(struct file *file,
135 const char __user * userbuf,
136 unsigned long count, void *data);
137static char *next_cmd(char **cmds);
138
139/* sysfs support */
140struct attribute_set {
141 unsigned int members, max_members;
142 struct attribute_group group;
143};
144
145static struct attribute_set *create_attr_set(unsigned int max_members,
146 const char* name);
147#define destroy_attr_set(_set) \
148 kfree(_set);
149static int add_to_attr_set(struct attribute_set* s, struct attribute *attr);
150static int add_many_to_attr_set(struct attribute_set* s,
151 struct attribute **attr,
152 unsigned int count);
153#define register_attr_set_with_sysfs(_attr_set, _kobj) \
154 sysfs_create_group(_kobj, &_attr_set->group)
155static void delete_attr_set(struct attribute_set* s, struct kobject *kobj);
156
157static int parse_strtoul(const char *buf, unsigned long max,
158 unsigned long *value);
159
160/* Device model */
161static struct platform_device *tpacpi_pdev;
162static struct class_device *tpacpi_hwmon;
163static struct platform_driver tpacpi_pdriver;
164static int tpacpi_create_driver_attributes(struct device_driver *drv);
165static void tpacpi_remove_driver_attributes(struct device_driver *drv);
166
167/* Module */
168static int experimental;
169static u32 dbg_level;
170static int force_load;
171static char *ibm_thinkpad_ec_found;
172
173static char* check_dmi_for_ec(void);
174static int thinkpad_acpi_module_init(void);
175static void thinkpad_acpi_module_exit(void);
176
177
178/****************************************************************************
179 * Subdrivers
180 */
181
182struct ibm_struct;
183
184struct tp_acpi_drv_struct {
185 char *hid;
186 struct acpi_driver *driver;
187
188 void (*notify) (struct ibm_struct *, u32);
189 acpi_handle *handle;
190 u32 type;
191 struct acpi_device *device;
192};
193
194struct ibm_struct {
195 char *name;
196
197 int (*read) (char *);
198 int (*write) (char *);
199 void (*exit) (void);
200
201 struct list_head all_drivers;
202
203 struct tp_acpi_drv_struct *acpi;
204
205 struct {
206 u8 acpi_driver_registered:1;
207 u8 acpi_notify_installed:1;
208 u8 proc_created:1;
209 u8 init_called:1;
210 u8 experimental:1;
211 } flags;
212};
213
214struct ibm_init_struct {
215 char param[32];
216
217 int (*init) (struct ibm_init_struct *);
218 struct ibm_struct *data;
219};
220
221static struct {
222#ifdef CONFIG_THINKPAD_ACPI_BAY
223 u16 bay_status:1;
224 u16 bay_eject:1;
225 u16 bay_status2:1;
226 u16 bay_eject2:1;
227#endif
228 u16 bluetooth:1;
229 u16 hotkey:1;
230 u16 hotkey_mask:1;
231 u16 light:1;
232 u16 light_status:1;
233 u16 wan:1;
234 u16 fan_ctrl_status_undef:1;
235} tp_features;
236
237static struct list_head tpacpi_all_drivers;
238
239static struct ibm_init_struct ibms_init[];
240static int set_ibm_param(const char *val, struct kernel_param *kp);
241static int ibm_init(struct ibm_init_struct *iibm);
242static void ibm_exit(struct ibm_struct *ibm);
243
244
245/*
246 * procfs master subdriver
247 */
248static int thinkpad_acpi_driver_init(struct ibm_init_struct *iibm);
249static int thinkpad_acpi_driver_read(char *p);
250
251
252/*
253 * Bay subdriver
254 */
255
256#ifdef CONFIG_THINKPAD_ACPI_BAY
257static acpi_handle bay_handle, bay_ej_handle;
258static acpi_handle bay2_handle, bay2_ej_handle;
259
260static int bay_init(struct ibm_init_struct *iibm);
261static void bay_notify(struct ibm_struct *ibm, u32 event);
262static int bay_read(char *p);
263static int bay_write(char *buf);
264#endif /* CONFIG_THINKPAD_ACPI_BAY */
265
266
267/*
268 * Beep subdriver
269 */
270
271static acpi_handle beep_handle;
272
273static int beep_read(char *p);
274static int beep_write(char *buf);
275
276
277/*
278 * Bluetooth subdriver
279 */
280
281#define TPACPI_BLUETH_SYSFS_GROUP "bluetooth"
282
283enum {
284 /* ACPI GBDC/SBDC bits */
285 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
286 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
287 TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */
288};
289
290static int bluetooth_init(struct ibm_init_struct *iibm);
291static int bluetooth_get_radiosw(void);
292static int bluetooth_set_radiosw(int radio_on);
293static int bluetooth_read(char *p);
294static int bluetooth_write(char *buf);
295
296
297/*
298 * Brightness (backlight) subdriver
299 */
300
301#define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
302
303static struct backlight_device *ibm_backlight_device;
304static int brightness_offset = 0x31;
305
306static int brightness_init(struct ibm_init_struct *iibm);
307static void brightness_exit(void);
308static int brightness_get(struct backlight_device *bd);
309static int brightness_set(int value);
310static int brightness_update_status(struct backlight_device *bd);
311static int brightness_read(char *p);
312static int brightness_write(char *buf);
313
314
315/*
316 * CMOS subdriver
317 */
318
319static int cmos_read(char *p);
320static int cmos_write(char *buf);
321
322
323/*
324 * Dock subdriver
325 */
326
327#ifdef CONFIG_THINKPAD_ACPI_DOCK
328static acpi_handle pci_handle;
329static acpi_handle dock_handle;
330
331static void dock_notify(struct ibm_struct *ibm, u32 event);
332static int dock_read(char *p);
333static int dock_write(char *buf);
334#endif /* CONFIG_THINKPAD_ACPI_DOCK */
335
336
337/*
338 * EC dump subdriver
339 */
340
341static int ecdump_read(char *p) ;
342static int ecdump_write(char *buf);
343
344
345/*
346 * Fan subdriver
347 */
348
349enum { /* Fan control constants */
350 fan_status_offset = 0x2f, /* EC register 0x2f */
351 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
352 * 0x84 must be read before 0x85 */
353
354 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
355 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
356
357 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
358};
359
360enum fan_status_access_mode {
361 TPACPI_FAN_NONE = 0, /* No fan status or control */
362 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
363 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
364};
365
366enum fan_control_access_mode {
367 TPACPI_FAN_WR_NONE = 0, /* No fan control */
368 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
369 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
370 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
371};
372
373enum fan_control_commands {
374 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
375 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
376 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
377 * and also watchdog cmd */
378};
379
380static int fan_control_allowed;
381
382static enum fan_status_access_mode fan_status_access_mode;
383static enum fan_control_access_mode fan_control_access_mode;
384static enum fan_control_commands fan_control_commands;
385static u8 fan_control_initial_status;
386static u8 fan_control_desired_level;
387static int fan_watchdog_maxinterval;
388
389static struct mutex fan_mutex;
390
391static acpi_handle fans_handle, gfan_handle, sfan_handle;
392
393static int fan_init(struct ibm_init_struct *iibm);
394static void fan_exit(void);
395static int fan_get_status(u8 *status);
396static int fan_get_status_safe(u8 *status);
397static int fan_get_speed(unsigned int *speed);
398static void fan_update_desired_level(u8 status);
399static void fan_watchdog_fire(struct work_struct *ignored);
400static void fan_watchdog_reset(void);
401static int fan_set_level(int level);
402static int fan_set_level_safe(int level);
403static int fan_set_enable(void);
404static int fan_set_disable(void);
405static int fan_set_speed(int speed);
406static int fan_read(char *p);
407static int fan_write(char *buf);
408static int fan_write_cmd_level(const char *cmd, int *rc);
409static int fan_write_cmd_enable(const char *cmd, int *rc);
410static int fan_write_cmd_disable(const char *cmd, int *rc);
411static int fan_write_cmd_speed(const char *cmd, int *rc);
412static int fan_write_cmd_watchdog(const char *cmd, int *rc);
413
414
415/*
416 * Hotkey subdriver
417 */
418
419#define TPACPI_HOTKEY_SYSFS_GROUP "hotkey"
420
421static int hotkey_orig_status;
422static int hotkey_orig_mask;
423
424static struct mutex hotkey_mutex;
425
426static int hotkey_init(struct ibm_init_struct *iibm);
427static void hotkey_exit(void);
428static int hotkey_get(int *status, int *mask);
429static int hotkey_set(int status, int mask);
430static void hotkey_notify(struct ibm_struct *ibm, u32 event);
431static int hotkey_read(char *p);
432static int hotkey_write(char *buf);
433
434
435/*
436 * LED subdriver
437 */
438
439enum led_access_mode {
440 TPACPI_LED_NONE = 0,
441 TPACPI_LED_570, /* 570 */
442 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
443 TPACPI_LED_NEW, /* all others */
444};
445
446enum { /* For TPACPI_LED_OLD */
447 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
448 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
449 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
450};
451
452static enum led_access_mode led_supported;
453static acpi_handle led_handle;
454
455static int led_init(struct ibm_init_struct *iibm);
456static int led_read(char *p);
457static int led_write(char *buf);
458
459/*
460 * Light (thinklight) subdriver
461 */
462
463static acpi_handle lght_handle, ledb_handle;
464
465static int light_init(struct ibm_init_struct *iibm);
466static int light_read(char *p);
467static int light_write(char *buf);
468
469
470/*
471 * Thermal subdriver
472 */
473
474enum thermal_access_mode {
475 TPACPI_THERMAL_NONE = 0, /* No thermal support */
476 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
477 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
478 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
479 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
480};
481
482enum { /* TPACPI_THERMAL_TPEC_* */
483 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
484 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
485 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
486};
487
488#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
489struct ibm_thermal_sensors_struct {
490 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
491};
492
493static enum thermal_access_mode thermal_read_mode;
494
495static int thermal_init(struct ibm_init_struct *iibm);
496static int thermal_get_sensor(int idx, s32 *value);
497static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
498static int thermal_read(char *p);
499
500
501/*
502 * Video subdriver
503 */
504
505enum video_access_mode {
506 TPACPI_VIDEO_NONE = 0,
507 TPACPI_VIDEO_570, /* 570 */
508 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
509 TPACPI_VIDEO_NEW, /* all others */
510};
511
512enum { /* video status flags, based on VIDEO_570 */
513 TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */
514 TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */
515 TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */
516};
517
518enum { /* TPACPI_VIDEO_570 constants */
519 TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */
520 TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to
521 * video_status_flags */
522 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */
523 TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */
524};
525
526static enum video_access_mode video_supported;
527static int video_orig_autosw;
528static acpi_handle vid_handle, vid2_handle;
529
530static int video_init(struct ibm_init_struct *iibm);
531static void video_exit(void);
532static int video_outputsw_get(void);
533static int video_outputsw_set(int status);
534static int video_autosw_get(void);
535static int video_autosw_set(int enable);
536static int video_outputsw_cycle(void);
537static int video_expand_toggle(void);
538static int video_read(char *p);
539static int video_write(char *buf);
540
541
542/*
543 * Volume subdriver
544 */
545
546static int volume_offset = 0x30;
547
548static int volume_read(char *p);
549static int volume_write(char *buf);
550
551
552/*
553 * Wan subdriver
554 */
555
556#define TPACPI_WAN_SYSFS_GROUP "wwan"
557
558enum {
559 /* ACPI GWAN/SWAN bits */
560 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
561 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
562 TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */
563};
564
565static int wan_init(struct ibm_init_struct *iibm);
566static int wan_get_radiosw(void);
567static int wan_set_radiosw(int radio_on);
568static int wan_read(char *p);
569static int wan_write(char *buf);
570
571
572#endif /* __THINKPAD_ACPI_H */
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index a064f36a0805..b5ac810404c0 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -317,6 +317,10 @@ static int __init acpi_pci_init(void)
317{ 317{
318 int ret; 318 int ret;
319 319
320 if (acpi_gbl_FADT.boot_flags & BAF_MSI_NOT_SUPPORTED) {
321 printk(KERN_INFO"ACPI FADT declares the system doesn't support MSI, so disable it\n");
322 pci_no_msi();
323 }
320 ret = register_acpi_bus_type(&acpi_pci_bus); 324 ret = register_acpi_bus_type(&acpi_pci_bus);
321 if (ret) 325 if (ret)
322 return 0; 326 return 0;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 65d6f23ead41..3411483240cd 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1303,119 +1303,6 @@ static void __init quirk_alder_ioapic(struct pci_dev *pdev)
1303DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic ); 1303DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic );
1304#endif 1304#endif
1305 1305
1306enum ide_combined_type { COMBINED = 0, IDE = 1, LIBATA = 2 };
1307/* Defaults to combined */
1308static enum ide_combined_type combined_mode;
1309
1310static int __init combined_setup(char *str)
1311{
1312 if (!strncmp(str, "ide", 3))
1313 combined_mode = IDE;
1314 else if (!strncmp(str, "libata", 6))
1315 combined_mode = LIBATA;
1316 else /* "combined" or anything else defaults to old behavior */
1317 combined_mode = COMBINED;
1318
1319 return 1;
1320}
1321__setup("combined_mode=", combined_setup);
1322
1323#ifdef CONFIG_SATA_INTEL_COMBINED
1324static void __devinit quirk_intel_ide_combined(struct pci_dev *pdev)
1325{
1326 u8 prog, comb, tmp;
1327 int ich = 0;
1328
1329 /*
1330 * Narrow down to Intel SATA PCI devices.
1331 */
1332 switch (pdev->device) {
1333 /* PCI ids taken from drivers/scsi/ata_piix.c */
1334 case 0x24d1:
1335 case 0x24df:
1336 case 0x25a3:
1337 case 0x25b0:
1338 ich = 5;
1339 break;
1340 case 0x2651:
1341 case 0x2652:
1342 case 0x2653:
1343 case 0x2680: /* ESB2 */
1344 ich = 6;
1345 break;
1346 case 0x27c0:
1347 case 0x27c4:
1348 ich = 7;
1349 break;
1350 case 0x2828: /* ICH8M */
1351 ich = 8;
1352 break;
1353 default:
1354 /* we do not handle this PCI device */
1355 return;
1356 }
1357
1358 /*
1359 * Read combined mode register.
1360 */
1361 pci_read_config_byte(pdev, 0x90, &tmp); /* combined mode reg */
1362
1363 if (ich == 5) {
1364 tmp &= 0x6; /* interesting bits 2:1, PATA primary/secondary */
1365 if (tmp == 0x4) /* bits 10x */
1366 comb = (1 << 0); /* SATA port 0, PATA port 1 */
1367 else if (tmp == 0x6) /* bits 11x */
1368 comb = (1 << 2); /* PATA port 0, SATA port 1 */
1369 else
1370 return; /* not in combined mode */
1371 } else {
1372 WARN_ON((ich != 6) && (ich != 7) && (ich != 8));
1373 tmp &= 0x3; /* interesting bits 1:0 */
1374 if (tmp & (1 << 0))
1375 comb = (1 << 2); /* PATA port 0, SATA port 1 */
1376 else if (tmp & (1 << 1))
1377 comb = (1 << 0); /* SATA port 0, PATA port 1 */
1378 else
1379 return; /* not in combined mode */
1380 }
1381
1382 /*
1383 * Read programming interface register.
1384 * (Tells us if it's legacy or native mode)
1385 */
1386 pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
1387
1388 /* if SATA port is in native mode, we're ok. */
1389 if (prog & comb)
1390 return;
1391
1392 /* Don't reserve any so the IDE driver can get them (but only if
1393 * combined_mode=ide).
1394 */
1395 if (combined_mode == IDE)
1396 return;
1397
1398 /* Grab them both for libata if combined_mode=libata. */
1399 if (combined_mode == LIBATA) {
1400 request_region(0x1f0, 8, "libata"); /* port 0 */
1401 request_region(0x170, 8, "libata"); /* port 1 */
1402 return;
1403 }
1404
1405 /* SATA port is in legacy mode. Reserve port so that
1406 * IDE driver does not attempt to use it. If request_region
1407 * fails, it will be obvious at boot time, so we don't bother
1408 * checking return values.
1409 */
1410 if (comb == (1 << 0))
1411 request_region(0x1f0, 8, "libata"); /* port 0 */
1412 else
1413 request_region(0x170, 8, "libata"); /* port 1 */
1414}
1415DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_intel_ide_combined );
1416#endif /* CONFIG_SATA_INTEL_COMBINED */
1417
1418
1419int pcie_mch_quirk; 1306int pcie_mch_quirk;
1420EXPORT_SYMBOL(pcie_mch_quirk); 1307EXPORT_SYMBOL(pcie_mch_quirk);
1421 1308
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 95045e33710d..e9bd29975db4 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -3770,7 +3770,8 @@ static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3770 * Return value: 3770 * Return value:
3771 * 0 on success / non-zero on failure 3771 * 0 on success / non-zero on failure
3772 **/ 3772 **/
3773static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes) 3773static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes,
3774 unsigned long deadline)
3774{ 3775{
3775 struct ipr_sata_port *sata_port = ap->private_data; 3776 struct ipr_sata_port *sata_port = ap->private_data;
3776 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg; 3777 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 09469e7db6a5..955adfb8d64c 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -276,6 +276,7 @@ enum acpi_prefered_pm_profiles {
276 276
277#define BAF_LEGACY_DEVICES 0x0001 277#define BAF_LEGACY_DEVICES 0x0001
278#define BAF_8042_KEYBOARD_CONTROLLER 0x0002 278#define BAF_8042_KEYBOARD_CONTROLLER 0x0002
279#define BAF_MSI_NOT_SUPPORTED 0x0008
279 280
280#define FADT2_REVISION_ID 3 281#define FADT2_REVISION_ID 3
281#define FADT2_MINUS_REVISION_ID 2 282#define FADT2_MINUS_REVISION_ID 2
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 6caeb98e29dd..edb31bfff68f 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -159,11 +159,19 @@ enum {
159 ATA_CMD_INIT_DEV_PARAMS = 0x91, 159 ATA_CMD_INIT_DEV_PARAMS = 0x91,
160 ATA_CMD_READ_NATIVE_MAX = 0xF8, 160 ATA_CMD_READ_NATIVE_MAX = 0xF8,
161 ATA_CMD_READ_NATIVE_MAX_EXT = 0x27, 161 ATA_CMD_READ_NATIVE_MAX_EXT = 0x27,
162 ATA_CMD_SET_MAX = 0xF9,
163 ATA_CMD_SET_MAX_EXT = 0x37,
162 ATA_CMD_READ_LOG_EXT = 0x2f, 164 ATA_CMD_READ_LOG_EXT = 0x2f,
163 165
164 /* READ_LOG_EXT pages */ 166 /* READ_LOG_EXT pages */
165 ATA_LOG_SATA_NCQ = 0x10, 167 ATA_LOG_SATA_NCQ = 0x10,
166 168
169 /* READ/WRITE LONG (obsolete) */
170 ATA_CMD_READ_LONG = 0x22,
171 ATA_CMD_READ_LONG_ONCE = 0x23,
172 ATA_CMD_WRITE_LONG = 0x32,
173 ATA_CMD_WRITE_LONG_ONCE = 0x33,
174
167 /* SETFEATURES stuff */ 175 /* SETFEATURES stuff */
168 SETFEATURES_XFER = 0x03, 176 SETFEATURES_XFER = 0x03,
169 XFER_UDMA_7 = 0x47, 177 XFER_UDMA_7 = 0x47,
@@ -194,6 +202,8 @@ enum {
194 SETFEATURES_WC_ON = 0x02, /* Enable write cache */ 202 SETFEATURES_WC_ON = 0x02, /* Enable write cache */
195 SETFEATURES_WC_OFF = 0x82, /* Disable write cache */ 203 SETFEATURES_WC_OFF = 0x82, /* Disable write cache */
196 204
205 SETFEATURES_SPINUP = 0x07, /* Spin-up drive */
206
197 /* ATAPI stuff */ 207 /* ATAPI stuff */
198 ATAPI_PKT_DMA = (1 << 0), 208 ATAPI_PKT_DMA = (1 << 0),
199 ATAPI_DMADIR = (1 << 2), /* ATAPI data dir: 209 ATAPI_DMADIR = (1 << 2), /* ATAPI data dir:
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 6859a3b14088..71ea92319241 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -99,7 +99,6 @@ extern struct resource ioport_resource;
99extern struct resource iomem_resource; 99extern struct resource iomem_resource;
100 100
101extern int request_resource(struct resource *root, struct resource *new); 101extern int request_resource(struct resource *root, struct resource *new);
102extern struct resource * ____request_resource(struct resource *root, struct resource *new);
103extern int release_resource(struct resource *new); 102extern int release_resource(struct resource *new);
104extern int insert_resource(struct resource *parent, struct resource *new); 103extern int insert_resource(struct resource *parent, struct resource *new);
105extern int allocate_resource(struct resource *root, struct resource *new, 104extern int allocate_resource(struct resource *root, struct resource *new,
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 0cfbcb6f08eb..d8cfc72ea9c1 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -210,6 +210,7 @@ enum {
210 210
211 /* host set flags */ 211 /* host set flags */
212 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */ 212 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */
213 ATA_HOST_STARTED = (1 << 1), /* Host started */
213 214
214 /* various lengths of time */ 215 /* various lengths of time */
215 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */ 216 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */
@@ -281,11 +282,13 @@ enum {
281 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */ 282 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
282 ATA_EHI_QUIET = (1 << 3), /* be quiet */ 283 ATA_EHI_QUIET = (1 << 3), /* be quiet */
283 284
284 ATA_EHI_DID_RESET = (1 << 16), /* already reset this port */ 285 ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
285 ATA_EHI_PRINTINFO = (1 << 17), /* print configuration info */ 286 ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
286 ATA_EHI_SETMODE = (1 << 18), /* configure transfer mode */ 287 ATA_EHI_PRINTINFO = (1 << 18), /* print configuration info */
287 ATA_EHI_POST_SETMODE = (1 << 19), /* revaildating after setmode */ 288 ATA_EHI_SETMODE = (1 << 19), /* configure transfer mode */
289 ATA_EHI_POST_SETMODE = (1 << 20), /* revaildating after setmode */
288 290
291 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
289 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK, 292 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK,
290 293
291 /* max repeat if error condition is still set after ->error_handler */ 294 /* max repeat if error condition is still set after ->error_handler */
@@ -367,34 +370,6 @@ struct ata_ioports {
367 void __iomem *scr_addr; 370 void __iomem *scr_addr;
368}; 371};
369 372
370struct ata_probe_ent {
371 struct list_head node;
372 struct device *dev;
373 const struct ata_port_operations *port_ops;
374 struct scsi_host_template *sht;
375 struct ata_ioports port[ATA_MAX_PORTS];
376 unsigned int n_ports;
377 unsigned int dummy_port_mask;
378 unsigned int pio_mask;
379 unsigned int mwdma_mask;
380 unsigned int udma_mask;
381 unsigned long irq;
382 unsigned long irq2;
383 unsigned int irq_flags;
384 unsigned long port_flags;
385 unsigned long _host_flags;
386 void __iomem * const *iomap;
387 void *private_data;
388
389 /* port_info for the secondary port. Together with irq2, it's
390 * used to implement non-uniform secondary port. Currently,
391 * the only user is ata_piix combined mode. This workaround
392 * will be removed together with ata_probe_ent when init model
393 * is updated.
394 */
395 const struct ata_port_info *pinfo2;
396};
397
398struct ata_host { 373struct ata_host {
399 spinlock_t lock; 374 spinlock_t lock;
400 struct device *dev; 375 struct device *dev;
@@ -427,6 +402,7 @@ struct ata_queued_cmd {
427 int dma_dir; 402 int dma_dir;
428 403
429 unsigned int pad_len; 404 unsigned int pad_len;
405 unsigned int sect_size;
430 406
431 unsigned int nbytes; 407 unsigned int nbytes;
432 unsigned int curbytes; 408 unsigned int curbytes;
@@ -472,6 +448,7 @@ struct ata_device {
472 struct scsi_device *sdev; /* attached SCSI device */ 448 struct scsi_device *sdev; /* attached SCSI device */
473 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ 449 /* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */
474 u64 n_sectors; /* size of device, if ATA */ 450 u64 n_sectors; /* size of device, if ATA */
451 u64 n_sectors_boot; /* size of ATA device at startup */
475 unsigned int class; /* ATA_DEV_xxx */ 452 unsigned int class; /* ATA_DEV_xxx */
476 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */ 453 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
477 u8 pio_mode; 454 u8 pio_mode;
@@ -597,11 +574,11 @@ struct ata_port {
597struct ata_port_operations { 574struct ata_port_operations {
598 void (*port_disable) (struct ata_port *); 575 void (*port_disable) (struct ata_port *);
599 576
600 void (*dev_config) (struct ata_port *, struct ata_device *); 577 void (*dev_config) (struct ata_device *);
601 578
602 void (*set_piomode) (struct ata_port *, struct ata_device *); 579 void (*set_piomode) (struct ata_port *, struct ata_device *);
603 void (*set_dmamode) (struct ata_port *, struct ata_device *); 580 void (*set_dmamode) (struct ata_port *, struct ata_device *);
604 unsigned long (*mode_filter) (const struct ata_port *, struct ata_device *, unsigned long); 581 unsigned long (*mode_filter) (struct ata_device *, unsigned long);
605 582
606 void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf); 583 void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf);
607 void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf); 584 void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
@@ -616,6 +593,8 @@ struct ata_port_operations {
616 593
617 void (*post_set_mode) (struct ata_port *ap); 594 void (*post_set_mode) (struct ata_port *ap);
618 595
596 int (*cable_detect) (struct ata_port *ap);
597
619 int (*check_atapi_dma) (struct ata_queued_cmd *qc); 598 int (*check_atapi_dma) (struct ata_queued_cmd *qc);
620 599
621 void (*bmdma_setup) (struct ata_queued_cmd *qc); 600 void (*bmdma_setup) (struct ata_queued_cmd *qc);
@@ -664,6 +643,7 @@ struct ata_port_info {
664 unsigned long mwdma_mask; 643 unsigned long mwdma_mask;
665 unsigned long udma_mask; 644 unsigned long udma_mask;
666 const struct ata_port_operations *port_ops; 645 const struct ata_port_operations *port_ops;
646 irq_handler_t irq_handler;
667 void *private_data; 647 void *private_data;
668}; 648};
669 649
@@ -686,6 +666,7 @@ extern const unsigned long sata_deb_timing_hotplug[];
686extern const unsigned long sata_deb_timing_long[]; 666extern const unsigned long sata_deb_timing_long[];
687 667
688extern const struct ata_port_operations ata_dummy_port_ops; 668extern const struct ata_port_operations ata_dummy_port_ops;
669extern const struct ata_port_info ata_dummy_port_info;
689 670
690static inline const unsigned long * 671static inline const unsigned long *
691sata_ehc_deb_timing(struct ata_eh_context *ehc) 672sata_ehc_deb_timing(struct ata_eh_context *ehc)
@@ -701,6 +682,7 @@ static inline int ata_port_is_dummy(struct ata_port *ap)
701 return ap->ops == &ata_dummy_port_ops; 682 return ap->ops == &ata_dummy_port_ops;
702} 683}
703 684
685extern void sata_print_link_status(struct ata_port *ap);
704extern void ata_port_probe(struct ata_port *); 686extern void ata_port_probe(struct ata_port *);
705extern void __sata_phy_reset(struct ata_port *ap); 687extern void __sata_phy_reset(struct ata_port *ap);
706extern void sata_phy_reset(struct ata_port *ap); 688extern void sata_phy_reset(struct ata_port *ap);
@@ -728,7 +710,15 @@ extern int ata_pci_device_resume(struct pci_dev *pdev);
728#endif 710#endif
729extern int ata_pci_clear_simplex(struct pci_dev *pdev); 711extern int ata_pci_clear_simplex(struct pci_dev *pdev);
730#endif /* CONFIG_PCI */ 712#endif /* CONFIG_PCI */
731extern int ata_device_add(const struct ata_probe_ent *ent); 713extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
714extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
715 const struct ata_port_info * const * ppi, int n_ports);
716extern int ata_host_start(struct ata_host *host);
717extern int ata_host_register(struct ata_host *host,
718 struct scsi_host_template *sht);
719extern int ata_host_activate(struct ata_host *host, int irq,
720 irq_handler_t irq_handler, unsigned long irq_flags,
721 struct scsi_host_template *sht);
732extern void ata_host_detach(struct ata_host *host); 722extern void ata_host_detach(struct ata_host *host);
733extern void ata_host_init(struct ata_host *, struct device *, 723extern void ata_host_init(struct ata_host *, struct device *,
734 unsigned long, const struct ata_port_operations *); 724 unsigned long, const struct ata_port_operations *);
@@ -828,11 +818,17 @@ extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
828extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, 818extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
829 int queue_depth); 819 int queue_depth);
830extern struct ata_device *ata_dev_pair(struct ata_device *adev); 820extern struct ata_device *ata_dev_pair(struct ata_device *adev);
821extern int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
831extern u8 ata_irq_on(struct ata_port *ap); 822extern u8 ata_irq_on(struct ata_port *ap);
832extern u8 ata_dummy_irq_on(struct ata_port *ap); 823extern u8 ata_dummy_irq_on(struct ata_port *ap);
833extern u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq); 824extern u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq);
834extern u8 ata_dummy_irq_ack(struct ata_port *ap, unsigned int chk_drq); 825extern u8 ata_dummy_irq_ack(struct ata_port *ap, unsigned int chk_drq);
835 826
827extern int ata_cable_40wire(struct ata_port *ap);
828extern int ata_cable_80wire(struct ata_port *ap);
829extern int ata_cable_sata(struct ata_port *ap);
830extern int ata_cable_unknown(struct ata_port *ap);
831
836/* 832/*
837 * Timing helpers 833 * Timing helpers
838 */ 834 */
@@ -870,10 +866,13 @@ struct pci_bits {
870 unsigned long val; 866 unsigned long val;
871}; 867};
872 868
873extern struct ata_probe_ent * 869extern int ata_pci_init_native_host(struct ata_host *host,
874ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask); 870 unsigned int port_mask);
871extern int ata_pci_prepare_native_host(struct pci_dev *pdev,
872 const struct ata_port_info * const * ppi,
873 int n_ports, struct ata_host **r_host);
875extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits); 874extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
876extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_device *, unsigned long); 875extern unsigned long ata_pci_default_filter(struct ata_device *, unsigned long);
877#endif /* CONFIG_PCI */ 876#endif /* CONFIG_PCI */
878 877
879/* 878/*
@@ -1173,6 +1172,7 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
1173 qc->n_elem = 0; 1172 qc->n_elem = 0;
1174 qc->err_mask = 0; 1173 qc->err_mask = 0;
1175 qc->pad_len = 0; 1174 qc->pad_len = 0;
1175 qc->sect_size = ATA_SECT_SIZE;
1176 1176
1177 ata_tf_init(qc->dev, &qc->tf); 1177 ata_tf_init(qc->dev, &qc->tf);
1178 1178
@@ -1220,7 +1220,7 @@ static inline void ata_pad_free(struct ata_port *ap, struct device *dev)
1220 1220
1221static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host) 1221static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
1222{ 1222{
1223 return (struct ata_port *) &host->hostdata[0]; 1223 return *(struct ata_port **)&host->hostdata[0];
1224} 1224}
1225 1225
1226#endif /* __LINUX_LIBATA_H__ */ 1226#endif /* __LINUX_LIBATA_H__ */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a3ad76221c6f..972491089ac9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -838,6 +838,7 @@ void __iomem * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
838void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr); 838void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
839void __iomem * const * pcim_iomap_table(struct pci_dev *pdev); 839void __iomem * const * pcim_iomap_table(struct pci_dev *pdev);
840int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name); 840int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name);
841void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask);
841 842
842extern int pci_pci_problems; 843extern int pci_pci_problems;
843#define PCIPCI_FAIL 1 /* No PCI PCI DMA */ 844#define PCIPCI_FAIL 1 /* No PCI PCI DMA */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 247b5e63f6c2..1b0ddbb8a804 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -368,7 +368,6 @@
368#define PCI_DEVICE_ID_ATI_IXP400_SATA 0x4379 368#define PCI_DEVICE_ID_ATI_IXP400_SATA 0x4379
369#define PCI_DEVICE_ID_ATI_IXP400_SATA2 0x437a 369#define PCI_DEVICE_ID_ATI_IXP400_SATA2 0x437a
370#define PCI_DEVICE_ID_ATI_IXP600_SATA 0x4380 370#define PCI_DEVICE_ID_ATI_IXP600_SATA 0x4380
371#define PCI_DEVICE_ID_ATI_IXP600_SRAID 0x4381
372#define PCI_DEVICE_ID_ATI_IXP600_SMBUS 0x4385 371#define PCI_DEVICE_ID_ATI_IXP600_SMBUS 0x4385
373#define PCI_DEVICE_ID_ATI_IXP600_IDE 0x438c 372#define PCI_DEVICE_ID_ATI_IXP600_IDE 0x438c
374 373
diff --git a/include/linux/sony-laptop.h b/include/linux/sony-laptop.h
new file mode 100644
index 000000000000..e2e036d94e4a
--- /dev/null
+++ b/include/linux/sony-laptop.h
@@ -0,0 +1,34 @@
1#ifndef _SONYLAPTOP_H_
2#define _SONYLAPTOP_H_
3
4#include <linux/types.h>
5
6#ifdef __KERNEL__
7
8/* used only for communication between v4l and sony-laptop */
9
10#define SONY_PIC_COMMAND_GETCAMERA 1 /* obsolete */
11#define SONY_PIC_COMMAND_SETCAMERA 2
12#define SONY_PIC_COMMAND_GETCAMERABRIGHTNESS 3 /* obsolete */
13#define SONY_PIC_COMMAND_SETCAMERABRIGHTNESS 4
14#define SONY_PIC_COMMAND_GETCAMERACONTRAST 5 /* obsolete */
15#define SONY_PIC_COMMAND_SETCAMERACONTRAST 6
16#define SONY_PIC_COMMAND_GETCAMERAHUE 7 /* obsolete */
17#define SONY_PIC_COMMAND_SETCAMERAHUE 8
18#define SONY_PIC_COMMAND_GETCAMERACOLOR 9 /* obsolete */
19#define SONY_PIC_COMMAND_SETCAMERACOLOR 10
20#define SONY_PIC_COMMAND_GETCAMERASHARPNESS 11 /* obsolete */
21#define SONY_PIC_COMMAND_SETCAMERASHARPNESS 12
22#define SONY_PIC_COMMAND_GETCAMERAPICTURE 13 /* obsolete */
23#define SONY_PIC_COMMAND_SETCAMERAPICTURE 14
24#define SONY_PIC_COMMAND_GETCAMERAAGC 15 /* obsolete */
25#define SONY_PIC_COMMAND_SETCAMERAAGC 16
26#define SONY_PIC_COMMAND_GETCAMERADIRECTION 17 /* obsolete */
27#define SONY_PIC_COMMAND_GETCAMERAROMVERSION 18 /* obsolete */
28#define SONY_PIC_COMMAND_GETCAMERAREVISION 19 /* obsolete */
29
30int sony_pic_camera_command(int command, u8 value);
31
32#endif /* __KERNEL__ */
33
34#endif /* _SONYLAPTOP_H_ */
diff --git a/kernel/resource.c b/kernel/resource.c
index bdb55a33f969..9bd14fd3e6de 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -213,27 +213,6 @@ int request_resource(struct resource *root, struct resource *new)
213EXPORT_SYMBOL(request_resource); 213EXPORT_SYMBOL(request_resource);
214 214
215/** 215/**
216 * ____request_resource - reserve a resource, with resource conflict returned
217 * @root: root resource descriptor
218 * @new: resource descriptor desired by caller
219 *
220 * Returns:
221 * On success, NULL is returned.
222 * On error, a pointer to the conflicting resource is returned.
223 */
224struct resource *____request_resource(struct resource *root, struct resource *new)
225{
226 struct resource *conflict;
227
228 write_lock(&resource_lock);
229 conflict = __request_resource(root, new);
230 write_unlock(&resource_lock);
231 return conflict;
232}
233
234EXPORT_SYMBOL(____request_resource);
235
236/**
237 * release_resource - release a previously reserved resource 216 * release_resource - release a previously reserved resource
238 * @old: resource pointer 217 * @old: resource pointer
239 */ 218 */
diff --git a/lib/devres.c b/lib/devres.c
index eb38849aa717..b1d336ce7f3d 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -296,5 +296,31 @@ int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name)
296 return rc; 296 return rc;
297} 297}
298EXPORT_SYMBOL(pcim_iomap_regions); 298EXPORT_SYMBOL(pcim_iomap_regions);
299
300/**
301 * pcim_iounmap_regions - Unmap and release PCI BARs
302 * @pdev: PCI device to map IO resources for
303 * @mask: Mask of BARs to unmap and release
304 *
305 * Unamp and release regions specified by @mask.
306 */
307void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask)
308{
309 void __iomem * const *iomap;
310 int i;
311
312 iomap = pcim_iomap_table(pdev);
313 if (!iomap)
314 return;
315
316 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
317 if (!(mask & (1 << i)))
318 continue;
319
320 pcim_iounmap(pdev, iomap[i]);
321 pci_release_region(pdev, i);
322 }
323}
324EXPORT_SYMBOL(pcim_iounmap_regions);
299#endif 325#endif
300#endif 326#endif