blob: 4001ad193ddc5c2c291d9a7c3a3d73d8bc476703 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
3 *
4 *
Borislav Deianov78f81cc2005-08-17 00:00:00 -04005 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Borislav Deianov78f81cc2005-08-17 00:00:00 -040020 */
21
22#define IBM_VERSION "0.12a"
23
24/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * Changelog:
Borislav Deianov78f81cc2005-08-17 00:00:00 -040026 *
27 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
28 * 2005-03-17 0.11 support for 600e, 770x
29 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
30 * support for 770e, G41
31 * G40 and G41 don't have a thinklight
32 * temperatures no longer experimental
33 * experimental brightness control
34 * experimental volume control
35 * experimental fan enable/disable
36 * 2005-01-16 0.10 fix module loading on R30, R31
37 * 2005-01-16 0.9 support for 570, R30, R31
38 * ultrabay support on A22p, A3x
39 * limit arg for cmos, led, beep, drop experimental status
40 * more capable led control on A21e, A22p, T20-22, X20
41 * experimental temperatures and fan speed
42 * experimental embedded controller register dump
43 * mark more functions as __init, drop incorrect __exit
44 * use MODULE_VERSION
45 * thanks to Henrik Brix Andersen <brix@gentoo.org>
46 * fix parameter passing on module loading
47 * thanks to Rusty Russell <rusty@rustcorp.com.au>
48 * thanks to Jim Radford <radford@blackbean.org>
49 * 2004-11-08 0.8 fix init error case, don't return from a macro
50 * thanks to Chris Wright <chrisw@osdl.org>
51 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
52 * fix led control on A21e
53 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
55 * proc file format changed
56 * video_switch command
57 * experimental cmos control
58 * experimental led control
59 * experimental acpi sounds
Borislav Deianov78f81cc2005-08-17 00:00:00 -040060 * 2004-09-16 0.4 support for module parameters
61 * hotkey mask can be prefixed by 0x
62 * video output switching
63 * video expansion control
64 * ultrabay eject support
65 * removed lcd brightness/on/off control, didn't work
66 * 2004-08-17 0.3 support for R40
67 * lcd off, brightness control
68 * thinklight on/off
69 * 2004-08-14 0.2 support for T series, X20
70 * bluetooth enable/disable
71 * hotkey events disabled by default
72 * removed fan control, currently useless
73 * 2004-08-09 0.1 initial release, support for X series
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include <linux/kernel.h>
77#include <linux/module.h>
78#include <linux/init.h>
79#include <linux/types.h>
80#include <linux/proc_fs.h>
Holger Macht8acb0252006-10-20 14:30:28 -070081#include <linux/backlight.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include <asm/uaccess.h>
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -020083#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85#include <acpi/acpi_drivers.h>
86#include <acpi/acnamesp.h>
87
88#define IBM_NAME "ibm"
89#define IBM_DESC "IBM ThinkPad ACPI Extras"
90#define IBM_FILE "ibm_acpi"
91#define IBM_URL "http://ibm-acpi.sf.net/"
92
Borislav Deianov78f81cc2005-08-17 00:00:00 -040093MODULE_AUTHOR("Borislav Deianov");
94MODULE_DESCRIPTION(IBM_DESC);
95MODULE_VERSION(IBM_VERSION);
96MODULE_LICENSE("GPL");
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define IBM_DIR IBM_NAME
99
100#define IBM_LOG IBM_FILE ": "
101#define IBM_ERR KERN_ERR IBM_LOG
102#define IBM_NOTICE KERN_NOTICE IBM_LOG
103#define IBM_INFO KERN_INFO IBM_LOG
104#define IBM_DEBUG KERN_DEBUG IBM_LOG
105
106#define IBM_MAX_ACPI_ARGS 3
107
108#define __unused __attribute__ ((unused))
109
110static int experimental;
111module_param(experimental, int, 0);
112
113static acpi_handle root_handle = NULL;
114
115#define IBM_HANDLE(object, parent, paths...) \
116 static acpi_handle object##_handle; \
117 static acpi_handle *object##_parent = &parent##_handle; \
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400118 static char *object##_path; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 static char *object##_paths[] = { paths }
120
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400121/*
122 * The following models are supported to various degrees:
123 *
124 * 570, 600e, 600x, 770e, 770x
125 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
126 * G40, G41
127 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
128 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
129 * X20, X21, X22, X23, X24, X30, X31, X40
130 *
131 * The following models have no supported features:
132 *
133 * 240, 240x, i1400
134 *
135 * Still missing DSDTs for the following models:
136 *
137 * A20p, A22e, A22m
138 * R52
139 * S31
140 * T43p
141 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400143IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
144 "\\_SB.PCI.ISA.EC", /* 570 */
145 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
146 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
147 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
148 "\\_SB.PCI0.ICH3.EC0", /* R31 */
149 "\\_SB.PCI0.LPC.EC", /* all others */
150 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400152IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
153 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
154 "\\_SB.PCI0.VID0", /* 770e */
155 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
156 "\\_SB.PCI0.AGP.VID", /* all others */
157 ); /* R30, R31 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400159IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400161IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
162 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
163 "\\CMS", /* R40, R40e */
164 ); /* all others */
Kristen Accardi63e5f242006-02-23 17:56:06 -0800165#ifdef CONFIG_ACPI_IBM_DOCK
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400166IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
167 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
168 "\\_SB.PCI0.PCI1.DOCK", /* all others */
169 "\\_SB.PCI.ISA.SLCE", /* 570 */
170 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
Kristen Accardi63e5f242006-02-23 17:56:06 -0800171#endif
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400172IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
173 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
174 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
175 ); /* A21e, R30, R31 */
176
177IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
178 "_EJ0", /* all others */
179 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
180
181IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
182 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
183 ); /* all others */
184
185IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
186 "_EJ0", /* 770x */
187 ); /* all others */
188
189/* don't list other alternatives as we install a notify handler on the 570 */
190IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
191
192IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
193 "^HKEY", /* R30, R31 */
194 "HKEY", /* all others */
195 ); /* 570 */
196
197IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
198IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
199
200IBM_HANDLE(led, ec, "SLED", /* 570 */
201 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
202 "LED", /* all others */
203 ); /* R30, R31 */
204
205IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
206IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
207IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -0200208IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400209
210IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
211 "\\FSPD", /* 600e/x, 770e, 770x */
212 ); /* all others */
213
214IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
215 "JFNS", /* 770x-JL */
216 ); /* all others */
217
218#define IBM_HKEY_HID "IBM0068"
219#define IBM_PCI_HID "PNP0A03"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -0200221enum thermal_access_mode {
222 IBMACPI_THERMAL_NONE = 0, /* No thermal support */
223 IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
224 IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -0200225 IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
226 IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -0200227};
228
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -0200229#define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -0200230struct ibm_thermal_sensors_struct {
231 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
232};
233
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -0200234/*
235 * FAN ACCESS MODES
236 *
237 * IBMACPI_FAN_RD_ACPI_GFAN:
238 * ACPI GFAN method: returns fan level
239 *
240 * see IBMACPI_FAN_WR_ACPI_SFAN
241 * EC 0x2f not available if GFAN exists
242 *
243 * IBMACPI_FAN_WR_ACPI_SFAN:
244 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
245 *
246 * EC 0x2f might be available *for reading*, but never for writing.
247 *
248 * IBMACPI_FAN_WR_TPEC:
249 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
250 * on almost all ThinkPads
251 *
252 * Fan speed changes of any sort (including those caused by the
253 * disengaged mode) are usually done slowly by the firmware as the
254 * maximum ammount of fan duty cycle change per second seems to be
255 * limited.
256 *
257 * Reading is not available if GFAN exists.
258 * Writing is not available if SFAN exists.
259 *
260 * Bits
261 * 7 automatic mode engaged;
262 * (default operation mode of the ThinkPad)
263 * fan level is ignored in this mode.
264 * 6 disengage mode (takes precedence over bit 7);
265 * not available on all thinkpads. May disable
266 * the tachometer, and speeds up fan to 100% duty-cycle,
267 * which speeds it up far above the standard RPM
268 * levels. It is not impossible that it could cause
269 * hardware damage.
270 * 5-3 unused in some models. Extra bits for fan level
271 * in others, but still useless as all values above
272 * 7 map to the same speed as level 7 in these models.
273 * 2-0 fan level (0..7 usually)
274 * 0x00 = stop
275 * 0x07 = max (set when temperatures critical)
276 * Some ThinkPads may have other levels, see
277 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
278 *
279 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
280 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
281 * does so, its initial value is meaningless (0x07).
282 *
283 * For firmware bugs, refer to:
284 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
285 *
286 * ----
287 *
288 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
289 * Main fan tachometer reading (in RPM)
290 *
291 * This register is present on all ThinkPads with a new-style EC, and
292 * it is known not to be present on the A21m/e, and T22, as there is
293 * something else in offset 0x84 according to the ACPI DSDT. Other
294 * ThinkPads from this same time period (and earlier) probably lack the
295 * tachometer as well.
296 *
297 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
298 * was never fixed by IBM to report the EC firmware version string
299 * probably support the tachometer (like the early X models), so
300 * detecting it is quite hard. We need more data to know for sure.
301 *
302 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
303 * might result.
304 *
305 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
306 * register is not invalidated in ThinkPads that disable tachometer
307 * readings. Thus, the tachometer readings go stale.
308 *
309 * For firmware bugs, refer to:
310 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
311 *
312 * IBMACPI_FAN_WR_ACPI_FANS:
313 * ThinkPad X31, X40, X41. Not available in the X60.
314 *
315 * FANS ACPI handle: takes three arguments: low speed, medium speed,
316 * high speed. ACPI DSDT seems to map these three speeds to levels
317 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
318 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
319 *
320 * The speeds are stored on handles
321 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
322 *
323 * There are three default speed sets, acessible as handles:
324 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
325 *
326 * ACPI DSDT switches which set is in use depending on various
327 * factors.
328 *
329 * IBMACPI_FAN_WR_TPEC is also available and should be used to
330 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
331 * but the ACPI tables just mention level 7.
332 */
333
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -0200334enum fan_status_access_mode {
335 IBMACPI_FAN_NONE = 0, /* No fan status or control */
336 IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
337 IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
338};
339
340enum fan_control_access_mode {
341 IBMACPI_FAN_WR_NONE = 0, /* No fan control */
342 IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
343 IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
344 IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
345};
346
347enum fan_control_commands {
348 IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
349 IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
350 IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd */
351};
352
353enum { /* Fan control constants */
354 fan_status_offset = 0x2f, /* EC register 0x2f */
355 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
356 * 0x84 must be read before 0x85 */
Henrique de Moraes Holschuhbab812a2006-11-24 11:47:12 -0200357
358 IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
359 * disengaged */
360 IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
361 * control */
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -0200362};
363
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -0200364static int ibm_thinkpad_ec_found;
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366struct ibm_struct {
367 char *name;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400368 char param[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 char *hid;
371 struct acpi_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400373 int (*init) (void);
374 int (*read) (char *);
375 int (*write) (char *);
376 void (*exit) (void);
377
378 void (*notify) (struct ibm_struct *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 acpi_handle *handle;
380 int type;
381 struct acpi_device *device;
382
383 int driver_registered;
384 int proc_created;
385 int init_called;
386 int notify_installed;
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 int experimental;
389};
390
391static struct proc_dir_entry *proc_dir = NULL;
392
Holger Macht8acb0252006-10-20 14:30:28 -0700393static struct backlight_device *ibm_backlight_device;
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
396#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
397#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
398
399static int acpi_evalf(acpi_handle handle,
400 void *res, char *method, char *fmt, ...)
401{
402 char *fmt0 = fmt;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400403 struct acpi_object_list params;
404 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
405 struct acpi_buffer result, *resultp;
406 union acpi_object out_obj;
407 acpi_status status;
408 va_list ap;
409 char res_type;
410 int success;
411 int quiet;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 if (!*fmt) {
414 printk(IBM_ERR "acpi_evalf() called with empty format\n");
415 return 0;
416 }
417
418 if (*fmt == 'q') {
419 quiet = 1;
420 fmt++;
421 } else
422 quiet = 0;
423
424 res_type = *(fmt++);
425
426 params.count = 0;
427 params.pointer = &in_objs[0];
428
429 va_start(ap, fmt);
430 while (*fmt) {
431 char c = *(fmt++);
432 switch (c) {
433 case 'd': /* int */
434 in_objs[params.count].integer.value = va_arg(ap, int);
435 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
436 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400437 /* add more types as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 default:
439 printk(IBM_ERR "acpi_evalf() called "
440 "with invalid format character '%c'\n", c);
441 return 0;
442 }
443 }
444 va_end(ap);
445
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400446 if (res_type != 'v') {
447 result.length = sizeof(out_obj);
448 result.pointer = &out_obj;
449 resultp = &result;
450 } else
451 resultp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400453 status = acpi_evaluate_object(handle, method, &params, resultp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 switch (res_type) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400456 case 'd': /* int */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (res)
458 *(int *)res = out_obj.integer.value;
459 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
460 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400461 case 'v': /* void */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 success = status == AE_OK;
463 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400464 /* add more types as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 default:
466 printk(IBM_ERR "acpi_evalf() called "
467 "with invalid format character '%c'\n", res_type);
468 return 0;
469 }
470
471 if (!success && !quiet)
472 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
473 method, fmt0, status);
474
475 return success;
476}
477
478static void __unused acpi_print_int(acpi_handle handle, char *method)
479{
480 int i;
481
482 if (acpi_evalf(handle, &i, method, "d"))
483 printk(IBM_INFO "%s = 0x%x\n", method, i);
484 else
485 printk(IBM_ERR "error calling %s\n", method);
486}
487
488static char *next_cmd(char **cmds)
489{
490 char *start = *cmds;
491 char *end;
492
493 while ((end = strchr(start, ',')) && end == start)
494 start = end + 1;
495
496 if (!end)
497 return NULL;
498
499 *end = 0;
500 *cmds = end + 1;
501 return start;
502}
503
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400504static int driver_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
506 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
507 printk(IBM_INFO "%s\n", IBM_URL);
508
509 return 0;
510}
511
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400512static int driver_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
514 int len = 0;
515
516 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
517 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
518
519 return len;
520}
521
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400522static int hotkey_supported;
523static int hotkey_mask_supported;
524static int hotkey_orig_status;
525static int hotkey_orig_mask;
526
527static int hotkey_get(int *status, int *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400530 return 0;
531
532 if (hotkey_mask_supported)
533 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
534 return 0;
535
536 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400539static int hotkey_set(int status, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
541 int i;
542
543 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 return 0;
545
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400546 if (hotkey_mask_supported)
547 for (i = 0; i < 32; i++) {
548 int bit = ((1 << i) & mask) != 0;
549 if (!acpi_evalf(hkey_handle,
550 NULL, "MHKM", "vdd", i + 1, bit))
551 return 0;
552 }
553
554 return 1;
555}
556
557static int hotkey_init(void)
558{
559 /* hotkey not supported on 570 */
560 hotkey_supported = hkey_handle != NULL;
561
562 if (hotkey_supported) {
563 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
564 A30, R30, R31, T20-22, X20-21, X22-24 */
565 hotkey_mask_supported =
566 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
567
568 if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
569 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571
572 return 0;
573}
574
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400575static int hotkey_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 int status, mask;
578 int len = 0;
579
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400580 if (!hotkey_supported) {
581 len += sprintf(p + len, "status:\t\tnot supported\n");
582 return len;
583 }
584
585 if (!hotkey_get(&status, &mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return -EIO;
587
588 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400589 if (hotkey_mask_supported) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
591 len += sprintf(p + len,
592 "commands:\tenable, disable, reset, <mask>\n");
593 } else {
594 len += sprintf(p + len, "mask:\t\tnot supported\n");
595 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
596 }
597
598 return len;
599}
600
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400601static int hotkey_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int status, mask;
604 char *cmd;
605 int do_cmd = 0;
606
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400607 if (!hotkey_supported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 return -ENODEV;
609
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400610 if (!hotkey_get(&status, &mask))
611 return -EIO;
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 while ((cmd = next_cmd(&buf))) {
614 if (strlencmp(cmd, "enable") == 0) {
615 status = 1;
616 } else if (strlencmp(cmd, "disable") == 0) {
617 status = 0;
618 } else if (strlencmp(cmd, "reset") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400619 status = hotkey_orig_status;
620 mask = hotkey_orig_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
622 /* mask set */
623 } else if (sscanf(cmd, "%x", &mask) == 1) {
624 /* mask set */
625 } else
626 return -EINVAL;
627 do_cmd = 1;
628 }
629
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400630 if (do_cmd && !hotkey_set(status, mask))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return -EIO;
632
633 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400634}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400636static void hotkey_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400638 if (hotkey_supported)
639 hotkey_set(hotkey_orig_status, hotkey_orig_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
642static void hotkey_notify(struct ibm_struct *ibm, u32 event)
643{
644 int hkey;
645
646 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
647 acpi_bus_generate_event(ibm->device, event, hkey);
648 else {
649 printk(IBM_ERR "unknown hotkey event %d\n", event);
650 acpi_bus_generate_event(ibm->device, event, 0);
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400654static int bluetooth_supported;
655
656static int bluetooth_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400658 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
659 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
660 bluetooth_supported = hkey_handle &&
661 acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 return 0;
664}
665
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400666static int bluetooth_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
668 int status;
669
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400670 if (!bluetooth_supported ||
671 !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 status = 0;
673
674 return status;
675}
676
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400677static int bluetooth_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
679 int len = 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400680 int status = bluetooth_status();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400682 if (!bluetooth_supported)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 len += sprintf(p + len, "status:\t\tnot supported\n");
684 else if (!(status & 1))
685 len += sprintf(p + len, "status:\t\tnot installed\n");
686 else {
687 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
688 len += sprintf(p + len, "commands:\tenable, disable\n");
689 }
690
691 return len;
692}
693
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400694static int bluetooth_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400696 int status = bluetooth_status();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 char *cmd;
698 int do_cmd = 0;
699
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400700 if (!bluetooth_supported)
701 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 while ((cmd = next_cmd(&buf))) {
704 if (strlencmp(cmd, "enable") == 0) {
705 status |= 2;
706 } else if (strlencmp(cmd, "disable") == 0) {
707 status &= ~2;
708 } else
709 return -EINVAL;
710 do_cmd = 1;
711 }
712
713 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 return 0;
717}
718
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400719static int wan_supported;
720
721static int wan_init(void)
722{
723 wan_supported = hkey_handle &&
724 acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
725
726 return 0;
727}
728
729static int wan_status(void)
730{
731 int status;
732
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -0200733 if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400734 status = 0;
735
736 return status;
737}
738
739static int wan_read(char *p)
740{
741 int len = 0;
742 int status = wan_status();
743
744 if (!wan_supported)
745 len += sprintf(p + len, "status:\t\tnot supported\n");
746 else if (!(status & 1))
747 len += sprintf(p + len, "status:\t\tnot installed\n");
748 else {
749 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
750 len += sprintf(p + len, "commands:\tenable, disable\n");
751 }
752
753 return len;
754}
755
756static int wan_write(char *buf)
757{
758 int status = wan_status();
759 char *cmd;
760 int do_cmd = 0;
761
762 if (!wan_supported)
763 return -ENODEV;
764
765 while ((cmd = next_cmd(&buf))) {
766 if (strlencmp(cmd, "enable") == 0) {
767 status |= 2;
768 } else if (strlencmp(cmd, "disable") == 0) {
769 status &= ~2;
770 } else
771 return -EINVAL;
772 do_cmd = 1;
773 }
774
775 if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
776 return -EIO;
777
778 return 0;
779}
780
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400781static int video_supported;
782static int video_orig_autosw;
783
784#define VIDEO_570 1
785#define VIDEO_770 2
786#define VIDEO_NEW 3
787
788static int video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400790 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 = 0;
799 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
800 /* 570 */
801 video_supported = VIDEO_570;
802 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
803 /* 600e/x, 770e, 770x */
804 video_supported = VIDEO_770;
805 else
806 /* all others */
807 video_supported = VIDEO_NEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 return 0;
810}
811
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400812static int video_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
814 int status = 0;
815 int i;
816
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400817 if (video_supported == VIDEO_570) {
818 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
819 status = i & 3;
820 } else if (video_supported == 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 == VIDEO_NEW) {
826 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
827 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
828 status |= 0x02 * i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400830 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 return status;
838}
839
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400840static int video_autosw(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400842 int autosw = 0;
843
844 if (video_supported == VIDEO_570)
845 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
846 else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW)
847 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
848
849 return autosw & 1;
850}
851
852static int video_read(char *p)
853{
854 int status = video_status();
855 int autosw = video_autosw();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 int len = 0;
857
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400858 if (!video_supported) {
859 len += sprintf(p + len, "status:\t\tnot supported\n");
860 return len;
861 }
862
863 len += sprintf(p + len, "status:\t\tsupported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
865 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400866 if (video_supported == VIDEO_NEW)
867 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
868 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
869 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
870 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
871 if (video_supported == VIDEO_NEW)
872 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
873 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
875
876 return len;
877}
878
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400879static int video_switch(void)
880{
881 int autosw = video_autosw();
882 int ret;
883
884 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
885 return -EIO;
886 ret = video_supported == VIDEO_570 ?
887 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
888 acpi_evalf(vid_handle, NULL, "VSWT", "v");
889 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
890
891 return ret;
892}
893
894static int video_expand(void)
895{
896 if (video_supported == VIDEO_570)
897 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
898 else if (video_supported == VIDEO_770)
899 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
900 else
901 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
902}
903
904static int video_switch2(int status)
905{
906 int ret;
907
908 if (video_supported == VIDEO_570) {
909 ret = acpi_evalf(NULL, NULL,
910 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
911 } else if (video_supported == VIDEO_770) {
912 int autosw = video_autosw();
913 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
914 return -EIO;
915
916 ret = acpi_evalf(vid_handle, NULL,
917 "ASWT", "vdd", status * 0x100, 0);
918
919 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
920 } else {
921 ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
922 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
923 }
924
925 return ret;
926}
927
928static int video_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
930 char *cmd;
931 int enable, disable, status;
932
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400933 if (!video_supported)
934 return -ENODEV;
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 enable = disable = 0;
937
938 while ((cmd = next_cmd(&buf))) {
939 if (strlencmp(cmd, "lcd_enable") == 0) {
940 enable |= 0x01;
941 } else if (strlencmp(cmd, "lcd_disable") == 0) {
942 disable |= 0x01;
943 } else if (strlencmp(cmd, "crt_enable") == 0) {
944 enable |= 0x02;
945 } else if (strlencmp(cmd, "crt_disable") == 0) {
946 disable |= 0x02;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400947 } else if (video_supported == VIDEO_NEW &&
948 strlencmp(cmd, "dvi_enable") == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 enable |= 0x08;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400950 } else if (video_supported == VIDEO_NEW &&
951 strlencmp(cmd, "dvi_disable") == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 disable |= 0x08;
953 } else if (strlencmp(cmd, "auto_enable") == 0) {
954 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
955 return -EIO;
956 } else if (strlencmp(cmd, "auto_disable") == 0) {
957 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
958 return -EIO;
959 } else if (strlencmp(cmd, "video_switch") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400960 if (!video_switch())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return -EIO;
962 } else if (strlencmp(cmd, "expand_toggle") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400963 if (!video_expand())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 return -EIO;
965 } else
966 return -EINVAL;
967 }
968
969 if (enable || disable) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400970 status = (video_status() & 0x0f & ~disable) | enable;
971 if (!video_switch2(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 return -EIO;
973 }
974
975 return 0;
976}
977
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400978static void video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400980 acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400983static int light_supported;
984static int light_status_supported;
985
986static int light_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400988 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
989 light_supported = (cmos_handle || lght_handle) && !ledb_handle;
990
991 if (light_supported)
992 /* light status not supported on
993 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
994 light_status_supported = acpi_evalf(ec_handle, NULL,
995 "KBLT", "qv");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 return 0;
998}
999
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001000static int light_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 int len = 0;
1003 int status = 0;
1004
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001005 if (!light_supported) {
1006 len += sprintf(p + len, "status:\t\tnot supported\n");
1007 } else if (!light_status_supported) {
1008 len += sprintf(p + len, "status:\t\tunknown\n");
1009 len += sprintf(p + len, "commands:\ton, off\n");
1010 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1012 return -EIO;
1013 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001014 len += sprintf(p + len, "commands:\ton, off\n");
1015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 return len;
1018}
1019
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001020static int light_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
1022 int cmos_cmd, lght_cmd;
1023 char *cmd;
1024 int success;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001025
1026 if (!light_supported)
1027 return -ENODEV;
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 while ((cmd = next_cmd(&buf))) {
1030 if (strlencmp(cmd, "on") == 0) {
1031 cmos_cmd = 0x0c;
1032 lght_cmd = 1;
1033 } else if (strlencmp(cmd, "off") == 0) {
1034 cmos_cmd = 0x0d;
1035 lght_cmd = 0;
1036 } else
1037 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 success = cmos_handle ?
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001040 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1041 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (!success)
1043 return -EIO;
1044 }
1045
1046 return 0;
1047}
1048
1049static int _sta(acpi_handle handle)
1050{
1051 int status;
1052
1053 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
1054 status = 0;
1055
1056 return status;
1057}
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -02001058
Kristen Accardi63e5f242006-02-23 17:56:06 -08001059#ifdef CONFIG_ACPI_IBM_DOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060#define dock_docked() (_sta(dock_handle) & 1)
1061
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001062static int dock_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 int len = 0;
1065 int docked = dock_docked();
1066
1067 if (!dock_handle)
1068 len += sprintf(p + len, "status:\t\tnot supported\n");
1069 else if (!docked)
1070 len += sprintf(p + len, "status:\t\tundocked\n");
1071 else {
1072 len += sprintf(p + len, "status:\t\tdocked\n");
1073 len += sprintf(p + len, "commands:\tdock, undock\n");
1074 }
1075
1076 return len;
1077}
1078
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001079static int dock_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
1081 char *cmd;
1082
1083 if (!dock_docked())
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001084 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 while ((cmd = next_cmd(&buf))) {
1087 if (strlencmp(cmd, "undock") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001088 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1089 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 return -EIO;
1091 } else if (strlencmp(cmd, "dock") == 0) {
1092 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1093 return -EIO;
1094 } else
1095 return -EINVAL;
1096 }
1097
1098 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001099}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101static void dock_notify(struct ibm_struct *ibm, u32 event)
1102{
1103 int docked = dock_docked();
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001104 int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001106 if (event == 1 && !pci) /* 570 */
1107 acpi_bus_generate_event(ibm->device, event, 1); /* button */
1108 else if (event == 1 && pci) /* 570 */
1109 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
1110 else if (event == 3 && docked)
1111 acpi_bus_generate_event(ibm->device, event, 1); /* button */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 else if (event == 3 && !docked)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001113 acpi_bus_generate_event(ibm->device, event, 2); /* undock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 else if (event == 0 && docked)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001115 acpi_bus_generate_event(ibm->device, event, 3); /* dock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 else {
1117 printk(IBM_ERR "unknown dock event %d, status %d\n",
1118 event, _sta(dock_handle));
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001119 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121}
Kristen Accardi63e5f242006-02-23 17:56:06 -08001122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001124static int bay_status_supported;
1125static int bay_status2_supported;
1126static int bay_eject_supported;
1127static int bay_eject2_supported;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001129static int bay_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001131 bay_status_supported = bay_handle &&
1132 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1133 bay_status2_supported = bay2_handle &&
1134 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
1135
1136 bay_eject_supported = bay_handle && bay_ej_handle &&
1137 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1138 bay_eject2_supported = bay2_handle && bay2_ej_handle &&
1139 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 return 0;
1142}
1143
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001144#define bay_occupied(b) (_sta(b##_handle) & 1)
1145
1146static int bay_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
1148 int len = 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001149 int occupied = bay_occupied(bay);
1150 int occupied2 = bay_occupied(bay2);
1151 int eject, eject2;
1152
1153 len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ?
1154 (occupied ? "occupied" : "unoccupied") :
1155 "not supported");
1156 if (bay_status2_supported)
1157 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1158 "occupied" : "unoccupied");
1159
1160 eject = bay_eject_supported && occupied;
1161 eject2 = bay_eject2_supported && occupied2;
1162
1163 if (eject && eject2)
1164 len += sprintf(p + len, "commands:\teject, eject2\n");
1165 else if (eject)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 len += sprintf(p + len, "commands:\teject\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001167 else if (eject2)
1168 len += sprintf(p + len, "commands:\teject2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 return len;
1171}
1172
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001173static int bay_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
1175 char *cmd;
1176
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001177 if (!bay_eject_supported && !bay_eject2_supported)
1178 return -ENODEV;
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001181 if (bay_eject_supported && strlencmp(cmd, "eject") == 0) {
1182 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1183 return -EIO;
1184 } else if (bay_eject2_supported &&
1185 strlencmp(cmd, "eject2") == 0) {
1186 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 return -EIO;
1188 } else
1189 return -EINVAL;
1190 }
1191
1192 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001193}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195static void bay_notify(struct ibm_struct *ibm, u32 event)
1196{
1197 acpi_bus_generate_event(ibm->device, event, 0);
1198}
1199
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001200static int cmos_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
1202 int len = 0;
1203
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001204 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1205 R30, R31, T20-22, X20-21 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 if (!cmos_handle)
1207 len += sprintf(p + len, "status:\t\tnot supported\n");
1208 else {
1209 len += sprintf(p + len, "status:\t\tsupported\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001210 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
1212
1213 return len;
1214}
1215
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001216static int cmos_eval(int cmos_cmd)
1217{
1218 if (cmos_handle)
1219 return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
1220 else
1221 return 1;
1222}
1223
1224static int cmos_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
1226 char *cmd;
1227 int cmos_cmd;
1228
1229 if (!cmos_handle)
1230 return -EINVAL;
1231
1232 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001233 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1234 cmos_cmd >= 0 && cmos_cmd <= 21) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 /* cmos_cmd set */
1236 } else
1237 return -EINVAL;
1238
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001239 if (!cmos_eval(cmos_cmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 return -EIO;
1241 }
1242
1243 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001244}
1245
1246static int led_supported;
1247
1248#define LED_570 1
1249#define LED_OLD 2
1250#define LED_NEW 3
1251
1252static int led_init(void)
1253{
1254 if (!led_handle)
1255 /* led not supported on R30, R31 */
1256 led_supported = 0;
1257 else if (strlencmp(led_path, "SLED") == 0)
1258 /* 570 */
1259 led_supported = LED_570;
1260 else if (strlencmp(led_path, "SYSL") == 0)
1261 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1262 led_supported = LED_OLD;
1263 else
1264 /* all others */
1265 led_supported = LED_NEW;
1266
1267 return 0;
1268}
1269
1270#define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1271
1272static int led_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
1274 int len = 0;
1275
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001276 if (!led_supported) {
1277 len += sprintf(p + len, "status:\t\tnot supported\n");
1278 return len;
1279 }
1280 len += sprintf(p + len, "status:\t\tsupported\n");
1281
1282 if (led_supported == LED_570) {
1283 /* 570 */
1284 int i, status;
1285 for (i = 0; i < 8; i++) {
1286 if (!acpi_evalf(ec_handle,
1287 &status, "GLED", "dd", 1 << i))
1288 return -EIO;
1289 len += sprintf(p + len, "%d:\t\t%s\n",
1290 i, led_status(status));
1291 }
1292 }
1293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 len += sprintf(p + len, "commands:\t"
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001295 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 return len;
1298}
1299
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001300/* off, on, blink */
1301static const int led_sled_arg1[] = { 0, 1, 3 };
1302static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1303static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1304static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1305
1306#define EC_HLCL 0x0c
1307#define EC_HLBL 0x0d
1308#define EC_HLMS 0x0e
1309
1310static int led_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
1312 char *cmd;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001313 int led, ind, ret;
1314
1315 if (!led_supported)
1316 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001319 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 return -EINVAL;
1321
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001322 if (strstr(cmd, "off")) {
1323 ind = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 } else if (strstr(cmd, "on")) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001325 ind = 1;
1326 } else if (strstr(cmd, "blink")) {
1327 ind = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 } else
1329 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001330
1331 if (led_supported == LED_570) {
1332 /* 570 */
1333 led = 1 << led;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001335 led, led_sled_arg1[ind]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001337 } else if (led_supported == LED_OLD) {
1338 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1339 led = 1 << led;
1340 ret = ec_write(EC_HLMS, led);
1341 if (ret >= 0)
1342 ret =
1343 ec_write(EC_HLBL, led * led_exp_hlbl[ind]);
1344 if (ret >= 0)
1345 ret =
1346 ec_write(EC_HLCL, led * led_exp_hlcl[ind]);
1347 if (ret < 0)
1348 return ret;
1349 } else {
1350 /* all others */
1351 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1352 led, led_led_arg1[ind]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 }
1356
1357 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001358}
1359
1360static int beep_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
1362 int len = 0;
1363
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001364 if (!beep_handle)
1365 len += sprintf(p + len, "status:\t\tnot supported\n");
1366 else {
1367 len += sprintf(p + len, "status:\t\tsupported\n");
1368 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 return len;
1372}
1373
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001374static int beep_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
1376 char *cmd;
1377 int beep_cmd;
1378
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001379 if (!beep_handle)
1380 return -ENODEV;
1381
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001383 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1384 beep_cmd >= 0 && beep_cmd <= 17) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /* beep_cmd set */
1386 } else
1387 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001388 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 return -EIO;
1390 }
1391
1392 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001393}
1394
1395static int acpi_ec_read(int i, u8 * p)
1396{
1397 int v;
1398
1399 if (ecrd_handle) {
1400 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
1401 return 0;
1402 *p = v;
1403 } else {
1404 if (ec_read(i, p) < 0)
1405 return 0;
1406 }
1407
1408 return 1;
1409}
1410
1411static int acpi_ec_write(int i, u8 v)
1412{
1413 if (ecwr_handle) {
1414 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
1415 return 0;
1416 } else {
1417 if (ec_write(i, v) < 0)
1418 return 0;
1419 }
1420
1421 return 1;
1422}
1423
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001424static enum thermal_access_mode thermal_read_mode;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001425
1426static int thermal_init(void)
1427{
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001428 u8 t, ta1, ta2;
1429 int i;
1430 int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1431
1432 if (ibm_thinkpad_ec_found && experimental) {
1433 /*
1434 * Direct EC access mode: sensors at registers
1435 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1436 * non-implemented, thermal sensors return 0x80 when
1437 * not available
1438 */
1439
1440 ta1 = ta2 = 0;
1441 for (i = 0; i < 8; i++) {
1442 if (likely(acpi_ec_read(0x78 + i, &t))) {
1443 ta1 |= t;
1444 } else {
1445 ta1 = 0;
1446 break;
1447 }
1448 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1449 ta2 |= t;
1450 } else {
1451 ta1 = 0;
1452 break;
1453 }
1454 }
1455 if (ta1 == 0) {
1456 /* This is sheer paranoia, but we handle it anyway */
1457 if (acpi_tmp7) {
1458 printk(IBM_ERR
1459 "ThinkPad ACPI EC access misbehaving, "
1460 "falling back to ACPI TMPx access mode\n");
1461 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1462 } else {
1463 printk(IBM_ERR
1464 "ThinkPad ACPI EC access misbehaving, "
1465 "disabling thermal sensors access\n");
1466 thermal_read_mode = IBMACPI_THERMAL_NONE;
1467 }
1468 } else {
1469 thermal_read_mode =
1470 (ta2 != 0) ?
1471 IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
1472 }
1473 } else if (acpi_tmp7) {
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001474 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1475 /* 600e/x, 770e, 770x */
1476 thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
1477 } else {
1478 /* Standard ACPI TMPx access, max 8 sensors */
1479 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1480 }
1481 } else {
1482 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1483 thermal_read_mode = IBMACPI_THERMAL_NONE;
1484 }
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001485
1486 return 0;
1487}
1488
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001489static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1490{
1491 int i, t;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001492 s8 tmp;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001493 char tmpi[] = "TMPi";
1494
1495 if (!s)
1496 return -EINVAL;
1497
1498 switch (thermal_read_mode) {
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001499#if IBMACPI_MAX_THERMAL_SENSORS >= 16
1500 case IBMACPI_THERMAL_TPEC_16:
1501 for (i = 0; i < 8; i++) {
1502 if (!acpi_ec_read(0xC0 + i, &tmp))
1503 return -EIO;
1504 s->temp[i + 8] = tmp * 1000;
1505 }
1506 /* fallthrough */
1507#endif
1508 case IBMACPI_THERMAL_TPEC_8:
1509 for (i = 0; i < 8; i++) {
1510 if (!acpi_ec_read(0x78 + i, &tmp))
1511 return -EIO;
1512 s->temp[i] = tmp * 1000;
1513 }
1514 return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
1515
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001516 case IBMACPI_THERMAL_ACPI_UPDT:
1517 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1518 return -EIO;
1519 for (i = 0; i < 8; i++) {
1520 tmpi[3] = '0' + i;
1521 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1522 return -EIO;
1523 s->temp[i] = (t - 2732) * 100;
1524 }
1525 return 8;
1526
1527 case IBMACPI_THERMAL_ACPI_TMP07:
1528 for (i = 0; i < 8; i++) {
1529 tmpi[3] = '0' + i;
1530 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1531 return -EIO;
1532 s->temp[i] = t * 1000;
1533 }
1534 return 8;
1535
1536 case IBMACPI_THERMAL_NONE:
1537 default:
1538 return 0;
1539 }
1540}
1541
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001542static int thermal_read(char *p)
1543{
1544 int len = 0;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001545 int n, i;
1546 struct ibm_thermal_sensors_struct t;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001547
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001548 n = thermal_get_sensors(&t);
1549 if (unlikely(n < 0))
1550 return n;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001551
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001552 len += sprintf(p + len, "temperatures:\t");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001553
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001554 if (n > 0) {
1555 for (i = 0; i < (n - 1); i++)
1556 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1557 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1558 } else
1559 len += sprintf(p + len, "not supported\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001560
1561 return len;
1562}
1563
1564static u8 ecdump_regs[256];
1565
1566static int ecdump_read(char *p)
1567{
1568 int len = 0;
1569 int i, j;
1570 u8 v;
1571
1572 len += sprintf(p + len, "EC "
1573 " +00 +01 +02 +03 +04 +05 +06 +07"
1574 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1575 for (i = 0; i < 256; i += 16) {
1576 len += sprintf(p + len, "EC 0x%02x:", i);
1577 for (j = 0; j < 16; j++) {
1578 if (!acpi_ec_read(i + j, &v))
1579 break;
1580 if (v != ecdump_regs[i + j])
1581 len += sprintf(p + len, " *%02x", v);
1582 else
1583 len += sprintf(p + len, " %02x", v);
1584 ecdump_regs[i + j] = v;
1585 }
1586 len += sprintf(p + len, "\n");
1587 if (j != 16)
1588 break;
1589 }
1590
1591 /* These are way too dangerous to advertise openly... */
1592#if 0
1593 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
1594 " (<offset> is 00-ff, <value> is 00-ff)\n");
1595 len += sprintf(p + len, "commands:\t0x<offset> <value> "
1596 " (<offset> is 00-ff, <value> is 0-255)\n");
1597#endif
1598 return len;
1599}
1600
1601static int ecdump_write(char *buf)
1602{
1603 char *cmd;
1604 int i, v;
1605
1606 while ((cmd = next_cmd(&buf))) {
1607 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
1608 /* i and v set */
1609 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
1610 /* i and v set */
1611 } else
1612 return -EINVAL;
1613 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
1614 if (!acpi_ec_write(i, v))
1615 return -EIO;
1616 } else
1617 return -EINVAL;
1618 }
1619
1620 return 0;
1621}
1622
1623static int brightness_offset = 0x31;
1624
Holger Macht8acb0252006-10-20 14:30:28 -07001625static int brightness_get(struct backlight_device *bd)
1626{
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -02001627 u8 level;
1628 if (!acpi_ec_read(brightness_offset, &level))
1629 return -EIO;
Holger Macht8acb0252006-10-20 14:30:28 -07001630
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -02001631 level &= 0x7;
1632 return level;
Holger Macht8acb0252006-10-20 14:30:28 -07001633}
1634
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001635static int brightness_read(char *p)
1636{
1637 int len = 0;
Holger Macht8acb0252006-10-20 14:30:28 -07001638 int level;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001639
Holger Macht8acb0252006-10-20 14:30:28 -07001640 if ((level = brightness_get(NULL)) < 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001641 len += sprintf(p + len, "level:\t\tunreadable\n");
1642 } else {
1643 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
1644 len += sprintf(p + len, "commands:\tup, down\n");
1645 len += sprintf(p + len, "commands:\tlevel <level>"
1646 " (<level> is 0-7)\n");
1647 }
1648
1649 return len;
1650}
1651
1652#define BRIGHTNESS_UP 4
1653#define BRIGHTNESS_DOWN 5
1654
Holger Macht8acb0252006-10-20 14:30:28 -07001655static int brightness_set(int value)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001656{
1657 int cmos_cmd, inc, i;
Holger Macht8acb0252006-10-20 14:30:28 -07001658 int current_value = brightness_get(NULL);
1659
1660 value &= 7;
1661
1662 cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
1663 inc = value > current_value ? 1 : -1;
1664 for (i = current_value; i != value; i += inc) {
1665 if (!cmos_eval(cmos_cmd))
1666 return -EIO;
1667 if (!acpi_ec_write(brightness_offset, i + inc))
1668 return -EIO;
1669 }
1670
1671 return 0;
1672}
1673
1674static int brightness_write(char *buf)
1675{
1676 int level;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001677 int new_level;
1678 char *cmd;
1679
1680 while ((cmd = next_cmd(&buf))) {
Holger Macht8acb0252006-10-20 14:30:28 -07001681 if ((level = brightness_get(NULL)) < 0)
1682 return level;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001683 level &= 7;
1684
1685 if (strlencmp(cmd, "up") == 0) {
1686 new_level = level == 7 ? 7 : level + 1;
1687 } else if (strlencmp(cmd, "down") == 0) {
1688 new_level = level == 0 ? 0 : level - 1;
1689 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1690 new_level >= 0 && new_level <= 7) {
1691 /* new_level set */
1692 } else
1693 return -EINVAL;
1694
Holger Macht8acb0252006-10-20 14:30:28 -07001695 brightness_set(new_level);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001696 }
1697
1698 return 0;
1699}
1700
Holger Macht8acb0252006-10-20 14:30:28 -07001701static int brightness_update_status(struct backlight_device *bd)
1702{
1703 return brightness_set(bd->props->brightness);
1704}
1705
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001706static int volume_offset = 0x30;
1707
1708static int volume_read(char *p)
1709{
1710 int len = 0;
1711 u8 level;
1712
1713 if (!acpi_ec_read(volume_offset, &level)) {
1714 len += sprintf(p + len, "level:\t\tunreadable\n");
1715 } else {
1716 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
1717 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
1718 len += sprintf(p + len, "commands:\tup, down, mute\n");
1719 len += sprintf(p + len, "commands:\tlevel <level>"
1720 " (<level> is 0-15)\n");
1721 }
1722
1723 return len;
1724}
1725
1726#define VOLUME_DOWN 0
1727#define VOLUME_UP 1
1728#define VOLUME_MUTE 2
1729
1730static int volume_write(char *buf)
1731{
1732 int cmos_cmd, inc, i;
1733 u8 level, mute;
1734 int new_level, new_mute;
1735 char *cmd;
1736
1737 while ((cmd = next_cmd(&buf))) {
1738 if (!acpi_ec_read(volume_offset, &level))
1739 return -EIO;
1740 new_mute = mute = level & 0x40;
1741 new_level = level = level & 0xf;
1742
1743 if (strlencmp(cmd, "up") == 0) {
1744 if (mute)
1745 new_mute = 0;
1746 else
1747 new_level = level == 15 ? 15 : level + 1;
1748 } else if (strlencmp(cmd, "down") == 0) {
1749 if (mute)
1750 new_mute = 0;
1751 else
1752 new_level = level == 0 ? 0 : level - 1;
1753 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
1754 new_level >= 0 && new_level <= 15) {
1755 /* new_level set */
1756 } else if (strlencmp(cmd, "mute") == 0) {
1757 new_mute = 0x40;
1758 } else
1759 return -EINVAL;
1760
1761 if (new_level != level) { /* mute doesn't change */
1762 cmos_cmd = new_level > level ? VOLUME_UP : VOLUME_DOWN;
1763 inc = new_level > level ? 1 : -1;
1764
1765 if (mute && (!cmos_eval(cmos_cmd) ||
1766 !acpi_ec_write(volume_offset, level)))
1767 return -EIO;
1768
1769 for (i = level; i != new_level; i += inc)
1770 if (!cmos_eval(cmos_cmd) ||
1771 !acpi_ec_write(volume_offset, i + inc))
1772 return -EIO;
1773
1774 if (mute && (!cmos_eval(VOLUME_MUTE) ||
1775 !acpi_ec_write(volume_offset,
1776 new_level + mute)))
1777 return -EIO;
1778 }
1779
1780 if (new_mute != mute) { /* level doesn't change */
1781 cmos_cmd = new_mute ? VOLUME_MUTE : VOLUME_UP;
1782
1783 if (!cmos_eval(cmos_cmd) ||
1784 !acpi_ec_write(volume_offset, level + new_mute))
1785 return -EIO;
1786 }
1787 }
1788
1789 return 0;
1790}
1791
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02001792static enum fan_status_access_mode fan_status_access_mode;
1793static enum fan_control_access_mode fan_control_access_mode;
1794static enum fan_control_commands fan_control_commands;
1795
1796static int fan_init(void)
1797{
1798 u8 status;
1799
1800 fan_status_access_mode = IBMACPI_FAN_NONE;
1801 fan_control_access_mode = IBMACPI_FAN_WR_NONE;
1802 fan_control_commands = 0;
1803
1804 if (gfan_handle) {
1805 /* 570, 600e/x, 770e, 770x */
1806 fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
1807 } else {
1808 /* all other ThinkPads: note that even old-style
1809 * ThinkPad ECs supports the fan control register */
1810 if (likely(acpi_ec_read(fan_status_offset, &status))) {
1811 fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
1812 } else {
1813 printk(IBM_ERR
1814 "ThinkPad ACPI EC access misbehaving, "
1815 "fan status and control unavailable\n");
1816 return 0;
1817 }
1818 }
1819
1820 if (sfan_handle) {
1821 /* 570, 770x-JL */
1822 fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02001823 fan_control_commands |=
1824 IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02001825 } else {
1826 if (!gfan_handle) {
1827 /* gfan without sfan means no fan control */
1828 /* all other models implement TP EC 0x2f control */
1829
1830 if (fans_handle) {
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02001831 /* X31, X40, X41 */
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02001832 fan_control_access_mode =
1833 IBMACPI_FAN_WR_ACPI_FANS;
1834 fan_control_commands |=
1835 IBMACPI_FAN_CMD_SPEED |
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02001836 IBMACPI_FAN_CMD_LEVEL |
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02001837 IBMACPI_FAN_CMD_ENABLE;
1838 } else {
1839 fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02001840 fan_control_commands |=
1841 IBMACPI_FAN_CMD_LEVEL |
1842 IBMACPI_FAN_CMD_ENABLE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02001843 }
1844 }
1845 }
1846
1847 return 0;
1848}
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001849
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001850static int fan_get_status(u8 *status)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001851{
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001852 u8 s;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001853
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02001854 /* TODO:
1855 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1856
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001857 switch (fan_status_access_mode) {
1858 case IBMACPI_FAN_RD_ACPI_GFAN:
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001859 /* 570, 600e/x, 770e, 770x */
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001860
1861 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001862 return -EIO;
1863
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001864 if (likely(status))
1865 *status = s & 0x07;
1866
1867 break;
1868
1869 case IBMACPI_FAN_RD_TPEC:
1870 /* all except 570, 600e/x, 770e, 770x */
1871 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
1872 return -EIO;
1873
1874 if (likely(status))
1875 *status = s;
1876
1877 break;
1878
1879 default:
1880 return -ENXIO;
1881 }
1882
1883 return 0;
1884}
1885
1886static int fan_get_speed(unsigned int *speed)
1887{
1888 u8 hi, lo;
1889
1890 switch (fan_status_access_mode) {
1891 case IBMACPI_FAN_RD_TPEC:
1892 /* all except 570, 600e/x, 770e, 770x */
1893 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
1894 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
1895 return -EIO;
1896
1897 if (likely(speed))
1898 *speed = (hi << 8) | lo;
1899
1900 break;
1901
1902 default:
1903 return -ENXIO;
1904 }
1905
1906 return 0;
1907}
1908
1909static int fan_read(char *p)
1910{
1911 int len = 0;
1912 int rc;
1913 u8 status;
1914 unsigned int speed = 0;
1915
1916 switch (fan_status_access_mode) {
1917 case IBMACPI_FAN_RD_ACPI_GFAN:
1918 /* 570, 600e/x, 770e, 770x */
1919 if ((rc = fan_get_status(&status)) < 0)
1920 return rc;
1921
Henrique de Moraes Holschuhbab812a2006-11-24 11:47:12 -02001922 len += sprintf(p + len, "status:\t\t%s\n"
1923 "level:\t\t%d\n",
1924 (status != 0) ? "enabled" : "disabled", status);
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001925 break;
1926
1927 case IBMACPI_FAN_RD_TPEC:
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001928 /* all except 570, 600e/x, 770e, 770x */
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001929 if ((rc = fan_get_status(&status)) < 0)
1930 return rc;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001931
Henrique de Moraes Holschuhbab812a2006-11-24 11:47:12 -02001932 len += sprintf(p + len, "status:\t\t%s\n",
1933 (status != 0) ? "enabled" : "disabled");
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001934
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02001935 if ((rc = fan_get_speed(&speed)) < 0)
1936 return rc;
1937
1938 len += sprintf(p + len, "speed:\t\t%d\n", speed);
Henrique de Moraes Holschuhbab812a2006-11-24 11:47:12 -02001939
1940 if (status & IBMACPI_FAN_EC_DISENGAGED)
1941 /* Disengaged mode takes precedence */
1942 len += sprintf(p + len, "level:\t\tdisengaged\n");
1943 else if (status & IBMACPI_FAN_EC_AUTO)
1944 len += sprintf(p + len, "level:\t\tauto\n");
1945 else
1946 len += sprintf(p + len, "level:\t\t%d\n", status);
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001947 break;
1948
1949 case IBMACPI_FAN_NONE:
1950 default:
1951 len += sprintf(p + len, "status:\t\tnot supported\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001952 }
1953
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02001954 if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
1955 len += sprintf(p + len, "commands:\tlevel <level>");
1956
1957 switch (fan_control_access_mode) {
1958 case IBMACPI_FAN_WR_ACPI_SFAN:
1959 len += sprintf(p + len, " (<level> is 0-7)\n");
1960 break;
1961
1962 default:
1963 len += sprintf(p + len, " (<level> is 0-7, "
1964 "auto, disengaged)\n");
1965 break;
1966 }
1967 }
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001968
1969 if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001970 len += sprintf(p + len, "commands:\tenable, disable\n");
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02001971
1972 if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001973 len += sprintf(p + len, "commands:\tspeed <speed>"
1974 " (<speed> is 0-65535)\n");
1975
1976 return len;
1977}
1978
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02001979static int fan_set_level(int level)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001980{
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02001981 switch (fan_control_access_mode) {
1982 case IBMACPI_FAN_WR_ACPI_SFAN:
1983 if (level >= 0 && level <= 7) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001984 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
1985 return -EIO;
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02001986 } else
1987 return -EINVAL;
1988 break;
1989
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02001990 case IBMACPI_FAN_WR_ACPI_FANS:
1991 case IBMACPI_FAN_WR_TPEC:
1992 if ((level != IBMACPI_FAN_EC_AUTO) &&
1993 (level != IBMACPI_FAN_EC_DISENGAGED) &&
1994 ((level < 0) || (level > 7)))
1995 return -EINVAL;
1996
1997 if (!acpi_ec_write(fan_status_offset, level))
1998 return -EIO;
1999 break;
2000
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002001 default:
2002 return -ENXIO;
2003 }
2004 return 0;
2005}
2006
2007static int fan_set_enable(void)
2008{
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002009 u8 s;
2010 int rc;
2011
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002012 switch (fan_control_access_mode) {
2013 case IBMACPI_FAN_WR_ACPI_FANS:
2014 case IBMACPI_FAN_WR_TPEC:
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002015 if ((rc = fan_get_status(&s)) < 0)
2016 return rc;
2017
2018 /* Don't go out of emergency fan mode */
2019 if (s != 7)
2020 s = IBMACPI_FAN_EC_AUTO;
2021
2022 if (!acpi_ec_write(fan_status_offset, s))
2023 return -EIO;
2024 break;
2025
2026 case IBMACPI_FAN_WR_ACPI_SFAN:
2027 if ((rc = fan_get_status(&s)) < 0)
2028 return rc;
2029
2030 s &= 0x07;
2031
2032 /* Set fan to at least level 4 */
2033 if (s < 4)
2034 s = 4;
2035
2036 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002037 return -EIO;
2038 break;
2039
2040 default:
2041 return -ENXIO;
2042 }
2043 return 0;
2044}
2045
2046static int fan_set_disable(void)
2047{
2048 switch (fan_control_access_mode) {
2049 case IBMACPI_FAN_WR_ACPI_FANS:
2050 case IBMACPI_FAN_WR_TPEC:
2051 if (!acpi_ec_write(fan_status_offset, 0x00))
2052 return -EIO;
2053 break;
2054
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002055 case IBMACPI_FAN_WR_ACPI_SFAN:
2056 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2057 return -EIO;
2058 break;
2059
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002060 default:
2061 return -ENXIO;
2062 }
2063 return 0;
2064}
2065
2066static int fan_set_speed(int speed)
2067{
2068 switch (fan_control_access_mode) {
2069 case IBMACPI_FAN_WR_ACPI_FANS:
2070 if (speed >= 0 && speed <= 65535) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002071 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2072 speed, speed, speed))
2073 return -EIO;
2074 } else
2075 return -EINVAL;
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002076 break;
2077
2078 default:
2079 return -ENXIO;
2080 }
2081 return 0;
2082}
2083
2084static int fan_write_cmd_level(const char *cmd, int *rc)
2085{
2086 int level;
2087
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002088 if (strlencmp(cmd, "level auto") == 0)
2089 level = IBMACPI_FAN_EC_AUTO;
2090 else if (strlencmp(cmd, "level disengaged") == 0)
2091 level = IBMACPI_FAN_EC_DISENGAGED;
2092 else if (sscanf(cmd, "level %d", &level) != 1)
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002093 return 0;
2094
2095 if ((*rc = fan_set_level(level)) == -ENXIO)
2096 printk(IBM_ERR "level command accepted for unsupported "
2097 "access mode %d", fan_control_access_mode);
2098
2099 return 1;
2100}
2101
2102static int fan_write_cmd_enable(const char *cmd, int *rc)
2103{
2104 if (strlencmp(cmd, "enable") != 0)
2105 return 0;
2106
2107 if ((*rc = fan_set_enable()) == -ENXIO)
2108 printk(IBM_ERR "enable command accepted for unsupported "
2109 "access mode %d", fan_control_access_mode);
2110
2111 return 1;
2112}
2113
2114static int fan_write_cmd_disable(const char *cmd, int *rc)
2115{
2116 if (strlencmp(cmd, "disable") != 0)
2117 return 0;
2118
2119 if ((*rc = fan_set_disable()) == -ENXIO)
2120 printk(IBM_ERR "disable command accepted for unsupported "
2121 "access mode %d", fan_control_access_mode);
2122
2123 return 1;
2124}
2125
2126static int fan_write_cmd_speed(const char *cmd, int *rc)
2127{
2128 int speed;
2129
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02002130 /* TODO:
2131 * Support speed <low> <medium> <high> ? */
2132
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002133 if (sscanf(cmd, "speed %d", &speed) != 1)
2134 return 0;
2135
2136 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2137 printk(IBM_ERR "speed command accepted for unsupported "
2138 "access mode %d", fan_control_access_mode);
2139
2140 return 1;
2141}
2142
2143static int fan_write(char *buf)
2144{
2145 char *cmd;
2146 int rc = 0;
2147
2148 while (!rc && (cmd = next_cmd(&buf))) {
2149 if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
2150 fan_write_cmd_level(cmd, &rc)) &&
2151 !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
2152 (fan_write_cmd_enable(cmd, &rc) ||
2153 fan_write_cmd_disable(cmd, &rc))) &&
2154 !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
2155 fan_write_cmd_speed(cmd, &rc))
2156 )
2157 rc = -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002158 }
2159
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002160 return rc;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002161}
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163static struct ibm_struct ibms[] = {
2164 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002165 .name = "driver",
2166 .init = driver_init,
2167 .read = driver_read,
2168 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002170 .name = "hotkey",
2171 .hid = IBM_HKEY_HID,
2172 .init = hotkey_init,
2173 .read = hotkey_read,
2174 .write = hotkey_write,
2175 .exit = hotkey_exit,
2176 .notify = hotkey_notify,
2177 .handle = &hkey_handle,
2178 .type = ACPI_DEVICE_NOTIFY,
2179 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002181 .name = "bluetooth",
2182 .init = bluetooth_init,
2183 .read = bluetooth_read,
2184 .write = bluetooth_write,
2185 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 {
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -04002187 .name = "wan",
2188 .init = wan_init,
2189 .read = wan_read,
2190 .write = wan_write,
2191 .experimental = 1,
2192 },
2193 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002194 .name = "video",
2195 .init = video_init,
2196 .read = video_read,
2197 .write = video_write,
2198 .exit = video_exit,
2199 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002201 .name = "light",
2202 .init = light_init,
2203 .read = light_read,
2204 .write = light_write,
2205 },
Kristen Accardi63e5f242006-02-23 17:56:06 -08002206#ifdef CONFIG_ACPI_IBM_DOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002208 .name = "dock",
2209 .read = dock_read,
2210 .write = dock_write,
2211 .notify = dock_notify,
2212 .handle = &dock_handle,
2213 .type = ACPI_SYSTEM_NOTIFY,
2214 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002216 .name = "dock",
2217 .hid = IBM_PCI_HID,
2218 .notify = dock_notify,
2219 .handle = &pci_handle,
2220 .type = ACPI_SYSTEM_NOTIFY,
2221 },
Kristen Accardi63e5f242006-02-23 17:56:06 -08002222#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002224 .name = "bay",
2225 .init = bay_init,
2226 .read = bay_read,
2227 .write = bay_write,
2228 .notify = bay_notify,
2229 .handle = &bay_handle,
2230 .type = ACPI_SYSTEM_NOTIFY,
2231 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002233 .name = "cmos",
2234 .read = cmos_read,
2235 .write = cmos_write,
2236 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002238 .name = "led",
2239 .init = led_init,
2240 .read = led_read,
2241 .write = led_write,
2242 },
2243 {
2244 .name = "beep",
2245 .read = beep_read,
2246 .write = beep_write,
2247 },
2248 {
2249 .name = "thermal",
2250 .init = thermal_init,
2251 .read = thermal_read,
2252 },
2253 {
2254 .name = "ecdump",
2255 .read = ecdump_read,
2256 .write = ecdump_write,
2257 .experimental = 1,
2258 },
2259 {
2260 .name = "brightness",
2261 .read = brightness_read,
2262 .write = brightness_write,
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002263 },
2264 {
2265 .name = "volume",
2266 .read = volume_read,
2267 .write = volume_write,
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002268 },
2269 {
2270 .name = "fan",
2271 .read = fan_read,
2272 .write = fan_write,
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002273 .init = fan_init,
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002274 .experimental = 1,
2275 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278static int dispatch_read(char *page, char **start, off_t off, int count,
2279 int *eof, void *data)
2280{
2281 struct ibm_struct *ibm = (struct ibm_struct *)data;
2282 int len;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (!ibm || !ibm->read)
2285 return -EINVAL;
2286
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002287 len = ibm->read(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 if (len < 0)
2289 return len;
2290
2291 if (len <= off + count)
2292 *eof = 1;
2293 *start = page + off;
2294 len -= off;
2295 if (len > count)
2296 len = count;
2297 if (len < 0)
2298 len = 0;
2299
2300 return len;
2301}
2302
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002303static int dispatch_write(struct file *file, const char __user * userbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 unsigned long count, void *data)
2305{
2306 struct ibm_struct *ibm = (struct ibm_struct *)data;
2307 char *kernbuf;
2308 int ret;
2309
2310 if (!ibm || !ibm->write)
2311 return -EINVAL;
2312
2313 kernbuf = kmalloc(count + 2, GFP_KERNEL);
2314 if (!kernbuf)
2315 return -ENOMEM;
2316
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002317 if (copy_from_user(kernbuf, userbuf, count)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 kfree(kernbuf);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002319 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
2321
2322 kernbuf[count] = 0;
2323 strcat(kernbuf, ",");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002324 ret = ibm->write(kernbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 if (ret == 0)
2326 ret = count;
2327
2328 kfree(kernbuf);
2329
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002330 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333static void dispatch_notify(acpi_handle handle, u32 event, void *data)
2334{
2335 struct ibm_struct *ibm = (struct ibm_struct *)data;
2336
2337 if (!ibm || !ibm->notify)
2338 return;
2339
2340 ibm->notify(ibm, event);
2341}
2342
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002343static int __init setup_notify(struct ibm_struct *ibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344{
2345 acpi_status status;
2346 int ret;
2347
2348 if (!*ibm->handle)
2349 return 0;
2350
2351 ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
2352 if (ret < 0) {
2353 printk(IBM_ERR "%s device not present\n", ibm->name);
2354 return 0;
2355 }
2356
2357 acpi_driver_data(ibm->device) = ibm;
2358 sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
2359
2360 status = acpi_install_notify_handler(*ibm->handle, ibm->type,
2361 dispatch_notify, ibm);
2362 if (ACPI_FAILURE(status)) {
2363 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
2364 ibm->name, status);
2365 return -ENODEV;
2366 }
2367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 return 0;
2369}
2370
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002371static int __init ibm_device_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 return 0;
2374}
2375
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002376static int __init register_driver(struct ibm_struct *ibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377{
2378 int ret;
2379
2380 ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
2381 if (!ibm->driver) {
2382 printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
2383 return -1;
2384 }
2385
2386 memset(ibm->driver, 0, sizeof(struct acpi_driver));
Henrique de Moraes Holschuh3dfd35c2006-11-24 10:32:32 -02002387 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 ibm->driver->ids = ibm->hid;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002389 ibm->driver->ops.add = &ibm_device_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
2391 ret = acpi_bus_register_driver(ibm->driver);
2392 if (ret < 0) {
2393 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
2394 ibm->hid, ret);
2395 kfree(ibm->driver);
2396 }
2397
2398 return ret;
2399}
2400
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002401static int __init ibm_init(struct ibm_struct *ibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
2403 int ret;
2404 struct proc_dir_entry *entry;
2405
2406 if (ibm->experimental && !experimental)
2407 return 0;
2408
2409 if (ibm->hid) {
2410 ret = register_driver(ibm);
2411 if (ret < 0)
2412 return ret;
2413 ibm->driver_registered = 1;
2414 }
2415
2416 if (ibm->init) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002417 ret = ibm->init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 if (ret != 0)
2419 return ret;
2420 ibm->init_called = 1;
2421 }
2422
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002423 if (ibm->read) {
2424 entry = create_proc_entry(ibm->name,
2425 S_IFREG | S_IRUGO | S_IWUSR,
2426 proc_dir);
2427 if (!entry) {
2428 printk(IBM_ERR "unable to create proc entry %s\n",
2429 ibm->name);
2430 return -ENODEV;
2431 }
2432 entry->owner = THIS_MODULE;
2433 entry->data = ibm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 entry->read_proc = &dispatch_read;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002435 if (ibm->write)
2436 entry->write_proc = &dispatch_write;
2437 ibm->proc_created = 1;
2438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
2440 if (ibm->notify) {
2441 ret = setup_notify(ibm);
2442 if (ret < 0)
2443 return ret;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002444 ibm->notify_installed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 }
2446
2447 return 0;
2448}
2449
2450static void ibm_exit(struct ibm_struct *ibm)
2451{
2452 if (ibm->notify_installed)
2453 acpi_remove_notify_handler(*ibm->handle, ibm->type,
2454 dispatch_notify);
2455
2456 if (ibm->proc_created)
2457 remove_proc_entry(ibm->name, proc_dir);
2458
2459 if (ibm->init_called && ibm->exit)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002460 ibm->exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
2462 if (ibm->driver_registered) {
2463 acpi_bus_unregister_driver(ibm->driver);
2464 kfree(ibm->driver);
2465 }
2466}
2467
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002468static void __init ibm_handle_init(char *name,
2469 acpi_handle * handle, acpi_handle parent,
2470 char **paths, int num_paths, char **path)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
2472 int i;
2473 acpi_status status;
2474
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002475 for (i = 0; i < num_paths; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 status = acpi_get_handle(parent, paths[i], handle);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002477 if (ACPI_SUCCESS(status)) {
2478 *path = paths[i];
2479 return;
2480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 }
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002482
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 *handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002486#define IBM_HANDLE_INIT(object) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 ibm_handle_init(#object, &object##_handle, *object##_parent, \
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002488 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490static int set_ibm_param(const char *val, struct kernel_param *kp)
2491{
2492 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002494 for (i = 0; i < ARRAY_SIZE(ibms); i++)
2495 if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
2496 if (strlen(val) > sizeof(ibms[i].param) - 2)
2497 return -ENOSPC;
2498 strcpy(ibms[i].param, val);
2499 strcat(ibms[i].param, ",");
2500 return 0;
2501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 return -EINVAL;
2504}
2505
2506#define IBM_PARAM(feature) \
2507 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2508
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002509IBM_PARAM(hotkey);
2510IBM_PARAM(bluetooth);
2511IBM_PARAM(video);
2512IBM_PARAM(light);
Kristen Accardi63e5f242006-02-23 17:56:06 -08002513#ifdef CONFIG_ACPI_IBM_DOCK
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002514IBM_PARAM(dock);
Kristen Accardi63e5f242006-02-23 17:56:06 -08002515#endif
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002516IBM_PARAM(bay);
2517IBM_PARAM(cmos);
2518IBM_PARAM(led);
2519IBM_PARAM(beep);
2520IBM_PARAM(ecdump);
2521IBM_PARAM(brightness);
2522IBM_PARAM(volume);
2523IBM_PARAM(fan);
2524
Holger Macht8acb0252006-10-20 14:30:28 -07002525static struct backlight_properties ibm_backlight_data = {
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -02002526 .owner = THIS_MODULE,
2527 .get_brightness = brightness_get,
2528 .update_status = brightness_update_status,
2529 .max_brightness = 7,
Holger Macht8acb0252006-10-20 14:30:28 -07002530};
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532static void acpi_ibm_exit(void)
2533{
2534 int i;
2535
Holger Macht8acb0252006-10-20 14:30:28 -07002536 if (ibm_backlight_device)
2537 backlight_device_unregister(ibm_backlight_device);
2538
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002539 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 ibm_exit(&ibms[i]);
2541
2542 remove_proc_entry(IBM_DIR, acpi_root_dir);
2543}
2544
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02002545static int __init check_dmi_for_ec(void)
2546{
2547 struct dmi_device *dev = NULL;
2548
2549 /*
2550 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2551 * X32 or newer, all Z series; Some models must have an
2552 * up-to-date BIOS or they will not be detected.
2553 *
2554 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2555 */
2556 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2557 if (strstr(dev->name, "IBM ThinkPad Embedded Controller"))
2558 return 1;
2559 }
2560 return 0;
2561}
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563static int __init acpi_ibm_init(void)
2564{
2565 int ret, i;
2566
2567 if (acpi_disabled)
2568 return -ENODEV;
2569
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002570 if (!acpi_specific_hotkey_enabled) {
2571 printk(IBM_ERR "using generic hotkey driver\n");
2572 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -05002573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002575 /* ec is required because many other handles are relative to it */
2576 IBM_HANDLE_INIT(ec);
2577 if (!ec_handle) {
2578 printk(IBM_ERR "ec object not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 return -ENODEV;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02002582 /* Models with newer firmware report the EC in DMI */
2583 ibm_thinkpad_ec_found = check_dmi_for_ec();
2584
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 /* these handles are not required */
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002586 IBM_HANDLE_INIT(vid);
2587 IBM_HANDLE_INIT(vid2);
2588 IBM_HANDLE_INIT(ledb);
2589 IBM_HANDLE_INIT(led);
2590 IBM_HANDLE_INIT(hkey);
2591 IBM_HANDLE_INIT(lght);
2592 IBM_HANDLE_INIT(cmos);
Kristen Accardi63e5f242006-02-23 17:56:06 -08002593#ifdef CONFIG_ACPI_IBM_DOCK
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002594 IBM_HANDLE_INIT(dock);
Kristen Accardi63e5f242006-02-23 17:56:06 -08002595#endif
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002596 IBM_HANDLE_INIT(pci);
2597 IBM_HANDLE_INIT(bay);
2598 if (bay_handle)
2599 IBM_HANDLE_INIT(bay_ej);
2600 IBM_HANDLE_INIT(bay2);
2601 if (bay2_handle)
2602 IBM_HANDLE_INIT(bay2_ej);
2603 IBM_HANDLE_INIT(beep);
2604 IBM_HANDLE_INIT(ecrd);
2605 IBM_HANDLE_INIT(ecwr);
2606 IBM_HANDLE_INIT(fans);
2607 IBM_HANDLE_INIT(gfan);
2608 IBM_HANDLE_INIT(sfan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
2610 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
2611 if (!proc_dir) {
2612 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
2613 return -ENODEV;
2614 }
2615 proc_dir->owner = THIS_MODULE;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002616
2617 for (i = 0; i < ARRAY_SIZE(ibms); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 ret = ibm_init(&ibms[i]);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002619 if (ret >= 0 && *ibms[i].param)
2620 ret = ibms[i].write(ibms[i].param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 if (ret < 0) {
2622 acpi_ibm_exit();
2623 return ret;
2624 }
2625 }
2626
Holger Macht8acb0252006-10-20 14:30:28 -07002627 ibm_backlight_device = backlight_device_register("ibm", NULL,
2628 &ibm_backlight_data);
Henrique de Moraes Holschuh8d297262006-11-24 11:47:07 -02002629 if (IS_ERR(ibm_backlight_device)) {
Holger Macht8acb0252006-10-20 14:30:28 -07002630 printk(IBM_ERR "Could not register ibm backlight device\n");
2631 ibm_backlight_device = NULL;
2632 acpi_ibm_exit();
2633 }
2634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 return 0;
2636}
2637
2638module_init(acpi_ibm_init);
2639module_exit(acpi_ibm_exit);